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/info.c
+++ new/usr/src/cmd/fm/fmdump/common/info.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) 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 <stdio.h>
27 28 #include <time.h>
28 29
29 30 /*ARGSUSED*/
30 31 static int
31 32 info_short(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
32 33 {
33 34 char buf[32];
34 35
35 36 fmdump_printf(fp, "%-20s %-32s\n",
36 37 fmdump_date(buf, sizeof (buf), rp), rp->rec_class);
37 38
38 39 return (0);
39 40 }
40 41
41 42 /*ARGSUSED*/
42 43 static int
43 44 info_verb1(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
44 45 {
45 46 char *uuid = "(absent)";
46 47 char buf[32];
47 48
48 49 (void) nvlist_lookup_string(rp->rec_nvl, FM_IREPORT_UUID, &uuid);
49 50
50 51 fmdump_printf(fp, "%-20s %-36s %s\n",
51 52 fmdump_date(buf, sizeof (buf), rp), uuid, rp->rec_class);
52 53
53 54 return (0);
54 55 }
55 56
56 57 /*ARGSUSED*/
57 58 static int
58 59 info_verb23_cmn(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp,
59 60 nvlist_prtctl_t pctl)
60 61 {
61 62 char buf[32];
62 63 char *uuid = "(absent)";
63 64
64 65 (void) nvlist_lookup_string(rp->rec_nvl, FM_IREPORT_UUID, &uuid);
65 66
66 67 fmdump_printf(fp, "%-20s.%9.9llu %s\n",
67 68 fmdump_year(buf, sizeof (buf), rp), rp->rec_nsec, uuid);
68 69
69 70 if (pctl)
70 71 nvlist_prt(rp->rec_nvl, pctl);
71 72 else
72 73 nvlist_print(fp, rp->rec_nvl);
73 74
74 75 fmdump_printf(fp, "\n");
75 76 return (0);
76 77 }
77 78
78 79 static int
79 80 info_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
80 81 {
81 82 return (info_verb23_cmn(lp, rp, fp, NULL));
82 83 }
83 84
84 85 static int
85 86 info_pretty(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
86 87 {
87 88 nvlist_prtctl_t pctl;
88 89 int rc;
89 90
90 91 if ((pctl = nvlist_prtctl_alloc()) != NULL) {
91 92 nvlist_prtctl_setdest(pctl, fp);
92 93 nvlist_prtctlop_nvlist(pctl, fmdump_render_nvlist, NULL);
93 94 }
94 95
95 96 rc = info_verb23_cmn(lp, rp, fp, pctl);
96 97
97 98 nvlist_prtctl_free(pctl);
98 99 return (rc);
99 100 }
100 101
101 102 const fmdump_ops_t fmdump_info_ops = {
102 103 "info", {
103 104 {
104 105 "TIME CLASS",
105 106 (fmd_log_rec_f *)info_short
106 107 }, {
↓ open down ↓ |
74 lines elided |
↑ open up ↑ |
107 108 "TIME UUID CLASS",
108 109 (fmd_log_rec_f *)info_verb1
109 110 }, {
110 111 "TIME UUID",
111 112 (fmd_log_rec_f *)info_verb2
112 113 }, {
113 114 "TIME UUID",
114 115 (fmd_log_rec_f *)info_pretty
115 116 }, {
116 117 NULL, NULL
118 +}, {
119 +NULL,
120 +(fmd_log_rec_f *)fmdump_print_json
117 121 } }
118 122 };
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX