Add command namespace {check_,event_,notification_} to legacy interfaces.

Fixes #5927
This commit is contained in:
Michael Friedrich 2014-05-12 14:30:15 +02:00
parent f50306f3a3
commit aa97c3c670
8 changed files with 65 additions and 62 deletions

View File

@ -143,15 +143,7 @@ void StatusDataWriter::DumpCommand(std::ostream& fp, const Command::Ptr& command
fp << "define command {" "\n"
"\t" "command_name\t";
if (command->GetType() == DynamicType::GetByName("CheckCommand"))
fp << "check_";
else if (command->GetType() == DynamicType::GetByName("NotificationCommand"))
fp << "notification_";
else if (command->GetType() == DynamicType::GetByName("EventCommand"))
fp << "event_";
fp << command->GetName() << "\n";
fp << CompatUtility::GetCommandName(command) << "\n";
fp << "\t" "command_line" "\t" << CompatUtility::GetCommandLine(command);
@ -283,11 +275,11 @@ void StatusDataWriter::DumpHostObject(std::ostream& fp, const Host::Ptr& host)
CheckCommand::Ptr checkcommand = host->GetCheckCommand();
if (checkcommand)
fp << "\t" "check_command" "\t" "check_" << checkcommand->GetName() << "!" << CompatUtility::GetCheckableCommandArgs(host) << "\n";
fp << "\t" "check_command" "\t" << CompatUtility::GetCommandName(checkcommand) << "!" << CompatUtility::GetCheckableCommandArgs(host) << "\n";
EventCommand::Ptr eventcommand = host->GetEventCommand();
if (eventcommand)
fp << "\t" "event_handler" "\t" "event_" << eventcommand->GetName() << "\n";
fp << "\t" "event_handler" "\t" << CompatUtility::GetCommandName(eventcommand) << "\n";
fp << "\t" "check_period" "\t" << CompatUtility::GetCheckableCheckPeriod(host) << "\n";
@ -339,8 +331,11 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl
{
CheckResult::Ptr cr = checkable->GetLastCheckResult();
fp << "\t" << "check_command=check_" << CompatUtility::GetCheckableCheckCommand(checkable) << "!" << CompatUtility::GetCheckableCommandArgs(checkable)<< "\n"
"\t" "event_handler=event_" << CompatUtility::GetCheckableEventHandler(checkable) << "\n"
EventCommand::Ptr eventcommand = checkable->GetEventCommand();
CheckCommand::Ptr checkcommand = checkable->GetCheckCommand();
fp << "\t" << "check_command=" << CompatUtility::GetCommandName(checkcommand) << "!" << CompatUtility::GetCheckableCommandArgs(checkable) << "\n"
"\t" "event_handler=" << CompatUtility::GetCommandName(eventcommand) << "\n"
"\t" "check_period=" << CompatUtility::GetCheckableCheckPeriod(checkable) << "\n"
"\t" "check_interval=" << CompatUtility::GetCheckableCheckInterval(checkable) << "\n"
"\t" "retry_interval=" << CompatUtility::GetCheckableRetryInterval(checkable) << "\n"
@ -445,11 +440,11 @@ void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& s
CheckCommand::Ptr checkcommand = service->GetCheckCommand();
if (checkcommand)
fp << "\t" "check_command" "\t" "check_" << checkcommand->GetName() << "!" << CompatUtility::GetCheckableCommandArgs(service)<< "\n";
fp << "\t" "check_command" "\t" << CompatUtility::GetCommandName(checkcommand) << "!" << CompatUtility::GetCheckableCommandArgs(service)<< "\n";
EventCommand::Ptr eventcommand = service->GetEventCommand();
if (eventcommand)
fp << "\t" "event_handler" "\t" "event_" << eventcommand->GetName() << "\n";
fp << "\t" "event_handler" "\t" << CompatUtility::GetCommandName(eventcommand) << "\n";
fp << "\t" "contacts" "\t";
DumpNameList(fp, CompatUtility::GetCheckableNotificationUsers(service));

View File

@ -68,54 +68,19 @@ void CommandsTable::FetchRows(const AddRowFunction& addRowFn)
Value CommandsTable::NameAccessor(const Value& row)
{
String buf;
Command::Ptr command = static_cast<Command::Ptr>(row);
if (!command)
return Empty;
if (command->GetType() == DynamicType::GetByName("CheckCommand"))
buf += "check_";
if (command->GetType() == DynamicType::GetByName("NotificationCommand"))
buf += "notification_";
if (command->GetType() == DynamicType::GetByName("EventCommand"))
buf += "event_";
buf += command->GetName();
return buf;
return CompatUtility::GetCommandName(command);
}
Value CommandsTable::LineAccessor(const Value& row)
{
String buf;
Command::Ptr command = static_cast<Command::Ptr>(row);
if (!command)
return Empty;
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.
String argitem = " \"" + arg + "\"";
boost::algorithm::replace_all(argitem, "\n", "\\n");
buf += argitem;
}
} else if (!commandLine.IsEmpty()) {
String args = Convert::ToString(commandLine);
boost::algorithm::replace_all(args, "\n", "\\n");
buf += args;
} else {
buf += "<internal>";
}
return buf;
return CompatUtility::GetCommandLine(command);
}
Value CommandsTable::CustomVariableNamesAccessor(const Value& row)

View File

