Code

markupf for translation
[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 alternantives 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 accross 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, ...);
20 void terminate (int result, const char *msg, ...);
22 /* Handle timeouts */
24 #ifdef LOCAL_TIMEOUT_ALARM_HANDLER
25 extern int timeout_interval;
26 RETSIGTYPE timeout_alarm_handler (int);
27 #else
28 int timeout_interval = DEFAULT_SOCKET_TIMEOUT;
29 extern RETSIGTYPE timeout_alarm_handler (int);
30 #endif
32 time_t start_time, end_time;
34 /* Test input types */
36 int is_integer (char *);
37 int is_intpos (char *);
38 int is_intneg (char *);
39 int is_intnonneg (char *);
40 int is_intpercent (char *);
42 int is_numeric (char *);
43 int is_positive (char *);
44 int is_negative (char *);
45 int is_nonnegative (char *);
46 int is_percentage (char *);
48 int is_option (char *);
50 /* generalized timer that will do milliseconds if available */
51 #ifndef HAVE_STRUCT_TIMEVAL
52 struct timeval {
53         long tv_sec;        /* seconds */
54         long tv_usec;  /* microseconds */
55 };
56 #endif
58 #ifndef HAVE_GETTIMEOFDAY
59 int gettimeofday(struct timeval *tv, struct timezone *tz);
60 #endif
62 double delta_time (struct timeval tv);
64 /* Handle strings safely */
66 void strip (char *buffer);
67 char *strscpy (char *dest, const char *src);
68 char *strscat (char *dest, const char *src);
69 char *strnl (char *str);
70 char *ssprintf (char *str, const char *fmt, ...); /* deprecate for asprintf */
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 (char *msg);
77 void usage2(char *msg, char *arg);
78 void usage3(char *msg, char arg);
80 char *state_text (int result);
82 #define max(a,b) (((a)>(b))?(a):(b))
84 /* The idea here is that, although not every plugin will use all of these, 
85    most will or should.  Therefore, for consistency, these very common 
86    options should have only these meanings throughout the overall suite */
88 #define STD_LONG_OPTS \
89 {"version",no_argument,0,'V'},\
90 {"verbose",no_argument,0,'v'},\
91 {"help",no_argument,0,'h'},\
92 {"timeout",required_argument,0,'t'},\
93 {"critical",required_argument,0,'c'},\
94 {"warning",required_argument,0,'w'},\
95 {"hostname",required_argument,0,'H'}
97 #define COPYRIGHT "Copyright (c) %s Nagios Plugin Development Team\n\
98 \t<%s>\n\n"
100 #define UT_HLP_VRS "\
101        %s (-h | --help) for detailed help\n\
102        %s (-V | --version) for version information\n"
104 #define UT_HELP_VRSN "\
105 \nOptions:\n\
106  -h, --help\n\
107     Print detailed help screen\n\
108  -V, --version\n\
109     Print version information\n"
111 #define UT_HOST_PORT "\
112  -H, --hostname=ADDRESS\n\
113     Host name or IP Address\n\
114  -%c, --port=INTEGER\n\
115     Port number (default: %s)\n"
117 #define UT_IPv46 "\
118  -4, --use-ipv4\n\
119     Use IPv4 connection\n\
120  -6, --use-ipv6\n\
121     Use IPv6 connection\n"
123 #define UT_VERBOSE "\
124  -v, --verbose\n\
125     Show details for command-line debugging (Nagios may truncate output)\n"
127 #define UT_WARN_CRIT "\
128  -w, --warning=DOUBLE\n\
129     Response time to result in warning status (seconds)\n\
130  -c, --critical=DOUBLE\n\
131     Response time to result in critical status (seconds)\n"
133 #define UT_TIMEOUT "\
134  -t, --timeout=INTEGER\n\
135     Seconds before connection times out (default: %d)\n"
137 #define UT_SUPPORT "\n\
138 Send email to nagios-users@lists.sourceforge.net if you have questions\n\
139 regarding use of this software. To submit patches or suggest improvements,\n\
140 send email to nagiosplug-devel@lists.sourceforge.net\n"
142 #define UT_NOWARRANTY "\
143 The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\n\
144 copies of the plugins under the terms of the GNU General Public License.\n\
145 For more information about these matters, see the file named COPYING.\n"