Code

Fix translations when extra-opts aren't enabled
[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 /* now some functions etc are being defined in ../lib/utils_base.c */
17 #include "utils_base.h"
19 #ifdef NP_EXTRA_OPTS
20 /* Include extra-opts functions if compiled in */
21 #include "extra_opts.h"
22 #else
23 /* else, fake np_extra_opts */
24 #define np_extra_opts(acptr,av,pr) av
25 #endif
27 /* Standardize version information, termination */
29 void support (void);
30 void print_revision (const char *, const char *);
32 /* Handle timeouts */
34 #ifdef LOCAL_TIMEOUT_ALARM_HANDLER
35 extern unsigned int timeout_state;
36 extern unsigned int timeout_interval;
37 RETSIGTYPE timeout_alarm_handler (int);
38 #else
39 unsigned int timeout_state = STATE_CRITICAL;
40 unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT;
41 extern RETSIGTYPE timeout_alarm_handler (int);
42 #endif
44 time_t start_time, end_time;
46 /* Test input types */
48 int is_integer (char *);
49 int is_intpos (char *);
50 int is_intneg (char *);
51 int is_intnonneg (char *);
52 int is_intpercent (char *);
54 int is_numeric (char *);
55 int is_positive (char *);
56 int is_negative (char *);
57 int is_nonnegative (char *);
58 int is_percentage (char *);
60 int is_option (char *);
62 /* Generalized timer that will do milliseconds if available */
63 #ifndef HAVE_STRUCT_TIMEVAL
64 struct timeval {
65         long tv_sec;        /* seconds */
66         long tv_usec;  /* microseconds */
67 };
68 #endif
70 #ifndef HAVE_GETTIMEOFDAY
71 int gettimeofday(struct timeval *, struct timezone *);
72 #endif
74 double delta_time (struct timeval tv);
75 long deltime (struct timeval tv);
77 /* Handle strings safely */
79 void strip (char *);
80 char *strscpy (char *, const char *);
81 char *strnl (char *);
82 char *strpcpy (char *, const char *, const char *);
83 char *strpcat (char *, const char *, const char *);
85 int max_state (int a, int b);
86 int max_state_alt (int a, int b);
88 void usage (const char *) __attribute__((noreturn));
89 void usage2(const char *, const char *) __attribute__((noreturn));
90 void usage3(const char *, int) __attribute__((noreturn));
91 void usage4(const char *) __attribute__((noreturn));
92 void usage5(void) __attribute__((noreturn));
93 void usage_va(const char *fmt, ...) __attribute__((noreturn));
95 const char *state_text (int);
97 #define max(a,b) (((a)>(b))?(a):(b))
98 #define min(a,b) (((a)<(b))?(a):(b))
100 char *perfdata (const char *,
101  long int,
102  const char *,
103  int,
104  long int,
105  int,
106  long int,
107  int,
108  long int,
109  int,
110  long int);
112 char *fperfdata (const char *,
113  double,
114  const char *,
115  int,
116  double,
117  int,
118  double,
119  int,
120  double,
121  int,
122  double);
124 /* The idea here is that, although not every plugin will use all of these, 
125    most will or should.  Therefore, for consistency, these very common 
126    options should have only these meanings throughout the overall suite */
128 #define STD_LONG_OPTS \
129 {"version",no_argument,0,'V'},\
130 {"verbose",no_argument,0,'v'},\
131 {"help",no_argument,0,'h'},\
132 {"timeout",required_argument,0,'t'},\
133 {"critical",required_argument,0,'c'},\
134 {"warning",required_argument,0,'w'},\
135 {"hostname",required_argument,0,'H'}
137 #define COPYRIGHT "Copyright (c) %s Nagios Plugin Development Team\n\
138 \t<%s>\n\n"
140 #define UT_HLP_VRS _("\
141        %s (-h | --help) for detailed help\n\
142        %s (-V | --version) for version information\n")
144 #define UT_HELP_VRSN _("\
145 \nOptions:\n\
146  -h, --help\n\
147     Print detailed help screen\n\
148  -V, --version\n\
149     Print version information\n")
151 #define UT_HOST_PORT _("\
152  -H, --hostname=ADDRESS\n\
153     Host name, IP Address, or unix socket (must be an absolute path)\n\
154  -%c, --port=INTEGER\n\
155     Port number (default: %s)\n")
157 #define UT_IPv46 _("\
158  -4, --use-ipv4\n\
159     Use IPv4 connection\n\
160  -6, --use-ipv6\n\
161     Use IPv6 connection\n")
163 #define UT_VERBOSE _("\
164  -v, --verbose\n\
165     Show details for command-line debugging (Nagios may truncate output)\n")
167 #define UT_WARN_CRIT _("\
168  -w, --warning=DOUBLE\n\
169     Response time to result in warning status (seconds)\n\
170  -c, --critical=DOUBLE\n\
171     Response time to result in critical status (seconds)\n")
173 #define UT_WARN_CRIT_RANGE _("\
174  -w, --warning=RANGE\n\
175     Warning range (format: start:end). Alert if outside this range\n\
176  -c, --critical=RANGE\n\
177     Critical range\n")
179 #define UT_TIMEOUT _("\
180  -t, --timeout=INTEGER\n\
181     Seconds before connection times out (default: %d)\n")
183 #ifdef NP_EXTRA_OPTS
184 #define UT_EXTRA_OPTS _("\
185  --extra-opts=[section][@file]\n\
186     Read additionnal options from ini file\n")
187 #define UT_EXTRA_OPTS_NOTES _("\
188  See: http://nagiosplugins.org/extra-opts for --extra-opts usage and examples.\n")
189 #else
190 #define UT_EXTRA_OPTS ""
191 #define UT_EXTRA_OPTS_NOTES ""
192 #endif
194 #define UT_THRESHOLDS_NOTES _("\
195  See:\n\
196  http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT\n\
197  for THRESHOLD format and examples.\n")
199 #define UT_SUPPORT _("\n\
200 Send email to nagios-users@lists.sourceforge.net if you have questions\n\
201 regarding use of this software. To submit patches or suggest improvements,\n\
202 send email to nagiosplug-devel@lists.sourceforge.net\n\n")
204 #define UT_NOWARRANTY _("\n\
205 The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\n\
206 copies of the plugins under the terms of the GNU General Public License.\n\
207 For more information about these matters, see the file named COPYING.\n")
209 #endif /* NP_UTILS_H */