diff --git a/centreon-plugins/apps/iis/restapi/custom/api.pm b/centreon-plugins/apps/iis/restapi/custom/api.pm new file mode 100644 index 000000000..815b09db1 --- /dev/null +++ b/centreon-plugins/apps/iis/restapi/custom/api.pm @@ -0,0 +1,279 @@ +# +# Copyright 2020 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 apps::iis::restapi::custom::api; + +use strict; +use warnings; +use centreon::plugins::http; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + 'api-username:s' => { name => 'api_username' }, + 'api-password:s' => { name => 'api_password' }, + 'api-token:s' => { name => 'api_token' }, + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port' }, + 'proto:s' => { name => 'proto' }, + 'timeout:s' => { name => 'timeout' }, + 'unknown-http-status:s' => { name => 'unknown_http_status' }, + 'warning-http-status:s' => { name => 'warning_http_status' }, + 'critical-http-status:s' => { name => 'critical_http_status' } + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{http} = centreon::plugins::http->new(%options); + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : ''; + $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 55539; + $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; + $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} : ''; + $self->{api_password} = (defined($self->{option_results}->{api_password})) ? $self->{option_results}->{api_password} : ''; + $self->{api_token} = (defined($self->{option_results}->{api_token})) ? $self->{option_results}->{api_token} : ''; + $self->{unknown_http_status} = (defined($self->{option_results}->{unknown_http_status})) ? $self->{option_results}->{unknown_http_status} : '%{http_code} < 200 or %{http_code} >= 300'; + $self->{warning_http_status} = (defined($self->{option_results}->{warning_http_status})) ? $self->{option_results}->{warning_http_status} : ''; + $self->{critical_http_status} = (defined($self->{option_results}->{critical_http_status})) ? $self->{option_results}->{critical_http_status} : ''; + + if ($self->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); + $self->{output}->option_exit(); + } + if ($self->{api_username} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-username option."); + $self->{output}->option_exit(); + } + if ($self->{api_password} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-password option."); + $self->{output}->option_exit(); + } + if ($self->{api_token} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-token option."); + $self->{output}->option_exit(); + } + + return 0; +} + +sub build_options_for_httplib { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = $self->{hostname}; + $self->{option_results}->{timeout} = $self->{timeout}; + $self->{option_results}->{port} = $self->{port}; + $self->{option_results}->{proto} = $self->{proto}; + $self->{option_results}->{timeout} = $self->{timeout}; +} + +sub settings { + my ($self, %options) = @_; + + 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}->add_header(key => 'Access-Token', value => 'Bearer ' . $self->{api_token}); + $self->{http}->set_options(%{$self->{option_results}}); + $self->{settings_done} = 1; +} + +sub get_hostname { + my ($self, %options) = @_; + + return $self->{hostname}; +} + +sub request_api { + my ($self, %options) = @_; + + $self->settings(); + my $login = {}; + if (!defined($self->{login_done})) { + $login = { credentials => 1, ntlmv2 => 1, username => $self->{api_username}, password => $self->{api_password} }; + $self->{login_done} = 1; + } + my $content = $self->{http}->request( + url_path => $options{endpoint}, + unknown_status => $self->{unknown_http_status}, + warning_status => $self->{warning_http_status}, + critical_status => $self->{critical_http_status}, + %$login + ); + + if (!defined($content) || $content eq '') { + $self->{output}->add_option_msg(short_msg => "API returns empty content [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']"); + $self->{output}->option_exit(); + } + + my $decoded; + eval { + $decoded = JSON::XS->new->utf8->decode($content); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)"); + $self->{output}->option_exit(); + } + + return $decoded; +} + +sub get_application_pools { + my ($self, %options) = @_; + + my $results = {}; + my $pools = $self->request_api(endpoint => '/api/webserver/application-pools'); + foreach (@{$pools->{app_pools}}) { + if (defined($options{filter_name}) && $options{filter_name} ne '' && + $_->{name} !~ /$options{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping pool '" . $_->{name} . "': no matching filter.", debug => 1); + next; + } + + $results->{ $_->{name} } = $_; + my $detail = $self->request_api(endpoint => '/api/webserver/application-pools/' . $_->{id}); + $results->{ $_->{name} }->{auto_start} = $detail->{auto_start}; + + next if (defined($options{no_monitoring})); + + my $monitor = $self->request_api(endpoint => '/api/webserver/application-pools/monitoring/' . $_->{id}); + $results->{ $_->{name} }->{requests} = $monitor->{requests}; + } + + return $results; +} + +sub get_websites { + my ($self, %options) = @_; + + my $results = {}; + my $websites = $self->request_api(endpoint => '/api/webserver/websites'); + foreach (@{$websites->{websites}}) { + if (defined($options{filter_name}) && $options{filter_name} ne '' && + $_->{name} !~ /$options{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping website '" . $_->{name} . "': no matching filter.", debug => 1); + next; + } + + $results->{ $_->{name} } = $_; + + next if (defined($options{no_monitoring})); + + my $monitor = $self->request_api(endpoint => '/api/webserver/websites/monitoring/' . $_->{id}); + $results->{ $_->{name} }->{network} = $monitor->{network}; + } + + return $results; +} + +1; + +__END__ + +=head1 NAME + +IIS Rest API + +=head1 REST API OPTIONS + +IIS Rest API + +=over 8 + +=item B<--hostname> + +IIS hostname. + +=item B<--port> + +Port used (Default: 55539) + +=item B<--proto> + +Specify https if needed (Default: 'https') + +=item B<--api-username> + +IIS API username. + +=item B<--api-password> + +IIS API password. + +=item B<--api-token> + +IIS API token. + +=item B<--timeout> + +Set timeout in seconds (Default: 10). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/apps/iis/restapi/mode/applicationpools.pm b/centreon-plugins/apps/iis/restapi/mode/applicationpools.pm new file mode 100644 index 000000000..8cbe040e5 --- /dev/null +++ b/centreon-plugins/apps/iis/restapi/mode/applicationpools.pm @@ -0,0 +1,155 @@ +# +# Copyright 2020 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 apps::iis::restapi::mode::applicationpools; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use Digest::MD5 qw(md5_hex); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + 'status: %s [auto start: %s]', + $self->{result_values}->{status}, + $self->{result_values}->{auto_start} + ); +} + +sub prefix_pool_output { + my ($self, %options) = @_; + + return "Application pool '" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'pools', type => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'All application pools are ok', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{pools} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'auto_start' }, { name => 'display' } ], + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + }, + { label => 'requests', nlabel => 'applicationpool.requests.persecond', set => { + key_values => [ { name => 'requests_total', per_second => 1 }, { name => 'display' } ], + output_template => 'requests: %.2f/s', + perfdatas => [ + { template => '%.2f', min => 0, unit => '/s', label_extra_instance => 1 } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{auto_start} eq "true" and %{status} !~ /starting|started/' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $results = $options{custom}->get_application_pools(filter_name => $self->{option_results}->{filter_name}); + + $self->{pools} = {}; + foreach (values %$results) { + $self->{pools}->{$_->{name}} = { + display => $_->{name}, + status => $_->{status}, + auto_start => $_->{auto_start} ? 'true' : 'false', + requests_total => $_->{requests}->{total} + }; + } + + $self->{cache_name} = 'iis_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check application pools. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='status' + +=item B<--filter-name> + +Filter application pool name (can be a regexp). + +=item B<--unknown-status> + +Set unknown threshold for status. +Can used special variables like: %{status}, %{auto_start}, %{display} + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{status}, %{auto_start}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{auto_start} eq "true" and %{status} !~ /starting|started/'). +Can used special variables like: %{status}, %{auto_start}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%). + +=back + +=cut diff --git a/centreon-plugins/apps/iis/restapi/mode/listapplicationpools.pm b/centreon-plugins/apps/iis/restapi/mode/listapplicationpools.pm new file mode 100644 index 000000000..44c287576 --- /dev/null +++ b/centreon-plugins/apps/iis/restapi/mode/listapplicationpools.pm @@ -0,0 +1,104 @@ +# +# Copyright 2020 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 apps::iis::restapi::mode::listapplicationpools; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + return $options{custom}->get_application_pools(no_monitoring => 1); +} + +sub run { + my ($self, %options) = @_; + + my $results = $self->manage_selection(custom => $options{custom}); + foreach (sort(keys %$results)) { + $self->{output}->output_add( + long_msg => sprintf( + '[name: %s] [status: %s] [auto_start: %s]', + $results->{$_}->{name}, + $results->{$_}->{status}, + $results->{$_}->{auto_start} ? 'true' : 'false' + ) + ); + } + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List application pools:' + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name', 'auto_start', 'status']); +} + +sub disco_show { + my ($self, %options) = @_; + + my $results = $self->manage_selection(custom => $options{custom}); + foreach (sort(keys %$results)) { + $self->{output}->add_disco_entry( + name => $results->{$_}->{name}, + status => $results->{$_}->{status}, + auto_start => $results->{$_}->{auto_start} ? 'true' : 'false' + ); + } +} + +1; + +__END__ + +=head1 MODE + +List application pools. + +=over 8 + +=back + +=cut diff --git a/centreon-plugins/apps/iis/restapi/mode/listwebsites.pm b/centreon-plugins/apps/iis/restapi/mode/listwebsites.pm new file mode 100644 index 000000000..151d21809 --- /dev/null +++ b/centreon-plugins/apps/iis/restapi/mode/listwebsites.pm @@ -0,0 +1,102 @@ +# +# Copyright 2020 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 apps::iis::restapi::mode::listwebsites; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + return $options{custom}->get_websites(no_monitoring => 1); +} + +sub run { + my ($self, %options) = @_; + + my $results = $self->manage_selection(custom => $options{custom}); + foreach (sort(keys %$results)) { + $self->{output}->output_add( + long_msg => sprintf( + '[name: %s] [status: %s]', + $results->{$_}->{name}, + $results->{$_}->{status} + ) + ); + } + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List websites:' + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name', 'status']); +} + +sub disco_show { + my ($self, %options) = @_; + + my $results = $self->manage_selection(custom => $options{custom}); + foreach (sort(keys %$results)) { + $self->{output}->add_disco_entry( + name => $results->{$_}->{name}, + status => $results->{$_}->{status} + ); + } +} + +1; + +__END__ + +=head1 MODE + +List websites. + +=over 8 + +=back + +=cut diff --git a/centreon-plugins/apps/iis/restapi/mode/websites.pm b/centreon-plugins/apps/iis/restapi/mode/websites.pm new file mode 100644 index 000000000..df9dba128 --- /dev/null +++ b/centreon-plugins/apps/iis/restapi/mode/websites.pm @@ -0,0 +1,191 @@ +# +# Copyright 2020 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 apps::iis::restapi::mode::websites; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use Digest::MD5 qw(md5_hex); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + 'status: %s', + $self->{result_values}->{status} + ); +} + +sub prefix_website_output { + my ($self, %options) = @_; + + return "Website '" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'websites', type => 1, cb_prefix_output => 'prefix_website_output', message_multiple => 'All websites are ok', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{websites} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'auto_start' }, { name => 'display' } ], + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + }, + { label => 'requests', nlabel => 'website.requests.persecond', set => { + key_values => [ { name => 'requests_total', per_second => 1 }, { name => 'display' } ], + output_template => 'requests: %.2f/s', + perfdatas => [ + { template => '%.2f', min => 0, unit => '/s', label_extra_instance => 1 } + ] + } + }, + { label => 'traffic-in', nlabel => 'website.traffic.in.bitspersecond', set => { + key_values => [ { name => 'traffic_in', per_second => 1 }, { name => 'display' } ], + output_template => 'traffic in: %s %s/s', + output_change_bytes => 2, + perfdatas => [ + { template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1 } + ] + } + }, + { label => 'traffic-out', nlabel => 'website.traffic.out.bitspersecond', set => { + key_values => [ { name => 'traffic_out', per_second => 1 }, { name => 'display' } ], + output_template => 'traffic out: %s %s/s', + output_change_bytes => 2, + perfdatas => [ + { template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1 } + ] + } + }, + { label => 'connections-current', nlabel => 'website.connections.current.count', set => { + key_values => [ { name => 'current_connections' }, { name => 'display' } ], + output_template => 'current connections: %s', + perfdatas => [ + { template => '%s', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'connections-total', nlabel => 'website.connections.total.persecond', set => { + key_values => [ { name => 'total_connections', per_second => 1 }, { name => 'display' } ], + output_template => 'total connections: %.2f/s', + perfdatas => [ + { template => '%.2f', min => 0, unit => '/s', label_extra_instance => 1 } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /starting|started/' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $results = $options{custom}->get_websites(filter_name => $self->{option_results}->{filter_name}); + + $self->{websites} = {}; + foreach (values %$results) { + $self->{websites}->{$_->{name}} = { + display => $_->{name}, + status => $_->{status}, + requests_total => $_->{requests}->{total}, + traffic_in => $_->{network}->{total_bytes_recv} * 8, + traffic_out => $_->{network}->{total_bytes_sent} * 8, + current_connections => $_->{network}->{current_connections}, + total_connections => $_->{network}->{total_connection_attempts} + }; + } + + $self->{cache_name} = 'iis_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check websites. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='status' + +=item B<--filter-name> + +Filter website name (can be a regexp). + +=item B<--unknown-status> + +Set unknown threshold for status. +Can used special variables like: %{status}, %{display} + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /starting|started/'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%). + +=back + +=cut diff --git a/centreon-plugins/apps/iis/restapi/plugin.pm b/centreon-plugins/apps/iis/restapi/plugin.pm new file mode 100644 index 000000000..f9bd7b047 --- /dev/null +++ b/centreon-plugins/apps/iis/restapi/plugin.pm @@ -0,0 +1,52 @@ +# +# Copyright 2020 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 apps::iis::restapi::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ( $class, %options ) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + $self->{modes} = { + 'application-pools' => 'apps::iis::restapi::mode::applicationpools', + 'list-application-pools' => 'apps::iis::restapi::mode::listapplicationpools', + 'list-websites' => 'apps::iis::restapi::mode::listwebsites', + 'websites' => 'apps::iis::restapi::mode::websites' + }; + + $self->{custom_modes}{api} = 'apps::iis::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Windows IIS in Rest API. + +=cut diff --git a/centreon-plugins/centreon/plugins/backend/http/curl.pm b/centreon-plugins/centreon/plugins/backend/http/curl.pm index 39bdc6c83..af14dbe5c 100644 --- a/centreon-plugins/centreon/plugins/backend/http/curl.pm +++ b/centreon-plugins/centreon/plugins/backend/http/curl.pm @@ -263,7 +263,9 @@ sub cb_get_header { sub request { my ($self, %options) = @_; - $self->{curl_easy} = Net::Curl::Easy->new(); + if (!defined($self->{curl_easy})) { + $self->{curl_easy} = Net::Curl::Easy->new(); + } if ($self->{output}->is_debug()) { $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_DEBUGFUNCTION'), parameter => \&cb_debug); @@ -294,8 +296,10 @@ sub request { if (defined($options{request}->{http_peer_addr}) && $options{request}->{http_peer_addr} ne '') { $url =~ /^(?:http|https):\/\/(.*?)(\/|\:|$)/; - $self->{curl_easy}->pushopt($self->{constant_cb}->(name => 'CURLOPT_RESOLVE'), - [$1 . ':' . $options{request}->{port_force} . ':' . $options{request}->{http_peer_addr}]); + $self->{curl_easy}->setopt( + $self->{constant_cb}->(name => 'CURLOPT_RESOLVE'), + [$1 . ':' . $options{request}->{port_force} . ':' . $options{request}->{http_peer_addr}] + ); } my $uri = URI->new($url); @@ -317,7 +321,7 @@ sub request { $self->set_method(%options, content_type_forced => $content_type_forced, headers => $headers); if (scalar(@$headers) > 0) { - $self->{curl_easy}->pushopt($self->{constant_cb}->(name => 'CURLOPT_HTTPHEADER'), $headers); + $self->{curl_easy}->setopt($self->{constant_cb}->(name => 'CURLOPT_HTTPHEADER'), $headers); } if (defined($options{request}->{cacert_file}) && $options{request}->{cacert_file} ne '') { diff --git a/centreon-plugins/centreon/plugins/backend/http/lwp.pm b/centreon-plugins/centreon/plugins/backend/http/lwp.pm index 93d93ee7a..6169080d6 100644 --- a/centreon-plugins/centreon/plugins/backend/http/lwp.pm +++ b/centreon-plugins/centreon/plugins/backend/http/lwp.pm @@ -123,8 +123,13 @@ sub request { my $request_options = $options{request}; if (!defined($self->{ua})) { $self->{ua} = centreon::plugins::backend::http::useragent->new( - keep_alive => 1, protocols_allowed => ['http', 'https'], timeout => $request_options->{timeout}, - credentials => $request_options->{credentials}, username => $request_options->{username}, password => $request_options->{password}); + keep_alive => 1, + protocols_allowed => ['http', 'https'], + timeout => $request_options->{timeout}, + credentials => $request_options->{credentials}, + username => $request_options->{username}, + password => $request_options->{password} + ); if (defined($request_options->{cookies_file})) { centreon::plugins::misc::mymodule_load( output => $self->{output}, diff --git a/centreon-plugins/centreon/plugins/backend/http/useragent.pm b/centreon-plugins/centreon/plugins/backend/http/useragent.pm index 0b467c66e..042e034e9 100644 --- a/centreon-plugins/centreon/plugins/backend/http/useragent.pm +++ b/centreon-plugins/centreon/plugins/backend/http/useragent.pm @@ -43,7 +43,7 @@ sub get_basic_credentials { my($self, $realm, $uri, $proxy) = @_; return if $proxy; return $self->{username}, $self->{password} if $self->{credentials} and wantarray; - return $self->{username}.":".$self->{password} if $self->{credentials}; + return $self->{username} . ':' . $self->{password} if $self->{credentials}; return undef; }