Mailer fix

This commit is contained in:
Denis Zheleztsov 2015-07-17 16:04:12 +03:00
parent a71081db62
commit 5bb8cc851f

View File

@ -98,13 +98,15 @@ sub get_previous_status {
my $check_run_file = '/etc/sensu/handlers/run/' . $check_name; my $check_run_file = '/etc/sensu/handlers/run/' . $check_name;
my $previous_check_status; my $previous_check_status;
if ( -e $check_run_file ) {
open my $run, '<', $check_run_file or warn "Cannot open file: $!\n"; open my $run, '<', $check_run_file or warn "Cannot open file: $!\n";
if ($run) {
while (<$run>) { while (<$run>) {
$previous_check_status = $_; $previous_check_status = $_;
} }
close($run); close($run);
write_status( $check_name, $status );
return $previous_check_status; return $previous_check_status;
} }
@ -118,20 +120,13 @@ sub get_previous_status {
# Check status # Check status
sub status_change { sub status_change {
my ($message) = @_;
my $check_name = $message->{check}->{name};
# Current check status
my $current_check_status = $message->{check}->{status}; my $current_check_status = $message->{check}->{status};
# Get provious check status # Get provious check status
my $previous_check_status my $previous_check_status
= get_previous_status( $check_name, $current_check_status ); = get_previous_status( $check_name, $current_check_status );
if ( ( $previous_check_status == -1 ) if ( $previous_check_status == $current_check_status ) {
or ( $previous_check_status eq $current_check_status ) )
{
return -1; return -1;
} }
else { else {
@ -145,6 +140,9 @@ if ( status_change == 0 ) {
`cat $mail_file | $mail_cmd -v -s "'$mail_subg'" $mail_to`; `cat $mail_file | $mail_cmd -v -s "'$mail_subg'" $mail_to`;
} }
else {
print "Status not changes\n";
}
# Remove temp file # Remove temp file
my @rm_cmd = ( 'rm', '-f', $mail_file ); my @rm_cmd = ( 'rm', '-f', $mail_file );