xref: /titanic_41/usr/src/cmd/fm/fmdump/common/info.c (revision 87a73014661ab4249b38f8fe4f8bd31bedca93b6)
1f6e214c7SGavin Maltby /*
2f6e214c7SGavin Maltby  * CDDL HEADER START
3f6e214c7SGavin Maltby  *
4f6e214c7SGavin Maltby  * The contents of this file are subject to the terms of the
5f6e214c7SGavin Maltby  * Common Development and Distribution License (the "License").
6f6e214c7SGavin Maltby  * You may not use this file except in compliance with the License.
7f6e214c7SGavin Maltby  *
8f6e214c7SGavin Maltby  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9f6e214c7SGavin Maltby  * or http://www.opensolaris.org/os/licensing.
10f6e214c7SGavin Maltby  * See the License for the specific language governing permissions
11f6e214c7SGavin Maltby  * and limitations under the License.
12f6e214c7SGavin Maltby  *
13f6e214c7SGavin Maltby  * When distributing Covered Code, include this CDDL HEADER in each
14f6e214c7SGavin Maltby  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15f6e214c7SGavin Maltby  * If applicable, add the following below this CDDL HEADER, with the
16f6e214c7SGavin Maltby  * fields enclosed by brackets "[]" replaced with your own identifying
17f6e214c7SGavin Maltby  * information: Portions Copyright [yyyy] [name of copyright owner]
18f6e214c7SGavin Maltby  *
19f6e214c7SGavin Maltby  * CDDL HEADER END
20f6e214c7SGavin Maltby  */
21f6e214c7SGavin Maltby /*
22f6e214c7SGavin Maltby  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23*87a73014SJoshua M. Clulow  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
24f6e214c7SGavin Maltby  */
25f6e214c7SGavin Maltby 
26f6e214c7SGavin Maltby #include <fmdump.h>
27f6e214c7SGavin Maltby #include <stdio.h>
28f6e214c7SGavin Maltby #include <time.h>
29f6e214c7SGavin Maltby 
30f6e214c7SGavin Maltby /*ARGSUSED*/
31f6e214c7SGavin Maltby static int
info_short(fmd_log_t * lp,const fmd_log_record_t * rp,FILE * fp)32f6e214c7SGavin Maltby info_short(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
33f6e214c7SGavin Maltby {
34f6e214c7SGavin Maltby 	char buf[32];
35f6e214c7SGavin Maltby 
36f6e214c7SGavin Maltby 	fmdump_printf(fp, "%-20s %-32s\n",
37f6e214c7SGavin Maltby 	    fmdump_date(buf, sizeof (buf), rp), rp->rec_class);
38f6e214c7SGavin Maltby 
39f6e214c7SGavin Maltby 	return (0);
40f6e214c7SGavin Maltby }
41f6e214c7SGavin Maltby 
42f6e214c7SGavin Maltby /*ARGSUSED*/
43f6e214c7SGavin Maltby static int
info_verb1(fmd_log_t * lp,const fmd_log_record_t * rp,FILE * fp)44f6e214c7SGavin Maltby info_verb1(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
45f6e214c7SGavin Maltby {
46f6e214c7SGavin Maltby 	char *uuid = "(absent)";
47f6e214c7SGavin Maltby 	char buf[32];
48f6e214c7SGavin Maltby 
49f6e214c7SGavin Maltby 	(void) nvlist_lookup_string(rp->rec_nvl, FM_IREPORT_UUID, &uuid);
50f6e214c7SGavin Maltby 
51f6e214c7SGavin Maltby 	fmdump_printf(fp, "%-20s %-36s %s\n",
52f6e214c7SGavin Maltby 	    fmdump_date(buf, sizeof (buf), rp), uuid, rp->rec_class);
53f6e214c7SGavin Maltby 
54f6e214c7SGavin Maltby 	return (0);
55f6e214c7SGavin Maltby }
56f6e214c7SGavin Maltby 
57f6e214c7SGavin Maltby /*ARGSUSED*/
58f6e214c7SGavin Maltby static int
info_verb23_cmn(fmd_log_t * lp,const fmd_log_record_t * rp,FILE * fp,nvlist_prtctl_t pctl)59f6e214c7SGavin Maltby info_verb23_cmn(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp,
60f6e214c7SGavin Maltby     nvlist_prtctl_t pctl)
61f6e214c7SGavin Maltby {
62f6e214c7SGavin Maltby 	char buf[32];
63f6e214c7SGavin Maltby 	char *uuid = "(absent)";
64f6e214c7SGavin Maltby 
65f6e214c7SGavin Maltby 	(void) nvlist_lookup_string(rp->rec_nvl, FM_IREPORT_UUID, &uuid);
66f6e214c7SGavin Maltby 
67f6e214c7SGavin Maltby 	fmdump_printf(fp, "%-20s.%9.9llu %s\n",
68f6e214c7SGavin Maltby 	    fmdump_year(buf, sizeof (buf), rp), rp->rec_nsec, uuid);
69f6e214c7SGavin Maltby 
70f6e214c7SGavin Maltby 	if (pctl)
71f6e214c7SGavin Maltby 		nvlist_prt(rp->rec_nvl, pctl);
72f6e214c7SGavin Maltby 	else
73f6e214c7SGavin Maltby 		nvlist_print(fp, rp->rec_nvl);
74f6e214c7SGavin Maltby 
75f6e214c7SGavin Maltby 	fmdump_printf(fp, "\n");
76f6e214c7SGavin Maltby 	return (0);
77f6e214c7SGavin Maltby }
78f6e214c7SGavin Maltby 
79f6e214c7SGavin Maltby static int
info_verb2(fmd_log_t * lp,const fmd_log_record_t * rp,FILE * fp)80f6e214c7SGavin Maltby info_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
81f6e214c7SGavin Maltby {
82f6e214c7SGavin Maltby 	return (info_verb23_cmn(lp, rp, fp, NULL));
83f6e214c7SGavin Maltby }
84f6e214c7SGavin Maltby 
85f6e214c7SGavin Maltby static int
info_pretty(fmd_log_t * lp,const fmd_log_record_t * rp,FILE * fp)86f6e214c7SGavin Maltby info_pretty(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
87f6e214c7SGavin Maltby {
88f6e214c7SGavin Maltby 	nvlist_prtctl_t pctl;
89f6e214c7SGavin Maltby 	int rc;
90f6e214c7SGavin Maltby 
91f6e214c7SGavin Maltby 	if ((pctl = nvlist_prtctl_alloc()) != NULL) {
92f6e214c7SGavin Maltby 		nvlist_prtctl_setdest(pctl, fp);
93f6e214c7SGavin Maltby 		nvlist_prtctlop_nvlist(pctl, fmdump_render_nvlist, NULL);
94f6e214c7SGavin Maltby 	}
95f6e214c7SGavin Maltby 
96f6e214c7SGavin Maltby 	rc = info_verb23_cmn(lp, rp, fp, pctl);
97f6e214c7SGavin Maltby 
98f6e214c7SGavin Maltby 	nvlist_prtctl_free(pctl);
99f6e214c7SGavin Maltby 	return (rc);
100f6e214c7SGavin Maltby }
101f6e214c7SGavin Maltby 
102f6e214c7SGavin Maltby const fmdump_ops_t fmdump_info_ops = {
103f6e214c7SGavin Maltby "info", {
104f6e214c7SGavin Maltby {
105f6e214c7SGavin Maltby "TIME                 CLASS",
106f6e214c7SGavin Maltby (fmd_log_rec_f *)info_short
107f6e214c7SGavin Maltby }, {
108f6e214c7SGavin Maltby "TIME                 UUID                                 CLASS",
109f6e214c7SGavin Maltby (fmd_log_rec_f *)info_verb1
110f6e214c7SGavin Maltby }, {
111f6e214c7SGavin Maltby "TIME                           UUID",
112f6e214c7SGavin Maltby (fmd_log_rec_f *)info_verb2
113f6e214c7SGavin Maltby }, {
114f6e214c7SGavin Maltby "TIME                           UUID",
115f6e214c7SGavin Maltby (fmd_log_rec_f *)info_pretty
116f6e214c7SGavin Maltby }, {
117f6e214c7SGavin Maltby NULL, NULL
118*87a73014SJoshua M. Clulow }, {
119*87a73014SJoshua M. Clulow NULL,
120*87a73014SJoshua M. Clulow (fmd_log_rec_f *)fmdump_print_json
121f6e214c7SGavin Maltby } }
122f6e214c7SGavin Maltby };
123