Bug #3050

[centstorage] bckp file forever

Added by Quentin Garnier about 2 years ago. Updated almost 2 years ago.

Status:ClosedStart date:02/08/2012
Priority:NormalDue date:
Assignee:-% Done:

100%

Category:-
Target version:Centreon-2.3.5
Resolution:

Description

Hi,

When centstorage has to be stopped. Sometimes, it will create a "bckp" file and centstorage will be in a loop. How ?
- centstorage searchs a bckp file
- In the function "movePerfDataFile", centstorage copy the "xxx.bckp" to "xxx.bckp_read"
- centstorage trunks "xxx.bckp" file (one line in the file)
- centstorage reads the "xxx.bckp_read" file
- centstorage deletes the "xxx.bckp_read" file
- centstorage searchs a bckp file. Yes!!! a bckp file with only one line :)
- and so on...
...

To solve the problem, we have to check. Here the new code:

sub movePerfDataFile($$){
    my $PERFDATA = $_[0];
    my $flag_bckp = $_[1];

    # Copy file before reading
    if (move($PERFDATA, $PERFDATA."_read")){
                # Erase old perfdata file.
                writeLogFile($PERFDATA."_read");
                if ($flag_bckp == 0) {
                        `echo "# New File " > $PERFDATA`;
                }
                undef($PERFDATA);
                return(1);
    } else {
                writeLogFile("Cannot copy $PERFDATA file : $!");
                undef($PERFDATA);
                return (0);
    }
}

...
sub GetPerfData() {
    # Init Var
    my ($line_tab, $sth2, $data, $flag_drop, $sleeptime, $configOptions, $now, $flag_bckp);
    use vars qw($con_oreon $con_ods %host %service $dataBinInfo $counterData);

    $flag_bckp = 0;
    # Init Buffer var
    $counterData = 0;
    $dataBinInfo = "";
    $now = time() + 86400;

    # Connect MySQL DB
    CheckMySQLConnexion();

    # Get path of perfdata file
    my $PFDT = getPerfDataFile();
    if (!defined($PFDT)) {
    writeLogFile("Could not find perf data file!");
    } 

    if ((defined($PFDT)) && (-r $PFDT || -r $PFDT.".bckp")) {
    # Check backup perfdata file 
    if (-r $PFDT.".bckp") {
            $flag_bckp = 1;
        $PFDT = $PFDT.".bckp";
    }
    # Move perfdata File befor reading            
    if (movePerfDataFile($PFDT, $flag_bckp) && open(PFDT, "< $PFDT"."_read")){

Best regards,

censtorage_block_bckp.patch Magnifier (1.48 KB) Quentin Garnier, 02/16/2012 04:05 pm

Associated revisions

Revision e2868636
Added by Julien Mathis about 2 years ago

fix #3050

git-svn-id: http://svn.centreon.com/trunk/centreon@12899 6bcd3966-0018-0410-8128-fd23d134de7e

History

#1 Updated by Quentin Garnier about 2 years ago

Patch for centreon 2.3.4.

#2 Updated by Julien Mathis about 2 years ago

  • Status changed from New to Solved
  • % Done changed from 0 to 100

Applied in changeset r12897.

#3 Updated by Julien Mathis about 2 years ago

Applied in changeset r12899.

#4 Updated by Quentin Garnier about 2 years ago

I'm seeing, there is some other issues. We have to modify lines:
Before:

sub movePerfDataFile($$){
    my $PERFDATA = $_[0];
    my $flag_bckp = $_[1];

    # Copy file before reading
    if (move($PERFDATA, $PERFDATA."_read")){
                # Erase old perfdata file.
                if ($flag_bckp == 0) {
                        `echo "# New File " > $PERFDATA`;
                }
                undef($PERFDATA);
                return(1);
    } else {
                writeLogFile("Cannot copy $PERFDATA file : $!");
                undef($PERFDATA);
                return (0);
    }
}
....
if ((defined($PFDT)) && (-r $PFDT || -r $PFDT.".bckp")) {
        # Check backup perfdata file
        if (-r $PFDT.".bckp") {
            $flag_bckp = 1;
            $PFDT = $PFDT.".bckp";
        }
...
                    if ($stop == 0) {
                        # TODO
                        if (!open(DROP, ">> ".$PFDT.".bckp")){
                            writeLogFile("Save reading data into ".$configOptions->{'drop_file'}." : $!");
                        } else {
                            writeLogFile("Cannot save reading data into ".$PFDT.".bckp : $!");
                        }
                        print DROP $_."\n";
                    }
...
            if ($flag_drop == 1) {
                if (!close(DROP)) {
                    writeLogFile("Cannot close filehandle DROP : ".$!);
                }
            }

After:

sub movePerfDataFile($$){
    my $PERFDATA = $_[0];
    my $flag_bckp = $_[1];
    my $PERFDATA_src = $PERFDATA;

    if ($flag_bckp == 1) {
               $PERFDATA_src = $PERFDATA . ".bckp";
    }
    if (move($PERFDATA_src, $PERFDATA."_read")){
                # Create empty perfdata file
                if ($flag_bckp == 0) {
                        `echo "# New File " > $PERFDATA`;
                }
                undef($PERFDATA);
                return(1);
    } else {
                writeLogFile("Cannot copy $PERFDATA file : $!");
                undef($PERFDATA);
                return (0);
    }
}
...
if ((defined($PFDT)) && (-r $PFDT || -r $PFDT.".bckp")) {
        # Check backup perfdata file
        if (-r $PFDT.".bckp") {
            $flag_bckp = 1;
        }
...
                        if ($flag_drop != 2) {
                                if (open(DROP, ">> ".$PFDT.".bckp")){
                                    writeLogFile("Save reading data into ".$PFDT.".bckp");
                                    $flag_drop = 2;
                                } else {
                                        writeLogFile("Cannot save reading data into ".$PFDT.".bckp : $!");
                                }
                        }
                        print DROP $_."\n";
                    } else {
...
            if ($flag_drop > 0) {
                if (!close(DROP)) {
                    writeLogFile("Cannot close filehandle DROP : ".$!);
                }
            }
...

#5 Updated by Quentin Garnier about 2 years ago

Ce n'est pas:

       print DROP $_."\n";

Mais:

       print DROP $_;

Il y'a déjà un "\n".

#6 Updated by Julien Mathis almost 2 years ago

  • Status changed from Solved to Closed

#7 Updated by Quentin Garnier almost 2 years ago

Applied in changeset r12996.

#8 Updated by Quentin Garnier almost 2 years ago

Applied in changeset r13034.

Also available in: Atom PDF