summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_snmp.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index d3968a2..aefda3d 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -46,6 +46,7 @@ const char *email = "devel@monitoring-plugins.org";
46#define DEFAULT_PRIV_PROTOCOL "DES" 46#define DEFAULT_PRIV_PROTOCOL "DES"
47#define DEFAULT_DELIMITER "=" 47#define DEFAULT_DELIMITER "="
48#define DEFAULT_OUTPUT_DELIMITER " " 48#define DEFAULT_OUTPUT_DELIMITER " "
49#define DEFAULT_BUFFER_SIZE 100
49 50
50#define mark(a) ((a)!=0?"*":"") 51#define mark(a) ((a)!=0?"*":"")
51 52
@@ -157,6 +158,7 @@ int perf_labels = 1;
157char* ip_version = ""; 158char* ip_version = "";
158double multiplier = 1.0; 159double multiplier = 1.0;
159char *fmtstr = ""; 160char *fmtstr = "";
161char buffer[DEFAULT_BUFFER_SIZE];
160 162
161static char *fix_snmp_range(char *th) 163static char *fix_snmp_range(char *th)
162{ 164{
@@ -1169,15 +1171,15 @@ multiply (char *str)
1169 double val; 1171 double val;
1170 char *conv = "%f"; 1172 char *conv = "%f";
1171 1173
1174 if(multiplier == 1)
1175 return(str);
1176
1172 if(verbose>2) 1177 if(verbose>2)
1173 printf(" multiply input: %s\n", str); 1178 printf(" multiply input: %s\n", str);
1174 1179
1175 val = strtod (str, &endptr); 1180 val = strtod (str, &endptr);
1176 if ((val == 0.0) && (endptr == str)) { 1181 if ((val == 0.0) && (endptr == str)) {
1177 if(multiplier != 1) { 1182 die(STATE_UNKNOWN, _("multiplier set (%.1f), but input is not a number: %s"), multiplier, str);
1178 die(STATE_UNKNOWN, _("multiplier set (%.1f), but input is not a number: %s"), multiplier, str);
1179 }
1180 return str;
1181 } 1183 }
1182 1184
1183 if(verbose>2) 1185 if(verbose>2)
@@ -1187,15 +1189,15 @@ multiply (char *str)
1187 conv = fmtstr; 1189 conv = fmtstr;
1188 } 1190 }
1189 if (val == (int)val) { 1191 if (val == (int)val) {
1190 sprintf(str, "%.0f", val); 1192 snprintf(buffer, DEFAULT_BUFFER_SIZE, "%.0f", val);
1191 } else { 1193 } else {
1192 if(verbose>2) 1194 if(verbose>2)
1193 printf(" multiply using format: %s\n", conv); 1195 printf(" multiply using format: %s\n", conv);
1194 sprintf(str, conv, val); 1196 snprintf(buffer, DEFAULT_BUFFER_SIZE, conv, val);
1195 } 1197 }
1196 if(verbose>2) 1198 if(verbose>2)
1197 printf(" multiply result: %s\n", str); 1199 printf(" multiply result: %s\n", buffer);
1198 return str; 1200 return buffer;
1199} 1201}
1200 1202
1201 1203