2 * collectd - src/match_timediff.c
3 * Copyright (C) 2008,2009 Florian Forster
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Florian Forster <octo at collectd.org>
29 #include "utils_cache.h"
30 #include "filter_chain.h"
39 typedef struct mt_match_s mt_match_t;
47 * internal helper functions
49 static int mt_create (const oconfig_item_t *ci, void **user_data) /* {{{ */
55 m = calloc (1, sizeof (*m));
58 ERROR ("mt_create: calloc failed.");
66 for (i = 0; i < ci->children_num; i++)
68 oconfig_item_t *child = ci->children + i;
70 if (strcasecmp ("Future", child->key) == 0)
71 status = cf_util_get_cdtime (child, &m->future);
72 else if (strcasecmp ("Past", child->key) == 0)
73 status = cf_util_get_cdtime (child, &m->past);
76 ERROR ("timediff match: The `%s' configuration option is not "
77 "understood and will be ignored.", child->key);
85 /* Additional sanity-checking */
88 if ((m->future == 0) && (m->past == 0))
90 ERROR ("timediff match: Either `Future' or `Past' must be configured. "
91 "This match will be ignored.");
106 } /* }}} int mt_create */
108 static int mt_destroy (void **user_data) /* {{{ */
110 if (user_data != NULL)
116 } /* }}} int mt_destroy */
118 static int mt_match (const data_set_t __attribute__((unused)) *ds, /* {{{ */
119 const value_list_t *vl,
120 notification_meta_t __attribute__((unused)) **meta, void **user_data)
125 if ((user_data == NULL) || (*user_data == NULL))
133 if (vl->time >= (now + m->future))
134 return (FC_MATCH_MATCHES);
139 if (vl->time <= (now - m->past))
140 return (FC_MATCH_MATCHES);
143 return (FC_MATCH_NO_MATCH);
144 } /* }}} int mt_match */
146 void module_register (void)
150 memset (&mproc, 0, sizeof (mproc));
151 mproc.create = mt_create;
152 mproc.destroy = mt_destroy;
153 mproc.match = mt_match;
154 fc_register_match ("timediff", mproc);
155 } /* module_register */
157 /* vim: set sw=2 sts=2 tw=78 et fdm=marker : */