From: Michael Friedrich Date: Thu, 3 Apr 2014 08:30:11 +0000 (+0200) Subject: Merge 'macros' and 'custom' attributes into 'vars', part 1. X-Git-Tag: v0.0.10~231 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5c58eb368c0d5532fbbaa68973dd48675d154bee;p=icinga2 Merge 'macros' and 'custom' attributes into 'vars', part 1. Refs #5855 --- diff --git a/components/compat/statusdatawriter.cpp b/components/compat/statusdatawriter.cpp index a786ab50a..65e806c9e 100644 --- a/components/compat/statusdatawriter.cpp +++ b/components/compat/statusdatawriter.cpp @@ -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"; diff --git a/components/livestatus/contactstable.cpp b/components/livestatus/contactstable.cpp index d18f12177..bf4653237 100644 --- a/components/livestatus/contactstable.cpp +++ b/components/livestatus/contactstable.cpp @@ -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(); - 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(); - 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(); - 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" || diff --git a/components/livestatus/hostgroupstable.cpp b/components/livestatus/hostgroupstable.cpp index 5ff8ad5be..8557959e5 100644 --- a/components/livestatus/hostgroupstable.cpp +++ b/components/livestatus/hostgroupstable.cpp @@ -85,32 +85,32 @@ Value HostGroupsTable::AliasAccessor(const Value& row) Value HostGroupsTable::NotesAccessor(const Value& row) { - Dictionary::Ptr custom = static_cast(row)->GetCustom(); + Dictionary::Ptr vars = static_cast(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(row)->GetCustom(); + Dictionary::Ptr vars = static_cast(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(row)->GetCustom(); + Dictionary::Ptr vars = static_cast(row)->GetVars(); - if (!custom) + if (!vars) return Empty; - return custom->Get("action_url"); + return vars->Get("action_url"); } Value HostGroupsTable::MembersAccessor(const Value& row) diff --git a/components/livestatus/hoststable.cpp b/components/livestatus/hoststable.cpp index 281faeaff..243dd4f2d 100644 --- a/components/livestatus/hoststable.cpp +++ b/components/livestatus/hoststable.cpp @@ -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(); 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(); 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(); String key; Value value; - BOOST_FOREACH(boost::tie(key, value), customvars) { + BOOST_FOREACH(boost::tie(key, value), vars) { Array::Ptr key_val = make_shared(); key_val->Add(key); key_val->Add(value); diff --git a/components/livestatus/servicegroupstable.cpp b/components/livestatus/servicegroupstable.cpp index e3373d3cf..6b6febfac 100644 --- a/components/livestatus/servicegroupstable.cpp +++ b/components/livestatus/servicegroupstable.cpp @@ -76,32 +76,32 @@ Value ServiceGroupsTable::AliasAccessor(const Value& row) Value ServiceGroupsTable::NotesAccessor(const Value& row) { - Dictionary::Ptr custom = static_cast(row)->GetCustom(); + Dictionary::Ptr vars = static_cast(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(row)->GetCustom(); + Dictionary::Ptr vars = static_cast(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(row)->GetCustom(); + Dictionary::Ptr vars = static_cast(row)->GetVars(); - if (!custom) + if (!vars) return Empty; - return custom->Get("action_url"); + return vars->Get("action_url"); } Value ServiceGroupsTable::MembersAccessor(const Value& row) diff --git a/components/livestatus/servicestable.cpp b/components/livestatus/servicestable.cpp index 664729d58..0fa3bfef2 100644 --- a/components/livestatus/servicestable.cpp +++ b/components/livestatus/servicestable.cpp @@ -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(); 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(); 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(); String key; Value value; - BOOST_FOREACH(boost::tie(key, value), customvars) { + BOOST_FOREACH(boost::tie(key, value), vars) { Array::Ptr key_val = make_shared(); key_val->Add(key); key_val->Add(value); diff --git a/doc/3.03-macros.md b/doc/3.03-macros.md index ab1300cd1..25488fca4 100644 --- a/doc/3.03-macros.md +++ b/doc/3.03-macros.md @@ -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 diff --git a/doc/4.2-global-variables.md b/doc/4.2-global-variables.md index 169e10295..6d018b39d 100644 --- a/doc/4.2-global-variables.md +++ b/doc/4.2-global-variables.md @@ -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. diff --git a/etc/icinga2/conf.d/generic-host.conf b/etc/icinga2/conf.d/generic-host.conf index 28be6ae8a..659071c2d 100644 --- a/etc/icinga2/conf.d/generic-host.conf +++ b/etc/icinga2/conf.d/generic-host.conf @@ -12,7 +12,7 @@ apply Service "ping4" { check_command = "ping4" assign where "generic-host" in host.templates - ignore where !host.macros.address + ignore where !host.vars.address } apply Service "ping6" { @@ -21,7 +21,7 @@ apply Service "ping6" { check_command = "ping6" assign where "generic-host" in host.templates - ignore where !host.macros.address6 + ignore where !host.vars.address6 } template Host "linux-server" { diff --git a/etc/icinga2/conf.d/localhost.conf b/etc/icinga2/conf.d/localhost.conf index 60c5f519b..c0212a0f1 100644 --- a/etc/icinga2/conf.d/localhost.conf +++ b/etc/icinga2/conf.d/localhost.conf @@ -6,8 +6,8 @@ object Host "localhost" { import "linux-server" - macros.address = "127.0.0.1" - macros.address6 = "::1" + vars.address = "127.0.0.1" + vars.address6 = "::1" } apply Service "icinga" { diff --git a/etc/icinga2/conf.d/users.conf b/etc/icinga2/conf.d/users.conf index 50183957d..762184f56 100644 --- a/etc/icinga2/conf.d/users.conf +++ b/etc/icinga2/conf.d/users.conf @@ -9,13 +9,11 @@ object User "icingaadmin" { display_name = "Icinga 2 Admin" groups = [ "icingaadmins" ] - macros = { - name = "Icinga 2 Admin" - email = "icinga@localhost" - pager = "icingaadmin@localhost.localdomain" - } + vars.name = "Icinga 2 Admin" + vars.email = "icinga@localhost" + vars.pager = "icingaadmin@localhost.localdomain" - custom.notes = "This is the Icinga 2 Admin account." + vars.notes = "This is the Icinga 2 Admin account." } diff --git a/itl/command-common.conf b/itl/command-common.conf index 28afbab6e..73e3536e0 100644 --- a/itl/command-common.conf +++ b/itl/command-common.conf @@ -30,16 +30,14 @@ object CheckCommand "ping4" { "-t", "$timeout$" ], - macros = { - wrta = 100, - wpl = 5, + vars.wrta = 100, + vars.wpl = 5, - crta = 200, - cpl = 15, + vars.crta = 200, + vars.cpl = 15, - packets = 5, - timeout = 0 - } + vars.packets = 5, + vars.timeout = 0 } object CheckCommand "ping6" { @@ -55,16 +53,14 @@ object CheckCommand "ping6" { "-t", "$timeout$" ], - macros = { - wrta = 100, - wpl = 5, + vars.wrta = 100, + vars.wpl = 5, - crta = 200, - cpl = 15, + vars.crta = 200, + vars.cpl = 15, - packets = 5, - timeout = 0 - } + vars.packets = 5, + vars.timeout = 0 } object CheckCommand "dummy" { @@ -76,19 +72,15 @@ object CheckCommand "dummy" { "$text$" ], - macros = { - state = 0, - text = "Check was successful." - } + vars.state = 0, + vars.text = "Check was successful." } object CheckCommand "passive" { import "dummy", - macros = { - state = 3, - text = "No Passive Check Result Received." - } + vars.state = 3, + vars.text = "No Passive Check Result Received." } object CheckCommand "tcp" { @@ -165,7 +157,7 @@ object CheckCommand "ssmtp" { "-p", "$port$" ], - macros.port = 465 + vars.port = 465 } object CheckCommand "ntp_time" { @@ -195,10 +187,8 @@ object CheckCommand "disk" { "-c", "$cfree$%" ], - macros = { - wfree = 20, - cfree = 10, - } + vars.wfree = 20, + vars.cfree = 10, } object CheckCommand "users"{ @@ -210,10 +200,8 @@ object CheckCommand "users"{ "-c", "$cgreater$" ], - macros = { - wgreater = 20, - cgreater = 50, - } + vars.wgreater = 20, + vars.cgreater = 50, } object CheckCommand "processes"{ @@ -225,10 +213,8 @@ object CheckCommand "processes"{ "-c", "$cgreater$" ], - macros = { - wgreater = 250, - cgreater = 400, - } + vars.wgreater = 250, + vars.cgreater = 400, } object CheckCommand "load"{ @@ -240,15 +226,13 @@ object CheckCommand "load"{ "-c", "$cload1$,$cload5$,$cload15$" ], - macros = { - wload1 = 5.0, - wload5 = 4.0, - wload15 = 3.0, + vars.wload1 = 5.0, + vars.wload5 = 4.0, + vars.wload15 = 3.0, - cload1 = 10.0, - cload5 = 6.0, - cload15 = 4.0 - } + vars.cload1 = 10.0, + vars.cload5 = 6.0, + vars.cload15 = 4.0 } object CheckCommand "snmp"{ @@ -261,13 +245,13 @@ object CheckCommand "snmp"{ "-C", "$community$" ], - macros.community = "public" + vars.community = "public" } object CheckCommand "snmp-uptime"{ import "snmp", - macros.oid = "1.3.6.1.2.1.1.3.0" + vars.oid = "1.3.6.1.2.1.1.3.0" } object CheckCommand "icinga"{ @@ -290,5 +274,5 @@ object CheckCommand "snmp-extend"{ "$plugin$" ], - macros.community = "public" + vars.community = "public" } diff --git a/lib/base/dynamicobject.ti b/lib/base/dynamicobject.ti index 682eb228d..ca18ea159 100644 --- a/lib/base/dynamicobject.ti +++ b/lib/base/dynamicobject.ti @@ -7,7 +7,7 @@ abstract class DynamicObject [config, get_protected] String type (TypeName); [config, get_protected] Array::Ptr templates; [config] Dictionary::Ptr methods; - [config] Dictionary::Ptr custom; + [config] Dictionary::Ptr vars; [config] Array::Ptr domains; [config] Array::Ptr authorities; [get_protected] bool active; diff --git a/lib/config/base-type.conf b/lib/config/base-type.conf index 66411d726..d4648e741 100644 --- a/lib/config/base-type.conf +++ b/lib/config/base-type.conf @@ -30,7 +30,7 @@ %attribute %dictionary "methods", - %attribute %dictionary "custom" { + %attribute %dictionary "vars" { %attribute %string "*" }, diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 2d8692378..787e84ecf 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -277,18 +277,18 @@ void HostDbObject::OnConfigUpdate(void) } /* custom variables */ - Dictionary::Ptr customvars; + Dictionary::Ptr vars; { ObjectLock olock(host); - customvars = CompatUtility::GetCustomVariableConfig(host); + vars = CompatUtility::GetCustomAttributeConfig(host); } - if (customvars) { - Log(LogDebug, "ido", "Dumping host customvars for '" + host->GetName() + "'"); + if (vars) { + Log(LogDebug, "ido", "Dumping host vars for '" + host->GetName() + "'"); - ObjectLock olock (customvars); + ObjectLock olock (vars); - BOOST_FOREACH(const Dictionary::Pair& kv, customvars) { + BOOST_FOREACH(const Dictionary::Pair& kv, vars) { if (!kv.first.IsEmpty()) { Log(LogDebug, "db_ido", "host customvar key: '" + kv.first + "' value: '" + Convert::ToString(kv.second) + "'"); diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 208e516fa..cdc94252f 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -264,19 +264,19 @@ void ServiceDbObject::OnConfigUpdate(void) } /* custom variables */ - Dictionary::Ptr customvars; + Dictionary::Ptr vars; { ObjectLock olock(service); - customvars = CompatUtility::GetCustomVariableConfig(service); + vars = CompatUtility::GetCustomAttributeConfig(service); } - if (customvars) { - Log(LogDebug, "db_ido", "Dumping service customvars for '" + service->GetName() + "'"); + if (vars) { + Log(LogDebug, "db_ido", "Dumping service vars for '" + service->GetName() + "'"); - ObjectLock olock(customvars); + ObjectLock olock(vars); - BOOST_FOREACH(const Dictionary::Pair& kv, customvars) { + BOOST_FOREACH(const Dictionary::Pair& kv, vars) { if (!kv.first.IsEmpty()) { Log(LogDebug, "db_ido", "service customvar key: '" + kv.first + "' value: '" + Convert::ToString(kv.second) + "'"); diff --git a/lib/db_ido/userdbobject.cpp b/lib/db_ido/userdbobject.cpp index f5cdb95df..01389bcb4 100644 --- a/lib/db_ido/userdbobject.cpp +++ b/lib/db_ido/userdbobject.cpp @@ -42,11 +42,11 @@ Dictionary::Ptr UserDbObject::GetConfigFields(void) const fields->Set("alias", user->GetDisplayName()); - Dictionary::Ptr macros = user->GetMacros(); + Dictionary::Ptr vars = user->GetVars(); - if (macros) { /* Yuck. */ - fields->Set("email_address", macros->Get("email")); - fields->Set("pager_address", macros->Get("pager")); + if (vars) { /* Yuck. */ + fields->Set("email_address", vars->Get("email")); + fields->Set("pager_address", vars->Get("pager")); } fields->Set("host_timeperiod_object_id", user->GetNotificationPeriod()); @@ -93,12 +93,12 @@ void UserDbObject::OnConfigUpdate(void) /* contact addresses */ Log(LogDebug, "db_ido", "contact addresses for '" + user->GetName() + "'"); - Dictionary::Ptr macros = user->GetMacros(); + Dictionary::Ptr vars = user->GetVars(); - if (macros) { /* This is sparta. */ + if (vars) { /* This is sparta. */ for (int i = 1; i <= 6; i++) { String key = "address" + Convert::ToString(i); - String val = macros->Get(key); + String val = vars->Get(key); if (val.IsEmpty()) continue; diff --git a/lib/icinga/command.cpp b/lib/icinga/command.cpp index cb0c8ef07..f419f52b4 100644 --- a/lib/icinga/command.cpp +++ b/lib/icinga/command.cpp @@ -25,10 +25,10 @@ REGISTER_TYPE(Command); bool Command::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const { - Dictionary::Ptr macros = GetMacros(); + Dictionary::Ptr vars = GetVars(); - if (macros && macros->Contains(macro)) { - *result = macros->Get(macro); + if (vars && vars->Contains(macro)) { + *result = vars->Get(macro); return true; } diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 501216184..252b3385b 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -73,12 +73,12 @@ String CompatUtility::GetHostAddress(const Host::Ptr& host) { ASSERT(host->OwnsLock()); - Dictionary::Ptr macros = host->GetMacros(); + Dictionary::Ptr vars = host->GetVars(); String address; - if (macros) - address = macros->Get("address"); + if (vars) + address = vars->Get("address"); if (address.IsEmpty()) address = host->GetName(); @@ -90,12 +90,12 @@ String CompatUtility::GetHostAddress6(const Host::Ptr& host) { ASSERT(host->OwnsLock()); - Dictionary::Ptr macros = host->GetMacros(); + Dictionary::Ptr vars = host->GetVars(); String address6; - if (macros) - address6 = macros->Get("address6"); + if (vars) + address6 = vars->Get("address6"); if (address6.IsEmpty()) address6 = host->GetName(); @@ -107,11 +107,11 @@ Host2dCoords CompatUtility::GetHost2dCoords(const Host::Ptr& host) { ASSERT(host->OwnsLock()); - Dictionary::Ptr custom = host->GetCustom(); + Dictionary::Ptr vars = host->GetVars(); Host2dCoords bag; - if (custom) { - String coords = custom->Get("2d_coords"); + if (vars) { + String coords = vars->Get("2d_coords"); bag.have_2d_coords = (!coords.IsEmpty() ? 1 : 0); std::vector tokens; @@ -428,67 +428,71 @@ int CompatUtility::GetServiceInNotificationPeriod(const Service::Ptr& service) return 1; } -/* custom attr */ -Dictionary::Ptr CompatUtility::GetCustomVariableConfig(const DynamicObject::Ptr& object) +/* vars attr */ +Dictionary::Ptr CompatUtility::GetCustomAttributeConfig(const DynamicObject::Ptr& object) { ASSERT(object->OwnsLock()); - Dictionary::Ptr custom; + Dictionary::Ptr vars; if (object->GetType() == DynamicType::GetByName("Host")) { - custom = static_pointer_cast(object)->GetCustom(); + vars = static_pointer_cast(object)->GetVars(); } else if (object->GetType() == DynamicType::GetByName("Service")) { - custom = static_pointer_cast(object)->GetCustom(); + vars = static_pointer_cast(object)->GetVars(); } else if (object->GetType() == DynamicType::GetByName("User")) { - custom = static_pointer_cast(object)->GetCustom(); + vars = static_pointer_cast(object)->GetVars(); } else { - Log(LogDebug, "icinga", "unknown object type for custom vars"); + Log(LogDebug, "icinga", "unknown object type for vars vars"); return Dictionary::Ptr(); } - Dictionary::Ptr customvars = make_shared(); + Dictionary::Ptr varsvars = make_shared(); - if (!custom) + if (!vars) return Dictionary::Ptr(); - ObjectLock olock(custom); - BOOST_FOREACH(const Dictionary::Pair& kv, custom) { + ObjectLock olock(vars); + BOOST_FOREACH(const Dictionary::Pair& kv, vars) { if (!kv.first.IsEmpty()) { - if (kv.first != "notes" && + if (kv.first != "address" && + kv.first != "address6" && + kv.first != "email" && + kv.first != "pager" && + kv.first != "notes" && kv.first != "action_url" && kv.first != "notes_url" && kv.first != "icon_image" && kv.first != "icon_image_alt" && kv.first != "statusmap_image" && kv.first != "2d_coords") - customvars->Set(kv.first, kv.second); + varsvars->Set(kv.first, kv.second); } } - return customvars; + return varsvars; } String CompatUtility::GetCustomAttributeConfig(const DynamicObject::Ptr& object, const String& name) { ASSERT(object->OwnsLock()); - Dictionary::Ptr custom; + Dictionary::Ptr vars; if (object->GetType() == DynamicType::GetByName("Host")) { - custom = static_pointer_cast(object)->GetCustom(); + vars = static_pointer_cast(object)->GetVars(); } else if (object->GetType() == DynamicType::GetByName("Service")) { - custom = static_pointer_cast(object)->GetCustom(); + vars = static_pointer_cast(object)->GetVars(); } else if (object->GetType() == DynamicType::GetByName("User")) { - custom = static_pointer_cast(object)->GetCustom(); + vars = static_pointer_cast(object)->GetVars(); } else { - Log(LogDebug, "icinga", "unknown object type for custom attributes"); + Log(LogDebug, "icinga", "unknown object type for vars attributes"); return Empty; } - if (!custom) + if (!vars) return Empty; - return custom->Get(name); + return vars->Get(name); } /* notifications */ diff --git a/lib/icinga/compatutility.h b/lib/icinga/compatutility.h index 8c64eee55..836eedef3 100644 --- a/lib/icinga/compatutility.h +++ b/lib/icinga/compatutility.h @@ -121,7 +121,7 @@ public: /* custom attribute */ static String GetCustomAttributeConfig(const DynamicObject::Ptr& object, const String& name); - static Dictionary::Ptr GetCustomVariableConfig(const DynamicObject::Ptr& object); + static Dictionary::Ptr GetCustomAttributeConfig(const DynamicObject::Ptr& object); /* check result */ static String GetCheckResultOutput(const CheckResult::Ptr& cr); diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 486cf4229..baeba55c0 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -502,13 +502,13 @@ bool Host::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *re } } + Dictionary::Ptr vars = GetVars(); + if (macro.SubStr(0, 5) == "_HOST") { - Dictionary::Ptr custom = GetCustom(); - *result = custom ? custom->Get(macro.SubStr(5)) : ""; + *result = vars ? vars->Get(macro.SubStr(5)) : ""; return true; } - Dictionary::Ptr macros = GetMacros(); String name = macro; @@ -517,8 +517,8 @@ bool Host::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *re else if (macro == "HOSTADDRESS6") name = "address6"; - if (macros && macros->Contains(name)) { - *result = macros->Get(name); + if (vars && vars->Contains(name)) { + *result = vars->Get(name); return true; } diff --git a/lib/icinga/host.ti b/lib/icinga/host.ti index a82b3a877..921a0a1c6 100644 --- a/lib/icinga/host.ti +++ b/lib/icinga/host.ti @@ -14,7 +14,6 @@ class Host : DynamicObject }}} }; [config] Array::Ptr groups; - [config] Dictionary::Ptr macros; [config] String check; [config, protected] Dictionary::Ptr services (ServiceDescriptions); [config] Dictionary::Ptr dependencies (DependencyDescriptions); diff --git a/lib/icinga/icinga-type.conf b/lib/icinga/icinga-type.conf index 5853519c9..c5bd6ef0d 100644 --- a/lib/icinga/icinga-type.conf +++ b/lib/icinga/icinga-type.conf @@ -23,10 +23,6 @@ %attribute %array "groups" { %attribute %name(HostGroup) "*" }, - - %attribute %dictionary "macros" { - %attribute %string "*" - } } %type HostGroup { @@ -49,10 +45,6 @@ %attribute %string "display_name", - %attribute %dictionary "macros" { - %attribute %string "*" - }, - %require "check_command", %attribute %name(CheckCommand) "check_command", %attribute %number "max_check_attempts", @@ -94,10 +86,6 @@ %require "service", %attribute %string "service", - %attribute %dictionary "macros" { - %attribute %string "*" - }, - %attribute %array "users" { %attribute %name(User) "*" }, @@ -127,10 +115,6 @@ %type User { %attribute %string "display_name", - %attribute %dictionary "macros" { - %attribute %string "*" - }, - %attribute %array "groups" { %attribute %name(UserGroup) "*" }, @@ -181,9 +165,6 @@ %attribute %array "escape_macros" { %attribute %string "*" }, - %attribute %dictionary "macros" { - %attribute %string "*" - }, %attribute %number "timeout" /* } */ } diff --git a/lib/icinga/icingaapplication.cpp b/lib/icinga/icingaapplication.cpp index c9ed80f8a..82148c6f7 100644 --- a/lib/icinga/icingaapplication.cpp +++ b/lib/icinga/icingaapplication.cpp @@ -116,9 +116,9 @@ IcingaApplication::Ptr IcingaApplication::GetInstance(void) return static_pointer_cast(Application::GetInstance()); } -Dictionary::Ptr IcingaApplication::GetMacros(void) const +Dictionary::Ptr IcingaApplication::GetVars(void) const { - ScriptVariable::Ptr sv = ScriptVariable::GetByName("IcingaMacros"); + ScriptVariable::Ptr sv = ScriptVariable::GetByName("IcingaVars"); if (!sv) return Dictionary::Ptr(); @@ -152,10 +152,10 @@ bool IcingaApplication::ResolveMacro(const String& macro, const CheckResult::Ptr return true; } - Dictionary::Ptr macros = GetMacros(); + Dictionary::Ptr vars = GetVars(); - if (macros && macros->Contains(macro)) { - *result = macros->Get(macro); + if (vars && vars->Contains(macro)) { + *result = vars->Get(macro); return true; } diff --git a/lib/icinga/icingaapplication.h b/lib/icinga/icingaapplication.h index b9f9e80e1..e77d5c25f 100644 --- a/lib/icinga/icingaapplication.h +++ b/lib/icinga/icingaapplication.h @@ -47,7 +47,7 @@ public: static IcingaApplication::Ptr GetInstance(void); String GetPidPath(void) const; - Dictionary::Ptr GetMacros(void) const; + Dictionary::Ptr GetVars(void) const; String GetNodeName(void) const; virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const; diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index 922e765cd..ee7b830bc 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -341,16 +341,16 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User:: bool Notification::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const { + Dictionary::Ptr vars = GetVars(); + if (macro.SubStr(0, 13) == "_NOTIFICATION") { - Dictionary::Ptr custom = GetCustom(); - *result = custom ? custom->Get(macro.SubStr(13)) : ""; + *result = vars ? vars->Get(macro.SubStr(13)) : ""; return true; } - Dictionary::Ptr macros = GetMacros(); - if (macros && macros->Contains(macro)) { - *result = macros->Get(macro); + if (vars && vars->Contains(macro)) { + *result = vars->Get(macro); return true; } diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index c2b0de52c..45431afac 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -373,16 +373,16 @@ bool Service::ResolveMacro(const String& macro, const CheckResult::Ptr& cr, Stri } } + Dictionary::Ptr vars = GetVars(); + if (macro.SubStr(0, 8) == "_SERVICE") { - Dictionary::Ptr custom = GetCustom(); - *result = custom ? custom->Get(macro.SubStr(8)) : ""; + *result = vars ? vars->Get(macro.SubStr(8)) : ""; return true; } - Dictionary::Ptr macros = GetMacros(); - if (macros && macros->Contains(macro)) { - *result = macros->Get(macro); + if (vars && vars->Contains(macro)) { + *result = vars->Get(macro); return true; } diff --git a/lib/icinga/service.ti b/lib/icinga/service.ti index c47a64163..954371651 100644 --- a/lib/icinga/service.ti +++ b/lib/icinga/service.ti @@ -29,7 +29,6 @@ class Service : DynamicObject return m_DisplayName; }}} }; - [config] Dictionary::Ptr macros; [config] Array::Ptr groups; [config, protected] String check_command (CheckCommandRaw); [config] int max_check_attempts (MaxCheckAttemptsRaw) { diff --git a/lib/icinga/user.cpp b/lib/icinga/user.cpp index 5bfcd0e8a..966c08f90 100644 --- a/lib/icinga/user.cpp +++ b/lib/icinga/user.cpp @@ -75,12 +75,12 @@ bool User::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *re *result = GetDisplayName(); return true; } else if (macro.SubStr(0, 5) == "_USER") { - Dictionary::Ptr custom = GetCustom(); - *result = custom ? custom->Get(macro.SubStr(5)) : ""; + Dictionary::Ptr vars = GetVars(); + *result = vars ? vars->Get(macro.SubStr(5)) : ""; return true; } else if (macro.SubStr(0, 8) == "_CONTACT") { - Dictionary::Ptr custom = GetCustom(); - *result = custom ? custom->Get(macro.SubStr(8)) : ""; + Dictionary::Ptr vars = GetVars(); + *result = vars ? vars->Get(macro.SubStr(8)) : ""; return true; } else { String tmacro; @@ -92,10 +92,10 @@ bool User::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *re else tmacro = macro; - Dictionary::Ptr macros = GetMacros(); + Dictionary::Ptr vars = GetVars(); - if (macros && macros->Contains(tmacro)) { - *result = macros->Get(tmacro); + if (vars && vars->Contains(tmacro)) { + *result = vars->Get(tmacro); return true; }