From 094e964660bd89544844c889744624d25666a320 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 27 Aug 2014 18:29:08 +0200 Subject: [PATCH] Log warning message if 'set_if' argument cannot be evaluated properly fixes #6968 --- lib/icinga/pluginutility.cpp | 15 ++++++++++++--- test/config/6968.conf | 28 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 test/config/6968.conf diff --git a/lib/icinga/pluginutility.cpp b/lib/icinga/pluginutility.cpp index f2b280184..41ad0fa92 100644 --- a/lib/icinga/pluginutility.cpp +++ b/lib/icinga/pluginutility.cpp @@ -94,8 +94,17 @@ void PluginUtility::ExecuteCommand(const Command::Ptr& commandObj, const Checkab String set_if_resolved = MacroProcessor::ResolveMacros(set_if, macroResolvers, cr, &missingMacro); - if (!missingMacro.IsEmpty() || !Convert::ToLong(set_if_resolved)) + if (!missingMacro.IsEmpty()) continue; + + try { + if (!Convert::ToLong(set_if_resolved)) + continue; + } catch (const std::exception& ex) { + /* tried to convert a string */ + Log(LogWarning, "PluginUtility", "Error evaluating set_if value '" + set_if_resolved + "': " + ex.what()); + continue; + } } } else @@ -213,10 +222,10 @@ Value PluginUtility::ParsePerfdata(const String& perfdata) { try { Dictionary::Ptr result = make_shared(); - + size_t begin = 0; String multi_prefix; - + for (;;) { size_t eqp = perfdata.FindFirstOf('=', begin); diff --git a/test/config/6968.conf b/test/config/6968.conf new file mode 100644 index 000000000..170eea6bc --- /dev/null +++ b/test/config/6968.conf @@ -0,0 +1,28 @@ +object Host "6968-server" { + import "test-generic-host" + address = "127.0.0.1" +} + +object Service "6968-test" { + import "test-generic-service" + + host_name = "6968-server" + check_command = "6968-check_vmware" + vars.vmware_check = "vCenter_License_Status" +} + +object CheckCommand "6968-check_vmware" { + import "plugin-check-command" + + command = [ PluginDir + "/check_vmware.pl" ] + arguments = { + "--server" = "$address$" + "--username" = "***" + "--password" = "***" + "--check" = { + set_if = "$vmware_check$" + } + } +} + + -- 2.40.0