[omd-commits] OMD Git: omd: pnp4nagios: new hook named "npcd" to switch to Bulk Mode with NPCD

git version control git at mathias-kettner.de
Thu Jul 12 08:41:06 CEST 2012


Module:   omd
Branch:   master
Commit:   40b97d35c90c034dee517254bb4accb36b5d4b31
URL:      http://omdistro.org/projects/omd/repository/revisions/40b97d35c90c034dee517254bb4accb36b5d4b31

Author:   Joerg Linge <pitchfork at pnp4nagios.org>
Date:     Thu Jul 12 08:35:19 2012 +0200
Commiter: Joerg Linge <pitchfork at pnp4nagios.org>
Date:     Thu Jul 12 08:35:19 2012 +0200

pnp4nagios: new hook named "npcd" to switch to Bulk Mode with NPCD

---

 packages/pnp4nagios/PNP4NAGIOS.hook                |   12 +++++-
 packages/pnp4nagios/skel/etc/init.d/npcd           |    2 +-
 .../skel/etc/nagios/conf.d/pnp4nagios.cfg          |   10 +++++
 .../pnp4nagios/skel/etc/pnp4nagios/nagios_npcd.cfg |   22 ++++++++++
 t/20-package_pnp4nagios.t                          |   42 +++++++++++++++++++-
 5 files changed, 85 insertions(+), 3 deletions(-)

diff --git a/packages/pnp4nagios/PNP4NAGIOS.hook b/packages/pnp4nagios/PNP4NAGIOS.hook
index 41f0093..31b61dd 100755
--- a/packages/pnp4nagios/PNP4NAGIOS.hook
+++ b/packages/pnp4nagios/PNP4NAGIOS.hook
@@ -14,7 +14,8 @@ case "$1" in
        echo "on"
    ;;
    choices)
-       echo "on: enable"
+       echo "on: enable bulk mode with npcdmod and npcd"
+       echo "npcd: enable bulk mode with npcd"
        echo "gearman: enable gearman worker"
        echo "off: disable"
    ;;
@@ -44,6 +45,15 @@ case "$1" in
            if [ -s $OMD_ROOT/etc/mod-gearman/perfdata.conf ]; then
                sed -i -e 's/^perfdata=.*$/perfdata=yes/' $OMD_ROOT/etc/mod-gearman/perfdata.conf
            fi
+       elif [ "$2" == "npcd" ]
+       then
+           if [ -e $OMD_ROOT/etc/nagios/nagios.d ] ; then
+               ln -sfn ../../pnp4nagios/nagios_npcd.cfg $OMD_ROOT/etc/nagios/nagios.d/pnp4nagios.cfg
+           fi
+           if [ -e $OMD_ROOT/etc/icinga/icinga.d ] ; then
+               ln -sfn ../../pnp4nagios/nagios_npcd.cfg $OMD_ROOT/etc/icinga/icinga.d/pnp4nagios.cfg
+           fi 
+           ln -sfn ../../pnp4nagios/apache.conf $OMD_ROOT/etc/apache/conf.d/pnp4nagios.conf
        else
            rm -f $OMD_ROOT/etc/nagios/nagios.d/pnp4nagios.cfg
            rm -f $OMD_ROOT/etc/icinga/icinga.d/pnp4nagios.cfg
diff --git a/packages/pnp4nagios/skel/etc/init.d/npcd b/packages/pnp4nagios/skel/etc/init.d/npcd
index 1c2f945..c79fb2c 100644
--- a/packages/pnp4nagios/skel/etc/init.d/npcd
+++ b/packages/pnp4nagios/skel/etc/init.d/npcd
@@ -93,7 +93,7 @@ fi
 #### OMD ### 
 # Start only if PNP is enabled
 . ###ROOT###/etc/omd/site.conf
-if [ "$CONFIG_PNP4NAGIOS" != on ] ; then
+if ( [ "$CONFIG_PNP4NAGIOS" != on ] && [ "$CONFIG_PNP4NAGIOS" != npcd ] ) ; then
     exit 5
 fi
 
diff --git a/packages/pnp4nagios/skel/etc/nagios/conf.d/pnp4nagios.cfg b/packages/pnp4nagios/skel/etc/nagios/conf.d/pnp4nagios.cfg
index 82af7d9..6fb9be4 100644
--- a/packages/pnp4nagios/skel/etc/nagios/conf.d/pnp4nagios.cfg
+++ b/packages/pnp4nagios/skel/etc/nagios/conf.d/pnp4nagios.cfg
@@ -16,3 +16,13 @@ define service {
    register             0
 }
 
