check_by_ssh: fix child process leak on timeouts
[monitoring-plugins.git] / plugins / utils.h
blob6aa316fe5851435b5c1a8450338e0fb23f6c840e
1 #ifndef NP_UTILS_H
2 #define NP_UTILS_H
3 /* Header file for Monitoring 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 extern time_t start_time, end_time;
34 /* Test input types */
36 int is_integer (char *);
37 int is_intpos (char *);
38 int is_intneg (char *);
39 int is_intnonneg (char *);
40 int is_intpercent (char *);
42 int is_numeric (char *);
43 int is_positive (char *);
44 int is_negative (char *);
45 int is_nonnegative (char *);
46 int is_percentage (char *);
48 int is_option (char *);
50 /* Generalized timer that will do milliseconds if available */
51 #ifndef HAVE_STRUCT_TIMEVAL
52 struct timeval {
53 long tv_sec; /* seconds */
54 long tv_usec; /* microseconds */
56 #endif
58 #ifndef HAVE_GETTIMEOFDAY
59 int gettimeofday(struct timeval *, struct timezone *);
60 #endif
62 double delta_time (struct timeval tv);
63 long deltime (struct timeval tv);
65 /* Handle strings safely */
67 void strip (char *);
68 char *strscpy (char *, const char *);
69 char *strnl (char *);
70 char *strpcpy (char *, const char *, const char *);
71 char *strpcat (char *, const char *, const char *);
72 int xvasprintf (char **strp, const char *fmt, va_list ap);
73 int xasprintf (char **strp, const char *fmt, ...);
75 int max_state (int a, int b);
76 int max_state_alt (int a, int b);
78 void usage (const char *) __attribute__((noreturn));
79 void usage2(const char *, const char *) __attribute__((noreturn));
80 void usage3(const char *, int) __attribute__((noreturn));
81 void usage4(const char *) __attribute__((noreturn));
82 void usage5(void) __attribute__((noreturn));
83 void usage_va(const char *fmt, ...) __attribute__((noreturn));
85 #define max(a,b) (((a)>(b))?(a):(b))
86 #define min(a,b) (((a)<(b))?(a):(b))
88 char *perfdata (const char *, long int, const char *, int, long int,
89 int, long int, int, long int, int, long int);
91 char *fperfdata (const char *, double, const char *, int, double,
92 int, double, int, double, int, double);
94 char *sperfdata (const char *, double, const char *, char *, char *,
95 int, double, int, double);
97 char *sperfdata_int (const char *, int, const char *, char *, char *,
98 int, int, int, int);
100 /* The idea here is that, although not every plugin will use all of these,
101 most will or should. Therefore, for consistency, these very common
102 options should have only these meanings throughout the overall suite */
104 #define STD_LONG_OPTS \
105 {"version",no_argument,0,'V'},\
106 {"verbose",no_argument,0,'v'},\
107 {"help",no_argument,0,'h'},\
108 {"timeout",required_argument,0,'t'},\
109 {"critical",required_argument,0,'c'},\
110 {"warning",required_argument,0,'w'},\
111 {"hostname",required_argument,0,'H'}
113 #define COPYRIGHT "Copyright (c) %s Monitoring Plugins Development Team\n\
114 \t<%s>\n\n"
116 #define UT_HLP_VRS _("\
117 %s (-h | --help) for detailed help\n\
118 %s (-V | --version) for version information\n")
120 #define UT_HELP_VRSN _("\
121 \nOptions:\n\
122 -h, --help\n\
123 Print detailed help screen\n\
124 -V, --version\n\
125 Print version information\n")
127 #define UT_HOST_PORT _("\
128 -H, --hostname=ADDRESS\n\
129 Host name, IP Address, or unix socket (must be an absolute path)\n\
130 -%c, --port=INTEGER\n\
131 Port number (default: %s)\n")
133 #define UT_IPv46 _("\
134 -4, --use-ipv4\n\
135 Use IPv4 connection\n\
136 -6, --use-ipv6\n\
137 Use IPv6 connection\n")
139 #define UT_VERBOSE _("\
140 -v, --verbose\n\
141 Show details for command-line debugging (output may be truncated by\n\
142 the monitoring system)\n")
144 #define UT_WARN_CRIT _("\
145 -w, --warning=DOUBLE\n\
146 Response time to result in warning status (seconds)\n\
147 -c, --critical=DOUBLE\n\
148 Response time to result in critical status (seconds)\n")
150 #define UT_WARN_CRIT_RANGE _("\
151 -w, --warning=RANGE\n\
152 Warning range (format: start:end). Alert if outside this range\n\
153 -c, --critical=RANGE\n\
154 Critical range\n")
156 #define UT_CONN_TIMEOUT _("\
157 -t, --timeout=INTEGER\n\
158 Seconds before connection times out (default: %d)\n")
160 #define UT_PLUG_TIMEOUT _("\
161 -t, --timeout=INTEGER\n\
162 Seconds before plugin times out (default: %d)\n")
164 #ifdef NP_EXTRA_OPTS
165 #define UT_EXTRA_OPTS _("\
166 --extra-opts=[section][@file]\n\
167 Read options from an ini file. See\n\
168 https://www.monitoring-plugins.org/doc/extra-opts.html\n\
169 for usage and examples.\n")
170 #else
171 #define UT_EXTRA_OPTS " \b"
172 #endif
174 #define UT_THRESHOLDS_NOTES _("\
175 See:\n\
176 https://www.monitoring-plugins.org/doc/guidelines.html#THRESHOLDFORMAT\n\
177 for THRESHOLD format and examples.\n")
179 #define UT_SUPPORT _("\n\
180 Send email to help@monitoring-plugins.org if you have questions regarding\n\
181 use of this software. To submit patches or suggest improvements, send email\n\
182 to devel@monitoring-plugins.org\n\n")
184 #define UT_NOWARRANTY _("\n\
185 The Monitoring Plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\n\
186 copies of the plugins under the terms of the GNU General Public License.\n\
187 For more information about these matters, see the file named COPYING.\n")
189 #endif /* NP_UTILS_H */