[icinga-checkins] icinga.org: icinga-core/fholzer/core: Automatic detection of icinga dir

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


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

Author: Alexander Wirt <formorer at debian.org>
Date:   Sat Apr 21 22:07:01 2012 +0200

Automatic detection of icinga dir

---

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

diff --git a/tools/icinga_verification.pl b/tools/icinga_verification.pl
index 92c515f..d939b40 100644
--- a/tools/icinga_verification.pl
+++ b/tools/icinga_verification.pl
@@ -34,6 +34,7 @@ sub get_key_from_ini ($$);
 sub which(@);
 sub slurp($);
 sub get_distribution;
+sub find_icinga_dir;
 
 ################################
 # Option parsing
@@ -86,15 +87,18 @@ if ( !$mysqlcheck ) {
 }
 
 #Icinga Base Set
-my $icinga_base = '';
-
-print "\nEnter your Icinga base </usr/local/icinga>: ";
-$icinga_base = <STDIN>;
-chomp($icinga_base);
-
-if ( !$icinga_base ) {
-    $icinga_base = '/usr/local/icinga';
+my $icinga_base = find_icinga_dir();
+
+if (! $icinga_base ) {
+    print "\nIcinga base not found.\nPlease enter your Icinga base: ";
+    $icinga_base = <STDIN>;
+    chomp($icinga_base);
+    if (! -d $icinga_base) {
+        print STDERR "Couldn't find icinga.cfg.";
+        exit 1;
+    }
 }
+
 ################################
 # Environment Checks
 ################################
@@ -359,3 +363,10 @@ sub get_distribution {
     }
 }
 
+sub find_icinga_dir {
+    my @locations = qw ( /etc/icinga/ /opt/icinga/etc/ /usr/local/icinga/etc/ );
+    foreach my $location (@locations) {
+        return $location if -e "$location/icinga.cfg";
+    }
+    return undef;
+}





More information about the icinga-checkins mailing list