}
#endif /* _WIN32 */
-void CompatComponent::DumpComments(ofstream& fp, const DynamicObject::Ptr& owner)
+void CompatComponent::DumpComments(ofstream& fp, const Service::Ptr& owner, CompatObjectType type)
{
Service::Ptr service;
Host::Ptr host;
- Dictionary::Ptr comments;
-
- if (owner->GetType() == DynamicType::GetByName("Service")) {
- service = dynamic_pointer_cast<Service>(owner);
- comments = service->GetComments();
-
- host = service->GetHost();
- } else {
- host = dynamic_pointer_cast<Host>(owner);
- comments = host->GetComments();
- }
+ Dictionary::Ptr comments = owner->GetComments();
if (!comments)
return;
String id;
Dictionary::Ptr comment;
BOOST_FOREACH(tie(id, comment), comments) {
- if (CommentProcessor::IsCommentExpired(comment))
+ if (Service::IsCommentExpired(comment))
continue;
- if (!service)
+ if (type == CompatTypeHost)
fp << "hostcomment {" << "\n";
else
fp << "servicecomment {" << "\n"
- << "\t" << "service_description=" << service->GetShortName() << "\n";
+ << "\t" << "service_description=" << owner->GetShortName() << "\n";
- fp << "\t" << "host_name=" << host->GetName() << "\n"
+ fp << "\t" << "host_name=" << owner->GetHost()->GetName() << "\n"
<< "\t" << "comment_id=" << static_cast<String>(comment->Get("legacy_id")) << "\n"
<< "\t" << "entry_time=" << static_cast<double>(comment->Get("entry_time")) << "\n"
<< "\t" << "entry_type=" << static_cast<long>(comment->Get("entry_type")) << "\n"
}
}
-void CompatComponent::DumpDowntimes(ofstream& fp, const DynamicObject::Ptr& owner)
+void CompatComponent::DumpDowntimes(ofstream& fp, const Service::Ptr& owner, CompatObjectType type)
{
- Service::Ptr service;
- Host::Ptr host;
- Dictionary::Ptr downtimes;
-
- if (owner->GetType() == DynamicType::GetByName("Service")) {
- service = dynamic_pointer_cast<Service>(owner);
- downtimes = service->GetDowntimes();
-
- host = service->GetHost();
- } else {
- host = dynamic_pointer_cast<Host>(owner);
- downtimes = host->GetDowntimes();
- }
+ Dictionary::Ptr downtimes = owner->GetDowntimes();
if (!downtimes)
return;
String id;
Dictionary::Ptr downtime;
BOOST_FOREACH(tie(id, downtime), downtimes) {
- if (DowntimeProcessor::IsDowntimeExpired(downtime))
+ if (Service::IsDowntimeExpired(downtime))
continue;
- if (!service)
+ if (type == CompatTypeHost)
fp << "hostdowntime {" << "\n";
else
fp << "servicedowntime {" << "\n"
- << "\t" << "service_description=" << service->GetShortName() << "\n";
+ << "\t" << "service_description=" << owner->GetShortName() << "\n";
- Dictionary::Ptr triggeredByObj = DowntimeProcessor::GetDowntimeByID(downtime->Get("triggered_by"));
+ Dictionary::Ptr triggeredByObj = Service::GetDowntimeByID(downtime->Get("triggered_by"));
int triggeredByLegacy = 0;
if (triggeredByObj)
triggeredByLegacy = triggeredByObj->Get("legacy_id");
- fp << "\t" << "host_name=" << host->GetName() << "\n"
+ fp << "\t" << "host_name=" << owner->GetHost()->GetName() << "\n"
<< "\t" << "downtime_id=" << static_cast<String>(downtime->Get("legacy_id")) << "\n"
<< "\t" << "entry_time=" << static_cast<double>(downtime->Get("entry_time")) << "\n"
<< "\t" << "start_time=" << static_cast<double>(downtime->Get("start_time")) << "\n"
<< "\t" << "triggered_by=" << triggeredByLegacy << "\n"
<< "\t" << "fixed=" << static_cast<long>(downtime->Get("fixed")) << "\n"
<< "\t" << "duration=" << static_cast<long>(downtime->Get("duration")) << "\n"
- << "\t" << "is_in_effect=" << (DowntimeProcessor::IsDowntimeActive(downtime) ? 1 : 0) << "\n"
+ << "\t" << "is_in_effect=" << (Service::IsDowntimeActive(downtime) ? 1 : 0) << "\n"
<< "\t" << "author=" << static_cast<String>(downtime->Get("author")) << "\n"
<< "\t" << "comment=" << static_cast<String>(downtime->Get("comment")) << "\n"
<< "\t" << "trigger_time=" << static_cast<double>(downtime->Get("trigger_time")) << "\n"
Service::Ptr hostcheck = host->GetHostCheckService();
- if (hostcheck)
- DumpServiceStatusAttrs(fp, hostcheck, CompatStateHost);
+ if (hostcheck) {
+ DumpServiceStatusAttrs(fp, hostcheck, CompatTypeHost);
+ }
- fp << "\t" << "problem_has_been_acknowledged=" << (host->GetAcknowledgement() != AcknowledgementNone ? 1 : 0) << "\n"
- << "\t" << "acknowledgement_type=" << static_cast<int>(host->GetAcknowledgement()) << "\n"
- << "\t" << "acknowledgement_end_time=" << host->GetAcknowledgementExpiry() << "\n"
- << "\t" << "scheduled_downtime_depth=" << (host->IsInDowntime() ? 1 : 0) << "\n"
- << "\t" << "}" << "\n"
+ fp << "\t" << "}" << "\n"
<< "\n";
- DumpDowntimes(fp, host);
- DumpComments(fp, host);
+ if (hostcheck) {
+ DumpDowntimes(fp, hostcheck, CompatTypeHost);
+ DumpComments(fp, hostcheck, CompatTypeHost);
+ }
}
void CompatComponent::DumpHostObject(ofstream& fp, const Host::Ptr& host)
<< "\n";
}
-void CompatComponent::DumpServiceStatusAttrs(ofstream& fp, const Service::Ptr& service, CompatStateType type)
+void CompatComponent::DumpServiceStatusAttrs(ofstream& fp, const Service::Ptr& service, CompatObjectType type)
{
String output;
String perfdata;
if (state > StateUnknown)
state = StateUnknown;
- if (type == CompatStateHost) {
+ if (type == CompatTypeHost) {
if (state == StateOK || state == StateWarning)
state = 0;
else
<< "\t" << "last_hard_state_change=" << service->GetLastHardStateChange() << "\n"
<< "\t" << "last_update=" << time(NULL) << "\n"
<< "\t" << "active_checks_enabled=" << (service->GetEnableActiveChecks() ? 1 : 0) <<"\n"
- << "\t" << "passive_checks_enabled=" << (service->GetEnablePassiveChecks() ? 1 : 0) << "\n";
+ << "\t" << "passive_checks_enabled=" << (service->GetEnablePassiveChecks() ? 1 : 0) << "\n"
+ << "\t" << "problem_has_been_acknowledged=" << (service->GetAcknowledgement() != AcknowledgementNone ? 1 : 0) << "\n"
+ << "\t" << "acknowledgement_type=" << static_cast<int>(service->GetAcknowledgement()) << "\n"
+ << "\t" << "acknowledgement_end_time=" << service->GetAcknowledgementExpiry() << "\n"
+ << "\t" << "scheduled_downtime_depth=" << (service->IsInDowntime() ? 1 : 0) << "\n";
}
void CompatComponent::DumpServiceStatus(ofstream& fp, const Service::Ptr& service)
<< "\t" << "host_name=" << service->GetHost()->GetName() << "\n"
<< "\t" << "service_description=" << service->GetShortName() << "\n";
- DumpServiceStatusAttrs(fp, service, CompatStateService);
+ DumpServiceStatusAttrs(fp, service, CompatTypeService);
- fp << "\t" << "problem_has_been_acknowledged=" << (service->GetAcknowledgement() != AcknowledgementNone ? 1 : 0) << "\n"
- << "\t" << "acknowledgement_type=" << static_cast<int>(service->GetAcknowledgement()) << "\n"
- << "\t" << "acknowledgement_end_time=" << service->GetAcknowledgementExpiry() << "\n"
- << "\t" << "scheduled_downtime_depth=" << (service->IsInDowntime() ? 1 : 0) << "\n"
- << "\t" << "}" << "\n"
+ fp << "\t" << "}" << "\n"
<< "\n";
- DumpDowntimes(fp, service);
- DumpComments(fp, service);
+ DumpDowntimes(fp, service, CompatTypeService);
+ DumpComments(fp, service, CompatTypeService);
}
void CompatComponent::DumpServiceObject(ofstream& fp, const Service::Ptr& service)
<< "\t" << "enable_failure_prediction=0" << "\n"
<< "\t" << "active_scheduled_service_check_stats=" << CIB::GetActiveChecksStatistics(60) << "," << CIB::GetActiveChecksStatistics(5 * 60) << "," << CIB::GetActiveChecksStatistics(15 * 60) << "\n"
<< "\t" << "passive_service_check_stats=" << CIB::GetPassiveChecksStatistics(60) << "," << CIB::GetPassiveChecksStatistics(5 * 60) << "," << CIB::GetPassiveChecksStatistics(15 * 60) << "\n"
- << "\t" << "next_downtime_id=" << DowntimeProcessor::GetNextDowntimeID() << "\n"
- << "\t" << "next_comment_id=" << CommentProcessor::GetNextCommentID() << "\n"
+ << "\t" << "next_downtime_id=" << Service::GetNextDowntimeID() << "\n"
+ << "\t" << "next_comment_id=" << Service::GetNextCommentID() << "\n"
<< "\t" << "}" << "\n"
<< "\n";
namespace icinga
{
-enum CompatStateType
+enum CompatObjectType
{
- CompatStateService,
- CompatStateHost
+ CompatTypeService,
+ CompatTypeHost
};
/**
String GetLogPath(void) const;
String GetCommandPath(void) const;
- void DumpDowntimes(ofstream& fp, const DynamicObject::Ptr& owner);
- void DumpComments(ofstream& fp, const DynamicObject::Ptr& owner);
+ void DumpDowntimes(ofstream& fp, const Service::Ptr& owner, CompatObjectType type);
+ void DumpComments(ofstream& fp, const Service::Ptr& owner, CompatObjectType type);
void DumpHostStatus(ofstream& fp, const Host::Ptr& host);
void DumpHostObject(ofstream& fp, const Host::Ptr& host);
- void DumpServiceStatusAttrs(ofstream& fp, const Service::Ptr& service, CompatStateType type);
+ void DumpServiceStatusAttrs(ofstream& fp, const Service::Ptr& service, CompatObjectType type);
template<typename T>
void DumpNameList(ofstream& fp, const T& list)
libicinga.la
libicinga_la_SOURCES = \
- acknowledgement.h \
checkresultmessage.cpp \
checkresultmessage.h \
cib.cpp \
cib.h \
- commentprocessor.cpp \
- commentprocessor.h \
- downtimeprocessor.cpp \
- downtimeprocessor.h \
externalcommandprocessor.cpp \
externalcommandprocessor.h \
host.cpp \
pluginchecktask.cpp \
pluginchecktask.h \
service.cpp \
+ service-comment.cpp \
+ service-downtime.cpp \
+ service.h \
servicegroup.cpp \
- servicegroup.h \
- service.h
+ servicegroup.h
libicinga_la_CPPFLAGS = \
-DI2_ICINGA_BUILD \
+++ /dev/null
-/******************************************************************************
- * Icinga 2 *
- * Copyright (C) 2012 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 ACKNOWLEDGEMENT_H
-#define ACKNOWLEDGEMENT_H
-
-namespace icinga
-{
-
-/**
- * The acknowledgement type of a host/service.
- *
- * @ingroup icinga
- */
-enum AcknowledgementType
-{
- AcknowledgementNone = 0,
- AcknowledgementNormal = 1,
- AcknowledgementSticky = 2
-};
-
-}
-
-#endif /* ACKNOWLEDGEMENT_H */
+++ /dev/null
-/******************************************************************************
- * Icinga 2 *
- * Copyright (C) 2012 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 COMMENTPROCESSOR_H
-#define COMMENTPROCESSOR_H
-
-namespace icinga
-{
-
-enum CommentType
-{
- Comment_User = 1,
- Comment_Downtime = 2,
- Comment_Flapping = 3,
- Comment_Acknowledgement = 4
-};
-
-/**
- * Comment processor.
- *
- * @ingroup icinga
- */
-class I2_ICINGA_API CommentProcessor
-{
-public:
- static int GetNextCommentID(void);
-
- static String AddComment(const DynamicObject::Ptr& owner,
- CommentType entryType, const String& author, const String& text,
- double expireTime);
-
- static void RemoveAllComments(const DynamicObject::Ptr& owner);
- static void RemoveComment(const String& id);
-
- static String GetIDFromLegacyID(int id);
- static DynamicObject::Ptr GetOwnerByCommentID(const String& id);
- static Dictionary::Ptr GetCommentByID(const String& id);
-
- static bool IsCommentExpired(const Dictionary::Ptr& comment);
-
- static void InvalidateCommentCache(void);
- static void ValidateCommentCache(void);
-
-private:
- static int m_NextCommentID;
-
- static map<int, String> m_LegacyCommentCache;
- static map<String, DynamicObject::WeakPtr> m_CommentCache;
- static bool m_CommentCacheValid;
- static Timer::Ptr m_CommentExpireTimer;
-
- CommentProcessor(void);
-
- static void CommentExpireTimerHandler(void);
-
- static void AddCommentsToCache(const DynamicObject::Ptr& owner);
- static void RemoveExpiredComments(const DynamicObject::Ptr& owner);
-};
-
-}
-
-#endif /* DOWNTIMEPROCESSOR_H */
+++ /dev/null
-/******************************************************************************
- * Icinga 2 *
- * Copyright (C) 2012 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 DOWNTIMEPROCESSOR_H
-#define DOWNTIMEPROCESSOR_H
-
-namespace icinga
-{
-
-/**
- * Downtime processor.
- *
- * @ingroup icinga
- */
-class I2_ICINGA_API DowntimeProcessor
-{
-public:
- static int GetNextDowntimeID(void);
-
- static String AddDowntime(const DynamicObject::Ptr& owner,
- const String& author, const String& comment,
- double startTime, double endTime,
- bool fixed, const String& triggeredBy, double duration);
-
- static void RemoveDowntime(const String& id);
-
- static void TriggerDowntimes(const DynamicObject::Ptr& owner);
- static void TriggerDowntime(const String& id);
-
- static String GetIDFromLegacyID(int id);
- static DynamicObject::Ptr GetOwnerByDowntimeID(const String& id);
- static Dictionary::Ptr GetDowntimeByID(const String& id);
-
- static bool IsDowntimeActive(const Dictionary::Ptr& downtime);
- static bool IsDowntimeExpired(const Dictionary::Ptr& downtime);
-
- static void InvalidateDowntimeCache(void);
- static void ValidateDowntimeCache(void);
-
-private:
- static int m_NextDowntimeID;
-
- static map<int, String> m_LegacyDowntimeCache;
- static map<String, DynamicObject::WeakPtr> m_DowntimeCache;
- static bool m_DowntimeCacheValid;
- static Timer::Ptr m_DowntimeExpireTimer;
-
- DowntimeProcessor(void);
-
- static void DowntimeExpireTimerHandler(void);
-
- static void AddDowntimesToCache(const DynamicObject::Ptr& owner);
- static void RemoveExpiredDowntimes(const DynamicObject::Ptr& owner);
-};
-
-}
-
-#endif /* DOWNTIMEPROCESSOR_H */
BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' is OK."));
Logger::Write(LogInformation, "icinga", "Setting acknowledgement for host '" + host->GetName() + "'");
- host->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal);
- host->SetAcknowledgementExpiry(0);
+ Service::Ptr service = host->GetHostCheckService();
+ if (service) {
+ service->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal);
+ service->SetAcknowledgementExpiry(0);
+ }
}
void ExternalCommandProcessor::AcknowledgeHostProblemExpire(double, const vector<String>& arguments)
BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' is OK."));
Logger::Write(LogInformation, "icinga", "Setting timed acknowledgement for host '" + host->GetName() + "'");
- host->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal);
- host->SetAcknowledgementExpiry(timestamp);
+ Service::Ptr service = host->GetHostCheckService();
+ if (service) {
+ service->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal);
+ service->SetAcknowledgementExpiry(timestamp);
+ }
}
void ExternalCommandProcessor::RemoveHostAcknowledgement(double, const vector<String>& arguments)
Host::Ptr host = Host::GetByName(arguments[0]);
Logger::Write(LogInformation, "icinga", "Removing acknowledgement for host '" + host->GetName() + "'");
- host->SetAcknowledgement(AcknowledgementNone);
- host->SetAcknowledgementExpiry(0);
+ Service::Ptr service = host->GetHostCheckService();
+ if (service) {
+ service->SetAcknowledgement(AcknowledgementNone);
+ service->SetAcknowledgementExpiry(0);
+ }
}
void ExternalCommandProcessor::EnableHostgroupSvcChecks(double, const vector<String>& arguments)
String triggeredBy;
int triggeredByLegacy = Convert::ToLong(arguments[5]);
if (triggeredByLegacy != 0)
- triggeredBy = DowntimeProcessor::GetIDFromLegacyID(triggeredByLegacy);
+ triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
- (void) DowntimeProcessor::AddDowntime(service, arguments[7], arguments[8],
+ (void) service->AddDowntime(arguments[7], arguments[8],
Convert::ToDouble(arguments[2]), Convert::ToDouble(arguments[3]),
Convert::ToBool(arguments[4]), triggeredBy, Convert::ToDouble(arguments[6]));
}
int id = Convert::ToLong(arguments[0]);
Logger::Write(LogInformation, "icinga", "Removing downtime ID " + arguments[0]);
- String rid = DowntimeProcessor::GetIDFromLegacyID(id);
- DowntimeProcessor::RemoveDowntime(rid);
+ String rid = Service::GetDowntimeIDFromLegacyID(id);
+ Service::RemoveDowntime(rid);
}
void ExternalCommandProcessor::ScheduleHostDowntime(double, const vector<String>& arguments)
String triggeredBy;
int triggeredByLegacy = Convert::ToLong(arguments[4]);
if (triggeredByLegacy != 0)
- triggeredBy = DowntimeProcessor::GetIDFromLegacyID(triggeredByLegacy);
+ triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
- (void) DowntimeProcessor::AddDowntime(host, arguments[6], arguments[7],
- Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
- Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
+ Service::Ptr service = host->GetHostCheckService();
+ 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 ExternalCommandProcessor::DelHostDowntime(double, const vector<String>& arguments)
int id = Convert::ToLong(arguments[0]);
Logger::Write(LogInformation, "icinga", "Removing downtime ID " + arguments[0]);
- String rid = DowntimeProcessor::GetIDFromLegacyID(id);
- DowntimeProcessor::RemoveDowntime(rid);
+ String rid = Service::GetDowntimeIDFromLegacyID(id);
+ Service::RemoveDowntime(rid);
}
void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const vector<String>& arguments)
String triggeredBy;
int triggeredByLegacy = Convert::ToLong(arguments[4]);
if (triggeredByLegacy != 0)
- triggeredBy = DowntimeProcessor::GetIDFromLegacyID(triggeredByLegacy);
-
- Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
- (void) DowntimeProcessor::AddDowntime(host, arguments[6], arguments[7],
- Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
- Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
+ triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
- (void) DowntimeProcessor::AddDowntime(service, arguments[6], arguments[7],
+ (void) service->AddDowntime(arguments[6], arguments[7],
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
}
String triggeredBy;
int triggeredByLegacy = Convert::ToLong(arguments[4]);
if (triggeredByLegacy != 0)
- triggeredBy = DowntimeProcessor::GetIDFromLegacyID(triggeredByLegacy);
+ triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
- (void) DowntimeProcessor::AddDowntime(host, arguments[6], arguments[7],
- Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
- Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
+ Service::Ptr service = host->GetHostCheckService();
+ 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]));
+ }
}
}
String triggeredBy;
int triggeredByLegacy = Convert::ToLong(arguments[4]);
if (triggeredByLegacy != 0)
- triggeredBy = DowntimeProcessor::GetIDFromLegacyID(triggeredByLegacy);
+ triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
/* Note: we can't just directly create downtimes for all the services by iterating
* over all hosts in the host group - otherwise we might end up creating multiple
BOOST_FOREACH(const Service::Ptr& service, services) {
Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
- (void) DowntimeProcessor::AddDowntime(service, arguments[6], arguments[7],
+ (void) service->AddDowntime(arguments[6], arguments[7],
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
}
String triggeredBy;
int triggeredByLegacy = Convert::ToLong(arguments[4]);
if (triggeredByLegacy != 0)
- triggeredBy = DowntimeProcessor::GetIDFromLegacyID(triggeredByLegacy);
+ triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
/* Note: we can't just directly create downtimes for all the hosts by iterating
* over all services in the service group - otherwise we might end up creating multiple
* downtimes for some hosts. */
- set<Host::Ptr> hosts;
+ set<Service::Ptr> services;
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
- hosts.insert(service->GetHost());
+ Service::Ptr hcService = service->GetHost()->GetHostCheckService();
+ if (hcService)
+ services.insert(hcService);
}
- BOOST_FOREACH(const Host::Ptr& host, hosts) {
- Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
- (void) DowntimeProcessor::AddDowntime(host, arguments[6], arguments[7],
+ BOOST_FOREACH(const Service::Ptr& service, services) {
+ Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
+ (void) service->AddDowntime(arguments[6], arguments[7],
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
}
String triggeredBy;
int triggeredByLegacy = Convert::ToLong(arguments[4]);
if (triggeredByLegacy != 0)
- triggeredBy = DowntimeProcessor::GetIDFromLegacyID(triggeredByLegacy);
+ triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
- (void) DowntimeProcessor::AddDowntime(service, arguments[6], arguments[7],
+ (void) service->AddDowntime(arguments[6], arguments[7],
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
}
Host::Ptr host = Host::GetByName(arguments[0]);
Logger::Write(LogInformation, "icinga", "Creating comment for host " + host->GetName());
- (void) CommentProcessor::AddComment(host, Comment_User, arguments[2], arguments[3], 0);
+ Service::Ptr service = host->GetHostCheckService();
+ if (service) {
+ (void) service->AddComment(CommentUser, arguments[2], arguments[3], 0);
+ }
}
void ExternalCommandProcessor::DelHostComment(double, const vector<String>& arguments)
int id = Convert::ToLong(arguments[0]);
Logger::Write(LogInformation, "icinga", "Removing comment ID " + arguments[0]);
- String rid = CommentProcessor::GetIDFromLegacyID(id);
- CommentProcessor::RemoveComment(rid);
+ String rid = Service::GetCommentIDFromLegacyID(id);
+ Service::RemoveComment(rid);
}
void ExternalCommandProcessor::AddSvcComment(double, const vector<String>& arguments)
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
Logger::Write(LogInformation, "icinga", "Creating comment for service " + service->GetName());
- (void) CommentProcessor::AddComment(service, Comment_User, arguments[3], arguments[4], 0);
+ (void) service->AddComment(CommentUser, arguments[3], arguments[4], 0);
}
void ExternalCommandProcessor::DelSvcComment(double, const vector<String>& arguments)
int id = Convert::ToLong(arguments[0]);
Logger::Write(LogInformation, "icinga", "Removing comment ID " + arguments[0]);
- String rid = CommentProcessor::GetIDFromLegacyID(id);
- CommentProcessor::RemoveComment(rid);
+ String rid = Service::GetCommentIDFromLegacyID(id);
+ Service::RemoveComment(rid);
}
void ExternalCommandProcessor::DelAllHostComments(double, const vector<String>& arguments)
Host::Ptr host = Host::GetByName(arguments[0]);
Logger::Write(LogInformation, "icinga", "Removing all comments for host " + host->GetName());
- CommentProcessor::RemoveAllComments(host);
+ Service::Ptr service = host->GetHostCheckService();
+ if (service) {
+ service->RemoveAllComments();
+ }
}
void ExternalCommandProcessor::DelAllSvcComments(double, const vector<String>& arguments)
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
Logger::Write(LogInformation, "icinga", "Removing all comments for service " + service->GetName());
- CommentProcessor::RemoveAllComments(service);
+ service->RemoveAllComments();
}
REGISTER_SCRIPTFUNCTION("native::ValidateServiceDictionary", &Host::ValidateServiceDictionary);
static AttributeDescription hostAttributes[] = {
- { "acknowledgement", Attribute_Replicated },
- { "acknowledgement_expiry", Attribute_Replicated },
- { "downtimes", Attribute_Replicated },
- { "comments", Attribute_Replicated },
{ "convenience_services", Attribute_Transient }
};
void Host::OnInitCompleted(void)
{
HostGroup::InvalidateMembersCache();
- DowntimeProcessor::InvalidateDowntimeCache();
UpdateSlaveServices();
}
Host::~Host(void)
{
HostGroup::InvalidateMembersCache();
- DowntimeProcessor::InvalidateDowntimeCache();
Dictionary::Ptr services = Get("convenience_services");
return Get("macros");
}
-Dictionary::Ptr Host::GetDowntimes(void) const
-{
- DowntimeProcessor::ValidateDowntimeCache();
-
- return Get("downtimes");
-}
-
-Dictionary::Ptr Host::GetComments(void) const
-{
- CommentProcessor::ValidateCommentCache();
-
- return Get("comments");
-}
-
Dictionary::Ptr Host::GetHostDependencies(void) const
{
return Get("hostdependencies");
bool Host::IsInDowntime(void) const
{
- Dictionary::Ptr downtimes = GetDowntimes();
-
- if (!downtimes)
- return false;
-
- Dictionary::Ptr downtime;
- BOOST_FOREACH(tie(tuples::ignore, downtime), downtimes) {
- if (DowntimeProcessor::IsDowntimeActive(downtime))
- return true;
- }
-
- return false;
+ Service::Ptr service = GetHostCheckService();
+ return (service || service->IsInDowntime());
}
bool Host::IsUp(void) const
{
if (name == "hostgroups")
HostGroup::InvalidateMembersCache();
- else if (name == "downtimes")
- DowntimeProcessor::InvalidateDowntimeCache();
else if (name == "services")
UpdateSlaveServices();
}
return services;
}
-AcknowledgementType Host::GetAcknowledgement(void)
-{
- Value value = Get("acknowledgement");
-
- if (value.IsEmpty())
- return AcknowledgementNone;
-
- int ivalue = static_cast<int>(value);
- AcknowledgementType avalue = static_cast<AcknowledgementType>(ivalue);
-
- if (avalue != AcknowledgementNone) {
- double expiry = GetAcknowledgementExpiry();
-
- if (expiry != 0 && expiry < Utility::GetTime()) {
- avalue = AcknowledgementNone;
- SetAcknowledgement(avalue);
- SetAcknowledgementExpiry(0);
- }
- }
-
- return avalue;
-}
-
-void Host::SetAcknowledgement(AcknowledgementType acknowledgement)
-{
- Set("acknowledgement", static_cast<long>(acknowledgement));
-}
-
-double Host::GetAcknowledgementExpiry(void) const
-{
- Value value = Get("acknowledgement_expiry");
-
- if (value.IsEmpty())
- return 0;
-
- return static_cast<double>(value);
-}
-
-void Host::SetAcknowledgementExpiry(double timestamp)
-{
- Set("acknowledgement_expiry", timestamp);
-}
-
void Host::InvalidateServicesCache(void)
{
m_ServicesCacheValid = false;
Dictionary::Ptr GetGroups(void) const;
Dictionary::Ptr GetMacros(void) const;
- Dictionary::Ptr GetDowntimes(void) const;
- Dictionary::Ptr GetComments(void) const;
Dictionary::Ptr GetHostDependencies(void) const;
Dictionary::Ptr GetServiceDependencies(void) const;
String GetHostCheck(void) const;
- AcknowledgementType GetAcknowledgement(void);
- void SetAcknowledgement(AcknowledgementType acknowledgement);
-
- double GetAcknowledgementExpiry(void) const;
- void SetAcknowledgementExpiry(double timestamp);
-
shared_ptr<Service> GetHostCheckService(void) const;
set<Host::Ptr> GetParentHosts(void) const;
set<shared_ptr<Service> > GetParentServices(void) const;
#include "endpointmanager.h"
#include "icingaapplication.h"
-#include "acknowledgement.h"
-#include "downtimeprocessor.h"
-#include "commentprocessor.h"
-
#include "host.h"
#include "hostgroup.h"
#include "service.h"
<ItemGroup>
<ClCompile Include="checkresultmessage.cpp" />
<ClCompile Include="cib.cpp" />
- <ClCompile Include="commentprocessor.cpp" />
- <ClCompile Include="downtimeprocessor.cpp" />
<ClCompile Include="externalcommandprocessor.cpp" />
<ClCompile Include="host.cpp" />
<ClCompile Include="hostgroup.cpp" />
<ClCompile Include="pluginchecktask.cpp" />
<ClCompile Include="nullchecktask.cpp" />
<ClCompile Include="service.cpp" />
+ <ClCompile Include="service-comment.cpp" />
+ <ClCompile Include="service-downtime.cpp" />
<ClCompile Include="servicegroup.cpp" />
</ItemGroup>
<ItemGroup>
- <ClInclude Include="acknowledgement.h" />
<ClInclude Include="checkresultmessage.h" />
<ClInclude Include="cib.h" />
- <ClInclude Include="commentprocessor.h" />
- <ClInclude Include="downtimeprocessor.h" />
<ClInclude Include="externalcommandprocessor.h" />
<ClInclude Include="host.h" />
<ClInclude Include="hostgroup.h" />
using namespace icinga;
-int CommentProcessor::m_NextCommentID = 1;
-map<int, String> CommentProcessor::m_LegacyCommentCache;
-map<String, DynamicObject::WeakPtr> CommentProcessor::m_CommentCache;
-bool CommentProcessor::m_CommentCacheValid;
-Timer::Ptr CommentProcessor::m_CommentExpireTimer;
+int Service::m_NextCommentID = 1;
+map<int, String> Service::m_LegacyCommentCache;
+map<String, Service::WeakPtr> Service::m_CommentCache;
+bool Service::m_CommentCacheValid;
+Timer::Ptr Service::m_CommentExpireTimer;
-int CommentProcessor::GetNextCommentID(void)
+int Service::GetNextCommentID(void)
{
return m_NextCommentID;
}
-String CommentProcessor::AddComment(const DynamicObject::Ptr& owner,
- CommentType entryType, const String& author, const String& text,
- double expireTime)
+String Service::AddComment(CommentType entryType, const String& author,
+ const String& text, double expireTime)
{
Dictionary::Ptr comment = boost::make_shared<Dictionary>();
comment->Set("entry_time", Utility::GetTime());
comment->Set("expire_time", expireTime);
comment->Set("legacy_id", m_NextCommentID++);
- Dictionary::Ptr comments = owner->Get("comments");
+ Dictionary::Ptr comments = Get("comments");
if (!comments)
comments = boost::make_shared<Dictionary>();
String id = Utility::NewUUID();
comments->Set(id, comment);
- owner->Set("comments", comments);
+ Set("comments", comments);
return id;
}
-void CommentProcessor::RemoveAllComments(const DynamicObject::Ptr& owner)
+void Service::RemoveAllComments(void)
{
- owner->Set("comments", Empty);
+ Set("comments", Empty);
}
-void CommentProcessor::RemoveComment(const String& id)
+void Service::RemoveComment(const String& id)
{
- DynamicObject::Ptr owner = GetOwnerByCommentID(id);
+ Service::Ptr owner = GetOwnerByCommentID(id);
if (!owner)
return;
}
}
-String CommentProcessor::GetIDFromLegacyID(int id)
+String Service::GetCommentIDFromLegacyID(int id)
{
map<int, String>::iterator it = m_LegacyCommentCache.find(id);
return it->second;
}
-DynamicObject::Ptr CommentProcessor::GetOwnerByCommentID(const String& id)
+Service::Ptr Service::GetOwnerByCommentID(const String& id)
{
ValidateCommentCache();
return m_CommentCache[id].lock();
}
-Dictionary::Ptr CommentProcessor::GetCommentByID(const String& id)
+Dictionary::Ptr Service::GetCommentByID(const String& id)
{
- DynamicObject::Ptr owner = GetOwnerByCommentID(id);
+ Service::Ptr owner = GetOwnerByCommentID(id);
if (!owner)
return Dictionary::Ptr();
return Dictionary::Ptr();
}
-bool CommentProcessor::IsCommentExpired(const Dictionary::Ptr& comment)
+bool Service::IsCommentExpired(const Dictionary::Ptr& comment)
{
double expire_time = comment->Get("expire_time");
return (expire_time != 0 && expire_time < Utility::GetTime());
}
-void CommentProcessor::InvalidateCommentCache(void)
+void Service::InvalidateCommentCache(void)
{
m_CommentCacheValid = false;
m_CommentCache.clear();
m_LegacyCommentCache.clear();
}
-void CommentProcessor::AddCommentsToCache(const DynamicObject::Ptr& owner)
+void Service::AddCommentsToCache(void)
{
- Dictionary::Ptr comments = owner->Get("comments");
+ Dictionary::Ptr comments = Get("comments");
if (!comments)
return;
legacy_id = m_NextCommentID++;
comment->Set("legacy_id", legacy_id);
- owner->Touch("comments");
+ Touch("comments");
}
m_LegacyCommentCache[legacy_id] = id;
- m_CommentCache[id] = owner;
+ m_CommentCache[id] = GetSelf();
}
}
-void CommentProcessor::ValidateCommentCache(void)
+void Service::ValidateCommentCache(void)
{
if (m_CommentCacheValid)
return;
m_LegacyCommentCache.clear();
DynamicObject::Ptr object;
- BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Host")->GetObjects()) {
- AddCommentsToCache(object);
- }
-
BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Service")->GetObjects()) {
- AddCommentsToCache(object);
+ Service::Ptr service = dynamic_pointer_cast<Service>(object);
+ service->AddCommentsToCache();
}
m_CommentCacheValid = true;
if (!m_CommentExpireTimer) {
m_CommentExpireTimer = boost::make_shared<Timer>();
m_CommentExpireTimer->SetInterval(300);
- m_CommentExpireTimer->OnTimerExpired.connect(boost::bind(&CommentProcessor::CommentExpireTimerHandler));
+ m_CommentExpireTimer->OnTimerExpired.connect(boost::bind(&Service::CommentExpireTimerHandler));
m_CommentExpireTimer->Start();
}
}
-void CommentProcessor::RemoveExpiredComments(const DynamicObject::Ptr& owner)
+void Service::RemoveExpiredComments(void)
{
- Dictionary::Ptr comments = owner->Get("comments");
+ Dictionary::Ptr comments = Get("comments");
if (!comments)
return;
comments->Remove(id);
}
- owner->Touch("comments");
+ Touch("comments");
}
}
-void CommentProcessor::CommentExpireTimerHandler(void)
+void Service::CommentExpireTimerHandler(void)
{
DynamicObject::Ptr object;
- BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Host")->GetObjects()) {
- RemoveExpiredComments(object);
- }
-
BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Service")->GetObjects()) {
- RemoveExpiredComments(object);
+ Service::Ptr service = dynamic_pointer_cast<Service>(object);
+ service->RemoveExpiredComments();
}
}
-
using namespace icinga;
-int DowntimeProcessor::m_NextDowntimeID = 1;
-map<int, String> DowntimeProcessor::m_LegacyDowntimeCache;
-map<String, DynamicObject::WeakPtr> DowntimeProcessor::m_DowntimeCache;
-bool DowntimeProcessor::m_DowntimeCacheValid;
-Timer::Ptr DowntimeProcessor::m_DowntimeExpireTimer;
+int Service::m_NextDowntimeID = 1;
+map<int, String> Service::m_LegacyDowntimeCache;
+map<String, Service::WeakPtr> Service::m_DowntimeCache;
+bool Service::m_DowntimeCacheValid;
+Timer::Ptr Service::m_DowntimeExpireTimer;
-int DowntimeProcessor::GetNextDowntimeID(void)
+int Service::GetNextDowntimeID(void)
{
return m_NextDowntimeID;
}
-String DowntimeProcessor::AddDowntime(const DynamicObject::Ptr& owner,
- const String& author, const String& comment,
- double startTime, double endTime,
- bool fixed, const String& triggeredBy, double duration)
+String Service::AddDowntime(const String& author, const String& comment,
+ double startTime, double endTime, bool fixed,
+ const String& triggeredBy, double duration)
{
Dictionary::Ptr downtime = boost::make_shared<Dictionary>();
downtime->Set("entry_time", Utility::GetTime());
downtime->Set("legacy_id", m_NextDowntimeID++);
if (!triggeredBy.IsEmpty()) {
- DynamicObject::Ptr otherOwner = GetOwnerByDowntimeID(triggeredBy);
+ Service::Ptr otherOwner = GetOwnerByDowntimeID(triggeredBy);
Dictionary::Ptr otherDowntimes = otherOwner->Get("downtimes");
Dictionary::Ptr otherDowntime = otherDowntimes->Get(triggeredBy);
Dictionary::Ptr triggers = otherDowntime->Get("triggers");
triggers->Set(triggeredBy, triggeredBy);
otherOwner->Touch("downtimes");
}
-
- Dictionary::Ptr downtimes = owner->Get("downtimes");
+
+ Dictionary::Ptr downtimes = Get("downtimes");
if (!downtimes)
downtimes = boost::make_shared<Dictionary>();
String id = Utility::NewUUID();
downtimes->Set(id, downtime);
- owner->Set("downtimes", downtimes);
+ Set("downtimes", downtimes);
return id;
}
-void DowntimeProcessor::RemoveDowntime(const String& id)
+void Service::RemoveDowntime(const String& id)
{
- DynamicObject::Ptr owner = GetOwnerByDowntimeID(id);
+ Service::Ptr owner = GetOwnerByDowntimeID(id);
if (!owner)
return;
-
+
Dictionary::Ptr downtimes = owner->Get("downtimes");
if (!downtimes)
owner->Touch("downtimes");
}
-void DowntimeProcessor::TriggerDowntimes(const DynamicObject::Ptr& owner)
+void Service::TriggerDowntimes(void)
{
- Dictionary::Ptr downtimes = owner->Get("downtimes");
+ Dictionary::Ptr downtimes = Get("downtimes");
if (!downtimes)
return;
-
+
String id;
BOOST_FOREACH(tie(id, tuples::ignore), downtimes) {
TriggerDowntime(id);
}
}
-void DowntimeProcessor::TriggerDowntime(const String& id)
+void Service::TriggerDowntime(const String& id)
{
- DynamicObject::Ptr owner = GetOwnerByDowntimeID(id);
+ Service::Ptr owner = GetOwnerByDowntimeID(id);
Dictionary::Ptr downtime = GetDowntimeByID(id);
double now = Utility::GetTime();
if (downtime->Get("trigger_time") == 0)
downtime->Set("trigger_time", now);
-
+
Dictionary::Ptr triggers = downtime->Get("triggers");
String tid;
BOOST_FOREACH(tie(tid, tuples::ignore), triggers) {
TriggerDowntime(tid);
}
-
+
owner->Touch("downtimes");
}
-String DowntimeProcessor::GetIDFromLegacyID(int id)
+String Service::GetDowntimeIDFromLegacyID(int id)
{
+ ValidateDowntimeCache();
+
map<int, String>::iterator it = m_LegacyDowntimeCache.find(id);
if (it == m_LegacyDowntimeCache.end())
return it->second;
}
-DynamicObject::Ptr DowntimeProcessor::GetOwnerByDowntimeID(const String& id)
+Service::Ptr Service::GetOwnerByDowntimeID(const String& id)
{
ValidateDowntimeCache();
return m_DowntimeCache[id].lock();
}
-Dictionary::Ptr DowntimeProcessor::GetDowntimeByID(const String& id)
+Dictionary::Ptr Service::GetDowntimeByID(const String& id)
{
- DynamicObject::Ptr owner = GetOwnerByDowntimeID(id);
+ Service::Ptr owner = GetOwnerByDowntimeID(id);
if (!owner)
return Dictionary::Ptr();
return Dictionary::Ptr();
}
-bool DowntimeProcessor::IsDowntimeActive(const Dictionary::Ptr& downtime)
+bool Service::IsDowntimeActive(const Dictionary::Ptr& downtime)
{
double now = Utility::GetTime();
return (triggerTime + downtime->Get("duration") < now);
}
-bool DowntimeProcessor::IsDowntimeExpired(const Dictionary::Ptr& downtime)
+bool Service::IsDowntimeExpired(const Dictionary::Ptr& downtime)
{
return (downtime->Get("end_time") < Utility::GetTime());
}
-void DowntimeProcessor::InvalidateDowntimeCache(void)
+void Service::InvalidateDowntimeCache(void)
{
m_DowntimeCacheValid = false;
m_DowntimeCache.clear();
m_LegacyDowntimeCache.clear();
}
-void DowntimeProcessor::AddDowntimesToCache(const DynamicObject::Ptr& owner)
+void Service::AddDowntimesToCache(void)
{
- Dictionary::Ptr downtimes = owner->Get("downtimes");
+ Dictionary::Ptr downtimes = Get("downtimes");
if (!downtimes)
return;
* this shouldn't usually happen - assign it a new ID. */
legacy_id = m_NextDowntimeID++;
downtime->Set("legacy_id", legacy_id);
- owner->Touch("downtimes");
+ Touch("downtimes");
}
m_LegacyDowntimeCache[legacy_id] = id;
- m_DowntimeCache[id] = owner;
+ m_DowntimeCache[id] = GetSelf();
}
}
-void DowntimeProcessor::ValidateDowntimeCache(void)
+void Service::ValidateDowntimeCache(void)
{
if (m_DowntimeCacheValid)
return;
m_LegacyDowntimeCache.clear();
DynamicObject::Ptr object;
- BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Host")->GetObjects()) {
- AddDowntimesToCache(object);
- }
-
BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Service")->GetObjects()) {
- AddDowntimesToCache(object);
+ Service::Ptr service = dynamic_pointer_cast<Service>(object);
+ service->AddDowntimesToCache();
}
m_DowntimeCacheValid = true;
if (!m_DowntimeExpireTimer) {
m_DowntimeExpireTimer = boost::make_shared<Timer>();
m_DowntimeExpireTimer->SetInterval(300);
- m_DowntimeExpireTimer->OnTimerExpired.connect(boost::bind(&DowntimeProcessor::DowntimeExpireTimerHandler));
+ m_DowntimeExpireTimer->OnTimerExpired.connect(boost::bind(&Service::DowntimeExpireTimerHandler));
m_DowntimeExpireTimer->Start();
}
}
-void DowntimeProcessor::RemoveExpiredDowntimes(const DynamicObject::Ptr& owner)
+void Service::RemoveExpiredDowntimes(void)
{
- Dictionary::Ptr downtimes = owner->Get("downtimes");
+ Dictionary::Ptr downtimes = Get("downtimes");
if (!downtimes)
return;
downtimes->Remove(id);
}
- owner->Touch("downtimes");
+ Touch("downtimes");
}
}
-void DowntimeProcessor::DowntimeExpireTimerHandler(void)
+void Service::DowntimeExpireTimerHandler(void)
{
DynamicObject::Ptr object;
- BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Host")->GetObjects()) {
- RemoveExpiredDowntimes(object);
- }
-
BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Service")->GetObjects()) {
- RemoveExpiredDowntimes(object);
+ Service::Ptr service = dynamic_pointer_cast<Service>(object);
+ service->RemoveExpiredDowntimes();
}
}
-
{
ServiceGroup::InvalidateMembersCache();
Host::InvalidateServicesCache();
- DowntimeProcessor::InvalidateDowntimeCache();
+ Service::InvalidateDowntimeCache();
+ Service::InvalidateCommentCache();
}
Service::~Service(void)
{
ServiceGroup::InvalidateMembersCache();
Host::InvalidateServicesCache();
- DowntimeProcessor::InvalidateDowntimeCache();
+ Service::InvalidateDowntimeCache();
+ Service::InvalidateCommentCache();
}
String Service::GetAlias(void) const
Dictionary::Ptr Service::GetDowntimes(void) const
{
- DowntimeProcessor::ValidateDowntimeCache();
+ Service::ValidateDowntimeCache();
return Get("downtimes");
}
Dictionary::Ptr Service::GetComments(void) const
{
- CommentProcessor::ValidateCommentCache();
+ Service::ValidateCommentCache();
return Get("comments");
}
Dictionary::Ptr downtime;
BOOST_FOREACH(tie(tuples::ignore, downtime), downtimes) {
- if (DowntimeProcessor::IsDowntimeActive(downtime))
+ if (Service::IsDowntimeActive(downtime))
return true;
}
}
if (GetState() != StateOK)
- DowntimeProcessor::TriggerDowntimes(GetSelf());
+ TriggerDowntimes();
}
ServiceState Service::StateFromString(const String& state)
else if (name == "host_name" || name == "short_name")
Host::InvalidateServicesCache();
else if (name == "downtimes")
- DowntimeProcessor::InvalidateDowntimeCache();
+ Service::InvalidateDowntimeCache();
+ else if (name == "comments")
+ Service::InvalidateCommentCache();
}
void Service::BeginExecuteCheck(const function<void (void)>& callback)
StateTypeHard
};
+/**
+ * The acknowledgement type of a service.
+ *
+ * @ingroup icinga
+ */
+enum AcknowledgementType
+{
+ AcknowledgementNone = 0,
+ AcknowledgementNormal = 1,
+ AcknowledgementSticky = 2
+};
+
+/**
+ * The type of a service comment.
+ *
+ * @ingroup icinga
+ */
+enum CommentType
+{
+ CommentUser = 1,
+ CommentDowntime = 2,
+ CommentFlapping = 3,
+ CommentAcknowledgement = 4
+};
+
class CheckResultMessage;
/**
static boost::signal<void (const Service::Ptr&, const String&)> OnCheckerChanged;
static boost::signal<void (const Service::Ptr&, const Value&)> OnNextCheckChanged;
+ /* Downtimes */
+ static int GetNextDowntimeID(void);
+
+ String AddDowntime(const String& author, const String& comment,
+ double startTime, double endTime, bool fixed,
+ const String& triggeredBy, double duration);
+
+ static void RemoveDowntime(const String& id);
+
+ void TriggerDowntimes(void);
+ static void TriggerDowntime(const String& id);
+
+ static String GetDowntimeIDFromLegacyID(int id);
+ static Service::Ptr GetOwnerByDowntimeID(const String& id);
+ static Dictionary::Ptr GetDowntimeByID(const String& id);
+
+ static bool IsDowntimeActive(const Dictionary::Ptr& downtime);
+ static bool IsDowntimeExpired(const Dictionary::Ptr& downtime);
+
+ static void InvalidateDowntimeCache(void);
+ static void ValidateDowntimeCache(void);
+
+ /* Comments */
+ static int GetNextCommentID(void);
+
+ String AddComment(CommentType entryType, const String& author,
+ const String& text, double expireTime);
+
+ void RemoveAllComments(void);
+ static void RemoveComment(const String& id);
+
+ static String GetCommentIDFromLegacyID(int id);
+ static Service::Ptr GetOwnerByCommentID(const String& id);
+ static Dictionary::Ptr GetCommentByID(const String& id);
+
+ static bool IsCommentExpired(const Dictionary::Ptr& comment);
+
+ static void InvalidateCommentCache(void);
+ static void ValidateCommentCache(void);
+
protected:
virtual void OnAttributeChanged(const String& name, const Value& oldValue);
private:
+ /* Downtimes */
+ static int m_NextDowntimeID;
+
+ static map<int, String> m_LegacyDowntimeCache;
+ static map<String, Service::WeakPtr> m_DowntimeCache;
+ static bool m_DowntimeCacheValid;
+ static Timer::Ptr m_DowntimeExpireTimer;
+
+ static void DowntimeExpireTimerHandler(void);
+
+ void AddDowntimesToCache(void);
+ void RemoveExpiredDowntimes(void);
+
+ /* Comments */
+ static int m_NextCommentID;
+
+ static map<int, String> m_LegacyCommentCache;
+ static map<String, Service::WeakPtr> m_CommentCache;
+ static bool m_CommentCacheValid;
+ static Timer::Ptr m_CommentExpireTimer;
+
+ static void CommentExpireTimerHandler(void);
+
+ void AddCommentsToCache(void);
+ void RemoveExpiredComments(void);
+
void CheckCompletedHandler(const Dictionary::Ptr& scheduleInfo,
const ScriptTask::Ptr& task, const function<void (void)>& callback);
};