]> granicus.if.org Git - icinga2/commitdiff
compat: dump commands to objects.cache
authorMichael Friedrich <michael.friedrich@netways.de>
Mon, 1 Jul 2013 18:12:03 +0000 (20:12 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Mon, 1 Jul 2013 18:12:03 +0000 (20:12 +0200)
service->notifications may create duplicates.

components/compat/compatcomponent.cpp
components/compat/compatcomponent.h
lib/icinga/command.cpp
lib/icinga/command.h

index 6cb60ccc116f8a497d7736d467dc7d37886376a1..11f2d798e4ce04a8e037de9ce7c47da9e44b1399 100644 (file)
@@ -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)
index fd91421290a5598c23be8fed9a1d1bdbafebbb04..d07cac66e6060e0125925d2ad71cfe3a74c170db 100644 (file)
@@ -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);
index 6eb00c1a26b624289926cd308dc417fbc0f2bede..8ac52e76352d327565e0b56f896d0efcaa0c0542 100644 (file)
@@ -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");
+}
index d796e6b43df20fe51288f6ff970b8ba89a8a7268..99c01108ae2a6a1c15ae52b08f102d9393738db9 100644 (file)
@@ -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;