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  */
  24 
  25 #include <fmdump.h>
  26 #include <strings.h>
  27 #include <stdio.h>
  28 #include <time.h>
  29 
  30 /*ARGSUSED*/
  31 static int
  32 asru_short(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
  33 {
  34         char buf[32];
  35 
  36         fmdump_printf(fp, "%-20s %-32s\n",
  37             fmdump_date(buf, sizeof (buf), rp), rp->rec_class);
  38 
  39         return (0);
  40 }
  41 
  42 /*ARGSUSED*/
  43 static int
  44 asru_verb1(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
  45 {
  46         char *uuid = "-";
  47         boolean_t f = 0, u = 0;
  48         char buf[32], state[32];
  49 
  50         (void) nvlist_lookup_string(rp->rec_nvl, FM_RSRC_ASRU_UUID, &uuid);
  51         (void) nvlist_lookup_boolean_value(rp->rec_nvl,
  52             FM_RSRC_ASRU_FAULTY, &f);
  53         (void) nvlist_lookup_boolean_value(rp->rec_nvl,
  54             FM_RSRC_ASRU_UNUSABLE, &u);
  55 
  56         state[0] = '\0';
  57 
  58         if (f)
  59                 (void) strcat(state, ",faulty");
  60         if (u)
  61                 (void) strcat(state, ",unusable");
  62         if (!f && !u)
  63                 (void) strcat(state, ",ok");
  64 
  65         fmdump_printf(fp, "%-20s %-36s %s\n",
  66             fmdump_date(buf, sizeof (buf), rp), uuid, state + 1);
  67 
  68         return (0);
  69 }
  70 
  71 /*ARGSUSED*/
  72 static int
  73 asru_verb23_cmn(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp,
  74     nvlist_prtctl_t pctl)
  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         if (pctl)
  99                 nvlist_prt(rp->rec_nvl, pctl);
 100         else
 101                 nvlist_print(fp, rp->rec_nvl);
 102 
 103         fmdump_printf(fp, "\n");
 104 
 105         return (0);
 106 }
 107 
 108 static int
 109 asru_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
 110 {
 111         return (asru_verb23_cmn(lp, rp, fp, NULL));
 112 }
 113 
 114 static int
 115 asru_pretty(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
 116 {
 117         nvlist_prtctl_t pctl;
 118         int rc;
 119 
 120         if ((pctl = nvlist_prtctl_alloc()) != NULL) {
 121                 nvlist_prtctl_setdest(pctl, fp);
 122                 nvlist_prtctlop_nvlist(pctl, fmdump_render_nvlist, NULL);
 123         }
 124 
 125         rc = asru_verb23_cmn(lp, rp, fp, pctl);
 126 
 127         nvlist_prtctl_free(pctl);
 128         return (rc);
 129 }
 130 
 131 const fmdump_ops_t fmdump_asru_ops = {
 132 "asru", {
 133 {
 134 "TIME                 CLASS",
 135 (fmd_log_rec_f *)asru_short
 136 }, {
 137 "TIME                 UUID                                 STATE",
 138 (fmd_log_rec_f *)asru_verb1
 139 }, {
 140 "TIME                           UUID                                 STATE",
 141 (fmd_log_rec_f *)asru_verb2
 142 }, {
 143 "TIME                           UUID                                 STATE",
 144 (fmd_log_rec_f *)asru_pretty
 145 }, {
 146 NULL, NULL
 147 } }
 148 };