2 * collectd - src/match_empty_counter.c
3 * Copyright (C) 2009 Florian Forster
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Florian Forster <octo at verplant.org>
24 #include "utils_cache.h"
25 #include "filter_chain.h"
31 typedef struct mec_match_s mec_match_t;
38 * internal helper functions
40 static int mec_create (const oconfig_item_t *ci, void **user_data) /* {{{ */
44 m = (mec_match_t *) malloc (sizeof (*m));
47 ERROR ("mec_create: malloc failed.");
50 memset (m, 0, sizeof (*m));
52 if (ci->children_num != 0)
54 ERROR ("empty_counter match: This match does not take any additional "
60 } /* }}} int mec_create */
62 static int mec_destroy (void **user_data) /* {{{ */
64 if (user_data != NULL)
70 } /* }}} int mec_destroy */
72 static int mec_match (const data_set_t __attribute__((unused)) *ds, /* {{{ */
73 const value_list_t *vl,
74 notification_meta_t __attribute__((unused)) **meta, void **user_data)
81 if ((user_data == NULL) || (*user_data == NULL))
89 for (i = 0; i < ds->ds_num; i++)
91 if (ds->ds[i].type != DS_TYPE_COUNTER)
95 if (vl->values[i].counter == 0)
99 if (num_counters == 0)
100 return (FC_MATCH_NO_MATCH);
101 else if (num_counters == num_empty)
102 return (FC_MATCH_MATCHES);
104 return (FC_MATCH_NO_MATCH);
105 } /* }}} int mec_match */
107 void module_register (void)
111 memset (&mproc, 0, sizeof (mproc));
112 mproc.create = mec_create;
113 mproc.destroy = mec_destroy;
114 mproc.match = mec_match;
115 fc_register_match ("empty_counter", mproc);
116 } /* module_register */
118 /* vim: set sw=2 sts=2 tw=78 et fdm=marker : */