From 8100ae446705ee1d1dd5412897b72bff2d619f09 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 26 Mar 2019 18:11:01 +0100 Subject: [PATCH] clean code --- .../compute/virtualmachine/mode/diskio.pm | 27 +++++------- .../compute/virtualmachine/mode/network.pm | 27 +++++------- .../network/expressroute/mode/traffic.pm | 17 +++---- .../network/networkinterface/mode/traffic.pm | 33 ++++++-------- .../network/vpngateway/mode/sitetraffic.pm | 17 +++---- .../network/vpngateway/mode/tunneltraffic.pm | 33 ++++++-------- .../storageaccount/mode/transactionscount.pm | 27 +++++------- .../mode/transactionslatency.pm | 19 +++----- .../mode/transactionsthroughput.pm | 29 +++++------- cloud/kubernetes/restapi/mode/podstatus.pm | 10 ++--- .../office365/exchange/mode/emailactivity.pm | 24 +++------- .../office365/exchange/mode/mailboxusage.pm | 44 +++++++------------ .../office365/onedrive/mode/usage.pm | 36 ++++++--------- .../office365/sharepoint/mode/siteusage.pm | 36 ++++++--------- .../sharepoint/mode/usersactivity.pm | 26 ++++------- .../office365/skype/mode/devicesusage.pm | 23 +++------- .../office365/skype/mode/usersactivity.pm | 26 ++++------- .../office365/teams/mode/devicesusage.pm | 25 +++-------- .../office365/teams/mode/usersactivity.pm | 26 ++++------- .../exporters/cadvisor/mode/memory.pm | 31 ++++++------- .../exporters/cadvisor/mode/storage.pm | 37 +++++++--------- .../exporters/nodeexporter/mode/memory.pm | 26 +++++------ .../exporters/nodeexporter/mode/storage.pm | 37 +++++++--------- 23 files changed, 235 insertions(+), 401 deletions(-) diff --git a/cloud/azure/compute/virtualmachine/mode/diskio.pm b/cloud/azure/compute/virtualmachine/mode/diskio.pm index 815d8a9d7..0a1f54b36 100644 --- a/cloud/azure/compute/virtualmachine/mode/diskio.pm +++ b/cloud/azure/compute/virtualmachine/mode/diskio.pm @@ -25,8 +25,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub prefix_metric_output { my ($self, %options) = @_; @@ -50,7 +48,7 @@ sub custom_metric_calc { sub custom_metric_threshold { my ($self, %options) = @_; - my $exit = $self->{perfdata}->threshold_check(value => defined($instance_mode->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, + my $exit = $self->{perfdata}->threshold_check(value => defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, threshold => [ { label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}, exit_litteral => 'warning' } ]); return $exit; @@ -63,8 +61,8 @@ sub custom_usage_perfdata { $extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0); $self->{output}->perfdata_add(label => $self->{result_values}->{metric_perf} . "_" . $self->{result_values}->{stat} . $extra_label, - unit => defined($instance_mode->{option_results}->{per_sec}) ? 'B/s' : 'B', - value => sprintf("%.2f", defined($instance_mode->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), + unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'B/s' : 'B', + value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), min => 0 @@ -75,7 +73,7 @@ sub custom_usage_output { my ($self, %options) = @_; my $msg = ""; - if (defined($instance_mode->{option_results}->{per_sec})) { + if (defined($self->{instance_mode}->{option_results}->{per_sec})) { my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value_per_sec}); $msg = $self->{result_values}->{metric_name} . ": " . $value . $unit . "/s"; } else { @@ -161,14 +159,13 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "resource:s@" => { name => 'resource' }, - "resource-group:s" => { name => 'resource_group' }, - "filter-metric:s" => { name => 'filter_metric' }, - "per-sec" => { name => 'per_sec' }, - }); - + $options{options}->add_options(arguments => { + "resource:s@" => { name => 'resource' }, + "resource-group:s" => { name => 'resource_group' }, + "filter-metric:s" => { name => 'filter_metric' }, + "per-sec" => { name => 'per_sec' }, + }); + return $self; } @@ -204,8 +201,6 @@ sub check_options { push @{$self->{az_metrics}}, $metric; } - - $instance_mode = $self; } sub manage_selection { diff --git a/cloud/azure/compute/virtualmachine/mode/network.pm b/cloud/azure/compute/virtualmachine/mode/network.pm index 8b7a546aa..e5b4710f1 100644 --- a/cloud/azure/compute/virtualmachine/mode/network.pm +++ b/cloud/azure/compute/virtualmachine/mode/network.pm @@ -25,8 +25,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub prefix_metric_output { my ($self, %options) = @_; @@ -50,7 +48,7 @@ sub custom_metric_calc { sub custom_metric_threshold { my ($self, %options) = @_; - my $exit = $self->{perfdata}->threshold_check(value => defined($instance_mode->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, + my $exit = $self->{perfdata}->threshold_check(value => defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, threshold => [ { label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}, exit_litteral => 'warning' } ]); return $exit; @@ -63,8 +61,8 @@ sub custom_traffic_perfdata { $extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0); $self->{output}->perfdata_add(label => $self->{result_values}->{metric_perf} . "_" . $self->{result_values}->{stat} . $extra_label, - unit => defined($instance_mode->{option_results}->{per_sec}) ? 'B/s' : 'B', - value => sprintf("%.2f", defined($instance_mode->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), + unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'B/s' : 'B', + value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), min => 0 @@ -75,7 +73,7 @@ sub custom_traffic_output { my ($self, %options) = @_; my $msg = ""; - if (defined($instance_mode->{option_results}->{per_sec})) { + if (defined($self->{instance_mode}->{option_results}->{per_sec})) { my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value_per_sec}); $msg = $self->{result_values}->{metric_name} . ": " . $value . $unit . "/s"; } else { @@ -120,14 +118,13 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "resource:s@" => { name => 'resource' }, - "resource-group:s" => { name => 'resource_group' }, - "filter-metric:s" => { name => 'filter_metric' }, - "per-sec" => { name => 'per_sec' }, - }); - + $options{options}->add_options(arguments => { + "resource:s@" => { name => 'resource' }, + "resource-group:s" => { name => 'resource_group' }, + "filter-metric:s" => { name => 'filter_metric' }, + "per-sec" => { name => 'per_sec' }, + }); + return $self; } @@ -162,8 +159,6 @@ sub check_options { push @{$self->{az_metrics}}, $metric; } - - $instance_mode = $self; } sub manage_selection { diff --git a/cloud/azure/network/expressroute/mode/traffic.pm b/cloud/azure/network/expressroute/mode/traffic.pm index 2127effa1..cc1120864 100644 --- a/cloud/azure/network/expressroute/mode/traffic.pm +++ b/cloud/azure/network/expressroute/mode/traffic.pm @@ -25,8 +25,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub prefix_traffic_output { my ($self, %options) = @_; @@ -113,13 +111,12 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "resource:s@" => { name => 'resource' }, - "resource-group:s" => { name => 'resource_group' }, - "filter-metric:s" => { name => 'filter_metric' }, - }); - + $options{options}->add_options(arguments => { + "resource:s@" => { name => 'resource' }, + "resource-group:s" => { name => 'resource_group' }, + "filter-metric:s" => { name => 'filter_metric' }, + }); + return $self; } @@ -154,8 +151,6 @@ sub check_options { push @{$self->{az_metrics}}, $metric; } - - $instance_mode = $self; } sub manage_selection { diff --git a/cloud/azure/network/networkinterface/mode/traffic.pm b/cloud/azure/network/networkinterface/mode/traffic.pm index 4b4c7abf5..5aefe45be 100644 --- a/cloud/azure/network/networkinterface/mode/traffic.pm +++ b/cloud/azure/network/networkinterface/mode/traffic.pm @@ -25,8 +25,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub prefix_metric_output { my ($self, %options) = @_; @@ -50,7 +48,7 @@ sub custom_metric_calc { sub custom_metric_threshold { my ($self, %options) = @_; - my $exit = $self->{perfdata}->threshold_check(value => defined($instance_mode->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, + my $exit = $self->{perfdata}->threshold_check(value => defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, threshold => [ { label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}, exit_litteral => 'warning' } ]); return $exit; @@ -63,8 +61,8 @@ sub custom_traffic_perfdata { $extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0); $self->{output}->perfdata_add(label => $self->{result_values}->{metric_perf} . "_" . $self->{result_values}->{stat} . $extra_label, - unit => defined($instance_mode->{option_results}->{per_sec}) ? 'B/s' : 'B', - value => sprintf("%.2f", defined($instance_mode->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), + unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'B/s' : 'B', + value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), min => 0 @@ -75,7 +73,7 @@ sub custom_traffic_output { my ($self, %options) = @_; my $msg = ""; - if (defined($instance_mode->{option_results}->{per_sec})) { + if (defined($self->{instance_mode}->{option_results}->{per_sec})) { my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value_per_sec}); $msg = $self->{result_values}->{metric_name} . ": " . $value . $unit . "/s"; } else { @@ -92,8 +90,8 @@ sub custom_packets_perfdata { $extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0); $self->{output}->perfdata_add(label => $self->{result_values}->{metric_perf} . "_" . $self->{result_values}->{stat} . $extra_label, - unit => defined($instance_mode->{option_results}->{per_sec}) ? 'packets/s' : 'packets', - value => sprintf("%.2f", defined($instance_mode->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), + unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'packets/s' : 'packets', + value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), min => 0 @@ -104,7 +102,7 @@ sub custom_packets_output { my ($self, %options) = @_; my $msg =""; - if (defined($instance_mode->{option_results}->{per_sec})) { + if (defined($self->{instance_mode}->{option_results}->{per_sec})) { $msg = sprintf("%s: %.2f packets/s", $self->{result_values}->{metric_name}, $self->{result_values}->{value_per_sec}); } else { $msg = sprintf("%s: %.2f packets", $self->{result_values}->{metric_name}, $self->{result_values}->{value}); @@ -165,14 +163,13 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "resource:s@" => { name => 'resource' }, - "resource-group:s" => { name => 'resource_group' }, - "filter-metric:s" => { name => 'filter_metric' }, - "per-sec" => { name => 'per_sec' }, - }); - + $options{options}->add_options(arguments => { + "resource:s@" => { name => 'resource' }, + "resource-group:s" => { name => 'resource_group' }, + "filter-metric:s" => { name => 'filter_metric' }, + "per-sec" => { name => 'per_sec' }, + }); + return $self; } @@ -207,8 +204,6 @@ sub check_options { push @{$self->{az_metrics}}, $metric; } - - $instance_mode = $self; } sub manage_selection { diff --git a/cloud/azure/network/vpngateway/mode/sitetraffic.pm b/cloud/azure/network/vpngateway/mode/sitetraffic.pm index ab7f40ff4..eef5df12a 100644 --- a/cloud/azure/network/vpngateway/mode/sitetraffic.pm +++ b/cloud/azure/network/vpngateway/mode/sitetraffic.pm @@ -25,8 +25,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub prefix_metric_output { my ($self, %options) = @_; @@ -133,13 +131,12 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "resource:s@" => { name => 'resource' }, - "resource-group:s" => { name => 'resource_group' }, - "filter-metric:s" => { name => 'filter_metric' }, - }); - + $options{options}->add_options(arguments => { + "resource:s@" => { name => 'resource' }, + "resource-group:s" => { name => 'resource_group' }, + "filter-metric:s" => { name => 'filter_metric' }, + }); + return $self; } @@ -174,8 +171,6 @@ sub check_options { push @{$self->{az_metrics}}, $metric; } - - $instance_mode = $self; } sub manage_selection { diff --git a/cloud/azure/network/vpngateway/mode/tunneltraffic.pm b/cloud/azure/network/vpngateway/mode/tunneltraffic.pm index 954a44861..fc76e74ef 100644 --- a/cloud/azure/network/vpngateway/mode/tunneltraffic.pm +++ b/cloud/azure/network/vpngateway/mode/tunneltraffic.pm @@ -25,8 +25,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub prefix_metric_output { my ($self, %options) = @_; @@ -51,7 +49,7 @@ sub custom_metric_calc { sub custom_metric_threshold { my ($self, %options) = @_; - my $exit = $self->{perfdata}->threshold_check(value => defined($instance_mode->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, + my $exit = $self->{perfdata}->threshold_check(value => defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, threshold => [ { label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}, exit_litteral => 'warning' } ]); return $exit; @@ -64,8 +62,8 @@ sub custom_traffic_perfdata { $extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0); $self->{output}->perfdata_add(label => $self->{result_values}->{metric_perf} . "_" . $self->{result_values}->{stat} . $extra_label, - unit => defined($instance_mode->{option_results}->{per_sec}) ? 'B/s' : 'B', - value => sprintf("%.2f", defined($instance_mode->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), + unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'B/s' : 'B', + value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), min => 0 @@ -76,7 +74,7 @@ sub custom_traffic_output { my ($self, %options) = @_; my $msg = ""; - if (defined($instance_mode->{option_results}->{per_sec})) { + if (defined($self->{instance_mode}->{option_results}->{per_sec})) { my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value_per_sec}); $msg = $self->{result_values}->{metric_name} . ": " . $value . $unit . "/s"; } else { @@ -93,8 +91,8 @@ sub custom_packets_perfdata { $extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0); $self->{output}->perfdata_add(label => $self->{result_values}->{metric_perf} . "_" . $self->{result_values}->{stat} . $extra_label, - unit => defined($instance_mode->{option_results}->{per_sec}) ? 'packets/s' : 'packets', - value => sprintf("%.2f", defined($instance_mode->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), + unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'packets/s' : 'packets', + value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), min => 0 @@ -105,7 +103,7 @@ sub custom_packets_output { my ($self, %options) = @_; my $msg =""; - if (defined($instance_mode->{option_results}->{per_sec})) { + if (defined($self->{instance_mode}->{option_results}->{per_sec})) { $msg = sprintf("%s: %.2f packets/s", $self->{result_values}->{metric_name}, $self->{result_values}->{value_per_sec}); } else { $msg = sprintf("%s: %.2f packets", $self->{result_values}->{metric_name}, $self->{result_values}->{value}); @@ -166,14 +164,13 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "resource:s@" => { name => 'resource' }, - "resource-group:s" => { name => 'resource_group' }, - "filter-metric:s" => { name => 'filter_metric' }, - "per-sec" => { name => 'per_sec' }, - }); - + $options{options}->add_options(arguments => { + "resource:s@" => { name => 'resource' }, + "resource-group:s" => { name => 'resource_group' }, + "filter-metric:s" => { name => 'filter_metric' }, + "per-sec" => { name => 'per_sec' }, + }); + return $self; } @@ -209,8 +206,6 @@ sub check_options { push @{$self->{az_metrics}}, $metric; } - - $instance_mode = $self; } sub manage_selection { diff --git a/cloud/azure/storage/storageaccount/mode/transactionscount.pm b/cloud/azure/storage/storageaccount/mode/transactionscount.pm index 6967d4228..9c6f3b22d 100644 --- a/cloud/azure/storage/storageaccount/mode/transactionscount.pm +++ b/cloud/azure/storage/storageaccount/mode/transactionscount.pm @@ -25,8 +25,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub prefix_metric_output { my ($self, %options) = @_; @@ -55,7 +53,7 @@ sub custom_metric_calc { sub custom_metric_threshold { my ($self, %options) = @_; - my $exit = $self->{perfdata}->threshold_check(value => defined($instance_mode->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, + my $exit = $self->{perfdata}->threshold_check(value => defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, threshold => [ { label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}, exit_litteral => 'warning' } ]); return $exit; @@ -68,8 +66,8 @@ sub custom_usage_perfdata { $extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0); $self->{output}->perfdata_add(label => $self->{result_values}->{metric_perf} . "_" . $self->{result_values}->{stat} . $extra_label, - unit => defined($instance_mode->{option_results}->{per_sec}) ? 'transactions/s' : 'transactions', - value => sprintf("%.2f", defined($instance_mode->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), + unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'transactions/s' : 'transactions', + value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), min => 0 @@ -80,7 +78,7 @@ sub custom_usage_output { my ($self, %options) = @_; my $msg = ""; - if (defined($instance_mode->{option_results}->{per_sec})) { + if (defined($self->{instance_mode}->{option_results}->{per_sec})) { $msg = sprintf("%s: %.2f transactions/s", $self->{result_values}->{metric_name}, $self->{result_values}->{value_per_sec}); } else { $msg = sprintf("%s: %.2f transactions", $self->{result_values}->{metric_name}, $self->{result_values}->{value}); @@ -120,14 +118,13 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "resource:s@" => { name => 'resource' }, - "resource-group:s" => { name => 'resource_group' }, - "resource-namespace:s" => { name => 'resource_namespace' }, - "per-sec" => { name => 'per_sec' }, - }); - + $options{options}->add_options(arguments => { + "resource:s@" => { name => 'resource' }, + "resource-group:s" => { name => 'resource_group' }, + "resource-namespace:s" => { name => 'resource_namespace' }, + "per-sec" => { name => 'per_sec' }, + }); + return $self; } @@ -160,8 +157,6 @@ sub check_options { foreach my $metric ('Transactions') { push @{$self->{az_metrics}}, $metric; } - - $instance_mode = $self; } sub manage_selection { diff --git a/cloud/azure/storage/storageaccount/mode/transactionslatency.pm b/cloud/azure/storage/storageaccount/mode/transactionslatency.pm index b502c312a..f43e289f6 100644 --- a/cloud/azure/storage/storageaccount/mode/transactionslatency.pm +++ b/cloud/azure/storage/storageaccount/mode/transactionslatency.pm @@ -25,8 +25,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub prefix_metric_output { my ($self, %options) = @_; @@ -68,14 +66,13 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "resource:s@" => { name => 'resource' }, - "resource-group:s" => { name => 'resource_group' }, - "resource-namespace:s" => { name => 'resource_namespace' }, - "filter-metric:s" => { name => 'filter_metric' }, - }); - + $options{options}->add_options(arguments => { + "resource:s@" => { name => 'resource' }, + "resource-group:s" => { name => 'resource_group' }, + "resource-namespace:s" => { name => 'resource_namespace' }, + "filter-metric:s" => { name => 'filter_metric' }, + }); + return $self; } @@ -111,8 +108,6 @@ sub check_options { push @{$self->{az_metrics}}, $metric; } - - $instance_mode = $self; } sub manage_selection { diff --git a/cloud/azure/storage/storageaccount/mode/transactionsthroughput.pm b/cloud/azure/storage/storageaccount/mode/transactionsthroughput.pm index 7b30d52d1..5738d5fa9 100644 --- a/cloud/azure/storage/storageaccount/mode/transactionsthroughput.pm +++ b/cloud/azure/storage/storageaccount/mode/transactionsthroughput.pm @@ -25,8 +25,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub prefix_metric_output { my ($self, %options) = @_; @@ -55,7 +53,7 @@ sub custom_metric_calc { sub custom_metric_threshold { my ($self, %options) = @_; - my $exit = $self->{perfdata}->threshold_check(value => defined($instance_mode->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, + my $exit = $self->{perfdata}->threshold_check(value => defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, threshold => [ { label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}, exit_litteral => 'warning' } ]); return $exit; @@ -68,8 +66,8 @@ sub custom_usage_perfdata { $extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0); $self->{output}->perfdata_add(label => $self->{result_values}->{metric_perf} . "_" . $self->{result_values}->{stat} . $extra_label, - unit => defined($instance_mode->{option_results}->{per_sec}) ? 'B/s' : 'B', - value => sprintf("%.2f", defined($instance_mode->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), + unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'B/s' : 'B', + value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), min => 0 @@ -80,7 +78,7 @@ sub custom_usage_output { my ($self, %options) = @_; my $msg = ""; - if (defined($instance_mode->{option_results}->{per_sec})) { + if (defined($self->{instance_mode}->{option_results}->{per_sec})) { my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value_per_sec}); $msg = $self->{result_values}->{metric_name} . ": " . $value . ' ' . $unit . "/s"; } else { @@ -122,15 +120,14 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "resource:s@" => { name => 'resource' }, - "resource-group:s" => { name => 'resource_group' }, - "resource-namespace:s" => { name => 'resource_namespace' }, - "filter-metric:s" => { name => 'filter_metric' }, - "per-sec" => { name => 'per_sec' }, - }); - + $options{options}->add_options(arguments => { + "resource:s@" => { name => 'resource' }, + "resource-group:s" => { name => 'resource_group' }, + "resource-namespace:s" => { name => 'resource_namespace' }, + "filter-metric:s" => { name => 'filter_metric' }, + "per-sec" => { name => 'per_sec' }, + }); + return $self; } @@ -166,8 +163,6 @@ sub check_options { push @{$self->{az_metrics}}, $metric; } - - $instance_mode = $self; } sub manage_selection { diff --git a/cloud/kubernetes/restapi/mode/podstatus.pm b/cloud/kubernetes/restapi/mode/podstatus.pm index 3cd27816c..b0f87645f 100644 --- a/cloud/kubernetes/restapi/mode/podstatus.pm +++ b/cloud/kubernetes/restapi/mode/podstatus.pm @@ -26,8 +26,6 @@ use strict; use warnings; use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); -my $instance_mode; - sub custom_pod_status_output { my ($self, %options) = @_; @@ -69,7 +67,7 @@ sub custom_ready_perfdata { my $extra_label = ''; $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); my %total_options = (); - if ($self->{result_values}->{total} > 0 && $instance_mode->{option_results}->{units} eq '%') { + if ($self->{result_values}->{total} > 0 && $self->{instance_mode}->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{total}; $total_options{cast_int} = 1; } @@ -86,7 +84,7 @@ sub custom_ready_threshold { my ($exit, $threshold_value); $threshold_value = $self->{result_values}->{ready}; - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_ready}; } $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, @@ -222,9 +220,7 @@ sub check_options { $self->SUPER::check_options(%options); $self->change_macros(macros => ['warning_pod_status', 'critical_pod_status', - 'warning_container_status', 'critical_container_status']); - - $instance_mode = $self; + 'warning_container_status', 'critical_container_status']); } sub manage_selection { diff --git a/cloud/microsoft/office365/exchange/mode/emailactivity.pm b/cloud/microsoft/office365/exchange/mode/emailactivity.pm index b6cd08ec3..ac703fb99 100644 --- a/cloud/microsoft/office365/exchange/mode/emailactivity.pm +++ b/cloud/microsoft/office365/exchange/mode/emailactivity.pm @@ -25,13 +25,11 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub custom_active_perfdata { my ($self, %options) = @_; my %total_options = (); - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{total}; $total_options{cast_int} = 1; } @@ -47,7 +45,7 @@ sub custom_active_threshold { my ($self, %options) = @_; my $threshold_value = $self->{result_values}->{active}; - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_active}; } my $exit = $self->{perfdata}->threshold_check(value => $threshold_value, @@ -176,23 +174,15 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "filter-mailbox:s" => { name => 'filter_mailbox' }, - "units:s" => { name => 'units', default => '%' }, - "filter-counters:s" => { name => 'filter_counters', default => 'active|total' }, - }); + $options{options}->add_options(arguments => { + "filter-mailbox:s" => { name => 'filter_mailbox' }, + "units:s" => { name => 'units', default => '%' }, + "filter-counters:s" => { name => 'filter_counters', default => 'active|total' }, + }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $instance_mode = $self; -} - sub manage_selection { my ($self, %options) = @_; diff --git a/cloud/microsoft/office365/exchange/mode/mailboxusage.pm b/cloud/microsoft/office365/exchange/mode/mailboxusage.pm index ef2991be5..7f7fe4e0b 100644 --- a/cloud/microsoft/office365/exchange/mode/mailboxusage.pm +++ b/cloud/microsoft/office365/exchange/mode/mailboxusage.pm @@ -25,13 +25,11 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub custom_active_perfdata { my ($self, %options) = @_; my %total_options = (); - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{total}; $total_options{cast_int} = 1; } @@ -47,7 +45,7 @@ sub custom_active_threshold { my ($self, %options) = @_; my $threshold_value = $self->{result_values}->{active}; - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_active}; } my $exit = $self->{perfdata}->threshold_check(value => $threshold_value, @@ -100,11 +98,11 @@ sub custom_status_threshold { local $SIG{__WARN__} = sub { $message = $_[0]; }; local $SIG{__DIE__} = sub { $message = $_[0]; }; - if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && - eval "$instance_mode->{option_results}->{critical_status}") { + if (defined($self->{instance_mode}->{option_results}->{critical_status}) && $self->{instance_mode}->{option_results}->{critical_status} ne '' && + eval "$self->{instance_mode}->{option_results}->{critical_status}") { $status = 'critical'; - } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && - eval "$instance_mode->{option_results}->{warning_status}") { + } elsif (defined($self->{instance_mode}->{option_results}->{warning_status}) && $self->{instance_mode}->{option_results}->{warning_status} ne '' && + eval "$self->{instance_mode}->{option_results}->{warning_status}") { $status = 'warning'; } }; @@ -223,34 +221,22 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "filter-mailbox:s" => { name => 'filter_mailbox' }, - "warning-status:s" => { name => 'warning_status', default => '%{used} > %{issue_warning_quota}' }, - "critical-status:s" => { name => 'critical_status', default => '%{used} > %{prohibit_send_quota}' }, - "units:s" => { name => 'units', default => '%' }, - "filter-counters:s" => { name => 'filter_counters', default => 'active|total' }, - }); - + $options{options}->add_options(arguments => { + "filter-mailbox:s" => { name => 'filter_mailbox' }, + "warning-status:s" => { name => 'warning_status', default => '%{used} > %{issue_warning_quota}' }, + "critical-status:s" => { name => 'critical_status', default => '%{used} > %{prohibit_send_quota}' }, + "units:s" => { name => 'units', default => '%' }, + "filter-counters:s" => { name => 'filter_counters', default => 'active|total' }, + }); + return $self; } -sub change_macros { - my ($self, %options) = @_; - - foreach (('warning_status', 'critical_status')) { - if (defined($self->{option_results}->{$_})) { - $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; - } - } -} - sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $instance_mode = $self; - $self->change_macros(); + $self->change_macros(macros => ['warning_status', 'critical_status']); } sub manage_selection { diff --git a/cloud/microsoft/office365/onedrive/mode/usage.pm b/cloud/microsoft/office365/onedrive/mode/usage.pm index 23aafa0f8..a32af5c53 100644 --- a/cloud/microsoft/office365/onedrive/mode/usage.pm +++ b/cloud/microsoft/office365/onedrive/mode/usage.pm @@ -25,13 +25,11 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub custom_active_perfdata { my ($self, %options) = @_; my %total_options = (); - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{total}; $total_options{cast_int} = 1; } @@ -47,7 +45,7 @@ sub custom_active_threshold { my ($self, %options) = @_; my $threshold_value = $self->{result_values}->{active}; - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_active}; } my $exit = $self->{perfdata}->threshold_check(value => $threshold_value, @@ -98,10 +96,10 @@ sub custom_usage_threshold { my ($exit, $threshold_value); $threshold_value = $self->{result_values}->{used}; - $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); - if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free})); + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_used}; - $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + $threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free})); } $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, @@ -250,23 +248,15 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "filter-url:s" => { name => 'filter_url' }, - "filter-owner:s" => { name => 'filter_owner' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, - "filter-counters:s" => { name => 'filter_counters', default => 'active-sites|total' }, - }); - - return $self; -} + $options{options}->add_options(arguments => { + "filter-url:s" => { name => 'filter_url' }, + "filter-owner:s" => { name => 'filter_owner' }, + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, + "filter-counters:s" => { name => 'filter_counters', default => 'active-sites|total' }, + }); -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $instance_mode = $self; + return $self; } sub manage_selection { diff --git a/cloud/microsoft/office365/sharepoint/mode/siteusage.pm b/cloud/microsoft/office365/sharepoint/mode/siteusage.pm index ad2ed1489..d11533150 100644 --- a/cloud/microsoft/office365/sharepoint/mode/siteusage.pm +++ b/cloud/microsoft/office365/sharepoint/mode/siteusage.pm @@ -25,13 +25,11 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub custom_active_perfdata { my ($self, %options) = @_; my %total_options = (); - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{total}; $total_options{cast_int} = 1; } @@ -47,7 +45,7 @@ sub custom_active_threshold { my ($self, %options) = @_; my $threshold_value = $self->{result_values}->{active}; - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_active}; } my $exit = $self->{perfdata}->threshold_check(value => $threshold_value, @@ -98,10 +96,10 @@ sub custom_usage_threshold { my ($exit, $threshold_value); $threshold_value = $self->{result_values}->{used}; - $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); - if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free})); + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_used}; - $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + $threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free})); } $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, @@ -286,23 +284,15 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "filter-url:s" => { name => 'filter_url' }, - "filter-id:s" => { name => 'filter_id' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, - "filter-counters:s" => { name => 'filter_counters', default => 'active-sites|total' }, - }); - - return $self; -} + $options{options}->add_options(arguments => { + "filter-url:s" => { name => 'filter_url' }, + "filter-id:s" => { name => 'filter_id' }, + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, + "filter-counters:s" => { name => 'filter_counters', default => 'active-sites|total' }, + }); -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $instance_mode = $self; + return $self; } sub manage_selection { diff --git a/cloud/microsoft/office365/sharepoint/mode/usersactivity.pm b/cloud/microsoft/office365/sharepoint/mode/usersactivity.pm index e248fd0f1..a4e0eeb53 100644 --- a/cloud/microsoft/office365/sharepoint/mode/usersactivity.pm +++ b/cloud/microsoft/office365/sharepoint/mode/usersactivity.pm @@ -25,13 +25,11 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub custom_active_perfdata { my ($self, %options) = @_; my %total_options = (); - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{total}; $total_options{cast_int} = 1; } @@ -47,7 +45,7 @@ sub custom_active_threshold { my ($self, %options) = @_; my $threshold_value = $self->{result_values}->{active}; - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_active}; } my $exit = $self->{perfdata}->threshold_check(value => $threshold_value, @@ -212,23 +210,15 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "filter-user:s" => { name => 'filter_user' }, - "units:s" => { name => 'units', default => '%' }, - "filter-counters:s" => { name => 'filter_counters', default => 'active|total' }, - }); - + $options{options}->add_options(arguments => { + "filter-user:s" => { name => 'filter_user' }, + "units:s" => { name => 'units', default => '%' }, + "filter-counters:s" => { name => 'filter_counters', default => 'active|total' }, + }); + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $instance_mode = $self; -} - sub manage_selection { my ($self, %options) = @_; diff --git a/cloud/microsoft/office365/skype/mode/devicesusage.pm b/cloud/microsoft/office365/skype/mode/devicesusage.pm index ba372a89e..6c740b8ab 100644 --- a/cloud/microsoft/office365/skype/mode/devicesusage.pm +++ b/cloud/microsoft/office365/skype/mode/devicesusage.pm @@ -25,13 +25,11 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub custom_active_perfdata { my ($self, %options) = @_; my %total_options = (); - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{total}; $total_options{cast_int} = 1; } @@ -47,7 +45,7 @@ sub custom_active_threshold { my ($self, %options) = @_; my $threshold_value = $self->{result_values}->{active}; - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_active}; } my $exit = $self->{perfdata}->threshold_check(value => $threshold_value, @@ -158,23 +156,14 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "filter-user:s" => { name => 'filter_user' }, - "units:s" => { name => 'units', default => '%' }, - "filter-counters:s" => { name => 'filter_counters' }, - }); + $options{options}->add_options(arguments => { + "filter-user:s" => { name => 'filter_user' }, + "units:s" => { name => 'units', default => '%' }, + }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $instance_mode = $self; -} - sub manage_selection { my ($self, %options) = @_; diff --git a/cloud/microsoft/office365/skype/mode/usersactivity.pm b/cloud/microsoft/office365/skype/mode/usersactivity.pm index 996d67afc..64650efdb 100644 --- a/cloud/microsoft/office365/skype/mode/usersactivity.pm +++ b/cloud/microsoft/office365/skype/mode/usersactivity.pm @@ -25,13 +25,11 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub custom_active_perfdata { my ($self, %options) = @_; my %total_options = (); - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{total}; $total_options{cast_int} = 1; } @@ -47,7 +45,7 @@ sub custom_active_threshold { my ($self, %options) = @_; my $threshold_value = $self->{result_values}->{active}; - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_active}; } my $exit = $self->{perfdata}->threshold_check(value => $threshold_value, @@ -176,23 +174,15 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "filter-user:s" => { name => 'filter_user' }, - "units:s" => { name => 'units', default => '%' }, - "filter-counters:s" => { name => 'filter_counters', default => 'active|total' }, - }); - + $options{options}->add_options(arguments => { + "filter-user:s" => { name => 'filter_user' }, + "units:s" => { name => 'units', default => '%' }, + "filter-counters:s" => { name => 'filter_counters', default => 'active|total' }, + }); + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $instance_mode = $self; -} - sub manage_selection { my ($self, %options) = @_; diff --git a/cloud/microsoft/office365/teams/mode/devicesusage.pm b/cloud/microsoft/office365/teams/mode/devicesusage.pm index c8832fe22..48e0607e6 100644 --- a/cloud/microsoft/office365/teams/mode/devicesusage.pm +++ b/cloud/microsoft/office365/teams/mode/devicesusage.pm @@ -25,13 +25,11 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub custom_active_perfdata { my ($self, %options) = @_; my %total_options = (); - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{total}; $total_options{cast_int} = 1; } @@ -47,7 +45,7 @@ sub custom_active_threshold { my ($self, %options) = @_; my $threshold_value = $self->{result_values}->{active}; - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_active}; } my $exit = $self->{perfdata}->threshold_check(value => $threshold_value, @@ -167,23 +165,14 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "filter-user:s" => { name => 'filter_user' }, - "units:s" => { name => 'units', default => '%' }, - "filter-counters:s" => { name => 'filter_counters' }, - }); - + $options{options}->add_options(arguments => { + "filter-user:s" => { name => 'filter_user' }, + "units:s" => { name => 'units', default => '%' }, + }); + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $instance_mode = $self; -} - sub manage_selection { my ($self, %options) = @_; diff --git a/cloud/microsoft/office365/teams/mode/usersactivity.pm b/cloud/microsoft/office365/teams/mode/usersactivity.pm index 108d783f3..0b88f4706 100644 --- a/cloud/microsoft/office365/teams/mode/usersactivity.pm +++ b/cloud/microsoft/office365/teams/mode/usersactivity.pm @@ -25,13 +25,11 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub custom_active_perfdata { my ($self, %options) = @_; my %total_options = (); - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{total}; $total_options{cast_int} = 1; } @@ -47,7 +45,7 @@ sub custom_active_threshold { my ($self, %options) = @_; my $threshold_value = $self->{result_values}->{active}; - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_active}; } my $exit = $self->{perfdata}->threshold_check(value => $threshold_value, @@ -194,23 +192,15 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "filter-user:s" => { name => 'filter_user' }, - "units:s" => { name => 'units', default => '%' }, - "filter-counters:s" => { name => 'filter_counters', default => 'active|total' }, - }); - + $options{options}->add_options(arguments => { + "filter-user:s" => { name => 'filter_user' }, + "units:s" => { name => 'units', default => '%' }, + "filter-counters:s" => { name => 'filter_counters', default => 'active|total' }, + }); + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $instance_mode = $self; -} - sub manage_selection { my ($self, %options) = @_; diff --git a/cloud/prometheus/exporters/cadvisor/mode/memory.pm b/cloud/prometheus/exporters/cadvisor/mode/memory.pm index 37db624a6..e29f6b16b 100644 --- a/cloud/prometheus/exporters/cadvisor/mode/memory.pm +++ b/cloud/prometheus/exporters/cadvisor/mode/memory.pm @@ -25,8 +25,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub custom_usage_perfdata { my ($self, %options) = @_; @@ -35,7 +33,7 @@ sub custom_usage_perfdata { my $extra_label = ''; $extra_label = '_' . $self->{result_values}->{perf} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); my %total_options = (); - if ($self->{result_values}->{total} > 0 && $instance_mode->{option_results}->{units} eq '%') { + if ($self->{result_values}->{total} > 0 && $self->{instance_mode}->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{total}; $total_options{cast_int} = 1; } @@ -50,10 +48,10 @@ sub custom_usage_perfdata { sub custom_usage_threshold { my ($self, %options) = @_; - return 'ok' if ($self->{result_values}->{total} <= 0 && $instance_mode->{option_results}->{units} eq '%'); + return 'ok' if ($self->{result_values}->{total} <= 0 && $self->{instance_mode}->{option_results}->{units} eq '%'); my ($exit, $threshold_value); $threshold_value = $self->{result_values}->{used}; - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_used}; } $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{result_values}->{label}, exit_litteral => 'critical' }, @@ -168,16 +166,15 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "container:s" => { name => 'container', default => 'container_name!~".*POD.*"' }, - "pod:s" => { name => 'pod', default => 'pod_name=~".*"' }, - "extra-filter:s@" => { name => 'extra_filter' }, - "units:s" => { name => 'units', default => '%' }, - "metric-overload:s@" => { name => 'metric_overload' }, - "filter-counters:s" => { name => 'filter_counters' }, - }); - + $options{options}->add_options(arguments => { + "container:s" => { name => 'container', default => 'container_name!~".*POD.*"' }, + "pod:s" => { name => 'pod', default => 'pod_name=~".*"' }, + "extra-filter:s@" => { name => 'extra_filter' }, + "units:s" => { name => 'units', default => '%' }, + "metric-overload:s@" => { name => 'metric_overload' }, + "filter-counters:s" => { name => 'filter_counters' }, + }); + return $self; } @@ -210,9 +207,7 @@ sub check_options { $self->{extra_filter} = ''; foreach my $filter (@{$self->{option_results}->{extra_filter}}) { $self->{extra_filter} .= ',' . $filter; - } - - $instance_mode = $self; + } } sub manage_selection { diff --git a/cloud/prometheus/exporters/cadvisor/mode/storage.pm b/cloud/prometheus/exporters/cadvisor/mode/storage.pm index 39d5cb52d..efbbd36e8 100644 --- a/cloud/prometheus/exporters/cadvisor/mode/storage.pm +++ b/cloud/prometheus/exporters/cadvisor/mode/storage.pm @@ -25,8 +25,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub custom_usage_perfdata { my ($self, %options) = @_; @@ -34,12 +32,12 @@ sub custom_usage_perfdata { $extra_label = '_' . $self->{result_values}->{label} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); my $label = 'used'; my $value_perf = $self->{result_values}->{used}; - if (defined($instance_mode->{option_results}->{free})) { + if (defined($self->{instance_mode}->{option_results}->{free})) { $label = 'free'; $value_perf = $self->{result_values}->{free}; } my %total_options = (); - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{total}; $total_options{cast_int} = 1; } @@ -56,10 +54,10 @@ sub custom_usage_threshold { my ($exit, $threshold_value); $threshold_value = $self->{result_values}->{used}; - $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); - if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free})); + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_used}; - $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + $threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free})); } $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); return $exit; @@ -149,17 +147,16 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "container:s" => { name => 'container', default => 'container_name!~".*POD.*"' }, - "pod:s" => { name => 'pod', default => 'pod_name=~".*"' }, - "device:s" => { name => 'device', default => 'device=~".*"' }, - "extra-filter:s@" => { name => 'extra_filter' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, - "metric-overload:s@" => { name => 'metric_overload' }, - }); - + $options{options}->add_options(arguments => { + "container:s" => { name => 'container', default => 'container_name!~".*POD.*"' }, + "pod:s" => { name => 'pod', default => 'pod_name=~".*"' }, + "device:s" => { name => 'device', default => 'device=~".*"' }, + "extra-filter:s@" => { name => 'extra_filter' }, + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, + "metric-overload:s@" => { name => 'metric_overload' }, + }); + return $self; } @@ -188,9 +185,7 @@ sub check_options { $self->{extra_filter} = ''; foreach my $filter (@{$self->{option_results}->{extra_filter}}) { $self->{extra_filter} .= ',' . $filter; - } - - $instance_mode = $self; + } } sub manage_selection { diff --git a/cloud/prometheus/exporters/nodeexporter/mode/memory.pm b/cloud/prometheus/exporters/nodeexporter/mode/memory.pm index a430673d2..5151e6dc6 100644 --- a/cloud/prometheus/exporters/nodeexporter/mode/memory.pm +++ b/cloud/prometheus/exporters/nodeexporter/mode/memory.pm @@ -25,8 +25,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub custom_usage_perfdata { my ($self, %options) = @_; @@ -35,7 +33,7 @@ sub custom_usage_perfdata { my $extra_label = ''; $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); my %total_options = (); - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{total}; $total_options{cast_int} = 1; } @@ -52,7 +50,7 @@ sub custom_usage_threshold { my ($exit, $threshold_value); $threshold_value = $self->{result_values}->{used}; - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_used}; } $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, @@ -137,15 +135,13 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "instance:s" => { name => 'instance', default => 'instance=~".*"' }, - "units:s" => { name => 'units', default => '%' }, - "extra-filter:s@" => { name => 'extra_filter' }, - "metric-overload:s@" => { name => 'metric_overload' }, - "filter-counters:s" => { name => 'filter_counters' }, - }); - + $options{options}->add_options(arguments => { + "instance:s" => { name => 'instance', default => 'instance=~".*"' }, + "units:s" => { name => 'units', default => '%' }, + "extra-filter:s@" => { name => 'extra_filter' }, + "metric-overload:s@" => { name => 'metric_overload' }, + }); + return $self; } @@ -176,9 +172,7 @@ sub check_options { $self->{extra_filter} = ''; foreach my $filter (@{$self->{option_results}->{extra_filter}}) { $self->{extra_filter} .= ',' . $filter; - } - - $instance_mode = $self; + } } sub manage_selection { diff --git a/cloud/prometheus/exporters/nodeexporter/mode/storage.pm b/cloud/prometheus/exporters/nodeexporter/mode/storage.pm index 5dd77765a..ede8dbdbe 100644 --- a/cloud/prometheus/exporters/nodeexporter/mode/storage.pm +++ b/cloud/prometheus/exporters/nodeexporter/mode/storage.pm @@ -25,8 +25,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my $instance_mode; - sub custom_usage_perfdata { my ($self, %options) = @_; @@ -34,12 +32,12 @@ sub custom_usage_perfdata { $extra_label = '_' . $self->{result_values}->{label} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); my $label = 'used'; my $value_perf = $self->{result_values}->{used}; - if (defined($instance_mode->{option_results}->{free})) { + if (defined($self->{instance_mode}->{option_results}->{free})) { $label = 'free'; $value_perf = $self->{result_values}->{free}; } my %total_options = (); - if ($instance_mode->{option_results}->{units} eq '%') { + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $total_options{total} = $self->{result_values}->{total}; $total_options{cast_int} = 1; } @@ -56,10 +54,10 @@ sub custom_usage_threshold { my ($exit, $threshold_value); $threshold_value = $self->{result_values}->{used}; - $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); - if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free})); + if ($self->{instance_mode}->{option_results}->{units} eq '%') { $threshold_value = $self->{result_values}->{prct_used}; - $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + $threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free})); } $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); return $exit; @@ -149,17 +147,16 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "instance:s" => { name => 'instance', default => 'instance=~".*"' }, - "mountpoint:s" => { name => 'mountpoint', default => 'mountpoint=~".*"' }, - "fstype:s" => { name => 'fstype', default => 'fstype!~"linuxfs|rootfs|tmpfs"' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, - "extra-filter:s@" => { name => 'extra_filter' }, - "metric-overload:s@" => { name => 'metric_overload' }, - }); - + $options{options}->add_options(arguments => { + "instance:s" => { name => 'instance', default => 'instance=~".*"' }, + "mountpoint:s" => { name => 'mountpoint', default => 'mountpoint=~".*"' }, + "fstype:s" => { name => 'fstype', default => 'fstype!~"linuxfs|rootfs|tmpfs"' }, + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, + "extra-filter:s@" => { name => 'extra_filter' }, + "metric-overload:s@" => { name => 'metric_overload' }, + }); + return $self; } @@ -188,9 +185,7 @@ sub check_options { $self->{extra_filter} = ''; foreach my $filter (@{$self->{option_results}->{extra_filter}}) { $self->{extra_filter} .= ',' . $filter; - } - - $instance_mode = $self; + } } sub manage_selection {