mirror of https://github.com/Icinga/icinga2.git
Pass through timestamps to external command handlers.
This commit is contained in:
parent
e887ff0550
commit
61f2b5f0cf
|
@ -179,7 +179,7 @@ void CompatComponent::ProcessCommand(const String& command)
|
||||||
Logger::Write(LogInformation, "compat", msgbuf.str());
|
Logger::Write(LogInformation, "compat", msgbuf.str());
|
||||||
|
|
||||||
vector<String> argvExtra(argv.begin() + 1, argv.end());
|
vector<String> argvExtra(argv.begin() + 1, argv.end());
|
||||||
ExternalCommand::Execute(argv[0], argvExtra);
|
ExternalCommand::Execute(ts, argv[0], argvExtra);
|
||||||
}
|
}
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ using namespace icinga;
|
||||||
bool I2_EXPORT ExternalCommand::m_Initialized;
|
bool I2_EXPORT ExternalCommand::m_Initialized;
|
||||||
map<String, ExternalCommand::Callback> I2_EXPORT ExternalCommand::m_Commands;
|
map<String, ExternalCommand::Callback> I2_EXPORT ExternalCommand::m_Commands;
|
||||||
|
|
||||||
int ExternalCommand::Execute(const String& command, const vector<String>& arguments)
|
int ExternalCommand::Execute(double time, const String& command, const vector<String>& arguments)
|
||||||
{
|
{
|
||||||
if (!m_Initialized) {
|
if (!m_Initialized) {
|
||||||
RegisterCommand("HELLO_WORLD", &ExternalCommand::HelloWorld);
|
RegisterCommand("HELLO_WORLD", &ExternalCommand::HelloWorld);
|
||||||
|
@ -39,7 +39,7 @@ int ExternalCommand::Execute(const String& command, const vector<String>& argume
|
||||||
if (it == m_Commands.end())
|
if (it == m_Commands.end())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return it->second(arguments);
|
return it->second(time, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExternalCommand::RegisterCommand(const String& command, const ExternalCommand::Callback& callback)
|
void ExternalCommand::RegisterCommand(const String& command, const ExternalCommand::Callback& callback)
|
||||||
|
@ -47,14 +47,14 @@ void ExternalCommand::RegisterCommand(const String& command, const ExternalComma
|
||||||
m_Commands[command] = callback;
|
m_Commands[command] = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ExternalCommand::HelloWorld(const vector<String>& arguments)
|
int ExternalCommand::HelloWorld(double time, const vector<String>& arguments)
|
||||||
{
|
{
|
||||||
Logger::Write(LogInformation, "icinga", "HelloWorld external command called.");
|
Logger::Write(LogInformation, "icinga", "HelloWorld external command called.");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ExternalCommand::ProcessServiceCheckResult(const vector<String>& arguments)
|
int ExternalCommand::ProcessServiceCheckResult(double time, const vector<String>& arguments)
|
||||||
{
|
{
|
||||||
if (arguments.size() < 4)
|
if (arguments.size() < 4)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -69,10 +69,10 @@ int ExternalCommand::ProcessServiceCheckResult(const vector<String>& arguments)
|
||||||
result->Set("state", PluginCheckTask::ExitStatusToState(exitStatus));
|
result->Set("state", PluginCheckTask::ExitStatusToState(exitStatus));
|
||||||
|
|
||||||
double now = Utility::GetTime();
|
double now = Utility::GetTime();
|
||||||
result->Set("schedule_start", now);
|
result->Set("schedule_start", time);
|
||||||
result->Set("schedule_end", now);
|
result->Set("schedule_end", time);
|
||||||
result->Set("execution_start", now);
|
result->Set("execution_start", time);
|
||||||
result->Set("execution_end", now);
|
result->Set("execution_end", time);
|
||||||
|
|
||||||
service->ProcessCheckResult(result);
|
service->ProcessCheckResult(result);
|
||||||
|
|
||||||
|
|
|
@ -26,13 +26,13 @@ namespace icinga
|
||||||
class I2_ICINGA_API ExternalCommand {
|
class I2_ICINGA_API ExternalCommand {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static int Execute(const String& command, const vector<String>& arguments);
|
static int Execute(double time, const String& command, const vector<String>& arguments);
|
||||||
|
|
||||||
static int HelloWorld(const vector<String>& arguments);
|
static int HelloWorld(double time, const vector<String>& arguments);
|
||||||
static int ProcessServiceCheckResult(const vector<String>& arguments);
|
static int ProcessServiceCheckResult(double time, const vector<String>& arguments);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef function<int (const vector<String>& arguments)> Callback;
|
typedef function<int (double time, const vector<String>& arguments)> Callback;
|
||||||
|
|
||||||
static bool m_Initialized;
|
static bool m_Initialized;
|
||||||
static map<String, Callback> m_Commands;
|
static map<String, Callback> m_Commands;
|
||||||
|
|
Loading…
Reference in New Issue