mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-04-07 20:35:27 +02:00
change httplib class to http class
This commit is contained in:
parent
abbb32f2f0
commit
da581a3051
@ -18,13 +18,13 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package docker::docker::mode::blockio;
|
||||
package cloud::docker::mode::blockio;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::httplib;
|
||||
use centreon::plugins::http;
|
||||
use centreon::plugins::statefile;
|
||||
use JSON;
|
||||
|
||||
@ -53,11 +53,11 @@ sub new {
|
||||
"cert-file:s" => { name => 'cert_file' },
|
||||
"key-file:s" => { name => 'key_file' },
|
||||
"cacert-file:s" => { name => 'cacert_file' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
});
|
||||
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -65,14 +65,6 @@ sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ((defined($self->{option_results}->{name})) && (defined($self->{option_results}->{id}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the name or id option");
|
||||
$self->{output}->option_exit();
|
||||
@ -98,6 +90,15 @@ sub check_options {
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{option_results}->{get_param} = [];
|
||||
push @{$self->{option_results}->{get_param}}, "stream=false";
|
||||
if (defined($self->{option_results}->{id})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{id}."/stats";
|
||||
} elsif (defined($self->{option_results}->{name})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{name}."/stats";
|
||||
}
|
||||
|
||||
$self->{http}->set_options(%{$self->{option_results}});
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
}
|
||||
|
||||
@ -107,21 +108,12 @@ sub run {
|
||||
my $new_datas = {};
|
||||
|
||||
if (defined($self->{option_results}->{id})) {
|
||||
$self->{statefile_value}->read(statefile => 'docker_' . $self->{option_results}->{id} . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode});
|
||||
$self->{statefile_value}->read(statefile => 'docker_' . $self->{option_results}->{id} . '_' . $self->{http}->get_port() . '_' . $self->{mode});
|
||||
} elsif (defined($self->{option_results}->{name})) {
|
||||
$self->{statefile_value}->read(statefile => 'docker_' . $self->{option_results}->{name} . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode});
|
||||
$self->{statefile_value}->read(statefile => 'docker_' . $self->{option_results}->{name} . '_' . $self->{http}->get_port() . '_' . $self->{mode});
|
||||
}
|
||||
|
||||
my $jsoncontent;
|
||||
my $query_form_get = { stream => 'false' };
|
||||
|
||||
if (defined($self->{option_results}->{id})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{id}."/stats";
|
||||
$jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get, connection_exit => 'critical');
|
||||
} elsif (defined($self->{option_results}->{name})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{name}."/stats";
|
||||
$jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get, connection_exit => 'critical');
|
||||
}
|
||||
my $jsoncontent = $self->{http}->request();
|
||||
|
||||
my $json = JSON->new;
|
||||
|
||||
|
@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::httplib;
|
||||
use centreon::plugins::http;
|
||||
use JSON;
|
||||
|
||||
my $thresholds = {
|
||||
@ -59,10 +59,11 @@ sub new {
|
||||
"cert-file:s" => { name => 'cert_file' },
|
||||
"key-file:s" => { name => 'key_file' },
|
||||
"cacert-file:s" => { name => 'cacert_file' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
"threshold-overload:s@" => { name => 'threshold_overload' },
|
||||
});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -70,16 +71,6 @@ sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
if ((defined($self->{option_results}->{name})) && ($self->{option_results}->{name} eq '')) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to specify the name option");
|
||||
$self->{output}->option_exit();
|
||||
@ -104,6 +95,18 @@ sub check_options {
|
||||
$self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
|
||||
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status};
|
||||
}
|
||||
|
||||
if (defined($self->{option_results}->{id})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{id}."/json";
|
||||
} elsif (defined($self->{option_results}->{name})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{name}."/json";
|
||||
} else {
|
||||
$self->{option_results}->{url_path} = "/containers/json";
|
||||
$self->{option_results}->{get_param} = [];
|
||||
push @{$self->{option_results}->{get_param}}, "all=true";
|
||||
}
|
||||
$self->{http}->set_options(%{$self->{option_results}});
|
||||
|
||||
}
|
||||
|
||||
sub get_severity {
|
||||
@ -130,19 +133,7 @@ sub get_severity {
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $jsoncontent;
|
||||
|
||||
if (defined($self->{option_results}->{id})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{id}."/json";
|
||||
$jsoncontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical');
|
||||
} elsif (defined($self->{option_results}->{name})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{name}."/json";
|
||||
$jsoncontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical');
|
||||
} else {
|
||||
$self->{option_results}->{url_path} = "/containers/json";
|
||||
my $query_form_get = { all => 'true' };
|
||||
$jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get, connection_exit => 'critical');
|
||||
}
|
||||
my $jsoncontent = $self->{http}->request();
|
||||
|
||||
my $json = JSON->new;
|
||||
|
||||
|
@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::httplib;
|
||||
use centreon::plugins::http;
|
||||
use centreon::plugins::statefile;
|
||||
use JSON;
|
||||
|
||||
@ -51,10 +51,11 @@ sub new {
|
||||
"cert-file:s" => { name => 'cert_file' },
|
||||
"key-file:s" => { name => 'key_file' },
|
||||
"cacert-file:s" => { name => 'cacert_file' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
});
|
||||
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
|
||||
return $self;
|
||||
}
|
||||
@ -63,16 +64,6 @@ sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
if ((defined($self->{option_results}->{name})) && (defined($self->{option_results}->{id}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the name or id option");
|
||||
$self->{output}->option_exit();
|
||||
@ -93,25 +84,29 @@ sub check_options {
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{option_results}->{get_param} = [];
|
||||
push @{$self->{option_results}->{get_param}}, "stream=false";
|
||||
if (defined($self->{option_results}->{id})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{id}."/stats";
|
||||
} elsif (defined($self->{option_results}->{name})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{name}."/stats";
|
||||
}
|
||||
|
||||
$self->{http}->set_options(%{$self->{option_results}});
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $jsoncontent;
|
||||
my $query_form_get = { stream => 'false' };
|
||||
|
||||
if (defined($self->{option_results}->{id})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{id}."/stats";
|
||||
$jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get, connection_exit => 'critical');
|
||||
$self->{statefile_value}->read(statefile => 'docker_' . $self->{option_results}->{id} . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode});
|
||||
$self->{statefile_value}->read(statefile => 'docker_' . $self->{option_results}->{id} . '_' . $self->{http}->get_port() . '_' . $self->{mode});
|
||||
} elsif (defined($self->{option_results}->{name})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{name}."/stats";
|
||||
$jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get, connection_exit => 'critical');
|
||||
$self->{statefile_value}->read(statefile => 'docker_' . $self->{option_results}->{name} . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode});
|
||||
$self->{statefile_value}->read(statefile => 'docker_' . $self->{option_results}->{name} . '_' . $self->{http}->get_port() . '_' . $self->{mode});
|
||||
}
|
||||
|
||||
my $jsoncontent = $self->{http}->request();
|
||||
|
||||
my $json = JSON->new;
|
||||
|
||||
my $webcontent;
|
||||
|
@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::httplib;
|
||||
use centreon::plugins::http;
|
||||
use JSON;
|
||||
|
||||
sub new {
|
||||
@ -52,9 +52,10 @@ sub new {
|
||||
"cert-file:s" => { name => 'cert_file' },
|
||||
"key-file:s" => { name => 'key_file' },
|
||||
"cacert-file:s" => { name => 'cacert_file' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -62,16 +63,6 @@ sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
if ((defined($self->{option_results}->{name})) && (defined($self->{option_results}->{id}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the name or id option");
|
||||
$self->{output}->option_exit();
|
||||
@ -96,25 +87,25 @@ sub check_options {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the registry-proto option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
if (defined($self->{option_results}->{id})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{id}."/json";
|
||||
} elsif (defined($self->{option_results}->{name})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{name}."/json";
|
||||
}
|
||||
|
||||
$self->{http}->set_options(%{$self->{option_results}});
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($jsoncontent,$jsoncontent2);
|
||||
my ($jsoncontent,$jsoncontent2, $webcontent, $webcontent2);
|
||||
|
||||
if (defined($self->{option_results}->{id})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{id}."/json";
|
||||
$jsoncontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical');
|
||||
} elsif (defined($self->{option_results}->{name})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{name}."/json";
|
||||
$jsoncontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical');
|
||||
}
|
||||
$jsoncontent = $self->{http}->request();
|
||||
|
||||
my $json = JSON->new;
|
||||
|
||||
my ($webcontent,$webcontent2);
|
||||
|
||||
eval {
|
||||
$webcontent = $json->decode($jsoncontent);
|
||||
};
|
||||
@ -131,7 +122,7 @@ sub run {
|
||||
$self->{option_results}->{proto} = $self->{option_results}->{registry_proto};
|
||||
$self->{option_results}->{hostname} = $self->{option_results}->{registry_hostname};
|
||||
|
||||
$jsoncontent2 = centreon::plugins::httplib::connect($self, connection_exit => 'critical');
|
||||
$jsoncontent2 = $self->{http}->request();
|
||||
|
||||
my $json2 = JSON->new;
|
||||
|
||||
|
@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::httplib;
|
||||
use centreon::plugins::http;
|
||||
use JSON;
|
||||
|
||||
sub new {
|
||||
@ -46,9 +46,10 @@ sub new {
|
||||
"cert-file:s" => { name => 'cert_file' },
|
||||
"key-file:s" => { name => 'key_file' },
|
||||
"cacert-file:s" => { name => 'cacert_file' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
});
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -56,22 +57,13 @@ sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
||||
my $jsoncontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical');
|
||||
my $jsoncontent = $self->{http}->request();;
|
||||
|
||||
my $json = JSON->new;
|
||||
|
||||
|
@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::httplib;
|
||||
use centreon::plugins::http;
|
||||
use JSON;
|
||||
|
||||
sub new {
|
||||
@ -46,9 +46,10 @@ sub new {
|
||||
"cert-file:s" => { name => 'cert_file' },
|
||||
"key-file:s" => { name => 'key_file' },
|
||||
"cacert-file:s" => { name => 'cacert_file' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
});
|
||||
|
||||
$self->{http}->set_options(%{$self->{option_results}});
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -56,25 +57,17 @@ sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
$self->{option_results}->{url_path} = $self->{option_results}->{url_path}."containers/json";
|
||||
$self->{option_results}->{get_param} = [];
|
||||
push @{$self->{option_results}->{get_param}}, "all=true";
|
||||
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
$self->{http}->set_options(%{$self->{option_results}})
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $jsoncontent;
|
||||
|
||||
$self->{option_results}->{url_path} = $self->{option_results}->{url_path}."containers/json";
|
||||
my $query_form_get = { all => 'true' };
|
||||
$jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get, connection_exit => 'critical');
|
||||
my $jsoncontent = $self->{http}->request();
|
||||
|
||||
my $json = JSON->new;
|
||||
|
||||
|
@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::httplib;
|
||||
use centreon::plugins::http;
|
||||
use JSON;
|
||||
|
||||
sub new {
|
||||
@ -50,7 +50,7 @@ sub new {
|
||||
"cert-file:s" => { name => 'cert_file' },
|
||||
"key-file:s" => { name => 'key_file' },
|
||||
"cacert-file:s" => { name => 'cacert_file' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
@ -60,16 +60,6 @@ sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
if ((defined($self->{option_results}->{name})) && (defined($self->{option_results}->{id}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the name or id option");
|
||||
$self->{output}->option_exit();
|
||||
@ -89,21 +79,22 @@ sub check_options {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{option_results}->{get_param} = [];
|
||||
push @{$self->{option_results}->{get_param}}, "stream=false";
|
||||
if (defined($self->{option_results}->{id})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{id}."/stats";
|
||||
} elsif (defined($self->{option_results}->{name})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{name}."/stats";
|
||||
}
|
||||
|
||||
$self->{http}->set_options(%{$self->{option_results}});
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $jsoncontent;
|
||||
my $query_form_get = { stream => 'false' };
|
||||
|
||||
if (defined($self->{option_results}->{id})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{id}."/stats";
|
||||
$jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get, connection_exit => 'critical');
|
||||
} elsif (defined($self->{option_results}->{name})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{name}."/stats";
|
||||
$jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get, connection_exit => 'critical');
|
||||
}
|
||||
my $jsoncontent = $self->{http}->request();
|
||||
|
||||
my $json = JSON->new;
|
||||
|
||||
|
@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::httplib;
|
||||
use centreon::plugins::http;
|
||||
use centreon::plugins::statefile;
|
||||
use JSON;
|
||||
|
||||
@ -53,11 +53,11 @@ sub new {
|
||||
"cert-file:s" => { name => 'cert_file' },
|
||||
"key-file:s" => { name => 'key_file' },
|
||||
"cacert-file:s" => { name => 'cacert_file' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
"timeout:s" => { name => 'timeout' },
|
||||
});
|
||||
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
|
||||
$self->{http} = centreon::plugins::http->new(output => $self->{output});
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -65,14 +65,6 @@ sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ((defined($self->{option_results}->{name})) && (defined($self->{option_results}->{id}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the name or id option");
|
||||
$self->{output}->option_exit();
|
||||
@ -98,6 +90,15 @@ sub check_options {
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{option_results}->{get_param} = [];
|
||||
push @{$self->{option_results}->{get_param}}, "stream=false";
|
||||
if (defined($self->{option_results}->{id})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{id}."/stats";
|
||||
} elsif (defined($self->{option_results}->{name})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{name}."/stats";
|
||||
}
|
||||
|
||||
$self->{http}->set_options(%{$self->{option_results}});
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
}
|
||||
|
||||
@ -107,21 +108,12 @@ sub run {
|
||||
my $new_datas = {};
|
||||
|
||||
if (defined($self->{option_results}->{id})) {
|
||||
$self->{statefile_value}->read(statefile => 'docker_' . $self->{option_results}->{id} . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode});
|
||||
$self->{statefile_value}->read(statefile => 'docker_' . $self->{option_results}->{id} . '_' . $self->{http}->get_port() . '_' . $self->{mode});
|
||||
} elsif (defined($self->{option_results}->{name})) {
|
||||
$self->{statefile_value}->read(statefile => 'docker_' . $self->{option_results}->{name} . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode});
|
||||
$self->{statefile_value}->read(statefile => 'docker_' . $self->{option_results}->{name} . '_' . $self->{http}->get_port() . '_' . $self->{mode});
|
||||
}
|
||||
|
||||
my $jsoncontent;
|
||||
my $query_form_get = { stream => 'false' };
|
||||
|
||||
if (defined($self->{option_results}->{id})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{id}."/stats";
|
||||
$jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get, connection_exit => 'critical');
|
||||
} elsif (defined($self->{option_results}->{name})) {
|
||||
$self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{name}."/stats";
|
||||
$jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get, connection_exit => 'critical');
|
||||
}
|
||||
my $jsoncontent = $self->{http}->request();
|
||||
|
||||
my $json = JSON->new;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user