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
16 /* now some functions etc are being defined in ../lib/utils_base.c */
17 #include "utils_base.h"
20 /* Include extra-opts functions if compiled in */
21 #include "extra_opts.h"
23 /* else, fake np_extra_opts */
24 #define np_extra_opts(acptr,av,pr) av
27 /* Standardize version information, termination */
30 void print_revision (const char *, const char *);
34 extern unsigned int timeout_state
;
35 extern unsigned int timeout_interval
;
37 RETSIGTYPE
timeout_alarm_handler (int);
39 extern time_t start_time
, end_time
;
41 /* Test input types */
43 int is_integer (char *);
44 int is_intpos (char *);
45 int is_intneg (char *);
46 int is_intnonneg (char *);
47 int is_intpercent (char *);
49 int is_numeric (char *);
50 int is_positive (char *);
51 int is_negative (char *);
52 int is_nonnegative (char *);
53 int is_percentage (char *);
55 int is_option (char *);
57 /* Generalized timer that will do milliseconds if available */
58 #ifndef HAVE_STRUCT_TIMEVAL
60 long tv_sec
; /* seconds */
61 long tv_usec
; /* microseconds */
65 #ifndef HAVE_GETTIMEOFDAY
66 int gettimeofday(struct timeval
*, struct timezone
*);
69 double delta_time (struct timeval tv
);
70 long deltime (struct timeval tv
);
72 /* Handle strings safely */
75 char *strscpy (char *, const char *);
77 char *strpcpy (char *, const char *, const char *);
78 char *strpcat (char *, const char *, const char *);
79 int xvasprintf (char **strp
, const char *fmt
, va_list ap
);
80 int xasprintf (char **strp
, const char *fmt
, ...);
82 int max_state (int a
, int b
);
83 int max_state_alt (int a
, int b
);
85 void usage (const char *) __attribute__((noreturn
));
86 void usage2(const char *, const char *) __attribute__((noreturn
));
87 void usage3(const char *, int) __attribute__((noreturn
));
88 void usage4(const char *) __attribute__((noreturn
));
89 void usage5(void) __attribute__((noreturn
));
90 void usage_va(const char *fmt
, ...) __attribute__((noreturn
));
92 const char *state_text (int);
94 #define max(a,b) (((a)>(b))?(a):(b))
95 #define min(a,b) (((a)<(b))?(a):(b))
97 char *perfdata (const char *,
109 char *fperfdata (const char *,
121 /* The idea here is that, although not every plugin will use all of these,
122 most will or should. Therefore, for consistency, these very common
123 options should have only these meanings throughout the overall suite */
125 #define STD_LONG_OPTS \
126 {"version",no_argument,0,'V'},\
127 {"verbose",no_argument,0,'v'},\
128 {"help",no_argument,0,'h'},\
129 {"timeout",required_argument,0,'t'},\
130 {"critical",required_argument,0,'c'},\
131 {"warning",required_argument,0,'w'},\
132 {"hostname",required_argument,0,'H'}
134 #define COPYRIGHT "Copyright (c) %s Nagios Plugin Development Team\n\
137 #define UT_HLP_VRS _("\
138 %s (-h | --help) for detailed help\n\
139 %s (-V | --version) for version information\n")
141 #define UT_HELP_VRSN _("\
144 Print detailed help screen\n\
146 Print version information\n")
148 #define UT_HOST_PORT _("\
149 -H, --hostname=ADDRESS\n\
150 Host name, IP Address, or unix socket (must be an absolute path)\n\
151 -%c, --port=INTEGER\n\
152 Port number (default: %s)\n")
154 #define UT_IPv46 _("\
156 Use IPv4 connection\n\
158 Use IPv6 connection\n")
160 #define UT_VERBOSE _("\
162 Show details for command-line debugging (Nagios may truncate output)\n")
164 #define UT_WARN_CRIT _("\
165 -w, --warning=DOUBLE\n\
166 Response time to result in warning status (seconds)\n\
167 -c, --critical=DOUBLE\n\
168 Response time to result in critical status (seconds)\n")
170 #define UT_WARN_CRIT_RANGE _("\
171 -w, --warning=RANGE\n\
172 Warning range (format: start:end). Alert if outside this range\n\
173 -c, --critical=RANGE\n\
176 #define UT_TIMEOUT _("\
177 -t, --timeout=INTEGER\n\
178 Seconds before connection times out (default: %d)\n")
181 #define UT_EXTRA_OPTS _("\
182 --extra-opts=[section][@file]\n\
183 Read options from an ini file. See\n\
184 https://www.nagios-plugins.org/doc/extra-opts.html\n\
185 for usage and examples.\n")
187 #define UT_EXTRA_OPTS ""
190 #define UT_THRESHOLDS_NOTES _("\
192 https://www.nagios-plugins.org/doc/guidelines.html#THRESHOLDFORMAT\n\
193 for THRESHOLD format and examples.\n")
195 #define UT_SUPPORT _("\n\
196 Send email to help@nagios-plugins.org if you have questions regarding use\n\
197 of this software. To submit patches or suggest improvements, send email to\n\
198 devel@nagios-plugins.org\n\n")
200 #define UT_NOWARRANTY _("\n\
201 The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\n\
202 copies of the plugins under the terms of the GNU General Public License.\n\
203 For more information about these matters, see the file named COPYING.\n")
205 #endif /* NP_UTILS_H */