- Timestamp:
- 01/28/08 21:15:20 (11 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/centreon-1.4.2.4/ODS/lib/verifyHostServiceIdName.pm
r3845 r3856 23 23 24 24 sub getLastRestart(){ 25 my $sth1_oreon = $con_oreon->prepare("SELECT last_restart FROM nagios_server"); 25 26 # Create connection 27 $con = DBI->connect("DBI:mysql:database=".$mysql_database_oreon.";host=".$mysql_host, $mysql_user, $mysql_passwd, {'RaiseError' => 0, 'PrintError' => 0, 'AutoCommit' => 1}); 28 29 my $sth1_oreon = $con->prepare("SELECT last_restart FROM nagios_server"); 26 30 if (!$sth1_oreon->execute) {writeLogFile("Error - getLastRestart : " . $sth1_oreon->errstr . "\n");} 27 31 my $data_oreon = $sth1_oreon->fetchrow_hashref(); 28 32 undef($sth1_oreon); 33 $con->disconnect(); 29 34 return $data_oreon->{'last_restart'}; 30 35 } … … 33 38 34 39 sub getLastRestartInMemory(){ 35 my $sth = $con_ods->prepare("SELECT last_restart FROM statistics"); 40 $con = DBI->connect("DBI:mysql:database=".$mysql_database_ods.";host=".$mysql_host, $mysql_user, $mysql_passwd, {'RaiseError' => 0, 'PrintError' => 0, 'AutoCommit' => 1}); 41 my $sth = $con->prepare("SELECT last_restart FROM statistics"); 36 42 if (!$sth->execute) {writeLogFile("Error - getLastRestartInMemory :" . $sth->errstr . "\n");} 37 43 my $data = $sth->fetchrow_hashref(); 38 44 undef($sth); 45 $con->disconnect(); 39 46 return $data->{'last_restart'}; 40 47 } 41 48 42 49 sub saveLastRestartInMemory($){ 50 $con = DBI->connect("DBI:mysql:database=".$mysql_database_ods.";host=".$mysql_host, $mysql_user, $mysql_passwd, {'RaiseError' => 0, 'PrintError' => 0, 'AutoCommit' => 1}); 43 51 my $sth = $con_ods->prepare("UPDATE statistics SET `last_restart` = '".$_[0]."'"); 44 if (!$sth->execute) {writeLogFile("Error - saveLastRestartInMemory : " . $sth->errstr . "\n");} 52 if (!$sth->execute) { 53 writeLogFile("Error - saveLastRestartInMemory : " . $sth->errstr . "\n"); 54 } 55 $con->disconnect(); 45 56 undef($sth); 46 57 } … … 49 60 50 61 sub getPurgeConfig(){ 51 my $sth = $con_ods->prepare("SELECT autodelete_rrd_db FROM config"); 62 $con = DBI->connect("DBI:mysql:database=".$mysql_database_ods.";host=".$mysql_host, $mysql_user, $mysql_passwd, {'RaiseError' => 0, 'PrintError' => 0, 'AutoCommit' => 1}); 63 my $sth = $con->prepare("SELECT autodelete_rrd_db FROM config"); 52 64 if (!$sth->execute) {writeLogFile("Error - getPurgeConfig :" . $sth->errstr . "\n");} 53 65 my $data = $sth->fetchrow_hashref(); 54 66 undef($sth); 67 $con->disconnect(); 55 68 return $data->{'autodelete_rrd_db'}; 56 69 } … … 59 72 60 73 sub getStorageDir(){ 61 my $sth = $con_ods->prepare("SELECT RRDdatabase_path FROM config"); 74 $con = DBI->connect("DBI:mysql:database=".$mysql_database_ods.";host=".$mysql_host, $mysql_user, $mysql_passwd, {'RaiseError' => 0, 'PrintError' => 0, 'AutoCommit' => 1}); 75 my $sth = $con->prepare("SELECT RRDdatabase_path FROM config"); 62 76 if (!$sth->execute) {writeLogFile("Error - getStorageDir : " . $sth->errstr . "\n");} 63 77 my $data = $sth->fetchrow_hashref(); 64 78 undef($sth); 79 $con->disconnect(); 65 80 return $data->{'RRDdatabase_path'}; 66 81 } … … 70 85 sub DeleteOldRrdDB(){ 71 86 my ($data, %base); 72 my $sth = $con_ods->prepare("SELECT metric_id FROM metrics"); 73 if (!$sth->execute) {writeLogFile("Error:" . $sth->errstr . "\n");} 87 $con = DBI->connect("DBI:mysql:database=".$mysql_database_ods.";host=".$mysql_host, $mysql_user, $mysql_passwd, {'RaiseError' => 0, 'PrintError' => 0, 'AutoCommit' => 1}); 88 my $sth = $con->prepare("SELECT metric_id FROM metrics"); 89 if (!$sth->execute) { 90 writeLogFile("Error:" . $sth->errstr . "\n"); 91 } 74 92 while ($data = $sth->fetchrow_hashref()){ 75 93 $base{$data->{'metric_id'}.".rrd"} = 1; … … 93 111 } 94 112 } 95 } 113 } 114 $con->disconnect(); 96 115 undef($some_dir); 97 116 undef(@files); … … 106 125 sub check_HostServiceID(){ 107 126 my ($data, $host_name, $service_description, $purge_mod); 108 my $sth1 = $con_ods->prepare("SELECT * FROM index_data ORDER BY host_name"); 127 $con = DBI->connect("DBI:mysql:database=".$mysql_database_ods.";host=".$mysql_host, $mysql_user, $mysql_passwd, {'RaiseError' => 0, 'PrintError' => 0, 'AutoCommit' => 1}); 128 my $sth1 = $con->prepare("SELECT * FROM index_data ORDER BY host_name"); 109 129 if (!$sth1->execute) {writeLogFile("Error : " . $sth1->errstr . "\n");} 110 130 while ($data = $sth1->fetchrow_hashref()){ … … 113 133 if (defined($host_name) && $host_name && defined($service_description) && $service_description && defined($data->{'host_name'}) && defined($data->{'service_description'}) && (($host_name ne $data->{'host_name'}) || ($service_description ne $data->{'service_description'}))){ 114 134 $str = "UPDATE index_data SET `host_name` = '".$host_name."', `service_description` = '".$service_description."' WHERE `host_id` = '".$data->{'host_id'}."' AND `service_id` = '".$data->{'service_id'}."'"; 115 my $sth2 = $con _ods->prepare($str);135 my $sth2 = $con->prepare($str); 116 136 writeLogFile("Error:" . $sth2->errstr . "\n") if (!$sth2->execute); 117 137 undef($sth2); … … 119 139 } 120 140 if (defined($last_restart) && $last_restart){ 121 $sth1 = $con _ods->prepare("UPDATE statistics SET `last_restart` = '".$last_restart."'");141 $sth1 = $con->prepare("UPDATE statistics SET `last_restart` = '".$last_restart."'"); 122 142 if (!$sth1->execute) {writeLogFile("Error:" . $sth1->errstr . "\n");} 123 143 undef($sth1); 124 144 } 145 $con->disconnect(); 125 146 } 126 147
