Code

def89705c7c1e4424b0d1315c603cfcf8ec4c80f
[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);
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 *,
94  long int,
95  const char *,
96  int,
97  long int,
98  int,
99  long int,
100  int,
101  long int,
102  int,
103  long int);
105 char *fperfdata (const char *,
106  double,
107  const char *,
108  int,
109  double,
110  int,
111  double,
112  int,
113  double,
114  int,
115  double);
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\
131 \t<%s>\n\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 "\
138 \nOptions:\n\
139  -h, --help\n\
140     Print detailed help screen\n\
141  -V, --version\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"
150 #define UT_IPv46 "\
151  -4, --use-ipv4\n\
152     Use IPv4 connection\n\
153  -6, --use-ipv6\n\
154     Use IPv6 connection\n"
156 #define UT_VERBOSE "\
157  -v, --verbose\n\
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\
170     Critical range\n"
172 #define UT_TIMEOUT "\
173  -t, --timeout=INTEGER\n\
174     Seconds before connection times out (default: %d)\n"
176 #define UT_THRESHOLDS_NOTES "\
177  See:\n\
178  http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT\n\
179  for THRESHOLD format and examples.\n"
181 #define UT_SUPPORT "\n\
182 Send email to nagios-users@lists.sourceforge.net if you have questions\n\
183 regarding use of this software. To submit patches or suggest improvements,\n\
184 send email to nagiosplug-devel@lists.sourceforge.net\n\n"
186 #define UT_NOWARRANTY "\n\
187 The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\n\
188 copies of the plugins under the terms of the GNU General Public License.\n\
189 For more information about these matters, see the file named COPYING.\n"
191 #endif /* NP_UTILS_H */