[icinga-checkins] icinga.org: icinga-core/fholzer/core: - add Icinga_Base_Set /usr/local/ icinga

git at icinga.org git at icinga.org
Fri Apr 20 15:01:43 CEST 2012


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

Author: Franz Holzer <office at frankstar.at>
Date:   Fri Apr 20 14:55:32 2012 +0200

- add Icinga_Base_Set /usr/local/icinga
- add ido2db.cfg Setup
- add ido2db.cfg Mysql Connection Test
- bugfix Mysql connections
- bugfix Mysql User Input
- add more Output

---

 tools/icinga_verification.pl |  137 ++++++++++++++++++++++++++++++++---------
 1 files changed, 107 insertions(+), 30 deletions(-)

diff --git a/tools/icinga_verification.pl b/tools/icinga_verification.pl
index b840cad..994582a 100644
--- a/tools/icinga_verification.pl
+++ b/tools/icinga_verification.pl
@@ -32,15 +32,12 @@ use Term::ANSIColor;
 ################################
 
 #Check if we are on Windows
-
 my $oscheck = $^O;
 if( $oscheck eq 'MSWin32' ){
 	print "We are on Windows, will quit now!";
 	exit;
 }
-
 # MySQL Config if MySQL is used
-
 my $mysqlcheck = `find /usr/bin -name mysql`;
 my $mysqldb = '';
 my $mysqlserver = '';
@@ -48,18 +45,26 @@ my $mysqluser = '';
 my $mysqlpw = '';
 
 if (!$mysqlcheck ){
-	print "no Mysql Found, skip Config";
+	print "no Mysql Server Found, skip Config";
 }
 else{
+
 $mysqldb = "icinga";
 print "\nMysql Found! - start Config Script\n";
+print "Values in '< >' are standarts! Confirm with [Enter]\n";
 print "\nEnter your MYSQL Server <localhost>: ";
 $mysqlserver = <STDIN>;
 chomp($mysqlserver);
+if (!$mysqlserver){
+	$mysqlserver = 'localhost';
+}
 
 print "Enter your MYSQL User <root>: ";
 $mysqluser = <STDIN>;
 chomp($mysqluser);
+if (!$mysqluser){
+	$mysqluser = 'root';
+}
 
 system('stty','-echo');
 print "Enter your MYSQL Password: ";
@@ -68,11 +73,16 @@ chomp($mysqlpw);
 system('stty','echo');
 }
 
-if (!$mysqlserver || !$mysqluser){
-	print "\n\nNo MYSQL Server or User specified - will exit now\n";
-	exit;
-}
+#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';
+}
 ################################
 # Environment Checks 
 ################################
@@ -107,58 +117,123 @@ my $date = `date`;
 my @apacheinfo = `httpd -V`;
 chomp(@apacheinfo);
 
+#Mysql Info
+my $mysqlver = `mysql -V`;
+my @mysqlver_split = split(',', $mysqlver);
+
 ######ADD JAVA HOMES, ORCALE HOMES, PATH -> via env | grep ######
 
 ################################
 # Icinga Checks 
 ################################
 
-
 # verify that idomod connected via socket to ido2db
 my $idocheck = `ps aux | grep ido2db | grep -v grep | wc -l`;
 chomp($idocheck);
 
-# MySQL Connect
-my $dbh = '';
+#ido2db socket type
+my $ido2dbsocket = `cat $icinga_base/etc/ido2db.cfg | grep ^socket_type=`;
+chomp($ido2dbsocket);
+
+#ido2db TCP Port
+my $ido2dbtcpport = `cat $icinga_base/etc/ido2db.cfg | grep ^tcp_port=`;
+chomp($ido2dbtcpport);
+
+#ido2db SSL Status
+#use_ssl=
+
+#ido2db Servertype
+#db_servertype=
+
+#ido2db Server Host Name
+my $mysqlserver_cfg = `cat $icinga_base/etc/ido2db.cfg | grep ^db_host=`;
+chomp($mysqlserver_cfg);
+my @mysqlserver_cfg_split = split('=', $mysqlserver_cfg);
+
+#ido2db Server port
+#db_port=
+
+#ido2db Server Socket
+#db_socket=
+
+#ido2db DB User
+my $mysqluser_cfg = `cat $icinga_base/etc/ido2db.cfg | grep ^db_user=`;
+chomp($mysqluser_cfg);
+my @mysqluser_cfg_split = split('=', $mysqluser_cfg);
+
+#ido2db DB Name
+my $mysqldb_cfg = `cat $icinga_base/etc/ido2db.cfg | grep ^db_name=`;
+chomp($mysqldb_cfg);
+my @mysqldb_cfg_split = split('=', $mysqldb_cfg);
+
+#ido2db Password
+my $mysqlpw_cfg = `cat $icinga_base/etc/ido2db.cfg | grep ^db_pass=`;
+chomp($mysqlpw_cfg);
+my @mysqlpw_cfg_split = split('=', $mysqlpw_cfg);
+
+# MySQL Checks#
+my $dbh_user = '';
+my $dbh_user_error = '';
+my $dbh_cfg = '';
+my $dbh_cfg_error = '';
 my $icinga_dbversion = '';
