[icinga-checkins] icinga.org: icinga-core/fholzer/core: Implement general service and binary lookup system

git at icinga.org git at icinga.org
Mon Apr 23 08:00:07 CEST 2012


Module: icinga-core
Branch: fholzer/core
Commit: e61a40c6e5f6c00267cfe11bb51e6529396e366d
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=e61a40c6e5f6c00267cfe11bb51e6529396e366d

Author: Alexander Wirt <formorer at debian.org>
Date:   Sun Apr 22 11:34:58 2012 +0200

Implement general service and binary lookup system

---

 tools/icinga_verification.pl |   37 +++++++++++++++++++++++++++----------
 1 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/tools/icinga_verification.pl b/tools/icinga_verification.pl
index 57cf3db..44c4b50 100644
--- a/tools/icinga_verification.pl
+++ b/tools/icinga_verification.pl
@@ -28,6 +28,7 @@ use DBI;
 use Term::ANSIColor;
 use Env qw (LANG PATH);
 use Getopt::Long;
+use File::Basename qw ( basename );
 
 # sub stubs
 sub get_key_from_ini ($$);
@@ -38,6 +39,16 @@ sub find_icinga_dir;
 sub get_icinga_version;
 sub get_ido2db_version;
 
+# preconfiguration
+my $config_ref = {
+    services => {
+        apache2 => { binaries => [ 'httpd', 'apache2' ] },
+        mysql => { binaries => [ 'mysqld' ] },
+        icinga => { binaries => [ 'icinga' ] },
+        ido2db => { binaries => [ 'snmptt' ] },
+    }
+};
+
 ################################
 # Option parsing
 ################################
@@ -122,7 +133,7 @@ my $date = localtime();
 #Apache Info
 my $bin;
 my $apacheinfo = join( '  ',
-      ( $bin = which( 'httpd', 'apache2' ) )
+      ( $bin = which( @{ $config_ref->{'services'}->{'apache2'}->{'binaries'} }) )
     ? (qx($bin -V))[ 0, 2, 3, 5, 6, 7, 8 ]
     : 'apache binary not found' );
 
@@ -292,18 +303,24 @@ print <<EOF;
 Process Status:
 EOF
 
-my @services = ( 'httpd', 'mysqld', 'snmptt', 'icinga', 'ido2db' );
-foreach my $service (@services) {
-    my $status = `/bin/ps cax | /bin/grep $service`;
-    if ( !$status ) {
-        print color("red"), " [$service]", color("reset"),
-            " not found or started\n";
+
+foreach my $service (keys($config_ref->{'services'})) {
+    my $binary = which (@{ $config_ref->{'services'}->{$service}->{'binaries'} });
+    if (! $binary ) {
+        print color("red"), " [$service]",color("reset"), " no binary found.\n";
     } else {
-        print color("green"), " [$service]", color("reset"),
-            " found and started\n";
+        my $binary = basename($binary);
+        my $status = qx(/bin/ps cax | /bin/grep $binary);
+        if ( !$status ) {
+            print color("red"), " [$service]", color("reset"),
+                " found but not running\n";
+        } else {
+            print color("green"), " [$service]", color("reset"),
+                " found and started\n";
+        }
     }
 }
-print " ############################################################\n";
+print "############################################################\n";
 
 exit;
 





More information about the icinga-checkins mailing list