Code

fix patch 998291
[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 /* $Id$ */
18 void support (void);
19 char *clean_revstring (const char *);
20 void print_revision (const char *, const char *);
21 void die (int, const char *, ...) __attribute__((noreturn,format(printf, 2, 3)));
23 /* Handle timeouts */
25 #ifdef LOCAL_TIMEOUT_ALARM_HANDLER
26 extern unsigned int timeout_interval;
27 RETSIGTYPE timeout_alarm_handler (int);
28 #else
29 unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT;
30 extern RETSIGTYPE timeout_alarm_handler (int);
31 #endif
33 time_t start_time, end_time;
35 /* Test input types */
37 int is_integer (char *);
38 int is_intpos (char *);
39 int is_intneg (char *);
40 int is_intnonneg (char *);
41 int is_intpercent (char *);
43 int is_numeric (char *);
44 int is_positive (char *);
45 int is_negative (char *);
46 int is_nonnegative (char *);
47 int is_percentage (char *);
49 int is_option (char *);
51 /* Generalized timer that will do milliseconds if available */
52 #ifndef HAVE_STRUCT_TIMEVAL
53 struct timeval {
54         long tv_sec;        /* seconds */
55         long tv_usec;  /* microseconds */
56 };
57 #endif
59 #ifndef HAVE_GETTIMEOFDAY
60 int gettimeofday(struct timeval *, struct timezone *);
61 #endif
63 double delta_time (struct timeval tv);
64 long deltime (struct timeval tv);
66 /* Handle strings safely */
68 void strip (char *);
69 char *strscpy (char *, const char *);
70 char *strnl (char *);
71 char *strpcpy (char *, const char *, const char *);
72 char *strpcat (char *, const char *, const char *);
74 int max_state (int a, int b);
76 void usage (const char *) __attribute__((noreturn));
77 void usage2(const char *, const char *) __attribute__((noreturn));
78 void usage3(const char *, int) __attribute__((noreturn));
79 void usage4(const char *);
81 const char *state_text (int);
83 #define max(a,b) (((a)>(b))?(a):(b))
84 #define min(a,b) (((a)<(b))?(a):(b))
86 char *perfdata (const char *,
87  long int,
88  const char *,
89  int,
90  long int,
91  int,
92  long int,
93  int,
94  long int,
95  int,
96  long int);
98 char *fperfdata (const char *,
99  double,
100  const char *,
101  int,
102  double,
103  int,
104  double,
105  int,
106  double,
107  int,
108  double);
110 /* The idea here is that, although not every plugin will use all of these, 
111    most will or should.  Therefore, for consistency, these very common 
112    options should have only these meanings throughout the overall suite */
114 #define STD_LONG_OPTS \
115 {"version",no_argument,0,'V'},\
116 {"verbose",no_argument,0,'v'},\
117 {"help",no_argument,0,'h'},\
118 {"timeout",required_argument,0,'t'},\
119 {"critical",required_argument,0,'c'},\
120 {"warning",required_argument,0,'w'},\
121 {"hostname",required_argument,0,'H'}
123 #define COPYRIGHT "Copyright (c) %s Nagios Plugin Development Team\n\
124 \t<%s>\n\n"
126 #define UT_HLP_VRS "\
127        %s (-h | --help) for detailed help\n\
128        %s (-V | --version) for version information\n"
130 #define UT_HELP_VRSN "\
131 \nOptions:\n\
132  -h, --help\n\
133     Print detailed help screen\n\
134  -V, --version\n\
135     Print version information\n"
137 #define UT_HOST_PORT "\
138  -H, --hostname=ADDRESS\n\
139     Host name or IP Address\n\
140  -%c, --port=INTEGER\n\
141     Port number (default: %s)\n"
143 #define UT_IPv46 "\
144  -4, --use-ipv4\n\
145     Use IPv4 connection\n\
146  -6, --use-ipv6\n\
147     Use IPv6 connection\n"
149 #define UT_VERBOSE "\
150  -v, --verbose\n\
151     Show details for command-line debugging (Nagios may truncate output)\n"
153 #define UT_WARN_CRIT "\
154  -w, --warning=DOUBLE\n\
155     Response time to result in warning status (seconds)\n\
156  -c, --critical=DOUBLE\n\
157     Response time to result in critical status (seconds)\n"
159 #define UT_TIMEOUT "\
160  -t, --timeout=INTEGER\n\
161     Seconds before connection times out (default: %d)\n"
163 #define UT_SUPPORT "\n\
164 Send email to nagios-users@lists.sourceforge.net if you have questions\n\
165 regarding use of this software. To submit patches or suggest improvements,\n\
166 send email to nagiosplug-devel@lists.sourceforge.net\n"
168 #define UT_NOWARRANTY "\n\
169 The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\n\
170 copies of the plugins under the terms of the GNU General Public License.\n\
171 For more information about these matters, see the file named COPYING.\n"