From c42a5823079347510fce82db4c59d9cdb30f6a2e Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sat, 5 Apr 2014 09:15:40 +0200 Subject: [PATCH] Rename "short_name", "host" and "sevice" attributes. Fixes #5857 --- doc/4.3-object-types.md | 32 +++++++++++------------ etc/icinga2/conf.d/localhost.conf | 2 +- lib/base/dynamicobject.ti | 10 +++++++- lib/config/base-type.conf | 4 +-- lib/config/configitem.cpp | 4 +-- lib/icinga/dependency-apply.cpp | 4 +-- lib/icinga/dependency.cpp | 12 ++++----- lib/icinga/dependency.ti | 8 +++--- lib/icinga/icinga-type.conf | 35 +++++++++++++------------- lib/icinga/notification-apply.cpp | 4 +-- lib/icinga/notification.cpp | 6 ++--- lib/icinga/notification.ti | 4 +-- lib/icinga/scheduleddowntime-apply.cpp | 4 +-- lib/icinga/scheduleddowntime.cpp | 6 ++--- lib/icinga/scheduleddowntime.ti | 4 +-- lib/icinga/service-apply.cpp | 4 +-- lib/icinga/service.cpp | 2 +- lib/icinga/service.ti | 10 +------- 18 files changed, 77 insertions(+), 78 deletions(-) diff --git a/doc/4.3-object-types.md b/doc/4.3-object-types.md index b34985020..808d5138a 100644 --- a/doc/4.3-object-types.md +++ b/doc/4.3-object-types.md @@ -53,8 +53,8 @@ by Icinga 2. Example: object Service "localhost-uptime" { - host = "localhost" - short_name = "uptime" + host_name = "localhost" + name = "uptime" display_name = "localhost Uptime" @@ -75,8 +75,8 @@ Attributes: Name |Description ----------------|---------------- - host |**Required.** The host this service belongs to. There must be a `Host` object with that name. - short_name |**Required.** The service name. Must be unique on a per-host basis (Similar to the service_description attribute in Icinga 1.x). + host_name |**Required.** The host this service belongs to. There must be a `Host` object with that name. + name |**Required.** The service name. Must be unique on a per-host basis (Similar to the service_description attribute in Icinga 1.x). display_name |**Optional.** A short description of the service. vars |**Optional.** A dictionary containing custom attributes that are specific to this host. check\_command |**Required.** The name of the check command. @@ -127,8 +127,8 @@ of service state changes and other events. Example: object Notification "localhost-ping-notification" { - host = "localhost" - service = "ping4" + host_name = "localhost" + service_name = "ping4" notification_command = "mail-notification" @@ -139,8 +139,8 @@ Attributes: Name |Description ----------------|---------------- - host |**Required.** The name of the host this notification belongs to. - service |**Required.** The short name of the service this notification belongs to. + host_name |**Required.** The name of the host this notification belongs to. + service_name |**Required.** The short name of the service this notification belongs to. vars |**Optional.** A dictionary containing custom attributes that are specific to this notification object. users |**Optional.** A list of user names who should be notified. user_groups |**Optional.** A list of user group names who should be notified. @@ -185,11 +185,11 @@ Dependency objects are used to specify dependencies between hosts and services. Example: object Dependency "webserver-internet" { - child_host = "webserver" - child_service = "ping4" + child_host_name = "webserver" + child_service_name = "ping4" - parent_host = "internet" - parent_service = "ping4" + parent_host_name = "internet" + parent_service_name = "ping4" state_filter = StateFilterOK @@ -344,8 +344,8 @@ ScheduledDowntime objects can be used to set up recurring downtimes for services Example: object ScheduledDowntime "some-downtime" { - host = "localhost" - service = "ping4" + host_name = "localhost" + service_name = "ping4" author = "icingaadmin" comment = "Some comment" @@ -362,8 +362,8 @@ Attributes: Name |Description ----------------|---------------- - host |**Required.** The name of the host this notification belongs to. - service |**Required.** The short name of the service this notification belongs to. + host_name |**Required.** The name of the host this notification belongs to. + service_name |**Required.** The short name of the service this notification belongs to. author |**Required.** The author of the downtime. comment |**Required.** A comment for the downtime. fixed |**Optional.** Whether this is a fixed downtime. Defaults to true. diff --git a/etc/icinga2/conf.d/localhost.conf b/etc/icinga2/conf.d/localhost.conf index c0212a0f1..b2b77f8cb 100644 --- a/etc/icinga2/conf.d/localhost.conf +++ b/etc/icinga2/conf.d/localhost.conf @@ -45,7 +45,7 @@ apply Service "load" { apply ScheduledDowntime "backup-downtime" { import "backup-downtime" - assign where service.host == "localhost" && service.short_name == "load" + assign where host.name == "localhost" && service.name == "load" } apply Service "processes" { diff --git a/lib/base/dynamicobject.ti b/lib/base/dynamicobject.ti index ca18ea159..49d2c642c 100644 --- a/lib/base/dynamicobject.ti +++ b/lib/base/dynamicobject.ti @@ -3,7 +3,15 @@ namespace icinga abstract class DynamicObject { - [config] String name (Name); + [config] String __name (Name); + [config] String name (ShortName) { + get {{{ + if (m_ShortName.IsEmpty()) + return GetName(); + else + return m_ShortName; + }}} + }; [config, get_protected] String type (TypeName); [config, get_protected] Array::Ptr templates; [config] Dictionary::Ptr methods; diff --git a/lib/config/base-type.conf b/lib/config/base-type.conf index d4648e741..75c3a6d5f 100644 --- a/lib/config/base-type.conf +++ b/lib/config/base-type.conf @@ -18,8 +18,8 @@ ******************************************************************************/ %type DynamicObject { - %require "name", - %attribute %string "name", + %require "__name", + %attribute %string "__name", %require "type", %attribute %string "type", diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index 5f3052b35..4889891a3 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -117,12 +117,12 @@ Dictionary::Ptr ConfigItem::GetProperties(void) if (!m_Properties) { m_Properties = make_shared(); m_Properties->Set("type", m_Type); - m_Properties->Set("name", m_Name); + m_Properties->Set("__name", m_Name); m_Properties->Set("__parent", m_Scope); GetExpressionList()->Evaluate(m_Properties); m_Properties->Remove("__parent"); - VERIFY(m_Properties->Get("type") == GetType() && m_Properties->Get("name") == GetName()); + VERIFY(m_Properties->Get("type") == GetType() && m_Properties->Get("__name") == GetName()); } return m_Properties; diff --git a/lib/icinga/dependency-apply.cpp b/lib/icinga/dependency-apply.cpp index 503998b06..3a6249a47 100644 --- a/lib/icinga/dependency-apply.cpp +++ b/lib/icinga/dependency-apply.cpp @@ -69,12 +69,12 @@ void Dependency::EvaluateApplyRules(const std::vector& rules) builder->SetScope(rule.GetScope()); builder->AddExpression(make_shared(&AExpression::OpSet, - make_shared(&AExpression::OpLiteral, "child_host", di), + make_shared(&AExpression::OpLiteral, "child_host_name", di), make_shared(&AExpression::OpLiteral, service->GetHost()->GetName(), di), di)); builder->AddExpression(make_shared(&AExpression::OpSet, - make_shared(&AExpression::OpLiteral, "child_service", di), + make_shared(&AExpression::OpLiteral, "child_service_name", di), make_shared(&AExpression::OpLiteral, service->GetShortName(), di), di)); builder->AddExpression(rule.GetExpression()); diff --git a/lib/icinga/dependency.cpp b/lib/icinga/dependency.cpp index 10bd6fa08..28d332554 100644 --- a/lib/icinga/dependency.cpp +++ b/lib/icinga/dependency.cpp @@ -116,28 +116,28 @@ bool Dependency::IsAvailable(DependencyType dt) const Checkable::Ptr Dependency::GetChild(void) const { - Host::Ptr host = Host::GetByName(GetChildHostRaw()); + Host::Ptr host = Host::GetByName(GetChildHostName()); if (!host) return Service::Ptr(); - if (GetChildServiceRaw().IsEmpty()) + if (GetChildServiceName().IsEmpty()) return host; else - return host->GetServiceByShortName(GetChildServiceRaw()); + return host->GetServiceByShortName(GetChildServiceName()); } Checkable::Ptr Dependency::GetParent(void) const { - Host::Ptr host = Host::GetByName(GetParentHostRaw()); + Host::Ptr host = Host::GetByName(GetParentHostName()); if (!host) return Service::Ptr(); - if (GetParentServiceRaw().IsEmpty()) + if (GetParentServiceName().IsEmpty()) return host; else - return host->GetServiceByShortName(GetParentServiceRaw()); + return host->GetServiceByShortName(GetParentServiceName()); } TimePeriod::Ptr Dependency::GetPeriod(void) const diff --git a/lib/icinga/dependency.ti b/lib/icinga/dependency.ti index 81ad26885..94d8649c7 100644 --- a/lib/icinga/dependency.ti +++ b/lib/icinga/dependency.ti @@ -6,11 +6,11 @@ namespace icinga class Dependency : DynamicObject { - [config] String child_host (ChildHostRaw); - [config] String child_service (ChildServiceRaw); + [config] String child_host_name; + [config] String child_service_name; - [config] String parent_host (ParentHostRaw); - [config] String parent_service (ParentServiceRaw); + [config] String parent_host_name; + [config] String parent_service_name; [config] String period (PeriodRaw); diff --git a/lib/icinga/icinga-type.conf b/lib/icinga/icinga-type.conf index 71b1bae86..771045c22 100644 --- a/lib/icinga/icinga-type.conf +++ b/lib/icinga/icinga-type.conf @@ -66,11 +66,10 @@ } %type Service %inherits Checkable { - %require "host", - %attribute %name(Host) "host", - - %attribute %string "short_name", + %require "host_name", + %attribute %name(Host) "host_name", + %attribute %string "name", %attribute %array "groups" { %attribute %name(ServiceGroup) "*" @@ -82,11 +81,11 @@ } %type Notification { - %require "host", - %attribute %name(Host) "host", + %require "host_name", + %attribute %name(Host) "host_name", - %require "service", - %attribute %string "service", + %require "service_name", + %attribute %string "service_name", %attribute %array "users" { %attribute %name(User) "*" @@ -190,10 +189,10 @@ } %type ScheduledDowntime { - %require "host", - %attribute %name(Host) "host", - %require "service", - %attribute %string "service", + %require "host_name", + %attribute %name(Host) "host_name", + %require "service_name", + %attribute %string "service_name", %require "author", %attribute %string "author", @@ -211,13 +210,13 @@ } %type Dependency { - %require "parent_host", - %attribute %name(Host) "parent_host", - %attribute %string "parent_service", + %require "parent_host_name", + %attribute %name(Host) "parent_host_name", + %attribute %string "parent_service_name", - %require "child_host", - %attribute %name(Host) "child_host", - %attribute %string "child_service", + %require "child_host_name", + %attribute %name(Host) "child_host_name", + %attribute %string "child_service_name", %attribute %name(TimePeriod) "period", diff --git a/lib/icinga/notification-apply.cpp b/lib/icinga/notification-apply.cpp index 557f6e124..998f5ed15 100644 --- a/lib/icinga/notification-apply.cpp +++ b/lib/icinga/notification-apply.cpp @@ -68,12 +68,12 @@ void Notification::EvaluateApplyRules(const std::vector& rules) builder->SetScope(rule.GetScope()); builder->AddExpression(make_shared(&AExpression::OpSet, - make_shared(&AExpression::OpLiteral, "host", di), + make_shared(&AExpression::OpLiteral, "host_name", di), make_shared(&AExpression::OpLiteral, service->GetHost()->GetName(), di), di)); builder->AddExpression(make_shared(&AExpression::OpSet, - make_shared(&AExpression::OpLiteral, "service", di), + make_shared(&AExpression::OpLiteral, "service_name", di), make_shared(&AExpression::OpLiteral, service->GetShortName(), di), di)); diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index f304f6d9e..f4d47f583 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -77,12 +77,12 @@ void Notification::Stop(void) Checkable::Ptr Notification::GetCheckable(void) const { - Host::Ptr host = Host::GetByName(GetHostRaw()); + Host::Ptr host = Host::GetByName(GetHostName()); - if (GetServiceRaw().IsEmpty()) + if (GetServiceName().IsEmpty()) return host; else - return host->GetServiceByShortName(GetServiceRaw()); + return host->GetServiceByShortName(GetServiceName()); } NotificationCommand::Ptr Notification::GetNotificationCommand(void) const diff --git a/lib/icinga/notification.ti b/lib/icinga/notification.ti index e6b299b4d..7449275fa 100644 --- a/lib/icinga/notification.ti +++ b/lib/icinga/notification.ti @@ -20,8 +20,8 @@ class Notification : DynamicObject [config] int notification_state_filter { default {{{ return ~(int)0; }}} }; - [config, protected] String host (HostRaw); - [config, protected] String service (ServiceRaw); + [config, protected] String host_name; + [config, protected] String service_name; [state] double last_notification; [state, set_protected] double next_notification (NextNotificationRaw); diff --git a/lib/icinga/scheduleddowntime-apply.cpp b/lib/icinga/scheduleddowntime-apply.cpp index ff1ffb127..09085adaa 100644 --- a/lib/icinga/scheduleddowntime-apply.cpp +++ b/lib/icinga/scheduleddowntime-apply.cpp @@ -68,12 +68,12 @@ void ScheduledDowntime::EvaluateApplyRules(const std::vector& rules) builder->SetScope(rule.GetScope()); builder->AddExpression(make_shared(&AExpression::OpSet, - make_shared(&AExpression::OpLiteral, "host", di), + make_shared(&AExpression::OpLiteral, "host_name", di), make_shared(&AExpression::OpLiteral, service->GetHost()->GetName(), di), di)); builder->AddExpression(make_shared(&AExpression::OpSet, - make_shared(&AExpression::OpLiteral, "service", di), + make_shared(&AExpression::OpLiteral, "service_name", di), make_shared(&AExpression::OpLiteral, service->GetShortName(), di), di)); diff --git a/lib/icinga/scheduleddowntime.cpp b/lib/icinga/scheduleddowntime.cpp index 7654fed51..826b8e376 100644 --- a/lib/icinga/scheduleddowntime.cpp +++ b/lib/icinga/scheduleddowntime.cpp @@ -61,12 +61,12 @@ void ScheduledDowntime::TimerProc(void) Checkable::Ptr ScheduledDowntime::GetCheckable(void) const { - Host::Ptr host = Host::GetByName(GetHostRaw()); + Host::Ptr host = Host::GetByName(GetHostName()); - if (GetServiceRaw().IsEmpty()) + if (GetServiceName().IsEmpty()) return host; else - return host->GetServiceByShortName(GetServiceRaw()); + return host->GetServiceByShortName(GetServiceName()); } std::pair ScheduledDowntime::FindNextSegment(void) diff --git a/lib/icinga/scheduleddowntime.ti b/lib/icinga/scheduleddowntime.ti index 6b31a5fa1..9f25e1cf1 100644 --- a/lib/icinga/scheduleddowntime.ti +++ b/lib/icinga/scheduleddowntime.ti @@ -5,8 +5,8 @@ namespace icinga class ScheduledDowntime : DynamicObject { - [config, protected] String host (HostRaw); - [config, protected] String service (ServiceRaw); + [config, protected] String host_name; + [config, protected] String service_name; [config] String author; [config] String comment; diff --git a/lib/icinga/service-apply.cpp b/lib/icinga/service-apply.cpp index 6433237e8..d41499070 100644 --- a/lib/icinga/service-apply.cpp +++ b/lib/icinga/service-apply.cpp @@ -67,12 +67,12 @@ void Service::EvaluateApplyRules(const std::vector& rules) builder->SetScope(rule.GetScope()); builder->AddExpression(make_shared(&AExpression::OpSet, - make_shared(&AExpression::OpLiteral, "host", di), + make_shared(&AExpression::OpLiteral, "host_name", di), make_shared(&AExpression::OpLiteral, host->GetName(), di), di)); builder->AddExpression(make_shared(&AExpression::OpSet, - make_shared(&AExpression::OpLiteral, "short_name", di), + make_shared(&AExpression::OpLiteral, "name", di), make_shared(&AExpression::OpLiteral, rule.GetName(), di), di)); diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index 2f9eac67a..62c4fffb8 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -54,7 +54,7 @@ void Service::OnConfigLoaded(void) } } - m_Host = Host::GetByName(GetHostRaw()); + m_Host = Host::GetByName(GetHostName()); if (m_Host) m_Host->AddService(GetSelf()); diff --git a/lib/icinga/service.ti b/lib/icinga/service.ti index 93cc57937..f48033500 100644 --- a/lib/icinga/service.ti +++ b/lib/icinga/service.ti @@ -16,15 +16,7 @@ class Service : Checkable return m_DisplayName; }}} }; - [config] String short_name { - get {{{ - if (m_ShortName.IsEmpty()) - return GetName(); - else - return m_ShortName; - }}} - }; - [config] String host (HostRaw); + [config] String host_name; [enum] ServiceState "state" { get {{{ return GetStateRaw(); -- 2.40.0