From 92c565d7449ea34559ae082473cb6e574abcbbee Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 5 Dec 2017 11:34:38 +0100 Subject: [PATCH] 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) -- 2.50.0