mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-20 12:14:44 +02:00
Don't run checks for services which have pending checks.
This commit is contained in:
parent
5670e14df5
commit
abc8d94e5f
@ -70,23 +70,23 @@ void CheckerComponent::CheckTimerHandler(void)
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
Service service = m_Services.top();
|
Service service = m_Services.top();
|
||||||
|
|
||||||
if (service.GetNextCheck() > now)
|
if (service.GetNextCheck() > now || service.HasPendingCheck())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
m_Services.pop();
|
||||||
|
service.SetPendingCheck(true);
|
||||||
|
|
||||||
Application::Log(LogInformation, "checker", "Executing service check for '" + service.GetName() + "'");
|
Application::Log(LogInformation, "checker", "Executing service check for '" + service.GetName() + "'");
|
||||||
|
|
||||||
CheckTask::Ptr task = CheckTask::CreateTask(service);
|
CheckTask::Ptr task = CheckTask::CreateTask(service);
|
||||||
task->Execute();
|
task->Execute();
|
||||||
m_PendingTasks.push_back(task);
|
m_PendingTasks.push_back(task);
|
||||||
|
|
||||||
m_Services.pop();
|
|
||||||
service.SetNextCheck(now + service.GetCheckInterval());
|
service.SetNextCheck(now + service.GetCheckInterval());
|
||||||
m_Services.push(service);
|
m_Services.push(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* adjust next call time for the check timer */
|
AdjustCheckTimer();
|
||||||
Service service = m_Services.top();
|
|
||||||
m_CheckTimer->SetInterval(service.GetNextCheck() - now);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckerComponent::ResultTimerHandler(void)
|
void CheckerComponent::ResultTimerHandler(void)
|
||||||
@ -101,11 +101,31 @@ void CheckerComponent::ResultTimerHandler(void)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task->GetService().SetPendingCheck(false);
|
||||||
|
|
||||||
CheckResult result = task->GetResult();
|
CheckResult result = task->GetResult();
|
||||||
Application::Log(LogInformation, "checker", "Got result! Plugin output: " + result.Output);
|
Application::Log(LogInformation, "checker", "Got result! Plugin output: " + result.Output);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_PendingTasks = unfinishedTasks;
|
m_PendingTasks = unfinishedTasks;
|
||||||
|
|
||||||
|
AdjustCheckTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckerComponent::AdjustCheckTimer(void)
|
||||||
|
{
|
||||||
|
if (m_Services.size() == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* adjust next call time for the check timer */
|
||||||
|
Service service = m_Services.top();
|
||||||
|
|
||||||
|
if (service.HasPendingCheck()) {
|
||||||
|
m_CheckTimer->Stop();
|
||||||
|
} else {
|
||||||
|
m_CheckTimer->SetInterval(service.GetNextCheck() - time(NULL));
|
||||||
|
m_CheckTimer->Start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckerComponent::AssignServiceRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request)
|
void CheckerComponent::AssignServiceRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request)
|
||||||
|
@ -23,11 +23,14 @@
|
|||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
struct ServiceNextCheckGreaterComparer
|
struct ServiceCheckPriorityLessComparer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool operator()(const Service& a, const Service& b)
|
bool operator()(const Service& a, const Service& b)
|
||||||
{
|
{
|
||||||
|
if (a.HasPendingCheck() && !b.HasPendingCheck())
|
||||||
|
return true;
|
||||||
|
|
||||||
return a.GetNextCheck() > b.GetNextCheck();
|
return a.GetNextCheck() > b.GetNextCheck();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -41,7 +44,7 @@ public:
|
|||||||
typedef shared_ptr<CheckerComponent> Ptr;
|
typedef shared_ptr<CheckerComponent> Ptr;
|
||||||
typedef weak_ptr<CheckerComponent> WeakPtr;
|
typedef weak_ptr<CheckerComponent> WeakPtr;
|
||||||
|
|
||||||
typedef priority_queue<Service, vector<Service>, ServiceNextCheckGreaterComparer> ServiceQueue;
|
typedef priority_queue<Service, vector<Service>, ServiceCheckPriorityLessComparer> ServiceQueue;
|
||||||
|
|
||||||
virtual string GetName(void) const;
|
virtual string GetName(void) const;
|
||||||
virtual void Start(void);
|
virtual void Start(void);
|
||||||
@ -58,6 +61,8 @@ private:
|
|||||||
void CheckTimerHandler(void);
|
void CheckTimerHandler(void);
|
||||||
void ResultTimerHandler(void);
|
void ResultTimerHandler(void);
|
||||||
|
|
||||||
|
void AdjustCheckTimer(void);
|
||||||
|
|
||||||
void AssignServiceRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
|
void AssignServiceRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
|
||||||
void RevokeServiceRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
|
void RevokeServiceRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
|
||||||
void ClearServicesRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
|
void ClearServicesRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
|
||||||
|
@ -4,6 +4,15 @@ using namespace icinga;
|
|||||||
|
|
||||||
map<string, CheckTask::Factory> CheckTask::m_Types;
|
map<string, CheckTask::Factory> CheckTask::m_Types;
|
||||||
|
|
||||||
|
CheckTask::CheckTask(const Service& service)
|
||||||
|
: m_Service(service)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
Service CheckTask::GetService(void) const
|
||||||
|
{
|
||||||
|
return m_Service;
|
||||||
|
}
|
||||||
|
|
||||||
void CheckTask::RegisterType(string type, Factory factory)
|
void CheckTask::RegisterType(string type, Factory factory)
|
||||||
{
|
{
|
||||||
m_Types[type] = factory;
|
m_Types[type] = factory;
|
||||||
|
@ -32,6 +32,8 @@ public:
|
|||||||
|
|
||||||
typedef function<CheckTask::Ptr(const Service&)> Factory;
|
typedef function<CheckTask::Ptr(const Service&)> Factory;
|
||||||
|
|
||||||
|
Service GetService(void) const;
|
||||||
|
|
||||||
virtual void Execute(void) = 0;
|
virtual void Execute(void) = 0;
|
||||||
virtual bool IsFinished(void) const = 0;
|
virtual bool IsFinished(void) const = 0;
|
||||||
virtual CheckResult GetResult(void) = 0;
|
virtual CheckResult GetResult(void) = 0;
|
||||||
@ -39,7 +41,12 @@ public:
|
|||||||
static void RegisterType(string type, Factory factory);
|
static void RegisterType(string type, Factory factory);
|
||||||
static CheckTask::Ptr CreateTask(const Service& service);
|
static CheckTask::Ptr CreateTask(const Service& service);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
CheckTask(const Service& service);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Service m_Service;
|
||||||
|
|
||||||
static map<string, Factory> m_Types;
|
static map<string, Factory> m_Types;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
NagiosCheckTask::NagiosCheckTask(const Service& service)
|
NagiosCheckTask::NagiosCheckTask(const Service& service)
|
||||||
|
: CheckTask(service)
|
||||||
{
|
{
|
||||||
string checkCommand = service.GetCheckCommand();
|
string checkCommand = service.GetCheckCommand();
|
||||||
m_Command = MacroProcessor::ResolveMacros(checkCommand, service.GetMacros()) + " 2>&1";
|
m_Command = MacroProcessor::ResolveMacros(checkCommand, service.GetMacros()) + " 2>&1";
|
||||||
|
@ -86,3 +86,15 @@ string Service::GetChecker(void) const
|
|||||||
GetConfigObject()->GetTag("checker", &value);
|
GetConfigObject()->GetTag("checker", &value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Service::SetPendingCheck(bool pending)
|
||||||
|
{
|
||||||
|
GetConfigObject()->SetTag("pendingCheck", pending);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Service::HasPendingCheck(void) const
|
||||||
|
{
|
||||||
|
bool value = false;
|
||||||
|
GetConfigObject()->GetTag("pendingCheck", &value);
|
||||||
|
return value;
|
||||||
|
}
|
@ -24,6 +24,8 @@ public:
|
|||||||
time_t GetNextCheck(void) const;
|
time_t GetNextCheck(void) const;
|
||||||
void SetChecker(string checker);
|
void SetChecker(string checker);
|
||||||
string GetChecker(void) const;
|
string GetChecker(void) const;
|
||||||
|
void SetPendingCheck(bool pending);
|
||||||
|
bool HasPendingCheck(void) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user