Code

Catch no responses from any server (1538341 - nmdias)
[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 /* Standardize version information, termination */
18 /* $Id$ */
20 void support (void);
21 char *clean_revstring (const char *);
22 void print_revision (const char *, const char *);
24 /* Handle timeouts */
26 #ifdef LOCAL_TIMEOUT_ALARM_HANDLER
27 extern unsigned int timeout_interval;
28 RETSIGTYPE timeout_alarm_handler (int);
29 #else
30 unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT;
31 extern RETSIGTYPE timeout_alarm_handler (int);
32 #endif
34 time_t start_time, end_time;
36 /* Test input types */
38 int is_integer (char *);
39 int is_intpos (char *);
40 int is_intneg (char *);
41 int is_intnonneg (char *);
42 int is_intpercent (char *);
44 int is_numeric (char *);
45 int is_positive (char *);
46 int is_negative (char *);
47 int is_nonnegative (char *);
48 int is_percentage (char *);
50 int is_option (char *);
52 /* Generalized timer that will do milliseconds if available */
53 #ifndef HAVE_STRUCT_TIMEVAL
54 struct timeval {
55         long tv_sec;        /* seconds */
56         long tv_usec;  /* microseconds */
57 };
58 #endif
60 #ifndef HAVE_GETTIMEOFDAY
61 int gettimeofday(struct timeval *, struct timezone *);
62 #endif
64 double delta_time (struct timeval tv);
65 long deltime (struct timeval tv);
67 /* Handle strings safely */
69 void strip (char *);
70 char *strscpy (char *, const char *);
71 char *strnl (char *);
72 char *strpcpy (char *, const char *, const char *);
73 char *strpcat (char *, const char *, const char *);
75 int max_state (int a, int b);
77 void usage (const char *) __attribute__((noreturn));
78 void usage2(const char *, const char *) __attribute__((noreturn));
79 void usage3(const char *, int) __attribute__((noreturn));
80 void usage4(const char *);
81 void usage_va(const char *fmt, ...);
83 const char *state_text (int);
85 #define max(a,b) (((a)>(b))?(a):(b))
86 #define min(a,b) (((a)<(b))?(a):(b))
88 char *perfdata (const char *,
89  long int,
90  const char *,
91  int,
92  long int,
93  int,
94  long int,
95  int,
96  long int,
97  int,
98  long int);
100 char *fperfdata (const char *,
101  double,
102  const char *,
103  int,
104  double,
105  int,
106  double,
107  int,
108  double,
109  int,
110  double);
112 /* The idea here is that, although not every plugin will use all of these, 
113    most will or should.  Therefore, for consistency, these very common 
114    options should have only these meanings throughout the overall suite */
116 #define STD_LONG_OPTS \
117 {"version",no_argument,0,'V'},\
118 {"verbose",no_argument,0,'v'},\
119 {"help",no_argument,0,'h'},\
120 {"timeout",required_argument,0,'t'},\
121 {"critical",required_argument,0,'c'},\
122 {"warning",required_argument,0,'w'},\
123 {"hostname",required_argument,0,'H'}
125 #define COPYRIGHT "Copyright (c) %s Nagios Plugin Development Team\n\
126 \t<%s>\n\n"
128 #define UT_HLP_VRS "\
129        %s (-h | --help) for detailed help\n\
130        %s (-V | --version) for version information\n"
132 #define UT_HELP_VRSN "\
133 \nOptions:\n\
134  -h, --help\n\
135     Print detailed help screen\n\
136  -V, --version\n\
137     Print version information\n"
139 #define UT_HOST_PORT "\
140  -H, --hostname=ADDRESS\n\
141     Host name, IP Address, or unix socket (must be an absolute path)\n\
142  -%c, --port=INTEGER\n\
143     Port number (default: %s)\n"
145 #define UT_IPv46 "\
146  -4, --use-ipv4\n\
147     Use IPv4 connection\n\
148  -6, --use-ipv6\n\
149     Use IPv6 connection\n"
151 #define UT_VERBOSE "\
152  -v, --verbose\n\
153     Show details for command-line debugging (Nagios may truncate output)\n"
155 #define UT_WARN_CRIT "\
156  -w, --warning=DOUBLE\n\
157     Response time to result in warning status (seconds)\n\
158  -c, --critical=DOUBLE\n\
159     Response time to result in critical status (seconds)\n"
161 #define UT_WARN_CRIT_RANGE "\
162  -w, --warning=RANGE\n\
163     Warning range (format: start:end). Alert if outside this range\n\
164  -c, --critical=RANGE\n\
165     Critical range\n"
167 #define UT_TIMEOUT "\
168  -t, --timeout=INTEGER\n\
169     Seconds before connection times out (default: %d)\n"
171 #define UT_SUPPORT "\n\
172 Send email to nagios-users@lists.sourceforge.net if you have questions\n\
173 regarding use of this software. To submit patches or suggest improvements,\n\
174 send email to nagiosplug-devel@lists.sourceforge.net\n"
176 #define UT_NOWARRANTY "\n\
177 The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\n\
178 copies of the plugins under the terms of the GNU General Public License.\n\
179 For more information about these matters, see the file named COPYING.\n"
181 #endif /* NP_UTILS_H */