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