Przeglądaj źródła

make state_text a function

git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@440 f882894a-f735-0410-b71e-b25c423dba1c
Karl DeBisschop 23 lat temu
rodzic
commit
4f29ac7115
2 zmienionych plików z 33 dodań i 9 usunięć
  1. 31 1
      plugins/utils.c
  2. 2 8
      plugins/utils.h

+ 31 - 1
plugins/utils.c

@@ -24,7 +24,8 @@ extern const char *progname;
 void support (void);
 void support (void);
 char *clean_revstring (const char *);
 char *clean_revstring (const char *);
 void print_revision (const char *, const char *);
 void print_revision (const char *, const char *);
-void terminate (int, const char *fmt, ...);
+void die (int result, const char *fmt, ...);
+void terminate (int result, const char *fmt, ...);
 RETSIGTYPE timeout_alarm_handler (int);
 RETSIGTYPE timeout_alarm_handler (int);
 
 
 int is_integer (char *);
 int is_integer (char *);
@@ -50,6 +51,8 @@ char *strnl (char *str);
 char *strpcpy (char *dest, const char *src, const char *str);
 char *strpcpy (char *dest, const char *src, const char *str);
 char *strpcat (char *dest, const char *src, const char *str);
 char *strpcat (char *dest, const char *src, const char *str);
 
 
+char *state_text (int result);
+
 #define LABELLEN 63
 #define LABELLEN 63
 #define STRLEN 64
 #define STRLEN 64
 #define TXTBLK 128
 #define TXTBLK 128
@@ -140,6 +143,33 @@ print_revision (const char *command_name, const char *revision_string)
 
 
 }
 }
 
 
+char *
+state_text (int result)
+{
+	switch (result) {
+	case STATE_OK:
+		return "OK";
+	case STATE_WARNING:
+		return "WARNING";
+	case STATE_CRITICAL:
+		return "CRITICAL";
+	case STATE_DEPENDENT:
+		return "DEPENDENT";
+	default:
+		return "UNKNOWN";
+	}
+}
+
+void
+die (int result, const char *fmt, ...)
+{
+	printf ("%s %s: ", sizeof (char) + index(progname, '_'), state_text(result));
+	va_list ap;
+	va_start (ap, fmt);
+	vprintf (fmt, ap);
+	va_end (ap);
+	exit (result);
+}
 
 
 void
 void
 terminate (int result, const char *fmt, ...)
 terminate (int result, const char *fmt, ...)

+ 2 - 8
plugins/utils.h

@@ -17,6 +17,7 @@ char *my_basename (char *);
 void support (void);
 void support (void);
 char *clean_revstring (const char *revstring);
 char *clean_revstring (const char *revstring);
 void print_revision (const char *, const char *);
 void print_revision (const char *, const char *);
+void die (int result, const char *fmt, ...);
 void terminate (int result, char *msg, ...);
 void terminate (int result, char *msg, ...);
 extern RETSIGTYPE timeout_alarm_handler (int);
 extern RETSIGTYPE timeout_alarm_handler (int);
 
 
@@ -71,17 +72,10 @@ void usage (char *msg);
 void usage2(char *msg, char *arg);
 void usage2(char *msg, char *arg);
 void usage3(char *msg, char arg);
 void usage3(char *msg, char arg);
 
 
+char *state_text (int result);
 
 
 #define max(a,b) (((a)>(b))?(a):(b))
 #define max(a,b) (((a)>(b))?(a):(b))
 
 
-#define state_text(a) \
-(a)==0?"OK":\
-(a)==1?"WARNING":\
-(a)==2?"CRITICAL":\
-(a)==3?"UNKNOWN":\
-(a)==4?"DEPENDENT":\
-"UNKNOWN"
-
 /* The idea here is that, although not every plugin will use all of these, 
 /* The idea here is that, although not every plugin will use all of these, 
    most will or should.  Therefore, for consistency, these very common 
    most will or should.  Therefore, for consistency, these very common 
    options should have only these meanings throughout the overall suite */
    options should have only these meanings throughout the overall suite */