--- plugins/check_snmp.c 2017-04-19 13:03:12.000000000 -0300 +++ plugins/check_snmp.c.new 2017-06-06 10:20:05.309690320 -0300 @@ -28,7 +28,7 @@ * *****************************************************************************/ -const char *progname = "check_snmp"; +const char *progname = "check_snmp_proative"; const char *copyright = "1999-2014"; const char *email = "devel@nagios-plugins.org"; @@ -132,6 +132,7 @@ int numcontext = 0; int verbose = 0; int usesnmpgetnext = FALSE; +float multiplicador; char *warning_thresholds = NULL; char *critical_thresholds = NULL; thresholds **thlds; @@ -223,6 +224,7 @@ oids = calloc(oids_size, sizeof (char *)); label = strdup ("SNMP"); + label = ""; units = strdup (""); port = strdup (DEFAULT_PORT); outbuff = strdup (""); @@ -485,7 +487,20 @@ /* Process this block for numeric comparisons */ /* Make some special values,like Timeticks numeric only if a threshold is defined */ - if (thlds[i]->warning || thlds[i]->critical || calculate_rate || is_ticks || offset != 0.0) { + if (thlds[i]->warning || thlds[i]->critical || calculate_rate || is_ticks || offset != 0.0 || multiplicador) { + + /* Aplica um multiplicador no resultado (float) */ + if (multiplicador > 0) { + if(verbose>0) + printf("Doing multiplication for result %s by %f\n", show, multiplicador); + + float show_temp = multiplicador * atof(show); + sprintf (show, "%.1f", show_temp); + + if(verbose>0) + printf("Multiplication result: %s\n", show); + } + ptr = strpbrk (show, "-0123456789"); if (ptr == NULL) die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); @@ -517,6 +532,7 @@ iresult = get_status(response_value[i], thlds[i]); xasprintf (&show, conv, response_value[i]); } + } /* Process this block for string matching */ @@ -657,7 +673,7 @@ } } - printf ("%s %s -%s %s\n", label, state_text (result), outbuff, perfstr); + printf ("%s%s -%s %s\n", label, state_text (result), outbuff, perfstr); if (mult_resp) printf ("%s", mult_resp); return result; @@ -691,6 +707,7 @@ {"port", required_argument, 0, 'p'}, {"retries", required_argument, 0, 'e'}, {"miblist", required_argument, 0, 'm'}, + {"multiplicador", required_argument, 0, 'M'}, {"protocol", required_argument, 0, 'P'}, {"context", required_argument, 0, 'N'}, {"seclevel", required_argument, 0, 'L'}, @@ -724,7 +741,7 @@ } while (1) { - c = getopt_long (argc, argv, "nhvVO46t:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:N:L:U:a:x:A:X:", + c = getopt_long (argc, argv, "nhvVO46t:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:M:P:N:L:U:a:x:A:X:", longopts, &option); if (c == -1 || c == EOF) @@ -787,6 +804,10 @@ timeout_interval = parse_timeout_string (optarg); break; /* Test parameters */ + case 'M': /* result multiplier */ + multiplicador = atof(optarg); + + break; case 'c': /* critical threshold */ critical_thresholds = optarg; break; @@ -1145,6 +1166,16 @@ void print_help (void) { + printf ("\n%s\n", _("*************************************************************************************")); + printf ("%s\n", _("Adaptado por Marcus Vinicius Oliveira em 06/06/2017 ")); + printf ("%s\n\n", _("marcus.oliveira@proativetec.com.br")); + printf ("%s\n", _("Este plugin eh um fork do check_snmp original (versao: nagios-plugins-2.2.1) ")); + printf ("%s\n\n", _("com as seguintes modificacoes customizadas da PROATIVE: ")); + printf ("\t%s\n", _("- Adicionada opcao -M, --multiplicador ")); + printf ("\t%s\n\n", _(" Aplica um multiplicador flutuante ao resultado numerico")); + printf ("\t%s\n\n", _("- Retirado label *SNMP* antes do status no output")); + printf ("%s\n\n\n", _("*************************************************************************************")); + print_revision (progname, NP_VERSION); printf (COPYRIGHT, copyright, email); @@ -1196,6 +1227,9 @@ printf (" %s \"%s\"\n", _("Delimiter to use when parsing returned data. Default is"), DEFAULT_DELIMITER); printf (" %s\n", _("Any data on the right hand side of the delimiter is considered")); printf (" %s\n", _("to be the data that should be used in the evaluation.")); + printf (" %s\n", "-M, --multiplicador=FLOAT"); + printf (" %s\n", _("The result will be multiplied by -M Option")); + /* Tests Against Integers */ printf (" %s\n", "-w, --warning=THRESHOLD(s)"); @@ -1276,5 +1310,5 @@ printf ("[-C community] [-s string] [-r regex] [-R regexi] [-t timeout] [-e retries]\n"); printf ("[-l label] [-u units] [-p port-number] [-d delimiter] [-D output-delimiter]\n"); printf ("[-m miblist] [-P snmp version] [-N context] [-L seclevel] [-U secname]\n"); - printf ("[-a authproto] [-A authpasswd] [-x privproto] [-X privpasswd]\n"); + printf ("[-a authproto] [-A authpasswd] [-x privproto] [-X privpasswd] [-M multiplicador]\n"); }