Code

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