From 70af1a35458d31888f2d1d1a0ce54bb7bd61593b Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Mon, 4 Dec 2017 16:52:52 +0100 Subject: [PATCH 01/33] Move CompatUtility::GetHostAlias into DB IDO host object method This is the only place where this mapping is used. --- lib/db_ido/hostdbobject.cpp | 12 ++++++++++-- lib/icinga/compatutility.cpp | 8 -------- lib/icinga/compatutility.hpp | 1 - 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 0dc0abc3f..28343d48c 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -47,8 +47,16 @@ Dictionary::Ptr HostDbObject::GetConfigFields() const Dictionary::Ptr fields = new Dictionary(); Host::Ptr host = static_pointer_cast(GetObject()); - fields->Set("alias", CompatUtility::GetHostAlias(host)); - fields->Set("display_name", host->GetDisplayName()); + /* Compatibility fallback. */ + String displayName = host->GetDisplayName(); + + if (!displayName.IsEmpty()) { + fields->Set("alias", displayName); + } else { + fields->Set("alias", host->GetName()); + } + + fields->Set("display_name", displayName); fields->Set("address", host->GetAddress()); fields->Set("address6", host->GetAddress6()); diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 29eef3dd5..f4b0e6fce 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -96,14 +96,6 @@ String CompatUtility::GetHostStateString(const Host::Ptr& host) return Host::StateToString(host->GetState()); } -String CompatUtility::GetHostAlias(const Host::Ptr& host) -{ - if (!host->GetDisplayName().IsEmpty()) - return host->GetName(); - else - return host->GetDisplayName(); -} - int CompatUtility::GetHostNotifyOnDown(const Host::Ptr& host) { unsigned long notification_state_filter = GetCheckableNotificationStateFilter(host); diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 5cfcbe7e3..62c437c19 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -46,7 +46,6 @@ public: /* host */ static int GetHostCurrentState(const Host::Ptr& host); static String GetHostStateString(const Host::Ptr& host); - static String GetHostAlias(const Host::Ptr& host); static int GetHostNotifyOnDown(const Host::Ptr& host); static int GetHostNotifyOnUnreachable(const Host::Ptr& host); From 92c565d7449ea34559ae082473cb6e574abcbbee Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 5 Dec 2017 11:34:38 +0100 Subject: [PATCH 02/33] Move CompatUtility::GetCheckableCheckType() into IDO/Livestatus features It is just boolean mapping to numbers, each modules does that in a sort of different way. DB IDO automatically transforms boolean to numbers. Livestatus would return JSON which keeps true booleans, but requires a number (just a guess, there is no spec for this message format). --- lib/db_ido/dbevents.cpp | 2 +- lib/db_ido/hostdbobject.cpp | 2 +- lib/db_ido/servicedbobject.cpp | 2 +- lib/icinga/compatutility.cpp | 5 ----- lib/icinga/compatutility.hpp | 1 - lib/livestatus/hoststable.cpp | 2 +- lib/livestatus/servicestable.cpp | 2 +- 7 files changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/db_ido/dbevents.cpp b/lib/db_ido/dbevents.cpp index ab2ba3e2b..6f4e567dc 100644 --- a/lib/db_ido/dbevents.cpp +++ b/lib/db_ido/dbevents.cpp @@ -1395,7 +1395,7 @@ void DbEvents::AddCheckableCheckHistory(const Checkable::Ptr& checkable, const C query1.Category = DbCatCheck; Dictionary::Ptr fields1 = new Dictionary(); - fields1->Set("check_type", CompatUtility::GetCheckableCheckType(checkable)); + fields1->Set("check_type", !checkable->GetEnableActiveChecks()); /* 0 .. active, 1 .. passive */ fields1->Set("current_check_attempt", checkable->GetCheckAttempt()); fields1->Set("max_check_attempts", checkable->GetMaxCheckAttempts()); fields1->Set("state_type", checkable->GetStateType()); diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 28343d48c..dc9271416 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -141,7 +141,7 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const 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("check_type", !host->GetEnableActiveChecks()); /* 0 .. active, 1 .. passive */ fields->Set("last_state_change", DbValue::FromTimestamp(host->GetLastStateChange())); fields->Set("last_hard_state_change", DbValue::FromTimestamp(host->GetLastHardStateChange())); fields->Set("last_hard_state", host->GetLastHardState()); diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 2c82e8b23..048122f13 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -128,7 +128,7 @@ Dictionary::Ptr ServiceDbObject::GetStatusFields() const fields->Set("last_check", DbValue::FromTimestamp(cr->GetScheduleEnd())); fields->Set("next_check", DbValue::FromTimestamp(service->GetNextCheck())); - fields->Set("check_type", CompatUtility::GetCheckableCheckType(service)); + fields->Set("check_type", !service->GetEnableActiveChecks()); /* 0 .. active, 1 .. passive */ fields->Set("last_state_change", DbValue::FromTimestamp(service->GetLastStateChange())); fields->Set("last_hard_state_change", DbValue::FromTimestamp(service->GetLastHardStateChange())); fields->Set("last_hard_state", service->GetLastHardState()); diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index f4b0e6fce..bea2dc1ec 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -183,11 +183,6 @@ String CompatUtility::GetCheckableCommandArgs(const Checkable::Ptr& checkable) return Empty; } -int CompatUtility::GetCheckableCheckType(const Checkable::Ptr& checkable) -{ - return (checkable->GetEnableActiveChecks() ? 0 : 1); -} - double CompatUtility::GetCheckableCheckInterval(const Checkable::Ptr& checkable) { return checkable->GetCheckInterval() / 60.0; diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 62c437c19..d6408534b 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -51,7 +51,6 @@ public: /* service */ static String GetCheckableCommandArgs(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); diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index a3c99d123..e2b920134 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -522,7 +522,7 @@ Value HostsTable::CheckTypeAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableCheckType(host); + return (host->GetEnableActiveChecks() ? 0 : 1); /* 0 .. active, 1 .. passive */ } Value HostsTable::LastStateAccessor(const Value& row) diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index 6c15efe4d..d3ecee4cb 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -549,7 +549,7 @@ Value ServicesTable::CheckTypeAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableCheckType(service); + return (service->GetEnableActiveChecks() ? 0 : 1); /* 0 .. active, 1 .. passive */ } Value ServicesTable::AcknowledgedAccessor(const Value& row) From 7bf2e0703283c4805c33d4726dd96950fa09406d Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 5 Dec 2017 13:35:09 +0100 Subject: [PATCH 03/33] Move CompatUtility::GetCheckableProblemHasBeenAcknowledged() into feature specific dumps --- lib/compat/statusdatawriter.cpp | 6 +++--- lib/db_ido/hostdbobject.cpp | 2 +- lib/db_ido/servicedbobject.cpp | 2 +- lib/icinga/compatutility.cpp | 6 ------ lib/icinga/compatutility.hpp | 1 - 5 files changed, 5 insertions(+), 12 deletions(-) diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index d1f39811d..e5b41f03e 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -372,7 +372,7 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl if (cr) { fp << "\t" << "check_source=" << cr->GetCheckSource() << "\n" - "\t" "last_check=" << static_cast(cr->GetScheduleEnd()) << "\n"; + "\t" "last_check=" << static_cast(cr->GetScheduleEnd()) << "\n"; } fp << "\t" << "next_check=" << static_cast(checkable->GetNextCheck()) << "\n" @@ -380,14 +380,14 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl "\t" "max_attempts=" << checkable->GetMaxCheckAttempts() << "\n" "\t" "last_state_change=" << static_cast(checkable->GetLastStateChange()) << "\n" "\t" "last_hard_state_change=" << static_cast(checkable->GetLastHardStateChange()) << "\n" - "\t" "last_update=" << static_cast(time(nullptr)) << "\n" + "\t" "last_update=" << static_cast(time(NULL)) << "\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" "problem_has_been_acknowledged=" << (checkable->GetAcknowledgement() != AcknowledgementNone ? 1 : 0) << "\n" "\t" "acknowledgement_type=" << CompatUtility::GetCheckableAcknowledgementType(checkable) << "\n" "\t" "acknowledgement_end_time=" << checkable->GetAcknowledgementExpiry() << "\n" "\t" "scheduled_downtime_depth=" << checkable->GetDowntimeDepth() << "\n" diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index dc9271416..b1477a3ee 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -153,7 +153,7 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const 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("problem_has_been_acknowledged", host->GetAcknowledgement() != AcknowledgementNone); fields->Set("acknowledgement_type", CompatUtility::GetCheckableAcknowledgementType(host)); fields->Set("current_notification_number", CompatUtility::GetCheckableNotificationNotificationNumber(host)); fields->Set("passive_checks_enabled", CompatUtility::GetCheckablePassiveChecksEnabled(host)); diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 048122f13..3263f40f1 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -141,7 +141,7 @@ Dictionary::Ptr ServiceDbObject::GetStatusFields() const fields->Set("next_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationNextNotification(service))); fields->Set("no_more_notifications", Empty); fields->Set("notifications_enabled", CompatUtility::GetCheckableNotificationsEnabled(service)); - fields->Set("problem_has_been_acknowledged", CompatUtility::GetCheckableProblemHasBeenAcknowledged(service)); + fields->Set("problem_has_been_acknowledged", service->GetAcknowledgement() != AcknowledgementNone); fields->Set("acknowledgement_type", CompatUtility::GetCheckableAcknowledgementType(service)); fields->Set("current_notification_number", CompatUtility::GetCheckableNotificationNotificationNumber(service)); fields->Set("passive_checks_enabled", CompatUtility::GetCheckablePassiveChecksEnabled(service)); diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index bea2dc1ec..52155ba34 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -207,12 +207,6 @@ int CompatUtility::GetCheckableHasBeenChecked(const Checkable::Ptr& checkable) return (checkable->GetLastCheckResult() ? 1 : 0); } - -int CompatUtility::GetCheckableProblemHasBeenAcknowledged(const Checkable::Ptr& checkable) -{ - return (checkable->GetAcknowledgement() != AcknowledgementNone ? 1 : 0); -} - int CompatUtility::GetCheckableAcknowledgementType(const Checkable::Ptr& checkable) { return static_cast(checkable->GetAcknowledgement()); diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index d6408534b..b2d77e358 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -55,7 +55,6 @@ public: 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); From 3847e37df121132ef4ad235f761dacfeca26906e Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 5 Dec 2017 14:17:57 +0100 Subject: [PATCH 04/33] Drop CompatUtility::GetCheckableAcknowledgementType() This already returns an integer. --- lib/compat/statusdatawriter.cpp | 2 +- lib/db_ido/hostdbobject.cpp | 2 +- lib/db_ido/servicedbobject.cpp | 2 +- lib/icinga/compatutility.cpp | 5 ----- lib/icinga/compatutility.hpp | 1 - lib/livestatus/hoststable.cpp | 2 +- lib/livestatus/servicestable.cpp | 2 +- 7 files changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index e5b41f03e..fb1ac5463 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -388,7 +388,7 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl "\t" "is_flapping=" << CompatUtility::GetCheckableIsFlapping(checkable) << "\n" "\t" "percent_state_change=" << CompatUtility::GetCheckablePercentStateChange(checkable) << "\n" "\t" "problem_has_been_acknowledged=" << (checkable->GetAcknowledgement() != AcknowledgementNone ? 1 : 0) << "\n" - "\t" "acknowledgement_type=" << CompatUtility::GetCheckableAcknowledgementType(checkable) << "\n" + "\t" "acknowledgement_type=" << checkable->GetAcknowledgement() << "\n" "\t" "acknowledgement_end_time=" << checkable->GetAcknowledgementExpiry() << "\n" "\t" "scheduled_downtime_depth=" << checkable->GetDowntimeDepth() << "\n" "\t" "last_notification=" << CompatUtility::GetCheckableNotificationLastNotification(checkable) << "\n" diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index b1477a3ee..d7bf870d2 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -154,7 +154,7 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const fields->Set("no_more_notifications", Empty); fields->Set("notifications_enabled", CompatUtility::GetCheckableNotificationsEnabled(host)); fields->Set("problem_has_been_acknowledged", host->GetAcknowledgement() != AcknowledgementNone); - fields->Set("acknowledgement_type", CompatUtility::GetCheckableAcknowledgementType(host)); + fields->Set("acknowledgement_type", host->GetAcknowledgement()); fields->Set("current_notification_number", CompatUtility::GetCheckableNotificationNotificationNumber(host)); fields->Set("passive_checks_enabled", CompatUtility::GetCheckablePassiveChecksEnabled(host)); fields->Set("active_checks_enabled", CompatUtility::GetCheckableActiveChecksEnabled(host)); diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 3263f40f1..74663ce62 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -142,7 +142,7 @@ Dictionary::Ptr ServiceDbObject::GetStatusFields() const fields->Set("no_more_notifications", Empty); fields->Set("notifications_enabled", CompatUtility::GetCheckableNotificationsEnabled(service)); fields->Set("problem_has_been_acknowledged", service->GetAcknowledgement() != AcknowledgementNone); - fields->Set("acknowledgement_type", CompatUtility::GetCheckableAcknowledgementType(service)); + fields->Set("acknowledgement_type", service->GetAcknowledgement()); fields->Set("current_notification_number", CompatUtility::GetCheckableNotificationNotificationNumber(service)); fields->Set("passive_checks_enabled", CompatUtility::GetCheckablePassiveChecksEnabled(service)); fields->Set("active_checks_enabled", CompatUtility::GetCheckableActiveChecksEnabled(service)); diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 52155ba34..2d1531e8f 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -207,11 +207,6 @@ int CompatUtility::GetCheckableHasBeenChecked(const Checkable::Ptr& checkable) return (checkable->GetLastCheckResult() ? 1 : 0); } -int CompatUtility::GetCheckableAcknowledgementType(const Checkable::Ptr& checkable) -{ - return static_cast(checkable->GetAcknowledgement()); -} - int CompatUtility::GetCheckablePassiveChecksEnabled(const Checkable::Ptr& checkable) { return (checkable->GetEnablePassiveChecks() ? 1 : 0); diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index b2d77e358..1daeefcf6 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -55,7 +55,6 @@ public: static double GetCheckableRetryInterval(const Checkable::Ptr& checkable); static String GetCheckableCheckPeriod(const Checkable::Ptr& checkable); static int GetCheckableHasBeenChecked(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); diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index e2b920134..6d79a8c87 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -512,7 +512,7 @@ Value HostsTable::AcknowledgementTypeAccessor(const Value& row) return Empty; ObjectLock olock(host); - return CompatUtility::GetCheckableAcknowledgementType(host); + return host->GetAcknowledgement(); } Value HostsTable::CheckTypeAccessor(const Value& row) diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index d3ecee4cb..d9a303b4b 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -571,7 +571,7 @@ Value ServicesTable::AcknowledgementTypeAccessor(const Value& row) return Empty; ObjectLock olock(service); - return CompatUtility::GetCheckableAcknowledgementType(service); + return service->GetAcknowledgement(); } Value ServicesTable::NoMoreNotificationsAccessor(const Value& row) From 334f633b0a12410078fdae267d6940e7f96d5914 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 5 Dec 2017 14:23:15 +0100 Subject: [PATCH 05/33] Drop CompatUtility::GetCheckableHasBeenChecked() and use Checkable::HasBeenChecked() --- lib/compat/statusdatawriter.cpp | 2 +- lib/db_ido/hostdbobject.cpp | 2 +- lib/db_ido/servicedbobject.cpp | 2 +- lib/icinga/compatutility.cpp | 5 ----- lib/icinga/compatutility.hpp | 1 - lib/livestatus/hoststable.cpp | 2 +- lib/livestatus/servicestable.cpp | 2 +- 7 files changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index fb1ac5463..eae647e41 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -338,7 +338,7 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl "\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" "has_been_checked=" << (checkable->HasBeenChecked() ? 1 : 0) << "\n" "\t" "should_be_scheduled=" << checkable->GetEnableActiveChecks() << "\n" "\t" "event_handler_enabled=" << CompatUtility::GetCheckableEventHandlerEnabled(checkable) << "\n"; diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index d7bf870d2..7749b275a 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -132,7 +132,7 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const } fields->Set("current_state", CompatUtility::GetHostCurrentState(host)); - fields->Set("has_been_checked", CompatUtility::GetCheckableHasBeenChecked(host)); + fields->Set("has_been_checked", host->HasBeenChecked()); fields->Set("should_be_scheduled", host->GetEnableActiveChecks()); fields->Set("current_check_attempt", host->GetCheckAttempt()); fields->Set("max_check_attempts", host->GetMaxCheckAttempts()); diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 74663ce62..eff6b71a8 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -119,7 +119,7 @@ Dictionary::Ptr ServiceDbObject::GetStatusFields() const } fields->Set("current_state", service->GetState()); - fields->Set("has_been_checked", CompatUtility::GetCheckableHasBeenChecked(service)); + fields->Set("has_been_checked", service->HasBeenChecked()); fields->Set("should_be_scheduled", service->GetEnableActiveChecks()); fields->Set("current_check_attempt", service->GetCheckAttempt()); fields->Set("max_check_attempts", service->GetMaxCheckAttempts()); diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 2d1531e8f..3b5d8c756 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -202,11 +202,6 @@ String CompatUtility::GetCheckableCheckPeriod(const Checkable::Ptr& checkable) return "24x7"; } -int CompatUtility::GetCheckableHasBeenChecked(const Checkable::Ptr& checkable) -{ - return (checkable->GetLastCheckResult() ? 1 : 0); -} - int CompatUtility::GetCheckablePassiveChecksEnabled(const Checkable::Ptr& checkable) { return (checkable->GetEnablePassiveChecks() ? 1 : 0); diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 1daeefcf6..e5a9a89e1 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -54,7 +54,6 @@ public: 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 GetCheckablePassiveChecksEnabled(const Checkable::Ptr& checkable); static int GetCheckableActiveChecksEnabled(const Checkable::Ptr& checkable); static int GetCheckableEventHandlerEnabled(const Checkable::Ptr& checkable); diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index 6d79a8c87..49dd9fac6 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -602,7 +602,7 @@ Value HostsTable::HasBeenCheckedAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableHasBeenChecked(host); + return Convert::ToLong(host->HasBeenChecked()); } Value HostsTable::CurrentNotificationNumberAccessor(const Value& row) diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index d9a303b4b..072535ca9 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -509,7 +509,7 @@ Value ServicesTable::HasBeenCheckedAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableHasBeenChecked(service); + return Convert::ToLong(service->HasBeenChecked()); } Value ServicesTable::LastStateAccessor(const Value& row) From 2d1f772a6eadb394c659a5c8441bbd6eaffd72d5 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 5 Dec 2017 15:28:08 +0100 Subject: [PATCH 06/33] Replace CompatUtility's enabled wrappers with native implementation getters Many conversions were not necessary, or could be dealt inside the actual feature. libcompat and liblivestatus can take care about such specifics on their own, lib_db_ido doesn't need boolean conversion in fields, that is done inside the db driver. --- lib/compat/statusdatawriter.cpp | 111 ++++++++++++++++--------------- lib/db_ido/hostdbobject.cpp | 24 +++---- lib/db_ido/servicedbobject.cpp | 24 +++---- lib/icinga/compatutility.cpp | 30 --------- lib/icinga/compatutility.hpp | 5 -- lib/livestatus/hoststable.cpp | 24 +++++-- lib/livestatus/servicestable.cpp | 14 ++-- 7 files changed, 104 insertions(+), 128 deletions(-) diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index eae647e41..6282cb9b1 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -266,12 +266,12 @@ void StatusDataWriter::DumpHostObject(std::ostream& fp, const Host::Ptr& host) 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" "active_checks_enabled" "\t" << Convert::ToLong(host->GetEnableActiveChecks()) << "\n" + "\t" "passive_checks_enabled" "\t" << Convert::ToLong(host->GetEnablePassiveChecks()) << "\n" + "\t" "notifications_enabled" "\t" << Convert::ToLong(host->GetEnableNotifications()) << "\n" "\t" "notification_options" "\t" << CompatUtility::GetCheckableNotificationNotificationOptions(host) << "\n" "\t" "notification_interval" "\t" << CompatUtility::GetCheckableNotificationNotificationInterval(host) << "\n" - "\t" "event_handler_enabled" "\t" << CompatUtility::GetCheckableEventHandlerEnabled(host) << "\n"; + "\t" "event_handler_enabled" "\t" << Convert::ToLong(host->GetEnableEventHandler()) << "\n"; CheckCommand::Ptr checkcommand = host->GetCheckCommand(); if (checkcommand) @@ -294,7 +294,7 @@ void StatusDataWriter::DumpHostObject(std::ostream& fp, const Host::Ptr& host) fp << "\t" << "initial_state" "\t" "o" "\n" "\t" "low_flap_threshold" "\t" << host->GetFlappingThresholdLow() << "\n" "\t" "high_flap_threshold" "\t" << host->GetFlappingThresholdHigh() << "\n" - "\t" "process_perf_data" "\t" << CompatUtility::GetCheckableProcessPerformanceData(host) << "\n" + "\t" "process_perf_data" "\t" << Convert::ToLong(host->GetEnablePerfdata()) << "\n" "\t" "check_freshness" "\t" "1" "\n"; fp << "\t" "host_groups" "\t"; @@ -338,9 +338,9 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl "\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=" << (checkable->HasBeenChecked() ? 1 : 0) << "\n" + "\t" "has_been_checked=" << Convert::ToLong(checkable->HasBeenChecked()) << "\n" "\t" "should_be_scheduled=" << checkable->GetEnableActiveChecks() << "\n" - "\t" "event_handler_enabled=" << CompatUtility::GetCheckableEventHandlerEnabled(checkable) << "\n"; + "\t" "event_handler_enabled=" << Convert::ToLong(checkable->GetEnableEventHandler()) << "\n"; if (cr) { fp << "\t" << "check_execution_time=" << Convert::ToString(cr->CalculateExecutionTime()) << "\n" @@ -381,10 +381,10 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl "\t" "last_state_change=" << static_cast(checkable->GetLastStateChange()) << "\n" "\t" "last_hard_state_change=" << static_cast(checkable->GetLastHardStateChange()) << "\n" "\t" "last_update=" << static_cast(time(NULL)) << "\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" "notifications_enabled" "\t" << Convert::ToLong(checkable->GetEnableNotifications()) << "\n" + "\t" "active_checks_enabled=" << Convert::ToLong(checkable->GetEnableActiveChecks()) << "\n" + "\t" "passive_checks_enabled=" << Convert::ToLong(checkable->GetEnablePassiveChecks()) << "\n" + "\t" "flap_detection_enabled=" << Convert::ToLong(checkable->GetEnableFlapping()) << "\n" "\t" "is_flapping=" << CompatUtility::GetCheckableIsFlapping(checkable) << "\n" "\t" "percent_state_change=" << CompatUtility::GetCheckablePercentStateChange(checkable) << "\n" "\t" "problem_has_been_acknowledged=" << (checkable->GetAcknowledgement() != AcknowledgementNone ? 1 : 0) << "\n" @@ -431,15 +431,15 @@ void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& s "\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::GetCheckableActiveChecksEnabled(service) << "\n" - "\t" "passive_checks_enabled" "\t" << CompatUtility::GetCheckablePassiveChecksEnabled(service) << "\n" - "\t" "flap_detection_enabled" "\t" << CompatUtility::GetCheckableFlapDetectionEnabled(service) << "\n" + "\t" "active_checks_enabled" "\t" << Convert::ToLong(service->GetEnableActiveChecks()) << "\n" + "\t" "passive_checks_enabled" "\t" << Convert::ToLong(service->GetEnablePassiveChecks()) << "\n" + "\t" "flap_detection_enabled" "\t" << Convert::ToLong(service->GetEnableFlapping()) << "\n" "\t" "is_volatile" "\t" << CompatUtility::GetCheckableIsVolatile(service) << "\n" - "\t" "notifications_enabled" "\t" << CompatUtility::GetCheckableNotificationsEnabled(service) << "\n" + "\t" "notifications_enabled" "\t" << Convert::ToLong(service->GetEnableNotifications()) << "\n" "\t" "notification_options" "\t" << CompatUtility::GetCheckableNotificationNotificationOptions(service) << "\n" "\t" "notification_interval" "\t" << CompatUtility::GetCheckableNotificationNotificationInterval(service) << "\n" "\t" "notification_period" "\t" << "" << "\n" - "\t" "event_handler_enabled" "\t" << CompatUtility::GetCheckableEventHandlerEnabled(service) << "\n"; + "\t" "event_handler_enabled" "\t" << Convert::ToLong(service->GetEnableEventHandler()) << "\n"; CheckCommand::Ptr checkcommand = service->GetCheckCommand(); if (checkcommand) @@ -466,8 +466,9 @@ void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& s fp << "\t" "initial_state" "\t" "o" "\n" "\t" "low_flap_threshold" "\t" << service->GetFlappingThresholdLow() << "\n" "\t" "high_flap_threshold" "\t" << service->GetFlappingThresholdHigh() << "\n" - "\t" "process_perf_data" "\t" << CompatUtility::GetCheckableProcessPerformanceData(service) << "\n" + "\t" "process_perf_data" "\t" << Convert::ToLong(service->GetEnablePerfdata()) << "\n" "\t" "check_freshness" << "\t" "1" "\n"; + if (!notes.IsEmpty()) fp << "\t" "notes" "\t" << notes << "\n"; if (!notes_url.IsEmpty()) @@ -740,23 +741,23 @@ void StatusDataWriter::UpdateObjectsCache() /* Icinga 1.x only allows host->host, service->service dependencies */ if (!child_service && !parent_service) { objectfp << "define hostdependency {" "\n" - "\t" "dependent_host_name" "\t" << child_host->GetName() << "\n" - "\t" "host_name" "\t" << parent_host->GetName() << "\n" - "\t" "execution_failure_criteria" "\t" << criteria << "\n" - "\t" "notification_failure_criteria" "\t" << criteria << "\n" - "\t" "}" "\n" - "\n"; + "\t" "dependent_host_name" "\t" << child_host->GetName() << "\n" + "\t" "host_name" "\t" << parent_host->GetName() << "\n" + "\t" "execution_failure_criteria" "\t" << criteria << "\n" + "\t" "notification_failure_criteria" "\t" << criteria << "\n" + "\t" "}" "\n" + "\n"; } else if (child_service && parent_service){ objectfp << "define servicedependency {" "\n" - "\t" "dependent_host_name" "\t" << child_service->GetHost()->GetName() << "\n" - "\t" "dependent_service_description" "\t" << child_service->GetShortName() << "\n" - "\t" "host_name" "\t" << parent_service->GetHost()->GetName() << "\n" - "\t" "service_description" "\t" << parent_service->GetShortName() << "\n" - "\t" "execution_failure_criteria" "\t" << criteria << "\n" - "\t" "notification_failure_criteria" "\t" << criteria << "\n" - "\t" "}" "\n" - "\n"; + "\t" "dependent_host_name" "\t" << child_service->GetHost()->GetName() << "\n" + "\t" "dependent_service_description" "\t" << child_service->GetShortName() << "\n" + "\t" "host_name" "\t" << parent_service->GetHost()->GetName() << "\n" + "\t" "service_description" "\t" << parent_service->GetShortName() << "\n" + "\t" "execution_failure_criteria" "\t" << criteria << "\n" + "\t" "notification_failure_criteria" "\t" << criteria << "\n" + "\t" "}" "\n" + "\n"; } } @@ -798,32 +799,32 @@ void StatusDataWriter::StatusTimerHandler() "\n"; statusfp << "info {" "\n" - "\t" "created=" << Utility::GetTime() << "\n" - "\t" "version=" << Application::GetAppVersion() << "\n" - "\t" "}" "\n" - "\n"; + "\t" "created=" << Utility::GetTime() << "\n" + "\t" "version=" << Application::GetAppVersion() << "\n" + "\t" "}" "\n" + "\n"; statusfp << "programstatus {" "\n" - "\t" "icinga_pid=" << Utility::GetPid() << "\n" - "\t" "daemon_mode=1" "\n" - "\t" "program_start=" << static_cast(Application::GetStartTime()) << "\n" - "\t" "active_host_checks_enabled=" << (IcingaApplication::GetInstance()->GetEnableHostChecks() ? 1 : 0) << "\n" - "\t" "passive_host_checks_enabled=1" "\n" - "\t" "active_service_checks_enabled=" << (IcingaApplication::GetInstance()->GetEnableServiceChecks() ? 1 : 0) << "\n" - "\t" "passive_service_checks_enabled=1" "\n" - "\t" "check_service_freshness=1" "\n" - "\t" "check_host_freshness=1" "\n" - "\t" "enable_notifications=" << (IcingaApplication::GetInstance()->GetEnableNotifications() ? 1 : 0) << "\n" - "\t" "enable_event_handlers=" << (IcingaApplication::GetInstance()->GetEnableEventHandlers() ? 1 : 0) << "\n" - "\t" "enable_flap_detection=" << (IcingaApplication::GetInstance()->GetEnableFlapping() ? 1 : 0) << "\n" - "\t" "enable_failure_prediction=0" "\n" - "\t" "process_performance_data=" << (IcingaApplication::GetInstance()->GetEnablePerfdata() ? 1 : 0) << "\n" - "\t" "active_scheduled_host_check_stats=" << CIB::GetActiveHostChecksStatistics(60) << "," << CIB::GetActiveHostChecksStatistics(5 * 60) << "," << CIB::GetActiveHostChecksStatistics(15 * 60) << "\n" - "\t" "passive_host_check_stats=" << CIB::GetPassiveHostChecksStatistics(60) << "," << CIB::GetPassiveHostChecksStatistics(5 * 60) << "," << CIB::GetPassiveHostChecksStatistics(15 * 60) << "\n" - "\t" "active_scheduled_service_check_stats=" << CIB::GetActiveServiceChecksStatistics(60) << "," << CIB::GetActiveServiceChecksStatistics(5 * 60) << "," << CIB::GetActiveServiceChecksStatistics(15 * 60) << "\n" - "\t" "passive_service_check_stats=" << CIB::GetPassiveServiceChecksStatistics(60) << "," << CIB::GetPassiveServiceChecksStatistics(5 * 60) << "," << CIB::GetPassiveServiceChecksStatistics(15 * 60) << "\n" - "\t" "next_downtime_id=" << Downtime::GetNextDowntimeID() << "\n" - "\t" "next_comment_id=" << Comment::GetNextCommentID() << "\n"; + "\t" "icinga_pid=" << Utility::GetPid() << "\n" + "\t" "daemon_mode=1" "\n" + "\t" "program_start=" << static_cast(Application::GetStartTime()) << "\n" + "\t" "active_host_checks_enabled=" << Convert::ToLong(IcingaApplication::GetInstance()->GetEnableHostChecks()) << "\n" + "\t" "passive_host_checks_enabled=1" "\n" + "\t" "active_service_checks_enabled=" << Convert::ToLong(IcingaApplication::GetInstance()->GetEnableServiceChecks()) << "\n" + "\t" "passive_service_checks_enabled=1" "\n" + "\t" "check_service_freshness=1" "\n" + "\t" "check_host_freshness=1" "\n" + "\t" "enable_notifications=" << Convert::ToLong(IcingaApplication::GetInstance()->GetEnableNotifications()) << "\n" + "\t" "enable_event_handlers=" << Convert::ToLong(IcingaApplication::GetInstance()->GetEnableEventHandlers()) << "\n" + "\t" "enable_flap_detection=" << Convert::ToLong(IcingaApplication::GetInstance()->GetEnableFlapping()) << "\n" + "\t" "enable_failure_prediction=0" "\n" + "\t" "process_performance_data=" << Convert::ToLong(IcingaApplication::GetInstance()->GetEnablePerfdata()) << "\n" + "\t" "active_scheduled_host_check_stats=" << CIB::GetActiveHostChecksStatistics(60) << "," << CIB::GetActiveHostChecksStatistics(5 * 60) << "," << CIB::GetActiveHostChecksStatistics(15 * 60) << "\n" + "\t" "passive_host_check_stats=" << CIB::GetPassiveHostChecksStatistics(60) << "," << CIB::GetPassiveHostChecksStatistics(5 * 60) << "," << CIB::GetPassiveHostChecksStatistics(15 * 60) << "\n" + "\t" "active_scheduled_service_check_stats=" << CIB::GetActiveServiceChecksStatistics(60) << "," << CIB::GetActiveServiceChecksStatistics(5 * 60) << "," << CIB::GetActiveServiceChecksStatistics(15 * 60) << "\n" + "\t" "passive_service_check_stats=" << CIB::GetPassiveServiceChecksStatistics(60) << "," << CIB::GetPassiveServiceChecksStatistics(5 * 60) << "," << CIB::GetPassiveServiceChecksStatistics(15 * 60) << "\n" + "\t" "next_downtime_id=" << Downtime::GetNextDowntimeID() << "\n" + "\t" "next_comment_id=" << Comment::GetNextCommentID() << "\n"; statusfp << "\t" "}" "\n" "\n"; diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 7749b275a..54d3da6d0 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -85,25 +85,25 @@ Dictionary::Ptr HostDbObject::GetConfigFields() const fields->Set("stalk_on_down", Empty); fields->Set("stalk_on_unreachable", Empty); - fields->Set("flap_detection_enabled", CompatUtility::GetCheckableFlapDetectionEnabled(host)); + fields->Set("flap_detection_enabled", host->GetEnableFlapping()); 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", CompatUtility::GetCheckableProcessPerformanceData(host)); + fields->Set("process_performance_data", host->GetEnablePerfdata()); 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("event_handler_enabled", host->GetEnableEventHandler()); + fields->Set("passive_checks_enabled", host->GetEnablePassiveChecks()); + fields->Set("active_checks_enabled", host->GetEnableActiveChecks()); fields->Set("retain_status_information", 1); fields->Set("retain_nonstatus_information", 1); - fields->Set("notifications_enabled", CompatUtility::GetCheckableNotificationsEnabled(host)); + fields->Set("notifications_enabled", host->GetEnableNotifications()); fields->Set("obsess_over_host", 0); fields->Set("failure_prediction_enabled", 0); @@ -152,14 +152,14 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const 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("notifications_enabled", host->GetEnableNotifications()); fields->Set("problem_has_been_acknowledged", host->GetAcknowledgement() != AcknowledgementNone); fields->Set("acknowledgement_type", host->GetAcknowledgement()); 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("passive_checks_enabled", host->GetEnablePassiveChecks()); + fields->Set("active_checks_enabled", host->GetEnableActiveChecks()); + fields->Set("event_handler_enabled", host->GetEnableEventHandler()); + fields->Set("flap_detection_enabled", host->GetEnableFlapping()); fields->Set("is_flapping", CompatUtility::GetCheckableIsFlapping(host)); fields->Set("percent_state_change", CompatUtility::GetCheckablePercentStateChange(host)); @@ -170,7 +170,7 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const fields->Set("scheduled_downtime_depth", host->GetDowntimeDepth()); fields->Set("failure_prediction_enabled", Empty); - fields->Set("process_performance_data", CompatUtility::GetCheckableProcessPerformanceData(host)); + fields->Set("process_performance_data", host->GetEnablePerfdata()); fields->Set("obsess_over_host", Empty); fields->Set("event_handler", CompatUtility::GetCheckableEventHandler(host)); fields->Set("check_command", CompatUtility::GetCheckableCheckCommand(host)); diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index eff6b71a8..fc2f4d041 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -78,22 +78,22 @@ Dictionary::Ptr ServiceDbObject::GetConfigFields() const fields->Set("stalk_on_unknown", 0); fields->Set("stalk_on_critical", 0); fields->Set("is_volatile", CompatUtility::GetCheckableIsVolatile(service)); - fields->Set("flap_detection_enabled", CompatUtility::GetCheckableFlapDetectionEnabled(service)); + fields->Set("flap_detection_enabled", service->GetEnableFlapping()); 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::GetCheckableLowFlapThreshold(service)); fields->Set("high_flap_threshold", CompatUtility::GetCheckableHighFlapThreshold(service)); - fields->Set("process_performance_data", CompatUtility::GetCheckableProcessPerformanceData(service)); + fields->Set("process_performance_data", service->GetEnablePerfdata()); 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("event_handler_enabled", service->GetEnableEventHandler()); + fields->Set("passive_checks_enabled", service->GetEnablePassiveChecks()); + fields->Set("active_checks_enabled", service->GetEnableActiveChecks()); fields->Set("retain_status_information", Empty); fields->Set("retain_nonstatus_information", Empty); - fields->Set("notifications_enabled", CompatUtility::GetCheckableNotificationsEnabled(service)); + fields->Set("notifications_enabled", service->GetEnableNotifications()); fields->Set("obsess_over_service", Empty); fields->Set("failure_prediction_enabled", Empty); fields->Set("notes", service->GetNotes()); @@ -140,14 +140,14 @@ Dictionary::Ptr ServiceDbObject::GetStatusFields() const 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::GetCheckableNotificationsEnabled(service)); + fields->Set("notifications_enabled", service->GetEnableNotifications()); fields->Set("problem_has_been_acknowledged", service->GetAcknowledgement() != AcknowledgementNone); fields->Set("acknowledgement_type", service->GetAcknowledgement()); 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("passive_checks_enabled", service->GetEnablePassiveChecks()); + fields->Set("active_checks_enabled", service->GetEnableActiveChecks()); + fields->Set("event_handler_enabled", service->GetEnableEventHandler()); + fields->Set("flap_detection_enabled", service->GetEnableFlapping()); fields->Set("is_flapping", CompatUtility::GetCheckableIsFlapping(service)); fields->Set("percent_state_change", CompatUtility::GetCheckablePercentStateChange(service)); @@ -157,7 +157,7 @@ Dictionary::Ptr ServiceDbObject::GetStatusFields() const } fields->Set("scheduled_downtime_depth", service->GetDowntimeDepth()); - fields->Set("process_performance_data", CompatUtility::GetCheckableProcessPerformanceData(service)); + fields->Set("process_performance_data", service->GetEnablePerfdata()); fields->Set("event_handler", CompatUtility::GetCheckableEventHandler(service)); fields->Set("check_command", CompatUtility::GetCheckableCheckCommand(service)); fields->Set("normal_check_interval", CompatUtility::GetCheckableCheckInterval(service)); diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 3b5d8c756..7b8d937ee 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -202,26 +202,6 @@ String CompatUtility::GetCheckableCheckPeriod(const Checkable::Ptr& checkable) return "24x7"; } -int CompatUtility::GetCheckablePassiveChecksEnabled(const Checkable::Ptr& checkable) -{ - return (checkable->GetEnablePassiveChecks() ? 1 : 0); -} - -int CompatUtility::GetCheckableActiveChecksEnabled(const Checkable::Ptr& checkable) -{ - return (checkable->GetEnableActiveChecks() ? 1 : 0); -} - -int CompatUtility::GetCheckableEventHandlerEnabled(const Checkable::Ptr& checkable) -{ - return (checkable->GetEnableEventHandler() ? 1 : 0); -} - -int CompatUtility::GetCheckableFlapDetectionEnabled(const Checkable::Ptr& checkable) -{ - return (checkable->GetEnableFlapping() ? 1 : 0); -} - int CompatUtility::GetCheckableIsFlapping(const Checkable::Ptr& checkable) { return (checkable->IsFlapping() ? 1 : 0); @@ -237,11 +217,6 @@ double CompatUtility::GetCheckablePercentStateChange(const Checkable::Ptr& check return checkable->GetFlappingCurrent(); } -int CompatUtility::GetCheckableProcessPerformanceData(const Checkable::Ptr& checkable) -{ - return (checkable->GetEnablePerfdata() ? 1 : 0); -} - String CompatUtility::GetCheckableEventHandler(const Checkable::Ptr& checkable) { String event_command_str; @@ -355,11 +330,6 @@ String CompatUtility::GetCustomAttributeConfig(const CustomVarObject::Ptr& objec } /* notifications */ -int CompatUtility::GetCheckableNotificationsEnabled(const Checkable::Ptr& checkable) -{ - return (checkable->GetEnableNotifications() ? 1 : 0); -} - int CompatUtility::GetCheckableNotificationLastNotification(const Checkable::Ptr& checkable) { double last_notification = 0.0; diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index e5a9a89e1..5e6b176ec 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -54,14 +54,9 @@ public: static double GetCheckableCheckInterval(const Checkable::Ptr& checkable); static double GetCheckableRetryInterval(const Checkable::Ptr& checkable); static String GetCheckableCheckPeriod(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 int GetCheckableIsReachable(const Checkable::Ptr& checkable); static double 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); diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index 49dd9fac6..61e38108f 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -76,7 +76,7 @@ void HostsTable::AddColumns(Table *table, const String& prefix, table->AddColumn(prefix + "max_check_attempts", Column(&HostsTable::MaxCheckAttemptsAccessor, objectAccessor)); table->AddColumn(prefix + "flap_detection_enabled", Column(&HostsTable::FlapDetectionEnabledAccessor, objectAccessor)); table->AddColumn(prefix + "check_freshness", Column(&Table::OneAccessor, objectAccessor)); - table->AddColumn(prefix + "process_performance_data", Column(&Table::ZeroAccessor, objectAccessor)); + table->AddColumn(prefix + "process_performance_data", Column(&HostsTable::ProcessPerformanceDataAccessor, objectAccessor)); table->AddColumn(prefix + "accept_passive_checks", Column(&HostsTable::AcceptPassiveChecksAccessor, objectAccessor)); table->AddColumn(prefix + "event_handler_enabled", Column(&HostsTable::EventHandlerEnabledAccessor, objectAccessor)); table->AddColumn(prefix + "acknowledgement_type", Column(&HostsTable::AcknowledgementTypeAccessor, objectAccessor)); @@ -481,7 +481,7 @@ Value HostsTable::FlapDetectionEnabledAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableFlapDetectionEnabled(host); + return Convert::ToLong(host->GetEnableFlapping()); } Value HostsTable::AcceptPassiveChecksAccessor(const Value& row) @@ -491,7 +491,7 @@ Value HostsTable::AcceptPassiveChecksAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckablePassiveChecksEnabled(host); + return Convert::ToLong(host->GetEnablePassiveChecks()); } Value HostsTable::EventHandlerEnabledAccessor(const Value& row) @@ -501,7 +501,7 @@ Value HostsTable::EventHandlerEnabledAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableEventHandlerEnabled(host); + return Convert::ToLong(host->GetEnableEventHandler()); } Value HostsTable::AcknowledgementTypeAccessor(const Value& row) @@ -632,7 +632,7 @@ Value HostsTable::ChecksEnabledAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableActiveChecksEnabled(host); + return Convert::ToLong(host->GetEnableActiveChecks()); } Value HostsTable::NotificationsEnabledAccessor(const Value& row) @@ -642,7 +642,17 @@ Value HostsTable::NotificationsEnabledAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableNotificationsEnabled(host); + return Convert::ToLong(host->GetEnableNotifications()); +} + +Value HostsTable::ProcessPerformanceDataAccessor(const Value& row) +{ + Host::Ptr host = static_cast(row); + + if (!host) + return Empty; + + return Convert::ToLong(host->GetEnablePerfdata()); } Value HostsTable::AcknowledgedAccessor(const Value& row) @@ -763,7 +773,7 @@ Value HostsTable::ActiveChecksEnabledAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableActiveChecksEnabled(host); + return Convert::ToLong(host->GetEnableActiveChecks()); } Value HostsTable::CheckOptionsAccessor(const Value&) diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index 072535ca9..e3aa936f5 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -721,7 +721,7 @@ Value ServicesTable::ChecksEnabledAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableActiveChecksEnabled(service); + return Convert::ToLong(service->GetEnableActiveChecks()); } Value ServicesTable::AcceptPassiveChecksAccessor(const Value& row) @@ -731,7 +731,7 @@ Value ServicesTable::AcceptPassiveChecksAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckablePassiveChecksEnabled(service); + return Convert::ToLong(service->GetEnablePassiveChecks()); } Value ServicesTable::EventHandlerEnabledAccessor(const Value& row) @@ -741,7 +741,7 @@ Value ServicesTable::EventHandlerEnabledAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableEventHandlerEnabled(service); + return Convert::ToLong(service->GetEnableEventHandler()); } Value ServicesTable::NotificationsEnabledAccessor(const Value& row) @@ -751,7 +751,7 @@ Value ServicesTable::NotificationsEnabledAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableNotificationsEnabled(service); + return Convert::ToLong(service->GetEnableNotifications()); } Value ServicesTable::ProcessPerformanceDataAccessor(const Value& row) @@ -761,7 +761,7 @@ Value ServicesTable::ProcessPerformanceDataAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableProcessPerformanceData(service); + return Convert::ToLong(service->GetEnablePerfdata()); } Value ServicesTable::ActiveChecksEnabledAccessor(const Value& row) @@ -771,7 +771,7 @@ Value ServicesTable::ActiveChecksEnabledAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableActiveChecksEnabled(service); + return Convert::ToLong(service->GetEnableActiveChecks()); } Value ServicesTable::CheckOptionsAccessor(const Value& row) @@ -787,7 +787,7 @@ Value ServicesTable::FlapDetectionEnabledAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableFlapDetectionEnabled(service); + return Convert::ToLong(service->GetEnableFlapping()); } Value ServicesTable::CheckFreshnessAccessor(const Value& row) From b4af0971af62b69aa6640ca0dd477d5a8b70d7f7 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 5 Dec 2017 18:53:22 +0100 Subject: [PATCH 07/33] Drop dead code in Livestatus feature --- lib/compat/statusdatawriter.cpp | 6 +++--- lib/db_ido/dbevents.cpp | 4 ++-- lib/db_ido/hostdbobject.cpp | 6 +++--- lib/db_ido/servicedbobject.cpp | 6 +++--- lib/icinga/compatutility.cpp | 15 --------------- lib/icinga/compatutility.hpp | 3 --- lib/livestatus/hoststable.cpp | 10 ++-------- lib/livestatus/hoststable.hpp | 1 - lib/livestatus/servicestable.cpp | 10 ++-------- lib/livestatus/servicestable.hpp | 1 - 10 files changed, 15 insertions(+), 47 deletions(-) diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index 6282cb9b1..2561e39c8 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -385,8 +385,8 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl "\t" "active_checks_enabled=" << Convert::ToLong(checkable->GetEnableActiveChecks()) << "\n" "\t" "passive_checks_enabled=" << Convert::ToLong(checkable->GetEnablePassiveChecks()) << "\n" "\t" "flap_detection_enabled=" << Convert::ToLong(checkable->GetEnableFlapping()) << "\n" - "\t" "is_flapping=" << CompatUtility::GetCheckableIsFlapping(checkable) << "\n" - "\t" "percent_state_change=" << CompatUtility::GetCheckablePercentStateChange(checkable) << "\n" + "\t" "is_flapping=" << Convert::ToLong(checkable->IsFlapping()) << "\n" + "\t" "percent_state_change=" << checkable->GetFlappingCurrent() << "\n" "\t" "problem_has_been_acknowledged=" << (checkable->GetAcknowledgement() != AcknowledgementNone ? 1 : 0) << "\n" "\t" "acknowledgement_type=" << checkable->GetAcknowledgement() << "\n" "\t" "acknowledgement_end_time=" << checkable->GetAcknowledgementExpiry() << "\n" @@ -394,7 +394,7 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl "\t" "last_notification=" << CompatUtility::GetCheckableNotificationLastNotification(checkable) << "\n" "\t" "next_notification=" << CompatUtility::GetCheckableNotificationNextNotification(checkable) << "\n" "\t" "current_notification_number=" << CompatUtility::GetCheckableNotificationNotificationNumber(checkable) << "\n" - "\t" "is_reachable=" << CompatUtility::GetCheckableIsReachable(checkable) << "\n"; + "\t" "is_reachable=" << Convert::ToLong(checkable->IsReachable()) << "\n"; } void StatusDataWriter::DumpServiceStatus(std::ostream& fp, const Service::Ptr& service) diff --git a/lib/db_ido/dbevents.cpp b/lib/db_ido/dbevents.cpp index 6f4e567dc..24ffd0ce1 100644 --- a/lib/db_ido/dbevents.cpp +++ b/lib/db_ido/dbevents.cpp @@ -137,8 +137,8 @@ void DbEvents::FlappingChangedHandler(const Checkable::Ptr& checkable) query1.Object = DbObject::GetOrCreateByObject(checkable); Dictionary::Ptr fields1 = new Dictionary(); - fields1->Set("is_flapping", CompatUtility::GetCheckableIsFlapping(checkable)); - fields1->Set("percent_state_change", CompatUtility::GetCheckablePercentStateChange(checkable)); + fields1->Set("is_flapping", checkable->IsFlapping()); + fields1->Set("percent_state_change", checkable->GetFlappingCurrent()); query1.Fields = fields1; diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 54d3da6d0..8aec40799 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -160,8 +160,8 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const fields->Set("active_checks_enabled", host->GetEnableActiveChecks()); fields->Set("event_handler_enabled", host->GetEnableEventHandler()); fields->Set("flap_detection_enabled", host->GetEnableFlapping()); - fields->Set("is_flapping", CompatUtility::GetCheckableIsFlapping(host)); - fields->Set("percent_state_change", CompatUtility::GetCheckablePercentStateChange(host)); + fields->Set("is_flapping", host->IsFlapping()); + fields->Set("percent_state_change", host->GetFlappingCurrent()); if (cr) { fields->Set("latency", Convert::ToString(cr->CalculateLatency())); @@ -177,7 +177,7 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const fields->Set("normal_check_interval", CompatUtility::GetCheckableCheckInterval(host)); fields->Set("retry_check_interval", CompatUtility::GetCheckableRetryInterval(host)); fields->Set("check_timeperiod_object_id", host->GetCheckPeriod()); - fields->Set("is_reachable", CompatUtility::GetCheckableIsReachable(host)); + fields->Set("is_reachable", host->IsReachable()); fields->Set("original_attributes", JsonEncode(host->GetOriginalAttributes())); diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index fc2f4d041..28886fc3f 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -148,8 +148,8 @@ Dictionary::Ptr ServiceDbObject::GetStatusFields() const fields->Set("active_checks_enabled", service->GetEnableActiveChecks()); fields->Set("event_handler_enabled", service->GetEnableEventHandler()); fields->Set("flap_detection_enabled", service->GetEnableFlapping()); - fields->Set("is_flapping", CompatUtility::GetCheckableIsFlapping(service)); - fields->Set("percent_state_change", CompatUtility::GetCheckablePercentStateChange(service)); + fields->Set("is_flapping", service->IsFlapping()); + fields->Set("percent_state_change", service->GetFlappingCurrent()); if (cr) { fields->Set("latency", Convert::ToString(cr->CalculateLatency())); @@ -163,7 +163,7 @@ Dictionary::Ptr ServiceDbObject::GetStatusFields() const 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("is_reachable", CompatUtility::GetCheckableIsReachable(service)); + fields->Set("is_reachable", service->IsReachable()); fields->Set("original_attributes", JsonEncode(service->GetOriginalAttributes())); diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 7b8d937ee..2f3557a36 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -202,21 +202,6 @@ String CompatUtility::GetCheckableCheckPeriod(const Checkable::Ptr& checkable) return "24x7"; } -int CompatUtility::GetCheckableIsFlapping(const Checkable::Ptr& checkable) -{ - return (checkable->IsFlapping() ? 1 : 0); -} - -int CompatUtility::GetCheckableIsReachable(const Checkable::Ptr& checkable) -{ - return (checkable->IsReachable() ? 1 : 0); -} - -double CompatUtility::GetCheckablePercentStateChange(const Checkable::Ptr& checkable) -{ - return checkable->GetFlappingCurrent(); -} - String CompatUtility::GetCheckableEventHandler(const Checkable::Ptr& checkable) { String event_command_str; diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 5e6b176ec..4f61279e9 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -54,9 +54,6 @@ public: static double GetCheckableCheckInterval(const Checkable::Ptr& checkable); static double GetCheckableRetryInterval(const Checkable::Ptr& checkable); static String GetCheckableCheckPeriod(const Checkable::Ptr& checkable); - static int GetCheckableIsFlapping(const Checkable::Ptr& checkable); - static int GetCheckableIsReachable(const Checkable::Ptr& checkable); - static double GetCheckablePercentStateChange(const Checkable::Ptr& checkable); static String GetCheckableEventHandler(const Checkable::Ptr& checkable); static String GetCheckableCheckCommand(const Checkable::Ptr& checkable); diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index 61e38108f..65994682c 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -108,7 +108,7 @@ void HostsTable::AddColumns(Table *table, const String& prefix, table->AddColumn(prefix + "scheduled_downtime_depth", Column(&HostsTable::ScheduledDowntimeDepthAccessor, objectAccessor)); table->AddColumn(prefix + "is_executing", Column(&Table::ZeroAccessor, objectAccessor)); table->AddColumn(prefix + "active_checks_enabled", Column(&HostsTable::ActiveChecksEnabledAccessor, objectAccessor)); - table->AddColumn(prefix + "check_options", Column(&HostsTable::CheckOptionsAccessor, objectAccessor)); + table->AddColumn(prefix + "check_options", Column(&Table::EmptyStringAccessor, objectAccessor)); table->AddColumn(prefix + "obsess_over_host", Column(&Table::ZeroAccessor, objectAccessor)); table->AddColumn(prefix + "modified_attributes", Column(&Table::ZeroAccessor, objectAccessor)); table->AddColumn(prefix + "modified_attributes_list", Column(&Table::ZeroAccessor, objectAccessor)); @@ -776,12 +776,6 @@ Value HostsTable::ActiveChecksEnabledAccessor(const Value& row) return Convert::ToLong(host->GetEnableActiveChecks()); } -Value HostsTable::CheckOptionsAccessor(const Value&) -{ - /* TODO - forcexec, freshness, orphan, none */ - return Empty; -} - Value HostsTable::CheckIntervalAccessor(const Value& row) { Host::Ptr host = static_cast(row); @@ -869,7 +863,7 @@ Value HostsTable::PercentStateChangeAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckablePercentStateChange(host); + return host->GetFlappingCurrent(); } Value HostsTable::InNotificationPeriodAccessor(const Value& row) diff --git a/lib/livestatus/hoststable.hpp b/lib/livestatus/hoststable.hpp index c6e34bb3b..9a08bec0c 100644 --- a/lib/livestatus/hoststable.hpp +++ b/lib/livestatus/hoststable.hpp @@ -99,7 +99,6 @@ protected: static Value IsFlappingAccessor(const Value& row); static Value ScheduledDowntimeDepthAccessor(const Value& row); static Value ActiveChecksEnabledAccessor(const Value& row); - static Value CheckOptionsAccessor(const Value& row); static Value CheckIntervalAccessor(const Value& row); static Value RetryIntervalAccessor(const Value& row); static Value NotificationIntervalAccessor(const Value& row); diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index e3aa936f5..c9cec7c39 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -103,7 +103,7 @@ void ServicesTable::AddColumns(Table *table, const String& prefix, table->AddColumn(prefix + "process_performance_data", Column(&ServicesTable::ProcessPerformanceDataAccessor, objectAccessor)); table->AddColumn(prefix + "is_executing", Column(&Table::ZeroAccessor, objectAccessor)); table->AddColumn(prefix + "active_checks_enabled", Column(&ServicesTable::ActiveChecksEnabledAccessor, objectAccessor)); - table->AddColumn(prefix + "check_options", Column(&ServicesTable::CheckOptionsAccessor, objectAccessor)); + table->AddColumn(prefix + "check_options", Column(&Table::EmptyStringAccessor, objectAccessor)); table->AddColumn(prefix + "flap_detection_enabled", Column(&ServicesTable::FlapDetectionEnabledAccessor, objectAccessor)); table->AddColumn(prefix + "check_freshness", Column(&ServicesTable::CheckFreshnessAccessor, objectAccessor)); table->AddColumn(prefix + "obsess_over_service", Column(&Table::ZeroAccessor, objectAccessor)); @@ -774,12 +774,6 @@ Value ServicesTable::ActiveChecksEnabledAccessor(const Value& row) return Convert::ToLong(service->GetEnableActiveChecks()); } -Value ServicesTable::CheckOptionsAccessor(const Value& row) -{ - /* TODO - forcexec, freshness, orphan, none */ - return Empty; -} - Value ServicesTable::FlapDetectionEnabledAccessor(const Value& row) { Service::Ptr service = static_cast(row); @@ -897,7 +891,7 @@ Value ServicesTable::PercentStateChangeAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckablePercentStateChange(service); + return service->GetFlappingCurrent(); } Value ServicesTable::InCheckPeriodAccessor(const Value& row) diff --git a/lib/livestatus/servicestable.hpp b/lib/livestatus/servicestable.hpp index 665557236..afa9c84cd 100644 --- a/lib/livestatus/servicestable.hpp +++ b/lib/livestatus/servicestable.hpp @@ -98,7 +98,6 @@ protected: static Value NotificationsEnabledAccessor(const Value& row); static Value ProcessPerformanceDataAccessor(const Value& row); static Value ActiveChecksEnabledAccessor(const Value& row); - static Value CheckOptionsAccessor(const Value& row); static Value FlapDetectionEnabledAccessor(const Value& row); static Value CheckFreshnessAccessor(const Value& row); static Value StalenessAccessor(const Value& row); From 5466197d29930352ac36b1bd4f4cbcb71d5db607 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 5 Dec 2017 19:30:45 +0100 Subject: [PATCH 08/33] Drop CompatUtility::*Command helpers --- lib/db_ido/hostdbobject.cpp | 12 ++++++++++-- lib/db_ido/servicedbobject.cpp | 12 ++++++++++-- lib/icinga/compatutility.cpp | 22 ---------------------- lib/icinga/compatutility.hpp | 3 --- 4 files changed, 20 insertions(+), 29 deletions(-) diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 8aec40799..8cb682409 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -172,8 +172,6 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const fields->Set("failure_prediction_enabled", Empty); fields->Set("process_performance_data", host->GetEnablePerfdata()); fields->Set("obsess_over_host", Empty); - 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()); @@ -181,6 +179,16 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const fields->Set("original_attributes", JsonEncode(host->GetOriginalAttributes())); + EventCommand::Ptr eventCommand = host->GetEventCommand(); + + if (eventCommand) + fields->Set("event_handler", eventCommand->GetName()); + + CheckCommand::Ptr checkCommand = host->GetCheckCommand(); + + if (checkCommand) + fields->Set("check_command", checkCommand->GetName()); + return fields; } diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 28886fc3f..597ad08de 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -158,8 +158,6 @@ Dictionary::Ptr ServiceDbObject::GetStatusFields() const fields->Set("scheduled_downtime_depth", service->GetDowntimeDepth()); fields->Set("process_performance_data", service->GetEnablePerfdata()); - 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()); @@ -167,6 +165,16 @@ Dictionary::Ptr ServiceDbObject::GetStatusFields() const fields->Set("original_attributes", JsonEncode(service->GetOriginalAttributes())); + EventCommand::Ptr eventCommand = service->GetEventCommand(); + + if (eventCommand) + fields->Set("event_handler", eventCommand->GetName()); + + CheckCommand::Ptr checkCommand = service->GetCheckCommand(); + + if (checkCommand) + fields->Set("check_command", checkCommand->GetName()); + return fields; } diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 2f3557a36..031754a9e 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -202,28 +202,6 @@ String CompatUtility::GetCheckableCheckPeriod(const Checkable::Ptr& checkable) return "24x7"; } -String CompatUtility::GetCheckableEventHandler(const Checkable::Ptr& checkable) -{ - String event_command_str; - EventCommand::Ptr eventcommand = checkable->GetEventCommand(); - - if (eventcommand) - event_command_str = eventcommand->GetName(); - - return event_command_str; -} - -String CompatUtility::GetCheckableCheckCommand(const Checkable::Ptr& checkable) -{ - String check_command_str; - CheckCommand::Ptr checkcommand = checkable->GetCheckCommand(); - - if (checkcommand) - check_command_str = checkcommand->GetName(); - - return check_command_str; -} - int CompatUtility::GetCheckableIsVolatile(const Checkable::Ptr& checkable) { return (checkable->GetVolatile() ? 1 : 0); diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 4f61279e9..0ec8f0eab 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -55,9 +55,6 @@ public: static double GetCheckableRetryInterval(const Checkable::Ptr& checkable); static String GetCheckableCheckPeriod(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); From db6ed405e4247bfab577eeb7beb63a2779971979 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 5 Dec 2017 19:51:34 +0100 Subject: [PATCH 09/33] Remove more redundant wrappers from CompatUtility class --- lib/compat/statusdatawriter.cpp | 2 +- lib/db_ido/hostdbobject.cpp | 4 ++-- lib/db_ido/servicedbobject.cpp | 6 +++--- lib/icinga/compatutility.cpp | 28 ---------------------------- lib/icinga/compatutility.hpp | 4 ---- lib/livestatus/hoststable.cpp | 11 +++++++---- lib/livestatus/servicestable.cpp | 11 +++++++---- 7 files changed, 20 insertions(+), 46 deletions(-) diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index 2561e39c8..bbc559918 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -434,7 +434,7 @@ void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& s "\t" "active_checks_enabled" "\t" << Convert::ToLong(service->GetEnableActiveChecks()) << "\n" "\t" "passive_checks_enabled" "\t" << Convert::ToLong(service->GetEnablePassiveChecks()) << "\n" "\t" "flap_detection_enabled" "\t" << Convert::ToLong(service->GetEnableFlapping()) << "\n" - "\t" "is_volatile" "\t" << CompatUtility::GetCheckableIsVolatile(service) << "\n" + "\t" "is_volatile" "\t" << Convert::ToLong(service->GetVolatile()) << "\n" "\t" "notifications_enabled" "\t" << Convert::ToLong(service->GetEnableNotifications()) << "\n" "\t" "notification_options" "\t" << CompatUtility::GetCheckableNotificationNotificationOptions(service) << "\n" "\t" "notification_interval" "\t" << CompatUtility::GetCheckableNotificationNotificationInterval(service) << "\n" diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 8cb682409..0ce0209be 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -89,8 +89,8 @@ Dictionary::Ptr HostDbObject::GetConfigFields() const 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("low_flap_threshold", host->GetFlappingThresholdLow()); + fields->Set("high_flap_threshold", host->GetFlappingThresholdLow()); fields->Set("process_performance_data", host->GetEnablePerfdata()); diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 597ad08de..24a522189 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -77,14 +77,14 @@ Dictionary::Ptr ServiceDbObject::GetConfigFields() const fields->Set("stalk_on_warning", 0); fields->Set("stalk_on_unknown", 0); fields->Set("stalk_on_critical", 0); - fields->Set("is_volatile", CompatUtility::GetCheckableIsVolatile(service)); + fields->Set("is_volatile", service->GetVolatile()); fields->Set("flap_detection_enabled", service->GetEnableFlapping()); 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::GetCheckableLowFlapThreshold(service)); - fields->Set("high_flap_threshold", CompatUtility::GetCheckableHighFlapThreshold(service)); + fields->Set("low_flap_threshold", service->GetFlappingThresholdLow()); + fields->Set("high_flap_threshold", service->GetFlappingThresholdLow()); fields->Set("process_performance_data", service->GetEnablePerfdata()); fields->Set("freshness_checks_enabled", CompatUtility::GetCheckableFreshnessChecksEnabled(service)); fields->Set("freshness_threshold", CompatUtility::GetCheckableFreshnessThreshold(service)); diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 031754a9e..7baf65bbd 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -202,21 +202,6 @@ String CompatUtility::GetCheckableCheckPeriod(const Checkable::Ptr& checkable) return "24x7"; } -int CompatUtility::GetCheckableIsVolatile(const Checkable::Ptr& checkable) -{ - return (checkable->GetVolatile() ? 1 : 0); -} - -double CompatUtility::GetCheckableLowFlapThreshold(const Checkable::Ptr& checkable) -{ - return checkable->GetFlappingThresholdLow(); -} - -double CompatUtility::GetCheckableHighFlapThreshold(const Checkable::Ptr& checkable) -{ - return checkable->GetFlappingThresholdHigh(); -} - int CompatUtility::GetCheckableFreshnessChecksEnabled(const Checkable::Ptr& checkable) { return (checkable->GetCheckInterval() > 0 ? 1 : 0); @@ -227,19 +212,6 @@ int CompatUtility::GetCheckableFreshnessThreshold(const Checkable::Ptr& checkabl return static_cast(checkable->GetCheckInterval()); } -double CompatUtility::GetCheckableStaleness(const Checkable::Ptr& checkable) -{ - if (checkable->HasBeenChecked() && checkable->GetLastCheck() > 0) - return (Utility::GetTime() - checkable->GetLastCheck()) / (checkable->GetCheckInterval() * 3600); - - return 0.0; -} - -int CompatUtility::GetCheckableIsAcknowledged(const Checkable::Ptr& checkable) -{ - return (checkable->IsAcknowledged() ? 1 : 0); -} - int CompatUtility::GetCheckableNoMoreNotifications(const Checkable::Ptr& checkable) { if (CompatUtility::GetCheckableNotificationNotificationInterval(checkable) == 0 && !checkable->GetVolatile()) diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 0ec8f0eab..64a6e8cfe 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -55,12 +55,8 @@ public: static double GetCheckableRetryInterval(const Checkable::Ptr& checkable); static String GetCheckableCheckPeriod(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); diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index 65994682c..6c0157f1b 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -663,7 +663,7 @@ Value HostsTable::AcknowledgedAccessor(const Value& row) return Empty; ObjectLock olock(host); - return CompatUtility::GetCheckableIsAcknowledged(host); + return host->IsAcknowledged(); } Value HostsTable::StateAccessor(const Value& row) @@ -813,7 +813,7 @@ Value HostsTable::LowFlapThresholdAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableLowFlapThreshold(host); + return host->GetFlappingThresholdLow(); } Value HostsTable::HighFlapThresholdAccessor(const Value& row) @@ -823,7 +823,7 @@ Value HostsTable::HighFlapThresholdAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableHighFlapThreshold(host); + return host->GetFlappingThresholdHigh(); } Value HostsTable::LatencyAccessor(const Value& row) @@ -1394,7 +1394,10 @@ Value HostsTable::StalenessAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableStaleness(host); + if (host->HasBeenChecked() && host->GetLastCheck() > 0) + return (Utility::GetTime() - host->GetLastCheck()) / (host->GetCheckInterval() * 3600); + + return 0.0; } Value HostsTable::GroupsAccessor(const Value& row) diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index c9cec7c39..4bf363a32 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -560,7 +560,7 @@ Value ServicesTable::AcknowledgedAccessor(const Value& row) return Empty; ObjectLock olock(service); - return CompatUtility::GetCheckableIsAcknowledged(service); + return service->IsAcknowledged(); } Value ServicesTable::AcknowledgementTypeAccessor(const Value& row) @@ -801,7 +801,10 @@ Value ServicesTable::StalenessAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableStaleness(service); + if (service->HasBeenChecked() && service->GetLastCheck() > 0) + return (Utility::GetTime() - service->GetLastCheck()) / (service->GetCheckInterval() * 3600); + + return 0.0; } Value ServicesTable::CheckIntervalAccessor(const Value& row) @@ -841,7 +844,7 @@ Value ServicesTable::LowFlapThresholdAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableLowFlapThreshold(service); + return service->GetFlappingThresholdLow(); } Value ServicesTable::HighFlapThresholdAccessor(const Value& row) @@ -851,7 +854,7 @@ Value ServicesTable::HighFlapThresholdAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableHighFlapThreshold(service); + return service->GetFlappingThresholdHigh(); } Value ServicesTable::LatencyAccessor(const Value& row) From cbea0c13f5580ec167f55f5a11c18e79ae23a1ef Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 6 Dec 2017 15:35:27 +0100 Subject: [PATCH 10/33] Drop Freshness wrappers from CompatUtility class --- lib/db_ido/hostdbobject.cpp | 4 ++-- lib/db_ido/servicedbobject.cpp | 4 ++-- lib/icinga/compatutility.cpp | 10 ---------- lib/icinga/compatutility.hpp | 3 --- lib/livestatus/servicestable.cpp | 12 +----------- lib/livestatus/servicestable.hpp | 1 - 6 files changed, 5 insertions(+), 29 deletions(-) diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 0ce0209be..0cdfbc520 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -94,8 +94,8 @@ Dictionary::Ptr HostDbObject::GetConfigFields() const fields->Set("process_performance_data", host->GetEnablePerfdata()); - fields->Set("freshness_checks_enabled", CompatUtility::GetCheckableFreshnessChecksEnabled(host)); - fields->Set("freshness_threshold", CompatUtility::GetCheckableFreshnessThreshold(host)); + fields->Set("freshness_checks_enabled", 1); + fields->Set("freshness_threshold", Convert::ToLong(host->GetCheckInterval())); fields->Set("event_handler_enabled", host->GetEnableEventHandler()); fields->Set("passive_checks_enabled", host->GetEnablePassiveChecks()); fields->Set("active_checks_enabled", host->GetEnableActiveChecks()); diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 24a522189..ae9032a00 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -86,8 +86,8 @@ Dictionary::Ptr ServiceDbObject::GetConfigFields() const fields->Set("low_flap_threshold", service->GetFlappingThresholdLow()); fields->Set("high_flap_threshold", service->GetFlappingThresholdLow()); fields->Set("process_performance_data", service->GetEnablePerfdata()); - fields->Set("freshness_checks_enabled", CompatUtility::GetCheckableFreshnessChecksEnabled(service)); - fields->Set("freshness_threshold", CompatUtility::GetCheckableFreshnessThreshold(service)); + fields->Set("freshness_checks_enabled", 1); + fields->Set("freshness_threshold", Convert::ToLong(service->GetCheckInterval())); fields->Set("event_handler_enabled", service->GetEnableEventHandler()); fields->Set("passive_checks_enabled", service->GetEnablePassiveChecks()); fields->Set("active_checks_enabled", service->GetEnableActiveChecks()); diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 7baf65bbd..9a1de411d 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -202,16 +202,6 @@ String CompatUtility::GetCheckableCheckPeriod(const Checkable::Ptr& checkable) return "24x7"; } -int CompatUtility::GetCheckableFreshnessChecksEnabled(const Checkable::Ptr& checkable) -{ - return (checkable->GetCheckInterval() > 0 ? 1 : 0); -} - -int CompatUtility::GetCheckableFreshnessThreshold(const Checkable::Ptr& checkable) -{ - return static_cast(checkable->GetCheckInterval()); -} - int CompatUtility::GetCheckableNoMoreNotifications(const Checkable::Ptr& checkable) { if (CompatUtility::GetCheckableNotificationNotificationInterval(checkable) == 0 && !checkable->GetVolatile()) diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 64a6e8cfe..0cce3732e 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -55,9 +55,6 @@ public: static double GetCheckableRetryInterval(const Checkable::Ptr& checkable); static String GetCheckableCheckPeriod(const Checkable::Ptr& checkable); - static int GetCheckableFreshnessChecksEnabled(const Checkable::Ptr& checkable); - static int GetCheckableFreshnessThreshold(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); diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index 4bf363a32..d88c3a906 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -105,7 +105,7 @@ void ServicesTable::AddColumns(Table *table, const String& prefix, table->AddColumn(prefix + "active_checks_enabled", Column(&ServicesTable::ActiveChecksEnabledAccessor, objectAccessor)); table->AddColumn(prefix + "check_options", Column(&Table::EmptyStringAccessor, objectAccessor)); table->AddColumn(prefix + "flap_detection_enabled", Column(&ServicesTable::FlapDetectionEnabledAccessor, objectAccessor)); - table->AddColumn(prefix + "check_freshness", Column(&ServicesTable::CheckFreshnessAccessor, objectAccessor)); + table->AddColumn(prefix + "check_freshness", Column(&Table::OneAccessor, objectAccessor)); table->AddColumn(prefix + "obsess_over_service", Column(&Table::ZeroAccessor, objectAccessor)); table->AddColumn(prefix + "modified_attributes", Column(&Table::ZeroAccessor, objectAccessor)); table->AddColumn(prefix + "modified_attributes_list", Column(&Table::ZeroAccessor, objectAccessor)); @@ -784,16 +784,6 @@ Value ServicesTable::FlapDetectionEnabledAccessor(const Value& row) return Convert::ToLong(service->GetEnableFlapping()); } -Value ServicesTable::CheckFreshnessAccessor(const Value& row) -{ - Service::Ptr service = static_cast(row); - - if (!service) - return Empty; - - return CompatUtility::GetCheckableFreshnessChecksEnabled(service); -} - Value ServicesTable::StalenessAccessor(const Value& row) { Service::Ptr service = static_cast(row); diff --git a/lib/livestatus/servicestable.hpp b/lib/livestatus/servicestable.hpp index afa9c84cd..17ff49a3a 100644 --- a/lib/livestatus/servicestable.hpp +++ b/lib/livestatus/servicestable.hpp @@ -99,7 +99,6 @@ protected: static Value ProcessPerformanceDataAccessor(const Value& row); static Value ActiveChecksEnabledAccessor(const Value& row); static Value FlapDetectionEnabledAccessor(const Value& row); - static Value CheckFreshnessAccessor(const Value& row); static Value StalenessAccessor(const Value& row); static Value CheckIntervalAccessor(const Value& row); static Value RetryIntervalAccessor(const Value& row); From b5f5d167dc2c1791d23fb5b033e52ed51750e02a Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 6 Dec 2017 15:42:39 +0100 Subject: [PATCH 11/33] Drop dead CompatUtility::GetCustomAttributeConfig --- lib/icinga/compatutility.cpp | 10 ---------- lib/icinga/compatutility.hpp | 1 - 2 files changed, 11 deletions(-) diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 9a1de411d..3ab26a187 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -244,16 +244,6 @@ Dictionary::Ptr CompatUtility::GetCustomAttributeConfig(const CustomVarObject::P return vars; } -String CompatUtility::GetCustomAttributeConfig(const CustomVarObject::Ptr& object, const String& name) -{ - Dictionary::Ptr vars = object->GetVars(); - - if (!vars) - return Empty; - - return vars->Get(name); -} - /* notifications */ int CompatUtility::GetCheckableNotificationLastNotification(const Checkable::Ptr& checkable) { diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 0cce3732e..e5c6af536 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -79,7 +79,6 @@ public: static std::set GetCheckableNotificationUserGroups(const Checkable::Ptr& checkable); /* custom attribute */ - static String GetCustomAttributeConfig(const CustomVarObject::Ptr& object, const String& name); static Dictionary::Ptr GetCustomAttributeConfig(const CustomVarObject::Ptr& object); /* check result */ From f2fe165ccb7946f2d39b0d8b3634d858852bb0a1 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 6 Dec 2017 15:51:19 +0100 Subject: [PATCH 12/33] Drop useless CompatUtility::GetCustomAttributeConfig() wrapper --- lib/db_ido/dbobject.cpp | 4 ++-- lib/icinga/compatutility.cpp | 11 ----------- lib/icinga/compatutility.hpp | 3 --- lib/livestatus/commandstable.cpp | 6 +++--- lib/livestatus/contactstable.cpp | 8 ++++---- lib/livestatus/hoststable.cpp | 8 ++++---- lib/livestatus/servicestable.cpp | 8 ++++---- 7 files changed, 17 insertions(+), 31 deletions(-) diff --git a/lib/db_ido/dbobject.cpp b/lib/db_ido/dbobject.cpp index 7a7fa92ae..b9c14d528 100644 --- a/lib/db_ido/dbobject.cpp +++ b/lib/db_ido/dbobject.cpp @@ -227,7 +227,7 @@ void DbObject::SendVarsConfigUpdateHeavy() query2.WhereCriteria->Set("object_id", obj); queries.emplace_back(std::move(query2)); - Dictionary::Ptr vars = CompatUtility::GetCustomAttributeConfig(custom_var_object); + Dictionary::Ptr vars = custom_var_object->GetVars(); if (vars) { ObjectLock olock (vars); @@ -274,7 +274,7 @@ void DbObject::SendVarsStatusUpdate() if (!custom_var_object) return; - Dictionary::Ptr vars = CompatUtility::GetCustomAttributeConfig(custom_var_object); + Dictionary::Ptr vars = custom_var_object->GetVars(); if (vars) { std::vector queries; diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 3ab26a187..ba7d566ea 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -233,17 +233,6 @@ int CompatUtility::GetCheckableInNotificationPeriod(const Checkable::Ptr& checka return 0; } -/* vars attr */ -Dictionary::Ptr CompatUtility::GetCustomAttributeConfig(const CustomVarObject::Ptr& object) -{ - Dictionary::Ptr vars = object->GetVars(); - - if (!vars) - return nullptr; - - return vars; -} - /* notifications */ int CompatUtility::GetCheckableNotificationLastNotification(const Checkable::Ptr& checkable) { diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index e5c6af536..25f827fec 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -78,9 +78,6 @@ public: static std::set GetCheckableNotificationUsers(const Checkable::Ptr& checkable); static std::set GetCheckableNotificationUserGroups(const Checkable::Ptr& checkable); - /* custom attribute */ - static Dictionary::Ptr GetCustomAttributeConfig(const CustomVarObject::Ptr& object); - /* check result */ static String GetCheckResultOutput(const CheckResult::Ptr& cr); static String GetCheckResultLongOutput(const CheckResult::Ptr& cr); diff --git a/lib/livestatus/commandstable.cpp b/lib/livestatus/commandstable.cpp index 6526486b1..8aa5f0998 100644 --- a/lib/livestatus/commandstable.cpp +++ b/lib/livestatus/commandstable.cpp @@ -103,7 +103,7 @@ Value CommandsTable::CustomVariableNamesAccessor(const Value& row) { ObjectLock olock(command); - vars = CompatUtility::GetCustomAttributeConfig(command); + vars = command->GetVars(); } Array::Ptr cv = new Array(); @@ -132,7 +132,7 @@ Value CommandsTable::CustomVariableValuesAccessor(const Value& row) { ObjectLock olock(command); - vars = CompatUtility::GetCustomAttributeConfig(command); + vars = command->GetVars(); } Array::Ptr cv = new Array(); @@ -161,7 +161,7 @@ Value CommandsTable::CustomVariablesAccessor(const Value& row) { ObjectLock olock(command); - vars = CompatUtility::GetCustomAttributeConfig(command); + vars = command->GetVars(); } Array::Ptr cv = new Array(); diff --git a/lib/livestatus/contactstable.cpp b/lib/livestatus/contactstable.cpp index fe725bc3c..54a613adc 100644 --- a/lib/livestatus/contactstable.cpp +++ b/lib/livestatus/contactstable.cpp @@ -207,7 +207,7 @@ Value ContactsTable::CustomVariableNamesAccessor(const Value& row) { ObjectLock olock(user); - vars = CompatUtility::GetCustomAttributeConfig(user); + vars = user->GetVars(); } Array::Ptr cv = new Array(); @@ -234,7 +234,7 @@ Value ContactsTable::CustomVariableValuesAccessor(const Value& row) { ObjectLock olock(user); - vars = CompatUtility::GetCustomAttributeConfig(user); + vars = user->GetVars(); } Array::Ptr cv = new Array(); @@ -264,7 +264,7 @@ Value ContactsTable::CustomVariablesAccessor(const Value& row) { ObjectLock olock(user); - vars = CompatUtility::GetCustomAttributeConfig(user); + vars = user->GetVars(); } Array::Ptr cv = new Array(); @@ -299,7 +299,7 @@ Value ContactsTable::CVIsJsonAccessor(const Value& row) { ObjectLock olock(user); - vars = CompatUtility::GetCustomAttributeConfig(user); + vars = user->GetVars(); } if (!vars) diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index 6c0157f1b..5cbaf986c 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -1021,7 +1021,7 @@ Value HostsTable::CustomVariableNamesAccessor(const Value& row) { ObjectLock olock(host); - vars = CompatUtility::GetCustomAttributeConfig(host); + vars = host->GetVars(); } Array::Ptr cv = new Array(); @@ -1048,7 +1048,7 @@ Value HostsTable::CustomVariableValuesAccessor(const Value& row) { ObjectLock olock(host); - vars = CompatUtility::GetCustomAttributeConfig(host); + vars = host->GetVars(); } Array::Ptr cv = new Array(); @@ -1078,7 +1078,7 @@ Value HostsTable::CustomVariablesAccessor(const Value& row) { ObjectLock olock(host); - vars = CompatUtility::GetCustomAttributeConfig(host); + vars = host->GetVars(); } Array::Ptr cv = new Array(); @@ -1113,7 +1113,7 @@ Value HostsTable::CVIsJsonAccessor(const Value& row) { ObjectLock olock(host); - vars = CompatUtility::GetCustomAttributeConfig(host); + vars = host->GetVars(); } if (!vars) diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index d88c3a906..492317328 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -1043,7 +1043,7 @@ Value ServicesTable::CustomVariableNamesAccessor(const Value& row) { ObjectLock olock(service); - vars = CompatUtility::GetCustomAttributeConfig(service); + vars = service->GetVars(); } Array::Ptr cv = new Array(); @@ -1070,7 +1070,7 @@ Value ServicesTable::CustomVariableValuesAccessor(const Value& row) { ObjectLock olock(service); - vars = CompatUtility::GetCustomAttributeConfig(service); + vars = service->GetVars(); } Array::Ptr cv = new Array(); @@ -1100,7 +1100,7 @@ Value ServicesTable::CustomVariablesAccessor(const Value& row) { ObjectLock olock(service); - vars = CompatUtility::GetCustomAttributeConfig(service); + vars = service->GetVars(); } Array::Ptr cv = new Array(); @@ -1135,7 +1135,7 @@ Value ServicesTable::CVIsJsonAccessor(const Value& row) { ObjectLock olock(service); - vars = CompatUtility::GetCustomAttributeConfig(service); + vars = service->GetVars(); } if (!vars) From 2478c4d0535508ff03f420675972d17c0578f555 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 6 Dec 2017 16:18:26 +0100 Subject: [PATCH 13/33] Move ConvertTimestamp functionality into DB IDO This is the only place where the timestamp is split into sec and usec. --- lib/db_ido/dbevents.cpp | 49 ++++++++++++++++++------------------ lib/db_ido/dbevents.hpp | 2 ++ lib/icinga/compatutility.cpp | 8 ------ lib/icinga/compatutility.hpp | 2 -- 4 files changed, 26 insertions(+), 35 deletions(-) diff --git a/lib/db_ido/dbevents.cpp b/lib/db_ido/dbevents.cpp index 24ffd0ce1..4620803f3 100644 --- a/lib/db_ido/dbevents.cpp +++ b/lib/db_ido/dbevents.cpp @@ -155,9 +155,8 @@ void DbEvents::FlappingChangedHandler(const Checkable::Ptr& checkable) void DbEvents::LastNotificationChangedHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable) { - double now = Utility::GetTime(); - std::pair now_bag = CompatUtility::ConvertTimestamp(now); - std::pair time_bag = CompatUtility::ConvertTimestamp(notification->GetNextNotification()); + std::pair now_bag = ConvertTimestamp(Utility::GetTime()); + std::pair time_bag = ConvertTimestamp(notification->GetNextNotification()); Host::Ptr host; Service::Ptr service; @@ -411,8 +410,7 @@ void DbEvents::RemoveCommentInternal(std::vector& queries, const Commen queries.emplace_back(std::move(query1)); /* History - update deletion time for service/host */ - double now = Utility::GetTime(); - std::pair time_bag = CompatUtility::ConvertTimestamp(now); + std::pair time_bag = ConvertTimestamp(Utility::GetTime()); DbQuery query2; query2.Table = "commenthistory"; @@ -490,7 +488,7 @@ void DbEvents::AddDowntimeInternal(std::vector& queries, const Downtime /* flexible downtimes are started at trigger time */ if (downtime->GetFixed()) { - std::pair time_bag = CompatUtility::ConvertTimestamp(downtime->GetStartTime()); + std::pair time_bag = ConvertTimestamp(downtime->GetStartTime()); fields1->Set("actual_start_time", DbValue::FromTimestamp(time_bag.first)); fields1->Set("actual_start_time_usec", time_bag.second); fields1->Set("was_started", ((downtime->GetStartTime() <= Utility::GetTime()) ? 1 : 0)); @@ -587,8 +585,7 @@ void DbEvents::RemoveDowntimeInternal(std::vector& queries, const Downt queries.emplace_back(std::move(query1)); /* History - update actual_end_time, was_cancelled for service (and host in case) */ - double now = Utility::GetTime(); - std::pair time_bag = CompatUtility::ConvertTimestamp(now); + std::pair time_bag = ConvertTimestamp(Utility::GetTime()); DbQuery query3; query3.Table = "downtimehistory"; @@ -650,8 +647,7 @@ void DbEvents::TriggerDowntime(const Downtime::Ptr& downtime) { Checkable::Ptr checkable = downtime->GetCheckable(); - double now = Utility::GetTime(); - std::pair time_bag = CompatUtility::ConvertTimestamp(now); + std::pair time_bag = ConvertTimestamp(Utility::GetTime()); /* Status */ DbQuery query1; @@ -735,8 +731,7 @@ void DbEvents::AddAcknowledgementHistory(const Checkable::Ptr& checkable, const Log(LogDebug, "DbEvents") << "add acknowledgement history for '" << checkable->GetName() << "'"; - double now = Utility::GetTime(); - std::pair time_bag = CompatUtility::ConvertTimestamp(now); + std::pair time_bag = ConvertTimestamp(Utility::GetTime()); unsigned long end_time = static_cast(expiry); @@ -835,8 +830,7 @@ void DbEvents::AddNotificationHistory(const Notification::Ptr& notification, con << "add notification history for '" << checkable->GetName() << "'"; /* start and end happen at the same time */ - double now = Utility::GetTime(); - std::pair time_bag = CompatUtility::ConvertTimestamp(now); + std::pair time_bag = ConvertTimestamp(Utility::GetTime()); DbQuery query1; query1.Table = "notifications"; @@ -916,7 +910,7 @@ void DbEvents::AddStateChangeHistory(const Checkable::Ptr& checkable, const Chec << "add state change history for '" << checkable->GetName() << "'"; double ts = cr->GetExecutionEnd(); - std::pair state_time_bag = CompatUtility::ConvertTimestamp(ts); + std::pair state_time_bag = ConvertTimestamp(ts); DbQuery query1; query1.Table = "statehistory"; @@ -1252,8 +1246,7 @@ void DbEvents::AddLogHistory(const Checkable::Ptr& checkable, const String& buff Log(LogDebug, "DbEvents") << "add log entry history for '" << checkable->GetName() << "'"; - double now = Utility::GetTime(); - std::pair time_bag = CompatUtility::ConvertTimestamp(now); + std::pair time_bag = ConvertTimestamp(Utility::GetTime()); DbQuery query1; query1.Table = "logentries"; @@ -1286,8 +1279,7 @@ void DbEvents::AddFlappingChangedHistory(const Checkable::Ptr& checkable) Log(LogDebug, "DbEvents") << "add flapping history for '" << checkable->GetName() << "'"; - double now = Utility::GetTime(); - std::pair time_bag = CompatUtility::ConvertTimestamp(now); + std::pair time_bag = ConvertTimestamp(Utility::GetTime()); DbQuery query1; query1.Table = "flappinghistory"; @@ -1333,8 +1325,7 @@ void DbEvents::AddEnableFlappingChangedHistory(const Checkable::Ptr& checkable) Log(LogDebug, "DbEvents") << "add flapping history for '" << checkable->GetName() << "'"; - double now = Utility::GetTime(); - std::pair time_bag = CompatUtility::ConvertTimestamp(now); + std::pair time_bag = ConvertTimestamp(Utility::GetTime()); DbQuery query1; query1.Table = "flappinghistory"; @@ -1401,10 +1392,10 @@ void DbEvents::AddCheckableCheckHistory(const Checkable::Ptr& checkable, const C fields1->Set("state_type", checkable->GetStateType()); double start = cr->GetExecutionStart(); - std::pair time_bag_start = CompatUtility::ConvertTimestamp(start); + std::pair time_bag_start = ConvertTimestamp(start); double end = cr->GetExecutionEnd(); - std::pair time_bag_end = CompatUtility::ConvertTimestamp(end); + std::pair time_bag_end = ConvertTimestamp(end); double execution_time = cr->CalculateExecutionTime(); @@ -1448,8 +1439,7 @@ void DbEvents::AddEventHandlerHistory(const Checkable::Ptr& checkable) Log(LogDebug, "DbEvents") << "add eventhandler history for '" << checkable->GetName() << "'"; - double now = Utility::GetTime(); - std::pair time_bag = CompatUtility::ConvertTimestamp(now); + std::pair time_bag = ConvertTimestamp(Utility::GetTime()); DbQuery query1; query1.Table = "eventhandlers"; @@ -1520,3 +1510,12 @@ void DbEvents::AddExternalCommandHistory(double time, const String& command, con query1.Fields = fields1; DbObject::OnQuery(query1); } + +std::pair DbEvents::ConvertTimestamp(double time) +{ + unsigned long time_sec = static_cast(time); + unsigned long time_usec = (time - time_sec) * 1000 * 1000; + + return std::make_pair(time_sec, time_usec); +} + diff --git a/lib/db_ido/dbevents.hpp b/lib/db_ido/dbevents.hpp index db52ccf1b..52523ba47 100644 --- a/lib/db_ido/dbevents.hpp +++ b/lib/db_ido/dbevents.hpp @@ -132,6 +132,8 @@ private: static void AddDowntimeInternal(std::vector& queries, const Downtime::Ptr& downtime, bool historical); static void RemoveDowntimeInternal(std::vector& queries, const Downtime::Ptr& downtime); static void EnableChangedHandlerInternal(const Checkable::Ptr& checkable, const String& fieldName, bool enabled); + + static std::pair ConvertTimestamp(double time); }; } diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index ba7d566ea..12cd063c0 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -507,14 +507,6 @@ String CompatUtility::UnEscapeString(const String& str) return result; } -std::pair CompatUtility::ConvertTimestamp(double time) -{ - unsigned long time_sec = static_cast(time); - unsigned long time_usec = (time - time_sec) * 1000 * 1000; - - return std::make_pair(time_sec, time_usec); -} - int CompatUtility::MapNotificationReasonType(NotificationType type) { switch (type) { diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 25f827fec..bc4226392 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -84,8 +84,6 @@ public: static String GetCheckResultPerfdata(const CheckResult::Ptr& cr); /* misc */ - static std::pair ConvertTimestamp(double time); - static int MapNotificationReasonType(NotificationType type); static int MapExternalCommandType(const String& name); From 906c1accaaaaa0a06072833fadd15b63bd40bee0 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 6 Dec 2017 16:39:22 +0100 Subject: [PATCH 14/33] Move more compatibility mappings into DB IDO --- lib/db_ido/dbevents.cpp | 385 ++++++++++++++++++++++++++++++++++- lib/db_ido/dbevents.hpp | 2 + lib/icinga/compatutility.cpp | 382 ---------------------------------- lib/icinga/compatutility.hpp | 3 - 4 files changed, 385 insertions(+), 387 deletions(-) diff --git a/lib/db_ido/dbevents.cpp b/lib/db_ido/dbevents.cpp index 4620803f3..9663a9a77 100644 --- a/lib/db_ido/dbevents.cpp +++ b/lib/db_ido/dbevents.cpp @@ -844,7 +844,7 @@ void DbEvents::AddNotificationHistory(const Notification::Ptr& notification, con Dictionary::Ptr fields1 = new Dictionary(); fields1->Set("notification_type", 1); /* service */ - fields1->Set("notification_reason", CompatUtility::MapNotificationReasonType(type)); + fields1->Set("notification_reason", MapNotificationReasonType(type)); fields1->Set("object_id", checkable); fields1->Set("start_time", DbValue::FromTimestamp(time_bag.first)); fields1->Set("start_time_usec", time_bag.second); @@ -1495,7 +1495,7 @@ void DbEvents::AddExternalCommandHistory(double time, const String& command, con Dictionary::Ptr fields1 = new Dictionary(); fields1->Set("entry_time", DbValue::FromTimestamp(static_cast(time))); - fields1->Set("command_type", CompatUtility::MapExternalCommandType(command)); + fields1->Set("command_type", MapExternalCommandType(command)); fields1->Set("command_name", command); fields1->Set("command_args", boost::algorithm::join(arguments, ";")); @@ -1519,3 +1519,384 @@ std::pair DbEvents::ConvertTimestamp(double time) return std::make_pair(time_sec, time_usec); } +int DbEvents::MapNotificationReasonType(NotificationType type) +{ + switch (type) { + case NotificationDowntimeStart: + return 5; + case NotificationDowntimeEnd: + return 6; + case NotificationDowntimeRemoved: + return 7; + case NotificationCustom: + return 8; + case NotificationAcknowledgement: + return 1; + case NotificationProblem: + return 0; + case NotificationRecovery: + return 0; + case NotificationFlappingStart: + return 2; + case NotificationFlappingEnd: + return 3; + default: + return 0; + } +} + +int DbEvents::MapExternalCommandType(const String& name) +{ + if (name == "NONE") + return 0; + if (name == "ADD_HOST_COMMENT") + return 1; + if (name == "DEL_HOST_COMMENT") + return 2; + if (name == "ADD_SVC_COMMENT") + return 3; + if (name == "DEL_SVC_COMMENT") + return 4; + if (name == "ENABLE_SVC_CHECK") + return 5; + if (name == "DISABLE_SVC_CHECK") + return 6; + if (name == "SCHEDULE_SVC_CHECK") + return 7; + if (name == "DELAY_SVC_NOTIFICATION") + return 9; + if (name == "DELAY_HOST_NOTIFICATION") + return 10; + if (name == "DISABLE_NOTIFICATIONS") + return 11; + if (name == "ENABLE_NOTIFICATIONS") + return 12; + if (name == "RESTART_PROCESS") + return 13; + if (name == "SHUTDOWN_PROCESS") + return 14; + if (name == "ENABLE_HOST_SVC_CHECKS") + return 15; + if (name == "DISABLE_HOST_SVC_CHECKS") + return 16; + if (name == "SCHEDULE_HOST_SVC_CHECKS") + return 17; + if (name == "DELAY_HOST_SVC_NOTIFICATIONS") + return 19; + if (name == "DEL_ALL_HOST_COMMENTS") + return 20; + if (name == "DEL_ALL_SVC_COMMENTS") + return 21; + if (name == "ENABLE_SVC_NOTIFICATIONS") + return 22; + if (name == "DISABLE_SVC_NOTIFICATIONS") + return 23; + if (name == "ENABLE_HOST_NOTIFICATIONS") + return 24; + if (name == "DISABLE_HOST_NOTIFICATIONS") + return 25; + if (name == "ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST") + return 26; + if (name == "DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST") + return 27; + if (name == "ENABLE_HOST_SVC_NOTIFICATIONS") + return 28; + if (name == "DISABLE_HOST_SVC_NOTIFICATIONS") + return 29; + if (name == "PROCESS_SERVICE_CHECK_RESULT") + return 30; + if (name == "SAVE_STATE_INFORMATION") + return 31; + if (name == "READ_STATE_INFORMATION") + return 32; + if (name == "ACKNOWLEDGE_HOST_PROBLEM") + return 33; + if (name == "ACKNOWLEDGE_SVC_PROBLEM") + return 34; + if (name == "START_EXECUTING_SVC_CHECKS") + return 35; + if (name == "STOP_EXECUTING_SVC_CHECKS") + return 36; + if (name == "START_ACCEPTING_PASSIVE_SVC_CHECKS") + return 37; + if (name == "STOP_ACCEPTING_PASSIVE_SVC_CHECKS") + return 38; + if (name == "ENABLE_PASSIVE_SVC_CHECKS") + return 39; + if (name == "DISABLE_PASSIVE_SVC_CHECKS") + return 40; + if (name == "ENABLE_EVENT_HANDLERS") + return 41; + if (name == "DISABLE_EVENT_HANDLERS") + return 42; + if (name == "ENABLE_HOST_EVENT_HANDLER") + return 43; + if (name == "DISABLE_HOST_EVENT_HANDLER") + return 44; + if (name == "ENABLE_SVC_EVENT_HANDLER") + return 45; + if (name == "DISABLE_SVC_EVENT_HANDLER") + return 46; + if (name == "ENABLE_HOST_CHECK") + return 47; + if (name == "DISABLE_HOST_CHECK") + return 48; + if (name == "START_OBSESSING_OVER_SVC_CHECKS") + return 49; + if (name == "STOP_OBSESSING_OVER_SVC_CHECKS") + return 50; + if (name == "REMOVE_HOST_ACKNOWLEDGEMENT") + return 51; + if (name == "REMOVE_SVC_ACKNOWLEDGEMENT") + return 52; + if (name == "SCHEDULE_FORCED_HOST_SVC_CHECKS") + return 53; + if (name == "SCHEDULE_FORCED_SVC_CHECK") + return 54; + if (name == "SCHEDULE_HOST_DOWNTIME") + return 55; + if (name == "SCHEDULE_SVC_DOWNTIME") + return 56; + if (name == "ENABLE_HOST_FLAP_DETECTION") + return 57; + if (name == "DISABLE_HOST_FLAP_DETECTION") + return 58; + if (name == "ENABLE_SVC_FLAP_DETECTION") + return 59; + if (name == "DISABLE_SVC_FLAP_DETECTION") + return 60; + if (name == "ENABLE_FLAP_DETECTION") + return 61; + if (name == "DISABLE_FLAP_DETECTION") + return 62; + if (name == "ENABLE_HOSTGROUP_SVC_NOTIFICATIONS") + return 63; + if (name == "DISABLE_HOSTGROUP_SVC_NOTIFICATIONS") + return 64; + if (name == "ENABLE_HOSTGROUP_HOST_NOTIFICATIONS") + return 65; + if (name == "DISABLE_HOSTGROUP_HOST_NOTIFICATIONS") + return 66; + if (name == "ENABLE_HOSTGROUP_SVC_CHECKS") + return 67; + if (name == "DISABLE_HOSTGROUP_SVC_CHECKS") + return 68; + if (name == "CANCEL_HOST_DOWNTIME") + return 69; + if (name == "CANCEL_SVC_DOWNTIME") + return 70; + if (name == "CANCEL_ACTIVE_HOST_DOWNTIME") + return 71; + if (name == "CANCEL_PENDING_HOST_DOWNTIME") + return 72; + if (name == "CANCEL_ACTIVE_SVC_DOWNTIME") + return 73; + if (name == "CANCEL_PENDING_SVC_DOWNTIME") + return 74; + if (name == "CANCEL_ACTIVE_HOST_SVC_DOWNTIME") + return 75; + if (name == "CANCEL_PENDING_HOST_SVC_DOWNTIME") + return 76; + if (name == "FLUSH_PENDING_COMMANDS") + return 77; + if (name == "DEL_HOST_DOWNTIME") + return 78; + if (name == "DEL_SVC_DOWNTIME") + return 79; + if (name == "ENABLE_FAILURE_PREDICTION") + return 80; + if (name == "DISABLE_FAILURE_PREDICTION") + return 81; + if (name == "ENABLE_PERFORMANCE_DATA") + return 82; + if (name == "DISABLE_PERFORMANCE_DATA") + return 83; + if (name == "SCHEDULE_HOSTGROUP_HOST_DOWNTIME") + return 84; + if (name == "SCHEDULE_HOSTGROUP_SVC_DOWNTIME") + return 85; + if (name == "SCHEDULE_HOST_SVC_DOWNTIME") + return 86; + if (name == "PROCESS_HOST_CHECK_RESULT") + return 87; + if (name == "START_EXECUTING_HOST_CHECKS") + return 88; + if (name == "STOP_EXECUTING_HOST_CHECKS") + return 89; + if (name == "START_ACCEPTING_PASSIVE_HOST_CHECKS") + return 90; + if (name == "STOP_ACCEPTING_PASSIVE_HOST_CHECKS") + return 91; + if (name == "ENABLE_PASSIVE_HOST_CHECKS") + return 92; + if (name == "DISABLE_PASSIVE_HOST_CHECKS") + return 93; + if (name == "START_OBSESSING_OVER_HOST_CHECKS") + return 94; + if (name == "STOP_OBSESSING_OVER_HOST_CHECKS") + return 95; + if (name == "SCHEDULE_HOST_CHECK") + return 96; + if (name == "SCHEDULE_FORCED_HOST_CHECK") + return 98; + if (name == "START_OBSESSING_OVER_SVC") + return 99; + if (name == "STOP_OBSESSING_OVER_SVC") + return 100; + if (name == "START_OBSESSING_OVER_HOST") + return 101; + if (name == "STOP_OBSESSING_OVER_HOST") + return 102; + if (name == "ENABLE_HOSTGROUP_HOST_CHECKS") + return 103; + if (name == "DISABLE_HOSTGROUP_HOST_CHECKS") + return 104; + if (name == "ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS") + return 105; + if (name == "DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS") + return 106; + if (name == "ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS") + return 107; + if (name == "DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS") + return 108; + if (name == "ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS") + return 109; + if (name == "DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS") + return 110; + if (name == "ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS") + return 111; + if (name == "DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS") + return 112; + if (name == "ENABLE_SERVICEGROUP_SVC_CHECKS") + return 113; + if (name == "DISABLE_SERVICEGROUP_SVC_CHECKS") + return 114; + if (name == "ENABLE_SERVICEGROUP_HOST_CHECKS") + return 115; + if (name == "DISABLE_SERVICEGROUP_HOST_CHECKS") + return 116; + if (name == "ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS") + return 117; + if (name == "DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS") + return 118; + if (name == "ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS") + return 119; + if (name == "DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS") + return 120; + if (name == "SCHEDULE_SERVICEGROUP_HOST_DOWNTIME") + return 121; + if (name == "SCHEDULE_SERVICEGROUP_SVC_DOWNTIME") + return 122; + if (name == "CHANGE_GLOBAL_HOST_EVENT_HANDLER") + return 123; + if (name == "CHANGE_GLOBAL_SVC_EVENT_HANDLER") + return 124; + if (name == "CHANGE_HOST_EVENT_HANDLER") + return 125; + if (name == "CHANGE_SVC_EVENT_HANDLER") + return 126; + if (name == "CHANGE_HOST_CHECK_COMMAND") + return 127; + if (name == "CHANGE_SVC_CHECK_COMMAND") + return 128; + if (name == "CHANGE_NORMAL_HOST_CHECK_INTERVAL") + return 129; + if (name == "CHANGE_NORMAL_SVC_CHECK_INTERVAL") + return 130; + if (name == "CHANGE_RETRY_SVC_CHECK_INTERVAL") + return 131; + if (name == "CHANGE_MAX_HOST_CHECK_ATTEMPTS") + return 132; + if (name == "CHANGE_MAX_SVC_CHECK_ATTEMPTS") + return 133; + if (name == "SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME") + return 134; + if (name == "ENABLE_HOST_AND_CHILD_NOTIFICATIONS") + return 135; + if (name == "DISABLE_HOST_AND_CHILD_NOTIFICATIONS") + return 136; + if (name == "SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME") + return 137; + if (name == "ENABLE_SERVICE_FRESHNESS_CHECKS") + return 138; + if (name == "DISABLE_SERVICE_FRESHNESS_CHECKS") + return 139; + if (name == "ENABLE_HOST_FRESHNESS_CHECKS") + return 140; + if (name == "DISABLE_HOST_FRESHNESS_CHECKS") + return 141; + if (name == "SET_HOST_NOTIFICATION_NUMBER") + return 142; + if (name == "SET_SVC_NOTIFICATION_NUMBER") + return 143; + if (name == "CHANGE_HOST_CHECK_TIMEPERIOD") + return 144; + if (name == "CHANGE_SVC_CHECK_TIMEPERIOD") + return 145; + if (name == "PROCESS_FILE") + return 146; + if (name == "CHANGE_CUSTOM_HOST_VAR") + return 147; + if (name == "CHANGE_CUSTOM_SVC_VAR") + return 148; + if (name == "CHANGE_CUSTOM_CONTACT_VAR") + return 149; + if (name == "ENABLE_CONTACT_HOST_NOTIFICATIONS") + return 150; + if (name == "DISABLE_CONTACT_HOST_NOTIFICATIONS") + return 151; + if (name == "ENABLE_CONTACT_SVC_NOTIFICATIONS") + return 152; + if (name == "DISABLE_CONTACT_SVC_NOTIFICATIONS") + return 153; + if (name == "ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS") + return 154; + if (name == "DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS") + return 155; + if (name == "ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS") + return 156; + if (name == "DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS") + return 157; + if (name == "CHANGE_RETRY_HOST_CHECK_INTERVAL") + return 158; + if (name == "SEND_CUSTOM_HOST_NOTIFICATION") + return 159; + if (name == "SEND_CUSTOM_SVC_NOTIFICATION") + return 160; + if (name == "CHANGE_HOST_NOTIFICATION_TIMEPERIOD") + return 161; + if (name == "CHANGE_SVC_NOTIFICATION_TIMEPERIOD") + return 162; + if (name == "CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD") + return 163; + if (name == "CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD") + return 164; + if (name == "CHANGE_HOST_MODATTR") + return 165; + if (name == "CHANGE_SVC_MODATTR") + return 166; + if (name == "CHANGE_CONTACT_MODATTR") + return 167; + if (name == "CHANGE_CONTACT_MODHATTR") + return 168; + if (name == "CHANGE_CONTACT_MODSATTR") + return 169; + if (name == "SYNC_STATE_INFORMATION") + return 170; + if (name == "DEL_DOWNTIME_BY_HOST_NAME") + return 171; + if (name == "DEL_DOWNTIME_BY_HOSTGROUP_NAME") + return 172; + if (name == "DEL_DOWNTIME_BY_START_TIME_COMMENT") + return 173; + if (name == "ACKNOWLEDGE_HOST_PROBLEM_EXPIRE") + return 174; + if (name == "ACKNOWLEDGE_SVC_PROBLEM_EXPIRE") + return 175; + if (name == "DISABLE_NOTIFICATIONS_EXPIRE_TIME") + return 176; + if (name == "CUSTOM_COMMAND") + return 999; + + return 0; +} diff --git a/lib/db_ido/dbevents.hpp b/lib/db_ido/dbevents.hpp index 52523ba47..cfc33b25f 100644 --- a/lib/db_ido/dbevents.hpp +++ b/lib/db_ido/dbevents.hpp @@ -134,6 +134,8 @@ private: static void EnableChangedHandlerInternal(const Checkable::Ptr& checkable, const String& fieldName, bool enabled); static std::pair ConvertTimestamp(double time); + static int MapNotificationReasonType(NotificationType type); + static int MapExternalCommandType(const String& name); }; } diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 12cd063c0..5d83a52bf 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -506,385 +506,3 @@ String CompatUtility::UnEscapeString(const String& str) boost::algorithm::replace_all(result, "\\n", "\n"); return result; } - -int CompatUtility::MapNotificationReasonType(NotificationType type) -{ - switch (type) { - case NotificationDowntimeStart: - return 5; - case NotificationDowntimeEnd: - return 6; - case NotificationDowntimeRemoved: - return 7; - case NotificationCustom: - return 8; - case NotificationAcknowledgement: - return 1; - case NotificationProblem: - return 0; - case NotificationRecovery: - return 0; - case NotificationFlappingStart: - return 2; - case NotificationFlappingEnd: - return 3; - default: - return 0; - } -} - -int CompatUtility::MapExternalCommandType(const String& name) -{ - if (name == "NONE") - return 0; - if (name == "ADD_HOST_COMMENT") - return 1; - if (name == "DEL_HOST_COMMENT") - return 2; - if (name == "ADD_SVC_COMMENT") - return 3; - if (name == "DEL_SVC_COMMENT") - return 4; - if (name == "ENABLE_SVC_CHECK") - return 5; - if (name == "DISABLE_SVC_CHECK") - return 6; - if (name == "SCHEDULE_SVC_CHECK") - return 7; - if (name == "DELAY_SVC_NOTIFICATION") - return 9; - if (name == "DELAY_HOST_NOTIFICATION") - return 10; - if (name == "DISABLE_NOTIFICATIONS") - return 11; - if (name == "ENABLE_NOTIFICATIONS") - return 12; - if (name == "RESTART_PROCESS") - return 13; - if (name == "SHUTDOWN_PROCESS") - return 14; - if (name == "ENABLE_HOST_SVC_CHECKS") - return 15; - if (name == "DISABLE_HOST_SVC_CHECKS") - return 16; - if (name == "SCHEDULE_HOST_SVC_CHECKS") - return 17; - if (name == "DELAY_HOST_SVC_NOTIFICATIONS") - return 19; - if (name == "DEL_ALL_HOST_COMMENTS") - return 20; - if (name == "DEL_ALL_SVC_COMMENTS") - return 21; - if (name == "ENABLE_SVC_NOTIFICATIONS") - return 22; - if (name == "DISABLE_SVC_NOTIFICATIONS") - return 23; - if (name == "ENABLE_HOST_NOTIFICATIONS") - return 24; - if (name == "DISABLE_HOST_NOTIFICATIONS") - return 25; - if (name == "ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST") - return 26; - if (name == "DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST") - return 27; - if (name == "ENABLE_HOST_SVC_NOTIFICATIONS") - return 28; - if (name == "DISABLE_HOST_SVC_NOTIFICATIONS") - return 29; - if (name == "PROCESS_SERVICE_CHECK_RESULT") - return 30; - if (name == "SAVE_STATE_INFORMATION") - return 31; - if (name == "READ_STATE_INFORMATION") - return 32; - if (name == "ACKNOWLEDGE_HOST_PROBLEM") - return 33; - if (name == "ACKNOWLEDGE_SVC_PROBLEM") - return 34; - if (name == "START_EXECUTING_SVC_CHECKS") - return 35; - if (name == "STOP_EXECUTING_SVC_CHECKS") - return 36; - if (name == "START_ACCEPTING_PASSIVE_SVC_CHECKS") - return 37; - if (name == "STOP_ACCEPTING_PASSIVE_SVC_CHECKS") - return 38; - if (name == "ENABLE_PASSIVE_SVC_CHECKS") - return 39; - if (name == "DISABLE_PASSIVE_SVC_CHECKS") - return 40; - if (name == "ENABLE_EVENT_HANDLERS") - return 41; - if (name == "DISABLE_EVENT_HANDLERS") - return 42; - if (name == "ENABLE_HOST_EVENT_HANDLER") - return 43; - if (name == "DISABLE_HOST_EVENT_HANDLER") - return 44; - if (name == "ENABLE_SVC_EVENT_HANDLER") - return 45; - if (name == "DISABLE_SVC_EVENT_HANDLER") - return 46; - if (name == "ENABLE_HOST_CHECK") - return 47; - if (name == "DISABLE_HOST_CHECK") - return 48; - if (name == "START_OBSESSING_OVER_SVC_CHECKS") - return 49; - if (name == "STOP_OBSESSING_OVER_SVC_CHECKS") - return 50; - if (name == "REMOVE_HOST_ACKNOWLEDGEMENT") - return 51; - if (name == "REMOVE_SVC_ACKNOWLEDGEMENT") - return 52; - if (name == "SCHEDULE_FORCED_HOST_SVC_CHECKS") - return 53; - if (name == "SCHEDULE_FORCED_SVC_CHECK") - return 54; - if (name == "SCHEDULE_HOST_DOWNTIME") - return 55; - if (name == "SCHEDULE_SVC_DOWNTIME") - return 56; - if (name == "ENABLE_HOST_FLAP_DETECTION") - return 57; - if (name == "DISABLE_HOST_FLAP_DETECTION") - return 58; - if (name == "ENABLE_SVC_FLAP_DETECTION") - return 59; - if (name == "DISABLE_SVC_FLAP_DETECTION") - return 60; - if (name == "ENABLE_FLAP_DETECTION") - return 61; - if (name == "DISABLE_FLAP_DETECTION") - return 62; - if (name == "ENABLE_HOSTGROUP_SVC_NOTIFICATIONS") - return 63; - if (name == "DISABLE_HOSTGROUP_SVC_NOTIFICATIONS") - return 64; - if (name == "ENABLE_HOSTGROUP_HOST_NOTIFICATIONS") - return 65; - if (name == "DISABLE_HOSTGROUP_HOST_NOTIFICATIONS") - return 66; - if (name == "ENABLE_HOSTGROUP_SVC_CHECKS") - return 67; - if (name == "DISABLE_HOSTGROUP_SVC_CHECKS") - return 68; - if (name == "CANCEL_HOST_DOWNTIME") - return 69; - if (name == "CANCEL_SVC_DOWNTIME") - return 70; - if (name == "CANCEL_ACTIVE_HOST_DOWNTIME") - return 71; - if (name == "CANCEL_PENDING_HOST_DOWNTIME") - return 72; - if (name == "CANCEL_ACTIVE_SVC_DOWNTIME") - return 73; - if (name == "CANCEL_PENDING_SVC_DOWNTIME") - return 74; - if (name == "CANCEL_ACTIVE_HOST_SVC_DOWNTIME") - return 75; - if (name == "CANCEL_PENDING_HOST_SVC_DOWNTIME") - return 76; - if (name == "FLUSH_PENDING_COMMANDS") - return 77; - if (name == "DEL_HOST_DOWNTIME") - return 78; - if (name == "DEL_SVC_DOWNTIME") - return 79; - if (name == "ENABLE_FAILURE_PREDICTION") - return 80; - if (name == "DISABLE_FAILURE_PREDICTION") - return 81; - if (name == "ENABLE_PERFORMANCE_DATA") - return 82; - if (name == "DISABLE_PERFORMANCE_DATA") - return 83; - if (name == "SCHEDULE_HOSTGROUP_HOST_DOWNTIME") - return 84; - if (name == "SCHEDULE_HOSTGROUP_SVC_DOWNTIME") - return 85; - if (name == "SCHEDULE_HOST_SVC_DOWNTIME") - return 86; - if (name == "PROCESS_HOST_CHECK_RESULT") - return 87; - if (name == "START_EXECUTING_HOST_CHECKS") - return 88; - if (name == "STOP_EXECUTING_HOST_CHECKS") - return 89; - if (name == "START_ACCEPTING_PASSIVE_HOST_CHECKS") - return 90; - if (name == "STOP_ACCEPTING_PASSIVE_HOST_CHECKS") - return 91; - if (name == "ENABLE_PASSIVE_HOST_CHECKS") - return 92; - if (name == "DISABLE_PASSIVE_HOST_CHECKS") - return 93; - if (name == "START_OBSESSING_OVER_HOST_CHECKS") - return 94; - if (name == "STOP_OBSESSING_OVER_HOST_CHECKS") - return 95; - if (name == "SCHEDULE_HOST_CHECK") - return 96; - if (name == "SCHEDULE_FORCED_HOST_CHECK") - return 98; - if (name == "START_OBSESSING_OVER_SVC") - return 99; - if (name == "STOP_OBSESSING_OVER_SVC") - return 100; - if (name == "START_OBSESSING_OVER_HOST") - return 101; - if (name == "STOP_OBSESSING_OVER_HOST") - return 102; - if (name == "ENABLE_HOSTGROUP_HOST_CHECKS") - return 103; - if (name == "DISABLE_HOSTGROUP_HOST_CHECKS") - return 104; - if (name == "ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS") - return 105; - if (name == "DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS") - return 106; - if (name == "ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS") - return 107; - if (name == "DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS") - return 108; - if (name == "ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS") - return 109; - if (name == "DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS") - return 110; - if (name == "ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS") - return 111; - if (name == "DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS") - return 112; - if (name == "ENABLE_SERVICEGROUP_SVC_CHECKS") - return 113; - if (name == "DISABLE_SERVICEGROUP_SVC_CHECKS") - return 114; - if (name == "ENABLE_SERVICEGROUP_HOST_CHECKS") - return 115; - if (name == "DISABLE_SERVICEGROUP_HOST_CHECKS") - return 116; - if (name == "ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS") - return 117; - if (name == "DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS") - return 118; - if (name == "ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS") - return 119; - if (name == "DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS") - return 120; - if (name == "SCHEDULE_SERVICEGROUP_HOST_DOWNTIME") - return 121; - if (name == "SCHEDULE_SERVICEGROUP_SVC_DOWNTIME") - return 122; - if (name == "CHANGE_GLOBAL_HOST_EVENT_HANDLER") - return 123; - if (name == "CHANGE_GLOBAL_SVC_EVENT_HANDLER") - return 124; - if (name == "CHANGE_HOST_EVENT_HANDLER") - return 125; - if (name == "CHANGE_SVC_EVENT_HANDLER") - return 126; - if (name == "CHANGE_HOST_CHECK_COMMAND") - return 127; - if (name == "CHANGE_SVC_CHECK_COMMAND") - return 128; - if (name == "CHANGE_NORMAL_HOST_CHECK_INTERVAL") - return 129; - if (name == "CHANGE_NORMAL_SVC_CHECK_INTERVAL") - return 130; - if (name == "CHANGE_RETRY_SVC_CHECK_INTERVAL") - return 131; - if (name == "CHANGE_MAX_HOST_CHECK_ATTEMPTS") - return 132; - if (name == "CHANGE_MAX_SVC_CHECK_ATTEMPTS") - return 133; - if (name == "SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME") - return 134; - if (name == "ENABLE_HOST_AND_CHILD_NOTIFICATIONS") - return 135; - if (name == "DISABLE_HOST_AND_CHILD_NOTIFICATIONS") - return 136; - if (name == "SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME") - return 137; - if (name == "ENABLE_SERVICE_FRESHNESS_CHECKS") - return 138; - if (name == "DISABLE_SERVICE_FRESHNESS_CHECKS") - return 139; - if (name == "ENABLE_HOST_FRESHNESS_CHECKS") - return 140; - if (name == "DISABLE_HOST_FRESHNESS_CHECKS") - return 141; - if (name == "SET_HOST_NOTIFICATION_NUMBER") - return 142; - if (name == "SET_SVC_NOTIFICATION_NUMBER") - return 143; - if (name == "CHANGE_HOST_CHECK_TIMEPERIOD") - return 144; - if (name == "CHANGE_SVC_CHECK_TIMEPERIOD") - return 145; - if (name == "PROCESS_FILE") - return 146; - if (name == "CHANGE_CUSTOM_HOST_VAR") - return 147; - if (name == "CHANGE_CUSTOM_SVC_VAR") - return 148; - if (name == "CHANGE_CUSTOM_CONTACT_VAR") - return 149; - if (name == "ENABLE_CONTACT_HOST_NOTIFICATIONS") - return 150; - if (name == "DISABLE_CONTACT_HOST_NOTIFICATIONS") - return 151; - if (name == "ENABLE_CONTACT_SVC_NOTIFICATIONS") - return 152; - if (name == "DISABLE_CONTACT_SVC_NOTIFICATIONS") - return 153; - if (name == "ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS") - return 154; - if (name == "DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS") - return 155; - if (name == "ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS") - return 156; - if (name == "DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS") - return 157; - if (name == "CHANGE_RETRY_HOST_CHECK_INTERVAL") - return 158; - if (name == "SEND_CUSTOM_HOST_NOTIFICATION") - return 159; - if (name == "SEND_CUSTOM_SVC_NOTIFICATION") - return 160; - if (name == "CHANGE_HOST_NOTIFICATION_TIMEPERIOD") - return 161; - if (name == "CHANGE_SVC_NOTIFICATION_TIMEPERIOD") - return 162; - if (name == "CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD") - return 163; - if (name == "CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD") - return 164; - if (name == "CHANGE_HOST_MODATTR") - return 165; - if (name == "CHANGE_SVC_MODATTR") - return 166; - if (name == "CHANGE_CONTACT_MODATTR") - return 167; - if (name == "CHANGE_CONTACT_MODHATTR") - return 168; - if (name == "CHANGE_CONTACT_MODSATTR") - return 169; - if (name == "SYNC_STATE_INFORMATION") - return 170; - if (name == "DEL_DOWNTIME_BY_HOST_NAME") - return 171; - if (name == "DEL_DOWNTIME_BY_HOSTGROUP_NAME") - return 172; - if (name == "DEL_DOWNTIME_BY_START_TIME_COMMENT") - return 173; - if (name == "ACKNOWLEDGE_HOST_PROBLEM_EXPIRE") - return 174; - if (name == "ACKNOWLEDGE_SVC_PROBLEM_EXPIRE") - return 175; - if (name == "DISABLE_NOTIFICATIONS_EXPIRE_TIME") - return 176; - if (name == "CUSTOM_COMMAND") - return 999; - - return 0; -} diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index bc4226392..601510b29 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -84,9 +84,6 @@ public: static String GetCheckResultPerfdata(const CheckResult::Ptr& cr); /* misc */ - static int MapNotificationReasonType(NotificationType type); - static int MapExternalCommandType(const String& name); - static String EscapeString(const String& str); static String UnEscapeString(const String& str); From 87b99c17b507848ee68a72fc019deca559b00792 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 6 Dec 2017 17:03:56 +0100 Subject: [PATCH 15/33] Drop CompatUtility::GetCheckResultPerfdata() --- lib/compat/statusdatawriter.cpp | 10 +++++----- lib/db_ido/dbevents.cpp | 3 ++- lib/db_ido/hostdbobject.cpp | 3 ++- lib/db_ido/servicedbobject.cpp | 3 ++- lib/icinga/compatutility.cpp | 8 -------- lib/icinga/compatutility.hpp | 1 - lib/livestatus/hoststable.cpp | 7 ++++--- lib/livestatus/servicestable.cpp | 7 ++++--- 8 files changed, 19 insertions(+), 23 deletions(-) diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index bbc559918..bbb5469ca 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -28,6 +28,7 @@ #include "icinga/timeperiod.hpp" #include "icinga/notificationcommand.hpp" #include "icinga/compatutility.hpp" +#include "icinga/pluginutility.hpp" #include "icinga/dependency.hpp" #include "base/configtype.hpp" #include "base/objectlock.hpp" @@ -366,13 +367,12 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl } 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(host->GetLastCheck()) << "\n"; if (cr) { - fp << "\t" << "check_source=" << cr->GetCheckSource() << "\n" - "\t" "last_check=" << static_cast(cr->GetScheduleEnd()) << "\n"; + fp << "\t" "plugin_output=" << CompatUtility::GetCheckResultOutput(cr) << "\n" + "\t" "long_plugin_output=" << CompatUtility::GetCheckResultLongOutput(cr) << "\n" + "\t" "performance_data=" << PluginUtility::FormatPerfdata(cr->GetPerformanceData()) << "\n" } fp << "\t" << "next_check=" << static_cast(checkable->GetNextCheck()) << "\n" diff --git a/lib/db_ido/dbevents.cpp b/lib/db_ido/dbevents.cpp index 9663a9a77..7c9598e87 100644 --- a/lib/db_ido/dbevents.cpp +++ b/lib/db_ido/dbevents.cpp @@ -32,6 +32,7 @@ #include "icinga/eventcommand.hpp" #include "icinga/externalcommandprocessor.hpp" #include "icinga/compatutility.hpp" +#include "icinga/pluginutility.hpp" #include "icinga/icingaapplication.hpp" #include @@ -1411,7 +1412,7 @@ void DbEvents::AddCheckableCheckHistory(const Checkable::Ptr& checkable, const C 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("perfdata", PluginUtility::FormatPerfdata(cr->GetPerformanceData())); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 0cdfbc520..c7eb4c89e 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -29,6 +29,7 @@ #include "icinga/checkcommand.hpp" #include "icinga/eventcommand.hpp" #include "icinga/compatutility.hpp" +#include "icinga/pluginutility.hpp" #include "base/convert.hpp" #include "base/objectlock.hpp" #include "base/logger.hpp" @@ -127,7 +128,7 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const if (cr) { fields->Set("output", CompatUtility::GetCheckResultOutput(cr)); fields->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr)); - fields->Set("perfdata", CompatUtility::GetCheckResultPerfdata(cr)); + fields->Set("perfdata", PluginUtility::FormatPerfdata(cr->GetPerformanceData())); fields->Set("check_source", cr->GetCheckSource()); } diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index ae9032a00..b39e600da 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -28,6 +28,7 @@ #include "icinga/eventcommand.hpp" #include "icinga/externalcommandprocessor.hpp" #include "icinga/compatutility.hpp" +#include "icinga/pluginutility.hpp" #include "icinga/icingaapplication.hpp" #include "remote/endpoint.hpp" #include "base/convert.hpp" @@ -114,7 +115,7 @@ Dictionary::Ptr ServiceDbObject::GetStatusFields() const if (cr) { fields->Set("output", CompatUtility::GetCheckResultOutput(cr)); fields->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr)); - fields->Set("perfdata", CompatUtility::GetCheckResultPerfdata(cr)); + fields->Set("perfdata", PluginUtility::FormatPerfdata(cr->GetPerformanceData())); fields->Set("check_source", cr->GetCheckSource()); } diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 5d83a52bf..154fcc4db 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -485,14 +485,6 @@ String CompatUtility::GetCheckResultLongOutput(const CheckResult::Ptr& cr) return Empty; } -String CompatUtility::GetCheckResultPerfdata(const CheckResult::Ptr& cr) -{ - if (!cr) - return String(); - - return PluginUtility::FormatPerfdata(cr->GetPerformanceData()); -} - String CompatUtility::EscapeString(const String& str) { String result = str; diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 601510b29..55a08d082 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -81,7 +81,6 @@ public: /* check result */ static String GetCheckResultOutput(const CheckResult::Ptr& cr); static String GetCheckResultLongOutput(const CheckResult::Ptr& cr); - static String GetCheckResultPerfdata(const CheckResult::Ptr& cr); /* misc */ static String EscapeString(const String& str); diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index 5cbaf986c..17ea108b4 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -29,6 +29,7 @@ #include "icinga/macroprocessor.hpp" #include "icinga/icingaapplication.hpp" #include "icinga/compatutility.hpp" +#include "icinga/pluginutility.hpp" #include "base/configtype.hpp" #include "base/objectlock.hpp" #include "base/json.hpp" @@ -407,10 +408,10 @@ Value HostsTable::PerfDataAccessor(const Value& row) String perfdata; CheckResult::Ptr cr = host->GetLastCheckResult(); - if (cr) - perfdata = CompatUtility::GetCheckResultPerfdata(cr); + if (!cr) + return Empty; - return perfdata; + return PluginUtility::FormatPerfdata(cr->GetPerformanceData()); } Value HostsTable::IconImageAccessor(const Value& row) diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index 492317328..1a7d3847d 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -31,6 +31,7 @@ #include "icinga/macroprocessor.hpp" #include "icinga/icingaapplication.hpp" #include "icinga/compatutility.hpp" +#include "icinga/pluginutility.hpp" #include "base/configtype.hpp" #include "base/objectlock.hpp" #include "base/json.hpp" @@ -342,10 +343,10 @@ Value ServicesTable::PerfDataAccessor(const Value& row) String perfdata; CheckResult::Ptr cr = service->GetLastCheckResult(); - if (cr) - perfdata = CompatUtility::GetCheckResultPerfdata(cr); + if (!cr) + return Empty; - return perfdata; + return PluginUtility::FormatPerfdata(cr->GetPerformanceData()); } Value ServicesTable::CheckPeriodAccessor(const Value& row) From 15e3524e42fa26f52d3eb9754bdd60652090de9f Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 6 Dec 2017 17:17:47 +0100 Subject: [PATCH 16/33] Move notification options wrapper into StatusDataWriter That's the only location which requires the old mapping. --- lib/compat/statusdatawriter.cpp | 56 +++++++++++++++++++++++++++++++-- lib/compat/statusdatawriter.hpp | 2 ++ lib/icinga/compatutility.cpp | 51 ------------------------------ lib/icinga/compatutility.hpp | 1 - 4 files changed, 55 insertions(+), 55 deletions(-) diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index bbb5469ca..142fdd91e 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -270,7 +270,7 @@ void StatusDataWriter::DumpHostObject(std::ostream& fp, const Host::Ptr& host) "\t" "active_checks_enabled" "\t" << Convert::ToLong(host->GetEnableActiveChecks()) << "\n" "\t" "passive_checks_enabled" "\t" << Convert::ToLong(host->GetEnablePassiveChecks()) << "\n" "\t" "notifications_enabled" "\t" << Convert::ToLong(host->GetEnableNotifications()) << "\n" - "\t" "notification_options" "\t" << CompatUtility::GetCheckableNotificationNotificationOptions(host) << "\n" + "\t" "notification_options" "\t" << GetNotificationOptions(host) << "\n" "\t" "notification_interval" "\t" << CompatUtility::GetCheckableNotificationNotificationInterval(host) << "\n" "\t" "event_handler_enabled" "\t" << Convert::ToLong(host->GetEnableEventHandler()) << "\n"; @@ -372,7 +372,7 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl if (cr) { fp << "\t" "plugin_output=" << CompatUtility::GetCheckResultOutput(cr) << "\n" "\t" "long_plugin_output=" << CompatUtility::GetCheckResultLongOutput(cr) << "\n" - "\t" "performance_data=" << PluginUtility::FormatPerfdata(cr->GetPerformanceData()) << "\n" + "\t" "performance_data=" << PluginUtility::FormatPerfdata(cr->GetPerformanceData()) << "\n"; } fp << "\t" << "next_check=" << static_cast(checkable->GetNextCheck()) << "\n" @@ -436,7 +436,7 @@ void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& s "\t" "flap_detection_enabled" "\t" << Convert::ToLong(service->GetEnableFlapping()) << "\n" "\t" "is_volatile" "\t" << Convert::ToLong(service->GetVolatile()) << "\n" "\t" "notifications_enabled" "\t" << Convert::ToLong(service->GetEnableNotifications()) << "\n" - "\t" "notification_options" "\t" << CompatUtility::GetCheckableNotificationNotificationOptions(service) << "\n" + "\t" "notification_options" "\t" << GetNotificationOptions(service) << "\n" "\t" "notification_interval" "\t" << CompatUtility::GetCheckableNotificationNotificationInterval(service) << "\n" "\t" "notification_period" "\t" << "" << "\n" "\t" "event_handler_enabled" "\t" << Convert::ToLong(service->GetEnableEventHandler()) << "\n"; @@ -864,3 +864,53 @@ void StatusDataWriter::ObjectHandler() { m_ObjectsCacheOutdated = true; } + +String StatusDataWriter::GetNotificationOptions(const Checkable::Ptr& checkable) +{ + Host::Ptr host; + Service::Ptr service; + tie(host, service) = GetHostService(checkable); + + unsigned long notification_type_filter = 0; + unsigned long notification_state_filter = 0; + + for (const Notification::Ptr& notification : checkable->GetNotifications()) { + notification_type_filter |= notification->GetTypeFilter(); + notification_state_filter |= notification->GetStateFilter(); + } + + std::vector notification_options; + + /* notification state filters */ + if (service) { + if (notification_state_filter & ServiceWarning) { + notification_options.push_back("w"); + } + if (notification_state_filter & ServiceUnknown) { + notification_options.push_back("u"); + } + if (notification_state_filter & ServiceCritical) { + notification_options.push_back("c"); + } + } else { + if (notification_state_filter & HostDown) { + notification_options.push_back("d"); + } + } + + /* notification type filters */ + if (notification_type_filter & NotificationRecovery) { + notification_options.push_back("r"); + } + if ((notification_type_filter & NotificationFlappingStart) || + (notification_type_filter & NotificationFlappingEnd)) { + notification_options.push_back("f"); + } + if ((notification_type_filter & NotificationDowntimeStart) || + (notification_type_filter & NotificationDowntimeEnd) || + (notification_type_filter & NotificationDowntimeRemoved)) { + notification_options.push_back("s"); + } + + return boost::algorithm::join(notification_options, ","); +} diff --git a/lib/compat/statusdatawriter.hpp b/lib/compat/statusdatawriter.hpp index c19377408..5dd68427f 100644 --- a/lib/compat/statusdatawriter.hpp +++ b/lib/compat/statusdatawriter.hpp @@ -97,6 +97,8 @@ private: void UpdateObjectsCache(); void StatusTimerHandler(); void ObjectHandler(); + + static String GetNotificationOptions(const Checkable::Ptr& checkable); }; } diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 154fcc4db..e86f20126 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -282,57 +282,6 @@ double CompatUtility::GetCheckableNotificationNotificationInterval(const Checkab return notification_interval / 60.0; } -String CompatUtility::GetCheckableNotificationNotificationOptions(const Checkable::Ptr& checkable) -{ - - Host::Ptr host; - Service::Ptr service; - tie(host, service) = GetHostService(checkable); - - unsigned long notification_type_filter = 0; - unsigned long notification_state_filter = 0; - - for (const Notification::Ptr& notification : checkable->GetNotifications()) { - notification_type_filter |= notification->GetTypeFilter(); - notification_state_filter |= notification->GetStateFilter(); - } - - std::vector notification_options; - - /* notification state filters */ - if (service) { - if (notification_state_filter & ServiceWarning) { - notification_options.emplace_back("w"); - } - if (notification_state_filter & ServiceUnknown) { - notification_options.emplace_back("u"); - } - if (notification_state_filter & ServiceCritical) { - notification_options.emplace_back("c"); - } - } else { - if (notification_state_filter & HostDown) { - notification_options.emplace_back("d"); - } - } - - /* notification type filters */ - if (notification_type_filter & NotificationRecovery) { - notification_options.emplace_back("r"); - } - if ((notification_type_filter & NotificationFlappingStart) || - (notification_type_filter & NotificationFlappingEnd)) { - notification_options.emplace_back("f"); - } - if ((notification_type_filter & NotificationDowntimeStart) || - (notification_type_filter & NotificationDowntimeEnd) || - (notification_type_filter & NotificationDowntimeRemoved)) { - notification_options.emplace_back("s"); - } - - return boost::algorithm::join(notification_options, ","); -} - int CompatUtility::GetCheckableNotificationTypeFilter(const Checkable::Ptr& checkable) { unsigned long notification_type_filter = 0; diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 55a08d082..4f1c59c60 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -65,7 +65,6 @@ public: static int GetCheckableNotificationNextNotification(const Checkable::Ptr& checkable); static int GetCheckableNotificationNotificationNumber(const Checkable::Ptr& checkable); static double GetCheckableNotificationNotificationInterval(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); From ce8bfdfa5a445723bd07898fba4b53caf2bce92d Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 6 Dec 2017 17:34:09 +0100 Subject: [PATCH 17/33] Move CompatUtility::GetCheckableInCheckPeriod() into Livestatus feature --- lib/icinga/compatutility.cpp | 11 ----------- lib/icinga/compatutility.hpp | 1 - lib/livestatus/hoststable.cpp | 8 +++++++- lib/livestatus/servicestable.cpp | 8 +++++++- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index e86f20126..ac87a1529 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -210,17 +210,6 @@ int CompatUtility::GetCheckableNoMoreNotifications(const Checkable::Ptr& checkab return 0; } -int CompatUtility::GetCheckableInCheckPeriod(const Checkable::Ptr& checkable) -{ - TimePeriod::Ptr timeperiod = checkable->GetCheckPeriod(); - - /* none set means always checked */ - if (!timeperiod) - return 1; - - return (timeperiod->IsInside(Utility::GetTime()) ? 1 : 0); -} - int CompatUtility::GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable) { for (const Notification::Ptr& notification : checkable->GetNotifications()) { diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 4f1c59c60..ee2bf3f2e 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -56,7 +56,6 @@ public: static String GetCheckableCheckPeriod(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 */ diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index 17ea108b4..2bc48ea0c 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -884,7 +884,13 @@ Value HostsTable::InCheckPeriodAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableInCheckPeriod(host); + TimePeriod::Ptr timeperiod = host->GetCheckPeriod(); + + /* none set means always checked */ + if (!timeperiod) + return 1; + + return Convert::ToLong(timeperiod->IsInside(Utility::GetTime())); } Value HostsTable::ContactsAccessor(const Value& row) diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index 1a7d3847d..00b11616c 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -895,7 +895,13 @@ Value ServicesTable::InCheckPeriodAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableInCheckPeriod(service); + TimePeriod::Ptr timeperiod = service->GetCheckPeriod(); + + /* none set means always checked */ + if (!timeperiod) + return 1; + + return Convert::ToLong(timeperiod->IsInside(Utility::GetTime())); } Value ServicesTable::InNotificationPeriodAccessor(const Value& row) From e3a899a9ac5b31d8318b23de2736e4642bb0c764 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 6 Dec 2017 17:49:53 +0100 Subject: [PATCH 18/33] Drop CompatUtility::GetCheckableCheckPeriod() --- lib/compat/statusdatawriter.cpp | 14 +++++++++++--- lib/icinga/compatutility.cpp | 9 --------- lib/icinga/compatutility.hpp | 1 - lib/livestatus/hoststable.cpp | 7 ++++++- lib/livestatus/servicestable.cpp | 7 ++++++- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index 142fdd91e..24be99a68 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -282,7 +282,9 @@ void StatusDataWriter::DumpHostObject(std::ostream& fp, const Host::Ptr& host) if (eventcommand && host->GetEnableEventHandler()) fp << "\t" "event_handler" "\t" << CompatUtility::GetCommandName(eventcommand) << "\n"; - fp << "\t" "check_period" "\t" << CompatUtility::GetCheckableCheckPeriod(host) << "\n"; + TimePeriod::Ptr checkPeriod = host->GetCheckPeriod(); + if (checkPeriod) + fp << "\t" "check_period" "\t" << checkPeriod->GetName() << "\n"; fp << "\t" "contacts" "\t"; DumpNameList(fp, CompatUtility::GetCheckableNotificationUsers(host)); @@ -336,13 +338,16 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl fp << "\t" << "check_command=" << CompatUtility::GetCommandName(checkcommand) << "!" << CompatUtility::GetCheckableCommandArgs(checkable) << "\n" "\t" "event_handler=" << CompatUtility::GetCommandName(eventcommand) << "\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=" << Convert::ToLong(checkable->HasBeenChecked()) << "\n" "\t" "should_be_scheduled=" << checkable->GetEnableActiveChecks() << "\n" "\t" "event_handler_enabled=" << Convert::ToLong(checkable->GetEnableEventHandler()) << "\n"; + TimePeriod::Ptr checkPeriod = checkable->GetCheckPeriod(); + if (checkPeriod) + fp << "\t" "check_period" "\t" << checkPeriod->GetName() << "\n"; + if (cr) { fp << "\t" << "check_execution_time=" << Convert::ToString(cr->CalculateExecutionTime()) << "\n" "\t" "check_latency=" << Convert::ToString(cr->CalculateLatency()) << "\n"; @@ -427,7 +432,6 @@ void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& s "\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::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" @@ -449,6 +453,10 @@ void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& s if (eventcommand && service->GetEnableEventHandler()) fp << "\t" "event_handler" "\t" << CompatUtility::GetCommandName(eventcommand) << "\n"; + TimePeriod::Ptr checkPeriod = service->GetCheckPeriod(); + if (checkPeriod) + fp << "\t" "check_period" "\t" << checkPeriod->GetName() << "\n"; + fp << "\t" "contacts" "\t"; DumpNameList(fp, CompatUtility::GetCheckableNotificationUsers(service)); fp << "\n"; diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index ac87a1529..2b030b3fa 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -193,15 +193,6 @@ double CompatUtility::GetCheckableRetryInterval(const Checkable::Ptr& checkable) return checkable->GetRetryInterval() / 60.0; } -String CompatUtility::GetCheckableCheckPeriod(const Checkable::Ptr& checkable) -{ - TimePeriod::Ptr check_period = checkable->GetCheckPeriod(); - if (check_period) - return check_period->GetName(); - else - return "24x7"; -} - int CompatUtility::GetCheckableNoMoreNotifications(const Checkable::Ptr& checkable) { if (CompatUtility::GetCheckableNotificationNotificationInterval(checkable) == 0 && !checkable->GetVolatile()) diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index ee2bf3f2e..8dac5d1e9 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -53,7 +53,6 @@ public: static String GetCheckableCommandArgs(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 GetCheckableNoMoreNotifications(const Checkable::Ptr& checkable); static int GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable); diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index 2bc48ea0c..b5959b9bc 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -304,7 +304,12 @@ Value HostsTable::CheckPeriodAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableCheckPeriod(host); + TimePeriod::Ptr checkPeriod = host->GetCheckPeriod(); + + if (!checkPeriod) + return Empty; + + return checkPeriod->GetName(); } Value HostsTable::NotesAccessor(const Value& row) diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index 00b11616c..1e9283bd8 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -356,7 +356,12 @@ Value ServicesTable::CheckPeriodAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableCheckPeriod(service); + TimePeriod::Ptr checkPeriod = service->GetCheckPeriod(); + + if (!checkPeriod) + return Empty; + + return checkPeriod->GetName(); } Value ServicesTable::NotesAccessor(const Value& row) From 1473957bc2131e6624098b200acb253ec9a48ca9 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 7 Dec 2017 11:29:39 +0100 Subject: [PATCH 19/33] Add inventory as comments where the left-over functions are actually used. --- lib/icinga/compatutility.cpp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 2b030b3fa..4583284bb 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -32,7 +32,7 @@ using namespace icinga; -/* command */ +/* Used in DB IDO, StatusDataWriter and Livestatus. */ String CompatUtility::GetCommandLine(const Command::Ptr& command) { Value commandLine = command->GetCommandLine(); @@ -56,6 +56,7 @@ String CompatUtility::GetCommandLine(const Command::Ptr& command) } String CompatUtility::GetCommandNamePrefix(const Command::Ptr& command) +/* Helper. */ { if (!command) return Empty; @@ -72,6 +73,7 @@ String CompatUtility::GetCommandNamePrefix(const Command::Ptr& command) } String CompatUtility::GetCommandName(const Command::Ptr& command) +/* Used in DB IDO, StatusDataWriter and Livestatus. */ { if (!command) return Empty; @@ -79,7 +81,7 @@ String CompatUtility::GetCommandName(const Command::Ptr& command) return GetCommandNamePrefix(command) + command->GetName(); } -/* host */ +/* Used in StatusDataWriter and DB IDO. */ int CompatUtility::GetHostCurrentState(const Host::Ptr& host) { if (host->GetState() != HostUp && !host->IsReachable()) @@ -88,6 +90,7 @@ int CompatUtility::GetHostCurrentState(const Host::Ptr& host) return host->GetState(); } +/* Used in StatusDataWriter and DB IDO. */ String CompatUtility::GetHostStateString(const Host::Ptr& host) { if (host->GetState() != HostUp && !host->IsReachable()) @@ -96,6 +99,7 @@ String CompatUtility::GetHostStateString(const Host::Ptr& host) return Host::StateToString(host->GetState()); } +/* Used in DB IDO. */ int CompatUtility::GetHostNotifyOnDown(const Host::Ptr& host) { unsigned long notification_state_filter = GetCheckableNotificationStateFilter(host); @@ -107,6 +111,7 @@ int CompatUtility::GetHostNotifyOnDown(const Host::Ptr& host) return 0; } +/* Used in DB IDO. */ int CompatUtility::GetHostNotifyOnUnreachable(const Host::Ptr& host) { unsigned long notification_state_filter = GetCheckableNotificationStateFilter(host); @@ -117,7 +122,7 @@ int CompatUtility::GetHostNotifyOnUnreachable(const Host::Ptr& host) return 0; } -/* service */ +/* Used in DB IDO, StatusDataWriter and Livestatus. */ String CompatUtility::GetCheckableCommandArgs(const Checkable::Ptr& checkable) { CheckCommand::Ptr command = checkable->GetCheckCommand(); @@ -183,16 +188,19 @@ String CompatUtility::GetCheckableCommandArgs(const Checkable::Ptr& checkable) return Empty; } +/* Used in DB IDO, StatusDataWriter and Livestatus. */ double CompatUtility::GetCheckableCheckInterval(const Checkable::Ptr& checkable) { return checkable->GetCheckInterval() / 60.0; } +/* Used in DB IDO, StatusDataWriter and Livestatus. */ double CompatUtility::GetCheckableRetryInterval(const Checkable::Ptr& checkable) { return checkable->GetRetryInterval() / 60.0; } +/* Used in Livestatus. */ int CompatUtility::GetCheckableNoMoreNotifications(const Checkable::Ptr& checkable) { if (CompatUtility::GetCheckableNotificationNotificationInterval(checkable) == 0 && !checkable->GetVolatile()) @@ -201,6 +209,7 @@ int CompatUtility::GetCheckableNoMoreNotifications(const Checkable::Ptr& checkab return 0; } +/* Used in Livestatus. */ int CompatUtility::GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable) { for (const Notification::Ptr& notification : checkable->GetNotifications()) { @@ -213,7 +222,7 @@ int CompatUtility::GetCheckableInNotificationPeriod(const Checkable::Ptr& checka return 0; } -/* notifications */ +/* Used in DB IDO, StatusDataWriter and Livestatus. */ int CompatUtility::GetCheckableNotificationLastNotification(const Checkable::Ptr& checkable) { double last_notification = 0.0; @@ -225,6 +234,7 @@ int CompatUtility::GetCheckableNotificationLastNotification(const Checkable::Ptr return static_cast(last_notification); } +/* Used in DB IDO, StatusDataWriter and Livestatus. */ int CompatUtility::GetCheckableNotificationNextNotification(const Checkable::Ptr& checkable) { double next_notification = 0.0; @@ -236,6 +246,7 @@ int CompatUtility::GetCheckableNotificationNextNotification(const Checkable::Ptr return static_cast(next_notification); } +/* Used in DB IDO, StatusDataWriter and Livestatus. */ int CompatUtility::GetCheckableNotificationNotificationNumber(const Checkable::Ptr& checkable) { int notification_number = 0; @@ -247,6 +258,7 @@ int CompatUtility::GetCheckableNotificationNotificationNumber(const Checkable::P return notification_number; } +/* Used in DB IDO, StatusDataWriter and Livestatus. */ double CompatUtility::GetCheckableNotificationNotificationInterval(const Checkable::Ptr& checkable) { double notification_interval = -1; @@ -262,6 +274,7 @@ double CompatUtility::GetCheckableNotificationNotificationInterval(const Checkab return notification_interval / 60.0; } +/* Helper. */ int CompatUtility::GetCheckableNotificationTypeFilter(const Checkable::Ptr& checkable) { unsigned long notification_type_filter = 0; @@ -275,6 +288,7 @@ int CompatUtility::GetCheckableNotificationTypeFilter(const Checkable::Ptr& chec return notification_type_filter; } +/* Helper. */ int CompatUtility::GetCheckableNotificationStateFilter(const Checkable::Ptr& checkable) { unsigned long notification_state_filter = 0; @@ -288,6 +302,7 @@ int CompatUtility::GetCheckableNotificationStateFilter(const Checkable::Ptr& che return notification_state_filter; } +/* Used in DB IDO. */ int CompatUtility::GetCheckableNotifyOnWarning(const Checkable::Ptr& checkable) { if (GetCheckableNotificationStateFilter(checkable) & ServiceWarning) @@ -296,6 +311,7 @@ int CompatUtility::GetCheckableNotifyOnWarning(const Checkable::Ptr& checkable) return 0; } +/* Used in DB IDO. */ int CompatUtility::GetCheckableNotifyOnCritical(const Checkable::Ptr& checkable) { if (GetCheckableNotificationStateFilter(checkable) & ServiceCritical) @@ -304,6 +320,7 @@ int CompatUtility::GetCheckableNotifyOnCritical(const Checkable::Ptr& checkable) return 0; } +/* Used in DB IDO. */ int CompatUtility::GetCheckableNotifyOnUnknown(const Checkable::Ptr& checkable) { if (GetCheckableNotificationStateFilter(checkable) & ServiceUnknown) @@ -312,6 +329,7 @@ int CompatUtility::GetCheckableNotifyOnUnknown(const Checkable::Ptr& checkable) return 0; } +/* Used in DB IDO. */ int CompatUtility::GetCheckableNotifyOnRecovery(const Checkable::Ptr& checkable) { if (GetCheckableNotificationTypeFilter(checkable) & NotificationRecovery) @@ -320,6 +338,7 @@ int CompatUtility::GetCheckableNotifyOnRecovery(const Checkable::Ptr& checkable) return 0; } +/* Used in DB IDO. */ int CompatUtility::GetCheckableNotifyOnFlapping(const Checkable::Ptr& checkable) { unsigned long notification_type_filter = GetCheckableNotificationTypeFilter(checkable); @@ -331,6 +350,7 @@ int CompatUtility::GetCheckableNotifyOnFlapping(const Checkable::Ptr& checkable) return 0; } +/* Used in DB IDO. */ int CompatUtility::GetCheckableNotifyOnDowntime(const Checkable::Ptr& checkable) { unsigned long notification_type_filter = GetCheckableNotificationTypeFilter(checkable); @@ -343,6 +363,7 @@ int CompatUtility::GetCheckableNotifyOnDowntime(const Checkable::Ptr& checkable) return 0; } +/* Used in DB IDO, StatusDataWriter and Livestatus. */ std::set CompatUtility::GetCheckableNotificationUsers(const Checkable::Ptr& checkable) { /* Service -> Notifications -> (Users + UserGroups -> Users) */ @@ -365,6 +386,7 @@ std::set CompatUtility::GetCheckableNotificationUsers(const Checkable return allUsers; } +/* Used in DB IDO, StatusDataWriter and Livestatus. */ std::set CompatUtility::GetCheckableNotificationUserGroups(const Checkable::Ptr& checkable) { std::set usergroups; @@ -380,6 +402,7 @@ std::set CompatUtility::GetCheckableNotificationUserGroups(const return usergroups; } +/* Used in DB IDO, StatusDataWriter, Livestatus, CompatLogger, GelfWriter. */ String CompatUtility::GetCheckResultOutput(const CheckResult::Ptr& cr) { if (!cr) @@ -394,6 +417,7 @@ String CompatUtility::GetCheckResultOutput(const CheckResult::Ptr& cr) return raw_output.SubStr(0, line_end); } +/* Used in DB IDO, StatusDataWriter and Livestatus. */ String CompatUtility::GetCheckResultLongOutput(const CheckResult::Ptr& cr) { if (!cr) @@ -414,6 +438,7 @@ String CompatUtility::GetCheckResultLongOutput(const CheckResult::Ptr& cr) return Empty; } +/* Helper for DB IDO, StatusDataWriter and Livestatus. Used in StatusDataWriter. */ String CompatUtility::EscapeString(const String& str) { String result = str; @@ -421,6 +446,7 @@ String CompatUtility::EscapeString(const String& str) return result; } +/* Used in ExternalCommandListener and CheckResultReader. */ String CompatUtility::UnEscapeString(const String& str) { String result = str; From fb76287d396bc4389335b06d378d10302c0d8b25 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 7 Dec 2017 11:42:39 +0100 Subject: [PATCH 20/33] Clean header includes in CompatUtility class --- lib/icinga/compatutility.hpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 8dac5d1e9..6ecf6b81a 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -21,12 +21,8 @@ #define COMPATUTILITY_H #include "icinga/i2-icinga.hpp" -#include "icinga/customvarobject.hpp" #include "icinga/host.hpp" #include "icinga/command.hpp" -#include "base/dictionary.hpp" -#include "base/array.hpp" -#include namespace icinga { From d373b0390794e43d759fadb253c3a7a10d3634f2 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 20 Dec 2017 16:46:50 +0100 Subject: [PATCH 21/33] Drop CompatUtility::GetCheckable*Interval() and hardcode their minute representation in compat features --- lib/compat/statusdatawriter.cpp | 12 ++++++------ lib/db_ido/hostdbobject.cpp | 8 ++++---- lib/db_ido/servicedbobject.cpp | 8 ++++---- lib/icinga/compatutility.cpp | 12 ------------ lib/icinga/compatutility.hpp | 2 -- lib/livestatus/hoststable.cpp | 4 ++-- lib/livestatus/servicestable.cpp | 4 ++-- 7 files changed, 18 insertions(+), 32 deletions(-) diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index 24be99a68..768059d5b 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -264,8 +264,8 @@ void StatusDataWriter::DumpHostObject(std::ostream& fp, const Host::Ptr& host) ObjectLock olock(host); - fp << "\t" "check_interval" "\t" << CompatUtility::GetCheckableCheckInterval(host) << "\n" - "\t" "retry_interval" "\t" << CompatUtility::GetCheckableRetryInterval(host) << "\n" + fp << "\t" "check_interval" "\t" << (host->GetCheckInterval() / 60.0) << "\n" + "\t" "retry_interval" "\t" << (host->GetRetryInterval() / 60.0) << "\n" "\t" "max_check_attempts" "\t" << host->GetMaxCheckAttempts() << "\n" "\t" "active_checks_enabled" "\t" << Convert::ToLong(host->GetEnableActiveChecks()) << "\n" "\t" "passive_checks_enabled" "\t" << Convert::ToLong(host->GetEnablePassiveChecks()) << "\n" @@ -338,8 +338,8 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl fp << "\t" << "check_command=" << CompatUtility::GetCommandName(checkcommand) << "!" << CompatUtility::GetCheckableCommandArgs(checkable) << "\n" "\t" "event_handler=" << CompatUtility::GetCommandName(eventcommand) << "\n" - "\t" "check_interval=" << CompatUtility::GetCheckableCheckInterval(checkable) << "\n" - "\t" "retry_interval=" << CompatUtility::GetCheckableRetryInterval(checkable) << "\n" + "\t" "check_interval=" << (checkable->GetCheckInterval() / 60.0) << "\n" + "\t" "retry_interval=" << (checkable->GetRetryInterval() / 60.0) << "\n" "\t" "has_been_checked=" << Convert::ToLong(checkable->HasBeenChecked()) << "\n" "\t" "should_be_scheduled=" << checkable->GetEnableActiveChecks() << "\n" "\t" "event_handler_enabled=" << Convert::ToLong(checkable->GetEnableEventHandler()) << "\n"; @@ -432,8 +432,8 @@ void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& s "\t" "host_name" "\t" << host->GetName() << "\n" "\t" "service_description" "\t" << service->GetShortName() << "\n" "\t" "display_name" "\t" << service->GetDisplayName() << "\n" - "\t" "check_interval" "\t" << CompatUtility::GetCheckableCheckInterval(service) << "\n" - "\t" "retry_interval" "\t" << CompatUtility::GetCheckableRetryInterval(service) << "\n" + "\t" "check_interval" "\t" << (service->GetCheckInterval() / 60.0) << "\n" + "\t" "retry_interval" "\t" << (service->GetRetryInterval() / 60.0) << "\n" "\t" "max_check_attempts" "\t" << service->GetMaxCheckAttempts() << "\n" "\t" "active_checks_enabled" "\t" << Convert::ToLong(service->GetEnableActiveChecks()) << "\n" "\t" "passive_checks_enabled" "\t" << Convert::ToLong(service->GetEnablePassiveChecks()) << "\n" diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index c7eb4c89e..393bbbb04 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -68,8 +68,8 @@ Dictionary::Ptr HostDbObject::GetConfigFields() const fields->Set("notification_timeperiod_object_id", Empty); 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("check_interval", (host->GetCheckInterval() / 60.0)); + fields->Set("retry_interval", (host->GetRetryInterval() / 60.0)); fields->Set("max_check_attempts", host->GetMaxCheckAttempts()); fields->Set("first_notification_delay", Empty); @@ -173,8 +173,8 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const fields->Set("failure_prediction_enabled", Empty); fields->Set("process_performance_data", host->GetEnablePerfdata()); fields->Set("obsess_over_host", Empty); - fields->Set("normal_check_interval", CompatUtility::GetCheckableCheckInterval(host)); - fields->Set("retry_check_interval", CompatUtility::GetCheckableRetryInterval(host)); + fields->Set("normal_check_interval", (host->GetCheckInterval() / 60.0)); + fields->Set("retry_check_interval", (host->GetRetryInterval() / 60.0)); fields->Set("check_timeperiod_object_id", host->GetCheckPeriod()); fields->Set("is_reachable", host->IsReachable()); diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index b39e600da..b50ebe13d 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -63,8 +63,8 @@ Dictionary::Ptr ServiceDbObject::GetConfigFields() const fields->Set("notification_timeperiod_object_id", Empty); fields->Set("check_timeperiod_object_id", service->GetCheckPeriod()); fields->Set("failure_prediction_options", Empty); - fields->Set("check_interval", CompatUtility::GetCheckableCheckInterval(service)); - fields->Set("retry_interval", CompatUtility::GetCheckableRetryInterval(service)); + fields->Set("check_interval", (service->GetCheckInterval() / 60.0)); + fields->Set("retry_interval", (service->GetRetryInterval() / 60.0)); fields->Set("max_check_attempts", service->GetMaxCheckAttempts()); fields->Set("first_notification_delay", Empty); fields->Set("notification_interval", CompatUtility::GetCheckableNotificationNotificationInterval(service)); @@ -159,8 +159,8 @@ Dictionary::Ptr ServiceDbObject::GetStatusFields() const fields->Set("scheduled_downtime_depth", service->GetDowntimeDepth()); fields->Set("process_performance_data", service->GetEnablePerfdata()); - fields->Set("normal_check_interval", CompatUtility::GetCheckableCheckInterval(service)); - fields->Set("retry_check_interval", CompatUtility::GetCheckableRetryInterval(service)); + fields->Set("normal_check_interval", (service->GetCheckInterval() / 60.0)); + fields->Set("retry_check_interval", (service->GetRetryInterval() / 60.0)); fields->Set("check_timeperiod_object_id", service->GetCheckPeriod()); fields->Set("is_reachable", service->IsReachable()); diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 4583284bb..89a0cb95b 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -188,18 +188,6 @@ String CompatUtility::GetCheckableCommandArgs(const Checkable::Ptr& checkable) return Empty; } -/* Used in DB IDO, StatusDataWriter and Livestatus. */ -double CompatUtility::GetCheckableCheckInterval(const Checkable::Ptr& checkable) -{ - return checkable->GetCheckInterval() / 60.0; -} - -/* Used in DB IDO, StatusDataWriter and Livestatus. */ -double CompatUtility::GetCheckableRetryInterval(const Checkable::Ptr& checkable) -{ - return checkable->GetRetryInterval() / 60.0; -} - /* Used in Livestatus. */ int CompatUtility::GetCheckableNoMoreNotifications(const Checkable::Ptr& checkable) { diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 6ecf6b81a..20ea8c601 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -47,8 +47,6 @@ public: /* service */ static String GetCheckableCommandArgs(const Checkable::Ptr& checkable); - static double GetCheckableCheckInterval(const Checkable::Ptr& checkable); - static double GetCheckableRetryInterval(const Checkable::Ptr& checkable); static int GetCheckableNoMoreNotifications(const Checkable::Ptr& checkable); static int GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable); diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index b5959b9bc..08e6104e1 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -789,7 +789,7 @@ Value HostsTable::CheckIntervalAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableCheckInterval(host); + return host->GetCheckInterval() / 60.0; } Value HostsTable::RetryIntervalAccessor(const Value& row) @@ -799,7 +799,7 @@ Value HostsTable::RetryIntervalAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableRetryInterval(host); + return host->GetRetryInterval() / 60.0; } Value HostsTable::NotificationIntervalAccessor(const Value& row) diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index 1e9283bd8..c3a941c5e 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -810,7 +810,7 @@ Value ServicesTable::CheckIntervalAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableCheckInterval(service); + return service->GetCheckInterval() / 60.0; } Value ServicesTable::RetryIntervalAccessor(const Value& row) @@ -820,7 +820,7 @@ Value ServicesTable::RetryIntervalAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableRetryInterval(service); + return service->GetRetryInterval() / 60.0; } Value ServicesTable::NotificationIntervalAccessor(const Value& row) From 48516560bc85dc6adea0b0ecbfd95babd89afda8 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 21 Dec 2017 08:57:36 +0100 Subject: [PATCH 22/33] Move the IDO specific compat notification filter logic into the feature --- lib/db_ido/hostdbobject.cpp | 15 ++++-- lib/db_ido/servicedbobject.cpp | 19 ++++--- lib/icinga/compatutility.cpp | 93 -------------------------------- lib/icinga/compatutility.hpp | 9 ---- lib/livestatus/hoststable.cpp | 2 +- lib/livestatus/servicestable.cpp | 2 +- 6 files changed, 25 insertions(+), 115 deletions(-) diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 393bbbb04..6be9b236a 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -75,12 +75,17 @@ Dictionary::Ptr HostDbObject::GetConfigFields() const 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)); + unsigned long notificationStateFilter = CompatUtility::GetCheckableNotificationTypeFilter(host); + unsigned long notificationTypeFilter = CompatUtility::GetCheckableNotificationTypeFilter(host); + + fields->Set("notify_on_down", (notificationStateFilter & ServiceWarning) || (notificationStateFilter && ServiceCritical)); + fields->Set("notify_on_unreachable", 1); /* We don't have this filter and state, and as such we don't filter such notifications. */ + fields->Set("notify_on_recovery", notificationTypeFilter & NotificationRecovery); + fields->Set("notify_on_flapping", (notificationTypeFilter & NotificationFlappingStart) || + (notificationTypeFilter & NotificationFlappingEnd)); + fields->Set("notify_on_downtime", (notificationTypeFilter & NotificationDowntimeStart) || + (notificationTypeFilter & NotificationDowntimeEnd) || (notificationTypeFilter & NotificationDowntimeRemoved)); fields->Set("stalk_on_up", Empty); fields->Set("stalk_on_down", Empty); diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index b50ebe13d..e8d3cc2de 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -68,12 +68,19 @@ Dictionary::Ptr ServiceDbObject::GetConfigFields() const fields->Set("max_check_attempts", service->GetMaxCheckAttempts()); fields->Set("first_notification_delay", Empty); 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)); + + unsigned long notificationStateFilter = CompatUtility::GetCheckableNotificationTypeFilter(service); + unsigned long notificationTypeFilter = CompatUtility::GetCheckableNotificationTypeFilter(service); + + fields->Set("notify_on_warning", notificationStateFilter & ServiceWarning); + fields->Set("notify_on_unknown", notificationStateFilter & ServiceUnknown); + fields->Set("notify_on_critical", notificationStateFilter & ServiceCritical); + fields->Set("notify_on_recovery", notificationTypeFilter & NotificationRecovery); + fields->Set("notify_on_flapping", (notificationTypeFilter & NotificationFlappingStart) || + (notificationTypeFilter & NotificationFlappingEnd)); + fields->Set("notify_on_downtime", (notificationTypeFilter & NotificationDowntimeStart) || + (notificationTypeFilter & NotificationDowntimeEnd) || (notificationTypeFilter & NotificationDowntimeRemoved)); + fields->Set("stalk_on_ok", 0); fields->Set("stalk_on_warning", 0); fields->Set("stalk_on_unknown", 0); diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 89a0cb95b..60a269baf 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -99,29 +99,6 @@ String CompatUtility::GetHostStateString(const Host::Ptr& host) return Host::StateToString(host->GetState()); } -/* Used in DB IDO. */ -int CompatUtility::GetHostNotifyOnDown(const Host::Ptr& host) -{ - unsigned long notification_state_filter = GetCheckableNotificationStateFilter(host); - - if ((notification_state_filter & ServiceCritical) || - (notification_state_filter & ServiceWarning)) - return 1; - - return 0; -} - -/* Used in DB IDO. */ -int CompatUtility::GetHostNotifyOnUnreachable(const Host::Ptr& host) -{ - unsigned long notification_state_filter = GetCheckableNotificationStateFilter(host); - - if (notification_state_filter & ServiceUnknown) - return 1; - - return 0; -} - /* Used in DB IDO, StatusDataWriter and Livestatus. */ String CompatUtility::GetCheckableCommandArgs(const Checkable::Ptr& checkable) { @@ -188,15 +165,6 @@ String CompatUtility::GetCheckableCommandArgs(const Checkable::Ptr& checkable) return Empty; } -/* Used in Livestatus. */ -int CompatUtility::GetCheckableNoMoreNotifications(const Checkable::Ptr& checkable) -{ - if (CompatUtility::GetCheckableNotificationNotificationInterval(checkable) == 0 && !checkable->GetVolatile()) - return 1; - - return 0; -} - /* Used in Livestatus. */ int CompatUtility::GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable) { @@ -290,67 +258,6 @@ int CompatUtility::GetCheckableNotificationStateFilter(const Checkable::Ptr& che return notification_state_filter; } -/* Used in DB IDO. */ -int CompatUtility::GetCheckableNotifyOnWarning(const Checkable::Ptr& checkable) -{ - if (GetCheckableNotificationStateFilter(checkable) & ServiceWarning) - return 1; - - return 0; -} - -/* Used in DB IDO. */ -int CompatUtility::GetCheckableNotifyOnCritical(const Checkable::Ptr& checkable) -{ - if (GetCheckableNotificationStateFilter(checkable) & ServiceCritical) - return 1; - - return 0; -} - -/* Used in DB IDO. */ -int CompatUtility::GetCheckableNotifyOnUnknown(const Checkable::Ptr& checkable) -{ - if (GetCheckableNotificationStateFilter(checkable) & ServiceUnknown) - return 1; - - return 0; -} - -/* Used in DB IDO. */ -int CompatUtility::GetCheckableNotifyOnRecovery(const Checkable::Ptr& checkable) -{ - if (GetCheckableNotificationTypeFilter(checkable) & NotificationRecovery) - return 1; - - return 0; -} - -/* Used in DB IDO. */ -int CompatUtility::GetCheckableNotifyOnFlapping(const Checkable::Ptr& checkable) -{ - unsigned long notification_type_filter = GetCheckableNotificationTypeFilter(checkable); - - if ((notification_type_filter & NotificationFlappingStart) || - (notification_type_filter & NotificationFlappingEnd)) - return 1; - - return 0; -} - -/* Used in DB IDO. */ -int CompatUtility::GetCheckableNotifyOnDowntime(const Checkable::Ptr& checkable) -{ - unsigned long notification_type_filter = GetCheckableNotificationTypeFilter(checkable); - - if ((notification_type_filter & NotificationDowntimeStart) || - (notification_type_filter & NotificationDowntimeEnd) || - (notification_type_filter & NotificationDowntimeRemoved)) - return 1; - - return 0; -} - /* Used in DB IDO, StatusDataWriter and Livestatus. */ std::set CompatUtility::GetCheckableNotificationUsers(const Checkable::Ptr& checkable) { diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 20ea8c601..25ae136f0 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -42,13 +42,10 @@ public: /* host */ static int GetHostCurrentState(const Host::Ptr& host); static String GetHostStateString(const Host::Ptr& host); - static int GetHostNotifyOnDown(const Host::Ptr& host); - static int GetHostNotifyOnUnreachable(const Host::Ptr& host); /* service */ static String GetCheckableCommandArgs(const Checkable::Ptr& checkable); - static int GetCheckableNoMoreNotifications(const Checkable::Ptr& checkable); static int GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable); /* notification */ @@ -59,12 +56,6 @@ public: static double GetCheckableNotificationNotificationInterval(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 GetCheckableNotificationUsers(const Checkable::Ptr& checkable); static std::set GetCheckableNotificationUserGroups(const Checkable::Ptr& checkable); diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index 08e6104e1..6e637c258 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -699,7 +699,7 @@ Value HostsTable::NoMoreNotificationsAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableNoMoreNotifications(host); + return (CompatUtility::GetCheckableNotificationNotificationInterval(host) == 0 && !host->GetVolatile()) ? 1 : 0; } Value HostsTable::LastCheckAccessor(const Value& row) diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index c3a941c5e..b0c70ce32 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -587,7 +587,7 @@ Value ServicesTable::NoMoreNotificationsAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableNoMoreNotifications(service); + return (CompatUtility::GetCheckableNotificationNotificationInterval(service) == 0 && !service->GetVolatile()) ? 1 : 0; } Value ServicesTable::LastTimeOkAccessor(const Value& row) From 915d0417c972bb31071fa70dc121f2edfe7a4c5a Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 21 Dec 2017 09:12:12 +0100 Subject: [PATCH 23/33] Move CompatUtility::GetHostCurrentState() logic into DB IDO and StatusData features --- lib/compat/statusdatawriter.cpp | 7 ++++++- lib/db_ido/dbevents.cpp | 20 +++++++++++++++----- lib/db_ido/dbevents.hpp | 1 + lib/db_ido/hostdbobject.cpp | 7 ++++++- lib/icinga/compatutility.cpp | 9 --------- lib/icinga/compatutility.hpp | 1 - 6 files changed, 28 insertions(+), 17 deletions(-) diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index 768059d5b..62e5e30c7 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -365,7 +365,12 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl "\t" "last_time_critical=" << static_cast(service->GetLastStateCritical()) << "\n" "\t" "last_time_unknown=" << static_cast(service->GetLastStateUnknown()) << "\n"; } else { - fp << "\t" "current_state=" << CompatUtility::GetHostCurrentState(host) << "\n" + int currentState = host->GetState(); + + if (currentState != HostUp && !host->IsReachable()) + currentState = 2; /* hardcoded compat state */ + + fp << "\t" "current_state=" << currentState << "\n" "\t" "last_hard_state=" << host->GetLastHardState() << "\n" "\t" "last_time_up=" << static_cast(host->GetLastStateUp()) << "\n" "\t" "last_time_down=" << static_cast(host->GetLastStateDown()) << "\n"; diff --git a/lib/db_ido/dbevents.cpp b/lib/db_ido/dbevents.cpp index 7c9598e87..b2f2ba012 100644 --- a/lib/db_ido/dbevents.cpp +++ b/lib/db_ido/dbevents.cpp @@ -761,7 +761,7 @@ void DbEvents::AddAcknowledgementHistory(const Checkable::Ptr& checkable, const if (service) { fields1->Set("state", service->GetState()); } else { - fields1->Set("state", CompatUtility::GetHostCurrentState(host)); + fields1->Set("state", GetHostState(host)); } String node = IcingaApplication::GetInstance()->GetNodeName(); @@ -855,7 +855,7 @@ void DbEvents::AddNotificationHistory(const Notification::Ptr& notification, con if (service) { fields1->Set("state", service->GetState()); } else { - fields1->Set("state", CompatUtility::GetHostCurrentState(host)); + fields1->Set("state", GetHostState(host)); } if (cr) { @@ -936,7 +936,7 @@ void DbEvents::AddStateChangeHistory(const Checkable::Ptr& checkable, const Chec fields1->Set("last_state", service->GetLastState()); fields1->Set("last_hard_state", service->GetLastHardState()); } else { - fields1->Set("state", CompatUtility::GetHostCurrentState(host)); + fields1->Set("state", GetHostState(host)); fields1->Set("last_state", host->GetLastState()); fields1->Set("last_hard_state", host->GetLastHardState()); } @@ -1421,7 +1421,7 @@ void DbEvents::AddCheckableCheckHistory(const Checkable::Ptr& checkable, const C fields1->Set("state", service->GetState()); } else { fields1->Set("host_object_id", host); - fields1->Set("state", CompatUtility::GetHostCurrentState(host)); + fields1->Set("state", GetHostState(host)); } String node = IcingaApplication::GetInstance()->GetNodeName(); @@ -1459,7 +1459,7 @@ void DbEvents::AddEventHandlerHistory(const Checkable::Ptr& checkable) fields1->Set("state", service->GetState()); fields1->Set("eventhandler_type", 1); } else { - fields1->Set("state", CompatUtility::GetHostCurrentState(host)); + fields1->Set("state", GetHostState(host)); fields1->Set("eventhandler_type", 0); } @@ -1512,6 +1512,16 @@ void DbEvents::AddExternalCommandHistory(double time, const String& command, con DbObject::OnQuery(query1); } +int DbEvents::GetHostState(const Host::Ptr& host) +{ + int currentState = host->GetState(); + + if (currentState != HostUp && !host->IsReachable()) + currentState = 2; /* hardcoded compat state */ + + return currentState; +} + std::pair DbEvents::ConvertTimestamp(double time) { unsigned long time_sec = static_cast(time); diff --git a/lib/db_ido/dbevents.hpp b/lib/db_ido/dbevents.hpp index cfc33b25f..91705e381 100644 --- a/lib/db_ido/dbevents.hpp +++ b/lib/db_ido/dbevents.hpp @@ -133,6 +133,7 @@ private: static void RemoveDowntimeInternal(std::vector& queries, const Downtime::Ptr& downtime); static void EnableChangedHandlerInternal(const Checkable::Ptr& checkable, const String& fieldName, bool enabled); + static int GetHostState(const Host::Ptr& host); static std::pair ConvertTimestamp(double time); static int MapNotificationReasonType(NotificationType type); static int MapExternalCommandType(const String& name); diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 6be9b236a..b77aeb4c9 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -137,7 +137,12 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const fields->Set("check_source", cr->GetCheckSource()); } - fields->Set("current_state", CompatUtility::GetHostCurrentState(host)); + int currentState = host->GetState(); + + if (currentState != HostUp && !host->IsReachable()) + currentState = 2; /* hardcoded compat state */ + + fields->Set("current_state", currentState); fields->Set("has_been_checked", host->HasBeenChecked()); fields->Set("should_be_scheduled", host->GetEnableActiveChecks()); fields->Set("current_check_attempt", host->GetCheckAttempt()); diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 60a269baf..6cb6f9b12 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -81,15 +81,6 @@ String CompatUtility::GetCommandName(const Command::Ptr& command) return GetCommandNamePrefix(command) + command->GetName(); } -/* Used in StatusDataWriter and DB IDO. */ -int CompatUtility::GetHostCurrentState(const Host::Ptr& host) -{ - if (host->GetState() != HostUp && !host->IsReachable()) - return 2; /* hardcoded compat state */ - - return host->GetState(); -} - /* Used in StatusDataWriter and DB IDO. */ String CompatUtility::GetHostStateString(const Host::Ptr& host) { diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 25ae136f0..98e71a8d7 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -40,7 +40,6 @@ public: static String GetCommandName(const Command::Ptr& command); /* host */ - static int GetHostCurrentState(const Host::Ptr& host); static String GetHostStateString(const Host::Ptr& host); /* service */ From 5222f7d058e7ddbad818f0c6d99b4e403fbfc95f Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 21 Dec 2017 09:13:47 +0100 Subject: [PATCH 24/33] GelfWriter should write the host notification output No idea why there was a hardcoded unreachable message inside. --- lib/perfdata/gelfwriter.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/perfdata/gelfwriter.cpp b/lib/perfdata/gelfwriter.cpp index 6742a11da..0394befa1 100644 --- a/lib/perfdata/gelfwriter.cpp +++ b/lib/perfdata/gelfwriter.cpp @@ -325,8 +325,7 @@ void GelfWriter::NotificationToUserHandlerInternal(const Notification::Ptr& noti fields->Set("short_message", output); } else { fields->Set("_type", "HOST NOTIFICATION"); - //TODO: why? - fields->Set("short_message", "(" + CompatUtility::GetHostStateString(host) + ")"); + fields->Set("short_message", output); } fields->Set("_state", service ? Service::StateToString(service->GetState()) : Host::StateToString(host->GetState())); From 7a012c062a0099322a3fa12265c7164f1445c992 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 21 Dec 2017 09:24:04 +0100 Subject: [PATCH 25/33] Move CompatUtility::GetHostStateString() logic into DB IDO and CompatLogger features --- lib/compat/compatlogger.cpp | 18 +++++++++++++----- lib/compat/compatlogger.hpp | 2 ++ lib/db_ido/dbevents.cpp | 10 +++++++++- lib/db_ido/dbevents.hpp | 1 + lib/icinga/compatutility.cpp | 9 --------- lib/icinga/compatutility.hpp | 3 --- 6 files changed, 25 insertions(+), 18 deletions(-) diff --git a/lib/compat/compatlogger.cpp b/lib/compat/compatlogger.cpp index 498b434f3..253a557e2 100644 --- a/lib/compat/compatlogger.cpp +++ b/lib/compat/compatlogger.cpp @@ -142,7 +142,7 @@ void CompatLogger::CheckResultHandler(const Checkable::Ptr& checkable, const Che msgbuf << "HOST ALERT: " << host->GetName() << ";" - << CompatUtility::GetHostStateString(host) << ";" + << GetHostStateString(host) << ";" << Host::StateTypeToString(host->GetStateType()) << ";" << attempt_after << ";" << output << "" @@ -258,7 +258,7 @@ void CompatLogger::NotificationSentHandler(const Notification::Ptr& notification if (service) notification_type_str = Service::StateToString(service->GetState()); else - notification_type_str = CompatUtility::GetHostStateString(host); + notification_type_str = GetHostStateString(host); } String author_comment = ""; @@ -290,7 +290,7 @@ void CompatLogger::NotificationSentHandler(const Notification::Ptr& notification << user->GetName() << ";" << host->GetName() << ";" << notification_type_str << " " - << "(" << CompatUtility::GetHostStateString(host) << ");" + << "(" << GetHostStateString(host) << ");" << command_name << ";" << output << ";" << author_comment @@ -422,7 +422,7 @@ void CompatLogger::EventCommandHandler(const Checkable::Ptr& checkable) } else { msgbuf << "HOST EVENT HANDLER: " << host->GetName() << ";" - << CompatUtility::GetHostStateString(host) << ";" + << GetHostStateString(host) << ";" << Host::StateTypeToString(host->GetStateType()) << ";" << current_attempt << ";" << event_command_name; @@ -435,6 +435,14 @@ void CompatLogger::EventCommandHandler(const Checkable::Ptr& checkable) } } +String CompatLogger::GetHostStateString(const Host::Ptr& host) +{ + if (host->GetState() != HostUp && !host->IsReachable()) + return "UNREACHABLE"; /* hardcoded compat state */ + + return Host::StateToString(host->GetState()); +} + void CompatLogger::WriteLine(const String& line) { ASSERT(OwnsLock()); @@ -499,7 +507,7 @@ void CompatLogger::ReopenFile(bool rotate) std::ostringstream msgbuf; msgbuf << "CURRENT HOST STATE: " << host->GetName() << ";" - << CompatUtility::GetHostStateString(host) << ";" + << GetHostStateString(host) << ";" << Host::StateTypeToString(host->GetStateType()) << ";" << host->GetCheckAttempt() << ";" << output << ""; diff --git a/lib/compat/compatlogger.hpp b/lib/compat/compatlogger.hpp index f12ae2e4a..1665b19ab 100644 --- a/lib/compat/compatlogger.hpp +++ b/lib/compat/compatlogger.hpp @@ -62,6 +62,8 @@ private: void ExternalCommandHandler(const String& command, const std::vector& arguments); void EventCommandHandler(const Checkable::Ptr& service); + static String GetHostStateString(const Host::Ptr& host); + Timer::Ptr m_RotationTimer; void RotationTimerHandler(); void ScheduleNextRotation(); diff --git a/lib/db_ido/dbevents.cpp b/lib/db_ido/dbevents.cpp index b2f2ba012..a0ec3e441 100644 --- a/lib/db_ido/dbevents.cpp +++ b/lib/db_ido/dbevents.cpp @@ -1025,7 +1025,7 @@ void DbEvents::AddCheckResultLogHistory(const Checkable::Ptr& checkable, const C } else { msgbuf << "HOST ALERT: " << host->GetName() << ";" - << CompatUtility::GetHostStateString(host) << ";" + << GetHostStateString(host) << ";" << Host::StateTypeToString(host->GetStateType()) << ";" << attempt_after << ";" << output << "" @@ -1522,6 +1522,14 @@ int DbEvents::GetHostState(const Host::Ptr& host) return currentState; } +String DbEvents::GetHostStateString(const Host::Ptr& host) +{ + if (host->GetState() != HostUp && !host->IsReachable()) + return "UNREACHABLE"; /* hardcoded compat state */ + + return Host::StateToString(host->GetState()); +} + std::pair DbEvents::ConvertTimestamp(double time) { unsigned long time_sec = static_cast(time); diff --git a/lib/db_ido/dbevents.hpp b/lib/db_ido/dbevents.hpp index 91705e381..3e27d2960 100644 --- a/lib/db_ido/dbevents.hpp +++ b/lib/db_ido/dbevents.hpp @@ -134,6 +134,7 @@ private: static void EnableChangedHandlerInternal(const Checkable::Ptr& checkable, const String& fieldName, bool enabled); static int GetHostState(const Host::Ptr& host); + static String GetHostStateString(const Host::Ptr& host); static std::pair ConvertTimestamp(double time); static int MapNotificationReasonType(NotificationType type); static int MapExternalCommandType(const String& name); diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 6cb6f9b12..93b39b3b6 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -81,15 +81,6 @@ String CompatUtility::GetCommandName(const Command::Ptr& command) return GetCommandNamePrefix(command) + command->GetName(); } -/* Used in StatusDataWriter and DB IDO. */ -String CompatUtility::GetHostStateString(const Host::Ptr& host) -{ - if (host->GetState() != HostUp && !host->IsReachable()) - return "UNREACHABLE"; /* hardcoded compat state */ - - return Host::StateToString(host->GetState()); -} - /* Used in DB IDO, StatusDataWriter and Livestatus. */ String CompatUtility::GetCheckableCommandArgs(const Checkable::Ptr& checkable) { diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 98e71a8d7..859f4509f 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -39,9 +39,6 @@ public: static String GetCommandLine(const Command::Ptr& command); static String GetCommandName(const Command::Ptr& command); - /* host */ - static String GetHostStateString(const Host::Ptr& host); - /* service */ static String GetCheckableCommandArgs(const Checkable::Ptr& checkable); From 9de233630a7d6a2275667a06e223f7e6b0e07675 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 21 Dec 2017 09:36:51 +0100 Subject: [PATCH 26/33] Move CompatUtility::GetCheckableInNotificationPeriod() logic into Livestatus feature --- lib/icinga/compatutility.cpp | 13 ------------- lib/icinga/compatutility.hpp | 2 -- lib/livestatus/hoststable.cpp | 9 ++++++++- lib/livestatus/servicestable.cpp | 9 ++++++++- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 93b39b3b6..3eb0dc573 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -147,19 +147,6 @@ String CompatUtility::GetCheckableCommandArgs(const Checkable::Ptr& checkable) return Empty; } -/* Used in Livestatus. */ -int CompatUtility::GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable) -{ - for (const Notification::Ptr& notification : checkable->GetNotifications()) { - TimePeriod::Ptr timeperiod = notification->GetPeriod(); - - if (!timeperiod || timeperiod->IsInside(Utility::GetTime())) - return 1; - } - - return 0; -} - /* Used in DB IDO, StatusDataWriter and Livestatus. */ int CompatUtility::GetCheckableNotificationLastNotification(const Checkable::Ptr& checkable) { diff --git a/lib/icinga/compatutility.hpp b/lib/icinga/compatutility.hpp index 859f4509f..388cdcb05 100644 --- a/lib/icinga/compatutility.hpp +++ b/lib/icinga/compatutility.hpp @@ -42,8 +42,6 @@ public: /* service */ static String GetCheckableCommandArgs(const Checkable::Ptr& checkable); - static int GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable); - /* notification */ static int GetCheckableNotificationsEnabled(const Checkable::Ptr& checkable); static int GetCheckableNotificationLastNotification(const Checkable::Ptr& checkable); diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index 6e637c258..b4ba38fe8 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -879,7 +879,14 @@ Value HostsTable::InNotificationPeriodAccessor(const Value& row) if (!host) return Empty; - return CompatUtility::GetCheckableInNotificationPeriod(host); + for (const Notification::Ptr& notification : host->GetNotifications()) { + TimePeriod::Ptr timeperiod = notification->GetPeriod(); + + if (!timeperiod || timeperiod->IsInside(Utility::GetTime())) + return 1; + } + + return 0; } Value HostsTable::InCheckPeriodAccessor(const Value& row) diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index b0c70ce32..2dcd9db9a 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -916,7 +916,14 @@ Value ServicesTable::InNotificationPeriodAccessor(const Value& row) if (!service) return Empty; - return CompatUtility::GetCheckableInNotificationPeriod(service); + for (const Notification::Ptr& notification : service->GetNotifications()) { + TimePeriod::Ptr timeperiod = notification->GetPeriod(); + + if (!timeperiod || timeperiod->IsInside(Utility::GetTime())) + return 1; + } + + return 0; } Value ServicesTable::ContactsAccessor(const Value& row) From e5462ea3d17b43cd3a22e8a3065ebe47c43d1869 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 21 Dec 2017 09:41:49 +0100 Subject: [PATCH 27/33] DB IDO: Remove check_command_args column The populated value is not entirely correct, and pulls in lots of compat code. --- lib/db_ido/hostdbobject.cpp | 1 - lib/db_ido/servicedbobject.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index b77aeb4c9..e5ba614f4 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -62,7 +62,6 @@ Dictionary::Ptr HostDbObject::GetConfigFields() const fields->Set("address6", host->GetAddress6()); fields->Set("check_command_object_id", host->GetCheckCommand()); - fields->Set("check_command_args", CompatUtility::GetCheckableCommandArgs(host)); fields->Set("eventhandler_command_object_id", host->GetEventCommand()); fields->Set("eventhandler_command_args", Empty); fields->Set("notification_timeperiod_object_id", Empty); diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index e8d3cc2de..5012465d9 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -57,7 +57,6 @@ Dictionary::Ptr ServiceDbObject::GetConfigFields() const fields->Set("host_object_id", host); fields->Set("display_name", service->GetDisplayName()); fields->Set("check_command_object_id", service->GetCheckCommand()); - fields->Set("check_command_args", CompatUtility::GetCheckableCommandArgs(service)); fields->Set("eventhandler_command_object_id", service->GetEventCommand()); fields->Set("eventhandler_command_args", Empty); fields->Set("notification_timeperiod_object_id", Empty); From d672df3f2cfee08ef923750a67aa91c07a82eaba Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 21 Dec 2017 09:57:21 +0100 Subject: [PATCH 28/33] DB IDO: Don't send empty columns in queries --- lib/db_ido/dbevents.cpp | 1 - lib/db_ido/hostdbobject.cpp | 15 --------------- lib/db_ido/servicedbobject.cpp | 13 ------------- 3 files changed, 29 deletions(-) diff --git a/lib/db_ido/dbevents.cpp b/lib/db_ido/dbevents.cpp index a0ec3e441..9dc50a954 100644 --- a/lib/db_ido/dbevents.cpp +++ b/lib/db_ido/dbevents.cpp @@ -1405,7 +1405,6 @@ void DbEvents::AddCheckableCheckHistory(const Checkable::Ptr& checkable, const C 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", CompatUtility::GetCommandLine(checkable->GetCheckCommand())); fields1->Set("execution_time", Convert::ToString(execution_time)); fields1->Set("latency", Convert::ToString(cr->CalculateLatency())); diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index e5ba614f4..62fcefe09 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -63,16 +63,11 @@ Dictionary::Ptr HostDbObject::GetConfigFields() const fields->Set("check_command_object_id", host->GetCheckCommand()); fields->Set("eventhandler_command_object_id", host->GetEventCommand()); - fields->Set("eventhandler_command_args", Empty); - fields->Set("notification_timeperiod_object_id", Empty); fields->Set("check_timeperiod_object_id", host->GetCheckPeriod()); - fields->Set("failure_prediction_options", Empty); fields->Set("check_interval", (host->GetCheckInterval() / 60.0)); fields->Set("retry_interval", (host->GetRetryInterval() / 60.0)); fields->Set("max_check_attempts", host->GetMaxCheckAttempts()); - fields->Set("first_notification_delay", Empty); - fields->Set("notification_interval", CompatUtility::GetCheckableNotificationNotificationInterval(host)); unsigned long notificationStateFilter = CompatUtility::GetCheckableNotificationTypeFilter(host); @@ -86,14 +81,7 @@ Dictionary::Ptr HostDbObject::GetConfigFields() const fields->Set("notify_on_downtime", (notificationTypeFilter & NotificationDowntimeStart) || (notificationTypeFilter & NotificationDowntimeEnd) || (notificationTypeFilter & NotificationDowntimeRemoved)); - fields->Set("stalk_on_up", Empty); - fields->Set("stalk_on_down", Empty); - fields->Set("stalk_on_unreachable", Empty); - fields->Set("flap_detection_enabled", host->GetEnableFlapping()); - 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", host->GetFlappingThresholdLow()); fields->Set("high_flap_threshold", host->GetFlappingThresholdLow()); @@ -161,7 +149,6 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const 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", host->GetEnableNotifications()); fields->Set("problem_has_been_acknowledged", host->GetAcknowledgement() != AcknowledgementNone); fields->Set("acknowledgement_type", host->GetAcknowledgement()); @@ -179,9 +166,7 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const } fields->Set("scheduled_downtime_depth", host->GetDowntimeDepth()); - fields->Set("failure_prediction_enabled", Empty); fields->Set("process_performance_data", host->GetEnablePerfdata()); - fields->Set("obsess_over_host", Empty); fields->Set("normal_check_interval", (host->GetCheckInterval() / 60.0)); fields->Set("retry_check_interval", (host->GetRetryInterval() / 60.0)); fields->Set("check_timeperiod_object_id", host->GetCheckPeriod()); diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 5012465d9..e6f674d84 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -58,14 +58,10 @@ Dictionary::Ptr ServiceDbObject::GetConfigFields() const fields->Set("display_name", service->GetDisplayName()); fields->Set("check_command_object_id", service->GetCheckCommand()); fields->Set("eventhandler_command_object_id", service->GetEventCommand()); - fields->Set("eventhandler_command_args", Empty); - fields->Set("notification_timeperiod_object_id", Empty); fields->Set("check_timeperiod_object_id", service->GetCheckPeriod()); - fields->Set("failure_prediction_options", Empty); fields->Set("check_interval", (service->GetCheckInterval() / 60.0)); fields->Set("retry_interval", (service->GetRetryInterval() / 60.0)); fields->Set("max_check_attempts", service->GetMaxCheckAttempts()); - fields->Set("first_notification_delay", Empty); fields->Set("notification_interval", CompatUtility::GetCheckableNotificationNotificationInterval(service)); unsigned long notificationStateFilter = CompatUtility::GetCheckableNotificationTypeFilter(service); @@ -86,10 +82,6 @@ Dictionary::Ptr ServiceDbObject::GetConfigFields() const fields->Set("stalk_on_critical", 0); fields->Set("is_volatile", service->GetVolatile()); fields->Set("flap_detection_enabled", service->GetEnableFlapping()); - 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", service->GetFlappingThresholdLow()); fields->Set("high_flap_threshold", service->GetFlappingThresholdLow()); fields->Set("process_performance_data", service->GetEnablePerfdata()); @@ -98,11 +90,7 @@ Dictionary::Ptr ServiceDbObject::GetConfigFields() const fields->Set("event_handler_enabled", service->GetEnableEventHandler()); fields->Set("passive_checks_enabled", service->GetEnablePassiveChecks()); fields->Set("active_checks_enabled", service->GetEnableActiveChecks()); - fields->Set("retain_status_information", Empty); - fields->Set("retain_nonstatus_information", Empty); fields->Set("notifications_enabled", service->GetEnableNotifications()); - fields->Set("obsess_over_service", Empty); - fields->Set("failure_prediction_enabled", Empty); fields->Set("notes", service->GetNotes()); fields->Set("notes_url", service->GetNotesUrl()); fields->Set("action_url", service->GetActionUrl()); @@ -146,7 +134,6 @@ Dictionary::Ptr ServiceDbObject::GetStatusFields() const fields->Set("state_type", service->GetStateType()); 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", service->GetEnableNotifications()); fields->Set("problem_has_been_acknowledged", service->GetAcknowledgement() != AcknowledgementNone); fields->Set("acknowledgement_type", service->GetAcknowledgement()); From 636cf62d3a5126e2b6d7da202e13b5ae6600099e Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 21 Dec 2017 10:32:39 +0100 Subject: [PATCH 29/33] DB IDO: Clean up code and group CompatUtility calls --- lib/db_ido/hostdbobject.cpp | 73 +++++++++++++--------------------- lib/db_ido/servicedbobject.cpp | 61 ++++++++++++---------------- 2 files changed, 52 insertions(+), 82 deletions(-) diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 62fcefe09..9136ed58a 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -60,18 +60,32 @@ Dictionary::Ptr HostDbObject::GetConfigFields() const fields->Set("display_name", displayName); fields->Set("address", host->GetAddress()); fields->Set("address6", host->GetAddress6()); - fields->Set("check_command_object_id", host->GetCheckCommand()); fields->Set("eventhandler_command_object_id", host->GetEventCommand()); fields->Set("check_timeperiod_object_id", host->GetCheckPeriod()); fields->Set("check_interval", (host->GetCheckInterval() / 60.0)); fields->Set("retry_interval", (host->GetRetryInterval() / 60.0)); fields->Set("max_check_attempts", host->GetMaxCheckAttempts()); + fields->Set("flap_detection_enabled", host->GetEnableFlapping()); + fields->Set("low_flap_threshold", host->GetFlappingThresholdLow()); + fields->Set("high_flap_threshold", host->GetFlappingThresholdLow()); + fields->Set("process_performance_data", host->GetEnablePerfdata()); + fields->Set("freshness_checks_enabled", 1); + fields->Set("freshness_threshold", Convert::ToLong(host->GetCheckInterval())); + fields->Set("event_handler_enabled", host->GetEnableEventHandler()); + fields->Set("passive_checks_enabled", host->GetEnablePassiveChecks()); + fields->Set("active_checks_enabled", host->GetEnableActiveChecks()); + fields->Set("notifications_enabled", host->GetEnableNotifications()); + fields->Set("notes", host->GetNotes()); + fields->Set("notes_url", host->GetNotesUrl()); + fields->Set("action_url", host->GetActionUrl()); + fields->Set("icon_image", host->GetIconImage()); + fields->Set("icon_image_alt", host->GetIconImageAlt()); fields->Set("notification_interval", CompatUtility::GetCheckableNotificationNotificationInterval(host)); - unsigned long notificationStateFilter = CompatUtility::GetCheckableNotificationTypeFilter(host); - unsigned long notificationTypeFilter = CompatUtility::GetCheckableNotificationTypeFilter(host); + unsigned long notificationStateFilter = CompatUtility::GetCheckableNotificationTypeFilter(host); + unsigned long notificationTypeFilter = CompatUtility::GetCheckableNotificationTypeFilter(host); fields->Set("notify_on_down", (notificationStateFilter & ServiceWarning) || (notificationStateFilter && ServiceCritical)); fields->Set("notify_on_unreachable", 1); /* We don't have this filter and state, and as such we don't filter such notifications. */ @@ -81,32 +95,6 @@ Dictionary::Ptr HostDbObject::GetConfigFields() const fields->Set("notify_on_downtime", (notificationTypeFilter & NotificationDowntimeStart) || (notificationTypeFilter & NotificationDowntimeEnd) || (notificationTypeFilter & NotificationDowntimeRemoved)); - fields->Set("flap_detection_enabled", host->GetEnableFlapping()); - fields->Set("low_flap_threshold", host->GetFlappingThresholdLow()); - fields->Set("high_flap_threshold", host->GetFlappingThresholdLow()); - - fields->Set("process_performance_data", host->GetEnablePerfdata()); - - fields->Set("freshness_checks_enabled", 1); - fields->Set("freshness_threshold", Convert::ToLong(host->GetCheckInterval())); - fields->Set("event_handler_enabled", host->GetEnableEventHandler()); - fields->Set("passive_checks_enabled", host->GetEnablePassiveChecks()); - fields->Set("active_checks_enabled", host->GetEnableActiveChecks()); - - fields->Set("retain_status_information", 1); - fields->Set("retain_nonstatus_information", 1); - - fields->Set("notifications_enabled", host->GetEnableNotifications()); - - fields->Set("obsess_over_host", 0); - fields->Set("failure_prediction_enabled", 0); - - fields->Set("notes", host->GetNotes()); - fields->Set("notes_url", host->GetNotesUrl()); - fields->Set("action_url", host->GetActionUrl()); - fields->Set("icon_image", host->GetIconImage()); - fields->Set("icon_image_alt", host->GetIconImageAlt()); - return fields; } @@ -122,6 +110,8 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const fields->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr)); fields->Set("perfdata", PluginUtility::FormatPerfdata(cr->GetPerformanceData())); fields->Set("check_source", cr->GetCheckSource()); + fields->Set("latency", cr->CalculateLatency()); + fields->Set("execution_time", cr->CalculateExecutionTime()); } int currentState = host->GetState(); @@ -134,46 +124,37 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const fields->Set("should_be_scheduled", host->GetEnableActiveChecks()); 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("last_check", DbValue::FromTimestamp(host->GetLastCheck())); fields->Set("next_check", DbValue::FromTimestamp(host->GetNextCheck())); fields->Set("check_type", !host->GetEnableActiveChecks()); /* 0 .. active, 1 .. passive */ fields->Set("last_state_change", DbValue::FromTimestamp(host->GetLastStateChange())); fields->Set("last_hard_state_change", DbValue::FromTimestamp(host->GetLastHardStateChange())); fields->Set("last_hard_state", host->GetLastHardState()); - fields->Set("last_time_up", DbValue::FromTimestamp(static_cast(host->GetLastStateUp()))); - fields->Set("last_time_down", DbValue::FromTimestamp(static_cast(host->GetLastStateDown()))); - fields->Set("last_time_unreachable", DbValue::FromTimestamp(static_cast(host->GetLastStateUnreachable()))); + fields->Set("last_time_up", DbValue::FromTimestamp(host->GetLastStateUp())); + fields->Set("last_time_down", DbValue::FromTimestamp(host->GetLastStateDown())); + fields->Set("last_time_unreachable", DbValue::FromTimestamp(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("notifications_enabled", host->GetEnableNotifications()); fields->Set("problem_has_been_acknowledged", host->GetAcknowledgement() != AcknowledgementNone); fields->Set("acknowledgement_type", host->GetAcknowledgement()); - fields->Set("current_notification_number", CompatUtility::GetCheckableNotificationNotificationNumber(host)); fields->Set("passive_checks_enabled", host->GetEnablePassiveChecks()); fields->Set("active_checks_enabled", host->GetEnableActiveChecks()); fields->Set("event_handler_enabled", host->GetEnableEventHandler()); fields->Set("flap_detection_enabled", host->GetEnableFlapping()); fields->Set("is_flapping", host->IsFlapping()); fields->Set("percent_state_change", host->GetFlappingCurrent()); - - if (cr) { - fields->Set("latency", Convert::ToString(cr->CalculateLatency())); - fields->Set("execution_time", Convert::ToString(cr->CalculateExecutionTime())); - } - fields->Set("scheduled_downtime_depth", host->GetDowntimeDepth()); fields->Set("process_performance_data", host->GetEnablePerfdata()); fields->Set("normal_check_interval", (host->GetCheckInterval() / 60.0)); fields->Set("retry_check_interval", (host->GetRetryInterval() / 60.0)); fields->Set("check_timeperiod_object_id", host->GetCheckPeriod()); fields->Set("is_reachable", host->IsReachable()); - fields->Set("original_attributes", JsonEncode(host->GetOriginalAttributes())); + fields->Set("current_notification_number", CompatUtility::GetCheckableNotificationNotificationNumber(host)); + fields->Set("last_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationLastNotification(host))); + fields->Set("next_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationNextNotification(host))); + EventCommand::Ptr eventCommand = host->GetEventCommand(); if (eventCommand) diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index e6f674d84..b48cbf757 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -62,24 +62,6 @@ Dictionary::Ptr ServiceDbObject::GetConfigFields() const fields->Set("check_interval", (service->GetCheckInterval() / 60.0)); fields->Set("retry_interval", (service->GetRetryInterval() / 60.0)); fields->Set("max_check_attempts", service->GetMaxCheckAttempts()); - fields->Set("notification_interval", CompatUtility::GetCheckableNotificationNotificationInterval(service)); - - unsigned long notificationStateFilter = CompatUtility::GetCheckableNotificationTypeFilter(service); - unsigned long notificationTypeFilter = CompatUtility::GetCheckableNotificationTypeFilter(service); - - fields->Set("notify_on_warning", notificationStateFilter & ServiceWarning); - fields->Set("notify_on_unknown", notificationStateFilter & ServiceUnknown); - fields->Set("notify_on_critical", notificationStateFilter & ServiceCritical); - fields->Set("notify_on_recovery", notificationTypeFilter & NotificationRecovery); - fields->Set("notify_on_flapping", (notificationTypeFilter & NotificationFlappingStart) || - (notificationTypeFilter & NotificationFlappingEnd)); - fields->Set("notify_on_downtime", (notificationTypeFilter & NotificationDowntimeStart) || - (notificationTypeFilter & NotificationDowntimeEnd) || (notificationTypeFilter & NotificationDowntimeRemoved)); - - 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", service->GetVolatile()); fields->Set("flap_detection_enabled", service->GetEnableFlapping()); fields->Set("low_flap_threshold", service->GetFlappingThresholdLow()); @@ -97,6 +79,20 @@ Dictionary::Ptr ServiceDbObject::GetConfigFields() const fields->Set("icon_image", service->GetIconImage()); fields->Set("icon_image_alt", service->GetIconImageAlt()); + fields->Set("notification_interval", CompatUtility::GetCheckableNotificationNotificationInterval(service)); + + unsigned long notificationStateFilter = CompatUtility::GetCheckableNotificationTypeFilter(service); + unsigned long notificationTypeFilter = CompatUtility::GetCheckableNotificationTypeFilter(service); + + fields->Set("notify_on_warning", notificationStateFilter & ServiceWarning); + fields->Set("notify_on_unknown", notificationStateFilter & ServiceUnknown); + fields->Set("notify_on_critical", notificationStateFilter & ServiceCritical); + fields->Set("notify_on_recovery", notificationTypeFilter & NotificationRecovery); + fields->Set("notify_on_flapping", (notificationTypeFilter & NotificationFlappingStart) || + (notificationTypeFilter & NotificationFlappingEnd)); + fields->Set("notify_on_downtime", (notificationTypeFilter & NotificationDowntimeStart) || + (notificationTypeFilter & NotificationDowntimeEnd) || (notificationTypeFilter & NotificationDowntimeRemoved)); + return fields; } @@ -111,6 +107,8 @@ Dictionary::Ptr ServiceDbObject::GetStatusFields() const fields->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr)); fields->Set("perfdata", PluginUtility::FormatPerfdata(cr->GetPerformanceData())); fields->Set("check_source", cr->GetCheckSource()); + fields->Set("latency", cr->CalculateLatency()); + fields->Set("execution_time", cr->CalculateExecutionTime()); } fields->Set("current_state", service->GetState()); @@ -118,47 +116,38 @@ Dictionary::Ptr ServiceDbObject::GetStatusFields() const fields->Set("should_be_scheduled", service->GetEnableActiveChecks()); 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("last_check", DbValue::FromTimestamp(service->GetLastCheck())); fields->Set("next_check", DbValue::FromTimestamp(service->GetNextCheck())); fields->Set("check_type", !service->GetEnableActiveChecks()); /* 0 .. active, 1 .. passive */ fields->Set("last_state_change", DbValue::FromTimestamp(service->GetLastStateChange())); fields->Set("last_hard_state_change", DbValue::FromTimestamp(service->GetLastHardStateChange())); fields->Set("last_hard_state", service->GetLastHardState()); - fields->Set("last_time_ok", DbValue::FromTimestamp(static_cast(service->GetLastStateOK()))); - fields->Set("last_time_warning", DbValue::FromTimestamp(static_cast(service->GetLastStateWarning()))); - fields->Set("last_time_critical", DbValue::FromTimestamp(static_cast(service->GetLastStateCritical()))); - fields->Set("last_time_unknown", DbValue::FromTimestamp(static_cast(service->GetLastStateUnknown()))); + fields->Set("last_time_ok", DbValue::FromTimestamp(service->GetLastStateOK())); + fields->Set("last_time_warning", DbValue::FromTimestamp(service->GetLastStateWarning())); + fields->Set("last_time_critical", DbValue::FromTimestamp(service->GetLastStateCritical())); + fields->Set("last_time_unknown", DbValue::FromTimestamp(service->GetLastStateUnknown())); fields->Set("state_type", service->GetStateType()); - fields->Set("last_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationLastNotification(service))); - fields->Set("next_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationNextNotification(service))); fields->Set("notifications_enabled", service->GetEnableNotifications()); fields->Set("problem_has_been_acknowledged", service->GetAcknowledgement() != AcknowledgementNone); fields->Set("acknowledgement_type", service->GetAcknowledgement()); - fields->Set("current_notification_number", CompatUtility::GetCheckableNotificationNotificationNumber(service)); fields->Set("passive_checks_enabled", service->GetEnablePassiveChecks()); fields->Set("active_checks_enabled", service->GetEnableActiveChecks()); fields->Set("event_handler_enabled", service->GetEnableEventHandler()); fields->Set("flap_detection_enabled", service->GetEnableFlapping()); fields->Set("is_flapping", service->IsFlapping()); fields->Set("percent_state_change", service->GetFlappingCurrent()); - - if (cr) { - fields->Set("latency", Convert::ToString(cr->CalculateLatency())); - fields->Set("execution_time", Convert::ToString(cr->CalculateExecutionTime())); - } - fields->Set("scheduled_downtime_depth", service->GetDowntimeDepth()); fields->Set("process_performance_data", service->GetEnablePerfdata()); fields->Set("normal_check_interval", (service->GetCheckInterval() / 60.0)); fields->Set("retry_check_interval", (service->GetRetryInterval() / 60.0)); fields->Set("check_timeperiod_object_id", service->GetCheckPeriod()); fields->Set("is_reachable", service->IsReachable()); - fields->Set("original_attributes", JsonEncode(service->GetOriginalAttributes())); + fields->Set("current_notification_number", CompatUtility::GetCheckableNotificationNotificationNumber(service)); + fields->Set("last_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationLastNotification(service))); + fields->Set("next_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationNextNotification(service))); + EventCommand::Ptr eventCommand = service->GetEventCommand(); if (eventCommand) From 4da3a507111dd2e20a2daa005cf80de3280d2d04 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 21 Dec 2017 12:00:42 +0100 Subject: [PATCH 30/33] Clean up DB IDO events code --- lib/db_ido/dbevents.cpp | 518 +++++++++++++++++++--------------------- 1 file changed, 240 insertions(+), 278 deletions(-) diff --git a/lib/db_ido/dbevents.cpp b/lib/db_ido/dbevents.cpp index 9dc50a954..1e5ec1bd2 100644 --- a/lib/db_ido/dbevents.cpp +++ b/lib/db_ido/dbevents.cpp @@ -96,10 +96,15 @@ void DbEvents::NextCheckUpdatedHandler(const Checkable::Ptr& checkable) tie(host, service) = GetHostService(checkable); DbQuery query1; - if (service) + query1.WhereCriteria = new Dictionary(); + + if (service) { query1.Table = "servicestatus"; - else + query1.WhereCriteria->Set("service_object_id", service); + } else { query1.Table = "hoststatus"; + query1.WhereCriteria->Set("host_object_id", host); + } query1.Type = DbQueryUpdate; query1.Category = DbCatState; @@ -111,12 +116,6 @@ void DbEvents::NextCheckUpdatedHandler(const Checkable::Ptr& checkable) query1.Fields = fields1; - query1.WhereCriteria = new Dictionary(); - if (service) - query1.WhereCriteria->Set("service_object_id", service); - else - query1.WhereCriteria->Set("host_object_id", host); - DbObject::OnQuery(query1); } @@ -127,10 +126,15 @@ void DbEvents::FlappingChangedHandler(const Checkable::Ptr& checkable) tie(host, service) = GetHostService(checkable); DbQuery query1; - if (service) + query1.WhereCriteria = new Dictionary(); + + if (service) { query1.Table = "servicestatus"; - else + query1.WhereCriteria->Set("service_object_id", service); + } else { query1.Table = "hoststatus"; + query1.WhereCriteria->Set("host_object_id", host); + } query1.Type = DbQueryUpdate; query1.Category = DbCatState; @@ -142,13 +146,6 @@ void DbEvents::FlappingChangedHandler(const Checkable::Ptr& checkable) fields1->Set("percent_state_change", checkable->GetFlappingCurrent()); query1.Fields = fields1; - - query1.WhereCriteria = new Dictionary(); - if (service) - query1.WhereCriteria->Set("service_object_id", service); - else - query1.WhereCriteria->Set("host_object_id", host); - query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ DbObject::OnQuery(query1); @@ -157,17 +154,22 @@ void DbEvents::FlappingChangedHandler(const Checkable::Ptr& checkable) void DbEvents::LastNotificationChangedHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable) { std::pair now_bag = ConvertTimestamp(Utility::GetTime()); - std::pair time_bag = ConvertTimestamp(notification->GetNextNotification()); + std::pair timeBag = ConvertTimestamp(notification->GetNextNotification()); Host::Ptr host; Service::Ptr service; tie(host, service) = GetHostService(checkable); DbQuery query1; - if (service) + query1.WhereCriteria = new Dictionary(); + + if (service) { query1.Table = "servicestatus"; - else + query1.WhereCriteria->Set("service_object_id", service); + } else { query1.Table = "hoststatus"; + query1.WhereCriteria->Set("host_object_id", host); + } query1.Type = DbQueryUpdate; query1.Category = DbCatState; @@ -176,17 +178,10 @@ void DbEvents::LastNotificationChangedHandler(const Notification::Ptr& notificat Dictionary::Ptr fields1 = new Dictionary(); fields1->Set("last_notification", DbValue::FromTimestamp(now_bag.first)); - fields1->Set("next_notification", DbValue::FromTimestamp(time_bag.first)); + fields1->Set("next_notification", DbValue::FromTimestamp(timeBag.first)); fields1->Set("current_notification_number", notification->GetNotificationNumber()); query1.Fields = fields1; - - query1.WhereCriteria = new Dictionary(); - if (service) - query1.WhereCriteria->Set("service_object_id", service); - else - query1.WhereCriteria->Set("host_object_id", host); - query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ DbObject::OnQuery(query1); @@ -211,10 +206,15 @@ void DbEvents::ReachabilityChangedHandler(const Checkable::Ptr& checkable, const tie(host, service) = GetHostService(child); DbQuery query1; - if (service) + query1.WhereCriteria = new Dictionary(); + + if (service) { query1.Table = "servicestatus"; - else + query1.WhereCriteria->Set("service_object_id", service); + } else { query1.Table = "hoststatus"; + query1.WhereCriteria->Set("host_object_id", host); + } query1.Type = DbQueryUpdate; query1.Category = DbCatState; @@ -225,13 +225,6 @@ void DbEvents::ReachabilityChangedHandler(const Checkable::Ptr& checkable, const fields1->Set("is_reachable", is_reachable); query1.Fields = fields1; - - query1.WhereCriteria = new Dictionary(); - if (service) - query1.WhereCriteria->Set("service_object_id", service); - else - query1.WhereCriteria->Set("host_object_id", host); - query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ DbObject::OnQuery(query1); @@ -271,10 +264,15 @@ void DbEvents::EnableChangedHandlerInternal(const Checkable::Ptr& checkable, con tie(host, service) = GetHostService(checkable); DbQuery query1; - if (service) + query1.WhereCriteria = new Dictionary(); + + if (service) { query1.Table = "servicestatus"; - else + query1.WhereCriteria->Set("service_object_id", service); + } else { query1.Table = "hoststatus"; + query1.WhereCriteria->Set("host_object_id", host); + } query1.Type = DbQueryUpdate; query1.Category = DbCatState; @@ -283,14 +281,8 @@ void DbEvents::EnableChangedHandlerInternal(const Checkable::Ptr& checkable, con Dictionary::Ptr fields1 = new Dictionary(); fields1->Set(fieldName, enabled); + query1.Fields = fields1; - - query1.WhereCriteria = new Dictionary(); - if (service) - query1.WhereCriteria->Set("service_object_id", service); - else - query1.WhereCriteria->Set("host_object_id", host); - query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ DbObject::OnQuery(query1); @@ -329,44 +321,44 @@ void DbEvents::AddCommentInternal(std::vector& queries, const Comment:: { Checkable::Ptr checkable = comment->GetCheckable(); - unsigned long entry_time = static_cast(comment->GetEntryTime()); - unsigned long entry_time_usec = (comment->GetEntryTime() - entry_time) * 1000 * 1000; + std::pair timeBag = ConvertTimestamp(comment->GetEntryTime()); Dictionary::Ptr fields1 = new Dictionary(); - fields1->Set("entry_time", DbValue::FromTimestamp(entry_time)); - fields1->Set("entry_time_usec", entry_time_usec); + fields1->Set("entry_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("entry_time_usec", timeBag.second); fields1->Set("entry_type", comment->GetEntryType()); fields1->Set("object_id", checkable); - if (checkable->GetReflectionType() == Host::TypeInstance) { - fields1->Set("comment_type", 2); - /* requires idoutils 1.10 schema fix */ - fields1->Set("internal_comment_id", comment->GetLegacyId()); - } else if (checkable->GetReflectionType() == Service::TypeInstance) { - fields1->Set("comment_type", 1); - fields1->Set("internal_comment_id", comment->GetLegacyId()); - } else { + int commentType = 0; + + if (checkable->GetReflectionType() == Host::TypeInstance) + commentType = 2; + else if (checkable->GetReflectionType() == Service::TypeInstance) + commentType = 1; + else { Log(LogDebug, "DbEvents", "unknown object type for adding comment."); return; } + fields1->Set("comment_type", commentType); + fields1->Set("internal_comment_id", comment->GetLegacyId()); fields1->Set("name", comment->GetName()); - fields1->Set("comment_time", DbValue::FromTimestamp(entry_time)); /* same as entry_time */ + fields1->Set("comment_time", DbValue::FromTimestamp(timeBag.first)); /* same as entry_time */ fields1->Set("author_name", comment->GetAuthor()); fields1->Set("comment_data", comment->GetText()); - fields1->Set("is_persistent", comment->GetPersistent() ? 1 : 0); + fields1->Set("is_persistent", comment->GetPersistent()); fields1->Set("comment_source", 1); /* external */ - fields1->Set("expires", (comment->GetExpireTime() > 0) ? 1 : 0); + fields1->Set("expires", (comment->GetExpireTime() > 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(IcingaApplication::GetInstance()->GetNodeName()); - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); DbQuery query1; + if (!historical) { query1.Table = "comments"; query1.Type = DbQueryInsert | DbQueryUpdate; @@ -376,11 +368,12 @@ void DbEvents::AddCommentInternal(std::vector& queries, const Comment:: query1.WhereCriteria = new Dictionary(); query1.WhereCriteria->Set("object_id", checkable); query1.WhereCriteria->Set("name", comment->GetName()); - query1.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(entry_time)); + query1.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(timeBag.first)); } else { query1.Table = "commenthistory"; query1.Type = DbQueryInsert; } + query1.Category = DbCatComment; query1.Fields = fields1; queries.emplace_back(std::move(query1)); @@ -397,21 +390,22 @@ void DbEvents::RemoveCommentInternal(std::vector& queries, const Commen { Checkable::Ptr checkable = comment->GetCheckable(); - unsigned long entry_time = static_cast(comment->GetEntryTime()); + std::pair timeBag = ConvertTimestamp(comment->GetEntryTime()); /* Status */ DbQuery query1; query1.Table = "comments"; query1.Type = DbQueryDelete; query1.Category = DbCatComment; + query1.WhereCriteria = new Dictionary(); query1.WhereCriteria->Set("object_id", checkable); - query1.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(entry_time)); + query1.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(timeBag.first)); query1.WhereCriteria->Set("name", comment->GetName()); queries.emplace_back(std::move(query1)); /* History - update deletion time for service/host */ - std::pair time_bag = ConvertTimestamp(Utility::GetTime()); + std::pair timeBagNow = ConvertTimestamp(Utility::GetTime()); DbQuery query2; query2.Table = "commenthistory"; @@ -419,14 +413,15 @@ void DbEvents::RemoveCommentInternal(std::vector& queries, const Commen query2.Category = DbCatComment; Dictionary::Ptr fields2 = new Dictionary(); - fields2->Set("deletion_time", DbValue::FromTimestamp(time_bag.first)); - fields2->Set("deletion_time_usec", time_bag.second); + fields2->Set("deletion_time", DbValue::FromTimestamp(timeBagNow.first)); + fields2->Set("deletion_time_usec", timeBagNow.second); query2.Fields = fields2; query2.WhereCriteria = new Dictionary(); query2.WhereCriteria->Set("object_id", checkable); - query2.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(entry_time)); + query2.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(timeBag.first)); query2.WhereCriteria->Set("name", comment->GetName()); + queries.emplace_back(std::move(query2)); } @@ -466,22 +461,23 @@ void DbEvents::AddDowntimeInternal(std::vector& queries, const Downtime fields1->Set("entry_time", DbValue::FromTimestamp(downtime->GetEntryTime())); fields1->Set("object_id", checkable); - if (checkable->GetReflectionType() == Host::TypeInstance) { - fields1->Set("downtime_type", 2); - /* requires idoutils 1.10 schema fix */ - fields1->Set("internal_downtime_id", downtime->GetLegacyId()); - } else if (checkable->GetReflectionType() == Service::TypeInstance) { - fields1->Set("downtime_type", 1); - fields1->Set("internal_downtime_id", downtime->GetLegacyId()); - } else { + int downtimeType = 0; + + if (checkable->GetReflectionType() == Host::TypeInstance) + downtimeType = 2; + else if (checkable->GetReflectionType() == Service::TypeInstance) + downtimeType = 1; + else { Log(LogDebug, "DbEvents", "unknown object type for adding downtime."); return; } + fields1->Set("downtime_type", downtimeType); + fields1->Set("internal_downtime_id", downtime->GetLegacyId()); fields1->Set("author_name", downtime->GetAuthor()); fields1->Set("comment_data", downtime->GetComment()); fields1->Set("triggered_by_id", Downtime::GetByName(downtime->GetTriggeredBy())); - fields1->Set("is_fixed", downtime->GetFixed() ? 1 : 0); + 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())); @@ -489,19 +485,19 @@ void DbEvents::AddDowntimeInternal(std::vector& queries, const Downtime /* flexible downtimes are started at trigger time */ if (downtime->GetFixed()) { - std::pair time_bag = ConvertTimestamp(downtime->GetStartTime()); - fields1->Set("actual_start_time", DbValue::FromTimestamp(time_bag.first)); - fields1->Set("actual_start_time_usec", time_bag.second); + std::pair timeBag = ConvertTimestamp(downtime->GetStartTime()); + + fields1->Set("actual_start_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("actual_start_time_usec", timeBag.second); fields1->Set("was_started", ((downtime->GetStartTime() <= Utility::GetTime()) ? 1 : 0)); } - fields1->Set("is_in_effect", (downtime->IsInEffect() ? 1 : 0)); + fields1->Set("is_in_effect", downtime->IsInEffect()); 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(IcingaApplication::GetInstance()->GetNodeName()); - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); @@ -533,10 +529,15 @@ void DbEvents::AddDowntimeInternal(std::vector& queries, const Downtime tie(host, service) = GetHostService(checkable); DbQuery query2; - if (service) + query2.WhereCriteria = new Dictionary(); + + if (service) { query2.Table = "servicestatus"; - else + query2.WhereCriteria->Set("service_object_id", service); + } else { query2.Table = "hoststatus"; + query2.WhereCriteria->Set("host_object_id", host); + } query2.Type = DbQueryUpdate; query2.Category = DbCatState; @@ -547,14 +548,8 @@ void DbEvents::AddDowntimeInternal(std::vector& queries, const Downtime fields2->Set("scheduled_downtime_depth", checkable->GetDowntimeDepth()); query2.Fields = fields2; - - query2.WhereCriteria = new Dictionary(); - if (service) - query2.WhereCriteria->Set("service_object_id", service); - else - query2.WhereCriteria->Set("host_object_id", host); - query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ + queries.emplace_back(std::move(query2)); } } @@ -586,7 +581,7 @@ void DbEvents::RemoveDowntimeInternal(std::vector& queries, const Downt queries.emplace_back(std::move(query1)); /* History - update actual_end_time, was_cancelled for service (and host in case) */ - std::pair time_bag = ConvertTimestamp(Utility::GetTime()); + std::pair timeBag = ConvertTimestamp(Utility::GetTime()); DbQuery query3; query3.Table = "downtimehistory"; @@ -597,8 +592,8 @@ void DbEvents::RemoveDowntimeInternal(std::vector& queries, const Downt fields3->Set("was_cancelled", downtime->GetWasCancelled() ? 1 : 0); if (downtime->GetFixed() || (!downtime->GetFixed() && downtime->GetTriggerTime() > 0)) { - fields3->Set("actual_end_time", DbValue::FromTimestamp(time_bag.first)); - fields3->Set("actual_end_time_usec", time_bag.second); + fields3->Set("actual_end_time", DbValue::FromTimestamp(timeBag.first)); + fields3->Set("actual_end_time_usec", timeBag.second); } fields3->Set("is_in_effect", 0); @@ -619,10 +614,15 @@ void DbEvents::RemoveDowntimeInternal(std::vector& queries, const Downt tie(host, service) = GetHostService(checkable); DbQuery query4; - if (service) + query4.WhereCriteria = new Dictionary(); + + if (service) { query4.Table = "servicestatus"; - else + query4.WhereCriteria->Set("service_object_id", service); + } else { query4.Table = "hoststatus"; + query4.WhereCriteria->Set("host_object_id", host); + } query4.Type = DbQueryUpdate; query4.Category = DbCatState; @@ -633,14 +633,8 @@ void DbEvents::RemoveDowntimeInternal(std::vector& queries, const Downt fields4->Set("scheduled_downtime_depth", checkable->GetDowntimeDepth()); query4.Fields = fields4; - - query4.WhereCriteria = new Dictionary(); - if (service) - query4.WhereCriteria->Set("service_object_id", service); - else - query4.WhereCriteria->Set("host_object_id", host); - query4.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ + queries.emplace_back(std::move(query4)); } @@ -648,7 +642,7 @@ void DbEvents::TriggerDowntime(const Downtime::Ptr& downtime) { Checkable::Ptr checkable = downtime->GetCheckable(); - std::pair time_bag = ConvertTimestamp(Utility::GetTime()); + std::pair timeBag = ConvertTimestamp(Utility::GetTime()); /* Status */ DbQuery query1; @@ -658,8 +652,8 @@ void DbEvents::TriggerDowntime(const Downtime::Ptr& downtime) Dictionary::Ptr fields1 = new 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("actual_start_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("actual_start_time_usec", timeBag.second); fields1->Set("is_in_effect", (downtime->IsInEffect() ? 1 : 0)); fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime())); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ @@ -684,8 +678,8 @@ void DbEvents::TriggerDowntime(const Downtime::Ptr& downtime) Dictionary::Ptr fields3 = new 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("actual_start_time", DbValue::FromTimestamp(timeBag.first)); + fields3->Set("actual_start_time_usec", timeBag.second); fields3->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime())); query3.Fields = fields3; @@ -699,10 +693,15 @@ void DbEvents::TriggerDowntime(const Downtime::Ptr& downtime) tie(host, service) = GetHostService(checkable); DbQuery query4; - if (service) + query4.WhereCriteria = new Dictionary(); + + if (service) { query4.Table = "servicestatus"; - else + query4.WhereCriteria->Set("service_object_id", service); + } else { query4.Table = "hoststatus"; + query4.WhereCriteria->Set("host_object_id", host); + } query4.Type = DbQueryUpdate; query4.Category = DbCatState; @@ -713,13 +712,6 @@ void DbEvents::TriggerDowntime(const Downtime::Ptr& downtime) fields4->Set("scheduled_downtime_depth", checkable->GetDowntimeDepth()); query4.Fields = fields4; - - query4.WhereCriteria = new Dictionary(); - if (service) - query4.WhereCriteria->Set("service_object_id", service); - else - query4.WhereCriteria->Set("host_object_id", host); - query4.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ DbObject::OnQuery(query4); @@ -732,9 +724,7 @@ void DbEvents::AddAcknowledgementHistory(const Checkable::Ptr& checkable, const Log(LogDebug, "DbEvents") << "add acknowledgement history for '" << checkable->GetName() << "'"; - std::pair time_bag = ConvertTimestamp(Utility::GetTime()); - - unsigned long end_time = static_cast(expiry); + std::pair timeBag = ConvertTimestamp(Utility::GetTime()); DbQuery query1; query1.Table = "acknowledgements"; @@ -746,27 +736,26 @@ void DbEvents::AddAcknowledgementHistory(const Checkable::Ptr& checkable, const tie(host, service) = GetHostService(checkable); Dictionary::Ptr fields1 = new Dictionary(); - fields1->Set("entry_time", DbValue::FromTimestamp(time_bag.first)); - fields1->Set("entry_time_usec", time_bag.second); + + fields1->Set("entry_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("entry_time_usec", timeBag.second); fields1->Set("acknowledgement_type", type); fields1->Set("object_id", checkable); fields1->Set("author_name", author); fields1->Set("comment_data", comment); - fields1->Set("persistent_comment", 1); //always persistent - fields1->Set("notify_contacts", notify ? 1 : 0); - fields1->Set("is_sticky", type == AcknowledgementSticky ? 1 : 0); - fields1->Set("end_time", DbValue::FromTimestamp(end_time)); + fields1->Set("persistent_comment", 1); + fields1->Set("notify_contacts", notify); + fields1->Set("is_sticky", type == AcknowledgementSticky); + fields1->Set("end_time", DbValue::FromTimestamp(expiry)); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ - if (service) { + if (service) fields1->Set("state", service->GetState()); - } else { + else fields1->Set("state", GetHostState(host)); - } - String node = IcingaApplication::GetInstance()->GetNodeName(); + Endpoint::Ptr endpoint = Endpoint::GetByName(IcingaApplication::GetInstance()->GetNodeName()); - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); @@ -797,10 +786,15 @@ void DbEvents::AddAcknowledgementInternal(const Checkable::Ptr& checkable, Ackno tie(host, service) = GetHostService(checkable); DbQuery query1; - if (service) + query1.WhereCriteria = new Dictionary(); + + if (service) { query1.Table = "servicestatus"; - else + query1.WhereCriteria->Set("service_object_id", service); + } else { query1.Table = "hoststatus"; + query1.WhereCriteria->Set("host_object_id", host); + } query1.Type = DbQueryUpdate; query1.Category = DbCatState; @@ -810,14 +804,8 @@ void DbEvents::AddAcknowledgementInternal(const Checkable::Ptr& checkable, Ackno Dictionary::Ptr fields1 = new Dictionary(); fields1->Set("acknowledgement_type", type); fields1->Set("problem_has_been_acknowledged", add ? 1 : 0); + query1.Fields = fields1; - - query1.WhereCriteria = new Dictionary(); - if (service) - query1.WhereCriteria->Set("service_object_id", service); - else - query1.WhereCriteria->Set("host_object_id", host); - query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ DbObject::OnQuery(query1); @@ -831,7 +819,7 @@ void DbEvents::AddNotificationHistory(const Notification::Ptr& notification, con << "add notification history for '" << checkable->GetName() << "'"; /* start and end happen at the same time */ - std::pair time_bag = ConvertTimestamp(Utility::GetTime()); + std::pair timeBag = ConvertTimestamp(Utility::GetTime()); DbQuery query1; query1.Table = "notifications"; @@ -847,16 +835,15 @@ void DbEvents::AddNotificationHistory(const Notification::Ptr& notification, con fields1->Set("notification_type", 1); /* service */ fields1->Set("notification_reason", 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("start_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("start_time_usec", timeBag.second); + fields1->Set("end_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("end_time_usec", timeBag.second); - if (service) { + if (service) fields1->Set("state", service->GetState()); - } else { + else fields1->Set("state", GetHostState(host)); - } if (cr) { fields1->Set("output", CompatUtility::GetCheckResultOutput(cr)); @@ -867,9 +854,8 @@ void DbEvents::AddNotificationHistory(const Notification::Ptr& notification, con fields1->Set("contacts_notified", static_cast(users.size())); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ - String node = IcingaApplication::GetInstance()->GetNodeName(); + Endpoint::Ptr endpoint = Endpoint::GetByName(IcingaApplication::GetInstance()->GetNodeName()); - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); @@ -889,10 +875,10 @@ void DbEvents::AddNotificationHistory(const Notification::Ptr& notification, con Dictionary::Ptr fields2 = new 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("start_time", DbValue::FromTimestamp(timeBag.first)); + fields2->Set("start_time_usec", timeBag.second); + fields2->Set("end_time", DbValue::FromTimestamp(timeBag.first)); + fields2->Set("end_time_usec", timeBag.second); fields2->Set("notification_id", query1.NotificationInsertID); fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */ @@ -911,7 +897,7 @@ void DbEvents::AddStateChangeHistory(const Checkable::Ptr& checkable, const Chec << "add state change history for '" << checkable->GetName() << "'"; double ts = cr->GetExecutionEnd(); - std::pair state_time_bag = ConvertTimestamp(ts); + std::pair timeBag = ConvertTimestamp(ts); DbQuery query1; query1.Table = "statehistory"; @@ -923,8 +909,8 @@ void DbEvents::AddStateChangeHistory(const Checkable::Ptr& checkable, const Chec tie(host, service) = GetHostService(checkable); Dictionary::Ptr fields1 = new Dictionary(); - fields1->Set("state_time", DbValue::FromTimestamp(state_time_bag.first)); - fields1->Set("state_time_usec", state_time_bag.second); + fields1->Set("state_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("state_time_usec", timeBag.second); fields1->Set("object_id", checkable); fields1->Set("state_change", 1); /* service */ fields1->Set("state_type", checkable->GetStateType()); @@ -949,9 +935,8 @@ void DbEvents::AddStateChangeHistory(const Checkable::Ptr& checkable, const Chec fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ - String node = IcingaApplication::GetInstance()->GetNodeName(); + Endpoint::Ptr endpoint = Endpoint::GetByName(IcingaApplication::GetInstance()->GetNodeName()); - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); @@ -962,31 +947,22 @@ void DbEvents::AddStateChangeHistory(const Checkable::Ptr& checkable, const Chec /* logentries */ void DbEvents::AddCheckResultLogHistory(const Checkable::Ptr& checkable, const CheckResult::Ptr &cr) { - Dictionary::Ptr vars_after = cr->GetVarsAfter(); + if (!cr) + return; - 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"); + Dictionary::Ptr varsBefore = cr->GetVarsBefore(); + Dictionary::Ptr varsAfter = cr->GetVarsAfter(); - 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) + if (varsBefore && varsAfter) { + if (varsBefore->Get("state") == varsAfter->Get("state") && + varsBefore->Get("state_type") == varsAfter->Get("state_type") && + varsBefore->Get("attempt") == varsAfter->Get("attempt") && + varsBefore->Get("reachable") == varsAfter->Get("reachable")) return; /* Nothing changed, ignore this checkresult. */ } LogEntryType type; - String output; - - if (cr) - output = CompatUtility::GetCheckResultOutput(cr); + String output = CompatUtility::GetCheckResultOutput(cr); Host::Ptr host; Service::Ptr service; @@ -1000,7 +976,7 @@ void DbEvents::AddCheckResultLogHistory(const Checkable::Ptr& checkable, const C << service->GetShortName() << ";" << Service::StateToString(service->GetState()) << ";" << Service::StateTypeToString(service->GetStateType()) << ";" - << attempt_after << ";" + << service->GetCheckAttempt() << ";" << output << "" << ""; @@ -1019,7 +995,7 @@ void DbEvents::AddCheckResultLogHistory(const Checkable::Ptr& checkable, const C break; default: Log(LogCritical, "DbEvents") - << "Unknown service state: " << state_after; + << "Unknown service state: " << service->GetState(); return; } } else { @@ -1027,7 +1003,7 @@ void DbEvents::AddCheckResultLogHistory(const Checkable::Ptr& checkable, const C << host->GetName() << ";" << GetHostStateString(host) << ";" << Host::StateTypeToString(host->GetStateType()) << ";" - << attempt_after << ";" + << host->GetCheckAttempt() << ";" << output << "" << ""; @@ -1040,11 +1016,11 @@ void DbEvents::AddCheckResultLogHistory(const Checkable::Ptr& checkable, const C break; default: Log(LogCritical, "DbEvents") - << "Unknown host state: " << state_after; + << "Unknown host state: " << host->GetState(); return; } - if (!reachable_after) + if (!host->IsReachable()) type = LogEntryTypeHostUnreachable; } @@ -1083,15 +1059,15 @@ void DbEvents::AddRemoveDowntimeLogHistory(const Downtime::Ptr& downtime) { Checkable::Ptr checkable = downtime->GetCheckable(); - String downtime_output; - String downtime_state_str; + String downtimeOutput; + String downtimeStateStr; if (downtime->GetWasCancelled()) { - downtime_output = "Scheduled downtime for service has been cancelled."; - downtime_state_str = "CANCELLED"; + downtimeOutput = "Scheduled downtime for service has been cancelled."; + downtimeStateStr = "CANCELLED"; } else { - downtime_output = "Service has exited from a period of scheduled downtime."; - downtime_state_str = "STOPPED"; + downtimeOutput = "Service has exited from a period of scheduled downtime."; + downtimeStateStr = "STOPPED"; } Host::Ptr host; @@ -1104,14 +1080,14 @@ void DbEvents::AddRemoveDowntimeLogHistory(const Downtime::Ptr& downtime) msgbuf << "SERVICE DOWNTIME ALERT: " << host->GetName() << ";" << service->GetShortName() << ";" - << downtime_state_str << "; " - << downtime_output + << downtimeStateStr << "; " + << downtimeOutput << ""; } else { msgbuf << "HOST DOWNTIME ALERT: " << host->GetName() << ";" - << downtime_state_str << "; " - << downtime_output + << downtimeStateStr << "; " + << downtimeOutput << ""; } @@ -1124,11 +1100,12 @@ void DbEvents::AddNotificationSentLogHistory(const Notification::Ptr& notificati { CheckCommand::Ptr commandObj = checkable->GetCheckCommand(); - String check_command = ""; - if (commandObj) - check_command = commandObj->GetName(); + String checkCommandName; - String notification_type_str = Notification::NotificationTypeToString(notification_type); + if (commandObj) + checkCommandName = commandObj->GetName(); + + String notificationTypeStr = Notification::NotificationTypeToString(notification_type); String author_comment = ""; if (notification_type == NotificationCustom || notification_type == NotificationAcknowledgement) { @@ -1138,10 +1115,7 @@ void DbEvents::AddNotificationSentLogHistory(const Notification::Ptr& notificati if (!cr) return; - String output; - - if (cr) - output = CompatUtility::GetCheckResultOutput(cr); + String output = CompatUtility::GetCheckResultOutput(cr); Host::Ptr host; Service::Ptr service; @@ -1154,18 +1128,18 @@ void DbEvents::AddNotificationSentLogHistory(const Notification::Ptr& notificati << user->GetName() << ";" << host->GetName() << ";" << service->GetShortName() << ";" - << notification_type_str << " " + << notificationTypeStr << " " << "(" << Service::StateToString(service->GetState()) << ");" - << check_command << ";" + << checkCommandName << ";" << output << author_comment << ""; } else { msgbuf << "HOST NOTIFICATION: " << user->GetName() << ";" << host->GetName() << ";" - << notification_type_str << " " + << notificationTypeStr << " " << "(" << Host::StateToString(host->GetState()) << ");" - << check_command << ";" + << checkCommandName << ";" << output << author_comment << ""; } @@ -1175,15 +1149,15 @@ void DbEvents::AddNotificationSentLogHistory(const Notification::Ptr& notificati void DbEvents::AddFlappingChangedLogHistory(const Checkable::Ptr& checkable) { - String flapping_state_str; - String flapping_output; + String flappingStateStr; + String flappingOutput; if (checkable->IsFlapping()) { - flapping_output = "Service appears to have started flapping (" + Convert::ToString(checkable->GetFlappingCurrent()) + "% change >= " + Convert::ToString(checkable->GetFlappingThresholdHigh()) + "% threshold)"; - flapping_state_str = "STARTED"; + flappingOutput = "Service appears to have started flapping (" + Convert::ToString(checkable->GetFlappingCurrent()) + "% change >= " + Convert::ToString(checkable->GetFlappingThresholdHigh()) + "% threshold)"; + flappingStateStr = "STARTED"; } else { - flapping_output = "Service appears to have stopped flapping (" + Convert::ToString(checkable->GetFlappingCurrent()) + "% change < " + Convert::ToString(checkable->GetFlappingThresholdLow()) + "% threshold)"; - flapping_state_str = "STOPPED"; + flappingOutput = "Service appears to have stopped flapping (" + Convert::ToString(checkable->GetFlappingCurrent()) + "% change < " + Convert::ToString(checkable->GetFlappingThresholdLow()) + "% threshold)"; + flappingStateStr = "STOPPED"; } Host::Ptr host; @@ -1196,14 +1170,14 @@ void DbEvents::AddFlappingChangedLogHistory(const Checkable::Ptr& checkable) msgbuf << "SERVICE FLAPPING ALERT: " << host->GetName() << ";" << service->GetShortName() << ";" - << flapping_state_str << "; " - << flapping_output + << flappingStateStr << "; " + << flappingOutput << ""; } else { msgbuf << "HOST FLAPPING ALERT: " << host->GetName() << ";" - << flapping_state_str << "; " - << flapping_output + << flappingStateStr << "; " + << flappingOutput << ""; } @@ -1215,8 +1189,8 @@ void DbEvents::AddEnableFlappingChangedLogHistory(const Checkable::Ptr& checkabl if (!checkable->GetEnableFlapping()) return; - String flapping_output = "Flap detection has been disabled"; - String flapping_state_str = "DISABLED"; + String flappingOutput = "Flap detection has been disabled"; + String flappingStateStr = "DISABLED"; Host::Ptr host; Service::Ptr service; @@ -1228,14 +1202,14 @@ void DbEvents::AddEnableFlappingChangedLogHistory(const Checkable::Ptr& checkabl msgbuf << "SERVICE FLAPPING ALERT: " << host->GetName() << ";" << service->GetShortName() << ";" - << flapping_state_str << "; " - << flapping_output + << flappingStateStr << "; " + << flappingOutput << ""; } else { msgbuf << "HOST FLAPPING ALERT: " << host->GetName() << ";" - << flapping_state_str << "; " - << flapping_output + << flappingStateStr << "; " + << flappingOutput << ""; } @@ -1247,7 +1221,7 @@ void DbEvents::AddLogHistory(const Checkable::Ptr& checkable, const String& buff Log(LogDebug, "DbEvents") << "add log entry history for '" << checkable->GetName() << "'"; - std::pair time_bag = ConvertTimestamp(Utility::GetTime()); + std::pair timeBag = ConvertTimestamp(Utility::GetTime()); DbQuery query1; query1.Table = "logentries"; @@ -1255,18 +1229,18 @@ void DbEvents::AddLogHistory(const Checkable::Ptr& checkable, const String& buff query1.Category = DbCatLog; Dictionary::Ptr fields1 = new 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_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("entry_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("entry_time_usec", timeBag.second); + fields1->Set("object_id", checkable); 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(IcingaApplication::GetInstance()->GetNodeName()); - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); @@ -1280,7 +1254,7 @@ void DbEvents::AddFlappingChangedHistory(const Checkable::Ptr& checkable) Log(LogDebug, "DbEvents") << "add flapping history for '" << checkable->GetName() << "'"; - std::pair time_bag = ConvertTimestamp(Utility::GetTime()); + std::pair timeBag = ConvertTimestamp(Utility::GetTime()); DbQuery query1; query1.Table = "flappinghistory"; @@ -1289,8 +1263,8 @@ void DbEvents::AddFlappingChangedHistory(const Checkable::Ptr& checkable) Dictionary::Ptr fields1 = new Dictionary(); - fields1->Set("event_time", DbValue::FromTimestamp(time_bag.first)); - fields1->Set("event_time_usec", time_bag.second); + fields1->Set("event_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("event_time_usec", timeBag.second); if (checkable->IsFlapping()) fields1->Set("event_type", 1000); @@ -1311,9 +1285,8 @@ void DbEvents::AddFlappingChangedHistory(const Checkable::Ptr& checkable) fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ - String node = IcingaApplication::GetInstance()->GetNodeName(); + Endpoint::Ptr endpoint = Endpoint::GetByName(IcingaApplication::GetInstance()->GetNodeName()); - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); @@ -1323,10 +1296,13 @@ void DbEvents::AddFlappingChangedHistory(const Checkable::Ptr& checkable) void DbEvents::AddEnableFlappingChangedHistory(const Checkable::Ptr& checkable) { + if (!checkable->GetEnableFlapping()) + return; + Log(LogDebug, "DbEvents") << "add flapping history for '" << checkable->GetName() << "'"; - std::pair time_bag = ConvertTimestamp(Utility::GetTime()); + std::pair timeBag = ConvertTimestamp(Utility::GetTime()); DbQuery query1; query1.Table = "flappinghistory"; @@ -1335,11 +1311,8 @@ void DbEvents::AddEnableFlappingChangedHistory(const Checkable::Ptr& checkable) Dictionary::Ptr fields1 = new Dictionary(); - fields1->Set("event_time", DbValue::FromTimestamp(time_bag.first)); - fields1->Set("event_time_usec", time_bag.second); - - if (!checkable->GetEnableFlapping()) - return; + fields1->Set("event_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("event_time_usec", timeBag.second); fields1->Set("event_type", 1001); fields1->Set("reason_type", 2); @@ -1353,12 +1326,10 @@ void DbEvents::AddEnableFlappingChangedHistory(const Checkable::Ptr& checkable) fields1->Set("percent_state_change", checkable->GetFlappingCurrent()); fields1->Set("low_threshold", checkable->GetFlappingThresholdLow()); fields1->Set("high_threshold", checkable->GetFlappingThresholdHigh()); - fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ - String node = IcingaApplication::GetInstance()->GetNodeName(); + Endpoint::Ptr endpoint = Endpoint::GetByName(IcingaApplication::GetInstance()->GetNodeName()); - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); @@ -1379,8 +1350,6 @@ void DbEvents::AddCheckableCheckHistory(const Checkable::Ptr& checkable, const C Service::Ptr service; tie(host, service) = GetHostService(checkable); - std::ostringstream msgbuf; - DbQuery query1; query1.Table = service ? "servicechecks" : "hostchecks"; query1.Type = DbQueryInsert; @@ -1393,26 +1362,25 @@ void DbEvents::AddCheckableCheckHistory(const Checkable::Ptr& checkable, const C fields1->Set("state_type", checkable->GetStateType()); double start = cr->GetExecutionStart(); - std::pair time_bag_start = ConvertTimestamp(start); - double end = cr->GetExecutionEnd(); - std::pair time_bag_end = ConvertTimestamp(end); + double executionTime = cr->CalculateExecutionTime(); - double execution_time = cr->CalculateExecutionTime(); + std::pair timeBagStart = ConvertTimestamp(start); + std::pair timeBagEnd = ConvertTimestamp(end); - fields1->Set("start_time", DbValue::FromTimestamp(time_bag_start.first)); - fields1->Set("start_time_usec", time_bag_start.second); - fields1->Set("end_time", DbValue::FromTimestamp(time_bag_end.first)); - fields1->Set("end_time_usec", time_bag_end.second); + fields1->Set("start_time", DbValue::FromTimestamp(timeBagStart.first)); + fields1->Set("start_time_usec", timeBagStart.second); + fields1->Set("end_time", DbValue::FromTimestamp(timeBagEnd.first)); + fields1->Set("end_time_usec", timeBagEnd.second); fields1->Set("command_object_id", checkable->GetCheckCommand()); - fields1->Set("command_line", CompatUtility::GetCommandLine(checkable->GetCheckCommand())); - fields1->Set("execution_time", Convert::ToString(execution_time)); - fields1->Set("latency", Convert::ToString(cr->CalculateLatency())); + fields1->Set("execution_time", executionTime); + fields1->Set("latency", cr->CalculateLatency()); fields1->Set("return_code", cr->GetExitStatus()); - fields1->Set("output", CompatUtility::GetCheckResultOutput(cr)); - fields1->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr)); fields1->Set("perfdata", PluginUtility::FormatPerfdata(cr->GetPerformanceData())); + fields1->Set("output", CompatUtility::GetCheckResultOutput(cr)); + fields1->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr)); + fields1->Set("command_line", CompatUtility::GetCommandLine(checkable->GetCheckCommand())); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ if (service) { @@ -1423,9 +1391,8 @@ void DbEvents::AddCheckableCheckHistory(const Checkable::Ptr& checkable, const C fields1->Set("state", GetHostState(host)); } - String node = IcingaApplication::GetInstance()->GetNodeName(); + Endpoint::Ptr endpoint = Endpoint::GetByName(IcingaApplication::GetInstance()->GetNodeName()); - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); @@ -1439,8 +1406,6 @@ void DbEvents::AddEventHandlerHistory(const Checkable::Ptr& checkable) Log(LogDebug, "DbEvents") << "add eventhandler history for '" << checkable->GetName() << "'"; - std::pair time_bag = ConvertTimestamp(Utility::GetTime()); - DbQuery query1; query1.Table = "eventhandlers"; query1.Type = DbQueryInsert; @@ -1453,6 +1418,9 @@ void DbEvents::AddEventHandlerHistory(const Checkable::Ptr& checkable) tie(host, service) = GetHostService(checkable); fields1->Set("object_id", checkable); + fields1->Set("state_type", checkable->GetStateType()); + fields1->Set("command_object_id", checkable->GetEventCommand()); + fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ if (service) { fields1->Set("state", service->GetState()); @@ -1462,19 +1430,15 @@ void DbEvents::AddEventHandlerHistory(const Checkable::Ptr& checkable) fields1->Set("eventhandler_type", 0); } - fields1->Set("state_type", checkable->GetStateType()); + std::pair timeBag = ConvertTimestamp(Utility::GetTime()); - 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("start_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("start_time_usec", timeBag.second); + fields1->Set("end_time", DbValue::FromTimestamp(timeBag.first)); + fields1->Set("end_time_usec", timeBag.second); - fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ + Endpoint::Ptr endpoint = Endpoint::GetByName(IcingaApplication::GetInstance()->GetNodeName()); - String node = IcingaApplication::GetInstance()->GetNodeName(); - - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); @@ -1494,16 +1458,14 @@ void DbEvents::AddExternalCommandHistory(double time, const String& command, con Dictionary::Ptr fields1 = new Dictionary(); - fields1->Set("entry_time", DbValue::FromTimestamp(static_cast(time))); + fields1->Set("entry_time", DbValue::FromTimestamp(time)); fields1->Set("command_type", 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(IcingaApplication::GetInstance()->GetNodeName()); - Endpoint::Ptr endpoint = Endpoint::GetByName(node); if (endpoint) fields1->Set("endpoint_object_id", endpoint); From ef7c80959d793ff92ac894c7d1f0d9d89325df70 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 21 Dec 2017 12:08:42 +0100 Subject: [PATCH 31/33] More cleanup for compat filters in DB IDO --- lib/db_ido/hostdbobject.cpp | 14 +++++++------- lib/db_ido/servicedbobject.cpp | 18 +++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 9136ed58a..0063a3d95 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -63,8 +63,8 @@ Dictionary::Ptr HostDbObject::GetConfigFields() const fields->Set("check_command_object_id", host->GetCheckCommand()); fields->Set("eventhandler_command_object_id", host->GetEventCommand()); fields->Set("check_timeperiod_object_id", host->GetCheckPeriod()); - fields->Set("check_interval", (host->GetCheckInterval() / 60.0)); - fields->Set("retry_interval", (host->GetRetryInterval() / 60.0)); + fields->Set("check_interval", host->GetCheckInterval() / 60.0); + fields->Set("retry_interval", host->GetRetryInterval() / 60.0); fields->Set("max_check_attempts", host->GetMaxCheckAttempts()); fields->Set("flap_detection_enabled", host->GetEnableFlapping()); fields->Set("low_flap_threshold", host->GetFlappingThresholdLow()); @@ -145,8 +145,8 @@ Dictionary::Ptr HostDbObject::GetStatusFields() const fields->Set("percent_state_change", host->GetFlappingCurrent()); fields->Set("scheduled_downtime_depth", host->GetDowntimeDepth()); fields->Set("process_performance_data", host->GetEnablePerfdata()); - fields->Set("normal_check_interval", (host->GetCheckInterval() / 60.0)); - fields->Set("retry_check_interval", (host->GetRetryInterval() / 60.0)); + fields->Set("normal_check_interval", host->GetCheckInterval() / 60.0); + fields->Set("retry_check_interval", host->GetRetryInterval() / 60.0); fields->Set("check_timeperiod_object_id", host->GetCheckPeriod()); fields->Set("is_reachable", host->IsReachable()); fields->Set("original_attributes", JsonEncode(host->GetOriginalAttributes())); @@ -267,7 +267,7 @@ void HostDbObject::OnConfigUpdateHeavy() continue; } - int state_filter = dep->GetStateFilter(); + int stateFilter = dep->GetStateFilter(); Log(LogDebug, "HostDbObject") << "parent host: " << parent->GetName(); @@ -277,8 +277,8 @@ void HostDbObject::OnConfigUpdateHeavy() fields2->Set("dependent_host_object_id", host); fields2->Set("inherits_parent", 1); fields2->Set("timeperiod_object_id", dep->GetPeriod()); - fields2->Set("fail_on_up", (state_filter & StateFilterUp) ? 1 : 0); - fields2->Set("fail_on_down", (state_filter & StateFilterDown) ? 1 : 0); + fields2->Set("fail_on_up", stateFilter & StateFilterUp); + fields2->Set("fail_on_down", stateFilter & StateFilterDown); fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */ DbQuery query2; diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index b48cbf757..93a80d199 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -59,8 +59,8 @@ Dictionary::Ptr ServiceDbObject::GetConfigFields() const fields->Set("check_command_object_id", service->GetCheckCommand()); fields->Set("eventhandler_command_object_id", service->GetEventCommand()); fields->Set("check_timeperiod_object_id", service->GetCheckPeriod()); - fields->Set("check_interval", (service->GetCheckInterval() / 60.0)); - fields->Set("retry_interval", (service->GetRetryInterval() / 60.0)); + fields->Set("check_interval", service->GetCheckInterval() / 60.0); + fields->Set("retry_interval", service->GetRetryInterval() / 60.0); fields->Set("max_check_attempts", service->GetMaxCheckAttempts()); fields->Set("is_volatile", service->GetVolatile()); fields->Set("flap_detection_enabled", service->GetEnableFlapping()); @@ -138,8 +138,8 @@ Dictionary::Ptr ServiceDbObject::GetStatusFields() const fields->Set("percent_state_change", service->GetFlappingCurrent()); fields->Set("scheduled_downtime_depth", service->GetDowntimeDepth()); fields->Set("process_performance_data", service->GetEnablePerfdata()); - fields->Set("normal_check_interval", (service->GetCheckInterval() / 60.0)); - fields->Set("retry_check_interval", (service->GetRetryInterval() / 60.0)); + fields->Set("normal_check_interval", service->GetCheckInterval() / 60.0); + fields->Set("retry_check_interval", service->GetRetryInterval() / 60.0); fields->Set("check_timeperiod_object_id", service->GetCheckPeriod()); fields->Set("is_reachable", service->IsReachable()); fields->Set("original_attributes", JsonEncode(service->GetOriginalAttributes())); @@ -227,7 +227,7 @@ void ServiceDbObject::OnConfigUpdateHeavy() Log(LogDebug, "ServiceDbObject") << "service parents: " << parent->GetName(); - int state_filter = dep->GetStateFilter(); + int stateFilter = dep->GetStateFilter(); /* service dependencies */ Dictionary::Ptr fields1 = new Dictionary(); @@ -235,10 +235,10 @@ void ServiceDbObject::OnConfigUpdateHeavy() fields1->Set("dependent_service_object_id", service); fields1->Set("inherits_parent", 1); fields1->Set("timeperiod_object_id", dep->GetPeriod()); - fields1->Set("fail_on_ok", (state_filter & StateFilterOK) ? 1 : 0); - fields1->Set("fail_on_warning", (state_filter & StateFilterWarning) ? 1 : 0); - fields1->Set("fail_on_critical", (state_filter & StateFilterCritical) ? 1 : 0); - fields1->Set("fail_on_unknown", (state_filter & StateFilterUnknown) ? 1 : 0); + fields1->Set("fail_on_ok", stateFilter & StateFilterOK); + fields1->Set("fail_on_warning", stateFilter & StateFilterWarning); + fields1->Set("fail_on_critical", stateFilter & StateFilterCritical); + fields1->Set("fail_on_unknown", stateFilter & StateFilterUnknown); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ DbQuery query1; From 403ab5c357bf376b543e17e88f2deb0a7e2f91c1 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 21 Dec 2017 12:12:06 +0100 Subject: [PATCH 32/33] Eliminate time(NULL) in StatusDataWriter --- lib/compat/statusdatawriter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index 62e5e30c7..f81a8d5ef 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -390,7 +390,7 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl "\t" "max_attempts=" << checkable->GetMaxCheckAttempts() << "\n" "\t" "last_state_change=" << static_cast(checkable->GetLastStateChange()) << "\n" "\t" "last_hard_state_change=" << static_cast(checkable->GetLastHardStateChange()) << "\n" - "\t" "last_update=" << static_cast(time(NULL)) << "\n" + "\t" "last_update=" << static_cast(Utility::GetTime()) << "\n" "\t" "notifications_enabled" "\t" << Convert::ToLong(checkable->GetEnableNotifications()) << "\n" "\t" "active_checks_enabled=" << Convert::ToLong(checkable->GetEnableActiveChecks()) << "\n" "\t" "passive_checks_enabled=" << Convert::ToLong(checkable->GetEnablePassiveChecks()) << "\n" From 50106057bf5eefc95707faea96fc5bb3a1cfc657 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 21 Dec 2017 15:45:11 +0100 Subject: [PATCH 33/33] Remove obsolete locks in Livestatus; apply style guide to DB IDO --- lib/db_ido/hostdbobject.cpp | 5 ++--- lib/livestatus/commandstable.cpp | 21 +++------------------ lib/livestatus/contactstable.cpp | 28 ++++------------------------ lib/livestatus/hoststable.cpp | 28 ++++------------------------ lib/livestatus/servicestable.cpp | 28 ++++------------------------ 5 files changed, 17 insertions(+), 93 deletions(-) diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 0063a3d95..e339b5e70 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -51,11 +51,10 @@ Dictionary::Ptr HostDbObject::GetConfigFields() const /* Compatibility fallback. */ String displayName = host->GetDisplayName(); - if (!displayName.IsEmpty()) { + if (!displayName.IsEmpty()) fields->Set("alias", displayName); - } else { + else fields->Set("alias", host->GetName()); - } fields->Set("display_name", displayName); fields->Set("address", host->GetAddress()); diff --git a/lib/livestatus/commandstable.cpp b/lib/livestatus/commandstable.cpp index 8aa5f0998..ae5145fc1 100644 --- a/lib/livestatus/commandstable.cpp +++ b/lib/livestatus/commandstable.cpp @@ -99,12 +99,7 @@ Value CommandsTable::CustomVariableNamesAccessor(const Value& row) if (!command) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(command); - vars = command->GetVars(); - } + Dictionary::Ptr vars = command->GetVars(); Array::Ptr cv = new Array(); @@ -128,12 +123,7 @@ Value CommandsTable::CustomVariableValuesAccessor(const Value& row) if (!command) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(command); - vars = command->GetVars(); - } + Dictionary::Ptr vars = command->GetVars(); Array::Ptr cv = new Array(); @@ -157,12 +147,7 @@ Value CommandsTable::CustomVariablesAccessor(const Value& row) if (!command) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(command); - vars = command->GetVars(); - } + Dictionary::Ptr vars = command->GetVars(); Array::Ptr cv = new Array(); diff --git a/lib/livestatus/contactstable.cpp b/lib/livestatus/contactstable.cpp index 54a613adc..aeca4b04d 100644 --- a/lib/livestatus/contactstable.cpp +++ b/lib/livestatus/contactstable.cpp @@ -203,12 +203,7 @@ Value ContactsTable::CustomVariableNamesAccessor(const Value& row) if (!user) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(user); - vars = user->GetVars(); - } + Dictionary::Ptr vars = user->GetVars(); Array::Ptr cv = new Array(); @@ -230,12 +225,7 @@ Value ContactsTable::CustomVariableValuesAccessor(const Value& row) if (!user) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(user); - vars = user->GetVars(); - } + Dictionary::Ptr vars = user->GetVars(); Array::Ptr cv = new Array(); @@ -260,12 +250,7 @@ Value ContactsTable::CustomVariablesAccessor(const Value& row) if (!user) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(user); - vars = user->GetVars(); - } + Dictionary::Ptr vars = user->GetVars(); Array::Ptr cv = new Array(); @@ -295,12 +280,7 @@ Value ContactsTable::CVIsJsonAccessor(const Value& row) if (!user) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(user); - vars = user->GetVars(); - } + Dictionary::Ptr vars = user->GetVars(); if (!vars) return Empty; diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index b4ba38fe8..795f31b8e 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -1036,12 +1036,7 @@ Value HostsTable::CustomVariableNamesAccessor(const Value& row) if (!host) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(host); - vars = host->GetVars(); - } + Dictionary::Ptr vars = host->GetVars(); Array::Ptr cv = new Array(); @@ -1063,12 +1058,7 @@ Value HostsTable::CustomVariableValuesAccessor(const Value& row) if (!host) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(host); - vars = host->GetVars(); - } + Dictionary::Ptr vars = host->GetVars(); Array::Ptr cv = new Array(); @@ -1093,12 +1083,7 @@ Value HostsTable::CustomVariablesAccessor(const Value& row) if (!host) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(host); - vars = host->GetVars(); - } + Dictionary::Ptr vars = host->GetVars(); Array::Ptr cv = new Array(); @@ -1128,12 +1113,7 @@ Value HostsTable::CVIsJsonAccessor(const Value& row) if (!host) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(host); - vars = host->GetVars(); - } + Dictionary::Ptr vars = host->GetVars(); if (!vars) return Empty; diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index 2dcd9db9a..3abffb423 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -1058,12 +1058,7 @@ Value ServicesTable::CustomVariableNamesAccessor(const Value& row) if (!service) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(service); - vars = service->GetVars(); - } + Dictionary::Ptr vars = service->GetVars(); Array::Ptr cv = new Array(); @@ -1085,12 +1080,7 @@ Value ServicesTable::CustomVariableValuesAccessor(const Value& row) if (!service) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(service); - vars = service->GetVars(); - } + Dictionary::Ptr vars = service->GetVars(); Array::Ptr cv = new Array(); @@ -1115,12 +1105,7 @@ Value ServicesTable::CustomVariablesAccessor(const Value& row) if (!service) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(service); - vars = service->GetVars(); - } + Dictionary::Ptr vars = service->GetVars(); Array::Ptr cv = new Array(); @@ -1150,12 +1135,7 @@ Value ServicesTable::CVIsJsonAccessor(const Value& row) if (!service) return Empty; - Dictionary::Ptr vars; - - { - ObjectLock olock(service); - vars = service->GetVars(); - } + Dictionary::Ptr vars = service->GetVars(); if (!vars) return Empty;