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

Refs #5855
This commit is contained in:
Michael Friedrich 2014-04-03 10:30:11 +02:00
parent c58e226f84
commit 5c58eb368c
29 changed files with 196 additions and 231 deletions

View File

@ -516,13 +516,13 @@ void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& s
void StatusDataWriter::DumpCustomAttributes(std::ostream& fp, const DynamicObject::Ptr& object) 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; return;
ObjectLock olock(custom); ObjectLock olock(vars);
BOOST_FOREACH(const Dictionary::Pair& kv, custom) { BOOST_FOREACH(const Dictionary::Pair& kv, vars) {
if (!kv.first.IsEmpty()) { if (!kv.first.IsEmpty()) {
fp << "\t"; fp << "\t";

View File

@ -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 + "service_notifications_enabled", Column(&ContactsTable::ServiceNotificationsEnabledAccessor, objectAccessor));
table->AddColumn(prefix + "in_host_notification_period", Column(&ContactsTable::InHostNotificationPeriodAccessor, 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 + "in_service_notification_period", Column(&ContactsTable::InServiceNotificationPeriodAccessor, objectAccessor));
table->AddColumn(prefix + "custom_variable_names", Column(&ContactsTable::CustomVariableNamesAccessor, objectAccessor)); table->AddColumn(prefix + "vars_variable_names", Column(&ContactsTable::CustomVariableNamesAccessor, objectAccessor));
table->AddColumn(prefix + "custom_variable_values", Column(&ContactsTable::CustomVariableValuesAccessor, objectAccessor)); table->AddColumn(prefix + "vars_variable_values", Column(&ContactsTable::CustomVariableValuesAccessor, objectAccessor));
table->AddColumn(prefix + "custom_variables", Column(&ContactsTable::CustomVariablesAccessor, objectAccessor)); table->AddColumn(prefix + "vars_variables", Column(&ContactsTable::CustomVariablesAccessor, objectAccessor));
table->AddColumn(prefix + "modified_attributes", Column(&ContactsTable::ModifiedAttributesAccessor, objectAccessor)); table->AddColumn(prefix + "modified_attributes", Column(&ContactsTable::ModifiedAttributesAccessor, objectAccessor));
table->AddColumn(prefix + "modified_attributes_list", Column(&ContactsTable::ModifiedAttributesListAccessor, objectAccessor)); table->AddColumn(prefix + "modified_attributes_list", Column(&ContactsTable::ModifiedAttributesListAccessor, objectAccessor));
} }
@ -93,12 +93,12 @@ Value ContactsTable::EmailAccessor(const Value& row)
if (!user) if (!user)
return Empty; return Empty;
Dictionary::Ptr macros = user->GetMacros(); Dictionary::Ptr vars = user->GetVars();
if (!macros) if (!vars)
return Empty; return Empty;
return macros->Get("email"); return vars->Get("email");
} }
Value ContactsTable::PagerAccessor(const Value& row) Value ContactsTable::PagerAccessor(const Value& row)
@ -108,12 +108,12 @@ Value ContactsTable::PagerAccessor(const Value& row)
if (!user) if (!user)
return Empty; return Empty;
Dictionary::Ptr macros = user->GetMacros(); Dictionary::Ptr vars = user->GetVars();
if (!macros) if (!vars)
return Empty; return Empty;
return macros->Get("pager"); return vars->Get("pager");
} }
Value ContactsTable::HostNotificationPeriodAccessor(const Value& row) Value ContactsTable::HostNotificationPeriodAccessor(const Value& row)
@ -204,17 +204,17 @@ Value ContactsTable::CustomVariableNamesAccessor(const Value& row)
if (!user) if (!user)
return Empty; return Empty;
Dictionary::Ptr custom = user->GetCustom(); Dictionary::Ptr vars = user->GetVars();
if (!custom) if (!vars)
return Empty; return Empty;
Array::Ptr cv = make_shared<Array>(); Array::Ptr cv = make_shared<Array>();
ObjectLock olock(custom); ObjectLock olock(vars);
String key; String key;
Value value; Value value;
BOOST_FOREACH(boost::tie(key, value), custom) { BOOST_FOREACH(boost::tie(key, value), vars) {
if (key == "notes" || if (key == "notes" ||
key == "action_url" || key == "action_url" ||
key == "notes_url" || key == "notes_url" ||
@ -237,17 +237,17 @@ Value ContactsTable::CustomVariableValuesAccessor(const Value& row)
if (!user) if (!user)
return Empty; return Empty;
Dictionary::Ptr custom = user->GetCustom(); Dictionary::Ptr vars = user->GetVars();
if (!custom) if (!vars)
return Empty; return Empty;
Array::Ptr cv = make_shared<Array>(); Array::Ptr cv = make_shared<Array>();
ObjectLock olock(custom); ObjectLock olock(vars);
String key; String key;
Value value; Value value;
BOOST_FOREACH(boost::tie(key, value), custom) { BOOST_FOREACH(boost::tie(key, value), vars) {
if (key == "notes" || if (key == "notes" ||
key == "action_url" || key == "action_url" ||
key == "notes_url" || key == "notes_url" ||
@ -270,17 +270,17 @@ Value ContactsTable::CustomVariablesAccessor(const Value& row)
if (!user) if (!user)
return Empty; return Empty;
Dictionary::Ptr custom = user->GetCustom(); Dictionary::Ptr vars = user->GetVars();
if (!custom) if (!vars)
return Empty; return Empty;
Array::Ptr cv = make_shared<Array>(); Array::Ptr cv = make_shared<Array>();
ObjectLock olock(custom); ObjectLock olock(vars);
String key; String key;
Value value; Value value;
BOOST_FOREACH(boost::tie(key, value), custom) { BOOST_FOREACH(boost::tie(key, value), vars) {
if (key == "notes" || if (key == "notes" ||
key == "action_url" || key == "action_url" ||
key == "notes_url" || key == "notes_url" ||

View File

@ -85,32 +85,32 @@ Value HostGroupsTable::AliasAccessor(const Value& row)
Value HostGroupsTable::NotesAccessor(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 Empty;
return custom->Get("notes"); return vars->Get("notes");
} }
Value HostGroupsTable::NotesUrlAccessor(const Value& row) 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 Empty;
return custom->Get("notes_url"); return vars->Get("notes_url");
} }
Value HostGroupsTable::ActionUrlAccessor(const Value& row) 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 Empty;
return custom->Get("action_url"); return vars->Get("action_url");
} }
Value HostGroupsTable::MembersAccessor(const Value& row) Value HostGroupsTable::MembersAccessor(const Value& row)

View File

@ -1372,21 +1372,21 @@ Value HostsTable::CustomVariableNamesAccessor(const Value& row)
if (!host) if (!host)
return Empty; return Empty;
Dictionary::Ptr customvars; Dictionary::Ptr vars;
{ {
ObjectLock olock(host); ObjectLock olock(host);
customvars = CompatUtility::GetCustomVariableConfig(host); vars = CompatUtility::GetCustomAttributeConfig(host);
} }
if (!customvars) if (!vars)
return Empty; return Empty;
Array::Ptr cv = make_shared<Array>(); Array::Ptr cv = make_shared<Array>();
String key; String key;
Value value; Value value;
BOOST_FOREACH(boost::tie(key, value), customvars) { BOOST_FOREACH(boost::tie(key, value), vars) {
cv->Add(key); cv->Add(key);
} }
@ -1400,21 +1400,21 @@ Value HostsTable::CustomVariableValuesAccessor(const Value& row)
if (!host) if (!host)
return Empty; return Empty;
Dictionary::Ptr customvars; Dictionary::Ptr vars;
{ {
ObjectLock olock(host); ObjectLock olock(host);
customvars = CompatUtility::GetCustomVariableConfig(host); vars = CompatUtility::GetCustomAttributeConfig(host);
} }
if (!customvars) if (!vars)
return Empty; return Empty;
Array::Ptr cv = make_shared<Array>(); Array::Ptr cv = make_shared<Array>();
String key; String key;
Value value; Value value;
BOOST_FOREACH(boost::tie(key, value), customvars) { BOOST_FOREACH(boost::tie(key, value), vars) {
cv->Add(value); cv->Add(value);
} }
@ -1428,21 +1428,21 @@ Value HostsTable::CustomVariablesAccessor(const Value& row)
if (!host) if (!host)
return Empty; return Empty;
Dictionary::Ptr customvars; Dictionary::Ptr vars;
{ {
ObjectLock olock(host); ObjectLock olock(host);
customvars = CompatUtility::GetCustomVariableConfig(host); vars = CompatUtility::GetCustomAttributeConfig(host);
} }
if (!customvars) if (!vars)
return Empty; return Empty;
Array::Ptr cv = make_shared<Array>(); Array::Ptr cv = make_shared<Array>();
String key; String key;
Value value; Value value;
BOOST_FOREACH(boost::tie(key, value), customvars) { BOOST_FOREACH(boost::tie(key, value), vars) {
Array::Ptr key_val = make_shared<Array>(); Array::Ptr key_val = make_shared<Array>();
key_val->Add(key); key_val->Add(key);
key_val->Add(value); key_val->Add(value);

View File

@ -76,32 +76,32 @@ Value ServiceGroupsTable::AliasAccessor(const Value& row)
Value ServiceGroupsTable::NotesAccessor(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 Empty;
return custom->Get("notes"); return vars->Get("notes");
} }
Value ServiceGroupsTable::NotesUrlAccessor(const Value& row) 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 Empty;
return custom->Get("notes_url"); return vars->Get("notes_url");
} }
Value ServiceGroupsTable::ActionUrlAccessor(const Value& row) 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 Empty;
return custom->Get("action_url"); return vars->Get("action_url");
} }
Value ServiceGroupsTable::MembersAccessor(const Value& row) Value ServiceGroupsTable::MembersAccessor(const Value& row)

View File

@ -1049,21 +1049,21 @@ Value ServicesTable::CustomVariableNamesAccessor(const Value& row)
if (!service) if (!service)
return Empty; return Empty;
Dictionary::Ptr customvars; Dictionary::Ptr vars;
{ {
ObjectLock olock(service); ObjectLock olock(service);
customvars = CompatUtility::GetCustomVariableConfig(service); vars = CompatUtility::GetCustomAttributeConfig(service);
} }
if (!customvars) if (!vars)
return Empty; return Empty;
Array::Ptr cv = make_shared<Array>(); Array::Ptr cv = make_shared<Array>();
String key; String key;
Value value; Value value;
BOOST_FOREACH(boost::tie(key, value), customvars) { BOOST_FOREACH(boost::tie(key, value), vars) {
cv->Add(key); cv->Add(key);
} }
@ -1077,21 +1077,21 @@ Value ServicesTable::CustomVariableValuesAccessor(const Value& row)
if (!service) if (!service)
return Empty; return Empty;
Dictionary::Ptr customvars; Dictionary::Ptr vars;
{ {
ObjectLock olock(service); ObjectLock olock(service);
customvars = CompatUtility::GetCustomVariableConfig(service); vars = CompatUtility::GetCustomAttributeConfig(service);
} }
if (!customvars) if (!vars)
return Empty; return Empty;
Array::Ptr cv = make_shared<Array>(); Array::Ptr cv = make_shared<Array>();
String key; String key;
Value value; Value value;
BOOST_FOREACH(boost::tie(key, value), customvars) { BOOST_FOREACH(boost::tie(key, value), vars) {
cv->Add(value); cv->Add(value);
} }
@ -1105,21 +1105,21 @@ Value ServicesTable::CustomVariablesAccessor(const Value& row)
if (!service) if (!service)
return Empty; return Empty;
Dictionary::Ptr customvars; Dictionary::Ptr vars;
{ {
ObjectLock olock(service); ObjectLock olock(service);
customvars = CompatUtility::GetCustomVariableConfig(service); vars = CompatUtility::GetCustomAttributeConfig(service);
} }
if (!customvars) if (!vars)
return Empty; return Empty;
Array::Ptr cv = make_shared<Array>(); Array::Ptr cv = make_shared<Array>();
String key; String key;
Value value; Value value;
BOOST_FOREACH(boost::tie(key, value), customvars) { BOOST_FOREACH(boost::tie(key, value), vars) {
Array::Ptr key_val = make_shared<Array>(); Array::Ptr key_val = make_shared<Array>();
key_val->Add(key); key_val->Add(key);
key_val->Add(value); key_val->Add(value);

View File

@ -66,7 +66,7 @@ up macros:
2. Service object 2. Service object
3. Host object 3. Host object
4. Command 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 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 command objects. The `my-ping` command shown above uses this to set default

View File

@ -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". 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". 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". 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. 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". 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. IcingaEnableNotifications |**Read-write.** Whether notifications are globally enabled. Defaults to true.

View File

@ -12,7 +12,7 @@ apply Service "ping4" {
check_command = "ping4" check_command = "ping4"
assign where "generic-host" in host.templates assign where "generic-host" in host.templates
ignore where !host.macros.address ignore where !host.vars.address
} }
apply Service "ping6" { apply Service "ping6" {
@ -21,7 +21,7 @@ apply Service "ping6" {
check_command = "ping6" check_command = "ping6"
assign where "generic-host" in host.templates assign where "generic-host" in host.templates
ignore where !host.macros.address6 ignore where !host.vars.address6
} }
template Host "linux-server" { template Host "linux-server" {

View File

@ -6,8 +6,8 @@
object Host "localhost" { object Host "localhost" {
import "linux-server" import "linux-server"
macros.address = "127.0.0.1" vars.address = "127.0.0.1"
macros.address6 = "::1" vars.address6 = "::1"
} }
apply Service "icinga" { apply Service "icinga" {

View File

@ -9,13 +9,11 @@ object User "icingaadmin" {
display_name = "Icinga 2 Admin" display_name = "Icinga 2 Admin"
groups = [ "icingaadmins" ] groups = [ "icingaadmins" ]
macros = { vars.name = "Icinga 2 Admin"
name = "Icinga 2 Admin" vars.email = "icinga@localhost"
email = "icinga@localhost" vars.pager = "icingaadmin@localhost.localdomain"
pager = "icingaadmin@localhost.localdomain"
}
custom.notes = "This is the Icinga 2 Admin account." vars.notes = "This is the Icinga 2 Admin account."
} }

View File

@ -30,16 +30,14 @@ object CheckCommand "ping4" {
"-t", "$timeout$" "-t", "$timeout$"
], ],
macros = { vars.wrta = 100,
wrta = 100, vars.wpl = 5,
wpl = 5,
crta = 200, vars.crta = 200,
cpl = 15, vars.cpl = 15,
packets = 5, vars.packets = 5,
timeout = 0 vars.timeout = 0
}
} }
object CheckCommand "ping6" { object CheckCommand "ping6" {
@ -55,16 +53,14 @@ object CheckCommand "ping6" {
"-t", "$timeout$" "-t", "$timeout$"
], ],
macros = { vars.wrta = 100,
wrta = 100, vars.wpl = 5,
wpl = 5,
crta = 200, vars.crta = 200,
cpl = 15, vars.cpl = 15,
packets = 5, vars.packets = 5,
timeout = 0 vars.timeout = 0
}
} }
object CheckCommand "dummy" { object CheckCommand "dummy" {
@ -76,19 +72,15 @@ object CheckCommand "dummy" {
"$text$" "$text$"
], ],
macros = { vars.state = 0,
state = 0, vars.text = "Check was successful."
text = "Check was successful."
}
} }
object CheckCommand "passive" { object CheckCommand "passive" {
import "dummy", import "dummy",
macros = { vars.state = 3,
state = 3, vars.text = "No Passive Check Result Received."
text = "No Passive Check Result Received."
}
} }
object CheckCommand "tcp" { object CheckCommand "tcp" {
@ -165,7 +157,7 @@ object CheckCommand "ssmtp" {
"-p", "$port$" "-p", "$port$"
], ],
macros.port = 465 vars.port = 465
} }
object CheckCommand "ntp_time" { object CheckCommand "ntp_time" {
@ -195,10 +187,8 @@ object CheckCommand "disk" {
"-c", "$cfree$%" "-c", "$cfree$%"
], ],
macros = { vars.wfree = 20,
wfree = 20, vars.cfree = 10,
cfree = 10,
}
} }
object CheckCommand "users"{ object CheckCommand "users"{
@ -210,10 +200,8 @@ object CheckCommand "users"{
"-c", "$cgreater$" "-c", "$cgreater$"
], ],
macros = { vars.wgreater = 20,
wgreater = 20, vars.cgreater = 50,
cgreater = 50,
}
} }
object CheckCommand "processes"{ object CheckCommand "processes"{
@ -225,10 +213,8 @@ object CheckCommand "processes"{
"-c", "$cgreater$" "-c", "$cgreater$"
], ],
macros = { vars.wgreater = 250,
wgreater = 250, vars.cgreater = 400,
cgreater = 400,
}
} }
object CheckCommand "load"{ object CheckCommand "load"{
@ -240,15 +226,13 @@ object CheckCommand "load"{
"-c", "$cload1$,$cload5$,$cload15$" "-c", "$cload1$,$cload5$,$cload15$"
], ],
macros = { vars.wload1 = 5.0,
wload1 = 5.0, vars.wload5 = 4.0,
wload5 = 4.0, vars.wload15 = 3.0,
wload15 = 3.0,
cload1 = 10.0, vars.cload1 = 10.0,
cload5 = 6.0, vars.cload5 = 6.0,
cload15 = 4.0 vars.cload15 = 4.0
}
} }
object CheckCommand "snmp"{ object CheckCommand "snmp"{
@ -261,13 +245,13 @@ object CheckCommand "snmp"{
"-C", "$community$" "-C", "$community$"
], ],
macros.community = "public" vars.community = "public"
} }
object CheckCommand "snmp-uptime"{ object CheckCommand "snmp-uptime"{
import "snmp", 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"{ object CheckCommand "icinga"{
@ -290,5 +274,5 @@ object CheckCommand "snmp-extend"{
"$plugin$" "$plugin$"
], ],
macros.community = "public" vars.community = "public"
} }

