Code

Strip leading spaces on dns return value (689563 - Simon L Nielsen)
[nagiosplug.git] / plugins / utils.h.in
index a21d63d6c3bcc342dea89b98a7173e088c3267ae..317ec46fba6cbd9ebc625b8b7a15e9129766be18 100644 (file)
@@ -1,4 +1,4 @@
-/* header file for nagios plugins uitls.c */
+/* header file for nagios plugins utils.c */
 
 /* this file should be included in all plugins */
 
@@ -16,7 +16,7 @@ suite of plugins. */
 char *my_basename (char *);
 void support (void);
 char *clean_revstring (const char *revstring);
-void print_revision (char *, const char *);
+void print_revision (const char *, const char *);
 void terminate (int result, char *msg, ...);
 extern RETSIGTYPE timeout_alarm_handler (int);
 
@@ -45,48 +45,57 @@ int is_percentage (char *);
 
 int is_option (char *);
 
+/* generalized timer that will do milliseconds if available */
+#ifndef HAVE_STRUCT_TIMEVAL
+struct timeval {
+       long tv_sec;        /* seconds */
+       long tv_usec;  /* microseconds */
+};
+#endif
+
+#ifndef HAVE_GETTIMEOFDAY
+int gettimeofday(struct timeval *tv, struct timezone *tz);
+#endif
+
+double delta_time (struct timeval tv);
+
 /* Handle strings safely */
 
 void strip (char *buffer);
 char *strscpy (char *dest, char *src);
 char *strscat (char *dest, char *src);
 char *strnl (char *str);
-char *ssprintf (char *str, const char *fmt, ...);
+char *ssprintf (char *str, const char *fmt, ...); /* deprecate for asprintf */
 char *strpcpy (char *dest, const char *src, const char *str);
 char *strpcat (char *dest, const char *src, const char *str);
 
-#define max(a,b) ((a)>(b))?(a):(b)
+int max_state (int a, int b);
 
-#define usage(msg) {\
-  printf(msg);\
-  print_usage();\
-exit(STATE_UNKNOWN);\
-}
+void usage (char *msg);
+void usage2(char *msg, char *arg);
+void usage3(char *msg, char arg);
 
-#define usage2(msg,arg) {\
-  printf("%s: %s - %s\n",PROGNAME,msg,arg);\
-  print_usage();\
-  exit(STATE_UNKNOWN);\
-}
+
+#define max(a,b) (((a)>(b))?(a):(b))
 
 #define state_text(a) \
 (a)==0?"OK":\
 (a)==1?"WARNING":\
 (a)==2?"CRITICAL":\
-(a)==-2?"DEPENDENT":\
+(a)==3?"UNKNOWN":\
+(a)==4?"DEPENDENT":\
 "UNKNOWN"
 
 /* The idea here is that, although not every plugin will use all of these, 
    most will or should.  Therefore, for consistency, these very common 
    options should have only these meanings throughout the overall suite */
 
-#define STD_OPTS "Vvht:c:w:H:F:"
-#define STD_OPTS_LONG \
+#define STD_LONG_OPTS \
 {"version",no_argument,0,'V'},\
 {"verbose",no_argument,0,'v'},\
 {"help",no_argument,0,'h'},\
 {"timeout",required_argument,0,'t'},\
 {"critical",required_argument,0,'c'},\
 {"warning",required_argument,0,'w'},\
-{"hostname",required_argument,0,'H'},\
-{"file",required_argument,0,'F'}
+{"hostname",required_argument,0,'H'}
+