xref: /onnv-gate/usr/src/cmd/fm/fmdump/common/asru.c (revision 12967:ab9ae749152f)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
55609Scy152378  * Common Development and Distribution License (the "License").
65609Scy152378  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*12967Sgavin.maltby@oracle.com  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate #include <fmdump.h>
260Sstevel@tonic-gate #include <strings.h>
270Sstevel@tonic-gate #include <stdio.h>
280Sstevel@tonic-gate #include <time.h>
290Sstevel@tonic-gate 
300Sstevel@tonic-gate /*ARGSUSED*/
310Sstevel@tonic-gate static int
asru_short(fmd_log_t * lp,const fmd_log_record_t * rp,FILE * fp)320Sstevel@tonic-gate asru_short(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
330Sstevel@tonic-gate {
340Sstevel@tonic-gate 	char buf[32];
350Sstevel@tonic-gate 
365609Scy152378 	fmdump_printf(fp, "%-20s %-32s\n",
375609Scy152378 	    fmdump_date(buf, sizeof (buf), rp), rp->rec_class);
380Sstevel@tonic-gate 
390Sstevel@tonic-gate 	return (0);
400Sstevel@tonic-gate }
410Sstevel@tonic-gate 
420Sstevel@tonic-gate /*ARGSUSED*/
430Sstevel@tonic-gate static int
asru_verb1(fmd_log_t * lp,const fmd_log_record_t * rp,FILE * fp)440Sstevel@tonic-gate asru_verb1(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
450Sstevel@tonic-gate {
460Sstevel@tonic-gate 	char *uuid = "-";
470Sstevel@tonic-gate 	boolean_t f = 0, u = 0;
480Sstevel@tonic-gate 	char buf[32], state[32];
490Sstevel@tonic-gate 
500Sstevel@tonic-gate 	(void) nvlist_lookup_string(rp->rec_nvl, FM_RSRC_ASRU_UUID, &uuid);
510Sstevel@tonic-gate 	(void) nvlist_lookup_boolean_value(rp->rec_nvl,
520Sstevel@tonic-gate 	    FM_RSRC_ASRU_FAULTY, &f);
530Sstevel@tonic-gate 	(void) nvlist_lookup_boolean_value(rp->rec_nvl,
540Sstevel@tonic-gate 	    FM_RSRC_ASRU_UNUSABLE, &u);
550Sstevel@tonic-gate 
560Sstevel@tonic-gate 	state[0] = '\0';
570Sstevel@tonic-gate 
580Sstevel@tonic-gate 	if (f)
590Sstevel@tonic-gate 		(void) strcat(state, ",faulty");
600Sstevel@tonic-gate 	if (u)
610Sstevel@tonic-gate 		(void) strcat(state, ",unusable");
620Sstevel@tonic-gate 	if (!f && !u)
630Sstevel@tonic-gate 		(void) strcat(state, ",ok");
640Sstevel@tonic-gate 
655609Scy152378 	fmdump_printf(fp, "%-20s %-36s %s\n",
665609Scy152378 	    fmdump_date(buf, sizeof (buf), rp), uuid, state + 1);
670Sstevel@tonic-gate 
680Sstevel@tonic-gate 	return (0);
690Sstevel@tonic-gate }
700Sstevel@tonic-gate 
7110928SStephen.Hanson@Sun.COM /*ARGSUSED*/
720Sstevel@tonic-gate static int
asru_verb23_cmn(fmd_log_t * lp,const fmd_log_record_t * rp,FILE * fp,nvlist_prtctl_t pctl)73*12967Sgavin.maltby@oracle.com asru_verb23_cmn(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp,
74*12967Sgavin.maltby@oracle.com     nvlist_prtctl_t pctl)
750Sstevel@tonic-gate {
7610928SStephen.Hanson@Sun.COM 	char *uuid = "-";
7710928SStephen.Hanson@Sun.COM 	boolean_t f = 0, u = 0;
7810928SStephen.Hanson@Sun.COM 	char buf[32], state[32];
7910928SStephen.Hanson@Sun.COM 
8010928SStephen.Hanson@Sun.COM 	(void) nvlist_lookup_string(rp->rec_nvl, FM_RSRC_ASRU_UUID, &uuid);
8110928SStephen.Hanson@Sun.COM 	(void) nvlist_lookup_boolean_value(rp->rec_nvl,
8210928SStephen.Hanson@Sun.COM 	    FM_RSRC_ASRU_FAULTY, &f);
8310928SStephen.Hanson@Sun.COM 	(void) nvlist_lookup_boolean_value(rp->rec_nvl,
8410928SStephen.Hanson@Sun.COM 	    FM_RSRC_ASRU_UNUSABLE, &u);
8510928SStephen.Hanson@Sun.COM 
8610928SStephen.Hanson@Sun.COM 	state[0] = '\0';
8710928SStephen.Hanson@Sun.COM 
8810928SStephen.Hanson@Sun.COM 	if (f)
8910928SStephen.Hanson@Sun.COM 		(void) strcat(state, ",faulty");
9010928SStephen.Hanson@Sun.COM 	if (u)
9110928SStephen.Hanson@Sun.COM 		(void) strcat(state, ",unusable");
9210928SStephen.Hanson@Sun.COM 	if (!f && !u)
9310928SStephen.Hanson@Sun.COM 		(void) strcat(state, ",ok");
9410928SStephen.Hanson@Sun.COM 
9510928SStephen.Hanson@Sun.COM 	fmdump_printf(fp, "%-20s.%9.9llu %-36s %s\n",
9610928SStephen.Hanson@Sun.COM 	    fmdump_year(buf, sizeof (buf), rp), rp->rec_nsec, uuid, state + 1);
970Sstevel@tonic-gate 
98*12967Sgavin.maltby@oracle.com 	if (pctl)
99*12967Sgavin.maltby@oracle.com 		nvlist_prt(rp->rec_nvl, pctl);
100*12967Sgavin.maltby@oracle.com 	else
101*12967Sgavin.maltby@oracle.com 		nvlist_print(fp, rp->rec_nvl);
102*12967Sgavin.maltby@oracle.com 
1030Sstevel@tonic-gate 	fmdump_printf(fp, "\n");
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate 	return (0);
1060Sstevel@tonic-gate }
1070Sstevel@tonic-gate 
108*12967Sgavin.maltby@oracle.com static int
asru_verb2(fmd_log_t * lp,const fmd_log_record_t * rp,FILE * fp)109*12967Sgavin.maltby@oracle.com asru_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
110*12967Sgavin.maltby@oracle.com {
111*12967Sgavin.maltby@oracle.com 	return (asru_verb23_cmn(lp, rp, fp, NULL));
112*12967Sgavin.maltby@oracle.com }
113*12967Sgavin.maltby@oracle.com 
114*12967Sgavin.maltby@oracle.com static int
asru_pretty(fmd_log_t * lp,const fmd_log_record_t * rp,FILE * fp)115*12967Sgavin.maltby@oracle.com asru_pretty(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
116*12967Sgavin.maltby@oracle.com {
117*12967Sgavin.maltby@oracle.com 	nvlist_prtctl_t pctl;
118*12967Sgavin.maltby@oracle.com 	int rc;
119*12967Sgavin.maltby@oracle.com 
120*12967Sgavin.maltby@oracle.com 	if ((pctl = nvlist_prtctl_alloc()) != NULL) {
121*12967Sgavin.maltby@oracle.com 		nvlist_prtctl_setdest(pctl, fp);
122*12967Sgavin.maltby@oracle.com 		nvlist_prtctlop_nvlist(pctl, fmdump_render_nvlist, NULL);
123*12967Sgavin.maltby@oracle.com 	}
124*12967Sgavin.maltby@oracle.com 
125*12967Sgavin.maltby@oracle.com 	rc = asru_verb23_cmn(lp, rp, fp, pctl);
126*12967Sgavin.maltby@oracle.com 
127*12967Sgavin.maltby@oracle.com 	nvlist_prtctl_free(pctl);
128*12967Sgavin.maltby@oracle.com 	return (rc);
129*12967Sgavin.maltby@oracle.com }
130*12967Sgavin.maltby@oracle.com 
1310Sstevel@tonic-gate const fmdump_ops_t fmdump_asru_ops = {
1320Sstevel@tonic-gate "asru", {
1330Sstevel@tonic-gate {
1340Sstevel@tonic-gate "TIME                 CLASS",
1350Sstevel@tonic-gate (fmd_log_rec_f *)asru_short
1360Sstevel@tonic-gate }, {
1370Sstevel@tonic-gate "TIME                 UUID                                 STATE",
1380Sstevel@tonic-gate (fmd_log_rec_f *)asru_verb1
1390Sstevel@tonic-gate }, {
14010928SStephen.Hanson@Sun.COM "TIME                           UUID                                 STATE",
1410Sstevel@tonic-gate (fmd_log_rec_f *)asru_verb2
1429501SRobert.Johnston@Sun.COM }, {
143*12967Sgavin.maltby@oracle.com "TIME                           UUID                                 STATE",
144*12967Sgavin.maltby@oracle.com (fmd_log_rec_f *)asru_pretty
145*12967Sgavin.maltby@oracle.com }, {
1469501SRobert.Johnston@Sun.COM NULL, NULL
1470Sstevel@tonic-gate } }
1480Sstevel@tonic-gate };
149