View File

@ -7,7 +7,7 @@ abstract class DynamicObject
[config, get_protected] String type (TypeName); [config, get_protected] String type (TypeName);
[config, get_protected] Array::Ptr templates; [config, get_protected] Array::Ptr templates;
[config] Dictionary::Ptr methods; [config] Dictionary::Ptr methods;
[config] Dictionary::Ptr custom; [config] Dictionary::Ptr vars;
[config] Array::Ptr domains; [config] Array::Ptr domains;
[config] Array::Ptr authorities; [config] Array::Ptr authorities;
[get_protected] bool active; [get_protected] bool active;

View File

@ -30,7 +30,7 @@
%attribute %dictionary "methods", %attribute %dictionary "methods",
%attribute %dictionary "custom" { %attribute %dictionary "vars" {
%attribute %string "*" %attribute %string "*"
}, },

View File

@ -277,18 +277,18 @@ void HostDbObject::OnConfigUpdate(void)
} }
/* custom variables */ /* custom variables */
Dictionary::Ptr customvars; Dictionary::Ptr vars;
{ {
ObjectLock olock(host); ObjectLock olock(host);
customvars = CompatUtility::GetCustomVariableConfig(host); vars = CompatUtility::GetCustomAttributeConfig(host);
} }
if (customvars) { if (vars) {
Log(LogDebug, "ido", "Dumping host customvars for '" + host->GetName() + "'"); 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()) { if (!kv.first.IsEmpty()) {
Log(LogDebug, "db_ido", "host customvar key: '" + kv.first + "' value: '" + Convert::ToString(kv.second) + "'"); Log(LogDebug, "db_ido", "host customvar key: '" + kv.first + "' value: '" + Convert::ToString(kv.second) + "'");

View File

@ -264,19 +264,19 @@ void ServiceDbObject::OnConfigUpdate(void)
} }
/* custom variables */ /* custom variables */
Dictionary::Ptr customvars; Dictionary::Ptr vars;
{ {
ObjectLock olock(service); ObjectLock olock(service);
customvars = CompatUtility::GetCustomVariableConfig(service); vars = CompatUtility::GetCustomAttributeConfig(service);
} }
if (customvars) { if (vars) {
Log(LogDebug, "db_ido", "Dumping service customvars for '" + service->GetName() + "'"); 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()) { if (!kv.first.IsEmpty()) {
Log(LogDebug, "db_ido", "service customvar key: '" + kv.first + "' value: '" + Convert::ToString(kv.second) + "'"); Log(LogDebug, "db_ido", "service customvar key: '" + kv.first + "' value: '" + Convert::ToString(kv.second) + "'");

View File

@ -42,11 +42,11 @@ Dictionary::Ptr UserDbObject::GetConfigFields(void) const
fields->Set("alias", user->GetDisplayName()); fields->Set("alias", user->GetDisplayName());
Dictionary::Ptr macros = user->GetMacros(); Dictionary::Ptr vars = user->GetVars();
if (macros) { /* Yuck. */ if (vars) { /* Yuck. */
fields->Set("email_address", macros->Get("email")); fields->Set("email_address", vars->Get("email"));
fields->Set("pager_address", macros->Get("pager")); fields->Set("pager_address", vars->Get("pager"));
} }
fields->Set("host_timeperiod_object_id", user->GetNotificationPeriod()); fields->Set("host_timeperiod_object_id", user->GetNotificationPeriod());
@ -93,12 +93,12 @@ void UserDbObject::OnConfigUpdate(void)
/* contact addresses */ /* contact addresses */
Log(LogDebug, "db_ido", "contact addresses for '" + user->GetName() + "'"); 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++) { for (int i = 1; i <= 6; i++) {
String key = "address" + Convert::ToString(i); String key = "address" + Convert::ToString(i);
String val = macros->Get(key); String val = vars->Get(key);
if (val.IsEmpty()) if (val.IsEmpty())
continue; continue;

View File

@ -25,10 +25,10 @@ REGISTER_TYPE(Command);
bool Command::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const 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)) { if (vars && vars->Contains(macro)) {
*result = macros->Get(macro); *result = vars->Get(macro);
return true; return true;
} }

View File

@ -73,12 +73,12 @@ String CompatUtility::GetHostAddress(const Host::Ptr& host)
{ {
ASSERT(host->OwnsLock()); ASSERT(host->OwnsLock());
Dictionary::Ptr macros = host->GetMacros(); Dictionary::Ptr vars = host->GetVars();
String address; String address;
if (macros) if (vars)
address = macros->Get("address"); address = vars->Get("address");
if (address.IsEmpty()) if (address.IsEmpty())
address = host->GetName(); address = host->GetName();
@ -90,12 +90,12 @@ String CompatUtility::GetHostAddress6(const Host::Ptr& host)
{ {
ASSERT(host->OwnsLock()); ASSERT(host->OwnsLock());
Dictionary::Ptr macros = host->GetMacros(); Dictionary::Ptr vars = host->GetVars();
String address6; String address6;
if (macros) if (vars)
address6 = macros->Get("address6"); address6 = vars->Get("address6");
if (address6.IsEmpty()) if (address6.IsEmpty())
address6 = host->GetName(); address6 = host->GetName();
@ -107,11 +107,11 @@ Host2dCoords CompatUtility::GetHost2dCoords(const Host::Ptr& host)
{ {
ASSERT(host->OwnsLock()); ASSERT(host->OwnsLock());
Dictionary::Ptr custom = host->GetCustom(); Dictionary::Ptr vars = host->GetVars();
Host2dCoords bag; Host2dCoords bag;
if (custom) { if (vars) {
String coords = custom->Get("2d_coords"); String coords = vars->Get("2d_coords");
bag.have_2d_coords = (!coords.IsEmpty() ? 1 : 0); bag.have_2d_coords = (!coords.IsEmpty() ? 1 : 0);
std::vector<String> tokens; std::vector<String> tokens;
@ -428,67 +428,71 @@ int CompatUtility::GetServiceInNotificationPeriod(const Service::Ptr& service)
return 1; return 1;
} }
/* custom attr */ /* vars attr */
Dictionary::Ptr CompatUtility::GetCustomVariableConfig(const DynamicObject::Ptr& object) Dictionary::Ptr CompatUtility::GetCustomAttributeConfig(const DynamicObject::Ptr& object)
{ {
ASSERT(object->OwnsLock()); ASSERT(object->OwnsLock());
Dictionary::Ptr custom; Dictionary::Ptr vars;
if (object->GetType() == DynamicType::GetByName("Host")) { if (object->GetType() == DynamicType::GetByName("Host")) {
custom = static_pointer_cast<Host>(object)->GetCustom(); vars = static_pointer_cast<Host>(object)->GetVars();
} else if (object->GetType() == DynamicType::GetByName("Service")) { } else if (object->GetType() == DynamicType::GetByName("Service")) {
custom = static_pointer_cast<Service>(object)->GetCustom(); vars = static_pointer_cast<Service>(object)->GetVars();
} else if (object->GetType() == DynamicType::GetByName("User")) { } else if (object->GetType() == DynamicType::GetByName("User")) {
custom = static_pointer_cast<User>(object)->GetCustom(); vars = static_pointer_cast<User>(object)->GetVars();
} else { } else {
Log(LogDebug, "icinga", "unknown object type for custom vars"); Log(LogDebug, "icinga", "unknown object type for vars vars");
return Dictionary::Ptr(); return Dictionary::Ptr();
} }
Dictionary::Ptr customvars = make_shared<Dictionary>(); Dictionary::Ptr varsvars = make_shared<Dictionary>();
if (!custom) if (!vars)
return Dictionary::Ptr(); return Dictionary::Ptr();
ObjectLock olock(custom); ObjectLock olock(vars);
BOOST_FOREACH(const Dictionary::Pair& kv, custom) { BOOST_FOREACH(const Dictionary::Pair& kv, vars) {
if (!kv.first.IsEmpty()) { 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 != "action_url" &&
kv.first != "notes_url" && kv.first != "notes_url" &&
kv.first != "icon_image" && kv.first != "icon_image" &&
kv.first != "icon_image_alt" && kv.first != "icon_image_alt" &&
kv.first != "statusmap_image" && kv.first != "statusmap_image" &&
kv.first != "2d_coords") 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) String CompatUtility::GetCustomAttributeConfig(const DynamicObject::Ptr& object, const String& name)
{ {
ASSERT(object->OwnsLock()); ASSERT(object->OwnsLock());
Dictionary::Ptr custom; Dictionary::Ptr vars;
if (object->GetType() == DynamicType::GetByName("Host")) { if (object->GetType() == DynamicType::GetByName("Host")) {
custom = static_pointer_cast<Host>(object)->GetCustom(); vars = static_pointer_cast<Host>(object)->GetVars();
} else if (object->GetType() == DynamicType::GetByName("Service")) { } else if (object->GetType() == DynamicType::GetByName("Service")) {
custom = static_pointer_cast<Service>(object)->GetCustom(); vars = static_pointer_cast<Service>(object)->GetVars();
} else if (object->GetType() == DynamicType::GetByName("User")) { } else if (object->GetType() == DynamicType::GetByName("User")) {
custom = static_pointer_cast<User>(object)->GetCustom(); vars = static_pointer_cast<User>(object)->GetVars();
} else { } else {
Log(LogDebug, "icinga", "unknown object type for custom attributes"); Log(LogDebug, "icinga", "unknown object type for vars attributes");
return Empty; return Empty;
} }
if (!custom) if (!vars)
return Empty; return Empty;
return custom->Get(name); return vars->Get(name);
} }
/* notifications */ /* notifications */

View File

@ -121,7 +121,7 @@ public:
/* custom attribute */ /* custom attribute */
static String GetCustomAttributeConfig(const DynamicObject::Ptr& object, const String& name); 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 */ /* check result */
static String GetCheckResultOutput(const CheckResult::Ptr& cr); static String GetCheckResultOutput(const CheckResult::Ptr& cr);

View File

@ -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") { if (macro.SubStr(0, 5) == "_HOST") {
Dictionary::Ptr custom = GetCustom(); *result = vars ? vars->Get(macro.SubStr(5)) : "";
*result = custom ? custom->Get(macro.SubStr(5)) : "";
return true; return true;
} }
Dictionary::Ptr macros = GetMacros();
String name = macro; String name = macro;
@ -517,8 +517,8 @@ bool Host::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *re
else if (macro == "HOSTADDRESS6") else if (macro == "HOSTADDRESS6")
name = "address6"; name = "address6";
if (macros && macros->Contains(name)) { if (vars && vars->Contains(name)) {
*result = macros->Get(name); *result = vars->Get(name);
return true; return true;
} }

View File

@ -14,7 +14,6 @@ class Host : DynamicObject
}}} }}}
}; };
[config] Array::Ptr groups; [config] Array::Ptr groups;
[config] Dictionary::Ptr macros;
[config] String check; [config] String check;
[config, protected] Dictionary::Ptr services (ServiceDescriptions); [config, protected] Dictionary::Ptr services (ServiceDescriptions);
[config] Dictionary::Ptr dependencies (DependencyDescriptions); [config] Dictionary::Ptr dependencies (DependencyDescriptions);

View File

@ -23,10 +23,6 @@
%attribute %array "groups" { %attribute %array "groups" {
%attribute %name(HostGroup) "*" %attribute %name(HostGroup) "*"
}, },
%attribute %dictionary "macros" {
%attribute %string "*"
}
} }
%type HostGroup { %type HostGroup {
@ -49,10 +45,6 @@
%attribute %string "display_name", %attribute %string "display_name",
%attribute %dictionary "macros" {
%attribute %string "*"
},
%require "check_command", %require "check_command",
%attribute %name(CheckCommand) "check_command", %attribute %name(CheckCommand) "check_command",
%attribute %number "max_check_attempts", %attribute %number "max_check_attempts",
@ -94,10 +86,6 @@
%require "service", %require "service",
%attribute %string "service", %attribute %string "service",
%attribute %dictionary "macros" {
%attribute %string "*"
},
%attribute %array "users" { %attribute %array "users" {
%attribute %name(User) "*" %attribute %name(User) "*"
}, },
@ -127,10 +115,6 @@
%type User { %type User {
%attribute %string "display_name", %attribute %string "display_name",
%attribute %dictionary "macros" {
%attribute %string "*"
},
%attribute %array "groups" { %attribute %array "groups" {
%attribute %name(UserGroup) "*" %attribute %name(UserGroup) "*"
}, },
@ -181,9 +165,6 @@
%attribute %array "escape_macros" { %attribute %array "escape_macros" {
%attribute %string "*" %attribute %string "*"
}, },
%attribute %dictionary "macros" {
%attribute %string "*"
},
%attribute %number "timeout" %attribute %number "timeout"
/* } */ /* } */
} }

View File

@ -116,9 +116,9 @@ IcingaApplication::Ptr IcingaApplication::GetInstance(void)
return static_pointer_cast<IcingaApplication>(Application::GetInstance()); return static_pointer_cast<IcingaApplication>(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) if (!sv)
return Dictionary::Ptr(); return Dictionary::Ptr();
@ -152,10 +152,10 @@ bool IcingaApplication::ResolveMacro(const String& macro, const CheckResult::Ptr
return true; return true;
} }
Dictionary::Ptr macros = GetMacros(); Dictionary::Ptr vars = GetVars();
if (macros && macros->Contains(macro)) { if (vars && vars->Contains(macro)) {
*result = macros->Get(macro); *result = vars->Get(macro);
return true; return true;
} }

View File

@ -47,7 +47,7 @@ public:
static IcingaApplication::Ptr GetInstance(void); static IcingaApplication::Ptr GetInstance(void);
String GetPidPath(void) const; String GetPidPath(void) const;
Dictionary::Ptr GetMacros(void) const; Dictionary::Ptr GetVars(void) const;
String GetNodeName(void) const; String GetNodeName(void) const;
virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const; virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const;

View File

@ -341,16 +341,16 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User::
bool Notification::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const bool Notification::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const
{ {
Dictionary::Ptr vars = GetVars();
if (macro.SubStr(0, 13) == "_NOTIFICATION") { if (macro.SubStr(0, 13) == "_NOTIFICATION") {
Dictionary::Ptr custom = GetCustom(); *result = vars ? vars->Get(macro.SubStr(13)) : "";
*result = custom ? custom->Get(macro.SubStr(13)) : "";
return true; return true;
} }
Dictionary::Ptr macros = GetMacros();
if (macros && macros->Contains(macro)) { if (vars && vars->Contains(macro)) {
*result = macros->Get(macro); *result = vars->Get(macro);
return true; return true;
} }

View File

@ -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") { if (macro.SubStr(0, 8) == "_SERVICE") {
Dictionary::Ptr custom = GetCustom(); *result = vars ? vars->Get(macro.SubStr(8)) : "";
*result = custom ? custom->Get(macro.SubStr(8)) : "";
return true; return true;
} }
Dictionary::Ptr macros = GetMacros();
if (macros && macros->Contains(macro)) { if (vars && vars->Contains(macro)) {
*result = macros->Get(macro); *result = vars->Get(macro);
return true; return true;
} }

View File

@ -29,7 +29,6 @@ class Service : DynamicObject
return m_DisplayName; return m_DisplayName;
}}} }}}
}; };
[config] Dictionary::Ptr macros;
[config] Array::Ptr groups; [config] Array::Ptr groups;
[config, protected] String check_command (CheckCommandRaw); [config, protected] String check_command (CheckCommandRaw);
[config] int max_check_attempts (MaxCheckAttemptsRaw) { [config] int max_check_attempts (MaxCheckAttemptsRaw) {

View File

@ -75,12 +75,12 @@ bool User::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *re
*result = GetDisplayName(); *result = GetDisplayName();
return true; return true;
} else if (macro.SubStr(0, 5) == "_USER") { } else if (macro.SubStr(0, 5) == "_USER") {
Dictionary::Ptr custom = GetCustom(); Dictionary::Ptr vars = GetVars();
*result = custom ? custom->Get(macro.SubStr(5)) : ""; *result = vars ? vars->Get(macro.SubStr(5)) : "";
return true; return true;
} else if (macro.SubStr(0, 8) == "_CONTACT") { } else if (macro.SubStr(0, 8) == "_CONTACT") {
Dictionary::Ptr custom = GetCustom(); Dictionary::Ptr vars = GetVars();
*result = custom ? custom->Get(macro.SubStr(8)) : ""; *result = vars ? vars->Get(macro.SubStr(8)) : "";
return true; return true;
} else { } else {
String tmacro; String tmacro;
@ -92,10 +92,10 @@ bool User::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *re
else else
tmacro = macro; tmacro = macro;
Dictionary::Ptr macros = GetMacros(); Dictionary::Ptr vars = GetVars();
if (macros && macros->Contains(tmacro)) { if (vars && vars->Contains(tmacro)) {
*result = macros->Get(tmacro); *result = vars->Get(tmacro);
return true; return true;
} }