add started time info for running container

This commit is contained in:
Shini31 2015-07-22 09:58:44 +02:00
parent 114e6fdd50
commit 2f31289bfa
1 changed files with 6 additions and 3 deletions

View File

@ -41,6 +41,7 @@ use strict;
use warnings; use warnings;
use centreon::plugins::httplib; use centreon::plugins::httplib;
use JSON; use JSON;
use DateTime::Format::ISO8601;
my $thresholds = { my $thresholds = {
state => [ state => [
@ -172,7 +173,7 @@ sub run {
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
my ($result, $containername); my ($result,$containername,$containertime);
my $exit = 'OK'; my $exit = 'OK';
if (defined($self->{option_results}->{id}) || defined($self->{option_results}->{name})) { if (defined($self->{option_results}->{id}) || defined($self->{option_results}->{name})) {
@ -181,13 +182,15 @@ sub run {
$result = $keys; $result = $keys;
$containername = $webcontent->{Name}; $containername = $webcontent->{Name};
$containername =~ s/^\///; $containername =~ s/^\///;
my $dt = DateTime::Format::ISO8601->parse_datetime($webcontent->{State}->{StartedAt});
$containertime = $dt->strftime('%F %T');
last; last;
} }
} }
$exit = $self->get_severity(section => 'state', value => $result); $exit = $self->get_severity(section => 'state', value => $result);
$self->{output}->output_add(severity => $exit, $self->{output}->output_add(severity => $exit,
short_msg => sprintf("Container %s is %s", $containername, $result)); short_msg => sprintf("Container %s is %s (started since %s)", $containername, $result, $containertime));
} else { } else {
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(severity => 'OK',
short_msg => sprintf("All containers are in Running state")); short_msg => sprintf("All containers are in Running state"));
@ -217,7 +220,7 @@ sub run {
} }
} }
if ($exit ne 'OK') { if (!$self->{output}->is_status(value => $exit, compare => 'OK', litteral => 1)) {
$self->{output}->output_add(severity => $exit, $self->{output}->output_add(severity => $exit,
short_msg => sprintf("Some containers are in wrong state")); short_msg => sprintf("Some containers are in wrong state"));
} }