summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Nierlein <Sven.Nierlein@consol.de>2023-03-15 08:51:18 (GMT)
committerSven Nierlein <Sven.Nierlein@consol.de>2023-03-15 08:51:18 (GMT)
commitc874f950e8e5b6a805d8adf759d521501b22c7ce (patch)
treec104f25cd64aaeb329b66a514819913b353b9cb1
parent40dc41225a3ce86bd6f1f446920cd5a6c32b8443 (diff)
downloadmonitoring-plugins-c874f95.tar.gz
check_snmp: disable multiplier when unused
- if no multiplier is set, simply return the given string. Otherwise we would strip off the unit. - if used, allocate new space to hold the result which might be larger than the initial input Signed-off-by: Sven Nierlein <sven@consol.de>
-rw-r--r--plugins/check_snmp.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index d3968a2..c4ddd0e 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,6 +1171,9 @@ 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
@@ -1187,15 +1192,15 @@ multiply (char *str)
1187 conv = fmtstr; 1192 conv = fmtstr;
1188 } 1193 }
1189 if (val == (int)val) { 1194 if (val == (int)val) {
1190 sprintf(str, "%.0f", val); 1195 snprintf(buffer, DEFAULT_BUFFER_SIZE, "%.0f", val);
1191 } else { 1196 } else {
1192 if(verbose>2) 1197 if(verbose>2)
1193 printf(" multiply using format: %s\n", conv); 1198 printf(" multiply using format: %s\n", conv);
1194 sprintf(str, conv, val); 1199 snprintf(buffer, DEFAULT_BUFFER_SIZE, conv, val);
1195 } 1200 }
1196 if(verbose>2) 1201 if(verbose>2)
1197 printf(" multiply result: %s\n", str); 1202 printf(" multiply result: %s\n", buffer);
1198 return str; 1203 return buffer;
1199} 1204}
1200 1205
1201 1206