xref: /illumos-gate/usr/src/cmd/fm/fmdump/common/error.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 <stdio.h>
287c478bd9Sstevel@tonic-gate #include <time.h>
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*ARGSUSED*/
317c478bd9Sstevel@tonic-gate static int
err_short(fmd_log_t * lp,const fmd_log_record_t * rp,FILE * fp)327c478bd9Sstevel@tonic-gate err_short(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
337c478bd9Sstevel@tonic-gate {
347c478bd9Sstevel@tonic-gate 	char buf[32];
357c478bd9Sstevel@tonic-gate 
3647911a7dScy 	fmdump_printf(fp, "%-20s %-32s\n",
3747911a7dScy 	    fmdump_date(buf, sizeof (buf), rp), rp->rec_class);
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate 	return (0);
407c478bd9Sstevel@tonic-gate }
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /*ARGSUSED*/
437c478bd9Sstevel@tonic-gate static int
err_verb1(fmd_log_t * lp,const fmd_log_record_t * rp,FILE * fp)447c478bd9Sstevel@tonic-gate err_verb1(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
457c478bd9Sstevel@tonic-gate {
467c478bd9Sstevel@tonic-gate 	uint64_t ena = 0;
477c478bd9Sstevel@tonic-gate 	char buf[32];
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate 	(void) nvlist_lookup_uint64(rp->rec_nvl, FM_EREPORT_ENA, &ena);
507c478bd9Sstevel@tonic-gate 
5147911a7dScy 	fmdump_printf(fp, "%-20s %-37s 0x%016llx\n",
5247911a7dScy 	    fmdump_date(buf, sizeof (buf), rp), rp->rec_class, ena);
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate 	return (0);
557c478bd9Sstevel@tonic-gate }
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate /*ARGSUSED*/
587c478bd9Sstevel@tonic-gate static int
err_verb23_cmn(fmd_log_t * lp,const fmd_log_record_t * rp,FILE * fp,nvlist_prtctl_t pctl)59f6e214c7SGavin Maltby err_verb23_cmn(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp,
60f6e214c7SGavin Maltby     nvlist_prtctl_t pctl)
617c478bd9Sstevel@tonic-gate {
627c478bd9Sstevel@tonic-gate 	char buf[32];
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 	fmdump_printf(fp, "%-20s.%9.9llu %s\n",
657c478bd9Sstevel@tonic-gate 	    fmdump_year(buf, sizeof (buf), rp), rp->rec_nsec, rp->rec_class);
667c478bd9Sstevel@tonic-gate 
67f6e214c7SGavin Maltby 	if (pctl)
68f6e214c7SGavin Maltby 		nvlist_prt(rp->rec_nvl, pctl);
69f6e214c7SGavin Maltby 	else
70f6e214c7SGavin Maltby 		nvlist_print(fp, rp->rec_nvl);
71f6e214c7SGavin Maltby 
727c478bd9Sstevel@tonic-gate 	fmdump_printf(fp, "\n");
737c478bd9Sstevel@tonic-gate 	return (0);
747c478bd9Sstevel@tonic-gate }
757c478bd9Sstevel@tonic-gate 
76f6e214c7SGavin Maltby static int
err_verb2(fmd_log_t * lp,const fmd_log_record_t * rp,FILE * fp)77f6e214c7SGavin Maltby err_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
78f6e214c7SGavin Maltby {
79f6e214c7SGavin Maltby 	return (err_verb23_cmn(lp, rp, fp, NULL));
80f6e214c7SGavin Maltby }
81f6e214c7SGavin Maltby 
82f6e214c7SGavin Maltby static int
err_pretty(fmd_log_t * lp,const fmd_log_record_t * rp,FILE * fp)83f6e214c7SGavin Maltby err_pretty(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
84f6e214c7SGavin Maltby {
85f6e214c7SGavin Maltby 	nvlist_prtctl_t pctl;
86f6e214c7SGavin Maltby 	int rc;
87f6e214c7SGavin Maltby 
88f6e214c7SGavin Maltby 	if ((pctl = nvlist_prtctl_alloc()) != NULL) {
89f6e214c7SGavin Maltby 		nvlist_prtctl_setdest(pctl, fp);
90f6e214c7SGavin Maltby 		nvlist_prtctlop_nvlist(pctl, fmdump_render_nvlist, NULL);
91f6e214c7SGavin Maltby 	}
92f6e214c7SGavin Maltby 
93f6e214c7SGavin Maltby 	rc = err_verb23_cmn(lp, rp, fp, pctl);
94f6e214c7SGavin Maltby 
95f6e214c7SGavin Maltby 	nvlist_prtctl_free(pctl);
96f6e214c7SGavin Maltby 	return (rc);
97f6e214c7SGavin Maltby }
98f6e214c7SGavin Maltby 
997c478bd9Sstevel@tonic-gate const fmdump_ops_t fmdump_err_ops = {
1007c478bd9Sstevel@tonic-gate "error", {
1017c478bd9Sstevel@tonic-gate {
1027c478bd9Sstevel@tonic-gate "TIME                 CLASS",
1037c478bd9Sstevel@tonic-gate (fmd_log_rec_f *)err_short
1047c478bd9Sstevel@tonic-gate }, {
1057c478bd9Sstevel@tonic-gate "TIME                 CLASS                                 ENA",
1067c478bd9Sstevel@tonic-gate (fmd_log_rec_f *)err_verb1
1077c478bd9Sstevel@tonic-gate }, {
1087c478bd9Sstevel@tonic-gate "TIME                           CLASS",
1097c478bd9Sstevel@tonic-gate (fmd_log_rec_f *)err_verb2
110b6955755SRobert Johnston }, {
111f6e214c7SGavin Maltby "TIME                           CLASS",
112f6e214c7SGavin Maltby (fmd_log_rec_f *)err_pretty
113f6e214c7SGavin Maltby }, {
114b6955755SRobert Johnston NULL, NULL
115*2db6d663SJoshua M. Clulow }, {
116*2db6d663SJoshua M. Clulow NULL,
117*2db6d663SJoshua M. Clulow (fmd_log_rec_f *)fmdump_print_json
1187c478bd9Sstevel@tonic-gate } }
1197c478bd9Sstevel@tonic-gate };
120