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)
{
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";

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 + "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" ||

View File

@ -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)

View File

@ -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);

View File

@ -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)

View File

@ -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);

View File

@ -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

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".
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.

View File

@ -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" {

View File

@ -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" {

View File

@ -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."
}

View File

@ -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"
}

View File

@ -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;

View File

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

View File

@ -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) + "'");

View File

@ -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) + "'");

View File

@ -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;

View File

@ -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;
}

View File

@ -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<String> 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<Host>(object)->GetCustom();
vars = static_pointer_cast<Host>(object)->GetVars();
} 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")) {
custom = static_pointer_cast<User>(object)->GetCustom();
vars = static_pointer_cast<User>(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>();
Dictionary::Ptr varsvars = make_shared<Dictionary>();
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<Host>(object)->GetCustom();
vars = static_pointer_cast<Host>(object)->GetVars();
} 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")) {
custom = static_pointer_cast<User>(object)->GetCustom();
vars = static_pointer_cast<User>(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 */

View File

@ -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);

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") {
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;
}

View File

@ -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);

View File

@ -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"
/* } */
}

View File

@ -116,9 +116,9 @@ IcingaApplication::Ptr IcingaApplication::GetInstance(void)
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)
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;
}

View File

@ -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;

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
{
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;
}

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") {
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;
}

View File

@ -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) {

View File

@ -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;
}