+ Enhance http class (Fix #108)

This commit is contained in:
garnier-quentin 2015-07-28 18:17:04 +02:00
parent 1c500841c0
commit aed5ed9304
49 changed files with 919 additions and 1128 deletions

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
sub new {
my ($class, %options) = @_;
@ -36,7 +36,7 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => "/server-status/?auto" },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
@ -44,8 +44,9 @@ sub new {
"proxyurl:s" => { name => 'proxyurl' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -61,20 +62,13 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
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();
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request();
# If not present: cpuload is 0
my ($cpuload) = 0;

View File

@ -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;
sub new {
@ -37,7 +37,7 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => "/server-status/?auto" },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
@ -49,8 +49,9 @@ sub new {
"critical-bytes:s" => { name => 'critical_bytes' },
"warning-access:s" => { name => 'warning_access' },
"critical-access:s" => { name => 'critical_access' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
return $self;
}
@ -83,22 +84,15 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Wrong critical-access threshold '" . $self->{option_results}->{critical_access} . "'.");
$self->{output}->option_exit();
}
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();
}
$self->{http}->set_options(%{$self->{option_results}});
$self->{statefile_value}->check_options(%options);
}
sub run {
my ($self, %options) = @_;
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request();
my ($rPerSec, $bPerReq, $total_access, $total_bytes, $avg_bPerSec);
$total_access = $1 if ($webcontent =~ /^Total Accesses:\s+([^\s]+)/mi);

View File

@ -25,7 +25,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use Time::HiRes qw(gettimeofday tv_interval);
use centreon::plugins::httplib;
use centreon::plugins::http;
sub new {
my ($class, %options) = @_;
@ -37,7 +37,7 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => "/server-status/?auto" },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
@ -45,8 +45,12 @@ sub new {
"proxyurl:s" => { name => 'proxyurl' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
"unknown-status:s" => { name => 'unknown_status', default => '' },
"warning-status:s" => { name => 'warning_status' },
"critical-status:s" => { name => 'critical_status', default => '%{http_code} < 200 or %{http_code} >= 300' },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -63,19 +67,7 @@ sub check_options {
$self->{output}->option_exit();
}
if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
$self->{output}->option_exit();
}
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();
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
@ -83,18 +75,19 @@ sub run {
my $timing0 = [gettimeofday];
my $webcontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical');
my $webcontent = $self->{http}->request();
my $timeelapsed = tv_interval ($timing0, [gettimeofday]);
my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed,
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Response time %fs ", $timeelapsed));
$self->{output}->perfdata_add(label => "time",
value => $timeelapsed,
short_msg => sprintf("Response time %.3fs", $timeelapsed));
$self->{output}->perfdata_add(label => "time", unit => 's',
value => sprintf('%.3f', $timeelapsed),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0);
$self->{output}->display();
$self->{output}->exit();
@ -146,6 +139,18 @@ Proxy URL if any
Threshold for HTTP timeout
=item B<--unknown-status>
Threshold warning for http response code
=item B<--warning-status>
Threshold warning for http response code
=item B<--critical-status>
Threshold critical for http response code (Default: '%{http_code} < 200 or %{http_code} >= 300')
=item B<--warning>
Threshold warning in seconds (server-status page response time)

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
sub new {
my ($class, %options) = @_;
@ -36,7 +36,7 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => "/server-status/?auto" },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
@ -44,8 +44,9 @@ sub new {
"proxyurl:s" => { name => 'proxyurl' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -61,26 +62,14 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
$self->{output}->option_exit();
}
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();
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request();
my $ScoreBoard = "";
if ($webcontent =~ /^Scoreboard:\s+([^\s]+)/mi) {
$ScoreBoard = $1;

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
sub new {
my ($class, %options) = @_;
@ -36,7 +36,7 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => "/server-status/?auto" },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
@ -44,8 +44,9 @@ sub new {
"proxyurl:s" => { name => 'proxyurl' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -61,25 +62,13 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
$self->{output}->option_exit();
}
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();
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request();
my ($BusyWorkers, $IdleWorkers, $ScoreBoard);
if ($webcontent =~ /^BusyWorkers:\s+([^\s]+)/mi) {
$BusyWorkers = $1;

View File

@ -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 Digest::MD5 qw(md5_hex);
use centreon::plugins::values;
@ -216,7 +216,7 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => "/apc.php" },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
@ -225,6 +225,7 @@ sub new {
"timeout:s" => { name => 'timeout', default => 30 },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
foreach (keys %{$maps_counters}) {
@ -246,25 +247,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();
}
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();
}
foreach (keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->init(option_results => $self->{option_results});
}
$self->{http}->set_options(%{$self->{option_results}});
$self->{statefile_value}->check_options(%options);
}
sub run {
my ($self, %options) = @_;
$self->{webcontent} = centreon::plugins::httplib::connect($self);
$self->{webcontent} = $self->{http}->request();
$self->manage_selection();

View File

@ -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::values;
my $maps_counters = {
@ -92,7 +92,7 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => "/apc.php" },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
@ -100,7 +100,9 @@ sub new {
"proxyurl:s" => { name => 'proxyurl' },
"timeout:s" => { name => 'timeout', default => 30 },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
foreach (keys %{$maps_counters}) {
$options{options}->add_options(arguments => {
'warning-' . $_ . ':s' => { name => 'warning-' . $_ },
@ -118,24 +120,17 @@ sub new {
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();
}
foreach (keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->init(option_results => $self->{option_results});
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
$self->{webcontent} = centreon::plugins::httplib::connect($self);
$self->{webcontent} = $self->{http}->request();
$self->manage_selection();

View File

@ -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;
@ -38,18 +38,18 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '8086'},
"proto:s" => { name => 'proto', default => 'http' },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => "/db" },
"database:s" => { name => 'database' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"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,10 +65,6 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
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}->{database})) {
$self->{output}->add_option_msg(short_msg => "Please set the database option");
$self->{output}->option_exit();
@ -77,7 +73,13 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= option");
$self->{output}->option_exit();
}
my $query = 'select sum("success") as "success_sum", sum("failure") as "failure_sum" from lmtpd.deliveries where time > '.$old_timestamp.'s and time < now()';
$self->{option_results}->{url_path} = $self->{option_results}->{url_path}."/".$self->{option_results}->{database}."/series";
$self->{option_results}->{get_param} = [];
push @{$self->{option_results}->{get_param}}, "q=" . $query, "p=" . $self->{option_results}->{password}, "u=" . $self->{option_results}->{username};
$self->{http}->set_options(%{$self->{option_results}});
$self->{statefile_value}->check_options(%options);
}
@ -98,14 +100,9 @@ sub run {
$self->{output}->exit();
}
$self->{option_results}->{url_path} = $self->{option_results}->{url_path}."/".$self->{option_results}->{database}."/series";
$self->{option_results}->{query} = 'select sum("success") as "success_sum", sum("failure") as "failure_sum" from lmtpd.deliveries where time > '.$old_timestamp.'s and time < now()';
my $query_form_get = { q => $self->{option_results}->{query}, p => $self->{option_results}->{password}, u => $self->{option_results}->{username} };
my $jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get);
my $jsoncontent = $self->{http}->request();
my $json = JSON->new;
my $webcontent;
eval {

View File

@ -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 = {
@ -50,10 +50,11 @@ sub new {
"urlpath:s" => { name => 'url_path', default => "/api/status" },
"proxyurl:s" => { name => 'proxyurl' },
"uid:s" => { name => 'uid' },
"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;
}
@ -88,19 +89,19 @@ sub check_options {
$self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status};
}
$self->{option_results}->{url_path} = $self->{option_results}->{url_path}."/".$self->{option_results}->{uid};
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
$self->{option_results}->{url_path} = $self->{option_results}->{url_path}."/".$self->{option_results}->{uid};
my $jsoncontent = centreon::plugins::httplib::connect($self);
my $jsoncontent = $self->{http}->request();
my $json = JSON->new;
my $webcontent;
eval {
$webcontent = $json->decode($jsoncontent);
};
@ -214,7 +215,7 @@ ID for checkmyws API
=item B<--timeout>
Threshold for HTTP timeout (Default: '3')
Threshold for HTTP timeout (Default: 5)
=item B<--threshold-overload>

View File

@ -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 = {
@ -45,15 +45,16 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '9200'},
"proto:s" => { name => 'proto', default => 'http' },
"urlpath:s" => { name => 'url_path', default => '/' },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path' },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"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;
}
@ -61,15 +62,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();
}
$self->{overload_th} = {};
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
if ($val !~ /^(.*?),(.*?),(.*)$/) {
@ -84,6 +76,9 @@ sub check_options {
$self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status};
}
$self->{option_results}->{url_path} = $self->{option_results}->{url_path} . "_cluster/health/";
$self->{http}->set_options(%{$self->{option_results}});
}
sub get_severity {
@ -111,9 +106,7 @@ sub get_severity {
sub run {
my ($self, %options) = @_;
$self->{option_results}->{url_path} = $self->{option_results}->{url_path}."_cluster/health/";
my $jsoncontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical');
my $jsoncontent = $self->{http}->request();
my $json = JSON->new;
@ -199,7 +192,7 @@ Specify password for API authentification
=item B<--timeout>
Threshold for HTTP timeout (Default: 3)
Threshold for HTTP timeout (Default: 5)
=item B<--threshold-overload>

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
use JSON;
use Data::Dumper;
@ -52,15 +52,16 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '9200'},
"proto:s" => { name => 'proto', default => 'http' },
"urlpath:s" => { name => 'url_path', default => '/' },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path' },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"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;
}
@ -68,15 +69,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();
}
$self->{overload_th} = {};
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
if ($val !~ /^(.*?),(.*?),(.*)$/) {
@ -92,6 +84,9 @@ sub check_options {
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status};
}
$self->{option_results}->{url_path} = $self->{option_results}->{url_path} . "_cluster/health";
$self->{option_results}->{get_param} = ['level=indices'];
$self->{http}->set_options(%{$self->{option_results}});
}
sub get_severity {
@ -119,10 +114,7 @@ sub get_severity {
sub run {
my ($self, %options) = @_;
$self->{option_results}->{url_path} = $self->{option_results}->{url_path}."_cluster/health";
my $query_form_get = { level => 'indices' };
my $jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get, connection_exit => 'critical');
my $jsoncontent = $self->{http}->request();
my $json = JSON->new;
my $webcontent;
@ -130,7 +122,6 @@ sub run {
eval {
$webcontent = $json->decode($jsoncontent);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode json response");
$self->{output}->option_exit();

View File

@ -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 {
@ -37,16 +37,17 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '9200'},
"proto:s" => { name => 'proto', default => 'http' },
"urlpath:s" => { name => 'url_path', default => '/' },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path' },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -54,15 +55,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 (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
@ -71,17 +63,17 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
$self->{option_results}->{url_path} = $self->{option_results}->{url_path} . "_cluster/stats/";
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
$self->{option_results}->{url_path} = $self->{option_results}->{url_path}."_cluster/stats/";
my $jsoncontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical');
my $jsoncontent = $self->{http}->request();
my $json = JSON->new;
my $webcontent;
eval {
@ -173,7 +165,7 @@ Threshold critical.
=item B<--timeout>
Threshold for HTTP timeout (Default: 3)
Threshold for HTTP timeout (Default: 5)
=back

View File

@ -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;
use DateTime;
@ -45,9 +45,10 @@ sub new {
"password:s" => { name => 'password' },
"owner:s" => { name => 'owner' },
"repository:s" => { name => 'repository' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
return $self;
@ -57,14 +58,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}->{repository})) {
$self->{output}->add_option_msg(short_msg => "Please set the repository option");
$self->{output}->option_exit();
@ -74,6 +67,8 @@ sub check_options {
$self->{output}->option_exit();
}
$self->{option_results}->{url_path} = "/repos/" . $self->{option_results}->{owner} . "/" . $self->{option_results}->{repository}."/commits";
$self->{http}->set_options(%{$self->{option_results}});
$self->{statefile_value}->check_options(%options);
}
@ -97,15 +92,10 @@ sub run {
# Change date format from epoch to iso8601
my $old_iso8601 = DateTime->from_epoch(epoch => $old_timestamp)."Z";
$self->{option_results}->{url_path} = "/repos/".$self->{option_results}->{owner}."/".$self->{option_results}->{repository}."/commits";
my $query_form_get = { per_page => '1000', since => $old_iso8601 };
my $jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get , connection_exit => 'critical');
my $jsoncontent = $self->{http}->request(get_param => ['per_page=1000', 'since=' . $old_iso8601]);
my $json = JSON->new;
my $webcontent;
eval {
$webcontent = $json->decode($jsoncontent);
};
@ -127,7 +117,6 @@ sub run {
$self->{output}->display();
$self->{output}->exit();
}
1;
@ -174,7 +163,7 @@ Specify GitHub's repository
=item B<--timeout>
Threshold for HTTP timeout (Default: 3)
Threshold for HTTP timeout (Default: 5)
=back

View File

@ -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 {
"owner:s" => { name => 'owner' },
"repository:s" => { name => 'repository' },
"label:s" => { name => 'label', default => '' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -56,14 +57,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}->{repository})) {
$self->{output}->add_option_msg(short_msg => "Please set the repository option");
$self->{output}->option_exit();
@ -73,33 +66,30 @@ sub check_options {
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
$self->{option_results}->{url_path} = "/repos/" . $self->{option_results}->{owner} . "/" . $self->{option_results}->{repository} . "/issues";
if (defined($self->{option_results}->{label}) && $self->{option_results}->{label} ne '') {
$self->{option_results}->{get_param} = ['state=open', 'labels=' . $self->{option_results}->{label}, 'per_page=1000'];
} else {
$self->{option_results}->{get_param} = ['state=open', 'per_page=1000'];
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
$self->{option_results}->{url_path} = "/repos/".$self->{option_results}->{owner}."/".$self->{option_results}->{repository} . "/issues";
my $query_form_get;
if (defined($self->{option_results}->{label}) && $self->{option_results}->{label} ne '') {
$query_form_get = { state => 'open', labels => $self->{option_results}->{label}, per_page => '1000' };
} else {
$query_form_get = { state => 'open', per_page => '1000' };
}
my $jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get , connection_exit => 'critical');
my $jsoncontent = $self->{http}->request();
my $json = JSON->new;
my $webcontent;
eval {
$webcontent = $json->decode($jsoncontent);
};
@ -136,7 +126,6 @@ sub run {
$self->{output}->display();
$self->{output}->exit();
}
1;

View File

@ -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 {
@ -36,7 +36,7 @@ sub new {
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname', default => 'api.github.com' },
"port:s" => { name => 'port', default => '443'},
"port:s" => { name => 'port', default => '443' },
"proto:s" => { name => 'proto', default => 'https' },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
@ -45,9 +45,10 @@ sub new {
"critical:s" => { name => 'critical' },
"owner:s" => { name => 'owner' },
"repository:s" => { name => 'repository' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -55,14 +56,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}->{repository})) {
$self->{output}->add_option_msg(short_msg => "Please set the repository option");
$self->{output}->option_exit();
@ -79,21 +72,19 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
$self->{option_results}->{url_path} = "/repos/".$self->{option_results}->{owner}."/".$self->{option_results}->{repository}."/pulls";
$self->{option_results}->{get_param} = ['state=open', 'per_page=1000'];
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
$self->{option_results}->{url_path} = "/repos/".$self->{option_results}->{owner}."/".$self->{option_results}->{repository}."/pulls";
my $query_form_get = { state => 'open', per_page => '1000' };
my $jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get , connection_exit => 'critical');
my $jsoncontent = $self->{http}->request();
my $json = JSON->new;
my $webcontent;
eval {
$webcontent = $json->decode($jsoncontent);
};
@ -118,7 +109,6 @@ sub run {
);
$self->{output}->display();
$self->{output}->exit();
}
1;
@ -173,7 +163,7 @@ Specify GitHub's repository
=item B<--timeout>
Threshold for HTTP timeout (Default: 3)
Threshold for HTTP timeout (Default: 5)
=back

View File

@ -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 = {
@ -50,10 +50,11 @@ sub new {
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"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;
}
@ -61,15 +62,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();
}
$self->{overload_th} = {};
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
if ($val !~ /^(.*?),(.*)$/) {
@ -84,6 +76,8 @@ sub check_options {
$self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status};
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub get_severity {
@ -110,12 +104,10 @@ sub get_severity {
sub run {
my ($self, %options) = @_;
my $jsoncontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical');
my $jsoncontent = $self->{http}->request();
my $json = JSON->new;
my $webcontent;
eval {
$webcontent = $json->decode($jsoncontent);
};
@ -132,7 +124,6 @@ sub run {
$self->{output}->display();
$self->{output}->exit();
}
1;
@ -175,7 +166,7 @@ Specify password
=item B<--timeout>
Threshold for HTTP timeout (Default: 3)
Threshold for HTTP timeout (Default: 5
=item B<--threshold-overload>

View File

@ -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;
@ -37,8 +37,8 @@ sub new {
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '80'},
"proto:s" => { name => 'proto', default => 'http' },
"port:s" => { name => 'port' },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path' },
"jobname:s" => { name => 'jobname' },
"credentials" => { name => 'credentials' },
@ -47,9 +47,10 @@ sub new {
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"checkstyle" => { name => 'checkstyle' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -65,32 +66,23 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
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}->{jobname})) {
$self->{output}->add_option_msg(short_msg => "Please set the jobname 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();
}
$self->{option_results}->{url_path} = $self->{option_results}->{url_path} . "/job/" . $self->{option_results}->{jobname} . "/api/json";
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
$self->{option_results}->{url_path} = $self->{option_results}->{url_path}."/job/".$self->{option_results}->{jobname}."/api/json";
my $jsoncontent = centreon::plugins::httplib::connect($self);
my $jsoncontent = $self->{http}->request();
my $json = JSON->new;
my $webcontent;
eval {
$webcontent = $json->decode($jsoncontent);
};
@ -187,7 +179,7 @@ Add checkstyle's violation output and perfdata
=item B<--timeout>
Threshold for HTTP timeout (Default: 3)
Threshold for HTTP timeout (Default: 5)
=back

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
use XML::XPath;
use Digest::SHA qw(hmac_sha256_base64);
@ -38,74 +38,49 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port' },
"proto:s" => { name => 'proto', default => "http" },
"urlpath:s" => { name => 'url_path', default => '/api/index.php?' },
"kayako-api-key:s" => { name => 'kayako_api_key' },
"kayako-secret-key:s" => { name => 'kayako_secret_key' },
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port' },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => '/api/index.php?' },
"kayako-api-key:s" => { name => 'kayako_api_key' },
"kayako-secret-key:s" => { name => 'kayako_secret_key' },
});
$self->set_signal_handlers;
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
sub set_signal_handlers {
my $self = shift;
$SIG{ALRM} = \&class_handle_ALRM;
$handlers{ALRM}->{$self} = sub { $self->handle_ALRM() };
}
sub class_handle_ALRM {
foreach (keys %{$handlers{ALRM}}) {
&{$handlers{ALRM}->{$_}}();
}
}
sub handle_ALRM {
my $self = shift;
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => sprintf("Cannot finished API execution (timeout received)"));
$self->{output}->display();
$self->{output}->exit();
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
$self->{option_results}->{timeout} > 0) {
alarm($self->{option_results}->{timeout});
}
if (!defined($self->{option_results}->{'kayako_api_key'})) {
if (!defined($self->{option_results}->{kayako_api_key})) {
$self->{output}->add_option_msg(short_msg => "Please specify an API key for Kayako.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{'kayako_secret_key'})) {
if (!defined($self->{option_results}->{kayako_secret_key})) {
$self->{output}->add_option_msg(short_msg => "Please specify a secret key for Kayako.");
$self->{output}->option_exit();
}
my $salt = '';
$salt .= int(rand(10)) for 1..10;
my $digest = hmac_sha256_base64($salt, $self->{option_results}->{kayako_secret_key});
$self->{option_results}->{url_path} .= "/Base/Department&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "=";
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
my $salt;
$salt .= int(rand(10)) for 1..10;
my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{'kayako_secret_key'});
$self->{option_results}->{'url_path'} .= "/Base/Department&apikey=" . $self->{option_results}->{'kayako_api_key'} . "&salt=" . $salt . "&signature=" . $digest . "=";
my $webcontent = centreon::plugins::httplib::connect($self);
my $xp = XML::XPath->new( $webcontent );
my $nodes = $xp->find('departments/department');
my $webcontent = $self->{http}->set_options(%{$self->{option_results}});
my $xp = XML::XPath->new($webcontent);
my $nodes = $xp->find('departments/department');
foreach my $actionNode ($nodes->get_nodelist) {
my ($id) = $xp->find('./id', $actionNode)->get_nodelist;
my $trim_id = centreon::plugins::misc::trim($id->string_value);
my ($title) = $xp->find('./title', $actionNode)->get_nodelist;
my $trim_title = centreon::plugins::misc::trim($title->string_value);
foreach my $actionNode ($nodes->get_nodelist) {
my ($id) = $xp->find('./id', $actionNode)->get_nodelist;
my $trim_id = centreon::plugins::misc::trim($id->string_value);
my ($title) = $xp->find('./title', $actionNode)->get_nodelist;
my $trim_title = centreon::plugins::misc::trim($title->string_value);
# print $trim_id." : ". $trim_title."\n";
# }
$self->{output}->output_add(long_msg => "'" . $trim_title . "' [id = " . $trim_id . "]");
}

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
use XML::XPath;
use Digest::SHA qw(hmac_sha256_base64);
@ -38,72 +38,49 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port' },
"proto:s" => { name => 'proto', default => "http" },
"urlpath:s" => { name => 'url_path', default => '/api/index.php?' },
"kayako-api-key:s" => { name => 'kayako_api_key' },
"kayako-secret-key:s" => { name => 'kayako_secret_key' },
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port' },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => '/api/index.php?' },
"kayako-api-key:s" => { name => 'kayako_api_key' },
"kayako-secret-key:s" => { name => 'kayako_secret_key' },
});
$self->set_signal_handlers;
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
sub set_signal_handlers {
my $self = shift;
$SIG{ALRM} = \&class_handle_ALRM;
$handlers{ALRM}->{$self} = sub { $self->handle_ALRM() };
}
sub class_handle_ALRM {
foreach (keys %{$handlers{ALRM}}) {
&{$handlers{ALRM}->{$_}}();
}
}
sub handle_ALRM {
my $self = shift;
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => sprintf("Cannot finished API execution (timeout received)"));
$self->{output}->display();
$self->{output}->exit();
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
$self->{option_results}->{timeout} > 0) {
alarm($self->{option_results}->{timeout});
}
if (!defined($self->{option_results}->{'kayako_api_key'})) {
if (!defined($self->{option_results}->{kayako_api_key})) {
$self->{output}->add_option_msg(short_msg => "Please specify an API key for Kayako.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{'kayako_secret_key'})) {
if (!defined($self->{option_results}->{kayako_secret_key})) {
$self->{output}->add_option_msg(short_msg => "Please specify a secret key for Kayako.");
$self->{output}->option_exit();
}
my $salt;
$salt .= int(rand(10)) for 1..10;
my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{kayako_secret_key});
$self->{option_results}->{url_path} .= "/Tickets/TicketPriority&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "=";
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
my $salt;
$salt .= int(rand(10)) for 1..10;
my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{'kayako_secret_key'});
$self->{option_results}->{'url_path'} .= "/Tickets/TicketPriority&apikey=" . $self->{option_results}->{'kayako_api_key'} . "&salt=" . $salt . "&signature=" . $digest . "=";
my $webcontent = centreon::plugins::httplib::connect($self);
my $xp = XML::XPath->new( $webcontent );
my $nodes = $xp->find('ticketpriorities/ticketpriority');
my $webcontent = $self->{http}->request();
my $xp = XML::XPath->new( $webcontent );
my $nodes = $xp->find('ticketpriorities/ticketpriority');
foreach my $actionNode ($nodes->get_nodelist) {
my ($id) = $xp->find('./id', $actionNode)->get_nodelist;
my $trim_id = centreon::plugins::misc::trim($id->string_value);
my ($title) = $xp->find('./title', $actionNode)->get_nodelist;
my $trim_title = centreon::plugins::misc::trim($title->string_value);
foreach my $actionNode ($nodes->get_nodelist) {
my ($id) = $xp->find('./id', $actionNode)->get_nodelist;
my $trim_id = centreon::plugins::misc::trim($id->string_value);
my ($title) = $xp->find('./title', $actionNode)->get_nodelist;
my $trim_title = centreon::plugins::misc::trim($title->string_value);
$self->{output}->output_add(long_msg => "'" . $trim_title . "' [id = " . $trim_id . "]");
}

View File

@ -24,12 +24,10 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
use XML::XPath;
use Digest::SHA qw(hmac_sha256_base64);
my %handlers = (ALRM => {} );
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@ -38,72 +36,50 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port' },
"proto:s" => { name => 'proto', default => "http" },
"urlpath:s" => { name => 'url_path', default => '/api/index.php?' },
"kayako-api-key:s" => { name => 'kayako_api_key' },
"kayako-secret-key:s" => { name => 'kayako_secret_key' },
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port' },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => '/api/index.php?' },
"kayako-api-key:s" => { name => 'kayako_api_key' },
"kayako-secret-key:s" => { name => 'kayako_secret_key' },
});
$self->set_signal_handlers;
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
sub set_signal_handlers {
my $self = shift;
$SIG{ALRM} = \&class_handle_ALRM;
$handlers{ALRM}->{$self} = sub { $self->handle_ALRM() };
}
sub class_handle_ALRM {
foreach (keys %{$handlers{ALRM}}) {
&{$handlers{ALRM}->{$_}}();
}
}
sub handle_ALRM {
my $self = shift;
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => sprintf("Cannot finished API execution (timeout received)"));
$self->{output}->display();
$self->{output}->exit();
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
$self->{option_results}->{timeout} > 0) {
alarm($self->{option_results}->{timeout});
}
if (!defined($self->{option_results}->{'kayako_api_key'})) {
if (!defined($self->{option_results}->{kayako_api_key})) {
$self->{output}->add_option_msg(short_msg => "Please specify an API key for Kayako.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{'kayako_secret_key'})) {
if (!defined($self->{option_results}->{kayako_secret_key})) {
$self->{output}->add_option_msg(short_msg => "Please specify a secret key for Kayako.");
$self->{output}->option_exit();
}
my $salt;
$salt .= int(rand(10)) for 1..10;
my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{'kayako_secret_key'});
$self->{option_results}->{url_path} .= "/Base/Staff&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "=";
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
my $salt;
$salt .= int(rand(10)) for 1..10;
my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{'kayako_secret_key'});
$self->{option_results}->{'url_path'} .= "/Base/Staff&apikey=" . $self->{option_results}->{'kayako_api_key'} . "&salt=" . $salt . "&signature=" . $digest . "=";
my $webcontent = centreon::plugins::httplib::connect($self);
my $xp = XML::XPath->new( $webcontent );
my $nodes = $xp->find('staffusers/staff');
my $webcontent = $self->{http}->request();
my $xp = XML::XPath->new( $webcontent );
my $nodes = $xp->find('staffusers/staff');
foreach my $actionNode ($nodes->get_nodelist) {
my ($id) = $xp->find('./id', $actionNode)->get_nodelist;
my $trim_id = centreon::plugins::misc::trim($id->string_value);
my ($title) = $xp->find('./username', $actionNode)->get_nodelist;
my $trim_title = centreon::plugins::misc::trim($title->string_value);
foreach my $actionNode ($nodes->get_nodelist) {
my ($id) = $xp->find('./id', $actionNode)->get_nodelist;
my $trim_id = centreon::plugins::misc::trim($id->string_value);
my ($title) = $xp->find('./username', $actionNode)->get_nodelist;
my $trim_title = centreon::plugins::misc::trim($title->string_value);
$self->{output}->output_add(long_msg => "'" . $trim_title . "' [id = " . $trim_id . "]");
}

View File

@ -24,12 +24,10 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
use XML::XPath;
use Digest::SHA qw(hmac_sha256_base64);
my %handlers = (ALRM => {} );
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@ -38,72 +36,50 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port' },
"proto:s" => { name => 'proto', default => "http" },
"urlpath:s" => { name => 'url_path', default => '/api/index.php?' },
"kayako-api-key:s" => { name => 'kayako_api_key' },
"kayako-secret-key:s" => { name => 'kayako_secret_key' },
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port' },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => '/api/index.php?' },
"kayako-api-key:s" => { name => 'kayako_api_key' },
"kayako-secret-key:s" => { name => 'kayako_secret_key' },
});
$self->set_signal_handlers;
return $self;
}
sub set_signal_handlers {
my $self = shift;
$SIG{ALRM} = \&class_handle_ALRM;
$handlers{ALRM}->{$self} = sub { $self->handle_ALRM() };
}
sub class_handle_ALRM {
foreach (keys %{$handlers{ALRM}}) {
&{$handlers{ALRM}->{$_}}();
}
}
sub handle_ALRM {
my $self = shift;
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => sprintf("Cannot finished scenario execution (timeout received)"));
$self->{output}->display();
$self->{output}->exit();
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
$self->{option_results}->{timeout} > 0) {
alarm($self->{option_results}->{timeout});
}
if (!defined($self->{option_results}->{'kayako_api_key'})) {
if (!defined($self->{option_results}->{kayako_api_key})) {
$self->{output}->add_option_msg(short_msg => "Please specify an API key for Kayako.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{'kayako_secret_key'})) {
if (!defined($self->{option_results}->{kayako_secret_key})) {
$self->{output}->add_option_msg(short_msg => "Please specify a secret key for Kayako.");
$self->{output}->option_exit();
}
my $salt;
$salt .= int(rand(10)) for 1..10;
my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{'kayako_secret_key'});
$self->{option_results}->{'url_path'} .= "/Tickets/TicketStatus&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "=";
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
my $salt;
$salt .= int(rand(10)) for 1..10;
my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{'kayako_secret_key'});
$self->{option_results}->{'url_path'} .= "/Tickets/TicketStatus&apikey=" . $self->{option_results}->{'kayako_api_key'} . "&salt=" . $salt . "&signature=" . $digest . "=";
my $webcontent = centreon::plugins::httplib::connect($self);
my $xp = XML::XPath->new( $webcontent );
my $nodes = $xp->find('ticketstatuses/ticketstatus');
foreach my $actionNode ($nodes->get_nodelist) {
my ($id) = $xp->find('./id', $actionNode)->get_nodelist;
my $trim_id = centreon::plugins::misc::trim($id->string_value);
my ($title) = $xp->find('./title', $actionNode)->get_nodelist;
my $trim_title = centreon::plugins::misc::trim($title->string_value);
my $webcontent = $self->{http}->request();
my $xp = XML::XPath->new($webcontent);
my $nodes = $xp->find('ticketstatuses/ticketstatus');
foreach my $actionNode ($nodes->get_nodelist) {
my ($id) = $xp->find('./id', $actionNode)->get_nodelist;
my $trim_id = centreon::plugins::misc::trim($id->string_value);
my ($title) = $xp->find('./title', $actionNode)->get_nodelist;
my $trim_title = centreon::plugins::misc::trim($title->string_value);
$self->{output}->output_add(long_msg => "'" . $trim_title . "' [id = " . $trim_id . "]");
}

View File

@ -25,7 +25,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::statefile;
use centreon::plugins::httplib;
use centreon::plugins::http;
use XML::XPath;
use Digest::SHA qw(hmac_sha256_base64);
use Time::Local;
@ -38,7 +38,6 @@ my @priority_filters;
my $ticket_total = 0;
my %tickets;
my $label;
my %handlers = (ALRM => {} );
sub new {
my ($class, %options) = @_;
@ -50,7 +49,7 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port' },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => '/api/index.php?' },
"kayako-api-key:s" => { name => 'kayako_api_key' },
"kayako-secret-key:s" => { name => 'kayako_secret_key' },
@ -64,82 +63,56 @@ sub new {
"start-date:s" => { name => 'start_date' },
"end-date:s" => { name => 'end_date' },
});
$self->set_signal_handlers;
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
sub set_signal_handlers {
my $self = shift;
$SIG{ALRM} = \&class_handle_ALRM;
$handlers{ALRM}->{$self} = sub { $self->handle_ALRM() };
}
sub class_handle_ALRM {
foreach (keys %{$handlers{ALRM}}) {
&{$handlers{ALRM}->{$_}}();
}
}
sub handle_ALRM {
my $self = shift;
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => sprintf("Cannot finished API execution (timeout received)"));
$self->{output}->display();
$self->{output}->exit();
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
$self->{option_results}->{timeout} > 0) {
alarm($self->{option_results}->{timeout});
}
if (!defined($self->{option_results}->{'kayako_api_key'})) {
if (!defined($self->{option_results}->{kayako_api_key})) {
$self->{output}->add_option_msg(short_msg => "Please specify an API key for Kayako.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{'kayako_secret_key'})) {
if (!defined($self->{option_results}->{kayako_secret_key})) {
$self->{output}->add_option_msg(short_msg => "Please specify a secret key for Kayako.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{'department_id'})) {
if (!defined($self->{option_results}->{department_id})) {
$self->{output}->add_option_msg(short_msg => "Please specify at least one department ID.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{'staff_id'})) {
$self->{option_results}->{'staff_id'} = "-1";
if (!defined($self->{option_results}->{staff_id})) {
$self->{option_results}->{staff_id} = "-1";
}
if (!defined($self->{option_results}->{'status_id'})) {
$self->{option_results}->{'status_id'} = "-1";
if (!defined($self->{option_results}->{status_id})) {
$self->{option_results}->{status_id} = "-1";
}
if (defined($self->{option_results}->{'priority_id'})) {
@priority_filters = split(/,/, $self->{option_results}->{'priority_id'});
if (defined($self->{option_results}->{priority_id})) {
@priority_filters = split(/,/, $self->{option_results}->{priority_id});
}
if (defined($self->{option_results}->{'start_date'})) {
if ($self->{option_results}->{'start_date'} !~ m/^\d{1,2}-\d{1,2}-\d{4}$/){
if (defined($self->{option_results}->{start_date})) {
if ($self->{option_results}->{start_date} !~ m/^\d{1,2}-\d{1,2}-\d{4}$/){
$self->{output}->add_option_msg(short_msg => "Please specify a valid date (DD-MM-YYYY).");
$self->{output}->option_exit();
} else {
my ($mday,$mon,$year) = split(/-/, $self->{option_results}->{'start_date'});
$start = $self->{option_results}->{'start_date'};
$self->{option_results}->{'start_date'} = timelocal(0,0,0,$mday,$mon-1,$year);
my ($mday,$mon,$year) = split(/-/, $self->{option_results}->{start_date});
$start = $self->{option_results}->{start_date};
$self->{option_results}->{start_date} = timelocal(0,0,0,$mday,$mon-1,$year);
}
}
if (defined($self->{option_results}->{'end_date'})) {
if ($self->{option_results}->{'end_date'} !~ m/^\d{1,2}-\d{1,2}-\d{4}$/){
if (defined($self->{option_results}->{end_date})) {
if ($self->{option_results}->{end_date} !~ m/^\d{1,2}-\d{1,2}-\d{4}$/){
$self->{output}->add_option_msg(short_msg => "Please specify a valid date (DD-MM-YYYY).");
$self->{output}->option_exit();
} else {
my ($mday,$mon,$year) = split(/-/, $self->{option_results}->{'end_date'});
$end = $self->{option_results}->{'end_date'};
$self->{option_results}->{'end_date'} = timelocal(59,59,23,$mday,$mon-1,$year);
my ($mday,$mon,$year) = split(/-/, $self->{option_results}->{end_date});
$end = $self->{option_results}->{end_date};
$self->{option_results}->{end_date} = timelocal(59,59,23,$mday,$mon-1,$year);
}
}
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
@ -153,6 +126,9 @@ sub check_options {
$self->{statefile_cache}->check_options(%options);
$self->{statefile_value}->check_options(%options);
$self->{http}->set_options(%{$self->{option_results}});
}
sub reload_cache {
@ -161,12 +137,12 @@ sub reload_cache {
$datas->{last_timestamp} = time();
my $salt;
my $salt = '';
$salt .= int(rand(10)) for 1..10;
my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{'kayako_secret_key'});
$self->{option_results}->{'url_path'} = $url_original_path . "/Base/Department&apikey=" . $self->{option_results}->{'kayako_api_key'} . "&salt=" . $salt . "&signature=" . $digest . "=";
my $webcontent = centreon::plugins::httplib::connect($self);
my $xp = XML::XPath->new( $webcontent );
my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{kayako_secret_key});
my $webcontent = $self->{http}->request(url_path => $url_original_path . "/Base/Department&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "=";);
my $xp = XML::XPath->new($webcontent);
my $nodes = $xp->find('departments/department');
foreach my $actionNode ($nodes->get_nodelist) {
my ($id) = $xp->find('./id', $actionNode)->get_nodelist;
@ -176,8 +152,7 @@ sub reload_cache {
$datas->{"department_".$trim_id} = $self->{output}->to_utf8($trim_title);
}
$self->{option_results}->{'url_path'} = $url_original_path . "/Tickets/TicketPriority&apikey=" . $self->{option_results}->{'kayako_api_key'} . "&salt=" . $salt . "&signature=" . $digest . "=";
$webcontent = centreon::plugins::httplib::connect($self);
$webcontent = $self->{http}->request(url_path => $url_original_path . "/Tickets/TicketPriority&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "=");
$xp = XML::XPath->new( $webcontent );
$nodes = $xp->find('ticketpriorities/ticketpriority');
foreach my $actionNode ($nodes->get_nodelist) {
@ -188,8 +163,7 @@ sub reload_cache {
$datas->{"priority_".$trim_id} = $self->{output}->to_utf8($trim_title);
}
$self->{option_results}->{'url_path'} = $url_original_path . "/Base/Staff&apikey=" . $self->{option_results}->{'kayako_api_key'} . "&salt=" . $salt . "&signature=" . $digest . "=";
$webcontent = centreon::plugins::httplib::connect($self);
$webcontent = $self->{http}->request(url_path => $url_original_path . "/Base/Staff&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "=");
$xp = XML::XPath->new( $webcontent );
$nodes = $xp->find('staffusers/staff');
foreach my $actionNode ($nodes->get_nodelist) {
@ -200,8 +174,7 @@ sub reload_cache {
$datas->{"staff_".$trim_id} = $self->{output}->to_utf8($trim_title);
}
$self->{option_results}->{'url_path'} = $url_original_path . "/Tickets/TicketStatus&apikey=" . $self->{option_results}->{'kayako_api_key'} . "&salt=" . $salt . "&signature=" . $digest . "=";
$webcontent = centreon::plugins::httplib::connect($self);
$webcontent = $self->{http}->request(url_path => $url_original_path . "/Tickets/TicketStatus&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "=");
$xp = XML::XPath->new( $webcontent );
$nodes = $xp->find('ticketstatuses/ticketstatus');
foreach my $actionNode ($nodes->get_nodelist) {
@ -217,10 +190,10 @@ sub reload_cache {
sub run {
my ($self, %options) = @_;
my $salt;
my $salt = '';
$salt .= int(rand(10)) for 1..10;
my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{'kayako_secret_key'});
$url_original_path = $self->{option_results}->{'url_path'};
my $digest = hmac_sha256_base64($salt, $self->{option_results}->{kayako_secret_key});
$url_original_path = $self->{option_results}->{url_path};
my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_api_' . ($self->{option_results}->{hostname}) . '_kayako');
my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp');
@ -230,8 +203,7 @@ sub run {
$self->{statefile_cache}->read();
}
$self->{option_results}->{'url_path'} = $url_original_path . "/Tickets/Ticket/ListAll/" . $self->{option_results}->{'department_id'} . "/" . $self->{option_results}->{'status_id'} . "/" . $self->{option_results}->{'staff_id'} . "/-1/-1/1420120620/-1/-1&apikey=" . $self->{option_results}->{'kayako_api_key'} . "&salt=" . $salt . "&signature=" . $digest . "=";
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request(url_path => $url_original_path . "/Tickets/Ticket/ListAll/" . $self->{option_results}->{department_id} . "/" . $self->{option_results}->{status_id} . "/" . $self->{option_results}->{staff_id} . "/-1/-1/1420120620/-1/-1&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "=");
my $xp = XML::XPath->new( $webcontent );
my $nodes = $xp->find('tickets/ticket');
@ -243,9 +215,9 @@ sub run {
my $trim_priorityid = centreon::plugins::misc::trim($priorityid->string_value);
my ($date) = $xp->find('./lastactivity', $actionNode)->get_nodelist;
my $trim_date = centreon::plugins::misc::trim($date->string_value);
if (defined($self->{option_results}->{'start_date'}) and (defined($self->{option_results}->{'end_date'}))) {
if ($trim_date > $self->{option_results}->{'start_date'} and $trim_date < $self->{option_results}->{'end_date'}) {
if (defined($self->{option_results}->{'priority_id'})){
if (defined($self->{option_results}->{start_date}) and (defined($self->{option_results}->{end_date}))) {
if ($trim_date > $self->{option_results}->{start_date} and $trim_date < $self->{option_results}->{end_date}) {
if (defined($self->{option_results}->{priority_id})){
foreach $priority_filter (@priority_filters) {
if ($priority_filter == $trim_priorityid){
$tickets{$priority_filter}++;
@ -256,9 +228,9 @@ sub run {
$ticket_total++;
}
}
} elsif (defined($self->{option_results}->{'start_date'}) and (!defined($self->{option_results}->{'end_date'}))) {
if ($trim_date > $self->{option_results}->{'start_date'}) {
if (defined($self->{option_results}->{'priority_id'})){
} elsif (defined($self->{option_results}->{start_date}) and (!defined($self->{option_results}->{end_date}))) {
if ($trim_date > $self->{option_results}->{start_date}) {
if (defined($self->{option_results}->{priority_id})){
foreach $priority_filter (@priority_filters) {
if ($priority_filter == $trim_priorityid){
$tickets{$priority_filter}++;
@ -269,9 +241,9 @@ sub run {
$ticket_total++;
}
}
} elsif (!defined($self->{option_results}->{'start_date'}) and (defined($self->{option_results}->{'end_date'}))) {
if ($trim_date < $self->{option_results}->{'end_date'}) {
if (defined($self->{option_results}->{'priority_id'})){
} elsif (!defined($self->{option_results}->{start_date}) and (defined($self->{option_results}->{end_date}))) {
if ($trim_date < $self->{option_results}->{end_date}) {
if (defined($self->{option_results}->{priority_id})){
foreach $priority_filter (@priority_filters) {
if ($priority_filter == $trim_priorityid){
$tickets{$priority_filter}++;
@ -283,7 +255,7 @@ sub run {
}
}
} else {
if (defined($self->{option_results}->{'priority_id'})){
if (defined($self->{option_results}->{priority_id})){
foreach $priority_filter (@priority_filters) {
if ($priority_filter == $trim_priorityid){
$tickets{$priority_filter}++;
@ -299,32 +271,32 @@ sub run {
###########
# Manage Output
###########
my $exit = $self->{perfdata}->threshold_check(value => $ticket_total, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
my $exit = $self->{perfdata}->threshold_check(value => $ticket_total, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
my $staff = "";
my $ticket_status = "";
my $period = "";
if (defined($self->{option_results}->{'staff_id'}) && ($self->{option_results}->{'staff_id'} =~ m/^\d*$/)) {
$staff = " for staff '" . $self->{statefile_cache}->get(name => 'staff_'.$self->{option_results}->{'staff_id'}) ."'";
if (defined($self->{option_results}->{staff_id}) && ($self->{option_results}->{staff_id} =~ m/^\d*$/)) {
$staff = " for staff '" . $self->{statefile_cache}->get(name => 'staff_'.$self->{option_results}->{staff_id}) ."'";
}
if (defined($self->{option_results}->{'status_id'}) && ($self->{option_results}->{'status_id'} =~ m/^\d*$/)) {
$ticket_status = " in status '" . $self->{statefile_cache}->get(name => 'status_'.$self->{option_results}->{'status_id'}) ."'";
if (defined($self->{option_results}->{status_id}) && ($self->{option_results}->{status_id} =~ m/^\d*$/)) {
$ticket_status = " in status '" . $self->{statefile_cache}->get(name => 'status_'.$self->{option_results}->{status_id}) ."'";
}
if (defined($self->{option_results}->{'start_date'}) || defined($self->{option_results}->{'end_date'})){
if (defined($self->{option_results}->{start_date}) || defined($self->{option_results}->{end_date})){
$period = " -";
}
if (defined($self->{option_results}->{'start_date'})){
if (defined($self->{option_results}->{start_date})){
$start = " Start: " . $start;
}
if (defined($self->{option_results}->{'end_date'})){
if (defined($self->{option_results}->{end_date})){
$end = " End: " . $end;
}
if (defined($self->{option_results}->{'priority_id'})){
if (defined($self->{option_results}->{priority_id})){
foreach $priority_filter (@priority_filters) {
$label = $self->{statefile_cache}->get(name => 'priority_'.$priority_filter);
$self->{output}->perfdata_add(label => $label, value => $tickets{$priority_filter},

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
my $maps = [
{ counter => 'active', output => 'Active connections %d', match => 'Active connections:\s*(\d+)' },
@ -43,13 +43,13 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => "/nginx_status" },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"proxyurl:s" => { name => 'proxyurl' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
});
foreach (@{$maps}) {
$options{options}->add_options(arguments => {
@ -57,6 +57,8 @@ sub new {
'critical-' . $_->{counter} . ':s' => { name => 'critical_' . $_->{counter} },
});
}
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -74,25 +76,14 @@ sub check_options {
$self->{output}->option_exit();
}
}
if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
$self->{output}->option_exit();
}
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();
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request();
foreach (@{$maps}) {
if ($webcontent !~ /$_->{match}/msi) {
$self->{output}->output_add(severity => 'UNKNOWN',

View File

@ -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;
my $maps = [
@ -43,13 +43,13 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => "/nginx_status" },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"proxyurl:s" => { name => 'proxyurl' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
});
foreach (@{$maps}) {
$options{options}->add_options(arguments => {
@ -58,6 +58,7 @@ sub new {
});
}
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -75,22 +76,15 @@ sub check_options {
$self->{output}->option_exit();
}
}
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();
}
$self->{statefile_value}->check_options(%options);
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request();
my ($buffer_creation, $exit) = (0, 0);
my $new_datas = {};
my $old_datas = {};

View File

@ -25,7 +25,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use Time::HiRes qw(gettimeofday tv_interval);
use centreon::plugins::httplib;
use centreon::plugins::http;
sub new {
my ($class, %options) = @_;
@ -37,7 +37,7 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => "/nginx_status" },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
@ -45,8 +45,12 @@ sub new {
"proxyurl:s" => { name => 'proxyurl' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
"unknown-status:s" => { name => 'unknown_status', default => '' },
"warning-status:s" => { name => 'warning_status' },
"critical-status:s" => { name => 'critical_status', default => '%{http_code} < 200 or %{http_code} >= 300' },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -63,19 +67,7 @@ sub check_options {
$self->{output}->option_exit();
}
if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
$self->{output}->option_exit();
}
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();
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
@ -83,12 +75,12 @@ sub run {
my $timing0 = [gettimeofday];
my $webcontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical');
my $webcontent = $self->{http}->request();
my $timeelapsed = tv_interval ($timing0, [gettimeofday]);
my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed,
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Response time %fs ", $timeelapsed));
$self->{output}->perfdata_add(label => "time",
@ -146,6 +138,18 @@ Proxy URL if any
Threshold for HTTP timeout
=item B<--unknown-status>
Threshold warning for http response code
=item B<--warning-status>
Threshold warning for http response code
=item B<--critical-status>
Threshold critical for http response code (Default: '%{http_code} < 200 or %{http_code} >= 300')
=item B<--warning>
Threshold warning in seconds (nginx_status page response time)

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
sub new {
my ($class, %options) = @_;
@ -35,23 +35,33 @@ sub new {
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"http-peer-addr:s" => { name => 'http_peer_addr' },
"port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" },
"urlpath:s" => { name => 'url_path', default => "/" },
"method:s" => { name => 'method' },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path' },
"credentials" => { name => 'credentials' },
"ntlm" => { name => 'ntlm' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"proxyurl:s" => { name => 'proxyurl' },
"expected-string:s" => { name => 'expected_string' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
"ssl:s" => { name => 'ssl', },
"cert-file:s" => { name => 'cert_file' },
"key-file:s" => { name => 'key_file' },
"cacert-file:s" => { name => 'cacert_file' },
"cert-pwd:s" => { name => 'cert_pwd' },
"cert-pkcs12" => { name => 'cert_pkcs12' },
"header:s@" => { name => 'header' },
"get-param:s@" => { name => 'get_param' },
"post-param:s@" => { name => 'post_param' },
"cookies-file:s" => { name => 'cookies_file' },
"unknown-status:s" => { name => 'unknown_status' },
"warning-status:s" => { name => 'warning_status' },
"critical-status:s" => { name => 'critical_status' },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -59,36 +69,17 @@ sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (!defined($self->{option_results}->{hostname})) {
$self->{output}->add_option_msg(short_msg => "You need to specify hostname.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{expected_string})) {
$self->{output}->add_option_msg(short_msg => "You need to specify --expected-string 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}->{credentials})) && (defined($self->{option_results}->{ntlm}))) {
$self->{output}->add_option_msg(short_msg => "--ntlm option must be used with --credentials option");
$self->{output}->option_exit();
}
if ((defined($self->{option_results}->{pkcs12})) && (!defined($self->{option_results}->{cert_file}) && !defined($self->{option_results}->{cert_pwd}))) {
$self->{output}->add_option_msg(short_msg => "You need to set --cert-file= and --cert-pwd= options when --pkcs12 is used");
$self->{output}->option_exit();
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
if (!defined($self->{option_results}->{port})) {
$self->{option_results}->{port} = centreon::plugins::httplib::get_port($self);
}
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request();
$self->{output}->output_add(long_msg => $webcontent);
if ($webcontent =~ /$self->{option_results}->{expected_string}/mi) {
@ -116,6 +107,10 @@ Check Webpage content
IP Addr/FQDN of the Webserver host
=item B<--http-peer-addr>
Set the address you want to connect (Useful if hostname is only a vhost. no ip resolve)
=item B<--port>
Port used by Webserver
@ -124,9 +119,13 @@ Port used by Webserver
Proxy URL if any
=item B<--method>
Specify http method used (Default: 'GET')
=item B<--proto>
Specify https if needed
Specify https if needed (Default: 'http')
=item B<--urlpath>
@ -150,7 +149,7 @@ Specify password for basic authentification (Mandatory if --credentials is speci
=item B<--timeout>
Threshold for HTTP timeout
Threshold for HTTP timeout (Default: 5)
=item B<--ssl>
@ -176,6 +175,34 @@ Specify certificate's password
Specify type of certificate (PKCS12)
=item B<--header>
Set HTTP headers (Multiple option)
=item B<--get-param>
Set GET params (Multiple option. Example: --get-param='key=value')
=item B<--post-param>
Set POST params (Multiple option. Example: --post-param='key=value')
=item B<--cookies-file>
Save cookies in a file (Example: '/tmp/lwp_cookies.dat')
=item B<--unknown-status>
Threshold warning for http response code (Default: '%{http_code} < 200 or %{http_code} >= 300')
=item B<--warning-status>
Threshold warning for http response code
=item B<--critical-status>
Threshold critical for http response code
=item B<--expected-string>
Specify String to check on the Webpage

View File

@ -25,7 +25,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use Time::HiRes qw(gettimeofday tv_interval);
use centreon::plugins::httplib;
use centreon::plugins::http;
use JSON::Path;
use JSON;
@ -40,9 +40,11 @@ sub new {
"data:s" => { name => 'data' },
"lookup:s@" => { name => 'lookup' },
"hostname:s" => { name => 'hostname' },
"http-peer-addr:s" => { name => 'http_peer_addr' },
"vhost:s" => { name => 'vhost' },
"port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" },
"urlpath:s" => { name => 'url_path', default => "/" },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path' },
"credentials" => { name => 'credentials' },
"ntlm" => { name => 'ntlm' },
"username:s" => { name => 'username' },
@ -57,6 +59,9 @@ sub new {
"cacert-file:s" => { name => 'cacert_file' },
"cert-pwd:s" => { name => 'cert_pwd' },
"cert-pkcs12" => { name => 'cert_pkcs12' },
"unknown-status:s" => { name => 'unknown_status' },
"warning-status:s" => { name => 'warning_status' },
"critical-status:s" => { name => 'critical_status' },
"warning-numeric:s" => { name => 'warning_numeric' },
"critical-numeric:s" => { name => 'critical_numeric' },
@ -80,6 +85,7 @@ sub new {
$self->{values_string_ok} = [];
$self->{values_string_warning} = [];
$self->{values_string_critical} = [];
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -106,47 +112,8 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Wrong critical-time threshold '" . $self->{option_results}->{critical_time} . "'.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{hostname})) {
$self->{output}->add_option_msg(short_msg => "You need to specify hostname.");
$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}->{credentials})) && (defined($self->{option_results}->{ntlm}))) {
$self->{output}->add_option_msg(short_msg => "--ntlm option must be used with --credentials option");
$self->{output}->option_exit();
}
if ((defined($self->{option_results}->{pkcs12})) && (!defined($self->{option_results}->{cert_file}) && !defined($self->{option_results}->{cert_pwd}))) {
$self->{output}->add_option_msg(short_msg => "You need to set --cert-file= and --cert-pwd= options when --pkcs12 is used");
$self->{output}->option_exit();
}
$self->{headers} = {};
if (defined($self->{option_results}->{header})) {
foreach (@{$self->{option_results}->{header}}) {
if (/^(.*?):(.*)/) {
$self->{headers}->{$1} = $2;
}
}
}
$self->{get_params} = {};
if (defined($self->{option_results}->{get_param})) {
foreach (@{$self->{option_results}->{get_param}}) {
if (/^([^=]+)={0,1}(.*)$/) {
my $key = $1;
my $value = defined($2) ? $2 : 1;
if (defined($self->{get_params}->{$key})) {
if (ref($self->{get_params}->{$key}) ne 'ARRAY') {
$self->{get_params}->{$key} = [ $self->{get_params}->{$key} ];
}
push @{$self->{get_params}->{$key}}, $value;
} else {
$self->{get_params}->{$key} = $value;
}
}
}
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub load_request {
@ -265,14 +232,10 @@ sub lookup {
sub run {
my ($self, %options) = @_;
if (!defined($self->{option_results}->{port})) {
$self->{option_results}->{port} = centreon::plugins::httplib::get_port($self);
}
$self->load_request();
my $timing0 = [gettimeofday];
$self->{json_response} = centreon::plugins::httplib::connect($self, headers => $self->{headers}, method => $self->{method},
query_form_get => $self->{get_params}, query_form_post => $self->{json_request});
$self->{json_response} = $self->{http}->request(method => $self->{method}, query_form_post => $self->{json_request});
my $timeelapsed = tv_interval ($timing0, [gettimeofday]);
$self->{output}->output_add(long_msg => $self->{json_response});
@ -395,6 +358,10 @@ HTTP OPTIONS:
IP Addr/FQDN of the Webserver host
=item B<--http-peer-addr>
Set the address you want to connect (Useful if hostname is only a vhost. no ip resolve)
=item B<--port>
Port used by Webserver
@ -463,6 +430,18 @@ Set GET params (Multiple option. Example: --get-param='key=value')
Set HTTP headers (Multiple option. Example: --header='Content-Type: xxxxx')
=item B<--unknown-status>
Threshold warning for http response code (Default: '%{http_code} < 200 or %{http_code} >= 300')
=item B<--warning-status>
Threshold warning for http response code
=item B<--critical-status>
Threshold critical for http response code
=back
=cut

View File

@ -25,7 +25,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use Time::HiRes qw(gettimeofday tv_interval);
use centreon::plugins::httplib;
use centreon::plugins::http;
sub new {
my ($class, %options) = @_;
@ -36,9 +36,11 @@ sub new {
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"http-peer-addr:s" => { name => 'http_peer_addr' },
"port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" },
"urlpath:s" => { name => 'url_path', default => "/" },
"method:s" => { name => 'method' },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path' },
"credentials" => { name => 'credentials' },
"ntlm" => { name => 'ntlm' },
"username:s" => { name => 'username' },
@ -46,14 +48,23 @@ sub new {
"proxyurl:s" => { name => 'proxyurl' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
"ssl:s" => { name => 'ssl' },
"cert-file:s" => { name => 'cert_file' },
"key-file:s" => { name => 'key_file' },
"cacert-file:s" => { name => 'cacert_file' },
"cert-pwd:s" => { name => 'cert_pwd' },
"cert-pkcs12" => { name => 'cert_pkcs12' },
"header:s@" => { name => 'header' },
"get-param:s@" => { name => 'get_param' },
"post-param:s@" => { name => 'post_param' },
"cookies-file:s" => { name => 'cookies_file' },
"unknown-status:s" => { name => 'unknown_status', default => '' },
"warning-status:s" => { name => 'warning_status' },
"critical-status:s" => { name => 'critical_status', default => '%{http_code} < 200 or %{http_code} >= 300' },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -70,37 +81,17 @@ sub check_options {
$self->{output}->option_exit();
}
if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
$self->{output}->option_exit();
}
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}->{pkcs12})) && (!defined($self->{option_results}->{cert_file}) && !defined($self->{option_results}->{cert_pwd}))) {
$self->{output}->add_option_msg(short_msg => "You need to set --cert-file= and --cert-pwd= options when --pkcs12 is used");
$self->{output}->option_exit();
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
if (!defined($self->{option_results}->{port})) {
$self->{option_results}->{port} = centreon::plugins::httplib::get_port($self);
}
my $timing0 = [gettimeofday];
my $webcontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical');
my $webcontent = $self->{http}->request();
my $timeelapsed = tv_interval ($timing0, [gettimeofday]);
my $timeelapsed = tv_interval($timing0, [gettimeofday]);
$self->{output}->output_add(long_msg => $webcontent);
@ -108,10 +99,11 @@ sub run {
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Response time %.3fs", $timeelapsed));
$self->{output}->perfdata_add(label => "time",
$self->{output}->perfdata_add(label => "time", unit => 's',
value => sprintf('%.3f', $timeelapsed),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0);
$self->{output}->display();
$self->{output}->exit();
@ -131,13 +123,21 @@ Check Webpage Time Response
IP Addr/FQDN of the webserver host
=item B<--http-peer-addr>
Set the address you want to connect (Useful if hostname is only a vhost. no ip resolve)
=item B<--port>
Port used by Webserver
=item B<--method>
Specify http method used (Default: 'GET')
=item B<--proto>
Specify https if needed
Specify https if needed (Default: 'http')
=item B<--urlpath>
@ -165,20 +165,12 @@ Proxy URL if any
=item B<--timeout>
Threshold for HTTP timeout
Threshold for HTTP timeout (Default: 5)
=item B<--ssl>
Specify SSL version (example : 'sslv3', 'tlsv1'...)
=item B<--warning>
Threshold warning in seconds (Webpage response time)
=item B<--critical>
Threshold critical in seconds (Webpage response time)
=item B<--cert-file>
Specify certificate to send to the webserver
@ -199,6 +191,42 @@ Specify certificate's password
Specify type of certificate (PKCS12)
=item B<--header>
Set HTTP headers (Multiple option)
=item B<--get-param>
Set GET params (Multiple option. Example: --get-param='key=value')
=item B<--post-param>
Set POST params (Multiple option. Example: --post-param='key=value')
=item B<--cookies-file>
Save cookies in a file (Example: '/tmp/lwp_cookies.dat')
=item B<--unknown-status>
Threshold warning for http response code
=item B<--warning-status>
Threshold warning for http response code
=item B<--critical-status>
Threshold critical for http response code (Default: '%{http_code} < 200 or %{http_code} >= 300')
=item B<--warning>
Threshold warning in seconds (Webpage response time)
=item B<--critical>
Threshold critical in seconds (Webpage response time)
=back
=cut

View File

@ -25,7 +25,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use Time::HiRes qw(gettimeofday tv_interval);
use centreon::plugins::httplib;
use centreon::plugins::http;
use XML::XPath;
sub new {
@ -40,9 +40,11 @@ sub new {
"data:s" => { name => 'data' },
"lookup:s@" => { name => 'lookup' },
"hostname:s" => { name => 'hostname' },
"http-peer-addr:s" => { name => 'http_peer_addr' },
"vhost:s" => { name => 'vhost' },
"port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" },
"urlpath:s" => { name => 'url_path', default => "/" },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path' },
"credentials" => { name => 'credentials' },
"ntlm" => { name => 'ntlm' },
"username:s" => { name => 'username' },
@ -56,6 +58,9 @@ sub new {
"cacert-file:s" => { name => 'cacert_file' },
"cert-pwd:s" => { name => 'cert_pwd' },
"cert-pkcs12" => { name => 'cert_pkcs12' },
"unknown-status:s" => { name => 'unknown_status' },
"warning-status:s" => { name => 'warning_status' },
"critical-status:s" => { name => 'critical_status' },
"warning-numeric:s" => { name => 'warning_numeric' },
"critical-numeric:s" => { name => 'critical_numeric' },
@ -79,6 +84,7 @@ sub new {
$self->{values_string_ok} = [];
$self->{values_string_warning} = [];
$self->{values_string_critical} = [];
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -113,31 +119,9 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "You need to specify data.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{hostname})) {
$self->{output}->add_option_msg(short_msg => "You need to specify hostname.");
$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}->{credentials})) && (defined($self->{option_results}->{ntlm}))) {
$self->{output}->add_option_msg(short_msg => "--ntlm option must be used with --credentials option");
$self->{output}->option_exit();
}
if ((defined($self->{option_results}->{pkcs12})) && (!defined($self->{option_results}->{cert_file}) && !defined($self->{option_results}->{cert_pwd}))) {
$self->{output}->add_option_msg(short_msg => "You need to set --cert-file= and --cert-pwd= options when --pkcs12 is used");
$self->{output}->option_exit();
}
$self->{headers} = {};
if (defined($self->{option_results}->{header})) {
foreach (@{$self->{option_results}->{header}}) {
if (/^(.*?):(.*)/) {
$self->{headers}->{$1} = $2;
}
}
}
$self->{headers}->{SOAPAction} = $self->{option_results}->{service_soap};
$self->{http}->set_options(%{$self->{option_results}});
$self->{http}->add_header(key => 'SOAPAction', value => $self->{option_results}->{service_soap});
}
sub load_request {
@ -257,13 +241,10 @@ sub lookup {
sub run {
my ($self, %options) = @_;
if (!defined($self->{option_results}->{port})) {
$self->{option_results}->{port} = centreon::plugins::httplib::get_port($self);
}
$self->load_request();
my $timing0 = [gettimeofday];
$self->{soap_response} = centreon::plugins::httplib::connect($self, headers => $self->{headers}, method => 'POST', query_form_post => $self->{soap_request});
$self->{soap_response} = $self->{http}->request(method => 'POST', query_form_post => $self->{soap_request});
my $timeelapsed = tv_interval ($timing0, [gettimeofday]);
$self->{output}->output_add(long_msg => $self->{soap_response});
@ -390,6 +371,10 @@ HTTP OPTIONS:
IP Addr/FQDN of the Webserver host
=item B<--http-peer-addr>
Set the address you want to connect (Useful if hostname is only a vhost. no ip resolve)
=item B<--port>
Port used by Webserver
@ -454,6 +439,18 @@ Specify type of certificate (PKCS1
Set HTTP headers (Multiple option)
=item B<--unknown-status>
Threshold warning for http response code (Default: '%{http_code} < 200 or %{http_code} >= 300')
=item B<--warning-status>
Threshold warning for http response code
=item B<--critical-status>
Threshold critical for http response code
=back
=cut

View File

@ -23,7 +23,7 @@ package apps::tomcat::web::mode::applications;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
sub new {
my ($class, %options) = @_;
@ -35,12 +35,12 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '8080' },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"proxyurl:s" => { name => 'proxyurl' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
"urlpath:s" => { name => 'url_path', default => '/manager/text/list' },
"name:s" => { name => 'name' },
"regexp" => { name => 'use_regexp' },
@ -49,7 +49,7 @@ sub new {
});
$self->{result} = {};
$self->{hostname} = undef;
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -57,27 +57,15 @@ sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
$self->{output}->option_exit();
}
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();
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub manage_selection {
my ($self, %options) = @_;
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request();
while ($webcontent =~ m/(.*):(.*):(.*):(.*)/g) {
while ($webcontent =~ m/(.*):(.*):(.*):(.*)/g) {
my ($context, $state, $sessions, $contextpath) = ($1, $2, $3, $4);
next if (defined($self->{option_results}->{filter_path}) && $self->{option_results}->{filter_path} ne '' &&

View File

@ -23,7 +23,7 @@ package apps::tomcat::web::mode::listapplication;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
sub new {
my ($class, %options) = @_;
@ -35,12 +35,12 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '8080' },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"proxyurl:s" => { name => 'proxyurl' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
"urlpath:s" => { name => 'url_path', default => '/manager/text/list' },
"filter-name:s" => { name => 'filter_name', },
"filter-state:s" => { name => 'filter_state', },
@ -48,7 +48,7 @@ sub new {
});
$self->{result} = {};
$self->{hostname} = undef;
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -56,25 +56,13 @@ sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
$self->{output}->option_exit();
}
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();
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub manage_selection {
my ($self, %options) = @_;
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request();
while ($webcontent =~ m/(.*):(.*):(.*):(.*)/g) {
my ($context, $state, $sessions, $contextpath) = ($1, $2, $3, $4);

View File

@ -23,7 +23,7 @@ package apps::tomcat::web::mode::memory;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
use XML::XPath;
sub new {
@ -36,38 +36,26 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '8080' },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"proxyurl:s" => { name => 'proxyurl' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
"urlpath:s" => { name => 'url_path', default => '/manager/status?XML=true' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
});
$self->{result} = {};
$self->{hostname} = undef;
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
$self->{output}->option_exit();
}
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 (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
@ -77,6 +65,7 @@ sub check_options {
$self->{output}->option_exit();
}
$self->{http}->set_options(%{$self->{option_results}});
}
my %xpath_to_check = (
@ -88,7 +77,7 @@ my %xpath_to_check = (
sub run {
my ($self, %options) = @_;
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request();
my $port = $self->{option_results}->{port};
#EXAMPLE 1:

View File

@ -23,7 +23,7 @@ package apps::tomcat::web::mode::requestinfo;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
use XML::XPath;
@ -39,12 +39,12 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '8080' },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"proxyurl:s" => { name => 'proxyurl' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
"urlpath:s" => { name => 'url_path', default => '/manager/status?XML=true' },
"name:s" => { name => 'name' },
"regexp" => { name => 'use_regexp' },
@ -69,18 +69,6 @@ sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
$self->{output}->option_exit();
}
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();
}
#MaxTime
if (($self->{perfdata}->threshold_validate(label => 'warning-maxtime', value => $self->{option_results}->{warning_maxtime})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning 'warning-maxtime' threshold '" . $self->{option_results}->{warning_maxtime} . "'.");
@ -123,6 +111,8 @@ sub check_options {
if (!defined($self->{hostname})) {
$self->{hostname} = 'me';
}
$self->{http}->set_options(%{$self->{option_results}});
}
my %xpath_to_check = (
@ -135,7 +125,7 @@ my %xpath_to_check = (
sub manage_selection {
my ($self, %options) = @_;
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request();
my $port = $self->{option_results}->{port};
#EXAMPLE 1:
@ -207,12 +197,12 @@ sub manage_selection {
};
if (scalar(keys %{$self->{result}}) <= 0) {
if (defined($self->{option_results}->{name})) {
$self->{output}->add_option_msg(short_msg => "No information found for name '" . $self->{option_results}->{name} . "'.");
} else {
$self->{output}->add_option_msg(short_msg => "No information found.");
}
$self->{output}->option_exit();
if (defined($self->{option_results}->{name})) {
$self->{output}->add_option_msg(short_msg => "No information found for name '" . $self->{option_results}->{name} . "'.");
} else {
$self->{output}->add_option_msg(short_msg => "No information found.");
}
$self->{output}->option_exit();
};
};
};

View File

@ -23,7 +23,7 @@ package apps::tomcat::web::mode::sessions;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
sub new {
my ($class, %options) = @_;
@ -35,12 +35,12 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '8080' },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"proxyurl:s" => { name => 'proxyurl' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
"urlpath:s" => { name => 'url_path', default => '/manager/text/list' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
@ -52,7 +52,7 @@ sub new {
});
$self->{result} = {};
$self->{hostname} = undef;
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -60,18 +60,6 @@ sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
$self->{output}->option_exit();
}
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 (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
@ -80,15 +68,15 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub manage_selection {
my ($self, %options) = @_;
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request();
while ($webcontent =~ m/(.*):(.*):(.*):(.*)/g) {
while ($webcontent =~ m/(.*):(.*):(.*):(.*)/g) {
my ($context, $state, $sessions, $contextpath) = ($1, $2, $3, $4);
next if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' &&

View File

@ -23,7 +23,7 @@ package apps::tomcat::web::mode::threads;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
use XML::XPath;
use URI::Escape;
@ -37,12 +37,12 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '8080' },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"proxyurl:s" => { name => 'proxyurl' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
"urlpath:s" => { name => 'url_path', default => '/manager/status?XML=true' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
@ -53,6 +53,7 @@ sub new {
$self->{result} = {};
$self->{hostname} = undef;
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -60,18 +61,6 @@ sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
$self->{output}->option_exit();
}
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 (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
@ -81,6 +70,7 @@ sub check_options {
$self->{output}->option_exit();
}
$self->{http}->set_options(%{$self->{option_results}});
}
my %xpath_to_check = (
@ -92,7 +82,7 @@ my %xpath_to_check = (
sub manage_selection {
my ($self, %options) = @_;
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request();
my $port = $self->{option_results}->{port};
#EXAMPLE 1:

View File

@ -23,7 +23,7 @@ package apps::tomcat::web::mode::traffic;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
use XML::XPath;
@ -39,12 +39,12 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => '8080' },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"proxyurl:s" => { name => 'proxyurl' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
"urlpath:s" => { name => 'url_path', default => '/manager/status?XML=true' },
"name:s" => { name => 'name' },
"regexp" => { name => 'use_regexp' },
@ -59,6 +59,7 @@ sub new {
$self->{result} = {};
$self->{hostname} = undef;
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -66,18 +67,6 @@ sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
$self->{output}->option_exit();
}
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 (($self->{perfdata}->threshold_validate(label => 'warning-in', value => $self->{option_results}->{warning_in})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning 'in' threshold '" . $self->{option_results}->{warning_in} . "'.");
$self->{output}->option_exit();
@ -109,6 +98,8 @@ sub check_options {
if (!defined($self->{hostname})) {
$self->{hostname} = 'me';
}
$self->{http}->set_options(%{$self->{option_results}});
}
my %xpath_to_check = (
@ -119,7 +110,7 @@ my %xpath_to_check = (
sub manage_selection {
my ($self, %options) = @_;
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request();
my $port = $self->{option_results}->{port};
#EXAMPLE 1:

268
centreon/plugins/http.pm Normal file
View File

@ -0,0 +1,268 @@
#
# Copyright 2015 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package centreon::plugins::http;
use strict;
use warnings;
use centreon::plugins::misc;
use LWP::UserAgent;
use HTTP::Cookies;
use URI;
use IO::Socket::SSL;
sub new {
my ($class, %options) = @_;
my $self = {};
bless $self, $class;
$self->{output} = $options{output};
$self->{ua} = undef;
$self->{options} = {
proto => 'http',
url_path => '/',
timeout => 5,
method => 'GET',
unknown_status => '%{http_code} < 200 or %{http_code} >= 300',
warning_status => undef,
critical_status => undef,
};
$self->{add_headers} = {};
return $self;
}
sub set_options {
my ($self, %options) = @_;
$self->{options} = { %{$self->{options}} };
foreach (keys %options) {
$self->{options}->{$_} = $options{$_} if (defined($options{$_}));
}
}
sub add_header {
my ($self, %options) = @_;
$self->{add_headers}->{$options{key}} = $options{value};
}
sub check_options {
my ($self, %options) = @_;
if (($options{request}->{proto} ne 'http') && ($options{request}->{proto} ne 'https')) {
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
$self->{output}->option_exit();
}
if (!defined($options{request}->{hostname})) {
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
$self->{output}->option_exit();
}
if ((defined($options{request}->{credentials})) && (!defined($options{request}->{username}) || !defined($options{request}->{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($options{request}->{pkcs12})) && (!defined($options{request}->{cert_file}) && !defined($options{request}->{cert_pwd}))) {
$self->{output}->add_option_msg(short_msg => "You need to set --cert-file= and --cert-pwd= options when --pkcs12 is used");
$self->{output}->option_exit();
}
$options{request}->{port} = $self->get_port();
$options{request}->{headers} = {};
if (defined($options{request}->{header})) {
foreach (@{$options{request}->{header}}) {
if (/^(.*?):(.*)/) {
$options{request}->{headers}->{$1} = $2;
}
}
}
foreach (keys %{$self->{add_headers}}) {
$options{request}->{headers}->{$_} = $self->{add_headers}->{$_};
}
foreach my $method (('get', 'post')) {
if (defined($options{request}->{$method . '_param'})) {
$self->{$method . '_params'} = {};
foreach (@{$options{request}->{$method . '_param'}}) {
if (/^([^=]+)={0,1}(.*)$/) {
my $key = $1;
my $value = defined($2) ? $2 : 1;
if (defined($self->{$method . '_params'}->{$key})) {
if (ref($self->{$method . '_params'}->{$key}) ne 'ARRAY') {
$self->{$method . '_params'}->{$key} = [ $self->{$method . '_params'}->{$key} ];
}
push @{$self->{$method . '_params'}->{$key}}, $value;
} else {
$self->{$method . '_params'}->{$key} = $value;
}
}
}
}
}
foreach (('unknown_status', 'warning_status', 'critical_status')) {
if (defined($options{request}->{$_})) {
$options{request}->{$_} =~ s/%\{http_code\}/\$response->code/g;
}
}
}
sub get_port {
my ($self, %options) = @_;
my $port = '';
if (defined($self->{options}->{port}) && $self->{options}->{port} ne '') {
$port = $self->{options}->{port};
} else {
$port = 80 if ($self->{options}->{proto} eq 'http');
$port = 443 if ($self->{options}->{proto} eq 'https');
}
return $port;
}
sub request {
my ($self, %options) = @_;
my $request_options = { %{$self->{options}} };
foreach (keys %options) {
$request_options->{$_} = $options{$_} if (defined($options{$_}));
}
$self->check_options(request => $request_options);
if (!defined($self->{ua})) {
$self->{ua} = LWP::UserAgent->new(keep_alive => 1, protocols_allowed => ['http', 'https'], timeout => $request_options->{timeout},
requests_redirectable => [ 'GET', 'HEAD', 'POST' ]);
if (defined($request_options->{cookies_file})) {
$self->{ua}->cookie_jar(HTTP::Cookies->new(file => $request_options->{cookies_file},
autosave => 1));
}
}
if (defined($request_options->{http_peer_addr})) {
push @LWP::Protocol::http::EXTRA_SOCK_OPTS, PeerAddr => $request_options->{http_peer_addr};
}
my ($response, $content);
my ($req, $url);
if (defined($request_options->{port}) && $request_options->{port} =~ /^[0-9]+$/) {
$url = $request_options->{proto}. "://" . $request_options->{hostname} . ':' . $request_options->{port} . $request_options->{url_path};
} else {
$url = $request_options->{proto}. "://" . $request_options->{hostname} . $request_options->{url_path};
}
my $uri = URI->new($url);
if (defined($self->{get_params})) {
$uri->query_form($self->{get_params});
}
$req = HTTP::Request->new($request_options->{method}, $uri);
my $content_type_forced;
foreach my $key (keys %{$request_options->{headers}}) {
if ($key !~ /content-type/i) {
$req->header($key => $request_options->{headers}->{$key});
} else {
$content_type_forced = $request_options->{headers}->{$key};
}
}
if ($request_options->{method} eq 'POST') {
if (defined($content_type_forced)) {
$req->content_type($content_type_forced);
$req->content($request_options->{query_form_post});
} else {
my $uri_post = URI->new();
if (defined($self->{post_params})) {
$uri_post->query_form($self->{post_params});
}
$req->content_type('application/x-www-form-urlencoded');
$req->content($uri_post->query);
}
}
if (defined($request_options->{credentials}) && defined($request_options->{ntlm})) {
$self->{ua}->credentials($request_options->{hostname} . ':' . $request_options->{port}, '', $request_options->{username}, $request_options->{password});
} elsif (defined($request_options->{credentials})) {
$req->authorization_basic($request_options->{username}, $request_options->{password});
}
if (defined($request_options->{proxyurl})) {
$self->{ua}->proxy(['http', 'https'], $request_options->{proxyurl});
}
if (defined($request_options->{cert_pkcs12}) && $request_options->{cert_file} ne '' && $request_options->{cert_pwd} ne '') {
eval "use Net::SSL"; die $@ if $@;
$ENV{HTTPS_PKCS12_FILE} = $request_options->{cert_file};
$ENV{HTTPS_PKCS12_PASSWORD} = $request_options->{cert_pwd};
}
my $ssl_context;
if (defined($request_options->{ssl}) && $request_options->{ssl} ne '') {
$ssl_context = { SSL_version => $request_options->{ssl} };
}
if (defined($request_options->{cert_file}) && !defined($request_options->{cert_pkcs12})) {
$ssl_context = {} if (!defined($ssl_context));
$ssl_context->{SSL_use_cert} = 1;
$ssl_context->{SSL_cert_file} = $request_options->{cert_file};
$ssl_context->{SSL_key_file} = $request_options->{key_file} if (defined($request_options->{key_file}));
$ssl_context->{SSL_ca_file} = $request_options->{cacert_file} if (defined($request_options->{cacert_file}));
}
if (defined($ssl_context)) {
my $context = new IO::Socket::SSL::SSL_Context(%{$ssl_context});
IO::Socket::SSL::set_default_context($context);
}
$response = $self->{ua}->request($req);
# Check response
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($request_options->{critical_status}) && $request_options->{critical_status} ne '' &&
eval "$request_options->{critical_status}") {
$status = 'critical';
} elsif (defined($request_options->{warning_status}) && $request_options->{warning_status} ne '' &&
eval "$request_options->{warning_status}") {
$status = 'warning';
} elsif (defined($request_options->{unknown_status}) && $request_options->{unknown_status} ne '' &&
eval "$request_options->{unknown_status}") {
$status = 'unknown';
}
};
if (defined($message)) {
$self->{output}->add_option_msg(short_msg => 'filter status issue: ' . $message);
$self->{output}->option_exit();
}
if (!$self->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $status,
short_msg => $response->status_line);
$self->{output}->display();
$self->{output}->exit();
}
return $response->content;
}
1;

View File

@ -1,141 +0,0 @@
#
# Copyright 2015 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package centreon::plugins::httplib;
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Cookies;
use URI;
use IO::Socket::SSL;
sub get_port {
my ($self, %options) = @_;
my $cache_port = '';
if (defined($self->{option_results}->{port}) && $self->{option_results}->{port} ne '') {
$cache_port = $self->{option_results}->{port};
} else {
$cache_port = 80 if ($self->{option_results}->{proto} eq 'http');
$cache_port = 443 if ($self->{option_results}->{proto} eq 'https');
}
return $cache_port;
}
sub connect {
my ($self, %options) = @_;
my $method = defined($options{method}) ? $options{method} : 'GET';
my $connection_exit = defined($options{connection_exit}) ? $options{connection_exit} : 'unknown';
my $ua = LWP::UserAgent->new(keep_alive => 1, protocols_allowed => ['http', 'https'], timeout => $self->{option_results}->{timeout},
requests_redirectable => [ 'GET', 'HEAD', 'POST' ]);
if (defined($options{cookies_file})) {
$ua->cookie_jar(HTTP::Cookies->new(file => $options{cookies_file},
autosave => 1));
}
my ($response, $content);
my ($req, $url);
if (defined($self->{option_results}->{port}) && $self->{option_results}->{port} =~ /^[0-9]+$/) {
$url = $self->{option_results}->{proto}. "://" . $self->{option_results}->{hostname}.':'. $self->{option_results}->{port} . $self->{option_results}->{url_path};
} else {
$url = $self->{option_results}->{proto}. "://" . $self->{option_results}->{hostname} . $self->{option_results}->{url_path};
}
my $uri = URI->new($url);
if (defined($options{query_form_get})) {
$uri->query_form($options{query_form_get});
}
$req = HTTP::Request->new($method => $uri);
my $content_type_forced;
if (defined($options{headers})) {
foreach my $key (keys %{$options{headers}}) {
if ($key !~ /content-type/i) {
$req->header($key => $options{headers}->{$key});
} else {
$content_type_forced = $options{headers}->{$key};
}
}
}
if ($method eq 'POST') {
if (defined($content_type_forced)) {
$req->content_type($content_type_forced);
$req->content($options{query_form_post});
} else {
my $uri_post = URI->new();
if (defined($options{query_form_post})) {
$uri_post->query_form($options{query_form_post});
}
$req->content_type('application/x-www-form-urlencoded');
$req->content($uri_post->query);
}
}
if (defined($self->{option_results}->{credentials}) && defined($self->{option_results}->{ntlm})) {
$ua->credentials($self->{option_results}->{hostname} . ':' . $self->{option_results}->{port}, '', $self->{option_results}->{username}, $self->{option_results}->{password});
} elsif (defined($self->{option_results}->{credentials})) {
$req->authorization_basic($self->{option_results}->{username}, $self->{option_results}->{password});
}
if (defined($self->{option_results}->{proxyurl})) {
$ua->proxy(['http', 'https'], $self->{option_results}->{proxyurl});
}
if (defined($self->{option_results}->{cert_pkcs12}) && $self->{option_results}->{cert_file} ne '' && $self->{option_results}->{cert_pwd} ne '') {
eval "use Net::SSL"; die $@ if $@;
$ENV{HTTPS_PKCS12_FILE} = $self->{option_results}->{cert_file};
$ENV{HTTPS_PKCS12_PASSWORD} = $self->{option_results}->{cert_pwd};
}
my $ssl_context;
if (defined($self->{option_results}->{ssl}) && $self->{option_results}->{ssl} ne '') {
$ssl_context = { SSL_version => $self->{option_results}->{ssl} };
}
if (defined($self->{option_results}->{cert_file}) && !defined($self->{option_results}->{cert_pkcs12})) {
$ssl_context = {} if (!defined($ssl_context));
$ssl_context->{SSL_use_cert} = 1;
$ssl_context->{SSL_cert_file} = $self->{option_results}->{cert_file};
$ssl_context->{SSL_key_file} = $self->{option_results}->{key_file} if (defined($self->{option_results}->{key_file}));
$ssl_context->{SSL_ca_file} = $self->{option_results}->{cacert_file} if (defined($self->{option_results}->{cacert_file}));
}
if (defined($ssl_context)) {
my $context = new IO::Socket::SSL::SSL_Context(%{$ssl_context});
IO::Socket::SSL::set_default_context($context);
}
$response = $ua->request($req);
if ($response->is_success) {
$content = $response->content;
return $content;
}
$self->{output}->output_add(severity => $connection_exit,
short_msg => $response->status_line);
$self->{output}->display();
$self->{output}->exit();
}
1;

View File

@ -318,13 +318,13 @@ sub powershell_escape {
sub minimal_version {
my ($version_src, $version_dst) = @_;
# No Version. We skip
if (!defined($version_src) || !defined($version_dst) ||
$version_src !~ /^[0-9]+(?:\.[0-9\.])*$/ || $version_dst !~ /^[0-9x]+(?:\.[0-9x\.])*$/) {
$version_src !~ /^[0-9]+(?:\.[0-9\.]+)*$/ || $version_dst !~ /^[0-9x]+(?:\.[0-9x]+)*$/) {
return 1;
}
my @version_src = split /\./, $version_src;
my @versions = split /\./, $version_dst;
for (my $i = 0; $i < scalar(@versions); $i++) {

View File

@ -1192,7 +1192,7 @@ To use it, add the following line at the beginning of your **mode**:
.. code-block:: perl
use centreon::plugins::httplib;
use centreon::plugins::http;
Some options must be set in **plugin.pm**:
@ -1244,7 +1244,9 @@ We suppose these options are defined :
.. code-block:: perl
my $webcontent = centreon::plugins::httplib::connect($self);
$self->{http} = centreon::plugins::http->new(output => $self->{output});
$self->{http}->set_options(%{$self->{option_results}});
my $webcontent = $self->{http}->request();
print $webcontent;
Output displays content of the webpage '\http://google.com/'.

View File

@ -1191,7 +1191,7 @@ Pour l'utiliser, ajouter la ligne suivante au début de votre **mode** :
.. code-block:: perl
use centreon::plugins::httplib;
use centreon::plugins::http;
Certaines options doivent être spécifiées dans **plugin.pm** :
@ -1243,7 +1243,9 @@ Nous supposons que ces options sont définies :
.. code-block:: perl
my $webcontent = centreon::plugins::httplib::connect($self);
$self->{http} = centreon::plugins::http->new(output => $self->{output});
$self->{http}->set_options(%{$self->{option_results}});
my $webcontent = $self->{http}->request();
print $webcontent;
La sortie affichera le contenu de la page web '\http://google.com/'.

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
sub new {
my ($class, %options) = @_;
@ -36,7 +36,7 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => "/index.htm?eL" },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
@ -45,9 +45,10 @@ sub new {
"warning" => { name => 'warning' },
"critical" => { name => 'critical' },
"closed" => { name => 'closed' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
});
$self->{status} = { closed => 'ok', opened => 'ok' };
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -63,20 +64,13 @@ sub check_options {
$self->{status}->{$label} = 'warning';
}
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();
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request();
my $contact;
if ($webcontent !~ /<body>(.*)<\/body>/msi || $1 !~ /([NW]).*?:/) {

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
sub new {
my ($class, %options) = @_;
@ -36,8 +36,8 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" },
"urlpath:s" => { name => 'url_path', default => "/" },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path' },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
@ -45,9 +45,10 @@ sub new {
"warning" => { name => 'warning' },
"critical" => { name => 'critical' },
"dry" => { name => 'dry' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
});
$self->{status} = { dry => 'ok', wet => 'ok' };
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -63,20 +64,13 @@ sub check_options {
$self->{status}->{$label} = 'warning';
}
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();
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request();
my $flood;
if ($webcontent !~ /<body>(.*)<\/body>/msi || $1 !~ /(dry|wet)/i) {

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
sub new {
my ($class, %options) = @_;
@ -36,7 +36,7 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => "/index.htm?em" },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
@ -44,8 +44,9 @@ sub new {
"proxyurl:s" => { name => 'proxyurl' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -61,20 +62,13 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
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();
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request();
my $humidity;
if ($webcontent !~ /<body>(.*)<\/body>/msi || $1 !~ /HU:\s*([0-9\.]+)/i) {

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
sub new {
my ($class, %options) = @_;
@ -36,7 +36,7 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => "/index.htm?em" },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
@ -44,8 +44,9 @@ sub new {
"proxyurl:s" => { name => 'proxyurl' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -61,20 +62,13 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
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();
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request();
my $illumination;
if ($webcontent !~ /<body>(.*)<\/body>/msi || $1 !~ /IL(?:\s*:\s*|\s*)([0-9\.]+)/i) {

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
sub new {
my ($class, %options) = @_;
@ -36,7 +36,7 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => "/index.htm?em" },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
@ -44,8 +44,9 @@ sub new {
"proxyurl:s" => { name => 'proxyurl' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -61,20 +62,13 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
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();
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request();
if ($webcontent !~ /<body>(.*)<\/body>/msi || $1 !~ /T([CF]):\s*([0-9\.]+)/i) {
$self->{output}->add_option_msg(short_msg => "Could not find temperature information.");

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
sub new {
my ($class, %options) = @_;
@ -36,7 +36,7 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => "/index.htm?eR" },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
@ -44,8 +44,9 @@ sub new {
"proxyurl:s" => { name => 'proxyurl' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -61,20 +62,13 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
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();
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request();
if ($webcontent !~ /<body>(.*)<\/body>/msi || $1 !~ /R([CF])\s*([0-9\.]+)/i) {
$self->{output}->add_option_msg(short_msg => "Could not find thermistor temperature information.");

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
sub new {
my ($class, %options) = @_;
@ -36,7 +36,7 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', },
"proto:s" => { name => 'proto', default => "http" },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => "/index.htm?ev" },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
@ -44,8 +44,9 @@ sub new {
"proxyurl:s" => { name => 'proxyurl' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"timeout:s" => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout' },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
@ -61,20 +62,13 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
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();
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
my $webcontent = centreon::plugins::httplib::connect($self);
my $webcontent = $self->{http}->request();
my $voltage;
if ($webcontent !~ /<body>(.*)<\/body>/msi || $1 !~ /CV\s*([0-9\.]+)/i) {

View File

@ -22,7 +22,7 @@ package storage::hp::p2000::xmlapi::custom;
use strict;
use warnings;
use centreon::plugins::httplib;
use centreon::plugins::http;
use XML::XPath;
use Digest::MD5 qw(md5_hex);
@ -108,7 +108,7 @@ sub check_options {
$self->{proto} = (defined($self->{option_results}->{proto})) ? shift(@{$self->{option_results}->{proto}}) : 'http';
$self->{url_path} = (defined($self->{option_results}->{url_path})) ? shift(@{$self->{option_results}->{url_path}}) : '/api/';
$self->{proxyurl} = (defined($self->{option_results}->{proxyurl})) ? shift(@{$self->{option_results}->{proxyurl}}) : undef;
if (!defined($self->{hostname})) {
$self->{output}->add_option_msg(short_msg => "Need to specify hostname option.");
$self->{output}->option_exit();
@ -129,8 +129,6 @@ sub build_options_for_httplib {
my ($self, %options) = @_;
$self->{option_results}->{hostname} = $self->{hostname};
$self->{option_results}->{username} = $self->{username};
$self->{option_results}->{password} = $self->{password};
$self->{option_results}->{timeout} = $self->{timeout};
$self->{option_results}->{port} = $self->{port};
$self->{option_results}->{proto} = $self->{proto};
@ -179,9 +177,9 @@ sub DESTROY {
my $self = shift;
if ($self->{logon} == 1) {
$self->{option_results}->{url_path} = $self->{url_path} . 'exit';
centreon::plugins::httplib::connect($self,
headers => {dataType => 'api', sessionKey => $self->{session_id} });
$self->{option_results}->{url_path} = ;
$self->{http}->request(url_path => $self->{url_path} . 'exit',
header => ['dataType: api', 'sessionKey: ' . $self->{session_id}]);
}
}
@ -191,9 +189,8 @@ sub get_infos {
my $cmd = $options{cmd};
$cmd =~ s/ /\//g;
$self->{option_results}->{url_path} = $self->{url_path} . $cmd;
my $response = centreon::plugins::httplib::connect($self,
headers => {dataType => 'api', sessionKey => $self->{session_id} });
my $response =$self->{http}->request(url_path => $self->{url_path} . $cmd,
header => ['dataType: api', 'sessionKey: '. $self->{session_id}]);
eval {
$xpath = XML::XPath->new(xml => $response);
@ -232,11 +229,12 @@ sub login {
my ($self, %options) = @_;
$self->build_options_for_httplib();
$self->{http} = centreon::plugins::http->new(output => $self->{output});
$self->{http}->set_options(%{$self->{option_results}});
# Login First
my $md5_hash = md5_hex($self->{username} . '_' . $self->{password});
$self->{option_results}->{url_path} = $self->{url_path} . 'login/' . $md5_hash;
my $response = centreon::plugins::httplib::connect($self);
my $response = $self->{http}->request(url_path => $self->{url_path} . 'login/' . $md5_hash);
$self->check_login(content => $response);
}