Code

Verbose should not have to exceed 3 as per developement guidelines
[nagiosplug.git] / plugins / utils.h
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 /* $Id$ */
31 void support (void);
32 char *clean_revstring (const char *);
33 void print_revision (const char *, const char *);
35 /* Handle timeouts */
37 #ifdef LOCAL_TIMEOUT_ALARM_HANDLER
38 extern unsigned int timeout_interval;
39 RETSIGTYPE timeout_alarm_handler (int);
40 #else
41 unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT;
42 extern RETSIGTYPE timeout_alarm_handler (int);
43 #endif
45 time_t start_time, end_time;
47 /* Test input types */
49 int is_integer (char *);
50 int is_intpos (char *);
51 int is_intneg (char *);
52 int is_intnonneg (char *);
53 int is_intpercent (char *);
55 int is_numeric (char *);
56 int is_positive (char *);
57 int is_negative (char *);
58 int is_nonnegative (char *);
59 int is_percentage (char *);
61 int is_option (char *);
63 /* Generalized timer that will do milliseconds if available */
64 #ifndef HAVE_STRUCT_TIMEVAL
65 struct timeval {
66         long tv_sec;        /* seconds */
67         long tv_usec;  /* microseconds */
68 };
69 #endif
71 #ifndef HAVE_GETTIMEOFDAY
72 int gettimeofday(struct timeval *, struct timezone *);
73 #endif
75 double delta_time (struct timeval tv);
76 long deltime (struct timeval tv);
78 /* Handle strings safely */
80 void strip (char *);
81 char *strscpy (char *, const char *);
82 char *strnl (char *);
83 char *strpcpy (char *, const char *, const char *);
84 char *strpcat (char *, const char *, const char *);
86 int max_state (int a, int b);
87 int max_state_alt (int a, int b);
89 void usage (const char *) __attribute__((noreturn));
90 void usage2(const char *, const char *) __attribute__((noreturn));
91 void usage3(const char *, int) __attribute__((noreturn));
92 void usage4(const char *) __attribute__((noreturn));
93 void usage5(void) __attribute__((noreturn));
94 void usage_va(const char *fmt, ...) __attribute__((noreturn));
96 const char *state_text (int);
98 #define max(a,b) (((a)>(b))?(a):(b))
99 #define min(a,b) (((a)<(b))?(a):(b))
101 char *perfdata (const char *,
102  long int,
103  const char *,
104  int,
105  long int,
106  int,
107  long int,
108  int,
109  long int,
110  int,
111  long int);
113 char *fperfdata (const char *,
114  double,
115  const char *,
116  int,
117  double,
118  int,
119  double,
120  int,
121  double,
122  int,
123  double);
125 /* The idea here is that, although not every plugin will use all of these, 
126    most will or should.  Therefore, for consistency, these very common 
127    options should have only these meanings throughout the overall suite */
129 #define STD_LONG_OPTS \
130 {"version",no_argument,0,'V'},\
131 {"verbose",no_argument,0,'v'},\
132 {"help",no_argument,0,'h'},\
133 {"timeout",required_argument,0,'t'},\
134 {"critical",required_argument,0,'c'},\
135 {"warning",required_argument,0,'w'},\
136 {"hostname",required_argument,0,'H'}
138 #define COPYRIGHT "Copyright (c) %s Nagios Plugin Development Team\n\
139 \t<%s>\n\n"
141 #define UT_HLP_VRS "\
142        %s (-h | --help) for detailed help\n\
143        %s (-V | --version) for version information\n"
145 #define UT_HELP_VRSN "\
146 \nOptions:\n\
147  -h, --help\n\
148     Print detailed help screen\n\
149  -V, --version\n\
150     Print version information\n"
152 #define UT_HOST_PORT "\
153  -H, --hostname=ADDRESS\n\
154     Host name, IP Address, or unix socket (must be an absolute path)\n\
155  -%c, --port=INTEGER\n\
156     Port number (default: %s)\n"
158 #define UT_IPv46 "\
159  -4, --use-ipv4\n\
160     Use IPv4 connection\n\
161  -6, --use-ipv6\n\
162     Use IPv6 connection\n"
164 #define UT_VERBOSE "\
165  -v, --verbose\n\
166     Show details for command-line debugging (Nagios may truncate output)\n"
168 #define UT_WARN_CRIT "\
169  -w, --warning=DOUBLE\n\
170     Response time to result in warning status (seconds)\n\
171  -c, --critical=DOUBLE\n\
172     Response time to result in critical status (seconds)\n"
174 #define UT_WARN_CRIT_RANGE "\
175  -w, --warning=RANGE\n\
176     Warning range (format: start:end). Alert if outside this range\n\
177  -c, --critical=RANGE\n\
178     Critical range\n"
180 #define UT_TIMEOUT "\
181  -t, --timeout=INTEGER\n\
182     Seconds before connection times out (default: %d)\n"
184 #ifdef NP_EXTRA_OPTS
185 #define UT_EXTRA_OPTS "\
186  --extra-opts=[section][@file]\n\
187     Read additionnal options from ini file\n"
188 #define UT_EXTRA_OPTS_NOTES "\
189  See: http://nagiosplugins.org/extra-opts for --extra-opts usage and examples.\n"
190 #else
191 #define UT_EXTRA_OPTS ""
192 #define UT_EXTRA_OPTS_NOTES ""
193 #endif
195 #define UT_THRESHOLDS_NOTES "\
196  See:\n\
197  http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT\n\
198  for THRESHOLD format and examples.\n"
200 #define UT_SUPPORT "\n\
201 Send email to nagios-users@lists.sourceforge.net if you have questions\n\
202 regarding use of this software. To submit patches or suggest improvements,\n\
203 send email to nagiosplug-devel@lists.sourceforge.net\n\n"
205 #define UT_NOWARRANTY "\n\
206 The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\n\
207 copies of the plugins under the terms of the GNU General Public License.\n\
208 For more information about these matters, see the file named COPYING.\n"
210 #endif /* NP_UTILS_H */