Skip to content
Permalink
Browse files

Merge 'macros' and 'custom' attributes into 'vars', part 1.

Refs #5855
  • Loading branch information
dnsmichi committed Apr 3, 2014
1 parent c58e226 commit 5c58eb368c0d5532fbbaa68973dd48675d154bee
@@ -516,13 +516,13 @@ void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& s

void StatusDataWriter::DumpCustomAttributes(std::ostream& fp, const DynamicObject::Ptr& object)
{
Dictionary::Ptr custom = object->GetCustom();
Dictionary::Ptr vars = object->GetVars();

if (!custom)
if (!vars)
return;

ObjectLock olock(custom);
BOOST_FOREACH(const Dictionary::Pair& kv, custom) {
ObjectLock olock(vars);
BOOST_FOREACH(const Dictionary::Pair& kv, vars) {
if (!kv.first.IsEmpty()) {
fp << "\t";

@@ -47,9 +47,9 @@ void ContactsTable::AddColumns(Table *table, const String& prefix,
table->AddColumn(prefix + "service_notifications_enabled", Column(&ContactsTable::ServiceNotificationsEnabledAccessor, objectAccessor));
table->AddColumn(prefix + "in_host_notification_period", Column(&ContactsTable::InHostNotificationPeriodAccessor, objectAccessor));
table->AddColumn(prefix + "in_service_notification_period", Column(&ContactsTable::InServiceNotificationPeriodAccessor, objectAccessor));
table->AddColumn(prefix + "custom_variable_names", Column(&ContactsTable::CustomVariableNamesAccessor, objectAccessor));
table->AddColumn(prefix + "custom_variable_values", Column(&ContactsTable::CustomVariableValuesAccessor, objectAccessor));
table->AddColumn(prefix + "custom_variables", Column(&ContactsTable::CustomVariablesAccessor, objectAccessor));
table->AddColumn(prefix + "vars_variable_names", Column(&ContactsTable::CustomVariableNamesAccessor, objectAccessor));
table->AddColumn(prefix + "vars_variable_values", Column(&ContactsTable::CustomVariableValuesAccessor, objectAccessor));
table->AddColumn(prefix + "vars_variables", Column(&ContactsTable::CustomVariablesAccessor, objectAccessor));
table->AddColumn(prefix + "modified_attributes", Column(&ContactsTable::ModifiedAttributesAccessor, objectAccessor));
table->AddColumn(prefix + "modified_attributes_list", Column(&ContactsTable::ModifiedAttributesListAccessor, objectAccessor));
}
@@ -93,12 +93,12 @@ Value ContactsTable::EmailAccessor(const Value& row)
if (!user)
return Empty;

Dictionary::Ptr macros = user->GetMacros();
Dictionary::Ptr vars = user->GetVars();

if (!macros)
if (!vars)
return Empty;

return macros->Get("email");
return vars->Get("email");
}

Value ContactsTable::PagerAccessor(const Value& row)
@@ -108,12 +108,12 @@ Value ContactsTable::PagerAccessor(const Value& row)
if (!user)
return Empty;

Dictionary::Ptr macros = user->GetMacros();
Dictionary::Ptr vars = user->GetVars();

if (!macros)
if (!vars)
return Empty;

return macros->Get("pager");
return vars->Get("pager");
}

Value ContactsTable::HostNotificationPeriodAccessor(const Value& row)
@@ -204,17 +204,17 @@ Value ContactsTable::CustomVariableNamesAccessor(const Value& row)
if (!user)
return Empty;

Dictionary::Ptr custom = user->GetCustom();
Dictionary::Ptr vars = user->GetVars();

if (!custom)
if (!vars)
return Empty;

Array::Ptr cv = make_shared<Array>();

ObjectLock olock(custom);
ObjectLock olock(vars);
String key;
Value value;
BOOST_FOREACH(boost::tie(key, value), custom) {
BOOST_FOREACH(boost::tie(key, value), vars) {
if (key == "notes" ||
key == "action_url" ||
key == "notes_url" ||
@@ -237,17 +237,17 @@ Value ContactsTable::CustomVariableValuesAccessor(const Value& row)
if (!user)
return Empty;

Dictionary::Ptr custom = user->GetCustom();
Dictionary::Ptr vars = user->GetVars();

if (!custom)
if (!vars)
return Empty;

Array::Ptr cv = make_shared<Array>();

ObjectLock olock(custom);
ObjectLock olock(vars);
String key;
Value value;
BOOST_FOREACH(boost::tie(key, value), custom) {
BOOST_FOREACH(boost::tie(key, value), vars) {
if (key == "notes" ||
key == "action_url" ||
key == "notes_url" ||
@@ -270,17 +270,17 @@ Value ContactsTable::CustomVariablesAccessor(const Value& row)
if (!user)
return Empty;

Dictionary::Ptr custom = user->GetCustom();
Dictionary::Ptr vars = user->GetVars();

if (!custom)
if (!vars)
return Empty;

Array::Ptr cv = make_shared<Array>();

ObjectLock olock(custom);
ObjectLock olock(vars);
String key;
Value value;
BOOST_FOREACH(boost::tie(key, value), custom) {
BOOST_FOREACH(boost::tie(key, value), vars) {
if (key == "notes" ||
key == "action_url" ||
key == "notes_url" ||
@@ -85,32 +85,32 @@ Value HostGroupsTable::AliasAccessor(const Value& row)

Value HostGroupsTable::NotesAccessor(const Value& row)
{
Dictionary::Ptr custom = static_cast<HostGroup::Ptr>(row)->GetCustom();
Dictionary::Ptr vars = static_cast<HostGroup::Ptr>(row)->GetVars();

if (!custom)
if (!vars)
return Empty;

return custom->Get("notes");
return vars->Get("notes");
}

Value HostGroupsTable::NotesUrlAccessor(const Value& row)
{
Dictionary::Ptr custom = static_cast<HostGroup::Ptr>(row)->GetCustom();
Dictionary::Ptr vars = static_cast<HostGroup::Ptr>(row)->GetVars();

if (!custom)
if (!vars)
return Empty;

return custom->Get("notes_url");
return vars->Get("notes_url");
}

Value HostGroupsTable::ActionUrlAccessor(const Value& row)
{
Dictionary::Ptr custom = static_cast<HostGroup::Ptr>(row)->GetCustom();
Dictionary::Ptr vars = static_cast<HostGroup::Ptr>(row)->GetVars();

if (!custom)
if (!vars)
return Empty;

return custom->Get("action_url");
return vars->Get("action_url");
}

Value HostGroupsTable::MembersAccessor(const Value& row)
@@ -1372,21 +1372,21 @@ Value HostsTable::CustomVariableNamesAccessor(const Value& row)
if (!host)
return Empty;

Dictionary::Ptr customvars;
Dictionary::Ptr vars;

{
ObjectLock olock(host);
customvars = CompatUtility::GetCustomVariableConfig(host);
vars = CompatUtility::GetCustomAttributeConfig(host);
}

if (!customvars)
if (!vars)
return Empty;

Array::Ptr cv = make_shared<Array>();

String key;
Value value;
BOOST_FOREACH(boost::tie(key, value), customvars) {
BOOST_FOREACH(boost::tie(key, value), vars) {
cv->Add(key);
}

@@ -1400,21 +1400,21 @@ Value HostsTable::CustomVariableValuesAccessor(const Value& row)
if (!host)
return Empty;

Dictionary::Ptr customvars;
Dictionary::Ptr vars;

{
ObjectLock olock(host);
customvars = CompatUtility::GetCustomVariableConfig(host);
vars = CompatUtility::GetCustomAttributeConfig(host);
}

if (!customvars)
if (!vars)
return Empty;

Array::Ptr cv = make_shared<Array>();

String key;
Value value;
BOOST_FOREACH(boost::tie(key, value), customvars) {
BOOST_FOREACH(boost::tie(key, value), vars) {
cv->Add(value);
}

@@ -1428,21 +1428,21 @@ Value HostsTable::CustomVariablesAccessor(const Value& row)
if (!host)
return Empty;

Dictionary::Ptr customvars;
Dictionary::Ptr vars;

{
ObjectLock olock(host);
customvars = CompatUtility::GetCustomVariableConfig(host);
vars = CompatUtility::GetCustomAttributeConfig(host);
}

if (!customvars)
if (!vars)
return Empty;

Array::Ptr cv = make_shared<Array>();

String key;
Value value;
BOOST_FOREACH(boost::tie(key, value), customvars) {
BOOST_FOREACH(boost::tie(key, value), vars) {
Array::Ptr key_val = make_shared<Array>();
key_val->Add(key);
key_val->Add(value);
@@ -76,32 +76,32 @@ Value ServiceGroupsTable::AliasAccessor(const Value& row)

Value ServiceGroupsTable::NotesAccessor(const Value& row)
{
Dictionary::Ptr custom = static_cast<ServiceGroup::Ptr>(row)->GetCustom();
Dictionary::Ptr vars = static_cast<ServiceGroup::Ptr>(row)->GetVars();

if (!custom)
if (!vars)
return Empty;

return custom->Get("notes");
return vars->Get("notes");
}

Value ServiceGroupsTable::NotesUrlAccessor(const Value& row)
{
Dictionary::Ptr custom = static_cast<ServiceGroup::Ptr>(row)->GetCustom();
Dictionary::Ptr vars = static_cast<ServiceGroup::Ptr>(row)->GetVars();

if (!custom)
if (!vars)
return Empty;

return custom->Get("notes_url");
return vars->Get("notes_url");
}

Value ServiceGroupsTable::ActionUrlAccessor(const Value& row)
{
Dictionary::Ptr custom = static_cast<ServiceGroup::Ptr>(row)->GetCustom();
Dictionary::Ptr vars = static_cast<ServiceGroup::Ptr>(row)->GetVars();

if (!custom)
if (!vars)
return Empty;

return custom->Get("action_url");
return vars->Get("action_url");
}

Value ServiceGroupsTable::MembersAccessor(const Value& row)
@@ -1049,21 +1049,21 @@ Value ServicesTable::CustomVariableNamesAccessor(const Value& row)
if (!service)
return Empty;

Dictionary::Ptr customvars;
Dictionary::Ptr vars;

{
ObjectLock olock(service);
customvars = CompatUtility::GetCustomVariableConfig(service);
vars = CompatUtility::GetCustomAttributeConfig(service);
}

if (!customvars)
if (!vars)
return Empty;

Array::Ptr cv = make_shared<Array>();

String key;
Value value;
BOOST_FOREACH(boost::tie(key, value), customvars) {
BOOST_FOREACH(boost::tie(key, value), vars) {
cv->Add(key);
}

@@ -1077,21 +1077,21 @@ Value ServicesTable::CustomVariableValuesAccessor(const Value& row)
if (!service)
return Empty;

Dictionary::Ptr customvars;
Dictionary::Ptr vars;

{
ObjectLock olock(service);
customvars = CompatUtility::GetCustomVariableConfig(service);
vars = CompatUtility::GetCustomAttributeConfig(service);
}

if (!customvars)
if (!vars)
return Empty;

Array::Ptr cv = make_shared<Array>();

String key;
Value value;
BOOST_FOREACH(boost::tie(key, value), customvars) {
BOOST_FOREACH(boost::tie(key, value), vars) {
cv->Add(value);
}

@@ -1105,21 +1105,21 @@ Value ServicesTable::CustomVariablesAccessor(const Value& row)
if (!service)
return Empty;

Dictionary::Ptr customvars;
Dictionary::Ptr vars;

{
ObjectLock olock(service);
customvars = CompatUtility::GetCustomVariableConfig(service);
vars = CompatUtility::GetCustomAttributeConfig(service);
}

if (!customvars)
if (!vars)
return Empty;

Array::Ptr cv = make_shared<Array>();

String key;
Value value;
BOOST_FOREACH(boost::tie(key, value), customvars) {
BOOST_FOREACH(boost::tie(key, value), vars) {
Array::Ptr key_val = make_shared<Array>();
key_val->Add(key);
key_val->Add(value);
@@ -66,7 +66,7 @@ up macros:
2. Service object
3. Host object
4. Command object
5. Global macros in the IcingaMacros constant
5. Global custom attributes in the IcingaVars constant

This execution order allows you to define default values for macros in your
command objects. The `my-ping` command shown above uses this to set default
@@ -10,7 +10,7 @@ IcingaLocalStateDir |**Read-only.** Contains the path of the local state d
IcingaPkgDataDir |**Read-only.** Contains the path of the package data directory. Defaults to IcingaPrefixDir + "/share/icinga2".
IcingaStatePath |**Read-write.** Contains the path of the Icinga 2 state file. Defaults to IcingaLocalStateDir + "/lib/icinga2/icinga2.state".
IcingaPidPath |**Read-write.** Contains the path of the Icinga 2 PID file. Defaults to IcingaLocalStateDir + "/run/icinga2/icinga2.pid".
IcingaMacros |**Read-write.** Contains a dictionary with global macros. Not set by default.
IcingaVars |**Read-write.** Contains a dictionary with global custom attributes. Not set by default.
IcingaNodeName |**Read-write.** Contains the cluster node name. Set to the local hostname by default.
ApplicationType |**Read-write.** Contains the name of the Application type. Defaults to "icinga/IcingaApplication".
IcingaEnableNotifications |**Read-write.** Whether notifications are globally enabled. Defaults to true.

0 comments on commit 5c58eb3

Please sign in to comment.
You can’t perform that action at this time.