[icinga-checkins] icinga.org: icinga-core/fholzer/core: Add generic distribution detection

git at icinga.org git at icinga.org
Sat Apr 21 20:23:45 CEST 2012


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

Author: Alexander Wirt <formorer at debian.org>
Date:   Sat Apr 21 10:24:44 2012 +0200

Add generic distribution detection

---

 tools/icinga_verification.pl |   35 ++++++++++++++++++++++++-----------
 1 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/tools/icinga_verification.pl b/tools/icinga_verification.pl
index e58806b..29c0d71 100644
--- a/tools/icinga_verification.pl
+++ b/tools/icinga_verification.pl
@@ -32,6 +32,8 @@ use Getopt::Long;
 # sub stubs
 sub get_key_from_ini ($$);
 sub which($);
+sub slurp($);
+sub get_distribution;
 
 ################################
 # Option parsing
@@ -103,17 +105,6 @@ my $perlversion = $^V;
 # Kernel version
 my $osversion = qx(uname -rp) ;
 
-# search for OS Information Files
-my @files = `find /etc -maxdepth 1 -name *-release 2>/dev/null`;
-my @distriinfo;
-
-if (@files == 0) {
-	print "no release info File found in /etc/";
-	exit -1;
-} else {
-	@distriinfo = `cat $files[0]`;
-}
-
 # PHP Version
 my $phpversion = (qx(php -v))[0];
 chomp($phpversion);
@@ -321,3 +312,25 @@ sub slurp($) {
     }
 }
 
+sub get_distribution {
+    #first try: lsb
+    if (-x which('lsb_release') ) {
+        open (my $fh, '-|', "lsb_release -d -c -r ");
+        my $version = do { local $/; <$fh> };
+        close($fh);
+        $version = join(", ", split ("\n", $version));
+        $version =~ s/\s+/ /g,
+        return $version;
+    } elsif ( -f '/etc/debian_version' ) {
+        my $version = slurp('/etc/debian_version');
+        chomp($version);
+        return "Debian GNU/Linux $version";
+    } elsif ( -f '/etc/redhat-release' ) {
+        my $version = slurp('/etc/redhat-release');
+        chomp($version);
+        return $version;
+    } else {
+        return "unknown";
+    }
+}
+





More information about the icinga-checkins mailing list