#!/usr/bin/perl

#
# OpServices Tecnologia da Informacao
# Do not touch in this file. This is
# the RPM automated adjust script that
# removes the old configurations and
# insert the new ones in nrpe.cfg.
#
# Version 1.0 for opservices-plugins-1.0
#

use strict;
use Data::Dumper;

# configurations
our $nrpefile = "/usr/local/opmon/libexec/nrpe.cfg";
our $tmpfile = "/tmp/nrpe-tmp.cfg";


# YOU DONT NEED TO CHANGE ANYTHING UNDER THIS LINE!
open( NRPE, "<$nrpefile" );
my @nrpelines = <NRPE>;
close( NRPE );

#print @nrpelines;

open( NNRPE, ">$tmpfile" );
for( my $i=0; $i<=$#nrpelines; $i++ ) {
    if( $nrpelines[$i] !~ "#OpServices" ) {
        print NNRPE $nrpelines[$i];
    }
}
close( NNRPE );

open( NRPEAPPEND, "</usr/local/opmon/libexec/opservices/nrpe-append.cfg" );
my @nrpeappend = <NRPEAPPEND>;
close( NRPEAPPEND );

open( NRPE, ">$nrpefile" );
foreach( @nrpeappend ) {
    print NRPE $_;
}
close( NRPE );

open( NNRPE, "<$tmpfile" );
my @tmplines = <NNRPE>;
close( NNRPE );

open( NRPE, ">>$nrpefile" );
foreach( @tmplines ) {
    print NRPE $_;
}
close( NRPE );



exit(0);
