From c874f950e8e5b6a805d8adf759d521501b22c7ce Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Wed, 15 Mar 2023 09:51:18 +0100 Subject: 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 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"; #define DEFAULT_PRIV_PROTOCOL "DES" #define DEFAULT_DELIMITER "=" #define DEFAULT_OUTPUT_DELIMITER " " +#define DEFAULT_BUFFER_SIZE 100 #define mark(a) ((a)!=0?"*":"") @@ -157,6 +158,7 @@ int perf_labels = 1; char* ip_version = ""; double multiplier = 1.0; char *fmtstr = ""; +char buffer[DEFAULT_BUFFER_SIZE]; static char *fix_snmp_range(char *th) { @@ -1169,6 +1171,9 @@ multiply (char *str) double val; char *conv = "%f"; + if(multiplier == 1) + return(str); + if(verbose>2) printf(" multiply input: %s\n", str); @@ -1187,15 +1192,15 @@ multiply (char *str) conv = fmtstr; } if (val == (int)val) { - sprintf(str, "%.0f", val); + snprintf(buffer, DEFAULT_BUFFER_SIZE, "%.0f", val); } else { if(verbose>2) printf(" multiply using format: %s\n", conv); - sprintf(str, conv, val); + snprintf(buffer, DEFAULT_BUFFER_SIZE, conv, val); } if(verbose>2) - printf(" multiply result: %s\n", str); - return str; + printf(" multiply result: %s\n", buffer); + return buffer; } -- cgit v0.10-9-g596f From c668f5303522b39466da3e86fecc255474276ac2 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 15 Mar 2023 18:16:04 +0100 Subject: Actually build check_mssql too diff --git a/plugins-scripts/Makefile.am b/plugins-scripts/Makefile.am index 088a445..7879791 100644 --- a/plugins-scripts/Makefile.am +++ b/plugins-scripts/Makefile.am @@ -16,13 +16,13 @@ VPATH=$(top_srcdir) $(top_srcdir)/plugins-scripts $(top_srcdir)/plugins-scripts/ libexec_SCRIPTS = check_breeze check_disk_smb check_flexlm check_ircd \ check_log check_oracle check_rpc check_sensors check_wave \ check_ifstatus check_ifoperstatus check_mailq check_file_age \ - check_uptime \ + check_uptime check_mssql \ utils.sh utils.pm EXTRA_DIST=check_breeze.pl check_disk_smb.pl check_flexlm.pl check_ircd.pl \ check_log.sh check_oracle.sh check_rpc.pl check_sensors.sh \ check_ifstatus.pl check_ifoperstatus.pl check_wave.pl check_mailq.pl check_file_age.pl \ - check_uptime.pl \ + check_uptime.pl check_mssql.pl \ utils.sh.in utils.pm.in t EDIT = sed \ -- cgit v0.10-9-g596f From 6e64973a4486248ff6c3de7d72637e44b6474c3e Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Mon, 27 Mar 2023 12:59:53 +0200 Subject: simplify code if statement is always true at this point, so remove it. diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index c4ddd0e..aefda3d 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -1179,10 +1179,7 @@ multiply (char *str) val = strtod (str, &endptr); if ((val == 0.0) && (endptr == str)) { - if(multiplier != 1) { - die(STATE_UNKNOWN, _("multiplier set (%.1f), but input is not a number: %s"), multiplier, str); - } - return str; + die(STATE_UNKNOWN, _("multiplier set (%.1f), but input is not a number: %s"), multiplier, str); } if(verbose>2) -- cgit v0.10-9-g596f