Implement dumping commands and timeperiods.

This commit is contained in:
Gunnar Beutner 2013-07-02 08:44:03 +02:00
parent 207b91224b
commit 03e019580a
7 changed files with 73 additions and 41 deletions

View 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";
}
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();
Dictionary::Ptr ranges = tp->Get("ranges");
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 (ranges) {
ObjectLock olock(ranges);
String key;
Value value;
BOOST_FOREACH(boost::tie(key, value), ranges) {
fp << "\t" << key << "\t" << Convert::ToString(value) << "\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 << "\t" << "}" << "\n"
<< "\n";
}
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::DumpCommand(std::ostream& fp, const Command::Ptr& command)
{
fp << "define command {" << "\n"
<< "\t" << "command_name\t" << command->GetName() << "\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";
}
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();

View 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);

View 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");
}

View 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;

View 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);

View 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);

View 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));