Show
Ignore:
Timestamp:
01/28/08 21:15:20 (11 months ago)
Author:
jmathis
Message:
 
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/centreon-1.4.2.4/ODS/lib/verifyHostServiceIdName.pm

    r3845 r3856  
    2323 
    2424sub 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"); 
    2630    if (!$sth1_oreon->execute) {writeLogFile("Error - getLastRestart : " . $sth1_oreon->errstr . "\n");} 
    2731    my $data_oreon = $sth1_oreon->fetchrow_hashref(); 
    2832    undef($sth1_oreon); 
     33    $con->disconnect(); 
    2934    return $data_oreon->{'last_restart'}; 
    3035} 
     
    3338 
    3439sub 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"); 
    3642    if (!$sth->execute) {writeLogFile("Error - getLastRestartInMemory :" . $sth->errstr . "\n");} 
    3743    my $data = $sth->fetchrow_hashref(); 
    3844    undef($sth); 
     45    $con->disconnect(); 
    3946    return $data->{'last_restart'}; 
    4047} 
    4148 
    4249sub saveLastRestartInMemory($){ 
     50        $con = DBI->connect("DBI:mysql:database=".$mysql_database_ods.";host=".$mysql_host, $mysql_user, $mysql_passwd, {'RaiseError' => 0, 'PrintError' => 0, 'AutoCommit' => 1}); 
    4351        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(); 
    4556    undef($sth); 
    4657} 
     
    4960 
    5061sub 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"); 
    5264    if (!$sth->execute) {writeLogFile("Error - getPurgeConfig :" . $sth->errstr . "\n");} 
    5365    my $data = $sth->fetchrow_hashref(); 
    5466    undef($sth); 
     67    $con->disconnect(); 
    5568    return $data->{'autodelete_rrd_db'}; 
    5669} 
     
    5972 
    6073sub 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"); 
    6276    if (!$sth->execute) {writeLogFile("Error - getStorageDir : " . $sth->errstr . "\n");} 
    6377    my $data = $sth->fetchrow_hashref(); 
    6478    undef($sth); 
     79    $con->disconnect(); 
    6580    return $data->{'RRDdatabase_path'}; 
    6681} 
     
    7085sub DeleteOldRrdDB(){ 
    7186        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    } 
    7492    while ($data = $sth->fetchrow_hashref()){ 
    7593        $base{$data->{'metric_id'}.".rrd"} = 1; 
     
    93111                        } 
    94112                } 
    95         }      
     113        } 
     114        $con->disconnect(); 
    96115        undef($some_dir); 
    97116        undef(@files); 
     
    106125sub check_HostServiceID(){ 
    107126        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"); 
    109129    if (!$sth1->execute) {writeLogFile("Error : " . $sth1->errstr . "\n");} 
    110130    while ($data = $sth1->fetchrow_hashref()){ 
     
    113133        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'}))){ 
    114134                $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); 
    116136                writeLogFile("Error:" . $sth2->errstr . "\n") if (!$sth2->execute); 
    117137                undef($sth2); 
     
    119139    } 
    120140        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."'"); 
    122142                if (!$sth1->execute) {writeLogFile("Error:" . $sth1->errstr . "\n");} 
    123143                undef($sth1); 
    124144        } 
     145        $con->disconnect(); 
    125146} 
    126147