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