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"
19 /* Standardize version information, termination */
24 char *clean_revstring (const char *);
25 void print_revision (const char *, const char *);
29 #ifdef LOCAL_TIMEOUT_ALARM_HANDLER
30 extern unsigned int timeout_interval
;
31 RETSIGTYPE
timeout_alarm_handler (int);
33 unsigned int timeout_interval
= DEFAULT_SOCKET_TIMEOUT
;
34 extern RETSIGTYPE
timeout_alarm_handler (int);
37 time_t start_time
, end_time
;
39 /* Test input types */
41 int is_integer (char *);
42 int is_intpos (char *);
43 int is_intneg (char *);
44 int is_intnonneg (char *);
45 int is_intpercent (char *);
47 int is_numeric (char *);
48 int is_positive (char *);
49 int is_negative (char *);
50 int is_nonnegative (char *);
51 int is_percentage (char *);
53 int is_option (char *);
55 /* Generalized timer that will do milliseconds if available */
56 #ifndef HAVE_STRUCT_TIMEVAL
58 long tv_sec
; /* seconds */
59 long tv_usec
; /* microseconds */
63 #ifndef HAVE_GETTIMEOFDAY
64 int gettimeofday(struct timeval
*, struct timezone
*);
67 double delta_time (struct timeval tv
);
68 long deltime (struct timeval tv
);
70 /* Handle strings safely */
73 char *strscpy (char *, const char *);
75 char *strpcpy (char *, const char *, const char *);
76 char *strpcat (char *, const char *, const char *);
78 int max_state (int a
, int b
);
79 int max_state_alt (int a
, int b
);
81 void usage (const char *) __attribute__((noreturn
));
82 void usage2(const char *, const char *) __attribute__((noreturn
));
83 void usage3(const char *, int) __attribute__((noreturn
));
84 void usage4(const char *) __attribute__((noreturn
));
85 void usage5(void) __attribute__((noreturn
));
86 void usage_va(const char *fmt
, ...) __attribute__((noreturn
));
88 const char *state_text (int);
90 #define max(a,b) (((a)>(b))?(a):(b))
91 #define min(a,b) (((a)<(b))?(a):(b))
93 char *perfdata (const char *,
105 char *fperfdata (const char *,
117 /* The idea here is that, although not every plugin will use all of these,
118 most will or should. Therefore, for consistency, these very common
119 options should have only these meanings throughout the overall suite */
121 #define STD_LONG_OPTS \
122 {"version",no_argument,0,'V'},\
123 {"verbose",no_argument,0,'v'},\
124 {"help",no_argument,0,'h'},\
125 {"timeout",required_argument,0,'t'},\
126 {"critical",required_argument,0,'c'},\
127 {"warning",required_argument,0,'w'},\
128 {"hostname",required_argument,0,'H'}
130 #define COPYRIGHT "Copyright (c) %s Nagios Plugin Development Team\n\
133 #define UT_HLP_VRS "\
134 %s (-h | --help) for detailed help\n\
135 %s (-V | --version) for version information\n"
137 #define UT_HELP_VRSN "\
140 Print detailed help screen\n\
142 Print version information\n"
144 #define UT_HOST_PORT "\
145 -H, --hostname=ADDRESS\n\
146 Host name, IP Address, or unix socket (must be an absolute path)\n\
147 -%c, --port=INTEGER\n\
148 Port number (default: %s)\n"
152 Use IPv4 connection\n\
154 Use IPv6 connection\n"
156 #define UT_VERBOSE "\
158 Show details for command-line debugging (Nagios may truncate output)\n"
160 #define UT_WARN_CRIT "\
161 -w, --warning=DOUBLE\n\
162 Response time to result in warning status (seconds)\n\
163 -c, --critical=DOUBLE\n\
164 Response time to result in critical status (seconds)\n"
166 #define UT_WARN_CRIT_RANGE "\
167 -w, --warning=RANGE\n\
168 Warning range (format: start:end). Alert if outside this range\n\
169 -c, --critical=RANGE\n\
172 #define UT_TIMEOUT "\
173 -t, --timeout=INTEGER\n\
174 Seconds before connection times out (default: %d)\n"
176 #define UT_SUPPORT "\n\
177 Send email to nagios-users@lists.sourceforge.net if you have questions\n\
178 regarding use of this software. To submit patches or suggest improvements,\n\
179 send email to nagiosplug-devel@lists.sourceforge.net\n"
181 #define UT_NOWARRANTY "\n\
182 The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\n\
183 copies of the plugins under the terms of the GNU General Public License.\n\
184 For more information about these matters, see the file named COPYING.\n"
186 #endif /* NP_UTILS_H */