2 * collectd - src/utils_complain.h
3 * Copyright (C) 2006-2013 Florian octo Forster
4 * Copyright (C) 2008 Sebastian tokkee Harl
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Florian octo Forster <octo at collectd.org>
26 * Sebastian tokkee Harl <sh at tokkee.org>
29 #ifndef UTILS_COMPLAIN_H
30 #define UTILS_COMPLAIN_H 1
32 #include "utils_time.h"
36 /* time of the last report */
39 /* How long to wait until reporting again.
40 * 0 indicates that the complaint is no longer valid. */
43 _Bool complained_once;
46 #define C_COMPLAIN_INIT_STATIC { 0, 0, 0 }
47 #define C_COMPLAIN_INIT(c) do { \
50 (c)->complained_once = 0; \
58 * Complain about something. This function will report a message (usually
59 * indicating some error condition) using the collectd logging mechanism.
60 * When this function is called again, reporting the message again will be
61 * deferred by an increasing interval (up to one day) to prevent flooding
62 * the logs. A call to `c_release' resets the counter.
65 * `level' The log level passed to `plugin_log'.
66 * `c' Identifier for the complaint.
67 * `format' Message format - see the documentation of printf(3).
69 __attribute__ ((format(printf,3,4)))
70 void c_complain (int level, c_complain_t *c, const char *format, ...);
77 * Complain about something once. This function will not report anything
78 * again, unless `c_release' has been called in between. If used after some
79 * calls to `c_complain', it will report again on the next interval and stop
82 * See `c_complain' for further details and a description of the parameters.
84 __attribute__ ((format(printf,3,4)))
85 void c_complain_once (int level, c_complain_t *c, const char *format, ...);
92 * Returns true if the specified complaint would be released, false else.
94 #define c_would_release(c) ((c)->interval != 0)
101 * Release a complaint. This will report a message once, marking the
102 * complaint as released.
104 * See `c_complain' for a description of the parameters.
106 __attribute__ ((format(printf,3,4)))
107 void c_do_release (int level, c_complain_t *c, const char *format, ...);
108 #define c_release(level, c, ...) \
110 if (c_would_release (c)) \
111 c_do_release(level, c, __VA_ARGS__); \
114 #endif /* UTILS_COMPLAIN_H */
116 /* vim: set sw=4 ts=4 tw=78 noexpandtab : */