Back to index

nagios-plugins  1.4.16
utils.h
Go to the documentation of this file.
00001 #ifndef NP_UTILS_H
00002 #define NP_UTILS_H
00003 /* Header file for nagios plugins utils.c */
00004 
00005 /* This file should be included in all plugins */
00006 
00007 /* The purpose of this package is to provide safer alternatives to C
00008 functions that might otherwise be vulnerable to hacking. This
00009 currently includes a standard suite of validation routines to be sure
00010 that an string argument acually converts to its intended type and a
00011 suite of string handling routine that do their own memory management
00012 in order to resist overflow attacks. In addition, a few functions are
00013 provided to standardize version and error reporting across the entire
00014 suite of plugins. */
00015 
00016 /* now some functions etc are being defined in ../lib/utils_base.c */
00017 #include "utils_base.h"
00018 
00019 #ifdef NP_EXTRA_OPTS
00020 /* Include extra-opts functions if compiled in */
00021 #include "extra_opts.h"
00022 #else
00023 /* else, fake np_extra_opts */
00024 #define np_extra_opts(acptr,av,pr) av
00025 #endif
00026 
00027 /* Standardize version information, termination */
00028 
00029 void support (void);
00030 void print_revision (const char *, const char *);
00031 
00032 /* Handle timeouts */
00033 
00034 #ifdef LOCAL_TIMEOUT_ALARM_HANDLER
00035 extern unsigned int timeout_state;
00036 extern unsigned int timeout_interval;
00037 RETSIGTYPE timeout_alarm_handler (int);
00038 #else
00039 unsigned int timeout_state = STATE_CRITICAL;
00040 unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT;
00041 extern RETSIGTYPE timeout_alarm_handler (int);
00042 #endif
00043 
00044 time_t start_time, end_time;
00045 
00046 /* Test input types */
00047 
00048 int is_integer (char *);
00049 int is_intpos (char *);
00050 int is_intneg (char *);
00051 int is_intnonneg (char *);
00052 int is_intpercent (char *);
00053 
00054 int is_numeric (char *);
00055 int is_positive (char *);
00056 int is_negative (char *);
00057 int is_nonnegative (char *);
00058 int is_percentage (char *);
00059 
00060 int is_option (char *);
00061 
00062 /* Generalized timer that will do milliseconds if available */
00063 #ifndef HAVE_STRUCT_TIMEVAL
00064 struct timeval {
00065        long tv_sec;        /* seconds */
00066        long tv_usec;  /* microseconds */
00067 };
00068 #endif
00069 
00070 #ifndef HAVE_GETTIMEOFDAY
00071 int gettimeofday(struct timeval *, struct timezone *);
00072 #endif
00073 
00074 double delta_time (struct timeval tv);
00075 long deltime (struct timeval tv);
00076 
00077 /* Handle strings safely */
00078 
00079 void strip (char *);
00080 char *strscpy (char *, const char *);
00081 char *strnl (char *);
00082 char *strpcpy (char *, const char *, const char *);
00083 char *strpcat (char *, const char *, const char *);
00084 
00085 int max_state (int a, int b);
00086 int max_state_alt (int a, int b);
00087 
00088 void usage (const char *) __attribute__((noreturn));
00089 void usage2(const char *, const char *) __attribute__((noreturn));
00090 void usage3(const char *, int) __attribute__((noreturn));
00091 void usage4(const char *) __attribute__((noreturn));
00092 void usage5(void) __attribute__((noreturn));
00093 void usage_va(const char *fmt, ...) __attribute__((noreturn));
00094 
00095 const char *state_text (int);
00096 
00097 #define max(a,b) (((a)>(b))?(a):(b))
00098 #define min(a,b) (((a)<(b))?(a):(b))
00099 
00100 char *perfdata (const char *,
00101  long int,
00102  const char *,
00103  int,
00104  long int,
00105  int,
00106  long int,
00107  int,
00108  long int,
00109  int,
00110  long int);
00111 
00112 char *fperfdata (const char *,
00113  double,
00114  const char *,
00115  int,
00116  double,
00117  int,
00118  double,
00119  int,
00120  double,
00121  int,
00122  double);
00123 
00124 /* The idea here is that, although not every plugin will use all of these, 
00125    most will or should.  Therefore, for consistency, these very common 
00126    options should have only these meanings throughout the overall suite */
00127 
00128 #define STD_LONG_OPTS \
00129 {"version",no_argument,0,'V'},\
00130 {"verbose",no_argument,0,'v'},\
00131 {"help",no_argument,0,'h'},\
00132 {"timeout",required_argument,0,'t'},\
00133 {"critical",required_argument,0,'c'},\
00134 {"warning",required_argument,0,'w'},\
00135 {"hostname",required_argument,0,'H'}
00136 
00137 #define COPYRIGHT "Copyright (c) %s Nagios Plugin Development Team\n\
00138 \t<%s>\n\n"
00139 
00140 #define UT_HLP_VRS _("\
00141        %s (-h | --help) for detailed help\n\
00142        %s (-V | --version) for version information\n")
00143 
00144 #define UT_HELP_VRSN _("\
00145 \nOptions:\n\
00146  -h, --help\n\
00147     Print detailed help screen\n\
00148  -V, --version\n\
00149     Print version information\n")
00150 
00151 #define UT_HOST_PORT _("\
00152  -H, --hostname=ADDRESS\n\
00153     Host name, IP Address, or unix socket (must be an absolute path)\n\
00154  -%c, --port=INTEGER\n\
00155     Port number (default: %s)\n")
00156 
00157 #define UT_IPv46 _("\
00158  -4, --use-ipv4\n\
00159     Use IPv4 connection\n\
00160  -6, --use-ipv6\n\
00161     Use IPv6 connection\n")
00162 
00163 #define UT_VERBOSE _("\
00164  -v, --verbose\n\
00165     Show details for command-line debugging (Nagios may truncate output)\n")
00166 
00167 #define UT_WARN_CRIT _("\
00168  -w, --warning=DOUBLE\n\
00169     Response time to result in warning status (seconds)\n\
00170  -c, --critical=DOUBLE\n\
00171     Response time to result in critical status (seconds)\n")
00172 
00173 #define UT_WARN_CRIT_RANGE _("\
00174  -w, --warning=RANGE\n\
00175     Warning range (format: start:end). Alert if outside this range\n\
00176  -c, --critical=RANGE\n\
00177     Critical range\n")
00178 
00179 #define UT_TIMEOUT _("\
00180  -t, --timeout=INTEGER\n\
00181     Seconds before connection times out (default: %d)\n")
00182 
00183 #ifdef NP_EXTRA_OPTS
00184 #define UT_EXTRA_OPTS _("\
00185  --extra-opts=[section][@file]\n\
00186     Read options from an ini file. See http://nagiosplugins.org/extra-opts\n\
00187     for usage and examples.\n")
00188 #else
00189 #define UT_EXTRA_OPTS ""
00190 #endif
00191 
00192 #define UT_THRESHOLDS_NOTES _("\
00193  See:\n\
00194  http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT\n\
00195  for THRESHOLD format and examples.\n")
00196 
00197 #define UT_SUPPORT _("\n\
00198 Send email to nagios-users@lists.sourceforge.net if you have questions\n\
00199 regarding use of this software. To submit patches or suggest improvements,\n\
00200 send email to nagiosplug-devel@lists.sourceforge.net\n\n")
00201 
00202 #define UT_NOWARRANTY _("\n\
00203 The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\n\
00204 copies of the plugins under the terms of the GNU General Public License.\n\
00205 For more information about these matters, see the file named COPYING.\n")
00206 
00207 #endif /* NP_UTILS_H */