Update extended check_http tests for 0d78171...
[monitoring-plugins.git] / plugins / utils.h
blob65e06ebd3793c567add534f5a61885c8090f2ec2
1 #ifndef NP_UTILS_H
2 #define NP_UTILS_H
3 /* Header file for nagios plugins utils.c */
5 /* This file should be included in all plugins */
7 /* The purpose of this package is to provide safer alternatives to C
8 functions that might otherwise be vulnerable to hacking. This
9 currently includes a standard suite of validation routines to be sure
10 that an string argument acually converts to its intended type and a
11 suite of string handling routine that do their own memory management
12 in order to resist overflow attacks. In addition, a few functions are
13 provided to standardize version and error reporting across the entire
14 suite of plugins. */
16 /* now some functions etc are being defined in ../lib/utils_base.c */
17 #include "utils_base.h"
19 #ifdef NP_EXTRA_OPTS
20 /* Include extra-opts functions if compiled in */
21 #include "extra_opts.h"
22 #else
23 /* else, fake np_extra_opts */
24 #define np_extra_opts(acptr,av,pr) av
25 #endif
27 /* Standardize version information, termination */
29 void support (void);
30 void print_revision (const char *, const char *);
32 /* Handle timeouts */
34 #ifdef LOCAL_TIMEOUT_ALARM_HANDLER
35 extern unsigned int timeout_interval;
36 RETSIGTYPE timeout_alarm_handler (int);
37 #else
38 unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT;
39 extern RETSIGTYPE timeout_alarm_handler (int);
40 #endif
42 time_t start_time, end_time;
44 /* Test input types */
46 int is_integer (char *);
47 int is_intpos (char *);
48 int is_intneg (char *);
49 int is_intnonneg (char *);
50 int is_intpercent (char *);
52 int is_numeric (char *);
53 int is_positive (char *);
54 int is_negative (char *);
55 int is_nonnegative (char *);
56 int is_percentage (char *);
58 int is_option (char *);
60 /* Generalized timer that will do milliseconds if available */
61 #ifndef HAVE_STRUCT_TIMEVAL
62 struct timeval {
63 long tv_sec; /* seconds */
64 long tv_usec; /* microseconds */
66 #endif
68 #ifndef HAVE_GETTIMEOFDAY
69 int gettimeofday(struct timeval *, struct timezone *);
70 #endif
72 double delta_time (struct timeval tv);
73 long deltime (struct timeval tv);
75 /* Handle strings safely */
77 void strip (char *);
78 char *strscpy (char *, const char *);
79 char *strnl (char *);
80 char *strpcpy (char *, const char *, const char *);
81 char *strpcat (char *, const char *, const char *);
83 int max_state (int a, int b);
84 int max_state_alt (int a, int b);
86 void usage (const char *) __attribute__((noreturn));
87 void usage2(const char *, const char *) __attribute__((noreturn));
88 void usage3(const char *, int) __attribute__((noreturn));
89 void usage4(const char *) __attribute__((noreturn));
90 void usage5(void) __attribute__((noreturn));
91 void usage_va(const char *fmt, ...) __attribute__((noreturn));
93 const char *state_text (int);
95 #define max(a,b) (((a)>(b))?(a):(b))
96 #define min(a,b) (((a)<(b))?(a):(b))
98 char *perfdata (const char *,
99 long int,
100 const char *,
101 int,
102 long int,
103 int,
104 long int,
105 int,
106 long int,
107 int,
108 long int);
110 char *fperfdata (const char *,
111 double,
112 const char *,
113 int,
114 double,
115 int,
116 double,
117 int,
118 double,
119 int,
120 double);
122 /* The idea here is that, although not every plugin will use all of these,
123 most will or should. Therefore, for consistency, these very common
124 options should have only these meanings throughout the overall suite */
126 #define STD_LONG_OPTS \
127 {"version",no_argument,0,'V'},\
128 {"verbose",no_argument,0,'v'},\
129 {"help",no_argument,0,'h'},\
130 {"timeout",required_argument,0,'t'},\
131 {"critical",required_argument,0,'c'},\
132 {"warning",required_argument,0,'w'},\
133 {"hostname",required_argument,0,'H'}
135 #define COPYRIGHT "Copyright (c) %s Nagios Plugin Development Team\n\
136 \t<%s>\n\n"
138 #define UT_HLP_VRS "\
139 %s (-h | --help) for detailed help\n\
140 %s (-V | --version) for version information\n"
142 #define UT_HELP_VRSN "\
143 \nOptions:\n\
144 -h, --help\n\
145 Print detailed help screen\n\
146 -V, --version\n\
147 Print version information\n"
149 #define UT_HOST_PORT "\
150 -H, --hostname=ADDRESS\n\
151 Host name, IP Address, or unix socket (must be an absolute path)\n\
152 -%c, --port=INTEGER\n\
153 Port number (default: %s)\n"
155 #define UT_IPv46 "\
156 -4, --use-ipv4\n\
157 Use IPv4 connection\n\
158 -6, --use-ipv6\n\
159 Use IPv6 connection\n"
161 #define UT_VERBOSE "\
162 -v, --verbose\n\
163 Show details for command-line debugging (Nagios may truncate output)\n"
165 #define UT_WARN_CRIT "\
166 -w, --warning=DOUBLE\n\
167 Response time to result in warning status (seconds)\n\
168 -c, --critical=DOUBLE\n\
169 Response time to result in critical status (seconds)\n"
171 #define UT_WARN_CRIT_RANGE "\
172 -w, --warning=RANGE\n\
173 Warning range (format: start:end). Alert if outside this range\n\
174 -c, --critical=RANGE\n\
175 Critical range\n"
177 #define UT_TIMEOUT "\
178 -t, --timeout=INTEGER\n\
179 Seconds before connection times out (default: %d)\n"
181 #ifdef NP_EXTRA_OPTS
182 #define UT_EXTRA_OPTS "\
183 --extra-opts=[section][@file]\n\
184 Read additionnal options from ini file\n"
185 #define UT_EXTRA_OPTS_NOTES "\
186 See: http://nagiosplugins.org/extra-opts for --extra-opts usage and examples.\n"
187 #else
188 #define UT_EXTRA_OPTS ""
189 #define UT_EXTRA_OPTS_NOTES ""
190 #endif
192 #define UT_THRESHOLDS_NOTES "\
193 See:\n\
194 http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT\n\
195 for THRESHOLD format and examples.\n"
197 #define UT_SUPPORT "\n\
198 Send email to nagios-users@lists.sourceforge.net if you have questions\n\
199 regarding use of this software. To submit patches or suggest improvements,\n\
200 send email to nagiosplug-devel@lists.sourceforge.net\n\n"
202 #define UT_NOWARRANTY "\n\
203 The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\n\
204 copies of the plugins under the terms of the GNU General Public License.\n\
205 For more information about these matters, see the file named COPYING.\n"
207 #endif /* NP_UTILS_H */