Bring aboard "status-notifier-cmd" configuration option class.
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Tue, 13 Sep 2011 01:54:53 +0000 (22:54 -0300)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Tue, 13 Sep 2011 01:54:53 +0000 (22:54 -0300)
src/config/option/statusnotifiercmdoption.cpp [new file with mode: 0644]
src/config/option/statusnotifiercmdoption.h [new file with mode: 0644]

diff --git a/src/config/option/statusnotifiercmdoption.cpp b/src/config/option/statusnotifiercmdoption.cpp
new file mode 100644 (file)
index 0000000..78070c8
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ The software in this package is distributed under the GNU General
+ Public License version 2 (with a special exception described below).
+
+ A copy of GNU General Public License (GPL) is included in this distribution,
+ in the file COPYING.GPL.
+
+ As a special exception, if other files instantiate templates or use macros
+ or inline functions from this file, or you compile this file and link it
+ with other works to produce a work based on this file, this file
+ does not by itself cause the resulting work to be covered
+ by the GNU General Public License.
+
+ However the source code for this file must still be made available
+ in accordance with section (3) of the GNU General Public License.
+
+ This exception does not invalidate any other reasons why a work based
+ on this file might be covered by the GNU General Public License.
+ */
+
+#include "config/option/statusnotifiercmdoption.h"
+
+#include <logfunc.hpp>
+
+using namespace std;
+using boost::program_options::value;
+using boost::program_options::variables_map;
+using I2n::Logger::GlobalLogger;
+
+//-----------------------------------------------------------------------------
+// StatusNotifierCmdOption
+//-----------------------------------------------------------------------------
+
+StatusNotifierCmdOption::StatusNotifierCmdOption() :
+    ConfigurationOption(
+        "status-notifier-cmd",
+        value<string>(),
+        "The command to execute to alert about host status."
+    )
+{
+}
+
+StatusNotifierCmdOption::~StatusNotifierCmdOption()
+{
+}
+
+bool StatusNotifierCmdOption::validate( const variables_map& vm ) const
+{
+    bool is_valid = ( vm.count( get_command_string() ) > 0 );
+
+    return is_valid;
+}
+
+bool StatusNotifierCmdOption::parse(
+        const variables_map& vm,
+        Configuration *configuration
+) const
+{
+    // status-notifier-cmd
+    if ( vm.count( get_command_string() ) > 0 )
+    {
+        string status_notifier_cmd = vm[ get_command_string() ].as<string>();
+        configuration->set_status_notifier_cmd( status_notifier_cmd );
+
+        GlobalLogger.info() << get_command_string() << "="
+                << status_notifier_cmd << endl;
+
+        return true;
+    }
+
+    return false;
+}
diff --git a/src/config/option/statusnotifiercmdoption.h b/src/config/option/statusnotifiercmdoption.h
new file mode 100644 (file)
index 0000000..c4245bc
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ The software in this package is distributed under the GNU General
+ Public License version 2 (with a special exception described below).
+
+ A copy of GNU General Public License (GPL) is included in this distribution,
+ in the file COPYING.GPL.
+
+ As a special exception, if other files instantiate templates or use macros
+ or inline functions from this file, or you compile this file and link it
+ with other works to produce a work based on this file, this file
+ does not by itself cause the resulting work to be covered
+ by the GNU General Public License.
+
+ However the source code for this file must still be made available
+ in accordance with section (3) of the GNU General Public License.
+
+ This exception does not invalidate any other reasons why a work based
+ on this file might be covered by the GNU General Public License.
+ */
+
+#ifndef STATUS_NOTIFIER_CMD_OPTION_H
+#define STATUS_NOTIFIER_CMD_OPTION_H
+
+#include <boost/program_options.hpp>
+
+#include "config/option/configurationoption.h"
+
+//-----------------------------------------------------------------------------
+// StatusNotifierCmdOption
+//-----------------------------------------------------------------------------
+
+/**
+ * @brief This class represents the "status-notifier-cmd" configuration option.
+ */
+class StatusNotifierCmdOption : public ConfigurationOption
+{
+public:
+    StatusNotifierCmdOption();
+    virtual ~StatusNotifierCmdOption();
+
+    virtual bool validate(
+            const boost::program_options::variables_map &vm
+    ) const;
+
+    virtual bool parse(
+            const boost::program_options::variables_map &vm,
+            Configuration *configuration
+    ) const;
+
+};
+
+#endif // STATUS_NOTIFIER_CMD_OPTION_H