Dictionary::Ptr nodes = make_shared<Dictionary>();
BOOST_FOREACH(const CheckerComponent::Ptr& checker, DynamicType::GetObjects<CheckerComponent>()) {
- unsigned long idle = checker->GetIdleServices();
- unsigned long pending = checker->GetPendingServices();
+ unsigned long idle = checker->GetIdleCheckables();
+ unsigned long pending = checker->GetPendingCheckables();
Dictionary::Ptr stats = make_shared<Dictionary>();
stats->Set("idle", idle);
DynamicObject::OnStopped.connect(bind(&CheckerComponent::ObjectHandler, this, _1));
DynamicObject::OnAuthorityChanged.connect(bind(&CheckerComponent::ObjectHandler, this, _1));
- Service::OnNextCheckChanged.connect(bind(&CheckerComponent::NextCheckChangedHandler, this, _1));
+ Checkable::OnNextCheckChanged.connect(bind(&CheckerComponent::NextCheckChangedHandler, this, _1));
}
void CheckerComponent::Start(void)
boost::mutex::scoped_lock lock(m_Mutex);
for (;;) {
- typedef boost::multi_index::nth_index<ServiceSet, 1>::type CheckTimeView;
- CheckTimeView& idx = boost::get<1>(m_IdleServices);
+ typedef boost::multi_index::nth_index<CheckableSet, 1>::type CheckTimeView;
+ CheckTimeView& idx = boost::get<1>(m_IdleCheckables);
while (idx.begin() == idx.end() && !m_Stopped)
m_CV.wait(lock);
break;
CheckTimeView::iterator it = idx.begin();
- Service::Ptr service = *it;
+ Checkable::Ptr service = *it;
if (!service->HasAuthority("checker")) {
- m_IdleServices.erase(service);
+ m_IdleCheckables.erase(service);
continue;
}
continue;
}
- m_IdleServices.erase(service);
+ m_IdleCheckables.erase(service);
bool forced = service->GetForceNextCheck();
bool check = true;
/* reschedule the service if checks are disabled */
if (!check) {
- m_IdleServices.insert(service);
+ m_IdleCheckables.insert(service);
lock.unlock();
service->UpdateNextCheck();
continue;
}
- m_PendingServices.insert(service);
+ m_PendingCheckables.insert(service);
lock.unlock();
}
}
-void CheckerComponent::ExecuteCheckHelper(const Service::Ptr& service)
+void CheckerComponent::ExecuteCheckHelper(const Checkable::Ptr& service)
{
try {
service->ExecuteCheck();
/* remove the service from the list of pending services; if it's not in the
* list this was a manual (i.e. forced) check and we must not re-add the
* service to the services list because it's already there. */
- CheckerComponent::ServiceSet::iterator it;
- it = m_PendingServices.find(service);
- if (it != m_PendingServices.end()) {
- m_PendingServices.erase(it);
+ CheckerComponent::CheckableSet::iterator it;
+ it = m_PendingCheckables.find(service);
+ if (it != m_PendingCheckables.end()) {
+ m_PendingCheckables.erase(it);
if (service->IsActive() && service->HasAuthority("checker"))
- m_IdleServices.insert(service);
+ m_IdleCheckables.insert(service);
m_CV.notify_all();
}
}
- Log(LogDebug, "checker", "Check finished for service '" + service->GetName() + "'");
+ Log(LogDebug, "checker", "Check finished for object '" + service->GetName() + "'");
}
void CheckerComponent::ResultTimerHandler(void)
{
boost::mutex::scoped_lock lock(m_Mutex);
- msgbuf << "Pending services: " << m_PendingServices.size() << "; Idle services: " << m_IdleServices.size() << "; Checks/s: " << CIB::GetActiveChecksStatistics(5) / 5.0;
+ msgbuf << "Pending services: " << m_PendingCheckables.size() << "; Idle services: " << m_IdleCheckables.size() << "; Checks/s: " << CIB::GetActiveChecksStatistics(5) / 5.0;
}
Log(LogInformation, "checker", msgbuf.str());
void CheckerComponent::ObjectHandler(const DynamicObject::Ptr& object)
{
- if (object->GetType() != DynamicType::GetByName("Service"))
+ if (!Type::GetByName("Checkable")->IsAssignableFrom(object->GetReflectionType()))
return;
- Service::Ptr service = static_pointer_cast<Service>(object);
+ Checkable::Ptr service = static_pointer_cast<Checkable>(object);
{
boost::mutex::scoped_lock lock(m_Mutex);
if (object->IsActive() && object->HasAuthority("checker")) {
- if (m_PendingServices.find(service) != m_PendingServices.end())
+ if (m_PendingCheckables.find(service) != m_PendingCheckables.end())
return;
- m_IdleServices.insert(service);
+ m_IdleCheckables.insert(service);
} else {
- m_IdleServices.erase(service);
- m_PendingServices.erase(service);
+ m_IdleCheckables.erase(service);
+ m_PendingCheckables.erase(service);
}
m_CV.notify_all();
}
}
-void CheckerComponent::NextCheckChangedHandler(const Service::Ptr& service)
+void CheckerComponent::NextCheckChangedHandler(const Checkable::Ptr& service)
{
boost::mutex::scoped_lock lock(m_Mutex);
/* remove and re-insert the service from the set in order to force an index update */
- typedef boost::multi_index::nth_index<ServiceSet, 0>::type ServiceView;
- ServiceView& idx = boost::get<0>(m_IdleServices);
+ typedef boost::multi_index::nth_index<CheckableSet, 0>::type CheckableView;
+ CheckableView& idx = boost::get<0>(m_IdleCheckables);
- ServiceView::iterator it = idx.find(service);
+ CheckableView::iterator it = idx.find(service);
if (it == idx.end())
return;
m_CV.notify_all();
}
-unsigned long CheckerComponent::GetIdleServices(void)
+unsigned long CheckerComponent::GetIdleCheckables(void)
{
boost::mutex::scoped_lock lock(m_Mutex);
- return m_IdleServices.size();
+ return m_IdleCheckables.size();
}
-unsigned long CheckerComponent::GetPendingServices(void)
+unsigned long CheckerComponent::GetPendingCheckables(void)
{
boost::mutex::scoped_lock lock(m_Mutex);
- return m_PendingServices.size();
+ return m_PendingCheckables.size();
}
/**
* @ingroup checker
*/
-struct ServiceNextCheckExtractor
+struct CheckableNextCheckExtractor
{
typedef double result_type;
/**
* @threadsafety Always.
*/
- double operator()(const Service::Ptr& service)
+ double operator()(const Checkable::Ptr& service)
{
return service->GetNextCheck();
}
DECLARE_TYPENAME(CheckerComponent);
typedef boost::multi_index_container<
- Service::Ptr,
+ Checkable::Ptr,
boost::multi_index::indexed_by<
- boost::multi_index::ordered_unique<boost::multi_index::identity<Service::Ptr> >,
- boost::multi_index::ordered_non_unique<ServiceNextCheckExtractor>
+ boost::multi_index::ordered_unique<boost::multi_index::identity<Checkable::Ptr> >,
+ boost::multi_index::ordered_non_unique<CheckableNextCheckExtractor>
>
- > ServiceSet;
+ > CheckableSet;
virtual void OnConfigLoaded(void);
virtual void Start(void);
virtual void Stop(void);
static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
- unsigned long GetIdleServices(void);
- unsigned long GetPendingServices(void);
+ unsigned long GetIdleCheckables(void);
+ unsigned long GetPendingCheckables(void);
private:
boost::mutex m_Mutex;
bool m_Stopped;
boost::thread m_Thread;
- ServiceSet m_IdleServices;
- ServiceSet m_PendingServices;
+ CheckableSet m_IdleCheckables;
+ CheckableSet m_PendingCheckables;
Timer::Ptr m_ResultTimer;
void CheckThreadProc(void);
void ResultTimerHandler(void);
- void ExecuteCheckHelper(const Service::Ptr& service);
+ void ExecuteCheckHelper(const Checkable::Ptr& service);
void AdjustCheckTimer(void);
void ObjectHandler(const DynamicObject::Ptr& object);
- void NextCheckChangedHandler(const Service::Ptr& service);
+ void NextCheckChangedHandler(const Checkable::Ptr& service);
void RescheduleCheckTimer(void);
REGISTER_SCRIPTFUNCTION(ClusterCheck, &ClusterCheckTask::ScriptFunc);
-void ClusterCheckTask::ScriptFunc(const Service::Ptr& service, const CheckResult::Ptr& cr)
+void ClusterCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr)
{
/* fetch specific cluster status */
std::pair<Dictionary::Ptr, Dictionary::Ptr> stats;
class ClusterCheckTask
{
public:
- static void ScriptFunc(const Service::Ptr& service, const CheckResult::Ptr& cr);
+ static void ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr);
private:
ClusterCheckTask(void);
m_MessageQueue.SetExceptionCallback(&ClusterListener::MessageExceptionHandler);
- Service::OnNewCheckResult.connect(boost::bind(&ClusterListener::CheckResultHandler, this, _1, _2, _3));
- Service::OnNextCheckChanged.connect(boost::bind(&ClusterListener::NextCheckChangedHandler, this, _1, _2, _3));
+ Checkable::OnNewCheckResult.connect(boost::bind(&ClusterListener::CheckResultHandler, this, _1, _2, _3));
+ Checkable::OnNextCheckChanged.connect(boost::bind(&ClusterListener::NextCheckChangedHandler, this, _1, _2, _3));
Notification::OnNextNotificationChanged.connect(boost::bind(&ClusterListener::NextNotificationChangedHandler, this, _1, _2, _3));
- Service::OnForceNextCheckChanged.connect(boost::bind(&ClusterListener::ForceNextCheckChangedHandler, this, _1, _2, _3));
- Service::OnForceNextNotificationChanged.connect(boost::bind(&ClusterListener::ForceNextNotificationChangedHandler, this, _1, _2, _3));
- Service::OnEnableActiveChecksChanged.connect(boost::bind(&ClusterListener::EnableActiveChecksChangedHandler, this, _1, _2, _3));
- Service::OnEnablePassiveChecksChanged.connect(boost::bind(&ClusterListener::EnablePassiveChecksChangedHandler, this, _1, _2, _3));
- Service::OnEnableNotificationsChanged.connect(boost::bind(&ClusterListener::EnableNotificationsChangedHandler, this, _1, _2, _3));
- Service::OnEnableFlappingChanged.connect(boost::bind(&ClusterListener::EnableFlappingChangedHandler, this, _1, _2, _3));
- Service::OnCommentAdded.connect(boost::bind(&ClusterListener::CommentAddedHandler, this, _1, _2, _3));
- Service::OnCommentRemoved.connect(boost::bind(&ClusterListener::CommentRemovedHandler, this, _1, _2, _3));
- Service::OnDowntimeAdded.connect(boost::bind(&ClusterListener::DowntimeAddedHandler, this, _1, _2, _3));
- Service::OnDowntimeRemoved.connect(boost::bind(&ClusterListener::DowntimeRemovedHandler, this, _1, _2, _3));
- Service::OnAcknowledgementSet.connect(boost::bind(&ClusterListener::AcknowledgementSetHandler, this, _1, _2, _3, _4, _5, _6));
- Service::OnAcknowledgementCleared.connect(boost::bind(&ClusterListener::AcknowledgementClearedHandler, this, _1, _2));
+ Checkable::OnForceNextCheckChanged.connect(boost::bind(&ClusterListener::ForceNextCheckChangedHandler, this, _1, _2, _3));
+ Checkable::OnForceNextNotificationChanged.connect(boost::bind(&ClusterListener::ForceNextNotificationChangedHandler, this, _1, _2, _3));
+ Checkable::OnEnableActiveChecksChanged.connect(boost::bind(&ClusterListener::EnableActiveChecksChangedHandler, this, _1, _2, _3));
+ Checkable::OnEnablePassiveChecksChanged.connect(boost::bind(&ClusterListener::EnablePassiveChecksChangedHandler, this, _1, _2, _3));
+ Checkable::OnEnableNotificationsChanged.connect(boost::bind(&ClusterListener::EnableNotificationsChangedHandler, this, _1, _2, _3));
+ Checkable::OnEnableFlappingChanged.connect(boost::bind(&ClusterListener::EnableFlappingChangedHandler, this, _1, _2, _3));
+ Checkable::OnCommentAdded.connect(boost::bind(&ClusterListener::CommentAddedHandler, this, _1, _2, _3));
+ Checkable::OnCommentRemoved.connect(boost::bind(&ClusterListener::CommentRemovedHandler, this, _1, _2, _3));
+ Checkable::OnDowntimeAdded.connect(boost::bind(&ClusterListener::DowntimeAddedHandler, this, _1, _2, _3));
+ Checkable::OnDowntimeRemoved.connect(boost::bind(&ClusterListener::DowntimeRemovedHandler, this, _1, _2, _3));
+ Checkable::OnAcknowledgementSet.connect(boost::bind(&ClusterListener::AcknowledgementSetHandler, this, _1, _2, _3, _4, _5, _6));
+ Checkable::OnAcknowledgementCleared.connect(boost::bind(&ClusterListener::AcknowledgementClearedHandler, this, _1, _2));
Endpoint::OnMessageReceived.connect(boost::bind(&ClusterListener::AsyncMessageHandler, this, _1, _2));
message->Set("security", security);
}
-void ClusterListener::CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr& cr, const String& authority)
+void ClusterListener::CheckResultHandler(const Checkable::Ptr& service, const CheckResult::Ptr& cr, const String& authority)
{
if (!authority.IsEmpty() && authority != GetIdentity())
return;
AsyncRelayMessage(Endpoint::Ptr(), message, true);
}
-void ClusterListener::NextCheckChangedHandler(const Service::Ptr& service, double nextCheck, const String& authority)
+void ClusterListener::NextCheckChangedHandler(const Checkable::Ptr& service, double nextCheck, const String& authority)
{
if (!authority.IsEmpty() && authority != GetIdentity())
return;
message->Set("method", "cluster::SetNextNotification");
message->Set("params", params);
- SetSecurityInfo(message, notification->GetService(), DomainPrivRead);
+ SetSecurityInfo(message, notification->GetCheckable(), DomainPrivRead);
AsyncRelayMessage(Endpoint::Ptr(), message, true);
}
-void ClusterListener::ForceNextCheckChangedHandler(const Service::Ptr& service, bool forced, const String& authority)
+void ClusterListener::ForceNextCheckChangedHandler(const Checkable::Ptr& service, bool forced, const String& authority)
{
if (!authority.IsEmpty() && authority != GetIdentity())
return;
AsyncRelayMessage(Endpoint::Ptr(), message, true);
}
-void ClusterListener::ForceNextNotificationChangedHandler(const Service::Ptr& service, bool forced, const String& authority)
+void ClusterListener::ForceNextNotificationChangedHandler(const Checkable::Ptr& service, bool forced, const String& authority)
{
if (!authority.IsEmpty() && authority != GetIdentity())
return;
AsyncRelayMessage(Endpoint::Ptr(), message, true);
}
-void ClusterListener::EnableActiveChecksChangedHandler(const Service::Ptr& service, bool enabled, const String& authority)
+void ClusterListener::EnableActiveChecksChangedHandler(const Checkable::Ptr& service, bool enabled, const String& authority)
{
if (!authority.IsEmpty() && authority != GetIdentity())
return;
AsyncRelayMessage(Endpoint::Ptr(), message, true);
}
-void ClusterListener::EnablePassiveChecksChangedHandler(const Service::Ptr& service, bool enabled, const String& authority)
+void ClusterListener::EnablePassiveChecksChangedHandler(const Checkable::Ptr& service, bool enabled, const String& authority)
{
if (!authority.IsEmpty() && authority != GetIdentity())
return;
AsyncRelayMessage(Endpoint::Ptr(), message, true);
}
-void ClusterListener::EnableNotificationsChangedHandler(const Service::Ptr& service, bool enabled, const String& authority)
+void ClusterListener::EnableNotificationsChangedHandler(const Checkable::Ptr& service, bool enabled, const String& authority)
{
if (!authority.IsEmpty() && authority != GetIdentity())
return;
AsyncRelayMessage(Endpoint::Ptr(), message, true);
}
-void ClusterListener::EnableFlappingChangedHandler(const Service::Ptr& service, bool enabled, const String& authority)
+void ClusterListener::EnableFlappingChangedHandler(const Checkable::Ptr& service, bool enabled, const String& authority)
{
if (!authority.IsEmpty() && authority != GetIdentity())
return;
AsyncRelayMessage(Endpoint::Ptr(), message, true);
}
-void ClusterListener::CommentAddedHandler(const Service::Ptr& service, const Comment::Ptr& comment, const String& authority)
+void ClusterListener::CommentAddedHandler(const Checkable::Ptr& service, const Comment::Ptr& comment, const String& authority)
{
if (!authority.IsEmpty() && authority != GetIdentity())
return;
AsyncRelayMessage(Endpoint::Ptr(), message, true);
}
-void ClusterListener::CommentRemovedHandler(const Service::Ptr& service, const Comment::Ptr& comment, const String& authority)
+void ClusterListener::CommentRemovedHandler(const Checkable::Ptr& service, const Comment::Ptr& comment, const String& authority)
{
if (!authority.IsEmpty() && authority != GetIdentity())
return;
AsyncRelayMessage(Endpoint::Ptr(), message, true);
}
-void ClusterListener::DowntimeAddedHandler(const Service::Ptr& service, const Downtime::Ptr& downtime, const String& authority)
+void ClusterListener::DowntimeAddedHandler(const Checkable::Ptr& service, const Downtime::Ptr& downtime, const String& authority)
{
if (!authority.IsEmpty() && authority != GetIdentity())
return;
AsyncRelayMessage(Endpoint::Ptr(), message, true);
}
-void ClusterListener::DowntimeRemovedHandler(const Service::Ptr& service, const Downtime::Ptr& downtime, const String& authority)
+void ClusterListener::DowntimeRemovedHandler(const Checkable::Ptr& service, const Downtime::Ptr& downtime, const String& authority)
{
if (!authority.IsEmpty() && authority != GetIdentity())
return;
AsyncRelayMessage(Endpoint::Ptr(), message, true);
}
-void ClusterListener::AcknowledgementSetHandler(const Service::Ptr& service, const String& author, const String& comment, AcknowledgementType type, double expiry, const String& authority)
+void ClusterListener::AcknowledgementSetHandler(const Checkable::Ptr& service, const String& author, const String& comment, AcknowledgementType type, double expiry, const String& authority)
{
if (!authority.IsEmpty() && authority != GetIdentity())
return;
AsyncRelayMessage(Endpoint::Ptr(), message, true);
}
-void ClusterListener::AcknowledgementClearedHandler(const Service::Ptr& service, const String& authority)
+void ClusterListener::AcknowledgementClearedHandler(const Checkable::Ptr& service, const String& authority)
{
if (!authority.IsEmpty() && authority != GetIdentity())
return;
String svc = params->Get("service");
- Service::Ptr service = Service::GetByName(svc);
+ Checkable::Ptr service = Checkable::GetByName(svc);
if (!service)
return;
String svc = params->Get("service");
- Service::Ptr service = Service::GetByName(svc);
+ Checkable::Ptr service = Checkable::GetByName(svc);
if (!service)
return;
String svc = params->Get("service");
- Service::Ptr service = Service::GetByName(svc);
+ Checkable::Ptr service = Checkable::GetByName(svc);
if (!service)
return;
String svc = params->Get("service");
- Service::Ptr service = Service::GetByName(svc);
+ Checkable::Ptr service = Checkable::GetByName(svc);
if (!service)
return;
String svc = params->Get("service");
- Service::Ptr service = Service::GetByName(svc);
+ Checkable::Ptr service = Checkable::GetByName(svc);
if (!service)
return;
String svc = params->Get("service");
- Service::Ptr service = Service::GetByName(svc);
+ Checkable::Ptr service = Checkable::GetByName(svc);
if (!service)
return;
String svc = params->Get("service");
- Service::Ptr service = Service::GetByName(svc);
+ Checkable::Ptr service = Checkable::GetByName(svc);
if (!service)
return;
String svc = params->Get("service");
- Service::Ptr service = Service::GetByName(svc);
+ Checkable::Ptr service = Checkable::GetByName(svc);
if (!service)
return;
if (!notification)
return;
- Service::Ptr service = notification->GetService();
+ Checkable::Ptr service = notification->GetCheckable();
if (!service->HasPrivileges(sender->GetName(), DomainPrivCommand)) {
Log(LogDebug, "cluster", "Not accepting cluster::SetNextNotification message from endpoint '" + sender->GetName() + "' for service '" + service->GetName() + "': Insufficient privileges.");
String svc = params->Get("service");
- Service::Ptr service = Service::GetByName(svc);
+ Checkable::Ptr service = Checkable::GetByName(svc);
if (!service)
return;
String svc = params->Get("service");
- Service::Ptr service = Service::GetByName(svc);
+ Checkable::Ptr service = Checkable::GetByName(svc);
if (!service)
return;
String svc = params->Get("service");
- Service::Ptr service = Service::GetByName(svc);
+ Checkable::Ptr service = Checkable::GetByName(svc);
if (!service)
return;
String svc = params->Get("service");
- Service::Ptr service = Service::GetByName(svc);
+ Checkable::Ptr service = Checkable::GetByName(svc);
if (!service)
return;
String svc = params->Get("service");
- Service::Ptr service = Service::GetByName(svc);
+ Checkable::Ptr service = Checkable::GetByName(svc);
if (!service)
return;
String svc = params->Get("service");
- Service::Ptr service = Service::GetByName(svc);
+ Checkable::Ptr service = Checkable::GetByName(svc);
if (!service)
return;
Stream::Ptr m_LogFile;
size_t m_LogMessageCount;
- void CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr& cr, const String& authority);
- void NextCheckChangedHandler(const Service::Ptr& service, double nextCheck, const String& authority);
+ void CheckResultHandler(const Checkable::Ptr& service, const CheckResult::Ptr& cr, const String& authority);
+ void NextCheckChangedHandler(const Checkable::Ptr& service, double nextCheck, const String& authority);
void NextNotificationChangedHandler(const Notification::Ptr& notification, double nextCheck, const String& authority);
- void ForceNextCheckChangedHandler(const Service::Ptr& service, bool forced, const String& authority);
- void ForceNextNotificationChangedHandler(const Service::Ptr& service, bool forced, const String& authority);
- void EnableActiveChecksChangedHandler(const Service::Ptr& service, bool enabled, const String& authority);
- void EnablePassiveChecksChangedHandler(const Service::Ptr& service, bool enabled, const String& authority);
- void EnableNotificationsChangedHandler(const Service::Ptr& service, bool enabled, const String& authority);
- void EnableFlappingChangedHandler(const Service::Ptr& service, bool enabled, const String& authority);
- void CommentAddedHandler(const Service::Ptr& service, const Comment::Ptr& comment, const String& authority);
- void CommentRemovedHandler(const Service::Ptr& service, const Comment::Ptr& comment, const String& authority);
- void DowntimeAddedHandler(const Service::Ptr& service, const Downtime::Ptr& downtime, const String& authority);
- void DowntimeRemovedHandler(const Service::Ptr& service, const Downtime::Ptr& downtime, const String& authority);
- void AcknowledgementSetHandler(const Service::Ptr& service, const String& author, const String& comment, AcknowledgementType type, double expiry, const String& authority);
- void AcknowledgementClearedHandler(const Service::Ptr& service, const String& authority);
+ void ForceNextCheckChangedHandler(const Checkable::Ptr& service, bool forced, const String& authority);
+ void ForceNextNotificationChangedHandler(const Checkable::Ptr& service, bool forced, const String& authority);
+ void EnableActiveChecksChangedHandler(const Checkable::Ptr& service, bool enabled, const String& authority);
+ void EnablePassiveChecksChangedHandler(const Checkable::Ptr& service, bool enabled, const String& authority);
+ void EnableNotificationsChangedHandler(const Checkable::Ptr& service, bool enabled, const String& authority);
+ void EnableFlappingChangedHandler(const Checkable::Ptr& service, bool enabled, const String& authority);
+ void CommentAddedHandler(const Checkable::Ptr& service, const Comment::Ptr& comment, const String& authority);
+ void CommentRemovedHandler(const Checkable::Ptr& service, const Comment::Ptr& comment, const String& authority);
+ void DowntimeAddedHandler(const Checkable::Ptr& service, const Downtime::Ptr& downtime, const String& authority);
+ void DowntimeRemovedHandler(const Checkable::Ptr& service, const Downtime::Ptr& downtime, const String& authority);
+ void AcknowledgementSetHandler(const Checkable::Ptr& service, const String& author, const String& comment, AcknowledgementType type, double expiry, const String& authority);
+ void AcknowledgementClearedHandler(const Checkable::Ptr& service, const String& authority);
void AsyncMessageHandler(const Endpoint::Ptr& sender, const Dictionary::Ptr& message);
void MessageHandler(const Endpoint::Ptr& sender, const Dictionary::Ptr& message);
{
DynamicObject::Start();
- Service::OnNewCheckResult.connect(bind(&CompatLogger::CheckResultHandler, this, _1, _2));
- Service::OnNotificationSentToUser.connect(bind(&CompatLogger::NotificationSentHandler, this, _1, _2, _3, _4, _5, _6, _7, _8));
- Service::OnFlappingChanged.connect(bind(&CompatLogger::FlappingHandler, this, _1, _2));
- Service::OnDowntimeTriggered.connect(boost::bind(&CompatLogger::TriggerDowntimeHandler, this, _1, _2));
- Service::OnDowntimeRemoved.connect(boost::bind(&CompatLogger::RemoveDowntimeHandler, this, _1, _2));
- Service::OnEventCommandExecuted.connect(bind(&CompatLogger::EventCommandHandler, this, _1));
+ Checkable::OnNewCheckResult.connect(bind(&CompatLogger::CheckResultHandler, this, _1, _2));
+ Checkable::OnNotificationSentToUser.connect(bind(&CompatLogger::NotificationSentHandler, this, _1, _2, _3, _4, _5, _6, _7, _8));
+ Checkable::OnFlappingChanged.connect(bind(&CompatLogger::FlappingHandler, this, _1, _2));
+ Checkable::OnDowntimeTriggered.connect(boost::bind(&CompatLogger::TriggerDowntimeHandler, this, _1, _2));
+ Checkable::OnDowntimeRemoved.connect(boost::bind(&CompatLogger::RemoveDowntimeHandler, this, _1, _2));
+ Checkable::OnEventCommandExecuted.connect(bind(&CompatLogger::EventCommandHandler, this, _1));
ExternalCommandProcessor::OnNewExternalCommand.connect(boost::bind(&CompatLogger::ExternalCommandHandler, this, _2, _3));
m_RotationTimer = make_shared<Timer>();
/**
* @threadsafety Always.
*/
-void CompatLogger::CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr &cr)
+void CompatLogger::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr &cr)
{
- Host::Ptr host = service->GetHost();
+ bool is_service = checkable->GetType() == DynamicType::GetByName("Service");
+ Host::Ptr host;
+ Service::Ptr service;
+
+ if (is_service) {
+ service = static_pointer_cast<Service>(checkable);
+ host = static_pointer_cast<Service>(checkable)->GetHost();
+ } else
+ host = static_pointer_cast<Host>(checkable);
Dictionary::Ptr vars_after = cr->GetVarsAfter();
output = CompatUtility::GetCheckResultOutput(cr);
std::ostringstream msgbuf;
- msgbuf << "SERVICE ALERT: "
- << host->GetName() << ";"
- << service->GetShortName() << ";"
- << Service::StateToString(static_cast<ServiceState>(state_after)) << ";"
- << Service::StateTypeToString(static_cast<StateType>(stateType_after)) << ";"
- << attempt_after << ";"
- << output << ""
- << "";
- {
- ObjectLock olock(this);
- WriteLine(msgbuf.str());
- }
-
- if (service == host->GetCheckService()) {
- std::ostringstream msgbuf;
+ if (is_service) {
+ msgbuf << "SERVICE ALERT: "
+ << host->GetName() << ";"
+ << service->GetShortName() << ";"
+ << Service::StateToString(static_cast<ServiceState>(state_after)) << ";"
+ << Service::StateTypeToString(static_cast<StateType>(stateType_after)) << ";"
+ << attempt_after << ";"
+ << output << ""
+ << "";
+ } else {
msgbuf << "HOST ALERT: "
<< host->GetName() << ";"
<< Host::StateToString(Host::CalculateState(static_cast<ServiceState>(state_after), host_reachable_after)) << ";"
- << Service::StateTypeToString(static_cast<StateType>(stateType_after)) << ";"
+ << Host::StateTypeToString(static_cast<StateType>(stateType_after)) << ";"
<< attempt_after << ";"
<< output << ""
<< "";
- {
- ObjectLock olock(this);
- WriteLine(msgbuf.str());
- }
-
}
{
ObjectLock olock(this);
+ WriteLine(msgbuf.str());
Flush();
}
}
/**
* @threadsafety Always.
*/
-void CompatLogger::TriggerDowntimeHandler(const Service::Ptr& service, const Downtime::Ptr& downtime)
+void CompatLogger::TriggerDowntimeHandler(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime)
{
- Host::Ptr host = service->GetHost();
+ bool is_service = checkable->GetType() == DynamicType::GetByName("Service");
+ Host::Ptr host;
+ Service::Ptr service;
+
+ if (is_service) {
+ service = static_pointer_cast<Service>(checkable);
+ host = static_pointer_cast<Service>(checkable)->GetHost();
+ } else
+ host = static_pointer_cast<Host>(checkable);
if (!downtime)
return;
std::ostringstream msgbuf;
- msgbuf << "SERVICE DOWNTIME ALERT: "
- << host->GetName() << ";"
- << service->GetShortName() << ";"
- << "STARTED" << "; "
- << "Service has entered a period of scheduled downtime."
- << "";
-
- {
- ObjectLock oLock(this);
- WriteLine(msgbuf.str());
- }
- if (service == host->GetCheckService()) {
- std::ostringstream msgbuf;
+ if (is_service) {
+ msgbuf << "SERVICE DOWNTIME ALERT: "
+ << host->GetName() << ";"
+ << service->GetShortName() << ";"
+ << "STARTED" << "; "
+ << "Checkable has entered a period of scheduled downtime."
+ << "";
+ } else {
msgbuf << "HOST DOWNTIME ALERT: "
<< host->GetName() << ";"
<< "STARTED" << "; "
- << "Service has entered a period of scheduled downtime."
+ << "Checkable has entered a period of scheduled downtime."
<< "";
-
- {
- ObjectLock oLock(this);
- WriteLine(msgbuf.str());
- }
}
{
ObjectLock oLock(this);
+ WriteLine(msgbuf.str());
Flush();
}
}
/**
* @threadsafety Always.
*/
-void CompatLogger::RemoveDowntimeHandler(const Service::Ptr& service, const Downtime::Ptr& downtime)
+void CompatLogger::RemoveDowntimeHandler(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime)
{
- Host::Ptr host = service->GetHost();
+ bool is_service = checkable->GetType() == DynamicType::GetByName("Service");
+ Host::Ptr host;
+ Service::Ptr service;
+
+ if (is_service) {
+ service = static_pointer_cast<Service>(checkable);
+ host = static_pointer_cast<Service>(checkable)->GetHost();
+ } else
+ host = static_pointer_cast<Host>(checkable);
if (!downtime)
return;
downtime_output = "Scheduled downtime for service has been cancelled.";
downtime_state_str = "CANCELLED";
} else {
- downtime_output = "Service has exited from a period of scheduled downtime.";
+ downtime_output = "Checkable has exited from a period of scheduled downtime.";
downtime_state_str = "STOPPED";
}
std::ostringstream msgbuf;
- msgbuf << "SERVICE DOWNTIME ALERT: "
- << host->GetName() << ";"
- << service->GetShortName() << ";"
- << downtime_state_str << "; "
- << downtime_output
- << "";
-
- {
- ObjectLock oLock(this);
- WriteLine(msgbuf.str());
- }
- if (service == host->GetCheckService()) {
- std::ostringstream msgbuf;
+ if (is_service) {
+ msgbuf << "SERVICE DOWNTIME ALERT: "
+ << host->GetName() << ";"
+ << service->GetShortName() << ";"
+ << downtime_state_str << "; "
+ << downtime_output
+ << "";
+ } else {
msgbuf << "HOST DOWNTIME ALERT: "
<< host->GetName() << ";"
<< downtime_state_str << "; "
<< downtime_output
<< "";
-
- {
- ObjectLock oLock(this);
- WriteLine(msgbuf.str());
- }
}
{
ObjectLock oLock(this);
+ WriteLine(msgbuf.str());
Flush();
}
}
/**
* @threadsafety Always.
*/
-void CompatLogger::NotificationSentHandler(const Notification::Ptr& notification, const Service::Ptr& service,
+void CompatLogger::NotificationSentHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable,
const User::Ptr& user, NotificationType const& notification_type, CheckResult::Ptr const& cr,
const String& author, const String& comment_text, const String& command_name)
{
- Host::Ptr host = service->GetHost();
+ bool is_service = checkable->GetType() == DynamicType::GetByName("Service");
+ Host::Ptr host;
+ Service::Ptr service;
+
+ if (is_service) {
+ service = static_pointer_cast<Service>(checkable);
+ host = static_pointer_cast<Service>(checkable)->GetHost();
+ } else
+ host = static_pointer_cast<Host>(checkable);
String notification_type_str = Notification::NotificationTypeToString(notification_type);
/* override problem notifications with their current state string */
- if (notification_type == NotificationProblem)
- notification_type_str = Service::StateToString(service->GetState());
+ if (notification_type == NotificationProblem) {
+ if (is_service)
+ notification_type_str = Service::StateToString(service->GetState());
+ else
+ notification_type_str = Host::StateToString(host->GetState());
+ }
String author_comment = "";
if (notification_type == NotificationCustom || notification_type == NotificationAcknowledgement) {
output = CompatUtility::GetCheckResultOutput(cr);
std::ostringstream msgbuf;
- msgbuf << "SERVICE NOTIFICATION: "
- << user->GetName() << ";"
- << host->GetName() << ";"
- << service->GetShortName() << ";"
- << notification_type_str << ";"
- << command_name << ";"
- << output << ";"
- << author_comment
- << "";
- {
- ObjectLock oLock(this);
- WriteLine(msgbuf.str());
- }
-
- if (service == host->GetCheckService()) {
- std::ostringstream msgbuf;
+ if (is_service) {
+ msgbuf << "SERVICE NOTIFICATION: "
+ << user->GetName() << ";"
+ << host->GetName() << ";"
+ << service->GetShortName() << ";"
+ << notification_type_str << ";"
+ << command_name << ";"
+ << output << ";"
+ << author_comment
+ << "";
+ } else {
msgbuf << "HOST NOTIFICATION: "
<< user->GetName() << ";"
<< host->GetName() << ";"
<< notification_type_str << " "
- << "(" << Service::StateToString(service->GetState()) << ");"
+ << "(" << Host::StateToString(host->GetState()) << ");"
<< command_name << ";"
<< output << ";"
<< author_comment
<< "";
+ }
- {
- ObjectLock oLock(this);
- WriteLine(msgbuf.str());
- }
- }
-
- {
- ObjectLock oLock(this);
+ {
+ ObjectLock oLock(this);
+ WriteLine(msgbuf.str());
Flush();
}
}
/**
* @threadsafety Always.
*/
-void CompatLogger::FlappingHandler(const Service::Ptr& service, FlappingState flapping_state)
+void CompatLogger::FlappingHandler(const Checkable::Ptr& checkable, FlappingState flapping_state)
{
- Host::Ptr host = service->GetHost();
+ bool is_service = checkable->GetType() == DynamicType::GetByName("Service");
+ Host::Ptr host;
+ Service::Ptr service;
+
+ if (is_service) {
+ service = static_pointer_cast<Service>(checkable);
+ host = static_pointer_cast<Service>(checkable)->GetHost();
+ } else
+ host = static_pointer_cast<Host>(checkable);
String flapping_state_str;
String flapping_output;
switch (flapping_state) {
case FlappingStarted:
- flapping_output = "Service appears to have started flapping (" + Convert::ToString(service->GetFlappingCurrent()) + "% change >= " + Convert::ToString(service->GetFlappingThreshold()) + "% threshold)";
+ flapping_output = "Checkable appears to have started flapping (" + Convert::ToString(service->GetFlappingCurrent()) + "% change >= " + Convert::ToString(service->GetFlappingThreshold()) + "% threshold)";
flapping_state_str = "STARTED";
break;
case FlappingStopped:
- flapping_output = "Service appears to have stopped flapping (" + Convert::ToString(service->GetFlappingCurrent()) + "% change < " + Convert::ToString(service->GetFlappingThreshold()) + "% threshold)";
+ flapping_output = "Checkable appears to have stopped flapping (" + Convert::ToString(service->GetFlappingCurrent()) + "% change < " + Convert::ToString(service->GetFlappingThreshold()) + "% threshold)";
flapping_state_str = "STOPPED";
break;
case FlappingDisabled:
}
std::ostringstream msgbuf;
- msgbuf << "SERVICE FLAPPING ALERT: "
- << host->GetName() << ";"
- << service->GetShortName() << ";"
- << flapping_state_str << "; "
- << flapping_output
- << "";
-
- {
- ObjectLock oLock(this);
- WriteLine(msgbuf.str());
- }
- if (service == host->GetCheckService()) {
- std::ostringstream msgbuf;
+ if (is_service) {
+ msgbuf << "SERVICE FLAPPING ALERT: "
+ << host->GetName() << ";"
+ << service->GetShortName() << ";"
+ << flapping_state_str << "; "
+ << flapping_output
+ << "";
+ } else {
msgbuf << "HOST FLAPPING ALERT: "
<< host->GetName() << ";"
<< flapping_state_str << "; "
<< flapping_output
<< "";
+ }
- {
- ObjectLock oLock(this);
- WriteLine(msgbuf.str());
- }
- }
-
- {
- ObjectLock oLock(this);
+ {
+ ObjectLock oLock(this);
+ WriteLine(msgbuf.str());
Flush();
}
}
}
}
-void CompatLogger::EventCommandHandler(const Service::Ptr& service)
+void CompatLogger::EventCommandHandler(const Checkable::Ptr& checkable)
{
- Host::Ptr host = service->GetHost();
+ bool is_service = checkable->GetType() == DynamicType::GetByName("Service");
+ Host::Ptr host;
+ Service::Ptr service;
+
+ if (is_service) {
+ service = static_pointer_cast<Service>(checkable);
+ host = static_pointer_cast<Service>(checkable)->GetHost();
+ } else
+ host = static_pointer_cast<Host>(checkable);
EventCommand::Ptr event_command = service->GetEventCommand();
String event_command_name = event_command->GetName();
- String state = Service::StateToString(service->GetState());
- String state_type = Service::StateTypeToString(service->GetStateType());
long current_attempt = service->GetCheckAttempt();
std::ostringstream msgbuf;
- msgbuf << "SERVICE EVENT HANDLER: "
- << host->GetName() << ";"
- << service->GetShortName() << ";"
- << state << ";"
- << state_type << ";"
- << current_attempt << ";"
- << event_command_name;
-
- {
- ObjectLock oLock(this);
- WriteLine(msgbuf.str());
- }
-
- if (service == host->GetCheckService()) {
- std::ostringstream msgbuf;
- msgbuf << "HOST EVENT HANDLER: "
+ if (is_service) {
+ msgbuf << "SERVICE EVENT HANDLER: "
+ << host->GetName() << ";"
+ << service->GetShortName() << ";"
+ << Service::StateToString(service->GetState()) << ";"
+ << Service::StateTypeToString(service->GetStateType()) << ";"
+ << current_attempt << ";"
+ << event_command_name;
+ } else {
+ msgbuf << "HOST EVENT HANDLER: "
<< host->GetName() << ";"
- << state << ";"
- << state_type << ";"
+ << Host::StateToString(host->GetState()) << ";"
+ << Host::StateTypeToString(host->GetStateType()) << ";"
<< current_attempt << ";"
<< event_command_name;
+ }
- {
- ObjectLock oLock(this);
- WriteLine(msgbuf.str());
- }
- }
-
- {
- ObjectLock oLock(this);
+ {
+ ObjectLock oLock(this);
+ WriteLine(msgbuf.str());
Flush();
}
}
WriteLine("LOG VERSION: 2.0");
BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- continue;
-
- bool reachable = host->IsReachable();
-
- ObjectLock olock(hc);
-
String output;
- CheckResult::Ptr cr = hc->GetLastCheckResult();
+ CheckResult::Ptr cr = host->GetLastCheckResult();
if (cr)
output = CompatUtility::GetCheckResultOutput(cr);
std::ostringstream msgbuf;
msgbuf << "CURRENT HOST STATE: "
<< host->GetName() << ";"
- << Host::StateToString(Host::CalculateState(hc->GetState(), reachable)) << ";"
- << Service::StateTypeToString(hc->GetStateType()) << ";"
- << hc->GetCheckAttempt() << ";"
+ << Host::StateToString(host->GetState()) << ";"
+ << Host::StateTypeToString(host->GetStateType()) << ";"
+ << host->GetCheckAttempt() << ";"
<< output << "";
WriteLine(msgbuf.str());
void WriteLine(const String& line);
void Flush(void);
- void CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr& cr);
- void NotificationSentHandler(const Notification::Ptr& notification, const Service::Ptr& service,
+ void CheckResultHandler(const Checkable::Ptr& service, const CheckResult::Ptr& cr);
+ void NotificationSentHandler(const Notification::Ptr& notification, const Checkable::Ptr& service,
const User::Ptr& user, NotificationType const& notification_type, CheckResult::Ptr const& cr,
const String& author, const String& comment_text, const String& command_name);
- void FlappingHandler(const Service::Ptr& service, FlappingState flapping_state);
- void TriggerDowntimeHandler(const Service::Ptr& service, const Downtime::Ptr& downtime);
- void RemoveDowntimeHandler(const Service::Ptr& service, const Downtime::Ptr& downtime);
+ void FlappingHandler(const Checkable::Ptr& service, FlappingState flapping_state);
+ void TriggerDowntimeHandler(const Checkable::Ptr& service, const Downtime::Ptr& downtime);
+ void RemoveDowntimeHandler(const Checkable::Ptr& service, const Downtime::Ptr& downtime);
void ExternalCommandHandler(const String& command, const std::vector<String>& arguments);
- void EventCommandHandler(const Service::Ptr& service);
+ void EventCommandHandler(const Checkable::Ptr& service);
Timer::Ptr m_RotationTimer;
void RotationTimerHandler(void);
Utility::QueueAsyncCallback(boost::bind(&StatusDataWriter::UpdateObjectsCache, this));
}
-void StatusDataWriter::DumpComments(std::ostream& fp, const Service::Ptr& owner, CompatObjectType type)
+void StatusDataWriter::DumpComments(std::ostream& fp, const Checkable::Ptr& checkable)
{
- Service::Ptr service;
- Dictionary::Ptr comments = owner->GetComments();
+ Dictionary::Ptr comments = checkable->GetComments();
- Host::Ptr host = owner->GetHost();
+ Host::Ptr host;
+ Service::Ptr service;
+ tie(host, service) = GetHostService(checkable);
ObjectLock olock(comments);
if (comment->IsExpired())
continue;
- if (type == CompatTypeHost)
- fp << "hostcomment {" << "\n";
- else
+ if (service)
fp << "servicecomment {" << "\n"
- << "\t" << "service_description=" << owner->GetShortName() << "\n";
+ << "\t" << "service_description=" << service->GetShortName() << "\n";
+ else
+ fp << "hostcomment {" << "\n";
fp << "\t" "host_name=" << host->GetName() << "\n"
"\t" "comment_id=" << comment->GetLegacyId() << "\n"
"\n";
}
-void StatusDataWriter::DumpDowntimes(std::ostream& fp, const Service::Ptr& owner, CompatObjectType type)
+void StatusDataWriter::DumpDowntimes(std::ostream& fp, const Checkable::Ptr& checkable)
{
- Host::Ptr host = owner->GetHost();
+ Dictionary::Ptr downtimes = checkable->GetDowntimes();
- Dictionary::Ptr downtimes = owner->GetDowntimes();
+ Host::Ptr host;
+ Service::Ptr service;
+ tie(host, service) = GetHostService(checkable);
ObjectLock olock(downtimes);
if (downtime->IsExpired())
continue;
- if (type == CompatTypeHost)
- fp << "hostdowntime {" "\n";
- else
+ if (service)
fp << "servicedowntime {" << "\n"
- "\t" "service_description=" << owner->GetShortName() << "\n";
+ "\t" "service_description=" << service->GetShortName() << "\n";
+ else
+ fp << "hostdowntime {" "\n";
Downtime::Ptr triggeredByObj = Service::GetDowntimeByID(downtime->GetTriggeredBy());
int triggeredByLegacy = 0;
fp << "hoststatus {" << "\n"
<< "\t" << "host_name=" << host->GetName() << "\n";
- Service::Ptr hc = host->GetCheckService();
- ObjectLock olock(hc);
-
- if (hc) {
- /* only dump status data information for Classic UI */
- fp << "\t" "check_service=" << hc->GetShortName() << "\n";
- DumpServiceStatusAttrs(fp, hc, CompatTypeHost);
+ {
+ ObjectLock olock(host);
+ DumpCheckableStatusAttrs(fp, host);
}
/* ugly but cgis parse only that */
fp << "\t" "}" "\n"
"\n";
- if (hc) {
- DumpDowntimes(fp, hc, CompatTypeHost);
- DumpComments(fp, hc, CompatTypeHost);
- }
+ DumpDowntimes(fp, host);
+ DumpComments(fp, host);
}
void StatusDataWriter::DumpHostObject(std::ostream& fp, const Host::Ptr& host)
if (!statusmap_image.IsEmpty())
fp << "\t" "statusmap_image" "\t" << statusmap_image << "\n";
- std::set<Host::Ptr> parents = host->GetParentHosts();
+ std::set<Checkable::Ptr> parents = host->GetParents();
if (!parents.empty()) {
fp << "\t" "parents" "\t";
fp << "\n";
}
- Service::Ptr hc = host->GetCheckService();
- if (hc) {
- ObjectLock olock(hc);
-
- fp << "\t" "check_interval" "\t" << CompatUtility::GetServiceCheckInterval(hc) << "\n"
- "\t" "retry_interval" "\t" << CompatUtility::GetServiceRetryInterval(hc) << "\n"
- "\t" "max_check_attempts" "\t" << hc->GetMaxCheckAttempts() << "\n"
- "\t" "active_checks_enabled" "\t" << CompatUtility::GetServiceActiveChecksEnabled(hc) << "\n"
- "\t" "passive_checks_enabled" "\t" << CompatUtility::GetServicePassiveChecksEnabled(hc) << "\n"
- "\t" "notifications_enabled" "\t" << CompatUtility::GetServiceNotificationsEnabled(hc) << "\n"
- "\t" "notification_options" "\t" << "d,u,r" << "\n"
- "\t" "notification_interval" "\t" << CompatUtility::GetServiceNotificationNotificationInterval(hc) << "\n"
- "\t" "event_handler_enabled" "\t" << CompatUtility::GetServiceEventHandlerEnabled(hc) << "\n";
-
- CheckCommand::Ptr checkcommand = hc->GetCheckCommand();
- if (checkcommand)
- fp << "\t" "check_command" "\t" "check_" << checkcommand->GetName() << "\n";
+ ObjectLock olock(host);
- EventCommand::Ptr eventcommand = hc->GetEventCommand();
- if (eventcommand)
- fp << "\t" "event_handler" "\t" "event_" << eventcommand->GetName() << "\n";
+ fp << "\t" "check_interval" "\t" << CompatUtility::GetCheckableCheckInterval(host) << "\n"
+ "\t" "retry_interval" "\t" << CompatUtility::GetCheckableRetryInterval(host) << "\n"
+ "\t" "max_check_attempts" "\t" << host->GetMaxCheckAttempts() << "\n"
+ "\t" "active_checks_enabled" "\t" << CompatUtility::GetCheckableActiveChecksEnabled(host) << "\n"
+ "\t" "passive_checks_enabled" "\t" << CompatUtility::GetCheckablePassiveChecksEnabled(host) << "\n"
+ "\t" "notifications_enabled" "\t" << CompatUtility::GetCheckableNotificationsEnabled(host) << "\n"
+ "\t" "notification_options" "\t" << "d,u,r" << "\n"
+ "\t" "notification_interval" "\t" << CompatUtility::GetCheckableNotificationNotificationInterval(host) << "\n"
+ "\t" "event_handler_enabled" "\t" << CompatUtility::GetCheckableEventHandlerEnabled(host) << "\n";
- fp << "\t" "check_period" "\t" << CompatUtility::GetServiceCheckPeriod(hc) << "\n";
+ CheckCommand::Ptr checkcommand = host->GetCheckCommand();
+ if (checkcommand)
+ fp << "\t" "check_command" "\t" "check_" << checkcommand->GetName() << "\n";
- fp << "\t" "contacts" "\t";
- DumpNameList(fp, CompatUtility::GetServiceNotificationUsers(hc));
- fp << "\n";
+ EventCommand::Ptr eventcommand = host->GetEventCommand();
+ if (eventcommand)
+ fp << "\t" "event_handler" "\t" "event_" << eventcommand->GetName() << "\n";
- fp << "\t" "contact_groups" "\t";
- DumpNameList(fp, CompatUtility::GetServiceNotificationUserGroups(hc));
- fp << "\n";
+ fp << "\t" "check_period" "\t" << CompatUtility::GetCheckableCheckPeriod(host) << "\n";
- fp << "\t" << "initial_state" "\t" "o" "\n"
- "\t" "low_flap_threshold" "\t" << hc->GetFlappingThreshold() << "\n"
- "\t" "high_flap_threshold" "\t" << hc->GetFlappingThreshold() << "\n"
- "\t" "process_perf_data" "\t" << CompatUtility::GetServiceProcessPerformanceData(hc) << "\n"
- "\t" "check_freshness" "\t" "1" "\n";
+ fp << "\t" "contacts" "\t";
+ DumpNameList(fp, CompatUtility::GetCheckableNotificationUsers(host));
+ fp << "\n";
- } else {
- fp << "\t" << "check_interval" "\t" "60" "\n"
- "\t" "retry_interval" "\t" "60" "\n"
- "\t" "max_check_attempts" "\t" "1" "\n"
- "\t" "active_checks_enabled" "\t" "0" << "\n"
- "\t" "passive_checks_enabled" "\t" "0" "\n"
- "\t" "notifications_enabled" "\t" "0" "\n";
+ fp << "\t" "contact_groups" "\t";
+ DumpNameList(fp, CompatUtility::GetCheckableNotificationUserGroups(host));
+ fp << "\n";
- }
+ fp << "\t" << "initial_state" "\t" "o" "\n"
+ "\t" "low_flap_threshold" "\t" << host->GetFlappingThreshold() << "\n"
+ "\t" "high_flap_threshold" "\t" << host->GetFlappingThreshold() << "\n"
+ "\t" "process_perf_data" "\t" << CompatUtility::GetCheckableProcessPerformanceData(host) << "\n"
+ "\t" "check_freshness" "\t" "1" "\n";
fp << "\t" "host_groups" "\t";
bool first = true;
"\n";
}
-void StatusDataWriter::DumpServiceStatusAttrs(std::ostream& fp, const Service::Ptr& service, CompatObjectType type)
+void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkable::Ptr& checkable)
{
- CheckResult::Ptr cr = service->GetLastCheckResult();
+ CheckResult::Ptr cr = checkable->GetLastCheckResult();
- fp << "\t" << "check_command=check_" << CompatUtility::GetServiceCheckCommand(service) << "\n"
- "\t" "event_handler=event_" << CompatUtility::GetServiceEventHandler(service) << "\n"
- "\t" "check_period=" << CompatUtility::GetServiceCheckPeriod(service) << "\n"
- "\t" "check_interval=" << CompatUtility::GetServiceCheckInterval(service) << "\n"
- "\t" "retry_interval=" << CompatUtility::GetServiceRetryInterval(service) << "\n"
- "\t" "has_been_checked=" << CompatUtility::GetServiceHasBeenChecked(service) << "\n"
- "\t" "should_be_scheduled=" << CompatUtility::GetServiceShouldBeScheduled(service) << "\n";
+ fp << "\t" << "check_command=check_" << CompatUtility::GetCheckableCheckCommand(checkable) << "\n"
+ "\t" "event_handler=event_" << CompatUtility::GetCheckableEventHandler(checkable) << "\n"
+ "\t" "check_period=" << CompatUtility::GetCheckableCheckPeriod(checkable) << "\n"
+ "\t" "check_interval=" << CompatUtility::GetCheckableCheckInterval(checkable) << "\n"
+ "\t" "retry_interval=" << CompatUtility::GetCheckableRetryInterval(checkable) << "\n"
+ "\t" "has_been_checked=" << CompatUtility::GetCheckableHasBeenChecked(checkable) << "\n"
+ "\t" "should_be_scheduled=" << CompatUtility::GetCheckableShouldBeScheduled(checkable) << "\n";
if (cr) {
fp << "\t" << "check_execution_time=" << Convert::ToString(Service::CalculateExecutionTime(cr)) << "\n"
"\t" "check_latency=" << Convert::ToString(Service::CalculateLatency(cr)) << "\n";
}
- if (type == CompatTypeHost && service->IsHostCheck()) {
- fp << "\t" << "current_state=" << service->GetHost()->GetState() << "\n";
- } else {
- fp << "\t" << "current_state=" << CompatUtility::GetServiceCurrentState(service) << "\n";
- }
+ Host::Ptr host;
+ Service::Ptr service;
+ tie(host, service) = GetHostService(checkable);
+
+ if (service)
+ fp << "\t" << "current_state=" << service->GetState() << "\n";
+ else
+ fp << "\t" << "current_state=" << host->GetState() << "\n";
- fp << "\t" "state_type=" << service->GetStateType() << "\n"
+ fp << "\t" "state_type=" << checkable->GetStateType() << "\n"
"\t" "plugin_output=" << CompatUtility::GetCheckResultOutput(cr) << "\n"
"\t" "long_plugin_output=" << CompatUtility::GetCheckResultLongOutput(cr) << "\n"
"\t" "performance_data=" << CompatUtility::GetCheckResultPerfdata(cr) << "\n";
"\t" "last_check=" << static_cast<long>(cr->GetScheduleEnd()) << "\n";
}
- fp << "\t" << "next_check=" << static_cast<long>(service->GetNextCheck()) << "\n"
- "\t" "current_attempt=" << service->GetCheckAttempt() << "\n"
- "\t" "max_attempts=" << service->GetMaxCheckAttempts() << "\n"
- "\t" "last_state_change=" << static_cast<long>(service->GetLastStateChange()) << "\n"
- "\t" "last_hard_state_change=" << static_cast<long>(service->GetLastHardStateChange()) << "\n"
- "\t" "last_time_ok=" << static_cast<int>(service->GetLastStateOK()) << "\n"
- "\t" "last_time_warn=" << static_cast<int>(service->GetLastStateWarning()) << "\n"
- "\t" "last_time_critical=" << static_cast<int>(service->GetLastStateCritical()) << "\n"
- "\t" "last_time_unknown=" << static_cast<int>(service->GetLastStateUnknown()) << "\n"
+ fp << "\t" << "next_check=" << static_cast<long>(checkable->GetNextCheck()) << "\n"
+ "\t" "current_attempt=" << checkable->GetCheckAttempt() << "\n"
+ "\t" "max_attempts=" << checkable->GetMaxCheckAttempts() << "\n"
+ "\t" "last_state_change=" << static_cast<long>(checkable->GetLastStateChange()) << "\n"
+ "\t" "last_hard_state_change=" << static_cast<long>(checkable->GetLastHardStateChange()) << "\n"
+ "\t" "last_time_ok=" << static_cast<int>(checkable->GetLastStateOK()) << "\n"
+ "\t" "last_time_warn=" << static_cast<int>(checkable->GetLastStateWarning()) << "\n"
+ "\t" "last_time_critical=" << static_cast<int>(checkable->GetLastStateCritical()) << "\n"
+ "\t" "last_time_unknown=" << static_cast<int>(checkable->GetLastStateUnknown()) << "\n"
"\t" "last_update=" << static_cast<long>(time(NULL)) << "\n"
- "\t" "notifications_enabled=" << CompatUtility::GetServiceNotificationsEnabled(service) << "\n"
- "\t" "active_checks_enabled=" << CompatUtility::GetServiceActiveChecksEnabled(service) << "\n"
- "\t" "passive_checks_enabled=" << CompatUtility::GetServicePassiveChecksEnabled(service) << "\n"
- "\t" "flap_detection_enabled=" << CompatUtility::GetServiceFlapDetectionEnabled(service) << "\n"
- "\t" "is_flapping=" << CompatUtility::GetServiceIsFlapping(service) << "\n"
- "\t" "percent_state_change=" << CompatUtility::GetServicePercentStateChange(service) << "\n"
- "\t" "problem_has_been_acknowledged=" << CompatUtility::GetServiceProblemHasBeenAcknowledged(service) << "\n"
- "\t" "acknowledgement_type=" << CompatUtility::GetServiceAcknowledgementType(service) << "\n"
- "\t" "acknowledgement_end_time=" << service->GetAcknowledgementExpiry() << "\n"
- "\t" "scheduled_downtime_depth=" << service->GetDowntimeDepth() << "\n"
- "\t" "last_notification=" << CompatUtility::GetServiceNotificationLastNotification(service) << "\n"
- "\t" "next_notification=" << CompatUtility::GetServiceNotificationNextNotification(service) << "\n"
- "\t" "current_notification_number=" << CompatUtility::GetServiceNotificationNotificationNumber(service) << "\n"
- "\t" "modified_attributes=" << service->GetModifiedAttributes() << "\n";
+ "\t" "notifications_enabled=" << CompatUtility::GetCheckableNotificationsEnabled(checkable) << "\n"
+ "\t" "active_checks_enabled=" << CompatUtility::GetCheckableActiveChecksEnabled(checkable) << "\n"
+ "\t" "passive_checks_enabled=" << CompatUtility::GetCheckablePassiveChecksEnabled(checkable) << "\n"
+ "\t" "flap_detection_enabled=" << CompatUtility::GetCheckableFlapDetectionEnabled(checkable) << "\n"
+ "\t" "is_flapping=" << CompatUtility::GetCheckableIsFlapping(checkable) << "\n"
+ "\t" "percent_state_change=" << CompatUtility::GetCheckablePercentStateChange(checkable) << "\n"
+ "\t" "problem_has_been_acknowledged=" << CompatUtility::GetCheckableProblemHasBeenAcknowledged(checkable) << "\n"
+ "\t" "acknowledgement_type=" << CompatUtility::GetCheckableAcknowledgementType(checkable) << "\n"
+ "\t" "acknowledgement_end_time=" << checkable->GetAcknowledgementExpiry() << "\n"
+ "\t" "scheduled_downtime_depth=" << checkable->GetDowntimeDepth() << "\n"
+ "\t" "last_notification=" << CompatUtility::GetCheckableNotificationLastNotification(checkable) << "\n"
+ "\t" "next_notification=" << CompatUtility::GetCheckableNotificationNextNotification(checkable) << "\n"
+ "\t" "current_notification_number=" << CompatUtility::GetCheckableNotificationNotificationNumber(checkable) << "\n"
+ "\t" "modified_attributes=" << checkable->GetModifiedAttributes() << "\n";
}
void StatusDataWriter::DumpServiceStatus(std::ostream& fp, const Service::Ptr& service)
{
ObjectLock olock(service);
- DumpServiceStatusAttrs(fp, service, CompatTypeService);
+ DumpCheckableStatusAttrs(fp, service);
}
fp << "\t" "}" "\n"
"\n";
- DumpDowntimes(fp, service, CompatTypeService);
- DumpComments(fp, service, CompatTypeService);
+ DumpDowntimes(fp, service);
+ DumpComments(fp, service);
}
void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& service)
"\t" "host_name" "\t" << host->GetName() << "\n"
"\t" "service_description" "\t" << service->GetShortName() << "\n"
"\t" "display_name" "\t" << service->GetDisplayName() << "\n"
- "\t" "check_period" "\t" << CompatUtility::GetServiceCheckPeriod(service) << "\n"
- "\t" "check_interval" "\t" << CompatUtility::GetServiceCheckInterval(service) << "\n"
- "\t" "retry_interval" "\t" << CompatUtility::GetServiceRetryInterval(service) << "\n"
+ "\t" "check_period" "\t" << CompatUtility::GetCheckableCheckPeriod(service) << "\n"
+ "\t" "check_interval" "\t" << CompatUtility::GetCheckableCheckInterval(service) << "\n"
+ "\t" "retry_interval" "\t" << CompatUtility::GetCheckableRetryInterval(service) << "\n"
"\t" "max_check_attempts" "\t" << service->GetMaxCheckAttempts() << "\n"
- "\t" "active_checks_enabled" "\t" << CompatUtility::GetServiceActiveChecksEnabled(service) << "\n"
- "\t" "passive_checks_enabled" "\t" << CompatUtility::GetServicePassiveChecksEnabled(service) << "\n"
- "\t" "flap_detection_enabled" "\t" << CompatUtility::GetServiceFlapDetectionEnabled(service) << "\n"
- "\t" "is_volatile" "\t" << CompatUtility::GetServiceIsVolatile(service) << "\n"
- "\t" "notifications_enabled" "\t" << CompatUtility::GetServiceNotificationsEnabled(service) << "\n"
- "\t" "notification_options" "\t" << CompatUtility::GetServiceNotificationNotificationOptions(service) << "\n"
- "\t" "notification_interval" "\t" << CompatUtility::GetServiceNotificationNotificationInterval(service) << "\n"
- "\t" "notification_period" "\t" << CompatUtility::GetServiceNotificationNotificationPeriod(service) << "\n"
- "\t" "event_handler_enabled" "\t" << CompatUtility::GetServiceEventHandlerEnabled(service) << "\n";
+ "\t" "active_checks_enabled" "\t" << CompatUtility::GetCheckableActiveChecksEnabled(service) << "\n"
+ "\t" "passive_checks_enabled" "\t" << CompatUtility::GetCheckablePassiveChecksEnabled(service) << "\n"
+ "\t" "flap_detection_enabled" "\t" << CompatUtility::GetCheckableFlapDetectionEnabled(service) << "\n"
+ "\t" "is_volatile" "\t" << CompatUtility::GetCheckableIsVolatile(service) << "\n"
+ "\t" "notifications_enabled" "\t" << CompatUtility::GetCheckableNotificationsEnabled(service) << "\n"
+ "\t" "notification_options" "\t" << CompatUtility::GetCheckableNotificationNotificationOptions(service) << "\n"
+ "\t" "notification_interval" "\t" << CompatUtility::GetCheckableNotificationNotificationInterval(service) << "\n"
+ "\t" "notification_period" "\t" << CompatUtility::GetCheckableNotificationNotificationPeriod(service) << "\n"
+ "\t" "event_handler_enabled" "\t" << CompatUtility::GetCheckableEventHandlerEnabled(service) << "\n";
CheckCommand::Ptr checkcommand = service->GetCheckCommand();
if (checkcommand)
fp << "\t" "event_handler" "\t" "event_" << eventcommand->GetName() << "\n";
fp << "\t" "contacts" "\t";
- DumpNameList(fp, CompatUtility::GetServiceNotificationUsers(service));
+ DumpNameList(fp, CompatUtility::GetCheckableNotificationUsers(service));
fp << "\n";
fp << "\t" "contact_groups" "\t";
- DumpNameList(fp, CompatUtility::GetServiceNotificationUserGroups(service));
+ DumpNameList(fp, CompatUtility::GetCheckableNotificationUserGroups(service));
fp << "\n";
String notes = CompatUtility::GetCustomAttributeConfig(service, "notes");
fp << "\t" "initial_state" "\t" "o" "\n"
"\t" "low_flap_threshold" "\t" << service->GetFlappingThreshold() << "\n"
"\t" "high_flap_threshold" "\t" << service->GetFlappingThreshold() << "\n"
- "\t" "process_perf_data" "\t" << CompatUtility::GetServiceProcessPerformanceData(service) << "\n"
+ "\t" "process_perf_data" "\t" << CompatUtility::GetCheckableProcessPerformanceData(service) << "\n"
"\t" "check_freshness" << "\t" "1" "\n";
if (!notes.IsEmpty())
fp << "\t" "notes" "\t" << notes << "\n";
}
BOOST_FOREACH(const Dependency::Ptr& dep, DynamicType::GetObjects<Dependency>()) {
- Service::Ptr parent_service = dep->GetParentService();
+ Checkable::Ptr parent = dep->GetParent();
+
+ if (!parent)
+ continue;
+
+ Host::Ptr parent_host;
+ Service::Ptr parent_service;
+ tie(parent_host, parent_service) = GetHostService(parent);
if (!parent_service)
continue;
- Service::Ptr child_service = dep->GetChildService();
+ Checkable::Ptr child = dep->GetChild();
+
+ if (!child)
+ continue;
+
+ Host::Ptr child_host;
+ Service::Ptr child_service;
+ tie(child_host, child_service) = GetHostService(child);
if (!child_service)
continue;
void DumpCommand(std::ostream& fp, const Command::Ptr& command);
void DumpTimePeriod(std::ostream& fp, const TimePeriod::Ptr& tp);
- void DumpDowntimes(std::ostream& fp, const Service::Ptr& owner, CompatObjectType type);
- void DumpComments(std::ostream& fp, const Service::Ptr& owner, CompatObjectType type);
+ void DumpDowntimes(std::ostream& fp, const Checkable::Ptr& owner);
+ void DumpComments(std::ostream& fp, const Checkable::Ptr& owner);
void DumpHostStatus(std::ostream& fp, const Host::Ptr& host);
void DumpHostObject(std::ostream& fp, const Host::Ptr& host);
- void DumpServiceStatusAttrs(std::ostream& fp, const Service::Ptr& service, CompatObjectType type);
+ void DumpCheckableStatusAttrs(std::ostream& fp, const Checkable::Ptr& checkable);
template<typename T>
void DumpNameList(std::ostream& fp, const T& list)
void CommentsTable::FetchRows(const AddRowFunction& addRowFn)
{
+ BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
+ Dictionary::Ptr comments = host->GetComments();
+
+ ObjectLock olock(comments);
+
+ String id;
+ Comment::Ptr comment;
+ BOOST_FOREACH(tie(id, comment), comments) {
+ addRowFn(comment);
+ }
+ }
+
BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
Dictionary::Ptr comments = service->GetComments();
String id;
Comment::Ptr comment;
- BOOST_FOREACH(boost::tie(id, comment), comments) {
- if (Service::GetOwnerByCommentID(id) == service)
- addRowFn(comment);
+ BOOST_FOREACH(tie(id, comment), comments) {
+ addRowFn(comment);
}
}
}
Object::Ptr CommentsTable::ServiceAccessor(const Value& row, const Column::ObjectAccessor& parentObjectAccessor)
{
Comment::Ptr comment = static_cast<Comment::Ptr>(row);
- return Service::GetOwnerByCommentID(comment->GetId());
+ return Checkable::GetOwnerByCommentID(comment->GetId()); // XXX: this might return a Host object
}
Value CommentsTable::AuthorAccessor(const Value& row)
Value CommentsTable::TypeAccessor(const Value& row)
{
Comment::Ptr comment = static_cast<Comment::Ptr>(row);
- Service::Ptr svc = Service::GetOwnerByCommentID(comment->GetId());
+ Checkable::Ptr checkable = Checkable::GetOwnerByCommentID(comment->GetId());
- if (!svc)
+ if (!checkable)
return Empty;
- return (svc->IsHostCheck() ? 1 : 2);
+ if (dynamic_pointer_cast<Host>(checkable))
+ return 1;
+ else
+ return 2;
}
Value CommentsTable::IsServiceAccessor(const Value& row)
{
Comment::Ptr comment = static_cast<Comment::Ptr>(row);
- Service::Ptr svc = Service::GetOwnerByCommentID(comment->GetId());
+ Checkable::Ptr checkable = Checkable::GetOwnerByCommentID(comment->GetId());
- if (!svc)
+ if (!checkable)
return Empty;
- return (svc->IsHostCheck() ? 0 : 1);
+ return (dynamic_pointer_cast<Host>(checkable) ? 0 : 1);
}
Value CommentsTable::EntryTypeAccessor(const Value& row)
Value DowntimesTable::IsServiceAccessor(const Value& row)
{
Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row);
- Service::Ptr svc = Service::GetOwnerByDowntimeID(downtime->GetId());
+ Checkable::Ptr checkable = Checkable::GetOwnerByDowntimeID(downtime->GetId());
- return (svc->IsHostCheck() ? 0 : 1);
+ return (dynamic_pointer_cast<Host>(checkable) ? 0 : 1);
}
Value DowntimesTable::StartTimeAccessor(const Value& row)
int num_hosts = 0;
BOOST_FOREACH(const Host::Ptr& host, static_cast<HostGroup::Ptr>(row)->GetMembers()) {
- Service::Ptr hc = host->GetCheckService();
-
- /* no hostcheck service or no checkresult */
- if (!hc || !hc->GetLastCheckResult())
+ /* no checkresult */
+ if (!host->GetLastCheckResult())
num_hosts++;
}
table->AddColumn(prefix + "services", Column(&HostsTable::ServicesAccessor, objectAccessor));
table->AddColumn(prefix + "services_with_state", Column(&HostsTable::ServicesWithStateAccessor, objectAccessor));
table->AddColumn(prefix + "services_with_info", Column(&HostsTable::ServicesWithInfoAccessor, objectAccessor));
- table->AddColumn(prefix + "check_service", Column(&HostsTable::CheckServiceAccessor, objectAccessor));
}
String HostsTable::GetName(void) const
if (!host)
return Empty;
- /* use hostcheck service */
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- CheckCommand::Ptr checkcommand = hc->GetCheckCommand();
+ CheckCommand::Ptr checkcommand = host->GetCheckCommand();
if (checkcommand)
return checkcommand->GetName(); /* this is the name without '!' args */
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- CheckCommand::Ptr checkcommand = hc->GetCheckCommand();
+ CheckCommand::Ptr checkcommand = host->GetCheckCommand();
if (checkcommand)
return checkcommand->GetName(); /* this is the name without '!' args */
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- EventCommand::Ptr eventcommand = hc->GetEventCommand();
+ EventCommand::Ptr eventcommand = host->GetEventCommand();
if (eventcommand)
return eventcommand->GetName();
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceNotificationNotificationPeriod(hc);
+ return CompatUtility::GetCheckableNotificationNotificationPeriod(host);
}
Value HostsTable::CheckPeriodAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceCheckPeriod(hc);
+ return CompatUtility::GetCheckableCheckPeriod(host);
}
Value HostsTable::NotesAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr service = host->GetCheckService();
-
- if (!service)
- return Empty;
-
std::vector<MacroResolver::Ptr> resolvers;
- if (service)
- resolvers.push_back(service);
-
resolvers.push_back(host);
resolvers.push_back(IcingaApplication::GetInstance());
if (!host)
return Empty;
- Service::Ptr service = host->GetCheckService();
-
- if (!service)
- return Empty;
-
std::vector<MacroResolver::Ptr> resolvers;
- if (service)
- resolvers.push_back(service);
-
resolvers.push_back(host);
resolvers.push_back(IcingaApplication::GetInstance());
if (!host)
return Empty;
- Service::Ptr service = host->GetCheckService();
-
- if (!service)
- return Empty;
-
std::vector<MacroResolver::Ptr> resolvers;
- if (service)
- resolvers.push_back(service);
-
resolvers.push_back(host);
resolvers.push_back(IcingaApplication::GetInstance());
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
String output;
+ CheckResult::Ptr cr = host->GetLastCheckResult();
- if(hc) {
- CheckResult::Ptr cr = hc->GetLastCheckResult();
-
- if (cr)
- output = CompatUtility::GetCheckResultOutput(cr);
- }
+ if (cr)
+ output = CompatUtility::GetCheckResultOutput(cr);
return output;
}
if (!host)
return Empty;
- Service::Ptr service = host->GetCheckService();
-
- if (!service)
- return Empty;
-
std::vector<MacroResolver::Ptr> resolvers;
- if (service)
- resolvers.push_back(service);
-
resolvers.push_back(host);
resolvers.push_back(IcingaApplication::GetInstance());
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
String long_output;
+ CheckResult::Ptr cr = host->GetLastCheckResult();
- if (hc) {
- CheckResult::Ptr cr = hc->GetLastCheckResult();
-
- if (cr)
- long_output = CompatUtility::GetCheckResultLongOutput(cr);
- }
+ if (cr)
+ long_output = CompatUtility::GetCheckResultLongOutput(cr);
return long_output;
}
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return hc->GetMaxCheckAttempts();
+ return host->GetMaxCheckAttempts();
}
Value HostsTable::FlapDetectionEnabledAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceFlapDetectionEnabled(hc);
+ return CompatUtility::GetCheckableFlapDetectionEnabled(host);
}
Value HostsTable::AcceptPassiveChecksAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServicePassiveChecksEnabled(hc);
+ return CompatUtility::GetCheckablePassiveChecksEnabled(host);
}
Value HostsTable::EventHandlerEnabledAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceEventHandlerEnabled(hc);
+ return CompatUtility::GetCheckableEventHandlerEnabled(host);
}
Value HostsTable::AcknowledgementTypeAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceAcknowledgementType(hc);
+ return CompatUtility::GetCheckableAcknowledgementType(host);
}
Value HostsTable::CheckTypeAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceCheckType(hc);
+ return CompatUtility::GetCheckableCheckType(host);
}
Value HostsTable::LastStateAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return hc->GetCheckAttempt();
+ return host->GetCheckAttempt();
}
Value HostsTable::LastNotificationAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceNotificationLastNotification(hc);
+ return CompatUtility::GetCheckableNotificationLastNotification(host);
}
Value HostsTable::NextNotificationAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceNotificationNextNotification(hc);
+ return CompatUtility::GetCheckableNotificationNextNotification(host);
}
Value HostsTable::NextCheckAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return static_cast<int>(hc->GetNextCheck());
+ return static_cast<int>(host->GetNextCheck());
}
Value HostsTable::LastHardStateChangeAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return static_cast<int>(hc->GetLastHardStateChange());
+ return static_cast<int>(host->GetLastHardStateChange());
}
Value HostsTable::HasBeenCheckedAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceHasBeenChecked(hc);
+ return CompatUtility::GetCheckableHasBeenChecked(host);
}
Value HostsTable::CurrentNotificationNumberAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceNotificationNotificationNumber(hc);
+ return CompatUtility::GetCheckableNotificationNotificationNumber(host);
}
Value HostsTable::TotalServicesAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceActiveChecksEnabled(hc);
+ return CompatUtility::GetCheckableActiveChecksEnabled(host);
}
Value HostsTable::NotificationsEnabledAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceNotificationsEnabled(hc);
+ return CompatUtility::GetCheckableNotificationsEnabled(host);
}
Value HostsTable::AcknowledgedAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceIsAcknowledged(hc);
+ return CompatUtility::GetCheckableIsAcknowledged(host);
}
Value HostsTable::StateAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceNoMoreNotifications(hc);
+ return CompatUtility::GetCheckableNoMoreNotifications(host);
}
Value HostsTable::LastCheckAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return static_cast<int>(hc->GetLastCheck());
+ return static_cast<int>(host->GetLastCheck());
}
Value HostsTable::LastStateChangeAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return hc->IsFlapping();
+ return host->IsFlapping();
}
Value HostsTable::ScheduledDowntimeDepthAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return hc->GetDowntimeDepth();
+ return host->GetDowntimeDepth();
}
Value HostsTable::ActiveChecksEnabledAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceActiveChecksEnabled(hc);
+ return CompatUtility::GetCheckableActiveChecksEnabled(host);
}
Value HostsTable::CheckOptionsAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return hc->GetModifiedAttributes();
+ return host->GetModifiedAttributes();
}
Value HostsTable::ModifiedAttributesListAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceCheckInterval(hc);
+ return CompatUtility::GetCheckableCheckInterval(host);
}
Value HostsTable::RetryIntervalAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceRetryInterval(hc);
+ return CompatUtility::GetCheckableRetryInterval(host);
}
Value HostsTable::NotificationIntervalAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceNotificationNotificationInterval(hc);
+ return CompatUtility::GetCheckableNotificationNotificationInterval(host);
}
Value HostsTable::LowFlapThresholdAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceLowFlapThreshold(hc);
+ return CompatUtility::GetCheckableLowFlapThreshold(host);
}
Value HostsTable::HighFlapThresholdAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceHighFlapThreshold(hc);
+ return CompatUtility::GetCheckableHighFlapThreshold(host);
}
Value HostsTable::X2dAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return (Service::CalculateLatency(hc->GetLastCheckResult()));
+ return (Service::CalculateLatency(host->GetLastCheckResult()));
}
Value HostsTable::ExecutionTimeAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return (Service::CalculateExecutionTime(hc->GetLastCheckResult()));
+ return (Service::CalculateExecutionTime(host->GetLastCheckResult()));
}
Value HostsTable::PercentStateChangeAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServicePercentStateChange(hc);
+ return CompatUtility::GetCheckablePercentStateChange(host);
}
Value HostsTable::InNotificationPeriodAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceInNotificationPeriod(hc);
+ return CompatUtility::GetCheckableInNotificationPeriod(host);
}
Value HostsTable::InCheckPeriodAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceInCheckPeriod(hc);
+ return CompatUtility::GetCheckableInCheckPeriod(host);
}
Value HostsTable::ContactsAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
Array::Ptr contact_names = make_shared<Array>();
- BOOST_FOREACH(const User::Ptr& user, CompatUtility::GetServiceNotificationUsers(hc)) {
+ BOOST_FOREACH(const User::Ptr& user, CompatUtility::GetCheckableNotificationUsers(host)) {
contact_names->Add(user->GetName());
}
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- Dictionary::Ptr downtimes = hc->GetDowntimes();
+ Dictionary::Ptr downtimes = host->GetDowntimes();
Array::Ptr ids = make_shared<Array>();
String id;
Downtime::Ptr downtime;
- BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
+ BOOST_FOREACH(tie(id, downtime), downtimes) {
if (!downtime)
continue;
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- Dictionary::Ptr downtimes = hc->GetDowntimes();
+ Dictionary::Ptr downtimes = host->GetDowntimes();
Array::Ptr ids = make_shared<Array>();
String id;
Downtime::Ptr downtime;
- BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
+ BOOST_FOREACH(tie(id, downtime), downtimes) {
if (!downtime)
continue;
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- Dictionary::Ptr comments = hc->GetComments();
+ Dictionary::Ptr comments = host->GetComments();
Array::Ptr ids = make_shared<Array>();
String id;
Comment::Ptr comment;
- BOOST_FOREACH(boost::tie(id, comment), comments) {
+ BOOST_FOREACH(tie(id, comment), comments) {
if (!comment)
continue;
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- Dictionary::Ptr comments = hc->GetComments();
+ Dictionary::Ptr comments = host->GetComments();
Array::Ptr ids = make_shared<Array>();
String id;
Comment::Ptr comment;
- BOOST_FOREACH(boost::tie(id, comment), comments) {
+ BOOST_FOREACH(tie(id, comment), comments) {
if (!comment)
continue;
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- Dictionary::Ptr comments = hc->GetComments();
+ Dictionary::Ptr comments = host->GetComments();
Array::Ptr ids = make_shared<Array>();
String id;
Comment::Ptr comment;
- BOOST_FOREACH(boost::tie(id, comment), comments) {
+ BOOST_FOREACH(tie(id, comment), comments) {
if (!comment)
continue;
String key;
Value value;
- BOOST_FOREACH(boost::tie(key, value), vars) {
+ BOOST_FOREACH(tie(key, value), vars) {
cv->Add(key);
}
String key;
Value value;
- BOOST_FOREACH(boost::tie(key, value), vars) {
+ BOOST_FOREACH(tie(key, value), vars) {
cv->Add(value);
}
String key;
Value value;
- BOOST_FOREACH(boost::tie(key, value), vars) {
+ BOOST_FOREACH(tie(key, value), vars) {
Array::Ptr key_val = make_shared<Array>();
key_val->Add(key);
key_val->Add(value);
Array::Ptr parents = make_shared<Array>();
- BOOST_FOREACH(const Host::Ptr& parent, host->GetParentHosts()) {
- parents->Add(parent->GetName());
+ BOOST_FOREACH(const Checkable::Ptr& parent, host->GetParents()) {
+ Host::Ptr parent_host = dynamic_pointer_cast<Host>(parent);
+
+ if (!parent_host)
+ continue;
+
+ parents->Add(parent_host->GetName());
}
return parents;
Array::Ptr childs = make_shared<Array>();
- BOOST_FOREACH(const Host::Ptr& child, host->GetChildHosts()) {
- childs->Add(child->GetName());
+ BOOST_FOREACH(const Checkable::Ptr& child, host->GetChildren()) {
+ Host::Ptr child_host = dynamic_pointer_cast<Host>(child);
+
+ if (!child_host)
+ continue;
+
+ childs->Add(child_host->GetName());
}
return childs;
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
+ if (host->GetState() == HostUp)
+ return HostUp;
+ else if (host->GetStateType() == StateTypeHard)
+ return host->GetState();
- if (hc->GetState() == StateOK)
- return StateOK;
- if (hc->GetStateType() == StateTypeHard)
- return hc->GetState();
-
- return hc->GetLastHardState();
+ return host->GetLastHardState();
}
Value HostsTable::StalenessAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
- return CompatUtility::GetServiceStaleness(hc);
+ return CompatUtility::GetCheckableStaleness(host);
}
Value HostsTable::GroupsAccessor(const Value& row)
if (!host)
return Empty;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- return Empty;
-
Array::Ptr contactgroup_names = make_shared<Array>();
- BOOST_FOREACH(const UserGroup::Ptr& usergroup, CompatUtility::GetServiceNotificationUserGroups(hc)) {
+ BOOST_FOREACH(const UserGroup::Ptr& usergroup, CompatUtility::GetCheckableNotificationUserGroups(host)) {
contactgroup_names->Add(usergroup->GetName());
}
return services;
}
-
-Value HostsTable::CheckServiceAccessor(const Value& row)
-{
- Host::Ptr host = static_cast<Host::Ptr>(row);
-
- if (!host)
- return Empty;
-
- Service::Ptr hc = host->GetCheckService();
-
- Array::Ptr services = make_shared<Array>();
-
- if (!hc)
- return Empty;
-
- return hc->GetShortName();
-}
-
static Value ServicesAccessor(const Value& row);
static Value ServicesWithStateAccessor(const Value& row);
static Value ServicesWithInfoAccessor(const Value& row);
- static Value CheckServiceAccessor(const Value& row);
};
}
static boost::mutex l_QueryMutex;
Query::Query(const std::vector<String>& lines, const String& compat_log_path)
- : m_KeepAlive(false), m_OutputFormat("csv"), m_ColumnHeaders(true), m_Limit(-1),
+ : m_KeepAlive(false), m_OutputFormat("csv"), m_ColumnHeaders(true),
m_LogTimeFrom(0), m_LogTimeUntil(static_cast<long>(Utility::GetTime()))
{
if (lines.size() == 0) {
String m_OutputFormat;
bool m_ColumnHeaders;
- int m_Limit;
String m_ResponseHeader;
if (!service)
return Empty;
- return CompatUtility::GetServiceNotificationNotificationPeriod(service);
+ return CompatUtility::GetCheckableNotificationNotificationPeriod(service);
}
Value ServicesTable::CheckPeriodAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceCheckPeriod(service);
+ return CompatUtility::GetCheckableCheckPeriod(service);
}
Value ServicesTable::NotesAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceCurrentState(service);
+ return service->GetState();
}
Value ServicesTable::HasBeenCheckedAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceHasBeenChecked(service);
+ return CompatUtility::GetCheckableHasBeenChecked(service);
}
Value ServicesTable::LastStateAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceCheckType(service);
+ return CompatUtility::GetCheckableCheckType(service);
}
Value ServicesTable::AcknowledgedAccessor(const Value& row)
return Empty;
- return CompatUtility::GetServiceIsAcknowledged(service);
+ return CompatUtility::GetCheckableIsAcknowledged(service);
}
Value ServicesTable::AcknowledgementTypeAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceNoMoreNotifications(service);
+ return CompatUtility::GetCheckableNoMoreNotifications(service);
}
Value ServicesTable::LastTimeOkAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceNotificationLastNotification(service);
+ return CompatUtility::GetCheckableNotificationLastNotification(service);
}
Value ServicesTable::NextNotificationAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceNotificationNextNotification(service);
+ return CompatUtility::GetCheckableNotificationNextNotification(service);
}
Value ServicesTable::CurrentNotificationNumberAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceNotificationNotificationNumber(service);
+ return CompatUtility::GetCheckableNotificationNotificationNumber(service);
}
Value ServicesTable::LastStateChangeAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceActiveChecksEnabled(service);
+ return CompatUtility::GetCheckableActiveChecksEnabled(service);
}
Value ServicesTable::AcceptPassiveChecksAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServicePassiveChecksEnabled(service);
+ return CompatUtility::GetCheckablePassiveChecksEnabled(service);
}
Value ServicesTable::EventHandlerEnabledAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceEventHandlerEnabled(service);
+ return CompatUtility::GetCheckableEventHandlerEnabled(service);
}
Value ServicesTable::NotificationsEnabledAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceNotificationsEnabled(service);
+ return CompatUtility::GetCheckableNotificationsEnabled(service);
}
Value ServicesTable::ProcessPerformanceDataAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceProcessPerformanceData(service);
+ return CompatUtility::GetCheckableProcessPerformanceData(service);
}
Value ServicesTable::ActiveChecksEnabledAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceActiveChecksEnabled(service);
+ return CompatUtility::GetCheckableActiveChecksEnabled(service);
}
Value ServicesTable::CheckOptionsAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceFlapDetectionEnabled(service);
+ return CompatUtility::GetCheckableFlapDetectionEnabled(service);
}
Value ServicesTable::CheckFreshnessAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceFreshnessChecksEnabled(service);
+ return CompatUtility::GetCheckableFreshnessChecksEnabled(service);
}
Value ServicesTable::ModifiedAttributesAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceStaleness(service);
+ return CompatUtility::GetCheckableStaleness(service);
}
Value ServicesTable::CheckIntervalAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceCheckInterval(service);
+ return CompatUtility::GetCheckableCheckInterval(service);
}
Value ServicesTable::RetryIntervalAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceRetryInterval(service);
+ return CompatUtility::GetCheckableRetryInterval(service);
}
Value ServicesTable::NotificationIntervalAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceNotificationNotificationInterval(service);
+ return CompatUtility::GetCheckableNotificationNotificationInterval(service);
}
Value ServicesTable::LowFlapThresholdAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceLowFlapThreshold(service);
+ return CompatUtility::GetCheckableLowFlapThreshold(service);
}
Value ServicesTable::HighFlapThresholdAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceHighFlapThreshold(service);
+ return CompatUtility::GetCheckableHighFlapThreshold(service);
}
Value ServicesTable::LatencyAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServicePercentStateChange(service);
+ return CompatUtility::GetCheckablePercentStateChange(service);
}
Value ServicesTable::InCheckPeriodAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceInCheckPeriod(service);
+ return CompatUtility::GetCheckableInCheckPeriod(service);
}
Value ServicesTable::InNotificationPeriodAccessor(const Value& row)
if (!service)
return Empty;
- return CompatUtility::GetServiceInNotificationPeriod(service);
+ return CompatUtility::GetCheckableInNotificationPeriod(service);
}
Value ServicesTable::ContactsAccessor(const Value& row)
Array::Ptr contact_names = make_shared<Array>();
- BOOST_FOREACH(const User::Ptr& user, CompatUtility::GetServiceNotificationUsers(service)) {
+ BOOST_FOREACH(const User::Ptr& user, CompatUtility::GetCheckableNotificationUsers(service)) {
contact_names->Add(user->GetName());
}
String id;
Downtime::Ptr downtime;
- BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
+ BOOST_FOREACH(tie(id, downtime), downtimes) {
if (!downtime)
continue;
String id;
Downtime::Ptr downtime;
- BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
+ BOOST_FOREACH(tie(id, downtime), downtimes) {
if (!downtime)
continue;
String id;
Comment::Ptr comment;
- BOOST_FOREACH(boost::tie(id, comment), comments) {
+ BOOST_FOREACH(tie(id, comment), comments) {
if (!comment)
continue;
String id;
Comment::Ptr comment;
- BOOST_FOREACH(boost::tie(id, comment), comments) {
+ BOOST_FOREACH(tie(id, comment), comments) {
if (!comment)
continue;
String id;
Comment::Ptr comment;
- BOOST_FOREACH(boost::tie(id, comment), comments) {
+ BOOST_FOREACH(tie(id, comment), comments) {
if (!comment)
continue;
String key;
Value value;
- BOOST_FOREACH(boost::tie(key, value), vars) {
+ BOOST_FOREACH(tie(key, value), vars) {
cv->Add(key);
}
String key;
Value value;
- BOOST_FOREACH(boost::tie(key, value), vars) {
+ BOOST_FOREACH(tie(key, value), vars) {
cv->Add(value);
}
String key;
Value value;
- BOOST_FOREACH(boost::tie(key, value), vars) {
+ BOOST_FOREACH(tie(key, value), vars) {
Array::Ptr key_val = make_shared<Array>();
key_val->Add(key);
key_val->Add(value);
Array::Ptr contactgroup_names = make_shared<Array>();
- BOOST_FOREACH(const UserGroup::Ptr& usergroup, CompatUtility::GetServiceNotificationUserGroups(service)) {
+ BOOST_FOREACH(const UserGroup::Ptr& usergroup, CompatUtility::GetCheckableNotificationUserGroups(service)) {
contactgroup_names->Add(usergroup->GetName());
}
String state_type = log_entry_attrs->Get("state_type"); //SOFT, HARD, STARTED, STOPPED, ...
String log_line = log_entry_attrs->Get("message"); /* use message from log table */
- Service::Ptr state_hist_service;
+ Checkable::Ptr checkable;
- /* host alert == get service check */
- if (service_description.IsEmpty()) {
- Host::Ptr state_host = Host::GetByName(host_name);
-
- if (!state_host)
- return;
-
- state_hist_service = state_host->GetCheckService();
- } else {
- /* assign service ptr as key */
- state_hist_service = Service::GetByNamePair(host_name, service_description);
- }
+ if (service_description.IsEmpty())
+ checkable = Host::GetByName(host_name);
+ else
+ checkable = Service::GetByNamePair(host_name, service_description);
/* invalid log line for state history */
- if (!state_hist_service)
+ if (!checkable)
return;
Array::Ptr state_hist_service_states;
unsigned long query_part = m_TimeUntil - m_TimeFrom;
/* insert new service states array with values if not existing */
- if (m_ServicesCache.find(state_hist_service) == m_ServicesCache.end()) {
+ if (m_CheckablesCache.find(checkable) == m_CheckablesCache.end()) {
/* create new values */
state_hist_service_states = make_shared<Array>();
state_hist_bag = make_shared<Dictionary>();
- state_hist_bag->Set("host_name", state_hist_service->GetHost()->GetName());
- state_hist_bag->Set("service_description", state_hist_service->GetShortName());
+ Service::Ptr service = dynamic_pointer_cast<Service>(checkable);
+ Host::Ptr host;
+
+ if (service)
+ host = service->GetHost();
+ else
+ host = static_pointer_cast<Host>(checkable);
+
+ state_hist_bag->Set("host_name", host->GetName());
+
+ if (service)
+ state_hist_bag->Set("service_description", service->GetShortName());
+
state_hist_bag->Set("state", state);
state_hist_bag->Set("in_downtime", 0);
state_hist_bag->Set("in_host_downtime", 0);
state_hist_service_states->Add(state_hist_bag);
- Log(LogDebug, "livestatus", "statehist: Adding new service '" + state_hist_service->GetName() + "' to services cache.");
+ Log(LogDebug, "livestatus", "statehist: Adding new object '" + checkable->GetName() + "' to services cache.");
} else {
- state_hist_service_states = m_ServicesCache[state_hist_service];
+ state_hist_service_states = m_CheckablesCache[checkable];
state_hist_bag = state_hist_service_states->Get(state_hist_service_states->GetLength()-1); /* fetch latest state from history */
/* state duration */
/* determine service notifications notification_period and compare against current timestamp */
bool in_notification_period = true;
String notification_period_name;
- BOOST_FOREACH(const Notification::Ptr& notification, state_hist_service->GetNotifications()) {
+ BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) {
TimePeriod::Ptr notification_period = notification->GetNotificationPeriod();
if (notification_period) {
state_hist_service_states->Add(state_hist_bag_new);
- Log(LogDebug, "livestatus", "statehist: State change detected for service '" +
- state_hist_service->GetName() + "' in '" + log_line + "'.");
+ Log(LogDebug, "livestatus", "statehist: State change detected for object '" +
+ checkable->GetName() + "' in '" + log_line + "'.");
}
break;
case LogEntryTypeHostFlapping:
}
- m_ServicesCache[state_hist_service] = state_hist_service_states;
+ m_CheckablesCache[checkable] = state_hist_service_states;
/* TODO find a way to directly call addRowFn() - right now m_ServicesCache depends on historical lines ("already seen service") */
}
/* generate log cache */
LogUtility::CreateLogCache(m_LogFileIndex, this, m_TimeFrom, m_TimeUntil, addRowFn);
- Service::Ptr state_hist_service;
+ Checkable::Ptr checkable;
- BOOST_FOREACH(boost::tie(state_hist_service, boost::tuples::ignore), m_ServicesCache) {
- BOOST_FOREACH(const Dictionary::Ptr& state_hist_bag, m_ServicesCache[state_hist_service]) {
+ BOOST_FOREACH(boost::tie(checkable, boost::tuples::ignore), m_CheckablesCache) {
+ BOOST_FOREACH(const Dictionary::Ptr& state_hist_bag, m_CheckablesCache[checkable]) {
/* pass a dictionary from state history array */
addRowFn(state_hist_bag);
}
private:
std::map<time_t, String> m_LogFileIndex;
- std::map<Service::Ptr, Array::Ptr> m_ServicesCache;
+ std::map<Checkable::Ptr, Array::Ptr> m_CheckablesCache;
time_t m_TimeFrom;
time_t m_TimeUntil;
String m_CompatLogPath;
{
DynamicObject::Start();
- Service::OnNotificationsRequested.connect(boost::bind(&NotificationComponent::SendNotificationsHandler, this, _1,
+ Checkable::OnNotificationsRequested.connect(boost::bind(&NotificationComponent::SendNotificationsHandler, this, _1,
_2, _3, _4, _5));
m_NotificationTimer = make_shared<Timer>();
double now = Utility::GetTime();
BOOST_FOREACH(const Notification::Ptr& notification, DynamicType::GetObjects<Notification>()) {
- Service::Ptr service = notification->GetService();
+ Checkable::Ptr checkable = notification->GetCheckable();
- if (notification->GetNotificationInterval() <= 0 && notification->GetLastProblemNotification() < service->GetLastHardStateChange())
+ if (notification->GetNotificationInterval() <= 0 && notification->GetLastProblemNotification() < checkable->GetLastHardStateChange())
continue;
if (notification->GetNextNotification() > now)
continue;
- bool reachable = service->IsReachable();
+ bool reachable = checkable->IsReachable();
{
ObjectLock olock(notification);
}
{
- ObjectLock olock(service);
+ ObjectLock olock(checkable);
- if (service->GetStateType() == StateTypeSoft)
+ if (checkable->GetStateType() == StateTypeSoft)
continue;
- if (service->GetState() == StateOK)
- continue;
+ Service::Ptr service = dynamic_pointer_cast<Service>(checkable);
+
+ if (service) {
+ if (service->GetState() == StateOK)
+ continue;
+ } else {
+ Host::Ptr host = static_pointer_cast<Host>(checkable);
+
+ if (host->GetState() == HostUp)
+ continue;
+ }
- if (!reachable || service->IsInDowntime() || service->IsAcknowledged())
+ if (!reachable || checkable->IsInDowntime() || checkable->IsAcknowledged())
continue;
}
try {
- Log(LogInformation, "notification", "Sending reminder notification for service '" + service->GetName() + "'");
- notification->BeginExecuteNotification(NotificationProblem, service->GetLastCheckResult(), false);
+ Log(LogInformation, "notification", "Sending reminder notification for object '" + checkable->GetName() + "'");
+ notification->BeginExecuteNotification(NotificationProblem, checkable->GetLastCheckResult(), false);
} catch (const std::exception& ex) {
std::ostringstream msgbuf;
- msgbuf << "Exception occured during notification for service '"
+ msgbuf << "Exception occured during notification for object '"
<< GetName() << "': " << DiagnosticInformation(ex);
String message = msgbuf.str();
/**
* Processes icinga::SendNotifications messages.
*/
-void NotificationComponent::SendNotificationsHandler(const Service::Ptr& service, NotificationType type,
+void NotificationComponent::SendNotificationsHandler(const Checkable::Ptr& checkable, NotificationType type,
const CheckResult::Ptr& cr, const String& author, const String& text)
{
- service->SendNotifications(type, cr, author, text);
+ checkable->SendNotifications(type, cr, author, text);
}
Timer::Ptr m_NotificationTimer;
void NotificationTimerHandler(void);
- void SendNotificationsHandler(const Service::Ptr& service, NotificationType type,
+ void SendNotificationsHandler(const Checkable::Ptr& checkable, NotificationType type,
const CheckResult::Ptr& cr, const String& author, const String& text);
};
m_Stream = make_shared<BufferedStream>(net_stream);
}
-void GraphiteWriter::CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr& cr)
+void GraphiteWriter::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
{
- if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !service->GetEnablePerfdata())
+ if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !checkable->GetEnablePerfdata())
return;
- Host::Ptr host = service->GetHost();
+ Service::Ptr service = dynamic_pointer_cast<Service>(checkable);
+ Host::Ptr host;
- String hostName = host->GetName();
- String serviceName = service->GetShortName();
+ if (service)
+ host = service->GetHost();
+ else
+ host = static_pointer_cast<Host>(checkable);
+ String hostName = host->GetName();
SanitizeMetric(hostName);
- SanitizeMetric(serviceName);
-
- String prefix = "icinga." + hostName + "." + serviceName;
- /* service metrics */
- SendMetric(prefix, "current_attempt", service->GetCheckAttempt());
- SendMetric(prefix, "max_check_attempts", service->GetMaxCheckAttempts());
- SendMetric(prefix, "state_type", service->GetStateType());
- SendMetric(prefix, "state", service->GetState());
- SendMetric(prefix, "latency", Service::CalculateLatency(cr));
- SendMetric(prefix, "execution_time", Service::CalculateExecutionTime(cr));
+ String prefix;
- SendPerfdata(prefix, cr);
+ if (service) {
+ String serviceName = service->GetShortName();
+ SanitizeMetric(serviceName);
+ prefix = "icinga." + hostName + "." + serviceName;
- if (service == host->GetCheckService()) {
+ SendMetric(prefix, "state", service->GetState());
+ } else {
prefix = "icinga." + hostName;
- /* host metrics */
- SendMetric(prefix, "current_attempt", service->GetCheckAttempt());
- SendMetric(prefix, "max_check_attempts", service->GetMaxCheckAttempts());
- SendMetric(prefix, "state_type", host->GetStateType());
SendMetric(prefix, "state", host->GetState());
- SendMetric(prefix, "latency", Service::CalculateLatency(cr));
- SendMetric(prefix, "execution_time", Service::CalculateExecutionTime(cr));
-
- SendPerfdata(prefix, cr);
}
+
+ SendMetric(prefix, "current_attempt", checkable->GetCheckAttempt());
+ SendMetric(prefix, "max_check_attempts", checkable->GetMaxCheckAttempts());
+ SendMetric(prefix, "state_type", checkable->GetStateType());
+ SendMetric(prefix, "latency", Service::CalculateLatency(cr));
+ SendMetric(prefix, "execution_time", Service::CalculateExecutionTime(cr));
+ SendPerfdata(prefix, cr);
}
void GraphiteWriter::SendPerfdata(const String& prefix, const CheckResult::Ptr& cr)
Timer::Ptr m_ReconnectTimer;
- void CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr& cr);
+ void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
void SendMetric(const String& prefix, const String& name, double value);
void SendPerfdata(const String& prefix, const CheckResult::Ptr& cr);
static void SanitizeMetric(String& str);
{
DynamicObject::Start();
- Service::OnNewCheckResult.connect(boost::bind(&PerfdataWriter::CheckResultHandler, this, _1, _2));
+ Checkable::OnNewCheckResult.connect(boost::bind(&PerfdataWriter::CheckResultHandler, this, _1, _2));
m_RotationTimer = make_shared<Timer>();
m_RotationTimer->OnTimerExpired.connect(boost::bind(&PerfdataWriter::RotationTimerHandler, this));
RotateFile(m_HostOutputFile, GetHostTempPath(), GetHostPerfdataPath());
}
-void PerfdataWriter::CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr& cr)
+void PerfdataWriter::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
{
- CONTEXT("Writing performance data for service '" + service->GetShortName() + "' on host '" + service->GetHost()->GetName() + "'");
+ CONTEXT("Writing performance data for object '" + checkable->GetName() + "'");
- if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !service->GetEnablePerfdata())
+ if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !checkable->GetEnablePerfdata())
return;
- Host::Ptr host = service->GetHost();
+ Service::Ptr service = dynamic_pointer_cast<Service>(checkable);
+ Host::Ptr host;
+
+ if (service)
+ host = service->GetHost();
+ else
+ host = static_pointer_cast<Host>(checkable);
std::vector<MacroResolver::Ptr> resolvers;
- resolvers.push_back(service);
+ if (service)
+ resolvers.push_back(service);
resolvers.push_back(host);
resolvers.push_back(IcingaApplication::GetInstance());
- String line = MacroProcessor::ResolveMacros(GetServiceFormatTemplate(), resolvers, cr);
-
- {
- ObjectLock olock(this);
- if (!m_ServiceOutputFile.good())
- return;
+ if (service) {
+ String line = MacroProcessor::ResolveMacros(GetServiceFormatTemplate(), resolvers, cr);
- m_ServiceOutputFile << line << "\n";
- }
+ {
+ ObjectLock olock(this);
+ if (!m_ServiceOutputFile.good())
+ return;
- if (service == host->GetCheckService()) {
- resolvers.clear();
- resolvers.push_back(host);
- resolvers.push_back(IcingaApplication::GetInstance());
- line = MacroProcessor::ResolveMacros(GetHostFormatTemplate(), resolvers, cr);
+ m_ServiceOutputFile << line << "\n";
+ }
+ } else {
+ String line = MacroProcessor::ResolveMacros(GetHostFormatTemplate(), resolvers, cr);
{
ObjectLock olock(this);
virtual void Start(void);
private:
- void CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr& cr);
+ void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
Timer::Ptr m_RotationTimer;
void RotationTimerHandler(void);
#include <boost/smart_ptr/weak_ptr.hpp>
#include <boost/smart_ptr/enable_shared_from_this.hpp>
#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/tuple/tuple.hpp>
using boost::shared_ptr;
using boost::weak_ptr;
using boost::dynamic_pointer_cast;
using boost::static_pointer_cast;
using boost::make_shared;
+using boost::tie;
namespace icinga
{
add_library(db_ido SHARED
commanddbobject.cpp dbconnection.cpp dbconnection.th dbconnection.th
- db_ido-type.cpp dbobject.cpp dbquery.cpp dbreference.cpp dbtype.cpp
+ db_ido-type.cpp dbevents.cpp dbobject.cpp dbquery.cpp dbreference.cpp dbtype.cpp
dbvalue.cpp endpointdbobject.cpp hostdbobject.cpp hostgroupdbobject.cpp
servicedbobject.cpp servicegroupdbobject.cpp timeperioddbobject.cpp
userdbobject.cpp usergroupdbobject.cpp
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+#include "db_ido/dbevents.h"
+#include "db_ido/dbtype.h"
+#include "db_ido/dbvalue.h"
+#include "base/convert.h"
+#include "base/objectlock.h"
+#include "base/initialize.h"
+#include "base/dynamictype.h"
+#include "base/utility.h"
+#include "remote/endpoint.h"
+#include "icinga/notification.h"
+#include "icinga/checkcommand.h"
+#include "icinga/eventcommand.h"
+#include "icinga/externalcommandprocessor.h"
+#include "icinga/compatutility.h"
+#include "icinga/icingaapplication.h"
+#include <boost/foreach.hpp>
+#include <boost/algorithm/string/join.hpp>
+
+using namespace icinga;
+
+INITIALIZE_ONCE(&DbEvents::StaticInitialize);
+
+void DbEvents::StaticInitialize(void)
+{
+ /* Status */
+ Service::OnCommentAdded.connect(boost::bind(&DbEvents::AddComment, _1, _2));
+ Service::OnCommentRemoved.connect(boost::bind(&DbEvents::RemoveComment, _1, _2));
+ Service::OnDowntimeAdded.connect(boost::bind(&DbEvents::AddDowntime, _1, _2));
+ Service::OnDowntimeRemoved.connect(boost::bind(&DbEvents::RemoveDowntime, _1, _2));
+ Service::OnDowntimeTriggered.connect(boost::bind(&DbEvents::TriggerDowntime, _1, _2));
+
+ /* History */
+ Service::OnCommentAdded.connect(boost::bind(&DbEvents::AddCommentHistory, _1, _2));
+ Service::OnDowntimeAdded.connect(boost::bind(&DbEvents::AddDowntimeHistory, _1, _2));
+ Service::OnAcknowledgementSet.connect(boost::bind(&DbEvents::AddAcknowledgementHistory, _1, _2, _3, _4, _5));
+
+ Service::OnNotificationSentToAllUsers.connect(bind(&DbEvents::AddNotificationHistory, _1, _2, _3, _4, _5, _6, _7));
+
+ Service::OnStateChange.connect(boost::bind(&DbEvents::AddStateChangeHistory, _1, _2, _3));
+
+ Service::OnNewCheckResult.connect(bind(&DbEvents::AddCheckResultLogHistory, _1, _2));
+ Service::OnNotificationSentToUser.connect(bind(&DbEvents::AddNotificationSentLogHistory, _1, _2, _3, _4, _5, _6, _7));
+ Service::OnFlappingChanged.connect(bind(&DbEvents::AddFlappingLogHistory, _1, _2));
+ Service::OnDowntimeTriggered.connect(boost::bind(&DbEvents::AddTriggerDowntimeLogHistory, _1, _2));
+ Service::OnDowntimeRemoved.connect(boost::bind(&DbEvents::AddRemoveDowntimeLogHistory, _1, _2));
+
+ Service::OnFlappingChanged.connect(bind(&DbEvents::AddFlappingHistory, _1, _2));
+ Service::OnNewCheckResult.connect(bind(&DbEvents::AddServiceCheckHistory, _1, _2));
+
+ Service::OnEventCommandExecuted.connect(bind(&DbEvents::AddEventHandlerHistory, _1));
+
+ ExternalCommandProcessor::OnNewExternalCommand.connect(boost::bind(&DbEvents::AddExternalCommandHistory, _1, _2, _3));
+}
+
+/* comments */
+void DbEvents::AddComments(const Checkable::Ptr& checkable)
+{
+ /* dump all comments */
+ Dictionary::Ptr comments = checkable->GetComments();
+
+ if (comments->GetLength() > 0)
+ RemoveComments(checkable);
+
+ ObjectLock olock(comments);
+
+ BOOST_FOREACH(const Dictionary::Pair& kv, comments) {
+ AddComment(checkable, kv.second);
+ }
+}
+
+void DbEvents::AddComment(const Checkable::Ptr& checkable, const Comment::Ptr& comment)
+{
+ AddCommentInternal(checkable, comment, false);
+}
+
+void DbEvents::AddCommentHistory(const Checkable::Ptr& checkable, const Comment::Ptr& comment)
+{
+ AddCommentInternal(checkable, comment, true);
+}
+
+void DbEvents::AddCommentInternal(const Checkable::Ptr& checkable, const Comment::Ptr& comment, bool historical)
+{
+ if (!comment) {
+ Log(LogWarning, "db_ido", "comment does not exist. not adding it.");
+ return;
+ }
+
+ Log(LogDebug, "db_ido", "adding service comment (id = " + Convert::ToString(comment->GetLegacyId()) + ") for '" + checkable->GetName() + "'");
+
+ /* add the service comment */
+ AddCommentByType(checkable, comment, historical);
+}
+
+void DbEvents::AddCommentByType(const DynamicObject::Ptr& object, const Comment::Ptr& comment, bool historical)
+{
+ unsigned long entry_time = static_cast<long>(comment->GetEntryTime());
+ unsigned long entry_time_usec = (comment->GetEntryTime() - entry_time) * 1000 * 1000;
+
+ Dictionary::Ptr fields1 = make_shared<Dictionary>();
+ fields1->Set("entry_time", DbValue::FromTimestamp(entry_time));
+ fields1->Set("entry_time_usec", entry_time_usec);
+ fields1->Set("entry_type", comment->GetEntryType());
+ fields1->Set("object_id", object);
+
+ if (object->GetType() == DynamicType::GetByName("Host")) {
+ fields1->Set("comment_type", 2);
+ /* requires idoutils 1.10 schema fix */
+ fields1->Set("internal_comment_id", comment->GetLegacyId());
+ } else if (object->GetType() == DynamicType::GetByName("Service")) {
+ fields1->Set("comment_type", 1);
+ fields1->Set("internal_comment_id", comment->GetLegacyId());
+ } else {
+ Log(LogDebug, "db_ido", "unknown object type for adding comment.");
+ return;
+ }
+
+ fields1->Set("comment_time", DbValue::FromTimestamp(entry_time)); /* same as entry_time */
+ fields1->Set("author_name", comment->GetAuthor());
+ fields1->Set("comment_data", comment->GetText());
+ fields1->Set("is_persistent", 1);
+ fields1->Set("comment_source", 1); /* external */
+ fields1->Set("expires", (comment->GetExpireTime() > 0) ? 1 : 0);
+ fields1->Set("expiration_time", DbValue::FromTimestamp(comment->GetExpireTime()));
+ fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
+
+ String node = IcingaApplication::GetInstance()->GetNodeName();
+
+ Endpoint::Ptr endpoint = Endpoint::GetByName(node);
+ if (endpoint)
+ fields1->Set("endpoint_object_id", endpoint);
+
+ DbQuery query1;
+ if (!historical) {
+ query1.Table = "comments";
+ } else {
+ query1.Table = "commenthistory";
+ }
+ query1.Type = DbQueryInsert;
+ query1.Category = DbCatComment;
+ query1.Fields = fields1;
+ DbObject::OnQuery(query1);
+}
+
+void DbEvents::RemoveComments(const Checkable::Ptr& checkable)
+{
+ Log(LogDebug, "db_ido", "removing service comments for '" + checkable->GetName() + "'");
+
+ DbQuery query1;
+ query1.Table = "comments";
+ query1.Type = DbQueryDelete;
+ query1.Category = DbCatComment;
+ query1.WhereCriteria = make_shared<Dictionary>();
+ query1.WhereCriteria->Set("object_id", checkable);
+ DbObject::OnQuery(query1);
+}
+
+void DbEvents::RemoveComment(const Checkable::Ptr& checkable, const Comment::Ptr& comment)
+{
+ if (!comment) {
+ Log(LogWarning, "db_ido", "comment does not exist. not deleting it.");
+ return;
+ }
+
+ Log(LogDebug, "db_ido", "removing service comment (id = " + Convert::ToString(comment->GetLegacyId()) + ") for '" + checkable->GetName() + "'");
+
+ /* Status */
+ DbQuery query1;
+ query1.Table = "comments";
+ query1.Type = DbQueryDelete;
+ query1.Category = DbCatComment;
+ query1.WhereCriteria = make_shared<Dictionary>();
+ query1.WhereCriteria->Set("object_id", checkable);
+ query1.WhereCriteria->Set("internal_comment_id", comment->GetLegacyId());
+ DbObject::OnQuery(query1);
+
+ /* History - update deletion time for service/host */
+ unsigned long entry_time = static_cast<long>(comment->GetEntryTime());
+
+ double now = Utility::GetTime();
+ std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now);
+
+ DbQuery query2;
+ query2.Table = "commenthistory";
+ query2.Type = DbQueryUpdate;
+ query2.Category = DbCatComment;
+
+ Dictionary::Ptr fields2 = make_shared<Dictionary>();
+ fields2->Set("deletion_time", DbValue::FromTimestamp(time_bag.first));
+ fields2->Set("deletion_time_usec", time_bag.second);
+ query2.Fields = fields2;
+
+ query2.WhereCriteria = make_shared<Dictionary>();
+ query2.WhereCriteria->Set("internal_comment_id", comment->GetLegacyId());
+ query2.WhereCriteria->Set("comment_time", DbValue::FromTimestamp(entry_time));
+ query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
+
+ DbObject::OnQuery(query2);
+}
+
+/* downtimes */
+void DbEvents::AddDowntimes(const Checkable::Ptr& checkable)
+{
+ /* dump all downtimes */
+ Dictionary::Ptr downtimes = checkable->GetDowntimes();
+
+ if (downtimes->GetLength() > 0)
+ RemoveDowntimes(checkable);
+
+ ObjectLock olock(downtimes);
+
+ BOOST_FOREACH(const Dictionary::Pair& kv, downtimes) {
+ AddDowntime(checkable, kv.second);
+ }
+}
+
+void DbEvents::AddDowntime(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime)
+{
+ AddDowntimeInternal(checkable, downtime, false);
+}
+
+void DbEvents::AddDowntimeHistory(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime)
+{
+ AddDowntimeInternal(checkable, downtime, true);
+}
+
+void DbEvents::AddDowntimeInternal(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime, bool historical)
+{
+ if (!downtime) {
+ Log(LogWarning, "db_ido", "downtime does not exist. not adding it.");
+ return;
+ }
+
+ Log(LogDebug, "db_ido", "adding service downtime (id = " + Convert::ToString(downtime->GetLegacyId()) + ") for '" + checkable->GetName() + "'");
+
+ /* add the downtime */
+ AddDowntimeByType(checkable, downtime, historical);}
+
+void DbEvents::AddDowntimeByType(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime, bool historical)
+{
+ Dictionary::Ptr fields1 = make_shared<Dictionary>();
+ fields1->Set("entry_time", DbValue::FromTimestamp(downtime->GetEntryTime()));
+ fields1->Set("object_id", checkable);
+
+ if (checkable->GetType() == DynamicType::GetByName("Host")) {
+ fields1->Set("downtime_type", 2);
+ /* requires idoutils 1.10 schema fix */
+ fields1->Set("internal_downtime_id", downtime->GetLegacyId());
+ } else if (checkable->GetType() == DynamicType::GetByName("Service")) {
+ fields1->Set("downtime_type", 1);
+ fields1->Set("internal_downtime_id", downtime->GetLegacyId());
+ } else {
+ Log(LogDebug, "db_ido", "unknown object type for adding downtime.");
+ return;
+ }
+
+ fields1->Set("author_name", downtime->GetAuthor());
+ fields1->Set("comment_data", downtime->GetComment());
+ fields1->Set("triggered_by_id", Service::GetDowntimeByID(downtime->GetTriggeredBy()));
+ fields1->Set("is_fixed", downtime->GetFixed());
+ fields1->Set("duration", downtime->GetDuration());
+ fields1->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime()));
+ fields1->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime()));
+ fields1->Set("was_started", Empty);
+ fields1->Set("actual_start_time", Empty);
+ fields1->Set("actual_start_time_usec", Empty);
+ fields1->Set("is_in_effect", Empty);
+ fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime()));
+ fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
+
+ String node = IcingaApplication::GetInstance()->GetNodeName();
+
+ Endpoint::Ptr endpoint = Endpoint::GetByName(node);
+ if (endpoint)
+ fields1->Set("endpoint_object_id", endpoint);
+
+ DbQuery query1;
+
+ if (!historical)
+ query1.Table = "scheduleddowntime";
+ else
+ query1.Table = "downtimehistory";
+
+ query1.Type = DbQueryInsert;
+ query1.Category = DbCatDowntime;
+ query1.Fields = fields1;
+ DbObject::OnQuery(query1);
+}
+
+void DbEvents::RemoveDowntimes(const Checkable::Ptr& checkable)
+{
+ Log(LogDebug, "db_ido", "removing service downtimes for '" + checkable->GetName() + "'");
+
+ DbQuery query1;
+ query1.Table = "scheduleddowntime";
+ query1.Type = DbQueryDelete;
+ query1.Category = DbCatDowntime;
+ query1.WhereCriteria = make_shared<Dictionary>();
+ query1.WhereCriteria->Set("object_id", checkable);
+ DbObject::OnQuery(query1);
+}
+
+void DbEvents::RemoveDowntime(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime)
+{
+ if (!downtime) {
+ Log(LogWarning, "db_ido", "downtime does not exist. not adding it.");
+ return;
+ }
+
+ Log(LogDebug, "db_ido", "removing service downtime (id = " + Convert::ToString(downtime->GetLegacyId()) + ") for '" + checkable->GetName() + "'");
+
+ /* Status */
+ DbQuery query1;
+ query1.Table = "scheduleddowntime";
+ query1.Type = DbQueryDelete;
+ query1.Category = DbCatDowntime;
+ query1.WhereCriteria = make_shared<Dictionary>();
+ query1.WhereCriteria->Set("object_id", checkable);
+ query1.WhereCriteria->Set("internal_downtime_id", downtime->GetLegacyId());
+ DbObject::OnQuery(query1);
+
+ /* History - update actual_end_time, was_cancelled for service (and host in case) */
+ double now = Utility::GetTime();
+ std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now);
+
+ DbQuery query3;
+ query3.Table = "downtimehistory";
+ query3.Type = DbQueryUpdate;
+ query3.Category = DbCatDowntime;
+
+ Dictionary::Ptr fields3 = make_shared<Dictionary>();
+ fields3->Set("was_cancelled", downtime->GetWasCancelled() ? 1 : 0);
+ fields3->Set("actual_end_time", DbValue::FromTimestamp(time_bag.first));
+ fields3->Set("actual_end_time_usec", time_bag.second);
+ query3.Fields = fields3;
+
+ query3.WhereCriteria = make_shared<Dictionary>();
+ query3.WhereCriteria->Set("internal_downtime_id", downtime->GetLegacyId());
+ query3.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(downtime->GetEntryTime()));
+ query3.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime()));
+ query3.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime()));
+ query3.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
+
+ DbObject::OnQuery(query3);
+}
+
+void DbEvents::TriggerDowntime(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime)
+{
+ if (!downtime) {
+ Log(LogWarning, "db_ido", "downtime does not exist. not updating it.");
+ return;
+ }
+
+ Log(LogDebug, "db_ido", "updating triggered service downtime (id = " + Convert::ToString(downtime->GetLegacyId()) + ") for '" + checkable->GetName() + "'");
+
+ double now = Utility::GetTime();
+ std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now);
+
+ /* Status */
+ DbQuery query1;
+ query1.Table = "scheduleddowntime";
+ query1.Type = DbQueryUpdate;
+ query1.Category = DbCatDowntime;
+
+ Dictionary::Ptr fields1 = make_shared<Dictionary>();
+ fields1->Set("was_started", 1);
+ fields1->Set("actual_start_time", DbValue::FromTimestamp(time_bag.first));
+ fields1->Set("actual_start_time_usec", time_bag.second);
+ fields1->Set("is_in_effect", 1);
+ fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime()));
+ fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
+
+ query1.WhereCriteria = make_shared<Dictionary>();
+ query1.WhereCriteria->Set("object_id", checkable);
+ query1.WhereCriteria->Set("internal_downtime_id", downtime->GetLegacyId());
+
+ query1.Fields = fields1;
+ DbObject::OnQuery(query1);
+
+ /* History - downtime was started for service (and host in case) */
+ DbQuery query3;
+ query3.Table = "downtimehistory";
+ query3.Type = DbQueryUpdate;
+ query3.Category = DbCatDowntime;
+
+ Dictionary::Ptr fields3 = make_shared<Dictionary>();
+ fields3->Set("was_started", 1);
+ fields3->Set("is_in_effect", 1);
+ fields3->Set("actual_start_time", DbValue::FromTimestamp(time_bag.first));
+ fields3->Set("actual_start_time_usec", time_bag.second);
+ fields3->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime()));
+ query3.Fields = fields3;
+
+ query3.WhereCriteria = make_shared<Dictionary>();
+ query3.WhereCriteria->Set("internal_downtime_id", downtime->GetLegacyId());
+ query3.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(downtime->GetEntryTime()));
+ query3.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime()));
+ query3.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime()));
+ query3.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
+
+ DbObject::OnQuery(query3);
+}
+
+/* acknowledgements */
+void DbEvents::AddAcknowledgementHistory(const Checkable::Ptr& checkable, const String& author, const String& comment,
+ AcknowledgementType type, double expiry)
+{
+ Log(LogDebug, "db_ido", "add acknowledgement history for '" + checkable->GetName() + "'");
+
+ double now = Utility::GetTime();
+ std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now);
+
+ unsigned long end_time = static_cast<long>(expiry);
+
+ DbQuery query1;
+ query1.Table = "acknowledgements";
+ query1.Type = DbQueryInsert;
+ query1.Category = DbCatAcknowledgement;
+
+ Host::Ptr host;
+ Service::Ptr service;
+ tie(host, service) = GetHostService(checkable);
+
+ Dictionary::Ptr fields1 = make_shared<Dictionary>();
+ fields1->Set("entry_time", DbValue::FromTimestamp(time_bag.first));
+ fields1->Set("entry_time_usec", time_bag.second);
+ fields1->Set("acknowledgement_type", type);
+ fields1->Set("object_id", checkable);
+ fields1->Set("state", service ? service->GetState() : host->GetState());
+ fields1->Set("author_name", author);
+ fields1->Set("comment_data", comment);
+ fields1->Set("is_sticky", type == AcknowledgementSticky ? 1 : 0);
+ fields1->Set("end_time", DbValue::FromTimestamp(end_time));
+ fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
+
+ String node = IcingaApplication::GetInstance()->GetNodeName();
+
+ Endpoint::Ptr endpoint = Endpoint::GetByName(node);
+ if (endpoint)
+ fields1->Set("endpoint_object_id", endpoint);
+
+ query1.Fields = fields1;
+ DbObject::OnQuery(query1);
+}
+
+/* notifications */
+void DbEvents::AddNotificationHistory(const Notification::Ptr& notification, const Checkable::Ptr& checkable, const std::set<User::Ptr>& users, NotificationType type,
+ const CheckResult::Ptr& cr, const String& author, const String& text)
+{
+ Log(LogDebug, "db_ido", "add notification history for '" + checkable->GetName() + "'");
+
+ /* start and end happen at the same time */
+ double now = Utility::GetTime();
+ std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now);
+
+ DbQuery query1;
+ query1.Table = "notifications";
+ query1.Type = DbQueryInsert;
+ query1.Category = DbCatNotification;
+ /* store the object ptr for caching the insert id for this object */
+ query1.NotificationObject = notification;
+
+ Host::Ptr host;
+ Service::Ptr service;
+ tie(host, service) = GetHostService(checkable);
+
+ Dictionary::Ptr fields1 = make_shared<Dictionary>();
+ fields1->Set("notification_type", 1); /* service */
+ fields1->Set("notification_reason", CompatUtility::MapNotificationReasonType(type));
+ fields1->Set("object_id", checkable);
+ fields1->Set("start_time", DbValue::FromTimestamp(time_bag.first));
+ fields1->Set("start_time_usec", time_bag.second);
+ fields1->Set("end_time", DbValue::FromTimestamp(time_bag.first));
+ fields1->Set("end_time_usec", time_bag.second);
+ fields1->Set("state", service ? service->GetState() : host->GetState());
+
+ if (cr) {
+ fields1->Set("output", CompatUtility::GetCheckResultOutput(cr));
+ fields1->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr));
+ }
+
+ fields1->Set("escalated", 0);
+ fields1->Set("contacts_notified", static_cast<long>(users.size()));
+ fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
+
+ String node = IcingaApplication::GetInstance()->GetNodeName();
+
+ Endpoint::Ptr endpoint = Endpoint::GetByName(node);
+ if (endpoint)
+ fields1->Set("endpoint_object_id", endpoint);
+
+ query1.Fields = fields1;
+ DbObject::OnQuery(query1);
+
+ DbQuery query2;
+ query2.Table = "contactnotifications";
+ query2.Type = DbQueryInsert;
+ query2.Category = DbCatNotification;
+
+ /* filtered users */
+ BOOST_FOREACH(const User::Ptr& user, users) {
+ Log(LogDebug, "db_ido", "add contact notification history for service '" + checkable->GetName() + "' and user '" + user->GetName() + "'.");
+
+ Dictionary::Ptr fields2 = make_shared<Dictionary>();
+ fields2->Set("contact_object_id", user);
+ fields2->Set("start_time", DbValue::FromTimestamp(time_bag.first));
+ fields2->Set("start_time_usec", time_bag.second);
+ fields2->Set("end_time", DbValue::FromTimestamp(time_bag.first));
+ fields2->Set("end_time_usec", time_bag.second);
+
+ fields2->Set("notification_id", notification); /* DbConnection class fills in real ID from notification insert id cache */
+ fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */
+
+ query2.Fields = fields2;
+ DbObject::OnQuery(query2);
+ }
+}
+
+/* statehistory */
+void DbEvents::AddStateChangeHistory(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type)
+{
+ Log(LogDebug, "db_ido", "add state change history for '" + checkable->GetName() + "'");
+
+ double now = Utility::GetTime();
+ std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now);
+
+ DbQuery query1;
+ query1.Table = "statehistory";
+ query1.Type = DbQueryInsert;
+ query1.Category = DbCatStateHistory;
+
+ Host::Ptr host;
+ Service::Ptr service;
+ tie(host, service) = GetHostService(checkable);
+
+ Dictionary::Ptr fields1 = make_shared<Dictionary>();
+ fields1->Set("state_time", DbValue::FromTimestamp(time_bag.first));
+ fields1->Set("state_time_usec", time_bag.second);
+ fields1->Set("object_id", checkable);
+ fields1->Set("state_change", 1); /* service */
+ fields1->Set("state", service ? service->GetState() : host->GetState());
+ fields1->Set("state_type", checkable->GetStateType());
+ fields1->Set("current_check_attempt", checkable->GetCheckAttempt());
+ fields1->Set("max_check_attempts", checkable->GetMaxCheckAttempts());
+
+ if (service) {
+ fields1->Set("last_state", service->GetLastState());
+ fields1->Set("last_hard_state", service->GetLastHardState());
+ } else {
+ fields1->Set("last_state", host->GetLastState());
+ fields1->Set("last_hard_state", host->GetLastHardState());
+ }
+
+ if (cr) {
+ fields1->Set("output", CompatUtility::GetCheckResultOutput(cr));
+ fields1->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr));
+ fields1->Set("check_source", cr->GetCheckSource());
+ }
+
+ fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
+
+ String node = IcingaApplication::GetInstance()->GetNodeName();
+
+ Endpoint::Ptr endpoint = Endpoint::GetByName(node);
+ if (endpoint)
+ fields1->Set("endpoint_object_id", endpoint);
+
+ query1.Fields = fields1;
+ DbObject::OnQuery(query1);
+}
+
+/* logentries */
+void DbEvents::AddCheckResultLogHistory(const Checkable::Ptr& checkable, const CheckResult::Ptr &cr)
+{
+ Dictionary::Ptr vars_after = cr->GetVarsAfter();
+
+ long state_after = vars_after->Get("state");
+ long stateType_after = vars_after->Get("state_type");
+ long attempt_after = vars_after->Get("attempt");
+ bool reachable_after = vars_after->Get("reachable");
+ bool host_reachable_after = vars_after->Get("host_reachable");
+
+ Dictionary::Ptr vars_before = cr->GetVarsBefore();
+
+ if (vars_before) {
+ long state_before = vars_before->Get("state");
+ long stateType_before = vars_before->Get("state_type");
+ long attempt_before = vars_before->Get("attempt");
+ bool reachable_before = vars_before->Get("reachable");
+
+ if (state_before == state_after && stateType_before == stateType_after &&
+ attempt_before == attempt_after && reachable_before == reachable_after)
+ return; /* Nothing changed, ignore this checkresult. */
+ }
+
+ LogEntryType type;
+ String output;
+
+ if (cr)
+ output = CompatUtility::GetCheckResultOutput(cr);
+
+ Host::Ptr host;
+ Service::Ptr service;
+ tie(host, service) = GetHostService(checkable);
+
+ std::ostringstream msgbuf;
+
+ if (service) {
+ msgbuf << "SERVICE ALERT: "
+ << host->GetName() << ";"
+ << service->GetShortName() << ";"
+ << Service::StateToString(static_cast<ServiceState>(state_after)) << ";"
+ << Service::StateTypeToString(static_cast<StateType>(stateType_after)) << ";"
+ << attempt_after << ";"
+ << output << ""
+ << "";
+
+ switch (service->GetState()) {
+ case StateOK:
+ type = LogEntryTypeServiceOk;
+ break;
+ case StateUnknown:
+ type = LogEntryTypeServiceUnknown;
+ break;
+ case StateWarning:
+ type = LogEntryTypeServiceWarning;
+ break;
+ case StateCritical:
+ type = LogEntryTypeServiceCritical;
+ break;
+ default:
+ Log(LogCritical, "db_ido", "Unknown service state: " + Convert::ToString(state_after));
+ return;
+ }
+ } else {
+ msgbuf << "HOST ALERT: "
+ << host->GetName() << ";"
+ << Host::StateToString(Host::CalculateState(static_cast<ServiceState>(state_after), host_reachable_after)) << ";"
+ << Service::StateTypeToString(static_cast<StateType>(stateType_after)) << ";"
+ << attempt_after << ";"
+ << output << ""
+ << "";
+
+ switch (host->GetState()) {
+ case HostUp:
+ type = LogEntryTypeHostUp;
+ break;
+ case HostDown:
+ type = LogEntryTypeHostDown;
+ break;
+ case HostUnreachable:
+ type = LogEntryTypeHostUnreachable;
+ break;
+ default:
+ Log(LogCritical, "db_ido", "Unknown host state: " + Convert::ToString(state_after));
+ return;
+ }
+
+ }
+
+ AddLogHistory(checkable, msgbuf.str(), type);
+}
+
+void DbEvents::AddTriggerDowntimeLogHistory(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime)
+{
+ if (!downtime)
+ return;
+
+ Host::Ptr host;
+ Service::Ptr service;
+ tie(host, service) = GetHostService(checkable);
+
+ std::ostringstream msgbuf;
+
+ if (service) {
+ msgbuf << "SERVICE DOWNTIME ALERT: "
+ << host->GetName() << ";"
+ << service->GetShortName() << ";"
+ << "STARTED" << "; "
+ << "Service has entered a period of scheduled downtime."
+ << "";
+ } else {
+ msgbuf << "HOST DOWNTIME ALERT: "
+ << host->GetName() << ";"
+ << "STARTED" << "; "
+ << "Service has entered a period of scheduled downtime."
+ << "";
+ }
+
+ AddLogHistory(checkable, msgbuf.str(), LogEntryTypeInfoMessage);
+}
+
+void DbEvents::AddRemoveDowntimeLogHistory(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime)
+{
+ if (!downtime)
+ return;
+
+ String downtime_output;
+ String downtime_state_str;
+
+ if (downtime->GetWasCancelled()) {
+ downtime_output = "Scheduled downtime for service has been cancelled.";
+ downtime_state_str = "CANCELLED";
+ } else {
+ downtime_output = "Service has exited from a period of scheduled downtime.";
+ downtime_state_str = "STOPPED";
+ }
+
+ Host::Ptr host;
+ Service::Ptr service;
+ tie(host, service) = GetHostService(checkable);
+
+ std::ostringstream msgbuf;
+
+ if (service) {
+ msgbuf << "SERVICE DOWNTIME ALERT: "
+ << host->GetName() << ";"
+ << service->GetShortName() << ";"
+ << downtime_state_str << "; "
+ << downtime_output
+ << "";
+ } else {
+ msgbuf << "HOST DOWNTIME ALERT: "
+ << host->GetName() << ";"
+ << downtime_state_str << "; "
+ << downtime_output
+ << "";
+ }
+
+ AddLogHistory(service, msgbuf.str(), LogEntryTypeInfoMessage);
+}
+
+void DbEvents::AddNotificationSentLogHistory(const Notification::Ptr& notification, const Checkable::Ptr& checkable, const User::Ptr& user,
+ NotificationType notification_type, const CheckResult::Ptr& cr,
+ const String& author, const String& comment_text)
+{
+ CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
+
+ String check_command = "";
+ if (commandObj)
+ check_command = commandObj->GetName();
+
+ String notification_type_str = Notification::NotificationTypeToString(notification_type);
+
+ String author_comment = "";
+ if (notification_type == NotificationCustom || notification_type == NotificationAcknowledgement) {
+ author_comment = ";" + author + ";" + comment_text;
+ }
+
+ if (!cr)
+ return;
+
+ String output;
+
+ if (cr)
+ output = CompatUtility::GetCheckResultOutput(cr);
+
+ Host::Ptr host;
+ Service::Ptr service;
+ tie(host, service) = GetHostService(checkable);
+
+ std::ostringstream msgbuf;
+
+ if (service) {
+ msgbuf << "SERVICE NOTIFICATION: "
+ << user->GetName() << ";"
+ << host->GetName() << ";"
+ << service->GetShortName() << ";"
+ << notification_type_str << " "
+ << "(" << Service::StateToString(service->GetState()) << ");"
+ << check_command << ";"
+ << output << author_comment
+ << "";
+ } else {
+ msgbuf << "HOST NOTIFICATION: "
+ << user->GetName() << ";"
+ << host->GetName() << ";"
+ << notification_type_str << " "
+ << "(" << Host::StateToString(host->GetState()) << ");"
+ << check_command << ";"
+ << output << author_comment
+ << "";
+ }
+
+ AddLogHistory(service, msgbuf.str(), LogEntryTypeHostNotification);
+}
+
+void DbEvents::AddFlappingLogHistory(const Checkable::Ptr& checkable, FlappingState flapping_state)
+{
+ String flapping_state_str;
+ String flapping_output;
+
+ switch (flapping_state) {
+ case FlappingStarted:
+ flapping_output = "Service appears to have started flapping (" + Convert::ToString(checkable->GetFlappingCurrent()) + "% change >= " + Convert::ToString(checkable->GetFlappingThreshold()) + "% threshold)";
+ flapping_state_str = "STARTED";
+ break;
+ case FlappingStopped:
+ flapping_output = "Service appears to have stopped flapping (" + Convert::ToString(checkable->GetFlappingCurrent()) + "% change < " + Convert::ToString(checkable->GetFlappingThreshold()) + "% threshold)";
+ flapping_state_str = "STOPPED";
+ break;
+ case FlappingDisabled:
+ flapping_output = "Flap detection has been disabled";
+ flapping_state_str = "DISABLED";
+ break;
+ default:
+ Log(LogCritical, "db_ido", "Unknown flapping state: " + Convert::ToString(flapping_state));
+ return;
+ }
+
+ Host::Ptr host;
+ Service::Ptr service;
+ tie(host, service) = GetHostService(checkable);
+
+ std::ostringstream msgbuf;
+
+ if (service) {
+ msgbuf << "SERVICE FLAPPING ALERT: "
+ << host->GetName() << ";"
+ << service->GetShortName() << ";"
+ << flapping_state_str << "; "
+ << flapping_output
+ << "";
+ } else {
+ msgbuf << "HOST FLAPPING ALERT: "
+ << host->GetName() << ";"
+ << flapping_state_str << "; "
+ << flapping_output
+ << "";
+ }
+
+ AddLogHistory(service, msgbuf.str(), LogEntryTypeInfoMessage);
+}
+
+void DbEvents::AddLogHistory(const Checkable::Ptr& checkable, String buffer, LogEntryType type)
+{
+ Log(LogDebug, "db_ido", "add log entry history for '" + checkable->GetName() + "'");
+
+ double now = Utility::GetTime();
+ std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now);
+
+ DbQuery query1;
+ query1.Table = "logentries";
+ query1.Type = DbQueryInsert;
+ query1.Category = DbCatLog;
+
+ Dictionary::Ptr fields1 = make_shared<Dictionary>();
+ fields1->Set("logentry_time", DbValue::FromTimestamp(time_bag.first));
+ fields1->Set("entry_time", DbValue::FromTimestamp(time_bag.first));
+ fields1->Set("entry_time_usec", time_bag.second);
+ fields1->Set("object_id", checkable); // added in 1.10 see #4754
+ fields1->Set("logentry_type", type);
+ fields1->Set("logentry_data", buffer);
+
+ fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
+
+ String node = IcingaApplication::GetInstance()->GetNodeName();
+
+ Endpoint::Ptr endpoint = Endpoint::GetByName(node);
+ if (endpoint)
+ fields1->Set("endpoint_object_id", endpoint);
+
+ query1.Fields = fields1;
+ DbObject::OnQuery(query1);
+}
+
+/* flappinghistory */
+void DbEvents::AddFlappingHistory(const Checkable::Ptr& checkable, FlappingState flapping_state)
+{
+ Log(LogDebug, "db_ido", "add flapping history for '" + checkable->GetName() + "'");
+
+ double now = Utility::GetTime();
+ std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now);
+
+ DbQuery query1;
+ query1.Table = "flappinghistory";
+ query1.Type = DbQueryInsert;
+ query1.Category = DbCatFlapping;
+
+ Dictionary::Ptr fields1 = make_shared<Dictionary>();
+
+ fields1->Set("event_time", DbValue::FromTimestamp(time_bag.first));
+ fields1->Set("event_time_usec", time_bag.second);
+
+ switch (flapping_state) {
+ case FlappingStarted:
+ fields1->Set("event_type", 1000);
+ break;
+ case FlappingStopped:
+ fields1->Set("event_type", 1001);
+ fields1->Set("reason_type", 1);
+ break;
+ case FlappingDisabled:
+ fields1->Set("event_type", 1001);
+ fields1->Set("reason_type", 2);
+ break;
+ default:
+ Log(LogDebug, "db_ido", "Unhandled flapping state: " + Convert::ToString(flapping_state));
+ return;
+ }
+
+ Host::Ptr host;
+ Service::Ptr service;
+ tie(host, service) = GetHostService(checkable);
+
+ fields1->Set("flapping_type", service ? 1 : 0);
+ fields1->Set("object_id", checkable);
+ fields1->Set("percent_state_change", checkable->GetFlappingCurrent());
+ fields1->Set("low_threshold", checkable->GetFlappingThreshold());
+ fields1->Set("high_threshold", checkable->GetFlappingThreshold());
+
+ fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
+
+ String node = IcingaApplication::GetInstance()->GetNodeName();
+
+ Endpoint::Ptr endpoint = Endpoint::GetByName(node);
+ if (endpoint)
+ fields1->Set("endpoint_object_id", endpoint);
+
+ query1.Fields = fields1;
+ DbObject::OnQuery(query1);
+}
+
+/* servicechecks */
+void DbEvents::AddServiceCheckHistory(const Checkable::Ptr& checkable, const CheckResult::Ptr &cr)
+{
+ if (!cr)
+ return;
+
+ Log(LogDebug, "db_ido", "add service check history for '" + checkable->GetName() + "'");
+
+ Host::Ptr host;
+ Service::Ptr service;
+ tie(host, service) = GetHostService(checkable);
+
+ std::ostringstream msgbuf;
+
+ DbQuery query1;
+ query1.Table = service ? "servicechecks" : "hostchecks";
+ query1.Type = DbQueryInsert;
+ query1.Category = DbCatCheck;
+
+ Dictionary::Ptr fields1 = make_shared<Dictionary>();
+ double execution_time = Service::CalculateExecutionTime(cr);
+
+ fields1->Set("check_type", CompatUtility::GetCheckableCheckType(checkable));
+ fields1->Set("current_check_attempt", checkable->GetCheckAttempt());
+ fields1->Set("max_check_attempts", checkable->GetMaxCheckAttempts());
+ fields1->Set("state_type", checkable->GetStateType());
+
+ double now = Utility::GetTime();
+ std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now);
+
+ double end = now + execution_time;
+ std::pair<unsigned long, unsigned long> time_bag_end = CompatUtility::ConvertTimestamp(end);
+
+ fields1->Set("start_time", DbValue::FromTimestamp(time_bag.first));
+ fields1->Set("start_time_usec", time_bag.second);
+ fields1->Set("end_time", DbValue::FromTimestamp(time_bag_end.first));
+ fields1->Set("end_time_usec", time_bag_end.second);
+ fields1->Set("command_object_id", checkable->GetCheckCommand());
+ fields1->Set("command_args", Empty);
+ fields1->Set("command_line", cr->GetCommand());
+ fields1->Set("execution_time", Convert::ToString(execution_time));
+ fields1->Set("latency", Convert::ToString(Service::CalculateLatency(cr)));
+ fields1->Set("return_code", cr->GetExitStatus());
+ fields1->Set("output", CompatUtility::GetCheckResultOutput(cr));
+ fields1->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr));
+ fields1->Set("perfdata", CompatUtility::GetCheckResultPerfdata(cr));
+
+ fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
+
+ if (service) {
+ fields1->Set("service_object_id", service);
+ fields1->Set("state", service->GetState());
+ } else {
+ fields1->Set("host_object_id", host);
+ fields1->Set("state", host->GetState());
+ }
+
+ String node = IcingaApplication::GetInstance()->GetNodeName();
+
+ Endpoint::Ptr endpoint = Endpoint::GetByName(node);
+ if (endpoint)
+ fields1->Set("endpoint_object_id", endpoint);
+
+ query1.Fields = fields1;
+ DbObject::OnQuery(query1);
+}
+
+/* eventhandlers */
+void DbEvents::AddEventHandlerHistory(const Checkable::Ptr& checkable)
+{
+ Log(LogDebug, "db_ido", "add eventhandler history for '" + checkable->GetName() + "'");
+
+ double now = Utility::GetTime();
+ std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now);
+
+ DbQuery query1;
+ query1.Table = "eventhandlers";
+ query1.Type = DbQueryInsert;
+ query1.Category = DbCatEventHandler;
+
+ Dictionary::Ptr fields1 = make_shared<Dictionary>();
+
+ Host::Ptr host;
+ Service::Ptr service;
+ tie(host, service) = GetHostService(checkable);
+
+ fields1->Set("eventhandler_type", service ? 1 : 0);
+ fields1->Set("object_id", checkable);
+ fields1->Set("state", service ? service->GetState() : host->GetState());
+ fields1->Set("state_type", checkable->GetStateType());
+
+ fields1->Set("start_time", DbValue::FromTimestamp(time_bag.first));
+ fields1->Set("start_time_usec", time_bag.second);
+ fields1->Set("end_time", DbValue::FromTimestamp(time_bag.first));
+ fields1->Set("end_time_usec", time_bag.second);
+ fields1->Set("command_object_id", checkable->GetEventCommand());
+
+ fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
+
+ String node = IcingaApplication::GetInstance()->GetNodeName();
+
+ Endpoint::Ptr endpoint = Endpoint::GetByName(node);
+ if (endpoint)
+ fields1->Set("endpoint_object_id", endpoint);
+
+ query1.Fields = fields1;
+ DbObject::OnQuery(query1);
+}
+
+/* externalcommands */
+void DbEvents::AddExternalCommandHistory(double time, const String& command, const std::vector<String>& arguments)
+{
+ Log(LogDebug, "db_ido", "add external command history");
+
+ DbQuery query1;
+ query1.Table = "externalcommands";
+ query1.Type = DbQueryInsert;
+ query1.Category = DbCatExternalCommand;
+
+ Dictionary::Ptr fields1 = make_shared<Dictionary>();
+
+ fields1->Set("entry_time", DbValue::FromTimestamp(static_cast<long>(time)));
+ fields1->Set("command_type", CompatUtility::MapExternalCommandType(command));
+ fields1->Set("command_name", command);
+ fields1->Set("command_args", boost::algorithm::join(arguments, ";"));
+
+ fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
+
+ String node = IcingaApplication::GetInstance()->GetNodeName();
+
+ Endpoint::Ptr endpoint = Endpoint::GetByName(node);
+ if (endpoint)
+ fields1->Set("endpoint_object_id", endpoint);
+
+ query1.Fields = fields1;
+ DbObject::OnQuery(query1);
+}
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+#ifndef DBEVENTS_H
+#define DBEVENTS_H
+
+#include "db_ido/dbobject.h"
+#include "base/dynamicobject.h"
+#include "icinga/service.h"
+
+namespace icinga
+{
+
+enum LogEntryType
+{
+ LogEntryTypeRuntimeError = 1,
+ LogEntryTypeRuntimeWarning = 2,
+ LogEntryTypeVerificationError = 4,
+ LogEntryTypeVerificationWarning = 8,
+ LogEntryTypeConfigError = 16,
+ LogEntryTypeConfigWarning = 32,
+ LogEntryTypeProcessInfo = 64,
+ LogEntryTypeEventHandler = 128,
+ LogEntryTypeExternalCommand = 512,
+ LogEntryTypeHostUp = 1024,
+ LogEntryTypeHostDown = 2048,
+ LogEntryTypeHostUnreachable = 4096,
+ LogEntryTypeServiceOk = 8192,
+ LogEntryTypeServiceUnknown = 16384,
+ LogEntryTypeServiceWarning = 32768,
+ LogEntryTypeServiceCritical = 65536,
+ LogEntryTypePassiveCheck = 1231072,
+ LogEntryTypeInfoMessage = 262144,
+ LogEntryTypeHostNotification = 524288,
+ LogEntryTypeServiceNotification = 1048576
+};
+
+/**
+ * IDO events
+ *
+ * @ingroup ido
+ */
+class DbEvents
+{
+public:
+ static void StaticInitialize(void);
+
+ static void AddCommentByType(const DynamicObject::Ptr& object, const Comment::Ptr& comment, bool historical);
+ static void AddComments(const Checkable::Ptr& checkable);
+ static void RemoveComments(const Checkable::Ptr& checkable);
+
+ static void AddDowntimeByType(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime, bool historical);
+ static void AddDowntimes(const Checkable::Ptr& checkable);
+ static void RemoveDowntimes(const Checkable::Ptr& checkable);
+
+ static void AddLogHistory(const Checkable::Ptr& checkable, String buffer, LogEntryType type);
+
+ /* Status */
+ static void AddComment(const Checkable::Ptr& checkable, const Comment::Ptr& comment);
+ static void RemoveComment(const Checkable::Ptr& checkable, const Comment::Ptr& comment);
+
+ static void AddDowntime(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime);
+ static void RemoveDowntime(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime);
+ static void TriggerDowntime(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime);
+
+ /* comment, downtime, acknowledgement history */
+ static void AddCommentHistory(const Checkable::Ptr& checkable, const Comment::Ptr& comment);
+ static void AddDowntimeHistory(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime);
+ static void AddAcknowledgementHistory(const Checkable::Ptr& checkable, const String& author, const String& comment,
+ AcknowledgementType type, double expiry);
+
+ /* notification & contactnotification history */
+ static void AddNotificationHistory(const Notification::Ptr& notification, const Checkable::Ptr& checkable,
+ const std::set<User::Ptr>& users, NotificationType type, const CheckResult::Ptr& cr, const String& author,
+ const String& text);
+
+ /* statehistory */
+ static void AddStateChangeHistory(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type);
+
+ /* logentries */
+ static void AddCheckResultLogHistory(const Checkable::Ptr& checkable, const CheckResult::Ptr &cr);
+ static void AddTriggerDowntimeLogHistory(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime);
+ static void AddRemoveDowntimeLogHistory(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime);
+ static void AddNotificationSentLogHistory(const Notification::Ptr& notification, const Checkable::Ptr& checkable,
+ const User::Ptr& user, NotificationType notification_type, const CheckResult::Ptr& cr, const String& author,
+ const String& comment_text);
+ static void AddFlappingLogHistory(const Checkable::Ptr& checkable, FlappingState flapping_state);
+
+ /* other history */
+ static void AddFlappingHistory(const Checkable::Ptr& checkable, FlappingState flapping_state);
+ static void AddServiceCheckHistory(const Checkable::Ptr& checkable, const CheckResult::Ptr &cr);
+ static void AddEventHandlerHistory(const Checkable::Ptr& checkable);
+ static void AddExternalCommandHistory(double time, const String& command, const std::vector<String>& arguments);
+
+private:
+ DbEvents(void);
+
+ static void AddCommentInternal(const Checkable::Ptr& checkable, const Comment::Ptr& comment, bool historical);
+ static void AddDowntimeInternal(const Checkable::Ptr& checkable, const Downtime::Ptr& downtime, bool historical);
+};
+
+}
+
+#endif /* DBEVENTS_H */
Dictionary::Ptr fields = make_shared<Dictionary>();
Host::Ptr host = static_pointer_cast<Host>(GetObject());
- Service::Ptr service = host->GetCheckService();
-
fields->Set("alias", CompatUtility::GetHostAlias(host));
fields->Set("display_name", host->GetDisplayName());
fields->Set("address", CompatUtility::GetHostAddress(host));
fields->Set("address6", CompatUtility::GetHostAddress6(host));
- if (service) {
- fields->Set("check_service_object_id", service);
- fields->Set("check_command_object_id", service->GetCheckCommand());
- fields->Set("check_command_args", Empty);
- fields->Set("eventhandler_command_object_id", service->GetEventCommand());
- fields->Set("eventhandler_command_args", Empty);
- fields->Set("notification_timeperiod_object_id", Notification::GetByName(CompatUtility::GetServiceNotificationNotificationPeriod(service)));
- fields->Set("check_timeperiod_object_id", service->GetCheckPeriod());
- fields->Set("failure_prediction_options", Empty);
- fields->Set("check_interval", CompatUtility::GetServiceCheckInterval(service));
- fields->Set("retry_interval", CompatUtility::GetServiceRetryInterval(service));
- fields->Set("max_check_attempts", service->GetMaxCheckAttempts());
-
- fields->Set("first_notification_delay", Empty);
-
- fields->Set("notification_interval", CompatUtility::GetServiceNotificationNotificationInterval(service));
- /* requires host check service */
- fields->Set("notify_on_down", CompatUtility::GetHostNotifyOnDown(host));
- fields->Set("notify_on_unreachable", CompatUtility::GetHostNotifyOnDown(host));
-
- fields->Set("notify_on_recovery", CompatUtility::GetServiceNotifyOnRecovery(service));
- fields->Set("notify_on_flapping", CompatUtility::GetServiceNotifyOnFlapping(service));
- fields->Set("notify_on_downtime", CompatUtility::GetServiceNotifyOnDowntime(service));
-
- fields->Set("stalk_on_up", Empty);
- fields->Set("stalk_on_down", Empty);
- fields->Set("stalk_on_unreachable", Empty);
-
- fields->Set("flap_detection_enabled", CompatUtility::GetServiceFlapDetectionEnabled(service));
- fields->Set("flap_detection_on_up", Empty);
- fields->Set("flap_detection_on_down", Empty);
- fields->Set("flap_detection_on_unreachable", Empty);
- fields->Set("low_flap_threshold", CompatUtility::GetServiceLowFlapThreshold(service));
- fields->Set("high_flap_threshold", CompatUtility::GetServiceHighFlapThreshold(service));
- }
+ fields->Set("check_service_object_id", host);
+ fields->Set("check_command_object_id", host->GetCheckCommand());
+ fields->Set("check_command_args", Empty);
+ fields->Set("eventhandler_command_object_id", host->GetEventCommand());
+ fields->Set("eventhandler_command_args", Empty);
+ fields->Set("notification_timeperiod_object_id", Notification::GetByName(CompatUtility::GetCheckableNotificationNotificationPeriod(host)));
+ fields->Set("check_timeperiod_object_id", host->GetCheckPeriod());
+ fields->Set("failure_prediction_options", Empty);
+ fields->Set("check_interval", CompatUtility::GetCheckableCheckInterval(host));
+ fields->Set("retry_interval", CompatUtility::GetCheckableRetryInterval(host));
+ fields->Set("max_check_attempts", host->GetMaxCheckAttempts());
+
+ fields->Set("first_notification_delay", Empty);
+
+ fields->Set("notification_interval", CompatUtility::GetCheckableNotificationNotificationInterval(host));
+ fields->Set("notify_on_down", CompatUtility::GetHostNotifyOnDown(host));
+ fields->Set("notify_on_unreachable", CompatUtility::GetHostNotifyOnDown(host));
+
+ fields->Set("notify_on_recovery", CompatUtility::GetCheckableNotifyOnRecovery(host));
+ fields->Set("notify_on_flapping", CompatUtility::GetCheckableNotifyOnFlapping(host));
+ fields->Set("notify_on_downtime", CompatUtility::GetCheckableNotifyOnDowntime(host));
+
+ fields->Set("stalk_on_up", Empty);
+ fields->Set("stalk_on_down", Empty);
+ fields->Set("stalk_on_unreachable", Empty);
+
+ fields->Set("flap_detection_enabled", CompatUtility::GetCheckableFlapDetectionEnabled(host));
+ fields->Set("flap_detection_on_up", Empty);
+ fields->Set("flap_detection_on_down", Empty);
+ fields->Set("flap_detection_on_unreachable", Empty);
+ fields->Set("low_flap_threshold", CompatUtility::GetCheckableLowFlapThreshold(host));
+ fields->Set("high_flap_threshold", CompatUtility::GetCheckableHighFlapThreshold(host));
fields->Set("process_performance_data", 0);
- if (service) {
- fields->Set("freshness_checks_enabled", CompatUtility::GetServiceFreshnessChecksEnabled(service));
- fields->Set("freshness_threshold", CompatUtility::GetServiceFreshnessThreshold(service));
- fields->Set("passive_checks_enabled", CompatUtility::GetServicePassiveChecksEnabled(service));
- fields->Set("event_handler_enabled", CompatUtility::GetServiceEventHandlerEnabled(service));
- fields->Set("active_checks_enabled", CompatUtility::GetServiceActiveChecksEnabled(service));
- }
+ fields->Set("freshness_checks_enabled", CompatUtility::GetCheckableFreshnessChecksEnabled(host));
+ fields->Set("freshness_threshold", CompatUtility::GetCheckableFreshnessThreshold(host));
+ fields->Set("passive_checks_enabled", CompatUtility::GetCheckablePassiveChecksEnabled(host));
+ fields->Set("event_handler_enabled", CompatUtility::GetCheckableEventHandlerEnabled(host));
+ fields->Set("active_checks_enabled", CompatUtility::GetCheckableActiveChecksEnabled(host));
fields->Set("retain_status_information", 1);
fields->Set("retain_nonstatus_information", 1);
- if (service)
- fields->Set("notifications_enabled", CompatUtility::GetServiceNotificationsEnabled(service));
+ fields->Set("notifications_enabled", CompatUtility::GetCheckableNotificationsEnabled(host));
fields->Set("obsess_over_host", 0);
fields->Set("failure_prediction_enabled", 0);
{
Dictionary::Ptr fields = make_shared<Dictionary>();
Host::Ptr host = static_pointer_cast<Host>(GetObject());
- Service::Ptr service = host->GetCheckService();
- /* fetch service status, or dump a pending hoststatus */
- if (service) {
- CheckResult::Ptr cr = service->GetLastCheckResult();
+ CheckResult::Ptr cr = host->GetLastCheckResult();
- if (cr) {
- fields->Set("output", CompatUtility::GetCheckResultOutput(cr));
- fields->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr));
- fields->Set("perfdata", CompatUtility::GetCheckResultPerfdata(cr));
- fields->Set("check_source", cr->GetCheckSource());
- }
-
- fields->Set("current_state", host->GetState());
- fields->Set("has_been_checked", CompatUtility::GetServiceHasBeenChecked(service));
- fields->Set("should_be_scheduled", CompatUtility::GetServiceShouldBeScheduled(service));
- fields->Set("current_check_attempt", service->GetCheckAttempt());
- fields->Set("max_check_attempts", service->GetMaxCheckAttempts());
-
- if (cr)
- fields->Set("last_check", DbValue::FromTimestamp(cr->GetScheduleEnd()));
-
- fields->Set("next_check", DbValue::FromTimestamp(service->GetNextCheck()));
- fields->Set("check_type", CompatUtility::GetServiceCheckType(service));
- fields->Set("last_state_change", DbValue::FromTimestamp(service->GetLastStateChange()));
- fields->Set("last_hard_state_change", DbValue::FromTimestamp(service->GetLastHardStateChange()));
- fields->Set("last_time_up", DbValue::FromTimestamp(static_cast<int>(host->GetLastStateUp())));
- fields->Set("last_time_down", DbValue::FromTimestamp(static_cast<int>(host->GetLastStateDown())));
- fields->Set("last_time_unreachable", DbValue::FromTimestamp(static_cast<int>(host->GetLastStateUnreachable())));
- fields->Set("state_type", service->GetStateType());
- fields->Set("last_notification", DbValue::FromTimestamp(CompatUtility::GetServiceNotificationLastNotification(service)));
- fields->Set("next_notification", DbValue::FromTimestamp(CompatUtility::GetServiceNotificationNextNotification(service)));
- fields->Set("no_more_notifications", Empty);
- fields->Set("notifications_enabled", CompatUtility::GetServiceNotificationsEnabled(service));
- fields->Set("problem_has_been_acknowledged", CompatUtility::GetServiceProblemHasBeenAcknowledged(service));
- fields->Set("acknowledgement_type", CompatUtility::GetServiceAcknowledgementType(service));
- fields->Set("current_notification_number", CompatUtility::GetServiceNotificationNotificationNumber(service));
- fields->Set("passive_checks_enabled", CompatUtility::GetServicePassiveChecksEnabled(service));
- fields->Set("active_checks_enabled", CompatUtility::GetServiceActiveChecksEnabled(service));
- fields->Set("event_handler_enabled", CompatUtility::GetServiceEventHandlerEnabled(service));
- fields->Set("flap_detection_enabled", CompatUtility::GetServiceFlapDetectionEnabled(service));
- fields->Set("is_flapping", CompatUtility::GetServiceIsFlapping(service));
- fields->Set("percent_state_change", CompatUtility::GetServicePercentStateChange(service));
-
- if (cr) {
- fields->Set("latency", Convert::ToString(Service::CalculateLatency(cr)));
- fields->Set("execution_time", Convert::ToString(Service::CalculateExecutionTime(cr)));
- }
- fields->Set("scheduled_downtime_depth", service->GetDowntimeDepth());
- fields->Set("failure_prediction_enabled", Empty);
- fields->Set("process_performance_data", 0); /* this is a host which does not process any perf data */
- fields->Set("obsess_over_host", Empty);
- fields->Set("modified_host_attributes", service->GetModifiedAttributes());
- fields->Set("event_handler", CompatUtility::GetServiceEventHandler(service));
- fields->Set("check_command", CompatUtility::GetServiceCheckCommand(service));
- fields->Set("normal_check_interval", CompatUtility::GetServiceCheckInterval(service));
- fields->Set("retry_check_interval", CompatUtility::GetServiceRetryInterval(service));
- fields->Set("check_timeperiod_object_id", service->GetCheckPeriod());
+ if (cr) {
+ fields->Set("output", CompatUtility::GetCheckResultOutput(cr));
+ fields->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr));
+ fields->Set("perfdata", CompatUtility::GetCheckResultPerfdata(cr));
+ fields->Set("check_source", cr->GetCheckSource());
}
- else {
- fields->Set("has_been_checked", 0);
- fields->Set("last_check", DbValue::FromTimestamp(0));
- fields->Set("next_check", DbValue::FromTimestamp(0));
- fields->Set("active_checks_enabled", 0);
+
+ fields->Set("current_state", host->GetState());
+ fields->Set("has_been_checked", CompatUtility::GetCheckableHasBeenChecked(host));
+ fields->Set("should_be_scheduled", CompatUtility::GetCheckableShouldBeScheduled(host));
+ fields->Set("current_check_attempt", host->GetCheckAttempt());
+ fields->Set("max_check_attempts", host->GetMaxCheckAttempts());
+
+ if (cr)
+ fields->Set("last_check", DbValue::FromTimestamp(cr->GetScheduleEnd()));
+
+ fields->Set("next_check", DbValue::FromTimestamp(host->GetNextCheck()));
+ fields->Set("check_type", CompatUtility::GetCheckableCheckType(host));
+ fields->Set("last_state_change", DbValue::FromTimestamp(host->GetLastStateChange()));
+ fields->Set("last_hard_state_change", DbValue::FromTimestamp(host->GetLastHardStateChange()));
+ fields->Set("last_time_up", DbValue::FromTimestamp(static_cast<int>(host->GetLastStateUp())));
+ fields->Set("last_time_down", DbValue::FromTimestamp(static_cast<int>(host->GetLastStateDown())));
+ fields->Set("last_time_unreachable", DbValue::FromTimestamp(static_cast<int>(host->GetLastStateUnreachable())));
+ fields->Set("state_type", host->GetStateType());
+ fields->Set("last_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationLastNotification(host)));
+ fields->Set("next_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationNextNotification(host)));
+ fields->Set("no_more_notifications", Empty);
+ fields->Set("notifications_enabled", CompatUtility::GetCheckableNotificationsEnabled(host));
+ fields->Set("problem_has_been_acknowledged", CompatUtility::GetCheckableProblemHasBeenAcknowledged(host));
+ fields->Set("acknowledgement_type", CompatUtility::GetCheckableAcknowledgementType(host));
+ fields->Set("current_notification_number", CompatUtility::GetCheckableNotificationNotificationNumber(host));
+ fields->Set("passive_checks_enabled", CompatUtility::GetCheckablePassiveChecksEnabled(host));
+ fields->Set("active_checks_enabled", CompatUtility::GetCheckableActiveChecksEnabled(host));
+ fields->Set("event_handler_enabled", CompatUtility::GetCheckableEventHandlerEnabled(host));
+ fields->Set("flap_detection_enabled", CompatUtility::GetCheckableFlapDetectionEnabled(host));
+ fields->Set("is_flapping", CompatUtility::GetCheckableIsFlapping(host));
+ fields->Set("percent_state_change", CompatUtility::GetCheckablePercentStateChange(host));
+
+ if (cr) {
+ fields->Set("latency", Convert::ToString(Service::CalculateLatency(cr)));
+ fields->Set("execution_time", Convert::ToString(Service::CalculateExecutionTime(cr)));
}
+ fields->Set("scheduled_downtime_depth", host->GetDowntimeDepth());
+ fields->Set("failure_prediction_enabled", Empty);
+ fields->Set("process_performance_data", 0); /* this is a host which does not process any perf data */
+ fields->Set("obsess_over_host", Empty);
+ fields->Set("modified_host_attributes", host->GetModifiedAttributes());
+ fields->Set("event_handler", CompatUtility::GetCheckableEventHandler(host));
+ fields->Set("check_command", CompatUtility::GetCheckableCheckCommand(host));
+ fields->Set("normal_check_interval", CompatUtility::GetCheckableCheckInterval(host));
+ fields->Set("retry_check_interval", CompatUtility::GetCheckableRetryInterval(host));
+ fields->Set("check_timeperiod_object_id", host->GetCheckPeriod());
+
return fields;
}
Host::Ptr host = static_pointer_cast<Host>(GetObject());
/* parents, host dependencies */
- BOOST_FOREACH(const Host::Ptr& parent, host->GetParentHosts()) {
+ BOOST_FOREACH(const Checkable::Ptr& checkable, host->GetParents()) {
+ Host::Ptr parent = dynamic_pointer_cast<Host>(checkable);
+
+ if (!parent)
+ continue;
+
Log(LogDebug, "db_ido", "host parents: " + parent->GetName());
/* parents: host_id, parent_host_object_id */
OnQuery(query2);
}
- /* host contacts, contactgroups */
- Service::Ptr service = host->GetCheckService();
-
- if (service) {
- Log(LogDebug, "db_ido", "host contacts: " + host->GetName());
+ Log(LogDebug, "db_ido", "host contacts: " + host->GetName());
- BOOST_FOREACH(const User::Ptr& user, CompatUtility::GetServiceNotificationUsers(service)) {
- Log(LogDebug, "db_ido", "host contacts: " + user->GetName());
+ BOOST_FOREACH(const User::Ptr& user, CompatUtility::GetCheckableNotificationUsers(host)) {
+ Log(LogDebug, "db_ido", "host contacts: " + user->GetName());
- Dictionary::Ptr fields_contact = make_shared<Dictionary>();
- fields_contact->Set("host_id", DbValue::FromObjectInsertID(host));
- fields_contact->Set("contact_object_id", user);
- fields_contact->Set("instance_id", 0); /* DbConnection class fills in real ID */
+ Dictionary::Ptr fields_contact = make_shared<Dictionary>();
+ fields_contact->Set("host_id", DbValue::FromObjectInsertID(host));
+ fields_contact->Set("contact_object_id", user);
+ fields_contact->Set("instance_id", 0); /* DbConnection class fills in real ID */
- DbQuery query_contact;
- query_contact.Table = GetType()->GetTable() + "_contacts";
- query_contact.Type = DbQueryInsert;
- query_contact.Category = DbCatConfig;
- query_contact.Fields = fields_contact;
- OnQuery(query_contact);
- }
+ DbQuery query_contact;
+ query_contact.Table = GetType()->GetTable() + "_contacts";
+ query_contact.Type = DbQueryInsert;
+ query_contact.Category = DbCatConfig;
+ query_contact.Fields = fields_contact;
+ OnQuery(query_contact);
+ }
- Log(LogDebug, "db_ido", "host contactgroups: " + host->GetName());
+ Log(LogDebug, "db_ido", "host contactgroups: " + host->GetName());
- BOOST_FOREACH(const UserGroup::Ptr& usergroup, CompatUtility::GetServiceNotificationUserGroups(service)) {
- Log(LogDebug, "db_ido", "host contactgroups: " + usergroup->GetName());
+ BOOST_FOREACH(const UserGroup::Ptr& usergroup, CompatUtility::GetCheckableNotificationUserGroups(host)) {
+ Log(LogDebug, "db_ido", "host contactgroups: " + usergroup->GetName());
- Dictionary::Ptr fields_contact = make_shared<Dictionary>();
- fields_contact->Set("host_id", DbValue::FromObjectInsertID(host));
- fields_contact->Set("contactgroup_object_id", usergroup);
- fields_contact->Set("instance_id", 0); /* DbConnection class fills in real ID */
+ Dictionary::Ptr fields_contact = make_shared<Dictionary>();
+ fields_contact->Set("host_id", DbValue::FromObjectInsertID(host));
+ fields_contact->Set("contactgroup_object_id", usergroup);
+ fields_contact->Set("instance_id", 0); /* DbConnection class fills in real ID */
- DbQuery query_contact;
- query_contact.Table = GetType()->GetTable() + "_contactgroups";
- query_contact.Type = DbQueryInsert;
- query_contact.Category = DbCatConfig;
- query_contact.Fields = fields_contact;
- OnQuery(query_contact);
- }
+ DbQuery query_contact;
+ query_contact.Table = GetType()->GetTable() + "_contactgroups";
+ query_contact.Type = DbQueryInsert;
+ query_contact.Category = DbCatConfig;
+ query_contact.Fields = fields_contact;
+ OnQuery(query_contact);
}
/* custom variables */
#include "db_ido/servicedbobject.h"
#include "db_ido/dbtype.h"
#include "db_ido/dbvalue.h"
+#include "db_ido/dbevents.h"
#include "base/convert.h"
#include "base/objectlock.h"
#include "base/initialize.h"
REGISTER_DBTYPE(Service, "service", DbObjectTypeService, "service_object_id", ServiceDbObject);
-INITIALIZE_ONCE(&ServiceDbObject::StaticInitialize);
-
-void ServiceDbObject::StaticInitialize(void)
-{
- /* Status */
- Service::OnCommentAdded.connect(boost::bind(&ServiceDbObject::AddComment, _1, _2));
- Service::OnCommentRemoved.connect(boost::bind(&ServiceDbObject::RemoveComment, _1, _2));
- Service::OnDowntimeAdded.connect(boost::bind(&ServiceDbObject::AddDowntime, _1, _2));
- Service::OnDowntimeRemoved.connect(boost::bind(&ServiceDbObject::RemoveDowntime, _1, _2));
- Service::OnDowntimeTriggered.connect(boost::bind(&ServiceDbObject::TriggerDowntime, _1, _2));
-
- /* History */
- Service::OnCommentAdded.connect(boost::bind(&ServiceDbObject::AddCommentHistory, _1, _2));
- Service::OnDowntimeAdded.connect(boost::bind(&ServiceDbObject::AddDowntimeHistory, _1, _2));
- Service::OnAcknowledgementSet.connect(boost::bind(&ServiceDbObject::AddAcknowledgementHistory, _1, _2, _3, _4, _5));
-
- Service::OnNotificationSentToAllUsers.connect(bind(&ServiceDbObject::AddNotificationHistory, _1, _2, _3, _4, _5, _6, _7));
-
- Service::OnStateChange.connect(boost::bind(&ServiceDbObject::AddStateChangeHistory, _1, _2, _3));
-
- Service::OnNewCheckResult.connect(bind(&ServiceDbObject::AddCheckResultLogHistory, _1, _2));
- Service::OnNotificationSentToUser.connect(bind(&ServiceDbObject::AddNotificationSentLogHistory, _1, _2, _3, _4, _5, _6, _7));
- Service::OnFlappingChanged.connect(bind(&ServiceDbObject::AddFlappingLogHistory, _1, _2));
- Service::OnDowntimeTriggered.connect(boost::bind(&ServiceDbObject::AddTriggerDowntimeLogHistory, _1, _2));
- Service::OnDowntimeRemoved.connect(boost::bind(&ServiceDbObject::AddRemoveDowntimeLogHistory, _1, _2));
-
- Service::OnFlappingChanged.connect(bind(&ServiceDbObject::AddFlappingHistory, _1, _2));
- Service::OnNewCheckResult.connect(bind(&ServiceDbObject::AddServiceCheckHistory, _1, _2));
-
- Service::OnEventCommandExecuted.connect(bind(&ServiceDbObject::AddEventHandlerHistory, _1));
-
- ExternalCommandProcessor::OnNewExternalCommand.connect(boost::bind(&ServiceDbObject::AddExternalCommandHistory, _1, _2, _3));
-}
-
ServiceDbObject::ServiceDbObject(const DbType::Ptr& type, const String& name1, const String& name2)
: DbObject(type, name1, name2)
{ }
fields->Set("check_command_args", Empty);
fields->Set("eventhandler_command_object_id", service->GetEventCommand());
fields->Set("eventhandler_command_args", Empty);
- fields->Set("notification_timeperiod_object_id", Notification::GetByName(CompatUtility::GetServiceNotificationNotificationPeriod(service)));
+ fields->Set("notification_timeperiod_object_id", Notification::GetByName(CompatUtility::GetCheckableNotificationNotificationPeriod(service)));
fields->Set("check_timeperiod_object_id", service->GetCheckPeriod());
fields->Set("failure_prediction_options", Empty);
- fields->Set("check_interval", CompatUtility::GetServiceCheckInterval(service));
- fields->Set("retry_interval", CompatUtility::GetServiceRetryInterval(service));
+ fields->Set("check_interval", CompatUtility::GetCheckableCheckInterval(service));
+ fields->Set("retry_interval", CompatUtility::GetCheckableRetryInterval(service));
fields->Set("max_check_attempts", service->GetMaxCheckAttempts());
fields->Set("first_notification_delay", Empty);
- fields->Set("notification_interval", CompatUtility::GetServiceNotificationNotificationInterval(service));
- fields->Set("notify_on_warning", CompatUtility::GetServiceNotifyOnWarning(service));
- fields->Set("notify_on_unknown", CompatUtility::GetServiceNotifyOnUnknown(service));
- fields->Set("notify_on_critical", CompatUtility::GetServiceNotifyOnCritical(service));
- fields->Set("notify_on_recovery", CompatUtility::GetServiceNotifyOnRecovery(service));
- fields->Set("notify_on_flapping", CompatUtility::GetServiceNotifyOnFlapping(service));
- fields->Set("notify_on_downtime", CompatUtility::GetServiceNotifyOnDowntime(service));
+ fields->Set("notification_interval", CompatUtility::GetCheckableNotificationNotificationInterval(service));
+ fields->Set("notify_on_warning", CompatUtility::GetCheckableNotifyOnWarning(service));
+ fields->Set("notify_on_unknown", CompatUtility::GetCheckableNotifyOnUnknown(service));
+ fields->Set("notify_on_critical", CompatUtility::GetCheckableNotifyOnCritical(service));
+ fields->Set("notify_on_recovery", CompatUtility::GetCheckableNotifyOnRecovery(service));
+ fields->Set("notify_on_flapping", CompatUtility::GetCheckableNotifyOnFlapping(service));
+ fields->Set("notify_on_downtime", CompatUtility::GetCheckableNotifyOnDowntime(service));
fields->Set("stalk_on_ok", 0);
fields->Set("stalk_on_warning", 0);
fields->Set("stalk_on_unknown", 0);
fields->Set("stalk_on_critical", 0);
- fields->Set("is_volatile", CompatUtility::GetServiceIsVolatile(service));
- fields->Set("flap_detection_enabled", CompatUtility::GetServiceFlapDetectionEnabled(service));
+ fields->Set("is_volatile", CompatUtility::GetCheckableIsVolatile(service));
+ fields->Set("flap_detection_enabled", CompatUtility::GetCheckableFlapDetectionEnabled(service));
fields->Set("flap_detection_on_ok", Empty);
fields->Set("flap_detection_on_warning", Empty);
fields->Set("flap_detection_on_unknown", Empty);
fields->Set("flap_detection_on_critical", Empty);
- fields->Set("low_flap_threshold", CompatUtility::GetServiceLowFlapThreshold(service));
- fields->Set("high_flap_threshold", CompatUtility::GetServiceHighFlapThreshold(service));
- fields->Set("process_performance_data", CompatUtility::GetServiceProcessPerformanceData(service));
- fields->Set("freshness_checks_enabled", CompatUtility::GetServiceFreshnessChecksEnabled(service));
- fields->Set("freshness_threshold", CompatUtility::GetServiceFreshnessThreshold(service));
- fields->Set("passive_checks_enabled", CompatUtility::GetServicePassiveChecksEnabled(service));
- fields->Set("event_handler_enabled", CompatUtility::GetServiceEventHandlerEnabled(service));
- fields->Set("active_checks_enabled", CompatUtility::GetServiceActiveChecksEnabled(service));
+ fields->Set("low_flap_threshold", CompatUtility::GetCheckableLowFlapThreshold(service));
+ fields->Set("high_flap_threshold", CompatUtility::GetCheckableHighFlapThreshold(service));
+ fields->Set("process_performance_data", CompatUtility::GetCheckableProcessPerformanceData(service));
+ fields->Set("freshness_checks_enabled", CompatUtility::GetCheckableFreshnessChecksEnabled(service));
+ fields->Set("freshness_threshold", CompatUtility::GetCheckableFreshnessThreshold(service));
+ fields->Set("passive_checks_enabled", CompatUtility::GetCheckablePassiveChecksEnabled(service));
+ fields->Set("event_handler_enabled", CompatUtility::GetCheckableEventHandlerEnabled(service));
+ fields->Set("active_checks_enabled", CompatUtility::GetCheckableActiveChecksEnabled(service));
fields->Set("retain_status_information", Empty);
fields->Set("retain_nonstatus_information", Empty);
- fields->Set("notifications_enabled", CompatUtility::GetServiceNotificationsEnabled(service));
+ fields->Set("notifications_enabled", CompatUtility::GetCheckableNotificationsEnabled(service));
fields->Set("obsess_over_service", Empty);
fields->Set("failure_prediction_enabled", Empty);
fields->Set("notes", CompatUtility::GetCustomAttributeConfig(service, "notes"));
fields->Set("check_source", cr->GetCheckSource());
}
- fields->Set("current_state", CompatUtility::GetServiceCurrentState(service));
- fields->Set("has_been_checked", CompatUtility::GetServiceHasBeenChecked(service));
- fields->Set("should_be_scheduled", CompatUtility::GetServiceShouldBeScheduled(service));
+ fields->Set("current_state", service->GetState());
+ fields->Set("has_been_checked", CompatUtility::GetCheckableHasBeenChecked(service));
+ fields->Set("should_be_scheduled", CompatUtility::GetCheckableShouldBeScheduled(service));
fields->Set("current_check_attempt", service->GetCheckAttempt());
fields->Set("max_check_attempts", service->GetMaxCheckAttempts());
fields->Set("last_check", DbValue::FromTimestamp(cr->GetScheduleEnd()));
fields->Set("next_check", DbValue::FromTimestamp(service->GetNextCheck()));
- fields->Set("check_type", CompatUtility::GetServiceCheckType(service));
+ fields->Set("check_type", CompatUtility::GetCheckableCheckType(service));
fields->Set("last_state_change", DbValue::FromTimestamp(service->GetLastStateChange()));
fields->Set("last_hard_state_change", DbValue::FromTimestamp(service->GetLastHardStateChange()));
fields->Set("last_time_ok", DbValue::FromTimestamp(static_cast<int>(service->GetLastStateOK())));
fields->Set("last_time_critical", DbValue::FromTimestamp(static_cast<int>(service->GetLastStateCritical())));
fields->Set("last_time_unknown", DbValue::FromTimestamp(static_cast<int>(service->GetLastStateUnknown())));
fields->Set("state_type", service->GetStateType());
- fields->Set("last_notification", DbValue::FromTimestamp(CompatUtility::GetServiceNotificationLastNotification(service)));
- fields->Set("next_notification", DbValue::FromTimestamp(CompatUtility::GetServiceNotificationNextNotification(service)));
+ fields->Set("last_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationLastNotification(service)));
+ fields->Set("next_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationNextNotification(service)));
fields->Set("no_more_notifications", Empty);
- fields->Set("notifications_enabled", CompatUtility::GetServiceNotificationsEnabled(service));
- fields->Set("problem_has_been_acknowledged", CompatUtility::GetServiceProblemHasBeenAcknowledged(service));
- fields->Set("acknowledgement_type", CompatUtility::GetServiceAcknowledgementType(service));
- fields->Set("current_notification_number", CompatUtility::GetServiceNotificationNotificationNumber(service));
- fields->Set("passive_checks_enabled", CompatUtility::GetServicePassiveChecksEnabled(service));
- fields->Set("active_checks_enabled", CompatUtility::GetServiceActiveChecksEnabled(service));
- fields->Set("event_handler_enabled", CompatUtility::GetServiceEventHandlerEnabled(service));
- fields->Set("flap_detection_enabled", CompatUtility::GetServiceFlapDetectionEnabled(service));
- fields->Set("is_flapping", CompatUtility::GetServiceIsFlapping(service));
- fields->Set("percent_state_change", CompatUtility::GetServicePercentStateChange(service));
+ fields->Set("notifications_enabled", CompatUtility::GetCheckableNotificationsEnabled(service));
+ fields->Set("problem_has_been_acknowledged", CompatUtility::GetCheckableProblemHasBeenAcknowledged(service));
+ fields->Set("acknowledgement_type", CompatUtility::GetCheckableAcknowledgementType(service));
+ fields->Set("current_notification_number", CompatUtility::GetCheckableNotificationNotificationNumber(service));
+ fields->Set("passive_checks_enabled", CompatUtility::GetCheckablePassiveChecksEnabled(service));
+ fields->Set("active_checks_enabled", CompatUtility::GetCheckableActiveChecksEnabled(service));
+ fields->Set("event_handler_enabled", CompatUtility::GetCheckableEventHandlerEnabled(service));
+ fields->Set("flap_detection_enabled", CompatUtility::GetCheckableFlapDetectionEnabled(service));
+ fields->Set("is_flapping", CompatUtility::GetCheckableIsFlapping(service));
+ fields->Set("percent_state_change", CompatUtility::GetCheckablePercentStateChange(service));
if (cr) {
fields->Set("latency", Convert::ToString(Service::CalculateLatency(cr)));
}
fields->Set("scheduled_downtime_depth", service->GetDowntimeDepth());
- fields->Set("process_performance_data", CompatUtility::GetServiceProcessPerformanceData(service));
- fields->Set("event_handler", CompatUtility::GetServiceEventHandler(service));
- fields->Set("check_command", CompatUtility::GetServiceCheckCommand(service));
- fields->Set("normal_check_interval", CompatUtility::GetServiceCheckInterval(service));
- fields->Set("retry_check_interval", CompatUtility::GetServiceRetryInterval(service));
+ fields->Set("process_performance_data", CompatUtility::GetCheckableProcessPerformanceData(service));
+ fields->Set("event_handler", CompatUtility::GetCheckableEventHandler(service));
+ fields->Set("check_command", CompatUtility::GetCheckableCheckCommand(service));
+ fields->Set("normal_check_interval", CompatUtility::GetCheckableCheckInterval(service));
+ fields->Set("retry_check_interval", CompatUtility::GetCheckableRetryInterval(service));
fields->Set("check_timeperiod_object_id", service->GetCheckPeriod());
fields->Set("modified_service_attributes", service->GetModifiedAttributes());
/* service dependencies */
Log(LogDebug, "db_ido", "service dependencies for '" + service->GetName() + "'");
- BOOST_FOREACH(const Service::Ptr& parent, service->GetParentServices()) {
+ BOOST_FOREACH(const Checkable::Ptr& checkable, service->GetParents()) {
+ Service::Ptr parent = dynamic_pointer_cast<Service>(checkable);
+
+ if (!parent)
+ continue;
+
Log(LogDebug, "db_ido", "service parents: " + parent->GetName());
/* service dependencies */
/* service contacts, contactgroups */
Log(LogDebug, "db_ido", "service contacts: " + service->GetName());
- BOOST_FOREACH(const User::Ptr& user, CompatUtility::GetServiceNotificationUsers(service)) {
+ BOOST_FOREACH(const User::Ptr& user, CompatUtility::GetCheckableNotificationUsers(service)) {
Log(LogDebug, "db_ido", "service contacts: " + user->GetName());
Dictionary::Ptr fields_contact = make_shared<Dictionary>();
Log(LogDebug, "db_ido", "service contactgroups: " + service->GetName());
- BOOST_FOREACH(const UserGroup::Ptr& usergroup, CompatUtility::GetServiceNotificationUserGroups(service)) {
+ BOOST_FOREACH(const UserGroup::Ptr& usergroup, CompatUtility::GetCheckableNotificationUserGroups(service)) {
Log(LogDebug, "db_ido", "service contactgroups: " + usergroup->GetName());
Dictionary::Ptr fields_contact = make_shared<Dictionary>();
}
/* update comments and downtimes on config change */
- AddComments(service);
- AddDowntimes(service);
+ DbEvents::AddComments(service);
+ DbEvents::AddDowntimes(service);
}
void ServiceDbObject::OnStatusUpdate(void)
{
- Service::Ptr service = static_pointer_cast<Service>(GetObject());
- Host::Ptr host = service->GetHost();
-
- /* update the host if hostcheck service */
- if (host->GetCheckService() != service)
- return;
-
- DbObject::Ptr dbobj = GetOrCreateByObject(host);
-
- if (!dbobj)
- return;
-
- dbobj->SendStatusUpdate();
-}
-
-/* comments */
-void ServiceDbObject::AddComments(const Service::Ptr& service)
-{
- /* dump all comments */
- Dictionary::Ptr comments = service->GetComments();
-
- if (comments->GetLength() > 0)
- RemoveComments(service);
-
- ObjectLock olock(comments);
-
- BOOST_FOREACH(const Dictionary::Pair& kv, comments) {
- AddComment(service, kv.second);
- }
-}
-
-void ServiceDbObject::AddComment(const Service::Ptr& service, const Comment::Ptr& comment)
-{
- AddCommentInternal(service, comment, false);
-}
-
-void ServiceDbObject::AddCommentHistory(const Service::Ptr& service, const Comment::Ptr& comment)
-{
- AddCommentInternal(service, comment, true);
-}
-
-void ServiceDbObject::AddCommentInternal(const Service::Ptr& service, const Comment::Ptr& comment, bool historical)
-{
- Host::Ptr host = service->GetHost();
-
- if (!comment) {
- Log(LogWarning, "db_ido", "comment does not exist. not adding it.");
- return;
- }
-
- Log(LogDebug, "db_ido", "adding service comment (id = " + Convert::ToString(comment->GetLegacyId()) + ") for '" + service->GetName() + "'");
-
- /* add the service comment */
- AddCommentByType(service, comment, historical);
-
- /* add the hostcheck service comment to the host as well */
- if (host->GetCheckService() == service) {
- Log(LogDebug, "db_ido", "adding host comment (id = " + Convert::ToString(comment->GetLegacyId()) + ") for '" + host->GetName() + "'");
- AddCommentByType(host, comment, historical);
- }
-}
-
-void ServiceDbObject::AddCommentByType(const DynamicObject::Ptr& object, const Comment::Ptr& comment, bool historical)
-{
- unsigned long entry_time = static_cast<long>(comment->GetEntryTime());
- unsigned long entry_time_usec = (comment->GetEntryTime() - entry_time) * 1000 * 1000;
-
- Dictionary::Ptr fields1 = make_shared<Dictionary>();
- fields1->Set("entry_time", DbValue::FromTimestamp(entry_time));
- fields1->Set("entry_time_usec", entry_time_usec);
- fields1->Set("entry_type", comment->GetEntryType());
- fields1->Set("object_id", object);
-
- if (object->GetType() == DynamicType::GetByName("Host")) {
- fields1->Set("comment_type", 2);
- /* requires idoutils 1.10 schema fix */
- fields1->Set("internal_comment_id", comment->GetLegacyId());
- } else if (object->GetType() == DynamicType::GetByName("Service")) {
- fields1->Set("comment_type", 1);
- fields1->Set("internal_comment_id", comment->GetLegacyId());
- } else {
- Log(LogDebug, "db_ido", "unknown object type for adding comment.");
- return;
- }
-
- fields1->Set("comment_time", DbValue::FromTimestamp(entry_time)); /* same as entry_time */
- fields1->Set("author_name", comment->GetAuthor());
- fields1->Set("comment_data", comment->GetText());
- fields1->Set("is_persistent", 1);
- fields1->Set("comment_source", 1); /* external */
- fields1->Set("expires", (comment->GetExpireTime() > 0) ? 1 : 0);
- fields1->Set("expiration_time", DbValue::FromTimestamp(comment->GetExpireTime()));
- fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
- String node = IcingaApplication::GetInstance()->GetNodeName();
-
- Endpoint::Ptr endpoint = Endpoint::GetByName(node);
- if (endpoint)
- fields1->Set("endpoint_object_id", endpoint);
-
- DbQuery query1;
- if (!historical) {
- query1.Table = "comments";
- } else {
- query1.Table = "commenthistory";
- }
- query1.Type = DbQueryInsert;
- query1.Category = DbCatComment;
- query1.Fields = fields1;
- OnQuery(query1);
-}
-
-void ServiceDbObject::RemoveComments(const Service::Ptr& service)
-{
- Host::Ptr host = service->GetHost();
-
- Log(LogDebug, "db_ido", "removing service comments for '" + service->GetName() + "'");
-
- DbQuery query1;
- query1.Table = "comments";
- query1.Type = DbQueryDelete;
- query1.Category = DbCatComment;
- query1.WhereCriteria = make_shared<Dictionary>();
- query1.WhereCriteria->Set("object_id", service);
- OnQuery(query1);
-
- /* delete hostcheck service's host comments */
- if (host->GetCheckService() == service) {
- query1.WhereCriteria = query1.WhereCriteria->ShallowClone();
- query1.WhereCriteria->Set("object_id", host);
- OnQuery(query1);
- }
-}
-
-void ServiceDbObject::RemoveComment(const Service::Ptr& service, const Comment::Ptr& comment)
-{
- Host::Ptr host = service->GetHost();
-
- if (!comment) {
- Log(LogWarning, "db_ido", "comment does not exist. not deleting it.");
- return;
- }
-
- Log(LogDebug, "db_ido", "removing service comment (id = " + Convert::ToString(comment->GetLegacyId()) + ") for '" + service->GetName() + "'");
-
- /* Status */
- DbQuery query1;
- query1.Table = "comments";
- query1.Type = DbQueryDelete;
- query1.Category = DbCatComment;
- query1.WhereCriteria = make_shared<Dictionary>();
- query1.WhereCriteria->Set("object_id", service);
- query1.WhereCriteria->Set("internal_comment_id", comment->GetLegacyId());
- OnQuery(query1);
-
- /* delete hostcheck service's host comments */
- if (host->GetCheckService() == service) {
- query1.WhereCriteria = query1.WhereCriteria->ShallowClone();
- query1.WhereCriteria->Set("object_id", host);
- OnQuery(query1);
- }
-
- /* History - update deletion time for service (and host in case) */
- unsigned long entry_time = static_cast<long>(comment->GetEntryTime());
-
- double now = Utility::GetTime();
- std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now);
-
- DbQuery query2;
- query2.Table = "commenthistory";
- query2.Type = DbQueryUpdate;
- query2.Category = DbCatComment;
-
- Dictionary::Ptr fields2 = make_shared<Dictionary>();
- fields2->Set("deletion_time", DbValue::FromTimestamp(time_bag.first));
- fields2->Set("deletion_time_usec", time_bag.second);
- query2.Fields = fields2;
-
- query2.WhereCriteria = make_shared<Dictionary>();
- query2.WhereCriteria->Set("internal_comment_id", comment->GetLegacyId());
- query2.WhereCriteria->Set("comment_time", DbValue::FromTimestamp(entry_time));
- query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
- OnQuery(query2);
-}
-
-/* downtimes */
-void ServiceDbObject::AddDowntimes(const Service::Ptr& service)
-{
- /* dump all downtimes */
- Dictionary::Ptr downtimes = service->GetDowntimes();
-
- if (downtimes->GetLength() > 0)
- RemoveDowntimes(service);
-
- ObjectLock olock(downtimes);
-
- BOOST_FOREACH(const Dictionary::Pair& kv, downtimes) {
- AddDowntime(service, kv.second);
- }
-}
-
-void ServiceDbObject::AddDowntime(const Service::Ptr& service, const Downtime::Ptr& downtime)
-{
- AddDowntimeInternal(service, downtime, false);
-}
-
-void ServiceDbObject::AddDowntimeHistory(const Service::Ptr& service, const Downtime::Ptr& downtime)
-{
- AddDowntimeInternal(service, downtime, true);
-}
-
-void ServiceDbObject::AddDowntimeInternal(const Service::Ptr& service, const Downtime::Ptr& downtime, bool historical)
-{
- Host::Ptr host = service->GetHost();
-
- if (!downtime) {
- Log(LogWarning, "db_ido", "downtime does not exist. not adding it.");
- return;
- }
-
- Log(LogDebug, "db_ido", "adding service downtime (id = " + Convert::ToString(downtime->GetLegacyId()) + ") for '" + service->GetName() + "'");
-
- /* add the service downtime */
- AddDowntimeByType(service, downtime, historical);
-
- /* add the hostcheck service downtime to the host as well */
- if (host->GetCheckService() == service) {
- Log(LogDebug, "db_ido", "adding host downtime (id = " + Convert::ToString(downtime->GetLegacyId()) + ") for '" + host->GetName() + "'");
- AddDowntimeByType(host, downtime, historical);
- }
-}
-
-void ServiceDbObject::AddDowntimeByType(const DynamicObject::Ptr& object, const Downtime::Ptr& downtime, bool historical)
-{
- Dictionary::Ptr fields1 = make_shared<Dictionary>();
- fields1->Set("entry_time", DbValue::FromTimestamp(downtime->GetEntryTime()));
- fields1->Set("object_id", object);
-
- if (object->GetType() == DynamicType::GetByName("Host")) {
- fields1->Set("downtime_type", 2);
- /* requires idoutils 1.10 schema fix */
- fields1->Set("internal_downtime_id", downtime->GetLegacyId());
- } else if (object->GetType() == DynamicType::GetByName("Service")) {
- fields1->Set("downtime_type", 1);
- fields1->Set("internal_downtime_id", downtime->GetLegacyId());
- } else {
- Log(LogDebug, "db_ido", "unknown object type for adding downtime.");
- return;
- }
-
- fields1->Set("author_name", downtime->GetAuthor());
- fields1->Set("comment_data", downtime->GetComment());
- fields1->Set("triggered_by_id", Service::GetDowntimeByID(downtime->GetTriggeredBy()));
- fields1->Set("is_fixed", downtime->GetFixed());
- fields1->Set("duration", downtime->GetDuration());
- fields1->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime()));
- fields1->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime()));
- fields1->Set("was_started", Empty);
- fields1->Set("actual_start_time", Empty);
- fields1->Set("actual_start_time_usec", Empty);
- fields1->Set("is_in_effect", Empty);
- fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime()));
- fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
- String node = IcingaApplication::GetInstance()->GetNodeName();
-
- Endpoint::Ptr endpoint = Endpoint::GetByName(node);
- if (endpoint)
- fields1->Set("endpoint_object_id", endpoint);
-
- DbQuery query1;
- if (!historical) {
- query1.Table = "scheduleddowntime";
- } else {
- query1.Table = "downtimehistory";
- }
- query1.Type = DbQueryInsert;
- query1.Category = DbCatDowntime;
- query1.Fields = fields1;
- OnQuery(query1);
-}
-
-void ServiceDbObject::RemoveDowntimes(const Service::Ptr& service)
-{
- Host::Ptr host = service->GetHost();
-
- Log(LogDebug, "db_ido", "removing service downtimes for '" + service->GetName() + "'");
-
- DbQuery query1;
- query1.Table = "scheduleddowntime";
- query1.Type = DbQueryDelete;
- query1.Category = DbCatDowntime;
- query1.WhereCriteria = make_shared<Dictionary>();
- query1.WhereCriteria->Set("object_id", service);
- OnQuery(query1);
-
- /* delete hostcheck service's host downtimes */
- if (host->GetCheckService() == service) {
- query1.WhereCriteria = query1.WhereCriteria->ShallowClone();
- query1.WhereCriteria->Set("object_id", host);
- OnQuery(query1);
- }
-}
-
-void ServiceDbObject::RemoveDowntime(const Service::Ptr& service, const Downtime::Ptr& downtime)
-{
- Host::Ptr host = service->GetHost();
-
- if (!downtime) {
- Log(LogWarning, "db_ido", "downtime does not exist. not adding it.");
- return;
- }
-
- Log(LogDebug, "db_ido", "removing service downtime (id = " + Convert::ToString(downtime->GetLegacyId()) + ") for '" + service->GetName() + "'");
-
- /* Status */
- DbQuery query1;
- query1.Table = "scheduleddowntime";
- query1.Type = DbQueryDelete;
- query1.Category = DbCatDowntime;
- query1.WhereCriteria = make_shared<Dictionary>();
- query1.WhereCriteria->Set("object_id", service);
- query1.WhereCriteria->Set("internal_downtime_id", downtime->GetLegacyId());
- OnQuery(query1);
-
- /* delete hostcheck service's host comments */
- if (host->GetCheckService() == service) {
- query1.WhereCriteria = query1.WhereCriteria->ShallowClone();
- query1.WhereCriteria->Set("object_id", host);
- OnQuery(query1);
- }
-
- /* History - update actual_end_time, was_cancelled for service (and host in case) */
- double now = Utility::GetTime();
- std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now);
-
- DbQuery query3;
- query3.Table = "downtimehistory";
- query3.Type = DbQueryUpdate;
- query3.Category = DbCatDowntime;
-
- Dictionary::Ptr fields3 = make_shared<Dictionary>();
- fields3->Set("was_cancelled", downtime->GetWasCancelled() ? 1 : 0);
- fields3->Set("actual_end_time", DbValue::FromTimestamp(time_bag.first));
- fields3->Set("actual_end_time_usec", time_bag.second);
- query3.Fields = fields3;
-
- query3.WhereCriteria = make_shared<Dictionary>();
- query3.WhereCriteria->Set("internal_downtime_id", downtime->GetLegacyId());
- query3.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(downtime->GetEntryTime()));
- query3.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime()));
- query3.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime()));
- query3.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
- OnQuery(query3);
-}
-
-void ServiceDbObject::TriggerDowntime(const Service::Ptr& service, const Downtime::Ptr& downtime)
-{
- Host::Ptr host = service->GetHost();
-
- if (!downtime) {
- Log(LogWarning, "db_ido", "downtime does not exist. not updating it.");
- return;
- }
-
- Log(LogDebug, "db_ido", "updating triggered service downtime (id = " + Convert::ToString(downtime->GetLegacyId()) + ") for '" + service->GetName() + "'");
-
- double now = Utility::GetTime();
- std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now);
-
- /* Status */
- DbQuery query1;
- query1.Table = "scheduleddowntime";
- query1.Type = DbQueryUpdate;
- query1.Category = DbCatDowntime;
-
- Dictionary::Ptr fields1 = make_shared<Dictionary>();
- fields1->Set("was_started", 1);
- fields1->Set("actual_start_time", DbValue::FromTimestamp(time_bag.first));
- fields1->Set("actual_start_time_usec", time_bag.second);
- fields1->Set("is_in_effect", 1);
- fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime()));
- fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
- query1.WhereCriteria = make_shared<Dictionary>();
- query1.WhereCriteria->Set("object_id", service);
- query1.WhereCriteria->Set("internal_downtime_id", downtime->GetLegacyId());
-
- query1.Fields = fields1;
- OnQuery(query1);
-
- /* delete hostcheck service's host comments */
- if (host->GetCheckService() == service) {
- query1.WhereCriteria = query1.WhereCriteria->ShallowClone();
- query1.WhereCriteria->Set("object_id", host);
- OnQuery(query1);
- }
-
- /* History - downtime was started for service (and host in case) */
- DbQuery query3;
- query3.Table = "downtimehistory";
- query3.Type = DbQueryUpdate;
- query3.Category = DbCatDowntime;
-
- Dictionary::Ptr fields3 = make_shared<Dictionary>();
- fields3->Set("was_started", 1);
- fields3->Set("is_in_effect", 1);
- fields3->Set("actual_start_time", DbValue::FromTimestamp(time_bag.first));
- fields3->Set("actual_start_time_usec", time_bag.second);
- fields3->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime()));
- query3.Fields = fields3;
-
- query3.WhereCriteria = make_shared<Dictionary>();
- query3.WhereCriteria->Set("internal_downtime_id", downtime->GetLegacyId());
- query3.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(downtime->GetEntryTime()));
- query3.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime()));
- query3.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime()));
- query3.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
- OnQuery(query3);
-}
-
-/* acknowledgements */
-void ServiceDbObject::AddAcknowledgementHistory(const Service::Ptr& service, const String& author, const String& comment,
- AcknowledgementType type, double expiry)
-{
- Host::Ptr host = service->GetHost();
-
- Log(LogDebug, "db_ido", "add acknowledgement history for '" + service->GetName() + "'");
-
- double now = Utility::GetTime();
- std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now);
-
- unsigned long end_time = static_cast<long>(expiry);
-
- DbQuery query1;
- query1.Table = "acknowledgements";
- query1.Type = DbQueryInsert;
- query1.Category = DbCatAcknowledgement;
-
- Dictionary::Ptr fields1 = make_shared<Dictionary>();
- fields1->Set("entry_time", DbValue::FromTimestamp(time_bag.first));
- fields1->Set("entry_time_usec", time_bag.second);
- fields1->Set("acknowledgement_type", type);
- fields1->Set("object_id", service);
- fields1->Set("state", CompatUtility::GetServiceCurrentState(service));
- fields1->Set("author_name", author);
- fields1->Set("comment_data", comment);
- fields1->Set("is_sticky", type == AcknowledgementSticky ? 1 : 0);
- fields1->Set("end_time", DbValue::FromTimestamp(end_time));
- fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
- String node = IcingaApplication::GetInstance()->GetNodeName();
-
- Endpoint::Ptr endpoint = Endpoint::GetByName(node);
- if (endpoint)
- fields1->Set("endpoint_object_id", endpoint);
-
- query1.Fields = fields1;
- OnQuery(query1);
-
- if (host->GetCheckService() == service) {
- fields1 = fields1->ShallowClone();
- fields1->Set("object_id", host);
- fields1->Set("state", host->GetState());
- query1.Fields = fields1;
- OnQuery(query1);
- }
-}
-
-/* notifications */
-void ServiceDbObject::AddNotificationHistory(const Notification::Ptr& notification, const Service::Ptr& service, const std::set<User::Ptr>& users, NotificationType type,
- const CheckResult::Ptr& cr, const String& author, const String& text)
-{
- Host::Ptr host = service->GetHost();
-
- Log(LogDebug, "db_ido", "add notification history for '" + service->GetName() + "'");
-
- /* start and end happen at the same time */
- double now = Utility::GetTime();
- std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now);
-
- DbQuery query1;
- query1.Table = "notifications";
- query1.Type = DbQueryInsert;
- query1.Category = DbCatNotification;
- /* store the object ptr for caching the insert id for this object */
- query1.NotificationObject = notification;
-
- Dictionary::Ptr fields1 = make_shared<Dictionary>();
- fields1->Set("notification_type", 1); /* service */
- fields1->Set("notification_reason", CompatUtility::MapNotificationReasonType(type));
- fields1->Set("object_id", service);
- fields1->Set("start_time", DbValue::FromTimestamp(time_bag.first));
- fields1->Set("start_time_usec", time_bag.second);
- fields1->Set("end_time", DbValue::FromTimestamp(time_bag.first));
- fields1->Set("end_time_usec", time_bag.second);
- fields1->Set("state", CompatUtility::GetServiceCurrentState(service));
-
- if (cr) {
- fields1->Set("output", CompatUtility::GetCheckResultOutput(cr));
- fields1->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr));
- }
-
- fields1->Set("escalated", 0);
- fields1->Set("contacts_notified", static_cast<long>(users.size()));
- fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
- String node = IcingaApplication::GetInstance()->GetNodeName();
-
- Endpoint::Ptr endpoint = Endpoint::GetByName(node);
- if (endpoint)
- fields1->Set("endpoint_object_id", endpoint);
-
- query1.Fields = fields1;
- OnQuery(query1);
-
- if (host->GetCheckService() == service) {
- fields1 = fields1->ShallowClone();
- fields1->Set("notification_type", 2); /* host */
- fields1->Set("object_id", host);
- fields1->Set("state", host->GetState());
- query1.Fields = fields1;
- OnQuery(query1);
- }
-
- DbQuery query2;
- query2.Table = "contactnotifications";
- query2.Type = DbQueryInsert;
- query2.Category = DbCatNotification;
-
- /* filtered users */
- BOOST_FOREACH(const User::Ptr& user, users) {
- Log(LogDebug, "db_ido", "add contact notification history for service '" + service->GetName() + "' and user '" + user->GetName() + "'.");
-
- Dictionary::Ptr fields2 = make_shared<Dictionary>();
- fields2->Set("contact_object_id", user);
- fields2->Set("start_time", DbValue::FromTimestamp(time_bag.first));
- fields2->Set("start_time_usec", time_bag.second);
- fields2->Set("end_time", DbValue::FromTimestamp(time_bag.first));
- fields2->Set("end_time_usec", time_bag.second);
-
- fields2->Set("notification_id", notification); /* DbConnection class fills in real ID from notification insert id cache */
- fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
- query2.Fields = fields2;
- OnQuery(query2);
- }
-}
-
-/* statehistory */
-void ServiceDbObject::AddStateChangeHistory(const Service::Ptr& service, const CheckResult::Ptr& cr, StateType type)
-{
- Host::Ptr host = service->GetHost();
-
- Log(LogDebug, "db_ido", "add state change history for '" + service->GetName() + "'");
-
- double now = Utility::GetTime();
- std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now);
-
- DbQuery query1;
- query1.Table = "statehistory";
- query1.Type = DbQueryInsert;
- query1.Category = DbCatStateHistory;
-
- Dictionary::Ptr fields1 = make_shared<Dictionary>();
- fields1->Set("state_time", DbValue::FromTimestamp(time_bag.first));
- fields1->Set("state_time_usec", time_bag.second);
- fields1->Set("object_id", service);
- fields1->Set("state_change", 1); /* service */
- fields1->Set("state", CompatUtility::GetServiceCurrentState(service));
- fields1->Set("state_type", service->GetStateType());
- fields1->Set("current_check_attempt", service->GetCheckAttempt());
- fields1->Set("max_check_attempts", service->GetMaxCheckAttempts());
- fields1->Set("last_state", service->GetLastState());
- fields1->Set("last_hard_state", service->GetLastHardState());
-
- if (cr) {
- fields1->Set("output", CompatUtility::GetCheckResultOutput(cr));
- fields1->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr));
- fields1->Set("check_source", cr->GetCheckSource());
- }
-
- fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
- String node = IcingaApplication::GetInstance()->GetNodeName();
-
- Endpoint::Ptr endpoint = Endpoint::GetByName(node);
- if (endpoint)
- fields1->Set("endpoint_object_id", endpoint);
-
- query1.Fields = fields1;
- OnQuery(query1);
-
- if (host->GetCheckService() == service) {
- fields1 = fields1->ShallowClone();
- fields1->Set("object_id", host);
- fields1->Set("state_change", 0); /* host */
- /* get host states instead */
- fields1->Set("state", host->GetState());
- fields1->Set("state_type", host->GetStateType());
- fields1->Set("last_state", host->GetLastState());
- fields1->Set("last_hard_state", host->GetLastHardState());
- query1.Fields = fields1;
- OnQuery(query1);
- }
-}
-
-/* logentries */
-void ServiceDbObject::AddCheckResultLogHistory(const Service::Ptr& service, const CheckResult::Ptr &cr)
-{
- Host::Ptr host = service->GetHost();
-
- Dictionary::Ptr vars_after = cr->GetVarsAfter();
-
- long state_after = vars_after->Get("state");
- long stateType_after = vars_after->Get("state_type");
- long attempt_after = vars_after->Get("attempt");
- bool reachable_after = vars_after->Get("reachable");
- bool host_reachable_after = vars_after->Get("host_reachable");
-
- Dictionary::Ptr vars_before = cr->GetVarsBefore();
-
- if (vars_before) {
- long state_before = vars_before->Get("state");
- long stateType_before = vars_before->Get("state_type");
- long attempt_before = vars_before->Get("attempt");
- bool reachable_before = vars_before->Get("reachable");
-
- if (state_before == state_after && stateType_before == stateType_after &&
- attempt_before == attempt_after && reachable_before == reachable_after)
- return; /* Nothing changed, ignore this checkresult. */
- }
-
- LogEntryType type;
- switch (service->GetState()) {
- case StateOK:
- type = LogEntryTypeServiceOk;
- break;
- case StateUnknown:
- type = LogEntryTypeServiceUnknown;
- break;
- case StateWarning:
- type = LogEntryTypeServiceWarning;
- break;
- case StateCritical:
- type = LogEntryTypeServiceCritical;
- break;
- default:
- Log(LogCritical, "db_ido", "Unknown service state: " + Convert::ToString(state_after));
- return;
- }
-
- String output;
-
- if (cr)
- output = CompatUtility::GetCheckResultOutput(cr);
-
- std::ostringstream msgbuf;
- msgbuf << "SERVICE ALERT: "
- << host->GetName() << ";"
- << service->GetShortName() << ";"
- << Service::StateToString(static_cast<ServiceState>(state_after)) << ";"
- << Service::StateTypeToString(static_cast<StateType>(stateType_after)) << ";"
- << attempt_after << ";"
- << output << ""
- << "";
-
- AddLogHistory(service, msgbuf.str(), type);
-
- if (service == host->GetCheckService()) {
- std::ostringstream msgbuf;
- msgbuf << "HOST ALERT: "
- << host->GetName() << ";"
- << Host::StateToString(Host::CalculateState(static_cast<ServiceState>(state_after), host_reachable_after)) << ";"
- << Service::StateTypeToString(static_cast<StateType>(stateType_after)) << ";"
- << attempt_after << ";"
- << output << ""
- << "";
-
- switch (host->GetState()) {
- case HostUp:
- type = LogEntryTypeHostUp;
- break;
- case HostDown:
- type = LogEntryTypeHostDown;
- break;
- case HostUnreachable:
- type = LogEntryTypeHostUnreachable;
- break;
- default:
- Log(LogCritical, "db_ido", "Unknown host state: " + Convert::ToString(state_after));
- return;
- }
-
- AddLogHistory(service, msgbuf.str(), type);
- }
-}
-
-void ServiceDbObject::AddTriggerDowntimeLogHistory(const Service::Ptr& service, const Downtime::Ptr& downtime)
-{
- Host::Ptr host = service->GetHost();
-
- if (!downtime)
- return;
-
- std::ostringstream msgbuf;
- msgbuf << "SERVICE DOWNTIME ALERT: "
- << host->GetName() << ";"
- << service->GetShortName() << ";"
- << "STARTED" << "; "
- << "Service has entered a period of scheduled downtime."
- << "";
-
- AddLogHistory(service, msgbuf.str(), LogEntryTypeInfoMessage);
-
- if (service == host->GetCheckService()) {
- std::ostringstream msgbuf;
- msgbuf << "HOST DOWNTIME ALERT: "
- << host->GetName() << ";"
- << "STARTED" << "; "
- << "Service has entered a period of scheduled downtime."
- << "";
-
- AddLogHistory(service, msgbuf.str(), LogEntryTypeInfoMessage);
- }
-}
-
-void ServiceDbObject::AddRemoveDowntimeLogHistory(const Service::Ptr& service, const Downtime::Ptr& downtime)
-{
- Host::Ptr host = service->GetHost();
-
- if (!downtime)
- return;
-
- String downtime_output;
- String downtime_state_str;
-
- if (downtime->GetWasCancelled()) {
- downtime_output = "Scheduled downtime for service has been cancelled.";
- downtime_state_str = "CANCELLED";
- } else {
- downtime_output = "Service has exited from a period of scheduled downtime.";
- downtime_state_str = "STOPPED";
- }
-
- std::ostringstream msgbuf;
- msgbuf << "SERVICE DOWNTIME ALERT: "
- << host->GetName() << ";"
- << service->GetShortName() << ";"
- << downtime_state_str << "; "
- << downtime_output
- << "";
-
- AddLogHistory(service, msgbuf.str(), LogEntryTypeInfoMessage);
-
- if (service == host->GetCheckService()) {
- std::ostringstream msgbuf;
- msgbuf << "HOST DOWNTIME ALERT: "
- << host->GetName() << ";"
- << downtime_state_str << "; "
- << downtime_output
- << "";
-
- AddLogHistory(service, msgbuf.str(), LogEntryTypeInfoMessage);
- }
-}
-
-void ServiceDbObject::AddNotificationSentLogHistory(const Notification::Ptr& notification, const Service::Ptr& service, const User::Ptr& user,
- NotificationType notification_type, const CheckResult::Ptr& cr,
- const String& author, const String& comment_text)
-{
- Host::Ptr host = service->GetHost();
-
- CheckCommand::Ptr commandObj = service->GetCheckCommand();
-
- String check_command = "";
- if (commandObj)
- check_command = commandObj->GetName();
-
- String notification_type_str = Notification::NotificationTypeToString(notification_type);
-
- String author_comment = "";
- if (notification_type == NotificationCustom || notification_type == NotificationAcknowledgement) {
- author_comment = ";" + author + ";" + comment_text;
- }
-
- if (!cr)
- return;
-
- String output;
-
- if (cr)
- output = CompatUtility::GetCheckResultOutput(cr);
-
- std::ostringstream msgbuf;
- msgbuf << "SERVICE NOTIFICATION: "
- << user->GetName() << ";"
- << host->GetName() << ";"
- << service->GetShortName() << ";"
- << notification_type_str << " "
- << "(" << Service::StateToString(service->GetState()) << ");"
- << check_command << ";"
- << output << author_comment
- << "";
-
- AddLogHistory(service, msgbuf.str(), LogEntryTypeServiceNotification);
-
- if (service == host->GetCheckService()) {
- std::ostringstream msgbuf;
- msgbuf << "HOST NOTIFICATION: "
- << user->GetName() << ";"
- << host->GetName() << ";"
- << notification_type_str << " "
- << "(" << Service::StateToString(service->GetState()) << ");"
- << check_command << ";"
- << output << author_comment
- << "";
-
- AddLogHistory(service, msgbuf.str(), LogEntryTypeHostNotification);
- }
-}
-
-void ServiceDbObject::AddFlappingLogHistory(const Service::Ptr& service, FlappingState flapping_state)
-{
- Host::Ptr host = service->GetHost();
-
- String flapping_state_str;
- String flapping_output;
-
- switch (flapping_state) {
- case FlappingStarted:
- flapping_output = "Service appears to have started flapping (" + Convert::ToString(service->GetFlappingCurrent()) + "% change >= " + Convert::ToString(service->GetFlappingThreshold()) + "% threshold)";
- flapping_state_str = "STARTED";
- break;
- case FlappingStopped:
- flapping_output = "Service appears to have stopped flapping (" + Convert::ToString(service->GetFlappingCurrent()) + "% change < " + Convert::ToString(service->GetFlappingThreshold()) + "% threshold)";
- flapping_state_str = "STOPPED";
- break;
- case FlappingDisabled:
- flapping_output = "Flap detection has been disabled";
- flapping_state_str = "DISABLED";
- break;
- default:
- Log(LogCritical, "db_ido", "Unknown flapping state: " + Convert::ToString(flapping_state));
- return;
- }
-
- std::ostringstream msgbuf;
- msgbuf << "SERVICE FLAPPING ALERT: "
- << host->GetName() << ";"
- << service->GetShortName() << ";"
- << flapping_state_str << "; "
- << flapping_output
- << "";
-
- AddLogHistory(service, msgbuf.str(), LogEntryTypeInfoMessage);
-
- if (service == host->GetCheckService()) {
- std::ostringstream msgbuf;
- msgbuf << "HOST FLAPPING ALERT: "
- << host->GetName() << ";"
- << flapping_state_str << "; "
- << flapping_output
- << "";
-
- AddLogHistory(service, msgbuf.str(), LogEntryTypeInfoMessage);
- }
-}
-
-void ServiceDbObject::AddLogHistory(const Service::Ptr& service, String buffer, LogEntryType type)
-{
- Host::Ptr host = service->GetHost();
-
- Log(LogDebug, "db_ido", "add log entry history for '" + service->GetName() + "'");
-
- double now = Utility::GetTime();
- std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now);
-
- DbQuery query1;
- query1.Table = "logentries";
- query1.Type = DbQueryInsert;
- query1.Category = DbCatLog;
-
- Dictionary::Ptr fields1 = make_shared<Dictionary>();
- fields1->Set("logentry_time", DbValue::FromTimestamp(time_bag.first));
- fields1->Set("entry_time", DbValue::FromTimestamp(time_bag.first));
- fields1->Set("entry_time_usec", time_bag.second);
- fields1->Set("object_id", service); // added in 1.10 see #4754
- fields1->Set("logentry_type", type);
- fields1->Set("logentry_data", buffer);
-
- fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
- String node = IcingaApplication::GetInstance()->GetNodeName();
-
- Endpoint::Ptr endpoint = Endpoint::GetByName(node);
- if (endpoint)
- fields1->Set("endpoint_object_id", endpoint);
-
- query1.Fields = fields1;
- OnQuery(query1);
-
- if (host->GetCheckService() == service) {
- fields1 = fields1->ShallowClone();
- fields1->Set("object_id", host); // added in 1.10 see #4754
- query1.Fields = fields1;
- OnQuery(query1);
- }
-}
-
-/* flappinghistory */
-void ServiceDbObject::AddFlappingHistory(const Service::Ptr& service, FlappingState flapping_state)
-{
- Host::Ptr host = service->GetHost();
-
- Log(LogDebug, "db_ido", "add flapping history for '" + service->GetName() + "'");
-
- double now = Utility::GetTime();
- std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now);
-
- DbQuery query1;
- query1.Table = "flappinghistory";
- query1.Type = DbQueryInsert;
- query1.Category = DbCatFlapping;
-
- Dictionary::Ptr fields1 = make_shared<Dictionary>();
-
- fields1->Set("event_time", DbValue::FromTimestamp(time_bag.first));
- fields1->Set("event_time_usec", time_bag.second);
-
- switch (flapping_state) {
- case FlappingStarted:
- fields1->Set("event_type", 1000);
- break;
- case FlappingStopped:
- fields1->Set("event_type", 1001);
- fields1->Set("reason_type", 1);
- break;
- case FlappingDisabled:
- fields1->Set("event_type", 1001);
- fields1->Set("reason_type", 2);
- break;
- default:
- Log(LogDebug, "db_ido", "Unhandled flapping state: " + Convert::ToString(flapping_state));
- return;
- }
-
- fields1->Set("flapping_type", 1); /* service */
- fields1->Set("object_id", service);
- fields1->Set("percent_state_change", service->GetFlappingCurrent());
- fields1->Set("low_threshold", service->GetFlappingThreshold());
- fields1->Set("high_threshold", service->GetFlappingThreshold());
-
- fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
- String node = IcingaApplication::GetInstance()->GetNodeName();
-
- Endpoint::Ptr endpoint = Endpoint::GetByName(node);
- if (endpoint)
- fields1->Set("endpoint_object_id", endpoint);
-
- query1.Fields = fields1;
- OnQuery(query1);
-
- if (host->GetCheckService() == service) {
- fields1 = fields1->ShallowClone();
- fields1->Set("object_id", host);
- fields1->Set("flapping_type", 0); /* host */
- query1.Fields = fields1;
- OnQuery(query1);
- }
-}
-
-/* servicechecks */
-void ServiceDbObject::AddServiceCheckHistory(const Service::Ptr& service, const CheckResult::Ptr &cr)
-{
- if (!cr)
- return;
-
- Host::Ptr host = service->GetHost();
-
- Log(LogDebug, "db_ido", "add service check history for '" + service->GetName() + "'");
-
- DbQuery query1;
- query1.Table = "servicechecks";
- query1.Type = DbQueryInsert;
- query1.Category = DbCatCheck;
-
- Dictionary::Ptr fields1 = make_shared<Dictionary>();
- double execution_time = Service::CalculateExecutionTime(cr);
-
- fields1->Set("check_type", CompatUtility::GetServiceCheckType(service));
- fields1->Set("current_check_attempt", service->GetCheckAttempt());
- fields1->Set("max_check_attempts", service->GetMaxCheckAttempts());
- fields1->Set("state", CompatUtility::GetServiceCurrentState(service));
- fields1->Set("state_type", service->GetStateType());
-
- double now = Utility::GetTime();
- std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now);
-
- double end = now + execution_time;
- std::pair<unsigned long, unsigned long> time_bag_end = CompatUtility::ConvertTimestamp(end);
-
- fields1->Set("start_time", DbValue::FromTimestamp(time_bag.first));
- fields1->Set("start_time_usec", time_bag.second);
- fields1->Set("end_time", DbValue::FromTimestamp(time_bag_end.first));
- fields1->Set("end_time_usec", time_bag_end.second);
- fields1->Set("command_object_id", service->GetCheckCommand());
- fields1->Set("command_args", Empty);
- fields1->Set("command_line", cr->GetCommand());
- fields1->Set("execution_time", Convert::ToString(execution_time));
- fields1->Set("latency", Convert::ToString(Service::CalculateLatency(cr)));
- fields1->Set("return_code", cr->GetExitStatus());
- fields1->Set("output", CompatUtility::GetCheckResultOutput(cr));
- fields1->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr));
- fields1->Set("perfdata", CompatUtility::GetCheckResultPerfdata(cr));
-
- fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
- fields1->Set("service_object_id", service);
-
- String node = IcingaApplication::GetInstance()->GetNodeName();
-
- Endpoint::Ptr endpoint = Endpoint::GetByName(node);
- if (endpoint)
- fields1->Set("endpoint_object_id", endpoint);
-
- query1.Fields = fields1;
- OnQuery(query1);
-
- if (host->GetCheckService() == service) {
- query1.Table = "hostchecks";
-
- fields1 = fields1->ShallowClone();
- fields1->Remove("service_object_id");
- fields1->Set("host_object_id", host);
- fields1->Set("state", host->GetState());
- fields1->Set("state_type", host->GetStateType());
- query1.Fields = fields1;
- OnQuery(query1);
- }
-}
-
-/* eventhandlers */
-void ServiceDbObject::AddEventHandlerHistory(const Service::Ptr& service)
-{
- Host::Ptr host = service->GetHost();
-
- Log(LogDebug, "db_ido", "add eventhandler history for '" + service->GetName() + "'");
-
- double now = Utility::GetTime();
- std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now);
-
- DbQuery query1;
- query1.Table = "eventhandlers";
- query1.Type = DbQueryInsert;
- query1.Category = DbCatEventHandler;
-
- Dictionary::Ptr fields1 = make_shared<Dictionary>();
-
- fields1->Set("eventhandler_type", 1); /* service */
- fields1->Set("object_id", service);
- fields1->Set("state", CompatUtility::GetServiceCurrentState(service));
- fields1->Set("state_type", service->GetStateType());
-
- fields1->Set("start_time", DbValue::FromTimestamp(time_bag.first));
- fields1->Set("start_time_usec", time_bag.second);
- fields1->Set("end_time", DbValue::FromTimestamp(time_bag.first));
- fields1->Set("end_time_usec", time_bag.second);
- fields1->Set("command_object_id", service->GetEventCommand());
-
- fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
- String node = IcingaApplication::GetInstance()->GetNodeName();
-
- Endpoint::Ptr endpoint = Endpoint::GetByName(node);
- if (endpoint)
- fields1->Set("endpoint_object_id", endpoint);
-
- query1.Fields = fields1;
- OnQuery(query1);
-
- if (host->GetCheckService() == service) {
- fields1 = fields1->ShallowClone();
- fields1->Set("eventhandler_type", 0); /* host */
- fields1->Set("object_id", host);
- fields1->Set("state", host->GetState());
- fields1->Set("state_type", host->GetStateType());
- query1.Fields = fields1;
- OnQuery(query1);
- }
-}
-
-/* externalcommands */
-void ServiceDbObject::AddExternalCommandHistory(double time, const String& command, const std::vector<String>& arguments)
-{
- Log(LogDebug, "db_ido", "add external command history");
-
- DbQuery query1;
- query1.Table = "externalcommands";
- query1.Type = DbQueryInsert;
- query1.Category = DbCatExternalCommand;
-
- Dictionary::Ptr fields1 = make_shared<Dictionary>();
-
- fields1->Set("entry_time", DbValue::FromTimestamp(static_cast<long>(time)));
- fields1->Set("command_type", CompatUtility::MapExternalCommandType(command));
- fields1->Set("command_name", command);
- fields1->Set("command_args", boost::algorithm::join(arguments, ";"));
-
- fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
-
- String node = IcingaApplication::GetInstance()->GetNodeName();
-
- Endpoint::Ptr endpoint = Endpoint::GetByName(node);
- if (endpoint)
- fields1->Set("endpoint_object_id", endpoint);
-
- query1.Fields = fields1;
- OnQuery(query1);
}
namespace icinga
{
-enum LogEntryType
-{
- LogEntryTypeRuntimeError = 1,
- LogEntryTypeRuntimeWarning = 2,
- LogEntryTypeVerificationError = 4,
- LogEntryTypeVerificationWarning = 8,
- LogEntryTypeConfigError = 16,
- LogEntryTypeConfigWarning = 32,
- LogEntryTypeProcessInfo = 64,
- LogEntryTypeEventHandler = 128,
- LogEntryTypeExternalCommand = 512,
- LogEntryTypeHostUp = 1024,
- LogEntryTypeHostDown = 2048,
- LogEntryTypeHostUnreachable = 4096,
- LogEntryTypeServiceOk = 8192,
- LogEntryTypeServiceUnknown = 16384,
- LogEntryTypeServiceWarning = 32768,
- LogEntryTypeServiceCritical = 65536,
- LogEntryTypePassiveCheck = 1231072,
- LogEntryTypeInfoMessage = 262144,
- LogEntryTypeHostNotification = 524288,
- LogEntryTypeServiceNotification = 1048576
-};
-
/**
* A Service database object.
*
virtual void OnConfigUpdate(void);
virtual void OnStatusUpdate(void);
-
-private:
- static void AddCommentInternal(const Service::Ptr& service, const Comment::Ptr& comment, bool historical);
- static void AddCommentByType(const DynamicObject::Ptr& object, const Comment::Ptr& comment, bool historical);
- static void AddComments(const Service::Ptr& service);
- static void RemoveComments(const Service::Ptr& service);
-
- static void AddDowntimeInternal(const Service::Ptr& service, const Downtime::Ptr& downtime, bool historical);
- static void AddDowntimeByType(const DynamicObject::Ptr& object, const Downtime::Ptr& downtime, bool historical);
- static void AddDowntimes(const Service::Ptr& service);
- static void RemoveDowntimes(const Service::Ptr& service);
-
- static void AddLogHistory(const Service::Ptr& service, String buffer, LogEntryType type);
-
- /* Status */
- static void AddComment(const Service::Ptr& service, const Comment::Ptr& comment);
- static void RemoveComment(const Service::Ptr& service, const Comment::Ptr& comment);
-
- static void AddDowntime(const Service::Ptr& service, const Downtime::Ptr& downtime);
- static void RemoveDowntime(const Service::Ptr& service, const Downtime::Ptr& downtime);
- static void TriggerDowntime(const Service::Ptr& service, const Downtime::Ptr& downtime);
-
- /* comment, downtime, acknowledgement history */
- static void AddCommentHistory(const Service::Ptr& service, const Comment::Ptr& comment);
- static void AddDowntimeHistory(const Service::Ptr& service, const Downtime::Ptr& downtime);
- static void AddAcknowledgementHistory(const Service::Ptr& service, const String& author, const String& comment,
- AcknowledgementType type, double expiry);
-
- /* notification & contactnotification history */
- static void AddNotificationHistory(const Notification::Ptr& notification, const Service::Ptr& service,
- const std::set<User::Ptr>& users, NotificationType type, const CheckResult::Ptr& cr, const String& author,
- const String& text);
-
- /* statehistory */
- static void AddStateChangeHistory(const Service::Ptr& service, const CheckResult::Ptr& cr, StateType type);
-
- /* logentries */
- static void AddCheckResultLogHistory(const Service::Ptr& service, const CheckResult::Ptr &cr);
- static void AddTriggerDowntimeLogHistory(const Service::Ptr& service, const Downtime::Ptr& downtime);
- static void AddRemoveDowntimeLogHistory(const Service::Ptr& service, const Downtime::Ptr& downtime);
- static void AddNotificationSentLogHistory(const Notification::Ptr& notification, const Service::Ptr& service,
- const User::Ptr& user, NotificationType notification_type, const CheckResult::Ptr& cr, const String& author,
- const String& comment_text);
- static void AddFlappingLogHistory(const Service::Ptr& service, FlappingState flapping_state);
-
- /* other history */
- static void AddFlappingHistory(const Service::Ptr& service, FlappingState flapping_state);
- static void AddServiceCheckHistory(const Service::Ptr& service, const CheckResult::Ptr &cr);
- static void AddEventHandlerHistory(const Service::Ptr& service);
- static void AddExternalCommandHistory(double time, const String& command, const std::vector<String>& arguments);
};
}
# along with this program; if not, write to the Free Software Foundation
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+mkclass_target(checkable.ti checkable.th)
mkclass_target(checkcommand.ti checkcommand.th)
mkclass_target(checkresult.ti checkresult.th)
mkclass_target(command.ti command.th)
mkembedconfig_target(icinga-type.conf icinga-type.cpp)
add_library(icinga SHARED
- api.cpp api.h checkcommand.cpp checkcommand.th checkresult.cpp checkresult.th
+ api.cpp checkable.cpp checkable.th checkable-dependency.cpp checkable-downtime.cpp checkable-event.cpp
+ checkable-flapping.cpp checkcommand.cpp checkcommand.th checkresult.cpp checkresult.th
cib.cpp command.cpp command.th comment.cpp comment.th compatutility.cpp dependency.cpp dependency.th
dependency-apply.cpp domain.cpp domain.th downtime.cpp downtime.th eventcommand.cpp eventcommand.th
externalcommandprocessor.cpp host.cpp host.th hostgroup.cpp hostgroup.th
macroprocessor.cpp macroresolver.cpp notificationcommand.cpp notificationcommand.th
notification.cpp notification.th notification-apply.cpp perfdatavalue.cpp perfdatavalue.th
pluginutility.cpp scheduleddowntime.cpp scheduleddowntime.th scheduleddowntime-apply.cpp
- service-apply.cpp service-check.cpp service-comment.cpp service.cpp service-dependency.cpp
- service-downtime.cpp service-event.cpp service-flapping.cpp service.th servicegroup.cpp servicegroup.th
- service-notification.cpp timeperiod.cpp timeperiod.th user.cpp user.th
+ service-apply.cpp checkable-check.cpp checkable-comment.cpp service.cpp service.th
+ servicegroup.cpp servicegroup.th checkable-notification.cpp timeperiod.cpp timeperiod.th user.cpp user.th
usergroup.cpp usergroup.th icinga-type.cpp
)
using namespace icinga;
-boost::signals2::signal<void (const Service::Ptr&, const CheckResult::Ptr&, const String&)> Service::OnNewCheckResult;
-boost::signals2::signal<void (const Service::Ptr&, const CheckResult::Ptr&, StateType, const String&)> Service::OnStateChange;
-boost::signals2::signal<void (const Service::Ptr&, NotificationType, const CheckResult::Ptr&, const String&, const String&)> Service::OnNotificationsRequested;
-boost::signals2::signal<void (const Service::Ptr&, double, const String&)> Service::OnNextCheckChanged;
-boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> Service::OnForceNextCheckChanged;
-boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> Service::OnForceNextNotificationChanged;
-boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> Service::OnEnableActiveChecksChanged;
-boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> Service::OnEnablePassiveChecksChanged;
-boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> Service::OnEnableNotificationsChanged;
-boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> Service::OnEnableFlappingChanged;
-boost::signals2::signal<void (const Service::Ptr&, FlappingState)> Service::OnFlappingChanged;
-
-CheckCommand::Ptr Service::GetCheckCommand(void) const
+boost::signals2::signal<void (const Checkable::Ptr&, const CheckResult::Ptr&, const String&)> Checkable::OnNewCheckResult;
+boost::signals2::signal<void (const Checkable::Ptr&, const CheckResult::Ptr&, StateType, const String&)> Checkable::OnStateChange;
+boost::signals2::signal<void (const Checkable::Ptr&, NotificationType, const CheckResult::Ptr&, const String&, const String&)> Checkable::OnNotificationsRequested;
+boost::signals2::signal<void (const Checkable::Ptr&, double, const String&)> Checkable::OnNextCheckChanged;
+boost::signals2::signal<void (const Checkable::Ptr&, bool, const String&)> Checkable::OnForceNextCheckChanged;
+boost::signals2::signal<void (const Checkable::Ptr&, bool, const String&)> Checkable::OnForceNextNotificationChanged;
+boost::signals2::signal<void (const Checkable::Ptr&, bool, const String&)> Checkable::OnEnableActiveChecksChanged;
+boost::signals2::signal<void (const Checkable::Ptr&, bool, const String&)> Checkable::OnEnablePassiveChecksChanged;
+boost::signals2::signal<void (const Checkable::Ptr&, bool, const String&)> Checkable::OnEnableNotificationsChanged;
+boost::signals2::signal<void (const Checkable::Ptr&, bool, const String&)> Checkable::OnEnableFlappingChanged;
+boost::signals2::signal<void (const Checkable::Ptr&, FlappingState)> Checkable::OnFlappingChanged;
+
+CheckCommand::Ptr Checkable::GetCheckCommand(void) const
{
String command;
return CheckCommand::GetByName(command);
}
-void Service::SetCheckCommand(const CheckCommand::Ptr& command)
+void Checkable::SetCheckCommand(const CheckCommand::Ptr& command)
{
SetOverrideCheckCommand(command->GetName());
}
-TimePeriod::Ptr Service::GetCheckPeriod(void) const
+TimePeriod::Ptr Checkable::GetCheckPeriod(void) const
{
String tp;
return TimePeriod::GetByName(tp);
}
-void Service::SetCheckPeriod(const TimePeriod::Ptr& tp)
+void Checkable::SetCheckPeriod(const TimePeriod::Ptr& tp)
{
SetOverrideCheckPeriod(tp->GetName());
}
-double Service::GetCheckInterval(void) const
+double Checkable::GetCheckInterval(void) const
{
if (!GetOverrideCheckInterval().IsEmpty())
return GetOverrideCheckInterval();
return GetCheckIntervalRaw();
}
-void Service::SetCheckInterval(double interval)
+void Checkable::SetCheckInterval(double interval)
{
SetOverrideCheckInterval(interval);
}
-double Service::GetRetryInterval(void) const
+double Checkable::GetRetryInterval(void) const
{
if (!GetOverrideRetryInterval().IsEmpty())
return GetOverrideRetryInterval();
return GetRetryIntervalRaw();
}
-void Service::SetRetryInterval(double interval)
+void Checkable::SetRetryInterval(double interval)
{
SetOverrideRetryInterval(interval);
}
-void Service::SetSchedulingOffset(long offset)
+void Checkable::SetSchedulingOffset(long offset)
{
m_SchedulingOffset = offset;
}
-long Service::GetSchedulingOffset(void)
+long Checkable::GetSchedulingOffset(void)
{
return m_SchedulingOffset;
}
-void Service::SetNextCheck(double nextCheck, const String& authority)
+void Checkable::SetNextCheck(double nextCheck, const String& authority)
{
SetNextCheckRaw(nextCheck);
OnNextCheckChanged(GetSelf(), nextCheck, authority);
}
-double Service::GetNextCheck(void)
+double Checkable::GetNextCheck(void)
{
return GetNextCheckRaw();
}
-void Service::UpdateNextCheck(void)
+void Checkable::UpdateNextCheck(void)
{
ObjectLock olock(this);
SetNextCheck(now - adj + interval);
}
-bool Service::HasBeenChecked(void) const
+bool Checkable::HasBeenChecked(void) const
{
return GetLastCheckResult() != NULL;
}
-double Service::GetLastCheck(void) const
+double Checkable::GetLastCheck(void) const
{
CheckResult::Ptr cr = GetLastCheckResult();
double schedule_end = -1;
return schedule_end;
}
-bool Service::GetEnableActiveChecks(void) const
+bool Checkable::GetEnableActiveChecks(void) const
{
if (!GetOverrideEnableActiveChecks().IsEmpty())
return GetOverrideEnableActiveChecks();
return GetEnableActiveChecksRaw();
}
-void Service::SetEnableActiveChecks(bool enabled, const String& authority)
+void Checkable::SetEnableActiveChecks(bool enabled, const String& authority)
{
SetOverrideEnableActiveChecks(enabled);
OnEnableActiveChecksChanged(GetSelf(), enabled, authority);
}
-bool Service::GetEnablePassiveChecks(void) const
+bool Checkable::GetEnablePassiveChecks(void) const
{
if (!GetOverrideEnablePassiveChecks().IsEmpty())
return GetOverrideEnablePassiveChecks();
return GetEnablePassiveChecksRaw();
}
-void Service::SetEnablePassiveChecks(bool enabled, const String& authority)
+void Checkable::SetEnablePassiveChecks(bool enabled, const String& authority)
{
SetOverrideEnablePassiveChecks(enabled);
OnEnablePassiveChecksChanged(GetSelf(), enabled, authority);
}
-bool Service::GetForceNextCheck(void) const
+bool Checkable::GetForceNextCheck(void) const
{
return GetForceNextCheckRaw();
}
-void Service::SetForceNextCheck(bool forced, const String& authority)
+void Checkable::SetForceNextCheck(bool forced, const String& authority)
{
SetForceNextCheckRaw(forced);
OnForceNextCheckChanged(GetSelf(), forced, authority);
}
-int Service::GetMaxCheckAttempts(void) const
+int Checkable::GetMaxCheckAttempts(void) const
{
if (!GetOverrideMaxCheckAttempts().IsEmpty())
return GetOverrideMaxCheckAttempts();
return GetMaxCheckAttemptsRaw();
}
-void Service::SetMaxCheckAttempts(int attempts)
+void Checkable::SetMaxCheckAttempts(int attempts)
{
SetOverrideMaxCheckAttempts(attempts);
}
-void Service::ProcessCheckResult(const CheckResult::Ptr& cr, const String& authority)
+void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const String& authority)
{
{
ObjectLock olock(this);
bool reachable = IsReachable();
bool notification_reachable = IsReachable(DependencyNotification);
- bool host_reachable = GetHost()->IsReachable();
-
ASSERT(!OwnsLock());
ObjectLock olock(this);
CheckResult::Ptr old_cr = GetLastCheckResult();
- ServiceState old_state = GetState();
+ ServiceState old_state = GetStateRaw();
StateType old_stateType = GetStateType();
long old_attempt = GetCheckAttempt();
bool recovery;
/* The ExecuteCheck function already sets the old state, but we need to do it again
* in case this was a passive check result. */
- SetLastState(old_state);
+ SetLastStateRaw(old_state);
SetLastStateType(old_stateType);
SetLastReachable(reachable);
} else {
if (old_attempt >= GetMaxCheckAttempts()) {
SetStateType(StateTypeHard);
- } else if (GetStateType() == StateTypeSoft || GetState() == StateOK) {
+ } else if (old_stateType == StateTypeSoft || old_state == StateOK) {
SetStateType(StateTypeSoft);
attempt = old_attempt + 1;
} else {
SetCheckAttempt(attempt);
- SetState(cr->GetState());
+ ServiceState new_state = cr->GetState();
+ SetStateRaw(new_state);
- bool stateChange = (old_state != GetState());
+ bool stateChange = (old_state != new_state);
if (stateChange) {
SetLastStateChange(now);
/* remove acknowledgements */
if (GetAcknowledgement() == AcknowledgementNormal ||
- (GetAcknowledgement() == AcknowledgementSticky && GetState() == StateOK)) {
+ (GetAcknowledgement() == AcknowledgementSticky && new_state == StateOK)) {
ClearAcknowledgement();
}
- /* reschedule service dependencies */
- BOOST_FOREACH(const Service::Ptr& parent, GetParentServices()) {
+ /* reschedule direct parents */
+ BOOST_FOREACH(const Checkable::Ptr& parent, GetParents()) {
+ if (parent.get() == this)
+ continue;
+
ObjectLock olock(parent);
parent->SetNextCheck(Utility::GetTime());
}
-
- /* reschedule host dependencies */
- BOOST_FOREACH(const Host::Ptr& parent, GetParentHosts()) {
- Service::Ptr service = parent->GetCheckService();
-
- if (service && service->GetName() != GetName()) {
- ObjectLock olock(service);
- service->SetNextCheck(Utility::GetTime());
- }
- }
}
bool remove_acknowledgement_comments = false;
bool hardChange = (GetStateType() == StateTypeHard && old_stateType == StateTypeSoft);
- if (old_state != GetState() && old_stateType == StateTypeHard && GetStateType() == StateTypeHard)
+ if (stateChange && old_stateType == StateTypeHard && GetStateType() == StateTypeHard)
hardChange = true;
if (GetVolatile())
hardChange = true;
if (hardChange) {
- SetLastHardState(GetState());
+ SetLastHardStateRaw(new_state);
SetLastHardStateChange(now);
}
- if (GetState() != StateOK)
+ if (new_state != StateOK)
TriggerDowntimes();
- Service::UpdateStatistics(cr);
+ Checkable::UpdateStatistics(cr);
bool in_downtime = IsInDowntime();
bool send_notification = hardChange && notification_reachable && !in_downtime && !IsAcknowledged();
RemoveCommentsByType(CommentAcknowledgement);
Dictionary::Ptr vars_after = make_shared<Dictionary>();
- vars_after->Set("state", GetState());
+ vars_after->Set("state", new_state);
vars_after->Set("state_type", GetStateType());
vars_after->Set("attempt", GetCheckAttempt());
vars_after->Set("reachable", reachable);
- vars_after->Set("host_reachable", host_reachable);
if (old_cr)
cr->SetVarsBefore(old_cr->GetVarsAfter());
olock.Unlock();
-// Log(LogDebug, "icinga", "Flapping: Service " + GetName() +
+// Log(LogDebug, "icinga", "Flapping: Checkable " + GetName() +
// " was: " + Convert::ToString(was_flapping) +
// " is: " + Convert::ToString(is_flapping) +
// " threshold: " + Convert::ToString(GetFlappingThreshold()) +
if (!was_flapping && is_flapping) {
OnNotificationsRequested(GetSelf(), NotificationFlappingStart, cr, "", "");
- Log(LogDebug, "icinga", "Flapping: Service " + GetName() + " started flapping (" + Convert::ToString(GetFlappingThreshold()) + "% < " + Convert::ToString(GetFlappingCurrent()) + "%).");
+ Log(LogDebug, "icinga", "Flapping: Checkable " + GetName() + " started flapping (" + Convert::ToString(GetFlappingThreshold()) + "% < " + Convert::ToString(GetFlappingCurrent()) + "%).");
OnFlappingChanged(GetSelf(), FlappingStarted);
} else if (was_flapping && !is_flapping) {
OnNotificationsRequested(GetSelf(), NotificationFlappingEnd, cr, "", "");
- Log(LogDebug, "icinga", "Flapping: Service " + GetName() + " stopped flapping (" + Convert::ToString(GetFlappingThreshold()) + "% >= " + Convert::ToString(GetFlappingCurrent()) + "%).");
+ Log(LogDebug, "icinga", "Flapping: Checkable " + GetName() + " stopped flapping (" + Convert::ToString(GetFlappingThreshold()) + "% >= " + Convert::ToString(GetFlappingCurrent()) + "%).");
OnFlappingChanged(GetSelf(), FlappingStopped);
} else if (send_notification)
OnNotificationsRequested(GetSelf(), recovery ? NotificationRecovery : NotificationProblem, cr, "", "");
}
-ServiceState Service::StateFromString(const String& state)
-{
- if (state == "OK")
- return StateOK;
- else if (state == "WARNING")
- return StateWarning;
- else if (state == "CRITICAL")
- return StateCritical;
- else
- return StateUnknown;
-}
-
-String Service::StateToString(ServiceState state)
-{
- switch (state) {
- case StateOK:
- return "OK";
- case StateWarning:
- return "WARNING";
- case StateCritical:
- return "CRITICAL";
- case StateUnknown:
- default:
- return "UNKNOWN";
- }
-}
-
-StateType Service::StateTypeFromString(const String& type)
-{
- if (type == "SOFT")
- return StateTypeSoft;
- else
- return StateTypeHard;
-}
-
-String Service::StateTypeToString(StateType type)
-{
- if (type == StateTypeSoft)
- return "SOFT";
- else
- return "HARD";
-}
-
-void Service::ExecuteCheck(void)
+void Checkable::ExecuteCheck(void)
{
- CONTEXT("Executing service check for service '" + GetShortName() + "' on host '" + GetHost()->GetName() + "'");
+ CONTEXT("Executing check for object '" + GetName() + "'");
ASSERT(!OwnsLock());
m_CheckRunning = true;
- SetLastState(GetState());
+ SetLastStateRaw(GetStateRaw());
SetLastStateType(GetLastStateType());
SetLastReachable(reachable);
}
double scheduled_start = GetNextCheck();
double before_check = Utility::GetTime();
- Service::Ptr self = GetSelf();
+ Checkable::Ptr self = GetSelf();
CheckResult::Ptr result = make_shared<CheckResult>();
GetCheckCommand()->Execute(GetSelf(), result);
}
-void Service::UpdateStatistics(const CheckResult::Ptr& cr)
+void Checkable::UpdateStatistics(const CheckResult::Ptr& cr)
{
time_t ts = cr->GetScheduleEnd();
CIB::UpdatePassiveChecksStatistics(ts, 1);
}
-double Service::CalculateExecutionTime(const CheckResult::Ptr& cr)
+double Checkable::CalculateExecutionTime(const CheckResult::Ptr& cr)
{
if (!cr)
return 0;
return cr->GetExecutionEnd() - cr->GetExecutionStart();
}
-double Service::CalculateLatency(const CheckResult::Ptr& cr)
+double Checkable::CalculateLatency(const CheckResult::Ptr& cr)
{
if (!cr)
return 0;
static int l_NextCommentID = 1;
static boost::mutex l_CommentMutex;
static std::map<int, String> l_LegacyCommentsCache;
-static std::map<String, Service::WeakPtr> l_CommentsCache;
+static std::map<String, Checkable::WeakPtr> l_CommentsCache;
static Timer::Ptr l_CommentsExpireTimer;
-boost::signals2::signal<void (const Service::Ptr&, const Comment::Ptr&, const String&)> Service::OnCommentAdded;
-boost::signals2::signal<void (const Service::Ptr&, const Comment::Ptr&, const String&)> Service::OnCommentRemoved;
+boost::signals2::signal<void (const Checkable::Ptr&, const Comment::Ptr&, const String&)> Checkable::OnCommentAdded;
+boost::signals2::signal<void (const Checkable::Ptr&, const Comment::Ptr&, const String&)> Checkable::OnCommentRemoved;
-int Service::GetNextCommentID(void)
+int Checkable::GetNextCommentID(void)
{
boost::mutex::scoped_lock lock(l_CommentMutex);
return l_NextCommentID;
}
-String Service::AddComment(CommentType entryType, const String& author,
+String Checkable::AddComment(CommentType entryType, const String& author,
const String& text, double expireTime, const String& id, const String& authority)
{
String uid;
return uid;
}
-void Service::RemoveAllComments(void)
+void Checkable::RemoveAllComments(void)
{
std::vector<String> ids;
Dictionary::Ptr comments = GetComments();
}
}
-void Service::RemoveComment(const String& id, const String& authority)
+void Checkable::RemoveComment(const String& id, const String& authority)
{
- Service::Ptr owner = GetOwnerByCommentID(id);
+ Checkable::Ptr owner = GetOwnerByCommentID(id);
if (!owner)
return;
OnCommentRemoved(owner, comment, authority);
}
-String Service::GetCommentIDFromLegacyID(int id)
+String Checkable::GetCommentIDFromLegacyID(int id)
{
boost::mutex::scoped_lock lock(l_CommentMutex);
return it->second;
}
-Service::Ptr Service::GetOwnerByCommentID(const String& id)
+Checkable::Ptr Checkable::GetOwnerByCommentID(const String& id)
{
boost::mutex::scoped_lock lock(l_CommentMutex);
return l_CommentsCache[id].lock();
}
-Comment::Ptr Service::GetCommentByID(const String& id)
+Comment::Ptr Checkable::GetCommentByID(const String& id)
{
- Service::Ptr owner = GetOwnerByCommentID(id);
+ Checkable::Ptr owner = GetOwnerByCommentID(id);
if (!owner)
return Comment::Ptr();
return Comment::Ptr();
}
-void Service::AddCommentsToCache(void)
+void Checkable::AddCommentsToCache(void)
{
#ifdef _DEBUG
- Log(LogDebug, "icinga", "Updating Service comments cache.");
+ Log(LogDebug, "icinga", "Updating Checkable comments cache.");
#endif /* _DEBUG */
Dictionary::Ptr comments = GetComments();
}
}
-void Service::RemoveCommentsByType(int type)
+void Checkable::RemoveCommentsByType(int type)
{
Dictionary::Ptr comments = GetComments();
}
}
-void Service::RemoveExpiredComments(void)
+void Checkable::RemoveExpiredComments(void)
{
Dictionary::Ptr comments = GetComments();
}
}
-void Service::CommentsExpireTimerHandler(void)
+void Checkable::CommentsExpireTimerHandler(void)
{
+ BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
+ host->RemoveExpiredComments();
+ }
+
BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
service->RemoveExpiredComments();
}
using namespace icinga;
-void Service::AddDependency(const Dependency::Ptr& dep)
+void Checkable::AddDependency(const Dependency::Ptr& dep)
{
boost::mutex::scoped_lock lock(m_DependencyMutex);
m_Dependencies.insert(dep);
}
-void Service::RemoveDependency(const Dependency::Ptr& dep)
+void Checkable::RemoveDependency(const Dependency::Ptr& dep)
{
boost::mutex::scoped_lock lock(m_DependencyMutex);
m_Dependencies.erase(dep);
}
-std::set<Dependency::Ptr> Service::GetDependencies(void) const
+std::set<Dependency::Ptr> Checkable::GetDependencies(void) const
{
boost::mutex::scoped_lock lock(m_DependencyMutex);
return m_Dependencies;
}
-void Service::AddReverseDependency(const Dependency::Ptr& dep)
+void Checkable::AddReverseDependency(const Dependency::Ptr& dep)
{
boost::mutex::scoped_lock lock(m_DependencyMutex);
m_ReverseDependencies.insert(dep);
}
-void Service::RemoveReverseDependency(const Dependency::Ptr& dep)
+void Checkable::RemoveReverseDependency(const Dependency::Ptr& dep)
{
boost::mutex::scoped_lock lock(m_DependencyMutex);
m_ReverseDependencies.erase(dep);
}
-std::set<Dependency::Ptr> Service::GetReverseDependencies(void) const
+std::set<Dependency::Ptr> Checkable::GetReverseDependencies(void) const
{
boost::mutex::scoped_lock lock(m_DependencyMutex);
return m_ReverseDependencies;
}
-bool Service::IsReachable(DependencyType dt, Dependency::Ptr *failedDependency, int rstack) const
+bool Checkable::IsReachable(DependencyType dt, Dependency::Ptr *failedDependency, int rstack) const
{
if (rstack > 20) {
Log(LogWarning, "icinga", "Too many nested dependencies for service '" + GetName() + "': Dependency failed.");
return false;
}
- BOOST_FOREACH(const Service::Ptr& service, GetParentServices()) {
+ BOOST_FOREACH(const Checkable::Ptr& service, GetParents()) {
if (!service->IsReachable(dt, failedDependency, rstack + 1))
return false;
}
- /* implicit dependency on host's check service */
- if (dt == DependencyState || dt == DependencyNotification) {
- Service::Ptr hc = GetHost()->GetCheckService();
+ /* implicit dependency on host if this is a service */
+ const Service *service = dynamic_cast<const Service *>(this);
+ if (service && (dt == DependencyState || dt == DependencyNotification)) {
+ Host::Ptr host = service->GetHost();
- if (hc && hc->GetState() == StateCritical && hc->GetStateType() == StateTypeHard) {
+ if (host && host->GetState() != HostUp && host->GetStateType() == StateTypeHard) {
if (failedDependency)
*failedDependency = Dependency::Ptr();
return true;
}
-std::set<Host::Ptr> Service::GetParentHosts(void) const
+std::set<Checkable::Ptr> Checkable::GetParents(void) const
{
- std::set<Host::Ptr> result;
-
- BOOST_FOREACH(const Service::Ptr& svc, GetParentServices())
- result.insert(svc->GetHost());
-
- return result;
-}
-
-std::set<Host::Ptr> Service::GetChildHosts(void) const
-{
- std::set<Host::Ptr> result;
-
- BOOST_FOREACH(const Service::Ptr& svc, GetChildServices())
- result.insert(svc->GetHost());
-
- return result;
-}
-
-std::set<Service::Ptr> Service::GetParentServices(void) const
-{
- std::set<Service::Ptr> parents;
+ std::set<Checkable::Ptr> parents;
BOOST_FOREACH(const Dependency::Ptr& dep, GetDependencies()) {
- Service::Ptr service = dep->GetParentService();
+ Checkable::Ptr parent = dep->GetParent();
- if (service)
- parents.insert(service);
+ if (parent)
+ parents.insert(parent);
}
return parents;
}
-std::set<Service::Ptr> Service::GetChildServices(void) const
+std::set<Checkable::Ptr> Checkable::GetChildren(void) const
{
- std::set<Service::Ptr> parents;
+ std::set<Checkable::Ptr> parents;
BOOST_FOREACH(const Dependency::Ptr& dep, GetReverseDependencies()) {
- Service::Ptr service = dep->GetChildService();
+ Checkable::Ptr service = dep->GetChild();
if (service)
parents.insert(service);
return parents;
}
-
static int l_NextDowntimeID = 1;
static boost::mutex l_DowntimeMutex;
static std::map<int, String> l_LegacyDowntimesCache;
-static std::map<String, Service::WeakPtr> l_DowntimesCache;
+static std::map<String, Checkable::WeakPtr> l_DowntimesCache;
static Timer::Ptr l_DowntimesExpireTimer;
-boost::signals2::signal<void (const Service::Ptr&, const Downtime::Ptr&, const String&)> Service::OnDowntimeAdded;
-boost::signals2::signal<void (const Service::Ptr&, const Downtime::Ptr&, const String&)> Service::OnDowntimeRemoved;
-boost::signals2::signal<void (const Service::Ptr&, const Downtime::Ptr&)> Service::OnDowntimeTriggered;
+boost::signals2::signal<void (const Checkable::Ptr&, const Downtime::Ptr&, const String&)> Checkable::OnDowntimeAdded;
+boost::signals2::signal<void (const Checkable::Ptr&, const Downtime::Ptr&, const String&)> Checkable::OnDowntimeRemoved;
+boost::signals2::signal<void (const Checkable::Ptr&, const Downtime::Ptr&)> Checkable::OnDowntimeTriggered;
-int Service::GetNextDowntimeID(void)
+int Checkable::GetNextDowntimeID(void)
{
boost::mutex::scoped_lock lock(l_DowntimeMutex);
return l_NextDowntimeID;
}
-String Service::AddDowntime(const String& author, const String& comment,
+String Checkable::AddDowntime(const String& author, const String& comment,
double startTime, double endTime, bool fixed,
const String& triggeredBy, double duration, const String& scheduledBy,
const String& id, const String& authority)
downtime->SetLegacyId(legacy_id);
if (!triggeredBy.IsEmpty()) {
- Service::Ptr otherOwner = GetOwnerByDowntimeID(triggeredBy);
+ Checkable::Ptr otherOwner = GetOwnerByDowntimeID(triggeredBy);
Dictionary::Ptr otherDowntimes = otherOwner->GetDowntimes();
Downtime::Ptr otherDowntime = otherDowntimes->Get(triggeredBy);
Dictionary::Ptr triggers = otherDowntime->GetTriggers();
return uid;
}
-void Service::RemoveDowntime(const String& id, bool cancelled, const String& authority)
+void Checkable::RemoveDowntime(const String& id, bool cancelled, const String& authority)
{
- Service::Ptr owner = GetOwnerByDowntimeID(id);
+ Checkable::Ptr owner = GetOwnerByDowntimeID(id);
if (!owner)
return;
OnDowntimeRemoved(owner, downtime, authority);
}
-void Service::TriggerDowntimes(void)
+void Checkable::TriggerDowntimes(void)
{
Dictionary::Ptr downtimes = GetDowntimes();
}
}
-void Service::TriggerDowntime(const String& id)
+void Checkable::TriggerDowntime(const String& id)
{
- Service::Ptr owner = GetOwnerByDowntimeID(id);
+ Checkable::Ptr owner = GetOwnerByDowntimeID(id);
Downtime::Ptr downtime = GetDowntimeByID(id);
if (!downtime)
OnDowntimeTriggered(owner, downtime);
}
-String Service::GetDowntimeIDFromLegacyID(int id)
+String Checkable::GetDowntimeIDFromLegacyID(int id)
{
boost::mutex::scoped_lock lock(l_DowntimeMutex);
return it->second;
}
-Service::Ptr Service::GetOwnerByDowntimeID(const String& id)
+Checkable::Ptr Checkable::GetOwnerByDowntimeID(const String& id)
{
boost::mutex::scoped_lock lock(l_DowntimeMutex);
return l_DowntimesCache[id].lock();
}
-Downtime::Ptr Service::GetDowntimeByID(const String& id)
+Downtime::Ptr Checkable::GetDowntimeByID(const String& id)
{
- Service::Ptr owner = GetOwnerByDowntimeID(id);
+ Checkable::Ptr owner = GetOwnerByDowntimeID(id);
if (!owner)
return Downtime::Ptr();
return Downtime::Ptr();
}
-void Service::StartDowntimesExpiredTimer(void)
+void Checkable::StartDowntimesExpiredTimer(void)
{
l_DowntimesExpireTimer = make_shared<Timer>();
l_DowntimesExpireTimer->SetInterval(60);
- l_DowntimesExpireTimer->OnTimerExpired.connect(boost::bind(&Service::DowntimesExpireTimerHandler));
+ l_DowntimesExpireTimer->OnTimerExpired.connect(boost::bind(&Checkable::DowntimesExpireTimerHandler));
l_DowntimesExpireTimer->Start();
}
-void Service::AddDowntimesToCache(void)
+void Checkable::AddDowntimesToCache(void)
{
#ifdef _DEBUG
- Log(LogDebug, "icinga", "Updating Service downtimes cache.");
+ Log(LogDebug, "icinga", "Updating Checkable downtimes cache.");
#endif /* _DEBUG */
Dictionary::Ptr downtimes = GetDowntimes();
}
}
-void Service::RemoveExpiredDowntimes(void)
+void Checkable::RemoveExpiredDowntimes(void)
{
Dictionary::Ptr downtimes = GetDowntimes();
}
}
-void Service::DowntimesExpireTimerHandler(void)
+void Checkable::DowntimesExpireTimerHandler(void)
{
+ BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
+ host->RemoveExpiredDowntimes();
+ }
+
BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
service->RemoveExpiredDowntimes();
}
}
-bool Service::IsInDowntime(void) const
+bool Checkable::IsInDowntime(void) const
{
Dictionary::Ptr downtimes = GetDowntimes();
return false;
}
-int Service::GetDowntimeDepth(void) const
+int Checkable::GetDowntimeDepth(void) const
{
int downtime_depth = 0;
Dictionary::Ptr downtimes = GetDowntimes();
using namespace icinga;
-boost::signals2::signal<void (const Service::Ptr&)> Service::OnEventCommandExecuted;
+boost::signals2::signal<void (const Checkable::Ptr&)> Checkable::OnEventCommandExecuted;
-bool Service::GetEnableEventHandler(void) const
+bool Checkable::GetEnableEventHandler(void) const
{
if (!GetOverrideEnableEventHandler().IsEmpty())
return GetOverrideEnableEventHandler();
return GetEnableEventHandlerRaw();
}
-void Service::SetEnableEventHandler(bool enabled)
+void Checkable::SetEnableEventHandler(bool enabled)
{
SetOverrideEnableEventHandler(enabled);
}
-EventCommand::Ptr Service::GetEventCommand(void) const
+EventCommand::Ptr Checkable::GetEventCommand(void) const
{
String command;
return EventCommand::GetByName(command);
}
-void Service::SetEventCommand(const EventCommand::Ptr& command)
+void Checkable::SetEventCommand(const EventCommand::Ptr& command)
{
SetOverrideEventCommand(command->GetName());
}
-void Service::ExecuteEventHandler(void)
+void Checkable::ExecuteEventHandler(void)
{
- CONTEXT("Executing event handler for service '" + GetShortName() + "' on host '" + GetHost()->GetName() + "'");
+ CONTEXT("Executing event handler for object '" + GetName() + "'");
if (!IcingaApplication::GetInstance()->GetEnableEventHandlers() || !GetEnableEventHandler())
return;
#define FLAPPING_INTERVAL (30 * 60)
-double Service::GetFlappingCurrent(void) const
+double Checkable::GetFlappingCurrent(void) const
{
if (GetFlappingPositive() + GetFlappingNegative() <= 0)
return 0;
return 100 * GetFlappingPositive() / (GetFlappingPositive() + GetFlappingNegative());
}
-bool Service::GetEnableFlapping(void) const
+bool Checkable::GetEnableFlapping(void) const
{
if (!GetOverrideEnableFlapping().IsEmpty())
return GetOverrideEnableFlapping();
return GetEnableFlappingRaw();
}
-void Service::SetEnableFlapping(bool enabled, const String& authority)
+void Checkable::SetEnableFlapping(bool enabled, const String& authority)
{
SetOverrideEnableFlapping(enabled);
OnEnableFlappingChanged(GetSelf(), enabled, authority);
}
-void Service::UpdateFlappingStatus(bool stateChange)
+void Checkable::UpdateFlappingStatus(bool stateChange)
{
double ts, now;
long positive, negative;
SetFlappingNegative(negative);
}
-bool Service::IsFlapping(void) const
+bool Checkable::IsFlapping(void) const
{
if (!GetEnableFlapping() || !IcingaApplication::GetInstance()->GetEnableFlapping())
return false;
using namespace icinga;
-boost::signals2::signal<void (const Notification::Ptr&, const Service::Ptr&, const std::set<User::Ptr>&,
- const NotificationType&, const CheckResult::Ptr&, const String&, const String&)> Service::OnNotificationSentToAllUsers;
-boost::signals2::signal<void (const Notification::Ptr&, const Service::Ptr&, const std::set<User::Ptr>&,
- const NotificationType&, const CheckResult::Ptr&, const String&, const String&)> Service::OnNotificationSendStart;
-boost::signals2::signal<void (const Notification::Ptr&, const Service::Ptr&, const User::Ptr&,
- const NotificationType&, const CheckResult::Ptr&, const String&, const String&, const String&)> Service::OnNotificationSentToUser;
-
-void Service::ResetNotificationNumbers(void)
+boost::signals2::signal<void (const Notification::Ptr&, const Checkable::Ptr&, const std::set<User::Ptr>&,
+ const NotificationType&, const CheckResult::Ptr&, const String&, const String&)> Checkable::OnNotificationSentToAllUsers;
+boost::signals2::signal<void (const Notification::Ptr&, const Checkable::Ptr&, const std::set<User::Ptr>&,
+ const NotificationType&, const CheckResult::Ptr&, const String&, const String&)> Checkable::OnNotificationSendStart;
+boost::signals2::signal<void (const Notification::Ptr&, const Checkable::Ptr&, const User::Ptr&,
+ const NotificationType&, const CheckResult::Ptr&, const String&, const String&, const String&)> Checkable::OnNotificationSentToUser;
+
+void Checkable::ResetNotificationNumbers(void)
{
BOOST_FOREACH(const Notification::Ptr& notification, GetNotifications()) {
ObjectLock olock(notification);
}
}
-void Service::SendNotifications(NotificationType type, const CheckResult::Ptr& cr, const String& author, const String& text)
+void Checkable::SendNotifications(NotificationType type, const CheckResult::Ptr& cr, const String& author, const String& text)
{
- CONTEXT("Sending notifications for service '" + GetShortName() + "' on host '" + GetHost()->GetName() + "'");
+ CONTEXT("Sending notifications for object '" + GetName() + "'");
bool force = GetForceNextNotification();
SetForceNextNotification(false);
}
- Log(LogInformation, "icinga", "Sending notifications for service '" + GetName() + "'");
+ Log(LogInformation, "icinga", "Sending notifications for object '" + GetName() + "'");
std::set<Notification::Ptr> notifications = GetNotifications();
if (notifications.empty())
- Log(LogInformation, "icinga", "Service '" + GetName() + "' does not have any notifications.");
+ Log(LogInformation, "icinga", "Checkable '" + GetName() + "' does not have any notifications.");
- Log(LogDebug, "icinga", "Service '" + GetName() + "' has " + Convert::ToString(notifications.size()) + " notification(s).");
+ Log(LogDebug, "icinga", "Checkable '" + GetName() + "' has " + Convert::ToString(notifications.size()) + " notification(s).");
BOOST_FOREACH(const Notification::Ptr& notification, notifications) {
try {
}
}
-std::set<Notification::Ptr> Service::GetNotifications(void) const
+std::set<Notification::Ptr> Checkable::GetNotifications(void) const
{
return m_Notifications;
}
-void Service::AddNotification(const Notification::Ptr& notification)
+void Checkable::AddNotification(const Notification::Ptr& notification)
{
m_Notifications.insert(notification);
}
-void Service::RemoveNotification(const Notification::Ptr& notification)
+void Checkable::RemoveNotification(const Notification::Ptr& notification)
{
m_Notifications.erase(notification);
}
-bool Service::GetEnableNotifications(void) const
+bool Checkable::GetEnableNotifications(void) const
{
if (!GetOverrideEnableNotifications().IsEmpty())
return GetOverrideEnableNotifications();
return GetEnableNotificationsRaw();
}
-void Service::SetEnableNotifications(bool enabled, const String& authority)
+void Checkable::SetEnableNotifications(bool enabled, const String& authority)
{
SetOverrideEnableNotifications(enabled);
OnEnableNotificationsChanged(GetSelf(), enabled, authority);
}
-bool Service::GetForceNextNotification(void) const
+bool Checkable::GetForceNextNotification(void) const
{
return GetForceNextNotificationRaw();
}
-void Service::SetForceNextNotification(bool forced, const String& authority)
+void Checkable::SetForceNextNotification(bool forced, const String& authority)
{
SetForceNextNotificationRaw(forced);
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+#include "icinga/service.h"
+#include "icinga/servicegroup.h"
+#include "icinga/checkcommand.h"
+#include "icinga/icingaapplication.h"
+#include "icinga/macroprocessor.h"
+#include "icinga/pluginutility.h"
+#include "icinga/dependency.h"
+#include "config/configitembuilder.h"
+#include "base/dynamictype.h"
+#include "base/objectlock.h"
+#include "base/convert.h"
+#include "base/utility.h"
+#include "base/initialize.h"
+#include <boost/foreach.hpp>
+#include <boost/bind/apply.hpp>
+
+using namespace icinga;
+
+REGISTER_TYPE(Checkable);
+
+INITIALIZE_ONCE(&Checkable::StartDowntimesExpiredTimer);
+
+boost::signals2::signal<void (const Checkable::Ptr&, const String&, const String&, AcknowledgementType, double, const String&)> Checkable::OnAcknowledgementSet;
+boost::signals2::signal<void (const Checkable::Ptr&, const String&)> Checkable::OnAcknowledgementCleared;
+
+Checkable::Checkable(void)
+ : m_CheckRunning(false)
+{ }
+
+void Checkable::Start(void)
+{
+ double now = Utility::GetTime();
+
+ if (GetNextCheck() < now + 300)
+ UpdateNextCheck();
+
+ DynamicObject::Start();
+}
+
+void Checkable::OnConfigLoaded(void)
+{
+ DynamicObject::OnConfigLoaded();
+
+ SetSchedulingOffset(Utility::Random());
+}
+
+void Checkable::OnStateLoaded(void)
+{
+ AddDowntimesToCache();
+ AddCommentsToCache();
+
+ std::vector<String> ids;
+ Dictionary::Ptr downtimes = GetDowntimes();
+
+ {
+ ObjectLock dlock(downtimes);
+ BOOST_FOREACH(const Dictionary::Pair& kv, downtimes) {
+ Downtime::Ptr downtime = kv.second;
+
+ if (downtime->GetScheduledBy().IsEmpty())
+ continue;
+
+ ids.push_back(kv.first);
+ }
+ }
+
+ BOOST_FOREACH(const String& id, ids) {
+ RemoveDowntime(id, true);
+ }
+}
+
+AcknowledgementType Checkable::GetAcknowledgement(void)
+{
+ ASSERT(OwnsLock());
+
+ AcknowledgementType avalue = static_cast<AcknowledgementType>(GetAcknowledgementRaw());
+
+ if (avalue != AcknowledgementNone) {
+ double expiry = GetAcknowledgementExpiry();
+
+ if (expiry != 0 && expiry < Utility::GetTime()) {
+ avalue = AcknowledgementNone;
+ ClearAcknowledgement();
+ }
+ }
+
+ return avalue;
+}
+
+bool Checkable::IsAcknowledged(void)
+{
+ return GetAcknowledgement() != AcknowledgementNone;
+}
+
+void Checkable::AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry, const String& authority)
+{
+ {
+ ObjectLock olock(this);
+
+ SetAcknowledgementRaw(type);
+ SetAcknowledgementExpiry(expiry);
+ }
+
+ OnNotificationsRequested(GetSelf(), NotificationAcknowledgement, GetLastCheckResult(), author, comment);
+
+ OnAcknowledgementSet(GetSelf(), author, comment, type, expiry, authority);
+}
+
+void Checkable::ClearAcknowledgement(const String& authority)
+{
+ ASSERT(OwnsLock());
+
+ SetAcknowledgementRaw(AcknowledgementNone);
+ SetAcknowledgementExpiry(0);
+
+ OnAcknowledgementCleared(GetSelf(), authority);
+}
+
+bool Checkable::GetEnablePerfdata(void) const
+{
+ if (!GetOverrideEnablePerfdata().IsEmpty())
+ return GetOverrideEnablePerfdata();
+ else
+ return GetEnablePerfdataRaw();
+}
+
+void Checkable::SetEnablePerfdata(bool enabled, const String& authority)
+{
+ SetOverrideEnablePerfdata(enabled);
+}
+
+int Checkable::GetModifiedAttributes(void) const
+{
+ int attrs = 0;
+
+ if (!GetOverrideEnableNotifications().IsEmpty())
+ attrs |= ModAttrNotificationsEnabled;
+
+ if (!GetOverrideEnableActiveChecks().IsEmpty())
+ attrs |= ModAttrActiveChecksEnabled;
+
+ if (!GetOverrideEnablePassiveChecks().IsEmpty())
+ attrs |= ModAttrPassiveChecksEnabled;
+
+ if (!GetOverrideEnableFlapping().IsEmpty())
+ attrs |= ModAttrFlapDetectionEnabled;
+
+ if (!GetOverrideEnableEventHandler().IsEmpty())
+ attrs |= ModAttrEventHandlerEnabled;
+
+ if (!GetOverrideEnablePerfdata().IsEmpty())
+ attrs |= ModAttrPerformanceDataEnabled;
+
+ if (!GetOverrideCheckInterval().IsEmpty())
+ attrs |= ModAttrNormalCheckInterval;
+
+ if (!GetOverrideRetryInterval().IsEmpty())
+ attrs |= ModAttrRetryCheckInterval;
+
+ if (!GetOverrideEventCommand().IsEmpty())
+ attrs |= ModAttrEventHandlerCommand;
+
+ if (!GetOverrideCheckCommand().IsEmpty())
+ attrs |= ModAttrCheckCommand;
+
+ if (!GetOverrideMaxCheckAttempts().IsEmpty())
+ attrs |= ModAttrMaxCheckAttempts;
+
+ if (!GetOverrideCheckPeriod().IsEmpty())
+ attrs |= ModAttrCheckTimeperiod;
+
+ // TODO: finish
+
+ return attrs;
+}
+
+void Checkable::SetModifiedAttributes(int flags)
+{
+ if ((flags & ModAttrNotificationsEnabled) == 0)
+ SetOverrideEnableNotifications(Empty);
+
+ if ((flags & ModAttrActiveChecksEnabled) == 0)
+ SetOverrideEnableActiveChecks(Empty);
+
+ if ((flags & ModAttrPassiveChecksEnabled) == 0)
+ SetOverrideEnablePassiveChecks(Empty);
+
+ if ((flags & ModAttrFlapDetectionEnabled) == 0)
+ SetOverrideEnableFlapping(Empty);
+
+ if ((flags & ModAttrEventHandlerEnabled) == 0)
+ SetOverrideEnableEventHandler(Empty);
+
+ if ((flags & ModAttrPerformanceDataEnabled) == 0)
+ SetOverrideEnablePerfdata(Empty);
+
+ if ((flags & ModAttrNormalCheckInterval) == 0)
+ SetOverrideCheckInterval(Empty);
+
+ if ((flags & ModAttrRetryCheckInterval) == 0)
+ SetOverrideRetryInterval(Empty);
+
+ if ((flags & ModAttrEventHandlerCommand) == 0)
+ SetOverrideEventCommand(Empty);
+
+ if ((flags & ModAttrCheckCommand) == 0)
+ SetOverrideCheckCommand(Empty);
+
+ if ((flags & ModAttrMaxCheckAttempts) == 0)
+ SetOverrideMaxCheckAttempts(Empty);
+
+ if ((flags & ModAttrCheckTimeperiod) == 0)
+ SetOverrideCheckPeriod(Empty);
+}
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+#ifndef CHECKABLE_H
+#define CHECKABLE_H
+
+#include "icinga/i2-icinga.h"
+#include "icinga/checkable.th"
+#include "icinga/macroresolver.h"
+#include "icinga/timeperiod.h"
+#include "icinga/notification.h"
+#include "icinga/comment.h"
+#include "icinga/downtime.h"
+#include "base/i2-base.h"
+#include "base/array.h"
+#include <boost/signals2.hpp>
+#include <boost/thread/once.hpp>
+
+namespace icinga
+{
+
+/**
+ * The state of service flapping.
+ *
+ * @ingroup icinga
+ */
+enum FlappingState
+{
+ FlappingStarted = 0,
+ FlappingDisabled = 1,
+ FlappingStopped = 2,
+ FlappingEnabled = 3
+};
+
+/**
+ * Modified attributes.
+ *
+ * @ingroup icinga
+ */
+enum ModifiedAttributeType
+{
+ ModAttrNotificationsEnabled = 1,
+ ModAttrActiveChecksEnabled = 2,
+ ModAttrPassiveChecksEnabled = 4,
+ ModAttrEventHandlerEnabled = 8,
+ ModAttrFlapDetectionEnabled = 16,
+ ModAttrFailurePredictionEnabled = 32,
+ ModAttrPerformanceDataEnabled = 64,
+ ModAttrObsessiveHandlerEnabled = 128,
+ ModAttrEventHandlerCommand = 256,
+ ModAttrCheckCommand = 512,
+ ModAttrNormalCheckInterval = 1024,
+ ModAttrRetryCheckInterval = 2048,
+ ModAttrMaxCheckAttempts = 4096,
+ ModAttrFreshnessChecksEnabled = 8192,
+ ModAttrCheckTimeperiod = 16384,
+ ModAttrCustomVariable = 32768,
+ ModAttrNotificationTimeperiod = 65536
+};
+
+/**
+ * @ingroup icinga
+ */
+enum DependencyType
+{
+ DependencyState,
+ DependencyCheckExecution,
+ DependencyNotification
+};
+
+class CheckCommand;
+class EventCommand;
+class Dependency;
+
+/**
+ * An Icinga service.
+ *
+ * @ingroup icinga
+ */
+class I2_ICINGA_API Checkable : public ObjectImpl<Checkable>
+{
+public:
+ DECLARE_PTR_TYPEDEFS(Checkable);
+ DECLARE_TYPENAME(Checkable);
+
+ Checkable(void);
+
+ std::set<Checkable::Ptr> GetParents(void) const;
+ std::set<Checkable::Ptr> GetChildren(void) const;
+
+ //bool IsHostCheck(void) const;
+
+ bool IsReachable(DependencyType dt = DependencyState, shared_ptr<Dependency> *failedDependency = NULL, int rstack = 0) const;
+
+ AcknowledgementType GetAcknowledgement(void);
+
+ void AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry = 0, const String& authority = String());
+ void ClearAcknowledgement(const String& authority = String());
+
+ /* Checks */
+ shared_ptr<CheckCommand> GetCheckCommand(void) const;
+ void SetCheckCommand(const shared_ptr<CheckCommand>& command);
+
+ TimePeriod::Ptr GetCheckPeriod(void) const;
+ void SetCheckPeriod(const TimePeriod::Ptr& tp);
+
+ double GetCheckInterval(void) const;
+ void SetCheckInterval(double interval);
+
+ double GetRetryInterval(void) const;
+ void SetRetryInterval(double interval);
+
+ int GetMaxCheckAttempts(void) const;
+ void SetMaxCheckAttempts(int attempts);
+
+ long GetSchedulingOffset(void);
+ void SetSchedulingOffset(long offset);
+
+ void SetNextCheck(double nextCheck, const String& authority = String());
+ double GetNextCheck(void);
+ void UpdateNextCheck(void);
+
+ bool HasBeenChecked(void) const;
+
+ double GetLastCheck(void) const;
+
+ bool GetEnableActiveChecks(void) const;
+ void SetEnableActiveChecks(bool enabled, const String& authority = String());
+
+ bool GetEnablePassiveChecks(void) const;
+ void SetEnablePassiveChecks(bool enabled, const String& authority = String());
+
+ bool GetForceNextCheck(void) const;
+ void SetForceNextCheck(bool forced, const String& authority = String());
+
+ static void UpdateStatistics(const CheckResult::Ptr& cr);
+
+ void ExecuteCheck(void);
+ void ProcessCheckResult(const CheckResult::Ptr& cr, const String& authority = String());
+
+ int GetModifiedAttributes(void) const;
+ void SetModifiedAttributes(int flags);
+
+ static double CalculateExecutionTime(const CheckResult::Ptr& cr);
+ static double CalculateLatency(const CheckResult::Ptr& cr);
+
+ static boost::signals2::signal<void (const Checkable::Ptr&, double, const String&)> OnNextCheckChanged;
+ static boost::signals2::signal<void (const Checkable::Ptr&, bool, const String&)> OnForceNextCheckChanged;
+ static boost::signals2::signal<void (const Checkable::Ptr&, bool, const String&)> OnForceNextNotificationChanged;
+ static boost::signals2::signal<void (const Checkable::Ptr&, bool, const String&)> OnEnableActiveChecksChanged;
+ static boost::signals2::signal<void (const Checkable::Ptr&, bool, const String&)> OnEnablePassiveChecksChanged;
+ static boost::signals2::signal<void (const Checkable::Ptr&, bool, const String&)> OnEnableNotificationsChanged;
+ static boost::signals2::signal<void (const Checkable::Ptr&, bool, const String&)> OnEnableFlappingChanged;
+ static boost::signals2::signal<void (const Checkable::Ptr&, const CheckResult::Ptr&, const String&)> OnNewCheckResult;
+ static boost::signals2::signal<void (const Checkable::Ptr&, const CheckResult::Ptr&, StateType, const String&)> OnStateChange;
+ static boost::signals2::signal<void (const Checkable::Ptr&, NotificationType, const CheckResult::Ptr&,
+ const String&, const String&)> OnNotificationsRequested;
+ static boost::signals2::signal<void (const Notification::Ptr&, const Checkable::Ptr&, const std::set<User::Ptr>&,
+ const NotificationType&, const CheckResult::Ptr&, const String&,
+ const String&)> OnNotificationSendStart;
+ static boost::signals2::signal<void (const Notification::Ptr&, const Checkable::Ptr&, const User::Ptr&,
+ const NotificationType&, const CheckResult::Ptr&, const String&,
+ const String&, const String&)> OnNotificationSentToUser;
+ static boost::signals2::signal<void (const Notification::Ptr&, const Checkable::Ptr&, const std::set<User::Ptr>&,
+ const NotificationType&, const CheckResult::Ptr&, const String&,
+ const String&)> OnNotificationSentToAllUsers;
+ static boost::signals2::signal<void (const Checkable::Ptr&, const Comment::Ptr&, const String&)> OnCommentAdded;
+ static boost::signals2::signal<void (const Checkable::Ptr&, const Comment::Ptr&, const String&)> OnCommentRemoved;
+ static boost::signals2::signal<void (const Checkable::Ptr&, const Downtime::Ptr&, const String&)> OnDowntimeAdded;
+ static boost::signals2::signal<void (const Checkable::Ptr&, const Downtime::Ptr&, const String&)> OnDowntimeRemoved;
+ static boost::signals2::signal<void (const Checkable::Ptr&, FlappingState)> OnFlappingChanged;
+ static boost::signals2::signal<void (const Checkable::Ptr&, const Downtime::Ptr&)> OnDowntimeTriggered;
+ static boost::signals2::signal<void (const Checkable::Ptr&, const String&, const String&, AcknowledgementType,
+ double, const String&)> OnAcknowledgementSet;
+ static boost::signals2::signal<void (const Checkable::Ptr&, const String&)> OnAcknowledgementCleared;
+ static boost::signals2::signal<void (const Checkable::Ptr&)> OnEventCommandExecuted;
+
+ /* Downtimes */
+ static int GetNextDowntimeID(void);
+
+ int GetDowntimeDepth(void) const;
+
+ String AddDowntime(const String& author, const String& comment,
+ double startTime, double endTime, bool fixed,
+ const String& triggeredBy, double duration,
+ const String& scheduledBy = String(), const String& id = String(),
+ const String& authority = String());
+
+ static void RemoveDowntime(const String& id, bool cancelled, const String& = String());
+
+ void TriggerDowntimes(void);
+ static void TriggerDowntime(const String& id);
+
+ static String GetDowntimeIDFromLegacyID(int id);
+ static Checkable::Ptr GetOwnerByDowntimeID(const String& id);
+ static Downtime::Ptr GetDowntimeByID(const String& id);
+
+ static void StartDowntimesExpiredTimer(void);
+
+ bool IsInDowntime(void) const;
+ bool IsAcknowledged(void);
+
+ /* Comments */
+ static int GetNextCommentID(void);
+
+ String AddComment(CommentType entryType, const String& author,
+ const String& text, double expireTime, const String& id = String(), const String& authority = String());
+
+ void RemoveAllComments(void);
+ void RemoveCommentsByType(int type);
+ static void RemoveComment(const String& id, const String& authority = String());
+
+ static String GetCommentIDFromLegacyID(int id);
+ static Checkable::Ptr GetOwnerByCommentID(const String& id);
+ static Comment::Ptr GetCommentByID(const String& id);
+
+ /* Notifications */
+ bool GetEnableNotifications(void) const;
+ void SetEnableNotifications(bool enabled, const String& authority = String());
+
+ void SendNotifications(NotificationType type, const CheckResult::Ptr& cr, const String& author = "", const String& text = "");
+
+ std::set<Notification::Ptr> GetNotifications(void) const;
+ void AddNotification(const Notification::Ptr& notification);
+ void RemoveNotification(const Notification::Ptr& notification);
+
+ void SetForceNextNotification(bool force, const String& authority = String());
+ bool GetForceNextNotification(void) const;
+
+ void ResetNotificationNumbers(void);
+
+ /* Event Handler */
+ void ExecuteEventHandler(void);
+
+ shared_ptr<EventCommand> GetEventCommand(void) const;
+ void SetEventCommand(const shared_ptr<EventCommand>& command);
+
+ bool GetEnableEventHandler(void) const;
+ void SetEnableEventHandler(bool enabled);
+
+ /* Flapping Detection */
+ double GetFlappingCurrent(void) const;
+
+ bool GetEnableFlapping(void) const;
+ void SetEnableFlapping(bool enabled, const String& authority = String());
+
+ bool IsFlapping(void) const;
+ void UpdateFlappingStatus(bool stateChange);
+
+ /* Performance data */
+ bool GetEnablePerfdata(void) const;
+ void SetEnablePerfdata(bool enabled, const String& authority = String());
+
+ /* Dependencies */
+ void AddDependency(const shared_ptr<Dependency>& dep);
+ void RemoveDependency(const shared_ptr<Dependency>& dep);
+ std::set<shared_ptr<Dependency> > GetDependencies(void) const;
+
+ void AddReverseDependency(const shared_ptr<Dependency>& dep);
+ void RemoveReverseDependency(const shared_ptr<Dependency>& dep);
+ std::set<shared_ptr<Dependency> > GetReverseDependencies(void) const;
+
+protected:
+ virtual void Start(void);
+
+ virtual void OnConfigLoaded(void);
+ virtual void OnStateLoaded(void);
+
+private:
+ bool m_CheckRunning;
+ long m_SchedulingOffset;
+
+ /* Downtimes */
+ static void DowntimesExpireTimerHandler(void);
+ void RemoveExpiredDowntimes(void);
+ void AddDowntimesToCache(void);
+
+ /* Comments */
+ static void CommentsExpireTimerHandler(void);
+ void RemoveExpiredComments(void);
+ void AddCommentsToCache(void);
+
+ /* Notifications */
+ std::set<Notification::Ptr> m_Notifications;
+
+ /* Dependencies */
+ mutable boost::mutex m_DependencyMutex;
+ std::set<shared_ptr<Dependency> > m_Dependencies;
+ std::set<shared_ptr<Dependency> > m_ReverseDependencies;
+};
+
+}
+
+#endif /* CHECKABLE_H */
--- /dev/null
+#include "icinga/icingaapplication.h"
+#include "base/dynamicobject.h"
+
+namespace icinga
+{
+
+code {{{
+/**
+ * The acknowledgement type of a service.
+ *
+ * @ingroup icinga
+ */
+enum AcknowledgementType
+{
+ AcknowledgementNone = 0,
+ AcknowledgementNormal = 1,
+ AcknowledgementSticky = 2
+};
+}}}
+
+abstract class Checkable : DynamicObject
+{
+ [config] Array::Ptr groups;
+ [config, protected] String check_command (CheckCommandRaw);
+ [config] int max_check_attempts (MaxCheckAttemptsRaw) {
+ default {{{ return 3; }}}
+ };
+ [config, protected] String check_period (CheckPeriodRaw);
+ [config] double check_interval (CheckIntervalRaw) {
+ default {{{ return 5 * 60; }}}
+ };
+ [config] double retry_interval (RetryIntervalRaw) {
+ default {{{ return 60; }}}
+ };
+ [config] String event_command (EventCommandRaw);
+ [config] bool volatile;
+ [config] double flapping_threshold {
+ default {{{ return 30; }}}
+ };
+ [config] bool enable_active_checks (EnableActiveChecksRaw) {
+ default {{{ return true; }}}
+ };
+ [config] bool enable_passive_checks (EnablePassiveChecksRaw) {
+ default {{{ return true; }}}
+ };
+ [config] bool enable_event_handler (EnableEventHandlerRaw) {
+ default {{{ return true; }}}
+ };
+ [config] bool enable_notifications (EnableNotificationsRaw) {
+ default {{{ return true; }}}
+ };
+ [config] bool enable_flapping (EnableFlappingRaw) {
+ default {{{ return true; }}}
+ };
+ [config] bool enable_perfdata (EnablePerfdataRaw) {
+ default {{{ return true; }}}
+ };
+
+ [state] double next_check (NextCheckRaw);
+ [state] int check_attempt {
+ default {{{ return 1; }}}
+ };
+ [state, enum] ServiceState state_raw {
+ default {{{ return StateUnknown; }}}
+ };
+ [state, enum] StateType state_type {
+ default {{{ return StateTypeSoft; }}}
+ };
+ [state, enum] ServiceState last_state_raw {
+ default {{{ return StateUnknown; }}}
+ };
+ [state, enum] ServiceState last_hard_state_raw {
+ default {{{ return StateUnknown; }}}
+ };
+ [state, enum] StateType last_state_type {
+ default {{{ return StateTypeSoft; }}}
+ };
+ [state] bool last_reachable {
+ default {{{ return true; }}}
+ };
+ [state] CheckResult::Ptr last_check_result;
+ [state] double last_state_change {
+ default {{{ return Application::GetStartTime(); }}}
+ };
+ [state] double last_hard_state_change {
+ default {{{ return Application::GetStartTime(); }}}
+ };
+ [state] double last_state_ok (LastStateOK);
+ [state] double last_state_warning;
+ [state] double last_state_critical;
+ [state] double last_state_unknown;
+ [state] double last_state_unreachable;
+ [state] bool last_in_downtime;
+ [state] bool force_next_check (ForceNextCheckRaw);
+ [state] int acknowledgement (AcknowledgementRaw) {
+ default {{{ return AcknowledgementNone; }}}
+ };
+ [state] double acknowledgement_expiry;
+ [state] Dictionary::Ptr comments {
+ default {{{ return make_shared<Dictionary>(); }}}
+ };
+ [state] Dictionary::Ptr downtimes {
+ default {{{ return make_shared<Dictionary>(); }}}
+ };
+ [state] bool force_next_notification (ForceNextNotificationRaw);
+ [state] int flapping_positive;
+ [state] int flapping_negative;
+ [state] double flapping_last_change;
+ [state] Value override_enable_notifications;
+ [state] Value override_enable_active_checks;
+ [state] Value override_enable_passive_checks;
+ [state] Value override_enable_flapping;
+ [state] Value override_enable_perfdata;
+ [state] Value override_check_interval;
+ [state] Value override_retry_interval;
+ [state] Value override_enable_event_handler;
+ [state] Value override_event_command;
+ [state] Value override_check_command;
+ [state] Value override_max_check_attempts;
+ [state] Value override_check_period;
+};
+
+}
REGISTER_TYPE(CheckCommand);
-void CheckCommand::Execute(const Service::Ptr& service, const CheckResult::Ptr& cr)
+void CheckCommand::Execute(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
{
std::vector<Value> arguments;
- arguments.push_back(service);
+ arguments.push_back(checkable);
arguments.push_back(cr);
InvokeMethod("execute", arguments);
}
DECLARE_PTR_TYPEDEFS(CheckCommand);
DECLARE_TYPENAME(CheckCommand);
- virtual void Execute(const Service::Ptr& service, const CheckResult::Ptr& cr);
+ virtual void Execute(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
};
}
#include "base/dynamictype.h"
#include "base/statsfunction.h"
#include <boost/foreach.hpp>
-#include <boost/tuple/tuple.hpp>
using namespace icinga;
if (host->GetState() == HostUnreachable)
hs.hosts_unreachable++;
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc) {
- hs.hosts_pending++;
- continue; /* skip host service check counting */
- }
-
- if (!hc->GetLastCheckResult())
+ if (!host->GetLastCheckResult())
hs.hosts_pending++;
- if (hc->IsFlapping())
+ if (host->IsFlapping())
hs.hosts_flapping++;
- if (hc->IsInDowntime())
+ if (host->IsInDowntime())
hs.hosts_in_downtime++;
- if (hc->IsAcknowledged())
+ if (host->IsAcknowledged())
hs.hosts_acknowledged++;
}
String name;
Value ret;
- BOOST_FOREACH(boost::tie(name, boost::tuples::ignore), StatsFunctionRegistry::GetInstance()->GetItems()) {
+ BOOST_FOREACH(tie(name, boost::tuples::ignore), StatsFunctionRegistry::GetInstance()->GetItems()) {
StatsFunction::Ptr func = StatsFunctionRegistry::GetInstance()->GetItem(name);
if (!func)
{
ASSERT(host->OwnsLock());
- Service::Ptr service = host->GetCheckService();
-
- if (!service)
- return 0;
-
- unsigned long notification_state_filter = GetServiceNotificationStateFilter(service);
+ unsigned long notification_state_filter = GetCheckableNotificationStateFilter(host);
if (notification_state_filter & (1<<StateCritical) ||
notification_state_filter & (1<<StateWarning))
{
ASSERT(host->OwnsLock());
- Service::Ptr service = host->GetCheckService();
-
- if (!service)
- return 0;
-
- unsigned long notification_state_filter = GetServiceNotificationStateFilter(service);
+ unsigned long notification_state_filter = GetCheckableNotificationStateFilter(host);
if (notification_state_filter & (1<<StateUnknown))
return 1;
}
/* service */
-int CompatUtility::GetServiceCurrentState(const Service::Ptr& service)
-{
- ASSERT(service->OwnsLock());
-
- int state = service->GetState();
-
- if (state > StateUnknown)
- return StateUnknown;
-
- return state;
-}
-
-int CompatUtility::GetServiceShouldBeScheduled(const Service::Ptr& service)
+int CompatUtility::GetCheckableShouldBeScheduled(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- return (service->GetEnableActiveChecks() ? 1 : 0);
+ return (checkable->GetEnableActiveChecks() ? 1 : 0);
}
-int CompatUtility::GetServiceCheckType(const Service::Ptr& service)
+int CompatUtility::GetCheckableCheckType(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- return (service->GetEnableActiveChecks() ? 0 : 1);
+ return (checkable->GetEnableActiveChecks() ? 0 : 1);
}
-double CompatUtility::GetServiceCheckInterval(const Service::Ptr& service)
+double CompatUtility::GetCheckableCheckInterval(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- return service->GetCheckInterval() / 60.0;
+ return checkable->GetCheckInterval() / 60.0;
}
-double CompatUtility::GetServiceRetryInterval(const Service::Ptr& service)
+double CompatUtility::GetCheckableRetryInterval(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- return service->GetRetryInterval() / 60.0;
+ return checkable->GetRetryInterval() / 60.0;
}
-String CompatUtility::GetServiceCheckPeriod(const Service::Ptr& service)
+String CompatUtility::GetCheckableCheckPeriod(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- TimePeriod::Ptr check_period = service->GetCheckPeriod();
+ TimePeriod::Ptr check_period = checkable->GetCheckPeriod();
if (check_period)
return check_period->GetName();
else
return "24x7";
}
-int CompatUtility::GetServiceHasBeenChecked(const Service::Ptr& service)
+int CompatUtility::GetCheckableHasBeenChecked(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- return (service->GetLastCheckResult() ? 1 : 0);
+ return (checkable->GetLastCheckResult() ? 1 : 0);
}
-int CompatUtility::GetServiceProblemHasBeenAcknowledged(const Service::Ptr& service)
+int CompatUtility::GetCheckableProblemHasBeenAcknowledged(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- return (service->GetAcknowledgement() != AcknowledgementNone ? 1 : 0);
+ return (checkable->GetAcknowledgement() != AcknowledgementNone ? 1 : 0);
}
-int CompatUtility::GetServiceAcknowledgementType(const Service::Ptr& service)
+int CompatUtility::GetCheckableAcknowledgementType(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- return static_cast<int>(service->GetAcknowledgement());
+ return static_cast<int>(checkable->GetAcknowledgement());
}
-int CompatUtility::GetServicePassiveChecksEnabled(const Service::Ptr& service)
+int CompatUtility::GetCheckablePassiveChecksEnabled(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- return (service->GetEnablePassiveChecks() ? 1 : 0);
+ return (checkable->GetEnablePassiveChecks() ? 1 : 0);
}
-int CompatUtility::GetServiceActiveChecksEnabled(const Service::Ptr& service)
+int CompatUtility::GetCheckableActiveChecksEnabled(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- return (service->GetEnableActiveChecks() ? 1 : 0);
+ return (checkable->GetEnableActiveChecks() ? 1 : 0);
}
-int CompatUtility::GetServiceEventHandlerEnabled(const Service::Ptr& service)
+int CompatUtility::GetCheckableEventHandlerEnabled(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- return (service->GetEventCommand() ? 1 : 0);
+ return (checkable->GetEventCommand() ? 1 : 0);
}
-int CompatUtility::GetServiceFlapDetectionEnabled(const Service::Ptr& service)
+int CompatUtility::GetCheckableFlapDetectionEnabled(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- return (service->GetEnableFlapping() ? 1 : 0);
+ return (checkable->GetEnableFlapping() ? 1 : 0);
}
-int CompatUtility::GetServiceIsFlapping(const Service::Ptr& service)
+int CompatUtility::GetCheckableIsFlapping(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- return (service->IsFlapping() ? 1 : 0);
+ return (checkable->IsFlapping() ? 1 : 0);
}
-String CompatUtility::GetServicePercentStateChange(const Service::Ptr& service)
+String CompatUtility::GetCheckablePercentStateChange(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- return Convert::ToString(service->GetFlappingCurrent());
+ return Convert::ToString(checkable->GetFlappingCurrent());
}
-int CompatUtility::GetServiceProcessPerformanceData(const Service::Ptr& service)
+int CompatUtility::GetCheckableProcessPerformanceData(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- return (service->GetEnablePerfdata() ? 1 : 0);
+ return (checkable->GetEnablePerfdata() ? 1 : 0);
}
-String CompatUtility::GetServiceEventHandler(const Service::Ptr& service)
+String CompatUtility::GetCheckableEventHandler(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
String event_command_str;
- EventCommand::Ptr eventcommand = service->GetEventCommand();
+ EventCommand::Ptr eventcommand = checkable->GetEventCommand();
if (eventcommand)
event_command_str = eventcommand->GetName();
return event_command_str;
}
-String CompatUtility::GetServiceCheckCommand(const Service::Ptr& service)
+String CompatUtility::GetCheckableCheckCommand(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
String check_command_str;
- CheckCommand::Ptr checkcommand = service->GetCheckCommand();
+ CheckCommand::Ptr checkcommand = checkable->GetCheckCommand();
if (checkcommand)
check_command_str = checkcommand->GetName();
return check_command_str;
}
-int CompatUtility::GetServiceIsVolatile(const Service::Ptr& service)
+int CompatUtility::GetCheckableIsVolatile(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- return (service->GetVolatile() ? 1 : 0);
+ return (checkable->GetVolatile() ? 1 : 0);
}
-double CompatUtility::GetServiceLowFlapThreshold(const Service::Ptr& service)
+double CompatUtility::GetCheckableLowFlapThreshold(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- return service->GetFlappingThreshold();
+ return checkable->GetFlappingThreshold();
}
-double CompatUtility::GetServiceHighFlapThreshold(const Service::Ptr& service)
+double CompatUtility::GetCheckableHighFlapThreshold(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- return service->GetFlappingThreshold();
+ return checkable->GetFlappingThreshold();
}
-int CompatUtility::GetServiceFreshnessChecksEnabled(const Service::Ptr& service)
+int CompatUtility::GetCheckableFreshnessChecksEnabled(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- return (service->GetCheckInterval() > 0 ? 1 : 0);
+ return (checkable->GetCheckInterval() > 0 ? 1 : 0);
}
-int CompatUtility::GetServiceFreshnessThreshold(const Service::Ptr& service)
+int CompatUtility::GetCheckableFreshnessThreshold(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- return static_cast<int>(service->GetCheckInterval());
+ return static_cast<int>(checkable->GetCheckInterval());
}
-double CompatUtility::GetServiceStaleness(const Service::Ptr& service)
+double CompatUtility::GetCheckableStaleness(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- if (service->HasBeenChecked() && service->GetLastCheck() > 0)
- return (Utility::GetTime() - service->GetLastCheck()) / (service->GetCheckInterval() * 3600);
+ if (checkable->HasBeenChecked() && checkable->GetLastCheck() > 0)
+ return (Utility::GetTime() - checkable->GetLastCheck()) / (checkable->GetCheckInterval() * 3600);
return 0.0;
}
-int CompatUtility::GetServiceIsAcknowledged(const Service::Ptr& service)
+int CompatUtility::GetCheckableIsAcknowledged(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- return (service->IsAcknowledged() ? 1 : 0);
+ return (checkable->IsAcknowledged() ? 1 : 0);
}
-int CompatUtility::GetServiceNoMoreNotifications(const Service::Ptr& service)
+int CompatUtility::GetCheckableNoMoreNotifications(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- if (CompatUtility::GetServiceNotificationNotificationInterval(service) == 0 && !service->GetVolatile())
+ if (CompatUtility::GetCheckableNotificationNotificationInterval(checkable) == 0 && !checkable->GetVolatile())
return 1;
return 0;
}
-int CompatUtility::GetServiceInCheckPeriod(const Service::Ptr& service)
+int CompatUtility::GetCheckableInCheckPeriod(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- TimePeriod::Ptr timeperiod = service->GetCheckPeriod();
+ TimePeriod::Ptr timeperiod = checkable->GetCheckPeriod();
/* none set means always checked */
if (!timeperiod)
return (timeperiod->IsInside(Utility::GetTime()) ? 1 : 0);
}
-int CompatUtility::GetServiceInNotificationPeriod(const Service::Ptr& service)
+int CompatUtility::GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
+ BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) {
ObjectLock olock(notification);
TimePeriod::Ptr timeperiod = notification->GetNotificationPeriod();
{
ASSERT(object->OwnsLock());
- Dictionary::Ptr vars;
-
- if (object->GetType() == DynamicType::GetByName("Host")) {
- vars = static_pointer_cast<Host>(object)->GetVars();
- } else if (object->GetType() == DynamicType::GetByName("Service")) {
- vars = static_pointer_cast<Service>(object)->GetVars();
- } else if (object->GetType() == DynamicType::GetByName("User")) {
- vars = static_pointer_cast<User>(object)->GetVars();
- } else {
- Log(LogDebug, "icinga", "unknown object type for vars vars");
- return Dictionary::Ptr();
- }
+ Dictionary::Ptr vars = object->GetVars();
Dictionary::Ptr varsvars = make_shared<Dictionary>();
{
ASSERT(object->OwnsLock());
- Dictionary::Ptr vars;
-
- if (object->GetType() == DynamicType::GetByName("Host")) {
- vars = static_pointer_cast<Host>(object)->GetVars();
- } else if (object->GetType() == DynamicType::GetByName("Service")) {
- vars = static_pointer_cast<Service>(object)->GetVars();
- } else if (object->GetType() == DynamicType::GetByName("User")) {
- vars = static_pointer_cast<User>(object)->GetVars();
- } else {
- Log(LogDebug, "icinga", "unknown object type for vars attributes");
- return Empty;
- }
+ Dictionary::Ptr vars = object->GetVars();
if (!vars)
return Empty;
}
/* notifications */
-int CompatUtility::GetServiceNotificationsEnabled(const Service::Ptr& service)
+int CompatUtility::GetCheckableNotificationsEnabled(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- return (service->GetEnableNotifications() ? 1 : 0);
+ return (checkable->GetEnableNotifications() ? 1 : 0);
}
-int CompatUtility::GetServiceNotificationLastNotification(const Service::Ptr& service)
+int CompatUtility::GetCheckableNotificationLastNotification(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
double last_notification = 0.0;
- BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
+ BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) {
if (notification->GetLastNotification() > last_notification)
last_notification = notification->GetLastNotification();
}
return static_cast<int>(last_notification);
}
-int CompatUtility::GetServiceNotificationNextNotification(const Service::Ptr& service)
+int CompatUtility::GetCheckableNotificationNextNotification(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
double next_notification = 0.0;
- BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
- if (notification->GetNextNotification() < next_notification)
+ BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) {
+ if (next_notification == 0 || notification->GetNextNotification() < next_notification)
next_notification = notification->GetNextNotification();
}
return static_cast<int>(next_notification);
}
-int CompatUtility::GetServiceNotificationNotificationNumber(const Service::Ptr& service)
+int CompatUtility::GetCheckableNotificationNotificationNumber(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
int notification_number = 0;
- BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
+ BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) {
if (notification->GetNotificationNumber() > notification_number)
notification_number = notification->GetNotificationNumber();
}
return notification_number;
}
-double CompatUtility::GetServiceNotificationNotificationInterval(const Service::Ptr& service)
+double CompatUtility::GetCheckableNotificationNotificationInterval(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
double notification_interval = -1;
- BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
+ BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) {
if (notification_interval == -1 || notification->GetNotificationInterval() < notification_interval)
notification_interval = notification->GetNotificationInterval();
}
return notification_interval / 60.0;
}
-String CompatUtility::GetServiceNotificationNotificationPeriod(const Service::Ptr& service)
+String CompatUtility::GetCheckableNotificationNotificationPeriod(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
TimePeriod::Ptr notification_period;
- BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
+ BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) {
if (notification->GetNotificationPeriod())
notification_period = notification->GetNotificationPeriod();
return notification_period->GetName();
}
-String CompatUtility::GetServiceNotificationNotificationOptions(const Service::Ptr& service)
+String CompatUtility::GetCheckableNotificationNotificationOptions(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
unsigned long notification_type_filter = 0;
unsigned long notification_state_filter = 0;
- BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
+ BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) {
if (notification->GetNotificationTypeFilter())
notification_type_filter = notification->GetNotificationTypeFilter();
return boost::algorithm::join(notification_options, ",");
}
-int CompatUtility::GetServiceNotificationTypeFilter(const Service::Ptr& service)
+int CompatUtility::GetCheckableNotificationTypeFilter(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
unsigned long notification_type_filter = 0;
- BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
+ BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) {
ObjectLock olock(notification);
if (notification->GetNotificationTypeFilter())
return notification_type_filter;
}
-int CompatUtility::GetServiceNotificationStateFilter(const Service::Ptr& service)
+int CompatUtility::GetCheckableNotificationStateFilter(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
unsigned long notification_state_filter = 0;
- BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
+ BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) {
ObjectLock olock(notification);
if (notification->GetNotificationStateFilter())
return notification_state_filter;
}
-int CompatUtility::GetServiceNotifyOnWarning(const Service::Ptr& service)
+int CompatUtility::GetCheckableNotifyOnWarning(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- if (GetServiceNotificationStateFilter(service) & (1<<StateWarning))
+ if (GetCheckableNotificationStateFilter(checkable) & (1<<StateWarning))
return 1;
return 0;
}
-int CompatUtility::GetServiceNotifyOnCritical(const Service::Ptr& service)
+int CompatUtility::GetCheckableNotifyOnCritical(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- if (GetServiceNotificationStateFilter(service) & (1<<StateCritical))
+ if (GetCheckableNotificationStateFilter(checkable) & (1<<StateCritical))
return 1;
return 0;
}
-int CompatUtility::GetServiceNotifyOnUnknown(const Service::Ptr& service)
+int CompatUtility::GetCheckableNotifyOnUnknown(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- if (GetServiceNotificationStateFilter(service) & (1<<StateUnknown))
+ if (GetCheckableNotificationStateFilter(checkable) & (1<<StateUnknown))
return 1;
return 0;
}
-int CompatUtility::GetServiceNotifyOnRecovery(const Service::Ptr& service)
+int CompatUtility::GetCheckableNotifyOnRecovery(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- if (GetServiceNotificationTypeFilter(service) & (1<<NotificationRecovery))
+ if (GetCheckableNotificationTypeFilter(checkable) & (1<<NotificationRecovery))
return 1;
return 0;
}
-int CompatUtility::GetServiceNotifyOnFlapping(const Service::Ptr& service)
+int CompatUtility::GetCheckableNotifyOnFlapping(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- unsigned long notification_type_filter = GetServiceNotificationTypeFilter(service);
+ unsigned long notification_type_filter = GetCheckableNotificationTypeFilter(checkable);
if (notification_type_filter & (1<<NotificationFlappingStart) ||
notification_type_filter & (1<<NotificationFlappingEnd))
return 0;
}
-int CompatUtility::GetServiceNotifyOnDowntime(const Service::Ptr& service)
+int CompatUtility::GetCheckableNotifyOnDowntime(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
- unsigned long notification_type_filter = GetServiceNotificationTypeFilter(service);
+ unsigned long notification_type_filter = GetCheckableNotificationTypeFilter(checkable);
if (notification_type_filter & (1<<NotificationDowntimeStart) ||
notification_type_filter & (1<<NotificationDowntimeEnd) ||
return 0;
}
-std::set<User::Ptr> CompatUtility::GetServiceNotificationUsers(const Service::Ptr& service)
+std::set<User::Ptr> CompatUtility::GetCheckableNotificationUsers(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
/* Service -> Notifications -> (Users + UserGroups -> Users) */
std::set<User::Ptr> allUsers;
std::set<User::Ptr> users;
- BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
+ BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) {
ObjectLock olock(notification);
users = notification->GetUsers();
return allUsers;
}
-std::set<UserGroup::Ptr> CompatUtility::GetServiceNotificationUserGroups(const Service::Ptr& service)
+std::set<UserGroup::Ptr> CompatUtility::GetCheckableNotificationUserGroups(const Checkable::Ptr& checkable)
{
- ASSERT(service->OwnsLock());
+ ASSERT(checkable->OwnsLock());
std::set<UserGroup::Ptr> usergroups;
/* Service -> Notifications -> UserGroups */
- BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
+ BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) {
ObjectLock olock(notification);
BOOST_FOREACH(const UserGroup::Ptr& ug, notification->GetUserGroups()) {
/**
* @ingroup icinga
*/
-enum CompatObjectType
-{
- CompatTypeService,
- CompatTypeHost
-};
-
-typedef struct {
+struct Host2dCoords {
int have_2d_coords;
String x_2d;
String y_2d;
-} Host2dCoords;
+};
/**
* Compatibility utility functions.
static int GetHostNotifyOnUnreachable(const Host::Ptr& host);
/* service */
- static int GetServiceCurrentState(const Service::Ptr& service);
- static int GetServiceShouldBeScheduled(const Service::Ptr& service);
- static int GetServiceCheckType(const Service::Ptr& service);
- static double GetServiceCheckInterval(const Service::Ptr& service);
- static double GetServiceRetryInterval(const Service::Ptr& service);
- static String GetServiceCheckPeriod(const Service::Ptr& service);
- static int GetServiceHasBeenChecked(const Service::Ptr& service);
- static int GetServiceProblemHasBeenAcknowledged(const Service::Ptr& service);
- static int GetServiceAcknowledgementType(const Service::Ptr& service);
- static int GetServicePassiveChecksEnabled(const Service::Ptr& service);
- static int GetServiceActiveChecksEnabled(const Service::Ptr& service);
- static int GetServiceEventHandlerEnabled(const Service::Ptr& service);
- static int GetServiceFlapDetectionEnabled(const Service::Ptr& service);
- static int GetServiceIsFlapping(const Service::Ptr& service);
- static String GetServicePercentStateChange(const Service::Ptr& service);
- static int GetServiceProcessPerformanceData(const Service::Ptr& service);
-
- static String GetServiceEventHandler(const Service::Ptr& service);
- static String GetServiceCheckCommand(const Service::Ptr& service);
-
- static int GetServiceIsVolatile(const Service::Ptr& service);
- static double GetServiceLowFlapThreshold(const Service::Ptr& service);
- static double GetServiceHighFlapThreshold(const Service::Ptr& service);
- static int GetServiceFreshnessChecksEnabled(const Service::Ptr& service);
- static int GetServiceFreshnessThreshold(const Service::Ptr& service);
- static double GetServiceStaleness(const Service::Ptr& service);
- static int GetServiceIsAcknowledged(const Service::Ptr& service);
- static int GetServiceNoMoreNotifications(const Service::Ptr& service);
- static int GetServiceInCheckPeriod(const Service::Ptr& service);
- static int GetServiceInNotificationPeriod(const Service::Ptr& service);
+ static int GetCheckableShouldBeScheduled(const Checkable::Ptr& checkable);
+ static int GetCheckableCheckType(const Checkable::Ptr& checkable);
+ static double GetCheckableCheckInterval(const Checkable::Ptr& checkable);
+ static double GetCheckableRetryInterval(const Checkable::Ptr& checkable);
+ static String GetCheckableCheckPeriod(const Checkable::Ptr& checkable);
+ static int GetCheckableHasBeenChecked(const Checkable::Ptr& checkable);
+ static int GetCheckableProblemHasBeenAcknowledged(const Checkable::Ptr& checkable);
+ static int GetCheckableAcknowledgementType(const Checkable::Ptr& checkable);
+ static int GetCheckablePassiveChecksEnabled(const Checkable::Ptr& checkable);
+ static int GetCheckableActiveChecksEnabled(const Checkable::Ptr& checkable);
+ static int GetCheckableEventHandlerEnabled(const Checkable::Ptr& checkable);
+ static int GetCheckableFlapDetectionEnabled(const Checkable::Ptr& checkable);
+ static int GetCheckableIsFlapping(const Checkable::Ptr& checkable);
+ static String GetCheckablePercentStateChange(const Checkable::Ptr& checkable);
+ static int GetCheckableProcessPerformanceData(const Checkable::Ptr& checkable);
+
+ static String GetCheckableEventHandler(const Checkable::Ptr& checkable);
+ static String GetCheckableCheckCommand(const Checkable::Ptr& checkable);
+
+ static int GetCheckableIsVolatile(const Checkable::Ptr& checkable);
+ static double GetCheckableLowFlapThreshold(const Checkable::Ptr& checkable);
+ static double GetCheckableHighFlapThreshold(const Checkable::Ptr& checkable);
+ static int GetCheckableFreshnessChecksEnabled(const Checkable::Ptr& checkable);
+ static int GetCheckableFreshnessThreshold(const Checkable::Ptr& checkable);
+ static double GetCheckableStaleness(const Checkable::Ptr& checkable);
+ static int GetCheckableIsAcknowledged(const Checkable::Ptr& checkable);
+ static int GetCheckableNoMoreNotifications(const Checkable::Ptr& checkable);
+ static int GetCheckableInCheckPeriod(const Checkable::Ptr& checkable);
+ static int GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable);
/* notification */
- static int GetServiceNotificationsEnabled(const Service::Ptr& service);
- static int GetServiceNotificationLastNotification(const Service::Ptr& service);
- static int GetServiceNotificationNextNotification(const Service::Ptr& service);
- static int GetServiceNotificationNotificationNumber(const Service::Ptr& service);
- static double GetServiceNotificationNotificationInterval(const Service::Ptr& service);
- static String GetServiceNotificationNotificationPeriod(const Service::Ptr& service);
- static String GetServiceNotificationNotificationOptions(const Service::Ptr& service);
- static int GetServiceNotificationTypeFilter(const Service::Ptr& service);
- static int GetServiceNotificationStateFilter(const Service::Ptr& service);
- static int GetServiceNotifyOnWarning(const Service::Ptr& service);
- static int GetServiceNotifyOnCritical(const Service::Ptr& service);
- static int GetServiceNotifyOnUnknown(const Service::Ptr& service);
- static int GetServiceNotifyOnRecovery(const Service::Ptr& service);
- static int GetServiceNotifyOnFlapping(const Service::Ptr& service);
- static int GetServiceNotifyOnDowntime(const Service::Ptr& service);
-
- static std::set<User::Ptr> GetServiceNotificationUsers(const Service::Ptr& service);
- static std::set<UserGroup::Ptr> GetServiceNotificationUserGroups(const Service::Ptr& service);
+ static int GetCheckableNotificationsEnabled(const Checkable::Ptr& checkable);
+ static int GetCheckableNotificationLastNotification(const Checkable::Ptr& checkable);
+ static int GetCheckableNotificationNextNotification(const Checkable::Ptr& checkable);
+ static int GetCheckableNotificationNotificationNumber(const Checkable::Ptr& checkable);
+ static double GetCheckableNotificationNotificationInterval(const Checkable::Ptr& checkable);
+ static String GetCheckableNotificationNotificationPeriod(const Checkable::Ptr& checkable);
+ static String GetCheckableNotificationNotificationOptions(const Checkable::Ptr& checkable);
+ static int GetCheckableNotificationTypeFilter(const Checkable::Ptr& checkable);
+ static int GetCheckableNotificationStateFilter(const Checkable::Ptr& checkable);
+ static int GetCheckableNotifyOnWarning(const Checkable::Ptr& checkable);
+ static int GetCheckableNotifyOnCritical(const Checkable::Ptr& checkable);
+ static int GetCheckableNotifyOnUnknown(const Checkable::Ptr& checkable);
+ static int GetCheckableNotifyOnRecovery(const Checkable::Ptr& checkable);
+ static int GetCheckableNotifyOnFlapping(const Checkable::Ptr& checkable);
+ static int GetCheckableNotifyOnDowntime(const Checkable::Ptr& checkable);
+
+ static std::set<User::Ptr> GetCheckableNotificationUsers(const Checkable::Ptr& checkable);
+ static std::set<UserGroup::Ptr> GetCheckableNotificationUserGroups(const Checkable::Ptr& checkable);
/* command */
static String GetCommandLine(const Command::Ptr& command);
******************************************************************************/
#include "icinga/dependency.h"
+#include "icinga/service.h"
#include "config/configitembuilder.h"
#include "base/initialize.h"
#include "base/dynamictype.h"
******************************************************************************/
#include "icinga/dependency.h"
+#include "icinga/service.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/logger_fwd.h"
ASSERT(!OwnsLock());
- if (!GetChildService())
+ if (!GetChild())
Log(LogWarning, "icinga", "Dependency '" + GetName() + "' references an invalid child service and will be ignored.");
else
- GetChildService()->AddDependency(GetSelf());
+ GetChild()->AddDependency(GetSelf());
- if (!GetParentService())
+ if (!GetParent())
Log(LogWarning, "icinga", "Dependency '" + GetName() + "' references an invalid parent service and will always fail.");
else
- GetParentService()->AddReverseDependency(GetSelf());
+ GetParent()->AddReverseDependency(GetSelf());
}
void Dependency::Stop(void)
{
DynamicObject::Stop();
- if (GetChildService())
- GetChildService()->RemoveDependency(GetSelf());
+ if (GetChild())
+ GetChild()->RemoveDependency(GetSelf());
- if (GetParentService())
- GetParentService()->RemoveReverseDependency(GetSelf());
+ if (GetParent())
+ GetParent()->RemoveReverseDependency(GetSelf());
}
bool Dependency::IsAvailable(DependencyType dt) const
{
- Service::Ptr service = GetParentService();
+ Checkable::Ptr parent = GetParent();
- if (!service)
+ if (!parent)
return false;
/* ignore if it's the same service */
- if (service == GetChildService()) {
+ if (parent == GetChild()) {
Log(LogDebug, "icinga", "Dependency '" + GetName() + "' passed: Parent and child service are identical.");
return true;
}
/* ignore pending services */
- if (!service->GetLastCheckResult()) {
+ if (!parent->GetLastCheckResult()) {
Log(LogDebug, "icinga", "Dependency '" + GetName() + "' passed: Service hasn't been checked yet.");
return true;
}
/* ignore soft states */
- if (service->GetStateType() == StateTypeSoft) {
+ if (parent->GetStateType() == StateTypeSoft) {
Log(LogDebug, "icinga", "Dependency '" + GetName() + "' passed: Service is in a soft state.");
return true;
}
+ bool is_service = parent->GetType() == DynamicType::GetByName("Service");
+ int state;
+
+ if (is_service)
+ state = static_cast<int>(static_pointer_cast<Service>(parent)->GetState());
+ else
+ state = static_cast<int>(static_pointer_cast<Host>(parent)->GetState());
+
/* check state */
- if ((1 << static_cast<int>(service->GetState())) & GetStateFilter()) {
- Log(LogDebug, "icinga", "Dependency '" + GetName() + "' passed: Service matches state filter.");
+ if ((1 << state) & GetStateFilter()) {
+ Log(LogDebug, "icinga", "Dependency '" + GetName() + "' passed: Object matches state filter.");
return true;
}
return false;
}
-Service::Ptr Dependency::GetChildService(void) const
+Checkable::Ptr Dependency::GetChild(void) const
{
Host::Ptr host = Host::GetByName(GetChildHostRaw());
return Service::Ptr();
if (GetChildServiceRaw().IsEmpty())
- return host->GetCheckService();
-
- return host->GetServiceByShortName(GetChildServiceRaw());
+ return host;
+ else
+ return host->GetServiceByShortName(GetChildServiceRaw());
}
-Service::Ptr Dependency::GetParentService(void) const
+Checkable::Ptr Dependency::GetParent(void) const
{
Host::Ptr host = Host::GetByName(GetParentHostRaw());
return Service::Ptr();
if (GetParentServiceRaw().IsEmpty())
- return host->GetCheckService();
-
- return host->GetServiceByShortName(GetParentServiceRaw());
+ return host;
+ else
+ return host->GetServiceByShortName(GetParentServiceRaw());
}
TimePeriod::Ptr Dependency::GetPeriod(void) const
#include "icinga/i2-icinga.h"
#include "icinga/dependency.th"
-#include "icinga/service.h"
#include "config/applyrule.h"
#include "base/array.h"
#include "base/dictionary.h"
DECLARE_PTR_TYPEDEFS(Dependency);
DECLARE_TYPENAME(Dependency);
- Service::Ptr GetParentService(void) const;
- Service::Ptr GetChildService(void) const;
+ shared_ptr<Checkable> GetParent(void) const;
+ shared_ptr<Checkable> GetChild(void) const;
TimePeriod::Ptr GetPeriod(void) const;
#include "base/dynamicobject.h"
-#include "icinga/service.h"
+#include "icinga/checkable.h"
namespace icinga
{
REGISTER_TYPE(EventCommand);
-void EventCommand::Execute(const Service::Ptr& service)
+void EventCommand::Execute(const Checkable::Ptr& checkable)
{
std::vector<Value> arguments;
- arguments.push_back(service);
+ arguments.push_back(checkable);
InvokeMethod("execute", arguments);
}
DECLARE_PTR_TYPEDEFS(EventCommand);
DECLARE_TYPENAME(EventCommand);
- virtual void Execute(const Service::Ptr& context);
+ virtual void Execute(const Checkable::Ptr& checkable);
};
}
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot process passive host check result for non-existent host '" + arguments[0] + "'"));
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot process passive host check result for host '" + arguments[0] + "' which has no check service."));
-
- if (!hc->GetEnablePassiveChecks())
+ if (!host->GetEnablePassiveChecks())
BOOST_THROW_EXCEPTION(std::invalid_argument("Got passive check result for host '" + arguments[0] + "' which has passive checks disabled."));
int exitStatus = Convert::ToDouble(arguments[1]);
result->SetActive(false);
Log(LogInformation, "icinga", "Processing passive check result for host '" + arguments[0] + "'");
- hc->ProcessCheckResult(result);
+ host->ProcessCheckResult(result);
{
- ObjectLock olock(hc);
+ ObjectLock olock(host);
/* Reschedule the next check. The side effect of this is that for as long
* as we receive passive results for a service we won't execute any
* active checks. */
- hc->SetNextCheck(Utility::GetTime() + hc->GetCheckInterval());
+ host->SetNextCheck(Utility::GetTime() + host->GetCheckInterval());
}
}
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot reschedule host check for non-existent host '" + arguments[0] + "'"));
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot reschedule host check for host '" + arguments[0] + "' which has no check service."));
-
double planned_check = Convert::ToDouble(arguments[1]);
- if (planned_check > hc->GetNextCheck()) {
+ if (planned_check > host->GetNextCheck()) {
Log(LogInformation, "icinga", "Ignoring reschedule request for host '" +
arguments[0] + "' (next check is already sooner than requested check time)");
return;
planned_check = Utility::GetTime();
{
- ObjectLock olock(hc);
+ ObjectLock olock(host);
- hc->SetNextCheck(planned_check);
+ host->SetNextCheck(planned_check);
}
}
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot reschedule forced host check for non-existent host '" + arguments[0] + "'"));
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot reschedule forced host check for host '" + arguments[0] + "' which has no check service."));
-
Log(LogInformation, "icinga", "Rescheduling next check for host '" + arguments[0] + "'");
{
- ObjectLock olock(hc);
+ ObjectLock olock(host);
- hc->SetForceNextCheck(true);
- hc->SetNextCheck(Convert::ToDouble(arguments[1]));
+ host->SetForceNextCheck(true);
+ host->SetNextCheck(Convert::ToDouble(arguments[1]));
}
}
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable host checks for non-existent host '" + arguments[0] + "'"));
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable host checks for host '" + arguments[0] + "' which has no check service."));
-
Log(LogInformation, "icinga", "Enabling active checks for host '" + arguments[0] + "'");
{
- ObjectLock olock(hc);
+ ObjectLock olock(host);
- hc->SetEnableActiveChecks(true);
+ host->SetEnableActiveChecks(true);
}
}
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable host check non-existent host '" + arguments[0] + "'"));
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable host checks for host '" + arguments[0] + "' which has no check service."));
-
Log(LogInformation, "icinga", "Disabling active checks for host '" + arguments[0] + "'");
{
- ObjectLock olock(hc);
+ ObjectLock olock(host);
- hc->SetEnableActiveChecks(false);
+ host->SetEnableActiveChecks(false);
}
}
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot acknowledge host problem for non-existent host '" + arguments[0] + "'"));
Log(LogInformation, "icinga", "Setting acknowledgement for host '" + host->GetName() + "'");
- Service::Ptr service = host->GetCheckService();
- if (service) {
- if (service->GetState() == StateOK)
- BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[0] + "' is OK."));
- service->AddComment(CommentAcknowledgement, arguments[4], arguments[5], 0);
- service->AcknowledgeProblem(arguments[4], arguments[5], sticky ? AcknowledgementSticky : AcknowledgementNormal);
- }
+ if (host->GetState() == HostUp)
+ BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[0] + "' is OK."));
+
+ host->AddComment(CommentAcknowledgement, arguments[4], arguments[5], 0);
+ host->AcknowledgeProblem(arguments[4], arguments[5], sticky ? AcknowledgementSticky : AcknowledgementNormal);
}
void ExternalCommandProcessor::AcknowledgeHostProblemExpire(double, const std::vector<String>& arguments)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot acknowledge host problem with expire time for non-existent host '" + arguments[0] + "'"));
Log(LogInformation, "icinga", "Setting timed acknowledgement for host '" + host->GetName() + "'");
- Service::Ptr service = host->GetCheckService();
- if (service) {
- if (service->GetState() == StateOK)
- BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[0] + "' is OK."));
- service->AddComment(CommentAcknowledgement, arguments[5], arguments[6], 0);
- service->AcknowledgeProblem(arguments[5], arguments[6], sticky ? AcknowledgementSticky : AcknowledgementNormal, timestamp);
- }
+ if (host->GetState() == HostUp)
+ BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[0] + "' is OK."));
+
+ host->AddComment(CommentAcknowledgement, arguments[5], arguments[6], 0);
+ host->AcknowledgeProblem(arguments[5], arguments[6], sticky ? AcknowledgementSticky : AcknowledgementNormal, timestamp);
}
void ExternalCommandProcessor::RemoveHostAcknowledgement(double, const std::vector<String>& arguments)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot remove acknowledgement for non-existent host '" + arguments[0] + "'"));
Log(LogInformation, "icinga", "Removing acknowledgement for host '" + host->GetName() + "'");
- Service::Ptr service = host->GetCheckService();
- if (service) {
- {
- ObjectLock olock(service);
- service->ClearAcknowledgement();
- }
- service->RemoveCommentsByType(CommentAcknowledgement);
+
+ {
+ ObjectLock olock(host);
+ host->ClearAcknowledgement();
}
+ host->RemoveCommentsByType(CommentAcknowledgement);
}
void ExternalCommandProcessor::EnableHostgroupSvcChecks(double, const std::vector<String>& arguments)
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable passive host checks for non-existent host '" + arguments[0] + "'"));
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable passive host checks for host '" + arguments[0] + "' which has no check service."));
-
Log(LogInformation, "icinga", "Enabling passive checks for host '" + arguments[0] + "'");
{
- ObjectLock olock(hc);
+ ObjectLock olock(host);
- hc->SetEnablePassiveChecks(true);
+ host->SetEnablePassiveChecks(true);
}
}
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable passive host checks for non-existent host '" + arguments[0] + "'"));
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable passive host checks for host '" + arguments[0] + "' which has no check service."));
-
Log(LogInformation, "icinga", "Disabling passive checks for host '" + arguments[0] + "'");
{
- ObjectLock olock(hc);
+ ObjectLock olock(host);
- hc->SetEnablePassiveChecks(false);
+ host->SetEnablePassiveChecks(false);
}
}
triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
Log(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
- Service::Ptr service = host->GetCheckService();
- if (service) {
- (void) service->AddDowntime(arguments[6], arguments[7],
- Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
- Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
- }
+
+ (void) host->AddDowntime(arguments[6], arguments[7],
+ Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
+ Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
}
void ExternalCommandProcessor::DelHostDowntime(double, const std::vector<String>& arguments)
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
Log(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
- Service::Ptr service = host->GetCheckService();
- if (service) {
- (void) service->AddDowntime(arguments[6], arguments[7],
- Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
- Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
- }
+
+ (void) host->AddDowntime(arguments[6], arguments[7],
+ Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
+ Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
}
}
* over all services in the service group - otherwise we might end up creating multiple
* downtimes for some hosts. */
- std::set<Service::Ptr> services;
+ std::set<Host::Ptr> hosts;
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
Host::Ptr host = service->GetHost();
- Service::Ptr hcService = host->GetCheckService();
- if (hcService)
- services.insert(hcService);
+ hosts.insert(host);
}
- BOOST_FOREACH(const Service::Ptr& service, services) {
- Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
- (void) service->AddDowntime(arguments[6], arguments[7],
+ BOOST_FOREACH(const Host::Ptr& host, hosts) {
+ Log(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
+ (void) host->AddDowntime(arguments[6], arguments[7],
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
}
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot add host comment for non-existent host '" + arguments[0] + "'"));
Log(LogInformation, "icinga", "Creating comment for host " + host->GetName());
- Service::Ptr service = host->GetCheckService();
- if (service)
- (void) service->AddComment(CommentUser, arguments[2], arguments[3], 0);
+ (void) host->AddComment(CommentUser, arguments[2], arguments[3], 0);
}
void ExternalCommandProcessor::DelHostComment(double, const std::vector<String>& arguments)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot delete all host comments for non-existent host '" + arguments[0] + "'"));
Log(LogInformation, "icinga", "Removing all comments for host " + host->GetName());
- Service::Ptr service = host->GetCheckService();
- if (service)
- service->RemoveAllComments();
+ host->RemoveAllComments();
}
void ExternalCommandProcessor::DelAllSvcComments(double, const std::vector<String>& arguments)
int options = Convert::ToLong(arguments[1]);
Log(LogInformation, "icinga", "Sending custom notification for host " + host->GetName());
- Service::Ptr service = host->GetCheckService();
- if (service) {
- if (options & 2) {
- ObjectLock olock(service);
- service->SetForceNextNotification(true);
- }
-
- Service::OnNotificationsRequested(service, NotificationCustom, service->GetLastCheckResult(), arguments[2], arguments[3]);
+ if (options & 2) {
+ ObjectLock olock(host);
+ host->SetForceNextNotification(true);
}
+
+ Checkable::OnNotificationsRequested(host, NotificationCustom, host->GetLastCheckResult(), arguments[2], arguments[3]);
}
void ExternalCommandProcessor::SendCustomSvcNotification(double, const std::vector<String>& arguments)
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot delay host notification for non-existent host '" + arguments[0] + "'"));
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot delay host notification for host '" + arguments[0] + "' which has no check service."));
-
Log(LogInformation, "icinga", "Delaying notifications for host '" + host->GetName() + "'");
- BOOST_FOREACH(const Notification::Ptr& notification, hc->GetNotifications()) {
+ BOOST_FOREACH(const Notification::Ptr& notification, host->GetNotifications()) {
ObjectLock olock(notification);
notification->SetNextNotification(Convert::ToDouble(arguments[1]));
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable host notifications for non-existent host '" + arguments[0] + "'"));
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable host notifications for host '" + arguments[0] + "' which has no check service."));
-
Log(LogInformation, "icinga", "Enabling notifications for host '" + arguments[0] + "'");
{
- ObjectLock olock(hc);
+ ObjectLock olock(host);
- hc->SetEnableNotifications(true);
+ host->SetEnableNotifications(true);
}
}
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable host notifications for non-existent host '" + arguments[0] + "'"));
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable host notifications for host '" + arguments[0] + "' which has no check service."));
-
Log(LogInformation, "icinga", "Disabling notifications for host '" + arguments[0] + "'");
{
- ObjectLock olock(hc);
+ ObjectLock olock(host);
- hc->SetEnableNotifications(false);
+ host->SetEnableNotifications(false);
}
}
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable hostgroup host checks for non-existent hostgroup '" + arguments[0] + "'"));
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc) {
- Log(LogInformation, "icinga", "Cannot disable active checks for host '" + host->GetName() + "' which has no check service.");
- } else {
- Log(LogInformation, "icinga", "Disabling active checks for host '" + host->GetName() + "'");
+ Log(LogInformation, "icinga", "Disabling active checks for host '" + host->GetName() + "'");
- {
- ObjectLock olock(hc);
+ {
+ ObjectLock olock(host);
- hc->SetEnableActiveChecks(false);
- }
+ host->SetEnableActiveChecks(false);
}
}
}
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable hostgroup passive host checks for non-existent hostgroup '" + arguments[0] + "'"));
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
- Service::Ptr hc = host->GetCheckService();
+ Log(LogInformation, "icinga", "Disabling passive checks for host '" + host->GetName() + "'");
- if (!hc) {
- Log(LogInformation, "icinga", "Cannot disable passive checks for host '" + host->GetName() + "' which has no check service.");
- } else {
- Log(LogInformation, "icinga", "Disabling passive checks for host '" + host->GetName() + "'");
-
- {
- ObjectLock olock(hc);
+ {
+ ObjectLock olock(host);
- hc->SetEnablePassiveChecks(false);
- }
+ host->SetEnablePassiveChecks(false);
}
}
}
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
Host::Ptr host = service->GetHost();
- Service::Ptr hc = host->GetCheckService();
+ Log(LogInformation, "icinga", "Disabling active checks for host '" + host->GetName() + "'");
- if (!hc) {
- Log(LogInformation, "icinga", "Cannot disable active checks for host '" + host->GetName() + "' which has no check service.");
- } else {
- Log(LogInformation, "icinga", "Disabling active checks for host '" + host->GetName() + "'");
-
- {
- ObjectLock olock(hc);
+ {
+ ObjectLock olock(host);
- hc->SetEnableActiveChecks(false);
- }
+ host->SetEnableActiveChecks(false);
}
}
}
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
Host::Ptr host = service->GetHost();
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc) {
- Log(LogInformation, "icinga", "Cannot disable passive checks for host '" + host->GetName() + "' which has no check service.");
- } else {
- Log(LogInformation, "icinga", "Disabling passive checks for host '" + host->GetName() + "'");
+ Log(LogInformation, "icinga", "Disabling passive checks for host '" + host->GetName() + "'");
- {
- ObjectLock olock(hc);
+ {
+ ObjectLock olock(host);
- hc->SetEnablePassiveChecks(false);
- }
+ host->SetEnablePassiveChecks(false);
}
}
}
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable hostgroup host checks for non-existent hostgroup '" + arguments[0] + "'"));
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc) {
- Log(LogInformation, "icinga", "Cannot enable active checks for host '" + host->GetName() + "' which has no check service.");
- } else {
- Log(LogInformation, "icinga", "Enabling active checks for host '" + host->GetName() + "'");
+ Log(LogInformation, "icinga", "Enabling active checks for host '" + host->GetName() + "'");
- {
- ObjectLock olock(hc);
+ {
+ ObjectLock olock(host);
- hc->SetEnableActiveChecks(true);
- }
+ host->SetEnableActiveChecks(true);
}
}
}
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable hostgroup passive host checks for non-existent hostgroup '" + arguments[0] + "'"));
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc) {
- Log(LogInformation, "icinga", "Cannot enable passive checks for host '" + host->GetName() + "' which has no check service.");
- } else {
- Log(LogInformation, "icinga", "Enabling passive checks for host '" + host->GetName() + "'");
+ Log(LogInformation, "icinga", "Enabling passive checks for host '" + host->GetName() + "'");
- {
- ObjectLock olock(hc);
+ {
+ ObjectLock olock(host);
- hc->SetEnablePassiveChecks(true);
- }
+ host->SetEnablePassiveChecks(true);
}
}
}
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
Host::Ptr host = service->GetHost();
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc) {
- Log(LogInformation, "icinga", "Cannot enable active checks for host '" + host->GetName() + "' which has no check service.");
- } else {
- Log(LogInformation, "icinga", "Enabling active checks for host '" + host->GetName() + "'");
+ Log(LogInformation, "icinga", "Enabling active checks for host '" + host->GetName() + "'");
- {
- ObjectLock olock(hc);
+ {
+ ObjectLock olock(host);
- hc->SetEnableActiveChecks(true);
- }
+ host->SetEnableActiveChecks(true);
}
}
}
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
Host::Ptr host = service->GetHost();
- Service::Ptr hc = host->GetCheckService();
+ Log(LogInformation, "icinga", "Enabling passive checks for host '" + host->GetName() + "'");
- if (!hc) {
- Log(LogInformation, "icinga", "Cannot enable passive host checks for host '" + host->GetName() + "' which has no check service.");
- } else {
- Log(LogInformation, "icinga", "Enabling passive checks for host '" + host->GetName() + "'");
-
- {
- ObjectLock olock(hc);
+ {
+ ObjectLock olock(host);
- hc->SetEnablePassiveChecks(true);
- }
+ host->SetEnablePassiveChecks(true);
}
}
}
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable host flapping for non-existent host '" + arguments[0] + "'"));
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable host flapping for host '" + arguments[0] + "' which has no check service."));
-
Log(LogInformation, "icinga", "Enabling flapping detection for host '" + arguments[0] + "'");
{
- ObjectLock olock(hc);
+ ObjectLock olock(host);
- hc->SetEnableFlapping(true);
+ host->SetEnableFlapping(true);
}
}
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable host flapping for non-existent host '" + arguments[0] + "'"));
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable host flapping for host '" + arguments[0] + "' which has no check service."));
-
Log(LogInformation, "icinga", "Disabling flapping detection for host '" + arguments[0] + "'");
{
- ObjectLock olock(hc);
+ ObjectLock olock(host);
- hc->SetEnableFlapping(false);
+ host->SetEnableFlapping(false);
}
}
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot update modified attributes for non-existent host '" + arguments[0] + "'"));
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot update modified attributes for host '" + arguments[0] + "' which has no check service."));
-
Log(LogInformation, "icinga", "Updating modified attributes for host '" + arguments[0] + "'");
int modifiedAttributes = Convert::ToLong(arguments[1]);
{
- ObjectLock olock(hc);
+ ObjectLock olock(host);
- hc->SetModifiedAttributes(modifiedAttributes);
+ host->SetModifiedAttributes(modifiedAttributes);
}
}
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot update check interval for non-existent host '" + arguments[0] + "'"));
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot update check interval for host '" + arguments[0] + "' which has no check service."));
-
Log(LogInformation, "icinga", "Updating check interval for host '" + arguments[0] + "'");
double interval = Convert::ToDouble(arguments[1]);
{
- ObjectLock olock(hc);
+ ObjectLock olock(host);
- hc->SetCheckInterval(interval * 60);
+ host->SetCheckInterval(interval * 60);
}
}
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot update retry interval for non-existent host '" + arguments[0] + "'"));
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot update retry interval for host '" + arguments[0] + "' which has no check service."));
-
Log(LogInformation, "icinga", "Updating retry interval for host '" + arguments[0] + "'");
double interval = Convert::ToDouble(arguments[1]);
{
- ObjectLock olock(hc);
+ ObjectLock olock(host);
- hc->SetRetryInterval(interval * 60);
+ host->SetRetryInterval(interval * 60);
}
}
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable event handler for non-existent host '" + arguments[0] + "'"));
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable event handler for host '" + arguments[0] + "' which has no check service."));
-
Log(LogInformation, "icinga", "Enabling event handler for host '" + arguments[0] + "'");
{
- ObjectLock olock(hc);
+ ObjectLock olock(host);
- hc->SetEnableEventHandler(true);
+ host->SetEnableEventHandler(true);
}
}
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable event handler for non-existent host '" + arguments[0] + "'"));
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable event handler for host '" + arguments[0] + "' which has no check service."));
-
Log(LogInformation, "icinga", "Disabling event handler for host '" + arguments[0] + "'");
{
- ObjectLock olock(hc);
+ ObjectLock olock(host);
- hc->SetEnableEventHandler(false);
+ host->SetEnableEventHandler(false);
}
}
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change event handler for non-existent host '" + arguments[0] + "'"));
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change event handler for host '" + arguments[0] + "' which has no check service."));
-
/* empty command string implicitely disables event handler */
if (arguments[1].IsEmpty()) {
- hc->SetEnableEventHandler(false);
+ host->SetEnableEventHandler(false);
} else {
EventCommand::Ptr command = EventCommand::GetByName(arguments[1]);
Log(LogInformation, "icinga", "Changing event handler for host '" + arguments[0] + "' to '" + arguments[1] + "'");
{
- ObjectLock olock(hc);
+ ObjectLock olock(host);
- hc->SetEventCommand(command);
+ host->SetEventCommand(command);
}
}
}
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change check command for non-existent host '" + arguments[0] + "'"));
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change check command for host '" + arguments[0] + "' which has no check service."));
-
CheckCommand::Ptr command = CheckCommand::GetByName(arguments[1]);
if (!command)
Log(LogInformation, "icinga", "Changing check command for host '" + arguments[0] + "' to '" + arguments[1] + "'");
{
- ObjectLock olock(hc);
+ ObjectLock olock(host);
- hc->SetCheckCommand(command);
+ host->SetCheckCommand(command);
}
}
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change max check attempts for non-existent host '" + arguments[0] + "'"));
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change max check attempts for host '" + arguments[0] + "' which has no check service."));
-
int attempts = Convert::ToLong(arguments[1]);
Log(LogInformation, "icinga", "Changing max check attempts for host '" + arguments[0] + "' to '" + arguments[1] + "'");
{
- ObjectLock olock(hc);
+ ObjectLock olock(host);
- hc->SetMaxCheckAttempts(attempts);
+ host->SetMaxCheckAttempts(attempts);
}
}
if (!host)
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change check period for non-existent host '" + arguments[0] + "'"));
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot change check period for host '" + arguments[0] + "' which has no check service."));
-
TimePeriod::Ptr tp = TimePeriod::GetByName(arguments[1]);
if (!tp)
Log(LogInformation, "icinga", "Changing check period for host '" + arguments[0] + "' to '" + arguments[1] + "'");
{
- ObjectLock olock(hc);
+ ObjectLock olock(host);
- hc->SetCheckPeriod(tp);
+ host->SetCheckPeriod(tp);
}
}
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot enable host notifications for non-existent hostgroup '" + arguments[0] + "'"));
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc) {
- Log(LogInformation, "icinga", "Cannot enable notifications for host '" + host->GetName() + "' which has no check service.");
- } else {
- Log(LogInformation, "icinga", "Enabling notifications for host '" + host->GetName() + "'");
+ Log(LogInformation, "icinga", "Enabling notifications for host '" + host->GetName() + "'");
- {
- ObjectLock olock(hc);
+ {
+ ObjectLock olock(host);
- hc->SetEnableNotifications(true);
- }
+ host->SetEnableNotifications(true);
}
}
}
BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot disable host notifications for non-existent hostgroup '" + arguments[0] + "'"));
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
- Service::Ptr hc = host->GetCheckService();
+ Log(LogInformation, "icinga", "Disabling notifications for host '" + host->GetName() + "'");
- if (!hc) {
- Log(LogInformation, "icinga", "Cannot disable notifications for host '" + host->GetName() + "' which has no check service.");
- } else {
- Log(LogInformation, "icinga", "Disabling notifications for host '" + host->GetName() + "'");
-
- {
- ObjectLock olock(hc);
+ {
+ ObjectLock olock(host);
- hc->SetEnableNotifications(false);
- }
+ host->SetEnableNotifications(false);
}
}
}
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
Host::Ptr host = service->GetHost();
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc) {
- Log(LogInformation, "icinga", "Cannot enable notifications for host '" + host->GetName() + "' which has no check service.");
- } else {
- Log(LogInformation, "icinga", "Enabling notifications for host '" + host->GetName() + "'");
+ Log(LogInformation, "icinga", "Enabling notifications for host '" + host->GetName() + "'");
- {
- ObjectLock olock(hc);
+ {
+ ObjectLock olock(host);
- hc->SetEnableNotifications(true);
- }
+ host->SetEnableNotifications(true);
}
}
}
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
Host::Ptr host = service->GetHost();
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc) {
- Log(LogInformation, "icinga", "Cannot disable notifications for host '" + host->GetName() + "' which has no check service.");
- } else {
- Log(LogInformation, "icinga", "Disabling notifications for host '" + host->GetName() + "'");
+ Log(LogInformation, "icinga", "Disabling notifications for host '" + host->GetName() + "'");
- {
- ObjectLock olock(hc);
+ {
+ ObjectLock olock(host);
- hc->SetEnableNotifications(false);
- }
+ host->SetEnableNotifications(false);
}
}
}
// TODO: unregister slave services/notifications?
}
-bool Host::IsReachable(DependencyType dt, shared_ptr<Dependency> *failedDependency) const
-{
- ASSERT(!OwnsLock());
-
- Service::Ptr hc = GetCheckService();
- if (!hc)
- return true;
-
- return hc->IsReachable(dt, failedDependency);
-}
-
std::set<Service::Ptr> Host::GetServices(void) const
{
boost::mutex::scoped_lock lock(m_ServicesMutex);
return GetServices().size();
}
-Service::Ptr Host::GetServiceByShortName(const Value& name) const
+Service::Ptr Host::GetServiceByShortName(const Value& name)
{
- if (name.IsEmpty()) {
- Service::Ptr hc = GetCheckService();
-
- if (!hc)
- BOOST_THROW_EXCEPTION(std::invalid_argument("Host does not have a host check service: " + GetName()));
-
- return hc;
- } else if (name.IsScalar()) {
+ if (name.IsScalar()) {
{
boost::mutex::scoped_lock lock(m_ServicesMutex);
}
}
-Service::Ptr Host::GetCheckService(void) const
-{
- String host_check = GetCheck();
-
- if (host_check.IsEmpty())
- return Service::Ptr();
-
- return GetServiceByShortName(host_check);
-}
-
-std::set<Host::Ptr> Host::GetParentHosts(void) const
-{
- std::set<Host::Ptr> result;
- Service::Ptr hc = GetCheckService();
-
- if (hc)
- result = hc->GetParentHosts();
-
- return result;
-}
-
-std::set<Host::Ptr> Host::GetChildHosts(void) const
-{
- std::set<Host::Ptr> result;
- Service::Ptr hc = GetCheckService();
-
- if (hc)
- result = hc->GetChildHosts();
-
- return result;
-}
-
-std::set<Service::Ptr> Host::GetParentServices(void) const
-{
- std::set<Service::Ptr> result;
- Service::Ptr hc = GetCheckService();
-
- if (hc)
- result = hc->GetParentServices();
-
- return result;
-}
-
-std::set<Service::Ptr> Host::GetChildServices(void) const
-{
- std::set<Service::Ptr> result;
- Service::Ptr hc = GetCheckService();
-
- if (hc)
- result = hc->GetChildServices();
-
- return result;
-}
-
HostState Host::CalculateState(ServiceState state, bool reachable)
{
if (!reachable)
if (!IsReachable())
return HostUnreachable;
- Service::Ptr hc = GetCheckService();
-
- if (!hc)
- return HostUp;
-
- switch (hc->GetState()) {
+ switch (GetStateRaw()) {
case StateOK:
case StateWarning:
return HostUp;
if (!IsReachable())
return HostUnreachable;
- Service::Ptr hc = GetCheckService();
-
- if (!hc)
- return HostUp;
-
- switch (hc->GetLastState()) {
+ switch (GetLastStateRaw()) {
case StateOK:
case StateWarning:
return HostUp;
if (!IsReachable())
return HostUnreachable;
- Service::Ptr hc = GetCheckService();
-
- if (!hc)
- return HostUp;
-
- switch (hc->GetLastHardState()) {
+ switch (GetLastHardStateRaw()) {
case StateOK:
case StateWarning:
return HostUp;
{
ASSERT(!OwnsLock());
- Service::Ptr hc = GetCheckService();
-
- if (!hc)
- return 0;
-
- if (hc->GetLastStateOK() > hc->GetLastStateWarning())
- return hc->GetLastStateOK();
+ if (GetLastStateOK() > GetLastStateWarning())
+ return GetLastStateOK();
else
- return hc->GetLastStateWarning();
+ return GetLastStateWarning();
}
double Host::GetLastStateDown(void) const
{
ASSERT(!OwnsLock());
- Service::Ptr hc = GetCheckService();
-
- if (!hc)
- return 0;
-
- return hc->GetLastStateCritical();
-}
-
-double Host::GetLastStateUnreachable(void) const
-{
- ASSERT(!OwnsLock());
-
- Service::Ptr hc = GetCheckService();
-
- if (!hc)
- return 0;
-
- return hc->GetLastStateUnreachable();
-}
-
-double Host::GetLastStateChange(void) const
-{
- Service::Ptr hc = GetCheckService();
-
- if (!hc)
- return Application::GetStartTime();
-
- return hc->GetLastStateChange();
-}
-
-
-double Host::GetLastHardStateChange(void) const
-{
- Service::Ptr hc = GetCheckService();
-
- if (!hc)
- return Application::GetStartTime();
-
- return hc->GetLastHardStateChange();
-}
-
-StateType Host::GetLastStateType(void) const
-{
- Service::Ptr hc = GetCheckService();
-
- if (!hc)
- return StateTypeHard;
-
- return hc->GetLastStateType();
-}
-
-StateType Host::GetStateType(void) const
-{
- Service::Ptr hc = GetCheckService();
-
- if (!hc)
- return StateTypeHard;
-
- return hc->GetStateType();
+ return GetLastStateCritical();
}
HostState Host::StateFromString(const String& state)
return true;
}
- Service::Ptr hc = GetCheckService();
- CheckResult::Ptr hccr;
-
- if (hc) {
- ServiceState state = hc->GetState();
- bool reachable = IsReachable();
-
- if (macro == "HOSTSTATE") {
- HostState hstate = CalculateState(state, reachable);
-
- switch (hstate) {
- case HostUnreachable:
- *result = "UNREACHABLE";
- break;
- case HostUp:
- *result = "UP";
- break;
- case HostDown:
- *result = "DOWN";
- break;
- default:
- ASSERT(0);
- }
-
- return true;
- } else if (macro == "HOSTSTATEID") {
- *result = Convert::ToString(state);
- return true;
- } else if (macro == "HOSTSTATETYPE") {
- *result = Service::StateTypeToString(hc->GetStateType());
- return true;
- } else if (macro == "HOSTATTEMPT") {
- *result = Convert::ToString(hc->GetCheckAttempt());
- return true;
- } else if (macro == "MAXHOSTATTEMPT") {
- *result = Convert::ToString(hc->GetMaxCheckAttempts());
- return true;
- } else if (macro == "LASTHOSTSTATE") {
- *result = StateToString(GetLastState());
- return true;
- } else if (macro == "LASTHOSTSTATEID") {
- *result = Convert::ToString(GetLastState());
- return true;
- } else if (macro == "LASTHOSTSTATETYPE") {
- *result = Service::StateTypeToString(GetLastStateType());
- return true;
- } else if (macro == "LASTHOSTSTATECHANGE") {
- *result = Convert::ToString((long)hc->GetLastStateChange());
- return true;
- } else if (macro == "HOSTDURATIONSEC") {
- *result = Convert::ToString((long)(Utility::GetTime() - hc->GetLastStateChange()));
- return true;
+ CheckResult::Ptr cr = GetLastCheckResult();
+
+ if (macro == "HOSTSTATE") {
+ switch (GetState()) {
+ case HostUnreachable:
+ *result = "UNREACHABLE";
+ break;
+ case HostUp:
+ *result = "UP";
+ break;
+ case HostDown:
+ *result = "DOWN";
+ break;
+ default:
+ ASSERT(0);
}
- hccr = hc->GetLastCheckResult();
+ return true;
+ } else if (macro == "HOSTSTATEID") {
+ *result = Convert::ToString(GetState());
+ return true;
+ } else if (macro == "HOSTSTATETYPE") {
+ *result = StateTypeToString(GetStateType());
+ return true;
+ } else if (macro == "HOSTATTEMPT") {
+ *result = Convert::ToString(GetCheckAttempt());
+ return true;
+ } else if (macro == "MAXHOSTATTEMPT") {
+ *result = Convert::ToString(GetMaxCheckAttempts());
+ return true;
+ } else if (macro == "LASTHOSTSTATE") {
+ *result = StateToString(GetLastState());
+ return true;
+ } else if (macro == "LASTHOSTSTATEID") {
+ *result = Convert::ToString(GetLastState());
+ return true;
+ } else if (macro == "LASTHOSTSTATETYPE") {
+ *result = StateTypeToString(GetLastStateType());
+ return true;
+ } else if (macro == "LASTHOSTSTATECHANGE") {
+ *result = Convert::ToString((long)GetLastStateChange());
+ return true;
+ } else if (macro == "HOSTDURATIONSEC") {
+ *result = Convert::ToString((long)(Utility::GetTime() - GetLastStateChange()));
+ return true;
+ } else if (macro == "HOSTCHECKCOMMAND") {
+ CheckCommand::Ptr commandObj = GetCheckCommand();
+
+ if (commandObj)
+ *result = commandObj->GetName();
+ else
+ *result = "";
+
+ return true;
}
- if (hccr) {
+
+ if (cr) {
if (macro == "HOSTLATENCY") {
- *result = Convert::ToString(Service::CalculateLatency(hccr));
+ *result = Convert::ToString(Service::CalculateLatency(cr));
return true;
} else if (macro == "HOSTEXECUTIONTIME") {
- *result = Convert::ToString(Service::CalculateExecutionTime(hccr));
+ *result = Convert::ToString(Service::CalculateExecutionTime(cr));
return true;
} else if (macro == "HOSTOUTPUT") {
- *result = hccr->GetOutput();
+ *result = cr->GetOutput();
return true;
} else if (macro == "HOSTPERFDATA") {
- *result = PluginUtility::FormatPerfdata(hccr->GetPerformanceData());
- return true;
- } else if (macro == "HOSTCHECKCOMMAND") {
- CheckCommand::Ptr commandObj = hc->GetCheckCommand();
-
- if (commandObj)
- *result = commandObj->GetName();
- else
- *result = "";
-
+ *result = PluginUtility::FormatPerfdata(cr->GetPerformanceData());
return true;
} else if (macro == "LASTHOSTCHECK") {
- *result = Convert::ToString((long)hccr->GetScheduleStart());
+ *result = Convert::ToString((long)cr->GetScheduleStart());
return true;
}
}
return true;
}
-
String name = macro;
if (name == "HOSTADDRESS")
HostUnreachable = 2
};
-enum DependencyType
-{
- DependencyState,
- DependencyCheckExecution,
- DependencyNotification
-};
-
/**
* An Icinga host.
*
DECLARE_PTR_TYPEDEFS(Host);
DECLARE_TYPENAME(Host);
- shared_ptr<Service> GetCheckService(void) const;
-
- std::set<Host::Ptr> GetParentHosts(void) const;
- std::set<Host::Ptr> GetChildHosts(void) const;
- std::set<shared_ptr<Service> > GetParentServices(void) const;
- std::set<shared_ptr<Service> > GetChildServices(void) const;
-
- bool IsReachable(DependencyType dt = DependencyState, shared_ptr<Dependency> *failedDependency = NULL) const;
-
- shared_ptr<Service> GetServiceByShortName(const Value& name) const;
+ shared_ptr<Service> GetServiceByShortName(const Value& name);
std::set<shared_ptr<Service> > GetServices(void) const;
void AddService(const shared_ptr<Service>& service);
static HostState CalculateState(ServiceState state, bool reachable);
HostState GetState(void) const;
- StateType GetStateType(void) const;
HostState GetLastState(void) const;
HostState GetLastHardState(void) const;
- StateType GetLastStateType(void) const;
- double GetLastStateChange(void) const;
- double GetLastHardStateChange(void) const;
double GetLastStateUp(void) const;
double GetLastStateDown(void) const;
- double GetLastStateUnreachable(void) const;
static HostState StateFromString(const String& state);
static String StateToString(HostState state);
+#include "icinga/checkable.h"
#include "base/dynamicobject.h"
namespace icinga
{
-class Host : DynamicObject
+class Host : Checkable
{
[config] String display_name {
get {{{
}}}
};
[config] Array::Ptr groups;
- [config] String check;
- [config, protected] Dictionary::Ptr services (ServiceDescriptions);
- [config] Dictionary::Ptr dependencies (DependencyDescriptions);
};
}
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-%type Host {
- %attribute %string "display_name",
- %attribute %string "check",
- %attribute %array "groups" {
- %attribute %name(HostGroup) "*"
- },
-}
-
-%type HostGroup {
- %attribute %string "display_name"
-}
-
%type IcingaApplication {
}
%attribute %number "update_interval"
}
-%type Service {
- %require "host",
- %attribute %name(Host) "host",
-
- %attribute %string "short_name",
-
+%type Checkable {
%attribute %string "display_name",
%require "check_command",
%attribute %number "volatile",
+ %attribute %array "authorities" {
+ %attribute %name(Endpoint) "*"
+ },
+}
+
+%type Host %inherits Checkable {
+ %attribute %string "display_name",
%attribute %array "groups" {
- %attribute %name(ServiceGroup) "*"
+ %attribute %name(HostGroup) "*"
},
+}
- %attribute %array "authorities" {
- %attribute %name(Endpoint) "*"
+%type HostGroup {
+ %attribute %string "display_name"
+}
+
+%type Service %inherits Checkable {
+ %require "host",
+ %attribute %name(Host) "host",
+
+ %attribute %string "short_name",
+
+
+ %attribute %array "groups" {
+ %attribute %name(ServiceGroup) "*"
},
}
#include "base/context.h"
#include "base/statsfunction.h"
#include <boost/foreach.hpp>
-#include <boost/tuple/tuple.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <fstream>
{
DynamicObject::Start();
- GetService()->AddNotification(GetSelf());
+ GetCheckable()->AddNotification(GetSelf());
}
void Notification::Stop(void)
{
DynamicObject::Stop();
- GetService()->RemoveNotification(GetSelf());
+ GetCheckable()->RemoveNotification(GetSelf());
}
-Service::Ptr Notification::GetService(void) const
+Checkable::Ptr Notification::GetCheckable(void) const
{
Host::Ptr host = Host::GetByName(GetHostRaw());
if (GetServiceRaw().IsEmpty())
- return host->GetCheckService();
+ return host;
else
return host->GetServiceByShortName(GetServiceRaw());
}
{
ASSERT(!OwnsLock());
+ Checkable::Ptr checkable = GetCheckable();
+
if (!force) {
TimePeriod::Ptr tp = GetNotificationPeriod();
double now = Utility::GetTime();
Dictionary::Ptr times = GetTimes();
- Service::Ptr service = GetService();
if (type == NotificationProblem) {
- if (times && times->Contains("begin") && now < service->GetLastHardStateChange() + times->Get("begin")) {
+ if (times && times->Contains("begin") && now < checkable->GetLastHardStateChange() + times->Get("begin")) {
Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': before escalation range");
return;
}
- if (times && times->Contains("end") && now > service->GetLastHardStateChange() + times->Get("end")) {
+ if (times && times->Contains("end") && now > checkable->GetLastHardStateChange() + times->Get("end")) {
Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': after escalation range");
return;
}
return;
}
- unsigned long fstate = 1 << GetService()->GetState();
+ Service::Ptr service = dynamic_pointer_cast<Service>(checkable);
+ Host::Ptr host;
+
+ if (service)
+ host = service->GetHost();
+ else
+ host = static_pointer_cast<Host>(checkable);
+
+ unsigned long fstate;
+
+ if (service)
+ fstate = 1 << service->GetState();
+ else
+ fstate = 1 << host->GetState();
if (!(fstate & GetNotificationStateFilter())) {
Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': state filter does not match");
std::copy(members.begin(), members.end(), std::inserter(allUsers, allUsers.begin()));
}
- Service::OnNotificationSendStart(GetSelf(), GetService(), allUsers, type, cr, author, text);
+ Service::OnNotificationSendStart(GetSelf(), checkable, allUsers, type, cr, author, text);
std::set<User::Ptr> allNotifiedUsers;
BOOST_FOREACH(const User::Ptr& user, allUsers) {
}
/* used in db_ido for notification history */
- Service::OnNotificationSentToAllUsers(GetSelf(), GetService(), allNotifiedUsers, type, cr, author, text);
+ Service::OnNotificationSentToAllUsers(GetSelf(), checkable, allNotifiedUsers, type, cr, author, text);
}
bool Notification::CheckNotificationUserFilters(NotificationType type, const User::Ptr& user, bool force)
return false;
}
- unsigned long fstate = 1 << GetService()->GetState();
+ Checkable::Ptr checkable = GetCheckable();
+ Service::Ptr service = dynamic_pointer_cast<Service>(checkable);
+ Host::Ptr host;
+
+ if (service)
+ host = service->GetHost();
+ else
+ host = static_pointer_cast<Host>(checkable);
+
+ unsigned long fstate;
+
+ if (service)
+ fstate = 1 << service->GetState();
+ else
+ fstate = 1 << host->GetState();
if (!(fstate & user->GetNotificationStateFilter())) {
Log(LogInformation, "icinga", "Not sending notifications for notification object '" +
}
/* required by compatlogger */
- Service::OnNotificationSentToUser(GetSelf(), GetService(), user, type, cr, author, text, command->GetName());
+ Service::OnNotificationSentToUser(GetSelf(), GetCheckable(), user, type, cr, author, text, command->GetName());
- Log(LogInformation, "icinga", "Completed sending notification for service '" + GetService()->GetName() + "'");
+ Log(LogInformation, "icinga", "Completed sending notification for object '" + GetCheckable()->GetName() + "'");
} catch (const std::exception& ex) {
std::ostringstream msgbuf;
- msgbuf << "Exception occured during notification for service '"
- << GetService()->GetName() << "': " << DiagnosticInformation(ex);
+ msgbuf << "Exception occured during notification for object '"
+ << GetCheckable()->GetName() << "': " << DiagnosticInformation(ex);
Log(LogWarning, "icinga", msgbuf.str());
}
}
NotificationFlappingEnd = 8,
};
-class Service;
class NotificationCommand;
+class Checkable;
/**
* An Icinga notification specification.
static void StaticInitialize(void);
- shared_ptr<Service> GetService(void) const;
+ shared_ptr<Checkable> GetCheckable(void) const;
shared_ptr<NotificationCommand> GetNotificationCommand(void) const;
TimePeriod::Ptr GetNotificationPeriod(void) const;
std::set<User::Ptr> GetUsers(void) const;
}
}
-Service::Ptr ScheduledDowntime::GetService(void) const
+Checkable::Ptr ScheduledDowntime::GetCheckable(void) const
{
Host::Ptr host = Host::GetByName(GetHostRaw());
if (GetServiceRaw().IsEmpty())
- return host->GetCheckService();
+ return host;
else
return host->GetServiceByShortName(GetServiceRaw());
}
void ScheduledDowntime::CreateNextDowntime(void)
{
- Dictionary::Ptr downtimes = GetService()->GetDowntimes();
+ Dictionary::Ptr downtimes = GetCheckable()->GetDowntimes();
{
ObjectLock dlock(downtimes);
return;
}
- GetService()->AddDowntime(GetAuthor(), GetComment(),
+ GetCheckable()->AddDowntime(GetAuthor(), GetComment(),
segment.first, segment.second,
GetFixed(), String(), GetDuration(), GetName());
}
static void StaticInitialize(void);
- Service::Ptr GetService(void) const;
+ Checkable::Ptr GetCheckable(void) const;
static void RegisterApplyRuleHandler(void);
static void EvaluateApplyRules(const std::vector<ApplyRule>& rules);
REGISTER_TYPE(Service);
-boost::signals2::signal<void (const Service::Ptr&, const String&, const String&, AcknowledgementType, double, const String&)> Service::OnAcknowledgementSet;
-boost::signals2::signal<void (const Service::Ptr&, const String&)> Service::OnAcknowledgementCleared;
-
INITIALIZE_ONCE(&Service::StartDowntimesExpiredTimer);
-Service::Service(void)
- : m_CheckRunning(false)
-{ }
-
-void Service::Start(void)
-{
- double now = Utility::GetTime();
-
- if (GetNextCheck() < now + 300)
- UpdateNextCheck();
-
- DynamicObject::Start();
-}
-
void Service::OnConfigLoaded(void)
{
Array::Ptr groups = GetGroups();
m_Host->AddService(GetSelf());
SetSchedulingOffset(Utility::Random());
-}
-
-void Service::OnStateLoaded(void)
-{
- AddDowntimesToCache();
- AddCommentsToCache();
-
- std::vector<String> ids;
- Dictionary::Ptr downtimes = GetDowntimes();
- {
- ObjectLock dlock(downtimes);
- BOOST_FOREACH(const Dictionary::Pair& kv, downtimes) {
- Downtime::Ptr downtime = kv.second;
-
- if (downtime->GetScheduledBy().IsEmpty())
- continue;
-
- ids.push_back(kv.first);
- }
- }
-
- BOOST_FOREACH(const String& id, ids) {
- RemoveDowntime(id, true);
- }
+ Checkable::OnConfigLoaded();
}
Service::Ptr Service::GetByNamePair(const String& hostName, const String& serviceName)
return m_Host;
}
-bool Service::IsHostCheck(void) const
+ServiceState Service::StateFromString(const String& state)
{
- ASSERT(!OwnsLock());
-
- Service::Ptr hc = GetHost()->GetCheckService();
-
- if (!hc)
- return false;
-
- return (hc->GetName() == GetName());
-
-}
-
-AcknowledgementType Service::GetAcknowledgement(void)
-{
- ASSERT(OwnsLock());
-
- AcknowledgementType avalue = static_cast<AcknowledgementType>(GetAcknowledgementRaw());
-
- if (avalue != AcknowledgementNone) {
- double expiry = GetAcknowledgementExpiry();
-
- if (expiry != 0 && expiry < Utility::GetTime()) {
- avalue = AcknowledgementNone;
- ClearAcknowledgement();
- }
- }
-
- return avalue;
-}
-
-bool Service::IsAcknowledged(void)
-{
- return GetAcknowledgement() != AcknowledgementNone;
+ if (state == "OK")
+ return StateOK;
+ else if (state == "WARNING")
+ return StateWarning;
+ else if (state == "CRITICAL")
+ return StateCritical;
+ else
+ return StateUnknown;
}
-void Service::AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry, const String& authority)
+String Service::StateToString(ServiceState state)
{
- {
- ObjectLock olock(this);
-
- SetAcknowledgementRaw(type);
- SetAcknowledgementExpiry(expiry);
+ switch (state) {
+ case StateOK:
+ return "OK";
+ case StateWarning:
+ return "WARNING";
+ case StateCritical:
+ return "CRITICAL";
+ case StateUnknown:
+ default:
+ return "UNKNOWN";
}
-
- OnNotificationsRequested(GetSelf(), NotificationAcknowledgement, GetLastCheckResult(), author, comment);
-
- OnAcknowledgementSet(GetSelf(), author, comment, type, expiry, authority);
}
-void Service::ClearAcknowledgement(const String& authority)
+StateType Service::StateTypeFromString(const String& type)
{
- ASSERT(OwnsLock());
-
- SetAcknowledgementRaw(AcknowledgementNone);
- SetAcknowledgementExpiry(0);
-
- OnAcknowledgementCleared(GetSelf(), authority);
-}
-
-bool Service::GetEnablePerfdata(void) const
-{
- if (!GetOverrideEnablePerfdata().IsEmpty())
- return GetOverrideEnablePerfdata();
+ if (type == "SOFT")
+ return StateTypeSoft;
else
- return GetEnablePerfdataRaw();
-}
-
-void Service::SetEnablePerfdata(bool enabled, const String& authority)
-{
- SetOverrideEnablePerfdata(enabled);
-}
-
-int Service::GetModifiedAttributes(void) const
-{
- int attrs = 0;
-
- if (!GetOverrideEnableNotifications().IsEmpty())
- attrs |= ModAttrNotificationsEnabled;
-
- if (!GetOverrideEnableActiveChecks().IsEmpty())
- attrs |= ModAttrActiveChecksEnabled;
-
- if (!GetOverrideEnablePassiveChecks().IsEmpty())
- attrs |= ModAttrPassiveChecksEnabled;
-
- if (!GetOverrideEnableFlapping().IsEmpty())
- attrs |= ModAttrFlapDetectionEnabled;
-
- if (!GetOverrideEnableEventHandler().IsEmpty())
- attrs |= ModAttrEventHandlerEnabled;
-
- if (!GetOverrideEnablePerfdata().IsEmpty())
- attrs |= ModAttrPerformanceDataEnabled;
-
- if (!GetOverrideCheckInterval().IsEmpty())
- attrs |= ModAttrNormalCheckInterval;
-
- if (!GetOverrideRetryInterval().IsEmpty())
- attrs |= ModAttrRetryCheckInterval;
-
- if (!GetOverrideEventCommand().IsEmpty())
- attrs |= ModAttrEventHandlerCommand;
-
- if (!GetOverrideCheckCommand().IsEmpty())
- attrs |= ModAttrCheckCommand;
-
- if (!GetOverrideMaxCheckAttempts().IsEmpty())
- attrs |= ModAttrMaxCheckAttempts;
-
- if (!GetOverrideCheckPeriod().IsEmpty())
- attrs |= ModAttrCheckTimeperiod;
-
- // TODO: finish
-
- return attrs;
+ return StateTypeHard;
}
-void Service::SetModifiedAttributes(int flags)
+String Service::StateTypeToString(StateType type)
{
- if ((flags & ModAttrNotificationsEnabled) == 0)
- SetOverrideEnableNotifications(Empty);
-
- if ((flags & ModAttrActiveChecksEnabled) == 0)
- SetOverrideEnableActiveChecks(Empty);
-
- if ((flags & ModAttrPassiveChecksEnabled) == 0)
- SetOverrideEnablePassiveChecks(Empty);
-
- if ((flags & ModAttrFlapDetectionEnabled) == 0)
- SetOverrideEnableFlapping(Empty);
-
- if ((flags & ModAttrEventHandlerEnabled) == 0)
- SetOverrideEnableEventHandler(Empty);
-
- if ((flags & ModAttrPerformanceDataEnabled) == 0)
- SetOverrideEnablePerfdata(Empty);
-
- if ((flags & ModAttrNormalCheckInterval) == 0)
- SetOverrideCheckInterval(Empty);
-
- if ((flags & ModAttrRetryCheckInterval) == 0)
- SetOverrideRetryInterval(Empty);
-
- if ((flags & ModAttrEventHandlerCommand) == 0)
- SetOverrideEventCommand(Empty);
-
- if ((flags & ModAttrCheckCommand) == 0)
- SetOverrideCheckCommand(Empty);
-
- if ((flags & ModAttrMaxCheckAttempts) == 0)
- SetOverrideMaxCheckAttempts(Empty);
-
- if ((flags & ModAttrCheckTimeperiod) == 0)
- SetOverrideCheckPeriod(Empty);
+ if (type == StateTypeSoft)
+ return "SOFT";
+ else
+ return "HARD";
}
bool Service::ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const
return false;
}
+
+boost::tuple<Host::Ptr, Service::Ptr> icinga::GetHostService(const Checkable::Ptr& checkable)
+{
+ Service::Ptr service = dynamic_pointer_cast<Service>(checkable);
+
+ if (service)
+ return boost::make_tuple(service->GetHost(), service);
+ else
+ return boost::make_tuple(static_pointer_cast<Host>(checkable), Service::Ptr());
+}
+
namespace icinga
{
-/**
- * The state of service flapping.
- *
- * @ingroup icinga
- */
-enum FlappingState
-{
- FlappingStarted = 0,
- FlappingDisabled = 1,
- FlappingStopped = 2,
- FlappingEnabled = 3
-};
-
-/**
- * Modified attributes.
- *
- * @ingroup icinga
- */
-enum ModifiedAttributeType
-{
- ModAttrNotificationsEnabled = 1,
- ModAttrActiveChecksEnabled = 2,
- ModAttrPassiveChecksEnabled = 4,
- ModAttrEventHandlerEnabled = 8,
- ModAttrFlapDetectionEnabled = 16,
- ModAttrFailurePredictionEnabled = 32,
- ModAttrPerformanceDataEnabled = 64,
- ModAttrObsessiveHandlerEnabled = 128,
- ModAttrEventHandlerCommand = 256,
- ModAttrCheckCommand = 512,
- ModAttrNormalCheckInterval = 1024,
- ModAttrRetryCheckInterval = 2048,
- ModAttrMaxCheckAttempts = 4096,
- ModAttrFreshnessChecksEnabled = 8192,
- ModAttrCheckTimeperiod = 16384,
- ModAttrCustomVariable = 32768,
- ModAttrNotificationTimeperiod = 65536
-};
-
-class CheckCommand;
-class EventCommand;
-
/**
* An Icinga service.
*
DECLARE_PTR_TYPEDEFS(Service);
DECLARE_TYPENAME(Service);
- Service(void);
-
static Service::Ptr GetByNamePair(const String& hostName, const String& serviceName);
Host::Ptr GetHost(void) const;
- std::set<Host::Ptr> GetParentHosts(void) const;
- std::set<Host::Ptr> GetChildHosts(void) const;
- std::set<Service::Ptr> GetParentServices(void) const;
- std::set<Service::Ptr> GetChildServices(void) const;
-
- bool IsHostCheck(void) const;
-
- bool IsReachable(DependencyType dt = DependencyState, shared_ptr<Dependency> *failedDependency = NULL, int rstack = 0) const;
-
- AcknowledgementType GetAcknowledgement(void);
-
- void AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry = 0, const String& authority = String());
- void ClearAcknowledgement(const String& authority = String());
-
- /* Checks */
- shared_ptr<CheckCommand> GetCheckCommand(void) const;
- void SetCheckCommand(const shared_ptr<CheckCommand>& command);
-
- TimePeriod::Ptr GetCheckPeriod(void) const;
- void SetCheckPeriod(const TimePeriod::Ptr& tp);
-
- double GetCheckInterval(void) const;
- void SetCheckInterval(double interval);
-
- double GetRetryInterval(void) const;
- void SetRetryInterval(double interval);
-
- int GetMaxCheckAttempts(void) const;
- void SetMaxCheckAttempts(int attempts);
-
- long GetSchedulingOffset(void);
- void SetSchedulingOffset(long offset);
-
- void SetNextCheck(double nextCheck, const String& authority = String());
- double GetNextCheck(void);
- void UpdateNextCheck(void);
-
- bool HasBeenChecked(void) const;
-
- double GetLastCheck(void) const;
-
- bool GetEnableActiveChecks(void) const;
- void SetEnableActiveChecks(bool enabled, const String& authority = String());
-
- bool GetEnablePassiveChecks(void) const;
- void SetEnablePassiveChecks(bool enabled, const String& authority = String());
-
- bool GetForceNextCheck(void) const;
- void SetForceNextCheck(bool forced, const String& authority = String());
-
- static void UpdateStatistics(const CheckResult::Ptr& cr);
-
- void ExecuteCheck(void);
- void ProcessCheckResult(const CheckResult::Ptr& cr, const String& authority = String());
-
- int GetModifiedAttributes(void) const;
- void SetModifiedAttributes(int flags);
-
- static double CalculateExecutionTime(const CheckResult::Ptr& cr);
- static double CalculateLatency(const CheckResult::Ptr& cr);
+ virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const;
static ServiceState StateFromString(const String& state);
static String StateToString(ServiceState state);
static StateType StateTypeFromString(const String& state);
static String StateTypeToString(StateType state);
- static boost::signals2::signal<void (const Service::Ptr&, double, const String&)> OnNextCheckChanged;
- static boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> OnForceNextCheckChanged;
- static boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> OnForceNextNotificationChanged;
- static boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> OnEnableActiveChecksChanged;
- static boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> OnEnablePassiveChecksChanged;
- static boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> OnEnableNotificationsChanged;
- static boost::signals2::signal<void (const Service::Ptr&, bool, const String&)> OnEnableFlappingChanged;
- static boost::signals2::signal<void (const Service::Ptr&, const CheckResult::Ptr&, const String&)> OnNewCheckResult;
- static boost::signals2::signal<void (const Service::Ptr&, const CheckResult::Ptr&, StateType, const String&)> OnStateChange;
- static boost::signals2::signal<void (const Service::Ptr&, NotificationType, const CheckResult::Ptr&,
- const String&, const String&)> OnNotificationsRequested;
- static boost::signals2::signal<void (const Notification::Ptr&, const Service::Ptr&, const std::set<User::Ptr>&,
- const NotificationType&, const CheckResult::Ptr&, const String&,
- const String&)> OnNotificationSendStart;
- static boost::signals2::signal<void (const Notification::Ptr&, const Service::Ptr&, const User::Ptr&,
- const NotificationType&, const CheckResult::Ptr&, const String&,
- const String&, const String&)> OnNotificationSentToUser;
- static boost::signals2::signal<void (const Notification::Ptr&, const Service::Ptr&, const std::set<User::Ptr>&,
- const NotificationType&, const CheckResult::Ptr&, const String&,
- const String&)> OnNotificationSentToAllUsers;
- static boost::signals2::signal<void (const Service::Ptr&, const Comment::Ptr&, const String&)> OnCommentAdded;
- static boost::signals2::signal<void (const Service::Ptr&, const Comment::Ptr&, const String&)> OnCommentRemoved;
- static boost::signals2::signal<void (const Service::Ptr&, const Downtime::Ptr&, const String&)> OnDowntimeAdded;
- static boost::signals2::signal<void (const Service::Ptr&, const Downtime::Ptr&, const String&)> OnDowntimeRemoved;
- static boost::signals2::signal<void (const Service::Ptr&, FlappingState)> OnFlappingChanged;
- static boost::signals2::signal<void (const Service::Ptr&, const Downtime::Ptr&)> OnDowntimeTriggered;
- static boost::signals2::signal<void (const Service::Ptr&, const String&, const String&, AcknowledgementType,
- double, const String&)> OnAcknowledgementSet;
- static boost::signals2::signal<void (const Service::Ptr&, const String&)> OnAcknowledgementCleared;
- static boost::signals2::signal<void (const Service::Ptr&)> OnEventCommandExecuted;
-
- virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const;
-
- /* Downtimes */
- static int GetNextDowntimeID(void);
-
- int GetDowntimeDepth(void) const;
-
- String AddDowntime(const String& author, const String& comment,
- double startTime, double endTime, bool fixed,
- const String& triggeredBy, double duration,
- const String& scheduledBy = String(), const String& id = String(),
- const String& authority = String());
-
- static void RemoveDowntime(const String& id, bool cancelled, const String& = String());
-
- void TriggerDowntimes(void);
- static void TriggerDowntime(const String& id);
-
- static String GetDowntimeIDFromLegacyID(int id);
- static Service::Ptr GetOwnerByDowntimeID(const String& id);
- static Downtime::Ptr GetDowntimeByID(const String& id);
-
- static void StartDowntimesExpiredTimer(void);
-
- bool IsInDowntime(void) const;
- bool IsAcknowledged(void);
-
- /* Comments */
- static int GetNextCommentID(void);
-
- String AddComment(CommentType entryType, const String& author,
- const String& text, double expireTime, const String& id = String(), const String& authority = String());
-
- void RemoveAllComments(void);
- void RemoveCommentsByType(int type);
- static void RemoveComment(const String& id, const String& authority = String());
-
- static String GetCommentIDFromLegacyID(int id);
- static Service::Ptr GetOwnerByCommentID(const String& id);
- static Comment::Ptr GetCommentByID(const String& id);
-
- /* Notifications */
- bool GetEnableNotifications(void) const;
- void SetEnableNotifications(bool enabled, const String& authority = String());
-
- void SendNotifications(NotificationType type, const CheckResult::Ptr& cr, const String& author = "", const String& text = "");
-
- std::set<Notification::Ptr> GetNotifications(void) const;
- void AddNotification(const Notification::Ptr& notification);
- void RemoveNotification(const Notification::Ptr& notification);
-
- void SetForceNextNotification(bool force, const String& authority = String());
- bool GetForceNextNotification(void) const;
-
- void ResetNotificationNumbers(void);
-
- /* Event Handler */
- void ExecuteEventHandler(void);
-
- shared_ptr<EventCommand> GetEventCommand(void) const;
- void SetEventCommand(const shared_ptr<EventCommand>& command);
-
- bool GetEnableEventHandler(void) const;
- void SetEnableEventHandler(bool enabled);
-
- /* Flapping Detection */
- double GetFlappingCurrent(void) const;
-
- bool GetEnableFlapping(void) const;
- void SetEnableFlapping(bool enabled, const String& authority = String());
-
- bool IsFlapping(void) const;
- void UpdateFlappingStatus(bool stateChange);
-
- /* Performance data */
- bool GetEnablePerfdata(void) const;
- void SetEnablePerfdata(bool enabled, const String& authority = String());
-
- /* Dependencies */
- void AddDependency(const shared_ptr<Dependency>& dep);
- void RemoveDependency(const shared_ptr<Dependency>& dep);
- std::set<shared_ptr<Dependency> > GetDependencies(void) const;
-
- void AddReverseDependency(const shared_ptr<Dependency>& dep);
- void RemoveReverseDependency(const shared_ptr<Dependency>& dep);
- std::set<shared_ptr<Dependency> > GetReverseDependencies(void) const;
-
static void RegisterApplyRuleHandler(void);
static void EvaluateApplyRules(const std::vector<ApplyRule>& rules);
protected:
- virtual void Start(void);
-
virtual void OnConfigLoaded(void);
- virtual void OnStateLoaded(void);
private:
Host::Ptr m_Host;
-
- bool m_CheckRunning;
- long m_SchedulingOffset;
-
- /* Downtimes */
- static void DowntimesExpireTimerHandler(void);
- void RemoveExpiredDowntimes(void);
- void AddDowntimesToCache(void);
-
- /* Comments */
- static void CommentsExpireTimerHandler(void);
- void RemoveExpiredComments(void);
- void AddCommentsToCache(void);
-
- /* Notifications */
- std::set<Notification::Ptr> m_Notifications;
-
- /* Dependencies */
- mutable boost::mutex m_DependencyMutex;
- std::set<shared_ptr<Dependency> > m_Dependencies;
- std::set<shared_ptr<Dependency> > m_ReverseDependencies;
};
+I2_ICINGA_API boost::tuple<Host::Ptr, Service::Ptr> GetHostService(const Checkable::Ptr& checkable);
+
}
#endif /* SERVICE_H */
+#include "icinga/checkable.h"
#include "icinga/host.h"
#include "icinga/icingaapplication.h"
#include "base/dynamicobject.h"
namespace icinga
{
-code {{{
-/**
- * The acknowledgement type of a service.
- *
- * @ingroup icinga
- */
-enum AcknowledgementType
-{
- AcknowledgementNone = 0,
- AcknowledgementNormal = 1,
- AcknowledgementSticky = 2
-};
-}}}
-
-class Service : DynamicObject
+class Service : Checkable
{
[config] String display_name {
get {{{
return m_DisplayName;
}}}
};
- [config] Array::Ptr groups;
- [config, protected] String check_command (CheckCommandRaw);
- [config] int max_check_attempts (MaxCheckAttemptsRaw) {
- default {{{ return 3; }}}
- };
- [config, protected] String check_period (CheckPeriodRaw);
- [config] double check_interval (CheckIntervalRaw) {
- default {{{ return 5 * 60; }}}
- };
- [config] double retry_interval (RetryIntervalRaw) {
- default {{{ return 60; }}}
- };
- [config] String event_command (EventCommandRaw);
- [config] bool volatile;
[config] String short_name {
get {{{
if (m_ShortName.IsEmpty())
}}}
};
[config] String host (HostRaw);
- [config] double flapping_threshold {
- default {{{ return 30; }}}
- };
- [config] Dictionary::Ptr notifications (NotificationDescriptions);
- [config] Dictionary::Ptr scheduled_downtimes (ScheduledDowntimeDescriptions);
- [config] Dictionary::Ptr dependencies (DependencyDescriptions);
- [config] bool enable_active_checks (EnableActiveChecksRaw) {
- default {{{ return true; }}}
- };
- [config] bool enable_passive_checks (EnablePassiveChecksRaw) {
- default {{{ return true; }}}
- };
- [config] bool enable_event_handler (EnableEventHandlerRaw) {
- default {{{ return true; }}}
- };
- [config] bool enable_notifications (EnableNotificationsRaw) {
- default {{{ return true; }}}
- };
- [config] bool enable_flapping (EnableFlappingRaw) {
- default {{{ return true; }}}
- };
- [config] bool enable_perfdata (EnablePerfdataRaw) {
- default {{{ return true; }}}
- };
-
- [state] double next_check (NextCheckRaw);
- [state] int check_attempt {
- default {{{ return 1; }}}
- };
- [state, enum] ServiceState "state" {
- default {{{ return StateUnknown; }}}
- };
- [state, enum] StateType state_type {
- default {{{ return StateTypeSoft; }}}
- };
- [state, enum] ServiceState last_state {
- default {{{ return StateUnknown; }}}
- };
- [state, enum] ServiceState last_hard_state {
- default {{{ return StateUnknown; }}}
- };
- [state, enum] StateType last_state_type {
- default {{{ return StateTypeSoft; }}}
- };
- [state] bool last_reachable {
- default {{{ return true; }}}
- };
- [state] CheckResult::Ptr last_check_result;
- [state] double last_state_change {
- default {{{ return Application::GetStartTime(); }}}
- };
- [state] double last_hard_state_change {
- default {{{ return Application::GetStartTime(); }}}
- };
- [state] double last_state_ok (LastStateOK);
- [state] double last_state_warning;
- [state] double last_state_critical;
- [state] double last_state_unknown;
- [state] double last_state_unreachable;
- [state] bool last_in_downtime;
- [state] bool force_next_check (ForceNextCheckRaw);
- [state] int acknowledgement (AcknowledgementRaw) {
- default {{{ return AcknowledgementNone; }}}
+ [enum] ServiceState "state" {
+ get {{{
+ return GetStateRaw();
+ }}}
};
- [state] double acknowledgement_expiry;
- [state] Dictionary::Ptr comments {
- default {{{ return make_shared<Dictionary>(); }}}
+ [enum] ServiceState last_state {
+ get {{{
+ return GetLastStateRaw();
+ }}}
};
- [state] Dictionary::Ptr downtimes {
- default {{{ return make_shared<Dictionary>(); }}}
+ [enum] ServiceState last_hard_state {
+ get {{{
+ return GetLastHardStateRaw();
+ }}}
};
- [state] bool force_next_notification (ForceNextNotificationRaw);
- [state] int flapping_positive;
- [state] int flapping_negative;
- [state] double flapping_last_change;
- [state] Value override_enable_notifications;
- [state] Value override_enable_active_checks;
- [state] Value override_enable_passive_checks;
- [state] Value override_enable_flapping;
- [state] Value override_enable_perfdata;
- [state] Value override_check_interval;
- [state] Value override_retry_interval;
- [state] Value override_enable_event_handler;
- [state] Value override_event_command;
- [state] Value override_check_command;
- [state] Value override_max_check_attempts;
- [state] Value override_check_period;
};
}
REGISTER_SCRIPTFUNCTION(IcingaCheck, &IcingaCheckTask::ScriptFunc);
-void IcingaCheckTask::ScriptFunc(const Service::Ptr& service, const CheckResult::Ptr& cr)
+void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr)
{
double interval = Utility::GetTime() - Application::GetStartTime();
class I2_METHODS_API IcingaCheckTask
{
public:
- static void ScriptFunc(const Service::Ptr& service, const CheckResult::Ptr& cr);
+ static void ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr);
private:
IcingaCheckTask(void);
REGISTER_SCRIPTFUNCTION(NullCheck, &NullCheckTask::ScriptFunc);
-void NullCheckTask::ScriptFunc(const Service::Ptr& service, const CheckResult::Ptr& cr)
+void NullCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr)
{
String output = "Hello from ";
output += Utility::GetHostName();
class I2_METHODS_API NullCheckTask
{
public:
- static void ScriptFunc(const Service::Ptr& service, const CheckResult::Ptr& cr);
+ static void ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr);
private:
NullCheckTask(void);
REGISTER_SCRIPTFUNCTION(NullEvent, &NullEventTask::ScriptFunc);
-void NullEventTask::ScriptFunc(const Service::Ptr&)
+void NullEventTask::ScriptFunc(const Checkable::Ptr&)
{ }
class I2_METHODS_API NullEventTask
{
public:
- static void ScriptFunc(const Service::Ptr& service);
+ static void ScriptFunc(const Checkable::Ptr& service);
private:
NullEventTask(void);
REGISTER_SCRIPTFUNCTION(PluginCheck, &PluginCheckTask::ScriptFunc);
-void PluginCheckTask::ScriptFunc(const Service::Ptr& service, const CheckResult::Ptr& cr)
+void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
{
- CheckCommand::Ptr commandObj = service->GetCheckCommand();
+ CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
Value raw_command = commandObj->GetCommandLine();
+ bool is_service = checkable->GetType() == DynamicType::GetByName("Service");
+ Host::Ptr host;
+ Service::Ptr service;
+
+ if (is_service) {
+ service = static_pointer_cast<Service>(checkable);
+ host = service->GetHost();
+ } else
+ host = static_pointer_cast<Host>(checkable);
+
std::vector<MacroResolver::Ptr> resolvers;
- resolvers.push_back(service);
- resolvers.push_back(service->GetHost());
+ if (is_service)
+ resolvers.push_back(service);
+ resolvers.push_back(host);
resolvers.push_back(commandObj);
resolvers.push_back(IcingaApplication::GetInstance());
- Value command = MacroProcessor::ResolveMacros(raw_command, resolvers, service->GetLastCheckResult(), Utility::EscapeShellCmd, commandObj->GetEscapeMacros());
+ Value command = MacroProcessor::ResolveMacros(raw_command, resolvers, checkable->GetLastCheckResult(), Utility::EscapeShellCmd, commandObj->GetEscapeMacros());
Dictionary::Ptr envMacros = make_shared<Dictionary>();
BOOST_FOREACH(const String& macro, export_macros) {
String value;
- if (!MacroProcessor::ResolveMacro(macro, resolvers, service->GetLastCheckResult(), &value)) {
+ if (!MacroProcessor::ResolveMacro(macro, resolvers, checkable->GetLastCheckResult(), &value)) {
Log(LogWarning, "icinga", "export_macros for service '" + service->GetName() + "' refers to unknown macro '" + macro + "'");
continue;
}
process->SetTimeout(commandObj->GetTimeout());
- process->Run(boost::bind(&PluginCheckTask::ProcessFinishedHandler, service, cr, _1));
+ process->Run(boost::bind(&PluginCheckTask::ProcessFinishedHandler, checkable, cr, _1));
}
-void PluginCheckTask::ProcessFinishedHandler(const Service::Ptr& service, const CheckResult::Ptr& cr, const ProcessResult& pr)
+void PluginCheckTask::ProcessFinishedHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const ProcessResult& pr)
{
String output = pr.Output;
output.Trim();
cr->SetExecutionStart(pr.ExecutionStart);
cr->SetExecutionEnd(pr.ExecutionEnd);
- service->ProcessCheckResult(cr);
+ checkable->ProcessCheckResult(cr);
}
class I2_METHODS_API PluginCheckTask
{
public:
- static void ScriptFunc(const Service::Ptr& service, const CheckResult::Ptr& cr);
+ static void ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr);
private:
PluginCheckTask(void);
- static void ProcessFinishedHandler(const Service::Ptr& service, const CheckResult::Ptr& cr, const ProcessResult& pr);
+ static void ProcessFinishedHandler(const Checkable::Ptr& service, const CheckResult::Ptr& cr, const ProcessResult& pr);
};
REGISTER_SCRIPTFUNCTION(PluginEvent, &PluginEventTask::ScriptFunc);
-void PluginEventTask::ScriptFunc(const Service::Ptr& service)
+void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable)
{
- EventCommand::Ptr commandObj = service->GetEventCommand();
+ EventCommand::Ptr commandObj = checkable->GetEventCommand();
Value raw_command = commandObj->GetCommandLine();
+ bool is_service = checkable->GetType() == DynamicType::GetByName("Service");
+ Host::Ptr host;
+ Service::Ptr service;
+
+ if (is_service) {
+ service = static_pointer_cast<Service>(checkable);
+ host = service->GetHost();
+ } else
+ host = static_pointer_cast<Host>(checkable);
+
std::vector<MacroResolver::Ptr> resolvers;
- resolvers.push_back(service);
- resolvers.push_back(service->GetHost());
+ if (is_service)
+ resolvers.push_back(service);
+ resolvers.push_back(host);
resolvers.push_back(commandObj);
resolvers.push_back(IcingaApplication::GetInstance());
- Value command = MacroProcessor::ResolveMacros(raw_command, resolvers, service->GetLastCheckResult(), Utility::EscapeShellCmd, commandObj->GetEscapeMacros());
+ Value command = MacroProcessor::ResolveMacros(raw_command, resolvers, checkable->GetLastCheckResult(), Utility::EscapeShellCmd, commandObj->GetEscapeMacros());
Dictionary::Ptr envMacros = make_shared<Dictionary>();
BOOST_FOREACH(const String& macro, export_macros) {
String value;
- if (!MacroProcessor::ResolveMacro(macro, resolvers, service->GetLastCheckResult(), &value)) {
+ if (!MacroProcessor::ResolveMacro(macro, resolvers, checkable->GetLastCheckResult(), &value)) {
Log(LogWarning, "icinga", "export_macros for command '" + commandObj->GetName() + "' refers to unknown macro '" + macro + "'");
continue;
}
class I2_METHODS_API PluginEventTask
{
public:
- static void ScriptFunc(const Service::Ptr& service);
+ static void ScriptFunc(const Checkable::Ptr& service);
private:
PluginEventTask(void);
NotificationType type = static_cast<NotificationType>(itype);
- Service::Ptr service = notification->GetService();
+ Checkable::Ptr checkable = notification->GetCheckable();
Value raw_command = commandObj->GetCommandLine();
notificationMacroResolver->Add("NOTIFICATIONAUTHORNAME", author);
notificationMacroResolver->Add("NOTIFICATIONCOMMENT", comment);
+ Host::Ptr host;
+ Service::Ptr service;
+ tie(host, service) = GetHostService(checkable);
+
std::vector<MacroResolver::Ptr> resolvers;
resolvers.push_back(user);
resolvers.push_back(notificationMacroResolver);
resolvers.push_back(notification);
- resolvers.push_back(service);
- resolvers.push_back(service->GetHost());
+ if (service)
+ resolvers.push_back(service);
+ resolvers.push_back(host);;
resolvers.push_back(commandObj);
resolvers.push_back(IcingaApplication::GetInstance());
process->SetTimeout(commandObj->GetTimeout());
- process->Run(boost::bind(&PluginNotificationTask::ProcessFinishedHandler, service, command, _1));
+ process->Run(boost::bind(&PluginNotificationTask::ProcessFinishedHandler, checkable, command, _1));
}
-void PluginNotificationTask::ProcessFinishedHandler(const Service::Ptr& service, const Value& command, const ProcessResult& pr)
+void PluginNotificationTask::ProcessFinishedHandler(const Checkable::Ptr& checkable, const Value& command, const ProcessResult& pr)
{
if (pr.ExitStatus != 0) {
std::ostringstream msgbuf;
- msgbuf << "Notification command '" << command << "' for service '"
- << service->GetName() << "' failed; exit status: "
+ msgbuf << "Notification command '" << command << "' for object '"
+ << checkable->GetName() << "' failed; exit status: "
<< pr.ExitStatus << ", output: " << pr.Output;
Log(LogWarning, "icinga", msgbuf.str());
}
-}
\ No newline at end of file
+}
private:
PluginNotificationTask(void);
- static void ProcessFinishedHandler(const Service::Ptr& service, const Value& command, const ProcessResult& pr);
+ static void ProcessFinishedHandler(const Checkable::Ptr& checkable, const Value& command, const ProcessResult& pr);
};
}
REGISTER_SCRIPTFUNCTION(RandomCheck, &RandomCheckTask::ScriptFunc);
-void RandomCheckTask::ScriptFunc(const Service::Ptr& service, const CheckResult::Ptr& cr)
+void RandomCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr)
{
String output = "Hello from ";
output += Utility::GetHostName();
class RandomCheckTask
{
public:
- static void ScriptFunc(const Service::Ptr& service, const CheckResult::Ptr& cr);
+ static void ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr);
private:
RandomCheckTask(void);