xref: /illumos-gate/usr/src/cmd/fm/fmdump/common/asru.c (revision 2db6d663)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
547911a7dScy  * Common Development and Distribution License (the "License").
647911a7dScy  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22f6e214c7SGavin Maltby  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
23*2db6d663SJoshua M. Clulow  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include <fmdump.h>
277c478bd9Sstevel@tonic-gate #include <strings.h>
287c478bd9Sstevel@tonic-gate #include <stdio.h>
297c478bd9Sstevel@tonic-gate #include <time.h>
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*ARGSUSED*/
327c478bd9Sstevel@tonic-gate static int
asru_short(fmd_log_t * lp,const fmd_log_record_t * rp,FILE * fp)337c478bd9Sstevel@tonic-gate asru_short(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
347c478bd9Sstevel@tonic-gate {
357c478bd9Sstevel@tonic-gate 	char buf[32];
367c478bd9Sstevel@tonic-gate 
3747911a7dScy 	fmdump_printf(fp, "%-20s %-32s\n",
3847911a7dScy 	    fmdump_date(buf, sizeof (buf), rp), rp->rec_class);
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate 	return (0);
417c478bd9Sstevel@tonic-gate }
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*ARGSUSED*/
447c478bd9Sstevel@tonic-gate static int
asru_verb1(fmd_log_t * lp,const fmd_log_record_t * rp,FILE * fp)457c478bd9Sstevel@tonic-gate asru_verb1(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
467c478bd9Sstevel@tonic-gate {
477c478bd9Sstevel@tonic-gate 	char *uuid = "-";
487c478bd9Sstevel@tonic-gate 	boolean_t f = 0, u = 0;
497c478bd9Sstevel@tonic-gate 	char buf[32], state[32];
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate 	(void) nvlist_lookup_string(rp->rec_nvl, FM_RSRC_ASRU_UUID, &uuid);
527c478bd9Sstevel@tonic-gate 	(void) nvlist_lookup_boolean_value(rp->rec_nvl,
537c478bd9Sstevel@tonic-gate 	    FM_RSRC_ASRU_FAULTY, &f);
547c478bd9Sstevel@tonic-gate 	(void) nvlist_lookup_boolean_value(rp->rec_nvl,
557c478bd9Sstevel@tonic-gate 	    FM_RSRC_ASRU_UNUSABLE, &u);
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate 	state[0] = '\0';
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate 	if (f)
607c478bd9Sstevel@tonic-gate 		(void) strcat(state, ",faulty");
617c478bd9Sstevel@tonic-gate 	if (u)
627c478bd9Sstevel@tonic-gate 		(void) strcat(state, ",unusable");
637c478bd9Sstevel@tonic-gate 	if (!f && !u)
647c478bd9Sstevel@tonic-gate 		(void) strcat(state, ",ok");
657c478bd9Sstevel@tonic-gate 
6647911a7dScy 	fmdump_printf(fp, "%-20s %-36s %s\n",
6747911a7dScy 	    fmdump_date(buf, sizeof (buf), rp), uuid, state + 1);
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate 	return (0);
707c478bd9Sstevel@tonic-gate }
717c478bd9Sstevel@tonic-gate 
72540db9a9SStephen Hanson /*ARGSUSED*/
737c478bd9Sstevel@tonic-gate static int
asru_verb23_cmn(fmd_log_t * lp,const fmd_log_record_t * rp,FILE * fp,nvlist_prtctl_t pctl)74f6e214c7SGavin Maltby asru_verb23_cmn(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp,
75f6e214c7SGavin Maltby     nvlist_prtctl_t pctl)
767c478bd9Sstevel@tonic-gate {
77540db9a9SStephen Hanson 	char *uuid = "-";
78540db9a9SStephen Hanson 	boolean_t f = 0, u = 0;
79540db9a9SStephen Hanson 	char buf[32], state[32];
80540db9a9SStephen Hanson 
81540db9a9SStephen Hanson 	(void) nvlist_lookup_string(rp->rec_nvl, FM_RSRC_ASRU_UUID, &uuid);
82540db9a9SStephen Hanson 	(void) nvlist_lookup_boolean_value(rp->rec_nvl,
83540db9a9SStephen Hanson 	    FM_RSRC_ASRU_FAULTY, &f);
84540db9a9SStephen Hanson 	(void) nvlist_lookup_boolean_value(rp->rec_nvl,
85540db9a9SStephen Hanson 	    FM_RSRC_ASRU_UNUSABLE, &u);
86540db9a9SStephen Hanson 
87540db9a9SStephen Hanson 	state[0] = '\0';
88540db9a9SStephen Hanson 
89540db9a9SStephen Hanson 	if (f)
90540db9a9SStephen Hanson 		(void) strcat(state, ",faulty");
91540db9a9SStephen Hanson 	if (u)
92540db9a9SStephen Hanson 		(void) strcat(state, ",unusable");
93540db9a9SStephen Hanson 	if (!f && !u)
94540db9a9SStephen Hanson 		(void) strcat(state, ",ok");
95540db9a9SStephen Hanson 
96540db9a9SStephen Hanson 	fmdump_printf(fp, "%-20s.%9.9llu %-36s %s\n",
97540db9a9SStephen Hanson 	    fmdump_year(buf, sizeof (buf), rp), rp->rec_nsec, uuid, state + 1);
987c478bd9Sstevel@tonic-gate 
99f6e214c7SGavin Maltby 	if (pctl)
100f6e214c7SGavin Maltby 		nvlist_prt(rp->rec_nvl, pctl);
101f6e214c7SGavin Maltby 	else
102f6e214c7SGavin Maltby 		nvlist_print(fp, rp->rec_nvl);
103f6e214c7SGavin Maltby 
1047c478bd9Sstevel@tonic-gate 	fmdump_printf(fp, "\n");
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	return (0);
1077c478bd9Sstevel@tonic-gate }
1087c478bd9Sstevel@tonic-gate 
109f6e214c7SGavin Maltby static int
asru_verb2(fmd_log_t * lp,const fmd_log_record_t * rp,FILE * fp)110f6e214c7SGavin Maltby asru_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
111f6e214c7SGavin Maltby {
112f6e214c7SGavin Maltby 	return (asru_verb23_cmn(lp, rp, fp, NULL));
113f6e214c7SGavin Maltby }
114f6e214c7SGavin Maltby 
115f6e214c7SGavin Maltby static int
asru_pretty(fmd_log_t * lp,const fmd_log_record_t * rp,FILE * fp)116f6e214c7SGavin Maltby asru_pretty(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
117f6e214c7SGavin Maltby {
118f6e214c7SGavin Maltby 	nvlist_prtctl_t pctl;
119f6e214c7SGavin Maltby 	int rc;
120f6e214c7SGavin Maltby 
121f6e214c7SGavin Maltby 	if ((pctl = nvlist_prtctl_alloc()) != NULL) {
122f6e214c7SGavin Maltby 		nvlist_prtctl_setdest(pctl, fp);
123f6e214c7SGavin Maltby 		nvlist_prtctlop_nvlist(pctl, fmdump_render_nvlist, NULL);
124f6e214c7SGavin Maltby 	}
125f6e214c7SGavin Maltby 
126f6e214c7SGavin Maltby 	rc = asru_verb23_cmn(lp, rp, fp, pctl);
127f6e214c7SGavin Maltby 
128f6e214c7SGavin Maltby 	nvlist_prtctl_free(pctl);
129f6e214c7SGavin Maltby 	return (rc);
130f6e214c7SGavin Maltby }
131f6e214c7SGavin Maltby 
1327c478bd9Sstevel@tonic-gate const fmdump_ops_t fmdump_asru_ops = {
1337c478bd9Sstevel@tonic-gate "asru", {
1347c478bd9Sstevel@tonic-gate {
1357c478bd9Sstevel@tonic-gate "TIME                 CLASS",
1367c478bd9Sstevel@tonic-gate (fmd_log_rec_f *)asru_short
1377c478bd9Sstevel@tonic-gate }, {
1387c478bd9Sstevel@tonic-gate "TIME                 UUID                                 STATE",
1397c478bd9Sstevel@tonic-gate (fmd_log_rec_f *)asru_verb1
1407c478bd9Sstevel@tonic-gate }, {
141540db9a9SStephen Hanson "TIME                           UUID                                 STATE",
1427c478bd9Sstevel@tonic-gate (fmd_log_rec_f *)asru_verb2
143b6955755SRobert Johnston }, {
144f6e214c7SGavin Maltby "TIME                           UUID                                 STATE",
145f6e214c7SGavin Maltby (fmd_log_rec_f *)asru_pretty
146f6e214c7SGavin Maltby }, {
147b6955755SRobert Johnston NULL, NULL
148*2db6d663SJoshua M. Clulow }, {
149*2db6d663SJoshua M. Clulow NULL,
150*2db6d663SJoshua M. Clulow (fmd_log_rec_f *)fmdump_print_json
1517c478bd9Sstevel@tonic-gate } }
1527c478bd9Sstevel@tonic-gate };
153