summaryrefslogtreecommitdiffstats
path: root/web/attachments/317729-check_snmp.patch
diff options
context:
space:
mode:
Diffstat (limited to 'web/attachments/317729-check_snmp.patch')
-rw-r--r--web/attachments/317729-check_snmp.patch406
1 files changed, 406 insertions, 0 deletions
diff --git a/web/attachments/317729-check_snmp.patch b/web/attachments/317729-check_snmp.patch
new file mode 100644
index 0000000..63ae35f
--- /dev/null
+++ b/web/attachments/317729-check_snmp.patch
@@ -0,0 +1,406 @@
1Index: plugins/check_snmp.c
2===================================================================
3--- plugins/check_snmp.c (revision 2160)
4+++ plugins/check_snmp.c (working copy)
5@@ -34,7 +34,7 @@
6
7 #include "common.h"
8 #include "utils.h"
9-#include "popen.h"
10+#include "utils_cmd.h"
11
12 #define DEFAULT_COMMUNITY "public"
13 #define DEFAULT_PORT "161"
14@@ -91,14 +91,14 @@
15 regmatch_t pmatch[10];
16 char timestamp[10] = "";
17 char errbuf[MAX_INPUT_BUFFER] = "";
18-char perfstr[MAX_INPUT_BUFFER] = "";
19+char perfstr[MAX_INPUT_BUFFER] = "| ";
20 int cflags = REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
21 int eflags = 0;
22 int errcode, excode;
23
24 char *server_address = NULL;
25 char *community = NULL;
26-char *authpriv = NULL;
27+char **authpriv = NULL;
28 char *proto = NULL;
29 char *seclevel = NULL;
30 char *secname = NULL;
31@@ -106,10 +106,11 @@
32 char *privproto = NULL;
33 char *authpasswd = NULL;
34 char *privpasswd = NULL;
35-char *oid;
36+char **oids = NULL;
37 char *label;
38 char *units;
39 char *port;
40+char *snmpcmd;
41 char string_value[MAX_INPUT_BUFFER] = "";
42 char **labels = NULL;
43 char **unitv = NULL;
44@@ -117,6 +118,8 @@
45 size_t labels_size = 8;
46 size_t nunits = 0;
47 size_t unitv_size = 8;
48+int numoids = 0;
49+int numauthpriv = 0;
50 int verbose = FALSE;
51 int usesnmpgetnext = FALSE;
52 unsigned long long lower_warn_lim[MAX_OIDS];
53@@ -139,18 +142,16 @@
54 {
55 int i = 0;
56 int iresult = STATE_UNKNOWN;
57- int found = 0;
58- int result = STATE_DEPENDENT;
59- char input_buffer[MAX_INPUT_BUFFER];
60- char *command_line = NULL;
61+ int result = STATE_UNKNOWN;
62+ char **command_line = NULL;
63 char *cl_hidden_auth = NULL;
64+ char *oidname = NULL;
65 char *response = NULL;
66 char *outbuff;
67- char *output;
68 char *ptr = NULL;
69- char *p2 = NULL;
70 char *show = NULL;
71 char type[8] = "";
72+ output chld_out, chld_err;
73
74 setlocale (LC_ALL, "");
75 bindtextdomain (PACKAGE, LOCALEDIR);
76@@ -162,12 +163,10 @@
77 eval_method[i] = CHECK_UNDEF;
78 i = 0;
79
80- oid = strdup ("");
81 label = strdup ("SNMP");
82 units = strdup ("");
83 port = strdup (DEFAULT_PORT);
84 outbuff = strdup ("");
85- output = strdup ("");
86 delimiter = strdup (" = ");
87 output_delim = strdup (DEFAULT_OUTPUT_DELIMITER);
88 /* miblist = strdup (DEFAULT_MIBLIST); */
89@@ -180,92 +179,71 @@
90 if (process_arguments (argc, argv) == ERROR)
91 usage4 (_("Could not parse arguments"));
92
93- /* create the command line to execute */
94- if(usesnmpgetnext == TRUE) {
95- asprintf(&command_line, "%s -t %d -r %d -m %s -v %s %s %s:%s %s",
96- PATH_TO_SNMPGETNEXT, timeout_interval, retries, miblist, proto,
97- authpriv, server_address, port, oid);
98- asprintf(&cl_hidden_auth, "%s -t %d -r %d -m %s -v %s %s %s:%s %s",
99- PATH_TO_SNMPGETNEXT, timeout_interval, retries, miblist, proto,
100- "[authpriv]", server_address, port, oid);
101+ /* Create the command array to execute */
102+ if(usesnmpgetnext == TRUE) {
103+ snmpcmd = strdup (PATH_TO_SNMPGETNEXT);
104 }else{
105+ snmpcmd = strdup (PATH_TO_SNMPGET);
106+ }
107+
108+ /* 10 is the number of arguments to pass before authpriv options and OIDs. Add one for terminating NULL */
109+ command_line = calloc (10 + numauthpriv + numoids + 1, sizeof (char *));
110+ command_line[0] = snmpcmd;
111+ command_line[1] = strdup ("-t");
112+ asprintf (&command_line[2], "%d", timeout_interval);
113+ command_line[3] = strdup ("-r");
114+ asprintf (&command_line[4], "%d", retries);
115+ command_line[5] = strdup ("-m");
116+ command_line[6] = strdup (miblist);
117+ command_line[7] = "-v";
118+ command_line[8] = strdup (proto);
119+ asprintf (&command_line[9], "%s:%s", server_address, port);
120
121- asprintf (&command_line, "%s -t %d -r %d -m %s -v %s %s %s:%s %s",
122- PATH_TO_SNMPGET, timeout_interval, retries, miblist, proto,
123- authpriv, server_address, port, oid);
124- asprintf(&cl_hidden_auth, "%s -t %d -r %d -m %s -v %s %s %s:%s %s",
125- PATH_TO_SNMPGET, timeout_interval, retries, miblist, proto,
126- "[authpriv]", server_address, port, oid);
127+ for (i = 0; i < numauthpriv; i++) {
128+ command_line[10 + numoids + i] = authpriv[i];
129 }
130
131- if (verbose)
132- printf ("%s\n", command_line);
133+ /* This is just for display purposes, so it can remain a string */
134+ asprintf(&cl_hidden_auth, "%s -t %d -r %d -m %s -v %s %s:%s %s",
135+ snmpcmd, timeout_interval, retries, miblist, proto,
136+ server_address, port, "[authpriv]");
137
138-
139- /* run the command */
140- child_process = spopen (command_line);
141- if (child_process == NULL) {
142- printf (_("Could not open pipe: %s\n"), cl_hidden_auth);
143- exit (STATE_UNKNOWN);
144+ for (i = 0; i < numoids; i++) {
145+ command_line[10 + i] = oids[i];
146+ asprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]);
147 }
148
149-#if 0 /* Removed May 29, 2007 */
150- child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
151- if (child_stderr == NULL) {
152- printf (_("Could not open stderr for %s\n"), cl_hidden_auth);
153- }
154-#endif
155-
156- while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process))
157- asprintf (&output, "%s%s", output, input_buffer);
158-
159 if (verbose)
160- printf ("%s\n", output);
161+ printf ("%s\n", cl_hidden_auth);
162
163- ptr = output;
164+ /* Run the command */
165+ result = cmd_run_array (command_line, &chld_out, &chld_err, 0);
166
167- strncat(perfstr, "| ", sizeof(perfstr)-strlen(perfstr)-1);
168- while (ptr) {
169- char *foo, *ptr2;
170- unsigned int copylen;
171+ if (chld_err.lines > 0) {
172+ printf ("%s problem - error output from command\nCMD: %s\n", label, cl_hidden_auth);
173+ for (i = 0; i < chld_err.lines; i++) {
174+ printf ("%s\n", chld_err.line[i]);
175+ }
176+ exit (STATE_WARNING);
177+ }
178
179- foo = strstr (ptr, delimiter);
180- copylen = foo-ptr;
181- if (copylen > sizeof(perfstr)-strlen(perfstr)-1)
182- copylen = sizeof(perfstr)-strlen(perfstr)-1;
183- ptr2 = ptr;
184- ptr = foo;
185+ /* Return UNKNOWN or worse if no output is returned */
186+ if (chld_out.lines == 0)
187+ die (max_state_alt (result, STATE_UNKNOWN), _("%s problem - No data received from host\nCMD: %s\n"),
188+ label,
189+ cl_hidden_auth);
190
191- if (ptr == NULL)
192- break;
193-
194- ptr += strlen (delimiter);
195- ptr += strspn (ptr, " ");
196-
197- found++;
198-
199- if (ptr[0] == '"') {
200- ptr++;
201- response = strpcpy (response, ptr, "\"");
202- ptr = strpbrk (ptr, "\"");
203- ptr += strspn (ptr, "\"\n");
204+ if (verbose) {
205+ for (i = 0; i < chld_out.lines; i++) {
206+ printf ("%s\n", chld_out.line[i]);
207 }
208- else {
209- response = strpcpy (response, ptr, "\n");
210- ptr = strpbrk (ptr, "\n");
211- ptr += strspn (ptr, "\n");
212- while
213- (strstr (ptr, delimiter) &&
214- strstr (ptr, "\n") && strstr (ptr, "\n") < strstr (ptr, delimiter)) {
215- response = strpcat (response, ptr, "\n");
216- ptr = strpbrk (ptr, "\n");
217- }
218- if (ptr && strstr (ptr, delimiter) == NULL) {
219- asprintf (&response, "%s%s", response, ptr);
220- ptr = NULL;
221- }
222- }
223+ }
224
225+ for (i = 0; i < chld_out.lines; i++) {
226+ ptr = chld_out.line[i];
227+ oidname = strpcpy (oidname, ptr, delimiter);
228+ response = strstr (ptr, delimiter);
229+
230 /* We strip out the datatype indicator for PHBs */
231
232 /* Clean up type array - Sol10 does not necessarily zero it out */
233@@ -289,7 +267,6 @@
234 show = strstr (response, "STRING: ") + 8;
235 else
236 show = response;
237- p2 = show;
238
239 iresult = STATE_DEPENDENT;
240
241@@ -306,10 +283,10 @@
242 eval_method[i] & WARN_LE ||
243 eval_method[i] & WARN_EQ ||
244 eval_method[i] & WARN_NE) {
245- p2 = strpbrk (p2, "0123456789");
246- if (p2 == NULL)
247+ ptr = strpbrk (show, "0123456789");
248+ if (ptr == NULL)
249 die (STATE_UNKNOWN,_("No valid data returned"));
250- response_value[i] = strtoul (p2, NULL, 10);
251+ response_value[i] = strtoul (ptr, NULL, 10);
252 iresult = check_num (i);
253 asprintf (&show, "%llu", response_value[i]);
254 }
255@@ -364,10 +341,8 @@
256 if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL)
257 asprintf (&outbuff, "%s %s", outbuff, unitv[i]);
258
259- i++;
260-
261 if (is_numeric(show)) {
262- strncat(perfstr, ptr2, copylen);
263+ strncat(perfstr, oidname, sizeof(perfstr)-strlen(perfstr)-1);
264 strncat(perfstr, "=", sizeof(perfstr)-strlen(perfstr)-1);
265 strncat(perfstr, show, sizeof(perfstr)-strlen(perfstr)-1);
266
267@@ -375,29 +350,6 @@
268 strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1);
269 strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1);
270 }
271-
272- } /* end while (ptr) */
273-
274- if (found == 0)
275- die (STATE_UNKNOWN,
276- _("%s problem - No data received from host\nCMD: %s\n"),
277- label,
278- cl_hidden_auth);
279-
280-#if 0 /* Removed May 29, 2007 */
281- /* WARNING if output found on stderr */
282- if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
283- result = max_state (result, STATE_WARNING);
284-
285- /* close stderr */
286- (void) fclose (child_stderr);
287-#endif
288-
289- /* close the pipe */
290- if (spclose (child_process)) {
291- if (result == STATE_OK)
292- result = STATE_UNKNOWN;
293- asprintf (&outbuff, "%s (%s)", outbuff, _("snmpget returned an error status"));
294 }
295
296 /* if (nunits == 1 || i == 1) */
297@@ -563,12 +515,12 @@
298 */
299 needmibs = TRUE;
300 }
301-
302- for (ptr = optarg; (ptr = index (ptr, ',')); ptr++)
303- ptr[0] = ' '; /* relpace comma with space */
304- for (ptr = optarg; (ptr = index (ptr, ' ')); ptr++)
305- j++; /* count OIDs */
306- asprintf (&oid, "%s %s", (oid?oid:""), optarg);
307+ oids = calloc(MAX_OIDS, sizeof (char *));
308+ for (ptr = strtok(optarg, ", "); ptr != NULL; ptr = strtok(NULL, ", ")) {
309+ oids[j] = strdup(ptr);
310+ j++;
311+ }
312+ numoids = j;
313 if (c == 'E' || c == 'e') {
314 jj++;
315 ii++;
316@@ -728,16 +680,25 @@
317
318 if (proto == NULL || (strcmp(proto,DEFAULT_PROTOCOL) == 0) ) { /* default protocol version */
319 asprintf(&proto, DEFAULT_PROTOCOL);
320- asprintf(&authpriv, "%s%s", "-c ", community);
321+ numauthpriv = 2;
322+ authpriv = calloc (numauthpriv, sizeof (char *));
323+ authpriv[0] = strdup ("-c");
324+ authpriv[1] = strdup (community);
325 }
326 else if ( strcmp (proto, "2c") == 0 ) { /* snmpv2c args */
327- asprintf(&authpriv, "%s%s", "-c ", community);
328+ numauthpriv = 2;
329+ authpriv = calloc (numauthpriv, sizeof (char *));
330+ authpriv[0] = strdup ("-c");
331+ authpriv[1] = strdup (community);
332 }
333 else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */
334 asprintf(&proto, "%s", "3");
335
336 if ( (strcmp(seclevel, "noAuthNoPriv") == 0) || seclevel == NULL ) {
337- asprintf(&authpriv, "%s", "-l noAuthNoPriv" );
338+ numauthpriv = 2;
339+ authpriv = calloc (numauthpriv, sizeof (char *));
340+ authpriv[0] = strdup ("-l");
341+ authpriv[1] = strdup ("noAuthNoPriv");
342 }
343 else if ( strcmp(seclevel, "authNoPriv") == 0 ) {
344 if ( secname == NULL || authpasswd == NULL) {
345@@ -745,7 +706,16 @@
346 print_usage ();
347 exit (STATE_UNKNOWN);
348 }
349- asprintf(&authpriv, "-l authNoPriv -a %s -u %s -A %s ", authproto, secname, authpasswd);
350+ numauthpriv = 8;
351+ authpriv = calloc (numauthpriv, sizeof (char *));
352+ authpriv[0] = strdup ("-l");
353+ authpriv[1] = strdup ("authNoPriv");
354+ authpriv[3] = strdup ("-a");
355+ authpriv[4] = strdup (authproto);
356+ authpriv[5] = strdup ("-u");
357+ authpriv[6] = strdup (secname);
358+ authpriv[7] = strdup ("-A");
359+ authpriv[8] = strdup (authpasswd);
360 }
361 else if ( strcmp(seclevel, "authPriv") == 0 ) {
362 if ( secname == NULL || authpasswd == NULL || privpasswd == NULL ) {
363@@ -753,7 +723,20 @@
364 print_usage ();
365 exit (STATE_UNKNOWN);
366 }
367- asprintf(&authpriv, "-l authPriv -a %s -u %s -A %s -x %s -X %s ", authproto, secname, authpasswd, privproto, privpasswd);
368+ numauthpriv = 12;
369+ authpriv = calloc (numauthpriv, sizeof (char *));
370+ authpriv[0] = strdup ("-l");
371+ authpriv[1] = strdup ("authPriv");
372+ authpriv[3] = strdup ("-a");
373+ authpriv[4] = strdup (authproto);
374+ authpriv[5] = strdup ("-u");
375+ authpriv[6] = strdup (secname);
376+ authpriv[7] = strdup ("-A");
377+ authpriv[8] = strdup (authpasswd);
378+ authpriv[9] = strdup ("-x");
379+ authpriv[10] = strdup (privproto);
380+ authpriv[11] = strdup ("-X");
381+ authpriv[12] = strdup (privpasswd);
382 }
383
384 }
385Index: plugins/Makefile.am
386===================================================================
387--- plugins/Makefile.am (revision 2160)
388+++ plugins/Makefile.am (working copy)
389@@ -93,7 +93,7 @@
390 check_procs_LDADD = $(BASEOBJS)
391 check_radius_LDADD = $(NETLIBS) $(RADIUSLIBS)
392 check_real_LDADD = $(NETLIBS)
393-check_snmp_LDADD = $(BASEOBJS) popen.o
394+check_snmp_LDADD = $(BASEOBJS)
395 check_smtp_LDADD = $(SSLOBJS) $(NETLIBS) $(SSLLIBS)
396 check_ssh_LDADD = $(NETLIBS)
397 check_swap_LDADD = $(MATHLIBS) $(BASEOBJS) popen.o
398@@ -135,7 +135,7 @@
399 check_procs_DEPENDENCIES = check_procs.c $(BASEOBJS) popen.o $(DEPLIBS)
400 check_radius_DEPENDENCIES = check_radius.c $(NETOBJS) $(DEPLIBS)
401 check_real_DEPENDENCIES = check_real.c $(NETOBJS) $(DEPLIBS)
402-check_snmp_DEPENDENCIES = check_snmp.c $(BASEOBJS) popen.o $(DEPLIBS)
403+check_snmp_DEPENDENCIES = check_snmp.c $(BASEOBJS) $(DEPLIBS)
404 check_smtp_DEPENDENCIES = check_smtp.c $(SSLOBJS) $(NETOBJS) $(DEPLIBS)
405 check_ssh_DEPENDENCIES = check_ssh.c $(NETOBJS) $(DEPLIBS)
406 check_swap_DEPENDENCIES = check_swap.c $(BASEOBJS) popen.o $(DEPLIBS)