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"
35 /* time of the last report */
38 /* How long to wait until reporting again.
39 * 0 indicates that the complaint is no longer valid. */
42 _Bool complained_once;
45 #define C_COMPLAIN_INIT_STATIC \
47 #define C_COMPLAIN_INIT(c) \
51 (c)->complained_once = 0; \
59 * Complain about something. This function will report a message (usually
60 * indicating some error condition) using the collectd logging mechanism.
61 * When this function is called again, reporting the message again will be
62 * deferred by an increasing interval (up to one day) to prevent flooding
63 * the logs. A call to `c_release' resets the counter.
66 * `level' The log level passed to `plugin_log'.
67 * `c' Identifier for the complaint.
68 * `format' Message format - see the documentation of printf(3).
70 __attribute__((format(printf, 3, 4))) void
71 c_complain(int level, c_complain_t *c, const char *format, ...);
78 * Complain about something once. This function will not report anything
79 * again, unless `c_release' has been called in between. If used after some
80 * calls to `c_complain', it will report again on the next interval and stop
83 * See `c_complain' for further details and a description of the parameters.
85 __attribute__((format(printf, 3, 4))) void
86 c_complain_once(int level, c_complain_t *c, const char *format, ...);
93 * Returns true if the specified complaint would be released, false else.
95 #define c_would_release(c) ((c)->interval != 0)
102 * Release a complaint. This will report a message once, marking the
103 * complaint as released.
105 * See `c_complain' for a description of the parameters.
107 __attribute__((format(printf, 3, 4))) void
108 c_do_release(int level, c_complain_t *c, const char *format, ...);
109 #define c_release(level, c, ...) \
111 if (c_would_release(c)) \
112 c_do_release(level, c, __VA_ARGS__); \
115 #endif /* UTILS_COMPLAIN_H */