1 0 stevel /* 2 0 stevel * CDDL HEADER START 3 0 stevel * 4 0 stevel * The contents of this file are subject to the terms of the 5 6640 cth * Common Development and Distribution License (the "License"). 6 6640 cth * You may not use this file except in compliance with the License. 7 0 stevel * 8 0 stevel * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 0 stevel * or http://www.opensolaris.org/os/licensing. 10 0 stevel * See the License for the specific language governing permissions 11 0 stevel * and limitations under the License. 12 0 stevel * 13 0 stevel * When distributing Covered Code, include this CDDL HEADER in each 14 0 stevel * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 0 stevel * If applicable, add the following below this CDDL HEADER, with the 16 0 stevel * fields enclosed by brackets "[]" replaced with your own identifying 17 0 stevel * information: Portions Copyright [yyyy] [name of copyright owner] 18 0 stevel * 19 0 stevel * CDDL HEADER END 20 0 stevel */ 21 0 stevel /* 22 6640 cth * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 0 stevel * Use is subject to license terms. 24 0 stevel */ 25 0 stevel 26 0 stevel #include <sys/fm/protocol.h> 27 0 stevel 28 0 stevel #include <strings.h> 29 0 stevel #include <libgen.h> 30 6640 cth #include <regex.h> 31 6640 cth #include <libnvpair.h> 32 0 stevel 33 0 stevel #include <fmd_log_impl.h> 34 0 stevel #include <fmd_log.h> 35 0 stevel 36 0 stevel /*ARGSUSED*/ 37 0 stevel int 38 0 stevel fmd_log_filter_class(fmd_log_t *lp, const fmd_log_record_t *rp, void *arg) 39 0 stevel { 40 8074 Sean nvlist_t **nva; 41 8074 Sean uint32_t i, size; 42 8074 Sean char *class; 43 8074 Sean 44 8074 Sean if (gmatch(rp->rec_class, arg)) 45 8074 Sean return (1); 46 8074 Sean 47 8074 Sean /* return false if the record doesn't contain valid fault list */ 48 8074 Sean if (! gmatch(rp->rec_class, FM_LIST_EVENT ".*") || 49 8074 Sean nvlist_lookup_uint32(rp->rec_nvl, FM_SUSPECT_FAULT_SZ, 50 8074 Sean &size) != 0 || size == 0 || 51 8074 Sean nvlist_lookup_nvlist_array(rp->rec_nvl, FM_SUSPECT_FAULT_LIST, 52 8074 Sean &nva, &size) != 0) 53 8074 Sean return (0); 54 8074 Sean 55 8074 Sean /* return true if any fault in the list matches */ 56 8074 Sean for (i = 0; i < size; i++) { 57 8074 Sean if (nvlist_lookup_string(nva[i], FM_CLASS, &class) == 0 && 58 8074 Sean gmatch(class, arg)) 59 8074 Sean return (1); 60 8074 Sean } 61 8074 Sean 62 8074 Sean return (0); 63 0 stevel } 64 0 stevel 65 0 stevel /*ARGSUSED*/ 66 0 stevel int 67 0 stevel fmd_log_filter_uuid(fmd_log_t *lp, const fmd_log_record_t *rp, void *arg) 68 0 stevel { 69 0 stevel char *uuid; 70 0 stevel 71 0 stevel /* 72 0 stevel * Note: the uuid filter matches *any* member whose name is 'uuid'. 73 0 stevel * This permits us to match not only a list.suspect uuid but any 74 0 stevel * other event that decides to embed uuids, too, using the same name. 75 0 stevel */ 76 0 stevel return (nvlist_lookup_string(rp->rec_nvl, 77 0 stevel "uuid", &uuid) == 0 && strcmp(uuid, arg) == 0); 78 0 stevel } 79 0 stevel 80 0 stevel /*ARGSUSED*/ 81 0 stevel int 82 0 stevel fmd_log_filter_before(fmd_log_t *lp, const fmd_log_record_t *rp, void *arg) 83 0 stevel { 84 0 stevel uint64_t sec = ((struct timeval *)arg)->tv_sec; 85 0 stevel uint64_t nsec = ((struct timeval *)arg)->tv_usec * (NANOSEC / MICROSEC); 86 0 stevel return (rp->rec_sec == sec ? rp->rec_nsec <= nsec : rp->rec_sec <= sec); 87 0 stevel } 88 0 stevel 89 0 stevel /*ARGSUSED*/ 90 0 stevel int 91 0 stevel fmd_log_filter_after(fmd_log_t *lp, const fmd_log_record_t *rp, void *arg) 92 0 stevel { 93 0 stevel uint64_t sec = ((struct timeval *)arg)->tv_sec; 94 0 stevel uint64_t nsec = ((struct timeval *)arg)->tv_usec * (NANOSEC / MICROSEC); 95 0 stevel return (rp->rec_sec == sec ? rp->rec_nsec >= nsec : rp->rec_sec >= sec); 96 0 stevel } 97 6640 cth 98 6640 cth /*ARGSUSED*/ 99 6640 cth int 100 6640 cth fmd_log_filter_nv(fmd_log_t *lp, const fmd_log_record_t *rp, void *arg) 101 6640 cth { 102 6640 cth fmd_log_filter_nvarg_t *argt = (fmd_log_filter_nvarg_t *)arg; 103 6640 cth char *name = argt->nvarg_name; 104 6640 cth char *value = argt->nvarg_value; 105 6640 cth regex_t *value_regex = argt->nvarg_value_regex; 106 6640 cth nvpair_t *nvp; 107 6640 cth int ai; 108 6640 cth 109 6640 cth /* see if nvlist has named member */ 110 6640 cth if (nvlist_lookup_nvpair_embedded_index(rp->rec_nvl, name, 111 6640 cth &nvp, &ai, NULL) != 0) 112 6640 cth return (0); /* name filter failure */ 113 6640 cth 114 6640 cth /* check value match for matching nvpair */ 115 6640 cth if ((value == NULL) || 116 6640 cth (nvpair_value_match_regex(nvp, ai, value, value_regex, NULL) == 1)) 117 6640 cth return (1); /* name/value filter pass */ 118 6640 cth 119 6640 cth return (0); /* value filter failure */ 120 6640 cth } 121