mirror of https://github.com/Icinga/icinga2.git
Add CompatUtility::GetModifiedAttributesList() for Livestatus.
Fixes #6042
This commit is contained in:
parent
72f7537fa6
commit
5b359ea518
|
@ -223,6 +223,5 @@ Value CommandsTable::ModifiedAttributesListAccessor(const Value& row)
|
||||||
if (!command)
|
if (!command)
|
||||||
return Empty;
|
return Empty;
|
||||||
|
|
||||||
/* not supported */
|
return CompatUtility::GetModifiedAttributesList(command);
|
||||||
return Empty;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "livestatus/contactstable.h"
|
#include "livestatus/contactstable.h"
|
||||||
#include "icinga/user.h"
|
#include "icinga/user.h"
|
||||||
#include "icinga/timeperiod.h"
|
#include "icinga/timeperiod.h"
|
||||||
|
#include "icinga/compatutility.h"
|
||||||
#include "base/dynamictype.h"
|
#include "base/dynamictype.h"
|
||||||
#include "base/objectlock.h"
|
#include "base/objectlock.h"
|
||||||
#include "base/utility.h"
|
#include "base/utility.h"
|
||||||
|
@ -280,6 +281,5 @@ Value ContactsTable::ModifiedAttributesListAccessor(const Value& row)
|
||||||
if (!user)
|
if (!user)
|
||||||
return Empty;
|
return Empty;
|
||||||
|
|
||||||
/* not supported */
|
return CompatUtility::GetModifiedAttributesList(user);
|
||||||
return Empty;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -756,8 +756,12 @@ Value HostsTable::ModifiedAttributesAccessor(const Value& row)
|
||||||
|
|
||||||
Value HostsTable::ModifiedAttributesListAccessor(const Value& row)
|
Value HostsTable::ModifiedAttributesListAccessor(const Value& row)
|
||||||
{
|
{
|
||||||
/* not supported */
|
Host::Ptr host = static_cast<Host::Ptr>(row);
|
||||||
return Empty;
|
|
||||||
|
if (!host)
|
||||||
|
return Empty;
|
||||||
|
|
||||||
|
return CompatUtility::GetModifiedAttributesList(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value HostsTable::CheckIntervalAccessor(const Value& row)
|
Value HostsTable::CheckIntervalAccessor(const Value& row)
|
||||||
|
|
|
@ -744,8 +744,12 @@ Value ServicesTable::ModifiedAttributesAccessor(const Value& row)
|
||||||
|
|
||||||
Value ServicesTable::ModifiedAttributesListAccessor(const Value& row)
|
Value ServicesTable::ModifiedAttributesListAccessor(const Value& row)
|
||||||
{
|
{
|
||||||
/* not supported */
|
Service::Ptr service = static_cast<Service::Ptr>(row);
|
||||||
return Empty;
|
|
||||||
|
if (!service)
|
||||||
|
return Empty;
|
||||||
|
|
||||||
|
return CompatUtility::GetModifiedAttributesList(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ServicesTable::StalenessAccessor(const Value& row)
|
Value ServicesTable::StalenessAccessor(const Value& row)
|
||||||
|
|
|
@ -381,6 +381,17 @@ void DynamicObject::SetVars(const Dictionary::Ptr& vars, const String& authority
|
||||||
OnVarsChanged(GetSelf());
|
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)
|
bool DynamicObject::IsVarOverridden(const String& name)
|
||||||
{
|
{
|
||||||
Dictionary::Ptr vars_override = GetOverrideVars();
|
Dictionary::Ptr vars_override = GetOverrideVars();
|
||||||
|
|
|
@ -100,6 +100,9 @@ public:
|
||||||
Dictionary::Ptr GetVars(void) const;
|
Dictionary::Ptr GetVars(void) const;
|
||||||
void SetVars(const Dictionary::Ptr& vars, const String& authority = String());
|
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);
|
bool IsVarOverridden(const String& name);
|
||||||
|
|
||||||
void Register(void);
|
void Register(void);
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "base/objectlock.h"
|
#include "base/objectlock.h"
|
||||||
#include "base/debug.h"
|
#include "base/debug.h"
|
||||||
#include "base/convert.h"
|
#include "base/convert.h"
|
||||||
|
#include <boost/make_shared.hpp>
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <boost/algorithm/string/replace.hpp>
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
#include <boost/algorithm/string/classification.hpp>
|
#include <boost/algorithm/string/classification.hpp>
|
||||||
|
@ -433,6 +434,62 @@ String CompatUtility::GetCustomAttributeConfig(const DynamicObject::Ptr& object,
|
||||||
return vars->Get(name);
|
return vars->Get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Array::Ptr CompatUtility::GetModifiedAttributesList(const DynamicObject::Ptr& object)
|
||||||
|
{
|
||||||
|
Array::Ptr mod_attr_list = make_shared<Array>();
|
||||||
|
|
||||||
|
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 */
|
/* notifications */
|
||||||
int CompatUtility::GetCheckableNotificationsEnabled(const Checkable::Ptr& checkable)
|
int CompatUtility::GetCheckableNotificationsEnabled(const Checkable::Ptr& checkable)
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "icinga/service.h"
|
#include "icinga/service.h"
|
||||||
#include "icinga/checkcommand.h"
|
#include "icinga/checkcommand.h"
|
||||||
#include "base/dictionary.h"
|
#include "base/dictionary.h"
|
||||||
|
#include "base/array.h"
|
||||||
#include "base/dynamicobject.h"
|
#include "base/dynamicobject.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -86,6 +87,8 @@ public:
|
||||||
static int GetCheckableInCheckPeriod(const Checkable::Ptr& checkable);
|
static int GetCheckableInCheckPeriod(const Checkable::Ptr& checkable);
|
||||||
static int GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable);
|
static int GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable);
|
||||||
|
|
||||||
|
static Array::Ptr GetModifiedAttributesList(const DynamicObject::Ptr& object);
|
||||||
|
|
||||||
/* notification */
|
/* notification */
|
||||||
static int GetCheckableNotificationsEnabled(const Checkable::Ptr& checkable);
|
static int GetCheckableNotificationsEnabled(const Checkable::Ptr& checkable);
|
||||||
static int GetCheckableNotificationLastNotification(const Checkable::Ptr& checkable);
|
static int GetCheckableNotificationLastNotification(const Checkable::Ptr& checkable);
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
GET commands
|
||||||
|
Columns: name modified_attributes modified_attributes_list
|
||||||
|
ResponseHeader: fixed16
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
GET contacts
|
||||||
|
Columns: name modified_attributes modified_attributes_list
|
||||||
|
ResponseHeader: fixed16
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
GET hosts
|
||||||
|
Columns: name modified_attributes modified_attributes_list
|
||||||
|
ResponseHeader: fixed16
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
GET services
|
||||||
|
Columns: name modified_attributes modified_attributes_list
|
||||||
|
ResponseHeader: fixed16
|
||||||
|
|
Loading…
Reference in New Issue