xref: /illumos-gate/usr/src/cmd/fm/fmdump/common/asru.c (revision b31b5de1357c915fe7dab4d9646d9d84f9fe69bc)
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 static int
73 asru_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
74 {
75 	(void) asru_verb1(lp, rp, fp);
76 
77 	nvlist_print(fp, rp->rec_nvl);
78 	fmdump_printf(fp, "\n");
79 
80 	return (0);
81 }
82 
83 const fmdump_ops_t fmdump_asru_ops = {
84 "asru", {
85 {
86 "TIME                 CLASS",
87 (fmd_log_rec_f *)asru_short
88 }, {
89 "TIME                 UUID                                 STATE",
90 (fmd_log_rec_f *)asru_verb1
91 }, {
92 "TIME                 UUID                                 STATE",
93 (fmd_log_rec_f *)asru_verb2
94 }, {
95 NULL, NULL
96 } }
97 };
98