Service::Ptr service = notification->GetService();
bool reachable = service->IsReachable();
- notification->SetNextNotification(Utility::GetTime() + notification->GetNotificationInterval());
+ {
+ ObjectLock olock(notification);
+ notification->SetNextNotification(Utility::GetTime() + notification->GetNotificationInterval());
+ }
bool send_notification;
check for localhost. Modify your 'icinga2.conf' configuration file by adding the following lines:
----
-template Service "my-ping" inherits "plugin-service" {
- check_command = [
+object CheckCommand "my-ping" inherits "plugin-check-command" {
+ command = [
"$plugindir$/check_ping",
"-H", "$address$",
"-w", "10,5%",
]
}
+template Service "my-ping" inherits "plugin-service" {
+ check_command = "my-ping"
+}
+
object Host "localhost" {
display_name = "Home, sweet home!",
}
----
-We're defining a service template called "my-ping" which inherits from the
-'plugin-service' template. The 'plugin-service' template is provided as part of
-the Icinga Template Library and describes how services are checked.
+We're defining a command object called "my-ping" which inherits from the
+'plugin-check-command' template. The 'plugin-check-command' template is provided as part of
+the Icinga Template Library and describes how checks are performed.
In the case of plugin-based services this means that the command specified by
the 'check_command' property is executed.
|address6 |The IPv6 address of the host.
|===
-Note that the 'my-ping' template does not define a value for the 'address' macro. This
+Note that the 'my-ping' command object does not define a value for the 'address' macro. This
is perfectly fine as long as that macro is defined somewhere else (e.g. in the host).
+We're also defining a service template called 'my-ping' which uses the command object
+we just created.
+
Next we're defining a 'Host' object called 'localhost'. We're setting an optional
display_name which is used by the CGIs when showing that host in the host overview.
Restart your Icinga 2 instance and check the CGIs for your new service's state. Unless
you have a low-latency network connection you will note that the service's state is 'CRITICAL'.
-This is because in the 'my-ping' template we have hard-coded the timeout as 25 milliseconds.
+This is because in the 'my-ping' command object we have hard-coded the timeout as 25 milliseconds.
Ideally we'd be able to specify different timeouts for our new service. Using macros we
can easily do this.
NOTE: If you've used Icinga 1.x before you're probably familiar with doing this by passing
ARGx macros to your check commands.
-Start by replacing your 'my-ping' service template with this:
+Start by replacing your 'my-ping' command object with this:
----
-template Service "my-ping" inherits "plugin-service" {
- check_command = [
+object CheckCommand "my-ping" inherits "plugin-check-command" {
+ command = [
"$plugindir$/check_ping",
"-H", "$address$",
"-w", "$wrta$,$wpl$%",
relative to the current configuration file are considered. The angle brackets tell
Icinga 2 to search its list of global include directories.
-One of the templates in the ITL is the 'ping4' template which is quite similar
-to our own 'my-ping' template:
+One of the templates in the ITL is the 'ping4' service template which is quite similar
+to our example objects:
----
-template Service "ping4" inherits "plugin-service" {
- check_command = [
+object CheckCommand "ping4" inherits "plugin-check-command" {
+ command = [
"$plugindir$/check_ping",
"-4",
"-H", "$address$",
timeout = 0
}
}
+
+template Service "ping4" {
+ check_command = "ping4"
+}
----
Lets simplify our configuration file by removing our custom 'my-ping' template and
the shell script:
----
-template Notification "mail-notification" inherits "plugin-notification" {
- notification_command = [
+object NotificationCommand "mail-notification" inherits "plugin-notification-command" {
+ command = [
"/etc/icinga2/mail-notification.sh",
"$email$"
],
"SERVICEOUTPUT"
]
}
+
+template Notification "mail-notification" inherits "plugin-notification" {
+ notification_command = "mail-notification"
+}
----
NOTE: Rather than adding these templates to your main configuration file you might want
icinga2itldir = ${pkgdatadir}/itl
icinga2itl_DATA = \
cluster.conf \
+ command.conf \
+ command-common.conf \
itl.conf \
host.conf \
notification.conf \
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+object CheckCommand "ping4" inherits "plugin-check-command" {
+ command = [
+ "$plugindir$/check_ping",
+ "-4",
+ "-H", "$address$",
+ "-w", "$wrta$,$wpl$%",
+ "-c", "$crta$,$cpl$%",
+ "-p", "$packets$",
+ "-t", "$timeout$"
+ ],
+
+ macros = {
+ wrta = 100,
+ wpl = 5,
+
+ crta = 200,
+ cpl = 15,
+
+ packets = 5,
+ timeout = 0
+ }
+}
+
+object CheckCommand "ping6" inherits "plugin-check-command" {
+ command = [
+ "$plugindir$/check_ping",
+ "-6",
+ "-H", "$address6$",
+ "-w", "$wrta$,$wpl$%",
+ "-c", "$crta$,$cpl$%",
+ "-p", "$packets$",
+ "-t", "$timeout$"
+ ],
+
+ macros = {
+ wrta = 100,
+ wpl = 5,
+
+ crta = 200,
+ cpl = 15,
+
+ packets = 5,
+ timeout = 0
+ }
+}
+
+object CheckCommand "dummy" inherits "plugin-check-command" {
+ command = [
+ "$plugindir$/check_dummy",
+ "$state$",
+ "$text$"
+ ],
+
+ macros = {
+ state = 0,
+ text = "Check was successful."
+ }
+}
+
+object CheckCommand "tcp" inherits "plugin-check-command" {
+ command = [
+ "$plugindir$/check_tcp",
+ "-H", "$address$",
+ "-p", "$port$"
+ ]
+}
+
+object CheckCommand "udp" inherits "plugin-check-command" {
+ command = [
+ "$plugindir$/check_udp",
+ "-H", "$address$",
+ "-p", "$port$"
+ ]
+}
+
+object CheckCommand "http_vhost" inherits "plugin-check-command" {
+ command = [
+ "$plugindir$/check_http",
+ "-H", "$vhost$"
+ ]
+}
+
+object CheckCommand "http_ip" inherits "plugin-check-command" {
+ command = [
+ "$plugindir$/check_ip",
+ "-H", "$address$"
+ ]
+}
+
+object CheckCommand "https_vhost" inherits "plugin-check-command" {
+ command = [
+ "$plugindir$/check_http",
+ "-H", "$vhost", "-S"
+ ]
+}
+
+object CheckCommand "https_ip" inherits "plugin-check-command" {
+ command = [
+ "$plugindir$/check_http",
+ "-I", "$address$", "-S"
+ ]
+}
+
+object CheckCommand "smtp" inherits "plugin-check-command" {
+ command = [
+ "$plugindir$/check_smtp",
+ "-H", "$address$"
+ ]
+}
+
+object CheckCommand "ssmtp" inherits "plugin-check-command" {
+ command = [
+ "$plugindir$/check_ssmtp",
+ "-H", "$address$",
+ "-p", "$port$"
+ ],
+
+ macros += {
+ port = 465
+ }
+}
+
+object CheckCommand "ntp_time" inherits "plugin-check-command" {
+ command = [
+ "$plugindir$/check_ntp_time",
+ "-H", "$address$"
+ ]
+}
+
+object CheckCommand "ssh" inherits "plugin-check-command" {
+ command = [
+ "$plugindir$/check_ssh",
+ "$address$"
+ ]
+}
+
+object CheckCommand "disk" inherits "plugin-check-command" {
+ command = [
+ "$plugindir$/check_disk",
+ "-w", "$wfree$",
+ "-c", "$cfree$"
+ ],
+
+ macros += {
+ wfree = "20%",
+ cfree = "10%",
+ }
+}
+
+object CheckCommand "users" inherits "plugin-check-command" {
+ command = [
+ "$plugindir$/check_users",
+ "-w", "$wgreater$",
+ "-c", "$cgreater$"
+ ],
+
+ macros += {
+ wgreater = 20,
+ cgreater = 50,
+ }
+}
+
+object CheckCommand "processes" inherits "plugin-check-command" {
+ command = [
+ "$plugindir$/check_procs",
+ "-w", "$wgreater$",
+ "-c", "$cgreater$"
+ ],
+
+ macros += {
+ wgreater = 250,
+ cgreater = 400,
+ }
+}
+
+object CheckCommand "load" inherits "plugin-check-command" {
+ command = [
+ "$plugindir$/check_load",
+ "-w", "$wload1$,$wload5$,$wload15$",
+ "-c", "$cload1$,$cload5$,$cload15$"
+ ],
+
+ macros = {
+ wload1 = 5.0,
+ wload5 = 4.0,
+ wload15 = 3.0,
+
+ cload1 = 10.0,
+ cload5 = 6.0,
+ cload15 = 4.0
+ }
+}
+
+object CheckCommand "snmp" inherits "plugin-check-command" {
+ command = [
+ "$plugindir$/check_snmp",
+ "-H", "$address$",
+ "-o", "$oid$",
+ "-C", "$community$"
+ ],
+
+ macros = {
+ community = "public"
+ }
+}
\ No newline at end of file
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+template CheckCommand "plugin-check-command" {
+ methods = {
+ execute = "PluginCheck"
+ }
+}
+
+template NotificationCommand "plugin-notification-command" {
+ methods = {
+ execute = "PluginNotification"
+ }
+}
+
+template EventCommand "plugin-event-command" {
+ methods = {
+ execute = "PluginEvent"
+ }
+}
*/
include "host.conf"
+include "command.conf"
+include "command-common.conf"
include "service.conf"
include "service-common.conf"
include "notification.conf"
* along with this program; if not, write to the Free Software Foundation *
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-
-template Service "ping4" inherits "plugin-service" {
- check_command = [
- "$plugindir$/check_ping",
- "-4",
- "-H", "$address$",
- "-w", "$wrta$,$wpl$%",
- "-c", "$crta$,$cpl$%",
- "-p", "$packets$",
- "-t", "$timeout$"
- ],
-
- macros = {
- wrta = 100,
- wpl = 5,
-
- crta = 200,
- cpl = 15,
-
- packets = 5,
- timeout = 0
- }
-}
-template Service "ping6" inherits "plugin-service" {
- check_command = [
- "$plugindir$/check_ping",
- "-6",
- "-H", "$address6$",
- "-w", "$wrta$,$wpl$%",
- "-c", "$crta$,$cpl$%",
- "-p", "$packets$",
- "-t", "$timeout$"
- ],
-
- macros = {
- wrta = 100,
- wpl = 5,
-
- crta = 200,
- cpl = 15,
-
- packets = 5,
- timeout = 0
- }
+template Service "ping4" {
+ check_command = "ping4"
}
-template Service "dummy" inherits "plugin-service" {
- check_command = [
- "$plugindir$/check_dummy",
- "$state$",
- "$text$"
- ],
-
- macros = {
- state = 0,
- text = "Check was successful."
- }
+template Service "ping6" {
+ check_command = "ping6"
}
-template Service "tcp" inherits "plugin-service" {
- check_command = [
- "$plugindir$/check_tcp",
- "-H", "$address$",
- "-p", "$port$"
- ]
+template Service "dummy" {
+ check_command = "dummy"
}
-template Service "udp" inherits "plugin-service" {
- check_command = [
- "$plugindir$/check_udp",
- "-H", "$address$",
- "-p", "$port$"
- ]
+template Service "tcp" {
+ check_command = "tcp"
}
-template Service "http_vhost" inherits "plugin-service" {
- check_command = [
- "$plugindir$/check_http",
- "-H", "$vhost$"
- ],
+template Service "udp" {
+ check_command = "udp"
}
-template Service "http_ip" inherits "plugin-service" {
- check_command = [
- "$plugindir$/check_http",
- "-I", "$address$"
- ]
+template Service "http_vhost" {
+ check_command = "http_vhost"
}
-template Service "https_vhost" inherits "plugin-service" {
- check_command = [
- "$plugindir$/check_http",
- "-H", "$vhost", "-S"
- ],
+template Service "http_ip" {
+ check_command = "http_ip"
}
-template Service "https_ip" inherits "plugin-service" {
- check_command = [
- "$plugindir$/check_http",
- "-I", "$address$", "-S"
- ],
+template Service "https_vhost" {
+ check_command = "https_vhost"
}
-template Service "smtp" inherits "plugin-service" {
- check_command = [
- "$plugindir$/check_smtp",
- "-H", "$address$"
- ]
+template Service "https_ip" {
+ check_command = "https_ip"
}
-template Service "ssmtp" inherits "plugin-service" {
- check_command = [
- "$plugindir$/check_ssmtp",
- "-H", "$address$",
- "-p", "$port$"
- ],
-
- macros += {
- port = 465
- }
+template Service "smtp" {
+ check_command = "smtp"
}
-template Service "ntp_time" inherits "plugin-service" {
- check_command = [
- "$plugindir$/check_ntp_time",
- "-H", "$address$"
- ]
+template Service "ssmtp" {
+ check_command = "ssmtp"
}
-template Service "ssh" inherits "plugin-service" {
- check_command = [
- "$plugindir$/check_ssh",
- "$address$"
- ]
+template Service "ntp_time" {
+ check_command = "ntp_time"
}
-template Service "disk" inherits "plugin-service" {
- check_command = [
- "$plugindir$/check_disk",
- "-w", "$wfree$",
- "-c", "$cfree$"
- ],
-
- macros += {
- wfree = "20%",
- cfree = "10%",
- }
+template Service "ssh" {
+ check_command = "ssh"
}
-template Service "users" inherits "plugin-service" {
- check_command = [
- "$plugindir$/check_users",
- "-w", "$wgreater$",
- "-c", "$cgreater$"
- ],
-
- macros += {
- wgreater = 20,
- cgreater = 50,
- }
+template Service "disk" {
+ check_command = "disk"
}
-template Service "processes" inherits "plugin-service" {
- check_command = [
- "$plugindir$/check_procs",
- "-w", "$wgreater$",
- "-c", "$cgreater$"
- ],
-
- macros += {
- wgreater = 250,
- cgreater = 400,
- }
+template Service "users" {
+ check_command = "users"
}
-
-template Service "load" inherits "plugin-service" {
- check_command = [
- "$plugindir$/check_load",
- "-w", "$wload1$,$wload5$,$wload15$",
- "-c", "$cload1$,$cload5$,$cload15$"
- ],
-
- macros = {
- wload1 = 5.0,
- wload5 = 4.0,
- wload15 = 3.0,
-
- cload1 = 10.0,
- cload5 = 6.0,
- cload15 = 4.0
- }
+template Service "processes" {
+ check_command = "processes"
}
-template Service "snmp" inherits "plugin-service" {
- check_command = [
- "$plugindir$/check_snmp",
- "-H", "$address$",
- "-o", "$oid$",
- "-C", "$community$"
- ],
+template Service "load" {
+ check_command = "load"
+}
- macros = {
- community = "public"
- }
+template Service "snmp" {
+ check_command = "snmp"
}
template Service "snmp-uptime" inherits "snmp" {
******************************************************************************/
#include "base/object.h"
+#include "base/value.h"
using namespace icinga;
return (m_Locked && m_LockOwner == boost::this_thread::get_id());
}
#endif /* _DEBUG */
+
+Object::SharedPtrHolder::operator Value(void) const
+{
+ return m_Object;
+}
namespace icinga
{
-class SharedPtrHolder;
+class Value;
/**
* Base class for all heap-allocated objects. At least one of its methods
return static_cast<shared_ptr<T> >(*this);
}
+ operator Value(void) const;
+
private:
Object::Ptr m_Object; /**< The object that belongs to this
holder instance */
libicinga_la_SOURCES = \
api.cpp \
api.h \
+ checkcommand.cpp \
+ checkcommand.h \
checkresultmessage.cpp \
checkresultmessage.h \
cib.cpp \
cib.h \
+ command.cpp \
+ command.h \
+ eventcommand.cpp \
+ eventcommand.h \
externalcommandprocessor.cpp \
externalcommandprocessor.h \
host.cpp \
macroresolver.h \
notification.cpp \
notification.h \
+ notificationcommand.cpp \
+ notificationcommand.h \
notificationrequestmessage.cpp \
notificationrequestmessage.h \
nullchecktask.cpp \
nullchecktask.h \
+ nulleventtask.cpp \
+ nulleventtask.h \
perfdatawriter.cpp \
perfdatawriter.h \
pluginchecktask.cpp \
pluginchecktask.h \
+ plugineventtask.cpp \
+ plugineventtask.h \
pluginnotificationtask.cpp \
pluginnotificationtask.h \
service.cpp \
service-check.cpp \
service-comment.cpp \
service-downtime.cpp \
+ service-event.cpp \
service-notification.cpp \
service.h \
servicegroup.cpp \
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+#include "icinga/checkcommand.h"
+#include "base/dynamictype.h"
+
+using namespace icinga;
+
+REGISTER_TYPE(CheckCommand);
+
+/**
+ * Constructor for the CheckCommand class.
+ *
+ * @param serializedUpdate A serialized dictionary containing attributes.
+ */
+CheckCommand::CheckCommand(const Dictionary::Ptr& serializedUpdate)
+ : Command(serializedUpdate)
+{ }
+
+CheckCommand::Ptr CheckCommand::GetByName(const String& name)
+{
+ DynamicObject::Ptr configObject = DynamicObject::GetObject("CheckCommand", name);
+
+ return dynamic_pointer_cast<CheckCommand>(configObject);
+}
+
+Dictionary::Ptr CheckCommand::Execute(const Service::Ptr& service)
+{
+ std::vector<Value> arguments;
+ arguments.push_back(service);
+ return InvokeMethod("execute", arguments);
+}
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+#ifndef CHECKCOMMAND_H
+#define CHECKCOMMAND_H
+
+#include "icinga/command.h"
+#include "icinga/service.h"
+
+namespace icinga
+{
+
+/**
+ * A command.
+ *
+ * @ingroup base
+ */
+class I2_BASE_API CheckCommand : public Command
+{
+public:
+ typedef shared_ptr<CheckCommand> Ptr;
+ typedef weak_ptr<CheckCommand> WeakPtr;
+
+ explicit CheckCommand(const Dictionary::Ptr& serializedUpdate);
+
+ static CheckCommand::Ptr GetByName(const String& name);
+
+ virtual Dictionary::Ptr Execute(const Service::Ptr& service);
+};
+
+}
+
+#endif /* CHECKCOMMAND_H */
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+#include "icinga/command.h"
+
+using namespace icinga;
+
+/**
+ * Constructor for the Command class.
+ *
+ * @param serializedUpdate A serialized dictionary containing attributes.
+ */
+Command::Command(const Dictionary::Ptr& serializedUpdate)
+ : DynamicObject(serializedUpdate)
+{
+ RegisterAttribute("macros", Attribute_Config, &m_Macros);
+ RegisterAttribute("export_macros", Attribute_Config, &m_ExportMacros);
+}
+
+Dictionary::Ptr Command::GetMacros(void) const
+{
+ return m_Macros;
+}
+
+Array::Ptr Command::GetExportMacros(void) const
+{
+ return m_ExportMacros;
+}
+
+bool Command::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const
+{
+ Dictionary::Ptr macros = GetMacros();
+
+ if (macros && macros->Contains(macro)) {
+ *result = macros->Get(macro);
+ return true;
+ }
+
+ return false;
+}
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+#ifndef COMMAND_H
+#define COMMAND_H
+
+#include "icinga/macroresolver.h"
+#include "base/i2-base.h"
+#include "base/array.h"
+#include "base/dynamicobject.h"
+#include "base/logger_fwd.h"
+#include <set>
+
+namespace icinga
+{
+
+/**
+ * A command.
+ *
+ * @ingroup base
+ */
+class I2_BASE_API Command : public DynamicObject, public MacroResolver
+{
+public:
+ typedef shared_ptr<Command> Ptr;
+ typedef weak_ptr<Command> WeakPtr;
+
+ explicit Command(const Dictionary::Ptr& serializedUpdate);
+
+ //virtual Dictionary::Ptr Execute(const Object::Ptr& context) = 0;
+
+ Dictionary::Ptr GetMacros(void) const;
+ Array::Ptr GetExportMacros(void) const;
+ virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
+
+private:
+ Attribute<Dictionary::Ptr> m_Macros;
+ Attribute<Array::Ptr> m_ExportMacros;
+};
+
+}
+
+#endif /* COMMAND_H */
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+#include "icinga/eventcommand.h"
+#include "base/dynamictype.h"
+
+using namespace icinga;
+
+REGISTER_TYPE(EventCommand);
+
+/**
+ * Constructor for the EventCommand class.
+ *
+ * @param serializedUpdate A serialized dictionary containing attributes.
+ */
+EventCommand::EventCommand(const Dictionary::Ptr& serializedUpdate)
+ : Command(serializedUpdate)
+{ }
+
+EventCommand::Ptr EventCommand::GetByName(const String& name)
+{
+ DynamicObject::Ptr configObject = DynamicObject::GetObject("EventCommand", name);
+
+ return dynamic_pointer_cast<EventCommand>(configObject);
+}
+
+void EventCommand::Execute(const Service::Ptr& service)
+{
+ std::vector<Value> arguments;
+ arguments.push_back(service);
+ InvokeMethod("execute", arguments);
+}
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+#ifndef EVENTCOMMAND_H
+#define EVENTCOMMAND_H
+
+#include "icinga/command.h"
+#include "icinga/service.h"
+
+namespace icinga
+{
+
+/**
+ * An event handler command.
+ *
+ * @ingroup base
+ */
+class I2_BASE_API EventCommand : public Command
+{
+public:
+ typedef shared_ptr<EventCommand> Ptr;
+ typedef weak_ptr<EventCommand> WeakPtr;
+
+ explicit EventCommand(const Dictionary::Ptr& serializedUpdate);
+
+ static EventCommand::Ptr GetByName(const String& name);
+
+ virtual void Execute(const Service::Ptr& context);
+};
+
+}
+
+#endif /* EVENTCOMMAND_H */
%attribute string "*"
},
- %attribute array "export_macros",
-
%attribute name(TimePeriod) "check_period",
%attribute number "check_interval",
%attribute number "retry_interval",
%attribute string "*"
},
- %attribute array "export_macros" {
- %attribute string "*"
- },
-
%attribute array "users" {
%attribute name(User) "*"
},
%attribute string "*"
},
- %attribute array "export_macros" {
- %attribute string "*"
- },
-
%attribute array "users" {
%attribute name(User) "*"
},
%attribute string "*"
},
- %attribute array "export_macros" {
- %attribute string "*"
- },
-
%attribute array "servicegroups" {
%attribute name(ServiceGroup) "*"
},
%attribute string "*"
},
- %attribute array "export_macros" {
- %attribute string "*"
- },
-
- %attribute array "check_command" {
- %attribute string "*"
- },
- %attribute string "check_command",
+ %require "check_command",
+ %attribute name(CheckCommand) "check_command",
%attribute number "max_check_attempts",
%attribute name(TimePeriod) "check_period",
%attribute number "check_interval",
%attribute number "retry_interval",
+ %attribute name(EventCommand) "event_command",
+
%attribute number "notification_interval",
%attribute name(TimePeriod) "notification_period",
%attribute string "*"
},
- %require "methods",
- %attribute dictionary "methods" {
- %require "check",
- %attribute string "check"
- },
-
%attribute dictionary "notifications" {
%attribute dictionary "*" {
%attribute array "templates" {
%attribute string "*"
},
- %attribute array "export_macros" {
- %attribute string "*"
- },
-
%attribute array "users" {
%attribute name(User) "*"
},
}
type Notification {
- %require "methods",
- %attribute dictionary "methods" {
- %require "notify",
- %attribute string "notify"
- },
-
%require "host_name",
%attribute string "host_name",
%attribute string "service",
%attribute string "*"
},
- %attribute array "export_macros" {
- %attribute string "*"
- },
-
%attribute array "users" {
%attribute name(User) "*"
},
%attribute number "end",
},
- %attribute array "notification_command" {
- %attribute string "*"
- },
- %attribute string "notification_command",
+ %attribute name(NotificationCommand) "notification_command",
%attribute number "notification_interval",
%attribute name(TimePeriod) "notification_period"
%attribute string "format_template",
%attribute number "rotation_interval"
}
+
+type Command {
+ %require "methods",
+ %attribute dictionary "methods" {
+ %require "execute",
+ %attribute string "execute"
+ },
+
+/* %if (methods.execute == "PluginNotification" || methods.execute == "PluginCheck" || methods.execute == "PluginEvent") { */
+// %require "command",
+ %attribute string "command",
+ %attribute array "command" {
+ %attribute string "*"
+ },
+ %attribute array "export_macros" {
+ %attribute string "*"
+ },
+ %attribute dictionary "macros" {
+ %attribute string "*"
+ }
+/* } */
+}
+
+type CheckCommand inherits Command {
+
+}
+
+type NotificationCommand inherits Command {
+
+}
+
+type EventCommand inherits Command {
+
+}
\ No newline at end of file
Dictionary::Ptr ranges = tp->Get("ranges");
-
-
if (ranges) {
for (int i = 0; i <= (end - begin) / (24 * 60 * 60); i++) {
time_t refts = begin + i * 24 * 60 * 60;
******************************************************************************/
#include "icinga/notification.h"
+#include "icinga/notificationcommand.h"
#include "icinga/macroprocessor.h"
#include "icinga/service.h"
#include "base/dynamictype.h"
return host->GetServiceByShortName(m_Service);
}
-Value Notification::GetNotificationCommand(void) const
+NotificationCommand::Ptr Notification::GetNotificationCommand(void) const
{
- return m_NotificationCommand;
+ return NotificationCommand::GetByName(m_NotificationCommand);
}
Dictionary::Ptr Notification::GetMacros(void) const
}
BOOST_FOREACH(const User::Ptr& user, allUsers) {
- Log(LogDebug, "icinga", "Sending notification for user " + user->GetName());
+ Log(LogDebug, "icinga", "Sending notification for user '" + user->GetName() + "'");
Utility::QueueAsyncCallback(boost::bind(&Notification::ExecuteNotificationHelper, this, type, user, cr, force));
}
}
}
}
- Notification::Ptr self = GetSelf();
-
- std::vector<Value> arguments;
- arguments.push_back(self);
- arguments.push_back(user);
- arguments.push_back(cr);
- arguments.push_back(type);
-
try {
- InvokeMethod("notify", arguments);
+ GetNotificationCommand()->Execute(GetSelf(), user, cr, type);
Log(LogInformation, "icinga", "Completed sending notification for service '" + GetService()->GetName() + "'");
} catch (const std::exception& ex) {
};
class Service;
+class NotificationCommand;
/**
* An Icinga notification specification.
static Notification::Ptr GetByName(const String& name);
shared_ptr<Service> GetService(void) const;
- Value GetNotificationCommand(void) const;
+ shared_ptr<NotificationCommand> GetNotificationCommand(void) const;
double GetNotificationInterval(void) const;
TimePeriod::Ptr GetNotificationPeriod(void) const;
Dictionary::Ptr GetMacros(void) const;
void OnAttributeChanged(const String& name);
private:
- Attribute<Value> m_NotificationCommand;
+ Attribute<String> m_NotificationCommand;
Attribute<double> m_NotificationInterval;
Attribute<String> m_NotificationPeriod;
Attribute<double> m_LastNotification;
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+#include "icinga/notificationcommand.h"
+#include "base/dynamictype.h"
+
+using namespace icinga;
+
+REGISTER_TYPE(NotificationCommand);
+
+/**
+ * Constructor for the NotificationCommand class.
+ *
+ * @param serializedUpdate A serialized dictionary containing attributes.
+ */
+NotificationCommand::NotificationCommand(const Dictionary::Ptr& serializedUpdate)
+ : Command(serializedUpdate)
+{ }
+
+NotificationCommand::Ptr NotificationCommand::GetByName(const String& name)
+{
+ DynamicObject::Ptr configObject = DynamicObject::GetObject("NotificationCommand", name);
+
+ return dynamic_pointer_cast<NotificationCommand>(configObject);
+}
+
+Dictionary::Ptr NotificationCommand::Execute(const Notification::Ptr& notification,
+ const User::Ptr& user, const Dictionary::Ptr& cr, const NotificationType& type)
+{
+ std::vector<Value> arguments;
+ arguments.push_back(notification);
+ arguments.push_back(user);
+ arguments.push_back(cr);
+ arguments.push_back(type);
+ return InvokeMethod("execute", arguments);
+}
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+#ifndef NOTIFICATIONCOMMAND_H
+#define NOTIFICATIONCOMMAND_H
+
+#include "icinga/command.h"
+#include "icinga/notification.h"
+
+namespace icinga
+{
+
+class Notification;
+
+/**
+ * A notification command.
+ *
+ * @ingroup base
+ */
+class I2_BASE_API NotificationCommand : public Command
+{
+public:
+ typedef shared_ptr<NotificationCommand> Ptr;
+ typedef weak_ptr<NotificationCommand> WeakPtr;
+
+ explicit NotificationCommand(const Dictionary::Ptr& serializedUpdate);
+
+ static NotificationCommand::Ptr GetByName(const String& name);
+
+ virtual Dictionary::Ptr Execute(const shared_ptr<Notification>& notification,
+ const User::Ptr& user, const Dictionary::Ptr& cr, const NotificationType& type);
+};
+
+}
+
+#endif /* NOTIFICATIONCOMMAND_H */
#include "icinga/nullchecktask.h"
#include "base/scriptfunction.h"
+#include "base/logger_fwd.h"
#include <boost/smart_ptr/make_shared.hpp>
using namespace icinga;
REGISTER_SCRIPTFUNCTION(NullCheck, &NullCheckTask::ScriptFunc);
-Dictionary::Ptr NullCheckTask::ScriptFunc(const Service::Ptr&)
+Dictionary::Ptr NullCheckTask::ScriptFunc(const Service::Ptr& service)
{
Dictionary::Ptr cr = boost::make_shared<Dictionary>();
cr->Set("state", StateUnknown);
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+#include "icinga/nulleventtask.h"
+#include "base/scriptfunction.h"
+#include "base/logger_fwd.h"
+#include <boost/smart_ptr/make_shared.hpp>
+
+using namespace icinga;
+
+REGISTER_SCRIPTFUNCTION(NullEvent, &NullEventTask::ScriptFunc);
+
+void NullEventTask::ScriptFunc(const Service::Ptr& service)
+{
+}
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+#ifndef NULLEVENTTASK_H
+#define NULLEVENTTASK_H
+
+#include "icinga/i2-icinga.h"
+#include "icinga/service.h"
+#include "base/dictionary.h"
+
+namespace icinga
+{
+
+/**
+ * Test class for additional event handler types. Implements the "null" event handler type.
+ *
+ * @ingroup icinga
+ */
+class I2_ICINGA_API NullEventTask
+{
+public:
+ static void ScriptFunc(const Service::Ptr& service);
+
+private:
+ NullEventTask(void);
+};
+
+}
+
+#endif /* NULLEVENTTASK_H */
******************************************************************************/
#include "icinga/pluginchecktask.h"
+#include "icinga/checkcommand.h"
#include "icinga/macroprocessor.h"
#include "icinga/icingaapplication.h"
#include "base/dynamictype.h"
Dictionary::Ptr PluginCheckTask::ScriptFunc(const Service::Ptr& service)
{
- Value raw_command = service->GetCheckCommand();
+ CheckCommand::Ptr commandObj = service->GetCheckCommand();
+ Value raw_command = commandObj->Get("command");
std::vector<MacroResolver::Ptr> resolvers;
+ resolvers.push_back(commandObj);
resolvers.push_back(service);
resolvers.push_back(service->GetHost());
resolvers.push_back(IcingaApplication::GetInstance());
Dictionary::Ptr envMacros = boost::make_shared<Dictionary>();
- Array::Ptr export_macros = service->GetExportMacros();
+ Array::Ptr export_macros = commandObj->GetExportMacros();
if (export_macros) {
BOOST_FOREACH(const String& macro, export_macros) {
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+#include "icinga/plugineventtask.h"
+#include "icinga/eventcommand.h"
+#include "icinga/macroprocessor.h"
+#include "icinga/icingaapplication.h"
+#include "base/dynamictype.h"
+#include "base/logger_fwd.h"
+#include "base/scriptfunction.h"
+#include "base/utility.h"
+#include "base/process.h"
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
+
+using namespace icinga;
+
+REGISTER_SCRIPTFUNCTION(PluginEvent, &PluginEventTask::ScriptFunc);
+
+void PluginEventTask::ScriptFunc(const Service::Ptr& service)
+{
+ EventCommand::Ptr commandObj = service->GetEventCommand();
+ Value raw_command = commandObj->Get("command");
+
+ std::vector<MacroResolver::Ptr> resolvers;
+ resolvers.push_back(commandObj);
+ resolvers.push_back(service);
+ resolvers.push_back(service->GetHost());
+ resolvers.push_back(IcingaApplication::GetInstance());
+
+ Value command = MacroProcessor::ResolveMacros(raw_command, resolvers, Dictionary::Ptr(), Utility::EscapeShellCmd);
+
+ Dictionary::Ptr envMacros = boost::make_shared<Dictionary>();
+
+ Array::Ptr export_macros = commandObj->GetExportMacros();
+
+ if (export_macros) {
+ BOOST_FOREACH(const String& macro, export_macros) {
+ String value;
+
+ if (!MacroProcessor::ResolveMacro(macro, resolvers, Dictionary::Ptr(), &value)) {
+ Log(LogWarning, "icinga", "export_macros for command '" + commandObj->GetName() + "' refers to unknown macro '" + macro + "'");
+ continue;
+ }
+
+ envMacros->Set(macro, value);
+ }
+ }
+
+ Process::Ptr process = boost::make_shared<Process>(Process::SplitCommand(command), envMacros);
+
+ process->Run();
+}
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+#ifndef PLUGINEVENTTASK_H
+#define PLUGINEVENTTASK_H
+
+#include "icinga/i2-icinga.h"
+#include "icinga/service.h"
+
+namespace icinga
+{
+
+/**
+ * Implements event handlers based on external plugins.
+ *
+ * @ingroup icinga
+ */
+class I2_ICINGA_API PluginEventTask
+{
+public:
+ static void ScriptFunc(const Service::Ptr& service);
+
+private:
+ PluginEventTask(void);
+};
+
+}
+
+#endif /* PLUGINEVENTTASK_H */
#include "icinga/pluginnotificationtask.h"
#include "icinga/notification.h"
+#include "icinga/notificationcommand.h"
#include "icinga/service.h"
#include "icinga/macroprocessor.h"
#include "icinga/icingaapplication.h"
void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, const User::Ptr& user, const Dictionary::Ptr& cr, int itype)
{
+ NotificationCommand::Ptr commandObj = notification->GetNotificationCommand();
+
NotificationType type = static_cast<NotificationType>(itype);
Service::Ptr service = notification->GetService();
- Value raw_command = notification->GetNotificationCommand();
+ Value raw_command = commandObj->Get("command");
StaticMacroResolver::Ptr notificationMacroResolver = boost::make_shared<StaticMacroResolver>();
notificationMacroResolver->Add("NOTIFICATIONTYPE", Notification::NotificationTypeToString(type));
std::vector<MacroResolver::Ptr> resolvers;
resolvers.push_back(user);
resolvers.push_back(notificationMacroResolver);
+ resolvers.push_back(commandObj);
resolvers.push_back(notification);
resolvers.push_back(service);
resolvers.push_back(service->GetHost());
******************************************************************************/
#include "icinga/service.h"
+#include "icinga/checkcommand.h"
#include "icinga/icingaapplication.h"
#include "icinga/checkresultmessage.h"
#include "icinga/cib.h"
boost::signals2::signal<void (const Service::Ptr&)> Service::OnCheckerChanged;
boost::signals2::signal<void (const Service::Ptr&)> Service::OnNextCheckChanged;
-Value Service::GetCheckCommand(void) const
+CheckCommand::Ptr Service::GetCheckCommand(void) const
{
- return m_CheckCommand;
+ return CheckCommand::GetByName(m_CheckCommand);
}
long Service::GetMaxCheckAttempts(void) const
int state = cr->Get("state");
SetState(static_cast<ServiceState>(state));
+ bool call_eventhandler = false;
+
if (old_state != GetState()) {
SetLastStateChange(now);
service->SetNextCheck(Utility::GetTime());
}
}
+
+ call_eventhandler = true;
}
bool hardChange = (GetStateType() == StateTypeHard && old_stateType == StateTypeSoft);
EndpointManager::GetInstance()->SendMulticastMessage(rm);
+ if (call_eventhandler)
+ ExecuteEventHandler();
+
if (send_downtime_notification)
RequestNotifications(in_downtime ? NotificationDowntimeStart : NotificationDowntimeEnd, cr);
Service::Ptr self = GetSelf();
- std::vector<Value> arguments;
- arguments.push_back(self);
-
Dictionary::Ptr result;
try {
- result = InvokeMethod("check", arguments);
+ result = GetCheckCommand()->Execute(GetSelf());
} catch (const std::exception& ex) {
std::ostringstream msgbuf;
msgbuf << "Exception occured during check for service '"
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+#include "icinga/service.h"
+#include "icinga/eventcommand.h"
+
+using namespace icinga;
+
+EventCommand::Ptr Service::GetEventCommand(void) const
+{
+ return EventCommand::GetByName(m_EventCommand);
+}
+
+void Service::ExecuteEventHandler(void)
+{
+ EventCommand::Ptr ec = GetEventCommand();
+
+ if (!ec)
+ return;
+
+ Log(LogDebug, "icinga", "Executing event handler for service '" + GetName() + "'");
+ ec->Execute(GetSelf());
+}
\ No newline at end of file
#include "icinga/service.h"
#include "icinga/servicegroup.h"
+#include "icinga/checkcommand.h"
#include "icinga/icingaapplication.h"
#include "icinga/macroprocessor.h"
#include "config/configitembuilder.h"
RegisterAttribute("display_name", Attribute_Config, &m_DisplayName);
RegisterAttribute("macros", Attribute_Config, &m_Macros);
- RegisterAttribute("export_macros", Attribute_Config, &m_ExportMacros);
RegisterAttribute("hostdependencies", Attribute_Config, &m_HostDependencies);
RegisterAttribute("servicedependencies", Attribute_Config, &m_ServiceDependencies);
RegisterAttribute("servicegroups", Attribute_Config, &m_ServiceGroups);
RegisterAttribute("retry_interval", Attribute_Config, &m_RetryInterval);
RegisterAttribute("checkers", Attribute_Config, &m_Checkers);
+ RegisterAttribute("event_command", Attribute_Config, &m_EventCommand);
+
RegisterAttribute("next_check", Attribute_Replicated, &m_NextCheck);
RegisterAttribute("current_checker", Attribute_Replicated, &m_CurrentChecker);
RegisterAttribute("check_attempt", Attribute_Replicated, &m_CheckAttempt);
return m_Macros;
}
-Array::Ptr Service::GetExportMacros(void) const
-{
- return m_ExportMacros;
-}
-
Array::Ptr Service::GetHostDependencies(void) const
{
return m_HostDependencies;
*result = GetDisplayName();
return true;
} else if (macro == "SERVICECHECKCOMMAND") {
- *result = "check_i2";
+ CheckCommand::Ptr commandObj = GetCheckCommand();
+
+ if (commandObj)
+ *result = commandObj->GetName();
+ else
+ *result = "";
+
return true;
}
CommentAcknowledgement = 4
};
-class CheckResultMessage;
+class CheckCommand;
+class EventCommand;
/**
* An Icinga service.
String GetDisplayName(void) const;
Host::Ptr GetHost(void) const;
Dictionary::Ptr GetMacros(void) const;
- Array::Ptr GetExportMacros(void) const;
Array::Ptr GetHostDependencies(void) const;
Array::Ptr GetServiceDependencies(void) const;
Array::Ptr GetGroups(void) const;
/* Checks */
Array::Ptr GetCheckers(void) const;
- Value GetCheckCommand(void) const;
+ shared_ptr<CheckCommand> GetCheckCommand(void) const;
long GetMaxCheckAttempts(void) const;
TimePeriod::Ptr GetCheckPeriod(void) const;
double GetCheckInterval(void) const;
void UpdateSlaveNotifications(void);
+ /* Event Handler */
+ void ExecuteEventHandler(void);
+ shared_ptr<EventCommand> GetEventCommand(void) const;
+
protected:
virtual void OnRegistrationCompleted(void);
virtual void OnAttributeChanged(const String& name);
Attribute<String> m_DisplayName;
Attribute<Dictionary::Ptr> m_Macros;
- Attribute<Array::Ptr> m_ExportMacros;
Attribute<Array::Ptr> m_HostDependencies;
Attribute<Array::Ptr> m_ServiceDependencies;
Attribute<Array::Ptr> m_ServiceGroups;
Attribute<String> m_HostName;
/* Checks */
- Attribute<Value> m_CheckCommand;
+ Attribute<String> m_CheckCommand;
Attribute<long> m_MaxCheckAttempts;
Attribute<String> m_CheckPeriod;
Attribute<double> m_CheckInterval;
Attribute<bool> m_ForceNextNotification;
static void RefreshNotificationsCache(void);
+
+ /* Event Handler */
+ Attribute<String> m_EventCommand;
};
}