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
53323Scindi  * Common Development and Distribution License (the "License").
63323Scindi  * 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 /*
226276Scy152378  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <fmdump.h>
290Sstevel@tonic-gate #include <stdio.h>
303323Scindi #include <strings.h>
310Sstevel@tonic-gate 
320Sstevel@tonic-gate /*ARGSUSED*/
330Sstevel@tonic-gate static int
340Sstevel@tonic-gate flt_short(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
350Sstevel@tonic-gate {
366276Scy152378 	char buf[32], str[32];
376276Scy152378 	char *class = NULL, *uuid = "-", *code = "-";
380Sstevel@tonic-gate 
390Sstevel@tonic-gate 	(void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_UUID, &uuid);
400Sstevel@tonic-gate 	(void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_DIAG_CODE, &code);
410Sstevel@tonic-gate 
426276Scy152378 	(void) nvlist_lookup_string(rp->rec_nvl, FM_CLASS, &class);
436276Scy152378 	if (class != NULL && strcmp(class, FM_LIST_REPAIRED_CLASS) == 0) {
446276Scy152378 		(void) snprintf(str, sizeof (str), "%s %s", code, "Repaired");
456276Scy152378 		code = str;
466276Scy152378 	}
47*7275Sstephh 	if (class != NULL && strcmp(class, FM_LIST_RESOLVED_CLASS) == 0) {
48*7275Sstephh 		(void) snprintf(str, sizeof (str), "%s %s", code, "Resolved");
49*7275Sstephh 		code = str;
50*7275Sstephh 	}
51*7275Sstephh 
52*7275Sstephh 	if (class != NULL && strcmp(class, FM_LIST_UPDATED_CLASS) == 0) {
53*7275Sstephh 		(void) snprintf(str, sizeof (str), "%s %s", code, "Updated");
54*7275Sstephh 		code = str;
55*7275Sstephh 	}
566276Scy152378 
575609Scy152378 	fmdump_printf(fp, "%-20s %-32s %s\n",
585609Scy152378 	    fmdump_date(buf, sizeof (buf), rp), uuid, code);
590Sstevel@tonic-gate 
600Sstevel@tonic-gate 	return (0);
610Sstevel@tonic-gate }
620Sstevel@tonic-gate 
630Sstevel@tonic-gate static int
640Sstevel@tonic-gate flt_verb1(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
650Sstevel@tonic-gate {
660Sstevel@tonic-gate 	uint_t i, size = 0;
670Sstevel@tonic-gate 	nvlist_t **nva;
68*7275Sstephh 	uint8_t *ba;
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 	(void) flt_short(lp, rp, fp);
710Sstevel@tonic-gate 	(void) nvlist_lookup_uint32(rp->rec_nvl, FM_SUSPECT_FAULT_SZ, &size);
720Sstevel@tonic-gate 
730Sstevel@tonic-gate 	if (size != 0) {
740Sstevel@tonic-gate 		(void) nvlist_lookup_nvlist_array(rp->rec_nvl,
750Sstevel@tonic-gate 		    FM_SUSPECT_FAULT_LIST, &nva, &size);
76*7275Sstephh 		(void) nvlist_lookup_uint8_array(rp->rec_nvl,
77*7275Sstephh 		    FM_SUSPECT_FAULT_STATUS, &ba, &size);
780Sstevel@tonic-gate 	}
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 	for (i = 0; i < size; i++) {
811414Scindi 		char *class = NULL, *rname = NULL, *aname = NULL, *fname = NULL;
823323Scindi 		char *loc = NULL;
831414Scindi 		nvlist_t *fru, *asru, *rsrc;
840Sstevel@tonic-gate 		uint8_t pct = 0;
850Sstevel@tonic-gate 
860Sstevel@tonic-gate 		(void) nvlist_lookup_uint8(nva[i], FM_FAULT_CERTAINTY, &pct);
870Sstevel@tonic-gate 		(void) nvlist_lookup_string(nva[i], FM_CLASS, &class);
880Sstevel@tonic-gate 
890Sstevel@tonic-gate 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_FRU, &fru) == 0)
900Sstevel@tonic-gate 			fname = fmdump_nvl2str(fru);
910Sstevel@tonic-gate 
921414Scindi 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_ASRU, &asru) == 0)
931414Scindi 			aname = fmdump_nvl2str(asru);
941414Scindi 
951414Scindi 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_RESOURCE, &rsrc) == 0)
961414Scindi 			rname = fmdump_nvl2str(rsrc);
971414Scindi 
983323Scindi 		if (nvlist_lookup_string(nva[i], FM_FAULT_LOCATION, &loc)
993323Scindi 		    == 0) {
1003530Srb144127 			if (fname && strncmp(fname, FM_FMRI_LEGACY_HC_PREFIX,
1013323Scindi 			    sizeof (FM_FMRI_LEGACY_HC_PREFIX)) == 0)
1023323Scindi 				loc = fname + sizeof (FM_FMRI_LEGACY_HC_PREFIX);
1033323Scindi 		}
1043323Scindi 
1053323Scindi 
106*7275Sstephh 		fmdump_printf(fp, "  %3u%%  %s",
1071414Scindi 		    pct, class ? class : "-");
1080Sstevel@tonic-gate 
109*7275Sstephh 		if (ba[i] & FM_SUSPECT_FAULTY)
110*7275Sstephh 			fmdump_printf(fp, "\n\n");
111*7275Sstephh 		else if (ba[i] & FM_SUSPECT_NOT_PRESENT)
112*7275Sstephh 			fmdump_printf(fp, "\tRemoved\n\n");
113*7275Sstephh 		else if (ba[i] & FM_SUSPECT_REPLACED)
114*7275Sstephh 			fmdump_printf(fp, "\tReplaced\n\n");
115*7275Sstephh 		else if (ba[i] & FM_SUSPECT_REPAIRED)
116*7275Sstephh 			fmdump_printf(fp, "\tRepair Attempted\n\n");
117*7275Sstephh 		else if (ba[i] & FM_SUSPECT_ACQUITTED)
118*7275Sstephh 			fmdump_printf(fp, "\tAcquitted\n\n");
119*7275Sstephh 		else
120*7275Sstephh 			fmdump_printf(fp, "\n\n");
121*7275Sstephh 
1221414Scindi 		fmdump_printf(fp, "        Problem in: %s\n",
123*7275Sstephh 		    rname ? rname : "-");
1241414Scindi 
1251414Scindi 		fmdump_printf(fp, "           Affects: %s\n",
1261414Scindi 		    aname ? aname : "-");
1271414Scindi 
1283323Scindi 		fmdump_printf(fp, "               FRU: %s\n",
1291414Scindi 		    fname ? fname : "-");
1300Sstevel@tonic-gate 
1313323Scindi 		fmdump_printf(fp, "          Location: %s\n\n",
1323323Scindi 		    loc ? loc : "-");
1333323Scindi 
1340Sstevel@tonic-gate 		free(fname);
1351414Scindi 		free(aname);
1360Sstevel@tonic-gate 		free(rname);
1370Sstevel@tonic-gate 	}
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate 	return (0);
1400Sstevel@tonic-gate }
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate static int
1430Sstevel@tonic-gate flt_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
1440Sstevel@tonic-gate {
1450Sstevel@tonic-gate 	const struct fmdump_fmt *efp = &fmdump_err_ops.do_formats[FMDUMP_VERB1];
1460Sstevel@tonic-gate 	const struct fmdump_fmt *ffp = &fmdump_flt_ops.do_formats[FMDUMP_VERB1];
1470Sstevel@tonic-gate 	uint_t i;
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate 	fmdump_printf(fp, "%s\n", ffp->do_hdr);
1500Sstevel@tonic-gate 	(void) flt_short(lp, rp, fp);
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate 	if (rp->rec_nrefs != 0)
1530Sstevel@tonic-gate 		fmdump_printf(fp, "\n  %s\n", efp->do_hdr);
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate 	for (i = 0; i < rp->rec_nrefs; i++) {
1560Sstevel@tonic-gate 		fmdump_printf(fp, "  ");
1570Sstevel@tonic-gate 		efp->do_func(lp, &rp->rec_xrefs[i], fp);
1580Sstevel@tonic-gate 	}
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate 	fmdump_printf(fp, "\n");
1610Sstevel@tonic-gate 	nvlist_print(fp, rp->rec_nvl);
1620Sstevel@tonic-gate 	fmdump_printf(fp, "\n");
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 	return (0);
1650Sstevel@tonic-gate }
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate const fmdump_ops_t fmdump_flt_ops = {
1680Sstevel@tonic-gate "fault", {
1690Sstevel@tonic-gate {
1700Sstevel@tonic-gate "TIME                 UUID                                 SUNW-MSG-ID",
1710Sstevel@tonic-gate (fmd_log_rec_f *)flt_short
1720Sstevel@tonic-gate }, {
1730Sstevel@tonic-gate "TIME                 UUID                                 SUNW-MSG-ID",
1740Sstevel@tonic-gate (fmd_log_rec_f *)flt_verb1
1750Sstevel@tonic-gate }, {
1760Sstevel@tonic-gate NULL,
1770Sstevel@tonic-gate (fmd_log_rec_f *)flt_verb2
1780Sstevel@tonic-gate } }
1790Sstevel@tonic-gate };
180