******************************************************************************/
abstract object Service "ping4" inherits "plugin-service" {
- check_command = "$plugindir$/check_ping -4 -H $address$ -w $wrta$,$wpl$% -c $crta$,$cpl$%a -p $packets$ -t $timeout$",
+ check_command = {
+ "$plugindir$/check_ping",
+ "-4",
+ "-H", "$address$",
+ "-w", "$wrta$,$wpl$%",
+ "-c", "$crta$,$cpl$%",
+ "-p", "$packets$",
+ "-t", "$timeout$"
+ },
macros = {
wrta = 100,
}
abstract object Service "ping6" inherits "plugin-service" {
- check_command = "$plugindir$/check_ping -6 -H $address6$ -w $wrta$,$wpl$% -c $crta$,$cpl$%a -p $packets$ -t $timeout$",
+ check_command = {
+ "$plugindir$/check_ping",
+ "-6",
+ "-H", "$address6$",
+ "-w", "$wrta$,$wpl$%",
+ "-c", "$crta$,$cpl$%",
+ "-p", "$packets$",
+ "-t", "$timeout$"
+ },
macros = {
wrta = 100,
}
abstract object Service "dummy" inherits "plugin-service" {
- check_command = "$plugindir$/check_dummy $state$ '$text$'",
+ check_command = {
+ "$plugindir$/check_dummy",
+ "$state$",
+ "$text$"
+ },
macros = {
state = 0,
}
abstract object Service "http_vhost" inherits "plugin-service" {
- check_command = "$plugindir$/check_http -H $vhost$"
+ check_command = {
+ "$plugindir$/check_http",
+ "-H", "$vhost$"
+ },
}
abstract object Service "http_ip" inherits "plugin-service" {
- check_command = "$plugindir$/check_http -I $address$"
+ check_command = {
+ "$plugindir$/check_http",
+ "-I", "$address$"
+ }
}
abstract object Service "ssh" inherits "plugin-service" {
- check_command = "$plugindir$/check_ssh $address$"
+ check_command = {
+ "$plugindir$/check_ssh",
+ "$address$"
+ }
}
abstract object Service "disk" inherits "plugin-service" {
- check_command = "$plugindir$/check_disk -w '$wfree$' -c '$cfree$'",
+ check_command = {
+ "$plugindir$/check_disk",
+ "-w", "$wfree$",
+ "-c", "$cfree$"
+ },
macros += {
wfree = "20%",
}
abstract object Service "users" inherits "plugin-service" {
- check_command = "$plugindir$/check_users -w '$wgreater$' -c '$cgreater$'",
+ check_command = {
+ "$plugindir$/check_users",
+ "-w", "$wgreater$",
+ "-c", "$cgreater$"
+ },
macros += {
wgreater = 20,
}
abstract object Service "processes" inherits "plugin-service" {
- check_command = "$plugindir$/check_procs -w '$wgreater$' -c '$cgreater$'",
+ check_command = {
+ "$plugindir$/check_procs",
+ "-w", "$wgreater$",
+ "-c", "$cgreater$"
+ },
macros += {
wgreater = 250,
abstract object Service "load" inherits "plugin-service" {
- check_command = "$plugindir$/check_load -w $wload1$,$wload5$,$wload15$ -c $cload1$,$cload5$,$cload15$",
+ check_command = {
+ "$plugindir$/check_load",
+ "-w", "$wload1$,$wload5$,$wload15$",
+ "-c", "$cload1$,$cload5$,$cload15$"
+ },
macros = {
wload1 = 5.0,
%attribute dictionary "*" {
%attribute string "service",
+ %attribute string "short_name",
+
%attribute dictionary "macros" {
%attribute string "*"
},
#endif /* _WIN32 */
}
-vector<String> Process::ParseCommand(const String& command)
+vector<String> Process::SplitCommand(const Value& command)
{
- // TODO: implement
vector<String> args;
+
+ if (command.IsObjectType<Dictionary>()) {
+ Dictionary::Ptr dict = command;
+ Value arg;
+ BOOST_FOREACH(tie(tuples::ignore, arg), dict) {
+ args.push_back(arg);
+ }
+
+ return args;
+ }
+
+ // TODO: implement
#ifdef _WIN32
args.push_back(command);
#else /* _WIN32 */
Process(const vector<String>& arguments, const Dictionary::Ptr& extraEnvironment = Dictionary::Ptr());
- static vector<String> ParseCommand(const String& command);
+ static vector<String> SplitCommand(const Value& command);
private:
static bool m_WorkersCreated;
using namespace icinga;
-String MacroProcessor::ResolveMacros(const String& str, const vector<Dictionary::Ptr>& macroDicts)
+Value MacroProcessor::ResolveMacros(const Value& cmd, const Dictionary::Ptr& macros)
+{
+ Value result;
+
+ if (cmd.IsScalar()) {
+ result = InternalResolveMacros(cmd, macros);
+ } else {
+ Dictionary::Ptr resultDict = boost::make_shared<Dictionary>();
+ Dictionary::Ptr dict = cmd;
+
+ Value arg;
+ BOOST_FOREACH(tie(tuples::ignore, arg), dict) {
+ resultDict->Add(InternalResolveMacros(arg, macros));
+ }
+
+ result = resultDict;
+ }
+
+ return result;
+}
+
+String MacroProcessor::InternalResolveMacros(const String& str, const Dictionary::Ptr& macros)
{
size_t offset, pos_first, pos_second;
BOOST_THROW_EXCEPTION(runtime_error("Closing $ not found in macro format String."));
String name = result.SubStr(pos_first + 1, pos_second - pos_first - 1);
- String value;
- bool resolved = false;
-
- BOOST_FOREACH(const Dictionary::Ptr& macroDict, macroDicts) {
- if (!macroDict || !macroDict->Contains(name))
- continue;
- String value = macroDict->Get(name);
- result.Replace(pos_first, pos_second - pos_first + 1, value);
- offset = pos_first + value.GetLength();
-
- resolved = true;
- break;
- }
-
- if (!resolved)
+ if (!macros || !macros->Contains(name))
BOOST_THROW_EXCEPTION(runtime_error("Macro '" + name + "' is not defined."));
+
+ String value = macros->Get(name);
+ result.Replace(pos_first, pos_second - pos_first + 1, value);
+ offset = pos_first + value.GetLength();
}
return result;
}
-Dictionary::Ptr MacroProcessor::MakeEnvironment(const vector<Dictionary::Ptr>& dicts)
+Dictionary::Ptr MacroProcessor::MergeMacroDicts(const vector<Dictionary::Ptr>& dicts)
{
Dictionary::Ptr result = boost::make_shared<Dictionary>();
class I2_ICINGA_API MacroProcessor
{
public:
- static String ResolveMacros(const String& str, const vector<Dictionary::Ptr>& macroDicts);
- static Dictionary::Ptr MakeEnvironment(const vector<Dictionary::Ptr>& macroDicts);
+ static Value ResolveMacros(const Value& str, const Dictionary::Ptr& macros);
+ static Dictionary::Ptr MergeMacroDicts(const vector<Dictionary::Ptr>& macroDicts);
+
+private:
+ static String InternalResolveMacros(const String& str, const Dictionary::Ptr& macros);
};
}
return host->GetServiceByShortName(service);
}
-String Notification::GetNotificationCommand(void) const
+Value Notification::GetNotificationCommand(void) const
{
return Get("notification_command");
}
static Notification::Ptr GetByName(const String& name);
shared_ptr<Service> GetService(void) const;
- String GetNotificationCommand(void) const;
+ Value GetNotificationCommand(void) const;
Dictionary::Ptr GetMacros(void) const;
void SendNotification(NotificationType type);
Service::Ptr service = vservice;
- String checkCommand = service->GetCheckCommand();
-
vector<Dictionary::Ptr> macroDicts;
macroDicts.push_back(service->GetMacros());
macroDicts.push_back(service->CalculateDynamicMacros());
macroDicts.push_back(service->GetHost()->GetMacros());
macroDicts.push_back(service->GetHost()->CalculateDynamicMacros());
macroDicts.push_back(IcingaApplication::GetInstance()->GetMacros());
- String command = MacroProcessor::ResolveMacros(checkCommand, macroDicts);
+ Dictionary::Ptr macros = MacroProcessor::MergeMacroDicts(macroDicts);
+
+ Value command = MacroProcessor::ResolveMacros(service->GetCheckCommand(), macros);
- Process::Ptr process = boost::make_shared<Process>(Process::ParseCommand(command), MacroProcessor::MakeEnvironment(macroDicts));
+ Process::Ptr process = boost::make_shared<Process>(Process::SplitCommand(command), macros);
PluginCheckTask ct(task, process);
Notification::Ptr notification = arguments[0];
NotificationType type = static_cast<NotificationType>(static_cast<int>(arguments[1]));
- String notificationCommand = notification->GetNotificationCommand();
-
vector<Dictionary::Ptr> macroDicts;
macroDicts.push_back(notification->GetMacros());
macroDicts.push_back(notification->GetService()->GetMacros());
macroDicts.push_back(notification->GetService()->GetHost()->GetMacros());
macroDicts.push_back(notification->GetService()->GetHost()->CalculateDynamicMacros());
macroDicts.push_back(IcingaApplication::GetInstance()->GetMacros());
- String command = MacroProcessor::ResolveMacros(notificationCommand, macroDicts);
+ Dictionary::Ptr macros = MacroProcessor::MergeMacroDicts(macroDicts);
+
+ Value command = MacroProcessor::ResolveMacros(notification->GetNotificationCommand(), macros);
- Process::Ptr process = boost::make_shared<Process>(Process::ParseCommand(command), MacroProcessor::MakeEnvironment(macroDicts));
+ Process::Ptr process = boost::make_shared<Process>(Process::SplitCommand(command), macros);
PluginNotificationTask ct(task, process, notification->GetService()->GetName(), command);
boost::signal<void (const Service::Ptr&, const String&)> Service::OnCheckerChanged;
boost::signal<void (const Service::Ptr&, const Value&)> Service::OnNextCheckChanged;
-String Service::GetCheckCommand(void) const
+Value Service::GetCheckCommand(void) const
{
return Get("check_command");
}
/* Checks */
Dictionary::Ptr GetCheckers(void) const;
- String GetCheckCommand(void) const;
+ Value GetCheckCommand(void) const;
long GetMaxCheckAttempts(void) const;
double GetCheckInterval(void) const;
double GetRetryInterval(void) const;