Merge branch 'master' of https://github.com/centreon/centreon-plugins
This commit is contained in:
commit
970d8a5571
|
@ -32,24 +32,26 @@ sub new {
|
|||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$self->{version} = '1.1';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', default => '2376'},
|
||||
"proto:s" => { name => 'proto', default => 'https' },
|
||||
"urlpath:s" => { name => 'url_path', default => '/' },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"ssl:s" => { name => 'ssl', },
|
||||
"cert-file:s" => { name => 'cert_file' },
|
||||
"key-file:s" => { name => 'key_file' },
|
||||
"cacert-file:s" => { name => 'cacert_file' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', default => '2376'},
|
||||
"proto:s" => { name => 'proto', default => 'https' },
|
||||
"urlpath:s" => { name => 'url_path', default => '/' },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"ssl:s" => { name => 'ssl', },
|
||||
"cert-file:s" => { name => 'cert_file' },
|
||||
"key-file:s" => { name => 'key_file' },
|
||||
"cacert-file:s" => { name => 'cacert_file' },
|
||||
"exclude:s" => { name => 'exclude' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
$self->{container_infos} = ();
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -64,7 +66,17 @@ sub check_options {
|
|||
$self->{http}->set_options(%{$self->{option_results}})
|
||||
}
|
||||
|
||||
sub run {
|
||||
sub check_exclude {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{status}}(\s|,|$)/) {
|
||||
$self->{output}->output_add(long_msg => sprintf("Skipping ${options{status}} container."));
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub api_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $jsoncontent = $self->{http}->request();
|
||||
|
@ -83,21 +95,59 @@ sub run {
|
|||
}
|
||||
|
||||
foreach my $val (@$webcontent) {
|
||||
my $containername = $val->{Names}->[0];
|
||||
$containername =~ s/^\///;
|
||||
my $containerid = $val->{Id};
|
||||
my $containerimage = $val->{Image};
|
||||
my $containerstate;
|
||||
if (($val->{Status} =~ m/^Up/) && ($val->{Status} =~ m/^(?:(?!Paused).)*$/)) {
|
||||
$containerstate = 'Running';
|
||||
} elsif ($val->{Status} =~ m/^Exited/) {
|
||||
$containerstate = 'Exited';
|
||||
} elsif ($val->{Status} =~ m/\(Paused\)$/) {
|
||||
$containerstate = 'Paused';
|
||||
}
|
||||
$self->{output}->output_add(long_msg => sprintf("%s [id = %s , image = %s, state = %s]",
|
||||
$containername, $containerid, $containerimage, $containerstate));
|
||||
return if ($self->check_exclude(status => 'Running'));
|
||||
$containerstate = 'Running';
|
||||
} elsif ($val->{Status} =~ m/^Exited/) {
|
||||
return if ($self->check_exclude(status => 'Exited'));
|
||||
$containerstate = 'Exited';
|
||||
} elsif ($val->{Status} =~ m/\(Paused\)$/) {
|
||||
return if ($self->check_exclude(status => 'Paused'));
|
||||
$containerstate = 'Paused';
|
||||
}
|
||||
my $containername = $val->{Names}->[0];
|
||||
$containername =~ s/^\///;
|
||||
$self->{container_infos}->{$containername}->{id} = $val->{Id};
|
||||
$self->{container_infos}->{$containername}->{image} = $val->{Image};
|
||||
$self->{container_infos}->{$containername}->{state} = $containerstate;
|
||||
}
|
||||
}
|
||||
|
||||
sub disco_format {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $names = ['name', 'id', 'image', 'state'];
|
||||
$self->{output}->add_disco_format(elements => $names);
|
||||
}
|
||||
|
||||
sub disco_show {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->api_request();
|
||||
|
||||
foreach my $containername (keys %{$self->{container_infos}}) {
|
||||
$self->{output}->add_disco_entry(name => $containername,
|
||||
id => $self->{container_infos}->{$containername}->{id},
|
||||
image => $self->{container_infos}->{$containername}->{image},
|
||||
state => $self->{container_infos}->{$containername}->{state},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->api_request();
|
||||
|
||||
foreach my $containername (keys %{$self->{container_infos}}) {
|
||||
$self->{output}->output_add(long_msg => sprintf("%s [id = %s , image = %s, state = %s]",
|
||||
$containername,
|
||||
$self->{container_infos}->{$containername}->{id},
|
||||
$self->{container_infos}->{$containername}->{image},
|
||||
$self->{container_infos}->{$containername}->{state}));
|
||||
}
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'List containers:');
|
||||
|
||||
|
@ -160,6 +210,10 @@ Specify key to send to the webserver
|
|||
|
||||
Specify root certificate to send to the webserver
|
||||
|
||||
=item B<--exlude>
|
||||
|
||||
Exclude specific container's state (comma seperated list) (Example: --exclude=Paused,Running)
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout (Default: 3)
|
||||
|
|
Loading…
Reference in New Issue