mirror of https://github.com/Icinga/icinga2.git
Implemented the PROCESS_SERVICE_CHECK_RESULT external command.
This commit is contained in:
parent
20eaa441df
commit
e887ff0550
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
ServiceState state;
|
||||
|
||||
switch (pr.ExitStatus) {
|
||||
case 0:
|
||||
state = StateOK;
|
||||
break;
|
||||
case 1:
|
||||
state = StateWarning;
|
||||
break;
|
||||
case 2:
|
||||
state = StateCritical;
|
||||
break;
|
||||
default:
|
||||
state = StateUnknown;
|
||||
break;
|
||||
}
|
||||
|
||||
result->Set("state", state);
|
||||
Dictionary::Ptr result = ParseCheckOutput(output);
|
||||
result->Set("state", ExitStatusToState(pr.ExitStatus));
|
||||
result->Set("execution_start", pr.ExecutionStart);
|
||||
result->Set("execution_end", pr.ExecutionEnd);
|
||||
|
||||
ct.m_Task->FinishResult(result);
|
||||
}
|
||||
|
||||
void PluginCheckTask::ProcessCheckOutput(const Dictionary::Ptr& result, String& output)
|
||||
ServiceState PluginCheckTask::ExitStatusToState(int exitStatus)
|
||||
{
|
||||
switch (exitStatus) {
|
||||
case 0:
|
||||
return StateOK;
|
||||
case 1:
|
||||
return StateWarning;
|
||||
case 2:
|
||||
return StateCritical;
|
||||
default:
|
||||
return StateUnknown;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue