Random Project

I had to make a few small changes to get jobs_failed working.

Script errored due to empty $minutessincestart:

sub nagios {
my $self = shift;
my %params = @_;
if (! $self->{nagios_level}) {
if ($params{mode} =~ /server::jobs::failed/) {
if ($self->{lastrunstatus} ne “succeeded”) {
if ($self->{lastrunstatus} eq “failed”) {
$self->add_nagios_critical(
sprintf “%s failed: %s”, $self->{name}, $self->{lastrunstatusmessage});
} elsif ($self->{lastrunstatus} eq “retry” || $self->{lastrunstatus} eq “canceled”) {
$self->add_nagios_warning(
sprintf “%s %s: %s”, $self->{name}, $self->{lastrunstatus}, $self->{lastrunstatusmessage});
} else {
if ($self->{lastrunstatus}) {
print “else: $params{mode} $self->{name} $self->{lastrunstatus}
“;
$self->add_nagios(
$self->check_thresholds($self->{lastrundurationseconds}, 60, 300),
#sprintf(“job %s ran for %d seconds (started %s)
“, $self->{name},
sprintf(“job %s ran for %d seconds (started %s)”, $self->{name},
$self->{lastrundurationseconds}, $self->{lastrundatetime}));
}
}
} else {
print “OK – $self->{name}, $self->{lastrundurationseconds}, $self->{lastrundatetime}
“;
}
}
}
}

Script alerted if lastrunstatus was not set:

sub nagios {
my $self = shift;
my %params = @_;
if (! $self->{nagios_level}) {
if ($params{mode} =~ /server::jobs::failed/) {
if ($self->{lastrunstatus} ne “succeeded”) {
if ($self->{lastrunstatus} eq “failed”) {
$self->add_nagios_critical(
sprintf “%s failed: %s”, $self->{name}, $self->{lastrunstatusmessage});
} elsif ($self->{lastrunstatus} eq “retry” || $self->{lastrunstatus} eq “canceled”) {
$self->add_nagios_warning(
sprintf “%s %s: %s”, $self->{name}, $self->{lastrunstatus}, $self->{lastrunstatusmessage});
} else {
if ($self->{lastrunstatus}) {
print “else: $params{mode} $self->{name} $self->{lastrunstatus}
“;
$self->add_nagios(
$self->check_thresholds($self->{lastrundurationseconds}, 60, 300),
#sprintf(“job %s ran for %d seconds (started %s)
“, $self->{name},
sprintf(“job %s ran for %d seconds (started %s)”, $self->{name},
$self->{lastrundurationseconds}, $self->{lastrundatetime}));
}
}
} else {
print “OK – $self->{name}, $self->{lastrundurationseconds}, $self->{lastrundatetime}
“;
}
}
}
}