Code

- explicitly include utils_base.h from utils.h
[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 *);
84 void usage_va(const char *fmt, ...);
86 const char *state_text (int);
88 #define max(a,b) (((a)>(b))?(a):(b))
89 #define min(a,b) (((a)<(b))?(a):(b))
91 char *perfdata (const char *,
92  long int,
93  const char *,
94  int,
95  long int,
96  int,
97  long int,
98  int,
99  long int,
100  int,
101  long int);
103 char *fperfdata (const char *,
104  double,
105  const char *,
106  int,
107  double,
108  int,
109  double,
110  int,
111  double,
112  int,
113  double);
115 /* The idea here is that, although not every plugin will use all of these, 
116    most will or should.  Therefore, for consistency, these very common 
117    options should have only these meanings throughout the overall suite */
119 #define STD_LONG_OPTS \
120 {"version",no_argument,0,'V'},\
121 {"verbose",no_argument,0,'v'},\
122 {"help",no_argument,0,'h'},\
123 {"timeout",required_argument,0,'t'},\
124 {"critical",required_argument,0,'c'},\
125 {"warning",required_argument,0,'w'},\
126 {"hostname",required_argument,0,'H'}
128 #define COPYRIGHT "Copyright (c) %s Nagios Plugin Development Team\n\
129 \t<%s>\n\n"
131 #define UT_HLP_VRS "\
132        %s (-h | --help) for detailed help\n\
133        %s (-V | --version) for version information\n"
135 #define UT_HELP_VRSN "\
136 \nOptions:\n\
137  -h, --help\n\
138     Print detailed help screen\n\
139  -V, --version\n\
140     Print version information\n"
142 #define UT_HOST_PORT "\
143  -H, --hostname=ADDRESS\n\
144     Host name, IP Address, or unix socket (must be an absolute path)\n\
145  -%c, --port=INTEGER\n\
146     Port number (default: %s)\n"
148 #define UT_IPv46 "\
149  -4, --use-ipv4\n\
150     Use IPv4 connection\n\
151  -6, --use-ipv6\n\
152     Use IPv6 connection\n"
154 #define UT_VERBOSE "\
155  -v, --verbose\n\
156     Show details for command-line debugging (Nagios may truncate output)\n"
158 #define UT_WARN_CRIT "\
159  -w, --warning=DOUBLE\n\
160     Response time to result in warning status (seconds)\n\
161  -c, --critical=DOUBLE\n\
162     Response time to result in critical status (seconds)\n"
164 #define UT_WARN_CRIT_RANGE "\
165  -w, --warning=RANGE\n\
166     Warning range (format: start:end). Alert if outside this range\n\
167  -c, --critical=RANGE\n\
168     Critical range\n"
170 #define UT_TIMEOUT "\
171  -t, --timeout=INTEGER\n\
172     Seconds before connection times out (default: %d)\n"
174 #define UT_SUPPORT "\n\
175 Send email to nagios-users@lists.sourceforge.net if you have questions\n\
176 regarding use of this software. To submit patches or suggest improvements,\n\
177 send email to nagiosplug-devel@lists.sourceforge.net\n"
179 #define UT_NOWARRANTY "\n\
180 The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\n\
181 copies of the plugins under the terms of the GNU General Public License.\n\
182 For more information about these matters, see the file named COPYING.\n"
184 #endif /* NP_UTILS_H */