CheckCommand::Ptr checkcommand = host->GetCheckCommand();
if (checkcommand)
- fp << "\t" "check_command" "\t" "check_" << checkcommand->GetName() << "\n";
+ fp << "\t" "check_command" "\t" "check_" << checkcommand->GetName() << "!" << CompatUtility::GetCheckableCommandArgs(host) << "\n";
EventCommand::Ptr eventcommand = host->GetEventCommand();
if (eventcommand)
{
CheckResult::Ptr cr = checkable->GetLastCheckResult();
- fp << "\t" << "check_command=check_" << CompatUtility::GetCheckableCheckCommand(checkable) << "\n"
+ fp << "\t" << "check_command=check_" << CompatUtility::GetCheckableCheckCommand(checkable) << "!" << CompatUtility::GetCheckableCommandArgs(checkable)<< "\n"
"\t" "event_handler=event_" << CompatUtility::GetCheckableEventHandler(checkable) << "\n"
"\t" "check_period=" << CompatUtility::GetCheckableCheckPeriod(checkable) << "\n"
"\t" "check_interval=" << CompatUtility::GetCheckableCheckInterval(checkable) << "\n"
CheckCommand::Ptr checkcommand = service->GetCheckCommand();
if (checkcommand)
- fp << "\t" "check_command" "\t" "check_" << checkcommand->GetName() << "\n";
+ fp << "\t" "check_command" "\t" "check_" << checkcommand->GetName() << "!" << CompatUtility::GetCheckableCommandArgs(service)<< "\n";
EventCommand::Ptr eventcommand = service->GetEventCommand();
if (eventcommand)
CheckCommand::Ptr checkcommand = host->GetCheckCommand();
if (checkcommand)
- return checkcommand->GetName(); /* this is the name without '!' args */
+ return checkcommand->GetName() + "!" + CompatUtility::GetCheckableCommandArgs(host);
return Empty;
}
CheckCommand::Ptr checkcommand = service->GetCheckCommand();
if (checkcommand)
- return checkcommand->GetName(); /* this is the name without '!' args */
+ return checkcommand->GetName() + "!" + CompatUtility::GetCheckableCommandArgs(service);
return Empty;
}
fields->Set("address6", host->GetAddress6());
fields->Set("check_command_object_id", host->GetCheckCommand());
- fields->Set("check_command_args", Empty);
+ fields->Set("check_command_args", CompatUtility::GetCheckableCommandArgs(host));
fields->Set("eventhandler_command_object_id", host->GetEventCommand());
fields->Set("eventhandler_command_args", Empty);
fields->Set("notification_timeperiod_object_id", Notification::GetByName(CompatUtility::GetCheckableNotificationNotificationPeriod(host)));
fields->Set("host_object_id", host);
fields->Set("display_name", service->GetDisplayName());
fields->Set("check_command_object_id", service->GetCheckCommand());
- fields->Set("check_command_args", Empty);
+ fields->Set("check_command_args", CompatUtility::GetCheckableCommandArgs(service));
fields->Set("eventhandler_command_object_id", service->GetEventCommand());
fields->Set("eventhandler_command_args", Empty);
fields->Set("notification_timeperiod_object_id", Notification::GetByName(CompatUtility::GetCheckableNotificationNotificationPeriod(service)));
}
/* service */
+String CompatUtility::GetCheckableCommandArgs(const Checkable::Ptr& checkable)
+{
+ CheckCommand::Ptr command = checkable->GetCheckCommand();
+
+ Dictionary::Ptr args = make_shared<Dictionary>();
+
+ if (command) {
+ Host::Ptr host;
+ Service::Ptr service;
+ tie(host, service) = GetHostService(checkable);
+ String command_line = GetCommandLine(command);
+
+ Dictionary::Ptr command_vars = command->GetVars();
+
+ if (command_vars) {
+ BOOST_FOREACH(Dictionary::Pair kv, command_vars) {
+ String macro = "$" + kv.first + "$"; // this is too simple
+ if (command_line.Contains(macro))
+ args->Set(kv.first, kv.second);
+
+ }
+ }
+
+ Dictionary::Ptr host_vars = host->GetVars();
+
+ if (host_vars) {
+ BOOST_FOREACH(Dictionary::Pair kv, host_vars) {
+ String macro = "$" + kv.first + "$"; // this is too simple
+ if (command_line.Contains(macro))
+ args->Set(kv.first, kv.second);
+ macro = "$host.vars." + kv.first + "$";
+ if (command_line.Contains(macro))
+ args->Set(kv.first, kv.second);
+ }
+ }
+
+ if (service) {
+ Dictionary::Ptr service_vars = service->GetVars();
+
+ if (service_vars) {
+ BOOST_FOREACH(Dictionary::Pair kv, service_vars) {
+ String macro = "$" + kv.first + "$"; // this is too simple
+ if (command_line.Contains(macro))
+ args->Set(kv.first, kv.second);
+ macro = "$service.vars." + kv.first + "$";
+ if (command_line.Contains(macro))
+ args->Set(kv.first, kv.second);
+ }
+ }
+ }
+
+ String arg_string;
+ BOOST_FOREACH(Dictionary::Pair kv, args) {
+ arg_string += kv.first + "=" + kv.second + "!";
+ }
+ return arg_string;
+ }
+
+ return Empty;
+}
+
int CompatUtility::GetCheckableCheckType(const Checkable::Ptr& checkable)
{
return (checkable->GetEnableActiveChecks() ? 0 : 1);
static int GetHostNotifyOnUnreachable(const Host::Ptr& host);
/* service */
+ static String GetCheckableCommandArgs(const Checkable::Ptr& checkable);
static int GetCheckableCheckType(const Checkable::Ptr& checkable);
static double GetCheckableCheckInterval(const Checkable::Ptr& checkable);
static double GetCheckableRetryInterval(const Checkable::Ptr& checkable);
--- /dev/null
+
+
+object CheckCommand "5926-macro-test" {
+ import "plugin-check-command"
+ command = "echo \"address: $address$ address_service: $service.vars.address$ foo: $foo$ keks: $keks$ god: $god$\""
+ //command = "echo \"address: $address$ address_service: $service.vars.address$\""
+}
+
+object Host "5926-macro-test-host" {
+ import "test-generic-host"
+ check_command = "5926-macro-test"
+ address = "1.2.3.4"
+ vars.god = "father"
+}
+
+apply Service "5926-macro-test-service" {
+ import "test-generic-service"
+ check_command = "5926-macro-test"
+ vars.address = "5.6.7.8"
+ vars.foo = "bar"
+ vars.keks = "schaschlik"
+
+ assign where host.name == "5926-macro-test-host"
+}