mirror of https://github.com/Icinga/icinga2.git
Use CustomVarObject instead of DynamicObject for all libicinga objects.
Fixes #6187
This commit is contained in:
parent
f966f6ec90
commit
601e10cb46
|
@ -507,7 +507,7 @@ void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& s
|
|||
"\n";
|
||||
}
|
||||
|
||||
void StatusDataWriter::DumpCustomAttributes(std::ostream& fp, const DynamicObject::Ptr& object)
|
||||
void StatusDataWriter::DumpCustomAttributes(std::ostream& fp, const CustomVarObject::Ptr& object)
|
||||
{
|
||||
Dictionary::Ptr vars = object->GetVars();
|
||||
|
||||
|
@ -808,8 +808,6 @@ void StatusDataWriter::StatusTimerHandler(void)
|
|||
"\t" "next_downtime_id=" << Service::GetNextDowntimeID() << "\n"
|
||||
"\t" "next_comment_id=" << Service::GetNextCommentID() << "\n";
|
||||
|
||||
DumpCustomAttributes(statusfp, IcingaApplication::GetInstance());
|
||||
|
||||
statusfp << "\t" "}" "\n"
|
||||
"\n";
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#define STATUSDATAWRITER_H
|
||||
|
||||
#include "compat/statusdatawriter.th"
|
||||
#include "icinga/customvarobject.h"
|
||||
#include "icinga/host.h"
|
||||
#include "icinga/service.h"
|
||||
#include "icinga/command.h"
|
||||
|
@ -94,7 +95,7 @@ private:
|
|||
void DumpServiceStatus(std::ostream& fp, const Service::Ptr& service);
|
||||
void DumpServiceObject(std::ostream& fp, const Service::Ptr& service);
|
||||
|
||||
void DumpCustomAttributes(std::ostream& fp, const DynamicObject::Ptr& object);
|
||||
void DumpCustomAttributes(std::ostream& fp, const CustomVarObject::Ptr& object);
|
||||
|
||||
void UpdateObjectsCache(void);
|
||||
void StatusTimerHandler(void);
|
||||
|
|
|
@ -45,7 +45,6 @@ boost::signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnStopp
|
|||
boost::signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnPaused;
|
||||
boost::signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnResumed;
|
||||
boost::signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnStateChanged;
|
||||
boost::signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnVarsChanged;
|
||||
|
||||
DynamicObject::DynamicObject(void)
|
||||
{ }
|
||||
|
@ -347,42 +346,3 @@ DynamicObject::Ptr DynamicObject::GetObject(const String& type, const String& na
|
|||
DynamicType::Ptr dtype = DynamicType::GetByName(type);
|
||||
return dtype->GetObject(name);
|
||||
}
|
||||
|
||||
|
||||
Dictionary::Ptr DynamicObject::GetVars(void) const
|
||||
{
|
||||
if (!GetOverrideVars().IsEmpty())
|
||||
return GetOverrideVars();
|
||||
else
|
||||
return GetVarsRaw();
|
||||
}
|
||||
|
||||
void DynamicObject::SetVars(const Dictionary::Ptr& vars)
|
||||
{
|
||||
SetOverrideVars(vars);
|
||||
|
||||
Log(LogDebug, "base", "Setting vars for object '" + GetName() + "'");
|
||||
|
||||
OnVarsChanged(GetSelf());
|
||||
}
|
||||
|
||||
int DynamicObject::GetModifiedAttributes(void) const
|
||||
{
|
||||
/* does nothing by default */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DynamicObject::SetModifiedAttributes(int)
|
||||
{
|
||||
/* does nothing by default */
|
||||
}
|
||||
|
||||
bool DynamicObject::IsVarOverridden(const String& name)
|
||||
{
|
||||
Dictionary::Ptr vars_override = GetOverrideVars();
|
||||
|
||||
if (!vars_override)
|
||||
return false;
|
||||
|
||||
return vars_override->Contains(name);
|
||||
}
|
||||
|
|
|
@ -33,27 +33,6 @@ namespace icinga
|
|||
|
||||
class DynamicType;
|
||||
|
||||
enum ModifiedAttributeType
|
||||
{
|
||||
ModAttrNotificationsEnabled = 1,
|
||||
ModAttrActiveChecksEnabled = 2,
|
||||
ModAttrPassiveChecksEnabled = 4,
|
||||
ModAttrEventHandlerEnabled = 8,
|
||||
ModAttrFlapDetectionEnabled = 16,
|
||||
ModAttrFailurePredictionEnabled = 32,
|
||||
ModAttrPerformanceDataEnabled = 64,
|
||||
ModAttrObsessiveHandlerEnabled = 128,
|
||||
ModAttrEventHandlerCommand = 256,
|
||||
ModAttrCheckCommand = 512,
|
||||
ModAttrNormalCheckInterval = 1024,
|
||||
ModAttrRetryCheckInterval = 2048,
|
||||
ModAttrMaxCheckAttempts = 4096,
|
||||
ModAttrFreshnessChecksEnabled = 8192,
|
||||
ModAttrCheckTimeperiod = 16384,
|
||||
ModAttrCustomVariable = 32768,
|
||||
ModAttrNotificationTimeperiod = 65536
|
||||
};
|
||||
|
||||
/**
|
||||
* A dynamic object that can be instantiated from the configuration file
|
||||
* and that supports attribute replication to remote application instances.
|
||||
|
@ -70,7 +49,6 @@ public:
|
|||
static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnPaused;
|
||||
static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnResumed;
|
||||
static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnStateChanged;
|
||||
static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnVarsChanged;
|
||||
|
||||
Value InvokeMethod(const String& method, const std::vector<Value>& arguments);
|
||||
|
||||
|
@ -83,14 +61,6 @@ public:
|
|||
Object::Ptr GetExtension(const String& key);
|
||||
void ClearExtension(const String& key);
|
||||
|
||||
Dictionary::Ptr GetVars(void) const;
|
||||
void SetVars(const Dictionary::Ptr& vars);
|
||||
|
||||
virtual int GetModifiedAttributes(void) const;
|
||||
virtual void SetModifiedAttributes(int flags);
|
||||
|
||||
bool IsVarOverridden(const String& name);
|
||||
|
||||
void Register(void);
|
||||
|
||||
void Activate(void);
|
||||
|
|
|
@ -266,7 +266,7 @@ DbReference DbConnection::GetInsertID(const DbType::Ptr& type, const DbReference
|
|||
return it->second;
|
||||
}
|
||||
|
||||
void DbConnection::SetNotificationInsertID(const DynamicObject::Ptr& obj, const DbReference& dbref)
|
||||
void DbConnection::SetNotificationInsertID(const CustomVarObject::Ptr& obj, const DbReference& dbref)
|
||||
{
|
||||
if (dbref.IsValid())
|
||||
m_NotificationInsertIDs[obj] = dbref;
|
||||
|
@ -274,9 +274,9 @@ void DbConnection::SetNotificationInsertID(const DynamicObject::Ptr& obj, const
|
|||
m_NotificationInsertIDs.erase(obj);
|
||||
}
|
||||
|
||||
DbReference DbConnection::GetNotificationInsertID(const DynamicObject::Ptr& obj) const
|
||||
DbReference DbConnection::GetNotificationInsertID(const CustomVarObject::Ptr& obj) const
|
||||
{
|
||||
std::map<DynamicObject::Ptr, DbReference>::const_iterator it;
|
||||
std::map<CustomVarObject::Ptr, DbReference>::const_iterator it;
|
||||
|
||||
it = m_NotificationInsertIDs.find(obj);
|
||||
|
||||
|
|
|
@ -49,8 +49,8 @@ public:
|
|||
DbReference GetInsertID(const DbObject::Ptr& dbobj) const;
|
||||
DbReference GetInsertID(const DbType::Ptr& type, const DbReference& objid) const;
|
||||
|
||||
void SetNotificationInsertID(const DynamicObject::Ptr& obj, const DbReference& dbref);
|
||||
DbReference GetNotificationInsertID(const DynamicObject::Ptr& obj) const;
|
||||
void SetNotificationInsertID(const CustomVarObject::Ptr& obj, const DbReference& dbref);
|
||||
DbReference GetNotificationInsertID(const CustomVarObject::Ptr& obj) const;
|
||||
|
||||
void SetObjectActive(const DbObject::Ptr& dbobj, bool active);
|
||||
bool GetObjectActive(const DbObject::Ptr& dbobj) const;
|
||||
|
@ -82,7 +82,7 @@ protected:
|
|||
private:
|
||||
std::map<DbObject::Ptr, DbReference> m_ObjectIDs;
|
||||
std::map<std::pair<DbType::Ptr, DbReference>, DbReference> m_InsertIDs;
|
||||
std::map<DynamicObject::Ptr, DbReference> m_NotificationInsertIDs;
|
||||
std::map<CustomVarObject::Ptr, DbReference> m_NotificationInsertIDs;
|
||||
std::set<DbObject::Ptr> m_ActiveObjects;
|
||||
std::set<DbObject::Ptr> m_ConfigUpdates;
|
||||
std::set<DbObject::Ptr> m_StatusUpdates;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "db_ido/dbobject.h"
|
||||
#include "db_ido/dbtype.h"
|
||||
#include "db_ido/dbvalue.h"
|
||||
#include "icinga/customvarobject.h"
|
||||
#include "icinga/service.h"
|
||||
#include "icinga/compatutility.h"
|
||||
#include "remote/endpoint.h"
|
||||
|
@ -46,7 +47,7 @@ void DbObject::StaticInitialize(void)
|
|||
{
|
||||
/* triggered in ProcessCheckResult(), requires UpdateNextCheck() to be called before */
|
||||
DynamicObject::OnStateChanged.connect(boost::bind(&DbObject::StateChangedHandler, _1));
|
||||
DynamicObject::OnVarsChanged.connect(boost::bind(&DbObject::VarsChangedHandler, _1));
|
||||
CustomVarObject::OnVarsChanged.connect(boost::bind(&DbObject::VarsChangedHandler, _1));
|
||||
}
|
||||
|
||||
void DbObject::SetObject(const DynamicObject::Ptr& object)
|
||||
|
@ -151,16 +152,21 @@ void DbObject::SendVarsConfigUpdate(void)
|
|||
{
|
||||
DynamicObject::Ptr obj = GetObject();
|
||||
|
||||
Dictionary::Ptr vars = CompatUtility::GetCustomAttributeConfig(obj);
|
||||
CustomVarObject::Ptr custom_var_object = dynamic_pointer_cast<CustomVarObject>(obj);
|
||||
|
||||
if (!custom_var_object)
|
||||
return;
|
||||
|
||||
Dictionary::Ptr vars = CompatUtility::GetCustomAttributeConfig(custom_var_object);
|
||||
|
||||
if (vars) {
|
||||
Log(LogDebug, "db_ido", "Updating object vars for '" + obj->GetName() + "'");
|
||||
Log(LogDebug, "db_ido", "Updating object vars for '" + custom_var_object->GetName() + "'");
|
||||
|
||||
ObjectLock olock (vars);
|
||||
|
||||
BOOST_FOREACH(const Dictionary::Pair& kv, vars) {
|
||||
if (!kv.first.IsEmpty()) {
|
||||
int overridden = obj->IsVarOverridden(kv.first) ? 1 : 0;
|
||||
int overridden = custom_var_object->IsVarOverridden(kv.first) ? 1 : 0;
|
||||
|
||||
Log(LogDebug, "db_ido", "object customvar key: '" + kv.first + "' value: '" + Convert::ToString(kv.second) +
|
||||
"' overridden: " + Convert::ToString(overridden));
|
||||
|
@ -188,16 +194,21 @@ void DbObject::SendVarsStatusUpdate(void)
|
|||
{
|
||||
DynamicObject::Ptr obj = GetObject();
|
||||
|
||||
Dictionary::Ptr vars = CompatUtility::GetCustomAttributeConfig(obj);
|
||||
CustomVarObject::Ptr custom_var_object = dynamic_pointer_cast<CustomVarObject>(obj);
|
||||
|
||||
if (!custom_var_object)
|
||||
return;
|
||||
|
||||
Dictionary::Ptr vars = CompatUtility::GetCustomAttributeConfig(custom_var_object);
|
||||
|
||||
if (vars) {
|
||||
Log(LogDebug, "db_ido", "Updating object vars for '" + obj->GetName() + "'");
|
||||
Log(LogDebug, "db_ido", "Updating object vars for '" + custom_var_object->GetName() + "'");
|
||||
|
||||
ObjectLock olock (vars);
|
||||
|
||||
BOOST_FOREACH(const Dictionary::Pair& kv, vars) {
|
||||
if (!kv.first.IsEmpty()) {
|
||||
int overridden = obj->IsVarOverridden(kv.first) ? 1 : 0;
|
||||
int overridden = custom_var_object->IsVarOverridden(kv.first) ? 1 : 0;
|
||||
|
||||
Log(LogDebug, "db_ido", "object customvar key: '" + kv.first + "' value: '" + Convert::ToString(kv.second) +
|
||||
"' overridden: " + Convert::ToString(overridden));
|
||||
|
@ -307,7 +318,7 @@ void DbObject::StateChangedHandler(const DynamicObject::Ptr& object)
|
|||
dbobj->SendStatusUpdate();
|
||||
}
|
||||
|
||||
void DbObject::VarsChangedHandler(const DynamicObject::Ptr& object)
|
||||
void DbObject::VarsChangedHandler(const CustomVarObject::Ptr& object)
|
||||
{
|
||||
DbObject::Ptr dbobj = GetOrCreateByObject(object);
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "db_ido/dbreference.h"
|
||||
#include "db_ido/dbquery.h"
|
||||
#include "db_ido/dbtype.h"
|
||||
#include "icinga/customvarobject.h"
|
||||
#include "base/dynamicobject.h"
|
||||
|
||||
namespace icinga
|
||||
|
@ -103,7 +104,7 @@ private:
|
|||
double m_LastStatusUpdate;
|
||||
|
||||
static void StateChangedHandler(const DynamicObject::Ptr& object);
|
||||
static void VarsChangedHandler(const DynamicObject::Ptr& object);
|
||||
static void VarsChangedHandler(const CustomVarObject::Ptr& object);
|
||||
|
||||
friend class DbType;
|
||||
};
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#define DBQUERY_H
|
||||
|
||||
#include "db_ido/i2-db_ido.h"
|
||||
#include "icinga/customvarobject.h"
|
||||
#include "base/dictionary.h"
|
||||
#include "base/dynamicobject.h"
|
||||
|
||||
|
@ -66,7 +67,7 @@ struct I2_DB_IDO_API DbQuery
|
|||
Dictionary::Ptr Fields;
|
||||
Dictionary::Ptr WhereCriteria;
|
||||
shared_ptr<DbObject> Object;
|
||||
shared_ptr<DynamicObject> NotificationObject;
|
||||
shared_ptr<CustomVarObject> NotificationObject;
|
||||
bool ConfigUpdate;
|
||||
bool StatusUpdate;
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ mkclass_target(eventcommand.ti eventcommand.th)
|
|||
mkclass_target(hostgroup.ti hostgroup.th)
|
||||
mkclass_target(host.ti host.th)
|
||||
mkclass_target(icingaapplication.ti icingaapplication.th)
|
||||
mkclass_target(customvarobject.ti customvarobject.th)
|
||||
mkclass_target(icingastatuswriter.ti icingastatuswriter.th)
|
||||
mkclass_target(notificationcommand.ti notificationcommand.th)
|
||||
mkclass_target(notification.ti notification.th)
|
||||
|
@ -45,11 +46,11 @@ add_library(icinga SHARED
|
|||
cib.cpp command.cpp command.th comment.cpp comment.th compatutility.cpp dependency.cpp dependency.th
|
||||
dependency-apply.cpp downtime.cpp downtime.th eventcommand.cpp eventcommand.th
|
||||
externalcommandprocessor.cpp host.cpp host.th hostgroup.cpp hostgroup.th icingaapplication.cpp
|
||||
icingaapplication.th icingastatuswriter.cpp icingastatuswriter.th legacytimeperiod.cpp macroprocessor.cpp
|
||||
notificationcommand.cpp notificationcommand.th notification.cpp notification.th notification-apply.cpp
|
||||
perfdatavalue.cpp perfdatavalue.th pluginutility.cpp scheduleddowntime.cpp scheduleddowntime.th
|
||||
scheduleddowntime-apply.cpp service-apply.cpp checkable-check.cpp checkable-comment.cpp service.cpp
|
||||
service.th servicegroup.cpp servicegroup.th checkable-notification.cpp timeperiod.cpp timeperiod.th
|
||||
icingaapplication.th customvarobject.cpp customvarobject.th icingastatuswriter.cpp icingastatuswriter.th
|
||||
legacytimeperiod.cpp macroprocessor.cpp notificationcommand.cpp notificationcommand.th notification.cpp
|
||||
notification.th notification-apply.cpp perfdatavalue.cpp perfdatavalue.th pluginutility.cpp scheduleddowntime.cpp
|
||||
scheduleddowntime.th scheduleddowntime-apply.cpp service-apply.cpp checkable-check.cpp checkable-comment.cpp
|
||||
service.cpp service.th servicegroup.cpp servicegroup.th checkable-notification.cpp timeperiod.cpp timeperiod.th
|
||||
user.cpp user.th usergroup.cpp usergroup.th icinga-type.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "icinga/icingaapplication.h"
|
||||
#include "base/dynamicobject.h"
|
||||
#include "icinga/customvarobject.h"
|
||||
#include "base/array.h"
|
||||
|
||||
namespace icinga
|
||||
|
@ -19,7 +19,7 @@ enum AcknowledgementType
|
|||
};
|
||||
}}}
|
||||
|
||||
abstract class Checkable : DynamicObject
|
||||
abstract class Checkable : CustomVarObject
|
||||
{
|
||||
[config] Array::Ptr groups {
|
||||
default {{{ return make_shared<Array>(); }}}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include "base/dynamicobject.h"
|
||||
#include "icinga/customvarobject.h"
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
abstract class Command : DynamicObject
|
||||
abstract class Command : CustomVarObject
|
||||
{
|
||||
[config] Value command (CommandLine);
|
||||
[config] Value arguments;
|
||||
|
|
|
@ -349,7 +349,7 @@ int CompatUtility::GetCheckableInNotificationPeriod(const Checkable::Ptr& checka
|
|||
|
||||
/* vars attr */
|
||||
|
||||
bool CompatUtility::IsLegacyAttribute(DynamicObject::Ptr const& object, const String& name)
|
||||
bool CompatUtility::IsLegacyAttribute(CustomVarObject::Ptr const& object, const String& name)
|
||||
{
|
||||
if ((name == "address" ||
|
||||
name == "address6") &&
|
||||
|
@ -379,7 +379,7 @@ bool CompatUtility::IsLegacyAttribute(DynamicObject::Ptr const& object, const St
|
|||
return false;
|
||||
}
|
||||
|
||||
Dictionary::Ptr CompatUtility::GetCustomAttributeConfig(const DynamicObject::Ptr& object)
|
||||
Dictionary::Ptr CompatUtility::GetCustomAttributeConfig(const CustomVarObject::Ptr& object)
|
||||
{
|
||||
Dictionary::Ptr vars = object->GetVars();
|
||||
|
||||
|
@ -399,7 +399,7 @@ Dictionary::Ptr CompatUtility::GetCustomAttributeConfig(const DynamicObject::Ptr
|
|||
return varsvars;
|
||||
}
|
||||
|
||||
String CompatUtility::GetCustomAttributeConfig(const DynamicObject::Ptr& object, const String& name)
|
||||
String CompatUtility::GetCustomAttributeConfig(const CustomVarObject::Ptr& object, const String& name)
|
||||
{
|
||||
Dictionary::Ptr vars = object->GetVars();
|
||||
|
||||
|
@ -409,7 +409,7 @@ String CompatUtility::GetCustomAttributeConfig(const DynamicObject::Ptr& object,
|
|||
return vars->Get(name);
|
||||
}
|
||||
|
||||
Array::Ptr CompatUtility::GetModifiedAttributesList(const DynamicObject::Ptr& object)
|
||||
Array::Ptr CompatUtility::GetModifiedAttributesList(const CustomVarObject::Ptr& object)
|
||||
{
|
||||
Array::Ptr mod_attr_list = make_shared<Array>();
|
||||
|
||||
|
|
|
@ -21,11 +21,11 @@
|
|||
#define COMPATUTILITY_H
|
||||
|
||||
#include "icinga/i2-icinga.h"
|
||||
#include "icinga/customvarobject.h"
|
||||
#include "icinga/host.h"
|
||||
#include "icinga/command.h"
|
||||
#include "base/dictionary.h"
|
||||
#include "base/array.h"
|
||||
#include "base/dynamicobject.h"
|
||||
#include <vector>
|
||||
|
||||
namespace icinga
|
||||
|
@ -80,7 +80,7 @@ public:
|
|||
static int GetCheckableInCheckPeriod(const Checkable::Ptr& checkable);
|
||||
static int GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable);
|
||||
|
||||
static Array::Ptr GetModifiedAttributesList(const DynamicObject::Ptr& object);
|
||||
static Array::Ptr GetModifiedAttributesList(const CustomVarObject::Ptr& object);
|
||||
|
||||
/* notification */
|
||||
static int GetCheckableNotificationsEnabled(const Checkable::Ptr& checkable);
|
||||
|
@ -103,9 +103,9 @@ public:
|
|||
static std::set<UserGroup::Ptr> GetCheckableNotificationUserGroups(const Checkable::Ptr& checkable);
|
||||
|
||||
/* custom attribute */
|
||||
static bool IsLegacyAttribute(const DynamicObject::Ptr& object, const String& name);
|
||||
static String GetCustomAttributeConfig(const DynamicObject::Ptr& object, const String& name);
|
||||
static Dictionary::Ptr GetCustomAttributeConfig(const DynamicObject::Ptr& object);
|
||||
static bool IsLegacyAttribute(const CustomVarObject::Ptr& object, const String& name);
|
||||
static String GetCustomAttributeConfig(const CustomVarObject::Ptr& object, const String& name);
|
||||
static Dictionary::Ptr GetCustomAttributeConfig(const CustomVarObject::Ptr& object);
|
||||
|
||||
/* check result */
|
||||
static String GetCheckResultOutput(const CheckResult::Ptr& cr);
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "icinga/customvarobject.h"
|
||||
#include "base/logger_fwd.h"
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
REGISTER_TYPE(CustomVarObject);
|
||||
|
||||
boost::signals2::signal<void (const CustomVarObject::Ptr&)> CustomVarObject::OnVarsChanged;
|
||||
|
||||
Dictionary::Ptr CustomVarObject::GetVars(void) const
|
||||
{
|
||||
if (!GetOverrideVars().IsEmpty())
|
||||
return GetOverrideVars();
|
||||
else
|
||||
return GetVarsRaw();
|
||||
}
|
||||
|
||||
void CustomVarObject::SetVars(const Dictionary::Ptr& vars)
|
||||
{
|
||||
SetOverrideVars(vars);
|
||||
|
||||
Log(LogDebug, "icinga", "Setting vars for object '" + GetName() + "'");
|
||||
|
||||
OnVarsChanged(GetSelf());
|
||||
}
|
||||
|
||||
int CustomVarObject::GetModifiedAttributes(void) const
|
||||
{
|
||||
/* does nothing by default */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CustomVarObject::SetModifiedAttributes(int, const MessageOrigin&)
|
||||
{
|
||||
/* does nothing by default */
|
||||
}
|
||||
|
||||
bool CustomVarObject::IsVarOverridden(const String& name)
|
||||
{
|
||||
Dictionary::Ptr vars_override = GetOverrideVars();
|
||||
|
||||
if (!vars_override)
|
||||
return false;
|
||||
|
||||
return vars_override->Contains(name);
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef CUSTOMVAROBJECT_H
|
||||
#define CUSTOMVAROBJECT_H
|
||||
|
||||
#include "icinga/customvarobject.th"
|
||||
#include "base/dynamicobject.h"
|
||||
#include "remote/messageorigin.h"
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
enum ModifiedAttributeType
|
||||
{
|
||||
ModAttrNotificationsEnabled = 1,
|
||||
ModAttrActiveChecksEnabled = 2,
|
||||
ModAttrPassiveChecksEnabled = 4,
|
||||
ModAttrEventHandlerEnabled = 8,
|
||||
ModAttrFlapDetectionEnabled = 16,
|
||||
ModAttrFailurePredictionEnabled = 32,
|
||||
ModAttrPerformanceDataEnabled = 64,
|
||||
ModAttrObsessiveHandlerEnabled = 128,
|
||||
ModAttrEventHandlerCommand = 256,
|
||||
ModAttrCheckCommand = 512,
|
||||
ModAttrNormalCheckInterval = 1024,
|
||||
ModAttrRetryCheckInterval = 2048,
|
||||
ModAttrMaxCheckAttempts = 4096,
|
||||
ModAttrFreshnessChecksEnabled = 8192,
|
||||
ModAttrCheckTimeperiod = 16384,
|
||||
ModAttrCustomVariable = 32768,
|
||||
ModAttrNotificationTimeperiod = 65536
|
||||
};
|
||||
|
||||
/**
|
||||
* A dynamic object that can be instantiated from the configuration file
|
||||
* and that supports attribute replication to remote application instances.
|
||||
*
|
||||
* @ingroup base
|
||||
*/
|
||||
class I2_BASE_API CustomVarObject : public ObjectImpl<CustomVarObject>
|
||||
{
|
||||
public:
|
||||
DECLARE_PTR_TYPEDEFS(CustomVarObject);
|
||||
|
||||
static boost::signals2::signal<void (const CustomVarObject::Ptr&)> OnVarsChanged;
|
||||
|
||||
Dictionary::Ptr GetVars(void) const;
|
||||
void SetVars(const Dictionary::Ptr& vars);
|
||||
|
||||
virtual int GetModifiedAttributes(void) const;
|
||||
virtual void SetModifiedAttributes(int flags, const MessageOrigin& origin = MessageOrigin());
|
||||
|
||||
bool IsVarOverridden(const String& name);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* CUSTOMVAROBJECT_H */
|
|
@ -0,0 +1,13 @@
|
|||
#include "base/dynamicobject.h"
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
abstract class CustomVarObject : DynamicObject
|
||||
{
|
||||
[config] Dictionary::Ptr vars (VarsRaw);
|
||||
|
||||
[state] Value override_vars;
|
||||
};
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
#include "base/dynamicobject.h"
|
||||
#include "icinga/customvarobject.h"
|
||||
#include "icinga/checkable.h"
|
||||
|
||||
namespace icinga
|
||||
|
@ -12,7 +12,7 @@ public:
|
|||
};
|
||||
}}}
|
||||
|
||||
class Dependency : DynamicObject < DependencyNameComposer
|
||||
class Dependency : CustomVarObject < DependencyNameComposer
|
||||
{
|
||||
[config] String child_host_name;
|
||||
[config] String child_service_name;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "icinga/checkable.h"
|
||||
#include "base/dynamicobject.h"
|
||||
#include "icinga/customvarobject.h"
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include "base/dynamicobject.h"
|
||||
#include "icinga/customvarobject.h"
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
class HostGroup : DynamicObject
|
||||
class HostGroup : CustomVarObject
|
||||
{
|
||||
[config] String display_name {
|
||||
get {{{
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include "base/dynamicobject.h"
|
||||
#include "icinga/customvarobject.h"
|
||||
#include "base/application.h"
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
class IcingaStatusWriter : DynamicObject
|
||||
class IcingaStatusWriter : CustomVarObject
|
||||
{
|
||||
[config] String status_path {
|
||||
default {{{ return Application::GetLocalStateDir() + "/cache/icinga2/status.json"; }}}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "icinga/macroprocessor.h"
|
||||
#include "icinga/macroresolver.h"
|
||||
#include "icinga/customvarobject.h"
|
||||
#include "base/array.h"
|
||||
#include "base/objectlock.h"
|
||||
#include "base/logger_fwd.h"
|
||||
|
@ -82,7 +83,7 @@ bool MacroProcessor::ResolveMacro(const String& macro, const ResolverList& resol
|
|||
continue;
|
||||
|
||||
if (objName.IsEmpty()) {
|
||||
DynamicObject::Ptr dobj = dynamic_pointer_cast<DynamicObject>(resolver.second);
|
||||
CustomVarObject::Ptr dobj = dynamic_pointer_cast<CustomVarObject>(resolver.second);
|
||||
|
||||
if (dobj) {
|
||||
Dictionary::Ptr vars = dobj->GetVars();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "base/dynamicobject.h"
|
||||
#include "icinga/customvarobject.h"
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
@ -11,7 +11,7 @@ public:
|
|||
};
|
||||
}}}
|
||||
|
||||
class Notification : DynamicObject < NotificationNameComposer
|
||||
class Notification : CustomVarObject < NotificationNameComposer
|
||||
{
|
||||
[config, protected] String command (CommandRaw);
|
||||
[config] double interval {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "base/dynamicobject.h"
|
||||
#include "icinga/customvarobject.h"
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "base/dynamicobject.h"
|
||||
#include "icinga/customvarobject.h"
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
@ -11,7 +11,7 @@ public:
|
|||
};
|
||||
}}}
|
||||
|
||||
class ScheduledDowntime : DynamicObject < ScheduledDowntimeNameComposer
|
||||
class ScheduledDowntime : CustomVarObject < ScheduledDowntimeNameComposer
|
||||
{
|
||||
[config, protected] String host_name;
|
||||
[config, protected] String service_name;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "icinga/checkable.h"
|
||||
#include "icinga/host.h"
|
||||
#include "icinga/icingaapplication.h"
|
||||
#include "base/dynamicobject.h"
|
||||
#include "icinga/customvarobject.h"
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include "base/dynamicobject.h"
|
||||
#include "icinga/customvarobject.h"
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
class ServiceGroup : DynamicObject
|
||||
class ServiceGroup : CustomVarObject
|
||||
{
|
||||
[config] String display_name {
|
||||
get {{{
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include "base/dynamicobject.h"
|
||||
#include "icinga/customvarobject.h"
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
class TimePeriod : DynamicObject
|
||||
class TimePeriod : CustomVarObject
|
||||
{
|
||||
[config] String display_name {
|
||||
get {{{
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include "base/dynamicobject.h"
|
||||
#include "icinga/customvarobject.h"
|
||||
#include "base/array.h"
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
class User : DynamicObject
|
||||
class User : CustomVarObject
|
||||
{
|
||||
[config] String display_name {
|
||||
get {{{
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include "base/dynamicobject.h"
|
||||
#include "icinga/customvarobject.h"
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
class UserGroup : DynamicObject
|
||||
class UserGroup : CustomVarObject
|
||||
{
|
||||
[config] String display_name {
|
||||
get {{{
|
||||
|
|
Loading…
Reference in New Issue