diff --git a/centreon-plugins/apps/varnish/local/mode/stats.pm b/centreon-plugins/apps/varnish/local/mode/stats.pm index 1ad78c574..42c82c96b 100644 --- a/centreon-plugins/apps/varnish/local/mode/stats.pm +++ b/centreon-plugins/apps/varnish/local/mode/stats.pm @@ -167,8 +167,7 @@ sub custom_output_second { my $label = $self->{label}; $label =~ s/-/_/g; - my $msg = sprintf('%s: %.2f/s', $self->{result_values}->{$label . '_description'}, $self->{result_values}->{$label}); - return $msg; + return sprintf('%s: %.2f/s', $self->{result_values}->{$label . '_description'}, $self->{result_values}->{$label}); } sub custom_output { @@ -176,8 +175,7 @@ sub custom_output { my $label = $self->{label}; $label =~ s/-/_/g; - my $msg = sprintf('%s: %s', $self->{result_values}->{$label . '_description'}, $self->{result_values}->{$label }); - return $msg; + return sprintf('%s: %s', $self->{result_values}->{$label . '_description'}, $self->{result_values}->{$label}); } sub set_counters { @@ -238,7 +236,9 @@ sub check_varnish_old { sub check_varnish_new { my ($self, %options) = @_; - return if (!defined($options{json}->{'MAIN.uptime'})); + my $counters = $options{json}; + $counters = $counters->{counters} if (defined($counters->{counters})); # since varnish 6.6.x + return if (!defined($counters->{'MAIN.uptime'})); # "MAIN.cache_hit": {"type": "MAIN", "value": 18437, "flag": "a", "description": "Cache hits"}, # "MAIN.cache_hitpass": {"type": "MAIN", "value": 3488, "flag": "a", "description": "Cache hits for pass"}, @@ -246,9 +246,9 @@ sub check_varnish_new { # "SMA.s0.g_space": { "description": "Bytes available", "flag": "g", "format": "B", "value": 4244053932 }, foreach (@{$self->{varnish_stats}}) { my $category = defined($_->{category}) ? $_->{category} : 'MAIN'; - next if (!defined($options{json}->{$category . '.' . $_->{entry}})); - $self->{global}->{$_->{entry}} = $options{json}->{$category . '.' . $_->{entry}}->{value}; - $self->{global}->{$_->{entry} . '_description'} = $options{json}->{$category . '.' . $_->{entry}}->{description}; + next if (!defined($counters->{ $category . '.' . $_->{entry} })); + $self->{global}->{$_->{entry}} = $counters->{ $category . '.' . $_->{entry} }->{value}; + $self->{global}->{$_->{entry} . '_description'} = $counters->{ $category . '.' . $_->{entry} }->{description}; } } diff --git a/centreon-plugins/apps/varnish/local/plugin.pm b/centreon-plugins/apps/varnish/local/plugin.pm index e0931db99..61cf99738 100644 --- a/centreon-plugins/apps/varnish/local/plugin.pm +++ b/centreon-plugins/apps/varnish/local/plugin.pm @@ -30,12 +30,11 @@ sub new { bless $self, $class; $self->{version} = '0.1'; - %{$self->{modes}} = ( - 'stats' => 'apps::varnish::local::mode::stats', - ); + $self->{modes} = { + 'stats' => 'apps::varnish::local::mode::stats' + }; $self->{custom_modes}->{cli} = 'centreon::plugins::script_custom::cli'; - return $self; }