diff options
Diffstat (limited to 'plugins/utils.h')
-rw-r--r-- | plugins/utils.h | 141 |
1 files changed, 73 insertions, 68 deletions
diff --git a/plugins/utils.h b/plugins/utils.h index 029ae5a6..92a6c115 100644 --- a/plugins/utils.h +++ b/plugins/utils.h | |||
@@ -21,43 +21,43 @@ suite of plugins. */ | |||
21 | 21 | ||
22 | #ifdef NP_EXTRA_OPTS | 22 | #ifdef NP_EXTRA_OPTS |
23 | /* Include extra-opts functions if compiled in */ | 23 | /* Include extra-opts functions if compiled in */ |
24 | #include "extra_opts.h" | 24 | # include "extra_opts.h" |
25 | #else | 25 | #else |
26 | /* else, fake np_extra_opts */ | 26 | /* else, fake np_extra_opts */ |
27 | #define np_extra_opts(acptr,av,pr) av | 27 | # define np_extra_opts(acptr, av, pr) av |
28 | #endif | 28 | #endif |
29 | 29 | ||
30 | /* Standardize version information, termination */ | 30 | /* Standardize version information, termination */ |
31 | 31 | ||
32 | void support (void); | 32 | void support(void); |
33 | void print_revision (const char *, const char *); | 33 | void print_revision(const char *, const char *); |
34 | 34 | ||
35 | extern time_t start_time, end_time; | 35 | extern time_t start_time, end_time; |
36 | 36 | ||
37 | /* Test input types */ | 37 | /* Test input types */ |
38 | 38 | ||
39 | bool is_integer (char *); | 39 | bool is_integer(char *); |
40 | bool is_intpos (char *); | 40 | bool is_intpos(char *); |
41 | bool is_intneg (char *); | 41 | bool is_intneg(char *); |
42 | bool is_intnonneg (char *); | 42 | bool is_intnonneg(char *); |
43 | bool is_intpercent (char *); | 43 | bool is_intpercent(char *); |
44 | bool is_uint64(char *number, uint64_t *target); | 44 | bool is_uint64(char *number, uint64_t *target); |
45 | bool is_int64(char *number, int64_t *target); | 45 | bool is_int64(char *number, int64_t *target); |
46 | 46 | ||
47 | bool is_numeric (char *); | 47 | bool is_numeric(char *); |
48 | bool is_positive (char *); | 48 | bool is_positive(char *); |
49 | bool is_negative (char *); | 49 | bool is_negative(char *); |
50 | bool is_nonnegative (char *); | 50 | bool is_nonnegative(char *); |
51 | bool is_percentage (char *); | 51 | bool is_percentage(char *); |
52 | bool is_percentage_expression (const char[]); | 52 | bool is_percentage_expression(const char[]); |
53 | 53 | ||
54 | bool is_option (char *); | 54 | bool is_option(char *); |
55 | 55 | ||
56 | /* Generalized timer that will do milliseconds if available */ | 56 | /* Generalized timer that will do milliseconds if available */ |
57 | #ifndef HAVE_STRUCT_TIMEVAL | 57 | #ifndef HAVE_STRUCT_TIMEVAL |
58 | struct timeval { | 58 | struct timeval { |
59 | long tv_sec; /* seconds */ | 59 | long tv_sec; /* seconds */ |
60 | long tv_usec; /* microseconds */ | 60 | long tv_usec; /* microseconds */ |
61 | }; | 61 | }; |
62 | #endif | 62 | #endif |
63 | 63 | ||
@@ -65,137 +65,142 @@ struct timeval { | |||
65 | int gettimeofday(struct timeval *, struct timezone *); | 65 | int gettimeofday(struct timeval *, struct timezone *); |
66 | #endif | 66 | #endif |
67 | 67 | ||
68 | double delta_time (struct timeval tv); | 68 | double delta_time(struct timeval tv); |
69 | long deltime (struct timeval tv); | 69 | long deltime(struct timeval tv); |
70 | 70 | ||
71 | /* Handle strings safely */ | 71 | /* Handle strings safely */ |
72 | 72 | ||
73 | void strip (char *); | 73 | void strip(char *); |
74 | char *strscpy (char *, const char *); | 74 | char *strscpy(char *, const char *); |
75 | char *strnl (char *); | 75 | char *strnl(char *); |
76 | char *strpcpy (char *, const char *, const char *); | 76 | char *strpcpy(char *, const char *, const char *); |
77 | char *strpcat (char *, const char *, const char *); | 77 | char *strpcat(char *, const char *, const char *); |
78 | int xvasprintf (char **strp, const char *fmt, va_list ap); | 78 | int xvasprintf(char **strp, const char *fmt, va_list ap); |
79 | int xasprintf (char **strp, const char *fmt, ...); | 79 | int xasprintf(char **strp, const char *fmt, ...); |
80 | 80 | ||
81 | void usage (const char *) __attribute__((noreturn)); | 81 | void usage(const char *) __attribute__((noreturn)); |
82 | void usage2(const char *, const char *) __attribute__((noreturn)); | 82 | void usage2(const char *, const char *) __attribute__((noreturn)); |
83 | void usage3(const char *, int) __attribute__((noreturn)); | 83 | void usage3(const char *, int) __attribute__((noreturn)); |
84 | void usage4(const char *) __attribute__((noreturn)); | 84 | void usage4(const char *) __attribute__((noreturn)); |
85 | void usage5(void) __attribute__((noreturn)); | 85 | void usage5(void) __attribute__((noreturn)); |
86 | void usage_va(const char *fmt, ...) __attribute__((noreturn)); | 86 | void usage_va(const char *fmt, ...) __attribute__((noreturn)); |
87 | 87 | ||
88 | #define max(a,b) (((a)>(b))?(a):(b)) | 88 | #define max(a, b) (((a) > (b)) ? (a) : (b)) |
89 | #define min(a,b) (((a)<(b))?(a):(b)) | 89 | #define min(a, b) (((a) < (b)) ? (a) : (b)) |
90 | 90 | ||
91 | char *perfdata (const char *, long int, const char *, int, long int, | 91 | char *perfdata(const char *, long int, const char *, bool, long int, bool, long int, bool, long int, bool, long int); |
92 | int, long int, int, long int, int, long int); | ||
93 | 92 | ||
94 | char *perfdata_uint64 (const char *, uint64_t , const char *, int, uint64_t, | 93 | char *perfdata_uint64(const char *, uint64_t, const char *, bool, uint64_t, bool, uint64_t, bool, uint64_t, bool, uint64_t); |
95 | int, uint64_t, int, uint64_t, int, uint64_t); | ||
96 | 94 | ||
97 | char *perfdata_int64 (const char *, int64_t, const char *, int, int64_t, | 95 | char *perfdata_int64(const char *, int64_t, const char *, bool, int64_t, bool, int64_t, bool, int64_t, bool, int64_t); |
98 | int, int64_t, int, int64_t, int, int64_t); | ||
99 | 96 | ||
100 | char *fperfdata (const char *, double, const char *, int, double, | 97 | char *fperfdata(const char *, double, const char *, bool, double, bool, double, bool, double, bool, double); |
101 | int, double, int, double, int, double); | ||
102 | 98 | ||
103 | char *sperfdata (const char *, double, const char *, char *, char *, | 99 | char *sperfdata(const char *, double, const char *, char *, char *, bool, double, bool, double); |
104 | int, double, int, double); | ||
105 | 100 | ||
106 | char *sperfdata_int (const char *, int, const char *, char *, char *, | 101 | char *sperfdata_int(const char *, int, const char *, char *, char *, bool, int, bool, int); |
107 | int, int, int, int); | ||
108 | 102 | ||
109 | /* The idea here is that, although not every plugin will use all of these, | 103 | /* The idea here is that, although not every plugin will use all of these, |
110 | most will or should. Therefore, for consistency, these very common | 104 | most will or should. Therefore, for consistency, these very common |
111 | options should have only these meanings throughout the overall suite */ | 105 | options should have only these meanings throughout the overall suite */ |
112 | 106 | ||
113 | #define STD_LONG_OPTS \ | 107 | #define STD_LONG_OPTS \ |
114 | {"version",no_argument,0,'V'},\ | 108 | {"version", no_argument, 0, 'V'}, {"verbose", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, \ |
115 | {"verbose",no_argument,0,'v'},\ | 109 | {"timeout", required_argument, 0, 't'}, {"critical", required_argument, 0, 'c'}, {"warning", required_argument, 0, 'w'}, \ |
116 | {"help",no_argument,0,'h'},\ | 110 | {"hostname", required_argument, 0, 'H'} |
117 | {"timeout",required_argument,0,'t'},\ | ||
118 | {"critical",required_argument,0,'c'},\ | ||
119 | {"warning",required_argument,0,'w'},\ | ||
120 | {"hostname",required_argument,0,'H'} | ||
121 | 111 | ||
122 | #define COPYRIGHT "Copyright (c) %s Monitoring Plugins Development Team\n\ | 112 | #define COPYRIGHT \ |
113 | "Copyright (c) %s Monitoring Plugins Development Team\n\ | ||
123 | \t<%s>\n\n" | 114 | \t<%s>\n\n" |
124 | 115 | ||
125 | #define UT_HLP_VRS _("\ | 116 | #define UT_HLP_VRS \ |
117 | _("\ | ||
126 | %s (-h | --help) for detailed help\n\ | 118 | %s (-h | --help) for detailed help\n\ |
127 | %s (-V | --version) for version information\n") | 119 | %s (-V | --version) for version information\n") |
128 | 120 | ||
129 | #define UT_HELP_VRSN _("\ | 121 | #define UT_HELP_VRSN \ |
122 | _("\ | ||
130 | \nOptions:\n\ | 123 | \nOptions:\n\ |
131 | -h, --help\n\ | 124 | -h, --help\n\ |
132 | Print detailed help screen\n\ | 125 | Print detailed help screen\n\ |
133 | -V, --version\n\ | 126 | -V, --version\n\ |
134 | Print version information\n") | 127 | Print version information\n") |
135 | 128 | ||
136 | #define UT_HOST_PORT _("\ | 129 | #define UT_HOST_PORT \ |
130 | _("\ | ||
137 | -H, --hostname=ADDRESS\n\ | 131 | -H, --hostname=ADDRESS\n\ |
138 | Host name, IP Address, or unix socket (must be an absolute path)\n\ | 132 | Host name, IP Address, or unix socket (must be an absolute path)\n\ |
139 | -%c, --port=INTEGER\n\ | 133 | -%c, --port=INTEGER\n\ |
140 | Port number (default: %s)\n") | 134 | Port number (default: %s)\n") |
141 | 135 | ||
142 | #define UT_IPv46 _("\ | 136 | #define UT_IPv46 \ |
137 | _("\ | ||
143 | -4, --use-ipv4\n\ | 138 | -4, --use-ipv4\n\ |
144 | Use IPv4 connection\n\ | 139 | Use IPv4 connection\n\ |
145 | -6, --use-ipv6\n\ | 140 | -6, --use-ipv6\n\ |
146 | Use IPv6 connection\n") | 141 | Use IPv6 connection\n") |
147 | 142 | ||
148 | #define UT_VERBOSE _("\ | 143 | #define UT_VERBOSE \ |
144 | _("\ | ||
149 | -v, --verbose\n\ | 145 | -v, --verbose\n\ |
150 | Show details for command-line debugging (output may be truncated by\n\ | 146 | Show details for command-line debugging (output may be truncated by\n\ |
151 | the monitoring system)\n") | 147 | the monitoring system)\n") |
152 | 148 | ||
153 | #define UT_WARN_CRIT _("\ | 149 | #define UT_WARN_CRIT \ |
150 | _("\ | ||
154 | -w, --warning=DOUBLE\n\ | 151 | -w, --warning=DOUBLE\n\ |
155 | Response time to result in warning status (seconds)\n\ | 152 | Response time to result in warning status (seconds)\n\ |
156 | -c, --critical=DOUBLE\n\ | 153 | -c, --critical=DOUBLE\n\ |
157 | Response time to result in critical status (seconds)\n") | 154 | Response time to result in critical status (seconds)\n") |
158 | 155 | ||
159 | #define UT_WARN_CRIT_RANGE _("\ | 156 | #define UT_WARN_CRIT_RANGE \ |
157 | _("\ | ||
160 | -w, --warning=RANGE\n\ | 158 | -w, --warning=RANGE\n\ |
161 | Warning range (format: start:end). Alert if outside this range\n\ | 159 | Warning range (format: start:end). Alert if outside this range\n\ |
162 | -c, --critical=RANGE\n\ | 160 | -c, --critical=RANGE\n\ |
163 | Critical range\n") | 161 | Critical range\n") |
164 | 162 | ||
165 | #define UT_CONN_TIMEOUT _("\ | 163 | #define UT_CONN_TIMEOUT \ |
164 | _("\ | ||
166 | -t, --timeout=INTEGER\n\ | 165 | -t, --timeout=INTEGER\n\ |
167 | Seconds before connection times out (default: %d)\n") | 166 | Seconds before connection times out (default: %d)\n") |
168 | 167 | ||
169 | #define UT_PLUG_TIMEOUT _("\ | 168 | #define UT_PLUG_TIMEOUT \ |
169 | _("\ | ||
170 | -t, --timeout=INTEGER\n\ | 170 | -t, --timeout=INTEGER\n\ |
171 | Seconds before plugin times out (default: %d)\n") | 171 | Seconds before plugin times out (default: %d)\n") |
172 | 172 | ||
173 | #ifdef NP_EXTRA_OPTS | 173 | #ifdef NP_EXTRA_OPTS |
174 | #define UT_EXTRA_OPTS _("\ | 174 | # define UT_EXTRA_OPTS \ |
175 | _("\ | ||
175 | --extra-opts=[section][@file]\n\ | 176 | --extra-opts=[section][@file]\n\ |
176 | Read options from an ini file. See\n\ | 177 | Read options from an ini file. See\n\ |
177 | https://www.monitoring-plugins.org/doc/extra-opts.html\n\ | 178 | https://www.monitoring-plugins.org/doc/extra-opts.html\n\ |
178 | for usage and examples.\n") | 179 | for usage and examples.\n") |
179 | #else | 180 | #else |
180 | #define UT_EXTRA_OPTS " \b" | 181 | # define UT_EXTRA_OPTS " \b" |
181 | #endif | 182 | #endif |
182 | 183 | ||
183 | #define UT_THRESHOLDS_NOTES _("\ | 184 | #define UT_THRESHOLDS_NOTES \ |
185 | _("\ | ||
184 | See:\n\ | 186 | See:\n\ |
185 | https://www.monitoring-plugins.org/doc/guidelines.html#THRESHOLDFORMAT\n\ | 187 | https://www.monitoring-plugins.org/doc/guidelines.html#THRESHOLDFORMAT\n\ |
186 | for THRESHOLD format and examples.\n") | 188 | for THRESHOLD format and examples.\n") |
187 | 189 | ||
188 | #define UT_SUPPORT _("\n\ | 190 | #define UT_SUPPORT \ |
191 | _("\n\ | ||
189 | Send email to help@monitoring-plugins.org if you have questions regarding\n\ | 192 | Send email to help@monitoring-plugins.org if you have questions regarding\n\ |
190 | use of this software. To submit patches or suggest improvements, send email\n\ | 193 | use of this software. To submit patches or suggest improvements, send email\n\ |
191 | to devel@monitoring-plugins.org\n\n") | 194 | to devel@monitoring-plugins.org\n\n") |
192 | 195 | ||
193 | #define UT_NOWARRANTY _("\n\ | 196 | #define UT_NOWARRANTY \ |
197 | _("\n\ | ||
194 | The Monitoring Plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\n\ | 198 | The Monitoring Plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\n\ |
195 | copies of the plugins under the terms of the GNU General Public License.\n\ | 199 | copies of the plugins under the terms of the GNU General Public License.\n\ |
196 | For more information about these matters, see the file named COPYING.\n") | 200 | For more information about these matters, see the file named COPYING.\n") |
197 | 201 | ||
198 | #define UT_OUTPUT_FORMAT _("\ | 202 | #define UT_OUTPUT_FORMAT \ |
203 | _("\ | ||
199 | --output-format=OUTPUT_FORMAT\n\ | 204 | --output-format=OUTPUT_FORMAT\n\ |
200 | Select output format. Valid values: \"multi-line\", \"mp-test-json\"\n") | 205 | Select output format. Valid values: \"multi-line\", \"mp-test-json\"\n") |
201 | 206 | ||