[icinga-checkins] icinga.org: icinga-core/fholzer/core: Add simple iniparser and fix some small typos

git at icinga.org git at icinga.org
Fri Apr 20 20:42:06 CEST 2012


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

Author: Alexander Wirt <formorer at grml.org>
Date:   Fri Apr 20 17:13:47 2012 +0200

Add simple iniparser and fix some small typos

if you want to know if something is set in in an inifile
try:
get_key_from_ini('/etc/icinga/icinga.cfg', 'max_debug_file_size');

---

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

diff --git a/tools/icinga_verification.pl b/tools/icinga_verification.pl
index b4d3bd0..c97d1a0 100644
--- a/tools/icinga_verification.pl
+++ b/tools/icinga_verification.pl
@@ -29,6 +29,8 @@ use Term::ANSIColor;
 use Env qw (LANG);
 use Getopt::Long;
 
+# sub stubs
+sub get_key_from_ini ($$);
 ################################
 # Option parsing
 ################################
@@ -119,10 +121,10 @@ my $date = localtime();
 
 #Apache Info
 #FIXME we need a way of testing several binarynames. on debian this is apache2
-my $apacheinfo = (qx(httpd -V))[0,2,3,5,6,7,8];
+my @apacheinfo = (qx(httpd -V))[0,2,3,5,6,7,8];
 
 #Mysql Info
-my $mysqlver = (split(",", qx(mysql -V)))[0]
+my $mysqlver = (split(",", qx(mysql -V)))[0];
 
 ######ADD JAVA HOMES, ORCALE HOMES, PATH -> via env | grep ######
 
@@ -278,3 +280,24 @@ my @services = ('httpd', 'mysqld', 'snmptt', 'icinga', 'ido2db');
 print " ############################################################\n";
 
 exit;
+
+sub get_key_from_ini ($$) {
+        my ($file, $key) = @_; 
+
+        if (! -f $file) {
+                print STDERR "Inifile $file does not exist\n";
+                return;
+        }   
+
+        if (open(my $fh, '<', $file)) {
+                while (my $line = <$fh>) {
+                        chmod($line);
+                        if ($line =~ /^\s*$key=([^\s]+)/) {
+                                print "$key = $1\n";
+                        }   
+                }   
+        } else {
+                print STDERR "Could not open initfile $file: $!\n";
+        }   
+}
+





More information about the icinga-checkins mailing list