diff --git a/apps/apache/serverstatus/mode/requests.pm b/apps/apache/serverstatus/mode/requests.pm index f6d2fc7ba..4e056a3db 100644 --- a/apps/apache/serverstatus/mode/requests.pm +++ b/apps/apache/serverstatus/mode/requests.pm @@ -108,13 +108,6 @@ sub check_options { $self->{output}->option_exit(); } - $self->{cache_port} = ''; - if (defined($self->{option_results}->{port}) && $self->{option_results}->{port} ne '') { - $self->{cache_port} = $self->{option_results}->{port}; - } else { - $self->{cache_port} = 80 if ($self->{option_results}->{proto} eq 'http'); - $self->{cache_port} = 443 if ($self->{option_results}->{proto} eq 'https'); - } $self->{statefile_value}->check_options(%options); } @@ -137,7 +130,7 @@ sub run { } $rPerSec = '0' . $rPerSec if ($rPerSec =~ /^\./); - $self->{statefile_value}->read(statefile => 'apache_' . $self->{option_results}->{hostname} . '_' . $self->{cache_port} . '_' . $self->{mode}); + $self->{statefile_value}->read(statefile => 'apache_' . $self->{option_results}->{hostname} . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode}); my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp'); my $old_total_access = $self->{statefile_value}->get(name => 'total_access'); my $old_total_bytes = $self->{statefile_value}->get(name => 'total_bytes'); diff --git a/centreon/plugins/httplib.pm b/centreon/plugins/httplib.pm index d0d700c8f..cfed6c980 100644 --- a/centreon/plugins/httplib.pm +++ b/centreon/plugins/httplib.pm @@ -40,6 +40,20 @@ use strict; use warnings; use LWP::UserAgent; +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 $ua = LWP::UserAgent->new( protocols_allowed => ['http', 'https'], timeout => $self->{option_results}->{timeout});