]> granicus.if.org Git - icinga2/commitdiff
Add the "exception" check command
authorGunnar Beutner <gunnar@beutner.name>
Mon, 8 Aug 2016 10:51:20 +0000 (12:51 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Mon, 8 Aug 2016 10:51:20 +0000 (12:51 +0200)
refs #10075

doc/7-icinga-template-library.md
itl/command-icinga.conf
lib/methods/CMakeLists.txt
lib/methods/exceptionchecktask.cpp [new file with mode: 0644]
lib/methods/exceptionchecktask.hpp [new file with mode: 0644]
lib/methods/methods-itl.conf

index cc0e519ef653cad5b4c58a863fb0f5cfe05f6c98..c491b6e73f6079d973219e9343639e9b28c55382 100644 (file)
@@ -79,6 +79,12 @@ and adds the check source to the check output.
 For test and demo purposes only. The `random` check command does not support
 any vars.
 
+### <a id="itl-exception"></a> exception
+
+Check command for the built-in `exception` check. This check throws an exception.
+
+For test and demo purposes only. The `exception` check command does not support
+any vars.
 
 # <a id="plugin-check-commands"></a> Plugin Check Commands
 
index 5b9e3b86f2372b11213ac6f1728f0e7649d9a53c..9070f9f36a05fcd8b441aa0eea3fba95edbaa6c1 100644 (file)
@@ -34,3 +34,7 @@ object CheckCommand "cluster-zone" {
 object CheckCommand "random" {
        import "random-check-command"
 }
+
+object CheckCommand "exception" {
+       import "exception-check-command"
+}
index 64aa5343a1048720b88499dcd4fbaa961c83eb7e..6666ab4749d1e7496b78c9aaaebf02bc5ee27898 100644 (file)
@@ -24,7 +24,7 @@ else()
 endif()
 
 set(methods_SOURCES
-  clusterchecktask.cpp clusterzonechecktask.cpp
+  clusterchecktask.cpp clusterzonechecktask.cpp exceptionchecktask.cpp
   icingachecktask.cpp methods-itl.cpp nullchecktask.cpp nulleventtask.cpp
   pluginchecktask.cpp plugineventtask.cpp pluginnotificationtask.cpp
   randomchecktask.cpp timeperiodtask.cpp ${WindowsSources}
diff --git a/lib/methods/exceptionchecktask.cpp b/lib/methods/exceptionchecktask.cpp
new file mode 100644 (file)
index 0000000..f9a3516
--- /dev/null
@@ -0,0 +1,41 @@
+/******************************************************************************
+ * Icinga 2                                                                   *
+ * Copyright (C) 2012-2016 Icinga Development Team (https://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 _WIN32
+#      include <stdlib.h>
+#endif /* _WIN32 */
+#include "methods/exceptionchecktask.hpp"
+#include "base/utility.hpp"
+#include "base/convert.hpp"
+#include "base/function.hpp"
+#include "base/logger.hpp"
+#include "base/exception.hpp"
+
+using namespace icinga;
+
+REGISTER_SCRIPTFUNCTION(ExceptionCheck, &ExceptionCheckTask::ScriptFunc);
+
+void ExceptionCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr,
+    const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
+{
+       if (resolvedMacros && !useResolvedMacros)
+               return;
+
+       BOOST_THROW_EXCEPTION(ScriptError("Test") << boost::errinfo_api_function("Test"));
+}
diff --git a/lib/methods/exceptionchecktask.hpp b/lib/methods/exceptionchecktask.hpp
new file mode 100644 (file)
index 0000000..a677e4c
--- /dev/null
@@ -0,0 +1,46 @@
+/******************************************************************************
+ * Icinga 2                                                                   *
+ * Copyright (C) 2012-2016 Icinga Development Team (https://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 EXCEPTIONCHECKTASK_H
+#define EXCEPTIONCHECKTASK_H
+
+#include "icinga/service.hpp"
+#include "base/dictionary.hpp"
+
+namespace icinga
+{
+
+/**
+ * Test class for additional check types. Implements the "exception" check type.
+ *
+ * @ingroup methods
+ */
+class ExceptionCheckTask
+{
+public:
+       static void ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr,
+           const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros);
+
+private:
+       ExceptionCheckTask(void);
+};
+
+}
+
+#endif /* EXCEPTIONCHECKTASK_H */
index 90039f6a5fb1bf0bddc4960be38f37f2ed8e05e0..3255be31381f1c72471dda7c8c885976b1cf53a2 100644 (file)
@@ -48,3 +48,7 @@ template EventCommand "plugin-event-command" {
 template CheckCommand "random-check-command" {
        execute = RandomCheck
 }
+
+template CheckCommand "exception-check-command" {
+       execute = ExceptionCheck
+}