Code

some minor fixes
[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 *revstring);
20 void print_revision (const char *, const char *);
21 void die (int result, const char *fmt, ...) __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 *tv, struct timezone *tz);
61 #endif
63 double delta_time (struct timeval tv);
64 long deltime (struct timeval tv);
66 /* Handle strings safely */
68 void strip (char *buffer);
69 char *strscpy (char *dest, const char *src);
70 char *strnl (char *str);
71 char *strpcpy (char *dest, const char *src, const char *str);
72 char *strpcat (char *dest, const char *src, const char *str);
74 int max_state (int a, int b);
76 void usage (const char *msg) __attribute__((noreturn));
77 void usage2(const char *msg, const char *arg) __attribute__((noreturn));
78 void usage3(const char *msg, int arg) __attribute__((noreturn));
80 const char *state_text (int result);
82 #define max(a,b) (((a)>(b))?(a):(b))
83 #define min(a,b) (((a)<(b))?(a):(b))
85 char *perfdata (const char *label,
86  long int val,
87  const char *uom,
88  int warnp,
89  long int warn,
90  int critp,
91  long int crit,
92  int minp,
93  long int minv,
94  int maxp,
95  long int maxv);
97 char *fperfdata (const char *label,
98  double val,
99  const char *uom,
100  int warnp,
101  double warn,
102  int critp,
103  double crit,
104  int minp,
105  double minv,
106  int maxp,
107  double maxv);
109 /* The idea here is that, although not every plugin will use all of these, 
110    most will or should.  Therefore, for consistency, these very common 
111    options should have only these meanings throughout the overall suite */
113 #define STD_LONG_OPTS \
114 {"version",no_argument,0,'V'},\
115 {"verbose",no_argument,0,'v'},\
116 {"help",no_argument,0,'h'},\
117 {"timeout",required_argument,0,'t'},\
118 {"critical",required_argument,0,'c'},\
119 {"warning",required_argument,0,'w'},\
120 {"hostname",required_argument,0,'H'}
122 #define COPYRIGHT "Copyright (c) %s Nagios Plugin Development Team\n\
123 \t<%s>\n\n"
125 #define UT_HLP_VRS "\
126        %s (-h | --help) for detailed help\n\
127        %s (-V | --version) for version information\n"
129 #define UT_HELP_VRSN "\
130 \nOptions:\n\
131  -h, --help\n\
132     Print detailed help screen\n\
133  -V, --version\n\
134     Print version information\n"
136 #define UT_HOST_PORT "\
137  -H, --hostname=ADDRESS\n\
138     Host name or IP Address\n\
139  -%c, --port=INTEGER\n\
140     Port number (default: %s)\n"
142 #define UT_IPv46 "\
143  -4, --use-ipv4\n\
144     Use IPv4 connection\n\
145  -6, --use-ipv6\n\
146     Use IPv6 connection\n"
148 #define UT_VERBOSE "\
149  -v, --verbose\n\
150     Show details for command-line debugging (Nagios may truncate output)\n"
152 #define UT_WARN_CRIT "\
153  -w, --warning=DOUBLE\n\
154     Response time to result in warning status (seconds)\n\
155  -c, --critical=DOUBLE\n\
156     Response time to result in critical status (seconds)\n"
158 #define UT_TIMEOUT "\
159  -t, --timeout=INTEGER\n\
160     Seconds before connection times out (default: %d)\n"
162 #define UT_SUPPORT "\n\
163 Send email to nagios-users@lists.sourceforge.net if you have questions\n\
164 regarding use of this software. To submit patches or suggest improvements,\n\
165 send email to nagiosplug-devel@lists.sourceforge.net\n"
167 #define UT_NOWARRANTY "\n\
168 The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\n\
169 copies of the plugins under the terms of the GNU General Public License.\n\
170 For more information about these matters, see the file named COPYING.\n"