From 5b359ea5188df4db3b065053a0d740a9bb1496d2 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 17 Apr 2014 16:01:44 +0200 Subject: [PATCH] Add CompatUtility::GetModifiedAttributesList() for Livestatus. Fixes #6042 --- components/livestatus/commandstable.cpp | 3 +- components/livestatus/contactstable.cpp | 4 +- components/livestatus/hoststable.cpp | 8 +++- components/livestatus/servicestable.cpp | 8 +++- lib/base/dynamicobject.cpp | 11 +++++ lib/base/dynamicobject.h | 3 ++ lib/icinga/compatutility.cpp | 57 +++++++++++++++++++++++++ lib/icinga/compatutility.h | 3 ++ test/livestatus/queries/command/modattr | 4 ++ test/livestatus/queries/contact/modattr | 4 ++ test/livestatus/queries/host/modattr | 4 ++ test/livestatus/queries/service/modattr | 4 ++ 12 files changed, 105 insertions(+), 8 deletions(-) create mode 100644 test/livestatus/queries/command/modattr create mode 100644 test/livestatus/queries/contact/modattr create mode 100644 test/livestatus/queries/host/modattr create mode 100644 test/livestatus/queries/service/modattr diff --git a/components/livestatus/commandstable.cpp b/components/livestatus/commandstable.cpp index 99f26c5d6..d945326b0 100644 --- a/components/livestatus/commandstable.cpp +++ b/components/livestatus/commandstable.cpp @@ -223,6 +223,5 @@ Value CommandsTable::ModifiedAttributesListAccessor(const Value& row) if (!command) return Empty; - /* not supported */ - return Empty; + return CompatUtility::GetModifiedAttributesList(command); } diff --git a/components/livestatus/contactstable.cpp b/components/livestatus/contactstable.cpp index 8a9e7549a..c8cf3e2ec 100644 --- a/components/livestatus/contactstable.cpp +++ b/components/livestatus/contactstable.cpp @@ -20,6 +20,7 @@ #include "livestatus/contactstable.h" #include "icinga/user.h" #include "icinga/timeperiod.h" +#include "icinga/compatutility.h" #include "base/dynamictype.h" #include "base/objectlock.h" #include "base/utility.h" @@ -280,6 +281,5 @@ Value ContactsTable::ModifiedAttributesListAccessor(const Value& row) if (!user) return Empty; - /* not supported */ - return Empty; + return CompatUtility::GetModifiedAttributesList(user); } diff --git a/components/livestatus/hoststable.cpp b/components/livestatus/hoststable.cpp index e365f6948..5077438c1 100644 --- a/components/livestatus/hoststable.cpp +++ b/components/livestatus/hoststable.cpp @@ -756,8 +756,12 @@ Value HostsTable::ModifiedAttributesAccessor(const Value& row) Value HostsTable::ModifiedAttributesListAccessor(const Value& row) { - /* not supported */ - return Empty; + Host::Ptr host = static_cast(row); + + if (!host) + return Empty; + + return CompatUtility::GetModifiedAttributesList(host); } Value HostsTable::CheckIntervalAccessor(const Value& row) diff --git a/components/livestatus/servicestable.cpp b/components/livestatus/servicestable.cpp index a6af0e09f..52b1a19d4 100644 --- a/components/livestatus/servicestable.cpp +++ b/components/livestatus/servicestable.cpp @@ -744,8 +744,12 @@ Value ServicesTable::ModifiedAttributesAccessor(const Value& row) Value ServicesTable::ModifiedAttributesListAccessor(const Value& row) { - /* not supported */ - return Empty; + Service::Ptr service = static_cast(row); + + if (!service) + return Empty; + + return CompatUtility::GetModifiedAttributesList(service); } Value ServicesTable::StalenessAccessor(const Value& row) diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp index 810554b8b..334065dff 100644 --- a/lib/base/dynamicobject.cpp +++ b/lib/base/dynamicobject.cpp @@ -381,6 +381,17 @@ void DynamicObject::SetVars(const Dictionary::Ptr& vars, const String& authority OnVarsChanged(GetSelf()); } +int DynamicObject::GetModifiedAttributes(void) const +{ + /* does nothing by default */ + return 0; +} + +void DynamicObject::SetModifiedAttributes(int flags) +{ + /* does nothing by default */ +} + bool DynamicObject::IsVarOverridden(const String& name) { Dictionary::Ptr vars_override = GetOverrideVars(); diff --git a/lib/base/dynamicobject.h b/lib/base/dynamicobject.h index 8891343f5..f729891d3 100644 --- a/lib/base/dynamicobject.h +++ b/lib/base/dynamicobject.h @@ -100,6 +100,9 @@ public: Dictionary::Ptr GetVars(void) const; void SetVars(const Dictionary::Ptr& vars, const String& authority = String()); + virtual int GetModifiedAttributes(void) const; + virtual void SetModifiedAttributes(int flags); + bool IsVarOverridden(const String& name); void Register(void); diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 8b782fcfc..92f67eca6 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -26,6 +26,7 @@ #include "base/objectlock.h" #include "base/debug.h" #include "base/convert.h" +#include #include #include #include @@ -433,6 +434,62 @@ String CompatUtility::GetCustomAttributeConfig(const DynamicObject::Ptr& object, return vars->Get(name); } +Array::Ptr CompatUtility::GetModifiedAttributesList(const DynamicObject::Ptr& object) +{ + Array::Ptr mod_attr_list = make_shared(); + + if (object->GetType() != DynamicType::GetByName("Host") && + object->GetType() != DynamicType::GetByName("Service") && + object->GetType() != DynamicType::GetByName("User") && + object->GetType() != DynamicType::GetByName("CheckCommand") && + object->GetType() != DynamicType::GetByName("EventCommand") && + object->GetType() != DynamicType::GetByName("NotificationCommand")) + return mod_attr_list; + + int flags = object->GetModifiedAttributes(); + + if ((flags & ModAttrNotificationsEnabled)) + mod_attr_list->Add("notifications_enabled"); + + if ((flags & ModAttrActiveChecksEnabled)) + mod_attr_list->Add("active_checks_enabled"); + + if ((flags & ModAttrPassiveChecksEnabled)) + mod_attr_list->Add("passive_checks_enabled"); + + if ((flags & ModAttrFlapDetectionEnabled)) + mod_attr_list->Add("flap_detection_enabled"); + + if ((flags & ModAttrEventHandlerEnabled)) + mod_attr_list->Add("event_handler_enabled"); + + if ((flags & ModAttrPerformanceDataEnabled)) + mod_attr_list->Add("performance_data_enabled"); + + if ((flags & ModAttrNormalCheckInterval)) + mod_attr_list->Add("check_interval"); + + if ((flags & ModAttrRetryCheckInterval)) + mod_attr_list->Add("retry_interval"); + + if ((flags & ModAttrEventHandlerCommand)) + mod_attr_list->Add("event_handler_command"); + + if ((flags & ModAttrCheckCommand)) + mod_attr_list->Add("check_command"); + + if ((flags & ModAttrMaxCheckAttempts)) + mod_attr_list->Add("max_check_attemps"); + + if ((flags & ModAttrCheckTimeperiod)) + mod_attr_list->Add("check_timeperiod"); + + if ((flags & ModAttrCustomVariable)) + mod_attr_list->Add("custom_variable"); + + return mod_attr_list; +} + /* notifications */ int CompatUtility::GetCheckableNotificationsEnabled(const Checkable::Ptr& checkable) { diff --git a/lib/icinga/compatutility.h b/lib/icinga/compatutility.h index fb28a766b..d88109f4f 100644 --- a/lib/icinga/compatutility.h +++ b/lib/icinga/compatutility.h @@ -24,6 +24,7 @@ #include "icinga/service.h" #include "icinga/checkcommand.h" #include "base/dictionary.h" +#include "base/array.h" #include "base/dynamicobject.h" #include @@ -86,6 +87,8 @@ public: static int GetCheckableInCheckPeriod(const Checkable::Ptr& checkable); static int GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable); + static Array::Ptr GetModifiedAttributesList(const DynamicObject::Ptr& object); + /* notification */ static int GetCheckableNotificationsEnabled(const Checkable::Ptr& checkable); static int GetCheckableNotificationLastNotification(const Checkable::Ptr& checkable); diff --git a/test/livestatus/queries/command/modattr b/test/livestatus/queries/command/modattr new file mode 100644 index 000000000..90aaea780 --- /dev/null +++ b/test/livestatus/queries/command/modattr @@ -0,0 +1,4 @@ +GET commands +Columns: name modified_attributes modified_attributes_list +ResponseHeader: fixed16 + diff --git a/test/livestatus/queries/contact/modattr b/test/livestatus/queries/contact/modattr new file mode 100644 index 000000000..8b520a074 --- /dev/null +++ b/test/livestatus/queries/contact/modattr @@ -0,0 +1,4 @@ +GET contacts +Columns: name modified_attributes modified_attributes_list +ResponseHeader: fixed16 + diff --git a/test/livestatus/queries/host/modattr b/test/livestatus/queries/host/modattr new file mode 100644 index 000000000..7bcb211bb --- /dev/null +++ b/test/livestatus/queries/host/modattr @@ -0,0 +1,4 @@ +GET hosts +Columns: name modified_attributes modified_attributes_list +ResponseHeader: fixed16 + diff --git a/test/livestatus/queries/service/modattr b/test/livestatus/queries/service/modattr new file mode 100644 index 000000000..bd4368ac2 --- /dev/null +++ b/test/livestatus/queries/service/modattr @@ -0,0 +1,4 @@ +GET services +Columns: name modified_attributes modified_attributes_list +ResponseHeader: fixed16 +