@ -223,7 +223,7 @@ Value HostsTable::CheckCommandAccessor(const Value& row)
CheckCommand::Ptr checkcommand = host->GetCheckCommand();
if (checkcommand)
return checkcommand->GetName(); /* this is the name without '!' args */
return CompatUtility::GetCommandName(checkcommand) + "!" + CompatUtility::GetCheckableCommandArgs(host);
return Empty;
}
@ -237,7 +237,7 @@ Value HostsTable::CheckCommandExpandedAccessor(const Value& row)
CheckCommand::Ptr checkcommand = host->GetCheckCommand();
if (checkcommand)
return checkcommand->GetName() + "!" + CompatUtility::GetCheckableCommandArgs(host);
return CompatUtility::GetCommandName(checkcommand) + "!" + CompatUtility::GetCheckableCommandArgs(host);
return Empty;
}
@ -251,7 +251,7 @@ Value HostsTable::EventHandlerAccessor(const Value& row)
EventCommand::Ptr eventcommand = host->GetEventCommand();
if (eventcommand)
return eventcommand->GetName();
return CompatUtility::GetCommandName(eventcommand);
return Empty;
}

View File

@ -191,7 +191,7 @@ Value ServicesTable::CheckCommandAccessor(const Value& row)
CheckCommand::Ptr checkcommand = service->GetCheckCommand();
if (checkcommand)
return checkcommand->GetName(); /* this is the name without '!' args */
return CompatUtility::GetCommandName(checkcommand) + "!" + CompatUtility::GetCheckableCommandArgs(service);
return Empty;
}
@ -206,7 +206,7 @@ Value ServicesTable::CheckCommandExpandedAccessor(const Value& row)
CheckCommand::Ptr checkcommand = service->GetCheckCommand();
if (checkcommand)
return checkcommand->GetName() + "!" + CompatUtility::GetCheckableCommandArgs(service);
return CompatUtility::GetCommandName(checkcommand) + "!" + CompatUtility::GetCheckableCommandArgs(service);
return Empty;
}
@ -221,7 +221,7 @@ Value ServicesTable::EventHandlerAccessor(const Value& row)
EventCommand::Ptr eventcommand = service->GetEventCommand();
if (eventcommand)
return eventcommand->GetName();
return CompatUtility::GetCommandName(eventcommand);
return Empty;
}

View File

@ -330,6 +330,16 @@ The `apt` check command does not support any vars.
## <a id="schemas"></a> Schemas
By convention `CheckCommand`, `EventCommand` and `NotificationCommand` objects
are exported using a prefix. This is mandatory for unique objects in the
command tables.
Object | Prefix
------------------------|------------------------
CheckCommand | check_
EventCommand | event_
NotificationCommand | notification_
### <a id="schema-status-files"></a> Status Files
Status files used by Icinga 1.x Classic UI: `status.dat`, `objects.cache`.

View File

@ -276,7 +276,14 @@ DbObject::Ptr DbObject::GetOrCreateByObject(const DynamicObject::Ptr& object)
name1 = service->GetHost()->GetName();
name2 = service->GetShortName();
} else {
name1 = object->GetName();
if (object->GetType() == DynamicType::GetByName("CheckCommand") ||
object->GetType() == DynamicType::GetByName("EventCommand") ||
object->GetType() == DynamicType::GetByName("NotificationCommand")) {
Command::Ptr command = dynamic_pointer_cast<Command>(object);
name1 = CompatUtility::GetCommandName(command);
}
else
name1 = object->GetName();
}
dbobj = dbtype->GetOrCreateObjectByName(name1, name2);

View File

@ -56,6 +56,30 @@ String CompatUtility::GetCommandLine(const Command::Ptr& command)
return result;
}
String CompatUtility::GetCommandNamePrefix(const Command::Ptr command)
{
if (!command)
return Empty;
String prefix;
if (command->GetType() == DynamicType::GetByName("CheckCommand"))
prefix = "check_";
else if (command->GetType() == DynamicType::GetByName("NotificationCommand"))
prefix = "notification_";
else if (command->GetType() == DynamicType::GetByName("EventCommand"))
prefix = "event_";
return prefix;
}
String CompatUtility::GetCommandName(const Command::Ptr command)
{
if (!command)
return Empty;
return GetCommandNamePrefix(command) + command->GetName();
}
/* host */
String CompatUtility::GetHostAlias(const Host::Ptr& host)
{

View File

@ -39,6 +39,9 @@ namespace icinga
class I2_ICINGA_API CompatUtility
{
public:
/* command */
static String GetCommandLine(const Command::Ptr& command);
static String GetCommandName(const Command::Ptr command);
/* host */
static String GetHostAlias(const Host::Ptr& host);
@ -99,9 +102,6 @@ public:
static std::set<User::Ptr> GetCheckableNotificationUsers(const Checkable::Ptr& checkable);
static std::set<UserGroup::Ptr> GetCheckableNotificationUserGroups(const Checkable::Ptr& checkable);
/* command */
static String GetCommandLine(const Command::Ptr& command);
/* custom attribute */
static bool IsLegacyAttribute(const DynamicObject::Ptr& object, const String& name);
static String GetCustomAttributeConfig(const DynamicObject::Ptr& object, const String& name);
@ -122,6 +122,8 @@ public:
private:
CompatUtility(void);
static String GetCommandNamePrefix(const Command::Ptr command);
};
}