diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-03-19 13:01:05 +0000 |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-03-19 13:01:05 +0000 |
commit | 4f29ac7115a5852a747242fc7973a6137817c3df (patch) | |
tree | cc5fcb8d542ed67ffd3a25057292e4ba20924f6b /plugins | |
parent | 8535da68ef4fdd8ccebc9a0fe72bf3bf61e71f65 (diff) | |
download | monitoring-plugins-4f29ac7115a5852a747242fc7973a6137817c3df.tar.gz |
make state_text a function
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@440 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/utils.c | 32 | ||||
-rw-r--r-- | plugins/utils.h | 10 |
2 files changed, 33 insertions, 9 deletions
diff --git a/plugins/utils.c b/plugins/utils.c index e204e238..b35b78af 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
@@ -24,7 +24,8 @@ extern const char *progname; | |||
24 | void support (void); | 24 | void support (void); |
25 | char *clean_revstring (const char *); | 25 | char *clean_revstring (const char *); |
26 | void print_revision (const char *, const char *); | 26 | void print_revision (const char *, const char *); |
27 | void terminate (int, const char *fmt, ...); | 27 | void die (int result, const char *fmt, ...); |
28 | void terminate (int result, const char *fmt, ...); | ||
28 | RETSIGTYPE timeout_alarm_handler (int); | 29 | RETSIGTYPE timeout_alarm_handler (int); |
29 | 30 | ||
30 | int is_integer (char *); | 31 | int is_integer (char *); |
@@ -50,6 +51,8 @@ char *strnl (char *str); | |||
50 | char *strpcpy (char *dest, const char *src, const char *str); | 51 | char *strpcpy (char *dest, const char *src, const char *str); |
51 | char *strpcat (char *dest, const char *src, const char *str); | 52 | char *strpcat (char *dest, const char *src, const char *str); |
52 | 53 | ||
54 | char *state_text (int result); | ||
55 | |||
53 | #define LABELLEN 63 | 56 | #define LABELLEN 63 |
54 | #define STRLEN 64 | 57 | #define STRLEN 64 |
55 | #define TXTBLK 128 | 58 | #define TXTBLK 128 |
@@ -140,6 +143,33 @@ print_revision (const char *command_name, const char *revision_string) | |||
140 | 143 | ||
141 | } | 144 | } |
142 | 145 | ||
146 | char * | ||
147 | state_text (int result) | ||
148 | { | ||
149 | switch (result) { | ||
150 | case STATE_OK: | ||
151 | return "OK"; | ||
152 | case STATE_WARNING: | ||
153 | return "WARNING"; | ||
154 | case STATE_CRITICAL: | ||
155 | return "CRITICAL"; | ||
156 | case STATE_DEPENDENT: | ||
157 | return "DEPENDENT"; | ||
158 | default: | ||
159 | return "UNKNOWN"; | ||
160 | } | ||
161 | } | ||
162 | |||
163 | void | ||
164 | die (int result, const char *fmt, ...) | ||
165 | { | ||
166 | printf ("%s %s: ", sizeof (char) + index(progname, '_'), state_text(result)); | ||
167 | va_list ap; | ||
168 | va_start (ap, fmt); | ||
169 | vprintf (fmt, ap); | ||
170 | va_end (ap); | ||
171 | exit (result); | ||
172 | } | ||
143 | 173 | ||
144 | void | 174 | void |
145 | terminate (int result, const char *fmt, ...) | 175 | terminate (int result, const char *fmt, ...) |
diff --git a/plugins/utils.h b/plugins/utils.h index 43b612c1..b345f7a2 100644 --- a/plugins/utils.h +++ b/plugins/utils.h | |||
@@ -17,6 +17,7 @@ char *my_basename (char *); | |||
17 | void support (void); | 17 | void support (void); |
18 | char *clean_revstring (const char *revstring); | 18 | char *clean_revstring (const char *revstring); |
19 | void print_revision (const char *, const char *); | 19 | void print_revision (const char *, const char *); |
20 | void die (int result, const char *fmt, ...); | ||
20 | void terminate (int result, char *msg, ...); | 21 | void terminate (int result, char *msg, ...); |
21 | extern RETSIGTYPE timeout_alarm_handler (int); | 22 | extern RETSIGTYPE timeout_alarm_handler (int); |
22 | 23 | ||
@@ -71,17 +72,10 @@ void usage (char *msg); | |||
71 | void usage2(char *msg, char *arg); | 72 | void usage2(char *msg, char *arg); |
72 | void usage3(char *msg, char arg); | 73 | void usage3(char *msg, char arg); |
73 | 74 | ||
75 | char *state_text (int result); | ||
74 | 76 | ||
75 | #define max(a,b) (((a)>(b))?(a):(b)) | 77 | #define max(a,b) (((a)>(b))?(a):(b)) |
76 | 78 | ||
77 | #define state_text(a) \ | ||
78 | (a)==0?"OK":\ | ||
79 | (a)==1?"WARNING":\ | ||
80 | (a)==2?"CRITICAL":\ | ||
81 | (a)==3?"UNKNOWN":\ | ||
82 | (a)==4?"DEPENDENT":\ | ||
83 | "UNKNOWN" | ||
84 | |||
85 | /* The idea here is that, although not every plugin will use all of these, | 79 | /* The idea here is that, although not every plugin will use all of these, |
86 | most will or should. Therefore, for consistency, these very common | 80 | most will or should. Therefore, for consistency, these very common |
87 | options should have only these meanings throughout the overall suite */ | 81 | options should have only these meanings throughout the overall suite */ |