]> granicus.if.org Git - icinga2/commitdiff
Implemented the PROCESS_SERVICE_CHECK_RESULT external command.
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 22 Jan 2013 11:05:36 +0000 (12:05 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Tue, 22 Jan 2013 11:05:36 +0000 (12:05 +0100)
lib/icinga/externalcommand.cpp
lib/icinga/externalcommand.h
lib/icinga/pluginchecktask.cpp
lib/icinga/pluginchecktask.h

index 3988049e8367f41c53e3181be963393595f28eab..ff94f3daa9dca54b36aad08df28687998c2f611f 100644 (file)
@@ -28,6 +28,7 @@ int ExternalCommand::Execute(const String& command, const vector<String>& argume
 {
        if (!m_Initialized) {
                RegisterCommand("HELLO_WORLD", &ExternalCommand::HelloWorld);
+               RegisterCommand("PROCESS_SERVICE_CHECK_RESULT", &ExternalCommand::ProcessServiceCheckResult);
 
                m_Initialized = true;
        }
@@ -53,3 +54,27 @@ int ExternalCommand::HelloWorld(const vector<String>& arguments)
        return 0;
 }
 
+int ExternalCommand::ProcessServiceCheckResult(const vector<String>& arguments)
+{
+       if (arguments.size() < 4)
+               return -1;
+
+       if (!Service::Exists(arguments[1]))
+               return -1;
+
+       Service::Ptr service = Service::GetByName(arguments[1]);
+
+       int exitStatus = arguments[2].ToDouble();
+       Dictionary::Ptr result = PluginCheckTask::ParseCheckOutput(arguments[3]);
+       result->Set("state", PluginCheckTask::ExitStatusToState(exitStatus));
+
+       double now = Utility::GetTime();
+       result->Set("schedule_start", now);
+       result->Set("schedule_end", now);
+       result->Set("execution_start", now);
+       result->Set("execution_end", now);
+
+       service->ProcessCheckResult(result);
+
+       return 0;
+}
index 408cdcf09daa46295b81c57b94897ddacab40935..90702bf836e5bbde734054d4f60925c3252d9df7 100644 (file)
@@ -29,6 +29,7 @@ public:
        static int Execute(const String& command, const vector<String>& arguments);
 
        static int HelloWorld(const vector<String>& arguments);
+       static int ProcessServiceCheckResult(const vector<String>& arguments);
 
 private:
        typedef function<int (const vector<String>& arguments)> Callback;
index c00650cf79d77e2a51ade1e92cb26c594c5dc7e9..39b643e172c067e965b1cdc1c295edf3500b48fb 100644 (file)
@@ -64,38 +64,34 @@ void PluginCheckTask::ProcessFinishedHandler(PluginCheckTask ct)
                return;
        }
 
-       Dictionary::Ptr result = boost::make_shared<Dictionary>();
-       result->Set("execution_start", pr.ExecutionStart);
-       result->Set("execution_end", pr.ExecutionEnd);
-
        String output = pr.Output;
        output.Trim();
-       ProcessCheckOutput(result, output);
+       Dictionary::Ptr result = ParseCheckOutput(output);
+       result->Set("state", ExitStatusToState(pr.ExitStatus));
+       result->Set("execution_start", pr.ExecutionStart);
+       result->Set("execution_end", pr.ExecutionEnd);
 
-       ServiceState state;
+       ct.m_Task->FinishResult(result);
+}
 
-       switch (pr.ExitStatus) {
+ServiceState PluginCheckTask::ExitStatusToState(int exitStatus)
+{
+       switch (exitStatus) {
                case 0:
-                       state = StateOK;
-                       break;
+                       return StateOK;
                case 1:
-                       state = StateWarning;
-                       break;
+                       return StateWarning;
                case 2:
-                       state = StateCritical;
-                       break;
+                       return StateCritical;
                default:
-                       state = StateUnknown;
-                       break;
+                       return StateUnknown;
        }
-
-       result->Set("state", state);
-
-       ct.m_Task->FinishResult(result);
 }
 
-void PluginCheckTask::ProcessCheckOutput(const Dictionary::Ptr& result, String& output)
+Dictionary::Ptr PluginCheckTask::ParseCheckOutput(const String& output)
 {
+       Dictionary::Ptr result = boost::make_shared<Dictionary>();
+
        String text;
        String perfdata;
 
@@ -121,4 +117,6 @@ void PluginCheckTask::ProcessCheckOutput(const Dictionary::Ptr& result, String&
 
        result->Set("output", text);
        result->Set("performance_data_raw", perfdata);
+
+       return result;
 }
index a8bc2846d4907f274ebefacdbead216543051673..520df9eec9edb5885ec08149f21b252406304638 100644 (file)
@@ -33,10 +33,12 @@ class I2_ICINGA_API PluginCheckTask
 public:
        static void ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>& arguments);
 
+       static ServiceState ExitStatusToState(int exitStatus);
+       static Dictionary::Ptr ParseCheckOutput(const String& output);
+
 private:
 
        static void ProcessFinishedHandler(PluginCheckTask ct);
-       static void ProcessCheckOutput(const Dictionary::Ptr& result, String& output);
 
        PluginCheckTask(const ScriptTask::Ptr& task, const Process::Ptr& process);