CheckResult result = task->GetResult();
Application::Log(LogDebug, "checker", "Got result for service '" + service.GetName() + "'");
- long latency = result.GetEndTime() - result.GetStartTime();
+ long execution_time = result.GetExecutionEnd() - result.GetExecutionStart();
+ long latency = (result.GetScheduleEnd() - result.GetScheduleStart()) - execution_time;
avg_latency += latency;
if (min_latency == -1 || latency < min_latency)
<< "\t" << "check_execution_time=0" << endl
<< "\t" << "check_latency=0" << endl
<< "\t" << "current_state=0" << endl
+ << "\t" << "state_type=1" << endl
<< "\t" << "last_check=" << time(NULL) << endl
<< "\t" << "next_check=" << time(NULL) << endl
<< "\t" << "current_attempt=1" << endl
cr = service.GetLastCheckResult();
string plugin_output;
- long start_time = -1, end_time = -1;
+ long schedule_start = -1, schedule_end = -1;
+ long execution_start = -1, execution_end = -1;
if (cr) {
cr->GetProperty("output", &plugin_output);
- cr->GetProperty("start_time", &start_time);
- cr->GetProperty("end_time", &end_time);
+ cr->GetProperty("schedule_start", &schedule_start);
+ cr->GetProperty("schedule_end", &schedule_end);
+ cr->GetProperty("execution_start", &execution_start);
+ cr->GetProperty("execution_end", &execution_end);
}
+ long execution_time = (execution_start - execution_start);
+ long latency = (schedule_end - schedule_start) - execution_time;
+
fp << "servicestatus {" << endl
<< "\t" << "host_name=" << service.GetHost().GetName() << endl
<< "\t" << "service_description=" << service.GetDisplayName() << endl
<< "\t" << "check_interval=" << service.GetCheckInterval() / 60.0 << endl
<< "\t" << "retry_interval=" << service.GetRetryInterval() / 60.0 << endl
- << "\t" << "has_been_checked=" << (end_time == -1 ? 0 : 1) << endl
+ << "\t" << "has_been_checked=" << (cr ? 1 : 0) << endl
<< "\t" << "should_be_scheduled=1" << endl
- << "\t" << "check_execution_time=" << end_time - start_time << endl
- << "\t" << "check_latency=0" << endl
+ << "\t" << "check_execution_time=" << execution_time << endl
+ << "\t" << "check_latency=" << latency << endl
<< "\t" << "current_state=" << service.GetState() << endl
+ << "\t" << "state_type=" << service.GetStateType() << endl
<< "\t" << "plugin_output=" << plugin_output << endl
- << "\t" << "last_check=" << start_time << endl
+ << "\t" << "last_check=" << schedule_start << endl
<< "\t" << "next_check=" << service.GetNextCheck() << endl
<< "\t" << "current_attempt=" << service.GetCurrentCheckAttempt() << endl
<< "\t" << "max_attempts=" << service.GetMaxCheckAttempts() << endl
<< "\t" << "}" << endl
<< endl;
+ statusfp << "programstatus {" << endl
+ << "\t" << "daemon_mode=1" << endl
+ << "\t" << "program_start=" << IcingaApplication::GetInstance()->GetStartTime() << endl
+ << "\t" << "active_service_checks_enabled=1" << endl
+ << "\t" << "passive_service_checks_enabled=1" << endl
+ << "\t" << "active_host_checks_enabled=0" << endl
+ << "\t" << "passive_host_checks_enabled=0" << endl
+ << "\t" << "check_service_freshness=1" << endl
+ << "\t" << "check_host_freshness=0" << endl
+ << "\t" << "enable_flap_detection=1" << endl
+ << "\t" << "enable_failure_prediction=0" << endl
+ << endl;
+
ofstream objectfp;
objectfp.open("objects.cache.tmp", ofstream::out | ofstream::trunc);
return m_Data;
}
-void CheckResult::SetStartTime(time_t ts)
+void CheckResult::SetScheduleStart(time_t ts)
{
- m_Data->SetProperty("start_time", static_cast<long>(ts));
+ m_Data->SetProperty("schedule_start", static_cast<long>(ts));
}
-time_t CheckResult::GetStartTime(void) const
+time_t CheckResult::GetScheduleStart(void) const
{
long value = 0;
- m_Data->GetProperty("start_time", &value);
+ m_Data->GetProperty("schedule_start", &value);
return static_cast<time_t>(value);
}
-void CheckResult::SetEndTime(time_t ts)
+void CheckResult::SetScheduleEnd(time_t ts)
{
- m_Data->SetProperty("end_time", static_cast<long>(ts));
+ m_Data->SetProperty("schedule_end", static_cast<long>(ts));
}
-time_t CheckResult::GetEndTime(void) const
+time_t CheckResult::GetScheduleEnd(void) const
{
long value = 0;
- m_Data->GetProperty("end_time", &value);
+ m_Data->GetProperty("schedule_end", &value);
return static_cast<time_t>(value);
}
+void CheckResult::SetExecutionStart(time_t ts)
+{
+ m_Data->SetProperty("execution_start", static_cast<long>(ts));
+}
+
+time_t CheckResult::GetExecutionStart(void) const
+{
+ long value = 0;
+ m_Data->GetProperty("execution_start", &value);
+ return static_cast<time_t>(value);
+}
+
+void CheckResult::SetExecutionEnd(time_t ts)
+{
+ m_Data->SetProperty("execution_end", static_cast<long>(ts));
+}
+
+time_t CheckResult::GetExecutionEnd(void) const
+{
+ long value = 0;
+ m_Data->GetProperty("execution_end", &value);
+ return value;
+}
+
void CheckResult::SetState(ServiceState state)
{
m_Data->SetProperty("state", static_cast<long>(state));
Dictionary::Ptr GetDictionary(void) const;
- void SetStartTime(time_t ts);
- time_t GetStartTime(void) const;
+ void SetScheduleStart(time_t ts);
+ time_t GetScheduleStart(void) const;
- void SetEndTime(time_t ts);
- time_t GetEndTime(void) const;
+ void SetScheduleEnd(time_t ts);
+ time_t GetScheduleEnd(void) const;
+
+ void SetExecutionStart(time_t ts);
+ time_t GetExecutionStart(void) const;
+
+ void SetExecutionEnd(time_t ts);
+ time_t GetExecutionEnd(void) const;
void SetState(ServiceState state);
ServiceState GetState(void) const;
: m_Service(service)
{ }
-Service CheckTask::GetService(void) const
+Service& CheckTask::GetService(void)
{
return m_Service;
}
+CheckResult& CheckTask::GetResult(void)
+{
+ return m_Result;
+}
+
void CheckTask::RegisterType(string type, Factory factory, QueueFlusher qflusher)
{
CheckTaskType ctt;
typedef function<CheckTask::Ptr(const Service&)> Factory;
typedef function<void()> QueueFlusher;
- Service GetService(void) const;
+ Service& GetService(void);
+ CheckResult& GetResult(void);
virtual void Enqueue(void) = 0;
- virtual CheckResult GetResult(void) = 0;
static void RegisterType(string type, Factory factory, QueueFlusher qflusher);
static CheckTask::Ptr CreateTask(const Service& service);
private:
Service m_Service;
+ CheckResult m_Result;
static map<string, CheckTaskType> m_Types;
Application::Log(LogInformation, "icinga", "Icinga component loader (version: " ICINGA_VERSION ")");
#endif /* _WIN32 */
+ time(&m_StartTime);
+
if (args.size() < 2) {
stringstream msgbuf;
msgbuf << "Syntax: " << args[0] << " <config-file>";
{
return m_Service;
}
+
+time_t IcingaApplication::GetStartTime(void) const
+{
+ return m_StartTime;
+}
string GetNode(void) const;
string GetService(void) const;
+ time_t GetStartTime(void) const;
+
private:
string m_CertificateFile;
string m_CAFile;
string m_Node;
string m_Service;
+ time_t m_StartTime;
+
void NewComponentHandler(const ConfigObject::Ptr& object);
void DeletedComponentHandler(const ConfigObject::Ptr& object);
};
{
time_t now;
time(&now);
- m_Result.SetStartTime(now);
+ GetResult().SetScheduleStart(now);
m_PendingTasks.push_back(GetSelf());
}
}
}
-CheckResult NagiosCheckTask::GetResult(void)
-{
- return m_Result;
-}
-
void NagiosCheckTask::CheckThreadProc(void)
{
mutex::scoped_lock lock(m_Mutex);
#endif /* _MSC_VER */
for (it = tasks.begin(); it != tasks.end(); ) {
+ int fd = it->first;
+ NagiosCheckTask::Ptr task = it->second;
+
#ifndef _MSC_VER
- if (!FD_ISSET(it->first, &readfds)) {
+ if (!FD_ISSET(fd, &readfds)) {
it++;
continue;
}
#endif /* _MSC_VER */
- if (!it->second->RunTask()) {
- CheckTask::FinishTask(it->second);
+ if (!task->RunTask()) {
+ time_t now;
+ time(&now);
+ task->GetResult().SetScheduleEnd(now);
+
+ CheckTask::FinishTask(task);
prev = it;
it++;
tasks.erase(prev);
NagiosCheckTask::Ptr task = m_Tasks.front();
m_Tasks.pop_front();
if (!task->InitTask()) {
+ time_t now;
+ time(&now);
+ task->GetResult().SetScheduleEnd(now);
+
CheckTask::FinishTask(task);
} else {
int fd = task->GetFD();
m_FP = popen(m_Command.c_str(), "r");
#endif /* _MSC_VER */
- return (m_FP != NULL);
+ if (m_FP == NULL) {
+ time_t now;
+ time(&now);
+ GetResult().SetExecutionEnd(now);
+
+ return false;
+ }
+
+ return true;
}
bool NagiosCheckTask::RunTask(void)
string output = m_OutputStream.str();
boost::algorithm::trim(output);
- m_Result.SetOutput(output);
+ GetResult().SetOutput(output);
int status, exitcode;
#ifdef _MSC_VER
break;
}
- m_Result.SetState(state);
+ GetResult().SetState(state);
#ifndef _MSC_VER
} else if (WIFSIGNALED(status)) {
stringstream outputbuf;
outputbuf << "Process was terminated by signal " << WTERMSIG(status);
- m_Result.SetOutput(outputbuf.str());
- m_Result.SetState(StateUnknown);
+ GetResult().SetOutput(outputbuf.str());
+ GetResult().SetState(StateUnknown);
}
#endif /* _MSC_VER */
time_t now;
time(&now);
- m_Result.SetEndTime(now);
+ GetResult().SetExecutionEnd(now);
return false;
}
NagiosCheckTask(const Service& service);
virtual void Enqueue(void);
- virtual CheckResult GetResult(void);
static CheckTask::Ptr CreateTask(const Service& service);
static void FlushQueue(void);
private:
string m_Command;
- CheckResult m_Result;
FILE *m_FP;
stringstream m_OutputStream;
time_t Service::GetLastStateChange(void) const
{
- long value = 0;
- GetConfigObject()->GetTag("last_state_change", &value);
+ long value;
+ if (!GetConfigObject()->GetTag("last_state_change", &value))
+ value = IcingaApplication::GetInstance()->GetStartTime();
return value;
}
time_t Service::GetLastHardStateChange(void) const
{
- long value = 0;
- GetConfigObject()->GetTag("last_hard_state_change", &value);
+ long value;
+ if (!GetConfigObject()->GetTag("last_hard_state_change", &value))
+ value = IcingaApplication::GetInstance()->GetStartTime();
return value;
}