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 /*
223530Srb144127  * Copyright 2007 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 {
360Sstevel@tonic-gate 	char buf[32], *uuid = "-", *code = "-";
370Sstevel@tonic-gate 
380Sstevel@tonic-gate 	(void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_UUID, &uuid);
390Sstevel@tonic-gate 	(void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_DIAG_CODE, &code);
400Sstevel@tonic-gate 
41*5609Scy152378 	fmdump_printf(fp, "%-20s %-32s %s\n",
42*5609Scy152378 	    fmdump_date(buf, sizeof (buf), rp), uuid, code);
430Sstevel@tonic-gate 
440Sstevel@tonic-gate 	return (0);
450Sstevel@tonic-gate }
460Sstevel@tonic-gate 
470Sstevel@tonic-gate static int
480Sstevel@tonic-gate flt_verb1(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
490Sstevel@tonic-gate {
500Sstevel@tonic-gate 	uint_t i, size = 0;
510Sstevel@tonic-gate 	nvlist_t **nva;
520Sstevel@tonic-gate 
530Sstevel@tonic-gate 	(void) flt_short(lp, rp, fp);
540Sstevel@tonic-gate 	(void) nvlist_lookup_uint32(rp->rec_nvl, FM_SUSPECT_FAULT_SZ, &size);
550Sstevel@tonic-gate 
560Sstevel@tonic-gate 	if (size != 0) {
570Sstevel@tonic-gate 		(void) nvlist_lookup_nvlist_array(rp->rec_nvl,
580Sstevel@tonic-gate 		    FM_SUSPECT_FAULT_LIST, &nva, &size);
590Sstevel@tonic-gate 	}
600Sstevel@tonic-gate 
610Sstevel@tonic-gate 	for (i = 0; i < size; i++) {
621414Scindi 		char *class = NULL, *rname = NULL, *aname = NULL, *fname = NULL;
633323Scindi 		char *loc = NULL;
641414Scindi 		nvlist_t *fru, *asru, *rsrc;
650Sstevel@tonic-gate 		uint8_t pct = 0;
660Sstevel@tonic-gate 
670Sstevel@tonic-gate 		(void) nvlist_lookup_uint8(nva[i], FM_FAULT_CERTAINTY, &pct);
680Sstevel@tonic-gate 		(void) nvlist_lookup_string(nva[i], FM_CLASS, &class);
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_FRU, &fru) == 0)
710Sstevel@tonic-gate 			fname = fmdump_nvl2str(fru);
720Sstevel@tonic-gate 
731414Scindi 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_ASRU, &asru) == 0)
741414Scindi 			aname = fmdump_nvl2str(asru);
751414Scindi 
761414Scindi 		if (nvlist_lookup_nvlist(nva[i], FM_FAULT_RESOURCE, &rsrc) == 0)
771414Scindi 			rname = fmdump_nvl2str(rsrc);
781414Scindi 
793323Scindi 		if (nvlist_lookup_string(nva[i], FM_FAULT_LOCATION, &loc)
803323Scindi 		    == 0) {
813530Srb144127 			if (fname && strncmp(fname, FM_FMRI_LEGACY_HC_PREFIX,
823323Scindi 			    sizeof (FM_FMRI_LEGACY_HC_PREFIX)) == 0)
833323Scindi 				loc = fname + sizeof (FM_FMRI_LEGACY_HC_PREFIX);
843323Scindi 		}
853323Scindi 
863323Scindi 
871414Scindi 		fmdump_printf(fp, "  %3u%%  %s\n\n",
881414Scindi 		    pct, class ? class : "-");
890Sstevel@tonic-gate 
901414Scindi 		/*
911414Scindi 		 * Originally we didn't require FM_FAULT_RESOURCE, so if it
921414Scindi 		 * isn't defined in the event, display the ASRU FMRI instead.
931414Scindi 		 */
941414Scindi 		fmdump_printf(fp, "        Problem in: %s\n",
951414Scindi 		    rname ? rname : aname ? aname : "-");
961414Scindi 
971414Scindi 		fmdump_printf(fp, "           Affects: %s\n",
981414Scindi 		    aname ? aname : "-");
991414Scindi 
1003323Scindi 		fmdump_printf(fp, "               FRU: %s\n",
1011414Scindi 		    fname ? fname : "-");
1020Sstevel@tonic-gate 
1033323Scindi 		fmdump_printf(fp, "          Location: %s\n\n",
1043323Scindi 		    loc ? loc : "-");
1053323Scindi 
1060Sstevel@tonic-gate 		free(fname);
1071414Scindi 		free(aname);
1080Sstevel@tonic-gate 		free(rname);
1090Sstevel@tonic-gate 	}
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 	return (0);
1120Sstevel@tonic-gate }
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate static int
1150Sstevel@tonic-gate flt_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
1160Sstevel@tonic-gate {
1170Sstevel@tonic-gate 	const struct fmdump_fmt *efp = &fmdump_err_ops.do_formats[FMDUMP_VERB1];
1180Sstevel@tonic-gate 	const struct fmdump_fmt *ffp = &fmdump_flt_ops.do_formats[FMDUMP_VERB1];
1190Sstevel@tonic-gate 	uint_t i;
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate 	fmdump_printf(fp, "%s\n", ffp->do_hdr);
1220Sstevel@tonic-gate 	(void) flt_short(lp, rp, fp);
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate 	if (rp->rec_nrefs != 0)
1250Sstevel@tonic-gate 		fmdump_printf(fp, "\n  %s\n", efp->do_hdr);
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate 	for (i = 0; i < rp->rec_nrefs; i++) {
1280Sstevel@tonic-gate 		fmdump_printf(fp, "  ");
1290Sstevel@tonic-gate 		efp->do_func(lp, &rp->rec_xrefs[i], fp);
1300Sstevel@tonic-gate 	}
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate 	fmdump_printf(fp, "\n");
1330Sstevel@tonic-gate 	nvlist_print(fp, rp->rec_nvl);
1340Sstevel@tonic-gate 	fmdump_printf(fp, "\n");
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate 	return (0);
1370Sstevel@tonic-gate }
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate const fmdump_ops_t fmdump_flt_ops = {
1400Sstevel@tonic-gate "fault", {
1410Sstevel@tonic-gate {
1420Sstevel@tonic-gate "TIME                 UUID                                 SUNW-MSG-ID",
1430Sstevel@tonic-gate (fmd_log_rec_f *)flt_short
1440Sstevel@tonic-gate }, {
1450Sstevel@tonic-gate "TIME                 UUID                                 SUNW-MSG-ID",
1460Sstevel@tonic-gate (fmd_log_rec_f *)flt_verb1
1470Sstevel@tonic-gate }, {
1480Sstevel@tonic-gate NULL,
1490Sstevel@tonic-gate (fmd_log_rec_f *)flt_verb2
1500Sstevel@tonic-gate } }
1510Sstevel@tonic-gate };
152