Code

markup 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 char *my_basename (char *);
17 void support (void);
18 char *clean_revstring (const char *revstring);
19 void print_revision (const char *, const char *);
20 void die (int result, const char *fmt, ...);
21 void terminate (int result, char *msg, ...);
22 extern RETSIGTYPE timeout_alarm_handler (int);
24 /* Handle timeouts */
26 time_t start_time, end_time;
27 int timeout_interval = DEFAULT_SOCKET_TIMEOUT;
29 /* Test input types */
31 int is_integer (char *);
32 int is_intpos (char *);
33 int is_intneg (char *);
34 int is_intnonneg (char *);
35 int is_intpercent (char *);
37 int is_numeric (char *);
38 int is_positive (char *);
39 int is_negative (char *);
40 int is_nonnegative (char *);
41 int is_percentage (char *);
43 int is_option (char *);
45 /* generalized timer that will do milliseconds if available */
46 #ifndef HAVE_STRUCT_TIMEVAL
47 struct timeval {
48         long tv_sec;        /* seconds */
49         long tv_usec;  /* microseconds */
50 };
51 #endif
53 #ifndef HAVE_GETTIMEOFDAY
54 int gettimeofday(struct timeval *tv, struct timezone *tz);
55 #endif
57 double delta_time (struct timeval tv);
59 /* Handle strings safely */
61 void strip (char *buffer);
62 char *strscpy (char *dest, char *src);
63 char *strscat (char *dest, char *src);
64 char *strnl (char *str);
65 char *ssprintf (char *str, const char *fmt, ...); /* deprecate for asprintf */
66 char *strpcpy (char *dest, const char *src, const char *str);
67 char *strpcat (char *dest, const char *src, const char *str);
69 int max_state (int a, int b);
71 void usage (char *msg);
72 void usage2(char *msg, char *arg);
73 void usage3(char *msg, char arg);
75 char *state_text (int result);
77 #define max(a,b) (((a)>(b))?(a):(b))
79 /* The idea here is that, although not every plugin will use all of these, 
80    most will or should.  Therefore, for consistency, these very common 
81    options should have only these meanings throughout the overall suite */
83 #define STD_LONG_OPTS \
84 {"version",no_argument,0,'V'},\
85 {"verbose",no_argument,0,'v'},\
86 {"help",no_argument,0,'h'},\
87 {"timeout",required_argument,0,'t'},\
88 {"critical",required_argument,0,'c'},\
89 {"warning",required_argument,0,'w'},\
90 {"hostname",required_argument,0,'H'}
92 #define COPYRIGHT "Copyright (c) %s Nagios Plugin Development Team\n\
93 \t<%s>\n\n"
95 #define HELP_VRSN "\
96 \nOptions:\n\
97  -h, --help\n\
98     Print detailed help screen\n\
99  -V, --version\n\
100     Print version information\n"
102 #define HOST_PORT "\
103  -H, --hostname=ADDRESS\n\
104     Host name or IP Address\n\
105  -%c, --port=INTEGER\n\
106     Port number (default: %s)\n"
108 #define IPv46 "\
109  -4, --use-ipv4\n\
110     Use IPv4 connection\n\
111  -6, --use-ipv6\n\
112     Use IPv6 connection\n"
114 #define VRBS "\
115  -v, --verbose\n\
116     Show details for command-line debugging (Nagios may truncate output)\n"
118 #define WARN_CRIT_TO "\
119  -w, --warning=DOUBLE\n\
120     Response time to result in warning status (seconds)\n\
121  -c, --critical=DOUBLE\n\
122     Response time to result in critical status (seconds)\n\
123  -t, --timeout=INTEGER\n\
124     Seconds before connection times out (default: %d)\n"