[icinga-checkins] icinga.org: icinga2/master: Add the "exception" check command

git at icinga.org git at icinga.org
Mon Aug 8 12:51:25 CEST 2016


Module: icinga2
Branch: master
Commit: 1cd8a25ab2cb1bf5a093a7df262a019dc9254084
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=1cd8a25ab2cb1bf5a093a7df262a019dc9254084

Author: Gunnar Beutner <gunnar at beutner.name>
Date:   Mon Aug  8 12:51:20 2016 +0200

Add the "exception" check command

refs #10075

---

 doc/7-icinga-template-library.md   |    6 +++++
 itl/command-icinga.conf            |    4 ++++
 lib/methods/CMakeLists.txt         |    2 +-
 lib/methods/exceptionchecktask.cpp |   41 ++++++++++++++++++++++++++++++++
 lib/methods/exceptionchecktask.hpp |   46 ++++++++++++++++++++++++++++++++++++
 lib/methods/methods-itl.conf       |    4 ++++
 6 files changed, 102 insertions(+), 1 deletion(-)

diff --git a/doc/7-icinga-template-library.md b/doc/7-icinga-template-library.md
index cc0e519..c491b6e 100644
--- a/doc/7-icinga-template-library.md
+++ b/doc/7-icinga-template-library.md
@@ -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
 
diff --git a/itl/command-icinga.conf b/itl/command-icinga.conf
index 5b9e3b8..9070f9f 100644
--- a/itl/command-icinga.conf
+++ b/itl/command-icinga.conf
@@ -34,3 +34,7 @@ object CheckCommand "cluster-zone" {
 object CheckCommand "random" {
 	import "random-check-command"
 }
+
+object CheckCommand "exception" {
+	import "exception-check-command"
+}
diff --git a/lib/methods/CMakeLists.txt b/lib/methods/CMakeLists.txt
index 64aa534..6666ab4 100644
--- a/lib/methods/CMakeLists.txt
+++ b/lib/methods/CMakeLists.txt
@@ -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
index 0000000..f9a3516
--- /dev/null
+++ b/lib/methods/exceptionchecktask.cpp
@@ -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
index 0000000..a677e4c
--- /dev/null
+++ b/lib/methods/exceptionchecktask.hpp
@@ -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 */
diff --git a/lib/methods/methods-itl.conf b/lib/methods/methods-itl.conf
index 90039f6..3255be3 100644
--- a/lib/methods/methods-itl.conf
+++ b/lib/methods/methods-itl.conf
@@ -48,3 +48,7 @@ template EventCommand "plugin-event-command" {
 template CheckCommand "random-check-command" {
 	execute = RandomCheck
 }
+
+template CheckCommand "exception-check-command" {
+	execute = ExceptionCheck
+}



More information about the icinga-checkins mailing list