+define command{
+       command_name    omd-process-service-perfdata-file
+       command_line    /bin/mv ###ROOT###/var/pnp4nagios/service-perfdata ###ROOT###/var/pnp4nagios/spool/service-perfdata.$TIMET$
+}
+
+define command{
+       command_name    omd-process-host-perfdata-file
+       command_line    /bin/mv ###ROOT###/var/pnp4nagios/host-perfdata ###ROOT###/var/pnp4nagios/spool/host-perfdata.$TIMET$
+}
+
diff --git a/packages/pnp4nagios/skel/etc/pnp4nagios/nagios_npcd.cfg b/packages/pnp4nagios/skel/etc/pnp4nagios/nagios_npcd.cfg
new file mode 100644
index 0000000..f0fe7af
--- /dev/null
+++ b/packages/pnp4nagios/skel/etc/pnp4nagios/nagios_npcd.cfg
@@ -0,0 +1,22 @@
+#
+# PNP4Nagios Bulk Mode with npcd
+# 
+process_performance_data=1
+
+#
+# service performance data
+#
+service_perfdata_file=###ROOT###/var/pnp4nagios/service-perfdata
+service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
+service_perfdata_file_mode=a
+service_perfdata_file_processing_interval=15
+service_perfdata_file_processing_command=omd-process-service-perfdata-file
+
+#
+# host performance data
+# 
+host_perfdata_file=###ROOT###/var/pnp4nagios/host-perfdata
+host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
+host_perfdata_file_mode=a
+host_perfdata_file_processing_interval=15
+host_perfdata_file_processing_command=omd-process-host-perfdata-file
diff --git a/t/20-package_pnp4nagios.t b/t/20-package_pnp4nagios.t
index 2785d2c..5a0035b 100644
--- a/t/20-package_pnp4nagios.t
+++ b/t/20-package_pnp4nagios.t
@@ -13,7 +13,7 @@ BEGIN {
     use lib "$FindBin::Bin/lib/lib/perl5";
 }
 
-plan( tests => 103 );
+plan( tests => 153 );
 
 ##################################################
 # create our test site
@@ -70,3 +70,43 @@ for my $test (@{$tests}) {
 ##################################################
 # cleanup test site
 TestUtils::remove_test_site($site);
+
+##################################################
+# Create test Site for npcd test
+
+$site = TestUtils::create_test_site() or TestUtils::bail_out_clean("no further testing without site");
+
+# create test host/service
+TestUtils::prepare_obj_config('t/data/omd/testconf1', '/omd/sites/'.$site.'/etc/nagios/conf.d', $site);
+
+# decrease pnp interval
+TestUtils::test_command({ cmd => "/usr/bin/env sed -i -e 's/^perfdata_file_processing_interval = 15/perfdata_file_processing_interval = 2/g' -e 's/^sleep_time = 15/sleep_time = 2/g' /opt/omd/sites/$site/etc/pnp4nagios/npcd.cfg" });
+
+##################################################
+# prepare initial data
+TestUtils::test_command({ cmd => $omd_bin." config $site set PNP4NAGIOS npcd" });
+TestUtils::test_command({ cmd => $omd_bin." start $site" });
+# submit a forced check, so we have initial perf data
+TestUtils::test_command({ cmd => "/bin/su - $site -c './lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u /$site/nagios/cgi-bin/cmd.cgi -e 200 -P \"cmd_typ=7&cmd_mod=2&host=omd-$site&service=Dummy+Service&start_time=2010-11-06+09%3A46%3A02&force_check=on&btnSubmit=Commit\" -r \"Your command request was successfully submitted\"'", like => '/HTTP OK:/' });
+TestUtils::wait_for_file("/omd/sites/$site/var/pnp4nagios/perfdata/omd-$site/Dummy_Service_omd-dummy.rrd", 60) or TestUtils::bail_out_clean("No need to test pnp without existing rrd");;
+
+
+##################################################
+# then execute some checks
+$tests = [
+  { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -u /$site/pnp4nagios -e 401'",                           like => '/HTTP OK:/' },
+  { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u /$site/pnp4nagios -e 301'",           like => '/HTTP OK:/' },
+  { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u /$site/pnp4nagios/index.php -e 302'", like => '/HTTP OK:/' },
+  { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u /$site/pnp4nagios/graph?host=omd-$site -e 200'", like => '/HTTP OK:/' },
+  { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u \"/$site/pnp4nagios/graph?host=omd-$site&srv=Dummy+Service\" -e 200'", like => '/HTTP OK:/' },
+  { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u \"/$site/pnp4nagios/image?host=omd-$site&srv=Dummy+Service\" -e 200'", like => '/HTTP OK:/' },
+  { cmd => $omd_bin." stop $site" },
+];
+for my $test (@{$tests}) {
+    TestUtils::test_command($test);
+}
+
+##################################################
+# cleanup test site
+TestUtils::remove_test_site($site);
+



More information about the omd-commits mailing list