mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-23 21:55:16 +02:00
minor typo and add unknown http status (#2300)
This commit is contained in:
parent
4509782456
commit
89a12b2bc4
@ -72,32 +72,22 @@ sub set_defaults {}
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : undef;
|
||||
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : '';
|
||||
$self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 80;
|
||||
$self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'http';
|
||||
$self->{url_path} = (defined($self->{option_results}->{url_path})) ? $self->{option_results}->{url_path} : '/v0/';
|
||||
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10;
|
||||
$self->{api_username} = (defined($self->{option_results}->{api_username})) ? $self->{option_results}->{api_username} : undef;
|
||||
$self->{api_password} = (defined($self->{option_results}->{api_password})) ? $self->{option_results}->{api_password} : undef;
|
||||
$self->{unknown_http_status} = (defined($self->{option_results}->{unknown_http_status})) ? $self->{option_results}->{unknown_status} : '';
|
||||
$self->{unknown_http_status} = (defined($self->{option_results}->{unknown_http_status})) ? $self->{option_results}->{unknown_status} : '%{http_code} < 200 or %{http_code} >= 300';
|
||||
$self->{warning_http_status} = (defined($self->{option_results}->{warning_http_status})) ? $self->{option_results}->{warning_status} : '';
|
||||
$self->{critical_http_status} = (defined($self->{option_results}->{critical_http_status})) ? $self->{option_results}->{critical_status} : '';
|
||||
|
||||
if (!defined($self->{hostname}) || $self->{hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify hostname option.");
|
||||
if ($self->{hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => 'Need to specify hostname option.');
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
#if (!defined($self->{api_username}) || $self->{api_username} eq '') {
|
||||
# $self->{output}->add_option_msg(short_msg => "Need to specify --api-username option.");
|
||||
# $self->{output}->option_exit();
|
||||
#}
|
||||
|
||||
#if (!defined($self->{api_password}) || $self->{api_password} eq '') {
|
||||
# $self->{output}->add_option_msg(short_msg => "Need to specify --api-password option.");
|
||||
# $self->{output}->option_exit();
|
||||
#}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -110,19 +100,19 @@ sub settings {
|
||||
|
||||
sub get_connection_info {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
||||
return $self->{hostname} . ":" . $self->{port};
|
||||
}
|
||||
|
||||
sub get_hostname {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
||||
return $self->{hostname};
|
||||
}
|
||||
|
||||
sub get_port {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
||||
return $self->{port};
|
||||
}
|
||||
|
||||
@ -133,7 +123,7 @@ sub json_decode {
|
||||
eval {
|
||||
$decoded = JSON::XS->new->utf8->decode($options{content});
|
||||
};
|
||||
|
||||
|
||||
if ($@) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@");
|
||||
$self->{output}->option_exit();
|
||||
@ -146,8 +136,7 @@ sub request_api {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->settings();
|
||||
|
||||
my $content = $self->{http}->request(
|
||||
my ($content) = $self->{http}->request(
|
||||
url_path => $self->{url_path} . $options{endpoint},
|
||||
unknown_status => $self->{unknown_http_status},
|
||||
warning_status => $self->{warning_http_status},
|
||||
@ -155,7 +144,6 @@ sub request_api {
|
||||
);
|
||||
|
||||
my $decoded = $self->json_decode(content => $content);
|
||||
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'filter-testcase:s' => { name => 'filter_testcase' },
|
||||
'filter-testcase:s' => { name => 'filter_testcase' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
@ -40,7 +40,7 @@ sub new {
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
||||
my $result = $options{custom}->request_api(endpoint => 'testcases');
|
||||
return $result->{testcases};
|
||||
}
|
||||
@ -49,14 +49,14 @@ sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $testcases = $self->manage_selection(%options);
|
||||
foreach my $testcase (values $testcases) {
|
||||
foreach my $testcase (@$testcases) {
|
||||
next if (defined($self->{option_results}->{filter_testcase})
|
||||
&& $self->{option_results}->{filter_testcase} ne ''
|
||||
&& $testcase->{testcase_alias} !~ /$self->{option_results}->{filter_testcase}/ );
|
||||
&& $testcase->{testcase_alias} !~ /$self->{option_results}->{filter_testcase}/);
|
||||
|
||||
$self->{output}->output_add(long_msg =>
|
||||
sprintf(
|
||||
'[name = %s]',$testcase->{testcase_alias}
|
||||
'[name = %s]', $testcase->{testcase_alias}
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -80,7 +80,7 @@ sub disco_show {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $testcases = $self->manage_selection(%options);
|
||||
foreach my $testcase (values $testcases) {
|
||||
foreach my $testcase (@$testcases) {
|
||||
next if (defined($self->{option_results}->{filter_case})
|
||||
&& $self->{option_results}->{filter_case} ne ''
|
||||
&& $testcase->{scenario} !~ /$self->{option_results}->{filter_case}/ );
|
||||
|
@ -59,7 +59,7 @@ sub set_counters {
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'cases', type => 3, cb_prefix_output => 'prefix_testcases_output', cb_long_output => 'testcase_long_output', indent_long_output => ' ', message_multiple => 'All test cases are ok',
|
||||
group => [
|
||||
{ name => 'global', type => '0' },
|
||||
{ name => 'global', type => 0 },
|
||||
{ name => 'testcases', display_long => 1, cb_prefix_output => 'prefix_testcase_output', message_multiple => 'test cases are ok', type => 1, skipped_code => { -10 => 1 } }
|
||||
]
|
||||
}
|
||||
@ -80,7 +80,7 @@ sub set_counters {
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold_ng
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{testcases} = [
|
||||
@ -96,7 +96,7 @@ sub set_counters {
|
||||
output_template => 'duration: %s ms',
|
||||
perfdatas => [
|
||||
{ template => '%s', unit => 'ms', min => 0, label_extra_instance => 1 }
|
||||
],
|
||||
]
|
||||
}
|
||||
}
|
||||
];
|
||||
@ -108,7 +108,7 @@ sub new {
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'filter-testcase:s' => { name => 'filter_testcase' },
|
||||
'filter-testcase:s' => { name => 'filter_testcase' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
@ -117,35 +117,36 @@ sub new {
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my %status = ( 0 => 'OK', 2 => 'FAILED' );
|
||||
my $status = { 0 => 'OK', 2 => 'FAILED' };
|
||||
my $results = $options{custom}->request_api(endpoint => '/testcases/');
|
||||
my $i;
|
||||
foreach (@{$results->{testcases}}) {
|
||||
next if (defined($self->{option_results}->{filter_testcase})
|
||||
next if (
|
||||
defined($self->{option_results}->{filter_testcase})
|
||||
&& $self->{option_results}->{filter_testcase} ne ''
|
||||
&& $_->{testcase_alias} !~ /$self->{option_results}->{filter_testcase}/ );
|
||||
&& $_->{testcase_alias} !~ /$self->{option_results}->{filter_testcase}/
|
||||
);
|
||||
|
||||
my $measures = $options{custom}->request_api(endpoint => '/testcases/' . $_->{testcase_alias} . '/');
|
||||
$i = 1;
|
||||
$self->{cases}->{$_->{testcase_alias}} = {
|
||||
display => $_->{testcase_alias},
|
||||
global => {
|
||||
display => $_->{testcase_alias},
|
||||
duration => $measures->{measures}[0]->{test_case_duration_ms},
|
||||
state => $status{$measures->{measures}[0]->{test_case_state}}
|
||||
},
|
||||
testcases => {}
|
||||
$self->{cases}->{ $_->{testcase_alias} } = {
|
||||
display => $_->{testcase_alias},
|
||||
global => {
|
||||
display => $_->{testcase_alias},
|
||||
duration => $measures->{measures}->[0]->{test_case_duration_ms},
|
||||
state => $status->{ $measures->{measures}->[0]->{test_case_state} }
|
||||
},
|
||||
testcases => {}
|
||||
};
|
||||
|
||||
foreach my $transaction (values $measures->{measures}){
|
||||
my $i = 1;
|
||||
foreach my $transaction (values %{$measures->{measures}}) {
|
||||
my $instance = $i . '_' . $transaction->{transaction_alias};
|
||||
$instance =~ s/ /_/g;
|
||||
$self->{cases}->{$_->{testcase_alias}}->{testcases}->{$instance} = {
|
||||
display => $instance,
|
||||
state => $status{$transaction->{transaction_state}},
|
||||
$self->{cases}->{ $_->{testcase_alias} }->{testcases}->{$instance} = {
|
||||
display => $instance,
|
||||
state => $status->{ $transaction->{transaction_state} },
|
||||
duration => $transaction->{transaction_performance_ms}
|
||||
};
|
||||
$i++;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ sub new {
|
||||
$self->{version} = '0.1';
|
||||
$self->{modes} = {
|
||||
'list-testcases' => 'apps::monitoring::alyvix::restapi::mode::listtestcases',
|
||||
'testcases' => 'apps::monitoring::alyvix::restapi::mode::testcases',
|
||||
'testcases' => 'apps::monitoring::alyvix::restapi::mode::testcases'
|
||||
};
|
||||
|
||||
$self->{custom_modes}->{api} = 'apps::monitoring::alyvix::restapi::custom::api';
|
||||
|
Loading…
x
Reference in New Issue
Block a user