-my $sth = '';
+my $sth_user = '';
+my $sth1_user = '';
 my @result_icingadb = ();
 my @row;
 my @result_icingaconninfo = ();
 
-
 if (!$mysqlcheck ){
 	print "no Mysql Found, skip Querys";
 }
 else{
-$dbh = DBI->connect("dbi:mysql:database=$mysqldb; host=$mysqlserver:mysql_server_prepare=1", "$mysqluser", "$mysqlpw")
-	or die "\n$DBI::errstr";
-
+# User Input Connect
+$dbh_user = DBI->connect("dbi:mysql:database=$mysqldb; host=$mysqlserver:mysql_server_prepare=1", "$mysqluser", "$mysqlpw", {
+	PrintError => 0,
+    RaiseError => 0
+}) or die color("red"), "\nMySQL Connect Failed. - check your input or MySQL Process\n", color("reset");
+
+chomp($dbh_user_error);	
+	
 # Query icinga DB Version
 $icinga_dbversion = 'SELECT version FROM icinga_dbversion';
-$sth = $dbh->prepare($icinga_dbversion) or die $DBI::errstr;
+$sth_user = $dbh_user->prepare($icinga_dbversion) or warn $DBI::errstr;
 
-$sth->execute() or die $DBI::errstr;
+$sth_user->execute() or warn $DBI::errstr;
 
 
-while(@row = $sth->fetchrow_array()){
-	push(@result_icingadb, at row);
-}
+	while(@row = $sth_user->fetchrow_array()){
+		push(@result_icingadb, at row);
+	}
 
 # Query icinga_conninfo
 my $icinga_conninfo = 'select conninfo_id, last_checkin_time from icinga_conninfo order by connect_time desc limit 2';
-my $sth1 = $dbh->prepare($icinga_conninfo) or die $DBI::errstr;
+$sth1_user = $dbh_user->prepare($icinga_conninfo) or warn $DBI::errstr;
+
+$sth1_user->execute() or warn $DBI::errstr;
+
+	while(@row = $sth1_user->fetchrow_array()){
+		push(@result_icingaconninfo,"id:", at row,"\n");
+	}
+	
+$dbh_user->disconnect();	
 
-$sth1->execute() or die $DBI::errstr;
+# ido2db.cfg Connection test
+$dbh_cfg = DBI->connect("dbi:mysql:database=$mysqldb_cfg_split[1]; host=$mysqlserver_cfg_split[1]:mysql_server_prepare=1", "$mysqluser_cfg_split[1]", "$mysqlpw_cfg_split[1]", {
+	PrintError => 0,
+    RaiseError => 0
+}) or $dbh_cfg_error = "ido2db.cfg - MySQL Connect Failed. - check your config";	
 
-while(@row = $sth1->fetchrow_array()){
-	push(@result_icingaconninfo,"id:", at row,"\n");
+chomp($dbh_cfg_error);		
 }
-# MySQL Disconnect
-$dbh->disconnect();
+
+if (!$dbh_cfg_error){
+	$dbh_cfg->disconnect();
 }
 
 # Test Print Out
+# later create a fileout with the output
+
 print "\n ############################################################";
 print "\n ######   Icinga Verification and Reporting Script     ######";
 print "\n ######  by Frankstar / Team Quality Assurance & VM    ######";
@@ -172,16 +247,18 @@ print " Environment-$envlang";
 print "\n Webserver Information:\n";
 print " $apacheinfo[0] \n $apacheinfo[2] \n $apacheinfo[3] \n $apacheinfo[5] \n $apacheinfo[6] \n $apacheinfo[7] \n $apacheinfo[8] \n";
 print "\n PHP Information:\n $phpversion[0]";
+print "\n MySQL Information:\n $mysqlver_split[0]\n";
 print "\n Icinga Informations:\n";
 print " idomod Connections: $idocheck\n";
 print " Icinga DB-Version: $result_icingadb[0]\n";
 print "\n ido2db last Connection Info:\n";
 print " @result_icingaconninfo";
-
+# ido2db.cfg mysql Test Connection
+print color("red"), "\n $dbh_cfg_error\n", color("reset");
 #Check Services
-print "\n Process Status:\n";
+print " Process Status:\n";
 
-my @services = ( 'blub', 'httpd', 'mysqld', 'snmptt', 'icinga', 'ido2db');
+my @services = ('httpd', 'mysqld', 'snmptt', 'icinga', 'ido2db');
  
  foreach my $service (@services) {
  my $status = `/bin/ps cax | /bin/grep $service`;





More information about the icinga-checkins mailing list