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