From: Gunnar Beutner Date: Mon, 1 Jul 2013 11:46:50 +0000 (+0200) Subject: Implement support for custom variables. X-Git-Tag: v0.0.2~27 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=23c87f6eaf16ac8f0b3044d790e14d66a9719b3d;p=icinga2 Implement support for custom variables. Fixes #4344 --- diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp index e87395a42..0f13e4e8b 100644 --- a/components/compat/compatcomponent.cpp +++ b/components/compat/compatcomponent.cpp @@ -25,6 +25,7 @@ #include "icinga/servicegroup.h" #include "base/dynamictype.h" #include "base/objectlock.h" +#include "base/convert.h" #include "base/logger_fwd.h" #include "base/exception.h" #include "base/application.h" @@ -328,6 +329,8 @@ void CompatComponent::DumpHostObject(std::ostream& fp, const Host::Ptr& host) } + DumpCustomAttributes(fp, host); + fp << "\t" << "}" << "\n" << "\n"; } @@ -471,11 +474,14 @@ void CompatComponent::DumpServiceObject(std::ostream& fp, const Service::Ptr& se << "\t" << "passive_checks_enabled" << "\t" << (service->GetEnablePassiveChecks() ? 1 : 0) << "\n" << "\t" << "notifications_enabled" << "\t" << (service->GetEnableNotifications() ? 1 : 0) << "\n" << "\t" << "notification_options" << "\t" << "u,w,c,r" << "\n" - << "\t" << "notification_interval" << "\t" << notification_interval / 60.0 << "\n" - << "\t" << "}" << "\n" - << "\n"; + << "\t" << "notification_interval" << "\t" << notification_interval / 60.0 << "\n"; } + DumpCustomAttributes(fp, service); + + fp << "\t" << "}" << "\n" + << "\n"; + BOOST_FOREACH(const Service::Ptr& parent, service->GetParentServices()) { Host::Ptr host = service->GetHost(); @@ -499,6 +505,27 @@ void CompatComponent::DumpServiceObject(std::ostream& fp, const Service::Ptr& se } } +void CompatComponent::DumpCustomAttributes(std::ostream& fp, const DynamicObject::Ptr& object) +{ + Dictionary::Ptr custom = object->Get("custom"); + + if (!custom) + return; + + ObjectLock olock(custom); + String key; + Value value; + BOOST_FOREACH(boost::tie(key, value), custom) { + fp << "\t"; + + if (key != "action_url" && key != "notes_url" && key != "icon_image" && + key != "icon_image_alt" && key != "statusmap_image" && "2d_coords") + fp << "_"; + + fp << key << "\t" << Convert::ToString(value) << "\n"; + } +} + /** * Periodically writes the status.dat and objects.cache files. */ diff --git a/components/compat/compatcomponent.h b/components/compat/compatcomponent.h index 135907d5f..fd9142129 100644 --- a/components/compat/compatcomponent.h +++ b/components/compat/compatcomponent.h @@ -106,6 +106,8 @@ private: void DumpServiceStatus(std::ostream& fp, const Service::Ptr& service); void DumpServiceObject(std::ostream& fp, const Service::Ptr& service); + void DumpCustomAttributes(std::ostream& fp, const DynamicObject::Ptr& object); + void StatusTimerHandler(void); };