summaryrefslogtreecommitdiffstats
path: root/plugins/check_snmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_snmp.c')
-rw-r--r--plugins/check_snmp.c56
1 files changed, 30 insertions, 26 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 0adf3be..c1d8e2d 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -170,8 +170,10 @@ static char buffer[DEFAULT_BUFFER_SIZE];
170static bool ignore_mib_parsing_errors = false; 170static bool ignore_mib_parsing_errors = false;
171 171
172static char *fix_snmp_range(char *th) { 172static char *fix_snmp_range(char *th) {
173 double left, right; 173 double left;
174 char *colon, *ret; 174 double right;
175 char *colon;
176 char *ret;
175 177
176 if ((colon = strchr(th, ':')) == NULL || *(colon + 1) == '\0') 178 if ((colon = strchr(th, ':')) == NULL || *(colon + 1) == '\0')
177 return th; 179 return th;
@@ -190,9 +192,11 @@ static char *fix_snmp_range(char *th) {
190} 192}
191 193
192int main(int argc, char **argv) { 194int main(int argc, char **argv) {
193 int len, total_oids; 195 int len;
196 int total_oids;
194 size_t line; 197 size_t line;
195 unsigned int bk_count = 0, dq_count = 0; 198 unsigned int bk_count = 0;
199 unsigned int dq_count = 0;
196 int iresult = STATE_UNKNOWN; 200 int iresult = STATE_UNKNOWN;
197 int result = STATE_UNKNOWN; 201 int result = STATE_UNKNOWN;
198 int return_code = 0; 202 int return_code = 0;
@@ -208,11 +212,14 @@ int main(int argc, char **argv) {
208 char *th_warn = NULL; 212 char *th_warn = NULL;
209 char *th_crit = NULL; 213 char *th_crit = NULL;
210 char type[8] = ""; 214 char type[8] = "";
211 output chld_out, chld_err; 215 output chld_out;
216 output chld_err;
212 char *previous_string = NULL; 217 char *previous_string = NULL;
213 char *ap = NULL; 218 char *ap = NULL;
214 char *state_string = NULL; 219 char *state_string = NULL;
215 size_t response_length, current_length, string_length; 220 size_t response_length;
221 size_t current_length;
222 size_t string_length;
216 char *temp_string = NULL; 223 char *temp_string = NULL;
217 char *quote_string = NULL; 224 char *quote_string = NULL;
218 time_t current_time; 225 time_t current_time;
@@ -676,11 +683,6 @@ int main(int argc, char **argv) {
676 683
677/* process command-line arguments */ 684/* process command-line arguments */
678int process_arguments(int argc, char **argv) { 685int process_arguments(int argc, char **argv) {
679 char *ptr;
680 int c = 1;
681 size_t j = 0, jj = 0;
682
683 int option = 0;
684 static struct option longopts[] = {STD_LONG_OPTS, 686 static struct option longopts[] = {STD_LONG_OPTS,
685 {"community", required_argument, 0, 'C'}, 687 {"community", required_argument, 0, 'C'},
686 {"oid", required_argument, 0, 'o'}, 688 {"oid", required_argument, 0, 'o'},
@@ -723,7 +725,7 @@ int process_arguments(int argc, char **argv) {
723 return ERROR; 725 return ERROR;
724 726
725 /* reverse compatibility for very old non-POSIX usage forms */ 727 /* reverse compatibility for very old non-POSIX usage forms */
726 for (c = 1; c < argc; c++) { 728 for (int c = 1; c < argc; c++) {
727 if (strcmp("-to", argv[c]) == 0) 729 if (strcmp("-to", argv[c]) == 0)
728 strcpy(argv[c], "-t"); 730 strcpy(argv[c], "-t");
729 if (strcmp("-wv", argv[c]) == 0) 731 if (strcmp("-wv", argv[c]) == 0)
@@ -732,13 +734,16 @@ int process_arguments(int argc, char **argv) {
732 strcpy(argv[c], "-c"); 734 strcpy(argv[c], "-c");
733 } 735 }
734 736
735 while (1) { 737 size_t j = 0;
736 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:M:f:z:", longopts, &option); 738 size_t jj = 0;
739 while (true) {
740 int option = 0;
741 int option_char = 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:M:f:z:", longopts, &option);
737 742
738 if (c == -1 || c == EOF) 743 if (option_char == -1 || option_char == EOF)
739 break; 744 break;
740 745
741 switch (c) { 746 switch (option_char) {
742 case '?': /* usage */ 747 case '?': /* usage */
743 usage5(); 748 usage5();
744 case 'h': /* help */ 749 case 'h': /* help */
@@ -821,7 +826,7 @@ int process_arguments(int argc, char **argv) {
821 */ 826 */
822 needmibs = true; 827 needmibs = true;
823 } 828 }
824 for (ptr = strtok(optarg, ", "); ptr != NULL; ptr = strtok(NULL, ", "), j++) { 829 for (char *ptr = strtok(optarg, ", "); ptr != NULL; ptr = strtok(NULL, ", "), j++) {
825 while (j >= oids_size) { 830 while (j >= oids_size) {
826 oids_size += OID_COUNT_STEP; 831 oids_size += OID_COUNT_STEP;
827 oids = realloc(oids, oids_size * sizeof(*oids)); 832 oids = realloc(oids, oids_size * sizeof(*oids));
@@ -829,16 +834,16 @@ int process_arguments(int argc, char **argv) {
829 oids[j] = strdup(ptr); 834 oids[j] = strdup(ptr);
830 } 835 }
831 numoids = j; 836 numoids = j;
832 if (c == 'E' || c == 'e') { 837 if (option_char == 'E' || option_char == 'e') {
833 jj++; 838 jj++;
834 while (j + 1 >= eval_size) { 839 while (j + 1 >= eval_size) {
835 eval_size += OID_COUNT_STEP; 840 eval_size += OID_COUNT_STEP;
836 eval_method = realloc(eval_method, eval_size * sizeof(*eval_method)); 841 eval_method = realloc(eval_method, eval_size * sizeof(*eval_method));
837 memset(eval_method + eval_size - OID_COUNT_STEP, 0, 8); 842 memset(eval_method + eval_size - OID_COUNT_STEP, 0, 8);
838 } 843 }
839 if (c == 'E') 844 if (option_char == 'E')
840 eval_method[j + 1] |= WARN_PRESENT; 845 eval_method[j + 1] |= WARN_PRESENT;
841 else if (c == 'e') 846 else if (option_char == 'e')
842 eval_method[j + 1] |= CRIT_PRESENT; 847 eval_method[j + 1] |= CRIT_PRESENT;
843 } 848 }
844 break; 849 break;
@@ -895,7 +900,7 @@ int process_arguments(int argc, char **argv) {
895 die(STATE_UNKNOWN, _("Could not reallocate labels[%d]"), (int)nlabels); 900 die(STATE_UNKNOWN, _("Could not reallocate labels[%d]"), (int)nlabels);
896 } 901 }
897 labels[nlabels - 1] = optarg; 902 labels[nlabels - 1] = optarg;
898 ptr = thisarg(optarg); 903 char *ptr = thisarg(optarg);
899 labels[nlabels - 1] = ptr; 904 labels[nlabels - 1] = ptr;
900 if (ptr[0] == '\'') 905 if (ptr[0] == '\'')
901 labels[nlabels - 1] = ptr + 1; 906 labels[nlabels - 1] = ptr + 1;
@@ -1154,24 +1159,23 @@ static char *nextarg(char *str) {
1154 1159
1155/* multiply result (values 0 < n < 1 work as divider) */ 1160/* multiply result (values 0 < n < 1 work as divider) */
1156static char *multiply(char *str) { 1161static char *multiply(char *str) {
1157 char *endptr;
1158 double val;
1159 char *conv = "%f";
1160
1161 if (multiplier == 1) 1162 if (multiplier == 1)
1162 return (str); 1163 return (str);
1163 1164
1164 if (verbose > 2) 1165 if (verbose > 2)
1165 printf(" multiply input: %s\n", str); 1166 printf(" multiply input: %s\n", str);
1166 1167
1167 val = strtod(str, &endptr); 1168 char *endptr;
1169 double val = strtod(str, &endptr);
1168 if ((val == 0.0) && (endptr == str)) { 1170 if ((val == 0.0) && (endptr == str)) {
1169 die(STATE_UNKNOWN, _("multiplier set (%.1f), but input is not a number: %s"), multiplier, str); 1171 die(STATE_UNKNOWN, _("multiplier set (%.1f), but input is not a number: %s"), multiplier, str);
1170 } 1172 }
1171 1173
1172 if (verbose > 2) 1174 if (verbose > 2)
1173 printf(" multiply extracted double: %f\n", val); 1175 printf(" multiply extracted double: %f\n", val);
1176
1174 val *= multiplier; 1177 val *= multiplier;
1178 char *conv = "%f";
1175 if (fmtstr_set) { 1179 if (fmtstr_set) {
1176 conv = fmtstr; 1180 conv = fmtstr;
1177 } 1181 }