1 /**
2 * collectd - src/utils_complain.h
3 * Copyright (C) 2006-2013 Florian octo Forster
4 * Copyright (C) 2008 Sebastian tokkee Harl
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
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.
23 *
24 * Authors:
25 * Florian octo Forster <octo at collectd.org>
26 * Sebastian tokkee Harl <sh at tokkee.org>
27 **/
29 #ifndef UTILS_COMPLAIN_H
30 #define UTILS_COMPLAIN_H 1
32 #include "utils_time.h"
34 typedef struct
35 {
36 /* time of the last report */
37 cdtime_t last;
39 /* How long to wait until reporting again.
40 * 0 indicates that the complaint is no longer valid. */
41 cdtime_t interval;
43 _Bool complained_once;
44 } c_complain_t;
46 #define C_COMPLAIN_INIT_STATIC { 0, 0, 0 }
47 #define C_COMPLAIN_INIT(c) do { \
48 (c)->last = 0; \
49 (c)->interval = 0; \
50 (c)->complained_once = 0; \
51 } while (0)
53 /*
54 * NAME
55 * c_complain
56 *
57 * DESCRIPTION
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.
63 *
64 * PARAMETERS
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).
68 */
69 void c_complain (int level, c_complain_t *c, const char *format, ...);
71 /*
72 * NAME
73 * c_complain_once
74 *
75 * DESCRIPTION
76 * Complain about something once. This function will not report anything
77 * again, unless `c_release' has been called in between. If used after some
78 * calls to `c_complain', it will report again on the next interval and stop
79 * after that.
80 *
81 * See `c_complain' for further details and a description of the parameters.
82 */
83 void c_complain_once (int level, c_complain_t *c, const char *format, ...);
85 /*
86 * NAME
87 * c_would_release
88 *
89 * DESCRIPTION
90 * Returns true if the specified complaint would be released, false else.
91 */
92 #define c_would_release(c) ((c)->interval != 0)
94 /*
95 * NAME
96 * c_release
97 *
98 * DESCRIPTION
99 * Release a complaint. This will report a message once, marking the
100 * complaint as released.
101 *
102 * See `c_complain' for a description of the parameters.
103 */
104 void c_do_release (int level, c_complain_t *c, const char *format, ...);
105 #define c_release(level, c, ...) \
106 do { \
107 if (c_would_release (c)) \
108 c_do_release(level, c, __VA_ARGS__); \
109 } while (0)
111 #endif /* UTILS_COMPLAIN_H */
113 /* vim: set sw=4 ts=4 tw=78 noexpandtab : */