From 207b91224bbff8ebd146fcb9505a782a6f2928f8 Mon Sep 17 00:00:00 2001 From: Michael Friedrich <michael.friedrich@netways.de> Date: Mon, 1 Jul 2013 20:12:03 +0200 Subject: [PATCH] compat: dump commands to objects.cache service->notifications may create duplicates. --- components/compat/compatcomponent.cpp | 42 +++++++++++++++++++++++++++ components/compat/compatcomponent.h | 2 ++ lib/icinga/command.cpp | 5 ++++ lib/icinga/command.h | 2 ++ 4 files changed, 51 insertions(+) diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp index 6cb60ccc1..11f2d798e 100644 --- a/components/compat/compatcomponent.cpp +++ b/components/compat/compatcomponent.cpp @@ -229,6 +229,46 @@ void CompatComponent::DumpComments(std::ostream& fp, const Service::Ptr& owner, } } +void CompatComponent::DumpTimeperiods(std::ostream& fp, const Service::Ptr& owner) +{ + +} +void CompatComponent::DumpCommands(std::ostream& fp, const Service::Ptr& owner) +{ + /* check_command, event_command -> service + * notification_command -> GetNotifications() -> GetNotificationCommand() + */ + CheckCommand::Ptr check_command = owner->GetCheckCommand(); + EventCommand::Ptr event_command = owner->GetEventCommand(); + + if (check_command) { + fp << "define command {" << "\n" + << "\t" << "command_name\t" << check_command->GetName() << "\n" + << "\t" << "command_line\t" << check_command->GetCommandLine() << "\n" + << "\t" << "}" << "\n" + << "\n"; + } + + if (event_command) { + fp << "define command {" << "\n" + << "\t" << "command_name\t" << event_command->GetName() << "\n" + << "\t" << "command_line\t" << event_command->GetCommandLine() << "\n" + << "\t" << "}" << "\n" + << "\n"; + } + BOOST_FOREACH(const Notification::Ptr& notification, owner->GetNotifications()) { + NotificationCommand::Ptr notification_command = notification->GetNotificationCommand(); + if(!notification_command) + continue; + + fp << "define command {" << "\n" + << "\t" << "command_name\t" << notification_command->GetName() << "\n" + << "\t" << "command_line\t" << notification_command->GetCommandLine() << "\n" + << "\t" << "}" << "\n" + << "\n"; + } + +} void CompatComponent::DumpDowntimes(std::ostream& fp, const Service::Ptr& owner, CompatObjectType type) { Host::Ptr host = owner->GetHost(); @@ -546,6 +586,8 @@ void CompatComponent::DumpServiceObject(std::ostream& fp, const Service::Ptr& se << "\t" << "}" << "\n" << "\n"; } + + DumpCommands(fp, service); } void CompatComponent::DumpCustomAttributes(std::ostream& fp, const DynamicObject::Ptr& object) diff --git a/components/compat/compatcomponent.h b/components/compat/compatcomponent.h index fd9142129..d07cac66e 100644 --- a/components/compat/compatcomponent.h +++ b/components/compat/compatcomponent.h @@ -65,6 +65,8 @@ private: String GetObjectsPath(void) const; String GetCommandPath(void) const; + void DumpCommands(std::ostream& fp, const Service::Ptr& owner); + void DumpTimeperiods(std::ostream& fp, const Service::Ptr& owner); void DumpDowntimes(std::ostream& fp, const Service::Ptr& owner, CompatObjectType type); void DumpComments(std::ostream& fp, const Service::Ptr& owner, CompatObjectType type); void DumpHostStatus(std::ostream& fp, const Host::Ptr& host); diff --git a/lib/icinga/command.cpp b/lib/icinga/command.cpp index 6eb00c1a2..8ac52e763 100644 --- a/lib/icinga/command.cpp +++ b/lib/icinga/command.cpp @@ -54,3 +54,8 @@ bool Command::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, Strin return false; } + +String Command::GetCommandLine(void) const +{ + return Get("command"); +} diff --git a/lib/icinga/command.h b/lib/icinga/command.h index d796e6b43..99c01108a 100644 --- a/lib/icinga/command.h +++ b/lib/icinga/command.h @@ -49,6 +49,8 @@ public: Array::Ptr GetExportMacros(void) const; virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const; + String GetCommandLine(void) const; + private: Attribute<Dictionary::Ptr> m_Macros; Attribute<Array::Ptr> m_ExportMacros;