Code

Command line argument bug (Howard Wilkinson)
[nagiosplug.git] / plugins / utils.h
1 /* Header file for nagios plugins utils.c */
3 /* This file should be included in all plugins */
5 /* The purpose of this package is to provide safer alternatives to C
6 functions that might otherwise be vulnerable to hacking. This
7 currently includes a standard suite of validation routines to be sure
8 that an string argument acually converts to its intended type and a
9 suite of string handling routine that do their own memory management
10 in order to resist overflow attacks. In addition, a few functions are
11 provided to standardize version and error reporting across the entire
12 suite of plugins. */
14 /* Standardize version information, termination */
16 void support (void);
17 char *clean_revstring (const char *revstring);
18 void print_revision (const char *, const char *);
19 void die (int result, const char *fmt, ...) __attribute__((noreturn,format(printf, 2, 3)));
21 /* Handle timeouts */
23 #ifdef LOCAL_TIMEOUT_ALARM_HANDLER
24 extern unsigned int timeout_interval;
25 RETSIGTYPE timeout_alarm_handler (int);
26 #else
27 unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT;
28 extern RETSIGTYPE timeout_alarm_handler (int);
29 #endif
31 time_t start_time, end_time;
33 /* Test input types */
35 int is_integer (char *);
36 int is_intpos (char *);
37 int is_intneg (char *);
38 int is_intnonneg (char *);
39 int is_intpercent (char *);
41 int is_numeric (char *);
42 int is_positive (char *);
43 int is_negative (char *);
44 int is_nonnegative (char *);
45 int is_percentage (char *);
47 int is_option (char *);
49 /* Generalized timer that will do milliseconds if available */
50 #ifndef HAVE_STRUCT_TIMEVAL
51 struct timeval {
52         long tv_sec;        /* seconds */
53         long tv_usec;  /* microseconds */
54 };
55 #endif
57 #ifndef HAVE_GETTIMEOFDAY
58 int gettimeofday(struct timeval *tv, struct timezone *tz);
59 #endif
61 double delta_time (struct timeval tv);
62 long deltime (struct timeval tv);
64 /* Handle strings safely */
66 void strip (char *buffer);
67 char *strscpy (char *dest, const char *src);
68 char *strnl (char *str);
69 char *strpcpy (char *dest, const char *src, const char *str);
70 char *strpcat (char *dest, const char *src, const char *str);
72 int max_state (int a, int b);
74 void usage (const char *msg) __attribute__((noreturn));
75 void usage2(const char *msg, const char *arg) __attribute__((noreturn));
76 void usage3(const char *msg, int arg) __attribute__((noreturn));
78 const char *state_text (int result);
80 #define max(a,b) (((a)>(b))?(a):(b))
81 #define min(a,b) (((a)<(b))?(a):(b))
83 char *perfdata (const char *label,
84  long int val,
85  const char *uom,
86  int warnp,
87  long int warn,
88  int critp,
89  long int crit,
90  int minp,
91  long int minv,
92  int maxp,
93  long int maxv);
95 char *fperfdata (const char *label,
96  double val,
97  const char *uom,
98  int warnp,
99  double warn,
100  int critp,
101  double crit,
102  int minp,
103  double minv,
104  int maxp,
105  double maxv);
107 /* The idea here is that, although not every plugin will use all of these, 
108    most will or should.  Therefore, for consistency, these very common 
109    options should have only these meanings throughout the overall suite */
111 #define STD_LONG_OPTS \
112 {"version",no_argument,0,'V'},\
113 {"verbose",no_argument,0,'v'},\
114 {"help",no_argument,0,'h'},\
115 {"timeout",required_argument,0,'t'},\
116 {"critical",required_argument,0,'c'},\
117 {"warning",required_argument,0,'w'},\
118 {"hostname",required_argument,0,'H'}
120 #define COPYRIGHT "Copyright (c) %s Nagios Plugin Development Team\n\
121 \t<%s>\n\n"
123 #define UT_HLP_VRS "\
124        %s (-h | --help) for detailed help\n\
125        %s (-V | --version) for version information\n"
127 #define UT_HELP_VRSN "\
128 \nOptions:\n\
129  -h, --help\n\
130     Print detailed help screen\n\
131  -V, --version\n\
132     Print version information\n"
134 #define UT_HOST_PORT "\
135  -H, --hostname=ADDRESS\n\
136     Host name or IP Address\n\
137  -%c, --port=INTEGER\n\
138     Port number (default: %s)\n"
140 #define UT_IPv46 "\
141  -4, --use-ipv4\n\
142     Use IPv4 connection\n\
143  -6, --use-ipv6\n\
144     Use IPv6 connection\n"
146 #define UT_VERBOSE "\
147  -v, --verbose\n\
148     Show details for command-line debugging (Nagios may truncate output)\n"
150 #define UT_WARN_CRIT "\
151  -w, --warning=DOUBLE\n\
152     Response time to result in warning status (seconds)\n\
153  -c, --critical=DOUBLE\n\
154     Response time to result in critical status (seconds)\n"
156 #define UT_TIMEOUT "\
157  -t, --timeout=INTEGER\n\
158     Seconds before connection times out (default: %d)\n"
160 #define UT_SUPPORT "\n\
161 Send email to nagios-users@lists.sourceforge.net if you have questions\n\
162 regarding use of this software. To submit patches or suggest improvements,\n\
163 send email to nagiosplug-devel@lists.sourceforge.net\n"
165 #define UT_NOWARRANTY "\
166 The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\n\
167 copies of the plugins under the terms of the GNU General Public License.\n\
168 For more information about these matters, see the file named COPYING.\n"