Print this page
OS-1840 fmdump shall emit JSON (copyright fixes)
OS-1840 fmdump shall emit JSON (use library)


   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) 2010, Oracle and/or its affiliates. All rights reserved.

  23  */
  24 
  25 /*
  26  * Rendering functions for nvlist_prt that are of use to all types
  27  * of log.
  28  */
  29 
  30 #include <fmdump.h>
  31 #include <stdio.h>
  32 #include <strings.h>
  33 
  34 extern topo_hdl_t *fmd_fmri_topo_hold(int);
  35 
  36 /*
  37  * Can be appointed to be called for dumping all nvlist members of
  38  * an nvlist we ask to print with nvlist_prt.  Return 0 if the
  39  * nvlist is not recognized as an fmri, and default formatting
  40  * will be applied; otherwise format as an fmri string and return 1.
  41  */
  42 


  54         if (nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &class) != 0 ||
  55             nvlist_lookup_uint8(fmri, FM_VERSION, &version) != 0)
  56                 return (0);
  57 
  58         /*
  59          * Instead of hardcoding known FMRI classes here we'll try
  60          * topo_fmri_nvl2str which should fail gracefully for invalid
  61          * schemes (ie an nvlist that just happens to have the expected
  62          * class and version members but that isn't an FMRI).
  63          */
  64         if (topo_fmri_nvl2str(thp, fmri, &fmristr, &err) != 0 ||
  65             fmristr == NULL)
  66                 return (0);
  67 
  68         nvlist_prtctl_doindent(pctl, 1);
  69         nvlist_prtctl_dofmt(pctl, NVLIST_FMT_MEMBER_NAME, name);
  70         (void) fprintf(fp, "%s", fmristr);
  71         topo_hdl_strfree(thp, fmristr);
  72 
  73         return (1);













  74 }


   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) 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
  24  */
  25 
  26 /*
  27  * Rendering functions for nvlist_prt that are of use to all types
  28  * of log.
  29  */
  30 
  31 #include <fmdump.h>
  32 #include <stdio.h>
  33 #include <strings.h>
  34 
  35 extern topo_hdl_t *fmd_fmri_topo_hold(int);
  36 
  37 /*
  38  * Can be appointed to be called for dumping all nvlist members of
  39  * an nvlist we ask to print with nvlist_prt.  Return 0 if the
  40  * nvlist is not recognized as an fmri, and default formatting
  41  * will be applied; otherwise format as an fmri string and return 1.
  42  */
  43 


  55         if (nvlist_lookup_string(fmri, FM_FMRI_SCHEME, &class) != 0 ||
  56             nvlist_lookup_uint8(fmri, FM_VERSION, &version) != 0)
  57                 return (0);
  58 
  59         /*
  60          * Instead of hardcoding known FMRI classes here we'll try
  61          * topo_fmri_nvl2str which should fail gracefully for invalid
  62          * schemes (ie an nvlist that just happens to have the expected
  63          * class and version members but that isn't an FMRI).
  64          */
  65         if (topo_fmri_nvl2str(thp, fmri, &fmristr, &err) != 0 ||
  66             fmristr == NULL)
  67                 return (0);
  68 
  69         nvlist_prtctl_doindent(pctl, 1);
  70         nvlist_prtctl_dofmt(pctl, NVLIST_FMT_MEMBER_NAME, name);
  71         (void) fprintf(fp, "%s", fmristr);
  72         topo_hdl_strfree(thp, fmristr);
  73 
  74         return (1);
  75 }
  76 
  77 /*
  78  * Thin wrapper around libnvpair's inbuilt JSON routine.  Simply dumps the
  79  * entire log record nvlist without any reformatting.
  80  */
  81 int
  82 fmdump_print_json(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
  83 {
  84         nvlist_print_json(fp, rp->rec_nvl);
  85         fprintf(fp, "\n");
  86 
  87         return (0);
  88 }