xref: /illumos-gate/usr/src/cmd/fm/fmdump/common/asru.c (revision edafac1f8203a7de1490688213c118b03215c89d)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
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_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
75 {
76 	char *uuid = "-";
77 	boolean_t f = 0, u = 0;
78 	char buf[32], state[32];
79 
80 	(void) nvlist_lookup_string(rp->rec_nvl, FM_RSRC_ASRU_UUID, &uuid);
81 	(void) nvlist_lookup_boolean_value(rp->rec_nvl,
82 	    FM_RSRC_ASRU_FAULTY, &f);
83 	(void) nvlist_lookup_boolean_value(rp->rec_nvl,
84 	    FM_RSRC_ASRU_UNUSABLE, &u);
85 
86 	state[0] = '\0';
87 
88 	if (f)
89 		(void) strcat(state, ",faulty");
90 	if (u)
91 		(void) strcat(state, ",unusable");
92 	if (!f && !u)
93 		(void) strcat(state, ",ok");
94 
95 	fmdump_printf(fp, "%-20s.%9.9llu %-36s %s\n",
96 	    fmdump_year(buf, sizeof (buf), rp), rp->rec_nsec, uuid, state + 1);
97 
98 	nvlist_print(fp, rp->rec_nvl);
99 	fmdump_printf(fp, "\n");
100 
101 	return (0);
102 }
103 
104 const fmdump_ops_t fmdump_asru_ops = {
105 "asru", {
106 {
107 "TIME                 CLASS",
108 (fmd_log_rec_f *)asru_short
109 }, {
110 "TIME                 UUID                                 STATE",
111 (fmd_log_rec_f *)asru_verb1
112 }, {
113 "TIME                           UUID                                 STATE",
114 (fmd_log_rec_f *)asru_verb2
115 }, {
116 NULL, NULL
117 } }
118 };
119