Code

- typo 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 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 /* The idea here is that, although not every plugin will use all of these, 
96    most will or should.  Therefore, for consistency, these very common 
97    options should have only these meanings throughout the overall suite */
99 #define STD_LONG_OPTS \
100 {"version",no_argument,0,'V'},\
101 {"verbose",no_argument,0,'v'},\
102 {"help",no_argument,0,'h'},\
103 {"timeout",required_argument,0,'t'},\
104 {"critical",required_argument,0,'c'},\
105 {"warning",required_argument,0,'w'},\
106 {"hostname",required_argument,0,'H'}
108 #define COPYRIGHT "Copyright (c) %s Nagios Plugin Development Team\n\
109 \t<%s>\n\n"
111 #define UT_HLP_VRS "\
112        %s (-h | --help) for detailed help\n\
113        %s (-V | --version) for version information\n"
115 #define UT_HELP_VRSN "\
116 \nOptions:\n\
117  -h, --help\n\
118     Print detailed help screen\n\
119  -V, --version\n\
120     Print version information\n"
122 #define UT_HOST_PORT "\
123  -H, --hostname=ADDRESS\n\
124     Host name or IP Address\n\
125  -%c, --port=INTEGER\n\
126     Port number (default: %s)\n"
128 #define UT_IPv46 "\
129  -4, --use-ipv4\n\
130     Use IPv4 connection\n\
131  -6, --use-ipv6\n\
132     Use IPv6 connection\n"
134 #define UT_VERBOSE "\
135  -v, --verbose\n\
136     Show details for command-line debugging (Nagios may truncate output)\n"
138 #define UT_WARN_CRIT "\
139  -w, --warning=DOUBLE\n\
140     Response time to result in warning status (seconds)\n\
141  -c, --critical=DOUBLE\n\
142     Response time to result in critical status (seconds)\n"
144 #define UT_TIMEOUT "\
145  -t, --timeout=INTEGER\n\
146     Seconds before connection times out (default: %d)\n"
148 #define UT_SUPPORT "\n\
149 Send email to nagios-users@lists.sourceforge.net if you have questions\n\
150 regarding use of this software. To submit patches or suggest improvements,\n\
151 send email to nagiosplug-devel@lists.sourceforge.net\n"
153 #define UT_NOWARRANTY "\
154 The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\n\
155 copies of the plugins under the terms of the GNU General Public License.\n\
156 For more information about these matters, see the file named COPYING.\n"