diff options
author | Sven Nierlein <sven@nierlein.de> | 2023-01-19 23:29:01 +0100 |
---|---|---|
committer | Sven Nierlein <sven@nierlein.org> | 2023-01-20 08:57:56 +0100 |
commit | f4930aee28ccb664691809e7dcc9198eb81429c5 (patch) | |
tree | aaec633b9ddbbc84f70c29999d56712cff32c342 /plugins | |
parent | 916572c1aecc37ebfea474f952df61d15d2f60b8 (diff) | |
download | monitoring-plugins-f4930aee28ccb664691809e7dcc9198eb81429c5.tar.gz |
fix check_snmp regex matches
the multiplier function always tried to extract a number, even if the result
is a string because of using a mib.
before:
```
./check_snmp -H hostname -P2c -c public -o IF-MIB::ifAdminStatus.11466 -vvv -r 0
/usr/bin/snmpget -Le -t 10 -r 5 -m ALL -v 2c [context] [authpriv] 10.0.13.11:161 IF-MIB::ifAdminStatus.11466
IF-MIB::ifAdminStatus.11466 = INTEGER: up(1)
Processing oid 1 (line 1)
oidname: IF-MIB::ifAdminStatus.11466
response: = INTEGER: up(1)
SNMP OK - 0 | IF-MIB::ifAdminStatus.11466=0;;
```
the regexp 0 matches, even if the actual result is "up(1)".
after this patch:
```
./check_snmp -H hostname -P2c -c public -o IF-MIB::ifAdminStatus.11466 -vvv -r 0
/usr/bin/snmpget -Le -t 10 -r 5 -m ALL -v 2c [context] [authpriv] 10.0.13.11:161 IF-MIB::ifAdminStatus.11466
IF-MIB::ifAdminStatus.11466 = INTEGER: up(1)
Processing oid 1 (line 1)
oidname: IF-MIB::ifAdminStatus.11466
response: = INTEGER: up(1)
SNMP CRITICAL - *up(1)* |
```
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_snmp.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 56bad880..d3968a27 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -1165,17 +1165,36 @@ nextarg (char *str) | |||
1165 | char * | 1165 | char * |
1166 | multiply (char *str) | 1166 | multiply (char *str) |
1167 | { | 1167 | { |
1168 | double val = strtod (str, NULL); | 1168 | char *endptr; |
1169 | val *= multiplier; | 1169 | double val; |
1170 | char *conv = "%f"; | 1170 | char *conv = "%f"; |
1171 | |||
1172 | if(verbose>2) | ||
1173 | printf(" multiply input: %s\n", str); | ||
1174 | |||
1175 | val = strtod (str, &endptr); | ||
1176 | if ((val == 0.0) && (endptr == str)) { | ||
1177 | if(multiplier != 1) { | ||
1178 | die(STATE_UNKNOWN, _("multiplier set (%.1f), but input is not a number: %s"), multiplier, str); | ||
1179 | } | ||
1180 | return str; | ||
1181 | } | ||
1182 | |||
1183 | if(verbose>2) | ||
1184 | printf(" multiply extracted double: %f\n", val); | ||
1185 | val *= multiplier; | ||
1171 | if (fmtstr != "") { | 1186 | if (fmtstr != "") { |
1172 | conv = fmtstr; | 1187 | conv = fmtstr; |
1173 | } | 1188 | } |
1174 | if (val == (int)val) { | 1189 | if (val == (int)val) { |
1175 | sprintf(str, "%.0f", val); | 1190 | sprintf(str, "%.0f", val); |
1176 | } else { | 1191 | } else { |
1192 | if(verbose>2) | ||
1193 | printf(" multiply using format: %s\n", conv); | ||
1177 | sprintf(str, conv, val); | 1194 | sprintf(str, conv, val); |
1178 | } | 1195 | } |
1196 | if(verbose>2) | ||
1197 | printf(" multiply result: %s\n", str); | ||
1179 | return str; | 1198 | return str; |
1180 | } | 1199 | } |
1181 | 1200 | ||