]> granicus.if.org Git - icinga2/commitdiff
Implement dumping commands and timeperiods.
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 2 Jul 2013 06:44:03 +0000 (08:44 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Tue, 2 Jul 2013 06:44:03 +0000 (08:44 +0200)
components/compat/compatcomponent.cpp
components/compat/compatcomponent.h
lib/icinga/command.cpp
lib/icinga/command.h
lib/icinga/pluginchecktask.cpp
lib/icinga/plugineventtask.cpp
lib/icinga/pluginnotificationtask.cpp

index 11f2d798e4ce04a8e037de9ce7c47da9e44b1399..0a6687c66cd5b24b01fd10dd187d80c3ee42dfa1 100644 (file)
@@ -229,46 +229,55 @@ void CompatComponent::DumpComments(std::ostream& fp, const Service::Ptr& owner,
        }
 }
 
-void CompatComponent::DumpTimeperiods(std::ostream& fp, const Service::Ptr& owner)
+void CompatComponent::DumpTimePeriod(std::ostream& fp, const TimePeriod::Ptr& tp)
 {
+       fp << "define timeperiod {" << "\n"
+          << "\t" << "timeperiod_name" << "\t" << tp->GetName() << "\n";
 
+       Dictionary::Ptr ranges = tp->Get("ranges");
+
+       if (ranges) {
+               ObjectLock olock(ranges);
+               String key;
+               Value value;
+               BOOST_FOREACH(boost::tie(key, value), ranges) {
+                       fp << "\t" << key << "\t" << Convert::ToString(value) << "\n";
+               }
+       }
+
+       fp << "\t" << "}" << "\n"
+          << "\n";
 }
-void CompatComponent::DumpCommands(std::ostream& fp, const Service::Ptr& owner)
+
+void CompatComponent::DumpCommand(std::ostream& fp, const Command::Ptr& command)
 {
-       /* 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";
-       }
+       fp << "define command {" << "\n"
+          << "\t" << "command_name\t" << command->GetName() << "\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";
+       fp << "\t" << "command_line\t";
+
+       Value commandLine = command->GetCommandLine();
+
+       if (commandLine.IsObjectType<Array>()) {
+               Array::Ptr args = commandLine;
+
+               ObjectLock olock(args);
+               String arg;
+               BOOST_FOREACH(arg, args) {
+                       // This is obviously incorrect for non-trivial cases.
+                       fp << " \"" << arg << "\"";
+               }
+       } else {
+               fp << Convert::ToString(commandLine) << "\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";
-        }
+       fp << "\n";
+
+       fp << "\t" << "}" << "\n"
+          << "\n";
 
 }
+
 void CompatComponent::DumpDowntimes(std::ostream& fp, const Service::Ptr& owner, CompatObjectType type)
 {
        Host::Ptr host = owner->GetHost();
@@ -586,8 +595,6 @@ 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)
@@ -783,6 +790,30 @@ void CompatComponent::StatusTimerHandler(void)
                objectfp << tempobjectfp.str();
        }
 
+       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("CheckCommand")) {
+               Command::Ptr command = static_pointer_cast<Command>(object);
+
+               DumpCommand(objectfp, command);
+       }
+
+       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("NotificationCommand")) {
+               Command::Ptr command = static_pointer_cast<Command>(object);
+
+               DumpCommand(objectfp, command);
+       }
+
+       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("EventCommand")) {
+               Command::Ptr command = static_pointer_cast<Command>(object);
+
+               DumpCommand(objectfp, command);
+       }
+
+       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("TimePeriod")) {
+               TimePeriod::Ptr tp = static_pointer_cast<TimePeriod>(object);
+
+               DumpTimePeriod(objectfp, tp);
+       }
+
        statusfp.close();
        objectfp.close();
 
index d07cac66e6060e0125925d2ad71cfe3a74c170db..39afaa4c640bcad69edb1a809eed2441e9ce7e5e 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "icinga/host.h"
 #include "icinga/service.h"
+#include "icinga/command.h"
 #include "base/dynamicobject.h"
 #include "base/objectlock.h"
 #include "base/timer.h"
@@ -65,8 +66,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 DumpCommand(std::ostream& fp, const Command::Ptr& command);
+       void DumpTimePeriod(std::ostream& fp, const TimePeriod::Ptr& tp);
        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 8ac52e76352d327565e0b56f896d0efcaa0c0542..12b615e99fc419890015d923458f712f7c899f12 100644 (file)
@@ -55,7 +55,7 @@ bool Command::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, Strin
        return false;
 }
 
-String Command::GetCommandLine(void) const
+Value Command::GetCommandLine(void) const
 {
        return Get("command");
 }
index 99c01108ae2a6a1c15ae52b08f102d9393738db9..cfa4a252adce29847c75891d4a87734bc2f1cecc 100644 (file)
@@ -49,7 +49,7 @@ public:
        Array::Ptr GetExportMacros(void) const;
        virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
 
-       String GetCommandLine(void) const;
+       Value GetCommandLine(void) const;
 
 private:
        Attribute<Dictionary::Ptr> m_Macros;
index 987d39cd293674300c8becd21270ed2667723d51..93abbca9cc6ab7e3adc9d39beda0f77243ca148e 100644 (file)
@@ -38,7 +38,7 @@ REGISTER_SCRIPTFUNCTION(PluginCheck,  &PluginCheckTask::ScriptFunc);
 Dictionary::Ptr PluginCheckTask::ScriptFunc(const Service::Ptr& service)
 {
        CheckCommand::Ptr commandObj = service->GetCheckCommand();
-       Value raw_command = commandObj->Get("command");
+       Value raw_command = commandObj->GetCommandLine();
 
        std::vector<MacroResolver::Ptr> resolvers;
        resolvers.push_back(commandObj);
index bb71100625dc44fb73afe535a79813807b8bab72..e2ee6fd8a5039db114a6e16b030944347e326256 100644 (file)
@@ -36,7 +36,7 @@ REGISTER_SCRIPTFUNCTION(PluginEvent, &PluginEventTask::ScriptFunc);
 void PluginEventTask::ScriptFunc(const Service::Ptr& service)
 {
        EventCommand::Ptr commandObj = service->GetEventCommand();
-       Value raw_command = commandObj->Get("command");
+       Value raw_command = commandObj->GetCommandLine();
 
        std::vector<MacroResolver::Ptr> resolvers;
        resolvers.push_back(commandObj);
index 63f893bd756e5e9e017ecd6d1404fea12d37b6cf..1f9a58d6fdc69aaa2cb5504cf2bfae9e1e040ac3 100644 (file)
@@ -43,7 +43,7 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, c
 
        Service::Ptr service = notification->GetService();
 
-       Value raw_command = commandObj->Get("command");
+       Value raw_command = commandObj->GetCommandLine();
 
        StaticMacroResolver::Ptr notificationMacroResolver = boost::make_shared<StaticMacroResolver>();
        notificationMacroResolver->Add("NOTIFICATIONTYPE", Notification::NotificationTypeToString(type));