summaryrefslogtreecommitdiffstats
path: root/web/attachments/121772-nagiosplug-cvs-timeout_status.diff
diff options
context:
space:
mode:
Diffstat (limited to 'web/attachments/121772-nagiosplug-cvs-timeout_status.diff')
-rw-r--r--web/attachments/121772-nagiosplug-cvs-timeout_status.diff208
1 files changed, 208 insertions, 0 deletions
diff --git a/web/attachments/121772-nagiosplug-cvs-timeout_status.diff b/web/attachments/121772-nagiosplug-cvs-timeout_status.diff
new file mode 100644
index 0000000..cf1e66a
--- /dev/null
+++ b/web/attachments/121772-nagiosplug-cvs-timeout_status.diff
@@ -0,0 +1,208 @@
1diff -urN ./plugins/check_nt.c ../plugins/plugins/check_nt.c
2--- ./plugins/check_nt.c 2005-01-24 08:29:53.000000000 +0100
3+++ ../plugins/plugins/check_nt.c 2005-02-17 12:26:57.000000000 +0100
4@@ -35,6 +35,9 @@
5 const char *copyright = "2003-2004";
6 const char *email = "nagiosplug-devel@lists.sourceforge.net";
7
8+extern const char *status_strings;
9+extern int timeout_status;
10+
11 #include "common.h"
12 #include "netutils.h"
13 #include "utils.h"
14@@ -454,6 +457,7 @@
15 {"hostname", required_argument,0,'H'},
16 {"version", no_argument, 0,'V'},
17 {"help", no_argument, 0,'h'},
18+ {"timeout-status", required_argument, 0, 'T'},
19 {0,0,0,0}
20 };
21
22@@ -478,7 +482,7 @@
23 }
24
25 while (1){
26- c = getopt_long(argc,argv,"+hVH:t:c:w:p:v:l:s:d:",longopts,&option);
27+ c = getopt_long(argc,argv,"+hVH:t:c:w:p:v:l:s:d:T:",longopts,&option);
28
29 if (c==-1||c==EOF||c==1)
30 break;
31@@ -549,8 +553,11 @@
32 socket_timeout=atoi(optarg);
33 if(socket_timeout<=0)
34 return ERROR;
35+ break;
36+ case 'T':
37+ if(set_timeout_status(optarg) == ERROR) return ERROR;
38+ break;
39 }
40-
41 }
42
43 if (vars_to_check==CHECK_NONE)
44diff -urN ./plugins/common.h ../plugins/plugins/common.h
45--- ./plugins/common.h 2004-12-10 11:42:00.000000000 +0100
46+++ ../plugins/plugins/common.h 2005-02-17 12:26:57.000000000 +0100
47@@ -157,8 +157,13 @@
48 ERROR = -1
49 };
50
51-/* AIX seems to have this defined somewhere else */
52-#ifndef FALSE
53+/* AIX seems to have FALSE defined somewhere else, so make sure
54+ * TRUE means something else (we assume it does if it's already defined) */
55+#ifdef FALSE
56+# ifndef TRUE
57+# define TRUE (FALSE ^ 1)
58+# endif
59+#else
60 enum {
61 FALSE,
62 TRUE
63@@ -170,7 +175,8 @@
64 STATE_WARNING,
65 STATE_CRITICAL,
66 STATE_UNKNOWN,
67- STATE_DEPENDENT
68+ STATE_DEPENDENT,
69+ STATE_OOB /* result out of bounds (keep last in list!) */
70 };
71
72 enum {
73diff -urN ./plugins/netutils.c ../plugins/plugins/netutils.c
74--- ./plugins/netutils.c 2005-01-05 21:53:22.000000000 +0100
75+++ ../plugins/plugins/netutils.c 2005-02-17 12:34:23.000000000 +0100
76@@ -38,18 +38,23 @@
77 int econn_refuse_state = STATE_CRITICAL;
78 int was_refused = FALSE;
79 int address_family = AF_UNSPEC;
80+extern char *status_strings;
81+extern int timeout_status;
82
83 static int my_connect(const char *address, int port, int *sd, int proto);
84 /* handles socket timeouts */
85 void
86 socket_timeout_alarm_handler (int sig)
87 {
88- if (sig == SIGALRM)
89- printf (_("CRITICAL - Socket timeout after %d seconds\n"), socket_timeout);
90- else
91- printf (_("CRITICAL - Abnormal timeout after %d seconds\n"), socket_timeout);
92+ /* this can only happen with poorly written plugins, so chalk
93+ * it up as input validation error and return STATE_UNKNOWN */
94+ if(timeout_status < 0 || timeout_status >= STATE_OOB)
95+ timeout_status = STATE_UNKNOWN;
96
97- exit (STATE_CRITICAL);
98+ printf (_("%s - Socket timeout after %d seconds\n"),
99+ status_strings[timeout_status], socket_timeout);
100+
101+ exit (timeout_status);
102 }
103
104
105diff -urN ./plugins/utils.c ../plugins/plugins/utils.c
106--- ./plugins/utils.c 2005-01-05 21:53:23.000000000 +0100
107+++ ../plugins/plugins/utils.c 2005-02-17 12:26:57.000000000 +0100
108@@ -23,6 +23,20 @@
109 extern void print_usage (void);
110 extern const char *progname;
111
112+/* NULL-terminate these arrays just to be prudent
113+ * It's a bit faster and a lot more portable to use two separate
114+ * arrays for this, as we don't need to rely on strcasecmp being available
115+ */
116+const char *status_strings[] = {
117+ "OK", "WARNING", "CRITICAL", "UNKNOWN", "DEPENDENT", NULL
118+};
119+const char *lowercase_status_strings[] = {
120+ "ok", "warning", "critical", "unknown", "dependent", NULL
121+};
122+/* plugins may set this themselves, so export it from here
123+ * and have the plugins import it explicitly as extern */
124+int timeout_status = STATE_CRITICAL;
125+
126 #define STRLEN 64
127 #define TXTBLK 128
128
129@@ -105,18 +119,10 @@
130 const char *
131 state_text (int result)
132 {
133- switch (result) {
134- case STATE_OK:
135- return "OK";
136- case STATE_WARNING:
137- return "WARNING";
138- case STATE_CRITICAL:
139- return "CRITICAL";
140- case STATE_DEPENDENT:
141- return "DEPENDENT";
142- default:
143+ if(result < 0 || result >= STATE_OOB)
144 return "UNKNOWN";
145- }
146+
147+ return status_strings[result];
148 }
149
150 void
151@@ -129,14 +135,54 @@
152 exit (result);
153 }
154
155+int
156+set_timeout_status(const char *arg)
157+{
158+ int i;
159+
160+ timeou_status = -1;
161+ for(i = 0; status_strings[i],lowercase_status_strings[i]; i++) {
162+ if(status_strings[i][0] = arg[0] ||
163+ lowercase_status_strings[i][0] = arg[0])
164+ {
165+ timeout_status = i;
166+ break;
167+ }
168+
169+ if(timeout_status != -1) return OK;
170+
171+ errno = 0;
172+ timeout_status = (int)strtol(arg, NULL, 0);
173+ if(timeout_status < STATE_OK || timeout_status >= STATE_OOB ||
174+ (!timeout_status && errno))
175+ {
176+ timeout_status = STATE_UNKNOWN;
177+ return ERROR;
178+ }
179+ }
180+
181+ return OK;
182+}
183+
184+
185 void
186 timeout_alarm_handler (int signo)
187 {
188+ /* don't segfault if someone stupid has set this arbitrarily */
189+ if(timeout_status < 0 || timeout_status >= STATE_OOB)
190+ timeout_status = STATE_UNKNOWN;
191+
192 if (signo == SIGALRM) {
193- printf (_("CRITICAL - Plugin timed out after %d seconds\n"),
194- timeout_interval);
195- exit (STATE_CRITICAL);
196+ printf (_("%s - Plugin timed out after %d seconds\n"),
197+ status_strings[timeout_status], timeout_interval);
198+ exit (timeout_status);
199 }
200+
201+ /* fallthrough so we print something in case some stupid plugin
202+ * contributor has set this function to the catch-all sighandler */
203+ printf(_("Caught signal %d in timeout_alarm_handler (bad coding).\n"),
204+ signo);
205+ exit(STATE_UNKNOWN);
206 }
207
208 int