Code

If the TMPDIR environment variable is set, use that instead of "/tmp" as
[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 /* Standardize version information, termination */
21 /* $Id$ */
23 void support (void);
24 char *clean_revstring (const char *);
25 void print_revision (const char *, const char *);
27 /* Handle timeouts */
29 #ifdef LOCAL_TIMEOUT_ALARM_HANDLER
30 extern unsigned int timeout_interval;
31 RETSIGTYPE timeout_alarm_handler (int);
32 #else
33 unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT;
34 extern RETSIGTYPE timeout_alarm_handler (int);
35 #endif
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
57 struct timeval {
58         long tv_sec;        /* seconds */
59         long tv_usec;  /* microseconds */
60 };
61 #endif
63 #ifndef HAVE_GETTIMEOFDAY
64 int gettimeofday(struct timeval *, struct timezone *);
65 #endif
67 double delta_time (struct timeval tv);
68 long deltime (struct timeval tv);
70 /* Handle strings safely */
72 void strip (char *);
73 char *strscpy (char *, const char *);
74 char *strnl (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);
80 void usage (const char *) __attribute__((noreturn));
81 void usage2(const char *, const char *) __attribute__((noreturn));
82 void usage3(const char *, int) __attribute__((noreturn));
83 void usage4(const char *) __attribute__((noreturn));
84 void usage5(void) __attribute__((noreturn));
85 void usage_va(const char *fmt, ...) __attribute__((noreturn));
87 const char *state_text (int);
89 #define max(a,b) (((a)>(b))?(a):(b))
90 #define min(a,b) (((a)<(b))?(a):(b))
92 char *perfdata (const char *,
93  long int,
94  const char *,
95  int,
96  long int,
97  int,
98  long int,
99  int,
100  long int,
101  int,
102  long int);
104 char *fperfdata (const char *,
105  double,
106  const char *,
107  int,
108  double,
109  int,
110  double,
111  int,
112  double,
113  int,
114  double);
116 /* The idea here is that, although not every plugin will use all of these, 
117    most will or should.  Therefore, for consistency, these very common 
118    options should have only these meanings throughout the overall suite */
120 #define STD_LONG_OPTS \
121 {"version",no_argument,0,'V'},\
122 {"verbose",no_argument,0,'v'},\
123 {"help",no_argument,0,'h'},\
124 {"timeout",required_argument,0,'t'},\
125 {"critical",required_argument,0,'c'},\
126 {"warning",required_argument,0,'w'},\
127 {"hostname",required_argument,0,'H'}
129 #define COPYRIGHT "Copyright (c) %s Nagios Plugin Development Team\n\
130 \t<%s>\n\n"
132 #define UT_HLP_VRS "\
133        %s (-h | --help) for detailed help\n\
134        %s (-V | --version) for version information\n"
136 #define UT_HELP_VRSN "\
137 \nOptions:\n\
138  -h, --help\n\
139     Print detailed help screen\n\
140  -V, --version\n\
141     Print version information\n"
143 #define UT_HOST_PORT "\
144  -H, --hostname=ADDRESS\n\
145     Host name, IP Address, or unix socket (must be an absolute path)\n\
146  -%c, --port=INTEGER\n\
147     Port number (default: %s)\n"
149 #define UT_IPv46 "\
150  -4, --use-ipv4\n\
151     Use IPv4 connection\n\
152  -6, --use-ipv6\n\
153     Use IPv6 connection\n"
155 #define UT_VERBOSE "\
156  -v, --verbose\n\
157     Show details for command-line debugging (Nagios may truncate output)\n"
159 #define UT_WARN_CRIT "\
160  -w, --warning=DOUBLE\n\
161     Response time to result in warning status (seconds)\n\
162  -c, --critical=DOUBLE\n\
163     Response time to result in critical status (seconds)\n"
165 #define UT_WARN_CRIT_RANGE "\
166  -w, --warning=RANGE\n\
167     Warning range (format: start:end). Alert if outside this range\n\
168  -c, --critical=RANGE\n\
169     Critical range\n"
171 #define UT_TIMEOUT "\
172  -t, --timeout=INTEGER\n\
173     Seconds before connection times out (default: %d)\n"
175 #define UT_SUPPORT "\n\
176 Send email to nagios-users@lists.sourceforge.net if you have questions\n\
177 regarding use of this software. To submit patches or suggest improvements,\n\
178 send email to nagiosplug-devel@lists.sourceforge.net\n"
180 #define UT_NOWARRANTY "\n\
181 The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\n\
182 copies of the plugins under the terms of the GNU General Public License.\n\
183 For more information about these matters, see the file named COPYING.\n"
185 #endif /* NP_UTILS_H */