parent
f99839813e
commit
6d1c41c0ea
|
@ -188,7 +188,9 @@ sub get_auth_token {
|
|||
method => 'POST',
|
||||
url_path => $self->{url_path} . '/Login',
|
||||
query_form_post => $encoded,
|
||||
warning_status => '', unknown_status => '', critical_status => ''
|
||||
warning_status => '',
|
||||
unknown_status => '',
|
||||
critical_status => ''
|
||||
);
|
||||
|
||||
if ($self->{http}->get_code() != 200) {
|
||||
|
@ -222,7 +224,6 @@ sub request_internal {
|
|||
}
|
||||
|
||||
my $content = $self->{http}->request(
|
||||
method => 'GET',
|
||||
url_path => $self->{url_path} . $options{endpoint},
|
||||
get_param => $options{get_param},
|
||||
warning_status => '',
|
||||
|
|
|
@ -118,8 +118,10 @@ sub load_response {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
if ($self->{response_type} eq 'xml') {
|
||||
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'XML::XPath',
|
||||
error_msg => "Cannot load module 'XML::XPath'.");
|
||||
centreon::plugins::misc::mymodule_load(
|
||||
output => $self->{output}, module => 'XML::XPath',
|
||||
error_msg => "Cannot load module 'XML::XPath'."
|
||||
);
|
||||
eval {
|
||||
$self->{xpath_response} = XML::XPath->new(xml => $options{response});
|
||||
};
|
||||
|
|
|
@ -123,7 +123,6 @@ sub settings {
|
|||
$self->{http}->add_header(key => 'Accept', value => 'application/json');
|
||||
if (defined($self->{auth_token})) {
|
||||
$self->{http}->add_header(key => 'Centreon-Auth-Token', value => $self->{auth_token});
|
||||
$self->{http}->add_header(key => 'Content-Type', value => 'application/json');
|
||||
}
|
||||
$self->{http}->set_options(%{$self->{option_results}});
|
||||
}
|
||||
|
@ -190,7 +189,10 @@ sub request_api {
|
|||
method => $options{method},
|
||||
url_path => $options{url_path},
|
||||
query_form_post => $encoded_form_post,
|
||||
critical_status => '', warning_status => '', unknown_status => ''
|
||||
header => $options{header},
|
||||
critical_status => '',
|
||||
warning_status => '',
|
||||
unknown_status => ''
|
||||
);
|
||||
|
||||
my $decoded;
|
||||
|
@ -211,7 +213,8 @@ sub submit_result {
|
|||
my ($response, $raw) = $self->request_api(
|
||||
method => 'POST',
|
||||
url_path => $self->{api_path} . '?action=submit&object=centreon_submit_results',
|
||||
query_form_post => $options{post_data}
|
||||
query_form_post => $options{post_data},
|
||||
header => ['Content-Type: application/json']
|
||||
);
|
||||
|
||||
return ($response, $raw);
|
||||
|
|
|
@ -37,26 +37,26 @@ sub set_counters {
|
|||
key_values => [ { name => '202' } ],
|
||||
output_template => '202: %d',
|
||||
perfdatas => [
|
||||
{ value => '202', template => '%d', min => 0 },
|
||||
],
|
||||
{ template => '%d', min => 0 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'results-400', nlabel => 'results.400.count', set => {
|
||||
key_values => [ { name => '400' } ],
|
||||
output_template => '400: %d',
|
||||
perfdatas => [
|
||||
{ value => '400', template => '%d', min => 0 },
|
||||
],
|
||||
{ template => '%d', min => 0 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'results-404', nlabel => 'results.404.count', set => {
|
||||
key_values => [ { name => '404' } ],
|
||||
output_template => '404: %d',
|
||||
perfdatas => [
|
||||
{ value => '404', template => '%d', min => 0 },
|
||||
],
|
||||
{ template => '%d', min => 0 }
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -72,21 +72,16 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
"host:s@" => { name => 'host' },
|
||||
"service:s@" => { name => 'service' },
|
||||
"status:s@" => { name => 'status' },
|
||||
"output:s@" => { name => 'output' },
|
||||
"perfdata:s@" => { name => 'perfdata' },
|
||||
'host:s@' => { name => 'host' },
|
||||
'service:s@' => { name => 'service' },
|
||||
'status:s@' => { name => 'status' },
|
||||
'output:s@' => { name => 'output' },
|
||||
'perfdata:s@' => { name => 'perfdata' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
|
|
@ -115,7 +115,6 @@ sub settings {
|
|||
return if (defined($self->{settings_done}));
|
||||
$self->build_options_for_httplib();
|
||||
$self->{http}->add_header(key => 'Accept', value => 'application/json');
|
||||
$self->{http}->add_header(key => 'Content-Type', value => 'application/json');
|
||||
$self->{http}->set_options(%{$self->{option_results}});
|
||||
$self->{settings_done} = 1;
|
||||
}
|
||||
|
|
|
@ -161,10 +161,6 @@ sub set_method {
|
|||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_POSTFIELDS'), parameter => undef);
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_HTTPGET'), parameter => 1);
|
||||
|
||||
if ($options{request}->{method} eq 'GET') {
|
||||
return ;
|
||||
}
|
||||
|
||||
if ($options{content_type_forced} == 1) {
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_POSTFIELDS'), parameter => $options{request}->{query_form_post})
|
||||
if (defined($options{request}->{query_form_post}));
|
||||
|
@ -175,6 +171,10 @@ sub set_method {
|
|||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_POSTFIELDS'), parameter => $uri_post->query);
|
||||
}
|
||||
|
||||
if ($options{request}->{method} eq 'GET') {
|
||||
return ;
|
||||
}
|
||||
|
||||
if ($options{request}->{method} eq 'POST') {
|
||||
$self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_POST'), parameter => 1);
|
||||
}
|
||||
|
|
|
@ -191,27 +191,21 @@ sub request {
|
|||
}
|
||||
$req = HTTP::Request->new($request_options->{method}, $uri);
|
||||
|
||||
my $content_type_forced;
|
||||
my $content_type_forced = 0;
|
||||
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};
|
||||
$req->header($key => $request_options->{headers}->{$key});
|
||||
if ($key =~ /content-type/i) {
|
||||
$content_type_forced = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($request_options->{method} ne 'GET') {
|
||||
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($request_options->{post_params})) {
|
||||
$uri_post->query_form($request_options->{post_params});
|
||||
}
|
||||
$req->content_type('application/x-www-form-urlencoded');
|
||||
$req->content($uri_post->query);
|
||||
}
|
||||
if ($content_type_forced == 1) {
|
||||
$req->content($request_options->{query_form_post});
|
||||
} elsif (defined($options{request}->{post_params})) {
|
||||
my $uri_post = URI->new();
|
||||
$uri_post->query_form($request_options->{post_params});
|
||||
$req->content_type('application/x-www-form-urlencoded');
|
||||
$req->content($uri_post->query);
|
||||
}
|
||||
|
||||
if (defined($request_options->{credentials}) && defined($request_options->{ntlmv2})) {
|
||||
|
|
Loading…
Reference in New Issue