}
}
-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();
<< "\t" << "}" << "\n"
<< "\n";
}
-
- DumpCommands(fp, service);
}
void CompatComponent::DumpCustomAttributes(std::ostream& fp, const DynamicObject::Ptr& object)
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();
#include "icinga/host.h"
#include "icinga/service.h"
+#include "icinga/command.h"
#include "base/dynamicobject.h"
#include "base/objectlock.h"
#include "base/timer.h"
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);