From 522a45fcd03917109fe46068daf3d8546f4b8100 Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Mon, 23 Mar 2020 16:31:46 +0100 Subject: [PATCH 001/190] typo(juniper): wrong help options --- .../juniper/common/junos/mode/interfaces.pm | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/centreon-plugins/network/juniper/common/junos/mode/interfaces.pm b/centreon-plugins/network/juniper/common/junos/mode/interfaces.pm index 9ba38452e..d05fad196 100644 --- a/centreon-plugins/network/juniper/common/junos/mode/interfaces.pm +++ b/centreon-plugins/network/juniper/common/junos/mode/interfaces.pm @@ -263,13 +263,7 @@ Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'to 'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%), 'speed' (b/s). -And also: 'in-tooshort' (%), 'in-toolong' (%), 'in-fcserror' (%), 'in-alignerror' (%), 'in-fragment' (%), -'in-overflow' (%), 'in-unknownop' (%), 'in-lengtherror' (%), 'in-codeerror' (%), 'in-carriererror' (%), -'in-jabber' (%), 'in-drop' (%), 'out-tooshort' (%), 'out-toolong' (%), 'out-underrun' (%), -'out-collision' (%), 'out-excessivecollision' (%), 'out-multiplecollision' (%), 'out-singlecollision' (%), -'out-excessivedeferred' (%),'out-deferred' (%), 'out-latecollision' (%), 'out-totalcollision' (%), -'out-drop' (%), 'out-jabber' (%), 'out-fcserror' (%), 'out-fragment' (%), -'input-power' (dBm), 'bias-current' (mA), 'output-power' (dBm), 'module-temperature' (C). +And also: 'fcs-errors (%)', 'input-power' (dBm), 'bias-current' (mA), 'output-power' (dBm), 'module-temperature' (C). =item B<--critical-*> @@ -279,13 +273,7 @@ Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'to 'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%), 'speed' (b/s). -And also: 'in-tooshort' (%), 'in-toolong' (%), 'in-fcserror' (%), 'in-alignerror' (%), 'in-fragment' (%), -'in-overflow' (%), 'in-unknownop' (%), 'in-lengtherror' (%), 'in-codeerror' (%), 'in-carriererror' (%), -'in-jabber' (%), 'in-drop' (%), 'out-tooshort' (%), 'out-toolong' (%), 'out-underrun' (%), -'out-collision' (%), 'out-excessivecollision' (%), 'out-multiplecollision' (%), 'out-singlecollision' (%), -'out-excessivedeferred' (%),'out-deferred' (%), 'out-latecollision' (%), 'out-totalcollision' (%), -'out-drop' (%), 'out-jabber' (%), 'out-fcserror' (%), 'out-fragment' (%), -'input-power' (dBm), 'bias-current' (mA), 'output-power' (dBm), 'module-temperature' (C). +And also: 'fcs-errors (%)', 'input-power' (dBm), 'bias-current' (mA), 'output-power' (dBm), 'module-temperature' (C). =item B<--units-traffic> From 98dbb8a2c0610ebde80b529526049ba13c8b5a5b Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 24 Mar 2020 08:57:09 +0100 Subject: [PATCH 002/190] remove community in snmp v3 --- centreon-plugins/centreon/plugins/snmp.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/centreon-plugins/centreon/plugins/snmp.pm b/centreon-plugins/centreon/plugins/snmp.pm index 9aa971c3f..5ccaaa770 100644 --- a/centreon-plugins/centreon/plugins/snmp.pm +++ b/centreon-plugins/centreon/plugins/snmp.pm @@ -772,6 +772,7 @@ sub check_options { } if ($options{option_results}->{snmp_version} eq '3') { + delete $self->{snmp_params}->{Community}; $self->{snmp_params}->{Context} = $options{option_results}->{snmp_context_name} if (defined($options{option_results}->{snmp_context_name})); $self->{snmp_params}->{ContextEngineId} = $options{option_results}->{snmp_context_engine_id} if (defined($options{option_results}->{snmp_context_engine_id})); From 6cf9369cf995dd89f4551fba9818144cef324c39 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 24 Mar 2020 09:25:13 +0100 Subject: [PATCH 003/190] fix ssh connection --- centreon-plugins/centreon/plugins/backend/ssh/plink.pm | 1 + centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm | 1 + centreon-plugins/network/paloalto/ssh/custom/cli.pm | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/centreon-plugins/centreon/plugins/backend/ssh/plink.pm b/centreon-plugins/centreon/plugins/backend/ssh/plink.pm index 658be03c7..1b4f745e2 100644 --- a/centreon-plugins/centreon/plugins/backend/ssh/plink.pm +++ b/centreon-plugins/centreon/plugins/backend/ssh/plink.pm @@ -65,6 +65,7 @@ sub execute { my ($self, %options) = @_; push @{$self->{ssh_option}}, '-T' if (defined($options{ssh_pipe}) && $options{ssh_pipe} == 1); + $options{command} .= $options{cmd_exit} if (defined($options{cmd_exit}) && $options{cmd_exit} ne ''); my ($content, $exit_code) = centreon::plugins::misc::execute( output => $self->{output}, diff --git a/centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm b/centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm index 2b86eca38..7374b7c21 100644 --- a/centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm +++ b/centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm @@ -67,6 +67,7 @@ sub execute { my ($self, %options) = @_; push @{$self->{ssh_option}}, '-T' if (defined($options{ssh_pipe}) && $options{ssh_pipe} == 1); + $options{command} .= $options{cmd_exit} if (defined($options{cmd_exit}) && $options{cmd_exit} ne ''); my ($content, $exit_code) = centreon::plugins::misc::execute( output => $self->{output}, diff --git a/centreon-plugins/network/paloalto/ssh/custom/cli.pm b/centreon-plugins/network/paloalto/ssh/custom/cli.pm index 31df4996a..d3f6d83d5 100644 --- a/centreon-plugins/network/paloalto/ssh/custom/cli.pm +++ b/centreon-plugins/network/paloalto/ssh/custom/cli.pm @@ -115,7 +115,8 @@ sub execute_command { command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $self->{ssh_commands}, command_path => $self->{option_results}->{command_path}, command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef, - timeout => $self->{option_results}->{timeout} + timeout => $self->{option_results}->{timeout}, + cmd_exit => !defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq '' ? "exit\n" : undef ); } else { if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq '') { From 070c55338509458381907d7b1673bb5e2673edf2 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 24 Mar 2020 09:43:23 +0100 Subject: [PATCH 004/190] fix interface name local linux --- .../os/linux/local/mode/packeterrors.pm | 33 +++++---- .../os/linux/local/mode/traffic.pm | 70 +++++++++---------- 2 files changed, 51 insertions(+), 52 deletions(-) diff --git a/centreon-plugins/os/linux/local/mode/packeterrors.pm b/centreon-plugins/os/linux/local/mode/packeterrors.pm index 19750f6d4..ae36efe81 100644 --- a/centreon-plugins/os/linux/local/mode/packeterrors.pm +++ b/centreon-plugins/os/linux/local/mode/packeterrors.pm @@ -30,14 +30,13 @@ use centreon::plugins::misc; sub custom_status_output { my ($self, %options) = @_; - - my $msg = sprintf('status : %s', $self->{result_values}->{status}); - return $msg; + + return sprintf('status : %s', $self->{result_values}->{status}); } sub custom_status_calc { my ($self, %options) = @_; - + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; return 0; @@ -46,13 +45,12 @@ sub custom_status_calc { sub custom_packet_output { my ($self, %options) = @_; - my $msg = sprintf("Packet %s %s : %.2f %% (%s)", + return sprintf('Packet %s %s : %.2f %% (%s)', ucfirst($self->{result_values}->{type}), ucfirst($self->{result_values}->{label}), $self->{result_values}->{result_prct}, $self->{result_values}->{diff_value} ); - return $msg; } sub custom_packet_calc { @@ -72,11 +70,11 @@ sub custom_packet_calc { sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'interface', type => 1, cb_prefix_output => 'prefix_interface_output', message_multiple => 'All interfaces are ok', skipped_code => { -10 => 1 } }, ]; - + $self->{maps_counters}->{interface} = [ { label => 'status', threshold => 0, set => { key_values => [ { name => 'status' }, { name => 'display' } ], @@ -137,7 +135,7 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - + $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, "remote" => { name => 'remote' }, @@ -171,12 +169,12 @@ sub prefix_interface_output { sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - + $self->{hostname} = $self->{option_results}->{hostname}; if (!defined($self->{hostname})) { $self->{hostname} = 'me'; } - + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); } @@ -191,7 +189,7 @@ sub do_selection { command_path => $self->{option_results}->{command_path}, command_options => $self->{option_results}->{command_options} ); - + my $mapping = { ifconfig => { get_interface => '^(\S+)(.*?)(\n\n|\n$)', @@ -210,23 +208,24 @@ sub do_selection { error_out => 'TX:.*?errors.*?\d+.*?\d+.*?(\d+)', }, }; - + my $type = 'ifconfig'; if ($stdout =~ /^\d+:\s+\S+:\s+{interface} = {}; while ($stdout =~ /$mapping->{$type}->{get_interface}/msg) { my ($interface_name, $values) = ($1, $2); my $states = ''; $states .= 'R' if ($values =~ /RUNNING|LOWER_UP/ms); $states .= 'U' if ($values =~ /UP/ms); - + $interface_name =~ s/:$//; + next if (defined($self->{option_results}->{no_loopback}) && $values =~ /LOOPBACK/ms); next if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' && $states !~ /$self->{option_results}->{filter_state}/); - + next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $interface_name !~ /$self->{option_results}->{name}/i); next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) @@ -249,7 +248,7 @@ sub do_selection { } } } - + if (scalar(keys %{$self->{interface}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No interface found."); $self->{output}->option_exit(); diff --git a/centreon-plugins/os/linux/local/mode/traffic.pm b/centreon-plugins/os/linux/local/mode/traffic.pm index 4de97304b..d7dfaf2a6 100644 --- a/centreon-plugins/os/linux/local/mode/traffic.pm +++ b/centreon-plugins/os/linux/local/mode/traffic.pm @@ -30,14 +30,13 @@ use centreon::plugins::misc; sub custom_status_output { my ($self, %options) = @_; - - my $msg = sprintf('status : %s', $self->{result_values}->{status}); - return $msg; + + return sprintf('status : %s', $self->{result_values}->{status}); } sub custom_status_calc { my ($self, %options) = @_; - + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; return 0; @@ -81,10 +80,11 @@ sub custom_traffic_output { my ($self, %options) = @_; my ($traffic_value, $traffic_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic_per_seconds}, network => 1); - my $msg = sprintf("Traffic %s : %s/s (%s)", - ucfirst($self->{result_values}->{label}), $traffic_value . $traffic_unit, - defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-'); - return $msg; + return sprintf( + 'Traffic %s : %s/s (%s)', + ucfirst($self->{result_values}->{label}), $traffic_value . $traffic_unit, + defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-' + ); } sub custom_traffic_calc { @@ -107,11 +107,11 @@ sub custom_traffic_calc { sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'interface', type => 1, cb_prefix_output => 'prefix_interface_output', message_multiple => 'All interfaces are ok', skipped_code => { -10 => 1 } }, ]; - + $self->{maps_counters}->{interface} = [ { label => 'status', threshold => 0, set => { key_values => [ { name => 'status' }, { name => 'display' } ], @@ -146,28 +146,28 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - + $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "remote" => { name => 'remote' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'ip' }, - "command-path:s" => { name => 'command_path', default => '/sbin' }, - "command-options:s" => { name => 'command_options', default => '-s addr 2>&1' }, - "filter-state:s" => { name => 'filter_state', }, - "units:s" => { name => 'units', default => 'b/s' }, - "name:s" => { name => 'name' }, - "regexp" => { name => 'use_regexp' }, - "regexp-isensitive" => { name => 'use_regexpi' }, - "speed:s" => { name => 'speed' }, - "no-loopback" => { name => 'no_loopback', }, - "unknown-status:s" => { name => 'unknown_status', default => '' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} ne "RU"' }, + 'hostname:s' => { name => 'hostname' }, + 'remote' => { name => 'remote' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'ip' }, + 'command-path:s' => { name => 'command_path', default => '/sbin' }, + 'command-options:s' => { name => 'command_options', default => '-s addr 2>&1' }, + 'filter-state:s' => { name => 'filter_state', }, + 'units:s' => { name => 'units', default => 'b/s' }, + 'name:s' => { name => 'name' }, + 'regexp' => { name => 'use_regexp' }, + 'regexp-isensitive' => { name => 'use_regexpi' }, + 'speed:s' => { name => 'speed' }, + 'no-loopback' => { name => 'no_loopback', }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} ne "RU"' }, }); return $self; @@ -200,7 +200,7 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "To use percent, you need to set --speed option."); $self->{output}->option_exit(); } - + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); } @@ -226,16 +226,16 @@ sub do_selection { while ($stdout =~ /$interface_pattern/msg) { my ($interface_name, $values) = ($1, $2); - + $interface_name =~ s/:$//; my $states = ''; $states .= 'R' if ($values =~ /RUNNING|LOWER_UP/ms); $states .= 'U' if ($values =~ /UP/ms); - + next if (defined($self->{option_results}->{no_loopback}) && $values =~ /LOOPBACK/ms); next if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' && $states !~ /$self->{option_results}->{filter_state}/); - + next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $interface_name !~ /$self->{option_results}->{name}/i); next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) From 478b167702d55c06f2787bfdf42066a9e1e10987 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 24 Mar 2020 10:49:59 +0100 Subject: [PATCH 005/190] forgitage vdom: add number of policies --- .../fortinet/fortigate/snmp/mode/vdomusage.pm | 43 +++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/snmp/mode/vdomusage.pm b/centreon-plugins/centreon/common/fortinet/fortigate/snmp/mode/vdomusage.pm index 1c5d0c7e1..e4d596b99 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/snmp/mode/vdomusage.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/snmp/mode/vdomusage.pm @@ -103,6 +103,7 @@ sub set_counters { { name => 'vdom_memory', type => 0, skipped_code => { -10 => 1 } }, { name => 'vdom_session', type => 0, skipped_code => { -10 => 1 } }, { name => 'vdom_traffic', type => 0, skipped_code => { -10 => 1 } }, + { name => 'vdom_policy', type => 0, skipped_code => { -10 => 1 } }, { name => 'vdom_status', type => 0, skipped_code => { -10 => 1 } } ] } @@ -159,6 +160,18 @@ sub set_counters { } ]; + $self->{maps_counters}->{vdom_policy} = [ + { label => 'policies-active', nlabel => 'virtualdomain.policies.active.count', set => { + key_values => [ { name => 'active_policies' }, { name => 'display' } ], + output_template => 'active policies: %d', + perfdatas => [ + { value => 'active_policies_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + } + ]; + $self->{maps_counters}->{vdom_session} = [ { label => 'sessions-active', nlabel => 'virtualdomain.sessions.active.count', set => { key_values => [ { name => 'active_sessions' }, { name => 'display' } ], @@ -177,7 +190,7 @@ sub set_counters { min => 0, unit => '/s', label_extra_instance => 1, instance_use => 'display_absolute' } ], } - }, + } ]; $self->{maps_counters}->{vdom_status} = [ @@ -217,7 +230,7 @@ sub set_counters { min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }, ], } - }, + } ]; } @@ -229,6 +242,7 @@ sub new { $options{options}->add_options(arguments => { 'filter-vdomain:s' => { name => 'filter_vdomain' }, 'add-traffic' => { name => 'add_traffic' }, + 'add-policy' => { name => 'add_policy' }, 'warning-status:s' => { name => 'warning_status', default => '' }, 'critical-status:s' => { name => 'critical_status', default => '' } }); @@ -301,6 +315,19 @@ sub add_traffic { } } +sub add_policy { + my ($self, %options) = @_; + + my $oid_fgFwPolID = '.1.3.6.1.4.1.12356.101.5.1.2.1.1.1'; + + my $snmp_result = $options{snmp}->get_table(oid => $oid_fgFwPolID); + foreach (keys %$snmp_result) { + /^$oid_fgFwPolID\.(\d+)/; + $self->{vdom}->{$1}->{vdom_policy}->{active_policies}++ + if (defined($self->{vdom}->{$1})); + } +} + sub manage_selection { my ($self, %options) = @_; @@ -338,8 +365,10 @@ sub manage_selection { vdom_cpu => { display => $name }, vdom_memory => { display => $name }, vdom_session => { display => $name }, - vdom_status => { display => $name }, + vdom_status => { display => $name } }; + $self->{vdom}->{$instance}->{vdom_policy} = { display => $name, active_policies => 0 } + if (defined($self->{option_results}->{add_policy})); } return if (scalar(keys %{$self->{vdom}}) <= 0); @@ -362,6 +391,8 @@ sub manage_selection { $self->add_traffic(snmp => $options{snmp}) if (defined($self->{option_results}->{add_traffic})); + $self->add_policy(snmp => $options{snmp}) + if (defined($self->{option_results}->{add_policy})); $self->{cache_name} = 'fortinet_fortigate_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . @@ -386,6 +417,10 @@ Filter by virtual domain name (can be a regexp). Add traffic usage by virtual domain. +=item B<--add-policy> + +Add number of policies by virtual domain. + =item B<--warning-status> Set warning threshold for status (Default: ''). @@ -401,7 +436,7 @@ Can used special variables like: %{op_mode}, %{ha_state} Thresholds. Can be: 'cpu-utilization', 'sessions-active', 'session-rate', 'memory-usage-prct', 'license-usage', 'license-free', -'license-usage-prct', 'traffic-in', 'traffic-out'. +'license-usage-prct', 'traffic-in', 'traffic-out', 'policies-active'. =back From 755944ef763296698e1ef870452a2e8ead01ba40 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 24 Mar 2020 11:27:14 +0100 Subject: [PATCH 006/190] add vdom for interfaces fortigate --- .../fortigate/snmp/mode/interfaces.pm | 197 +++++++++++++++ .../network/fortinet/fortigate/snmp/plugin.pm | 2 +- .../snmp_standard/mode/interfaces.pm | 224 ++++++++++-------- 3 files changed, 319 insertions(+), 104 deletions(-) create mode 100644 centreon-plugins/centreon/common/fortinet/fortigate/snmp/mode/interfaces.pm diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/snmp/mode/interfaces.pm b/centreon-plugins/centreon/common/fortinet/fortigate/snmp/mode/interfaces.pm new file mode 100644 index 000000000..2c39ef269 --- /dev/null +++ b/centreon-plugins/centreon/common/fortinet/fortigate/snmp/mode/interfaces.pm @@ -0,0 +1,197 @@ +# +# 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 centreon::common::fortinet::fortigate::snmp::mode::interfaces; + +use base qw(snmp_standard::mode::interfaces); + +use strict; +use warnings; + +sub set_oids_label { + my ($self, %options) = @_; + + $self->SUPER::set_oids_label(%options); + $self->{oids_label}->{vdom} = { oid => '.1.3.6.1.4.1.12356.101.7.2.1.1.1', cache => 'reload_cache_vdom_index' }; +} + +sub reload_cache_vdom_index { + my ($self, %options) = @_; + + my $oid_fgVdEntName = '.1.3.6.1.4.1.12356.101.3.2.1.1.2'; + my $snmp_result = $self->{snmp}->get_table(oid => $oid_fgVdEntName); + + my $store_index = defined($options{store_index}) && $options{store_index} == 1 ? 1 : 0; + foreach (keys %{$options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }}) { + /^$self->{oids_label}->{$options{name}}->{oid}\.(.*)$/; + push @{$options{datas}->{all_ids}}, $1 if ($store_index == 1); + + $options{datas}->{$options{name} . "_" . $1} = $snmp_result->{ $oid_fgVdEntName . '.' . $options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }->{$_} }; + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + return $self; +} + + +1; + +__END__ + +=head1 MODE + +Check interfaces. + +=over 8 + +=item B<--add-global> + +Check global port statistics (By default if no --add-* option is set). + +=item B<--add-status> + +Check interface status. + +=item B<--add-duplex-status> + +Check duplex status (with --warning-status and --critical-status). + +=item B<--add-traffic> + +Check interface traffic. + +=item B<--add-errors> + +Check interface errors. + +=item B<--add-cast> + +Check interface cast. + +=item B<--add-speed> + +Check interface speed. + +=item B<--add-volume> + +Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting). + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{admstatus} eq "up" and %{opstatus} ne "up"'). +Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} + +=item B<--warning-*> + +Threshold warning. +Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', +'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', +'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%), +'speed' (b/s). + +=item B<--critical-*> + +Threshold critical. +Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', +'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', +'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%), +'speed' (b/s). + +=item B<--units-traffic> + +Units of thresholds for the traffic (Default: '%') ('%', 'b/s'). + +=item B<--units-errors> + +Units of thresholds for errors/discards (Default: '%') ('%', 'absolute'). + +=item B<--nagvis-perfdata> + +Display traffic perfdata to be compatible with nagvis widget. + +=item B<--interface> + +Set the interface (number expected) ex: 1,2,... (empty means 'check all interface'). + +=item B<--name> + +Allows to use interface name with option --interface instead of interface oid index (Can be a regexp) + +=item B<--speed> + +Set interface speed for incoming/outgoing traffic (in Mb). + +=item B<--speed-in> + +Set interface speed for incoming traffic (in Mb). + +=item B<--speed-out> + +Set interface speed for outgoing traffic (in Mb). + +=item B<--no-skipped-counters> + +Don't skip counters when no change. + +=item B<--force-counters32> + +Force to use 32 bits counters (even in snmp v2c and v3). Should be used when 64 bits counters are buggy. + +=item B<--reload-cache-time> + +Time in minutes before reloading cache file (default: 180). + +=item B<--oid-filter> + +Choose OID used to filter interface (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr, Vdom). + +=item B<--oid-display> + +Choose OID used to display interface (default: ifName) (values: ifDesc, ifAlias, ifName, IpAddr, Vdom). + +=item B<--oid-extra-display> + +Add an OID to display. + +=item B<--display-transform-src> + +Regexp src to transform display value. + +=item B<--display-transform-dst> + +Regexp dst to transform display value. + +=item B<--show-cache> + +Display cache interface datas. + +=back + +=cut diff --git a/centreon-plugins/network/fortinet/fortigate/snmp/plugin.pm b/centreon-plugins/network/fortinet/fortigate/snmp/plugin.pm index 693214c43..bf748554f 100644 --- a/centreon-plugins/network/fortinet/fortigate/snmp/plugin.pm +++ b/centreon-plugins/network/fortinet/fortigate/snmp/plugin.pm @@ -36,7 +36,7 @@ sub new { 'cpu' => 'centreon::common::fortinet::fortigate::snmp::mode::cpu', 'disk' => 'centreon::common::fortinet::fortigate::snmp::mode::disk', 'hardware' => 'centreon::common::fortinet::fortigate::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', + 'interfaces' => 'centreon::common::fortinet::fortigate::snmp::mode::interfaces', 'ips-stats' => 'centreon::common::fortinet::fortigate::snmp::mode::ipsstats', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'list-virtualdomains' => 'centreon::common::fortinet::fortigate::snmp::mode::listvirtualdomains', diff --git a/centreon-plugins/snmp_standard/mode/interfaces.pm b/centreon-plugins/snmp_standard/mode/interfaces.pm index c0a9a3a35..013e6b125 100644 --- a/centreon-plugins/snmp_standard/mode/interfaces.pm +++ b/centreon-plugins/snmp_standard/mode/interfaces.pm @@ -34,7 +34,7 @@ sub custom_threshold_output { my ($self, %options) = @_; my $status = 'ok'; my $message; - + eval { local $SIG{__WARN__} = sub { $message = $_[0]; }; local $SIG{__DIE__} = sub { $message = $_[0]; }; @@ -90,14 +90,14 @@ sub custom_cast_calc { my $diff_cast = ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}}); my $total = $diff_cast - + ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref1}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref1}}) - + ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref2}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref2}}); + + ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref1}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref1}}) + + ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref2}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{total_ref2}}); if ($total == 0 && !defined($self->{instance_mode}->{option_results}->{no_skipped_counters})) { $self->{error_msg} = "skipped"; return -2; } - + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; $self->{result_values}->{$options{extra_options}->{label_ref} . '_prct'} = $total == 0 ? 0 : $diff_cast * 100 / $total; return 0; @@ -126,7 +126,7 @@ sub custom_traffic_perfdata { $self->{output}->perfdata_add( label => $self->{result_values}->{label}, instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, - value => sprintf("%.2f", $self->{result_values}->{traffic_per_seconds}), + value => sprintf('%.2f', $self->{result_values}->{traffic_per_seconds}), warning => $warning, critical => $critical, min => 0, max => $self->{result_values}->{speed} @@ -136,7 +136,7 @@ sub custom_traffic_perfdata { label => 'traffic_' . $self->{result_values}->{label}, unit => 'b/s', nlabel => $self->{nlabel}, instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, - value => sprintf("%.2f", $self->{result_values}->{traffic_per_seconds}), + value => sprintf('%.2f', $self->{result_values}->{traffic_per_seconds}), warning => $warning, critical => $critical, min => 0, max => $self->{result_values}->{speed} @@ -160,10 +160,11 @@ sub custom_traffic_output { my ($self, %options) = @_; my ($traffic_value, $traffic_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic_per_seconds}, network => 1); - my $msg = sprintf("Traffic %s : %s/s (%s)", - ucfirst($self->{result_values}->{label}), $traffic_value . $traffic_unit, - defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-'); - return $msg; + return sprintf( + 'Traffic %s : %s/s (%s)', + ucfirst($self->{result_values}->{label}), $traffic_value . $traffic_unit, + defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-' + ); } sub custom_traffic_calc { @@ -171,13 +172,13 @@ sub custom_traffic_calc { return -10 if (defined($self->{instance_mode}->{last_status}) && $self->{instance_mode}->{last_status} == 0); if ($options{new_datas}->{$self->{instance} . '_mode_traffic'} ne $options{old_datas}->{$self->{instance} . '_mode_traffic'}) { - $self->{error_msg} = "buffer creation"; + $self->{error_msg} = 'buffer creation'; return -2; } my $diff_traffic = ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}}); if ($diff_traffic == 0 && !defined($self->{instance_mode}->{option_results}->{no_skipped_counters})) { - $self->{error_msg} = "skipped"; + $self->{error_msg} = 'skipped'; return -2; } @@ -187,7 +188,7 @@ sub custom_traffic_calc { $self->{result_values}->{traffic_prct} = $self->{result_values}->{traffic_per_seconds} * 100 / $options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}}; $self->{result_values}->{speed} = $options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}}; } - + $self->{result_values}->{label} = $options{extra_options}->{label_ref}; $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; return 0; @@ -223,7 +224,7 @@ sub custom_errors_perfdata { sub custom_errors_threshold { my ($self, %options) = @_; - + my $exit = 'ok'; if ($self->{instance_mode}->{option_results}->{units_errors} eq '%') { $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); @@ -236,10 +237,11 @@ sub custom_errors_threshold { sub custom_errors_output { my ($self, %options) = @_; - my $msg = sprintf("Packets %s : %.2f%% (%s)", - $self->{result_values}->{label}, - $self->{result_values}->{prct}, $self->{result_values}->{used}); - return $msg; + return sprintf( + 'Packets %s : %.2f%% (%s)', + $self->{result_values}->{label}, + $self->{result_values}->{prct}, $self->{result_values}->{used} + ); } sub custom_errors_calc { @@ -250,7 +252,7 @@ sub custom_errors_calc { $self->{error_msg} = "buffer creation"; return -2; } - + my $diff = ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref1} . $options{extra_options}->{label_ref2}} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref1} . $options{extra_options}->{label_ref2}}); my $total = ($options{new_datas}->{$self->{instance} . '_total_' . $options{extra_options}->{label_ref1} . '_packets'} - @@ -259,7 +261,7 @@ sub custom_errors_calc { $self->{error_msg} = "skipped"; return -2; } - + $self->{result_values}->{prct} = $total == 0 ? 0 : $diff * 100 / $total; $self->{result_values}->{used} = $diff; $self->{result_values}->{total} = $total; @@ -296,8 +298,8 @@ sub set_counters_global { output_use => 'total_port_absolute', threshold_use => 'total_port_absolute', perfdatas => [ { label => 'total_port', value => 'total_port_absolute', template => '%s', - min => 0, max => 'total_port_absolute' }, - ], + min => 0, max => 'total_port_absolute' } + ] } }, { label => 'global-admin-up', filter => 'add_global', nlabel => 'total.interfaces.admin.up.count', set => { @@ -306,8 +308,8 @@ sub set_counters_global { output_use => 'global_admin_up_absolute', threshold_use => 'global_admin_up_absolute', perfdatas => [ { label => 'total_admin_up', value => 'global_admin_up_absolute', template => '%s', - min => 0, max => 'total_port_absolute' }, - ], + min => 0, max => 'total_port_absolute' } + ] } }, { label => 'total-admin-down', filter => 'add_global', nlabel => 'total.interfaces.admin.down.count', set => { @@ -316,8 +318,8 @@ sub set_counters_global { output_use => 'global_admin_down_absolute', threshold_use => 'global_admin_down_absolute', perfdatas => [ { label => 'total_admin_down', value => 'global_admin_down_absolute', template => '%s', - min => 0, max => 'total_port_absolute' }, - ], + min => 0, max => 'total_port_absolute' } + ] } }, { label => 'total-oper-up', filter => 'add_global', nlabel => 'total.interfaces.operational.up.count', set => { @@ -326,8 +328,8 @@ sub set_counters_global { output_use => 'global_oper_up_absolute', threshold_use => 'global_oper_up_absolute', perfdatas => [ { label => 'total_oper_up', value => 'global_oper_up_absolute', template => '%s', - min => 0, max => 'total_port_absolute' }, - ], + min => 0, max => 'total_port_absolute' } + ] } }, { label => 'total-oper-down', filter => 'add_global', nlabel => 'total.interfaces.operational.down.count', set => { @@ -336,10 +338,10 @@ sub set_counters_global { output_use => 'global_oper_down_absolute', threshold_use => 'global_oper_down_absolute', perfdatas => [ { label => 'global_oper_down', value => 'global_oper_down_absolute', template => '%s', - min => 0, max => 'total_port_absolute' }, - ], + min => 0, max => 'total_port_absolute' } + ] } - }, + } ; } @@ -352,9 +354,9 @@ sub set_counters_status { closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => $self->can('custom_threshold_output'), + closure_custom_threshold_check => $self->can('custom_threshold_output') } - }, + } ; } @@ -370,7 +372,7 @@ sub set_counters_traffic { closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in' }, closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic In : %s', closure_custom_perfdata => $self->can('custom_traffic_perfdata'), - closure_custom_threshold_check => $self->can('custom_traffic_threshold'), + closure_custom_threshold_check => $self->can('custom_traffic_threshold') } }, { label => 'out-traffic', filter => 'add_traffic', nlabel => 'interface.traffic.out.bitspersecond', set => { @@ -379,9 +381,9 @@ sub set_counters_traffic { closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out' }, closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic Out : %s', closure_custom_perfdata => $self->can('custom_traffic_perfdata'), - closure_custom_threshold_check => $self->can('custom_traffic_threshold'), + closure_custom_threshold_check => $self->can('custom_traffic_threshold') } - }, + } ; } @@ -396,7 +398,7 @@ sub set_counters_errors { closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'in', label_ref2 => 'discard' }, closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets In Discard : %s', closure_custom_perfdata => $self->can('custom_errors_perfdata'), - closure_custom_threshold_check => $self->can('custom_errors_threshold'), + closure_custom_threshold_check => $self->can('custom_errors_threshold') } }, { label => 'in-error', filter => 'add_errors', nlabel => 'interface.packets.in.errors.count', set => { @@ -404,7 +406,7 @@ sub set_counters_errors { closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'in', label_ref2 => 'error' }, closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets In Error : %s', closure_custom_perfdata => $self->can('custom_errors_perfdata'), - closure_custom_threshold_check => $self->can('custom_errors_threshold'), + closure_custom_threshold_check => $self->can('custom_errors_threshold') } }, { label => 'out-discard', filter => 'add_errors', nlabel => 'interface.packets.out.discards.count', set => { @@ -412,7 +414,7 @@ sub set_counters_errors { closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'out', label_ref2 => 'discard' }, closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets Out Discard : %s', closure_custom_perfdata => $self->can('custom_errors_perfdata'), - closure_custom_threshold_check => $self->can('custom_errors_threshold'), + closure_custom_threshold_check => $self->can('custom_errors_threshold') } }, { label => 'out-error', filter => 'add_errors', nlabel => 'interface.packets.out.errors.count', set => { @@ -420,9 +422,9 @@ sub set_counters_errors { closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'out', label_ref2 => 'error' }, closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets Out Error : %s', closure_custom_perfdata => $self->can('custom_errors_perfdata'), - closure_custom_threshold_check => $self->can('custom_errors_threshold'), + closure_custom_threshold_check => $self->can('custom_errors_threshold') } - }, + } ; } @@ -439,8 +441,8 @@ sub set_counters_cast { output_use => 'iucast_prct', threshold_use => 'iucast_prct', perfdatas => [ { value => 'iucast_prct', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, - ], + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'in-bcast', filter => 'add_cast', nlabel => 'interface.packets.in.broadcast.count', set => { @@ -450,8 +452,8 @@ sub set_counters_cast { output_use => 'ibcast_prct', threshold_use => 'ibcast_prct', perfdatas => [ { value => 'ibcast_prct', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, - ], + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'in-mcast', filter => 'add_cast', nlabel => 'interface.packets.in.multicast.count', set => { @@ -461,8 +463,8 @@ sub set_counters_cast { output_use => 'imcast_prct', threshold_use => 'imcast_prct', perfdatas => [ { value => 'imcast_prct', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, - ], + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'out-ucast', filter => 'add_cast', nlabel => 'interface.packets.out.unicast.count', set => { @@ -472,8 +474,8 @@ sub set_counters_cast { output_use => 'oucast_prct', threshold_use => 'oucast_prct', perfdatas => [ { value => 'oucast_prct', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, - ], + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'out-bcast', filter => 'add_cast', nlabel => 'interface.packets.out.broadcast.count', set => { @@ -483,8 +485,8 @@ sub set_counters_cast { output_use => 'obcast_prct', threshold_use => 'obcast_prct', perfdatas => [ { value => 'obcast_prct', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, - ], + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'out-mcast', filter => 'add_cast', nlabel => 'interface.packets.out.multicast.count', set => { @@ -494,8 +496,8 @@ sub set_counters_cast { output_use => 'omcast_prct', threshold_use => 'omcast_prct', perfdatas => [ { value => 'omcast_prct', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, - ], + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } + ] } }, ; @@ -515,8 +517,8 @@ sub set_counters_speed { output_use => 'speed', threshold_use => 'speed', perfdatas => [ { value => 'speed', template => '%s', - unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], + unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display' } + ] } }, ; @@ -534,8 +536,8 @@ sub set_counters_volume { output_change_bytes => 1, perfdatas => [ { label => 'volume_in', value => 'in_volume_absolute', template => '%s', - unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] } }, { label => 'out-volume', filter => 'add_volume', nlabel => 'interface.volume.out.bytes', set => { @@ -544,10 +546,10 @@ sub set_counters_volume { output_change_bytes => 1, perfdatas => [ { label => 'volume_out', value => 'out_volume_absolute', template => '%s', - unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] } - }, + } ; } @@ -576,7 +578,7 @@ sub set_counters { sub prefix_interface_output { my ($self, %options) = @_; - + return "Interface '" . $options{instance_value}->{display} . "'$options{instance_value}->{extra_display} " } @@ -606,13 +608,13 @@ sub set_key_values_status { sub set_key_values_in_traffic { my ($self, %options) = @_; - + return [ { name => 'in', diff => 1 }, { name => 'speed_in'}, { name => 'display' }, { name => 'mode_traffic' } ]; } sub set_key_values_out_traffic { my ($self, %options) = @_; - + return [ { name => 'out', diff => 1 }, { name => 'speed_out'}, { name => 'display' }, { name => 'mode_traffic' } ]; } @@ -629,7 +631,7 @@ sub set_oids_label { sub set_oids_status { my ($self, %options) = @_; - + $self->{oid_adminstatus} = '.1.3.6.1.2.1.2.2.1.7'; $self->{oid_adminstatus_mapping} = { 1 => 'up', 2 => 'down', 3 => 'testing', 4 => 'unknown', 5 => 'dormant', 6 => 'notPresent', 7 => 'lowerLayerDown', @@ -646,7 +648,7 @@ sub set_oids_status { sub set_oids_errors { my ($self, %options) = @_; - + $self->{oid_ifInDiscards} = '.1.3.6.1.2.1.2.2.1.13'; $self->{oid_ifInErrors} = '.1.3.6.1.2.1.2.2.1.14'; $self->{oid_ifOutDiscards} = '.1.3.6.1.2.1.2.2.1.19'; @@ -655,7 +657,7 @@ sub set_oids_errors { sub set_oids_traffic { my ($self, %options) = @_; - + $self->{oid_speed32} = '.1.3.6.1.2.1.2.2.1.5'; # in b/s $self->{oid_in32} = '.1.3.6.1.2.1.2.2.1.10'; # in B $self->{oid_out32} = '.1.3.6.1.2.1.2.2.1.16'; # in B @@ -666,7 +668,7 @@ sub set_oids_traffic { sub set_oids_cast { my ($self, %options) = @_; - + # 32bits $self->{oid_ifInUcastPkts} = '.1.3.6.1.2.1.2.2.1.11'; $self->{oid_ifInBroadcastPkts} = '.1.3.6.1.2.1.31.1.1.1.3'; @@ -674,7 +676,7 @@ sub set_oids_cast { $self->{oid_ifOutUcastPkts} = '.1.3.6.1.2.1.2.2.1.17'; $self->{oid_ifOutMulticastPkts} = '.1.3.6.1.2.1.31.1.1.1.4'; $self->{oid_ifOutBroadcastPkts} = '.1.3.6.1.2.1.31.1.1.1.5'; - + # 64 bits $self->{oid_ifHCInUcastPkts} = '.1.3.6.1.2.1.31.1.1.1.7'; $self->{oid_ifHCInMulticastPkts} = '.1.3.6.1.2.1.31.1.1.1.8'; @@ -686,14 +688,14 @@ sub set_oids_cast { sub set_oids_speed { my ($self, %options) = @_; - + $self->{oid_speed32} = '.1.3.6.1.2.1.2.2.1.5'; # in b/s $self->{oid_speed64} = '.1.3.6.1.2.1.31.1.1.1.15'; # need multiple by '1000000' } sub check_oids_label { my ($self, %options) = @_; - + foreach (('oid_filter', 'oid_display')) { $self->{option_results}->{$_} = lc($self->{option_results}->{$_}) if (defined($self->{option_results}->{$_})); if (!defined($self->{oids_label}->{$self->{option_results}->{$_}}->{oid})) { @@ -703,7 +705,7 @@ sub check_oids_label { $self->{output}->option_exit(); } } - + if (defined($self->{option_results}->{oid_extra_display})) { $self->{option_results}->{oid_extra_display} = lc($self->{option_results}->{oid_extra_display}); if (!defined($self->{oids_label}->{$self->{option_results}->{oid_extra_display}}->{oid})) { @@ -715,55 +717,55 @@ sub check_oids_label { sub default_check_status { my ($self, %options) = @_; - + return '%{opstatus} eq "up"'; } sub default_warning_status { my ($self, %options) = @_; - + return ''; } sub default_critical_status { my ($self, %options) = @_; - + return '%{admstatus} eq "up" and %{opstatus} ne "up"'; } sub default_global_admin_up_rule { my ($self, %options) = @_; - + return '%{admstatus} eq "up"'; } sub default_global_admin_down_rule { my ($self, %options) = @_; - + return '%{admstatus} ne "up"'; } sub default_global_oper_up_rule { my ($self, %options) = @_; - + return '%{opstatus} eq "up"'; } sub default_global_oper_down_rule { my ($self, %options) = @_; - + return '%{opstatus} ne "up"'; } sub default_oid_filter_name { my ($self, %options) = @_; - + return 'ifname'; } sub default_oid_display_name { my ($self, %options) = @_; - + return 'ifname'; } @@ -798,7 +800,7 @@ sub new { 'show-cache' => { name => 'show_cache' }, 'reload-cache-time:s' => { name => 'reload_cache_time', default => 180 }, 'nagvis-perfdata' => { name => 'nagvis_perfdata' }, - 'force-counters32' => { name => 'force_counters32' }, + 'force-counters32' => { name => 'force_counters32' } }); if ($self->{no_traffic} == 0) { $options{options}->add_options(arguments => { 'add-traffic' => { name => 'add_traffic' } }); @@ -817,26 +819,26 @@ sub new { } if ($self->{no_oid_options} == 0) { $options{options}->add_options(arguments => { - 'oid-filter:s' => { name => 'oid_filter', default => $self->default_oid_filter_name() }, - 'oid-display:s' => { name => 'oid_display', default => $self->default_oid_display_name() }, - 'oid-extra-display:s' => { name => 'oid_extra_display' }, + 'oid-filter:s' => { name => 'oid_filter', default => $self->default_oid_filter_name() }, + 'oid-display:s' => { name => 'oid_display', default => $self->default_oid_display_name() }, + 'oid-extra-display:s' => { name => 'oid_extra_display' } }); } if ($self->{no_interfaceid_options} == 0) { $options{options}->add_options(arguments => { - 'name' => { name => 'use_name' }, + 'name' => { name => 'use_name' } }); } - + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); - + return $self; } sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - + $self->set_oids_label(); $self->check_oids_label(); @@ -912,9 +914,9 @@ sub check_oids_options_change { sub reload_cache_index_value { my ($self, %options) = @_; - + my $store_index = defined($options{store_index}) && $options{store_index} == 1 ? 1 : 0; - foreach ($self->{snmp}->oid_lex_sort(keys %{$options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }})) { + foreach (keys %{$options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }}) { /^$self->{oids_label}->{$options{name}}->{oid}\.(.*)$/; push @{$options{datas}->{all_ids}}, $1 if ($store_index == 1); $options{datas}->{$options{name} . "_" . $1} = $self->{output}->to_utf8($options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }->{$_}); @@ -923,9 +925,9 @@ sub reload_cache_index_value { sub reload_cache_values_index { my ($self, %options) = @_; - + my $store_index = defined($options{store_index}) && $options{store_index} == 1 ? 1 : 0; - foreach ($self->{snmp}->oid_lex_sort(keys %{$options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }})) { + foreach (keys %{$options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }}) { /^$self->{oids_label}->{$options{name}}->{oid}\.(.*)$/; push @{$options{datas}->{all_ids}}, $options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }->{$_} if ($store_index == 1); if (defined($options{datas}->{$options{name} . "_" . $options{result}->{ $self->{oids_label}->{$options{name}}->{oid} }->{$_}})) { @@ -985,7 +987,8 @@ sub add_selected_interface { $self->{int}->{$options{id}} = { display => $self->get_display_value(id => $options{id}), extra_display => '' }; if (defined($self->{option_results}->{oid_extra_display})) { - $self->{int}->{$options{id}}->{extra_display} = ' [ ' . $self->{statefile_cache}->get(name => $self->{option_results}->{oid_extra_display} . "_" . $options{id}) . ' ]'; + my $name = $self->{statefile_cache}->get(name => $self->{option_results}->{oid_extra_display} . '_' . $options{id}); + $self->{int}->{$options{id}}->{extra_display} = ' [ ' . (defined($name) ? $name : '') . ' ]'; } } @@ -1068,21 +1071,34 @@ sub load_errors { my ($self, %options) = @_; $self->set_oids_errors(); - $self->{snmp}->load(oids => [$self->{oid_ifInDiscards}, $self->{oid_ifInErrors}, - $self->{oid_ifOutDiscards}, $self->{oid_ifOutErrors}], instances => $self->{array_interface_selected}); + $self->{snmp}->load( + oids => [ + $self->{oid_ifInDiscards}, $self->{oid_ifInErrors}, + $self->{oid_ifOutDiscards}, $self->{oid_ifOutErrors} + ], + instances => $self->{array_interface_selected} + ); } sub load_cast { my ($self, %options) = @_; $self->set_oids_cast(); - $self->{snmp}->load(oids => [$self->{oid_ifInUcastPkts}, $self->{oid_ifInBroadcastPkts}, $self->{oid_ifInMulticastPkts}, - $self->{oid_ifOutUcastPkts}, $self->{oid_ifOutMulticastPkts}, $self->{oid_ifOutBroadcastPkts}], - instances => $self->{array_interface_selected}); + $self->{snmp}->load( + oids => [ + $self->{oid_ifInUcastPkts}, $self->{oid_ifInBroadcastPkts}, $self->{oid_ifInMulticastPkts}, + $self->{oid_ifOutUcastPkts}, $self->{oid_ifOutMulticastPkts}, $self->{oid_ifOutBroadcastPkts} + ], + instances => $self->{array_interface_selected} + ); if (!$self->{snmp}->is_snmpv1() && !defined($self->{option_results}->{force_counters32})) { - $self->{snmp}->load(oids => [$self->{oid_ifHCInUcastPkts}, $self->{oid_ifHCInMulticastPkts}, $self->{oid_ifHCInBroadcastPkts}, - $self->{oid_ifHCOutUcastPkts}, $self->{oid_ifHCOutMulticastPkts}, $self->{oid_ifHCOutBroadcastPkts}], - instances => $self->{array_interface_selected}); + $self->{snmp}->load( + oids => [ + $self->{oid_ifHCInUcastPkts}, $self->{oid_ifHCInMulticastPkts}, $self->{oid_ifHCInBroadcastPkts}, + $self->{oid_ifHCOutUcastPkts}, $self->{oid_ifHCOutMulticastPkts}, $self->{oid_ifHCOutBroadcastPkts} + ], + instances => $self->{array_interface_selected} + ); } } @@ -1151,8 +1167,10 @@ sub add_result_global { } } - $self->{global} = { total_port => 0, global_admin_up => 0, global_admin_down => 0, - global_oper_up => 0, global_oper_down => 0}; + $self->{global} = { + total_port => 0, global_admin_up => 0, global_admin_down => 0, + global_oper_up => 0, global_oper_down => 0 + }; foreach (@{$self->{array_interface_selected}}) { my $opstatus = $self->{oid_opstatus_mapping}->{$self->{results}->{$self->{oid_opstatus} . '.' . $_}}; my $admstatus = $self->{oid_adminstatus_mapping}->{$self->{results}->{$self->{oid_adminstatus} . '.' . $_}}; From 6be51512dfa0ea3d9919e7e778ba14e027144220 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Tue, 24 Mar 2020 14:22:30 +0100 Subject: [PATCH 007/190] enh(plugin)Palo-Alto vsys close #1849 --- .../paloalto/snmp/mode/vsyssessions.pm | 203 ++++++++++++++++++ .../network/paloalto/snmp/plugin.pm | 1 + 2 files changed, 204 insertions(+) create mode 100644 centreon-plugins/network/paloalto/snmp/mode/vsyssessions.pm diff --git a/centreon-plugins/network/paloalto/snmp/mode/vsyssessions.pm b/centreon-plugins/network/paloalto/snmp/mode/vsyssessions.pm new file mode 100644 index 000000000..0a9040321 --- /dev/null +++ b/centreon-plugins/network/paloalto/snmp/mode/vsyssessions.pm @@ -0,0 +1,203 @@ +# +# 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 network::paloalto::snmp::mode::vsyssessions; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'vsys', type => 1, cb_prefix_output => 'prefix_vsys_output', message_multiple => 'Vsys Sessions metrics are OK' }, + ]; + $self->{maps_counters}->{vsys} = [ + { label => 'active', set => { + key_values => [ { name => 'panVsysActiveSessions' }, { name => 'panVsysMaxSessions' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_active_calc'), + closure_custom_output => $self->can('custom_active_output'), + closure_custom_perfdata => $self->can('custom_active_perfdata'), + closure_custom_threshold_check => $self->can('custom_active_threshold'), + + } + }, + { label => 'active-tcp', nlabel => 'vsys.sessions.active.tcp.count', set => { + key_values => [ { name => 'panVsysActiveTcpCps' }, { name => 'display' } ], + output_template => 'Active TCP : %s', + perfdatas => [ + { label => 'active_tcp', value => 'panVsysActiveTcpCps_absolute', template => '%s', + label_extra_instance => 1, instance_use => 'display_absolute', min => 0 }, + ], + } + }, + { label => 'active-udp', nlabel => 'vsys.sessions.active.udp.count', set => { + key_values => [ { name => 'panVsysActiveUdpCps' }, { name => 'display' } ], + output_template => 'Active UDP : %s', + perfdatas => [ + { label => 'active_udp', value => 'panVsysActiveUdpCps_absolute', template => '%s', + label_extra_instance => 1, instance_use => 'display_absolute', min => 0 }, + ], + } + }, + { label => 'active-other', nlabel => 'vsys.sessions.active.other.count', set => { + key_values => [ { name => 'panVsysActiveOtherIpCps' }, { name => 'display' } ], + output_template => 'Other : %s', + perfdatas => [ + { label => 'active_other', value => 'panVsysActiveOtherIpCps_absolute', template => '%s', + label_extra_instance => 1, instance_use => 'display_absolute', min => 0 }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, force_new_perfdata => 1, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +sub prefix_vsys_output { + my ($self, %options) = @_; + + return "Vsys '" . $options{instance_value}->{display} . "' "; + +} + +sub custom_active_perfdata { + my ($self, %options) = @_; + + my $label = 'active'; + my %total_options = (); + if ($self->{result_values}->{panVsysMaxSessions} != 0) { + $total_options{total} = $self->{result_values}->{panVsysMaxSessions}; + $total_options{cast_int} = 1; + } + + $self->{output}->perfdata_add(label => $self->{result_values}->{display} . "#active.sessions.count", + value => $self->{result_values}->{panVsysActiveSessions}, + warning => defined($total_options{total}) ? + $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options) : undef, + critical => defined($total_options{total}) ? + $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options) : undef, + min => 0, + max => $self->{result_values}->{panVsysMaxSessions}); +} + +sub custom_active_threshold { + my ($self, %options) = @_; + + my ($exit, $threshold_value) = ('ok'); + if ($self->{result_values}->{panVsysMaxSessions} != 0) { + $threshold_value = $self->{result_values}->{active_prct}; + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => + [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]) if (defined($threshold_value)); + return $exit; +} + +sub custom_active_output { + my ($self, %options) = @_; + + my $msg = sprintf("Active : %s (%s)", + $self->{result_values}->{panVsysActiveSessions}, + $self->{result_values}->{panVsysMaxSessions} != 0 ? $self->{result_values}->{active_prct} . " %" : + '-'); + return $msg; +} + +sub custom_active_calc { + my ($self, %options) = @_; + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{panVsysActiveSessions} = $options{new_datas}->{$self->{instance} . '_panVsysActiveSessions'}; + $self->{result_values}->{panVsysMaxSessions} = $options{new_datas}->{$self->{instance} . '_panVsysMaxSessions'}; + $self->{result_values}->{active_prct} = 0; + if ($self->{result_values}->{panVsysMaxSessions} != 0) { + $self->{result_values}->{active_prct} = $self->{result_values}->{panVsysActiveSessions} * 100 / $self->{result_values}->{panVsysMaxSessions}; + } + return 0; +} + +my $mapping = { + panVsysName => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.2' }, + panVsysActiveSessions => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.4' }, + panVsysMaxSessions => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.5' }, + panVsysActiveTcpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.6' }, + panVsysActiveUdpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.7' }, + panVsysActiveOtherIpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.8' }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_panVsysEntry = '.1.3.6.1.4.1.25461.2.1.2.3.9.1'; + $self->{results} = $options{snmp}->get_table(oid => $oid_panVsysEntry, + nothing_quit => 1); + + foreach my $oid (keys %{$self->{results}}) { + next if $oid !~ /^$mapping->{panVsysName}->{oid}\.(.*)$/; + my $instance = $1; + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); + + $self->{vsys}->{$result->{panVsysName}} = { + display => $result->{panVsysName}, + panVsysMaxSessions => defined($result->{panVsysMaxSessions}) ? $result->{panVsysMaxSessions} : 0, + panVsysActiveSessions => $result->{panVsysActiveSessions}, + panVsysActiveTcpCps => $result->{panVsysActiveTcpCps}, + panVsysActiveUdpCps => $result->{panVsysActiveUdpCps}, + panVsysActiveOtherIpCps => $result->{panVsysActiveOtherIpCps} + }; + + } +} + +1; + +__END__ + +=head1 MODE + +Check sessions per Vsys + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'active' (%), 'active-tcp', 'active-udp', 'active-other' + +=item B<--critical-*> + +Threshold critical. +Can be: 'active' (%), 'active-tcp', 'active-udp', 'active-other' + +=back + +=cut diff --git a/centreon-plugins/network/paloalto/snmp/plugin.pm b/centreon-plugins/network/paloalto/snmp/plugin.pm index 41509f404..4b4e476a0 100644 --- a/centreon-plugins/network/paloalto/snmp/plugin.pm +++ b/centreon-plugins/network/paloalto/snmp/plugin.pm @@ -40,6 +40,7 @@ sub new { 'memory' => 'network::paloalto::snmp::mode::memory', 'panorama' => 'network::paloalto::snmp::mode::panorama', 'sessions' => 'network::paloalto::snmp::mode::sessions', + 'vsys-sessions' => 'network::paloalto::snmp::mode::vsyssessions', ); return $self; From 5a6c258dfe8a7152a55e80167484c7d84a8cb065 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 25 Mar 2020 09:17:57 +0100 Subject: [PATCH 008/190] add cache for fortigate policy --- .../fortinet/fortigate/snmp/mode/vdomusage.pm | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/snmp/mode/vdomusage.pm b/centreon-plugins/centreon/common/fortinet/fortigate/snmp/mode/vdomusage.pm index e4d596b99..c2842db05 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/snmp/mode/vdomusage.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/snmp/mode/vdomusage.pm @@ -115,7 +115,7 @@ sub set_counters { closure_custom_output => $self->can('custom_license_output'), perfdatas => [ { value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute' } - ], + ] } }, { label => 'license-free', nlabel => 'virtualdomains.license.free.count', display_ok => 0, set => { @@ -123,7 +123,7 @@ sub set_counters { closure_custom_output => $self->can('custom_license_output'), perfdatas => [ { value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute' } - ], + ] } }, { label => 'license-usage-prct', nlabel => 'virtualdomains.license.usage.percentage', display_ok => 0, set => { @@ -131,7 +131,7 @@ sub set_counters { closure_custom_output => $self->can('custom_license_output'), perfdatas => [ { value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%' } - ], + ] } } ]; @@ -143,7 +143,7 @@ sub set_counters { perfdatas => [ { value => 'cpu_absolute', template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' } - ], + ] } } ]; @@ -167,7 +167,7 @@ sub set_counters { perfdatas => [ { value => 'active_policies_absolute', template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + ] } } ]; @@ -179,7 +179,7 @@ sub set_counters { perfdatas => [ { value => 'active_sessions_absolute', template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + ] } }, { label => 'session-rate', nlabel => 'virtualdomain.sessions.rate.persecond', set => { @@ -188,7 +188,7 @@ sub set_counters { perfdatas => [ { value => 'session_rate_absolute', template => '%d', min => 0, unit => '/s', label_extra_instance => 1, instance_use => 'display_absolute' } - ], + ] } } ]; @@ -215,7 +215,7 @@ sub set_counters { perfdatas => [ { value => 'traffic_per_second', template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }, - ], + ] } }, { label => 'traffic-out', nlabel => 'virtualdomain.traffic.out.bitspersecond', set => { @@ -228,7 +228,7 @@ sub set_counters { perfdatas => [ { value => 'traffic_per_second', template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }, - ], + ] } } ]; @@ -240,13 +240,15 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'filter-vdomain:s' => { name => 'filter_vdomain' }, - 'add-traffic' => { name => 'add_traffic' }, - 'add-policy' => { name => 'add_policy' }, - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '' } + 'filter-vdomain:s' => { name => 'filter_vdomain' }, + 'add-traffic' => { name => 'add_traffic' }, + 'add-policy' => { name => 'add_policy' }, + 'policy-cache-time:s' => { name => 'policy_cache_time', default => 60 }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' } }); + $self->{cache_policy} = centreon::plugins::statefile->new(%options); return $self; } @@ -255,6 +257,7 @@ sub check_options { $self->SUPER::check_options(%options); $self->change_macros(macros => ['warning_status', 'critical_status']); + $self->{cache_policy}->check_options(%options) if (defined($self->{option_results}->{add_policy})); } my $map_opmode = { 1 => 'nat', 2 => 'transparent' }; @@ -262,7 +265,7 @@ my $map_ha = { 1 => 'master', 2 => 'backup', 3 => 'standalone' }; my $mapping = { fgVdNumber => { oid => '.1.3.6.1.4.1.12356.101.3.1.1' }, - fgVdMaxVdoms => { oid => '.1.3.6.1.4.1.12356.101.3.1.2' }, + fgVdMaxVdoms => { oid => '.1.3.6.1.4.1.12356.101.3.1.2' } }; my $mapping_vdom = { fgVdEntOpMode => { oid => '.1.3.6.1.4.1.12356.101.3.2.1.1.3', map => $map_opmode }, @@ -320,7 +323,15 @@ sub add_policy { my $oid_fgFwPolID = '.1.3.6.1.4.1.12356.101.5.1.2.1.1.1'; - my $snmp_result = $options{snmp}->get_table(oid => $oid_fgFwPolID); + my $has_cache_file = $self->{cache_policy}->read(statefile => 'fortinet_fortigate_policy_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port()); + my $timestamp_cache = $self->{cache_policy}->get(name => 'last_timestamp'); + my $snmp_result = $self->{cache_policy}->get(name => 'snmp_result'); + if ($has_cache_file == 0 || !defined($timestamp_cache) || !defined($snmp_result) || + ((time() - $timestamp_cache) > (($self->{option_results}->{policy_cache_time}) * 60))) { + $snmp_result = $options{snmp}->get_table(oid => $oid_fgFwPolID); + $self->{cache_policy}->write(data => { last_timestamp => time(), snmp_result => $snmp_result }); + } + foreach (keys %$snmp_result) { /^$oid_fgFwPolID\.(\d+)/; $self->{vdom}->{$1}->{vdom_policy}->{active_policies}++ @@ -421,6 +432,10 @@ Add traffic usage by virtual domain. Add number of policies by virtual domain. +=item B<--policy-cache-time> + +Time in minutes before reloading cache file (default: 60). + =item B<--warning-status> Set warning threshold for status (Default: ''). From 8bd0e983f053140683cb3bfbfb700928e0aa9487 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 25 Mar 2020 16:04:23 +0100 Subject: [PATCH 009/190] wip: eltek enexus snmp --- .../devices/eltek/enexus/snmp/mode/alarms.pm | 175 ++++++++++ .../devices/eltek/enexus/snmp/mode/battery.pm | 317 ++++++++++++++++++ .../devices/eltek/enexus/snmp/mode/outputs.pm | 198 +++++++++++ .../devices/eltek/enexus/snmp/plugin.pm | 50 +++ 4 files changed, 740 insertions(+) create mode 100644 centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/alarms.pm create mode 100644 centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/battery.pm create mode 100644 centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/outputs.pm create mode 100644 centreon-plugins/hardware/devices/eltek/enexus/snmp/plugin.pm diff --git a/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/alarms.pm b/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/alarms.pm new file mode 100644 index 000000000..dcb1c84a2 --- /dev/null +++ b/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/alarms.pm @@ -0,0 +1,175 @@ +# +# 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 hardware::devices::eltek::enexus::snmp::mode::alarms; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use centreon::plugins::misc; + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf('status: %s', + $self->{result_values}->{status} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'alarm', type => 1, cb_prefix_output => 'prefix_alarm_output', message_multiple => 'All alarms are ok', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'alarms-active', nlabel => 'alarms.active.count', display_ok => 0, set => { + key_values => [ { name => 'active' }, { name => 'total' } ], + output_template => 'current active alarms: %d', + perfdatas => [ + { value => 'active_absolute', template => '%d', min => 0, max => 'total_absolute' } + ] + } + } + ]; + + $self->{maps_counters}->{alarm} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'name' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + } + ]; +} + +sub prefix_alarm_output { + my ($self, %options) = @_; + + return "Alarm '" . $options{instance_value}->{name} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, 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} eq "alarm"' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); +} + +my $map_status = { 0 => 'normal', 1 => 'alarm' }; + +my $mapping = { + alarmGroupStatus => { oid => '.1.3.6.1.4.1.12148.10.14.1.1.2', map => $map_status }, + alarmGroupDescription => { oid => '.1.3.6.1.4.1.12148.10.14.1.1.3' } +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_alarmGroupEntry = '.1.3.6.1.4.1.12148.10.14.1.1'; + my $snmp_result = $options{snmp}->get_table( + oid => $oid_alarmGroupEntry, + start => $mapping->{alarmGroupStatus}->{oid}, + nothing_quit => 1 + ); + + $self->{global} = { total => 0, active => 0 }; + $self->{alarm} = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{alarmGroupStatus}->{oid}\.(.*)$/); + my $instance = $1; + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + $result->{alarmGroupDescription} = centreon::plugins::misc::trim($result->{alarmGroupDescription}); + $result->{alarmGroupDescription} = $instance if ($result->{alarmGroupDescription} eq ''); + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{alarmGroupDescription} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping alarm '" . $result->{alarmGroupDescription} . "'.", debug => 1); + next; + } + + $self->{alarm}->{$instance} = { + name => $result->{alarmGroupDescription}, + status => $result->{alarmGroupStatus} + }; + $self->{global}->{total}++; + $self->{global}->{active}++ if ($result->{alarmGroupStatus} eq 'alarm'); + } +} + +1; + +__END__ + +=head1 MODE + +Check alarms. + +=over 8 + +=item B<--filter-name> + +Filter name (can be a regexp). + +=item B<--unknown-status> + +Set unknown threshold for status (Default: ''). +Can used special variables like: %{state}, %{status}, %{lastOpError}, %{display} + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{name}, %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} eq "alarm"). +Can used special variables like: %{name}, %{status} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'alarms-active'. + +=back + +=cut diff --git a/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/battery.pm b/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/battery.pm new file mode 100644 index 000000000..29857b605 --- /dev/null +++ b/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/battery.pm @@ -0,0 +1,317 @@ +# +# 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 hardware::devices::eltek::enexus::snmp::mode::battery; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use centreon::plugins::misc; + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf('status: %s', + $self->{result_values}->{status} + ); +} + +sub custom_temperature_output { + my ($self, %options) = @_; + + return sprintf('temperature: %s %s', + $self->{result_values}->{temperature_absolute}, + $self->{result_values}->{temperature_unit_absolute} + ); +} + +sub custom_temperature_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + nlabel => 'battery.temperature.' . ($self->{result_values}->{temperature_unit_absolute} eq 'C' ? 'celsius' : 'fahrenheit'), + unit => $self->{result_values}->{temperature_unit_absolute}, + value => $self->{result_values}->{temperature_absolute}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + ); +} + +sub custom_charge_remaining_output { + my ($self, %options) = @_; + + return sprintf('remaining capacity: %s %s', + $self->{result_values}->{charge_remaining_absolute}, + $self->{result_values}->{charge_remaining_unit_absolute} + ); +} + +sub custom_charge_remaining_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + nlabel => 'battery.charge.remaining.' . ($self->{result_values}->{charge_remaining_unit_absolute} eq '%' ? '%' : 'amperehour'), + unit => $self->{result_values}->{charge_remaining_unit_absolute}, + value => $self->{result_values}->{charge_remaining_absolute}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + min => 0, + max => $self->{result_values}->{charge_remaining_unit_absolute} eq '%' ? 100 : undef + ); +} + +sub custom_charge_time_output { + my ($self, %options) = @_; + + return sprintf( + 'remaining time: %s', + centreon::plugins::misc::change_seconds(value => $self->{result_values}->{charge_remaining_time_absolute}) + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'battery', type => 0, cb_prefix_output => 'prefix_battery_output', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{battery} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + }, + { label => 'temperature', display_ok => 0, set => { + key_values => [ { name => 'temperature' }, { name => 'temperature_unit' } ], + closure_custom_output => $self->can('custom_temperature_output'), + closure_custom_perfdata => $self->can('custom_temperature_perfdata') + } + }, + { label => 'charge-remaining', set => { + key_values => [ { name => 'charge_remaining' }, { name => 'charge_remaining_unit' } ], + closure_custom_output => $self->can('custom_charge_remaining_output'), + closure_custom_perfdata => $self->can('custom_charge_remaining_perfdata') + } + }, + { label => 'charge-remaining-time', nlabel => 'battery.charge.remaining.time.seconds', set => { + key_values => [ { name => 'charge_remaining_time' } ], + closure_custom_output => $self->can('custom_charge_time_output'), + perfdatas => [ + { value => 'charge_remaining_time_absolute', template => '%s', min => 0, unit => 's' }, + ], + } + }, + { label => 'voltage', nlabel => 'battery.voltage.volt', display_ok => 0, set => { + key_values => [ { name => 'voltage' } ], + output_template => 'voltage: %.2f V', + perfdatas => [ + { value => 'voltage_absolute', template => '%.2f', unit => 'V' } + ] + } + }, + { label => 'current', nlabel => 'battery.current.ampere', display_ok => 0, set => { + key_values => [ { name => 'current' } ], + output_template => 'current: %.2f A', + perfdatas => [ + { value => 'current_absolute', template => '%.2f', min => 0, unit => 'A' } + ] + } + }, + ]; +} + +sub prefix_battery_output { + my ($self, %options) = @_; + + return "Battery "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /minor|warning/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /error|major|critical/i' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => [ + 'warning_status', 'critical_status', 'unknown_status', + ]); +} + +my $map_status = { + 0 => 'error', 1 => 'normal', 2 => 'minorAlarm', 3 => 'majorAlarm', + 4 => 'disabled', 5 => 'disconnected', 6 => 'notPresent', + 7 => 'minorAndMajor', 8 => 'majorLow', 9 => 'minorLow', + 10 => 'majorHigh', 11 => 'minorHigh', 12 => 'event', + 13 => 'valueVolt', 14 => 'valueAmp', 15 => 'valueTemp', + 16 => 'valueUnit', 17 => 'valuePerCent', 18 => 'critical', + 19 => 'warning' +}; +my $map_decimal_setting = { 0 => 'ampere', 1 => 'deciAmpere' }; +my $map_temp_setting = { 0 => 'celsius', 1 => 'fahrenheit' }; +my $map_capacity = { 0 => 'ah', 1 => 'percent' }; + +my $mapping = { + powerSystemCurrentDecimalSetting => { oid => '.1.3.6.1.4.1.12148.10.2.15', map => $map_decimal_setting }, + powerSystemTemperatureScale => { oid => '.1.3.6.1.4.1.12148.10.2.16', map => $map_temp_setting }, + powerSystemCapacityScale => { oid => '.1.3.6.1.4.1.12148.10.2.17', map => $map_capacity }, + batteryStatus => { oid => '.1.3.6.1.4.1.12148.10.10.1', map => $map_status }, + batteryVoltageValue => { oid => '.1.3.6.1.4.1.12148.10.10.5.5' }, + batteryVoltageMajorHighLevel => { oid => '.1.3.6.1.4.1.12148.10.10.5.6' }, + batteryVoltageMinorHighLevel => { oid => '.1.3.6.1.4.1.12148.10.10.5.7' }, # 0.01 for vdc + batteryVoltageMinorLowLevel => { oid => '.1.3.6.1.4.1.12148.10.10.5.8' }, + batteryVoltageMajorLowLevel => { oid => '.1.3.6.1.4.1.12148.10.10.5.9' }, + batteryCurrentsValue => { oid => '.1.3.6.1.4.1.12148.10.10.6.5' }, # A or dA + batteryCurrentsMajorHighLevel => { oid => '.1.3.6.1.4.1.12148.10.10.6.6' }, + batteryCurrentsMinorHighLevel => { oid => '.1.3.6.1.4.1.12148.10.10.6.7' }, + batteryCurrentsMinorLowLevel => { oid => '.1.3.6.1.4.1.12148.10.10.6.8' }, + batteryCurrentsMajorLowLevel => { oid => '.1.3.6.1.4.1.12148.10.10.6.9' }, + batteryTemperaturesValue => { oid => '.1.3.6.1.4.1.12148.10.10.7.5' }, # C or F + batteryTemperaturesMajorHighLevel => { oid => '.1.3.6.1.4.1.12148.10.10.7.6' }, + batteryTemperaturesMinorHighLevel => { oid => '.1.3.6.1.4.1.12148.10.10.7.7' }, + batteryTemperaturesMinorLowLevel => { oid => '.1.3.6.1.4.1.12148.10.10.7.8' }, + batteryTemperaturesMajorLowLevel => { oid => '.1.3.6.1.4.1.12148.10.10.7.9' }, + batteryRemainingCapacityValue => { oid => '.1.3.6.1.4.1.12148.10.10.9.5' }, # ah or % + batteryRemainingCapacityMinorLowLevel => { oid => '.1.3.6.1.4.1.12148.10.10.9.6' }, + batteryRemainingCapacityMajorLowLevel => { oid => '.1.3.6.1.4.1.12148.10.10.9.7' }, +}; + +sub threshold_eltek_configured { + my ($self, %options) = @_; + + if ((!defined($self->{option_results}->{'critical-' . $options{label}}) || $self->{option_results}->{'critical-' . $options{label}} eq '') && + (!defined($self->{option_results}->{'warning-' . $options{label}}) || $self->{option_results}->{'warning-' . $options{label}} eq '')) { + my ($crit, $warn) = ('', ''); + $crit = $options{low_crit} . ':' if (defined($options{low_crit}) && $options{low_crit} ne ''); + $crit .= $options{high_crit} if (defined($options{high_crit}) && $options{high_crit} ne ''); + $warn = $options{low_warn} . ':' if (defined($options{low_warn}) && $options{low_warn} ne ''); + $warn .= $options{high_warn} if (defined($options{high_warn}) && $options{high_warn} ne ''); + $self->{perfdata}->threshold_validate(label => 'critical-' . $options{label}, value => $crit); + $self->{perfdata}->threshold_validate(label => 'warning-' . $options{label}, value => $warn); + } +} + +sub manage_selection { + my ($self, %options) = @_; + + # we can calculate the time remaining if unit is ah (amperehour). + + my $oid_outputControlUnitOutputEntry = '.1.3.6.1.4.1.12148.10.12.2.1'; + my $snmp_result = $options{snmp}->get_leef( + oids => [ map($_->{oid} . '.0', values(%$mapping)) ], + nothing_quit => 1 + ); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); + + my $scale_current = 1; + $scale_current = 0.1 if ($result->{powerSystemCurrentDecimalSetting} eq 'deciAmpere'); + $self->{battery} = { + status => $result->{batteryStatus}, + temperature => $result->{batteryTemperaturesValue}, + temperature_unit => $result->{powerSystemTemperatureScale} eq 'celsius' ? 'C' : 'F', + voltage => $result->{batteryVoltageValue} * 0.01, + current => $result->{batteryCurrentsValue} * $scale_current, + charge_remaining => $result->{batteryRemainingCapacityValue}, + charge_remaining_unit => $result->{powerSystemCapacityScale} + }; + if ($result->{powerSystemCapacityScale} eq 'ah' && $result->{batteryCurrentsValue} < 0) { + $self->{battery}->{charge_remaining_time} = + int($result->{batteryRemainingCapacityValue} * 3600 / $result->{batteryCurrentsValue} * $scale_current * -1); + } + + $self->threshold_eltek_configured( + label => 'temperature', + high_crit => $result->{batteryTemperaturesMajorHighLevel}, + low_crit => $result->{batteryTemperaturesMajorLowLevel}, + high_warn => $result->{batteryTemperaturesMinorHighLevel}, + low_warn => $result->{batteryTemperaturesMinorLowLevel} + ); + $self->threshold_eltek_configured( + label => 'battery-voltage-volt', + high_crit => $result->{batteryVoltageMajorHighLevel} * 0.01, + low_crit => $result->{batteryVoltageMajorLowLevel} * 0.01, + high_warn => $result->{batteryVoltageMinorHighLevel} * 0.01, + low_warn => $result->{batteryVoltageMinorLowLevel} * 0.01 + ); + $self->threshold_eltek_configured( + label => 'battery-current-ampere', + high_crit => $result->{batteryCurrentsMajorHighLevel} * $scale_current, + low_crit => $result->{batteryCurrentsMajorLowLevel} * $scale_current, + high_warn => $result->{batteryCurrentsMinorHighLevel} * $scale_current, + low_warn => $result->{batteryCurrentsMinorLowLevel} * $scale_current + ); + $self->threshold_eltek_configured( + label => 'charge-remaining', + low_crit => $result->{batteryRemainingCapacityMajorLowLevel}, + low_warn => $result->{batteryRemainingCapacityMinorLowLevel} + ); +} + +1; + +__END__ + +=head1 MODE + +Check battery. + +=over 8 + +=item B<--unknown-status> + +Set unknown threshold for status. +Can used special variables like: %{status} + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{status} =~ /minor|warning/i'). +Can used special variables like: %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /error|major|critical/i'). +Can used special variables like: %{status} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'temperature', 'voltage', 'current', +'charge-remaining', 'charge-remaining-time'. + +=back + +=cut diff --git a/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/outputs.pm b/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/outputs.pm new file mode 100644 index 000000000..2630eb63b --- /dev/null +++ b/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/outputs.pm @@ -0,0 +1,198 @@ +# +# 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 hardware::devices::eltek::enexus::snmp::mode::outputs; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use centreon::plugins::misc; + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf('status: %s', + $self->{result_values}->{status} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'cuo', type => 1, cb_prefix_output => 'prefix_cuo_output', message_multiple => 'All outputs for control units are ok', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'outputs-disconnected', nlabel => 'outputs.disconnected.count', display_ok => 0, set => { + key_values => [ { name => 'disconnected' }, { name => 'total_contactors' } ], + output_template => 'current disconnected outputs: %d', + perfdatas => [ + { value => 'disconnected_absolute', template => '%d', min => 0, max => 'total_contactors_absolute' } + ] + } + }, + { label => 'outputs-notenergized', nlabel => 'outputs.notenergized.count', display_ok => 0, set => { + key_values => [ { name => 'notenergized' }, { name => 'total_relay' } ], + output_template => 'current not energized outputs: %d', + perfdatas => [ + { value => 'notenergized_absolute', template => '%d', min => 0, max => 'total_relay_absolute' } + ] + } + } + ]; + + $self->{maps_counters}->{cuo} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'name' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + } + ]; +} + +sub prefix_cuo_output { + my ($self, %options) = @_; + + return "Control unit output '" . $options{instance_value}->{name} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, 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} =~ /notenergized|disconnected/i' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => [ + 'warning_status', 'critical_status', 'unknown_status', + ]); +} + +my $map_status = { 0 => 'notenergized', 1 => 'energized', 2 => 'disconnected', 3 => 'connected' }; + +my $mapping = { + outputControlUnitOutputStatus => { oid => '.1.3.6.1.4.1.12148.10.12.2.1.2', map => $map_status }, + outputControlUnitOutputDescription => { oid => '.1.3.6.1.4.1.12148.10.12.2.1.3' } +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_outputControlUnitOutputEntry = '.1.3.6.1.4.1.12148.10.12.2.1'; + my $snmp_result = $options{snmp}->get_table( + oid => $oid_outputControlUnitOutputEntry, + start => $mapping->{outputControlUnitOutputStatus}->{oid}, + nothing_quit => 1 + ); + + $self->{global} = { total_relay => 0, total_contactors => 0, energized => 0, notenergized => 0, connected => 0, disconnected => 0 }; + $self->{cuo} = {}; + my $duplicated = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{outputControlUnitOutputStatus}->{oid}\.(.*)$/); + my $instance = $1; + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + my $name = centreon::plugins::misc::trim($result->{outputControlUnitOutputDescription}); + $name = $instance if ($name eq ''); + $name = $instance if (defined($duplicated->{$name})); + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping control unit output '" . $name . "'.", debug => 1); + next; + } + + if (defined($self->{cuo}->{$name})) { + $duplicated->{$name} = 1; + my $instance2 = $self->{cuo}->{$name}->{instance}; + $self->{cuo}->{$instance2} = $self->{cuo}->{$name}; + $self->{cuo}->{$instance2}->{name} = $instance2; + delete $self->{cuo}->{$name}; + $name = $instance; + } + + $self->{cuo}->{$name} = { + instance => $instance, + name => $name, + status => $result->{outputControlUnitOutputStatus} + }; + $self->{global}->{total_relay}++ if ($result->{outputControlUnitOutputStatus} =~ /energized/); + $self->{global}->{total_contactors}++ if ($result->{outputControlUnitOutputStatus} =~ /connected/); + $self->{global}->{$result->{outputControlUnitOutputStatus}}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check outputs for control units. + +=over 8 + +=item B<--filter-name> + +Filter name (can be a regexp). + +=item B<--unknown-status> + +Set unknown threshold for status. +Can used special variables like: %{status}, %{name} + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{status}, %{name} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /notenergized|disconnected/i'). +Can used special variables like: %{status}, %{name} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'current'. + +=back + +=cut diff --git a/centreon-plugins/hardware/devices/eltek/enexus/snmp/plugin.pm b/centreon-plugins/hardware/devices/eltek/enexus/snmp/plugin.pm new file mode 100644 index 000000000..297ae1605 --- /dev/null +++ b/centreon-plugins/hardware/devices/eltek/enexus/snmp/plugin.pm @@ -0,0 +1,50 @@ +# +# 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 hardware::devices::eltek::enexus::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'alarms' => 'hardware::devices::eltek::enexus::snmp::mode::alarms', + 'battery' => 'hardware::devices::eltek::enexus::snmp::mode::battery', + 'outputs' => 'hardware::devices::eltek::enexus::snmp::mode::outputs' + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Eltek eNexus in SNMP (SmartPack2 V2.x, SmartPack S V2.x and Compack V2.x). + +=cut From 5728e53924df9bef3ebcbafd82a7bb5b06ef58fc Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 26 Mar 2020 10:18:59 +0100 Subject: [PATCH 010/190] mode load for eltek enexus --- .../devices/eltek/enexus/snmp/mode/battery.pm | 8 +- .../devices/eltek/enexus/snmp/mode/load.pm | 222 ++++++++++++++++++ .../devices/eltek/enexus/snmp/plugin.pm | 1 + 3 files changed, 226 insertions(+), 5 deletions(-) create mode 100644 centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/load.pm diff --git a/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/battery.pm b/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/battery.pm index 29857b605..652603bde 100644 --- a/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/battery.pm +++ b/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/battery.pm @@ -139,14 +139,14 @@ sub set_counters { { value => 'current_absolute', template => '%.2f', min => 0, unit => 'A' } ] } - }, + } ]; } sub prefix_battery_output { my ($self, %options) = @_; - return "Battery "; + return 'Battery '; } sub new { @@ -228,9 +228,6 @@ sub threshold_eltek_configured { sub manage_selection { my ($self, %options) = @_; - # we can calculate the time remaining if unit is ah (amperehour). - - my $oid_outputControlUnitOutputEntry = '.1.3.6.1.4.1.12148.10.12.2.1'; my $snmp_result = $options{snmp}->get_leef( oids => [ map($_->{oid} . '.0', values(%$mapping)) ], nothing_quit => 1 @@ -248,6 +245,7 @@ sub manage_selection { charge_remaining => $result->{batteryRemainingCapacityValue}, charge_remaining_unit => $result->{powerSystemCapacityScale} }; + # we can calculate the time remaining if unit is ah (amperehour) and current battery is discharging (negative value) if ($result->{powerSystemCapacityScale} eq 'ah' && $result->{batteryCurrentsValue} < 0) { $self->{battery}->{charge_remaining_time} = int($result->{batteryRemainingCapacityValue} * 3600 / $result->{batteryCurrentsValue} * $scale_current * -1); diff --git a/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/load.pm b/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/load.pm new file mode 100644 index 000000000..5c80df04e --- /dev/null +++ b/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/load.pm @@ -0,0 +1,222 @@ +# +# 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 hardware::devices::eltek::enexus::snmp::mode::load; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use Digest::MD5 qw(md5_hex); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf('status: %s', + $self->{result_values}->{status} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'load', type => 0, cb_prefix_output => 'prefix_load_output', skipped_code => { -10 => 1 } }, + { name => 'phase', type => 1, cb_prefix_output => 'prefix_phase_output', message_multiple => 'All phases are ok', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{load} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + }, + { label => 'current', nlabel => 'load.current.ampere', set => { + key_values => [ { name => 'current' } ], + output_template => 'current: %s A', + perfdatas => [ + { value => 'current_absolute', template => '%s', unit => 'A', min => 0 } + ] + } + }, + { label => 'energy-delivered', nlabel => 'load.energy.delivered.watt', display_ok => 0, set => { + key_values => [ { name => 'energy', diff => 1 } ], + output_template => 'accumulated energy delivered: %s W', + perfdatas => [ + { value => 'energy_absolute', template => '%s', unit => 'W', min => 0 } + ] + } + } + ]; + + $self->{maps_counters}->{phase} = [ + { label => 'voltage', nlabel => 'phase.voltage.volt', set => { + key_values => [ { name => 'voltage' } ], + output_template => 'voltage: %.2f V', + perfdatas => [ + { value => 'voltage_absolute', template => '%.2f', unit => 'V', label_extra_instance => 1 } + ] + } + } + ]; +} + +sub prefix_load_output { + my ($self, %options) = @_; + + return 'Load '; +} + +sub prefix_phase_output { + my ($self, %options) = @_; + + return "Phase '" . $options{instance_value}->{display} . "' "; +} + +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 => { + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /minor|warning/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /error|major|critical/i' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => [ + 'warning_status', 'critical_status', 'unknown_status', + ]); +} + +my $map_status = { + 0 => 'error', 1 => 'normal', 2 => 'minorAlarm', 3 => 'majorAlarm', + 4 => 'disabled', 5 => 'disconnected', 6 => 'notPresent', + 7 => 'minorAndMajor', 8 => 'majorLow', 9 => 'minorLow', + 10 => 'majorHigh', 11 => 'minorHigh', 12 => 'event', + 13 => 'valueVolt', 14 => 'valueAmp', 15 => 'valueTemp', + 16 => 'valueUnit', 17 => 'valuePerCent', 18 => 'critical', + 19 => 'warning' +}; +my $map_decimal_setting = { 0 => 'ampere', 1 => 'deciAmpere' }; + +my $mapping = { + powerSystemCurrentDecimalSetting => { oid => '.1.3.6.1.4.1.12148.10.2.15', map => $map_decimal_setting }, + loadStatus => { oid => '.1.3.6.1.4.1.12148.10.9.1', map => $map_status }, + loadCurrentValue => { oid => '.1.3.6.1.4.1.12148.10.9.2.5' }, # A or dA + loadCurrentMajorHighLevel => { oid => '.1.3.6.1.4.1.12148.10.9.2.6' }, + loadCurrentMinorHighLevel => { oid => '.1.3.6.1.4.1.12148.10.9.2.7' }, + loadEnergyLogAccumulated => { oid => '.1.3.6.1.4.1.12148.10.9.8.1' }, # Watt +}; + +sub threshold_eltek_configured { + my ($self, %options) = @_; + + if ((!defined($self->{option_results}->{'critical-' . $options{label}}) || $self->{option_results}->{'critical-' . $options{label}} eq '') && + (!defined($self->{option_results}->{'warning-' . $options{label}}) || $self->{option_results}->{'warning-' . $options{label}} eq '')) { + my ($crit, $warn) = ('', ''); + $crit = $options{low_crit} . ':' if (defined($options{low_crit}) && $options{low_crit} ne ''); + $crit .= $options{high_crit} if (defined($options{high_crit}) && $options{high_crit} ne ''); + $warn = $options{low_warn} . ':' if (defined($options{low_warn}) && $options{low_warn} ne ''); + $warn .= $options{high_warn} if (defined($options{high_warn}) && $options{high_warn} ne ''); + $self->{perfdata}->threshold_validate(label => 'critical-' . $options{label}, value => $crit); + $self->{perfdata}->threshold_validate(label => 'warning-' . $options{label}, value => $warn); + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_leef( + oids => [ map($_->{oid} . '.0', values(%$mapping)) ], + nothing_quit => 1 + ); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); + + my $scale_current = 1; + $scale_current = 0.1 if ($result->{powerSystemCurrentDecimalSetting} eq 'deciAmpere'); + $self->{load} = { + status => $result->{loadStatus}, + energy => $result->{loadEnergyLogAccumulated}, + current => $result->{loadCurrentValue} * $scale_current + }; + + $self->threshold_eltek_configured( + label => 'load-current-ampere', + high_crit => $result->{loadCurrentMajorHighLevel} * $scale_current, + high_warn => $result->{loadCurrentMinorHighLevel} * $scale_current + ); + + my $oid_loadVoltageValue = '.1.3.6.1.4.1.12148.10.9.9.1.6'; + $snmp_result = $options{snmp}->get_table(oid => $oid_loadVoltageValue); + $self->{phase} = {}; + foreach (keys %$snmp_result) { + /\.(\d+)$/; + $self->{phase}->{$1} = { display => $1, voltage => $snmp_result->{$_} * 0.01 }; + } + + $self->{cache_name} = 'eltek_enexus_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check load. + +=over 8 + +=item B<--unknown-status> + +Set unknown threshold for status. +Can used special variables like: %{status} + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{status} =~ /minor|warning/i'). +Can used special variables like: %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /error|major|critical/i'). +Can used special variables like: %{status} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'current', 'energy-delivered'. + +=back + +=cut diff --git a/centreon-plugins/hardware/devices/eltek/enexus/snmp/plugin.pm b/centreon-plugins/hardware/devices/eltek/enexus/snmp/plugin.pm index 297ae1605..b6fd4245c 100644 --- a/centreon-plugins/hardware/devices/eltek/enexus/snmp/plugin.pm +++ b/centreon-plugins/hardware/devices/eltek/enexus/snmp/plugin.pm @@ -33,6 +33,7 @@ sub new { %{$self->{modes}} = ( 'alarms' => 'hardware::devices::eltek::enexus::snmp::mode::alarms', 'battery' => 'hardware::devices::eltek::enexus::snmp::mode::battery', + 'load' => 'hardware::devices::eltek::enexus::snmp::mode::load', 'outputs' => 'hardware::devices::eltek::enexus::snmp::mode::outputs' ); From e71d614bd85321bd7c0b58fe750ba896a244d8ca Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 26 Mar 2020 14:06:32 +0100 Subject: [PATCH 011/190] add vsx mode for checkpoint --- .../network/checkpoint/snmp/mode/hastate.pm | 52 ++-- .../network/checkpoint/snmp/mode/memory.pm | 18 +- .../network/checkpoint/snmp/mode/vpnstatus.pm | 4 +- .../network/checkpoint/snmp/mode/vsx.pm | 242 ++++++++++++++++++ .../network/checkpoint/snmp/plugin.pm | 21 +- 5 files changed, 291 insertions(+), 46 deletions(-) create mode 100644 centreon-plugins/network/checkpoint/snmp/mode/vsx.pm diff --git a/centreon-plugins/network/checkpoint/snmp/mode/hastate.pm b/centreon-plugins/network/checkpoint/snmp/mode/hastate.pm index 1600f1307..8e2401ed4 100644 --- a/centreon-plugins/network/checkpoint/snmp/mode/hastate.pm +++ b/centreon-plugins/network/checkpoint/snmp/mode/hastate.pm @@ -24,22 +24,16 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); sub custom_status_output { my ($self, %options) = @_; + my $msg = "HA State: '" . $self->{result_values}->{hastate} . "' "; $msg .= "Role: '" . $self->{result_values}->{role} . "' "; return $msg; } -sub custom_status_calc { - my ($self, %options) = @_; - $self->{result_values}->{hastate} = $options{new_datas}->{$self->{instance} . '_hastate'}; - $self->{result_values}->{role} = $options{new_datas}->{$self->{instance} . '_role'}; - return 0; -} - sub set_counters { my ($self, %options) = @_; @@ -49,12 +43,12 @@ sub set_counters { $self->{maps_counters}->{high_availability} = [ { label => 'status', threshold => 0, set => { key_values => [ { name => 'hastate' }, { name => 'role' } ], - closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold } - }, + } ]; } @@ -63,12 +57,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{hastate} !~ /(UP|working)/' }, - "no-ha-status:s" => { name => 'no_ha_status', default => 'UNKNOWN' }, - }); + $options{options}->add_options(arguments => { + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{hastate} !~ /(UP|working)/' }, + 'no-ha-status:s' => { name => 'no_ha_status', default => 'UNKNOWN' } + }); return $self; } @@ -96,20 +89,27 @@ sub manage_selection { $self->{high_availability} = {}; - my $result = $options{snmp}->get_leef(oids => [$oid_haInstalled, $oid_haState, $oid_haStatCode, $oid_haStarted], - nothing_quit => 1); + my $result = $options{snmp}->get_leef( + oids => [$oid_haInstalled, $oid_haState, $oid_haStatCode, $oid_haStarted], + nothing_quit => 1 + ); if ($result->{$oid_haInstalled} < 1 or $result->{$oid_haStarted} eq "no") { - $self->{output}->output_add(severity => $self->{option_results}->{no_ha_status}, - short_msg => sprintf("Looks like HA is not started, or not installed .."), - long_msg => sprintf("HA Installed : '%u' HA Started : '%s'", - $result->{$oid_haInstalled}, $result->{$oid_haStarted}), - ); + $self->{output}->output_add( + severity => $self->{option_results}->{no_ha_status}, + short_msg => sprintf("Looks like HA is not started, or not installed .."), + long_msg => sprintf( + "HA Installed : '%u' HA Started : '%s'", + $result->{$oid_haInstalled}, $result->{$oid_haStarted} + ), + ); $self->{output}->display(); $self->{output}->exit(); } - $self->{high_availability} = { hastate => $map_status{$result->{$oid_haStatCode}}, - role => $result->{$oid_haState} }; + $self->{high_availability} = { + hastate => $map_status{$result->{$oid_haStatCode}}, + role => $result->{$oid_haState} + }; } 1; diff --git a/centreon-plugins/network/checkpoint/snmp/mode/memory.pm b/centreon-plugins/network/checkpoint/snmp/mode/memory.pm index d91eb1e73..67203270f 100644 --- a/centreon-plugins/network/checkpoint/snmp/mode/memory.pm +++ b/centreon-plugins/network/checkpoint/snmp/mode/memory.pm @@ -33,11 +33,12 @@ sub custom_usage_output { my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}); - my $msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_absolute}, - $total_free_value . " " . $total_free_unit, 100 - $self->{result_values}->{prct_used_absolute}); - return $msg; + return sprintf( + 'Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)', + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_absolute}, + $total_free_value . " " . $total_free_unit, 100 - $self->{result_values}->{prct_used_absolute} + ); } sub set_counters { @@ -61,6 +62,7 @@ sub set_counters { } }, ]; + $self->{maps_counters}->{swap} = [ { label => 'swap', set => { key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'total' } ], @@ -73,6 +75,7 @@ sub set_counters { } }, ]; + $self->{maps_counters}->{malloc} = [ { label => 'failed-malloc', set => { key_values => [ { name => 'failed_mallocs', diff => 1 } ], @@ -103,9 +106,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - }); + $options{options}->add_options(arguments => { + }); return $self; } diff --git a/centreon-plugins/network/checkpoint/snmp/mode/vpnstatus.pm b/centreon-plugins/network/checkpoint/snmp/mode/vpnstatus.pm index 73aa1b3e9..e9fae20d9 100644 --- a/centreon-plugins/network/checkpoint/snmp/mode/vpnstatus.pm +++ b/centreon-plugins/network/checkpoint/snmp/mode/vpnstatus.pm @@ -127,14 +127,14 @@ sub manage_selection { $self->{output}->output_add(long_msg => "skipping '" . $result->{tunnelPeerObjName} . "': no matching filter.", debug => 1); next; } - + $self->{vpn}->{$instance} = { display => $result->{tunnelPeerObjName}, status => $result->{tunnelState}, type => $result->{tunnelType} }; } - + if (scalar(keys %{$self->{vpn}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No vpn found."); $self->{output}->option_exit(); diff --git a/centreon-plugins/network/checkpoint/snmp/mode/vsx.pm b/centreon-plugins/network/checkpoint/snmp/mode/vsx.pm new file mode 100644 index 000000000..9bab2217a --- /dev/null +++ b/centreon-plugins/network/checkpoint/snmp/mode/vsx.pm @@ -0,0 +1,242 @@ +# +# 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 network::checkpoint::snmp::mode::vsx; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +sub vsx_long_output { + my ($self, %options) = @_; + + return "checking virtual system '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_vsx_output { + my ($self, %options) = @_; + + return "virtual system '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_cpu_output { + my ($self, %options) = @_; + + return 'cpu usage: '; +} + + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'vsx', type => 3, cb_prefix_output => 'prefix_vsx_output', cb_long_output => 'vsx_long_output', + indent_long_output => ' ', message_multiple => 'All virtual systems are ok', + group => [ + { name => 'vsx_cpu', type => 0, cb_prefix_output => 'prefix_cpu_output', skipped_code => { -10 => 1 } }, + { name => 'vsx_memory', type => 0, skipped_code => { -10 => 1 } }, + { name => 'vsx_connection', type => 0, skipped_code => { -10 => 1 } }, + { name => 'vsx_traffic', type => 0, skipped_code => { -10 => 1 } } + ] + } + ]; + + $self->{maps_counters}->{vsx_cpu} = [ + { label => 'cpu-utilization-1hour', nlabel => 'virtualsystem.cpu.utilization.1hour.percentage', set => { + key_values => [ { name => 'cpu_1hour' }, { name => 'display' } ], + output_template => '%.2f%% (1hour)', + perfdatas => [ + { value => 'cpu_1hour_absolute', template => '%.2f', unit => '%', min => 0, max => 100, + label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + }, + { label => 'cpu-utilization-1min', nlabel => 'virtualsystem.cpu.utilization.1min.percentage', set => { + key_values => [ { name => 'cpu_1min' }, { name => 'display' } ], + output_template => '%.2f%% (1min)', + perfdatas => [ + { value => 'cpu_1min_absolute', template => '%.2f', unit => '%', min => 0, max => 100, + label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + } + ]; + + $self->{maps_counters}->{vsx_memory} = [ + { label => 'memory-usage', nlabel => 'virtualsystem.memory.usage.bytes', set => { + key_values => [ { name => 'memory_used' }, { name => 'display' } ], + output_template => 'memory used: %s%s', + output_change_bytes => 1, + perfdatas => [ + { value => 'memory_used_absolute', template => '%s', min => 0, + unit => 'B', label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + } + ]; + + $self->{maps_counters}->{vsx_connection} = [ + { label => 'connections-active', nlabel => 'virtualsystem.connections.active.count', set => { + key_values => [ { name => 'active_connections' }, { name => 'display' } ], + output_template => 'active connections: %d', + perfdatas => [ + { value => 'active_connections_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + } + ]; + + $self->{maps_counters}->{vsx_traffic} = [ + { label => 'traffic-accepted', nlabel => 'virtualsystem.traffic.accepted.bitspersecond', set => { + key_values => [ { name => 'traffic_accepted', diff => 1 }, { name => 'display' } ], + output_template => 'traffic accepted: %s%s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_accepted_per_second', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' } + ] + } + }, + { label => 'traffic-dropped', nlabel => 'virtualsystem.traffic.dropped.bitspersecond', set => { + key_values => [ { name => 'traffic_dropped', diff => 1 }, { name => 'display' } ], + output_template => 'traffic dropped: %s%s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_dropped_per_second', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' } + ] + } + }, + { label => 'traffic-rejected', nlabel => 'virtualsystem.traffic.rejected.bitspersecond', set => { + key_values => [ { name => 'traffic_rejected', diff => 1 }, { name => 'display' } ], + output_template => 'traffic rejected: %s%s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_rejected_per_second', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' } + ] + } + } + ]; +} + +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-vsx:s' => { name => 'filter_vsx' } + }); + + return $self; +} + +my $mapping = { + cpu_1min => { oid => '.1.3.6.1.4.1.2620.1.16.22.2.1.3' }, # vsxStatusCPUUsage1min + cpu_1hour => { oid => '.1.3.6.1.4.1.2620.1.16.22.2.1.4' }, # vsxStatusCPUUsage1hr + memory_used => { oid => '.1.3.6.1.4.1.2620.1.16.22.3.1.3' }, # vsxStatusMemoryUsage (KB) + active_connections => { oid => '.1.3.6.1.4.1.2620.1.16.23.1.1.2' }, # vsxCountersConnNum + traffic_accepted => { oid => '.1.3.6.1.4.1.2620.1.16.23.1.1.9' }, # vsxCountersBytesAcceptedTotal + traffic_dropped => { oid => '.1.3.6.1.4.1.2620.1.16.23.1.1.10' }, # vsxCountersBytesDroppedTotal + traffic_rejected => { oid => '.1.3.6.1.4.1.2620.1.16.23.1.1.11' } # vsxCountersBytesRejectedTotal +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_vsxStatusVsName = '.1.3.6.1.4.1.2620.1.16.22.1.1.3'; + my $snmp_result = $options{snmp}->get_table( + oid => $oid_vsxStatusVsName, + nothing_quit => 1 + ); + + $self->{vsx} = {}; + foreach (keys %$snmp_result) { + /^$oid_vsxStatusVsName\.(.*)/; + my $instance = $1; + my $name = $snmp_result->{$_}; + + if (defined($self->{option_results}->{filter_vsx}) && $self->{option_results}->{filter_vsx} ne '' && + $name !~ /$self->{option_results}->{filter_vsx}/) { + $self->{output}->output_add(long_msg => "skipping virtual system '" . $name . "'.", debug => 1); + next; + } + + $self->{vsx}->{$instance} = { + display => $name, + vsx_cpu => { display => $name }, + vsx_memory => { display => $name }, + vsx_connection => { display => $name }, + vsx_traffic => { display => $name } + }; + } + + return if (scalar(keys %{$self->{vsx}}) <= 0); + + $options{snmp}->load( + oids => [ map($_->{oid}, values(%$mapping)) ], + instances => [ keys %{$self->{vsx}} ], + instance_regexp => '^(.*)$' + ); + $snmp_result = $options{snmp}->get_leef(); + foreach (keys %{$self->{vsx}}) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + $self->{vsx}->{$_}->{vsx_cpu}->{cpu_1min} = $result->{cpu_1min}; + $self->{vsx}->{$_}->{vsx_cpu}->{cpu_1hour} = $result->{cpu_1hour}; + $self->{vsx}->{$_}->{vsx_memory}->{memory_used} = $result->{memory_used} * 1024; + $self->{vsx}->{$_}->{vsx_connection}->{active_connections} = $result->{active_connections}; + $self->{vsx}->{$_}->{vsx_traffic}->{traffic_accepted} = $result->{traffic_accepted} * 8; + $self->{vsx}->{$_}->{vsx_traffic}->{traffic_dropped} = $result->{traffic_dropped} * 8; + $self->{vsx}->{$_}->{vsx_traffic}->{traffic_rejected} = $result->{traffic_rejected} * 8; + } + + $self->{cache_name} = 'checkpoint_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_vsx}) ? md5_hex($self->{option_results}->{filter_vsx}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check virtual systems. + +=over 8 + +=item B<--filter-vsx> + +Filter by virtual system name (can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'cpu-utilization', 'sessions-active', 'session-rate', +'memory-usage-prct', 'license-usage', 'license-free', +'license-usage-prct', 'traffic-in', 'traffic-out', 'policies-active'. + +=back + +=cut diff --git a/centreon-plugins/network/checkpoint/snmp/plugin.pm b/centreon-plugins/network/checkpoint/snmp/plugin.pm index 963713424..42d7a5ba1 100644 --- a/centreon-plugins/network/checkpoint/snmp/plugin.pm +++ b/centreon-plugins/network/checkpoint/snmp/plugin.pm @@ -31,16 +31,17 @@ sub new { $self->{version} = '0.5'; %{$self->{modes}} = ( - 'connections' => 'network::checkpoint::snmp::mode::connections', - 'cpu' => 'network::checkpoint::snmp::mode::cpu', - 'hardware' => 'network::checkpoint::snmp::mode::hardware', - 'hastate' => 'network::checkpoint::snmp::mode::hastate', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::checkpoint::snmp::mode::memory', - 'uptime' => 'snmp_standard::mode::uptime', - 'vpn-status' => 'network::checkpoint::snmp::mode::vpnstatus', - 'vrrp-status' => 'snmp_standard::mode::vrrp', + 'connections' => 'network::checkpoint::snmp::mode::connections', + 'cpu' => 'network::checkpoint::snmp::mode::cpu', + 'hardware' => 'network::checkpoint::snmp::mode::hardware', + 'hastate' => 'network::checkpoint::snmp::mode::hastate', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::checkpoint::snmp::mode::memory', + 'uptime' => 'snmp_standard::mode::uptime', + 'vpn-status' => 'network::checkpoint::snmp::mode::vpnstatus', + 'vrrp-status' => 'snmp_standard::mode::vrrp', + 'vsx' => 'network::checkpoint::snmp::mode::vsx', ); return $self; From 929ecb7c0271cd5dceaf232207a51f6a108e119b Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 26 Mar 2020 14:07:23 +0100 Subject: [PATCH 012/190] enhance typo --- centreon-plugins/network/checkpoint/snmp/mode/vsx.pm | 6 +++--- .../cisco/meraki/cloudcontroller/snmp/mode/deviceusage.pm | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/centreon-plugins/network/checkpoint/snmp/mode/vsx.pm b/centreon-plugins/network/checkpoint/snmp/mode/vsx.pm index 9bab2217a..5418e8e5e 100644 --- a/centreon-plugins/network/checkpoint/snmp/mode/vsx.pm +++ b/centreon-plugins/network/checkpoint/snmp/mode/vsx.pm @@ -233,9 +233,9 @@ Filter by virtual system name (can be a regexp). =item B<--warning-*> B<--critical-*> Thresholds. -Can be: 'cpu-utilization', 'sessions-active', 'session-rate', -'memory-usage-prct', 'license-usage', 'license-free', -'license-usage-prct', 'traffic-in', 'traffic-out', 'policies-active'. +Can be: 'memory-usage', 'traffic-accepted', 'traffic-dropped', +'traffic-rejected', 'cpu-utilization-1hour', 'cpu-utilization-1min', +'connections-active'. =back diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/snmp/mode/deviceusage.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/snmp/mode/deviceusage.pm index 4264f2a41..ecdfa8981 100644 --- a/centreon-plugins/network/cisco/meraki/cloudcontroller/snmp/mode/deviceusage.pm +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/snmp/mode/deviceusage.pm @@ -30,9 +30,8 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - my $msg = 'status : ' . $self->{result_values}->{status}; - return $msg; + return 'status : ' . $self->{result_values}->{status}; } sub custom_status_calc { From d8d8952668f1efdf1c70b370eaf364c6543e29b1 Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Thu, 26 Mar 2020 19:28:49 +0100 Subject: [PATCH 013/190] Fix nsclient++ new API --- centreon-plugins/apps/protocols/nrpe/custom/nsclient.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/apps/protocols/nrpe/custom/nsclient.pm b/centreon-plugins/apps/protocols/nrpe/custom/nsclient.pm index 6bbf04331..8e562b79f 100644 --- a/centreon-plugins/apps/protocols/nrpe/custom/nsclient.pm +++ b/centreon-plugins/apps/protocols/nrpe/custom/nsclient.pm @@ -142,7 +142,7 @@ sub output_perf { my $result = 'UNKNOWN'; $result = $errors_num{$options{result}} if ($options{result} =~ /[0-3]/); - $result = $options{result}if ($options{result} =~ /\w+/); + $result = $options{result} if ($options{result} =~ /[A-Z]+/); my %result = ( code => $result, From 04b1fd89f8520b60ed1ee3a4c025ac077a32683b Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Thu, 26 Mar 2020 22:49:57 +0100 Subject: [PATCH 014/190] Typo in interfaces perfdata new label --- centreon-plugins/snmp_standard/mode/interfaces.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/snmp_standard/mode/interfaces.pm b/centreon-plugins/snmp_standard/mode/interfaces.pm index c0a9a3a35..3e11c4fda 100644 --- a/centreon-plugins/snmp_standard/mode/interfaces.pm +++ b/centreon-plugins/snmp_standard/mode/interfaces.pm @@ -201,7 +201,7 @@ sub custom_errors_perfdata { if ($self->{instance_mode}->{option_results}->{units_errors} eq '%') { $self->{output}->perfdata_add( label => 'packets_' . $self->{result_values}->{label2} . '_' . $self->{result_values}->{label1}, unit => '%', - nlabel => 'interface.packets.' . $self->{result_values}->{label1} . '.' . $self->{result_values}->{label2} . 's.percentage', + nlabel => 'interface.packets.' . $self->{result_values}->{label1} . '.' . $self->{result_values}->{label2} . '.percentage', instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, value => sprintf("%.2f", $self->{result_values}->{prct}), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}), From 7a31d32d3a79f44b3ebd0188c0c982cd35100695 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 27 Mar 2020 09:04:00 +0100 Subject: [PATCH 015/190] fix help --- .../hardware/devices/eltek/enexus/snmp/mode/outputs.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/outputs.pm b/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/outputs.pm index 2630eb63b..37a86ffcb 100644 --- a/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/outputs.pm +++ b/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/outputs.pm @@ -191,7 +191,7 @@ Can used special variables like: %{status}, %{name} =item B<--warning-*> B<--critical-*> Thresholds. -Can be: 'current'. +Can be: 'outputs-disconnected', 'outputs-notenergized'. =back From ac5a4ce3a043d7dad39bce0df065589afe9f1eb4 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 27 Mar 2020 09:17:08 +0100 Subject: [PATCH 016/190] update vpn-status checkpoint --- .../checkpoint/snmp/mode/connections.pm | 5 +- .../network/checkpoint/snmp/mode/cpu.pm | 10 +-- .../network/checkpoint/snmp/mode/vpnstatus.pm | 77 +++++++++++-------- 3 files changed, 52 insertions(+), 40 deletions(-) diff --git a/centreon-plugins/network/checkpoint/snmp/mode/connections.pm b/centreon-plugins/network/checkpoint/snmp/mode/connections.pm index e0141c3cc..90adbcc9c 100644 --- a/centreon-plugins/network/checkpoint/snmp/mode/connections.pm +++ b/centreon-plugins/network/checkpoint/snmp/mode/connections.pm @@ -29,7 +29,7 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { 'warning:s' => { name => 'warning' }, 'critical:s' => { name => 'critical' }, @@ -65,7 +65,7 @@ sub run { my $oid_fwNumCom = '.1.3.6.1.4.1.2620.1.1.25.3.0'; my $oid_fwConnTableLimit = '.1.3.6.1.4.1.2620.1.1.25.10.0'; my $result = $self->{snmp}->get_leef(oids => [$oid_fwNumCom, $oid_fwConnTableLimit], nothing_quit => 1); - + my $value = $result->{$oid_fwNumCom}; my $extra = ''; my %total_options = (); @@ -78,7 +78,6 @@ sub run { } } - my $exit = $self->{perfdata}->threshold_check(value => $value, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add( diff --git a/centreon-plugins/network/checkpoint/snmp/mode/cpu.pm b/centreon-plugins/network/checkpoint/snmp/mode/cpu.pm index 5759d6587..d34127b0d 100644 --- a/centreon-plugins/network/checkpoint/snmp/mode/cpu.pm +++ b/centreon-plugins/network/checkpoint/snmp/mode/cpu.pm @@ -29,7 +29,7 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { 'warning:s' => { name => 'warning', }, 'critical:s' => { name => 'critical', }, @@ -41,7 +41,7 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); $self->{output}->option_exit(); @@ -59,11 +59,11 @@ sub run { my $oid_procUsrTime = '.1.3.6.1.4.1.2620.1.6.7.2.1.0'; my $oid_procSysTime = '.1.3.6.1.4.1.2620.1.6.7.2.2.0'; my $oid_procIdleTime = '.1.3.6.1.4.1.2620.1.6.7.2.3.0'; - + my $result = $self->{snmp}->get_leef(oids => [$oid_procUsrTime, $oid_procSysTime, $oid_procIdleTime], nothing_quit => 1); - + my $totalCpuUsed = $result->{$oid_procUsrTime} + $result->{$oid_procSysTime}; - + my $exit = $self->{perfdata}->threshold_check(value => $totalCpuUsed, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(severity => $exit, diff --git a/centreon-plugins/network/checkpoint/snmp/mode/vpnstatus.pm b/centreon-plugins/network/checkpoint/snmp/mode/vpnstatus.pm index e9fae20d9..08c42fa21 100644 --- a/centreon-plugins/network/checkpoint/snmp/mode/vpnstatus.pm +++ b/centreon-plugins/network/checkpoint/snmp/mode/vpnstatus.pm @@ -24,48 +24,50 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); sub custom_status_output { my ($self, %options) = @_; - - my $msg = 'status : ' . $self->{result_values}->{status}; - return $msg; -} -sub custom_status_calc { - my ($self, %options) = @_; - - $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - $self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'}; - return 0; + return 'status : ' . $self->{result_values}->{status}; } sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, { name => 'vpn', type => 1, cb_prefix_output => 'prefix_vpn_output', message_multiple => 'All vpn are ok' } ]; - + + $self->{maps_counters}->{global} = [ + { label => 'tunnels-total', nlabel => 'vpn.tunnels.total.count', display_ok => 0, set => { + key_values => [ { name => 'total' } ], + output_template => 'current total number of tunnels: %d', + perfdatas => [ + { value => 'total_absolute', template => '%d', min => 0 } + ] + } + } + ]; + $self->{maps_counters}->{vpn} = [ { label => 'status', threshold => 0, set => { key_values => [ { name => 'type' }, { name => 'status' }, { name => 'display' } ], - closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold } - }, + } ]; } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - + $options{options}->add_options(arguments => { 'filter-name:s' => { name => 'filter_name' }, 'warning-status:s' => { name => 'warning_status', default => '' }, @@ -73,7 +75,7 @@ sub new { 'filter-name:s' => { name => 'filter_name' }, 'buggy-snmp' => { name => 'buggy_snmp' }, }); - + return $self; } @@ -86,37 +88,42 @@ sub check_options { sub prefix_vpn_output { my ($self, %options) = @_; - + return "VPN '" . $options{instance_value}->{display} . "' "; } -my %map_type = (1 => 'regular', 2 => 'permanent'); -my %map_state = (3 => 'active', 4 => 'destroy', 129 => 'idle', 130 => 'phase1', +my $map_type = { 1 => 'regular', 2 => 'permanent' }; +my $map_state = { + 3 => 'active', 4 => 'destroy', 129 => 'idle', 130 => 'phase1', 131 => 'down', 132 => 'init' -); +}; my $mapping = { tunnelPeerObjName => { oid => '.1.3.6.1.4.1.2620.500.9002.1.2' }, - tunnelState => { oid => '.1.3.6.1.4.1.2620.500.9002.1.3', map => \%map_state }, - tunnelType => { oid => '.1.3.6.1.4.1.2620.500.9002.1.11', map => \%map_type }, + tunnelState => { oid => '.1.3.6.1.4.1.2620.500.9002.1.3', map => $map_state }, + tunnelType => { oid => '.1.3.6.1.4.1.2620.500.9002.1.11', map => $map_type } }; my $oid_tunnelEntry = '.1.3.6.1.4.1.2620.500.9002.1'; sub manage_selection { my ($self, %options) = @_; - $self->{vs} = {}; my $snmp_result; if (defined($self->{option_results}->{buggy_snmp})) { $snmp_result = $options{snmp}->get_table(oid => $oid_tunnelEntry, nothing_quit => 1); } else { - $snmp_result = $options{snmp}->get_multiple_table(oids => [ - { oid => $mapping->{tunnelPeerObjName}->{oid} }, - { oid => $mapping->{tunnelState}->{oid} }, - { oid => $mapping->{tunnelType}->{oid} }, - ], nothing_quit => 1, return_type => 1); + $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_tunnelEntry, start => $mapping->{tunnelPeerObjName}->{oid}, end => $mapping->{tunnelState}->{oid} }, + { oid => $mapping->{tunnelType}->{oid} } + ], + nothing_quit => 1, + return_type => 1 + ); } + $self->{global} = { total => 0 }; + $self->{vs} = {}; foreach my $oid (keys %{$snmp_result}) { next if ($oid !~ /^$mapping->{tunnelState}->{oid}\.(.*)$/); my $instance = $1; @@ -133,6 +140,7 @@ sub manage_selection { status => $result->{tunnelState}, type => $result->{tunnelType} }; + $self->{global}->{total}++; } if (scalar(keys %{$self->{vpn}}) <= 0) { @@ -169,6 +177,11 @@ Can used special variables like: %{type}, %{status}, %{display} Checkpoint snmp can be buggy. Test that option if no response. +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'tunnels-total'. + =back =cut From 63d41ac6ee402ad9520ebf2042ae033ab8878621 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Fri, 27 Mar 2020 09:25:12 +0100 Subject: [PATCH 017/190] enh(plugin) include vsys within global session mode --- .../network/paloalto/snmp/mode/sessions.pm | 212 +++++++++++++++--- .../paloalto/snmp/mode/vsyssessions.pm | 203 ----------------- 2 files changed, 178 insertions(+), 237 deletions(-) delete mode 100644 centreon-plugins/network/paloalto/snmp/mode/vsyssessions.pm diff --git a/centreon-plugins/network/paloalto/snmp/mode/sessions.pm b/centreon-plugins/network/paloalto/snmp/mode/sessions.pm index 9fdf069b4..404f9be4e 100644 --- a/centreon-plugins/network/paloalto/snmp/mode/sessions.pm +++ b/centreon-plugins/network/paloalto/snmp/mode/sessions.pm @@ -27,9 +27,10 @@ use warnings; sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } }, + { name => 'vsys', type => 1, cb_prefix_output => 'prefix_vsys_output', message_multiple => 'Vsys sessions metrics are OK', skipped_code => { -10 => 1 } }, ]; $self->{maps_counters}->{global} = [ { label => 'active', set => { @@ -38,10 +39,10 @@ sub set_counters { closure_custom_output => $self->can('custom_active_output'), closure_custom_perfdata => $self->can('custom_active_perfdata'), closure_custom_threshold_check => $self->can('custom_active_threshold'), - + } }, - { label => 'active-ssl-proxy', set => { + { label => 'active-ssl-proxy', nlabel => 'sessions.active.vpnssl.count', set => { key_values => [ { name => 'panSessionSslProxyUtilization' } ], output_template => 'Active SSL Proxy : %.2f %%', perfdatas => [ @@ -50,7 +51,7 @@ sub set_counters { ], } }, - { label => 'active-tcp', set => { + { label => 'active-tcp', nlabel => 'sessions.active.tcp.count', set => { key_values => [ { name => 'panSessionActiveTcp' } ], output_template => 'Active TCP : %s', perfdatas => [ @@ -58,7 +59,7 @@ sub set_counters { ], } }, - { label => 'active-udp', set => { + { label => 'active-udp', nlabel => 'sessions.active.udp.count', set => { key_values => [ { name => 'panSessionActiveUdp' } ], output_template => 'Active UDP : %s', perfdatas => [ @@ -66,7 +67,7 @@ sub set_counters { ], } }, - { label => 'active-icmp', set => { + { label => 'active-icmp', nlabel => 'sessions.active.icmp.count', set => { key_values => [ { name => 'panSessionActiveICMP' } ], output_template => 'Active ICMP : %s', perfdatas => [ @@ -75,66 +76,171 @@ sub set_counters { } }, ]; + + $self->{maps_counters}->{vsys} = [ + { label => 'active-vsys', set => { + key_values => [ { name => 'panVsysActiveSessions' }, { name => 'panVsysMaxSessions' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_active_calc'), + closure_custom_output => $self->can('custom_active_output'), + closure_custom_perfdata => $self->can('custom_active_perfdata'), + closure_custom_threshold_check => $self->can('custom_active_threshold'), + + } + }, + { label => 'vsys-active-tcp', nlabel => 'vsys.sessions.active.tcp.count', set => { + key_values => [ { name => 'panVsysActiveTcpCps' }, { name => 'display' } ], + output_template => 'Active TCP : %s', + perfdatas => [ + { label => 'active_tcp', value => 'panVsysActiveTcpCps_absolute', template => '%s', + label_extra_instance => 1, instance_use => 'display_absolute', min => 0 }, + ], + } + }, + { label => 'vsys-active-udp', nlabel => 'vsys.sessions.active.udp.count', set => { + key_values => [ { name => 'panVsysActiveUdpCps' }, { name => 'display' } ], + output_template => 'Active UDP : %s', + perfdatas => [ + { label => 'active_udp', value => 'panVsysActiveUdpCps_absolute', template => '%s', + label_extra_instance => 1, instance_use => 'display_absolute', min => 0 }, + ], + } + }, + { label => 'vsys-active-other', nlabel => 'vsys.sessions.active.other.count', set => { + key_values => [ { name => 'panVsysActiveOtherIpCps' }, { name => 'display' } ], + output_template => 'Other : %s', + perfdatas => [ + { label => 'active_other', value => 'panVsysActiveOtherIpCps_absolute', template => '%s', + label_extra_instance => 1, instance_use => 'display_absolute', min => 0 }, + ], + } + }, + ]; + + + } sub prefix_global_output { my ($self, %options) = @_; - + return "Sessions "; } +sub prefix_vsys_output { + my ($self, %options) = @_; + + return "Vsys '" . $options{instance_value}->{display} . "' "; + +} + sub custom_active_perfdata { my ($self, %options) = @_; - - my $label = 'active'; - my %total_options = (); - if ($self->{result_values}->{panSessionMax} != 0) { - $total_options{total} = $self->{result_values}->{panSessionMax}; - $total_options{cast_int} = 1; - } - $self->{output}->perfdata_add(label => $label, - value => $self->{result_values}->{panSessionActive}, - warning => defined($total_options{total}) ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options) : undef, - critical => defined($total_options{total}) ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options) : undef, - min => 0, max => $self->{result_values}->{panSessionMax}); + my %total_options = (); + + if ($self->{label} eq 'active') { + if ($self->{result_values}->{panSessionMax} != 0) { + $total_options{total} = $self->{result_values}->{panSessionMax}; + $total_options{cast_int} = 1; + } + + $self->{output}->perfdata_add(label => $self->{label}, + nlabel => 'sessions.active.count', + value => $self->{result_values}->{panSessionActive}, + warning => defined($total_options{total}) ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options) : undef, + critical => defined($total_options{total}) ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options) : undef, + min => 0, max => $self->{result_values}->{panSessionMax}); + } else { + if ($self->{result_values}->{panVsysMaxSessions} != 0) { + $total_options{total} = $self->{result_values}->{panVsysMaxSessions}; + $total_options{cast_int} = 1; + } + + $self->{output}->perfdata_add(label => $self->{label}, + nlabel => $self->{result_values}->{display} . "#" . 'sessions.active.count', + value => $self->{result_values}->{panVsysActiveSessions}, + warning => defined($total_options{total}) ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options) : undef, + critical => defined($total_options{total}) ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options) : undef, + min => 0, max => $self->{result_values}->{panVsysMaxSessions}); + } } sub custom_active_threshold { my ($self, %options) = @_; - + my ($exit, $threshold_value) = ('ok'); - if ($self->{result_values}->{panSessionMax} != 0) { - $threshold_value = $self->{result_values}->{active_prct}; + + if ($self->{label} eq 'active') { + if ($self->{result_values}->{panSessionMax} != 0) { + $threshold_value = $self->{result_values}->{active_prct}; + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => + [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]) if (defined($threshold_value)); + return $exit; + } else { + if ($self->{result_values}->{panVsysMaxSessions} != 0) { + $threshold_value = $self->{result_values}->{active_prct}; + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => + [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]) if (defined($threshold_value)); + return $exit; } - $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => - [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]) if (defined($threshold_value)); - return $exit; } sub custom_active_output { my ($self, %options) = @_; - - my $msg = sprintf("Active : %s (%s)", + + my $msg = ""; + if ($self->{label} eq 'active') { + $msg = sprintf("Active : %s (%s)", $self->{result_values}->{panSessionActive}, - $self->{result_values}->{panSessionMax} != 0 ? $self->{result_values}->{active_prct} . " %" : + $self->{result_values}->{panSessionMax} != 0 ? $self->{result_values}->{active_prct} . " %" : '-'); + } else { + $msg = sprintf("Active : %s (%s)", + $self->{result_values}->{panVsysActiveSessions}, + $self->{result_values}->{panVsysMaxSessions} != 0 ? $self->{result_values}->{active_prct} . " %" : + '-'); + } return $msg; } sub custom_active_calc { my ($self, %options) = @_; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; $self->{result_values}->{panSessionActive} = $options{new_datas}->{$self->{instance} . '_panSessionActive'}; $self->{result_values}->{panSessionMax} = $options{new_datas}->{$self->{instance} . '_panSessionMax'}; + $self->{result_values}->{panVsysActiveSessions} = $options{new_datas}->{$self->{instance} . '_panVsysActiveSessions'}; + $self->{result_values}->{panVsysMaxSessions} = $options{new_datas}->{$self->{instance} . '_panVsysMaxSessions'}; $self->{result_values}->{active_prct} = 0; - if ($self->{result_values}->{panSessionMax} != 0) { - $self->{result_values}->{active_prct} = $self->{result_values}->{panSessionActive} * 100 / $self->{result_values}->{panSessionMax}; + + if ($self->{label} eq 'active') { + if ($self->{result_values}->{panSessionMax} != 0) { + $self->{result_values}->{active_prct} = $self->{result_values}->{panSessionActive} * 100 / $self->{result_values}->{panSessionMax}; + } + } else { + if ($self->{result_values}->{panVsysMaxSessions} != 0) { + $self->{result_values}->{active_prct} = $self->{result_values}->{panVsysActiveSessions} * 100 / $self->{result_values}->{panVsysMaxSessions}; + } } return 0; } -my $mapping = { +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, force_new_perfdata => 1, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'add-vsys' => { name => 'add_vsys' }, + }); + + return $self; +} + + +my $mapping_sessions = { panSessionMax => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.2' }, panSessionActive => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.3' }, panSessionActiveTcp => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.4' }, @@ -144,14 +250,50 @@ my $mapping = { panSessionSslProxyUtilization => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.8' }, }; +my $mapping_vsys = { + panVsysName => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.2' }, + panVsysActiveSessions => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.4' }, + panVsysMaxSessions => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.5' }, + panVsysActiveTcpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.6' }, + panVsysActiveUdpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.7' }, + panVsysActiveOtherIpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.8' }, +}; + +sub add_vsys { + my ($self, %options) = @_; + + my $oid_panVsysEntry = '.1.3.6.1.4.1.25461.2.1.2.3.9.1'; + $self->{results} = $options{snmp}->get_table(oid => $oid_panVsysEntry, + nothing_quit => 1); + + foreach my $oid (keys %{$self->{results}}) { + next if $oid !~ /^$mapping_vsys->{panVsysName}->{oid}\.(.*)$/; + my $instance = $1; + + my $result = $options{snmp}->map_instance(mapping => $mapping_vsys, results => $self->{results}, instance => $instance); + + $self->{vsys}->{$result->{panVsysName}} = { + display => $result->{panVsysName}, + panVsysMaxSessions => defined($result->{panVsysMaxSessions}) ? $result->{panVsysMaxSessions} : 0, + panVsysActiveSessions => $result->{panVsysActiveSessions}, + panVsysActiveTcpCps => $result->{panVsysActiveTcpCps}, + panVsysActiveUdpCps => $result->{panVsysActiveUdpCps}, + }; + + } +} + sub manage_selection { my ($self, %options) = @_; my $oid_panSession = '.1.3.6.1.4.1.25461.2.1.2.3'; $self->{results} = $options{snmp}->get_table(oid => $oid_panSession, nothing_quit => 1); - $self->{global} = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => '0'); + $self->{global} = $options{snmp}->map_instance(mapping => $mapping_sessions, results => $self->{results}, instance => '0'); $self->{global}->{panSessionMax} = 0 if (!defined($self->{global}->{panSessionMax})); + + $self->add_vsys(snmp => $options{snmp}) + if (defined($self->{option_results}->{add_vsys})); } 1; @@ -167,12 +309,14 @@ Check sessions. =item B<--warning-*> Threshold warning. -Can be: 'active' (%), 'active-tcp', 'active-udp', 'active-icmp', 'active-ssl-proxy' (%). +Global: 'active' (%), 'active-tcp', 'active-udp', 'active-icmp', 'active-ssl-proxy' (%). +Per vsys: 'active-vsys' (%), 'vsys-active-tcp' 'vsys-active-udp' 'vsys-active-other' =item B<--critical-*> Threshold critical. -Can be: 'active' (%), 'active-tcp', 'active-udp', 'active-icmp', 'active-ssl-proxy' (%). +Global: 'active' (%), 'active-tcp', 'active-udp', 'active-icmp', 'active-ssl-proxy' (%). +Per vsys: 'active-vsys' (%), 'vsys-active-tcp' 'vsys-active-udp' 'vsys-active-other' =back diff --git a/centreon-plugins/network/paloalto/snmp/mode/vsyssessions.pm b/centreon-plugins/network/paloalto/snmp/mode/vsyssessions.pm deleted file mode 100644 index 0a9040321..000000000 --- a/centreon-plugins/network/paloalto/snmp/mode/vsyssessions.pm +++ /dev/null @@ -1,203 +0,0 @@ -# -# 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 network::paloalto::snmp::mode::vsyssessions; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'vsys', type => 1, cb_prefix_output => 'prefix_vsys_output', message_multiple => 'Vsys Sessions metrics are OK' }, - ]; - $self->{maps_counters}->{vsys} = [ - { label => 'active', set => { - key_values => [ { name => 'panVsysActiveSessions' }, { name => 'panVsysMaxSessions' }, { name => 'display' } ], - closure_custom_calc => $self->can('custom_active_calc'), - closure_custom_output => $self->can('custom_active_output'), - closure_custom_perfdata => $self->can('custom_active_perfdata'), - closure_custom_threshold_check => $self->can('custom_active_threshold'), - - } - }, - { label => 'active-tcp', nlabel => 'vsys.sessions.active.tcp.count', set => { - key_values => [ { name => 'panVsysActiveTcpCps' }, { name => 'display' } ], - output_template => 'Active TCP : %s', - perfdatas => [ - { label => 'active_tcp', value => 'panVsysActiveTcpCps_absolute', template => '%s', - label_extra_instance => 1, instance_use => 'display_absolute', min => 0 }, - ], - } - }, - { label => 'active-udp', nlabel => 'vsys.sessions.active.udp.count', set => { - key_values => [ { name => 'panVsysActiveUdpCps' }, { name => 'display' } ], - output_template => 'Active UDP : %s', - perfdatas => [ - { label => 'active_udp', value => 'panVsysActiveUdpCps_absolute', template => '%s', - label_extra_instance => 1, instance_use => 'display_absolute', min => 0 }, - ], - } - }, - { label => 'active-other', nlabel => 'vsys.sessions.active.other.count', set => { - key_values => [ { name => 'panVsysActiveOtherIpCps' }, { name => 'display' } ], - output_template => 'Other : %s', - perfdatas => [ - { label => 'active_other', value => 'panVsysActiveOtherIpCps_absolute', template => '%s', - label_extra_instance => 1, instance_use => 'display_absolute', min => 0 }, - ], - } - }, - ]; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, force_new_perfdata => 1, %options); - bless $self, $class; - - $options{options}->add_options(arguments => { - }); - - return $self; -} - -sub prefix_vsys_output { - my ($self, %options) = @_; - - return "Vsys '" . $options{instance_value}->{display} . "' "; - -} - -sub custom_active_perfdata { - my ($self, %options) = @_; - - my $label = 'active'; - my %total_options = (); - if ($self->{result_values}->{panVsysMaxSessions} != 0) { - $total_options{total} = $self->{result_values}->{panVsysMaxSessions}; - $total_options{cast_int} = 1; - } - - $self->{output}->perfdata_add(label => $self->{result_values}->{display} . "#active.sessions.count", - value => $self->{result_values}->{panVsysActiveSessions}, - warning => defined($total_options{total}) ? - $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options) : undef, - critical => defined($total_options{total}) ? - $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options) : undef, - min => 0, - max => $self->{result_values}->{panVsysMaxSessions}); -} - -sub custom_active_threshold { - my ($self, %options) = @_; - - my ($exit, $threshold_value) = ('ok'); - if ($self->{result_values}->{panVsysMaxSessions} != 0) { - $threshold_value = $self->{result_values}->{active_prct}; - } - $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => - [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]) if (defined($threshold_value)); - return $exit; -} - -sub custom_active_output { - my ($self, %options) = @_; - - my $msg = sprintf("Active : %s (%s)", - $self->{result_values}->{panVsysActiveSessions}, - $self->{result_values}->{panVsysMaxSessions} != 0 ? $self->{result_values}->{active_prct} . " %" : - '-'); - return $msg; -} - -sub custom_active_calc { - my ($self, %options) = @_; - - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - $self->{result_values}->{panVsysActiveSessions} = $options{new_datas}->{$self->{instance} . '_panVsysActiveSessions'}; - $self->{result_values}->{panVsysMaxSessions} = $options{new_datas}->{$self->{instance} . '_panVsysMaxSessions'}; - $self->{result_values}->{active_prct} = 0; - if ($self->{result_values}->{panVsysMaxSessions} != 0) { - $self->{result_values}->{active_prct} = $self->{result_values}->{panVsysActiveSessions} * 100 / $self->{result_values}->{panVsysMaxSessions}; - } - return 0; -} - -my $mapping = { - panVsysName => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.2' }, - panVsysActiveSessions => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.4' }, - panVsysMaxSessions => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.5' }, - panVsysActiveTcpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.6' }, - panVsysActiveUdpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.7' }, - panVsysActiveOtherIpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.8' }, -}; - -sub manage_selection { - my ($self, %options) = @_; - - my $oid_panVsysEntry = '.1.3.6.1.4.1.25461.2.1.2.3.9.1'; - $self->{results} = $options{snmp}->get_table(oid => $oid_panVsysEntry, - nothing_quit => 1); - - foreach my $oid (keys %{$self->{results}}) { - next if $oid !~ /^$mapping->{panVsysName}->{oid}\.(.*)$/; - my $instance = $1; - - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); - - $self->{vsys}->{$result->{panVsysName}} = { - display => $result->{panVsysName}, - panVsysMaxSessions => defined($result->{panVsysMaxSessions}) ? $result->{panVsysMaxSessions} : 0, - panVsysActiveSessions => $result->{panVsysActiveSessions}, - panVsysActiveTcpCps => $result->{panVsysActiveTcpCps}, - panVsysActiveUdpCps => $result->{panVsysActiveUdpCps}, - panVsysActiveOtherIpCps => $result->{panVsysActiveOtherIpCps} - }; - - } -} - -1; - -__END__ - -=head1 MODE - -Check sessions per Vsys - -=over 8 - -=item B<--warning-*> - -Threshold warning. -Can be: 'active' (%), 'active-tcp', 'active-udp', 'active-other' - -=item B<--critical-*> - -Threshold critical. -Can be: 'active' (%), 'active-tcp', 'active-udp', 'active-other' - -=back - -=cut From 01a1e7ec2ff856915d9d9deb2c587dd8ff3855c4 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Fri, 27 Mar 2020 09:27:39 +0100 Subject: [PATCH 018/190] enh(plugin) delete vsyssession mode ref in plugin.pm --- centreon-plugins/network/paloalto/snmp/plugin.pm | 1 - 1 file changed, 1 deletion(-) diff --git a/centreon-plugins/network/paloalto/snmp/plugin.pm b/centreon-plugins/network/paloalto/snmp/plugin.pm index 4b4e476a0..41509f404 100644 --- a/centreon-plugins/network/paloalto/snmp/plugin.pm +++ b/centreon-plugins/network/paloalto/snmp/plugin.pm @@ -40,7 +40,6 @@ sub new { 'memory' => 'network::paloalto::snmp::mode::memory', 'panorama' => 'network::paloalto::snmp::mode::panorama', 'sessions' => 'network::paloalto::snmp::mode::sessions', - 'vsys-sessions' => 'network::paloalto::snmp::mode::vsyssessions', ); return $self; From b423cb63896fd690829cae8745dd57eb9e6c5ce8 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 27 Mar 2020 11:22:59 +0100 Subject: [PATCH 019/190] Fix #1904 --- .../storage/synology/snmp/mode/ha.pm | 154 ++++++++++++++++++ .../storage/synology/snmp/plugin.pm | 3 +- 2 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 centreon-plugins/storage/synology/snmp/mode/ha.pm diff --git a/centreon-plugins/storage/synology/snmp/mode/ha.pm b/centreon-plugins/storage/synology/snmp/mode/ha.pm new file mode 100644 index 000000000..799a0ae92 --- /dev/null +++ b/centreon-plugins/storage/synology/snmp/mode/ha.pm @@ -0,0 +1,154 @@ +# +# 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 storage::synology::snmp::mode::ha; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + "cluster status is '%s' [heartbeat status: %s] [active node: %s] [passive node: %s]", + $self->{result_values}->{cluster_status}, + $self->{result_values}->{heartbeat_status}, + $self->{result_values}->{active_node_name}, + $self->{result_values}->{passive_node_name} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', threshold => 0, set => { + key_values => [ + { name => 'cluster_status' }, { name => 'heartbeat_status' }, + { name => 'active_node_name' }, { name => 'passive_node_name' } + ], + closure_custom_calc => \&catalog_status_threshold, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + }, + { label => 'heartbeat-latency', nlabel => 'ha.heartbeat.latency.microseconds', display_ok => 0, set => { + key_values => [ { name => 'heartbeat_latency' } ], + output_template => 'heartbeat latency: %s us', + perfdatas => [ + { value => 'heartbeat_latency_absolute', template => '%s', min => 0, unit => 'us' } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '%{cluster_status} =~ /warning/i || %{heartbeat_status} =~ /abnormal/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{cluster_status} =~ /critical/i || %{heartbeat_status} =~ /disconnected/i' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); +} + +my $map_cluster_status = { + 0 => 'normal', 1 => 'warning', 2 => 'critical', 3 => 'upgrading', 4 => 'processing' +}; +my $map_heartbeat_status = { + 0 => 'normal', 1 => 'abnormal', 2 => 'disconnected', 3 => 'empty' +}; + +my $mapping = { + active_node_name => { oid => '.1.3.6.1.4.1.6574.106.1' }, # activeNodeName + passive_node_name => { oid => '.1.3.6.1.4.1.6574.106.2' }, # passiveNodeName + cluster_status => { oid => '.1.3.6.1.4.1.6574.106.5', map => $map_cluster_status }, # clusterStatus + heartbeat_status => { oid => '.1.3.6.1.4.1.6574.106.6', map => $map_heartbeat_status }, # heartbeatStatus + heartbeat_latency => { oid => '.1.3.6.1.4.1.6574.106.8' } # microseconds +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_leef( + oids => [ map($_->{oid} . '.0', values(%$mapping)) ], + nothing_quit => 1 + ); + $self->{global} = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); +} + +1; + +__END__ + +=head1 MODE + +Check high availability. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^status$' + +=item B<--unknown-status> + +Set unknown threshold for status. +Can used special variables like: %{cluster_status}, %{heartbeat_status}, %{active_node_name}, %{passive_node_name} + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{cluster_status} =~ /warning/i || %{heartbeat_status} =~ /abnormal/i'). +Can used special variables like: %{cluster_status}, %{heartbeat_status}, %{active_node_name}, %{passive_node_name} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{cluster_status} =~ /critical/i || %{heartbeat_status} =~ /disconnected/i'). +Can used special variables like: %{cluster_status}, %{heartbeat_status}, %{active_node_name}, %{passive_node_name} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'heartbeat-latency'. + +=back + +=cut diff --git a/centreon-plugins/storage/synology/snmp/plugin.pm b/centreon-plugins/storage/synology/snmp/plugin.pm index f3c8abd49..f1ce05244 100644 --- a/centreon-plugins/storage/synology/snmp/plugin.pm +++ b/centreon-plugins/storage/synology/snmp/plugin.pm @@ -33,12 +33,13 @@ sub new { %{$self->{modes}} = ( 'components' => 'storage::synology::snmp::mode::hardware', 'cpu' => 'snmp_standard::mode::cpu', + 'ha' => 'storage::synology::snmp::mode::ha', 'interfaces' => 'snmp_standard::mode::interfaces', 'memory' => 'snmp_standard::mode::memory', 'load' => 'snmp_standard::mode::loadaverage', 'storage' => 'snmp_standard::mode::storage', 'temperature' => 'storage::synology::snmp::mode::temperature', - 'ups' => 'storage::synology::snmp::mode::ups', + 'ups' => 'storage::synology::snmp::mode::ups' ); return $self; From b357c1d9fbf98f8b4b4c06cf2705aba923397e0b Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 27 Mar 2020 12:04:48 +0100 Subject: [PATCH 020/190] enhance paloalto sessions --- .../network/paloalto/snmp/mode/sessions.pm | 293 +++++++----------- 1 file changed, 114 insertions(+), 179 deletions(-) diff --git a/centreon-plugins/network/paloalto/snmp/mode/sessions.pm b/centreon-plugins/network/paloalto/snmp/mode/sessions.pm index 404f9be4e..9234c9e9b 100644 --- a/centreon-plugins/network/paloalto/snmp/mode/sessions.pm +++ b/centreon-plugins/network/paloalto/snmp/mode/sessions.pm @@ -25,6 +25,44 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub custom_vsys_active_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + label => $self->{label}, + nlabel => $self->{nlabel}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display_absolute} : undef, + value => $self->{result_values}->{sessions_active_absolute}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + min => 0, + max => $self->{result_values}->{sessions_max_absolute} != 0 ? $self->{result_values}->{sessions_max_absolute} : undef + ); +} + +sub custom_active_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + label => $self->{label}, + nlabel => $self->{nlabel}, + value => $self->{result_values}->{sessions_active_absolute}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + min => 0, + max => $self->{result_values}->{sessions_max_absolute} != 0 ? $self->{result_values}->{sessions_max_absolute} : undef + ); +} + +sub custom_active_output { + my ($self, %options) = @_; + + return sprintf('active: %s (%s)', + $self->{result_values}->{sessions_active_absolute}, + $self->{result_values}->{sessions_max_absolute} != 0 ? $self->{result_values}->{sessions_max_absolute} : '-' + ); +} + sub set_counters { my ($self, %options) = @_; @@ -33,76 +71,79 @@ sub set_counters { { name => 'vsys', type => 1, cb_prefix_output => 'prefix_vsys_output', message_multiple => 'Vsys sessions metrics are OK', skipped_code => { -10 => 1 } }, ]; $self->{maps_counters}->{global} = [ - { label => 'active', set => { - key_values => [ { name => 'panSessionActive' }, { name => 'panSessionMax' } ], - closure_custom_calc => $self->can('custom_active_calc'), + { label => 'active', nlabel => 'sessions.active.count', set => { + key_values => [ { name => 'sessions_active' }, { name => 'sessions_max' } ], closure_custom_output => $self->can('custom_active_output'), - closure_custom_perfdata => $self->can('custom_active_perfdata'), - closure_custom_threshold_check => $self->can('custom_active_threshold'), - + closure_custom_perfdata => $self->can('custom_active_perfdata') } }, - { label => 'active-ssl-proxy', nlabel => 'sessions.active.vpnssl.count', set => { - key_values => [ { name => 'panSessionSslProxyUtilization' } ], - output_template => 'Active SSL Proxy : %.2f %%', + { label => 'active-prct', nlabel => 'sessions.active.percentage', display_ok => 0, set => { + key_values => [ { name => 'sessions_active_prct' } ], + output_template => 'active: %.2f %%', perfdatas => [ - { label => 'active_ssl_proxy', value => 'panSessionSslProxyUtilization_absolute', template => '%.2f', unit => '%', - min => 0, max => 100 }, - ], + { label => 'active_prct', value => 'sessions_active_prct_absolute', template => '%.2f', unit => '%', + min => 0, max => 100 } + ] } }, { label => 'active-tcp', nlabel => 'sessions.active.tcp.count', set => { key_values => [ { name => 'panSessionActiveTcp' } ], - output_template => 'Active TCP : %s', + output_template => 'active TCP: %s', perfdatas => [ - { label => 'active_tcp', value => 'panSessionActiveTcp_absolute', template => '%s', min => 0 }, - ], + { label => 'active_tcp', value => 'panSessionActiveTcp_absolute', template => '%s', min => 0 } + ] } }, { label => 'active-udp', nlabel => 'sessions.active.udp.count', set => { key_values => [ { name => 'panSessionActiveUdp' } ], - output_template => 'Active UDP : %s', + output_template => 'active UDP: %s', perfdatas => [ - { label => 'active_udp', value => 'panSessionActiveUdp_absolute', template => '%s', min => 0 }, - ], + { label => 'active_udp', value => 'panSessionActiveUdp_absolute', template => '%s', min => 0 } + ] } }, { label => 'active-icmp', nlabel => 'sessions.active.icmp.count', set => { key_values => [ { name => 'panSessionActiveICMP' } ], - output_template => 'Active ICMP : %s', + output_template => 'active ICMP: %s', perfdatas => [ - { label => 'active_icmp', value => 'panSessionActiveICMP_absolute', template => '%s', min => 0 }, - ], + { label => 'active_icmp', value => 'panSessionActiveICMP_absolute', template => '%s', min => 0 } + ] } - }, + } ]; $self->{maps_counters}->{vsys} = [ - { label => 'active-vsys', set => { - key_values => [ { name => 'panVsysActiveSessions' }, { name => 'panVsysMaxSessions' }, { name => 'display' } ], - closure_custom_calc => $self->can('custom_active_calc'), + { label => 'vsys-active', nlabel => 'vsys.sessions.active.count', set => { + key_values => [ { name => 'sessions_active' }, { name => 'sessions_max' }, { name => 'display' } ], closure_custom_output => $self->can('custom_active_output'), - closure_custom_perfdata => $self->can('custom_active_perfdata'), - closure_custom_threshold_check => $self->can('custom_active_threshold'), - + closure_custom_perfdata => $self->can('custom_vsys_active_perfdata') + } + }, + { label => 'vsys-active-prct', nlabel => 'vsys.sessions.active.percentage', display_ok => 0, set => { + key_values => [ { name => 'sessions_active_prct' } ], + output_template => 'active: %.2f %%', + perfdatas => [ + { label => 'active_prct', value => 'sessions_active_prct_absolute', template => '%.2f', unit => '%', + min => 0, max => 100 } + ] } }, { label => 'vsys-active-tcp', nlabel => 'vsys.sessions.active.tcp.count', set => { key_values => [ { name => 'panVsysActiveTcpCps' }, { name => 'display' } ], - output_template => 'Active TCP : %s', + output_template => 'active TCP: %s', perfdatas => [ { label => 'active_tcp', value => 'panVsysActiveTcpCps_absolute', template => '%s', - label_extra_instance => 1, instance_use => 'display_absolute', min => 0 }, - ], + label_extra_instance => 1, min => 0 } + ] } }, { label => 'vsys-active-udp', nlabel => 'vsys.sessions.active.udp.count', set => { key_values => [ { name => 'panVsysActiveUdpCps' }, { name => 'display' } ], - output_template => 'Active UDP : %s', + output_template => 'active UDP: %s', perfdatas => [ { label => 'active_udp', value => 'panVsysActiveUdpCps_absolute', template => '%s', - label_extra_instance => 1, instance_use => 'display_absolute', min => 0 }, - ], + label_extra_instance => 1, min => 0 } + ] } }, { label => 'vsys-active-other', nlabel => 'vsys.sessions.active.other.count', set => { @@ -110,14 +151,11 @@ sub set_counters { output_template => 'Other : %s', perfdatas => [ { label => 'active_other', value => 'panVsysActiveOtherIpCps_absolute', template => '%s', - label_extra_instance => 1, instance_use => 'display_absolute', min => 0 }, - ], + label_extra_instance => 1, min => 0 } + ] } - }, + } ]; - - - } sub prefix_global_output { @@ -129,102 +167,7 @@ sub prefix_global_output { sub prefix_vsys_output { my ($self, %options) = @_; - return "Vsys '" . $options{instance_value}->{display} . "' "; - -} - -sub custom_active_perfdata { - my ($self, %options) = @_; - - my %total_options = (); - - if ($self->{label} eq 'active') { - if ($self->{result_values}->{panSessionMax} != 0) { - $total_options{total} = $self->{result_values}->{panSessionMax}; - $total_options{cast_int} = 1; - } - - $self->{output}->perfdata_add(label => $self->{label}, - nlabel => 'sessions.active.count', - value => $self->{result_values}->{panSessionActive}, - warning => defined($total_options{total}) ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options) : undef, - critical => defined($total_options{total}) ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options) : undef, - min => 0, max => $self->{result_values}->{panSessionMax}); - } else { - if ($self->{result_values}->{panVsysMaxSessions} != 0) { - $total_options{total} = $self->{result_values}->{panVsysMaxSessions}; - $total_options{cast_int} = 1; - } - - $self->{output}->perfdata_add(label => $self->{label}, - nlabel => $self->{result_values}->{display} . "#" . 'sessions.active.count', - value => $self->{result_values}->{panVsysActiveSessions}, - warning => defined($total_options{total}) ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options) : undef, - critical => defined($total_options{total}) ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options) : undef, - min => 0, max => $self->{result_values}->{panVsysMaxSessions}); - } -} - -sub custom_active_threshold { - my ($self, %options) = @_; - - my ($exit, $threshold_value) = ('ok'); - - if ($self->{label} eq 'active') { - if ($self->{result_values}->{panSessionMax} != 0) { - $threshold_value = $self->{result_values}->{active_prct}; - } - $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => - [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]) if (defined($threshold_value)); - return $exit; - } else { - if ($self->{result_values}->{panVsysMaxSessions} != 0) { - $threshold_value = $self->{result_values}->{active_prct}; - } - $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => - [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]) if (defined($threshold_value)); - return $exit; - } -} - -sub custom_active_output { - my ($self, %options) = @_; - - my $msg = ""; - if ($self->{label} eq 'active') { - $msg = sprintf("Active : %s (%s)", - $self->{result_values}->{panSessionActive}, - $self->{result_values}->{panSessionMax} != 0 ? $self->{result_values}->{active_prct} . " %" : - '-'); - } else { - $msg = sprintf("Active : %s (%s)", - $self->{result_values}->{panVsysActiveSessions}, - $self->{result_values}->{panVsysMaxSessions} != 0 ? $self->{result_values}->{active_prct} . " %" : - '-'); - } - return $msg; -} - -sub custom_active_calc { - my ($self, %options) = @_; - - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - $self->{result_values}->{panSessionActive} = $options{new_datas}->{$self->{instance} . '_panSessionActive'}; - $self->{result_values}->{panSessionMax} = $options{new_datas}->{$self->{instance} . '_panSessionMax'}; - $self->{result_values}->{panVsysActiveSessions} = $options{new_datas}->{$self->{instance} . '_panVsysActiveSessions'}; - $self->{result_values}->{panVsysMaxSessions} = $options{new_datas}->{$self->{instance} . '_panVsysMaxSessions'}; - $self->{result_values}->{active_prct} = 0; - - if ($self->{label} eq 'active') { - if ($self->{result_values}->{panSessionMax} != 0) { - $self->{result_values}->{active_prct} = $self->{result_values}->{panSessionActive} * 100 / $self->{result_values}->{panSessionMax}; - } - } else { - if ($self->{result_values}->{panVsysMaxSessions} != 0) { - $self->{result_values}->{active_prct} = $self->{result_values}->{panVsysActiveSessions} * 100 / $self->{result_values}->{panVsysMaxSessions}; - } - } - return 0; + return "Vsys '" . $options{instance_value}->{display} . "' sessions "; } sub new { @@ -233,7 +176,7 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'add-vsys' => { name => 'add_vsys' }, + 'add-vsys' => { name => 'add_vsys' }, }); return $self; @@ -241,56 +184,54 @@ sub new { my $mapping_sessions = { - panSessionMax => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.2' }, - panSessionActive => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.3' }, - panSessionActiveTcp => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.4' }, - panSessionActiveUdp => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.5' }, - panSessionActiveICMP => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.6' }, - #panSessionActiveSslProxy => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.7' }, Cannot get the max if 0... - panSessionSslProxyUtilization => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.8' }, + sessions_max => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.2' }, # panSessionMax + sessions_active => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.3' }, # panSessionActive + panSessionActiveTcp => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.4' }, + panSessionActiveUdp => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.5' }, + panSessionActiveICMP => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.6' }, + panSessionSslProxyUtilization => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.8' } }; - my $mapping_vsys = { - panVsysName => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.2' }, - panVsysActiveSessions => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.4' }, - panVsysMaxSessions => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.5' }, - panVsysActiveTcpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.6' }, - panVsysActiveUdpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.7' }, - panVsysActiveOtherIpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.8' }, + display => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.2' }, # panVsysName + sessions_active => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.4' }, # panVsysActiveSessions + sessions_max => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.5' }, # panVsysMaxSessions + panVsysActiveTcpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.6' }, + panVsysActiveUdpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.7' }, + panVsysActiveOtherIpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.8' } }; sub add_vsys { my ($self, %options) = @_; my $oid_panVsysEntry = '.1.3.6.1.4.1.25461.2.1.2.3.9.1'; - $self->{results} = $options{snmp}->get_table(oid => $oid_panVsysEntry, - nothing_quit => 1); + my $snmp_result = $options{snmp}->get_table( + oid => $oid_panVsysEntry, + nothing_quit => 1 + ); - foreach my $oid (keys %{$self->{results}}) { + foreach my $oid (keys %$snmp_result) { next if $oid !~ /^$mapping_vsys->{panVsysName}->{oid}\.(.*)$/; my $instance = $1; - my $result = $options{snmp}->map_instance(mapping => $mapping_vsys, results => $self->{results}, instance => $instance); - - $self->{vsys}->{$result->{panVsysName}} = { - display => $result->{panVsysName}, - panVsysMaxSessions => defined($result->{panVsysMaxSessions}) ? $result->{panVsysMaxSessions} : 0, - panVsysActiveSessions => $result->{panVsysActiveSessions}, - panVsysActiveTcpCps => $result->{panVsysActiveTcpCps}, - panVsysActiveUdpCps => $result->{panVsysActiveUdpCps}, - }; - + my $result = $options{snmp}->map_instance(mapping => $mapping_vsys, results => $snmp_result, instance => $instance); + $self->{vsys}->{$result->{display}} = $result; + $self->{vsys}->{$result->{display}}->{sessions_max} = 0 if (!defined($result->{sessions_max})); + $self->{vsys}->{$result->{display}}->{sessions_active_prct} = $result->{sessions_active} * 100 / $self->{vsys}->{$result->{display}}->{sessions_max} + if ($self->{vsys}->{$result->{display}}->{sessions_max} != 0); } } sub manage_selection { my ($self, %options) = @_; - my $oid_panSession = '.1.3.6.1.4.1.25461.2.1.2.3'; - $self->{results} = $options{snmp}->get_table(oid => $oid_panSession, - nothing_quit => 1); - $self->{global} = $options{snmp}->map_instance(mapping => $mapping_sessions, results => $self->{results}, instance => '0'); - $self->{global}->{panSessionMax} = 0 if (!defined($self->{global}->{panSessionMax})); + my $snmp_result = $options{snmp}->get_leef( + oids => [ map($_->{oid} . '.0', values(%$mapping_sessions)) ], + nothing_quit => 1 + ); + $self->{global} = $options{snmp}->map_instance(mapping => $mapping_sessions, results => $snmp_result, instance => '0'); + $self->{global}->{sessions_max} = 0 if (!defined($self->{global}->{sessions_max})); + $self->{global}->{sessions_active_prct} = $self->{global}->{sessions_active} * 100 / $self->{global}->{sessions_max} + if ($self->{global}->{sessions_max} != 0); $self->add_vsys(snmp => $options{snmp}) if (defined($self->{option_results}->{add_vsys})); @@ -306,17 +247,11 @@ Check sessions. =over 8 -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. -Global: 'active' (%), 'active-tcp', 'active-udp', 'active-icmp', 'active-ssl-proxy' (%). -Per vsys: 'active-vsys' (%), 'vsys-active-tcp' 'vsys-active-udp' 'vsys-active-other' - -=item B<--critical-*> - -Threshold critical. -Global: 'active' (%), 'active-tcp', 'active-udp', 'active-icmp', 'active-ssl-proxy' (%). -Per vsys: 'active-vsys' (%), 'vsys-active-tcp' 'vsys-active-udp' 'vsys-active-other' +Thresholds. +Global: 'active', 'active-prct', (%), 'active-tcp', 'active-udp', 'active-icmp', +Per vsys: 'vsys-active', 'vsys-active-prct' (%), 'vsys-active-tcp' 'vsys-active-udp' 'vsys-active-other'. =back From 30c166439c197d230dd5d13d819ffefb83a1cc3a Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 27 Mar 2020 13:00:19 +0100 Subject: [PATCH 021/190] fix palo alto sessions --- centreon-plugins/network/paloalto/snmp/mode/sessions.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/network/paloalto/snmp/mode/sessions.pm b/centreon-plugins/network/paloalto/snmp/mode/sessions.pm index 9234c9e9b..157130103 100644 --- a/centreon-plugins/network/paloalto/snmp/mode/sessions.pm +++ b/centreon-plugins/network/paloalto/snmp/mode/sessions.pm @@ -210,7 +210,7 @@ sub add_vsys { ); foreach my $oid (keys %$snmp_result) { - next if $oid !~ /^$mapping_vsys->{panVsysName}->{oid}\.(.*)$/; + next if ($oid !~ /^$mapping_vsys->{display}->{oid}\.(.*)$/); my $instance = $1; my $result = $options{snmp}->map_instance(mapping => $mapping_vsys, results => $snmp_result, instance => $instance); From 1e6a7db21f7014ab382099a988abb0b44a5e5113 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 27 Mar 2020 13:01:03 +0100 Subject: [PATCH 022/190] fix palo alto sessions --- centreon-plugins/network/paloalto/snmp/mode/sessions.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/network/paloalto/snmp/mode/sessions.pm b/centreon-plugins/network/paloalto/snmp/mode/sessions.pm index 157130103..78567fd68 100644 --- a/centreon-plugins/network/paloalto/snmp/mode/sessions.pm +++ b/centreon-plugins/network/paloalto/snmp/mode/sessions.pm @@ -148,7 +148,7 @@ sub set_counters { }, { label => 'vsys-active-other', nlabel => 'vsys.sessions.active.other.count', set => { key_values => [ { name => 'panVsysActiveOtherIpCps' }, { name => 'display' } ], - output_template => 'Other : %s', + output_template => 'other: %s', perfdatas => [ { label => 'active_other', value => 'panVsysActiveOtherIpCps_absolute', template => '%s', label_extra_instance => 1, min => 0 } From 4b9af8e8f8c734f19171fc23f9f78a5914fa6707 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 27 Mar 2020 15:10:40 +0100 Subject: [PATCH 023/190] typo + Fix #1894 --- .../database/mongodb/custom/driver.pm | 25 +++++------ .../mongodb/mode/collectionstatistics.pm | 13 +++--- .../database/mongodb/mode/connections.pm | 8 ++-- .../database/mongodb/mode/connectiontime.pm | 8 ++-- .../mongodb/mode/databasestatistics.pm | 15 +++---- .../database/mongodb/mode/queries.pm | 17 ++++---- .../mongodb/mode/replicationstatus.pm | 41 +++++++++---------- 7 files changed, 56 insertions(+), 71 deletions(-) diff --git a/centreon-plugins/database/mongodb/custom/driver.pm b/centreon-plugins/database/mongodb/custom/driver.pm index 1db7e0fe5..bb7306021 100644 --- a/centreon-plugins/database/mongodb/custom/driver.pm +++ b/centreon-plugins/database/mongodb/custom/driver.pm @@ -40,23 +40,24 @@ sub new { $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 => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port' }, - "protocol:s" => { name => 'protocol' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout' }, - "ssl-opt:s@" => { name => 'ssl_opt' }, + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port' }, + 'protocol:s' => { name => 'protocol' }, + 'username:s' => { name => 'username' }, + 'password:s' => { name => 'password' }, + 'timeout:s' => { name => 'timeout' }, + 'ssl-opt:s@' => { name => 'ssl_opt' }, }); } + $options{options}->add_help(package => __PACKAGE__, sections => 'DRIVER OPTIONS', once => 1); $self->{output} = $options{output}; $self->{mode} = $options{mode}; - + return $self; } @@ -127,10 +128,10 @@ sub connect { $uri = $self->{protocol} . '://'; $uri .= $encoded_username . ':' . $encoded_password . '@' if ($encoded_username ne '' && $encoded_password ne ''); $uri .= $self->{hostname} if ($self->{hostname} ne ''); - $uri .= ':' . $self->{port} if ($self->{port} ne ''); + $uri .= ':' . $self->{port} if ($self->{port} ne '' && $self->{protocol} eq 'mongodb+srv'); $self->{output}->output_add(long_msg => 'Connection URI: ' . $uri, debug => 1); - + my $ssl = (defined($self->{ssl_opts})) ? $self->{ssl_opts} : 0; $self->{client} = MongoDB::MongoClient->new(host => $uri, ssl => $ssl); $self->{client}->connect(); @@ -163,7 +164,7 @@ sub run_command { if (!defined($self->{client})) { $self->connect(); } - + my $db = $self->{client}->get_database($options{database}); return $db->run_command($options{command}); } diff --git a/centreon-plugins/database/mongodb/mode/collectionstatistics.pm b/centreon-plugins/database/mongodb/mode/collectionstatistics.pm index 6001ba28a..7f6e54d7f 100644 --- a/centreon-plugins/database/mongodb/mode/collectionstatistics.pm +++ b/centreon-plugins/database/mongodb/mode/collectionstatistics.pm @@ -105,25 +105,22 @@ sub new { sub manage_selection { my ($self, %options) = @_; - - $self->{custom} = $options{custom}; + + my $databases = $options{custom}->list_databases(); $self->{databases} = {}; - - my $databases = $self->{custom}->list_databases(); - foreach my $database (sort @{$databases}) { next if (defined($self->{option_results}->{filter_database}) && $self->{option_results}->{filter_database} ne '' && $database !~ /$self->{option_results}->{filter_database}/); - my $collections = $self->{custom}->list_collections(database => $database); + my $collections = $options{custom}->list_collections(database => $database); $self->{databases}->{$database}->{display} = $database; foreach my $collection (sort @{$collections}) { - my $cl_stats = $self->{custom}->run_command( + my $cl_stats = $options{custom}->run_command( database => $database, - command => $self->{custom}->ordered_hash(collStats => $collection), + command => $options{custom}->ordered_hash(collStats => $collection), ); $self->{databases}->{$database}->{collections}->{$collection} = { diff --git a/centreon-plugins/database/mongodb/mode/connections.pm b/centreon-plugins/database/mongodb/mode/connections.pm index 82b07960c..54fd88821 100644 --- a/centreon-plugins/database/mongodb/mode/connections.pm +++ b/centreon-plugins/database/mongodb/mode/connections.pm @@ -88,14 +88,12 @@ sub new { sub manage_selection { my ($self, %options) = @_; - - $self->{custom} = $options{custom}; $self->{global} = {}; - my $server_stats = $self->{custom}->run_command( + my $server_stats = $options{custom}->run_command( database => 'admin', - command => $self->{custom}->ordered_hash(serverStatus => 1), + command => $options{custom}->ordered_hash(serverStatus => 1), ); $self->{global}->{active} = $server_stats->{connections}->{active}; @@ -103,7 +101,7 @@ sub manage_selection { $self->{global}->{usage} = $server_stats->{connections}->{current} / ($server_stats->{connections}->{current} + $server_stats->{connections}->{available}); $self->{global}->{totalCreated} = $server_stats->{connections}->{totalCreated}; - $self->{cache_name} = "mongodb_" . $self->{mode} . '_' . $self->{custom}->get_hostname() . '_' . $self->{custom}->get_port() . '_' . + $self->{cache_name} = "mongodb_" . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . $options{custom}->get_port() . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); } diff --git a/centreon-plugins/database/mongodb/mode/connectiontime.pm b/centreon-plugins/database/mongodb/mode/connectiontime.pm index c291fffe6..fd3dee309 100644 --- a/centreon-plugins/database/mongodb/mode/connectiontime.pm +++ b/centreon-plugins/database/mongodb/mode/connectiontime.pm @@ -50,7 +50,7 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - + $options{options}->add_options(arguments => {}); return $self; @@ -58,13 +58,11 @@ sub new { sub manage_selection { my ($self, %options) = @_; - - $self->{custom} = $options{custom}; my $start = Time::HiRes::time(); - $self->{custom}->connect(); + $options{custom}->connect(); my $end = Time::HiRes::time(); - + $self->{global}->{connection_time} = ($end - $start) * 1000; } diff --git a/centreon-plugins/database/mongodb/mode/databasestatistics.pm b/centreon-plugins/database/mongodb/mode/databasestatistics.pm index 9a7a18e68..fd10ea8f7 100644 --- a/centreon-plugins/database/mongodb/mode/databasestatistics.pm +++ b/centreon-plugins/database/mongodb/mode/databasestatistics.pm @@ -115,29 +115,26 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-database:s" => { name => 'filter_database' }, + 'filter-database:s' => { name => 'filter_database' } }); return $self; } sub manage_selection { my ($self, %options) = @_; - - $self->{custom} = $options{custom}; + + my $databases = $options{custom}->list_databases(); $self->{databases} = {}; - - my $databases = $self->{custom}->list_databases(); - foreach my $database (sort @{$databases}) { next if (defined($self->{option_results}->{filter_database}) && $self->{option_results}->{filter_database} ne '' && $database !~ /$self->{option_results}->{filter_database}/); - my $db_stats = $self->{custom}->run_command( + my $db_stats = $options{custom}->run_command( database => $database, - command => $self->{custom}->ordered_hash('dbStats' => 1), + command => $options{custom}->ordered_hash(dbStats => 1), ); - + $self->{databases}->{$db_stats->{db}} = { display => $db_stats->{db}, collections => $db_stats->{collections}, diff --git a/centreon-plugins/database/mongodb/mode/queries.pm b/centreon-plugins/database/mongodb/mode/queries.pm index 125339420..fea4d56c0 100644 --- a/centreon-plugins/database/mongodb/mode/queries.pm +++ b/centreon-plugins/database/mongodb/mode/queries.pm @@ -28,11 +28,11 @@ use Digest::MD5 qw(md5_hex); sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'global', type => 0, cb_prefix_output => 'prefix_output' }, ]; - + $self->{maps_counters}->{global} = [ { label => 'total', nlabel => 'queries.total.persecond', set => { key_values => [ { name => 'total', diff => 1 } ], @@ -44,7 +44,7 @@ sub set_counters { } }, ]; - + foreach ('insert', 'query', 'update', 'delete', 'getmore', 'command') { push @{$self->{maps_counters}->{global}}, { label => $_, nlabel => 'queries.' . $_ . '.persecond', display_ok => 0, set => { @@ -71,7 +71,7 @@ sub set_counters { sub prefix_output { my ($self, %options) = @_; - return "Requests "; + return 'Requests '; } sub new { @@ -86,14 +86,11 @@ sub new { sub manage_selection { my ($self, %options) = @_; - - $self->{custom} = $options{custom}; $self->{global} = {}; - - my $server_stats = $self->{custom}->run_command( + my $server_stats = $options{custom}->run_command( database => 'admin', - command => $self->{custom}->ordered_hash(serverStatus => 1), + command => $options{custom}->ordered_hash(serverStatus => 1), ); foreach my $querie (keys %{$server_stats->{opcounters}}) { @@ -101,7 +98,7 @@ sub manage_selection { $self->{global}->{total} += $server_stats->{opcounters}->{$querie}; } - $self->{cache_name} = "mongodb_" . $self->{mode} . '_' . $self->{custom}->get_hostname() . '_' . $self->{custom}->get_port() . '_' . + $self->{cache_name} = 'mongodb_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . $options{custom}->get_port() . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); } diff --git a/centreon-plugins/database/mongodb/mode/replicationstatus.pm b/centreon-plugins/database/mongodb/mode/replicationstatus.pm index 358bc7480..03ae69a14 100644 --- a/centreon-plugins/database/mongodb/mode/replicationstatus.pm +++ b/centreon-plugins/database/mongodb/mode/replicationstatus.pm @@ -41,7 +41,6 @@ sub custom_status_output { my $msg = sprintf("Current member state is '%s'", $self->{result_values}->{state}); $msg .= sprintf(", syncing to '%s'", $self->{result_values}->{sync_host}) if ($self->{result_values}->{state} ne 'PRIMARY'); - return $msg; } @@ -50,20 +49,18 @@ sub custom_status_calc { $self->{result_values}->{state} = $mapping_states{$options{new_datas}->{$self->{instance} . '_myState'}}; $self->{result_values}->{sync_host} = $options{new_datas}->{$self->{instance} . '_syncSourceHost'}; - return 0; } sub custom_member_status_output { my ($self, %options) = @_; - my $msg = sprintf("state is '%s' and health is '%s' [slave delay: %s] [priority: %s]", + return sprintf("state is '%s' and health is '%s' [slave delay: %s] [priority: %s]", $self->{result_values}->{state}, $self->{result_values}->{health}, $self->{result_values}->{slave_delay}, - $self->{result_values}->{priority}); - - return $msg; + $self->{result_values}->{priority} + ); } sub custom_member_status_calc { @@ -131,11 +128,12 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, - "warning-member-status:s" => { name => 'warning_member_status', default => '%{state} !~ /PRIMARY|SECONDARY/' }, - "critical-member-status:s" => { name => 'critical_member_status', default => '%{health} !~ /up/' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, + 'warning-member-status:s' => { name => 'warning_member_status', default => '%{state} !~ /PRIMARY|SECONDARY/' }, + 'critical-member-status:s' => { name => 'critical_member_status', default => '%{health} !~ /up/' }, }); + return $self; } @@ -143,18 +141,18 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $self->change_macros(macros => ['warning_status', 'critical_status', - 'warning_member_status', 'critical_member_status']); + $self->change_macros(macros => [ + 'warning_status', 'critical_status', + 'warning_member_status', 'critical_member_status' + ]); } sub manage_selection { my ($self, %options) = @_; - - $self->{custom} = $options{custom}; - my $ismaster = $self->{custom}->run_command( + my $ismaster = $options{custom}->run_command( database => 'admin', - command => $self->{custom}->ordered_hash('ismaster' => 1), + command => $options{custom}->ordered_hash(ismaster => 1), ); if (!defined($ismaster->{me})) { @@ -164,10 +162,9 @@ sub manage_selection { $self->{global} = {}; $self->{members} = {}; - - my $repl_conf = $self->{custom}->run_command( + my $repl_conf = $options{custom}->run_command( database => 'admin', - command => $self->{custom}->ordered_hash('replSetGetConfig' => 1), + command => $options{custom}->ordered_hash(replSetGetConfig => 1), ); my %config; @@ -175,9 +172,9 @@ sub manage_selection { $config{$member->{host}} = { priority => $member->{priority}, slaveDelay => $member->{slaveDelay} } } - my $repl_status = $self->{custom}->run_command( + my $repl_status = $options{custom}->run_command( database => 'admin', - command => $self->{custom}->ordered_hash('replSetGetStatus' => 1), + command => $options{custom}->ordered_hash(replSetGetStatus => 1), ); $self->{global}->{myState} = $repl_status->{myState}; @@ -191,7 +188,7 @@ sub manage_selection { health => $member->{health}, optimeDate => $member->{optime}->{ts}->{seconds}, slaveDelay => $config{$member->{name}}->{slaveDelay}, - priority => $config{$member->{name}}->{priority}, + priority => $config{$member->{name}}->{priority} } } From 2b1ec1614c92fd6aa16de19d8aecb62fc5446931 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 27 Mar 2020 15:11:08 +0100 Subject: [PATCH 024/190] Fix #1894 --- centreon-plugins/database/mongodb/custom/driver.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/database/mongodb/custom/driver.pm b/centreon-plugins/database/mongodb/custom/driver.pm index bb7306021..cc9016c84 100644 --- a/centreon-plugins/database/mongodb/custom/driver.pm +++ b/centreon-plugins/database/mongodb/custom/driver.pm @@ -128,7 +128,7 @@ sub connect { $uri = $self->{protocol} . '://'; $uri .= $encoded_username . ':' . $encoded_password . '@' if ($encoded_username ne '' && $encoded_password ne ''); $uri .= $self->{hostname} if ($self->{hostname} ne ''); - $uri .= ':' . $self->{port} if ($self->{port} ne '' && $self->{protocol} eq 'mongodb+srv'); + $uri .= ':' . $self->{port} if ($self->{port} ne '' && $self->{protocol} ne 'mongodb+srv'); $self->{output}->output_add(long_msg => 'Connection URI: ' . $uri, debug => 1); From fd0434513bbf2c27e3c8671b2fb7d7d9f61527a0 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 27 Mar 2020 15:42:15 +0100 Subject: [PATCH 025/190] Fix #1885 --- .../network/paloalto/ssh/mode/system.pm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/centreon-plugins/network/paloalto/ssh/mode/system.pm b/centreon-plugins/network/paloalto/ssh/mode/system.pm index 0b72030b2..2cc828ac1 100644 --- a/centreon-plugins/network/paloalto/ssh/mode/system.pm +++ b/centreon-plugins/network/paloalto/ssh/mode/system.pm @@ -117,6 +117,7 @@ sub new { $options{options}->add_options(arguments => { 'warning-status:s' => { name => 'warning_status', default => '' }, 'critical-status:s' => { name => 'critical_status', default => '%{oper_mode} !~ /normal/i' }, + 'timezone:s' => { name => 'timezone' } }); return $self; @@ -127,6 +128,7 @@ sub check_options { $self->SUPER::check_options(%options); $self->change_macros(macros => ['warning_status', 'critical_status']); + $self->{option_results}->{timezone} = 'GMT' if (!defined($self->{option_results}->{timezone}) || $self->{option_results}->{timezone} eq ''); } sub get_diff_time { @@ -135,10 +137,7 @@ sub get_diff_time { # '2019/10/15 12:03:58 BST' return if ($options{time} !~ /^\s*(\d{4})\/(\d{2})\/(\d{2})\s+(\d+):(\d+):(\d+)\s+(\S+)/); - my $tz = $7; - $tz = 'GMT' if ($tz eq 'BST'); - $tz = 'Europe/Paris' if ($tz eq 'CEST'); - $tz = 'America/New_York' if ($tz eq 'EST'); + my $tz = centreon::plugins::misc::set_timezone(name => $self->{option_results}->{timezone}); my $dt = DateTime->new( year => $1, month => $2, @@ -146,7 +145,7 @@ sub get_diff_time { hour => $4, minute => $5, second => $6, - time_zone => $tz + %$tz ); return (time() - $dt->epoch); } @@ -198,6 +197,10 @@ Check system. Only display some counters (regexp can be used). Example: --filter-counters='^status$' +=item B<--timezone> + +Timezone options. Default is 'GMT'. + =item B<--warning-status> Set warning threshold for status (Default: ''). From f91c1df709ba57092f9284c4b7d314680ca3d5fa Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 27 Mar 2020 15:54:59 +0100 Subject: [PATCH 026/190] fix synology ha --- centreon-plugins/storage/synology/snmp/mode/ha.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/storage/synology/snmp/mode/ha.pm b/centreon-plugins/storage/synology/snmp/mode/ha.pm index 799a0ae92..5987e5b6b 100644 --- a/centreon-plugins/storage/synology/snmp/mode/ha.pm +++ b/centreon-plugins/storage/synology/snmp/mode/ha.pm @@ -51,7 +51,7 @@ sub set_counters { { name => 'cluster_status' }, { name => 'heartbeat_status' }, { name => 'active_node_name' }, { name => 'passive_node_name' } ], - closure_custom_calc => \&catalog_status_threshold, + closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, closure_custom_threshold_check => \&catalog_status_threshold From 05f7536d4753d944c34509f45112757762fd16f8 Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Sat, 28 Mar 2020 14:43:00 +0100 Subject: [PATCH 027/190] MikroTik, add proper disk mode --- .../network/mikrotik/snmp/mode/disk.pm | 104 ++++++++++++++++++ .../network/mikrotik/snmp/mode/memory.pm | 4 +- .../network/mikrotik/snmp/plugin.pm | 1 + 3 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 centreon-plugins/network/mikrotik/snmp/mode/disk.pm diff --git a/centreon-plugins/network/mikrotik/snmp/mode/disk.pm b/centreon-plugins/network/mikrotik/snmp/mode/disk.pm new file mode 100644 index 000000000..edbd7e6a0 --- /dev/null +++ b/centreon-plugins/network/mikrotik/snmp/mode/disk.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 network::mikrotik::snmp::mode::disk; + +use base qw(snmp_standard::mode::storage); + +use strict; +use warnings; + +sub default_storage_type { + my ($self, %options) = @_; + + return '^(?!(hrStorageRam)$)'; +} + +sub prefix_storage_output { + my ($self, %options) = @_; + + return "Disk '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check memory. + +=over 8 + +=item B<--warning-usage> + +Threshold warning. + +=item B<--critical-usage> + +Threshold critical. + +=item B<--units> + +Units of thresholds (Default: '%') ('%', 'B'). + +=item B<--free> + +Thresholds are on free space left. + +=item B<--storage> + +Set the storage (number expected) ex: 1, 2,... (empty means 'check all storage'). + +=item B<--name> + +Allows to use storage name with option --storage instead of storage oid index. + +=item B<--regexp> + +Allows to use regexp to filter storage (with option --name). + +=item B<--regexp-isensitive> + +Allows to use regexp non case-sensitive (with --regexp). + +=item B<--reload-cache-time> + +Time in minutes before reloading cache file (default: 180). + +=item B<--show-cache> + +Display cache storage datas. + +=item B<--filter-storage-type> + +Filter storage types with a regexp (Default: '^(?!(hrStorageRam)$)'). + +=back + +=cut diff --git a/centreon-plugins/network/mikrotik/snmp/mode/memory.pm b/centreon-plugins/network/mikrotik/snmp/mode/memory.pm index dc451ef33..fccdc8808 100644 --- a/centreon-plugins/network/mikrotik/snmp/mode/memory.pm +++ b/centreon-plugins/network/mikrotik/snmp/mode/memory.pm @@ -28,7 +28,7 @@ use warnings; sub default_storage_type { my ($self, %options) = @_; - return '^(hrStorageRam|hrStorageFlashMemory)'; + return '^hrStorageRam$'; } sub prefix_storage_output { @@ -97,7 +97,7 @@ Display cache storage datas. =item B<--filter-storage-type> -Filter storage types with a regexp (Default: '^(hrStorageRam|hrStorageFlashMemory)$'). +Filter storage types with a regexp (Default: '^hrStorageRam$'). =back diff --git a/centreon-plugins/network/mikrotik/snmp/plugin.pm b/centreon-plugins/network/mikrotik/snmp/plugin.pm index b45557fa1..d79b3eb55 100644 --- a/centreon-plugins/network/mikrotik/snmp/plugin.pm +++ b/centreon-plugins/network/mikrotik/snmp/plugin.pm @@ -32,6 +32,7 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( 'cpu' => 'snmp_standard::mode::cpu', + 'disk' => 'network::mikrotik::snmp::mode::disk', 'environment' => 'network::mikrotik::snmp::mode::environment', 'interfaces' => 'network::mikrotik::snmp::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', From d50714acffba19470039bd70d543a9f9afeff482 Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Sat, 28 Mar 2020 14:50:33 +0100 Subject: [PATCH 028/190] Typo --- centreon-plugins/network/mikrotik/snmp/mode/disk.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/network/mikrotik/snmp/mode/disk.pm b/centreon-plugins/network/mikrotik/snmp/mode/disk.pm index edbd7e6a0..da39790de 100644 --- a/centreon-plugins/network/mikrotik/snmp/mode/disk.pm +++ b/centreon-plugins/network/mikrotik/snmp/mode/disk.pm @@ -51,7 +51,7 @@ __END__ =head1 MODE -Check memory. +Check disk. =over 8 From f326c1e44b78a5d5e0a656ff1cec1244aeead2f8 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 30 Mar 2020 16:03:22 +0200 Subject: [PATCH 029/190] add wan3g cisco standard snmp mode --- .../common/cisco/standard/snmp/mode/wan3g.pm | 439 ++++++++++++++++++ .../network/cisco/standard/snmp/plugin.pm | 35 +- 2 files changed, 457 insertions(+), 17 deletions(-) create mode 100644 centreon-plugins/centreon/common/cisco/standard/snmp/mode/wan3g.pm diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/wan3g.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/wan3g.pm new file mode 100644 index 000000000..15d8b8d34 --- /dev/null +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/wan3g.pm @@ -0,0 +1,439 @@ +# +# 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 centreon::common::cisco::standard::snmp::mode::wan3g; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use Digest::MD5 qw(md5_hex); + +sub custom_connection_status_output { + my ($self, %options) = @_; + + return sprintf( + 'connection status: %s', + $self->{result_values}->{connection_status} + ); +} + +sub custom_sim_status_output { + my ($self, %options) = @_; + + return sprintf( + 'sim status: %s', + $self->{result_values}->{sim_status} + ); +} + +sub custom_modem_status_output { + my ($self, %options) = @_; + + return sprintf( + 'modem status: %s', + $self->{result_values}->{modem_status} + ); +} + +sub custom_radio_status_output { + my ($self, %options) = @_; + + return sprintf( + 'current band: %s [channel number: %s]', + $self->{result_values}->{current_band}, + $self->{result_values}->{channel_number} + ); +} + +sub custom_network_status_output { + my ($self, %options) = @_; + + return sprintf( + 'service status: %s', + $self->{result_values}->{service_status} + ); +} + + +sub modem_long_output { + my ($self, %options) = @_; + + return "checking module '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_modem_output { + my ($self, %options) = @_; + + return "module '" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'modem', type => 3, cb_prefix_output => 'prefix_modem_output', cb_long_output => 'modem_long_output', + indent_long_output => ' ', message_multiple => 'All cellular modems are ok', + group => [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'radio', type => 0, skipped_code => { -10 => 1 } }, + { name => 'network', type => 0, skipped_code => { -10 => 1 } } + ] + } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'modem-status', threshold => 0, set => { + key_values => [ { name => 'modem_status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_modem_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + }, + { label => 'connection-status', threshold => 0, set => { + key_values => [ { name => 'connection_status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_connection_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + }, + { label => 'sim-status', threshold => 0, set => { + key_values => [ { name => 'sim_status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_sim_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + }, + { label => 'temperature', nlabel => 'modem.temperature.celsius', display_ok => 0, set => { + key_values => [ { name => 'temperature' }, { name => 'display' } ], + output_template => 'memory used: %s%s', + output_change_bytes => 1, + perfdatas => [ + { value => 'temperature_absolute', template => '%s', min => 0, + unit => 'C', label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + } + ]; + + $self->{maps_counters}->{radio} = [ + { label => 'radio-status', threshold => 0, set => { + key_values => [ { name => 'current_band' }, { name => 'channel_number' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_radio_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + }, + { label => 'radio-rssi', nlabel => 'modem.radio.rssi.dbm', set => { + key_values => [ { name => 'rssi' }, { name => 'display' } ], + output_template => 'received signal strength: %s dBm', + output_change_bytes => 1, + perfdatas => [ + { value => 'rssi_absolute', template => '%s', min => 0, + unit => 'dBm', label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + } + ]; + + $self->{maps_counters}->{network} = [ + { label => 'network-status', threshold => 0, set => { + key_values => [ { name => 'service_status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_network_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + }, + { label => 'traffic-in', nlabel => 'modem.traffic.in.bitspersecond', set => { + key_values => [ { name => 'traffic_in', diff => 1 }, { name => 'display' } ], + output_template => 'traffic in: %s%s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_in_per_second', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' } + ] + } + }, + { label => 'traffic-out', nlabel => 'modem.traffic.out.bitspersecond', set => { + key_values => [ { name => 'traffic_out', diff => 1 }, { name => 'display' } ], + output_template => 'traffic out: %s%s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_out_per_second', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' } + ] + } + } + ]; +} + +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-modem-status:s' => { name => 'unknown_modem_status', default => '%{modem_status} =~ /unknown/i' }, + 'warning-modem-status:s' => { name => 'warning_modem_status', default => '%{modem_status} =~ /lowPowerMode/i' }, + 'critical-modem-status:s' => { name => 'critical_modem_status', default => '%{modem_status} =~ /offLine/i' }, + 'unknown-connection-status:s' => { name => 'unknown_connection_status', default => '%{connection_status} =~ /unknown/i' }, + 'warning-connection-status:s' => { name => 'warning_connection_status', default => '' }, + 'critical-connection-status:s' => { name => 'critical_connection_status', default => '%{connection_status} =~ /inactive|idle|disconnected|error/i' }, + 'unknown-sim-status:s' => { name => 'unknown_sim_status', default => '%{sim_status} =~ /unknown/i' }, + 'warning-sim-status:s' => { name => 'warning_sim_status', default => '' }, + 'critical-sim-status:s' => { name => 'critical_sim_status', default => '%{sim_status} !~ /ok|unknown/i' }, + 'unknown-radio-status:s' => { name => 'unknown_radio_status', default => '%{current_band} =~ /unknown/i' }, + 'warning-radio-status:s' => { name => 'warning_radio_status', default => '' }, + 'critical-radio-status:s' => { name => 'critical_radio_status', default => '%{current_band} =~ /invalid|none/i' }, + 'unknown-network-status:s' => { name => 'unknown_network_status', default => '%{service_status} =~ /unknown/i' }, + 'warning-network-status:s' => { name => 'warning_network_status', default => '' }, + 'critical-network-status:s' => { name => 'critical_network_status', default => '%{service_status} =~ /emergencyOnly|noService/i' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros( + macros => [ + 'unknown_modem_status', 'warning_modem_status', 'critical_modem_status', + 'unknown_connection_status', 'warning_connection_status', 'critical_connection_status', + 'unknown_sim_status', 'warning_sim_status', 'critical_sim_status', + 'unknown_radio_status', 'warning_radio_status', 'critical_radio_status', + 'unknown_network_status', 'warning_network_status', 'critical_network_status', + ] + ); +} + +my $map_current_band = { + 1 => 'unknown', 2 => 'invalid', 3 => 'none', + 4 => 'gsm850', 5 => 'gsm900', 6 => 'gsm1800', + 7 => 'gsm1900', 8 => 'wcdma800', 9 => 'wcdma850', + 10 => 'wcdma1900', 11 => 'wcdma2100', 12 => 'lteBand' +}; +my $map_modem_status = { + 1 => 'unknown', 2 => 'offLine', 3 => 'onLine', 4 => 'lowPowerMode' +}; +my $map_connection_status = { + 1 => 'unknown', 2 => 'error', 3 => 'connecting', + 4 => 'dormant', 5 => 'connected', 6 => 'disconnected', + 7 => 'idle', 8 => 'active', 9 => 'inactive' +}; +my $map_sim_status = { + 1 => 'unknown', 2 => 'ok', 3 => 'notInserted', + 4 => 'removed', 5 => 'initFailure', 6 => 'generalFailure', + 7 => 'locked', 8 => 'chv1Blocked', 9 => 'chv2Blocked', + 10 => 'chv1Rejected', 11 => 'chv2Rejected', + 12 => 'mepLocked', 13 => 'networkRejected' +}; +my $map_service_status = { + 1 => 'unknown', 2 => 'noService', + 3 => 'normal', 4 => 'emergencyOnly' +}; + +my $mapping = { + rssi => { oid => '.1.3.6.1.4.1.9.9.661.1.3.4.1.1.1' }, # c3gCurrentGsmRssi + current_band => { oid => '.1.3.6.1.4.1.9.9.661.1.3.4.1.1.3', map => $map_current_band }, # c3gGsmCurrentBand + channel_number => { oid => '.1.3.6.1.4.1.9.9.661.1.3.4.1.1.4' }, # c3gGsmChannelNumber + modem_status => { oid => '.1.3.6.1.4.1.9.9.661.1.3.1.1.6', map => $map_modem_status }, # c3gModemStatus + temperature => { oid => '.1.3.6.1.4.1.9.9.661.1.1.1.12' }, # c3gModemTemperature + connection_status => { oid => '.1.3.6.1.4.1.9.9.661.1.3.1.1.6', map => $map_connection_status }, # c3gConnectionStatus + sim_status => { oid => '.1.3.6.1.4.1.9.9.661.1.3.5.1.1.2', map => $map_sim_status }, # c3gGsmSimStatus + service_status => { oid => '.1.3.6.1.4.1.9.9.661.1.3.2.1.2', map => $map_service_status }, # c3gGsmCurrentServiceStatus + traffic_out => { oid => '.1.3.6.1.4.1.9.9.661.1.3.2.1.19' }, # c3gGsmTotalByteTransmitted + traffic_in => { oid => '.1.3.6.1.4.1.9.9.661.1.3.2.1.20' }, # c3gGsmTotalByteReceived +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_entPhysicalName = '.1.3.6.1.2.1.47.1.1.1.1.7'; + my $snmp_result = $options{snmp}->get_table( + oid => $mapping->{connection_status}->{oid}, + nothing_quit => 1 + ); + + my $instances = []; + foreach (keys %$snmp_result) { + /\.(\d+)$/; + push @$instances, $1; + } + + $options{snmp}->load( + oids => [ $oid_entPhysicalName ], + instances => $instances, + instance_regexp => '^(.*)$' + ); + $snmp_result = $options{snmp}->get_leef(); + + $self->{modem} = {}; + foreach (keys %$snmp_result) { + /\.(\d+)$/; + my $instance = $1; + my $name = $snmp_result->{$_}; + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping module '" . $name . "'.", debug => 1); + next; + } + + $self->{modem}->{$instance} = { + display => $name, + global => { display => $name }, + radio => { display => $name }, + network => { display => $name } + }; + } + + return if (scalar(keys %{$self->{modem}}) <= 0); + + $options{snmp}->load( + oids => [ map($_->{oid}, values(%$mapping)) ], + instances => [ keys %{$self->{modem}} ], + instance_regexp => '^(.*)$' + ); + $snmp_result = $options{snmp}->get_leef(); + foreach (keys %{$self->{modem}}) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + $self->{modem}->{$_}->{global}->{modem_status} = $result->{modem_status}; + $self->{modem}->{$_}->{global}->{connection_status} = $result->{connection_status}; + $self->{modem}->{$_}->{global}->{sim_status} = $result->{sim_status}; + $self->{modem}->{$_}->{global}->{temperature} = $result->{temperature}; + $self->{modem}->{$_}->{radio}->{current_band} = $result->{current_band}; + $self->{modem}->{$_}->{radio}->{channel_number} = $result->{channel_number}; + $self->{modem}->{$_}->{radio}->{rssi} = $result->{rssi}; + $self->{modem}->{$_}->{network}->{traffic_in} = $result->{traffic_in}; + $self->{modem}->{$_}->{network}->{traffic_out} = $result->{traffic_out}; + $self->{modem}->{$_}->{network}->{service_status} = $result->{service_status}; + } + + $self->{cache_name} = 'cisco_standard_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + (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 cellular 3G and 4G LTE WAN. + +=over 8 + +=item B<--filter-name> + +Filter by name (can be a regexp). + +=item B<--unknown-modem-status> + +Set unknown threshold for status (Default: '%{modem_status} =~ /unknown/i'). +Can used special variables like: %{modem_status}, %{display} + +=item B<--warning-modem-status> + +Set warning threshold for status (Default: '%{modem_status} =~ /lowPowerMode/i'). +Can used special variables like: %{modem_status}, %{display} + +=item B<--critical-modem-status> + +Set critical threshold for status (Default: '%{modem_status} =~ /offLine/i'). +Can used special variables like: %{modem_status}, %{display} + +=item B<--unknown-connection-status> + +Set unknown threshold for status (Default: '%{connection_status} =~ /unknown/i'). +Can used special variables like: %{connection_status}, %{display} + +=item B<--warning-connection-status> + +Set warning threshold for status. +Can used special variables like: %{connection_status}, %{display} + +=item B<--critical-connection-status> + +Set critical threshold for status (Default: '%{connection_status} =~ /inactive|idle|disconnected|error/i'). +Can used special variables like: %{connection_status}, %{display} + +=item B<--unknown-sim-status> + +Set unknown threshold for status (Default: '%{sim_status} =~ /unknown/i'). +Can used special variables like: %{sim_status}, %{display} + +=item B<--warning-sim-status> + +Set warning threshold for status. +Can used special variables like: %{sim_status}, %{display} + +=item B<--critical-sim-status> + +Set critical threshold for status (Default: '%{sim_status} !~ /ok|unknown/i'). +Can used special variables like: %{sim_status}, %{display} + +=item B<--unknown-radio-status> + +Set unknown threshold for status (Default: '%{current_band} =~ /unknown/i'). +Can used special variables like: %{current_band}, %{channel_number}, %{display} + +=item B<--warning-radio-status> + +Set warning threshold for status. +Can used special variables like: %{current_band}, %{channel_number}, %{display} + +=item B<--critical-radio-status> + +Set critical threshold for status (Default: '%{current_band} =~ /invalid|none/i'). +Can used special variables like: %{current_band}, %{channel_number}, %{display} + +=item B<--unknown-network-status> + +Set unknown threshold for status (Default: '%{service_status} =~ /unknown/i'). +Can used special variables like: %{service_status}, %{display} + +=item B<--warning-network-status> + +Set warning threshold for status. +Can used special variables like: %{service_status}, %{display} + +=item B<--critical-network-status> + +Set critical threshold for status (Default: '%{service_status} =~ /emergencyOnly|noService/i'). +Can used special variables like: %{service_status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'temperature', 'traffic-in', 'traffic-out'. + +=back + +=cut diff --git a/centreon-plugins/network/cisco/standard/snmp/plugin.pm b/centreon-plugins/network/cisco/standard/snmp/plugin.pm index 61e9bf9c7..af5301c7e 100644 --- a/centreon-plugins/network/cisco/standard/snmp/plugin.pm +++ b/centreon-plugins/network/cisco/standard/snmp/plugin.pm @@ -31,23 +31,24 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'arp' => 'snmp_standard::mode::arp', - 'configuration' => 'centreon::common::cisco::standard::snmp::mode::configuration', - 'cpu' => 'centreon::common::cisco::standard::snmp::mode::cpu', - 'environment' => 'centreon::common::cisco::standard::snmp::mode::environment', - 'hsrp' => 'centreon::common::cisco::standard::snmp::mode::hsrp', - 'interfaces' => 'centreon::common::cisco::standard::snmp::mode::interfaces', - 'ipsla' => 'centreon::common::cisco::standard::snmp::mode::ipsla', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-spanning-trees' => 'snmp_standard::mode::listspanningtrees', - 'load' => 'centreon::common::cisco::standard::snmp::mode::load', - 'memory' => 'centreon::common::cisco::standard::snmp::mode::memory', - 'memory-flash' => 'centreon::common::cisco::standard::snmp::mode::memoryflash', - 'qos-usage' => 'centreon::common::cisco::standard::snmp::mode::qosusage', - 'spanning-tree' => 'snmp_standard::mode::spanningtree', - 'stack' => 'centreon::common::cisco::standard::snmp::mode::stack', - 'uptime' => 'snmp_standard::mode::uptime', - 'voice-call' => 'centreon::common::cisco::standard::snmp::mode::voicecall', + 'arp' => 'snmp_standard::mode::arp', + 'configuration' => 'centreon::common::cisco::standard::snmp::mode::configuration', + 'cpu' => 'centreon::common::cisco::standard::snmp::mode::cpu', + 'environment' => 'centreon::common::cisco::standard::snmp::mode::environment', + 'hsrp' => 'centreon::common::cisco::standard::snmp::mode::hsrp', + 'interfaces' => 'centreon::common::cisco::standard::snmp::mode::interfaces', + 'ipsla' => 'centreon::common::cisco::standard::snmp::mode::ipsla', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-spanning-trees' => 'snmp_standard::mode::listspanningtrees', + 'load' => 'centreon::common::cisco::standard::snmp::mode::load', + 'memory' => 'centreon::common::cisco::standard::snmp::mode::memory', + 'memory-flash' => 'centreon::common::cisco::standard::snmp::mode::memoryflash', + 'qos-usage' => 'centreon::common::cisco::standard::snmp::mode::qosusage', + 'spanning-tree' => 'snmp_standard::mode::spanningtree', + 'stack' => 'centreon::common::cisco::standard::snmp::mode::stack', + 'uptime' => 'snmp_standard::mode::uptime', + 'voice-call' => 'centreon::common::cisco::standard::snmp::mode::voicecall', + 'wan3g' => 'centreon::common::cisco::standard::snmp::mode::wan3g' ); return $self; From c6ac89a19f6ac64b7727e5276c4e382d04df736b Mon Sep 17 00:00:00 2001 From: Simon Bomm Date: Tue, 31 Mar 2020 10:19:45 +0200 Subject: [PATCH 030/190] fix(plugin) use the good c3gConnectionStatus OID --- .../centreon/common/cisco/standard/snmp/mode/wan3g.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/wan3g.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/wan3g.pm index 15d8b8d34..da72efd56 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/wan3g.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/wan3g.pm @@ -264,7 +264,7 @@ my $mapping = { channel_number => { oid => '.1.3.6.1.4.1.9.9.661.1.3.4.1.1.4' }, # c3gGsmChannelNumber modem_status => { oid => '.1.3.6.1.4.1.9.9.661.1.3.1.1.6', map => $map_modem_status }, # c3gModemStatus temperature => { oid => '.1.3.6.1.4.1.9.9.661.1.1.1.12' }, # c3gModemTemperature - connection_status => { oid => '.1.3.6.1.4.1.9.9.661.1.3.1.1.6', map => $map_connection_status }, # c3gConnectionStatus + connection_status => { oid => '.1.3.6.1.4.1.9.9.661.1.1.1.8', map => $map_connection_status }, # c3gConnectionStatus sim_status => { oid => '.1.3.6.1.4.1.9.9.661.1.3.5.1.1.2', map => $map_sim_status }, # c3gGsmSimStatus service_status => { oid => '.1.3.6.1.4.1.9.9.661.1.3.2.1.2', map => $map_service_status }, # c3gGsmCurrentServiceStatus traffic_out => { oid => '.1.3.6.1.4.1.9.9.661.1.3.2.1.19' }, # c3gGsmTotalByteTransmitted From 30ade14ed7906a46ab72466645ef72b96fdf6901 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 31 Mar 2020 10:38:37 +0200 Subject: [PATCH 031/190] use bigint for qos usage --- .../cisco/standard/snmp/mode/qosusage.pm | 133 +++++++++--------- 1 file changed, 70 insertions(+), 63 deletions(-) diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/qosusage.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/qosusage.pm index b130f73dc..55f357544 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/qosusage.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/qosusage.pm @@ -25,6 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Digest::MD5 qw(md5_hex); +use bigint; sub set_counters { my ($self, %options) = @_; @@ -32,7 +33,7 @@ sub set_counters { $self->{maps_counters_type} = [ { name => 'total', type => 0 }, { name => 'interface_classmap', type => 1, cb_prefix_output => 'prefix_intcmap_output', message_multiple => 'All interface classmaps are ok' }, - { name => 'classmap', type => 1, cb_prefix_output => 'prefix_cmap_output', message_multiple => 'All classmaps are ok' }, + { name => 'classmap', type => 1, cb_prefix_output => 'prefix_cmap_output', message_multiple => 'All classmaps are ok' } ]; $self->{maps_counters}->{interface_classmap} = [ @@ -42,7 +43,7 @@ sub set_counters { closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_output => $self->can('custom_traffic_output'), closure_custom_perfdata => $self->can('custom_traffic_perfdata'), - closure_custom_threshold_check => $self->can('custom_traffic_threshold'), + closure_custom_threshold_check => $self->can('custom_traffic_threshold') } }, { label => 'int-cmap-drop', set => { @@ -51,10 +52,10 @@ sub set_counters { output_template => 'Drop : %s %s/s', perfdatas => [ { label => 'icmap_drop', value => 'drop_usage_per_second', template => '%d', - unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] } - }, + } ]; $self->{maps_counters}->{classmap} = [ { label => 'cmap-traffic', set => { @@ -63,8 +64,8 @@ sub set_counters { output_template => 'Traffic : %s %s/s', perfdatas => [ { label => 'cmap_traffic', value => 'traffic_usage_per_second', template => '%d', - unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] } }, { label => 'cmap-drop', set => { @@ -73,11 +74,12 @@ sub set_counters { output_template => 'Drop : %s %s/s', perfdatas => [ { label => 'cmap_drop', value => 'drop_usage_per_second', template => '%d', - unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] } - }, + } ]; + $self->{maps_counters}->{total} = [ { label => 'total-traffic', set => { key_values => [ { name => 'traffic_usage', diff => 1 } ], @@ -85,8 +87,8 @@ sub set_counters { output_template => 'Total Traffic : %s %s/s', perfdatas => [ { label => 'total_traffic', value => 'traffic_usage_per_second', template => '%d', - unit => 'b/s', min => 0 }, - ], + unit => 'b/s', min => 0 } + ] } }, { label => 'total-drop', set => { @@ -95,16 +97,16 @@ sub set_counters { output_template => 'Total Drop : %s %s/s', perfdatas => [ { label => 'total_drop', value => 'drop_usage_per_second', template => '%d', - unit => 'b/s', min => 0 }, - ], + unit => 'b/s', min => 0 } + ] } - }, + } ]; } sub custom_traffic_perfdata { my ($self, %options) = @_; - + my ($warning, $critical); if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && (defined($self->{result_values}->{total}) && $self->{result_values}->{total} =~ /[0-9]/)) { @@ -114,7 +116,7 @@ sub custom_traffic_perfdata { $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}); $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}); } - + $self->{output}->perfdata_add( label => 'icmap_traffic', unit => 'b/s', instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, @@ -127,7 +129,7 @@ sub custom_traffic_perfdata { sub custom_traffic_threshold { my ($self, %options) = @_; - + my $exit = 'ok'; if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && (defined($self->{result_values}->{total}) && $self->{result_values}->{total} =~ /[0-9]/)) { @@ -142,10 +144,11 @@ sub custom_traffic_output { my ($self, %options) = @_; my ($traffic_value, $traffic_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic_per_seconds}, network => 1); - my $msg = sprintf("Traffic : %s/s (%s)", - $traffic_value . $traffic_unit, - defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-'); - return $msg; + return sprintf( + 'Traffic : %s/s (%s)', + $traffic_value . $traffic_unit, + defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-' + ); } sub custom_traffic_calc { @@ -154,7 +157,7 @@ sub custom_traffic_calc { $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; $self->{result_values}->{traffic_usage} = $options{new_datas}->{$self->{instance} . '_traffic_usage'}; - + my $diff_traffic = ($options{new_datas}->{$self->{instance} . '_traffic_usage'} - $options{old_datas}->{$self->{instance} . '_traffic_usage'}); $self->{result_values}->{traffic_per_seconds} = $diff_traffic / $options{delta_time}; if ($options{new_datas}->{$self->{instance} . '_total'} =~ /[1-9]/) { @@ -182,10 +185,10 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-source:s" => { name => 'filter_source' }, - "oid-filter:s" => { name => 'oid_filter', default => 'ifname' }, - "oid-display:s" => { name => 'oid_display', default => 'ifname' }, - "units-traffic:s" => { name => 'units_traffic', default => '%' }, + 'filter-source:s' => { name => 'filter_source' }, + 'oid-filter:s' => { name => 'oid_filter', default => 'ifname' }, + 'oid-display:s' => { name => 'oid_display', default => 'ifname' }, + 'units-traffic:s' => { name => 'units_traffic', default => '%' } }); return $self; @@ -205,7 +208,7 @@ sub check_options { sub check_oids_label { my ($self, %options) = @_; - + foreach (('oid_filter', 'oid_display')) { $self->{option_results}->{$_} = lc($self->{option_results}->{$_}) if (defined($self->{option_results}->{$_})); if (!defined($self->{oids_label}->{$self->{option_results}->{$_}})) { @@ -218,23 +221,20 @@ sub check_oids_label { } my $mapping = { - cbQosCMPrePolicyByteOverflow => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.4' }, - cbQosCMPrePolicyByte => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.5' }, - cbQosCMPrePolicyByte64 => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.6' }, cbQosCMPostPolicyByteOverflow => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.8' }, cbQosCMPostPolicyByte => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.9' }, cbQosCMPostPolicyByte64 => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.10' }, cbQosCMDropByteOverflow => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.15' }, cbQosCMDropByte => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.16' }, - cbQosCMDropByte64 => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.17' }, + cbQosCMDropByte64 => { oid => '.1.3.6.1.4.1.9.9.166.1.15.1.1.17' } }; my $mapping2 = { cbQosTSCfgRate => { oid => '.1.3.6.1.4.1.9.9.166.1.13.1.1.1' }, # bps - cbQosTSCfgRate64 => { oid => '.1.3.6.1.4.1.9.9.166.1.13.1.1.11' }, # bps + cbQosTSCfgRate64 => { oid => '.1.3.6.1.4.1.9.9.166.1.13.1.1.11' } # bps }; my $mapping3 = { cbQosQueueingCfgBandwidth => { oid => '.1.3.6.1.4.1.9.9.166.1.9.1.1.1' }, - cbQosQueueingCfgBandwidthUnits => { oid => '.1.3.6.1.4.1.9.9.166.1.9.1.1.2' }, + cbQosQueueingCfgBandwidthUnits => { oid => '.1.3.6.1.4.1.9.9.166.1.9.1.1.2' } }; my $oid_cbQosIfIndex = '.1.3.6.1.4.1.9.9.166.1.1.1.1.4'; @@ -252,17 +252,17 @@ my $oid_cbQosQueueingCfgEntry = '.1.3.6.1.4.1.9.9.166.1.9.1.1'; sub build_qos_information { my ($self, %options) = @_; - + my $qos_data = { complete_name => $options{class_name} }; # Need to try and find the queueing (it's a child) $qos_data->{queueing} = $options{link_queueing}->{$options{policy_index} . '.' . $options{object_index}} if (defined($options{link_queueing}->{$options{policy_index} . '.' . $options{object_index}})); $qos_data->{shaping} = $options{link_shaping}->{$options{policy_index} . '.' . $options{object_index}} if (!defined($qos_data->{shaping}) && defined($options{link_shaping}->{$options{policy_index} . '.' . $options{object_index}})); - + while (($options{object_index} = $self->{results}->{$oid_cbQosParentObjectsIndex}->{$oid_cbQosParentObjectsIndex . '.' . $options{policy_index} . '.' . $options{object_index}}) != 0) { my $config_index = $self->{results}->{$oid_cbQosConfigIndex}->{$oid_cbQosConfigIndex . '.' . $options{policy_index} . '.' . $options{object_index}}; - + my $tmp_name = ''; # try to find policy_map or class_map if (defined($self->{results}->{$oid_cbQosCMName}->{$oid_cbQosCMName . '.' . $config_index})) { @@ -270,23 +270,23 @@ sub build_qos_information { } elsif (defined($self->{results}->{$oid_cbQosPolicyMapName}->{$oid_cbQosPolicyMapName . '.' . $config_index})) { $tmp_name = $self->{results}->{$oid_cbQosPolicyMapName}->{$oid_cbQosPolicyMapName . '.' . $config_index}; } - + $qos_data->{shaping} = $options{link_shaping}->{$options{policy_index} . '.' . $options{object_index}} if (!defined($qos_data->{shaping}) && defined($options{link_shaping}->{$options{policy_index} . '.' . $options{object_index}})); - + $qos_data->{complete_name} = $tmp_name . ':' . $qos_data->{complete_name}; } - + return $qos_data; } sub manage_selection { my ($self, %options) = @_; - + $self->{interface_classmap} = {}; $self->{classmap} = {}; $self->{total} = { drop_usage => 0, total_usage => 0 }; - + my $request_oids = [ { oid => $self->{oids_label}->{$self->{option_results}->{oid_filter}} }, { oid => $oid_cbQosPolicyMapName }, @@ -294,9 +294,9 @@ sub manage_selection { { oid => $oid_cbQosConfigIndex }, { oid => $oid_cbQosCMName }, { oid => $oid_cbQosQueueingCfgEntry, end => $mapping3->{cbQosQueueingCfgBandwidthUnits}->{oid} }, - { oid => $oid_cbQosCMStatsEntry, start => $mapping->{cbQosCMPrePolicyByteOverflow}->{oid}, end => $mapping->{cbQosCMDropByte64}->{oid} }, + { oid => $oid_cbQosCMStatsEntry, start => $mapping->{cbQosCMPostPolicyByteOverflow}->{oid}, end => $mapping->{cbQosCMDropByte64}->{oid} }, { oid => $oid_cbQosParentObjectsIndex }, - { oid => $oid_cbQosTSCfgEntry, end => $mapping2->{cbQosTSCfgRate64}->{oid} }, + { oid => $oid_cbQosTSCfgEntry, end => $mapping2->{cbQosTSCfgRate64}->{oid} } ]; push @$request_oids, { oid => $self->{oids_label}->{$self->{option_results}->{oid_display}} } if ($self->{option_results}->{oid_filter} ne $self->{option_results}->{oid_display}); @@ -321,8 +321,8 @@ sub manage_selection { } foreach (keys %{$self->{results}->{$oid_cbQosCMStatsEntry}}) { - next if (!/$mapping->{cbQosCMPrePolicyByte}->{oid}\.(\d+)\.(\d+)/); - + next if (!/$mapping->{cbQosCMPostPolicyByteOverflow}->{oid}\.(\d+)\.(\d+)/); + my ($policy_index, $qos_object_index) = ($1, $2); my $class_name = $classmap_name{$policy_index . '.' . $qos_object_index}; @@ -338,24 +338,29 @@ sub manage_selection { next; } - my $qos_data = $self->build_qos_information(class_name => $class_name, policy_index => $policy_index, object_index => $qos_object_index, - link_queueing => $link_queueing, link_shaping => $link_shaping); - + my $qos_data = $self->build_qos_information( + class_name => $class_name, + policy_index => $policy_index, + object_index => $qos_object_index, + link_queueing => $link_queueing, + link_shaping => $link_shaping + ); + my $interface_filter = $self->{results}->{$self->{oids_label}->{$self->{option_results}->{oid_filter}}}->{$self->{oids_label}->{$self->{option_results}->{oid_filter}} . '.' . $if_index}; my $name = $interface_filter . ':' . $qos_data->{complete_name}; - + if (defined($self->{option_results}->{filter_source}) && $self->{option_results}->{filter_source} ne '' && $name !~ /$self->{option_results}->{filter_source}/) { $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter source.", debug => 1); next; } - + # Same hash key but only for disco context if (defined($options{disco})) { $self->{interface_classmap}->{$policy_index . '.' . $qos_object_index} = $name; next; } - + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cbQosCMStatsEntry}, instance => $policy_index . '.' . $qos_object_index); my $traffic_usage = (defined($result->{cbQosCMPostPolicyByte64}) && $result->{cbQosCMPostPolicyByte64} =~ /[1-9]/) ? $result->{cbQosCMPostPolicyByte64} : (($result->{cbQosCMPostPolicyByteOverflow} << 32) + $result->{cbQosCMPostPolicyByte}); @@ -366,40 +371,42 @@ sub manage_selection { my $result_shaping = $options{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$oid_cbQosTSCfgEntry}, instance => $qos_data->{shaping}); $total = defined($result_shaping->{cbQosTSCfgRate64}) ? $result_shaping->{cbQosTSCfgRate64} : $result_shaping->{cbQosTSCfgRate}; } - + $self->{interface_classmap}->{$policy_index . '.' . $qos_object_index} = { display => $name, - traffic_usage => $traffic_usage * 8, drop_usage => $drop_usage * 8, total => $total + traffic_usage => $traffic_usage * 8, + drop_usage => $drop_usage * 8, + total => $total }; - + my @tabname = split /:/, $name; if (defined($tabname[3])){ - $class_name = $tabname[3].'-'.$class_name; + $class_name = $tabname[3] . '-' . $class_name; } - + $self->{classmap}->{$name} = { display => $class_name, drop_usage => 0, traffic_usage => 0} if (!defined($self->{classmap}->{$name})); $self->{classmap}->{$name}->{traffic_usage} += $traffic_usage * 8; $self->{classmap}->{$name}->{drop_usage} += $drop_usage * 8; - + if (!defined($tabname[3])){ $self->{total}->{traffic_usage} += $traffic_usage * 8; $self->{total}->{drop_usage} += $drop_usage * 8; } } - - $self->{cache_name} = "cisco_qos_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + + $self->{cache_name} = 'cisco_qos_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{filter_source}) ? md5_hex($self->{option_results}->{filter_source}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); - + if (scalar(keys %{$self->{interface_classmap}}) <= 0 && !defined($options{disco})) { - $self->{output}->add_option_msg(short_msg => "Cannot found classmap."); + $self->{output}->add_option_msg(short_msg => 'Cannot found classmap.'); $self->{output}->option_exit(); } } sub disco_format { my ($self, %options) = @_; - + $self->{output}->add_disco_format(elements => ['name']); } From ca149dba05657c2af329bed166d2b2e6781977f8 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 31 Mar 2020 11:34:20 +0200 Subject: [PATCH 032/190] fix fortinet core filter cpu --- .../centreon/common/fortinet/fortigate/snmp/mode/cpu.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/fortinet/fortigate/snmp/mode/cpu.pm index 91185c599..245ce76e6 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/snmp/mode/cpu.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/snmp/mode/cpu.pm @@ -147,8 +147,9 @@ sub manage_selection { $cpu += $snmp_result->{$oid_fgProcessorUsage}->{$_}; } + my $num_core = scalar(keys %{$self->{cpu_core}}); $self->{cpu_avg} = { - average => ($i > 0) ? $cpu / $i : $snmp_result->{$oid_fgSysCpuUsage}->{$oid_fgSysCpuUsage . '.0'} + average => $num_core > 0 ? $cpu / $num_core : $snmp_result->{$oid_fgSysCpuUsage}->{$oid_fgSysCpuUsage . '.0'} }; if (defined($self->{option_results}->{cluster})) { From 4498762a0a1b4e641b6d65d6229761fb20a7c993 Mon Sep 17 00:00:00 2001 From: Thibault S <48209914+thibaults-centreon@users.noreply.github.com> Date: Tue, 31 Mar 2020 14:10:53 +0200 Subject: [PATCH 033/190] add(plugin): Amazon EFS (#1913) * add(plugin): Amazon EFS --- centreon-plugins/efs/mode/connections.pm | 231 +++++++++++++++++ centreon-plugins/efs/mode/datausage.pm | 310 +++++++++++++++++++++++ centreon-plugins/efs/mode/discovery.pm | 112 ++++++++ centreon-plugins/efs/plugin.pm | 52 ++++ 4 files changed, 705 insertions(+) create mode 100644 centreon-plugins/efs/mode/connections.pm create mode 100644 centreon-plugins/efs/mode/datausage.pm create mode 100644 centreon-plugins/efs/mode/discovery.pm create mode 100644 centreon-plugins/efs/plugin.pm diff --git a/centreon-plugins/efs/mode/connections.pm b/centreon-plugins/efs/mode/connections.pm new file mode 100644 index 000000000..aa7e4a092 --- /dev/null +++ b/centreon-plugins/efs/mode/connections.pm @@ -0,0 +1,231 @@ +# +# 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 cloud::aws::efs::mode::connections; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my %metrics_mapping = ( + 'ClientConnections' => { + 'output' => 'Client Connections', + 'label' => 'client-connections', + 'nlabel' => 'efs.clients.connections.count', + 'unit' => '' + } +); + + +sub custom_metric_calc { + my ($self, %options) = @_; + + $self->{result_values}->{timeframe} = $options{new_datas}->{$self->{instance} . '_timeframe'}; + $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{metric}}; + $self->{result_values}->{metric} = $options{extra_options}->{metric}; + return 0; +} + +sub custom_metric_threshold { + my ($self, %options) = @_; + + my $exit = $self->{perfdata}->threshold_check( + value => $self->{result_values}->{value}, + threshold => [ { label => 'critical-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'critical' }, + { label => 'warning-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_metric_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + instances => $self->{instance}, + label => $metrics_mapping{$self->{result_values}->{metric}}->{label}, + nlabel => $metrics_mapping{$self->{result_values}->{metric}}->{nlabel}, + unit => $metrics_mapping{$self->{result_values}->{metric}}->{unit}, + value => $self->{result_values}->{value}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}) + ); +} + +sub custom_metric_output { + my ($self, %options) = @_; + my $msg = ""; + + my ($value, $unit) = ($self->{result_values}->{value}, $metrics_mapping{$self->{result_values}->{metric}}->{unit}); + return $msg = sprintf("%s: %.2f %s", $metrics_mapping{$self->{result_values}->{metric}}->{output}, $value, $unit); +} + + +sub prefix_metric_output { + my ($self, %options) = @_; + + return "'" . $options{instance_value}->{display} . "' "; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + return "EFS FileSystemId'" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All FS metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + set => { + key_values => [ { name => $metric }, { name => 'timeframe' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_metric_calc'), + closure_custom_calc_extra_options => { metric => $metric }, + closure_custom_output => $self->can('custom_metric_output'), + closure_custom_perfdata => $self->can('custom_metric_perfdata'), + closure_custom_threshold_check => $self->can('custom_metric_threshold'), + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "name:s@" => { name => 'name' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{name}) || $self->{option_results}->{name} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --name option."); + $self->{output}->option_exit(); + } + + foreach my $instance (@{$self->{option_results}->{name}}) { + if ($instance ne '') { + push @{$self->{aws_instance}}, $instance; + } + } + + $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 172800; + $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 86400; + $self->{aws_statistics} = ['Sum']; + + foreach my $metric (keys %metrics_mapping) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + push @{$self->{aws_metrics}}, $metric; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my %metric_results; + foreach my $instance (@{$self->{aws_instance}}) { + $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( + region => $self->{option_results}->{region}, + namespace => 'AWS/EFS', + dimensions => [ { Name => 'FileSystemId', Value => $instance } ], + metrics => $self->{aws_metrics}, + statistics => $self->{aws_statistics}, + timeframe => $self->{aws_timeframe}, + period => $self->{aws_period}, + ); + + foreach my $metric (@{$self->{aws_metrics}}) { + foreach my $statistic (@{$self->{aws_statistics}}) { + next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && + !defined($self->{option_results}->{zeroed})); + + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{timeframe} = $self->{aws_timeframe}; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = + defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? + $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + } + } + } + + if (scalar(keys %{$self->{metrics}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check EFS FileSystem Connection Count. + +Example: +perl centreon_plugins.pl --plugin=cloud::aws::efs::plugin --custommode=paws --mode=connections --region='eu-west-1' +--name='fs-1234abcd' --warning-client-connections='50' --critical-client-connections='100' --verbose + +See 'https://docs.aws.amazon.com/efs/latest/ug/monitoring-cloudwatch.html' for more information. + + +=over 8 + +=item B<--name> + +Set the instance name (Required) (Can be multiple). + +=item B<--warning-client-connections> + +Warning threshold. + +=item B<--critical-client-connections> + +Critical threshold. + +=back + +=cut diff --git a/centreon-plugins/efs/mode/datausage.pm b/centreon-plugins/efs/mode/datausage.pm new file mode 100644 index 000000000..3711b2f39 --- /dev/null +++ b/centreon-plugins/efs/mode/datausage.pm @@ -0,0 +1,310 @@ +# +# 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 cloud::aws::efs::mode::datausage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my %metrics_mapping = ( + 'DataReadIOBytes' => { + 'output' => 'Data Read IO Bytes', + 'label' => 'data-iobytes-read', + 'nlabel' => { + 'absolute' => 'efs.data.iobytes.read.bytes', + 'per_second' => 'efs.data.iobytes.read.bytespersecond', + }, + 'unit' => 'B' + }, + 'DataWriteIOBytes' => { + 'output' => 'Data Write IO Bytes', + 'label' => 'data-iobytes-write', + 'nlabel' => { + 'absolute' => 'efs.data.iobytes.write.bytes', + 'per_second' => 'efs.data.iobytes.write.bytespersecond', + }, + 'unit' => 'B' + }, + 'MetaDataIOBytes' => { + 'output' => 'MetaData IO Bytes', + 'label' => 'metadata-iobytes', + 'nlabel' => { + 'absolute' => 'efs.metadata.iobytes.bytes', + 'per_second' => 'efs.metadata.iobytes.bytespersecond', + }, + 'unit' => 'B' + }, + 'TotalIOBytes' => { + 'output' => 'Total IO Bytes', + 'label' => 'total-iobytes', + 'nlabel' => { + 'absolute' => 'efs.total.iobytes.bytes', + 'per_second' => 'efs.total.iobytes.bytespersecond', + }, + 'unit' => 'B' + }, + 'BurstCreditBalance' => { + 'output' => 'Burst Credit Balance Bytes', + 'label' => 'burst-bytes', + 'nlabel' => { + 'absolute' => 'efs.creditbalance.burst.bytes', + 'per_second' => 'efs.creditbalance.burst.bytespersecond', + }, + 'unit' => 'B' + } + +); + +sub custom_metric_calc { + my ($self, %options) = @_; + + $self->{result_values}->{timeframe} = $options{new_datas}->{$self->{instance} . '_timeframe'}; + $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{metric}}; + $self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe}; + $self->{result_values}->{metric} = $options{extra_options}->{metric}; + return 0; +} + +sub custom_metric_threshold { + my ($self, %options) = @_; + + 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-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'critical' }, + { label => 'warning-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_metric_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + instances => $self->{instance}, + label => $metrics_mapping{$self->{result_values}->{metric}}->{label}, + nlabel => defined($self->{instance_mode}->{option_results}->{per_sec}) ? + $metrics_mapping{$self->{result_values}->{metric}}->{nlabel}->{per_second} : + $metrics_mapping{$self->{result_values}->{metric}}->{nlabel}->{absolute}, + unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? + $metrics_mapping{$self->{result_values}->{metric}}->{unit} . '/s' : + $metrics_mapping{$self->{result_values}->{metric}}->{unit}, + 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-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}), + ); +} + +sub custom_metric_output { + my ($self, %options) = @_; + my $msg = ""; + + if (defined($self->{instance_mode}->{option_results}->{per_sec})) { + my ($value, $unit) = ($metrics_mapping{$self->{result_values}->{metric}}->{unit} eq 'B') ? + $self->{perfdata}->change_bytes(value => $self->{result_values}->{value_per_sec}) : + ($self->{result_values}->{value_per_sec}, $metrics_mapping{$self->{result_values}->{metric}}->{unit}); + $msg = sprintf("%s: %.2f %s", $metrics_mapping{$self->{result_values}->{metric}}->{output}, $value, $unit . '/s'); + } else { + my ($value, $unit) = ($metrics_mapping{$self->{result_values}->{metric}}->{unit} eq 'B') ? + $self->{perfdata}->change_bytes(value => $self->{result_values}->{value}) : + ($self->{result_values}->{value}, $metrics_mapping{$self->{result_values}->{metric}}->{unit}); + $msg = sprintf("%s: %.2f %s", $metrics_mapping{$self->{result_values}->{metric}}->{output}, $value, $unit); + } + return $msg; +} + +sub prefix_metric_output { + my ($self, %options) = @_; + + return "'" . $options{instance_value}->{display} . "' "; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + return "EFS FileSystemId'" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All FS metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + set => { + key_values => [ { name => $metric }, { name => 'timeframe' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_metric_calc'), + closure_custom_calc_extra_options => { metric => $metric }, + closure_custom_output => $self->can('custom_metric_output'), + closure_custom_perfdata => $self->can('custom_metric_perfdata'), + closure_custom_threshold_check => $self->can('custom_metric_threshold'), + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "type:s" => { name => 'type' }, + "name:s@" => { name => 'name' }, + "per-sec" => { name => 'per_sec' }, + "filter-metric:s" => { name => 'filter_metric' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{name}) || $self->{option_results}->{name} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --name option."); + $self->{output}->option_exit(); + } + + foreach my $instance (@{$self->{option_results}->{name}}) { + if ($instance ne '') { + push @{$self->{aws_instance}}, $instance; + } + } + + $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600; + $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; + + $self->{aws_statistics} = ['Average']; + if (defined($self->{option_results}->{statistic})) { + $self->{aws_statistics} = []; + foreach my $stat (@{$self->{option_results}->{statistic}}) { + if ($stat ne '') { + push @{$self->{aws_statistics}}, ucfirst(lc($stat)); + } + } + } + + foreach my $metric (keys %metrics_mapping) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + + push @{$self->{aws_metrics}}, $metric; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my %metric_results; + foreach my $instance (@{$self->{aws_instance}}) { + $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( + region => $self->{option_results}->{region}, + namespace => 'AWS/EFS', + dimensions => [ { Name => "FileSystemId", Value => $instance } ], + metrics => $self->{aws_metrics}, + statistics => $self->{aws_statistics}, + timeframe => $self->{aws_timeframe}, + period => $self->{aws_period}, + ); + + foreach my $metric (@{$self->{aws_metrics}}) { + foreach my $statistic (@{$self->{aws_statistics}}) { + next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && + !defined($self->{option_results}->{zeroed})); + + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{timeframe} = $self->{aws_timeframe}; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = + defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? + $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + } + } + } + + if (scalar(keys %{$self->{metrics}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check EFS FileSystem Data IO metrics. + +Example: +perl centreon_plugins.pl --plugin=cloud::aws::efs::plugin --custommode=paws --mode=datausage --region='eu-west-1' +--name='fs-1234abcd' --filter-metric='DataReadIOBytes' --warning-data-iobytes-read='5' --critical-data-iobytes-read='10' --verbose + +See 'https://docs.aws.amazon.com/efs/latest/ug/monitoring-cloudwatch.html' for more information. + + +=over 8 + +=item B<--name> + +Set the instance name (Required) (Can be multiple). + +=item B<--filter-metric> + +Filter on a specific metric +Can be: DataReadIOBytes, DataWriteIOBytes, MetaDataIOBytes, TotalIOBytes, BurstCreditBalance + +=item B<--statistic> + +Set the metric calculation method (Default: Average) +Can be 'minimum', 'maximum', 'average', 'sum' + +=item B<--warning-$metric$> + +Thresholds warning ($metric$ can be: 'data-iobytes-read', 'data-iobytes-write', 'metadata-iobytes', 'total-iobytes', 'burst-bytes'). + +=item B<--critical-$metric$> + +Thresholds critical ($metric$ can be: 'data-iobytes-read', 'data-iobytes-write', 'metadata-iobytes', 'total-iobytes', 'burst-bytes'). + +=back + +=cut diff --git a/centreon-plugins/efs/mode/discovery.pm b/centreon-plugins/efs/mode/discovery.pm new file mode 100644 index 000000000..f66982d8b --- /dev/null +++ b/centreon-plugins/efs/mode/discovery.pm @@ -0,0 +1,112 @@ +# +# 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 cloud::aws::efs::mode::discovery; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + "prettify" => { name => 'prettify' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + + my @disco_data; + my $disco_stats; + + $disco_stats->{start_time} = time(); + + my $fs_instances = $options{custom}->discovery( + region => $self->{option_results}->{region}, + service => 'efs', + command => 'describe-file-systems' + ); + + foreach my $fs_instance (@{$fs_instances->{FileSystems}}) { + next if (!defined($fs_instance->{FileSystemId})); + my %efs; + $efs{type} = "efs"; + $efs{id} = $fs_instance->{FileSystemId}; + $efs{name} = $fs_instance->{Name}; + $efs{creation_time} = $fs_instance->{CreationTime}; + $efs{size} = $fs_instance->{SizeInBytes}->{Value}; + $efs{perf_mode} = $fs_instance->{PerformanceMode }; + $efs{is_encrypted} = $fs_instance->{Encrypted}; + $efs{throughput_mode} = $fs_instance->{ThroughputMode}; + push @disco_data, \%efs; + } + + $disco_stats->{end_time} = time(); + $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; + $disco_stats->{discovered_items} = @disco_data; + $disco_stats->{results} = \@disco_data; + + my $encoded_data; + eval { + if (defined($self->{option_results}->{prettify})) { + $encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats); + } else { + $encoded_data = JSON::XS->new->utf8->encode($disco_stats); + } + }; + if ($@) { + $encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; + } + + $self->{output}->output_add(short_msg => $encoded_data); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +EFS discovery. + +=over 8 + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/efs/plugin.pm b/centreon-plugins/efs/plugin.pm new file mode 100644 index 000000000..1921b281a --- /dev/null +++ b/centreon-plugins/efs/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 cloud::aws::efs::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} = '1.0'; + %{ $self->{modes} } = ( + 'connections' => 'cloud::aws::efs::mode::connections', + 'datausage' => 'cloud::aws::efs::mode::datausage', + 'discovery' => 'cloud::aws::efs::mode::discovery' + ); + + $self->{custom_modes}{paws} = 'cloud::aws::custom::paws'; + $self->{custom_modes}{awscli} = 'cloud::aws::custom::awscli'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Amazon Elastic File System (Amazon EFS). + +=cut From 12659f387348d0e7c61db29eaa7bd09cedbe2ffa Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 31 Mar 2020 15:56:16 +0200 Subject: [PATCH 034/190] wip meraki rest api --- .../centreon/plugins/templates/counter.pm | 7 + .../cloudcontroller/restapi/custom/api.pm | 329 ++++++++++++++++++ .../cloudcontroller/restapi/mode/networks.pm | 162 +++++++++ .../meraki/cloudcontroller/restapi/plugin.pm | 50 +++ 4 files changed, 548 insertions(+) create mode 100644 centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm create mode 100644 centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/networks.pm create mode 100644 centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/plugin.pm diff --git a/centreon-plugins/centreon/plugins/templates/counter.pm b/centreon-plugins/centreon/plugins/templates/counter.pm index e47e39f32..f17ad53bf 100644 --- a/centreon-plugins/centreon/plugins/templates/counter.pm +++ b/centreon-plugins/centreon/plugins/templates/counter.pm @@ -620,6 +620,13 @@ sub run_multiple { } } +sub read_statefile_key { + my ($self, %options) = @_; + + $self->{statefile_value}->read(statefile => $self->{cache_name}); + return $self->{statefile_value}->get(name => $options{key}); +} + sub run { my ($self, %options) = @_; diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm new file mode 100644 index 000000000..78c860212 --- /dev/null +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm @@ -0,0 +1,329 @@ +# +# 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 network::cisco::meraki::cloudcontroller::restapi::custom::api; + +use strict; +use warnings; +use centreon::plugins::http; +use centreon::plugins::statefile; +use JSON::XS; +use Digest::MD5 qw(md5_hex); + +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 => { + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port' }, + 'proto:s' => { name => 'proto' }, + 'api-token:s' => { name => 'api_token' }, + 'timeout:s' => { name => 'timeout' }, + 'reload-cache-time:s' => { name => 'reload_cache_time' } + }); + } + $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); + $self->{cache} = centreon::plugins::statefile->new(%options); + $self->{cache_checked} = 0; + + 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} : 'api.meraki.com'; + $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443; + $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_token} = (defined($self->{option_results}->{api_token})) ? $self->{option_results}->{api_token} : ''; + $self->{reload_cache_time} = (defined($self->{option_results}->{reload_cache_time})) ? $self->{option_results}->{reload_cache_time} : 180; + + if (!defined($self->{hostname}) || $self->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); + $self->{output}->option_exit(); + } + if (!defined($self->{api_token}) || $self->{api_token} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-token option."); + $self->{output}->option_exit(); + } + + $self->{cache}->check_options(option_results => $self->{option_results}); + return 0; +} + +sub get_token { + my ($self, %options) = @_; + + return md5_hex($self->{api_token}); +} + +sub get_cache_networks { + my ($self, %options) = @_; + + $self->cache_networks_organizations(); + return $self->{cache_networks}; +} + +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->{http}->add_header(key => 'X-Cisco-Meraki-API-Key', value => $self->{api_token}); +} + +sub settings { + my ($self, %options) = @_; + + $self->build_options_for_httplib(); + $self->{http}->set_options(%{$self->{option_results}}); +} + +sub request_api { + my ($self, %options) = @_; + + $self->settings(); + + #400: Bad Request- You did something wrong, e.g. a malformed request or missing parameter. + #403: Forbidden- You don't have permission to do that. + #404: Not found- No such URL, or you don't have access to the API or organization at all. + #429: Too Many Requests- You submitted more than 5 calls in 1 second to an Organization, triggering rate limiting. This also applies for API calls made across multiple organizations that triggers rate limiting for one of the organizations. + do { + my $response = $self->{http}->request( + url_path => '/api/v0' . $options{endpoint}, + critical_status => '', + warning_status => '', + unknown_status => '(%{http_code} < 200 or %{http_code} >= 300) and %{http_code} != 429' + ); + + if ($self->{http}->get_code() == 429) { + sleep(1); + continue; + } + + my $content; + eval { + $content = JSON::XS->new->utf8->decode($response); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@"); + $self->{output}->option_exit(); + } + return ($content); + } while (1); +} + +sub cache_networks_organizations { + my ($self, %options) = @_; + + return if ($self->{cache_checked} == 1); + + $self->{cache_checked} = 1; + my $has_cache_file = $self->{cache}->read(statefile => 'cache_cisco_meraki_' . $self->get_token()); + my $timestamp_cache = $self->{cache}->get(name => 'last_timestamp'); + $self->{cache_organizations} = $self->{cache}->get(name => 'organizations'); + $self->{cache_networks} = $self->{cache}->get(name => 'networks'); + + if ($has_cache_file == 0 || !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{reload_cache_time}) * 60))) { + $self->{cache_organizations} = {}; + $self->{cache_organizations} = $self->get_organizations(disable_cache => 1); + $self->{cache_networks} = $self->get_networks(organizations => [keys %{$self->{cache_organizations}}], disable_cache => 1); + + $self->{cache}->write(data => { + last_timestamp => time(), + organizations => $self->{cache_organizations}, + networks => $self->{cache_networks} + }); + } +} + +sub get_organizations { + my ($self, %options) = @_; + + $self->cache_networks_organizations(); + return $self->{cache_organizations} if (!defined($options{disable_cache}) || $options{disable_cache} == 0); + my $datas = $self->request_api(endpoint => '/organizations'); + my $results = {}; + $results->{$_->{id}} = $_ foreach (@$datas); + + return $results; +} + +sub get_networks { + my ($self, %options) = @_; + + $self->cache_networks_organizations(); + return $self->{cache_networks} if (!defined($options{disable_cache}) || $options{disable_cache} == 0); + + my $results = {}; + foreach my $id (keys %{$self->{cache_organizations}}) { + my $datas = $self->request_api(endpoint => '/organizations/' . $id . '/networks'); + $results->{$_->{id}} = $_ foreach (@$datas); + } + + return $results; +} + +sub filter_networks { + my ($self, %options) = @_; + + my $network_ids = []; + foreach (values %{$self->{cache_networks}}) { + if (!defined($options{filter_name}) || $options{filter_name} eq '') { + push @$network_ids, $_->{id}; + } elsif ($_->{name} =~ /$options{filter_name}/) { + push @$network_ids, $_->{id}; + } + } + + if (scalar(@$network_ids) > 5) { + $self->{output}->add_option_msg(short_msg => 'cannot check than 5 networks at once'); + $self->{output}->option_exit(); + } + + return $network_ids; +} + +sub get_networks_connection_stats { + my ($self, %options) = @_; + + $self->cache_networks_organizations(); + my $network_ids = $self->filter_networks(filter_name => $options{filter_name}); + + my $timespan = defined($options{timespan}) ? $options{timespan} : 300; + $timespan = 1 if ($timespan <= 0); + my $results = {}; + foreach my $id (@$network_ids) { + my $datas = $self->request_api(endpoint => '/networks/' . $id . '/connectionStats?timespan=' . $options{timespan}); + $results->{$id} = $datas; + } + + return $results; +} + +sub get_networks_clients { + my ($self, %options) = @_; + + $self->cache_networks_organizations(); + my $network_ids = $self->filter_networks(filter_name => $options{filter_name}); + + my $timespan = defined($options{timespan}) ? $options{timespan} : 300; + $timespan = 1 if ($timespan <= 0); + my $results = {}; + foreach my $id (@$network_ids) { + my $datas = $self->request_api(endpoint => '/networks/' . $id . '/clients?timespan=' . $options{timespan}); + $results->{$id} = $datas; + } + + return $results; +} + +sub get_device_statuses { + my ($self, %options) = @_; +} + +1; + +__END__ + +=head1 NAME + +Meraki REST API + +=head1 SYNOPSIS + +api_token Rest API custom mode + +=head1 REST API OPTIONS + +=over 8 + +=item B<--hostname> + +Meraki api hostname (default: 'api.meraki.com') + +=item B<--port> + +Port used (Default: 443) + +=item B<--proto> + +Specify https if needed (Default: 'https') + +=item B<--api-token> + +Meraki api token. + +=item B<--timeout> + +Set HTTP timeout + +=item B<--reload-cache-time> + +Time in minutes before reloading cache file (default: 180). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/networks.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/networks.pm new file mode 100644 index 000000000..c15bbc0a9 --- /dev/null +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/networks.pm @@ -0,0 +1,162 @@ +# +# 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 network::cisco::meraki::cloudcontroller::restapi::mode::networks; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'networks', type => 1, cb_prefix_output => 'prefix_network_output', message_multiple => 'All networks are ok' } + ]; + + $self->{maps_counters}->{networks} = [ + { label => 'connections-success', nlabel => 'network.connections.success.count', set => { + key_values => [ { name => 'assoc' }, { name => 'display' } ], + output_template => 'connections success: %s', + perfdatas => [ + { value => 'assoc_absolute', + template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + }, + { label => 'connections-auth', nlabel => 'network.connections.auth.count', display_ok => 0, set => { + key_values => [ { name => 'auth' }, { name => 'display' } ], + output_template => 'connections auth: %s', + perfdatas => [ + { value => 'auth_absolute', + template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + }, + { label => 'connections-assoc', nlabel => 'network.connections.assoc.count', display_ok => 0, set => { + key_values => [ { name => 'assoc' }, { name => 'display' } ], + output_template => 'connections assoc: %s', + perfdatas => [ + { value => 'assoc_absolute', + template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + }, + { label => 'connections-dhcp', nlabel => 'network.connections.dhcp.count', display_ok => 0, set => { + key_values => [ { name => 'dhcp' }, { name => 'display' } ], + output_template => 'connections dhcp: %s', + perfdatas => [ + { value => 'dhcp_absolute', + template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + }, + { label => 'connections-dns', nlabel => 'network.connections.dns.count', display_ok => 0, set => { + key_values => [ { name => 'dns' }, { name => 'display' } ], + output_template => 'connections dns: %s', + perfdatas => [ + { value => 'dns_absolute', + template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + } + ]; +} + +sub prefix_network_output { + my ($self, %options) = @_; + + return "Network '" . $options{instance_value}->{display} . "' "; +} + +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' } + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{cache_name} = 'meraki_' . $self->{mode} . '_' . $options{custom}->get_token() . '_' . + (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')); + my $last_timestamp = $self->read_statefile_key(key => 'last_timestamp'); + my $timespan = 300; + $timespan = time() - $last_timestamp if (defined($last_timestamp)); + + my $cache_networks = $options{custom}->get_cache_networks(); + my $connections = $options{custom}->get_networks_connection_stats(timespan => $timespan, filter_name => $self->{option_results}->{filter_name}); + my $clients = $options{custom}->get_networks_clients(timespan => $timespan, filter_name => $self->{option_results}->{filter_name}); + + $self->{networks} = {}; + foreach my $id (keys %$connections) { + $self->{networks}->{$id} = { + display => $cache_networks->{$id}->{name}, + assoc => defined($connections->{$id}->{assoc}) ? $connections->{$id}->{assoc} : 0, + auth => defined($connections->{$id}->{assoc}) ? $connections->{$id}->{auth} : 0, + dhcp => defined($connections->{$id}->{assoc}) ? $connections->{$id}->{assoc} : 0, + dns => defined($connections->{$id}->{assoc}) ? $connections->{$id}->{dhcp} : 0, + success => defined($connections->{$id}->{assoc}) ? $connections->{$id}->{success} : 0 + }; + + } + + if (scalar(keys %{$self->{networks}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No networks found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check networks. + +=over 8 + +=item B<--filter-name> + +Filter network name (Can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'volume-data-read-bytespersecond', 'volume-data-written-bytespersecond', +'volume-reads-count', 'volume-writes-count', +'volume-data-transfer-bytespersecond', 'volume-iops-ops', +'volume-cache-write-usage-percentage', 'volume-cache-write-hits-count', +'volume-cache-write-misses-count', 'volume-cache-read-hits-count', +'volume-cache-read-misses-count'. + +=back + +=cut diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/plugin.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/plugin.pm new file mode 100644 index 000000000..ed31ce585 --- /dev/null +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/plugin.pm @@ -0,0 +1,50 @@ +# +# 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 network::cisco::meraki::cloudcontroller::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} = '1.0'; + %{$self->{modes}} = ( + 'devices' => 'network::cisco::meraki::cloudcontroller::restapi::mode::devices', + 'networks' => 'network::cisco::meraki::cloudcontroller::restapi::mode::networks' + ); + + $self->{custom_modes}{api} = 'network::cisco::meraki::cloudcontroller::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Cisco Meraki cloud controller through HTTP/REST API. + +=cut From 6f7173926b84d2356e40d757153da0b4368d9c2a Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 31 Mar 2020 16:19:26 +0200 Subject: [PATCH 035/190] wip cisco meraki rest api --- .../cloudcontroller/restapi/mode/networks.pm | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/networks.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/networks.pm index c15bbc0a9..ce53e1e7a 100644 --- a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/networks.pm +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/networks.pm @@ -78,6 +78,26 @@ sub set_counters { template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } ] } + }, + { label => 'traffic-in', nlabel => 'network.traffic.in.bitspersecond', set => { + key_values => [ { name => 'traffic_in', diff => 1 }, { name => 'display' } ], + output_template => 'traffic in: %s %s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_in_per_second', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' } + ] + } + }, + { label => 'traffic-out', nlabel => 'network.traffic.out.bitspersecond', set => { + key_values => [ { name => 'traffic_out', diff => 1 }, { name => 'display' } ], + output_template => 'traffic out: %s %s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_out_per_second', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' } + ] + } } ]; } @@ -122,9 +142,16 @@ sub manage_selection { auth => defined($connections->{$id}->{assoc}) ? $connections->{$id}->{auth} : 0, dhcp => defined($connections->{$id}->{assoc}) ? $connections->{$id}->{assoc} : 0, dns => defined($connections->{$id}->{assoc}) ? $connections->{$id}->{dhcp} : 0, - success => defined($connections->{$id}->{assoc}) ? $connections->{$id}->{success} : 0 + success => defined($connections->{$id}->{assoc}) ? $connections->{$id}->{success} : 0, + traffic_in => 0, traffic_out => 0 }; - + + if (defined($clients->{$id})) { + foreach (@{$clients->{$id}}) { + $self->{networks}->{$id}->{traffic_in} += $_->{usage}->{recv} * 8; + $self->{networks}->{$id}->{traffic_out} += $_->{usage}->{sent} * 8; + } + } } if (scalar(keys %{$self->{networks}}) <= 0) { @@ -150,12 +177,8 @@ Filter network name (Can be a regexp). =item B<--warning-*> B<--critical-*> Thresholds. -Can be: 'volume-data-read-bytespersecond', 'volume-data-written-bytespersecond', -'volume-reads-count', 'volume-writes-count', -'volume-data-transfer-bytespersecond', 'volume-iops-ops', -'volume-cache-write-usage-percentage', 'volume-cache-write-hits-count', -'volume-cache-write-misses-count', 'volume-cache-read-hits-count', -'volume-cache-read-misses-count'. +Can be: 'connections-success', 'connections-auth', 'connections-assoc', +'connections-dhcp', 'connections-dns', 'traffic-in', 'traffic-out'. =back From 58f0e58009cbf283cbe0f1b2d2f796d1fe13d637 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 31 Mar 2020 18:36:35 +0200 Subject: [PATCH 036/190] fix efs path --- .../{ => cloud/aws}/efs/mode/connections.pm | 11 +++++---- .../{ => cloud/aws}/efs/mode/datausage.pm | 23 ++++++++++--------- .../{ => cloud/aws}/efs/mode/discovery.pm | 8 +++---- .../{ => cloud/aws}/efs/plugin.pm | 6 ++--- .../cloudcontroller/restapi/custom/api.pm | 2 +- 5 files changed, 26 insertions(+), 24 deletions(-) rename centreon-plugins/{ => cloud/aws}/efs/mode/connections.pm (96%) rename centreon-plugins/{ => cloud/aws}/efs/mode/datausage.pm (97%) rename centreon-plugins/{ => cloud/aws}/efs/mode/discovery.pm (94%) rename centreon-plugins/{ => cloud/aws}/efs/plugin.pm (83%) diff --git a/centreon-plugins/efs/mode/connections.pm b/centreon-plugins/cloud/aws/efs/mode/connections.pm similarity index 96% rename from centreon-plugins/efs/mode/connections.pm rename to centreon-plugins/cloud/aws/efs/mode/connections.pm index aa7e4a092..f812f247c 100644 --- a/centreon-plugins/efs/mode/connections.pm +++ b/centreon-plugins/cloud/aws/efs/mode/connections.pm @@ -97,7 +97,7 @@ sub long_output { sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', message_multiple => 'All FS metrics are ok', indent_long_output => ' ', @@ -128,10 +128,11 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - + $options{options}->add_options(arguments => { - "name:s@" => { name => 'name' }, + 'name:s@' => { name => 'name' }, }); + return $self; } @@ -153,7 +154,7 @@ sub check_options { $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 172800; $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 86400; $self->{aws_statistics} = ['Sum']; - + foreach my $metric (keys %metrics_mapping) { next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' && $metric !~ /$self->{option_results}->{filter_metric}/); @@ -175,7 +176,7 @@ sub manage_selection { timeframe => $self->{aws_timeframe}, period => $self->{aws_period}, ); - + foreach my $metric (@{$self->{aws_metrics}}) { foreach my $statistic (@{$self->{aws_statistics}}) { next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && diff --git a/centreon-plugins/efs/mode/datausage.pm b/centreon-plugins/cloud/aws/efs/mode/datausage.pm similarity index 97% rename from centreon-plugins/efs/mode/datausage.pm rename to centreon-plugins/cloud/aws/efs/mode/datausage.pm index 3711b2f39..dd5171618 100644 --- a/centreon-plugins/efs/mode/datausage.pm +++ b/centreon-plugins/cloud/aws/efs/mode/datausage.pm @@ -76,7 +76,7 @@ my %metrics_mapping = ( sub custom_metric_calc { my ($self, %options) = @_; - + $self->{result_values}->{timeframe} = $options{new_datas}->{$self->{instance} . '_timeframe'}; $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{metric}}; $self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe}; @@ -90,7 +90,8 @@ sub custom_metric_threshold { 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-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'critical' }, - { label => 'warning-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'warning' } ]); + { label => 'warning-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'warning' } ] + ); return $exit; } @@ -134,13 +135,13 @@ sub custom_metric_output { sub prefix_metric_output { my ($self, %options) = @_; - + return "'" . $options{instance_value}->{display} . "' "; } sub prefix_statistics_output { my ($self, %options) = @_; - + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; } @@ -152,7 +153,7 @@ sub long_output { sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', message_multiple => 'All FS metrics are ok', indent_long_output => ' ', @@ -183,12 +184,12 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - + $options{options}->add_options(arguments => { - "type:s" => { name => 'type' }, - "name:s@" => { name => 'name' }, - "per-sec" => { name => 'per_sec' }, - "filter-metric:s" => { name => 'filter_metric' }, + 'type:s' => { name => 'type' }, + 'name:s@' => { name => 'name' }, + 'per-sec' => { name => 'per_sec' }, + 'filter-metric:s' => { name => 'filter_metric' }, }); return $self; @@ -211,7 +212,7 @@ sub check_options { $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600; $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; - + $self->{aws_statistics} = ['Average']; if (defined($self->{option_results}->{statistic})) { $self->{aws_statistics} = []; diff --git a/centreon-plugins/efs/mode/discovery.pm b/centreon-plugins/cloud/aws/efs/mode/discovery.pm similarity index 94% rename from centreon-plugins/efs/mode/discovery.pm rename to centreon-plugins/cloud/aws/efs/mode/discovery.pm index f66982d8b..fc575bcaf 100644 --- a/centreon-plugins/efs/mode/discovery.pm +++ b/centreon-plugins/cloud/aws/efs/mode/discovery.pm @@ -30,11 +30,11 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { - "prettify" => { name => 'prettify' }, + 'prettify' => { name => 'prettify' } }); - + return $self; } @@ -87,7 +87,7 @@ sub run { if ($@) { $encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; } - + $self->{output}->output_add(short_msg => $encoded_data); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); $self->{output}->exit(); diff --git a/centreon-plugins/efs/plugin.pm b/centreon-plugins/cloud/aws/efs/plugin.pm similarity index 83% rename from centreon-plugins/efs/plugin.pm rename to centreon-plugins/cloud/aws/efs/plugin.pm index 1921b281a..4b8f112bd 100644 --- a/centreon-plugins/efs/plugin.pm +++ b/centreon-plugins/cloud/aws/efs/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{ $self->{modes} } = ( - 'connections' => 'cloud::aws::efs::mode::connections', - 'datausage' => 'cloud::aws::efs::mode::datausage', - 'discovery' => 'cloud::aws::efs::mode::discovery' + 'connections' => 'cloud::aws::efs::mode::connections', + 'datausage' => 'cloud::aws::efs::mode::datausage', + 'discovery' => 'cloud::aws::efs::mode::discovery' ); $self->{custom_modes}{paws} = 'cloud::aws::custom::paws'; diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm index 78c860212..bfc2a979e 100644 --- a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm @@ -235,7 +235,7 @@ sub filter_networks { } if (scalar(@$network_ids) > 5) { - $self->{output}->add_option_msg(short_msg => 'cannot check than 5 networks at once'); + $self->{output}->add_option_msg(short_msg => 'cannot check than 5 networks at once (api rate limit)'); $self->{output}->option_exit(); } From 0806fcf71d3ec27ab06d7684c0edb1ab251695ca Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 1 Apr 2020 10:00:18 +0200 Subject: [PATCH 037/190] fix cisco qos usage --- .../cisco/standard/snmp/mode/qosusage.pm | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/qosusage.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/qosusage.pm index 55f357544..79708b47f 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/qosusage.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/qosusage.pm @@ -363,9 +363,21 @@ sub manage_selection { my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cbQosCMStatsEntry}, instance => $policy_index . '.' . $qos_object_index); my $traffic_usage = (defined($result->{cbQosCMPostPolicyByte64}) && $result->{cbQosCMPostPolicyByte64} =~ /[1-9]/) ? - $result->{cbQosCMPostPolicyByte64} : (($result->{cbQosCMPostPolicyByteOverflow} << 32) + $result->{cbQosCMPostPolicyByte}); - my $drop_usage = (defined($result->{cbQosCMDropByte64}) && $result->{cbQosCMDropByte64} =~ /[1-9]/) ? - $result->{cbQosCMDropByte64} : (($result->{cbQosCMDropByteOverflow} << 32) + $result->{cbQosCMDropByte}); + $result->{cbQosCMPostPolicyByte64} : + ( + ($result->{cbQosCMPostPolicyByteOverflow} == 4294967295) ? + undef : + ($result->{cbQosCMPostPolicyByteOverflow} * 4294967295 + $result->{cbQosCMPostPolicyByte}) + ); + my $drop_usage = + (defined($result->{cbQosCMDropByte64}) && $result->{cbQosCMDropByte64} =~ /[1-9]/) ? + $result->{cbQosCMDropByte64} : + ( + ($result->{cbQosCMDropByteOverflow} == 4294967295) ? + undef : + ($result->{cbQosCMDropByteOverflow} * 4294967295 + $result->{cbQosCMDropByte}) + ); + my $total = 'unknown'; if (defined($qos_data->{shaping})) { my $result_shaping = $options{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$oid_cbQosTSCfgEntry}, instance => $qos_data->{shaping}); @@ -374,8 +386,8 @@ sub manage_selection { $self->{interface_classmap}->{$policy_index . '.' . $qos_object_index} = { display => $name, - traffic_usage => $traffic_usage * 8, - drop_usage => $drop_usage * 8, + traffic_usage => defined($traffic_usage) ? $traffic_usage * 8 : undef, + drop_usage => defined($drop_usage) ? $drop_usage * 8 : undef, total => $total }; @@ -385,12 +397,12 @@ sub manage_selection { } $self->{classmap}->{$name} = { display => $class_name, drop_usage => 0, traffic_usage => 0} if (!defined($self->{classmap}->{$name})); - $self->{classmap}->{$name}->{traffic_usage} += $traffic_usage * 8; - $self->{classmap}->{$name}->{drop_usage} += $drop_usage * 8; + $self->{classmap}->{$name}->{traffic_usage} += defined($traffic_usage) ? $traffic_usage * 8 : 0; + $self->{classmap}->{$name}->{drop_usage} += defined($drop_usage) ? $drop_usage * 8 : 0; if (!defined($tabname[3])){ - $self->{total}->{traffic_usage} += $traffic_usage * 8; - $self->{total}->{drop_usage} += $drop_usage * 8; + $self->{total}->{traffic_usage} += defined($traffic_usage) ? $traffic_usage * 8 : 0; + $self->{total}->{drop_usage} += defined($drop_usage) ? $drop_usage * 8 : 0; } } From 9f17efe2026fc5f7970b1baa7fb440433e04a730 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 1 Apr 2020 12:33:33 +0200 Subject: [PATCH 038/190] better management of multiple counters --- .../centreon/plugins/templates/counter.pm | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/centreon-plugins/centreon/plugins/templates/counter.pm b/centreon-plugins/centreon/plugins/templates/counter.pm index f17ad53bf..5b56573ea 100644 --- a/centreon-plugins/centreon/plugins/templates/counter.pm +++ b/centreon-plugins/centreon/plugins/templates/counter.pm @@ -309,7 +309,7 @@ sub run_instances { $self->{lproblems} = 0; $self->{multiple} = 1; - if (scalar(keys %{$self->{$options{config}->{name}}}) == 1) { + if (scalar(keys %{$self->{$options{config}->{name}}}) <= 1) { $self->{multiple} = 0; } @@ -401,7 +401,7 @@ sub run_group { my $multiple = 1; return if (scalar(keys %{$self->{$options{config}->{name}}}) <= 0); - if (scalar(keys %{$self->{$options{config}->{name}}}) == 1) { + if (scalar(keys %{$self->{$options{config}->{name}}}) <= 1) { $multiple = 0; } @@ -478,7 +478,7 @@ sub run_multiple_instances { my $no_message_multiple = 1; my $multiple = 1; - if (scalar(keys %{$self->{$options{config}->{name}}}) == 1) { + if (scalar(keys %{$self->{$options{config}->{name}}}) <= 1) { $multiple = 0; } @@ -580,13 +580,15 @@ sub run_multiple { my ($self, %options) = @_; my $multiple = 1; - if (scalar(keys %{$self->{$options{config}->{name}}}) == 1) { + if (scalar(keys %{$self->{$options{config}->{name}}}) <= 1) { $multiple = 0; } if ($multiple == 1) { - $self->{output}->output_add(severity => 'OK', - short_msg => $options{config}->{message_multiple}); + $self->{output}->output_add( + severity => 'OK', + short_msg => $options{config}->{message_multiple} + ); } foreach my $instance (sort keys %{$self->{$options{config}->{name}}}) { From f7b7fca73fb451c0ef28dabdef217258d10640e8 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 1 Apr 2020 12:34:04 +0200 Subject: [PATCH 039/190] wip: add meraki mode devices --- .../cloudcontroller/restapi/custom/api.pm | 130 +++++- .../cloudcontroller/restapi/mode/devices.pm | 372 ++++++++++++++++++ .../cloudcontroller/restapi/mode/networks.pm | 8 +- 3 files changed, 498 insertions(+), 12 deletions(-) create mode 100644 centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/devices.pm diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm index bfc2a979e..f846f6d12 100644 --- a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm @@ -116,10 +116,17 @@ sub get_token { sub get_cache_networks { my ($self, %options) = @_; - $self->cache_networks_organizations(); + $self->cache_meraki_entities(); return $self->{cache_networks}; } +sub get_cache_devices { + my ($self, %options) = @_; + + $self->cache_meraki_entities(); + return $self->{cache_devices}; +} + sub build_options_for_httplib { my ($self, %options) = @_; @@ -171,7 +178,7 @@ sub request_api { } while (1); } -sub cache_networks_organizations { +sub cache_meraki_entities { my ($self, %options) = @_; return if ($self->{cache_checked} == 1); @@ -181,16 +188,19 @@ sub cache_networks_organizations { my $timestamp_cache = $self->{cache}->get(name => 'last_timestamp'); $self->{cache_organizations} = $self->{cache}->get(name => 'organizations'); $self->{cache_networks} = $self->{cache}->get(name => 'networks'); + $self->{cache_devices} = $self->{cache}->get(name => 'devices'); if ($has_cache_file == 0 || !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{reload_cache_time}) * 60))) { $self->{cache_organizations} = {}; $self->{cache_organizations} = $self->get_organizations(disable_cache => 1); $self->{cache_networks} = $self->get_networks(organizations => [keys %{$self->{cache_organizations}}], disable_cache => 1); + $self->{cache_devices} = $self->get_devices(organizations => [keys %{$self->{cache_organizations}}], disable_cache => 1); $self->{cache}->write(data => { last_timestamp => time(), organizations => $self->{cache_organizations}, - networks => $self->{cache_networks} + networks => $self->{cache_networks}, + devices => $self->{cache_devices} }); } } @@ -198,7 +208,7 @@ sub cache_networks_organizations { sub get_organizations { my ($self, %options) = @_; - $self->cache_networks_organizations(); + $self->cache_meraki_entities(); return $self->{cache_organizations} if (!defined($options{disable_cache}) || $options{disable_cache} == 0); my $datas = $self->request_api(endpoint => '/organizations'); my $results = {}; @@ -210,7 +220,7 @@ sub get_organizations { sub get_networks { my ($self, %options) = @_; - $self->cache_networks_organizations(); + $self->cache_meraki_entities(); return $self->{cache_networks} if (!defined($options{disable_cache}) || $options{disable_cache} == 0); my $results = {}; @@ -222,6 +232,21 @@ sub get_networks { return $results; } +sub get_devices { + my ($self, %options) = @_; + + $self->cache_meraki_entities(); + return $self->{cache_devices} if (!defined($options{disable_cache}) || $options{disable_cache} == 0); + + my $results = {}; + foreach my $id (keys %{$self->{cache_organizations}}) { + my $datas = $self->request_api(endpoint => '/organizations/' . $id . '/devices'); + $results->{$_->{serial}} = $_ foreach (@$datas); + } + + return $results; +} + sub filter_networks { my ($self, %options) = @_; @@ -242,10 +267,25 @@ sub filter_networks { return $network_ids; } +sub filter_organizations { + my ($self, %options) = @_; + + my $organization_ids = []; + foreach (values %{$self->{cache_organizations}}) { + if (!defined($options{filter_name}) || $options{filter_name} eq '') { + push @$organization_ids, $_->{id}; + } elsif ($_->{name} =~ /$options{filter_name}/) { + push @$organization_ids, $_->{id}; + } + } + + return $organization_ids; +} + sub get_networks_connection_stats { my ($self, %options) = @_; - $self->cache_networks_organizations(); + $self->cache_meraki_entities(); my $network_ids = $self->filter_networks(filter_name => $options{filter_name}); my $timespan = defined($options{timespan}) ? $options{timespan} : 300; @@ -262,7 +302,7 @@ sub get_networks_connection_stats { sub get_networks_clients { my ($self, %options) = @_; - $self->cache_networks_organizations(); + $self->cache_meraki_entities(); my $network_ids = $self->filter_networks(filter_name => $options{filter_name}); my $timespan = defined($options{timespan}) ? $options{timespan} : 300; @@ -276,8 +316,82 @@ sub get_networks_clients { return $results; } -sub get_device_statuses { +sub get_organization_device_statuses { my ($self, %options) = @_; + + $self->cache_meraki_entities(); + my $organization_ids = $self->filter_organizations(filter_name => $options{filter_name}); + my $results = {}; + foreach my $id (@$organization_ids) { + my $datas = $self->request_api(endpoint => '/organizations/' . $id . '/deviceStatuses'); + foreach (@$datas) { + $results->{$_->{serial}} = $_; + $results->{organizationId} = $id; + } + } + + return $results; +} + +sub get_network_device_connection_stats { + my ($self, %options) = @_; + + if (scalar(keys %{$options{devices}}) > 5) { + $self->{output}->add_option_msg(short_msg => 'cannot check more than 5 devices at once (api rate limit)'); + $self->{output}->option_exit(); + } + + $self->cache_meraki_entities(); + my $timespan = defined($options{timespan}) ? $options{timespan} : 300; + $timespan = 1 if ($timespan <= 0); + + my $results = {}; + foreach (keys %{$options{devices}}) { + my $data = $self->request_api(endpoint => '/networks/' . $options{devices}->{$_} . '/devices/' . $_ . '/connectionStats?timespan=' . $options{timespan}); + $results->{$_} = $data; + } + + return $results; +} + +sub get_network_device_uplink { + my ($self, %options) = @_; + + if (scalar(keys %{$options{devices}}) > 5) { + $self->{output}->add_option_msg(short_msg => 'cannot check more than 5 devices at once (api rate limit)'); + $self->{output}->option_exit(); + } + + $self->cache_meraki_entities(); + + my $results = {}; + foreach (keys %{$options{devices}}) { + my $data = $self->request_api(endpoint => '/networks/' . $options{devices}->{$_} . '/devices/' . $_ . '/uplink'); + $results->{$_} = $data; + } + + return $results; +} + +sub get_device_clients { + my ($self, %options) = @_; + + if (scalar(keys %{$options{devices}}) > 5) { + $self->{output}->add_option_msg(short_msg => 'cannot check more than 5 devices at once (api rate limit)'); + $self->{output}->option_exit(); + } + + $self->cache_meraki_entities(); + my $timespan = defined($options{timespan}) ? $options{timespan} : 300; + $timespan = 1 if ($timespan <= 0); + + my $results = {}; + foreach (keys %{$options{devices}}) { + my $data = $self->request_api(endpoint => '/devices/' . $_ . '/clients?timespan=' . $options{timespan}); + $results->{$_} = $data; + } + + return $results; } 1; diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/devices.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/devices.pm new file mode 100644 index 000000000..26e46067d --- /dev/null +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/devices.pm @@ -0,0 +1,372 @@ +# +# 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 network::cisco::meraki::cloudcontroller::restapi::mode::devices; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use Digest::MD5 qw(md5_hex); + +sub custom_status_output { + my ($self, %options) = @_; + + return 'status: ' . $self->{result_values}->{status}; +} + +sub custom_link_status_output { + my ($self, %options) = @_; + + return 'status: ' . $self->{result_values}->{link_status}; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } }, + { name => 'devices', type => 3, cb_prefix_output => 'prefix_device_output', cb_long_output => 'device_long_output', indent_long_output => ' ', message_multiple => 'All devices are ok', + group => [ + { name => 'device_status', type => 0, skipped_code => { -10 => 1 } }, + { name => 'device_connections', type => 0, cb_prefix_output => 'prefix_connection_output', skipped_code => { -10 => 1 } }, + { name => 'device_traffic', type => 0, cb_prefix_output => 'prefix_traffic_output', skipped_code => { -10 => 1, -11 => 1 } }, + { name => 'device_links', display_long => 1, cb_prefix_output => 'prefix_link_output', message_multiple => 'All links are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total-online', nlabel => 'devices.total.online.count', display_ok => 0, set => { + key_values => [ { name => 'online'}, { name => 'total'} ], + output_template => 'online: %s', + perfdatas => [ + { value => 'online_absolute', template => '%s', min => 0, max => 'total_absolute' } + ] + } + }, + { label => 'total-offline', nlabel => 'devices.total.offline.count', display_ok => 0, set => { + key_values => [ { name => 'offline'}, { name => 'total'} ], + output_template => 'offline: %s', + perfdatas => [ + { value => 'offline_absolute', template => '%s', min => 0, max => 'total_absolute' } + ] + } + }, + { label => 'total-alerting', nlabel => 'devices.total.alerting.count', display_ok => 0, set => { + key_values => [ { name => 'alerting'}, { name => 'total'} ], + output_template => 'alerting: %s', + perfdatas => [ + { value => 'alerting_absolute', template => '%s', min => 0, max => 'total_absolute' } + ] + } + }, + ]; + + $self->{maps_counters}->{device_status} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + } + ]; + + $self->{maps_counters}->{device_connections} = [ + { label => 'connections-success', nlabel => 'device.connections.success.count', set => { + key_values => [ { name => 'assoc' }, { name => 'display' } ], + output_template => 'success: %s', + perfdatas => [ + { value => 'assoc_absolute', + template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + }, + { label => 'connections-auth', nlabel => 'device.connections.auth.count', display_ok => 0, set => { + key_values => [ { name => 'auth' }, { name => 'display' } ], + output_template => 'auth: %s', + perfdatas => [ + { value => 'auth_absolute', + template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + }, + { label => 'connections-assoc', nlabel => 'device.connections.assoc.count', display_ok => 0, set => { + key_values => [ { name => 'assoc' }, { name => 'display' } ], + output_template => 'assoc: %s', + perfdatas => [ + { value => 'assoc_absolute', + template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + }, + { label => 'connections-dhcp', nlabel => 'device.connections.dhcp.count', display_ok => 0, set => { + key_values => [ { name => 'dhcp' }, { name => 'display' } ], + output_template => 'dhcp: %s', + perfdatas => [ + { value => 'dhcp_absolute', + template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + }, + { label => 'connections-dns', nlabel => 'device.connections.dns.count', display_ok => 0, set => { + key_values => [ { name => 'dns' }, { name => 'display' } ], + output_template => 'dns: %s', + perfdatas => [ + { value => 'dns_absolute', + template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + } + ]; + + $self->{maps_counters}->{device_traffic} = [ + { label => 'traffic-in', nlabel => 'device.traffic.in.bitspersecond', set => { + key_values => [ { name => 'traffic_in', diff => 1 }, { name => 'display' } ], + output_template => 'in: %s %s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_in_per_second', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' } + ] + } + }, + { label => 'traffic-out', nlabel => 'device.traffic.out.bitspersecond', set => { + key_values => [ { name => 'traffic_out', diff => 1 }, { name => 'display' } ], + output_template => 'out: %s %s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_out_per_second', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' } + ] + } + } + ]; + + $self->{maps_counters}->{device_links} = [ + { label => 'link-status', threshold => 0, set => { + key_values => [ { name => 'link_status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_link_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + } + ]; +} + +sub device_long_output { + my ($self, %options) = @_; + + return "checking device '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_device_output { + my ($self, %options) = @_; + + return "Device '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return 'Devices '; +} + +sub prefix_connection_output { + my ($self, %options) = @_; + + return 'connection '; +} + +sub prefix_traffic_output { + my ($self, %options) = @_; + + return 'traffic '; +} + +sub prefix_link_output { + my ($self, %options) = @_; + + return "link '" . $options{instance_value}->{display} . "' "; +} + +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} =~ /alerting/i' }, + 'unknown-link-status:s' => { name => 'unknown_link_status', default => '' }, + 'warning-link-status:s' => { name => 'warning_link_status', default => '' }, + 'critical-link-status:s' => { name => 'critical_link_status', default => '%{link_status} =~ /failed/i' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => [ + 'unknown_status', 'warning_status', 'critical_status', + 'unknown_link_status', 'warning_link_status', 'critical_link_status' + ]); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{cache_name} = 'meraki_' . $self->{mode} . '_' . $options{custom}->get_token() . '_' . + (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')); + my $last_timestamp = $self->read_statefile_key(key => 'last_timestamp'); + my $timespan = 300; + $timespan = time() - $last_timestamp if (defined($last_timestamp)); + + my $cache_devices = $options{custom}->get_cache_devices(); + my $devices = {}; + foreach (values %$cache_devices) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $_->{name} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping device '" . $_->{name} . "': no matching filter.", debug => 1); + next; + } + + $devices->{$_->{serial}} = $_->{networkId}; + } + + my $device_statuses = $options{custom}->get_organization_device_statuses(); + my $connections = $options{custom}->get_network_device_connection_stats(timespan => $timespan, devices => $devices); + my $clients = $options{custom}->get_device_clients(timespan => $timespan, devices => $devices); + my $links = $options{custom}->get_network_device_uplink(devices => $devices); + + $self->{global} = { total => 0, online => 0, offline => 0, alerting => 0 }; + $self->{devices} = {}; + foreach my $serial (keys %$devices) { + $self->{devices}->{$serial} = { + display => $cache_devices->{$serial}->{name}, + device_status => { + display => $cache_devices->{$serial}->{name}, + status => $device_statuses->{$serial}->{status} + }, + device_connections => { + display => $cache_devices->{$serial}->{name}, + assoc => defined($connections->{$serial}->{assoc}) ? $connections->{$serial}->{assoc} : 0, + auth => defined($connections->{$serial}->{auth}) ? $connections->{$serial}->{auth} : 0, + dhcp => defined($connections->{$serial}->{dhcp}) ? $connections->{$serial}->{dhcp} : 0, + dns => defined($connections->{$serial}->{dns}) ? $connections->{$serial}->{dns} : 0, + success => defined($connections->{$serial}->{assoc}) ? $connections->{$serial}->{success} : 0, + }, + device_traffic => { + display => $cache_devices->{$serial}->{name}, + traffic_in => 0, + traffic_out => 0 + }, + device_links => {} + }; + + if (defined($clients->{$serial})) { + foreach (@{$clients->{$serial}}) { + $self->{devices}->{$serial}->{device_traffic}->{traffic_in} += $_->{usage}->{recv} * 8; + $self->{devices}->{$serial}->{device_traffic}->{traffic_out} += $_->{usage}->{sent} * 8; + } + } + + if (defined($links->{$serial})) { + foreach (@{$links->{$serial}}) { + $self->{devices}->{$serial}->{device_links}->{$_->{interface}} = { + display => $_->{interface}, + link_status => lc($_->{status}) + }; + } + } + + $self->{global}->{total}++; + $self->{global}->{ lc($device_statuses->{$serial}->{status}) }++ + if (!defined($self->{global}->{ lc($device_statuses->{$serial}->{status}) })) + } + + if (scalar(keys %{$self->{devices}}) <= 0) { + $self->{output}->output_add(short_msg => 'no devices found'); + } +} + +1; + +__END__ + +=head1 MODE + +Check devices. + +=over 8 + +=item B<--filter-name> + +Filter device 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} =~ /alerting/i'). +Can used special variables like: %{status}, %{display} + +=item B<--unknown-link-status> + +Set unknown threshold for status. +Can used special variables like: %{link_status}, %{display} + +=item B<--warning-link-status> + +Set warning threshold for status. +Can used special variables like: %{link_status}, %{display} + +=item B<--critical-link-status> + +Set critical threshold for status (Default: '%{link_status} =~ /failed/i'). +Can used special variables like: %{link_status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'connections-success', 'connections-auth', 'connections-assoc', +'connections-dhcp', 'connections-dns', 'traffic-in', 'traffic-out'. + +=back + +=cut diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/networks.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/networks.pm index ce53e1e7a..4960262ba 100644 --- a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/networks.pm +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/networks.pm @@ -139,10 +139,10 @@ sub manage_selection { $self->{networks}->{$id} = { display => $cache_networks->{$id}->{name}, assoc => defined($connections->{$id}->{assoc}) ? $connections->{$id}->{assoc} : 0, - auth => defined($connections->{$id}->{assoc}) ? $connections->{$id}->{auth} : 0, - dhcp => defined($connections->{$id}->{assoc}) ? $connections->{$id}->{assoc} : 0, - dns => defined($connections->{$id}->{assoc}) ? $connections->{$id}->{dhcp} : 0, - success => defined($connections->{$id}->{assoc}) ? $connections->{$id}->{success} : 0, + auth => defined($connections->{$id}->{auth}) ? $connections->{$id}->{auth} : 0, + dhcp => defined($connections->{$id}->{dhcp}) ? $connections->{$id}->{dhcp} : 0, + dns => defined($connections->{$id}->{dns}) ? $connections->{$id}->{dns} : 0, + success => defined($connections->{$id}->{success}) ? $connections->{$id}->{success} : 0, traffic_in => 0, traffic_out => 0 }; From 7d1754c1cdc2bd46412fbcdd748a0d7ff01884a1 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 1 Apr 2020 13:42:24 +0200 Subject: [PATCH 040/190] wip: add cisco meraki api requests --- .../cloudcontroller/restapi/custom/api.pm | 23 +++ .../restapi/mode/apirequests.pm | 136 ++++++++++++++++++ .../meraki/cloudcontroller/restapi/plugin.pm | 5 +- 3 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/apirequests.pm diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm index f846f6d12..6e866a2f6 100644 --- a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm @@ -113,6 +113,13 @@ sub get_token { return md5_hex($self->{api_token}); } +sub get_cache_organizations { + my ($self, %options) = @_; + + $self->cache_meraki_entities(); + return $self->{cache_organizations}; +} + sub get_cache_networks { my ($self, %options) = @_; @@ -333,6 +340,22 @@ sub get_organization_device_statuses { return $results; } +sub get_organization_api_requests_overview { + my ($self, %options) = @_; + + $self->cache_meraki_entities(); + my $organization_ids = $self->filter_organizations(filter_name => $options{filter_name}); + my $timespan = defined($options{timespan}) ? $options{timespan} : 300; + $timespan = 1 if ($timespan <= 0); + + my $results = {}; + foreach my $id (@$organization_ids) { + $results->{$id} = $self->request_api(endpoint => '/organizations/' . $id . '/apiRequests/overview?timespan=' . $options{timespan}); + } + + return $results; +} + sub get_network_device_connection_stats { my ($self, %options) = @_; diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/apirequests.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/apirequests.pm new file mode 100644 index 000000000..b738ea9db --- /dev/null +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/apirequests.pm @@ -0,0 +1,136 @@ +# +# 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 network::cisco::meraki::cloudcontroller::restapi::mode::apirequests; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'organizations', type => 1, cb_prefix_output => 'prefix_organization_output', message_multiple => 'All organizations are ok' } + ]; + + $self->{maps_counters}->{organizations} = [ + { label => 'api-requests-200', nlabel => 'organization.api.requests.200.count', set => { + key_values => [ { name => 'requests_200' }, { name => 'display' } ], + output_template => 'code 200: %s', + perfdatas => [ + { value => 'requests_200_absolute', + template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + }, + { label => 'api-requests-404', nlabel => 'organization.api.requests.404.count', set => { + key_values => [ { name => 'requests_404' }, { name => 'display' } ], + output_template => 'code 404: %s', + perfdatas => [ + { value => 'requests_404_absolute', + template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + }, + { label => 'api-requests-429', nlabel => 'organization.api.requests.429.count', set => { + key_values => [ { name => 'requests_429' }, { name => 'display' } ], + output_template => 'code 429: %s', + perfdatas => [ + { value => 'requests_429_absolute', + template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + } + ]; +} + +sub prefix_organization_output { + my ($self, %options) = @_; + + return "Organization '" . $options{instance_value}->{display} . "' requests "; +} + +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' } + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{cache_name} = 'meraki_' . $self->{mode} . '_' . $options{custom}->get_token() . '_' . + (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')); + my $last_timestamp = $self->read_statefile_key(key => 'last_timestamp'); + my $timespan = 300; + $timespan = time() - $last_timestamp if (defined($last_timestamp)); + + my $cache_organizations = $options{custom}->get_cache_organizations(); + my $api_requests = $options{custom}->get_organization_api_requests_overview(timespan => $timespan, filter_name => $self->{option_results}->{filter_name}); + + $self->{organizations} = {}; + foreach my $id (keys %$api_requests) { + $self->{organizations}->{$id} = { + display => $cache_organizations->{$id}->{name}, + requests_200 => defined($api_requests->{$id}->{responseCodeCounts}->{200}) ? $api_requests->{$id}->{responseCodeCounts}->{200} : 0, + requests_404 => defined($api_requests->{$id}->{responseCodeCounts}->{404}) ? $api_requests->{$id}->{responseCodeCounts}->{404} : 0, + requests_429 => defined($api_requests->{$id}->{responseCodeCounts}->{429}) ? $api_requests->{$id}->{responseCodeCounts}->{429} : 0, + }; + } + + if (scalar(keys %{$self->{organizations}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No organizations found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check api requests. + +=over 8 + +=item B<--filter-name> + +Filter organization name (Can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'connections-success', 'connections-auth', 'connections-assoc', +'connections-dhcp', 'connections-dns', 'traffic-in', 'traffic-out'. + +=back + +=cut diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/plugin.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/plugin.pm index ed31ce585..136e24225 100644 --- a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/plugin.pm +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/plugin.pm @@ -31,8 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'devices' => 'network::cisco::meraki::cloudcontroller::restapi::mode::devices', - 'networks' => 'network::cisco::meraki::cloudcontroller::restapi::mode::networks' + 'api-requests' => 'network::cisco::meraki::cloudcontroller::restapi::mode::apirequests', + 'devices' => 'network::cisco::meraki::cloudcontroller::restapi::mode::devices', + 'networks' => 'network::cisco::meraki::cloudcontroller::restapi::mode::networks' ); $self->{custom_modes}{api} = 'network::cisco::meraki::cloudcontroller::restapi::custom::api'; From 57d79b5d164c4f38c541e287d030bb5282c949f1 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 1 Apr 2020 13:43:38 +0200 Subject: [PATCH 041/190] wip: add cisco meraki api requests --- .../cisco/meraki/cloudcontroller/restapi/mode/apirequests.pm | 3 +-- .../cisco/meraki/cloudcontroller/restapi/mode/devices.pm | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/apirequests.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/apirequests.pm index b738ea9db..d40159f41 100644 --- a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/apirequests.pm +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/apirequests.pm @@ -128,8 +128,7 @@ Filter organization name (Can be a regexp). =item B<--warning-*> B<--critical-*> Thresholds. -Can be: 'connections-success', 'connections-auth', 'connections-assoc', -'connections-dhcp', 'connections-dns', 'traffic-in', 'traffic-out'. +Can be: 'api-requests-200', 'api-requests-404', 'api-requests-429'. =back diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/devices.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/devices.pm index 26e46067d..8a7bdb35e 100644 --- a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/devices.pm +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/devices.pm @@ -364,8 +364,9 @@ Can used special variables like: %{link_status}, %{display} =item B<--warning-*> B<--critical-*> Thresholds. -Can be: 'connections-success', 'connections-auth', 'connections-assoc', -'connections-dhcp', 'connections-dns', 'traffic-in', 'traffic-out'. +Can be: 'total-online', 'total-offline', 'total-alerting', +'traffic-in', 'traffic-out', 'connections-success', 'connections-auth', +'connections-assoc', 'connections-dhcp', 'connections-dns'. =back From c8f6a8f3b2096c7588ebf4247c0b835b48832686 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 1 Apr 2020 14:54:09 +0200 Subject: [PATCH 042/190] add discovery for meraki rest api --- .../cloudcontroller/restapi/mode/discovery.pm | 114 ++++++++++++++++++ .../meraki/cloudcontroller/restapi/plugin.pm | 1 + 2 files changed, 115 insertions(+) create mode 100644 centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/discovery.pm diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/discovery.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/discovery.pm new file mode 100644 index 000000000..2ceffee3c --- /dev/null +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/discovery.pm @@ -0,0 +1,114 @@ +# +# 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 network::cisco::meraki::cloudcontroller::restapi::mode::discovery; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'prettify' => { name => 'prettify' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + + my (@disco_data, $disco_stats); + $disco_stats->{start_time} = time(); + + my $organizations = $options{custom}->get_organizations(disable_cache => 1); + my $networks = $options{custom}->get_networks(organizations => [keys %{$self->{organizations}}], disable_cache => 1); + my $devices = $options{custom}->get_devices(organizations => [keys %{$self->{organizations}}], disable_cache => 1); + my $devices_statuses = $options{custom}->get_organization_device_statuses(); + + $disco_stats->{end_time} = time(); + $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; + + foreach (values %$devices) { + my $node = { + %$_, + %{$devices_statuses->{$_->{serial}}}, + networkName => $networks->{ $devices_statuses->{$_->{serial}}->{networkId} }->{name}, + organizationName => $organizations->{ $networks->{ $devices_statuses->{$_->{serial}}->{networkId} }->{organizationId} }->{name}, + type => 'device' + }; + + push @disco_data, $node; + } + + foreach (values %$networks) { + my $node = { + %$_, + organizationName => $organizations->{ $_->{organizationId} }->{name}, + type => 'network' + }; + + push @disco_data, $node; + } + + $disco_stats->{discovered_items} = @disco_data; + $disco_stats->{results} = \@disco_data; + + my $encoded_data; + eval { + if (defined($self->{option_results}->{prettify})) { + $encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats); + } else { + $encoded_data = JSON::XS->new->utf8->encode($disco_stats); + } + }; + if ($@) { + $encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; + } + + $self->{output}->output_add(short_msg => $encoded_data); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Resources discovery. + +=over 8 + +=back + +=cut diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/plugin.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/plugin.pm index 136e24225..30e023dbf 100644 --- a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/plugin.pm +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/plugin.pm @@ -33,6 +33,7 @@ sub new { %{$self->{modes}} = ( 'api-requests' => 'network::cisco::meraki::cloudcontroller::restapi::mode::apirequests', 'devices' => 'network::cisco::meraki::cloudcontroller::restapi::mode::devices', + 'discovery' => 'network::cisco::meraki::cloudcontroller::restapi::mode::discovery', 'networks' => 'network::cisco::meraki::cloudcontroller::restapi::mode::networks' ); From ec9437b733f257e25b05d30b07fd8fa5d5c19b92 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 1 Apr 2020 15:03:13 +0200 Subject: [PATCH 043/190] update variable filter meraki --- .../meraki/cloudcontroller/restapi/mode/devices.pm | 10 +++++----- .../meraki/cloudcontroller/restapi/mode/networks.pm | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/devices.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/devices.pm index 8a7bdb35e..db4ad3088 100644 --- a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/devices.pm +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/devices.pm @@ -217,7 +217,7 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'filter-name:s' => { name => 'filter_name' }, + 'filter-device-name:s' => { name => 'filter_device_name' }, 'unknown-status:s' => { name => 'unknown_status', default => '' }, 'warning-status:s' => { name => 'warning_status', default => '' }, 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /alerting/i' }, @@ -244,7 +244,7 @@ sub manage_selection { $self->{cache_name} = 'meraki_' . $self->{mode} . '_' . $options{custom}->get_token() . '_' . (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')); + (defined($self->{option_results}->{filter_device_name}) ? md5_hex($self->{option_results}->{filter_device_name}) : md5_hex('all')); my $last_timestamp = $self->read_statefile_key(key => 'last_timestamp'); my $timespan = 300; $timespan = time() - $last_timestamp if (defined($last_timestamp)); @@ -252,8 +252,8 @@ sub manage_selection { my $cache_devices = $options{custom}->get_cache_devices(); my $devices = {}; foreach (values %$cache_devices) { - if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $_->{name} !~ /$self->{option_results}->{filter_name}/) { + if (defined($self->{option_results}->{filter_device_name}) && $self->{option_results}->{filter_device_name} ne '' && + $_->{name} !~ /$self->{option_results}->{filter_device_name}/) { $self->{output}->output_add(long_msg => "skipping device '" . $_->{name} . "': no matching filter.", debug => 1); next; } @@ -327,7 +327,7 @@ Check devices. =over 8 -=item B<--filter-name> +=item B<--filter-device-name> Filter device name (Can be a regexp). diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/networks.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/networks.pm index 4960262ba..64e53ef5e 100644 --- a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/networks.pm +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/networks.pm @@ -114,7 +114,7 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'filter-name:s' => { name => 'filter_name' } + 'filter-network-name:s' => { name => 'filter_network_name' } }); return $self; @@ -125,14 +125,14 @@ sub manage_selection { $self->{cache_name} = 'meraki_' . $self->{mode} . '_' . $options{custom}->get_token() . '_' . (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')); + (defined($self->{option_results}->{filter_network_name}) ? md5_hex($self->{option_results}->{filter_network_name}) : md5_hex('all')); my $last_timestamp = $self->read_statefile_key(key => 'last_timestamp'); my $timespan = 300; $timespan = time() - $last_timestamp if (defined($last_timestamp)); my $cache_networks = $options{custom}->get_cache_networks(); - my $connections = $options{custom}->get_networks_connection_stats(timespan => $timespan, filter_name => $self->{option_results}->{filter_name}); - my $clients = $options{custom}->get_networks_clients(timespan => $timespan, filter_name => $self->{option_results}->{filter_name}); + my $connections = $options{custom}->get_networks_connection_stats(timespan => $timespan, filter_name => $self->{option_results}->{filter_network_name}); + my $clients = $options{custom}->get_networks_clients(timespan => $timespan, filter_name => $self->{option_results}->{filter_network_name}); $self->{networks} = {}; foreach my $id (keys %$connections) { @@ -170,7 +170,7 @@ Check networks. =over 8 -=item B<--filter-name> +=item B<--filter-network-name> Filter network name (Can be a regexp). From 72d67fad6b7533b1e31b877a13a43eacf95a4f8f Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 1 Apr 2020 15:04:24 +0200 Subject: [PATCH 044/190] update variable filter meraki --- .../meraki/cloudcontroller/restapi/mode/apirequests.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/apirequests.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/apirequests.pm index d40159f41..092c91dda 100644 --- a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/apirequests.pm +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/apirequests.pm @@ -76,7 +76,7 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'filter-name:s' => { name => 'filter_name' } + 'filter-organization-name:s' => { name => 'filter_organization_name' } }); return $self; @@ -87,13 +87,13 @@ sub manage_selection { $self->{cache_name} = 'meraki_' . $self->{mode} . '_' . $options{custom}->get_token() . '_' . (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')); + (defined($self->{option_results}->{filter_organization_name}) ? md5_hex($self->{option_results}->{filter_organization_name}) : md5_hex('all')); my $last_timestamp = $self->read_statefile_key(key => 'last_timestamp'); my $timespan = 300; $timespan = time() - $last_timestamp if (defined($last_timestamp)); my $cache_organizations = $options{custom}->get_cache_organizations(); - my $api_requests = $options{custom}->get_organization_api_requests_overview(timespan => $timespan, filter_name => $self->{option_results}->{filter_name}); + my $api_requests = $options{custom}->get_organization_api_requests_overview(timespan => $timespan, filter_name => $self->{option_results}->{filter_organization_name}); $self->{organizations} = {}; foreach my $id (keys %$api_requests) { @@ -121,7 +121,7 @@ Check api requests. =over 8 -=item B<--filter-name> +=item B<--filter-organization-name> Filter organization name (Can be a regexp). From f351a4bb2e2d88b730ba369227568837455c3e37 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 1 Apr 2020 17:39:51 +0200 Subject: [PATCH 045/190] enhance indent --- .../database/oracle/mode/rmanbackupage.pm | 66 +++++++++++-------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/centreon-plugins/database/oracle/mode/rmanbackupage.pm b/centreon-plugins/database/oracle/mode/rmanbackupage.pm index afd2b6d98..25bd09c06 100644 --- a/centreon-plugins/database/oracle/mode/rmanbackupage.pm +++ b/centreon-plugins/database/oracle/mode/rmanbackupage.pm @@ -30,22 +30,22 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { - "skip-no-backup" => { name => 'skip_no_backup', }, - "filter-type:s" => { name => 'filter_type', }, - "timezone:s" => { name => 'timezone', }, - "incremental-level" => { name => 'incremental_level', }, + 'skip-no-backup' => { name => 'skip_no_backup', }, + 'filter-type:s' => { name => 'filter_type', }, + 'timezone:s' => { name => 'timezone', }, + 'incremental-level' => { name => 'incremental_level', }, }); foreach (('db incr', 'db full', 'archivelog', 'controlfile')) { my $label = $_; $label =~ s/ /-/g; $options{options}->add_options(arguments => { - 'warning-' . $label . ':s' => { name => 'warning-' . $label }, - 'critical-' . $label . ':s' => { name => 'critical-' . $label }, - 'no-' . $label => { name => 'no-' . $label }, - }); + 'warning-' . $label . ':s' => { name => 'warning-' . $label }, + 'critical-' . $label . ':s' => { name => 'critical-' . $label }, + 'no-' . $label => { name => 'no-' . $label }, + }); } return $self; @@ -69,7 +69,7 @@ sub check_options { if (defined($self->{option_results}->{timezone}) && $self->{option_results}->{timezone} ne '') { $ENV{TZ} = $self->{option_results}->{timezone}; } - + if (defined($self->{option_results}->{incremental_level})) { # the special request don't retrieve controlfiles. But controlfiles are saved with archivelog. $self->{option_results}->{'no-controlfile'} = 1; @@ -135,13 +135,13 @@ sub run { my @values = localtime($last_time); my $dt = DateTime->new( - year => $values[5] + 1900, - month => $values[4] + 1, - day => $values[3], - hour => $values[2], - minute => $values[1], - second => $values[0], - time_zone => 'UTC', + year => $values[5] + 1900, + month => $values[4] + 1, + day => $values[3], + hour => $values[2], + minute => $values[1], + second => $values[0], + time_zone => 'UTC' ); my $offset = $last_time - $dt->epoch; $last_time = $last_time + $offset; @@ -152,29 +152,37 @@ sub run { my $type_perfdata = $type; $type_perfdata =~ s/ /_/g; $self->{output}->output_add(long_msg => sprintf("Last Rman '%s' backups : %s", $type, $backup_age_convert)); - $self->{output}->perfdata_add(label => sprintf('%s_backup_age', $type_perfdata), - value => $backup_age, - unit => 's', - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $label), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $label), - min => 0); + $self->{output}->perfdata_add( + label => sprintf('%s_backup_age', $type_perfdata), + value => $backup_age, + unit => 's', + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $label), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $label), + min => 0 + ); my $exit_code = $self->{perfdata}->threshold_check(value => $backup_age, threshold => [ { label => 'critical-' . $label, exit_litteral => 'critical' }, { label => 'warning-' . $label, exit_litteral => 'warning' } ]); if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("Last Rman '%s' backups : %s", $type, $backup_age_convert)); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf("Last Rman '%s' backups : %s", $type, $backup_age_convert) + ); } } if ($executed == 0 && !defined($self->{option_results}->{'no-' . $label})) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Rman '%s' backups never executed", uc($_))); + $self->{output}->output_add( + severity => 'CRITICAL', + short_msg => sprintf("Rman '%s' backups never executed", uc($_)) + ); } } if (($count_backups == 0) && (!defined($self->{option_results}->{skip_no_backup}))) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Rman backups never executed.")); + $self->{output}->output_add( + severity => 'CRITICAL', + short_msg => sprintf("Rman backups never executed.") + ); } $self->{output}->display(); From 4e8d3621a2c16573985fd8a54966121a5ac293d0 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 2 Apr 2020 09:44:06 +0200 Subject: [PATCH 046/190] Fix #1908 --- .../snmp_standard/mode/diskusage.pm | 62 ++++++++++--------- .../snmp_standard/mode/storage.pm | 62 +++++++++++-------- 2 files changed, 68 insertions(+), 56 deletions(-) diff --git a/centreon-plugins/snmp_standard/mode/diskusage.pm b/centreon-plugins/snmp_standard/mode/diskusage.pm index 850438f35..a4a5824c0 100644 --- a/centreon-plugins/snmp_standard/mode/diskusage.pm +++ b/centreon-plugins/snmp_standard/mode/diskusage.pm @@ -33,11 +33,12 @@ sub custom_usage_output { my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}); my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}); - my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_absolute}, - $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_absolute}); - return $msg; + return sprintf( + 'Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)', + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_absolute}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_absolute} + ); } sub set_counters { @@ -53,10 +54,10 @@ sub set_counters { key_values => [ { name => 'count' } ], output_template => 'Partitions count : %d', perfdatas => [ - { label => 'count', value => 'count_absolute', template => '%d', min => 0 }, - ], + { label => 'count', value => 'count_absolute', template => '%d', min => 0 } + ] } - }, + } ]; $self->{maps_counters}->{diskpath} = [ @@ -65,8 +66,8 @@ sub set_counters { closure_custom_output => $self->can('custom_usage_output'), perfdatas => [ { label => 'used', value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', - unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' } + ] } }, { label => 'usage-free', display_ok => 0, nlabel => 'storage.space.free.bytes', set => { @@ -74,8 +75,8 @@ sub set_counters { closure_custom_output => $self->can('custom_usage_output'), perfdatas => [ { label => 'free', value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', - unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' } + ] } }, { label => 'usage-prct', display_ok => 0, nlabel => 'storage.space.usage.percentage', set => { @@ -83,8 +84,8 @@ sub set_counters { output_template => 'Used : %.2f %%', perfdatas => [ { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, - unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' } + ] } }, { label => 'inodes', nlabel => 'storage.inodes.usage.percentage', set => { @@ -92,10 +93,10 @@ sub set_counters { output_template => 'Inodes Used: %s %%', perfdatas => [ { label => 'inodes', value => 'inodes_absolute', template => '%d', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' } + ] } - }, + } ]; } @@ -179,16 +180,18 @@ sub manage_selection { my $name_diskpath = $self->get_display_value(id => $_); if (!defined($result->{$oid_dskTotalHigh . "." . $_})) { - $self->{output}->add_option_msg(long_msg => sprintf( - "skipping partition '%s': not found (need to reload the cache)", - $name_diskpath) + $self->{output}->add_option_msg( + long_msg => sprintf( + "skipping partition '%s': not found (need to reload the cache)", + $name_diskpath + ) ); next; } my $total_size = (($result->{$oid_dskTotalHigh . "." . $_} << 32) + $result->{$oid_dskTotalLow . "." . $_}) * 1024; if ($total_size == 0) { - $self->{output}->output_add(long_msg => sprintf("skipping partition '%s' (total size is 0)", $name_diskpath)); + $self->{output}->output_add(long_msg => sprintf("skipping partition '%s' (total size is 0)", $name_diskpath), debug => 1); next; } my $total_used = (($result->{$oid_dskUsedHigh . "." . $_} << 32) + $result->{$oid_dskUsedLow . "." . $_}) * 1024; @@ -221,7 +224,7 @@ sub manage_selection { } if (scalar(keys %{$self->{diskpath}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "Issue with disk path information (see details)"); + $self->{output}->add_option_msg(short_msg => 'Issue with disk path information (see details)'); $self->{output}->option_exit(); } } @@ -232,9 +235,9 @@ sub reload_cache { $datas->{last_timestamp} = time(); $datas->{all_ids} = []; - + my $oid_dskPath = '.1.3.6.1.4.1.2021.9.1.2'; - + my $result = $self->{snmp}->get_table(oid => $oid_dskPath); foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$result})) { next if ($key !~ /\.([0-9]+)$/); @@ -270,11 +273,11 @@ sub get_selection { my $all_ids = $self->{statefile_cache}->get(name => 'all_ids'); if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{diskpath})) { # get by ID - my $name = $self->{statefile_cache}->get(name => "dskPath_" . $self->{option_results}->{diskpath}); + my $name = $self->{statefile_cache}->get(name => 'dskPath_' . $self->{option_results}->{diskpath}); push @{$self->{diskpath_id_selected}}, $self->{option_results}->{diskpath} if (defined($name)); } else { foreach my $i (@{$all_ids}) { - my $filter_name = $self->{statefile_cache}->get(name => "dskPath_" . $i); + my $filter_name = $self->{statefile_cache}->get(name => 'dskPath_' . $i); next if (!defined($filter_name)); if (!defined($self->{option_results}->{diskpath})) { @@ -292,7 +295,7 @@ sub get_selection { } } } - + if (scalar(@{$self->{diskpath_id_selected}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No disk path found. Can be: filters, cache file."); $self->{output}->option_exit(); @@ -301,12 +304,13 @@ sub get_selection { sub get_display_value { my ($self, %options) = @_; - my $value = $self->{statefile_cache}->get(name => "dskPath_" . $options{id}); - + my $value = $self->{statefile_cache}->get(name => 'dskPath_' . $options{id}); + if (defined($self->{option_results}->{display_transform_src})) { $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst})); eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}"; } + return $value; } diff --git a/centreon-plugins/snmp_standard/mode/storage.pm b/centreon-plugins/snmp_standard/mode/storage.pm index f1269077d..9321f5c29 100644 --- a/centreon-plugins/snmp_standard/mode/storage.pm +++ b/centreon-plugins/snmp_standard/mode/storage.pm @@ -106,7 +106,13 @@ sub custom_usage_threshold { $threshold_value = $self->{result_values}->{prct_used}; $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->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } ]); + $exit = $self->{perfdata}->threshold_check( + value => $threshold_value, + threshold => [ + { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, + { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } + ] + ); return $exit; } @@ -116,11 +122,12 @@ sub custom_usage_output { my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); - my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, - $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); - return $msg; + return sprintf( + 'Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)', + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free} + ); } sub custom_usage_calc { @@ -160,19 +167,19 @@ sub custom_access_output { sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'global', type => 0 }, { name => 'storage', type => 1, cb_prefix_output => 'prefix_storage_output', message_multiple => 'All storages are ok', skipped_code => { -10 => 1 } }, ]; - + $self->{maps_counters}->{global} = [ { label => 'count', nlabel => 'storage.partitions.count', display_ok => 0, set => { key_values => [ { name => 'count' } ], output_template => 'Partitions count : %d', perfdatas => [ - { label => 'count', value => 'count_absolute', template => '%d', min => 0 }, - ], + { label => 'count', value => 'count_absolute', template => '%d', min => 0 } + ] } }, ]; @@ -183,7 +190,7 @@ sub set_counters { closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_output => $self->can('custom_usage_output'), closure_custom_perfdata => $self->can('custom_usage_perfdata'), - closure_custom_threshold_check => $self->can('custom_usage_threshold'), + closure_custom_threshold_check => $self->can('custom_usage_threshold') } }, { label => 'access', nlabel => 'storage.access', set => { @@ -191,22 +198,22 @@ sub set_counters { closure_custom_output => $self->can('custom_access_output'), perfdatas => [ { label => 'access', value => 'access_absolute', template => '%d', min => 1, max => 2, - label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + label_extra_instance => 1, instance_use => 'display_absolute' } + ] } - }, + } ]; } sub prefix_storage_output { my ($self, %options) = @_; - + return "Storage '" . $options{instance_value}->{display} . "' "; } sub default_storage_type { my ($self, %options) = @_; - + return '^(hrStorageFixedDisk|hrStorageNetworkDisk|hrFSBerkeleyFFS)$'; } @@ -214,7 +221,7 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { 'units:s' => { name => 'units', default => '%' }, 'free' => { name => 'free' }, @@ -235,7 +242,7 @@ sub new { $self->{storage_id_selected} = []; $self->{statefile_cache} = centreon::plugins::statefile->new(%options); - + return $self; } @@ -248,7 +255,7 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Space reservation argument must be between 0 and 100 percent."); $self->{output}->option_exit(); } - + $self->{option_results}->{oid_filter} = lc($self->{option_results}->{oid_filter}); if ($self->{option_results}->{oid_filter} !~ /^(hrstoragedescr|hrfsmountpoint)$/) { $self->{output}->add_option_msg(short_msg => "Unsupported --oid-filter option."); @@ -265,7 +272,7 @@ sub check_options { sub access_result { my ($self, %options) = @_; - + return {} if (!defined($self->{option_results}->{add_access})); my $oid_hrFSAccess = '.1.3.6.1.2.1.25.3.8.1.5'; @@ -290,20 +297,20 @@ sub access_result { $result->{$_} = $snmp_result->{$oid_hrFSAccess . '.' . $relations->{$_}}; } } - + return $result; } sub manage_selection { my ($self, %options) = @_; - + $self->get_selection(snmp => $options{snmp}); - + my $oid_hrStorageAllocationUnits = '.1.3.6.1.2.1.25.2.3.1.4'; my $oid_hrStorageSize = '.1.3.6.1.2.1.25.2.3.1.5'; my $oid_hrStorageUsed = '.1.3.6.1.2.1.25.2.3.1.6'; my $oid_hrStorageType = '.1.3.6.1.2.1.25.2.3.1.2'; - + $options{snmp}->load( oids => [$oid_hrStorageAllocationUnits, $oid_hrStorageSize, $oid_hrStorageUsed], instances => $self->{storage_id_selected}, @@ -311,7 +318,7 @@ sub manage_selection { ); my $result = $options{snmp}->get_leef(); my $access_result = $self->access_result(snmp => $options{snmp}); - + $self->{global}->{count} = 0; $self->{storage} = {}; foreach (sort @{$self->{storage_id_selected}}) { @@ -330,12 +337,13 @@ sub manage_selection { # in bytes hrStorageAllocationUnits my $total_size = $result->{$oid_hrStorageSize . "." . $_} * $result->{$oid_hrStorageAllocationUnits . "." . $_}; if ($total_size <= 0) { - $self->{output}->add_option_msg( + $self->{output}->output_add( long_msg => sprintf( "skipping storage '%s': total size is <= 0 (%s)", $name_storage, int($total_size) - ) + ), + debug => 1 ); next; } From ad5c15337748ec19e0ff2a9816fcdf3a565a13bb Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 2 Apr 2020 09:52:25 +0200 Subject: [PATCH 047/190] Fix #1915 --- centreon-plugins/snmp_standard/mode/memory.pm | 90 ++++++++++--------- 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/centreon-plugins/snmp_standard/mode/memory.pm b/centreon-plugins/snmp_standard/mode/memory.pm index 7ad4d8365..79289c4a9 100644 --- a/centreon-plugins/snmp_standard/mode/memory.pm +++ b/centreon-plugins/snmp_standard/mode/memory.pm @@ -28,26 +28,27 @@ use warnings; sub custom_usage_output { my ($self, %options) = @_; - my $msg = sprintf("Ram Total: %s %s Used (-buffers/cache): %s %s (%.2f%%) Free: %s %s (%.2f%%)", - $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}), - $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}), - $self->{result_values}->{prct_used_absolute}, - $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}), - $self->{result_values}->{prct_free_absolute}); - return $msg; -} - -sub custom_swap_output { - my ($self, %options) = @_; - - my $msg = sprintf("Swap Total: %s %s Used: %s %s (%.2f%%) Free: %s %s (%.2f%%)", + return sprintf( + 'Ram Total: %s %s Used (-buffers/cache): %s %s (%.2f%%) Free: %s %s (%.2f%%)', + $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}), + $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}), + $self->{result_values}->{prct_used_absolute}, + $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}), + $self->{result_values}->{prct_free_absolute} + ); +} + +sub custom_swap_output { + my ($self, %options) = @_; + + return sprintf( + 'Swap Total: %s %s Used: %s %s (%.2f%%) Free: %s %s (%.2f%%)', $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}), $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}), $self->{result_values}->{prct_used_absolute}, $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}), $self->{result_values}->{prct_free_absolute} ); - return $msg; } sub set_counters { @@ -57,15 +58,15 @@ sub set_counters { { name => 'ram', type => 0, skipped_code => { -10 => 1 } }, { name => 'swap', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } }, ]; - + $self->{maps_counters}->{ram} = [ { label => 'usage', nlabel => 'memory.usage.bytes', set => { key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], closure_custom_output => $self->can('custom_usage_output'), perfdatas => [ { label => 'used', value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', - unit => 'B', cast_int => 1 }, - ], + unit => 'B', cast_int => 1 } + ] } }, { label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => { @@ -73,8 +74,8 @@ sub set_counters { closure_custom_output => $self->can('custom_usage_output'), perfdatas => [ { label => 'free', value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', - unit => 'B', cast_int => 1 }, - ], + unit => 'B', cast_int => 1 } + ] } }, { label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => { @@ -82,8 +83,8 @@ sub set_counters { output_template => 'Ram Used : %.2f %%', perfdatas => [ { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, - unit => '%' }, - ], + unit => '%' } + ] } }, { label => 'buffer', nlabel => 'memory.buffer.bytes', set => { @@ -92,8 +93,8 @@ sub set_counters { output_change_bytes => 1, perfdatas => [ { label => 'buffer', value => 'memBuffer_absolute', template => '%d', - min => 0, unit => 'B' }, - ], + min => 0, unit => 'B' } + ] } }, { label => 'cached', nlabel => 'memory.cached.bytes', set => { @@ -102,8 +103,8 @@ sub set_counters { output_change_bytes => 1, perfdatas => [ { label => 'cached', value => 'memCached_absolute', template => '%d', - min => 0, unit => 'B' }, - ], + min => 0, unit => 'B' } + ] } }, { label => 'shared', nlabel => 'memory.shared.bytes', set => { @@ -112,8 +113,8 @@ sub set_counters { output_change_bytes => 1, perfdatas => [ { label => 'shared', value => 'memShared_absolute', template => '%d', - min => 0, unit => 'B' }, - ], + min => 0, unit => 'B' } + ] } }, ]; @@ -123,8 +124,8 @@ sub set_counters { closure_custom_output => $self->can('custom_swap_output'), perfdatas => [ { label => 'swap', value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', - unit => 'B', cast_int => 1 }, - ], + unit => 'B', cast_int => 1 } + ] } }, { label => 'swap-free', display_ok => 0, nlabel => 'swap.free.bytes', set => { @@ -132,8 +133,8 @@ sub set_counters { closure_custom_output => $self->can('custom_swap_output'), perfdatas => [ { label => 'swap_free', value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', - unit => 'B', cast_int => 1 }, - ], + unit => 'B', cast_int => 1 } + ] } }, { label => 'swap-prct', display_ok => 0, nlabel => 'swap.usage.percentage', set => { @@ -141,10 +142,10 @@ sub set_counters { output_template => 'Swap Used : %.2f %%', perfdatas => [ { label => 'swap_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, - unit => '%' }, - ], + unit => '%' } + ] } - }, + } ]; } @@ -152,15 +153,15 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { - 'units:s' => { name => 'units', default => '%' }, - 'free' => { name => 'free' }, - 'swap' => { name => 'check_swap' }, - 'redhat' => { name => 'redhat' }, - 'autodetect-redhat' => { name => 'autodetect_redhat' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' }, + 'swap' => { name => 'check_swap' }, + 'redhat' => { name => 'redhat' }, + 'autodetect-redhat' => { name => 'autodetect_redhat' } }); - + return $self; } @@ -268,9 +269,14 @@ sub memory_calc { ## memShared = MemShared in /proc/meminfo ## memBuffer = Buffers in /proc/meminfo ## memCached = Cached + SReclaimable in /proc/meminfo (https://bugzilla.redhat.com/attachment.cgi?id=1554747&action=diff) - + $used = (defined($self->{option_results}->{redhat})) ? $total - $available : $total - $available - $buffer - $cached; $free = (defined($self->{option_results}->{redhat})) ? $available : $total - $used; + # if the value is negative. maybe the autodetect failed. + if ($used < 0 && defined($self->{option_results}->{autodetect_redhat})) { + $used = $total - $available; + $free = $available; + } $prct_used = $used * 100 / $total; $prct_free = 100 - $prct_used; } From f2c6acbe9d5b4a23adf0ab3370af5715cfcbe717 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 2 Apr 2020 10:10:28 +0200 Subject: [PATCH 048/190] Fix #1917 --- .../snmp_standard/mode/diskusage.pm | 58 ++++++++++--------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/centreon-plugins/snmp_standard/mode/diskusage.pm b/centreon-plugins/snmp_standard/mode/diskusage.pm index a4a5824c0..8365d7f40 100644 --- a/centreon-plugins/snmp_standard/mode/diskusage.pm +++ b/centreon-plugins/snmp_standard/mode/diskusage.pm @@ -122,12 +122,12 @@ sub new { 'display-transform-src:s' => { name => 'display_transform_src' }, 'display-transform-dst:s' => { name => 'display_transform_dst' }, 'show-cache' => { name => 'show_cache' }, - 'space-reservation:s' => { name => 'space_reservation' }, + 'space-reservation:s' => { name => 'space_reservation' } }); $self->{diskpath_id_selected} = []; $self->{statefile_cache} = centreon::plugins::statefile->new(%options); - + return $self; } @@ -153,33 +153,35 @@ sub check_options { $self->{statefile_cache}->check_options(%options); } +my $mapping = { + dskTotal32 => { oid => '.1.3.6.1.4.1.2021.9.1.6' }, # kB + dskUsed32 => { oid => '.1.3.6.1.4.1.2021.9.1.8' }, # kB + dskPercentNode => { oid => '.1.3.6.1.4.1.2021.9.1.10' }, + dskTotalLow => { oid => '.1.3.6.1.4.1.2021.9.1.11' }, # kB + dskTotalHigh => { oid => '.1.3.6.1.4.1.2021.9.1.12' }, # kB + dskUsedLow => { oid => '.1.3.6.1.4.1.2021.9.1.15' }, # kB + dskUsedHigh => { oid => '.1.3.6.1.4.1.2021.9.1.16' } # kB +}; + sub manage_selection { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->get_selection(); - - my $oid_dskTotalLow = '.1.3.6.1.4.1.2021.9.1.11'; # in kB - my $oid_dskTotalHigh = '.1.3.6.1.4.1.2021.9.1.12'; # in kB - my $oid_dskUsedLow = '.1.3.6.1.4.1.2021.9.1.15'; # in kB - my $oid_dskUsedHigh = '.1.3.6.1.4.1.2021.9.1.16'; # in kB - my $oid_dskPercentNode = '.1.3.6.1.4.1.2021.9.1.10'; + $self->get_selection(snmp => $options{snmp}); - $self->{snmp}->load( - oids => [ - $oid_dskTotalLow, $oid_dskTotalHigh, $oid_dskUsedLow, $oid_dskUsedHigh, $oid_dskPercentNode - ], + $options{snmp}->load( + oids => [ map($_->{oid}, values(%$mapping)) ], instances => $self->{diskpath_id_selected}, nothing_quit => 1 ); - my $result = $self->{snmp}->get_leef(); - + my $snmp_result = $options{snmp}->get_leef(); + $self->{global}->{count} = 0; $self->{diskpath} = {}; foreach (sort @{$self->{diskpath_id_selected}}) { my $name_diskpath = $self->get_display_value(id => $_); - if (!defined($result->{$oid_dskTotalHigh . "." . $_})) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + if (!defined($result->{dskTotal32}) && !defined($result->{dskTotalHigh})) { $self->{output}->add_option_msg( long_msg => sprintf( "skipping partition '%s': not found (need to reload the cache)", @@ -188,13 +190,13 @@ sub manage_selection { ); next; } - - my $total_size = (($result->{$oid_dskTotalHigh . "." . $_} << 32) + $result->{$oid_dskTotalLow . "." . $_}) * 1024; + + my $total_size = defined($result->{dskTotalHigh}) ? ((($result->{dskTotalHigh} << 32) + $result->{dskTotalLow}) * 1024) : $result->{dskTotal32} * 1024; if ($total_size == 0) { $self->{output}->output_add(long_msg => sprintf("skipping partition '%s' (total size is 0)", $name_diskpath), debug => 1); next; } - my $total_used = (($result->{$oid_dskUsedHigh . "." . $_} << 32) + $result->{$oid_dskUsedLow . "." . $_}) * 1024; + my $total_used = defined($result->{dskUsedHigh}) ? ((($result->{dskUsedHigh} << 32) + $result->{dskUsedLow}) * 1024) : $result->{dskUsed32} * 1024; my $reserved_value = 0; if (defined($self->{option_results}->{space_reservation})) { @@ -211,18 +213,18 @@ sub manage_selection { $prct_free = 0; } - $self->{diskpath}->{$_} = { + $self->{diskpath}->{$name_diskpath} = { display => $name_diskpath, total => $total_size, used => $total_used, free => $free, prct_free => $prct_free, prct_used => $prct_used, - inodes => defined($result->{$oid_dskPercentNode . "." . $_}) ? $result->{$oid_dskPercentNode . "." . $_} : undef, + inodes => $result->{dskPercentNode} }; $self->{global}->{count}++; } - + if (scalar(keys %{$self->{diskpath}}) <= 0) { $self->{output}->add_option_msg(short_msg => 'Issue with disk path information (see details)'); $self->{output}->option_exit(); @@ -230,7 +232,7 @@ sub manage_selection { } sub reload_cache { - my ($self) = @_; + my ($self, %options) = @_; my $datas = {}; $datas->{last_timestamp} = time(); @@ -238,8 +240,8 @@ sub reload_cache { my $oid_dskPath = '.1.3.6.1.4.1.2021.9.1.2'; - my $result = $self->{snmp}->get_table(oid => $oid_dskPath); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$result})) { + my $result = $options{snmp}->get_table(oid => $oid_dskPath); + foreach my $key (keys %$result) { next if ($key !~ /\.([0-9]+)$/); my $diskpath_index = $1; push @{$datas->{all_ids}}, $diskpath_index; @@ -258,7 +260,7 @@ sub get_selection { my ($self, %options) = @_; # init cache file - my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_snmpstandard_' . $self->{snmp}->get_hostname() . '_' . $self->{snmp}->get_port() . '_' . $self->{mode}); + my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_snmpstandard_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode}); if (defined($self->{option_results}->{show_cache})) { $self->{output}->add_option_msg(long_msg => $self->{statefile_cache}->get_string_content()); $self->{output}->option_exit(); @@ -266,7 +268,7 @@ sub get_selection { my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp'); if ($has_cache_file == 0 || !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) { - $self->reload_cache(); + $self->reload_cache(snmp => $options{snmp}); $self->{statefile_cache}->read(); } From 20b5a81111dbef9078173e35be4cd9689d12cb76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Schr=C3=B6ter?= Date: Thu, 2 Apr 2020 16:01:49 +0200 Subject: [PATCH 049/190] add support for ACS8000 series (psu oid differs from ACS6000 series) --- .../acs/8000/snmp/mode/components/psu.pm | 71 ++++++++++++ .../avocent/acs/8000/snmp/mode/hardware.pm | 104 ++++++++++++++++++ .../kvm/avocent/acs/8000/snmp/plugin.pm | 51 +++++++++ 3 files changed, 226 insertions(+) create mode 100644 centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/components/psu.pm create mode 100644 centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/hardware.pm create mode 100644 centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/plugin.pm diff --git a/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/components/psu.pm b/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/components/psu.pm new file mode 100644 index 000000000..cc79ec0a1 --- /dev/null +++ b/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/components/psu.pm @@ -0,0 +1,71 @@ +# +# Copyright 2019 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 hardware::kvm::avocent::acs::8000::snmp::mode::components::psu; + +use strict; +use warnings; + +my %map_states = (1 => 'statePowerOn', 2 => 'statePowerOff', 9999 => 'powerNotInstalled'); + +my $mapping = { + acsPowerSupplyStatePw1 => { oid => '.1.3.6.1.4.1.10418.26.2.1.8.2', map => \%map_states }, + acsPowerSupplyStatePw2 => { oid => '.1.3.6.1.4.1.10418.26.2.1.8.3', map => \%map_states }, +}; +my $oid_acsPowerSupply = '.1.3.6.1.4.1.10418.26.2.1.8'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_acsPowerSupply }; +} + +sub check_psu { + my ($self, %options) = @_; + + return if ($self->check_filter(section => 'psu', instance => $options{instance})); + return if ($options{state} eq 'powerNotInstalled' && + $self->absent_problem(section => 'psu', instance => $options{instance})); + $self->{components}->{psu}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("power supply '%s' status is %s.", + $options{instance}, $options{state} + )); + my $exit = $self->get_severity(section => 'psu', value => $options{state}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Power supply '%s' status is %s", + $options{instance}, $options{state})); + } +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking power supplies"); + $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; + return if ($self->check_filter(section => 'psu')); + + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_acsPowerSupply}, instance => '0'); + check_psu($self, state => $result->{acsPowerSupplyStatePw1}, instance => '1'); + check_psu($self, state => $result->{acsPowerSupplyStatePw2}, instance => '2'); +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/hardware.pm b/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/hardware.pm new file mode 100644 index 000000000..9eabd07b3 --- /dev/null +++ b/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/hardware.pm @@ -0,0 +1,104 @@ +# +# Copyright 2019 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 hardware::kvm::avocent::acs::8000::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(psu)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + psu => [ + ['statePowerOn', 'OK'], + ['statePowerOff', 'CRITICAL'], + ['powerNotInstalled', 'OK'], + ], + }; + + $self->{components_path} = 'hardware::kvm::avocent::acs::8000::snmp::mode::components'; + $self->{components_module} = ['psu']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); + bless $self, $class; + + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'psu'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=psu) +Can also exclude specific instance: --filter=psu,1 + +=item B<--absent-problem> + +Return an error if an entity is not 'present' (default is skipping) (comma seperated list) +Can be specific or global: --absent-problem=psu + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='psu,CRITICAL,^(?!(statePowerOn)$)' + +=back + +=cut \ No newline at end of file diff --git a/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/plugin.pm b/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/plugin.pm new file mode 100644 index 000000000..114d91643 --- /dev/null +++ b/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/plugin.pm @@ -0,0 +1,51 @@ +# +# Copyright 2019 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 hardware::kvm::avocent::acs::8000::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'hardware' => 'hardware::kvm::avocent::acs::8000::snmp::mode::hardware', + 'load' => 'snmp_standard::mode::loadaverage', + 'memory' => 'snmp_standard::mode::memory', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Avocent ACS 8000 series in SNMP. + +=cut From c965706bee55100d04c742ea1cd579eff10e35bb Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 2 Apr 2020 16:31:23 +0200 Subject: [PATCH 050/190] break change: refacto hddtemp plugin --- centreon-plugins/apps/hddtemp/custom/cli.pm | 264 ++++++++++++++++++ centreon-plugins/apps/hddtemp/custom/tcp.pm | 198 +++++++++++++ .../apps/hddtemp/local/mode/temperature.pm | 184 ------------ centreon-plugins/apps/hddtemp/local/plugin.pm | 48 ---- .../apps/hddtemp/mode/listdrives.pm | 97 +++++++ .../apps/hddtemp/mode/temperatures.pm | 169 +++++++++++ .../apps/hddtemp/{remote => }/plugin.pm | 17 +- .../apps/hddtemp/remote/mode/listdrives.pm | 160 ----------- .../apps/hddtemp/remote/mode/temperature.pm | 210 -------------- .../centreon/plugins/backend/ssh/libssh.pm | 2 +- .../centreon/plugins/backend/ssh/plink.pm | 3 +- .../centreon/plugins/backend/ssh/sshcli.pm | 3 +- 12 files changed, 744 insertions(+), 611 deletions(-) create mode 100644 centreon-plugins/apps/hddtemp/custom/cli.pm create mode 100644 centreon-plugins/apps/hddtemp/custom/tcp.pm delete mode 100644 centreon-plugins/apps/hddtemp/local/mode/temperature.pm delete mode 100644 centreon-plugins/apps/hddtemp/local/plugin.pm create mode 100644 centreon-plugins/apps/hddtemp/mode/listdrives.pm create mode 100644 centreon-plugins/apps/hddtemp/mode/temperatures.pm rename centreon-plugins/apps/hddtemp/{remote => }/plugin.pm (65%) delete mode 100644 centreon-plugins/apps/hddtemp/remote/mode/listdrives.pm delete mode 100644 centreon-plugins/apps/hddtemp/remote/mode/temperature.pm diff --git a/centreon-plugins/apps/hddtemp/custom/cli.pm b/centreon-plugins/apps/hddtemp/custom/cli.pm new file mode 100644 index 000000000..9df6ecfc4 --- /dev/null +++ b/centreon-plugins/apps/hddtemp/custom/cli.pm @@ -0,0 +1,264 @@ +# +# 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::hddtemp::custom::cli; + +use strict; +use warnings; +use centreon::plugins::ssh; +use centreon::plugins::misc; + +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 => { + 'hostname:s' => { name => 'hostname' }, + 'timeout:s' => { name => 'timeout', default => 45 }, + 'command-drives:s' => { name => 'command_drives' }, + 'command-path-drives:s' => { name => 'command_path_drives' }, + 'command-options-drives:s' => { name => 'command_options_drives' }, + 'command-hddtemp:s' => { name => 'command_hddtemp' }, + 'command-path-hddtemp:s' => { name => 'command_path_hddtemp' }, + 'command-options-hddtemp:s' => { name => 'command_options_hddtemp' }, + 'sudo:s' => { name => 'sudo' } + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'CLI OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{ssh} = centreon::plugins::ssh->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) = @_; + + if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { + $self->{ssh}->check_options(option_results => $self->{option_results}); + } + + return 0; +} + +sub list_drives { + my ($self, %options) = @_; + + my $stdout; + if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { + ($stdout) = $self->{ssh}->execute( + hostname => $self->{option_results}->{hostname}, + command => defined($self->{option_results}->{command_drives}) && $self->{option_results}->{command_drives} ne '' ? $self->{option_results}->{command_drives} : 'lsblk', + command_path => $self->{option_results}->{command_path_drives}, + command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options_drives} ne '' ? $self->{option_results}->{command_options_drives} : '-I 8 -d -o NAME -p -n', + timeout => $self->{option_results}->{timeout} + ); + } else { + ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => { timeout => $self->{option_results}->{timeout} }, + command => defined($self->{option_results}->{command_drives}) && $self->{option_results}->{command_drives} ne '' ? $self->{option_results}->{command_drives} : 'lsblk', + command_path => $self->{option_results}->{command_path_drives}, + command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options_drives} ne '' ? $self->{option_results}->{command_options_drives} : '-I 8 -d -o NAME -p -n' + ); + } + + $self->{output}->output_add(long_msg => "command response: $stdout", debug => 1); + my $drives = {}; + $drives->{$_} = {} foreach (split /\n/, $stdout); + + return $drives; +} + +sub get_drives_information { + my ($self, %options) = @_; + + my $drives = $self->list_drives(); + my $cmd_options = '-u C ' . join(' ', keys %$drives); + + my ($stdout, $exit_code); + if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { + ($stdout, $exit_code) = $self->{ssh}->execute( + hostname => $self->{option_results}->{hostname}, + sudo => $self->{option_results}->{sudo}, + command => defined($self->{option_results}->{command_hddtemp}) && $self->{option_results}->{command_hddtemp} ne '' ? $self->{option_results}->{command_hddtemp} : 'hddtemp', + command_path => $self->{option_results}->{command_path_hddtemp}, + command_options => defined($self->{option_results}->{command_options_hddtemp}) && $self->{option_results}->{command_options_hddtemp} ne '' ? $self->{option_results}->{command_options_hddtemp} : $cmd_options, + timeout => $self->{option_results}->{timeout}, + no_quit => 1 + ); + } else { + ($stdout, $exit_code) = centreon::plugins::misc::execute( + output => $self->{output}, + options => { timeout => $self->{option_results}->{timeout} }, + sudo => $self->{option_results}->{sudo}, + command => defined($self->{option_results}->{command_hddtemp}) && $self->{option_results}->{command_hddtemp} ne '' ? $self->{option_results}->{command_hddtemp} : 'hddtemp', + command_path => $self->{option_results}->{command_path_hddtemp}, + command_options => defined($self->{option_results}->{command_options_hddtemp}) && $self->{option_results}->{command_options_hddtemp} ne '' ? $self->{option_results}->{command_options_hddtemp} : $cmd_options . ' 2> /dev/null', + no_quit => 1, + ); + } + + # exit values can be: 0/1. Need root permissions. + if ($exit_code != 0 && $exit_code != 1) { + $self->{output}->add_option_msg(short_msg => sprintf('command execution error [exit code: %s]', $exit_code)); + $self->{output}->option_exit(); + } + + # OK: + # /dev/sda: SanDisk ...: 32 C + # ERROR: + # message on stderr. So if we don't catch stderr and we have nothing, surely error. for example: + # /dev/sda: open: Permission denied + # UNKNOWN: + # /dev/sda: SanDisk ...: no sensor + # SLEEP: + # /dev/sda: SanDisk ...: drive is sleeping + # NOSENSOR: + # /dev/sda: SanDisk ...: drive supported, but it doesn't have a temperature sensor + # NOT_APPLICABLE: + # /dev/sda: SanDisk ...: misc message + foreach my $name (keys %$drives) { + if ($stdout =~ /^$name:.*?:\s+(\d+).*?C/m) { + $drives->{$name}->{status} = 'ok'; + $drives->{$name}->{temperature_unit} = 'C'; + $drives->{$name}->{temperature} = $1; + } elsif ($stdout =~ /^$name:.*?:\s+(.*)$/m) { + my $message = $1; + $drives->{$name}->{status} = 'notApplicable'; + $drives->{$name}->{status} = 'unknown' if ($message =~ /no sensor/i); + $drives->{$name}->{status} = 'driveSleep' if ($message =~ /drive is sleeping/i); + $drives->{$name}->{status} = 'noSensor' if ($message =~ /drive supported, but it doesn't have a temperature sensor/i); + } else { + $drives->{$name}->{status} = 'error'; + } + } + + return $drives; +} + +1; + +__END__ + +=head1 NAME + +ssh + +=head1 SYNOPSIS + +my ssh + +=head1 CLI OPTIONS + +=over 8 + +=item B<--hostname> + +Hostname to query (ssh mode). + +=item B<--timeout> + +Timeout in seconds for the command (Default: 45). + +=item You can override command for drives listing. +By default, we use 'lsblk -I 8 -d -o NAME -p -n': + +=over 16 + +=item B<--command-drives> + +Command to get information. Used it you have output in a file. + +=item B<--command-path-drives> + +Command path. + +=item B<--command-options-drives> + +Command options. + +=back + +=item You can override command hddtemp used. +By default, we use 'hddtemp -u C /dev/sda /dev/sdb ...' built with the result of drives command: + +=over 16 + +=item B<--command-hddtemp> + +Command to get information. Used it you have output in a file. + +=item B<--command-path-hddtemp> + +Command path. + +=item B<--command-options-hddtemp> + +Command options. + +=item B<--sudo> + +Sudo hddtemp command. + +=back + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/apps/hddtemp/custom/tcp.pm b/centreon-plugins/apps/hddtemp/custom/tcp.pm new file mode 100644 index 000000000..532026900 --- /dev/null +++ b/centreon-plugins/apps/hddtemp/custom/tcp.pm @@ -0,0 +1,198 @@ +# +# 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::hddtemp::custom::tcp; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use IO::Socket; + +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 => { + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port' }, + 'timeout:s' => { name => 'timeout' } + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'CUSTOM TCP OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + + 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} =~ /(\d+)/ ? $1 : 7634; + $self->{timeout} = (defined($self->{option_results}->{timeout})) && $self->{option_results}->{timeout} =~ /(\d+)/ ? $1 : 30; + + if ($self->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => 'Need to specify --hostname option.'); + $self->{output}->option_exit(); + } + + return 0; +} + +sub get_hddtemp_drives { + my ($self, %options) = @_; + + my $socket = new IO::Socket::INET( + Proto => 'tcp', + PeerAddr => $self->{hostname}, + PeerPort => $self->{port}, + Timeout => $self->{timeout} + ); + + if (!defined($socket)) { + $self->{output}->add_option_msg(short_msg => "could not connect: $@"); + $self->{output}->option_exit(); + } + + my $line; + eval { + local $SIG{ALRM} = sub { die 'Timeout'; }; + alarm($self->{timeout}); + $line = <$socket>; + alarm(0); + }; + $socket->shutdown(2); + if ($@) { + $self->{output}->add_option_msg(short_msg => 'cannot get informations: ' . $@); + $self->{output}->option_exit(); + } + + return $line; +} + +sub list_drives { + my ($self, %options) = @_; + + my $line = $self->get_hddtemp_drives(); + my $drives = {}; + while ($line =~ /\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|/msg) { + $drives->{$1} = {}; + } + + return $drives; +} + +sub get_drives_information { + my ($self, %options) = @_; + + my $line = $self->get_hddtemp_drives(); + + #|/dev/sda|SanDisk ....|33|C| + #|/dev/sda|Scan .... |NA|*| + my $mapping_errors = { + NA => 'notApplicable', + UNK => 'unknown', + NOS => 'noSensor', + SLP => 'driveSleep', + ERR => 'error' + }; + + my $drives = {}; + while ($line =~ /\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|/msg) { + my ($name, $value, $unit) = ($1, $3, $4); + if ($value =~ /\d+/) { + $drives->{$name} = { temperature => $value, temperature_unit => $unit, status => 'ok' }; + } else { + $drives->{$name} = { status => $mapping_errors->{$value} }; + } + } + + return $drives; +} + +1; + +__END__ + +=head1 NAME + +Hddtemp + +=head1 CUSTOM TCP OPTIONS + +Hddtemp tcp + +=over 8 + +=item B<--hostname> + +Hostname or IP address. + +=item B<--port> + +Port used (Default: 7634) + +=item B<--timeout> + +Set timeout in seconds (Default: 30). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/apps/hddtemp/local/mode/temperature.pm b/centreon-plugins/apps/hddtemp/local/mode/temperature.pm deleted file mode 100644 index 06091f8a6..000000000 --- a/centreon-plugins/apps/hddtemp/local/mode/temperature.pm +++ /dev/null @@ -1,184 +0,0 @@ -# -# 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::hddtemp::local::mode::temperature; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; -use centreon::plugins::misc; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "remote" => { name => 'remote' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'hddtemp' }, - "command-path:s" => { name => 'command_path', default => '/usr/sbin' }, - "command-options:s" => { name => 'command_options', default => '-u' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "disks:s" => { name => 'disks' }, - "unit:s" => { name => 'unit', default => 'C' } - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{critical} . "'."); - $self->{output}->option_exit(); - } - if (!defined($self->{option_results}->{disks}) || $self->{option_results}->{disks} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify hdd (ex. /dev/sda)."); - $self->{output}->option_exit(); - } - - #### Create command_options - if (defined($self->{option_results}->{unit})) { - $self->{option_results}->{command_options} .= $self->{option_results}->{unit}; - } - $self->{option_results}->{command_options} .= ' ' . $self->{option_results}->{disks}; - $self->{option_results}->{command_options} .= ' 2>&1'; -} - -sub run { - my ($self, %options) = @_; - my $total_size = 0; - - my $stdout = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - sudo => $self->{option_results}->{sudo}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); - - $self->{output}->output_add(severity => 'OK', - short_msg => "All temperatures are ok."); - foreach (split(/\n/, $stdout)) { - next if (!/(.*): (.*): ([0-9]*)/); - my ($disk, $model, $temp) = ($1, $2, $3); - - my $exit_code = $self->{perfdata}->threshold_check(value => $temp, - threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(long_msg => sprintf("%s: %s", $disk, $temp . '°' . $self->{option_results}->{unit})); - if (!$self->{output}->is_status(litteral => 1, value => $exit_code, compare => 'ok')) { - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("'%s' temp is %s", $disk, $temp . '°' . $self->{option_results}->{unit})); - } - $self->{output}->perfdata_add(label => $disk, unit => $self->{option_results}->{unit}, - value => $temp, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check hdd temperature with hddtemp. - -=over 8 - -=item B<--disks> - -Disks to check (ex: /dev/sda) - -=item B<--unit> - -Temperature unit (default: C). - -=item B<--warning> - -Threshold warning in °. - -=item B<--critical> - -Threshold critical in °. - -=item B<--remote> - -Execute command remotely in 'ssh'. - -=item B<--hostname> - -Hostname to query (need --remote). - -=item B<--ssh-option> - -Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). - -=item B<--ssh-path> - -Specify ssh command path (default: none) - -=item B<--ssh-command> - -Specify ssh command (default: 'ssh'). Useful to use 'plink'. - -=item B<--timeout> - -Timeout in seconds for the command (Default: 30). - -=item B<--sudo> - -Use 'sudo' to execute the command. - -=item B<--command> - -Command to get information (Default: 'hddtemp'). -Can be changed if you have output in a file. - -=item B<--command-path> - -Command path (Default: '/usr/sbin'). - -=item B<--command-options> - -Command options (Default: '-u'). - -=back - -=cut diff --git a/centreon-plugins/apps/hddtemp/local/plugin.pm b/centreon-plugins/apps/hddtemp/local/plugin.pm deleted file mode 100644 index ff84f189a..000000000 --- a/centreon-plugins/apps/hddtemp/local/plugin.pm +++ /dev/null @@ -1,48 +0,0 @@ -# -# 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::hddtemp::local::plugin; - -use strict; -use warnings; -use base qw(centreon::plugins::script_simple); - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '0.1'; - %{$self->{modes}} = ( - 'temperature' => 'apps::hddtemp::local::mode::temperature', - ); - - return $self; -} - -1; - -__END__ - -=head1 PLUGIN DESCRIPTION - -Check Linux through local commands (the plugin can use SSH). - -=cut diff --git a/centreon-plugins/apps/hddtemp/mode/listdrives.pm b/centreon-plugins/apps/hddtemp/mode/listdrives.pm new file mode 100644 index 000000000..b91957926 --- /dev/null +++ b/centreon-plugins/apps/hddtemp/mode/listdrives.pm @@ -0,0 +1,97 @@ +# +# 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::hddtemp::mode::listdrives; + +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}->list_drives(); +} + +sub run { + my ($self, %options) = @_; + + my $drives = $self->manage_selection(%options); + foreach (sort keys %$drives) { + $self->{output}->output_add(long_msg => + sprintf( + '[name = %s]', + $_ + ) + ); + } + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List drives:' + ); + + $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']); +} + +sub disco_show { + my ($self, %options) = @_; + + my $drives = $self->manage_selection(%options); + foreach (sort keys %$drives) { + $self->{output}->add_disco_entry(name => $_); + } +} + +1; + +__END__ + +=head1 MODE + +List queues. + +=over 8 + +=back + +=cut diff --git a/centreon-plugins/apps/hddtemp/mode/temperatures.pm b/centreon-plugins/apps/hddtemp/mode/temperatures.pm new file mode 100644 index 000000000..61f2e2d77 --- /dev/null +++ b/centreon-plugins/apps/hddtemp/mode/temperatures.pm @@ -0,0 +1,169 @@ +# +# 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::hddtemp::mode::temperatures; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + 'status: %s', + $self->{result_values}->{status}, + ); +} + +sub custom_temperature_output { + my ($self, %options) = @_; + + return sprintf('temperature: %s %s', + $self->{result_values}->{temperature_absolute}, + $self->{result_values}->{temperature_unit_absolute} + ); +} + +sub custom_temperature_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + nlabel => 'drive.temperature.' . ($self->{result_values}->{temperature_unit_absolute} eq 'C' ? 'celsius' : 'fahrenheit'), + instances => $self->{result_values}->{display_absolute}, + unit => $self->{result_values}->{temperature_unit_absolute}, + value => $self->{result_values}->{temperature_absolute}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + ); +} + +sub prefix_drive_output { + my ($self, %options) = @_; + + return "Drive '" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'drives', type => 1, cb_prefix_output => 'prefix_drive_output', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{drives} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + }, + { label => 'temperature', set => { + key_values => [ { name => 'temperature' }, { name => 'temperature_unit' }, { name => 'display' } ], + closure_custom_output => $self->can('custom_temperature_output'), + closure_custom_perfdata => $self->can('custom_temperature_perfdata') + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, 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} !~ /ok/i' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $results = $options{custom}->get_drives_information(); + + $self->{drives} = {}; + foreach (keys %$results) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $_ !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping drive '" . $_ . "': no matching filter.", debug => 1); + next; + } + + $self->{drives}->{$_} = { + display => $_, + %{$results->{$_}} + }; + } +} + +1; + +__END__ + +=head1 MODE + +Check drive temperatures. + +=over 8 + +=item B<--filter-name> + +Filter drive name (Can use 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} !~ /ok/i'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'temperature'. + +=back + +=cut diff --git a/centreon-plugins/apps/hddtemp/remote/plugin.pm b/centreon-plugins/apps/hddtemp/plugin.pm similarity index 65% rename from centreon-plugins/apps/hddtemp/remote/plugin.pm rename to centreon-plugins/apps/hddtemp/plugin.pm index 57b0fb743..2a1a0c83f 100644 --- a/centreon-plugins/apps/hddtemp/remote/plugin.pm +++ b/centreon-plugins/apps/hddtemp/plugin.pm @@ -18,23 +18,25 @@ # limitations under the License. # -package apps::hddtemp::remote::plugin; +package apps::hddtemp::plugin; use strict; use warnings; -use base qw(centreon::plugins::script_simple); +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->{version} = '1.0'; %{$self->{modes}} = ( - 'temperature' => 'apps::hddtemp::remote::mode::temperature', - 'list-drives' => 'apps::hddtemp::remote::mode::listdrives', + 'list-drives' => 'apps::hddtemp::mode::listdrives', + 'temperatures' => 'apps::hddtemp::mode::temperatures' ); + $self->{custom_modes}{tcp} = 'apps::hddtemp::custom::tcp'; + $self->{custom_modes}{cli} = 'apps::hddtemp::custom::cli'; return $self; } @@ -44,6 +46,9 @@ __END__ =head1 PLUGIN DESCRIPTION -Check HDDTEMP Status throuh TCP Socket +Check drives temperature with hddtemp. +Two custom modes availables: +'tcp' (remotely with hddtemp in daemon mode) +'command' (with hddtemp command. you can execute locally or through ssh). =cut diff --git a/centreon-plugins/apps/hddtemp/remote/mode/listdrives.pm b/centreon-plugins/apps/hddtemp/remote/mode/listdrives.pm deleted file mode 100644 index f9ae7e492..000000000 --- a/centreon-plugins/apps/hddtemp/remote/mode/listdrives.pm +++ /dev/null @@ -1,160 +0,0 @@ -# -# 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::hddtemp::remote::mode::listdrives; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; -use IO::Socket; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '7634' }, - "timeout:s" => { name => 'timeout', default => '10' }, - "filter-name:s" => { name => 'filter_name', }, - }); - - $self->{result} = {}; - $self->{hostname} = undef; - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - -} - -sub manage_selection { - my ($self, %options) = @_; - - my $oSocketConn = new IO::Socket::INET ( Proto => 'tcp', - PeerAddr => $self->{option_results}->{hostname}, - PeerPort => $self->{option_results}->{port}, - Timeout => $self->{option_results}->{timeout}, - ); - - if (!defined($oSocketConn)) { - $self->{output}->add_option_msg(short_msg => "Could not connect."); - $self->{output}->option_exit(); - } - - #|/dev/sda|SD280813AS|35|C|#|/dev/sdb|ST2000CD005-1CH134|35|C| - - my $line; - - eval { - local $SIG{ALRM} = sub { die "Timeout by signal ALARM\n"; }; - alarm(10); - $line = <$oSocketConn>; - alarm(0); - }; - $oSocketConn->shutdown(2); - if ($@) { - $self->{output}->add_option_msg(short_msg => "Cannot get informations."); - $self->{output}->option_exit(); - } - - while ($line =~ /\|([^|]+)\|([^|]+)\|([^|]+)\|(C|F)\|/g) { - my ($drive, $serial, $temperature, $unit) = ($1, $2, $3, $4); - - if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $drive !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "Skipping drive '" . $drive . "': no matching filter name"); - next; - } - - $self->{result}->{$drive} = {serial => $serial, temperature => $temperature, unit => $unit}; - } -} - -sub run { - my ($self, %options) = @_; - - $self->manage_selection(); - foreach my $name (sort(keys %{$self->{result}})) { - $self->{output}->output_add(long_msg => "'" . $name . "' [temperature = " . $self->{result}->{$name}->{temperature} . $self->{result}->{$name}->{unit} . ']'); - } - - $self->{output}->output_add(severity => 'OK', - short_msg => 'List Drives:'); - $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', 'temperature']); -} - -sub disco_show { - my ($self, %options) = @_; - - $self->manage_selection(); - foreach my $name (sort(keys %{$self->{result}})) { - $self->{output}->add_disco_entry(name => $name, - temperature => $self->{result}->{$name}->{temperature} - ); - } -} - -1; - -__END__ - -=head1 MODE - -List HDDTEMP Harddrives - -=over 8 - -=item B<--hostname> - -IP Address or FQDN of the Server - -=item B<--port> - -Port used by Hddtemp (Default: 7634) - -=item B<--timeout> - -Set Timeout for Socketconnect - -=item B<--filter-name> - -Filter Harddrive name (regexp can be used). - -=back - -=cut diff --git a/centreon-plugins/apps/hddtemp/remote/mode/temperature.pm b/centreon-plugins/apps/hddtemp/remote/mode/temperature.pm deleted file mode 100644 index 0e837c94c..000000000 --- a/centreon-plugins/apps/hddtemp/remote/mode/temperature.pm +++ /dev/null @@ -1,210 +0,0 @@ -# -# 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::hddtemp::remote::mode::temperature; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; -use IO::Socket; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '7634' }, - "timeout:s" => { name => 'timeout', default => '10' }, - "name:s" => { name => 'name' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "regexp" => { name => 'use_regexp' }, - "regexp-isensitive" => { name => 'use_regexpi' }, - }); - - $self->{result} = {}; - $self->{hostname} = undef; - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } - -} - -sub manage_selection { - my ($self, %options) = @_; - - my $oSocketConn = new IO::Socket::INET ( - Proto => 'tcp', - PeerAddr => $self->{option_results}->{hostname}, - PeerPort => $self->{option_results}->{port}, - Timeout => $self->{option_results}->{timeout}, - ); - - if (!defined($oSocketConn)) { - $self->{output}->add_option_msg(short_msg => "Could not connect."); - $self->{output}->option_exit(); - } - - #|/dev/sda|SD280813AS|35|C|#|/dev/sdb|ST2000CD005-1CH134|35|C| - - my $line; - - eval { - local $SIG{ALRM} = sub { die "Timeout by signal ALARM\n"; }; - alarm(10); - $line = <$oSocketConn>; - alarm(0); - }; - $oSocketConn->shutdown(2); - if ($@) { - $self->{output}->add_option_msg(short_msg => "Cannot get informations."); - $self->{output}->option_exit(); - } - - while ($line =~ /\|([^|]+)\|([^|]+)\|([^|]+)\|(C|F)\|/g) { - my ($drive, $serial, $temperature, $unit) = ($1, $2, $3, $4); - - next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) - && $drive !~ /$self->{option_results}->{name}/i); - next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) - && $drive !~ /$self->{option_results}->{name}/); - next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) - && $drive ne $self->{option_results}->{name}); - - $self->{result}->{$drive} = {serial => $serial, temperature => $temperature, unit => $unit}; - } - - if (scalar(keys %{$self->{result}}) <= 0) { - if (defined($self->{option_results}->{name})) { - $self->{output}->add_option_msg(short_msg => "No drives found for name '" . $self->{option_results}->{name} . "'."); - } else { - $self->{output}->add_option_msg(short_msg => "No drives found."); - } - $self->{output}->option_exit(); - } - -} - -sub run { - my ($self, %options) = @_; - - $self->manage_selection(); - - if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All Harddrive Temperatures are ok.'); - }; - - foreach my $name (sort(keys %{$self->{result}})) { - my $exit = $self->{perfdata}->threshold_check(value => $self->{result}->{$name}->{temperature}, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - $self->{output}->output_add(long_msg => sprintf("Harddrive '%s' Temperature : %s%s", - $name, - $self->{result}->{$name}->{temperature}, - $self->{result}->{$name}->{unit})); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Harddrive '%s' Temperature : %s%s", - $name, - $self->{result}->{$name}->{temperature}, - $self->{result}->{$name}->{unit})); - } - - my $extra_label; - $extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})); - $self->{output}->perfdata_add( - label => 'temp', - intances => $extra_label, - unit => $self->{result}->{$name}->{unit}, - value => sprintf("%.2f", $self->{result}->{$name}->{temperature}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0 - ); - }; - - $self->{output}->display(); - $self->{output}->exit(); -}; - -1; - -__END__ - -=head1 MODE - -Check HDDTEMP Temperature by Socket Connect - -=over 8 - -=item B<--hostname> - -IP Address or FQDN of the Server - -=item B<--port> - -Port used by Hddtemp (Default: 7634) - -=item B<--timeout> - -Set Timeout for Socketconnect - -=item B<--warning> - -Warning Threshold for Temperature - -=item B<--critical> - -Critical Threshold for Temperature - -=item B<--name> - -Set the Harddrive name (empty means 'check all Harddrives') - -=item B<--regexp> - -Allows to use regexp to filter Harddrive (with option --name). - -=item B<--regexp-isensitive> - -Allows to use regexp non case-sensitive (with --regexp). - -=back - -=cut diff --git a/centreon-plugins/centreon/plugins/backend/ssh/libssh.pm b/centreon-plugins/centreon/plugins/backend/ssh/libssh.pm index d38445166..eae3df26c 100644 --- a/centreon-plugins/centreon/plugins/backend/ssh/libssh.pm +++ b/centreon-plugins/centreon/plugins/backend/ssh/libssh.pm @@ -138,7 +138,7 @@ sub execute { $self->{output}->option_exit(); } - if ($exit_code != 0) { + if ($exit_code != 0 && (!defined($options{no_quit}) || $options{no_quit} != 1)) { $self->{output}->add_option_msg(short_msg => sprintf('command execution error [exit code: %s]', $exit_code)); $self->{output}->option_exit(); } diff --git a/centreon-plugins/centreon/plugins/backend/ssh/plink.pm b/centreon-plugins/centreon/plugins/backend/ssh/plink.pm index 1b4f745e2..90aab1a3d 100644 --- a/centreon-plugins/centreon/plugins/backend/ssh/plink.pm +++ b/centreon-plugins/centreon/plugins/backend/ssh/plink.pm @@ -81,7 +81,8 @@ sub execute { ssh_path => $self->{ssh_path}, ssh_option => $self->{ssh_option}, timeout => $options{timeout} - } + }, + no_quit => $options{no_quit} ); if (defined($options{ssh_pipe}) && $options{ssh_pipe} == 1) { diff --git a/centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm b/centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm index 7374b7c21..fd8290212 100644 --- a/centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm +++ b/centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm @@ -83,7 +83,8 @@ sub execute { ssh_path => $self->{ssh_path}, ssh_option => $self->{ssh_option}, timeout => $options{timeout} - } + }, + no_quit => $options{no_quit} ); if (defined($options{ssh_pipe}) && $options{ssh_pipe} == 1) { From d11019951af3c9465be4e757ae0468f69b3cfad4 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 3 Apr 2020 10:07:22 +0200 Subject: [PATCH 051/190] enhance list-trunks f5 --- .../network/f5/bigip/snmp/mode/listtrunks.pm | 107 +++++++++--------- .../network/f5/bigip/snmp/mode/trunks.pm | 4 +- 2 files changed, 54 insertions(+), 57 deletions(-) diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/listtrunks.pm b/centreon-plugins/network/f5/bigip/snmp/mode/listtrunks.pm index e7c687b56..5e0b44125 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/listtrunks.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/listtrunks.pm @@ -29,13 +29,10 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "name:s" => { name => 'name' }, - "regexp" => { name => 'use_regexp' }, - }); - $self->{trunks_selected} = []; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'name' } + }); return $self; } @@ -45,62 +42,67 @@ sub check_options { $self->SUPER::init(%options); } -my %map_trunk_status = ( +my $map_trunk_status = { 0 => 'up', 1 => 'down', 2 => 'disable', 3 => 'uninitialized', 4 => 'loopback', - 5 => 'unpopulated', -); + 5 => 'unpopulated' +}; -my $sysTrunkTable = '.1.3.6.1.4.1.3375.2.1.2.12.1.2'; -my $sysTrunkName = '.1.3.6.1.4.1.3375.2.1.2.12.1.2.1.1'; -my $sysTrunkStatus = '.1.3.6.1.4.1.3375.2.1.2.12.1.2.1.2'; -my $sysTrunkOperBw = '.1.3.6.1.4.1.3375.2.1.2.12.1.2.1.5'; +my $mapping = { + sysTrunkName => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.1.2.1.1' }, + sysTrunkStatus => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.1.2.1.2', map => $map_trunk_status }, + sysTrunkOperBw => { oid => '.1.3.6.1.4.1.3375.2.1.2.12.1.2.1.5' } +}; +my $oid_sysTrunkTable = '.1.3.6.1.4.1.3375.2.1.2.12.1.2'; sub manage_selection { my ($self, %options) = @_; - $self->{result} = $self->{snmp}->get_table(oid => $sysTrunkTable, nothing_quit => 1); - - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{result}})) { - next if ($oid !~ /^$sysTrunkName\.(.*)$/); + my $snmp_result = $options{snmp}->get_table( + oid => $oid_sysTrunkTable, + end => $mapping->{sysTrunkOperBw}->{oid}, + nothing_quit => 1 + ); + my $trunks = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{sysTrunkName}->{oid}\.(.*)$/); my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); - # Get all without a name - if (!defined($self->{option_results}->{name})) { - push @{$self->{trunks_selected}}, $instance; + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{sysTrunkName} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping trunk '" . $result->{sysTrunkName} . "': no matching filter name.", debug => 1); next; } - - if (!defined($self->{option_results}->{use_regexp}) && $self->{result}->{$sysTrunkName . '.' . $instance} eq $self->{option_results}->{name}) { - push @{$self->{trunks_selected}}, $instance; - next; - } - if (defined($self->{option_results}->{use_regexp}) && $self->{result}->{$sysTrunkName . '.' . $instance} =~ /$self->{option_results}->{name}/) { - push @{$self->{trunks_selected}}, $instance; - next; - } - - $self->{output}->output_add(long_msg => "Skipping pool '" . $self->{result}->{$sysTrunkName . '.' . $instance} . "': no matching filter name", debug => 1); + + $trunks->{$result->{sysTrunkName}} = $result; } + + return $trunks; } sub run { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->manage_selection(); - foreach my $instance (sort @{$self->{trunks_selected}}) { - $self->{output}->output_add(long_msg => sprintf("'%s' [status: %s] [speed: %s]", - $self->{result}->{$sysTrunkName . '.' . $instance}, - $map_trunk_status{$self->{result}->{$sysTrunkStatus . '.' . $instance}}, - $self->{result}->{$sysTrunkOperBw . '.' . $instance})); + my $trunks = $self->manage_selection(snmp => $options{snmp}); + foreach (sort keys %$trunks) { + $self->{output}->output_add( + long_msg => sprintf( + "'%s' [status: %s] [speed: %s]", + $_, + $trunks->{$_}->{sysTrunkStatus}, + $trunks->{$_}->{sysTrunkOperBw} + ) + ); } - $self->{output}->output_add(severity => 'OK', - short_msg => 'List Trunks:'); + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List trunks:' + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -113,15 +115,14 @@ sub disco_format { sub disco_show { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->manage_selection(disco => 1); - foreach my $instance (sort @{$self->{trunks_selected}}) { - my $name = $self->{result}->{$sysTrunkName . '.' . $instance}; - my $status = $map_trunk_status{$self->{result}->{$sysTrunkStatus . '.' . $instance}}; - my $speed = $self->{result}->{$sysTrunkOperBw . '.' . $instance}; - - $self->{output}->add_disco_entry(name => $name, status => $status, speed => $speed); + my $trunks = $self->manage_selection(snmp => $options{snmp}); + foreach (sort keys %$trunks) { + $self->{output}->add_disco_entry( + name => $_, + status => $trunks->{$_}->{sysTrunkStatus}, + speed => $trunks->{$_}->{sysTrunkOperBw} + ); } } @@ -135,13 +136,9 @@ List Trunks. =over 8 -=item B<--name> +=item B<--filter-name> -Set the trunk name. - -=item B<--regexp> - -Allows to use regexp to filter trunk name (with option --name). +Filter by trunk name (regexp can be used). =back diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/trunks.pm b/centreon-plugins/network/f5/bigip/snmp/mode/trunks.pm index c815b2126..44adeddf9 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/trunks.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/trunks.pm @@ -390,8 +390,8 @@ sub manage_selection { my $results = $options{snmp}->get_multiple_table( oids => [ - { oid => $oid_sysTrunkTable }, - { oid => $oid_sysTrunkStatTable }, + { oid => $oid_sysTrunkTable, end => $mapping_sysTrunk->{sysTrunkOperBw}->{oid} }, + { oid => $oid_sysTrunkStatTable } ], nothing_quit => 1 ); From a605f9cd2710fa90f4bfa99b2b01e79164cbf9b7 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 3 Apr 2020 10:50:06 +0200 Subject: [PATCH 052/190] add remove header http class --- centreon-plugins/centreon/plugins/http.pm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/centreon-plugins/centreon/plugins/http.pm b/centreon-plugins/centreon/plugins/http.pm index 7d35bc545..0fc547c6c 100644 --- a/centreon-plugins/centreon/plugins/http.pm +++ b/centreon-plugins/centreon/plugins/http.pm @@ -82,6 +82,12 @@ sub add_header { $self->{add_headers}->{$options{key}} = $options{value}; } +sub remove_header { + my ($self, %options) = @_; + + delete $self->{add_headers}->{$options{key}} if (defined($self->{add_headers}->{$options{key}})); +} + sub check_options { my ($self, %options) = @_; From b153a84d660ed7143a4121dc769671cd869f8950 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 3 Apr 2020 10:50:37 +0200 Subject: [PATCH 053/190] Ref #1886 --- centreon-plugins/cloud/azure/custom/api.pm | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/centreon-plugins/cloud/azure/custom/api.pm b/centreon-plugins/cloud/azure/custom/api.pm index ff5970c3e..165520f3c 100644 --- a/centreon-plugins/cloud/azure/custom/api.pm +++ b/centreon-plugins/cloud/azure/custom/api.pm @@ -153,7 +153,6 @@ sub settings { $self->build_options_for_httplib(); $self->{http}->add_header(key => 'Accept', value => 'application/json'); - $self->{http}->add_header(key => 'Content-Type', value => 'application/x-www-form-urlencoded'); if (defined($self->{access_token})) { $self->{http}->add_header(key => 'Authorization', value => 'Bearer ' . $self->{access_token}); } @@ -163,7 +162,13 @@ sub settings { sub get_access_token { my ($self, %options) = @_; - my $has_cache_file = $options{statefile}->read(statefile => 'azure_api_' . md5_hex($self->{subscription}) . '_' . md5_hex($self->{tenant}) . '_' . md5_hex($self->{client_id})); + my $has_cache_file = $options{statefile}->read( + statefile => + 'azure_api_' . + md5_hex($self->{subscription}) . '_' . + md5_hex($self->{tenant}) . '_' . + md5_hex($self->{client_id}) + ); my $expires_on = $options{statefile}->get(name => 'expires_on'); my $access_token = $options{statefile}->get(name => 'access_token'); @@ -180,7 +185,8 @@ sub get_access_token { my $content = $self->{http}->request( method => 'POST', query_form_post => $post_data, full_url => $self->{login_endpoint} . '/' . $self->{tenant} . '/oauth2/token', - hostname => '' + hostname => '', + header => [ 'Content-Type: application/x-www-form-urlencoded' ] ); if (!defined($content) || $content eq '' || $self->{http}->get_header(name => 'content-length') == 0) { @@ -220,10 +226,7 @@ sub request_api { $self->settings(); - $self->{output}->output_add(long_msg => "URL: '" . $options{full_url} . "'", debug => 1); - - my $content = $self->{http}->request(%options); - + my $content = $self->{http}->request(%options); if (!defined($content) || $content eq '' || $self->{http}->get_header(name => 'content-length') == 0) { $self->{output}->add_option_msg(short_msg => "Management endpoint API returns empty content [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']"); $self->{output}->option_exit(); From 8a1e9e7409826bd5db2b7575789c458b197b3daa Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 3 Apr 2020 11:44:18 +0200 Subject: [PATCH 054/190] remove useless dep --- centreon-plugins/apps/mq/rabbitmq/restapi/custom/api.pm | 1 - 1 file changed, 1 deletion(-) diff --git a/centreon-plugins/apps/mq/rabbitmq/restapi/custom/api.pm b/centreon-plugins/apps/mq/rabbitmq/restapi/custom/api.pm index c8a25b796..45526813b 100644 --- a/centreon-plugins/apps/mq/rabbitmq/restapi/custom/api.pm +++ b/centreon-plugins/apps/mq/rabbitmq/restapi/custom/api.pm @@ -25,7 +25,6 @@ use base qw(centreon::plugins::mode); use strict; use warnings; use centreon::plugins::http; -use URI::Encode; use JSON::XS; sub new { From e07568309c1d3b76a1817b4d364f795c4bef204f Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 3 Apr 2020 11:45:02 +0200 Subject: [PATCH 055/190] Fix #1886 --- .../azure/compute/virtualmachine/mode/cpu.pm | 15 +-- centreon-plugins/cloud/azure/custom/api.pm | 20 +++ centreon-plugins/cloud/azure/custom/azcli.pm | 16 +++ .../azure/management/monitor/mode/logs.pm | 121 ++++++++++++++++++ .../cloud/azure/management/monitor/plugin.pm | 3 +- 5 files changed, 166 insertions(+), 9 deletions(-) create mode 100644 centreon-plugins/cloud/azure/management/monitor/mode/logs.pm diff --git a/centreon-plugins/cloud/azure/compute/virtualmachine/mode/cpu.pm b/centreon-plugins/cloud/azure/compute/virtualmachine/mode/cpu.pm index 145c887fb..8149deda8 100644 --- a/centreon-plugins/cloud/azure/compute/virtualmachine/mode/cpu.pm +++ b/centreon-plugins/cloud/azure/compute/virtualmachine/mode/cpu.pm @@ -81,13 +81,12 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $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 =>v{ + 'resource:s@' => { name => 'resource' }, + 'resource-group:s' => { name => 'resource_group' }, + 'filter-metric:s' => { name => 'filter_metric' } + }); + return $self; } @@ -99,7 +98,7 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Need to specify either --resource with --resource-group option or --resource ."); $self->{output}->option_exit(); } - + $self->{az_resource} = $self->{option_results}->{resource}; $self->{az_resource_group} = $self->{option_results}->{resource_group} if (defined($self->{option_results}->{resource_group})); $self->{az_resource_type} = 'virtualMachines'; diff --git a/centreon-plugins/cloud/azure/custom/api.pm b/centreon-plugins/cloud/azure/custom/api.pm index 165520f3c..5bfa01459 100644 --- a/centreon-plugins/cloud/azure/custom/api.pm +++ b/centreon-plugins/cloud/azure/custom/api.pm @@ -635,6 +635,26 @@ sub azure_list_sqldatabases { return $response->{value}; } +sub azure_get_log_analytics_set_url { + my ($self, %options) = @_; + + my $uri = URI::Encode->new({encode_reserved => 1}); + my $encoded_query = $uri->encode($options{query}); + my $encoded_interval = $uri->encode($options{interval}); + my $url = $self->{management_endpoint} . '/v1/workspaces/' . $options{workspace_id} . '/query?query=' . $encoded_query . '×pan=' . $encoded_interval; + + return $url; +} + +sub azure_get_log_analytics { + my ($self, %options) = @_; + + my $full_url = $self->azure_get_log_analytics_set_url(%options); + my $response = $self->request_api(method => 'GET', full_url => $full_url, hostname => ''); + + return $response; +} + 1; __END__ diff --git a/centreon-plugins/cloud/azure/custom/azcli.pm b/centreon-plugins/cloud/azure/custom/azcli.pm index 3f2b7deed..5ae02540e 100644 --- a/centreon-plugins/cloud/azure/custom/azcli.pm +++ b/centreon-plugins/cloud/azure/custom/azcli.pm @@ -507,6 +507,22 @@ sub azure_list_sqldatabases { return $raw_results; } +sub azure_get_log_analytics_set_cmd { + my ($self, %options) = @_; + + return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); + + my $cmd_options = "monitor log-analytics query --workspace '$options{workspace_id}' --analytics-query \"$options{query}\" --timespan '$options{interval}'"; + return $cmd_options; +} + +sub azure_get_log_analytics { + my ($self, %options) = @_; + + my $cmd_options = $self->azure_get_log_analytics_set_cmd(%options); + return $self->execute(cmd_options => $cmd_options); +} + 1; __END__ diff --git a/centreon-plugins/cloud/azure/management/monitor/mode/logs.pm b/centreon-plugins/cloud/azure/management/monitor/mode/logs.pm new file mode 100644 index 000000000..27dc87574 --- /dev/null +++ b/centreon-plugins/cloud/azure/management/monitor/mode/logs.pm @@ -0,0 +1,121 @@ +# +# 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 cloud::azure::management::monitor::mode::logs; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total', nlabel => 'logs.total.count', set => { + key_values => [ { name => 'total' } ], + output_template => 'total logs: %s', + perfdatas => [ + { value => 'total_absolute', template => '%s', min => 0 } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'workspace-id:s' => { name => 'workspace_id' }, + 'query:s' => { name => 'query'} + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{workspace_id}) || $self->{option_results}->{workspace_id} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --workspace-id ."); + $self->{output}->option_exit(); + } + + if (!defined($self->{option_results}->{query}) || $self->{option_results}->{query} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify a query."); + $self->{output}->option_exit(); + } + + $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M'; +} + +sub manage_selection { + my ($self, %options) = @_; + + my ($log_results) = $options{custom}->azure_get_log_analytics( + workspace_id => $self->{option_results}->{workspace_id}, + query => $self->{option_results}->{query}, + interval => $self->{az_interval} + ); + + $self->{global} = { total => 0 }; + foreach my $table (@{$log_results->{tables}}) { + foreach (@{$table->{rows}}) { + $self->{global}->{total} += $_->[2]; + } + } +} + +1; + +__END__ + +=head1 MODE + +Check logs queries. +You should set option: --management-endpoint='https://api.loganalytics.io' + +=over 8 + +=item B<--workspace-id> + +Set workspace id (Required). + +=item B<--query> + +Set query (Required). +Syntax: https://docs.microsoft.com/en-us/azure/kusto/query/ + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: count. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/management/monitor/plugin.pm b/centreon-plugins/cloud/azure/management/monitor/plugin.pm index a217fb34e..197528585 100644 --- a/centreon-plugins/cloud/azure/management/monitor/plugin.pm +++ b/centreon-plugins/cloud/azure/management/monitor/plugin.pm @@ -31,10 +31,11 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( + 'alert' => 'cloud::azure::management::monitor::mode::alert', 'discovery' => 'cloud::azure::management::monitor::mode::discovery', 'get-metrics' => 'cloud::azure::management::monitor::mode::getmetrics', 'health' => 'cloud::azure::management::monitor::mode::health', - 'alert' => 'cloud::azure::management::monitor::mode::alert', + 'logs' => 'cloud::azure::management::monitor::mode::logs' ); $self->{custom_modes}{azcli} = 'cloud::azure::custom::azcli'; From c86077ec97c57200c78c9c3ca0c482613ba877ad Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 3 Apr 2020 13:14:47 +0200 Subject: [PATCH 056/190] perfdata vm memory --- .../apps/vmware/connector/mode/memoryvm.pm | 106 +++++++++--------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/centreon-plugins/apps/vmware/connector/mode/memoryvm.pm b/centreon-plugins/apps/vmware/connector/mode/memoryvm.pm index 80b375483..617b1736a 100644 --- a/centreon-plugins/apps/vmware/connector/mode/memoryvm.pm +++ b/centreon-plugins/apps/vmware/connector/mode/memoryvm.pm @@ -47,7 +47,7 @@ sub custom_usage_perfdata { my ($label, $nlabel) = ('used', $self->{nlabel}); my $value_perf = $self->{result_values}->{used}; if (defined($self->{instance_mode}->{option_results}->{free})) { - ($label, $nlabel) = ('free', 'vm.memory.free.bytes'); + ($label, $nlabel) = ('free', 'vm.memory.' . $self->{result_values}->{label_ref} . '.free.bytes'); $value_perf = $self->{result_values}->{free}; } @@ -58,7 +58,7 @@ sub custom_usage_perfdata { } $self->{output}->perfdata_add( - label => $label, unit => 'B', + label => $self->{result_values}->{label_ref} . '_' . $label, unit => 'B', instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, nlabel => $nlabel, value => $value_perf, @@ -88,12 +88,13 @@ sub custom_usage_output { my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); - my $msg = sprintf("Memory %s Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", - $self->{result_values}->{label_ref}, - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, - $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); - return $msg; + my $msg = sprintf( + 'Memory %s Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)', + $self->{result_values}->{label_ref}, + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free} + ); } sub custom_usage_calc { @@ -107,7 +108,7 @@ sub custom_usage_calc { $self->{error_msg} = 'size is 0'; return -20; } - + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_' . $self->{result_values}->{label_ref}}; $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; @@ -120,24 +121,21 @@ sub custom_overhead_output { my ($self, %options) = @_; my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{overhead_absolute}); - my $msg = sprintf("Memory overhead: %s %s", $value, $unit); - return $msg; + return sprintf('Memory overhead: %s %s', $value, $unit); } sub custom_ballooning_output { my ($self, %options) = @_; my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{vmmemctl_absolute}); - my $msg = sprintf("Memory ballooning: %s %s", $value, $unit); - return $msg; + return sprintf('Memory ballooning: %s %s', $value, $unit); } sub custom_shared_output { my ($self, %options) = @_; my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{shared_absolute}); - my $msg = sprintf("Memory shared: %s %s", $value, $unit); - return $msg; + return sprintf('Memory shared: %s %s', $value, $unit); } sub set_counters { @@ -162,30 +160,30 @@ sub set_counters { closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold } - }, + } ]; $self->{maps_counters}->{global_consumed} = [ - { label => 'consumed', nlabel => 'vm.memory.usage.bytes', set => { + { label => 'consumed', nlabel => 'vm.memory.consumed.usage.bytes', set => { key_values => [ { name => 'consumed' }, { name => 'total' } ], closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'consumed' }, closure_custom_output => $self->can('custom_usage_output'), closure_custom_perfdata => $self->can('custom_usage_perfdata'), - closure_custom_threshold_check => $self->can('custom_usage_threshold'), + closure_custom_threshold_check => $self->can('custom_usage_threshold') } - }, + } ]; $self->{maps_counters}->{global_active} = [ - { label => 'active', nlabel => 'vm.memory.active.bytes', set => { + { label => 'active', nlabel => 'vm.memory.active.usage.bytes', set => { key_values => [ { name => 'active' }, { name => 'total' } ], closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'active' }, closure_custom_output => $self->can('custom_usage_output'), closure_custom_perfdata => $self->can('custom_usage_perfdata'), - closure_custom_threshold_check => $self->can('custom_usage_threshold'), + closure_custom_threshold_check => $self->can('custom_usage_threshold') } - }, + } ]; $self->{maps_counters}->{global_overhead} = [ { label => 'overhead', nlabel => 'vm.memory.overhead.bytes', set => { @@ -193,10 +191,10 @@ sub set_counters { closure_custom_output => $self->can('custom_overhead_output'), perfdatas => [ { label => 'overhead', value => 'overhead_absolute', template => '%s', unit => 'B', - min => 0, label_extra_instance => 1 }, - ], + min => 0, label_extra_instance => 1 } + ] } - }, + } ]; $self->{maps_counters}->{global_vmmemctl} = [ { label => 'ballooning', nlabel => 'vm.memory.ballooning.bytes', set => { @@ -204,10 +202,10 @@ sub set_counters { closure_custom_output => $self->can('custom_ballooning_output'), perfdatas => [ { label => 'ballooning', value => 'vmmemctl_absolute', template => '%s', unit => 'B', - min => 0, label_extra_instance => 1 }, - ], + min => 0, label_extra_instance => 1 } + ] } - }, + } ]; $self->{maps_counters}->{global_shared} = [ { label => 'shared', nlabel => 'vm.memory.shared.bytes', set => { @@ -215,10 +213,10 @@ sub set_counters { closure_custom_output => $self->can('custom_shared_output'), perfdatas => [ { label => 'shared', value => 'shared_absolute', template => '%s', unit => 'B', - min => 0, label_extra_instance => 1 }, - ], + min => 0, label_extra_instance => 1 } + ] } - }, + } ]; } @@ -230,7 +228,7 @@ sub prefix_vm_output { $msg .= ' [annotation: ' . $options{instance_value}->{config_annotation} . ']'; } $msg .= ' : '; - + return $msg; } @@ -241,7 +239,7 @@ sub vm_long_output { if (defined($options{instance_value}->{config_annotation})) { $msg .= ' [annotation: ' . $options{instance_value}->{config_annotation} . ']'; } - + return $msg; } @@ -251,20 +249,20 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "vm-hostname:s" => { name => 'vm_hostname' }, - "filter" => { name => 'filter' }, - "scope-datacenter:s" => { name => 'scope_datacenter' }, - "scope-cluster:s" => { name => 'scope_cluster' }, - "scope-host:s" => { name => 'scope_host' }, - "filter-description:s" => { name => 'filter_description' }, - "filter-os:s" => { name => 'filter_os' }, - "filter-uuid:s" => { name => 'filter_uuid' }, - "display-description" => { name => 'display_description' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, - "unknown-status:s" => { name => 'unknown_status', default => '%{connection_state} !~ /^connected$/i or %{power_state} !~ /^poweredOn$/i' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, + 'vm-hostname:s' => { name => 'vm_hostname' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' }, + 'scope-cluster:s' => { name => 'scope_cluster' }, + 'scope-host:s' => { name => 'scope_host' }, + 'filter-description:s' => { name => 'filter_description' }, + 'filter-os:s' => { name => 'filter_os' }, + 'filter-uuid:s' => { name => 'filter_uuid' }, + 'display-description' => { name => 'display_description' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' }, + 'unknown-status:s' => { name => 'unknown_status', default => '%{connection_state} !~ /^connected$/i or %{power_state} !~ /^poweredOn$/i' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, }); return $self; @@ -281,19 +279,21 @@ sub manage_selection { my ($self, %options) = @_; $self->{vm} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'memvm'); + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'memvm' + ); foreach my $vm_id (keys %{$response->{data}}) { my $vm_name = $response->{data}->{$vm_id}->{name}; - + $self->{vm}->{$vm_name} = { display => $vm_name, global => { connection_state => $response->{data}->{$vm_id}->{connection_state}, power_state => $response->{data}->{$vm_id}->{power_state}, }, }; - + foreach (('consumed', 'active', 'overhead', 'vmmemctl', 'shared')) { next if (!defined($response->{data}->{$vm_id}->{'mem.' . $_ . '.average'})); $self->{vm}->{$vm_name}->{'global_' . $_} = { @@ -301,7 +301,7 @@ sub manage_selection { total => $response->{data}->{$vm_id}->{memory_size} }; } - + if (defined($self->{option_results}->{display_description})) { $self->{vm}->{$vm_name}->{config_annotation} = $options{custom}->strip_cr(value => $response->{data}->{$vm_id}->{'config.annotation'}); } From fb08b42ac36660ef8a883303b6d5e0e4fd73b3c9 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 3 Apr 2020 14:43:43 +0200 Subject: [PATCH 057/190] Fix #1902 --- .../network/arista/snmp/mode/memory.pm | 181 ++++++++++++------ 1 file changed, 121 insertions(+), 60 deletions(-) diff --git a/centreon-plugins/network/arista/snmp/mode/memory.pm b/centreon-plugins/network/arista/snmp/mode/memory.pm index 6ab97efb8..9d8b90d59 100644 --- a/centreon-plugins/network/arista/snmp/mode/memory.pm +++ b/centreon-plugins/network/arista/snmp/mode/memory.pm @@ -25,45 +25,144 @@ use base qw(snmp_standard::mode::storage); use strict; use warnings; -sub default_storage_type { +sub custom_usage_output { my ($self, %options) = @_; - - return '^(hrStorageRam|hrStorageFlashMemory)'; + + return sprintf( + 'Ram Total: %s %s Used (-buffers/cache): %s %s (%.2f%%) Free: %s %s (%.2f%%)', + $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}), + $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}), + $self->{result_values}->{prct_used_absolute}, + $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}), + $self->{result_values}->{prct_free_absolute} + ); } sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ - { name => 'storage', type => 1, cb_prefix_output => 'prefix_storage_output', message_multiple => 'All memory spaces are ok' }, + { name => 'ram', type => 0, skipped_code => { -10 => 1 } } ]; - - $self->{maps_counters}->{storage} = [ + + $self->{maps_counters}->{ram} = [ { label => 'usage', nlabel => 'memory.usage.bytes', set => { - key_values => [ { name => 'display' }, { name => 'used' }, { name => 'size' }, { name => 'allocation_units' } ], - closure_custom_calc => $self->can('custom_usage_calc'), + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], closure_custom_output => $self->can('custom_usage_output'), - closure_custom_perfdata => $self->can('custom_usage_perfdata'), - closure_custom_threshold_check => $self->can('custom_usage_threshold'), + perfdatas => [ + { value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1 } + ] } }, + { label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1 } + ] + } + }, + { label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => { + key_values => [ { name => 'prct_used' } ], + output_template => 'Ram Used : %.2f %%', + perfdatas => [ + { value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, + unit => '%' } + ] + } + }, + { label => 'buffer', nlabel => 'memory.buffer.bytes', set => { + key_values => [ { name => 'buffer' } ], + output_template => 'Buffer: %s %s', + output_change_bytes => 1, + perfdatas => [ + { value => 'buffer_absolute', template => '%d', + min => 0, unit => 'B' } + ] + } + }, + { label => 'cached', nlabel => 'memory.cached.bytes', set => { + key_values => [ { name => 'cached' } ], + output_template => 'Cached: %s %s', + output_change_bytes => 1, + perfdatas => [ + { value => 'cached_absolute', template => '%d', + min => 0, unit => 'B' } + ] + } + } ]; } -sub prefix_storage_output { - my ($self, %options) = @_; - - return "Memory space '" . $options{instance_value}->{display} . "' "; -} - sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; return $self; } +my $mapping = { + hrStorageDescr => { oid => '.1.3.6.1.2.1.25.2.3.1.3' }, + hrStorageAllocationUnits => { oid => '.1.3.6.1.2.1.25.2.3.1.4' }, + hrStorageSize => { oid => '.1.3.6.1.2.1.25.2.3.1.5' }, + hrStorageUsed => { oid => '.1.3.6.1.2.1.25.2.3.1.6' } +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $storage_type_ram = '.1.3.6.1.2.1.25.2.1.2'; + my $oid_hrstoragetype = '.1.3.6.1.2.1.25.2.3.1.2'; + + my $snmp_result = $options{snmp}->get_table(oid => $oid_hrstoragetype, nothing_quit => 1); + my $storages = []; + foreach (keys %$snmp_result) { + next if ($snmp_result->{$_} ne $storage_type_ram); + /^$oid_hrstoragetype\.(.*)$/; + push @$storages, $1; + } + + $options{snmp}->load( + oids => [map($_->{oid}, values(%$mapping))], + instances => $storages, + nothing_quit => 1 + ); + $snmp_result = $options{snmp}->get_leef(); + + my ($total, $used, $cached, $buffer); + #.1.3.6.1.2.1.25.2.3.1.3.1 = STRING: RAM + #.1.3.6.1.2.1.25.2.3.1.3.2 = STRING: RAM (Buffers) + #.1.3.6.1.2.1.25.2.3.1.3.3 = STRING: RAM (Cache) + foreach (@$storages) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + my $current = $result->{hrStorageUsed} * $result->{hrStorageAllocationUnits}; + next if ($current < 0); + + if ($result->{hrStorageDescr} =~ /RAM.*?Cache/i) { + $cached = $current; + } elsif ($result->{hrStorageDescr} =~ /RAM.*?Buffers/i) { + $buffer = $current; + } elsif ($result->{hrStorageDescr} =~ /RAM/i) { + $used = $current; + $total = $result->{hrStorageSize} * $result->{hrStorageAllocationUnits}; + } + } + + $used -= (defined($cached) ? $cached : 0) - (defined($buffer) ? $buffer : 0); + $self->{ram} = { + total => $total, + cached => $cached, + buffer => $buffer, + used => $used, + free => $total - $used, + prct_used => $used * 100 / $total, + prct_free => 100 - ($used * 100 / $total) + }; +} + 1; __END__ @@ -74,49 +173,11 @@ Check memory. =over 8 -=item B<--warning-usage> +=item B<--warning-*> B<--critical-*> -Threshold warning. - -=item B<--critical-usage> - -Threshold critical. - -=item B<--units> - -Units of thresholds (Default: '%') ('%', 'B'). - -=item B<--free> - -Thresholds are on free space left. - -=item B<--storage> - -Set the storage (number expected) ex: 1, 2,... (empty means 'check all storage'). - -=item B<--name> - -Allows to use storage name with option --storage instead of storage oid index. - -=item B<--regexp> - -Allows to use regexp to filter storage (with option --name). - -=item B<--regexp-isensitive> - -Allows to use regexp non case-sensitive (with --regexp). - -=item B<--reload-cache-time> - -Time in minutes before reloading cache file (default: 180). - -=item B<--show-cache> - -Display cache storage datas. - -=item B<--filter-storage-type> - -Filter storage types with a regexp (Default: '^(hrStorageRam|hrStorageFlashMemory)$'). +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%), +'buffer' (B), 'cached' (B). =back From 472d9d19844662816ee6add8ebb3acd7cd2df2bf Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 3 Apr 2020 14:57:02 +0200 Subject: [PATCH 058/190] enhance typo --- .../acs/6000/snmp/mode/components/psu.pm | 29 +++++++++++------ .../avocent/acs/6000/snmp/mode/hardware.pm | 23 +++++++------ .../acs/8000/snmp/mode/components/psu.pm | 32 ++++++++++++------- .../avocent/acs/8000/snmp/mode/hardware.pm | 19 ++++++----- 4 files changed, 60 insertions(+), 43 deletions(-) diff --git a/centreon-plugins/hardware/kvm/avocent/acs/6000/snmp/mode/components/psu.pm b/centreon-plugins/hardware/kvm/avocent/acs/6000/snmp/mode/components/psu.pm index d64ae8273..9e8994891 100644 --- a/centreon-plugins/hardware/kvm/avocent/acs/6000/snmp/mode/components/psu.pm +++ b/centreon-plugins/hardware/kvm/avocent/acs/6000/snmp/mode/components/psu.pm @@ -33,32 +33,41 @@ my $oid_acsPowerSupply = '.1.3.6.1.4.1.10418.16.2.1.8'; sub load { my ($self) = @_; - + push @{$self->{request}}, { oid => $oid_acsPowerSupply }; } sub check_psu { my ($self, %options) = @_; - + return if ($self->check_filter(section => 'psu', instance => $options{instance})); return if ($options{state} eq 'powerNotInstalled' && $self->absent_problem(section => 'psu', instance => $options{instance})); $self->{components}->{psu}->{total}++; - $self->{output}->output_add(long_msg => sprintf("power supply '%s' status is %s.", - $options{instance}, $options{state} - )); + $self->{output}->output_add( + long_msg => sprintf( + "power supply '%s' status is %s.", + $options{instance}, $options{state} + ) + ); + my $exit = $self->get_severity(section => 'psu', value => $options{state}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Power supply '%s' status is %s", - $options{instance}, $options{state})); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Power supply '%s' status is %s", + $options{instance}, + $options{state} + ) + ); } } sub check { my ($self) = @_; - + $self->{output}->output_add(long_msg => "Checking power supplies"); $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; return if ($self->check_filter(section => 'psu')); @@ -68,4 +77,4 @@ sub check { check_psu($self, state => $result->{acsPowerSupplyStatePw2}, instance => '2'); } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/kvm/avocent/acs/6000/snmp/mode/hardware.pm b/centreon-plugins/hardware/kvm/avocent/acs/6000/snmp/mode/hardware.pm index 4b92bb5ff..d8f24ca3a 100644 --- a/centreon-plugins/hardware/kvm/avocent/acs/6000/snmp/mode/hardware.pm +++ b/centreon-plugins/hardware/kvm/avocent/acs/6000/snmp/mode/hardware.pm @@ -27,26 +27,26 @@ use warnings; sub set_system { my ($self, %options) = @_; - + $self->{regexp_threshold_overload_check_section_option} = '^(psu)$'; - + $self->{cb_hook2} = 'snmp_execute'; - + $self->{thresholds} = { psu => [ ['statePowerOn', 'OK'], ['statePowerOff', 'CRITICAL'], - ['powerNotInstalled', 'OK'], - ], + ['powerNotInstalled', 'OK'] + ] }; - + $self->{components_path} = 'hardware::kvm::avocent::acs::6000::snmp::mode::components'; $self->{components_module} = ['psu']; } sub snmp_execute { my ($self, %options) = @_; - + $self->{snmp} = $options{snmp}; $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); } @@ -55,10 +55,9 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - }); + + $options{options}->add_options(arguments => { + }); return $self; } @@ -101,4 +100,4 @@ Example: --threshold-overload='psu,CRITICAL,^(?!(statePowerOn)$)' =back -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/components/psu.pm b/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/components/psu.pm index cc79ec0a1..c17cb32d4 100644 --- a/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/components/psu.pm +++ b/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/components/psu.pm @@ -27,38 +27,48 @@ my %map_states = (1 => 'statePowerOn', 2 => 'statePowerOff', 9999 => 'powerNotIn my $mapping = { acsPowerSupplyStatePw1 => { oid => '.1.3.6.1.4.1.10418.26.2.1.8.2', map => \%map_states }, - acsPowerSupplyStatePw2 => { oid => '.1.3.6.1.4.1.10418.26.2.1.8.3', map => \%map_states }, + acsPowerSupplyStatePw2 => { oid => '.1.3.6.1.4.1.10418.26.2.1.8.3', map => \%map_states } }; my $oid_acsPowerSupply = '.1.3.6.1.4.1.10418.26.2.1.8'; sub load { my ($self) = @_; - + push @{$self->{request}}, { oid => $oid_acsPowerSupply }; } sub check_psu { my ($self, %options) = @_; - + return if ($self->check_filter(section => 'psu', instance => $options{instance})); return if ($options{state} eq 'powerNotInstalled' && $self->absent_problem(section => 'psu', instance => $options{instance})); $self->{components}->{psu}->{total}++; - $self->{output}->output_add(long_msg => sprintf("power supply '%s' status is %s.", - $options{instance}, $options{state} - )); + $self->{output}->output_add( + long_msg => sprintf( + "power supply '%s' status is %s.", + $options{instance}, + $options{state} + ) + ); + my $exit = $self->get_severity(section => 'psu', value => $options{state}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Power supply '%s' status is %s", - $options{instance}, $options{state})); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Power supply '%s' status is %s", + $options{instance}, + $options{state} + ) + ); } } sub check { my ($self) = @_; - + $self->{output}->output_add(long_msg => "Checking power supplies"); $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; return if ($self->check_filter(section => 'psu')); @@ -68,4 +78,4 @@ sub check { check_psu($self, state => $result->{acsPowerSupplyStatePw2}, instance => '2'); } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/hardware.pm b/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/hardware.pm index 9eabd07b3..8a3283d75 100644 --- a/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/hardware.pm +++ b/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/hardware.pm @@ -27,17 +27,17 @@ use warnings; sub set_system { my ($self, %options) = @_; - + $self->{regexp_threshold_overload_check_section_option} = '^(psu)$'; - + $self->{cb_hook2} = 'snmp_execute'; - + $self->{thresholds} = { psu => [ ['statePowerOn', 'OK'], ['statePowerOff', 'CRITICAL'], - ['powerNotInstalled', 'OK'], - ], + ['powerNotInstalled', 'OK'] + ] }; $self->{components_path} = 'hardware::kvm::avocent::acs::8000::snmp::mode::components'; @@ -55,10 +55,9 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - }); + + $options{options}->add_options(arguments => { + }); return $self; } @@ -101,4 +100,4 @@ Example: --threshold-overload='psu,CRITICAL,^(?!(statePowerOn)$)' =back -=cut \ No newline at end of file +=cut From fb2b8d3ca096a839b92831b5572d029f8175a90a Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 3 Apr 2020 14:59:48 +0200 Subject: [PATCH 059/190] acs 8000 new perfdata --- .../hardware/kvm/avocent/acs/8000/snmp/mode/hardware.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/hardware.pm b/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/hardware.pm index 8a3283d75..4efd2cde9 100644 --- a/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/hardware.pm +++ b/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/hardware.pm @@ -53,7 +53,7 @@ sub snmp_execute { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { From 5f751570c2d8714dd07c345c0fdfbd115f0107e6 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 3 Apr 2020 15:30:51 +0200 Subject: [PATCH 060/190] add endpoint in access token azure --- centreon-plugins/cloud/azure/custom/api.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/centreon-plugins/cloud/azure/custom/api.pm b/centreon-plugins/cloud/azure/custom/api.pm index 5bfa01459..6fb27744e 100644 --- a/centreon-plugins/cloud/azure/custom/api.pm +++ b/centreon-plugins/cloud/azure/custom/api.pm @@ -167,7 +167,8 @@ sub get_access_token { 'azure_api_' . md5_hex($self->{subscription}) . '_' . md5_hex($self->{tenant}) . '_' . - md5_hex($self->{client_id}) + md5_hex($self->{client_id}) . '_' . + md5_hex($self->{management_endpoint}) ); my $expires_on = $options{statefile}->get(name => 'expires_on'); my $access_token = $options{statefile}->get(name => 'access_token'); From 5974948fb3b883e8e509be03bc41454af6c105cb Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 3 Apr 2020 16:05:51 +0200 Subject: [PATCH 061/190] add mode for avocent acs 8000 --- .../avocent/acs/8000/snmp/mode/serialports.pm | 196 ++++++++++++++++++ .../kvm/avocent/acs/8000/snmp/plugin.pm | 1 + 2 files changed, 197 insertions(+) create mode 100644 centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/serialports.pm diff --git a/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/serialports.pm b/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/serialports.pm new file mode 100644 index 000000000..152a73e9c --- /dev/null +++ b/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/mode/serialports.pm @@ -0,0 +1,196 @@ +# +# 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 hardware::kvm::avocent::acs::8000::snmp::mode::serialports; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use Digest::MD5 qw(md5_hex); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + 'status: %s', + $self->{result_values}->{status} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'serials', type => 1, cb_prefix_output => 'prefix_serial_output', message_multiple => 'All serial ports are ok' } + ]; + + $self->{maps_counters}->{serials} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + }, + { label => 'traffic-in', nlabel => 'serialport.traffic.in.bitspersecond', set => { + key_values => [ { name => 'traffic_in', diff => 1 }, { name => 'display' } ], + output_template => 'traffic in: %s%s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_in_per_second', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + }, + { label => 'traffic-out', nlabel => 'serialport.traffic.out.bitspersecond', set => { + key_values => [ { name => 'traffic_out', diff => 1 }, { name => 'display' } ], + output_template => 'traffic out: %s%s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_out_per_second', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + } + ]; +} + +sub prefix_serial_output { + my ($self, %options) = @_; + + return "Serial port '" . $options{instance_value}->{display} . "' "; +} + +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 => '' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros( + macros => [ + 'unknown_status', 'warning_status', 'critical_status' + ] + ); +} + +my $map_status = { 1 => 'disabled', 2 => 'idle', 3 => 'inUse' }; + +my $mapping = { + status => { oid => '.1.3.6.1.4.1.10418.26.2.3.2.1.3', map => $map_status }, # acsSerialPortTableStatus + traffic_out => { oid => '.1.3.6.1.4.1.10418.26.2.3.2.1.16' }, # acsSerialPortTableTxBytes + traffic_in => { oid => '.1.3.6.1.4.1.10418.26.2.3.2.1.17' } # acsSerialPortTableRxBytes +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_acsSerialPortTableDeviceName = '.1.3.6.1.4.1.10418.26.2.3.2.1.2'; + my $snmp_result = $options{snmp}->get_table( + oid => $oid_acsSerialPortTableDeviceName, + nothing_quit => 1 + ); + + $self->{serials} = {}; + foreach (keys %$snmp_result) { + /\.(\d+)$/; + my $instance = $1; + my $name = $snmp_result->{$_}; + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping port '" . $name . "'.", debug => 1); + next; + } + + $self->{serials}->{$instance} = { display => $name }; + } + + return if (scalar(keys %{$self->{serials}}) <= 0); + + $options{snmp}->load( + oids => [ map($_->{oid}, values(%$mapping)) ], + instances => [ keys %{$self->{serials}} ], + instance_regexp => '^(.*)$' + ); + $snmp_result = $options{snmp}->get_leef(); + foreach (keys %{$self->{serials}}) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + $self->{serials}->{$_} = { %{$self->{serials}->{$_}}, %$result }; + } + + $self->{cache_name} = 'avocent_acs_8000_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + (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 serial ports. + +=over 8 + +=item B<--filter-name> + +Filter by serial device 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. +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'traffic-in', 'traffic-out'. + +=back + +=cut diff --git a/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/plugin.pm b/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/plugin.pm index 114d91643..0cc231f14 100644 --- a/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/plugin.pm +++ b/centreon-plugins/hardware/kvm/avocent/acs/8000/snmp/plugin.pm @@ -35,6 +35,7 @@ sub new { 'hardware' => 'hardware::kvm::avocent::acs::8000::snmp::mode::hardware', 'load' => 'snmp_standard::mode::loadaverage', 'memory' => 'snmp_standard::mode::memory', + 'serial-ports' => 'hardware::kvm::avocent::acs::8000::snmp::mode::serialports' ); return $self; From 85e1a1af6a07857cb81f2b6a8a993478119db822 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 3 Apr 2020 16:09:02 +0200 Subject: [PATCH 062/190] fix azure logs --- centreon-plugins/cloud/azure/management/monitor/mode/logs.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/cloud/azure/management/monitor/mode/logs.pm b/centreon-plugins/cloud/azure/management/monitor/mode/logs.pm index 27dc87574..f238c4b81 100644 --- a/centreon-plugins/cloud/azure/management/monitor/mode/logs.pm +++ b/centreon-plugins/cloud/azure/management/monitor/mode/logs.pm @@ -86,7 +86,7 @@ sub manage_selection { $self->{global} = { total => 0 }; foreach my $table (@{$log_results->{tables}}) { foreach (@{$table->{rows}}) { - $self->{global}->{total} += $_->[2]; + $self->{global}->{total} += $_->[0]; } } } From bc3833b4c6f9c5be69aa2031caf3973f60b4ec90 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Sun, 5 Apr 2020 19:06:03 +0200 Subject: [PATCH 063/190] new(plugin) add sfdc minimal check --- .../apps/salesforce/restapi/custom/api.pm | 168 ++++++++++++++++++ .../salesforce/restapi/mode/sfdcinstance.pm | 142 +++++++++++++++ .../apps/salesforce/restapi/plugin.pm | 48 +++++ 3 files changed, 358 insertions(+) create mode 100644 centreon-plugins/apps/salesforce/restapi/custom/api.pm create mode 100644 centreon-plugins/apps/salesforce/restapi/mode/sfdcinstance.pm create mode 100644 centreon-plugins/apps/salesforce/restapi/plugin.pm diff --git a/centreon-plugins/apps/salesforce/restapi/custom/api.pm b/centreon-plugins/apps/salesforce/restapi/custom/api.pm new file mode 100644 index 000000000..f70c32fc9 --- /dev/null +++ b/centreon-plugins/apps/salesforce/restapi/custom/api.pm @@ -0,0 +1,168 @@ +# +# 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::salesforce::restapi::custom::api; + +use strict; +use warnings; +use centreon::plugins::http; +use JSON; + +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 => { + "hostname:s" => { name => 'hostname' }, + "timeout:s" => { name => 'timeout' }, + "api-versions:s" => { name => 'api_version' }, + }); + } + $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} : 'api.status.salesforce.com'; + $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; + $self->{api_version} = (defined($self->{option_results}->{api_version})) ? $self->{option_results}->{api_version} : 'v1'; + + 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} = 443; + $self->{option_results}->{proto} = 'https'; +} + +sub settings { + my ($self, %options) = @_; + + $self->build_options_for_httplib(); + $self->{http}->add_header(key => 'Accept', value => 'application/json'); + $self->{http}->add_header(key => 'Content-Type', value => 'application/json'); + $self->{http}->set_options(%{$self->{option_results}}); +} + +sub request_api { + my ($self, %options) = @_; + + $self->settings(); + + my $content = $self->{http}->request(method => 'GET', url_path => '/' . $self->{api_version} . $options{path}, + critical_status => '', warning_status => '', unknown_status => ''); + + my $decoded; + eval { + $decoded = decode_json($content); + }; + if ($@) { + $self->{output}->output_add(long_msg => $content, debug => 1); + $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); + $self->{output}->option_exit(); + } + if ($self->{http}->get_code() != 200) { + $self->{output}->add_option_msg(short_msg => "Connection issue: " . $decoded->{msg}); + $self->{output}->option_exit(); + } + + return $decoded; +} + +1; + +__END__ + +=head1 NAME + +SFDC API boilerplate + +=head1 SYNOPSIS + +Get informations from SFDC API + +=head1 REST API OPTIONS + +=over 8 + +=item B<--hostname> + +Set hostname to query (default: 'api.status.salesforce.com') + +=item B<--timeout> + +Set HTTP timeout in seconds (Default: '10'). + +=item B<--api-path> + +API base url path (Default: '/v1'). + +=back + +=head1 DESCRIPTION + +B. + +=cut + diff --git a/centreon-plugins/apps/salesforce/restapi/mode/sfdcinstance.pm b/centreon-plugins/apps/salesforce/restapi/mode/sfdcinstance.pm new file mode 100644 index 000000000..ac941ada3 --- /dev/null +++ b/centreon-plugins/apps/salesforce/restapi/mode/sfdcinstance.pm @@ -0,0 +1,142 @@ +# +# 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::salesforce::restapi::mode::sfdcinstance; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + "Salesforce '%s' instance status is '%s' (active:'%s') ", + $self->{result_values}->{name}, + $self->{result_values}->{status}, + $self->{result_values}->{active} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'status', type => 1 }, + ]; + + $self->{maps_counters}->{status} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'active' }, { name => 'name' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + }, + { label => 'incident', nlabel => 'salesforce.incident.current.count', set => { + key_values => [ { name => 'incident' } ], + output_template => '%s incidents currently', + perfdatas => [ + { label => 'incident', value => 'incident_absolute', template => '%s', + min => 0, label_extra_instance => 1 }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'instance:s@' => { name => 'instance' }, + 'alias' => { name => 'use_alias' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /OK/' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); + +} + +sub manage_selection { + my ($self, %options) = @_; + + my $instance_path = (defined($self->{option_results}->{use_alias})) ? '/instanceAliases/' : '/instances/'; + + foreach my $instance (@{$self->{option_results}->{instance}}) { + my $result = $options{custom}->request_api(path => $instance_path . $instance . '/status'); + + $self->{status}->{$instance} = { + active => $result->{isActive}, + incident => scalar(@{$result->{Incidents}}), + name => $instance, + status => $result->{status}, + }; + } + +} + +1; + +__END__ + +=head1 MODE + +Check instance status and incident count through Salesforce API + +=over 8 + +=item B<--instance> + +Set your instance identifier + +=item B<--alias> + +Add this option if your want to use your instance alias + +=item B<--unknown-status> + +Set unknown threshold for instance status (Default: ''). + +=item B<--warning-status> + +Set warning threshold for instance status (Default: ''). + +=item B<--critical-status> + +Set critical threshold for instance status (Default: '%{status} !~ /OK/'). + +=back + +=cut + diff --git a/centreon-plugins/apps/salesforce/restapi/plugin.pm b/centreon-plugins/apps/salesforce/restapi/plugin.pm new file mode 100644 index 000000000..3b2ae71cd --- /dev/null +++ b/centreon-plugins/apps/salesforce/restapi/plugin.pm @@ -0,0 +1,48 @@ +# +# 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::salesforce::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}} = ( + 'sfdc-instance' => 'apps::salesforce::restapi::mode::sfdcinstance', + ); + $self->{custom_modes}{api} = 'apps::salesforce::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check SFDC service through its status API + +=cut From 7523b1ead072e17726d0d8c01765ab5b74ae9dea Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 6 Apr 2020 10:47:50 +0200 Subject: [PATCH 064/190] add name for pnic vmware --- .../apps/vmware/connector/mode/nethost.pm | 120 +++++++++--------- 1 file changed, 61 insertions(+), 59 deletions(-) diff --git a/centreon-plugins/apps/vmware/connector/mode/nethost.pm b/centreon-plugins/apps/vmware/connector/mode/nethost.pm index 94f6acb9b..05488e026 100644 --- a/centreon-plugins/apps/vmware/connector/mode/nethost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/nethost.pm @@ -29,8 +29,7 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - my $msg = 'status ' . $self->{result_values}->{status}; - return $msg; + return 'status ' . $self->{result_values}->{status}; } sub custom_status_calc { @@ -43,8 +42,7 @@ sub custom_status_calc { sub custom_linkstatus_output { my ($self, %options) = @_; - my $msg = 'status ' . $self->{result_values}->{link_status}; - return $msg; + return 'status ' . $self->{result_values}->{link_status}; } sub custom_linkstatus_calc { @@ -58,9 +56,10 @@ sub custom_traffic_output { my ($self, %options) = @_; my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic}, network => 1); - my $msg = sprintf("traffic %s : %s/s (%.2f %%)", - $self->{result_values}->{label_ref}, $value . $unit, $self->{result_values}->{traffic_prct}); - return $msg; + return sprintf( + "traffic %s : %s/s (%.2f %%)", + $self->{result_values}->{label_ref}, $value . $unit, $self->{result_values}->{traffic_prct} + ); } sub custom_traffic_calc { @@ -78,11 +77,12 @@ sub custom_traffic_calc { sub custom_dropped_output { my ($self, %options) = @_; - my $msg = sprintf("packets %s dropped : %.2f %% (%d/%d packets)", - $self->{result_values}->{label_ref}, - $self->{result_values}->{dropped_prct}, - $self->{result_values}->{dropped}, $self->{result_values}->{packets}); - return $msg; + return sprintf( + 'packets %s dropped : %.2f %% (%d/%d packets)', + $self->{result_values}->{label_ref}, + $self->{result_values}->{dropped_prct}, + $self->{result_values}->{dropped}, $self->{result_values}->{packets} + ); } sub custom_dropped_calc { @@ -109,22 +109,22 @@ sub set_counters { { name => 'global', type => 0, skipped_code => { -10 => 1 } }, { name => 'global_host', type => 0, skipped_code => { -10 => 1 } }, { name => 'pnic', cb_prefix_output => 'prefix_pnic_output', message_multiple => 'All physical interfaces are ok', type => 1, skipped_code => { -10 => 1 } }, - { name => 'vswitch', cb_prefix_output => 'prefix_vswitch_output', message_multiple => 'All vswitchs are ok', type => 1, skipped_code => { -10 => 1 } }, + { name => 'vswitch', cb_prefix_output => 'prefix_vswitch_output', message_multiple => 'All vswitchs are ok', type => 1, skipped_code => { -10 => 1 } } ] } ]; - + $self->{maps_counters}->{global} = [ { label => 'status', threshold => 0, set => { key_values => [ { name => 'state' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold } - }, + } ]; - + $self->{maps_counters}->{global_host} = [ { label => 'host-traffic-in', nlabel => 'host.traffic.in.bitsperseconds', set => { key_values => [ { name => 'traffic_in' } ], @@ -132,8 +132,8 @@ sub set_counters { output_change_bytes => 2, perfdatas => [ { label => 'host_traffic_in', value => 'traffic_in_absolute', template => '%s', - unit => 'b/s', min => 0, label_extra_instance => 1 }, - ], + unit => 'b/s', min => 0, label_extra_instance => 1 } + ] } }, { label => 'host-traffic-out', nlabel => 'host.traffic.out.bitsperseconds', set => { @@ -142,12 +142,12 @@ sub set_counters { output_change_bytes => 2, perfdatas => [ { label => 'host_traffic_out', value => 'traffic_out_absolute', template => '%s', - unit => 'b/s', min => 0, label_extra_instance => 1 }, - ], + unit => 'b/s', min => 0, label_extra_instance => 1 } + ] } - }, + } ]; - + $self->{maps_counters}->{vswitch} = [ { label => 'vswitch-traffic-in', nlabel => 'host.vswitch.traffic.in.bitsperseconds', set => { key_values => [ { name => 'traffic_in' } ], @@ -165,19 +165,19 @@ sub set_counters { output_change_bytes => 2, perfdatas => [ { label => 'vswitch_traffic_out', value => 'traffic_out_absolute', template => '%s', - unit => 'b/s', min => 0, label_extra_instance => 1 }, - ], + unit => 'b/s', min => 0, label_extra_instance => 1 } + ] } - }, + } ]; - + $self->{maps_counters}->{pnic} = [ { label => 'link-status', threshold => 0, set => { - key_values => [ { name => 'status' } ], + key_values => [ { name => 'status' }, { name => 'display' } ], closure_custom_calc => $self->can('custom_linkstatus_calc'), closure_custom_output => $self->can('custom_linkstatus_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold } }, { label => 'link-traffic-in', nlabel => 'host.traffic.in.bitsperseconds', set => { @@ -187,8 +187,8 @@ sub set_counters { threshold_use => 'traffic_prct', perfdatas => [ { label => 'traffic_in', value => 'traffic', template => '%s', unit => 'b/s', - min => 0, max => 'speed', threshold_total => 'speed', cast_int => 1, label_extra_instance => 1 }, - ], + min => 0, max => 'speed', threshold_total => 'speed', cast_int => 1, label_extra_instance => 1 } + ] } }, { label => 'link-traffic-out', nlabel => 'host.traffic.out.bitsperseconds', set => { @@ -198,8 +198,8 @@ sub set_counters { threshold_use => 'traffic_prct', perfdatas => [ { label => 'traffic_out', value => 'traffic', template => '%s', unit => 'b/s', - min => 0, max => 'speed', threshold_total => 'speed', cast_int => 1, label_extra_instance => 1 }, - ], + min => 0, max => 'speed', threshold_total => 'speed', cast_int => 1, label_extra_instance => 1 } + ] } }, { label => 'link-dropped-in', nlabel => 'host.packets.in.dropped.percentage', set => { @@ -209,8 +209,8 @@ sub set_counters { threshold_use => 'dropped_prct', perfdatas => [ { label => 'packets_dropped_in', value => 'dropped_prct', template => '%s', unit => '%', - min => 0, max => 100, label_extra_instance => 1 }, - ], + min => 0, max => 100, label_extra_instance => 1 } + ] } }, { label => 'link-dropped-out', nlabel => 'host.packets.out.dropped.percentage', set => { @@ -220,10 +220,10 @@ sub set_counters { threshold_use => 'dropped_prct', perfdatas => [ { label => 'packets_dropped_out', value => 'dropped_prct', template => '%s', unit => '%', - min => 0, max => 100, label_extra_instance => 1 }, - ], + min => 0, max => 100, label_extra_instance => 1 } + ] } - }, + } ]; } @@ -257,20 +257,20 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "esx-hostname:s" => { name => 'esx_hostname' }, - "nic-name:s" => { name => 'nic_name' }, - "filter" => { name => 'filter' }, - "scope-datacenter:s" => { name => 'scope_datacenter' }, - "scope-cluster:s" => { name => 'scope_cluster' }, - "no-proxyswitch" => { name => 'no_proxyswitch' }, - "unknown-status:s" => { name => 'unknown_status', default => '%{status} !~ /^connected$/i' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, - "unknown-link-status:s" => { name => 'unknown_link_status', default => '' }, - "warning-link-status:s" => { name => 'warning_link_status', default => '' }, - "critical-link-status:s" => { name => 'critical_link_status', default => '%{link_status} !~ /up/' }, + 'esx-hostname:s' => { name => 'esx_hostname' }, + 'nic-name:s' => { name => 'nic_name' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' }, + 'scope-cluster:s' => { name => 'scope_cluster' }, + 'no-proxyswitch' => { name => 'no_proxyswitch' }, + 'unknown-status:s' => { name => 'unknown_status', default => '%{status} !~ /^connected$/i' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, + 'unknown-link-status:s' => { name => 'unknown_link_status', default => '' }, + 'warning-link-status:s' => { name => 'warning_link_status', default => '' }, + 'critical-link-status:s' => { name => 'critical_link_status', default => '%{link_status} !~ /up/' } }); - + return $self; } @@ -278,8 +278,10 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status', - 'unknown_link_status', 'warning_link_status', 'critical_link_status']); + $self->change_macros(macros => [ + 'unknown_status', 'warning_status', 'critical_status', + 'unknown_link_status', 'warning_link_status', 'critical_link_status' + ]); } sub manage_selection { @@ -308,7 +310,7 @@ sub manage_selection { $pnic_name !~ /$self->{option_results}->{nic_name}/); $self->{host}->{$host_name}->{pnic}->{$pnic_name} = { - display => $pnic_name, + display => $pnic_name, status => $response->{data}->{$host_id}->{pnic}->{$pnic_name}->{status} , traffic_in => $response->{data}->{$host_id}->{pnic}->{$pnic_name}->{'net.received.average'}, traffic_out => $response->{data}->{$host_id}->{pnic}->{$pnic_name}->{'net.transmitted.average'}, @@ -392,18 +394,18 @@ Can used special variables like: %{status} =item B<--unknown-link-status> -Set warning threshold for status (Default: ''). -Can used special variables like: %{link_status} +Set warning threshold for status. +Can used special variables like: %{link_status}, %{display} =item B<--warning-link-status> -Set warning threshold for status (Default: ''). -Can used special variables like: %{link_status} +Set warning threshold for status. +Can used special variables like: %{link_status}, %{display} =item B<--critical-link-status> Set critical threshold for status (Default: '%{link_status} !~ /up/'). -Can used special variables like: %{link_status} +Can used special variables like: %{link_status}, %{display} =item B<--warning-*> From fbec7c10ef376adb60b73967e190a4395e4dbd68 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 6 Apr 2020 11:12:09 +0200 Subject: [PATCH 065/190] fix compat datastore uusage --- .../vmware/connector/mode/datastoreusage.pm | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/centreon-plugins/apps/vmware/connector/mode/datastoreusage.pm b/centreon-plugins/apps/vmware/connector/mode/datastoreusage.pm index ab9950896..a5edae08b 100644 --- a/centreon-plugins/apps/vmware/connector/mode/datastoreusage.pm +++ b/centreon-plugins/apps/vmware/connector/mode/datastoreusage.pm @@ -137,7 +137,7 @@ sub set_counters { min => 0, max => 'total_space', label_extra_instance => 1 }, ], } - }, + } ]; } @@ -153,14 +153,14 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'datastore-name:s' => { name => 'datastore_name' }, - 'filter' => { name => 'filter' }, - 'scope-datacenter:s' => { name => 'scope_datacenter' }, - 'units:s' => { name => 'units', default => '%' }, - 'free' => { name => 'free' }, - 'unknown-status:s' => { name => 'unknown_status', default => '%{accessible} !~ /^true|1$/i' }, - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '' }, + 'datastore-name:s' => { name => 'datastore_name' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' }, + 'unknown-status:s' => { name => 'unknown_status', default => '%{accessible} !~ /^true|1$/i' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' } }); return $self; @@ -172,8 +172,12 @@ sub check_options { # Compatibility $self->compat_threshold_counter(%options, compat => { - th => [ ['usage', { free => 'usage-free', prct => 'usage-prct'} ], [ 'datastore.space.usage.bytes', { free => 'datastore.space.free.bytes', prct => 'datastore.space.usage.percentage' } ] ], - units => $options{option_results}->{units}, free => $options{option_results}->{free} + th => [ + [ 'usage', { free => 'usage-free', prct => 'usage-prct'} ], + [ 'instance-datastore-space-usage-bytes', { free => 'instance-datastore-space-free-bytes', prct => 'instance-datastore-space-usage-percentage' } ] + ], + units => $options{option_results}->{units}, + free => $options{option_results}->{free} } ); From a46cc7b19bcaca46272baf2ac399d4a9a9836dfc Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 6 Apr 2020 11:38:01 +0200 Subject: [PATCH 066/190] fix nethost vmware --- centreon-plugins/apps/vmware/connector/mode/nethost.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/centreon-plugins/apps/vmware/connector/mode/nethost.pm b/centreon-plugins/apps/vmware/connector/mode/nethost.pm index 05488e026..61ac63ff1 100644 --- a/centreon-plugins/apps/vmware/connector/mode/nethost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/nethost.pm @@ -48,6 +48,7 @@ sub custom_linkstatus_output { sub custom_linkstatus_calc { my ($self, %options) = @_; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; $self->{result_values}->{link_status} = $options{new_datas}->{$self->{instance} . '_status'}; return 0; } From b59f6be9f60d9b5f8fa6e88a161d596f1c9da549 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 6 Apr 2020 12:07:15 +0200 Subject: [PATCH 067/190] add filter name for pdu eaton --- .../hardware/pdu/eaton/snmp/mode/group.pm | 34 +++++++++++++------ .../hardware/pdu/eaton/snmp/mode/outlet.pm | 18 ++++++++-- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/centreon-plugins/hardware/pdu/eaton/snmp/mode/group.pm b/centreon-plugins/hardware/pdu/eaton/snmp/mode/group.pm index 71d01ce01..2a11324eb 100644 --- a/centreon-plugins/hardware/pdu/eaton/snmp/mode/group.pm +++ b/centreon-plugins/hardware/pdu/eaton/snmp/mode/group.pm @@ -27,9 +27,9 @@ use warnings; sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ - { name => 'group', type => 1, cb_prefix_output => 'prefix_group_output', message_multiple => 'All groups are ok', skipped_code => { -10 => 1 } }, + { name => 'group', type => 1, cb_prefix_output => 'prefix_group_output', message_multiple => 'All groups are ok', skipped_code => { -10 => 1 } } ]; $self->{maps_counters}->{group} = [ @@ -38,8 +38,8 @@ sub set_counters { output_template => 'Current : %.2f A', perfdatas => [ { value => 'groupCurrent_absolute', template => '%.2f', - min => 0, unit => 'A', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + min => 0, unit => 'A', label_extra_instance => 1, instance_use => 'display_absolute' } + ] } }, { label => 'voltage', nlabel => 'group.voltage.volt', set => { @@ -47,8 +47,8 @@ sub set_counters { output_template => 'Voltage : %.2f V', perfdatas => [ { value => 'groupVoltage_absolute', template => '%.2f', - unit => 'V', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => 'V', label_extra_instance => 1, instance_use => 'display_absolute' } + ] } }, { label => 'power', nlabel => 'group.power.watt', set => { @@ -56,10 +56,10 @@ sub set_counters { output_template => 'Power : %.2f W', perfdatas => [ { value => 'groupWatts_absolute', template => '%.2f', - unit => 'W', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => 'W', label_extra_instance => 1, instance_use => 'display_absolute' } + ] } - }, + } ]; } @@ -69,6 +69,7 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' } }); return $self; @@ -90,7 +91,6 @@ my $mapping = { sub manage_selection { my ($self, %options) = @_; - $self->{group} = {}; my $snmp_result = $options{snmp}->get_multiple_table( oids => [ { oid => $mapping->{groupName}->{oid} }, @@ -101,11 +101,12 @@ sub manage_selection { return_type => 1, nothing_quit => 1 ); + $self->{group} = {}; foreach my $oid (keys %{$snmp_result}) { $oid =~ /\.(\d+)\.(\d+)$/; my ($strapping_index, $group_index) = ($1, $2); next if (defined($self->{group}->{$strapping_index . '.' . $group_index})); - + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $strapping_index . '.' . $group_index); $result->{groupVoltage} *= 0.001 if (defined($result->{groupVoltage})); $result->{groupCurrent} *= 0.001 if (defined($result->{groupCurrent})); @@ -113,6 +114,13 @@ sub manage_selection { if (defined($result->{groupName}) && $result->{groupName} ne '') { $display = $result->{groupName} . ' strapping ' . $strapping_index; } + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $display !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $display . "': no matching filter.", debug => 1); + next; + } + $self->{group}->{$strapping_index . '.' . $group_index} = { display => $display, %$result }; } @@ -132,6 +140,10 @@ Check group metrics (voltage, current and power). =over 8 +=item B<--filter-name> + +Filter group name (can be a regexp). + =item B<--warning-*> Threshold warning. diff --git a/centreon-plugins/hardware/pdu/eaton/snmp/mode/outlet.pm b/centreon-plugins/hardware/pdu/eaton/snmp/mode/outlet.pm index 4604bf97c..0583c293e 100644 --- a/centreon-plugins/hardware/pdu/eaton/snmp/mode/outlet.pm +++ b/centreon-plugins/hardware/pdu/eaton/snmp/mode/outlet.pm @@ -69,6 +69,7 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' } }); return $self; @@ -90,7 +91,6 @@ my $mapping = { sub manage_selection { my ($self, %options) = @_; - $self->{outlet} = {}; my $snmp_result = $options{snmp}->get_multiple_table( oids => [ { oid => $mapping->{outletName}->{oid} }, @@ -101,12 +101,13 @@ sub manage_selection { return_type => 1, nothing_quit => 1 ); + $self->{outlet} = {}; foreach my $oid (keys %{$snmp_result}) { $oid =~ /\.(\d+)\.(\d+)$/; my ($strapping_index, $outlet_index) = ($1, $2); - + next if (defined($self->{outlet}->{$strapping_index . '.' . $outlet_index})); - + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $strapping_index . '.' . $outlet_index); $result->{outletVoltage} *= 0.001 if (defined($result->{outletVoltage})); $result->{outletCurrent} *= 0.001 if (defined($result->{outletCurrent})); @@ -114,6 +115,13 @@ sub manage_selection { if (defined($result->{outletName}) && $result->{outletName} ne '') { $display = $result->{outletName} . ' strapping ' . $strapping_index; } + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $display !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $display . "': no matching filter.", debug => 1); + next; + } + $self->{outlet}->{$strapping_index . '.' . $outlet_index} = { display => $display, %$result }; } @@ -133,6 +141,10 @@ Check outlet metrics (voltage, current and power). =over 8 +=item B<--filter-name> + +Filter outlet name (can be a regexp). + =item B<--warning-*> Threshold warning. From f5b26d499f764f6cda4587b7425da8402105b426 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 6 Apr 2020 13:54:44 +0200 Subject: [PATCH 068/190] enhance cluster status vmware --- .../vmware/connector/mode/statuscluster.pm | 38 +++++++++++-------- .../vmware/connector/mode/vsanclusterusage.pm | 21 ++++------ 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/centreon-plugins/apps/vmware/connector/mode/statuscluster.pm b/centreon-plugins/apps/vmware/connector/mode/statuscluster.pm index 07e8f0189..c195c0214 100644 --- a/centreon-plugins/apps/vmware/connector/mode/statuscluster.pm +++ b/centreon-plugins/apps/vmware/connector/mode/statuscluster.pm @@ -30,9 +30,9 @@ sub custom_status_output { my ($self, %options) = @_; my $msg = 'status is ' . $self->{result_values}->{overall_status}; - if ($self->{result_values}->{vsan_status} ne '') { - $msg .= ' [vsan status: ' . $self->{result_values}->{vsan_status} . ']'; - } + $msg .= ' [vsan status: ' . $self->{result_values}->{vsan_status} . ']' if ($self->{result_values}->{vsan_status} ne ''); + $msg .= ' [ha enabled: ' . $self->{result_values}->{ha_enabled} . ']' if ($self->{result_values}->{ha_enabled} ne ''); + $msg .= ' [drs enabled: ' . $self->{result_values}->{drs_enabled} . ']' if ($self->{result_values}->{drs_enabled} ne ''); return $msg; } @@ -40,18 +40,24 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'cluster', type => 1, cb_prefix_output => 'prefix_cluster_output', message_multiple => 'All clusters are ok' }, + { name => 'cluster', type => 1, cb_prefix_output => 'prefix_cluster_output', message_multiple => 'All clusters are ok' } ]; $self->{maps_counters}->{cluster} = [ { label => 'status', threshold => 0, set => { - key_values => [ { name => 'overall_status' }, { name => 'vsan_status' }, { name => 'display' } ], + key_values => [ + { name => 'overall_status' }, + { name => 'vsan_status' }, + { name => 'ha_enabled' }, + { name => 'drs_enabled' }, + { name => 'display' } + ], closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold } - }, + } ]; } @@ -65,41 +71,43 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { 'cluster-name:s' => { name => 'cluster_name' }, 'filter' => { name => 'filter' }, 'scope-datacenter:s' => { name => 'scope_datacenter' }, 'unknown-status:s' => { name => 'unknown_status', default => '%{overall_status} =~ /gray/i || %{vsan_status} =~ /gray/i' }, 'warning-status:s' => { name => 'warning_status', default => '%{overall_status} =~ /yellow/i || %{vsan_status} =~ /yellow/i' }, - 'critical-status:s' => { name => 'critical_status', default => '%{overall_status} =~ /red/i || %{vsan_status} =~ /red/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{overall_status} =~ /red/i || %{vsan_status} =~ /red/i' } }); - + return $self; } sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); } sub manage_selection { my ($self, %options) = @_; - $self->{cluster} = {}; my $response = $options{custom}->execute( params => $self->{option_results}, command => 'statuscluster' ); + $self->{cluster} = {}; foreach my $cluster_id (keys %{$response->{data}}) { my $cluster_name = $response->{data}->{$cluster_id}->{name}; $self->{cluster}->{$cluster_name} = { display => $cluster_name, overall_status => $response->{data}->{$cluster_id}->{overall_status}, vsan_status => defined($response->{data}->{$cluster_id}->{vsan_cluster_status}) ? $response->{data}->{$cluster_id}->{vsan_cluster_status} : '', + ha_enabled => defined($response->{data}->{$cluster_id}->{ha_enabled}) ? $response->{data}->{$cluster_id}->{ha_enabled} : '', + drs_enabled => defined($response->{data}->{$cluster_id}->{drs_enabled}) ? $response->{data}->{$cluster_id}->{drs_enabled} : '' }; } } @@ -130,17 +138,17 @@ Search in following datacenter(s) (can be a regexp). =item B<--unknown-status> Set warning threshold for status (Default: '%{overall_status} =~ /gray/i || %{vsan_status} =~ /gray/i'). -Can used special variables like: %{overall_status}, %{vsan_status} +Can used special variables like: %{overall_status}, %{vsan_status}, %{drs_enabled}, %{ha_enabled} =item B<--warning-status> Set warning threshold for status (Default: '%{overall_status} =~ /yellow/i || %{vsan_status} =~ /yellow/i'). -Can used special variables like: %{overall_status}, %{vsan_status} +Can used special variables like: %{overall_status}, %{vsan_status}, %{drs_enabled}, %{ha_enabled} =item B<--critical-status> Set critical threshold for status (Default: '%{overall_status} =~ /red/i || %{vsan_status} =~ /red/i'). -Can used special variables like: %{overall_status}, %{vsan_status} +Can used special variables like: %{overall_status}, %{vsan_status}, %{drs_enabled}, %{ha_enabled} =back diff --git a/centreon-plugins/apps/vmware/connector/mode/vsanclusterusage.pm b/centreon-plugins/apps/vmware/connector/mode/vsanclusterusage.pm index b7e2e6a89..a2459810a 100644 --- a/centreon-plugins/apps/vmware/connector/mode/vsanclusterusage.pm +++ b/centreon-plugins/apps/vmware/connector/mode/vsanclusterusage.pm @@ -112,21 +112,14 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => { - 'cluster-name:s' => { name => 'cluster_name' }, - 'filter' => { name => 'filter' }, - 'scope-datacenter:s' => { name => 'scope_datacenter' }, - }); - - return $self; -} -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); + $options{options}->add_options(arguments => { + 'cluster-name:s' => { name => 'cluster_name' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' } + }); + + return $self; } sub manage_selection { From 922e545db3f112b6c1c79a783436f35337e9794d Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 8 Apr 2020 17:11:02 +0200 Subject: [PATCH 069/190] enhance indent --- .../apps/vmware/connector/mode/cpuhost.pm | 2 +- .../cloud/ovh/restapi/custom/api.pm | 42 +++++++++---------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/centreon-plugins/apps/vmware/connector/mode/cpuhost.pm b/centreon-plugins/apps/vmware/connector/mode/cpuhost.pm index 9d59e9299..adcc66c51 100644 --- a/centreon-plugins/apps/vmware/connector/mode/cpuhost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/cpuhost.pm @@ -63,7 +63,7 @@ sub set_counters { } }, ]; - + $self->{maps_counters}->{global_cpu} = [ { label => 'total-cpu', nlabel => 'host.cpu.utilization.percentage', set => { key_values => [ { name => 'cpu_average' } ], diff --git a/centreon-plugins/cloud/ovh/restapi/custom/api.pm b/centreon-plugins/cloud/ovh/restapi/custom/api.pm index a21f5e04b..0a79255c7 100644 --- a/centreon-plugins/cloud/ovh/restapi/custom/api.pm +++ b/centreon-plugins/cloud/ovh/restapi/custom/api.pm @@ -28,7 +28,7 @@ use Digest::SHA 'sha1_hex'; my %map_ovh_type = ( OVH_API_EU => 'https://eu.api.ovh.com/1.0', - OVH_API_CA => 'https://ca.api.ovh.com/1.0', + OVH_API_CA => 'https://ca.api.ovh.com/1.0' ); sub new { @@ -44,14 +44,14 @@ sub new { $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 => { - "ovh-type:s@" => { name => 'ovh_type' }, - "ovh-application-key:s@" => { name => 'ovh_application_key' }, - "ovh-application-secret:s@" => { name => 'ovh_application_secret' }, - "ovh-consumer-key:s@" => { name => 'ovh_consumer_key' }, - "timeout:s@" => { name => 'timeout' }, + 'ovh-type:s@' => { name => 'ovh_type' }, + 'ovh-application-key:s@' => { name => 'ovh_application_key' }, + 'ovh-application-secret:s@' => { name => 'ovh_application_secret' }, + 'ovh-consumer-key:s@' => { name => 'ovh_consumer_key' }, + 'timeout:s@' => { name => 'timeout' } }); } $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); @@ -61,23 +61,17 @@ sub new { $self->{http} = centreon::plugins::http->new(%options); return $self; - } -# Method to manage multiples sub set_options { my ($self, %options) = @_; - # options{options_result} $self->{option_results} = $options{option_results}; } -# Method to manage multiples sub set_defaults { my ($self, %options) = @_; - # options{default} - # Manage default value foreach (keys %{$options{default}}) { if ($_ eq $self->{mode}) { for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { @@ -117,19 +111,19 @@ sub check_options { scalar(@{$self->{option_results}->{ovh_application_key}}) == 0) { return 0; } - + return 1; } sub build_options_for_httplib { my ($self, %options) = @_; - + $self->{option_results}->{timeout} = $self->{timeout}; } sub settings { my ($self, %options) = @_; - + $self->build_options_for_httplib(); $self->{http}->add_header(key => 'X-Ovh-Application', value => $self->{ovh_application_key}); if (!defined($options{no_signature}) || $options{no_signature} == 0) { @@ -149,7 +143,7 @@ sub settings { $self->{http}->add_header(key => 'Content-type', value => 'application/json'); $self->{option_results}->{query_form_post} = $content; } - + $self->{http}->add_header(key => 'X-Ovh-Consumer', value => $self->{ovh_consumer_key}); $self->{http}->add_header(key => 'X-Ovh-Timestamp', value => $now); $self->{http}->add_header(key => 'X-Ovh-Signature', value => '$1$' . sha1_hex(join('+', ( @@ -172,7 +166,7 @@ sub time_delta { my $response = $self->get(path => '/auth/time', no_signature => 1, no_decode => 1); $self->{time_delta} = $response - time(); } - + return $self->{time_delta}; } @@ -181,14 +175,18 @@ sub get { $self->settings(%options); - my $response = $self->{http}->request(full_url => $map_ovh_type{uc($self->{ovh_type})} . $options{path}, - hostname => '', critical_status => '', warning_status => ''); + my $response = $self->{http}->request( + full_url => $map_ovh_type{uc($self->{ovh_type})} . $options{path}, + hostname => '', + critical_status => '', + warning_status => '' + ); my ($client_warning) = $self->{http}->get_header(name => 'Client-Warning'); if (defined($client_warning) && $client_warning eq 'Internal response') { $self->{output}->add_option_msg(short_msg => "Internal LWP::UserAgent error: $response"); $self->{output}->option_exit(); } - + if (defined($options{no_decode}) && $options{no_decode} == 1) { return $response; } @@ -201,7 +199,7 @@ sub get { $self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@"); $self->{output}->option_exit(); } - + return $content; } From c973e6184d2fbc7cc718270f88050dd2fd18302c Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Wed, 8 Apr 2020 19:02:30 +0200 Subject: [PATCH 070/190] network::ibm::bladecenter new plugin --- .../snmp/mode/components/faultled.pm | 66 ++++++++++ .../snmp/mode/components/temperature.pm | 86 ++++++++++++ .../network/ibm/bladecenter/snmp/mode/cpu.pm | 87 +++++++++++++ .../network/ibm/bladecenter/snmp/mode/disk.pm | 104 +++++++++++++++ .../ibm/bladecenter/snmp/mode/environment.pm | 84 ++++++++++++ .../ibm/bladecenter/snmp/mode/memory.pm | 123 ++++++++++++++++++ .../network/ibm/bladecenter/snmp/plugin.pm | 55 ++++++++ 7 files changed, 605 insertions(+) create mode 100644 centreon-plugins/network/ibm/bladecenter/snmp/mode/components/faultled.pm create mode 100644 centreon-plugins/network/ibm/bladecenter/snmp/mode/components/temperature.pm create mode 100644 centreon-plugins/network/ibm/bladecenter/snmp/mode/cpu.pm create mode 100644 centreon-plugins/network/ibm/bladecenter/snmp/mode/disk.pm create mode 100644 centreon-plugins/network/ibm/bladecenter/snmp/mode/environment.pm create mode 100644 centreon-plugins/network/ibm/bladecenter/snmp/mode/memory.pm create mode 100644 centreon-plugins/network/ibm/bladecenter/snmp/plugin.pm diff --git a/centreon-plugins/network/ibm/bladecenter/snmp/mode/components/faultled.pm b/centreon-plugins/network/ibm/bladecenter/snmp/mode/components/faultled.pm new file mode 100644 index 000000000..7fc415513 --- /dev/null +++ b/centreon-plugins/network/ibm/bladecenter/snmp/mode/components/faultled.pm @@ -0,0 +1,66 @@ +# +# 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 network::ibm::bladecenter::snmp::mode::components::faultled; + +use strict; +use warnings; + +my %map_faultled_states = ( 1 => 'on', 2 => 'off' ); + +sub load {} + +sub check_faultled { + my ($self, %options) = @_; + + $self->{components}->{faultled}->{total}++; + + $self->{output}->output_add(long_msg => + sprintf( + "Fault LED state is %s", + $options{value} + ) + ); + my $exit = $self->get_severity(section => 'faultled', value => $options{value}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Fault LED state is %s", + $options{value} + ) + ); + } +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking fault LED"); + $self->{components}->{faultled} = { name => 'faultled', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'faultled')); + + my $oid_mmspFaultLED = '.1.3.6.1.4.1.26543.2.5.1.3.10.12.0'; + my $results = $self->{snmp}->get_leef(oids => [$oid_mmspFaultLED], nothing_quit => 1); + + check_faultled($self, value => $map_faultled_states{$results->{$oid_mmspFaultLED}}); +} + +1; diff --git a/centreon-plugins/network/ibm/bladecenter/snmp/mode/components/temperature.pm b/centreon-plugins/network/ibm/bladecenter/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..036fc21be --- /dev/null +++ b/centreon-plugins/network/ibm/bladecenter/snmp/mode/components/temperature.pm @@ -0,0 +1,86 @@ +# +# 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 network::ibm::bladecenter::snmp::mode::components::temperature; + +use strict; +use warnings; + +sub load {} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking temperatures"); + $self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'temperature')); + + my $oid_hwTemperatureWarn = '.1.3.6.1.4.1.26543.2.5.1.3.1.22.0'; + my $oid_hwTemperatureShut = '.1.3.6.1.4.1.26543.2.5.1.3.1.23.0'; + my $results = $self->{snmp}->get_leef(oids => [$oid_hwTemperatureWarn, $oid_hwTemperatureShut], nothing_quit => 1); + + # .1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1.20.1 = STRING: "44 C (Warn at 66 C / Recover at 61 C)" + # .1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1.21.1 = STRING: "44 C (Shutdown at 72 C / Recover at 67 C)" + $results->{$oid_hwTemperatureWarn} =~ /^([.0-9]+)\s*C\s*\(Warn(?:ing)?\s*at\s*([.0-9]+)\s*C/i; + my $temperature = $1; + my $warning = $2; + $results->{$oid_hwTemperatureShut} =~ /^([.0-9]+)\s*C\s*\(Shutdown\s*at\s*([.0-9]+)\s*C/i; + if ($1 > $temperature) { + $temperature = $1; + } + my $critical = ($warning + $2) / 2; + + $self->{components}->{temperature}->{total}++; + + $self->{output}->output_add(long_msg => + sprintf( + "Temperature is %.1f C", + $temperature + ) + ); + + my $exit = 'OK'; + if ($temperature >= $warning) { + $exit = 'WARNING'; + } + if ($temperature >= $critical) { + $exit = 'CRITICAL'; + } + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Temperature is %.1f C", + $temperature + ) + ); + } + + $self->{output}->perfdata_add( + label => 'temperature', unit => 'C', + nlabel => 'hardware.temperature.celsius', + instances => 'system', + value => $temperature, + warning => $warning, + critical => $critical + ); +} + +1; diff --git a/centreon-plugins/network/ibm/bladecenter/snmp/mode/cpu.pm b/centreon-plugins/network/ibm/bladecenter/snmp/mode/cpu.pm new file mode 100644 index 000000000..ef7893af7 --- /dev/null +++ b/centreon-plugins/network/ibm/bladecenter/snmp/mode/cpu.pm @@ -0,0 +1,87 @@ +# +# 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 network::ibm::bladecenter::snmp::mode::cpu; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'cpu', type => 0, skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{cpu} = [ + { label => 'average', nlabel => 'cpu.utilization.percentage', set => { + key_values => [ { name => 'average' } ], + output_template => '%.2f %%', + perfdatas => [ + { label => 'total_cpu_avg', value => 'average_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_mpCpuStatsUtil1Minute = '.1.3.6.1.4.1.26543.2.5.1.2.2.3.0'; + my $result = $options{snmp}->get_leef(oids => [$oid_mpCpuStatsUtil1Minute], nothing_quit => 1); + + $self->{cpu} = { + average => $result->{$oid_mpCpuStatsUtil1Minute}, + } +} + +1; + +__END__ + +=head1 MODE + +Check CPU usage (over the last minute). + +=over 8 + +=item B<--warning-average> + +Warning threshold average CPU utilization. + +=item B<--critical-average> + +Critical threshold average CPU utilization. + +=back + +=cut diff --git a/centreon-plugins/network/ibm/bladecenter/snmp/mode/disk.pm b/centreon-plugins/network/ibm/bladecenter/snmp/mode/disk.pm new file mode 100644 index 000000000..b8466a931 --- /dev/null +++ b/centreon-plugins/network/ibm/bladecenter/snmp/mode/disk.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 network::ibm::bladecenter::snmp::mode::disk; + +use base qw(snmp_standard::mode::storage); + +use strict; +use warnings; + +sub default_storage_type { + my ($self, %options) = @_; + + return '^(?!(hrStorageRam)$)'; +} + +sub prefix_storage_output { + my ($self, %options) = @_; + + return "Disk '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check disk. + +=over 8 + +=item B<--warning-usage> + +Threshold warning. + +=item B<--critical-usage> + +Threshold critical. + +=item B<--units> + +Units of thresholds (Default: '%') ('%', 'B'). + +=item B<--free> + +Thresholds are on free space left. + +=item B<--storage> + +Set the storage (number expected) ex: 1, 2,... (empty means 'check all storage'). + +=item B<--name> + +Allows to use storage name with option --storage instead of storage oid index. + +=item B<--regexp> + +Allows to use regexp to filter storage (with option --name). + +=item B<--regexp-isensitive> + +Allows to use regexp non case-sensitive (with --regexp). + +=item B<--reload-cache-time> + +Time in minutes before reloading cache file (default: 180). + +=item B<--show-cache> + +Display cache storage datas. + +=item B<--filter-storage-type> + +Filter storage types with a regexp (Default: '^(?!(hrStorageRam)$)'). + +=back + +=cut diff --git a/centreon-plugins/network/ibm/bladecenter/snmp/mode/environment.pm b/centreon-plugins/network/ibm/bladecenter/snmp/mode/environment.pm new file mode 100644 index 000000000..935e17f2d --- /dev/null +++ b/centreon-plugins/network/ibm/bladecenter/snmp/mode/environment.pm @@ -0,0 +1,84 @@ +# +# 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 network::ibm::bladecenter::snmp::mode::environment; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(faultled|temperature)$'; + + $self->{cb_hook2} = 'snmp_execute'; + $self->{thresholds} = { + 'faultled' => [ + ['on', 'CRITICAL'], + ['off', 'OK'], + ], + }; + + $self->{components_path} = 'network::ibm::bladecenter::snmp::mode::components'; + $self->{components_module} = ['faultled', 'temperature']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'faultled', 'temperature'. + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=back + +=cut diff --git a/centreon-plugins/network/ibm/bladecenter/snmp/mode/memory.pm b/centreon-plugins/network/ibm/bladecenter/snmp/mode/memory.pm new file mode 100644 index 000000000..35c2279bd --- /dev/null +++ b/centreon-plugins/network/ibm/bladecenter/snmp/mode/memory.pm @@ -0,0 +1,123 @@ +# +# 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 network::ibm::bladecenter::snmp::mode::memory; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub custom_usage_output { + my ($self, %options) = @_; + + return sprintf( + 'Ram Total: %s %s Used: %s %s (%.2f%%) Free: %s %s (%.2f%%)', + $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}), + $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}), + $self->{result_values}->{prct_used_absolute}, + $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}), + $self->{result_values}->{prct_free_absolute} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'memory', type => 0, skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{memory} = [ + { label => 'usage', nlabel => 'memory.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { label => 'used', value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1 }, + ], + } + }, + { label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { label => 'free', value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1 }, + ], + } + }, + { label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => { + key_values => [ { name => 'prct_used' } ], + output_template => 'Used : %.2f %%', + perfdatas => [ + { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, + unit => '%' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_totalMemoryStats = '.1.3.6.1.4.1.26543.2.5.1.2.12.1.0'; # in bytes + my $oid_memoryFreeStats = '.1.3.6.1.4.1.26543.2.5.1.2.12.2.0'; # in bytes + my $result = $options{snmp}->get_leef(oids => [$oid_totalMemoryStats, $oid_memoryFreeStats], nothing_quit => 1); + + my $free = $result->{$oid_memoryFreeStats}; + my $total = $result->{$oid_totalMemoryStats}; + my $prct_used = ($total - $free) * 100 / $total; + $self->{memory} = { + total => $total, + used => $total - $free, + free => $free, + prct_used => $prct_used, + prct_free => 100 - $prct_used, + } +} + +1; + +__END__ + +=head1 MODE + +Check memory usage. + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%). + +=back + +=cut diff --git a/centreon-plugins/network/ibm/bladecenter/snmp/plugin.pm b/centreon-plugins/network/ibm/bladecenter/snmp/plugin.pm new file mode 100644 index 000000000..4ec79937b --- /dev/null +++ b/centreon-plugins/network/ibm/bladecenter/snmp/plugin.pm @@ -0,0 +1,55 @@ +# +# 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 network::ibm::bladecenter::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'cpu' => 'network::ibm::bladecenter::snmp::mode::cpu', + 'disk' => 'network::ibm::bladecenter::snmp::mode::disk', + 'environment' => 'network::ibm::bladecenter::snmp::mode::environment', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::ibm::bladecenter::snmp::mode::memory', + 'time' => 'snmp_standard::mode::ntp', + 'uptime' => 'snmp_standard::mode::uptime', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check IBM BladeCenter switches in SNMP. + +=cut From 94099ea99d307501a878a1790884edfac4b5bb6b Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Wed, 8 Apr 2020 19:08:06 +0200 Subject: [PATCH 071/190] network::lenovo::flexsystem new plugin --- .../snmp/mode/components/faultled.pm | 66 +++++++ .../snmp/mode/components/temperature.pm | 86 +++++++++ .../lenovo/flexsystem/snmp/mode/cpu.pm | 127 ++++++++++++++ .../lenovo/flexsystem/snmp/mode/disk.pm | 104 +++++++++++ .../flexsystem/snmp/mode/environment.pm | 84 +++++++++ .../lenovo/flexsystem/snmp/mode/memory.pm | 163 ++++++++++++++++++ .../network/lenovo/flexsystem/snmp/plugin.pm | 55 ++++++ 7 files changed, 685 insertions(+) create mode 100644 centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/faultled.pm create mode 100644 centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/temperature.pm create mode 100644 centreon-plugins/network/lenovo/flexsystem/snmp/mode/cpu.pm create mode 100644 centreon-plugins/network/lenovo/flexsystem/snmp/mode/disk.pm create mode 100644 centreon-plugins/network/lenovo/flexsystem/snmp/mode/environment.pm create mode 100644 centreon-plugins/network/lenovo/flexsystem/snmp/mode/memory.pm create mode 100644 centreon-plugins/network/lenovo/flexsystem/snmp/plugin.pm diff --git a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/faultled.pm b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/faultled.pm new file mode 100644 index 000000000..b987d1162 --- /dev/null +++ b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/faultled.pm @@ -0,0 +1,66 @@ +# +# 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 network::lenovo::flexsystem::snmp::mode::components::faultled; + +use strict; +use warnings; + +my %map_faultled_states = ( 1 => 'on', 2 => 'off' ); + +sub load {} + +sub check_faultled { + my ($self, %options) = @_; + + $self->{components}->{faultled}->{total}++; + + $self->{output}->output_add(long_msg => + sprintf( + "Fault LED state is %s", + $options{value} + ) + ); + my $exit = $self->get_severity(section => 'faultled', value => $options{value}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Fault LED state is %s", + $options{value} + ) + ); + } +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking fault LED"); + $self->{components}->{faultled} = { name => 'faultled', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'faultled')); + + my $oid_mmspFaultLED = '.1.3.6.1.4.1.20301.2.5.1.3.10.12.0'; + my $results = $self->{snmp}->get_leef(oids => [$oid_mmspFaultLED], nothing_quit => 1); + + check_faultled($self, value => $map_faultled_states{$results->{$oid_mmspFaultLED}}); +} + +1; diff --git a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/temperature.pm b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..3fb804d38 --- /dev/null +++ b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/temperature.pm @@ -0,0 +1,86 @@ +# +# 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 network::lenovo::flexsystem::snmp::mode::components::temperature; + +use strict; +use warnings; + +sub load {} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking temperatures"); + $self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'temperature')); + + my $oid_hwTemperatureWarn = '.1.3.6.1.4.1.20301.2.5.1.3.1.22.0'; + my $oid_hwTemperatureShut = '.1.3.6.1.4.1.20301.2.5.1.3.1.23.0'; + my $results = $self->{snmp}->get_leef(oids => [$oid_hwTemperatureWarn, $oid_hwTemperatureShut], nothing_quit => 1); + + # .1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1.20.1 = STRING: "44 C (Warning at 66 C / Recover at 61 C)" + # .1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1.21.1 = STRING: "44 C (Shutdown at 72 C / Recover at 67 C)" + $results->{$oid_hwTemperatureWarn} =~ /^([.0-9]+)\s*C\s*\(Warn(?:ing)?\s*at\s*([.0-9]+)\s*C/i; + my $temperature = $1; + my $warning = $2; + $results->{$oid_hwTemperatureShut} =~ /^([.0-9]+)\s*C\s*\(Shutdown\s*at\s*([.0-9]+)\s*C/i; + if ($1 > $temperature) { + $temperature = $1; + } + my $critical = ($warning + $2) / 2; + + $self->{components}->{temperature}->{total}++; + + $self->{output}->output_add(long_msg => + sprintf( + "Temperature is %.1f C", + $temperature + ) + ); + + my $exit = 'OK'; + if ($temperature >= $warning) { + $exit = 'WARNING'; + } + if ($temperature >= $critical) { + $exit = 'CRITICAL'; + } + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Temperature is %.1f C", + $temperature + ) + ); + } + + $self->{output}->perfdata_add( + label => 'temperature', unit => 'C', + nlabel => 'hardware.temperature.celsius', + instances => 'system', + value => $temperature, + warning => $warning, + critical => $critical + ); +} + +1; diff --git a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/cpu.pm b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/cpu.pm new file mode 100644 index 000000000..c17707bcb --- /dev/null +++ b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/cpu.pm @@ -0,0 +1,127 @@ +# +# 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 network::lenovo::flexsystem::snmp::mode::cpu; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'cpu', type => 1, cb_prefix_output => 'prefix_message_output', message_multiple => 'All CPU usages are ok' }, + ]; + + $self->{maps_counters}->{cpu} = [ + { label => 'average', nlabel => 'cpu.utilization.percentage', set => { + key_values => [ { name => 'average' }, { name => 'display' } ], + output_template => '%.2f %%', + perfdatas => [ + { label => 'total_cpu_avg', value => 'average_absolute', template => '%.2f', + min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_message_output { + my ($self, %options) = @_; + + return "Switch '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter:s' => { name => 'filter', default => '.*' } + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_mpCpuSwitchNumberRev = '.1.3.6.1.4.1.20301.2.5.1.2.2.12.1.1.1'; + my $oid_mpCpuStatsUtil1MinuteSwRev = '.1.3.6.1.4.1.20301.2.5.1.2.2.12.1.1.5'; + + my $result = $options{snmp}->get_table(oid => $oid_mpCpuSwitchNumberRev, nothing_quit => 1); + my @instance_oids = (); + foreach my $oid (keys %$result) { + if ($result->{$oid} =~ /$self->{option_results}->{filter}/i) { + push @instance_oids, $oid; + } + } + + if (scalar(@instance_oids) == 0) { + $self->{output}->add_option_msg(short_msg => "Cannot find switch number '$self->{option_results}->{filter}'."); + $self->{output}->option_exit(); + } + + $options{snmp}->load( + oids => [$oid_mpCpuStatsUtil1MinuteSwRev], + instances => \@instance_oids, + instance_regexp => "^" . $oid_mpCpuSwitchNumberRev . '\.(.+)' + ); + my $result2 = $options{snmp}->get_leef(); + + foreach my $instance (@instance_oids) { + $instance =~ /^$oid_mpCpuSwitchNumberRev\.(.+)/; + $instance = $1; + + $self->{cpu}->{$instance} = { + display => $result->{$oid_mpCpuSwitchNumberRev . '.' . $instance}, + average => $result2->{$oid_mpCpuStatsUtil1MinuteSwRev . '.' . $instance}, + }; + } +} + +1; + +__END__ + +=head1 MODE + +Check CPU usage (over the last minute). + +=over 8 + +=item B<--filter> + +Filter switch number (Default: '.*'). + +=item B<--warning-average> + +Warning threshold average CPU utilization. + +=item B<--critical-average> + +Critical threshold average CPU utilization. + +=back + +=cut diff --git a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/disk.pm b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/disk.pm new file mode 100644 index 000000000..16ec7a79b --- /dev/null +++ b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/disk.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 network::lenovo::flexsystem::snmp::mode::disk; + +use base qw(snmp_standard::mode::storage); + +use strict; +use warnings; + +sub default_storage_type { + my ($self, %options) = @_; + + return '^(?!(hrStorageRam)$)'; +} + +sub prefix_storage_output { + my ($self, %options) = @_; + + return "Disk '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check disk. + +=over 8 + +=item B<--warning-usage> + +Threshold warning. + +=item B<--critical-usage> + +Threshold critical. + +=item B<--units> + +Units of thresholds (Default: '%') ('%', 'B'). + +=item B<--free> + +Thresholds are on free space left. + +=item B<--storage> + +Set the storage (number expected) ex: 1, 2,... (empty means 'check all storage'). + +=item B<--name> + +Allows to use storage name with option --storage instead of storage oid index. + +=item B<--regexp> + +Allows to use regexp to filter storage (with option --name). + +=item B<--regexp-isensitive> + +Allows to use regexp non case-sensitive (with --regexp). + +=item B<--reload-cache-time> + +Time in minutes before reloading cache file (default: 180). + +=item B<--show-cache> + +Display cache storage datas. + +=item B<--filter-storage-type> + +Filter storage types with a regexp (Default: '^(?!(hrStorageRam)$)'). + +=back + +=cut diff --git a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/environment.pm b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/environment.pm new file mode 100644 index 000000000..632d32a71 --- /dev/null +++ b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/environment.pm @@ -0,0 +1,84 @@ +# +# 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 network::lenovo::flexsystem::snmp::mode::environment; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(faultled|temperature)$'; + + $self->{cb_hook2} = 'snmp_execute'; + $self->{thresholds} = { + 'faultled' => [ + ['on', 'CRITICAL'], + ['off', 'OK'], + ], + }; + + $self->{components_path} = 'network::lenovo::flexsystem::snmp::mode::components'; + $self->{components_module} = ['faultled', 'temperature']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'faultled', 'temperature'. + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=back + +=cut diff --git a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/memory.pm b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/memory.pm new file mode 100644 index 000000000..232a2c98e --- /dev/null +++ b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/memory.pm @@ -0,0 +1,163 @@ +# +# 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 network::lenovo::flexsystem::snmp::mode::memory; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub custom_usage_output { + my ($self, %options) = @_; + + return sprintf( + 'Ram Total: %s %s Used: %s %s (%.2f%%) Free: %s %s (%.2f%%)', + $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}), + $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}), + $self->{result_values}->{prct_used_absolute}, + $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}), + $self->{result_values}->{prct_free_absolute} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'memory', type => 1, cb_prefix_output => 'prefix_message_output', message_multiple => 'All memory usages are ok' }, + ]; + + $self->{maps_counters}->{memory} = [ + { label => 'usage', nlabel => 'memory.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { label => 'used', value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { label => 'free', value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => { + key_values => [ { name => 'prct_used' } ], + output_template => 'Used : %.2f %%', + perfdatas => [ + { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_message_output { + my ($self, %options) = @_; + + return "Switch '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter:s' => { name => 'filter', default => '.*' } + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_switchNumber = '.1.3.6.1.4.1.20301.2.5.1.2.12.9.1.1.1'; + my $oid_totalMemoryStatsRev = '.1.3.6.1.4.1.20301.2.5.1.2.12.9.1.1.3'; # in bytes + my $oid_memoryFreeStatsRev = '.1.3.6.1.4.1.20301.2.5.1.2.12.9.1.1.4'; # in bytes + + my $result = $options{snmp}->get_table(oid => $oid_switchNumber, nothing_quit => 1); + my @instance_oids = (); + foreach my $oid (keys %$result) { + if ($result->{$oid} =~ /$self->{option_results}->{filter}/i) { + push @instance_oids, $oid; + } + } + + if (scalar(@instance_oids) == 0) { + $self->{output}->add_option_msg(short_msg => "Cannot find switch number '$self->{option_results}->{filter}'."); + $self->{output}->option_exit(); + } + + $options{snmp}->load( + oids => [$oid_totalMemoryStatsRev, $oid_memoryFreeStatsRev], + instances => \@instance_oids, + instance_regexp => "^" . $oid_switchNumber . '\.(.+)' + ); + my $result2 = $options{snmp}->get_leef(); + + foreach my $instance (@instance_oids) { + $instance =~ /^$oid_switchNumber\.(.+)/; + $instance = $1; + + my $free = $result2->{$oid_memoryFreeStatsRev . '.' . $instance}; + my $total = $result2->{$oid_totalMemoryStatsRev . '.' . $instance}; + my $prct_used = ($total - $free) * 100 / $total; + $self->{memory}->{$instance} = { + display => $result->{$oid_switchNumber . '.' . $instance}, + total => $total, + used => $total - $free, + free => $free, + prct_used => $prct_used, + prct_free => 100 - $prct_used, + }; + } +} + +1; + +__END__ + +=head1 MODE + +Check memory usage. + +=over 8 + +=item B<--filter> + +Filter switch number (Default: '.*'). + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%). + +=back + +=cut diff --git a/centreon-plugins/network/lenovo/flexsystem/snmp/plugin.pm b/centreon-plugins/network/lenovo/flexsystem/snmp/plugin.pm new file mode 100644 index 000000000..15dfa65b6 --- /dev/null +++ b/centreon-plugins/network/lenovo/flexsystem/snmp/plugin.pm @@ -0,0 +1,55 @@ +# +# 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 network::lenovo::flexsystem::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'cpu' => 'network::lenovo::flexsystem::snmp::mode::cpu', + 'disk' => 'network::lenovo::flexsystem::snmp::mode::disk', + 'environment' => 'network::lenovo::flexsystem::snmp::mode::environment', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::lenovo::flexsystem::snmp::mode::memory', + 'time' => 'snmp_standard::mode::ntp', + 'uptime' => 'snmp_standard::mode::uptime', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Lenovo Flex System switches in SNMP. + +=cut From fab93a90f00874c73c2b3a848b87881044e2f72f Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Wed, 8 Apr 2020 22:32:26 +0200 Subject: [PATCH 072/190] add filter-type to ec2 discovery --- centreon-plugins/cloud/aws/ec2/mode/discovery.pm | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/centreon-plugins/cloud/aws/ec2/mode/discovery.pm b/centreon-plugins/cloud/aws/ec2/mode/discovery.pm index ed6e9dd76..a6c43047e 100644 --- a/centreon-plugins/cloud/aws/ec2/mode/discovery.pm +++ b/centreon-plugins/cloud/aws/ec2/mode/discovery.pm @@ -32,7 +32,8 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "prettify" => { name => 'prettify' }, + "prettify" => { name => 'prettify' }, + "filter-type:s" => { name => 'filter_type' }, }); return $self; @@ -86,8 +87,10 @@ sub run { } push @{$ec2{tags}}, { key => $tag->{Key}, value => $tag->{Value} }; } - push @disco_data, \%ec2; - push @disco_data, \%asg if (defined($asg{name}) && $asg{name} ne ''); + push @disco_data, \%ec2 unless (defined($self->{option_results}->{filter_type}) + && $ec2{type} !~ /$self->{option_results}->{filter_type}/); + push @disco_data, \%asg unless ((defined($self->{option_results}->{filter_type}) + && $asg{type} !~ /$self->{option_results}->{filter_type}/) || !defined($asg{name}) || $asg{name} eq ''); } } @@ -123,6 +126,10 @@ EC2/ASG discovery. =over 8 +=item B<--filter-type> + +Filter type. + =item B<--prettify> Prettify JSON output. From 5f0ba8f9d1a2a0bc3a0d6466b25bf69e91d566ac Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 10 Apr 2020 11:36:04 +0200 Subject: [PATCH 073/190] prepare new release --- centreon-plugins/changelog | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/centreon-plugins/changelog b/centreon-plugins/changelog index 095c7f0f6..9204b28dd 100644 --- a/centreon-plugins/changelog +++ b/centreon-plugins/changelog @@ -1,3 +1,20 @@ +2020-04-10 Quentin Garnier + * Plugin added: Dell OS10 SNMP + * Plugin added: Sirportly notification + * Plugin added: Mobotix Camera SNMP + * Plugin added: Ibm MQ MQI + * Plugin added: Supermicro BMC SNMP + * Plugin added: Eltek Enexus SNMP + * Plugin added: Cisco Meraki Rest API + * Plugin added: Aws EFS + * Core: add backend ssh system (plink, ssh and libssh) + * Mode added: [azure] 'alert' + * Mode added: [checkpoint/snmp] 'vsx' + * Mode added: [synology/snmp] 'ha' + * Mode added: [cisco/standard/snmp] 'wan3g' + * Break: [fortigate/snmp] 'cpu', 'memory', 'vdom' (merge) + * Break: [supermicro/snmp] move directory + 2020-02-04 Quentin Garnier * Plugin added: Allied Telesis SNMP * Plugin added: UPS HP SNMP From dae290957b9cad1db76e5d7a5631e302996978a2 Mon Sep 17 00:00:00 2001 From: thibaults-centreon Date: Fri, 10 Apr 2020 14:25:34 +0200 Subject: [PATCH 074/190] add(plugin): AWS VPN --- centreon-plugins/cloud/aws/custom/awscli.pm | 67 +++- centreon-plugins/cloud/aws/custom/paws.pm | 88 ++--- .../cloud/aws/vpn/mode/listvpn.pm | 96 ++++++ .../cloud/aws/vpn/mode/traffic.pm | 315 ++++++++++++++++++ centreon-plugins/cloud/aws/vpn/plugin.pm | 52 +++ 5 files changed, 559 insertions(+), 59 deletions(-) create mode 100644 centreon-plugins/cloud/aws/vpn/mode/listvpn.pm create mode 100644 centreon-plugins/cloud/aws/vpn/mode/traffic.pm create mode 100644 centreon-plugins/cloud/aws/vpn/plugin.pm diff --git a/centreon-plugins/cloud/aws/custom/awscli.pm b/centreon-plugins/cloud/aws/custom/awscli.pm index 3530adfe8..ab62709fb 100644 --- a/centreon-plugins/cloud/aws/custom/awscli.pm +++ b/centreon-plugins/cloud/aws/custom/awscli.pm @@ -160,7 +160,7 @@ sub execute { $self->{output}->option_exit(); } - return $raw_results; + return $raw_results; } sub cloudwatch_get_metrics_set_cmd { @@ -176,7 +176,7 @@ sub cloudwatch_get_metrics_set_cmd { } $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); - return $cmd_options; + return $cmd_options; } sub cloudwatch_get_metrics { @@ -229,7 +229,7 @@ sub discovery_set_cmd { my $cmd_options = $options{service} . " " . $options{command} . " --region $options{region} --output json"; $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); - return $cmd_options; + return $cmd_options; } sub discovery { @@ -249,7 +249,7 @@ sub cloudwatch_get_alarms_set_cmd { my $cmd_options = "cloudwatch describe-alarms --region $options{region} --output json"; $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); - return $cmd_options; + return $cmd_options; } sub cloudwatch_get_alarms { @@ -282,7 +282,7 @@ sub cloudwatch_list_metrics_set_cmd { $cmd_options .= " --metric-name $options{metric}" if (defined($options{metric})); $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); - return $cmd_options; + return $cmd_options; } sub cloudwatch_list_metrics { @@ -302,7 +302,7 @@ sub cloudwatchlogs_describe_log_groups_set_cmd { my $cmd_options = "logs describe-log-groups --region $self->{option_results}->{region} --output json"; $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); - return $cmd_options; + return $cmd_options; } sub cloudwatchlogs_describe_log_groups { @@ -329,7 +329,7 @@ sub cloudwatchlogs_filter_log_events_set_cmd { } $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); - return $cmd_options; + return $cmd_options; } sub cloudwatchlogs_filter_log_events { @@ -349,7 +349,7 @@ sub ec2_get_instances_status_set_cmd { my $cmd_options = "ec2 describe-instance-status --include-all-instances --no-dry-run --region $options{region} --output json"; $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); - return $cmd_options; + return $cmd_options; } sub ec2_get_instances_status { @@ -361,7 +361,7 @@ sub ec2_get_instances_status { my $instance_results = {}; foreach (@{$raw_results->{InstanceStatuses}}) { $instance_results->{$_->{InstanceId}} = { - state => $_->{InstanceState}->{Name}, + state => $_->{InstanceState}->{Name}, status => => $_->{InstanceStatus}->{Status} }; } @@ -377,7 +377,7 @@ sub ec2_list_resources_set_cmd { my $cmd_options = "ec2 describe-instances --no-dry-run --region $options{region} --output json"; $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); - return $cmd_options; + return $cmd_options; } sub ec2_list_resources { @@ -394,7 +394,7 @@ sub ec2_list_resources { my %already = map { $_->{Name} => $_ } @{$resource_results}; if ($tag->{Key} eq "aws:autoscaling:groupName") { next if (defined($already{$tag->{Value}})); - push @{$resource_results}, { + push @{$resource_results}, { Name => $tag->{Value}, Type => 'asg', }; @@ -402,7 +402,7 @@ sub ec2_list_resources { push @instance_tags, $tag->{Value}; } } - push @{$resource_results}, { + push @{$resource_results}, { Name => $instance->{InstanceId}, Type => 'instance', AvailabilityZone => $instance->{Placement}->{AvailabilityZone}, @@ -411,7 +411,6 @@ sub ec2_list_resources { Tags => join(",", @instance_tags), KeyName => $instance->{KeyName}, }; - } } @@ -426,7 +425,7 @@ sub asg_get_resources_set_cmd { my $cmd_options = "autoscaling describe-auto-scaling-groups --region $options{region} --output json"; $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); - return $cmd_options; + return $cmd_options; } sub asg_get_resources { @@ -446,7 +445,7 @@ sub rds_get_instances_status_set_cmd { my $cmd_options = "rds describe-db-instances --region $options{region} --output json"; $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); - return $cmd_options; + return $cmd_options; } sub rds_get_instances_status { @@ -471,7 +470,7 @@ sub rds_list_instances_set_cmd { my $cmd_options = "rds describe-db-instances --region $options{region} --output json"; $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); - return $cmd_options; + return $cmd_options; } sub rds_list_instances { @@ -502,7 +501,7 @@ sub rds_list_clusters_set_cmd { my $cmd_options = "rds describe-db-clusters --region $options{region} --output json"; $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); - return $cmd_options; + return $cmd_options; } sub rds_list_clusters { @@ -524,6 +523,40 @@ sub rds_list_clusters { return $cluster_results; } +sub vpn_list_connections_set_cmd { + my ($self, %options) = @_; + + return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); + + my $cmd_options = "ec2 describe-vpn-connections --region $options{region} --output json"; + $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); + + return $cmd_options; +} + +sub vpn_list_connections { + my ($self, %options) = @_; + + my $cmd_options = $self->vpn_list_connections_set_cmd(%options); + my $raw_results = $self->execute(cmd_options => $cmd_options); + + my $connections_results = []; + foreach my $connection (@{$raw_results->{VpnConnections}}) { + my @name_tags; + foreach my $tag (@{$connection->{Tags}}) { + if ($tag->{Key} eq "Name" && defined($tag->{Value})) { + push @name_tags, $tag->{Value}; + } + } + push @{$connections_results}, { + id => $connection->{VpnConnectionId}, + name => join(",", @name_tags), + state => $connection->{State} + } + }; + return $connections_results; +} + 1; __END__ diff --git a/centreon-plugins/cloud/aws/custom/paws.pm b/centreon-plugins/cloud/aws/custom/paws.pm index 44f20e736..030aa81bc 100644 --- a/centreon-plugins/cloud/aws/custom/paws.pm +++ b/centreon-plugins/cloud/aws/custom/paws.pm @@ -39,9 +39,8 @@ sub new { $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 => { + $options{options}->add_options(arguments => { 'aws-secret-key:s' => { name => 'aws_secret_key' }, 'aws-access-key:s' => { name => 'aws_access_key' }, 'region:s' => { name => 'region' }, @@ -53,28 +52,23 @@ sub new { }); } $options{options}->add_help(package => __PACKAGE__, sections => 'PAWS OPTIONS', once => 1); - $self->{output} = $options{output}; $self->{mode} = $options{mode}; - return $self; } sub get_region { my ($self, %options) = @_; - return $self->{option_results}->{region}; } 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++) { @@ -95,19 +89,16 @@ sub check_options { $ENV{HTTP_PROXY} = $self->{option_results}->{proxyurl}; $ENV{HTTPS_PROXY} = $self->{option_results}->{proxyurl}; } - if (defined($self->{option_results}->{aws_secret_key}) && $self->{option_results}->{aws_secret_key} ne '') { $ENV{AWS_SECRET_KEY} = $self->{option_results}->{aws_secret_key}; } if (defined($self->{option_results}->{aws_access_key}) && $self->{option_results}->{aws_access_key} ne '') { $ENV{AWS_ACCESS_KEY} = $self->{option_results}->{aws_access_key}; } - if (!defined($self->{option_results}->{region}) || $self->{option_results}->{region} eq '') { $self->{output}->add_option_msg(short_msg => "Need to specify --region option."); $self->{output}->option_exit(); } - if (defined($self->{option_results}->{statistic})) { foreach my $statistic (@{$self->{option_results}->{statistic}}) { if ($statistic !~ /minimum|maximum|average|sum/) { @@ -116,20 +107,18 @@ sub check_options { } } } - return 0; } sub cloudwatch_get_metrics { my ($self, %options) = @_; - + my $metric_results = {}; eval { my $lwp_caller = new Paws::Net::LWPCaller(); my $cw = Paws->service('CloudWatch', caller => $lwp_caller, region => $options{region}); my $start_time = DateTime->now->subtract(seconds => $options{timeframe})->iso8601; my $end_time = DateTime->now->iso8601; - foreach my $metric_name (@{$options{metrics}}) { my $metric_result = $cw->GetMetricStatistics( MetricName => $metric_name, @@ -142,7 +131,6 @@ sub cloudwatch_get_metrics { #Unit => $unit, Dimensions => $options{dimensions}, ); - $metric_results->{$metric_result->{Label}} = { points => 0 }; foreach my $point (@{$metric_result->{Datapoints}}) { if (defined($point->{Average})) { @@ -161,10 +149,9 @@ sub cloudwatch_get_metrics { $metric_results->{$metric_result->{Label}}->{sum} = 0 if (!defined($metric_results->{$metric_result->{Label}}->{sum})); $metric_results->{$metric_result->{Label}}->{sum} += $point->{Sum}; } - $metric_results->{$metric_result->{Label}}->{points}++; } - + if (defined($metric_results->{$metric_result->{Label}}->{average})) { $metric_results->{$metric_result->{Label}}->{average} /= $metric_results->{$metric_result->{Label}}->{points}; } @@ -174,7 +161,6 @@ sub cloudwatch_get_metrics { $self->{output}->add_option_msg(short_msg => "error: $@"); $self->{output}->option_exit(); } - return $metric_results; } @@ -205,7 +191,7 @@ sub cloudwatch_get_alarms { sub cloudwatch_list_metrics { my ($self, %options) = @_; - + my $metric_results = []; eval { my $lwp_caller = new Paws::Net::LWPCaller(); @@ -219,13 +205,13 @@ sub cloudwatch_list_metrics { foreach my $dimension (@{$_->{Dimensions}}) { push @$dimensions, { Name => $dimension->{Name}, Value => $dimension->{Value} }; } - push @{$metric_results}, { + push @{$metric_results}, { Namespace => $_->{Namespace}, MetricName => $_->{MetricName}, Dimensions => $dimensions, }; } - + last if (!defined($list_metrics->{NextToken})); $cw_options{NextToken} = $list_metrics->{NextToken}; } @@ -234,7 +220,6 @@ sub cloudwatch_list_metrics { $self->{output}->add_option_msg(short_msg => "error: $@"); $self->{output}->option_exit(); } - return $metric_results; } @@ -250,7 +235,7 @@ sub cloudwatchlogs_describe_log_groups { foreach (@{$list_log_groups->{logGroups}}) { push @$log_groups_results, $_; } - + last if (!defined($list_log_groups->{NextToken})); $cw_options{NextToken} = $list_log_groups->{NextToken}; } @@ -259,7 +244,6 @@ sub cloudwatchlogs_describe_log_groups { $self->{output}->add_option_msg(short_msg => "error: $@"); $self->{output}->option_exit(); } - return $log_groups_results; } @@ -277,7 +261,6 @@ sub cloudwatchlogs_filter_log_events { foreach (@{$list_log_groups->{logGroups}}) { push @$log_groups_results, $_; } - last if (!defined($list_log_groups->{NextToken})); $cw_options{NextToken} = $list_log_groups->{NextToken}; } @@ -286,19 +269,17 @@ sub cloudwatchlogs_filter_log_events { $self->{output}->add_option_msg(short_msg => "error: $@"); $self->{output}->option_exit(); } - return $log_groups_results; } sub ec2_get_instances_status { my ($self, %options) = @_; - + my $instance_results = {}; eval { my $lwp_caller = new Paws::Net::LWPCaller(); my $ec2 = Paws->service('EC2', caller => $lwp_caller, region => $options{region}); my $instances = $ec2->DescribeInstanceStatus(DryRun => 0, IncludeAllInstances => 1); - foreach (@{$instances->{InstanceStatuses}}) { $instance_results->{$_->{InstanceId}} = { state => $_->{InstanceState}->{Name}, status => => $_->{InstanceStatus}->{Status} }; @@ -308,19 +289,18 @@ sub ec2_get_instances_status { $self->{output}->add_option_msg(short_msg => "error: $@"); $self->{output}->option_exit(); } - + return $instance_results; } sub ec2_list_resources { my ($self, %options) = @_; - + my $resource_results = []; eval { my $lwp_caller = new Paws::Net::LWPCaller(); my $ec2 = Paws->service('EC2', caller => $lwp_caller, region => $options{region}); my $list_instances = $ec2->DescribeInstances(DryRun => 0); - foreach my $reservation (@{$list_instances->{Reservations}}) { foreach my $instance (@{$reservation->{Instances}}) { my @instance_tags; @@ -328,7 +308,7 @@ sub ec2_list_resources { my %already = map { $_->{Name} => $_ } @{$resource_results}; if ($tag->{Key} eq "aws:autoscaling:groupName") { next if (defined($already{$tag->{Value}})); - push @{$resource_results}, { + push @{$resource_results}, { Name => $tag->{Value}, Type => 'asg', }; @@ -336,7 +316,7 @@ sub ec2_list_resources { push @instance_tags, $tag->{Key} . ":" . $tag->{Value}; } } - push @{$resource_results}, { + push @{$resource_results}, { Name => $instance->{InstanceId}, Type => 'instance', AvailabilityZone => $instance->{Placement}->{AvailabilityZone}, @@ -344,7 +324,7 @@ sub ec2_list_resources { State => $instance->{State}->{Name}, Tags => join(",", @instance_tags), }; - + } } }; @@ -352,7 +332,7 @@ sub ec2_list_resources { $self->{output}->add_option_msg(short_msg => "error: $@"); $self->{output}->option_exit(); } - + return $resource_results; } @@ -375,7 +355,7 @@ sub asg_get_resources { sub rds_get_instances_status { my ($self, %options) = @_; - + my $instance_results = {}; eval { my $lwp_caller = new Paws::Net::LWPCaller(); @@ -389,19 +369,18 @@ sub rds_get_instances_status { $self->{output}->add_option_msg(short_msg => "error: $@"); $self->{output}->option_exit(); } - + return $instance_results; } sub rds_list_instances { my ($self, %options) = @_; - + my $instance_results = []; eval { my $lwp_caller = new Paws::Net::LWPCaller(); my $rds = Paws->service('RDS', caller => $lwp_caller, region => $options{region}); my $list_instances = $rds->DescribeDBInstances(); - foreach my $instance (@{$list_instances->{DBInstances}}) { push @{$instance_results}, { Name => $instance->{DBInstanceIdentifier}, @@ -416,19 +395,16 @@ sub rds_list_instances { $self->{output}->add_option_msg(short_msg => "error: $@"); $self->{output}->option_exit(); } - return $instance_results; } sub rds_list_clusters { my ($self, %options) = @_; - my $cluster_results = []; eval { my $lwp_caller = new Paws::Net::LWPCaller(); my $rds = Paws->service('RDS', caller => $lwp_caller, region => $options{region}); my $list_clusters = $rds->DescribeDBClusters(); - foreach my $cluster (@{$list_clusters->{DBClusters}}) { push @{$cluster_results}, { Name => $cluster->{DBClusterIdentifier}, @@ -442,10 +418,38 @@ sub rds_list_clusters { $self->{output}->add_option_msg(short_msg => "error: $@"); $self->{output}->option_exit(); } - return $cluster_results; } +sub vpn_list_connections { + my ($self, %options) = @_; + my $connections_results = []; + eval { + my $lwp_caller = new Paws::Net::LWPCaller(); + my $rds = Paws->service('EC2', caller => $lwp_caller, region => $options{region}); + my $list_vpn = $vpn->DescribeVpnConnections(); + foreach my $connection (@{$list_vpn->{VpnConnections}}) { + my @name_tags; + foreach my $tag (@{$connection->{Tags}}) { + if ($tag->{Key} eq "Name" && defined($tag->{Value})) { + push @name_tags, $tag->{Value}; + } + } + push @{$connections_results}, { + id => $connection->{VpnConnectionId}, + name => join(",", @name_tags), + state => $connection->{State} + } + }; + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "error: $@"); + $self->{output}->option_exit(); + } + + return $connections_results; +} + 1; __END__ diff --git a/centreon-plugins/cloud/aws/vpn/mode/listvpn.pm b/centreon-plugins/cloud/aws/vpn/mode/listvpn.pm new file mode 100644 index 000000000..ff7fdcfc7 --- /dev/null +++ b/centreon-plugins/cloud/aws/vpn/mode/listvpn.pm @@ -0,0 +1,96 @@ +# +# 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 cloud::aws::vpn::mode::listvpn; + +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) = @_; + + $self->{connection} = $options{custom}->vpn_list_connections(region => $self->{option_results}->{region}); +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach (@{$self->{connection}}) { + $self->{output}->output_add( + long_msg => sprintf("[Id = %s][Name = %s][State = %s]", + $_->{id}, $_->{name}, $_->{state} )); + } + + $self->{output}->output_add(severity => 'OK', + short_msg => 'List VPN connections:'); + $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 => ['id', 'name', 'state']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach (@{$self->{connection}}) { + $self->{output}->add_disco_entry( + id => $_->{id}, + name => $_->{name}, + state => $_->{state}, + ); + }; +} + +1; + +__END__ + +=head1 MODE + +List EC2 instances. + +=over 8 + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/vpn/mode/traffic.pm b/centreon-plugins/cloud/aws/vpn/mode/traffic.pm new file mode 100644 index 000000000..d23cd5552 --- /dev/null +++ b/centreon-plugins/cloud/aws/vpn/mode/traffic.pm @@ -0,0 +1,315 @@ +# +# 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 cloud::aws::vpn::mode::traffic; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my %metrics_mapping = ( + 'TunnelState' => { + 'output' => 'Tunnel State', + 'label' => 'tunnel-state', + 'nlabel' => { + 'absolute' => 'vpn.tunnel.tunnelstate'}, + 'unit' => '' + }, + 'TunnelDataIn' => { + 'output' => 'Tunnel Data In', + 'label' => 'tunnel-datain', + 'nlabel' => { + 'absolute' => 'vpn.tunnel.datain.bytes', + 'per_second' => 'vpn.tunnel.datain.bytespersecond', + }, + 'unit' => 'B' + }, + 'TunnelDataOut' => { + 'output' => 'Tunnel Data Out', + 'label' => 'tunnel-dataout', + 'nlabel' => { + 'absolute' => 'vpn.tunnel.dataout.bytes', + 'per_second' => 'vpn.tunnel.dataout.bytespersecond', + }, + 'unit' => 'B' + } +); + + +sub custom_metric_calc { + my ($self, %options) = @_; + + $self->{result_values}->{timeframe} = $options{new_datas}->{$self->{instance} . '_timeframe'}; + $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{metric}}; + $self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe}; + $self->{result_values}->{metric} = $options{extra_options}->{metric}; + return 0; +} + +sub custom_metric_calc_state { + my ($self, %options) = @_; + + $self->{result_values}->{timeframe} = $options{new_datas}->{$self->{instance} . '_timeframe'}; + $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{metric}}; + $self->{result_values}->{value_per_sec} = $self->{result_values}->{value}; + $self->{result_values}->{metric} = $options{extra_options}->{metric}; + return 0; +} + +sub custom_metric_threshold { + my ($self, %options) = @_; + + 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-' . $metrics_mapping{$self->{result_values}->{metric}}->{label} , exit_litteral => 'critical' }, + { label => 'warning-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'warning' } ] + ); + return $exit; +} + +sub custom_metric_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + instances => $self->{instance}, + label => $metrics_mapping{$self->{result_values}->{metric}}->{label}, + nlabel => defined($self->{instance_mode}->{option_results}->{per_sec}) ? + $metrics_mapping{$self->{result_values}->{metric}}->{nlabel}->{per_second} : + $metrics_mapping{$self->{result_values}->{metric}}->{nlabel}->{absolute}, + unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? + $metrics_mapping{$self->{result_values}->{metric}}->{unit} . '/s' : + $metrics_mapping{$self->{result_values}->{metric}}->{unit}, + 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-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}), + ); +} + +sub custom_metric_perfdata_state { + my ($self, %options) = @_; + + $self->{output}->perfdata_add( + instances => $self->{instance}, + label => $metrics_mapping{$self->{result_values}->{metric}}->{label}, + nlabel => $metrics_mapping{$self->{result_values}->{metric}}->{nlabel}->{absolute}, + unit => $metrics_mapping{$self->{result_values}->{metric}}->{unit}, + value => sprintf("%.2f", $self->{result_values}->{value}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}), + ); +} + +sub custom_metric_output { + my ($self, %options) = @_; + my $msg = ""; + + if (defined($self->{instance_mode}->{option_results}->{per_sec})) { + my ($value, $unit) = ($metrics_mapping{$self->{result_values}->{metric}}->{unit} eq 'B') ? + $self->{perfdata}->change_bytes(value => $self->{result_values}->{value_per_sec}) : + ($self->{result_values}->{value_per_sec}, $metrics_mapping{$self->{result_values}->{metric}}->{unit}); + $msg = sprintf("%s: %.2f %s", $metrics_mapping{$self->{result_values}->{metric}}->{output}, $value, $unit . '/s'); + } else { + my ($value, $unit) = ($metrics_mapping{$self->{result_values}->{metric}}->{unit} eq 'B') ? + $self->{perfdata}->change_bytes(value => $self->{result_values}->{value}) : + ($self->{result_values}->{value}, $metrics_mapping{$self->{result_values}->{metric}}->{unit}); + $msg = sprintf("%s: %.2f %s", $metrics_mapping{$self->{result_values}->{metric}}->{output}, $value, $unit); + } + return $msg; +} + +sub custom_metric_output_state { + my ($self, %options) = @_; + my $msg = ""; + + my $value = $self->{result_values}->{value}; + $msg = sprintf("%s: %.2f", $metrics_mapping{$self->{result_values}->{metric}}->{output}, $value); + return $msg; +} + +sub prefix_metric_output { + my ($self, %options) = @_; + + return "'" . $options{instance_value}->{display} . "' "; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + return "AWS VPN Tunnel'" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All VPN metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + set => { + key_values => [ { name => $metric }, { name => 'timeframe' }, { name => 'display' } ], + closure_custom_calc => ($metric =~ /State/) ? $self->can('custom_metric_calc_state') : $self->can('custom_metric_calc'), + closure_custom_calc_extra_options => { metric => $metric }, + closure_custom_output => ($metric =~ /State/) ? $self->can('custom_metric_output_state') : $self->can('custom_metric_output'), + closure_custom_perfdata => ($metric =~ /State/) ? $self->can('custom_metric_perfdata_state') : $self->can('custom_metric_perfdata'), + closure_custom_threshold_check => $self->can('custom_metric_threshold'), + } + } + push @{$self->{maps_counters}->{statistics}}, $entry; + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'vpnid:s@' => { name => 'vpn_id' }, + 'per-sec' => { name => 'per_sec' }, + 'filter-metric:s' => { name => 'filter_metric' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{vpn_id}) || $self->{option_results}->{vpn_id} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --vpnid option."); + $self->{output}->option_exit(); + }; + + foreach my $instance (@{$self->{option_results}->{vpn_id}}) { + if ($instance ne '') { + push @{$self->{aws_instance}}, $instance; + }; + } + + $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600; + $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; + + $self->{aws_statistics} = ['Average']; + if (defined($self->{option_results}->{statistic})) { + $self->{aws_statistics} = []; + foreach my $stat (@{$self->{option_results}->{statistic}}) { + if ($stat ne '') { + push @{$self->{aws_statistics}}, ucfirst(lc($stat)); + } + } + }; + foreach my $metric (keys %metrics_mapping) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + push @{$self->{aws_metrics}}, $metric; + }; +} + +sub manage_selection { + my ($self, %options) = @_; + + my %metric_results; + foreach my $instance (@{$self->{aws_instance}}) { + $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( + region => $self->{option_results}->{region}, + namespace => 'AWS/VPN', + dimensions => [ { Name => 'VpnId', Value => $instance } ], + metrics => $self->{aws_metrics}, + statistics => $self->{aws_statistics}, + timeframe => $self->{aws_timeframe}, + period => $self->{aws_period}, + ); + + foreach my $metric (@{$self->{aws_metrics}}) { + foreach my $statistic (@{$self->{aws_statistics}}) { + next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && + !defined($self->{option_results}->{zeroed})); + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{timeframe} = $self->{aws_timeframe}; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = + defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? + $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + } + } + } + + if (scalar(keys %{$self->{metrics}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check AWS VPN Connection. + +Example: +perl centreon_plugins.pl --plugin=cloud::aws::vpn::plugin --custommode=awscli --mode=traffic --region='eu-west-1' +--vpnid='vpn-1234567890abcdefg' --warning-tunnel-state='1:' --critical-tunnel-state='0.5:' --warning --verbose + +See 'https://docs.aws.amazon.com/vpn/latest/s2svpn/monitoring-cloudwatch-vpn.html' for more information. + + +=over 8 + +=item B<--vpnid> + +Set the VpnId (Required). + +=item B<--filter-metric> + +Filter on a specific metric. +Can be: TunnelState, TunnelDataIn, TunnelDataOut + +=item B<--warning-$metric$> + +Warning thresholds ($metric$ can be: 'tunnel-state', 'tunnel-datain', 'tunnel-dataout'). + +=item B<--critical-$metric$> + +Critical thresholds ($metric$ can be: 'tunnel-state', 'tunnel-datain', 'tunnel-dataout'). + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/vpn/plugin.pm b/centreon-plugins/cloud/aws/vpn/plugin.pm new file mode 100644 index 000000000..208a13de7 --- /dev/null +++ b/centreon-plugins/cloud/aws/vpn/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 cloud::aws::vpn::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} = '1.0'; + %{ $self->{modes} } = ( + 'traffic' => 'cloud::aws::vpn::mode::traffic', + 'listvpn' => 'cloud::aws::vpn::mode::listvpn', + 'discovery' => 'cloud::aws::vpn::mode::discovery' + ); + + $self->{custom_modes}{paws} = 'cloud::aws::custom::paws'; + $self->{custom_modes}{awscli} = 'cloud::aws::custom::awscli'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Amazon Site-To-Site VPN (Amazon VPN). + +=cut From 2a4ab14bd5bfb14d89051fbbba6318da2fa5714f Mon Sep 17 00:00:00 2001 From: thibaults-centreon Date: Fri, 10 Apr 2020 14:27:09 +0200 Subject: [PATCH 075/190] add(plugin): AWS VPN --- centreon-plugins/cloud/aws/vpn/mode/listvpn.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/cloud/aws/vpn/mode/listvpn.pm b/centreon-plugins/cloud/aws/vpn/mode/listvpn.pm index ff7fdcfc7..6cb8eb17d 100644 --- a/centreon-plugins/cloud/aws/vpn/mode/listvpn.pm +++ b/centreon-plugins/cloud/aws/vpn/mode/listvpn.pm @@ -87,7 +87,7 @@ __END__ =head1 MODE -List EC2 instances. +List VPN instances. =over 8 From c08aa99a9eb3b20b8b4cfe174e5cf5caf5fa5bd9 Mon Sep 17 00:00:00 2001 From: thibaults-centreon Date: Fri, 10 Apr 2020 14:33:55 +0200 Subject: [PATCH 076/190] fix trailing spaces --- centreon-plugins/cloud/aws/custom/paws.pm | 57 +++++++++++------------ 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/centreon-plugins/cloud/aws/custom/paws.pm b/centreon-plugins/cloud/aws/custom/paws.pm index 030aa81bc..23b06c1d0 100644 --- a/centreon-plugins/cloud/aws/custom/paws.pm +++ b/centreon-plugins/cloud/aws/custom/paws.pm @@ -39,6 +39,7 @@ sub new { $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 => { 'aws-secret-key:s' => { name => 'aws_secret_key' }, @@ -52,23 +53,28 @@ sub new { }); } $options{options}->add_help(package => __PACKAGE__, sections => 'PAWS OPTIONS', once => 1); + $self->{output} = $options{output}; $self->{mode} = $options{mode}; + return $self; } sub get_region { my ($self, %options) = @_; + return $self->{option_results}->{region}; } 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++) { @@ -89,16 +95,19 @@ sub check_options { $ENV{HTTP_PROXY} = $self->{option_results}->{proxyurl}; $ENV{HTTPS_PROXY} = $self->{option_results}->{proxyurl}; } + if (defined($self->{option_results}->{aws_secret_key}) && $self->{option_results}->{aws_secret_key} ne '') { $ENV{AWS_SECRET_KEY} = $self->{option_results}->{aws_secret_key}; } if (defined($self->{option_results}->{aws_access_key}) && $self->{option_results}->{aws_access_key} ne '') { $ENV{AWS_ACCESS_KEY} = $self->{option_results}->{aws_access_key}; } + if (!defined($self->{option_results}->{region}) || $self->{option_results}->{region} eq '') { $self->{output}->add_option_msg(short_msg => "Need to specify --region option."); $self->{output}->option_exit(); } + if (defined($self->{option_results}->{statistic})) { foreach my $statistic (@{$self->{option_results}->{statistic}}) { if ($statistic !~ /minimum|maximum|average|sum/) { @@ -107,6 +116,7 @@ sub check_options { } } } + return 0; } @@ -119,6 +129,7 @@ sub cloudwatch_get_metrics { my $cw = Paws->service('CloudWatch', caller => $lwp_caller, region => $options{region}); my $start_time = DateTime->now->subtract(seconds => $options{timeframe})->iso8601; my $end_time = DateTime->now->iso8601; + foreach my $metric_name (@{$options{metrics}}) { my $metric_result = $cw->GetMetricStatistics( MetricName => $metric_name, @@ -131,6 +142,7 @@ sub cloudwatch_get_metrics { #Unit => $unit, Dimensions => $options{dimensions}, ); + $metric_results->{$metric_result->{Label}} = { points => 0 }; foreach my $point (@{$metric_result->{Datapoints}}) { if (defined($point->{Average})) { @@ -149,6 +161,7 @@ sub cloudwatch_get_metrics { $metric_results->{$metric_result->{Label}}->{sum} = 0 if (!defined($metric_results->{$metric_result->{Label}}->{sum})); $metric_results->{$metric_result->{Label}}->{sum} += $point->{Sum}; } + $metric_results->{$metric_result->{Label}}->{points}++; } @@ -161,6 +174,7 @@ sub cloudwatch_get_metrics { $self->{output}->add_option_msg(short_msg => "error: $@"); $self->{output}->option_exit(); } + return $metric_results; } @@ -220,6 +234,7 @@ sub cloudwatch_list_metrics { $self->{output}->add_option_msg(short_msg => "error: $@"); $self->{output}->option_exit(); } + return $metric_results; } @@ -244,6 +259,7 @@ sub cloudwatchlogs_describe_log_groups { $self->{output}->add_option_msg(short_msg => "error: $@"); $self->{output}->option_exit(); } + return $log_groups_results; } @@ -261,6 +277,7 @@ sub cloudwatchlogs_filter_log_events { foreach (@{$list_log_groups->{logGroups}}) { push @$log_groups_results, $_; } + last if (!defined($list_log_groups->{NextToken})); $cw_options{NextToken} = $list_log_groups->{NextToken}; } @@ -269,6 +286,7 @@ sub cloudwatchlogs_filter_log_events { $self->{output}->add_option_msg(short_msg => "error: $@"); $self->{output}->option_exit(); } + return $log_groups_results; } @@ -280,6 +298,7 @@ sub ec2_get_instances_status { my $lwp_caller = new Paws::Net::LWPCaller(); my $ec2 = Paws->service('EC2', caller => $lwp_caller, region => $options{region}); my $instances = $ec2->DescribeInstanceStatus(DryRun => 0, IncludeAllInstances => 1); + foreach (@{$instances->{InstanceStatuses}}) { $instance_results->{$_->{InstanceId}} = { state => $_->{InstanceState}->{Name}, status => => $_->{InstanceStatus}->{Status} }; @@ -301,6 +320,7 @@ sub ec2_list_resources { my $lwp_caller = new Paws::Net::LWPCaller(); my $ec2 = Paws->service('EC2', caller => $lwp_caller, region => $options{region}); my $list_instances = $ec2->DescribeInstances(DryRun => 0); + foreach my $reservation (@{$list_instances->{Reservations}}) { foreach my $instance (@{$reservation->{Instances}}) { my @instance_tags; @@ -308,7 +328,7 @@ sub ec2_list_resources { my %already = map { $_->{Name} => $_ } @{$resource_results}; if ($tag->{Key} eq "aws:autoscaling:groupName") { next if (defined($already{$tag->{Value}})); - push @{$resource_results}, { + push @{$resource_results}, { Name => $tag->{Value}, Type => 'asg', }; @@ -316,7 +336,7 @@ sub ec2_list_resources { push @instance_tags, $tag->{Key} . ":" . $tag->{Value}; } } - push @{$resource_results}, { + push @{$resource_results}, { Name => $instance->{InstanceId}, Type => 'instance', AvailabilityZone => $instance->{Placement}->{AvailabilityZone}, @@ -381,6 +401,7 @@ sub rds_list_instances { my $lwp_caller = new Paws::Net::LWPCaller(); my $rds = Paws->service('RDS', caller => $lwp_caller, region => $options{region}); my $list_instances = $rds->DescribeDBInstances(); + foreach my $instance (@{$list_instances->{DBInstances}}) { push @{$instance_results}, { Name => $instance->{DBInstanceIdentifier}, @@ -395,16 +416,19 @@ sub rds_list_instances { $self->{output}->add_option_msg(short_msg => "error: $@"); $self->{output}->option_exit(); } + return $instance_results; } sub rds_list_clusters { my ($self, %options) = @_; + my $cluster_results = []; eval { my $lwp_caller = new Paws::Net::LWPCaller(); my $rds = Paws->service('RDS', caller => $lwp_caller, region => $options{region}); my $list_clusters = $rds->DescribeDBClusters(); + foreach my $cluster (@{$list_clusters->{DBClusters}}) { push @{$cluster_results}, { Name => $cluster->{DBClusterIdentifier}, @@ -418,6 +442,7 @@ sub rds_list_clusters { $self->{output}->add_option_msg(short_msg => "error: $@"); $self->{output}->option_exit(); } + return $cluster_results; } @@ -453,56 +478,30 @@ sub vpn_list_connections { 1; __END__ - =head1 NAME - Amazon AWS - =head1 SYNOPSIS - Amazon AWS - =head1 PAWS OPTIONS - =over 8 - =item B<--aws-secret-key> - Set AWS secret key. - =item B<--aws-access-key> - Set AWS access key. - =item B<--region> - Set the region name (Required). - =item B<--period> - Set period in seconds. - =item B<--timeframe> - Set timeframe in seconds. - =item B<--statistic> - Set cloudwatch statistics (Can be: 'minimum', 'maximum', 'average', 'sum'). - =item B<--zeroed> - Set metrics value to 0 if none. Usefull when CloudWatch does not return value when not defined. - =item B<--proxyurl> - Proxy URL if any - =back - =head1 DESCRIPTION - B. - -=cut +=cut \ No newline at end of file From 4dcee2dee9ef577dd4fb48d9fd2b99810901b518 Mon Sep 17 00:00:00 2001 From: thibaults-centreon Date: Fri, 10 Apr 2020 14:38:32 +0200 Subject: [PATCH 077/190] fix help --- centreon-plugins/cloud/aws/custom/paws.pm | 29 ++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/centreon-plugins/cloud/aws/custom/paws.pm b/centreon-plugins/cloud/aws/custom/paws.pm index 23b06c1d0..cc899ba34 100644 --- a/centreon-plugins/cloud/aws/custom/paws.pm +++ b/centreon-plugins/cloud/aws/custom/paws.pm @@ -478,30 +478,57 @@ sub vpn_list_connections { 1; __END__ + =head1 NAME + Amazon AWS + =head1 SYNOPSIS + Amazon AWS + =head1 PAWS OPTIONS + =over 8 + =item B<--aws-secret-key> + Set AWS secret key. + =item B<--aws-access-key> + Set AWS access key. + =item B<--region> + Set the region name (Required). + =item B<--period> + Set period in seconds. + =item B<--timeframe> + Set timeframe in seconds. + =item B<--statistic> -Set cloudwatch statistics (Can be: 'minimum', 'maximum', 'average', 'sum'). + +Set cloudwatch statistics +(Can be: 'minimum', 'maximum', 'average', 'sum'). + =item B<--zeroed> + Set metrics value to 0 if none. Usefull when CloudWatch does not return value when not defined. + =item B<--proxyurl> + Proxy URL if any + =back + =head1 DESCRIPTION + B. + =cut \ No newline at end of file From 104c50eb8d041aeaab1d9d3d6be43281e7b21fc8 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 10 Apr 2020 14:52:27 +0200 Subject: [PATCH 078/190] fix help --- centreon-plugins/storage/hp/3par/ssh/mode/volumeusage.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/storage/hp/3par/ssh/mode/volumeusage.pm b/centreon-plugins/storage/hp/3par/ssh/mode/volumeusage.pm index b97f8d6e9..e2a5b502a 100644 --- a/centreon-plugins/storage/hp/3par/ssh/mode/volumeusage.pm +++ b/centreon-plugins/storage/hp/3par/ssh/mode/volumeusage.pm @@ -156,7 +156,7 @@ Filter volume name (can be a regexp). =item B<--warning-*> B<--critical-*> -Threshold warning. +Thresholds. Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%). =back From 7c758bf3377e40c9240698cf97454bd2b2293ac7 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 10 Apr 2020 14:53:05 +0200 Subject: [PATCH 079/190] add ibm bladecenter and lenovo flexsystem snmp plugins --- .../ibm/nos}/snmp/mode/components/faultled.pm | 11 +- .../nos}/snmp/mode/components/temperature.pm | 57 +++++---- .../common/ibm/nos}/snmp/mode/cpu.pm | 26 ++-- .../common/ibm/nos}/snmp/mode/disk.pm | 6 +- .../common/ibm/nos}/snmp/mode/environment.pm | 35 ++++-- .../common/ibm/nos}/snmp/mode/memory.pm | 30 ++--- .../network/ibm/bladecenter/snmp/mode/disk.pm | 104 ---------------- .../network/ibm/bladecenter/snmp/plugin.pm | 20 ++-- .../snmp/mode/components/faultled.pm | 9 +- .../snmp/mode/components/temperature.pm | 111 +++++++++++------- .../lenovo/flexsystem/snmp/mode/cpu.pm | 94 ++++++++------- .../flexsystem/snmp/mode/environment.pm | 28 ++++- .../lenovo/flexsystem/snmp/mode/memory.pm | 99 ++++++++-------- .../network/lenovo/flexsystem/snmp/plugin.pm | 16 +-- 14 files changed, 305 insertions(+), 341 deletions(-) rename centreon-plugins/{network/ibm/bladecenter => centreon/common/ibm/nos}/snmp/mode/components/faultled.pm (90%) rename centreon-plugins/{network/ibm/bladecenter => centreon/common/ibm/nos}/snmp/mode/components/temperature.pm (55%) rename centreon-plugins/{network/ibm/bladecenter => centreon/common/ibm/nos}/snmp/mode/cpu.pm (74%) rename centreon-plugins/{network/lenovo/flexsystem => centreon/common/ibm/nos}/snmp/mode/disk.pm (95%) rename centreon-plugins/{network/ibm/bladecenter => centreon/common/ibm/nos}/snmp/mode/environment.pm (69%) rename centreon-plugins/{network/ibm/bladecenter => centreon/common/ibm/nos}/snmp/mode/memory.pm (82%) delete mode 100644 centreon-plugins/network/ibm/bladecenter/snmp/mode/disk.pm diff --git a/centreon-plugins/network/ibm/bladecenter/snmp/mode/components/faultled.pm b/centreon-plugins/centreon/common/ibm/nos/snmp/mode/components/faultled.pm similarity index 90% rename from centreon-plugins/network/ibm/bladecenter/snmp/mode/components/faultled.pm rename to centreon-plugins/centreon/common/ibm/nos/snmp/mode/components/faultled.pm index 7fc415513..f77620cb9 100644 --- a/centreon-plugins/network/ibm/bladecenter/snmp/mode/components/faultled.pm +++ b/centreon-plugins/centreon/common/ibm/nos/snmp/mode/components/faultled.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::ibm::bladecenter::snmp::mode::components::faultled; +package centreon::common::ibm::nos::snmp::mode::components::faultled; use strict; use warnings; @@ -31,7 +31,7 @@ sub check_faultled { my ($self, %options) = @_; $self->{components}->{faultled}->{total}++; - + $self->{output}->output_add(long_msg => sprintf( "Fault LED state is %s", @@ -52,13 +52,14 @@ sub check_faultled { sub check { my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking fault LED"); + + $self->{output}->output_add(long_msg => 'checking fault LED'); $self->{components}->{faultled} = { name => 'faultled', total => 0, skip => 0 }; return if ($self->check_filter(section => 'faultled')); my $oid_mmspFaultLED = '.1.3.6.1.4.1.26543.2.5.1.3.10.12.0'; - my $results = $self->{snmp}->get_leef(oids => [$oid_mmspFaultLED], nothing_quit => 1); + my $results = $self->{snmp}->get_leef(oids => [$oid_mmspFaultLED]); + return if (!defined($results->{$oid_mmspFaultLED})); check_faultled($self, value => $map_faultled_states{$results->{$oid_mmspFaultLED}}); } diff --git a/centreon-plugins/network/ibm/bladecenter/snmp/mode/components/temperature.pm b/centreon-plugins/centreon/common/ibm/nos/snmp/mode/components/temperature.pm similarity index 55% rename from centreon-plugins/network/ibm/bladecenter/snmp/mode/components/temperature.pm rename to centreon-plugins/centreon/common/ibm/nos/snmp/mode/components/temperature.pm index 036fc21be..704bf3121 100644 --- a/centreon-plugins/network/ibm/bladecenter/snmp/mode/components/temperature.pm +++ b/centreon-plugins/centreon/common/ibm/nos/snmp/mode/components/temperature.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::ibm::bladecenter::snmp::mode::components::temperature; +package centreon::common::ibm::nos::snmp::mode::components::temperature; use strict; use warnings; @@ -27,59 +27,70 @@ sub load {} sub check { my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking temperatures"); + + $self->{output}->output_add(long_msg => 'checking temperatures'); $self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 }; return if ($self->check_filter(section => 'temperature')); my $oid_hwTemperatureWarn = '.1.3.6.1.4.1.26543.2.5.1.3.1.22.0'; my $oid_hwTemperatureShut = '.1.3.6.1.4.1.26543.2.5.1.3.1.23.0'; - my $results = $self->{snmp}->get_leef(oids => [$oid_hwTemperatureWarn, $oid_hwTemperatureShut], nothing_quit => 1); + my $results = $self->{snmp}->get_leef(oids => [$oid_hwTemperatureWarn, $oid_hwTemperatureShut]); + return if (!defined($results->{$oid_hwTemperatureWarn})); + + my $instance = 'system'; # .1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1.20.1 = STRING: "44 C (Warn at 66 C / Recover at 61 C)" # .1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1.21.1 = STRING: "44 C (Shutdown at 72 C / Recover at 67 C)" $results->{$oid_hwTemperatureWarn} =~ /^([.0-9]+)\s*C\s*\(Warn(?:ing)?\s*at\s*([.0-9]+)\s*C/i; - my $temperature = $1; - my $warning = $2; + my ($temperature, $warning_mib) = ($1, $2); $results->{$oid_hwTemperatureShut} =~ /^([.0-9]+)\s*C\s*\(Shutdown\s*at\s*([.0-9]+)\s*C/i; - if ($1 > $temperature) { - $temperature = $1; - } - my $critical = ($warning + $2) / 2; + $temperature = $1 if ($1 > $temperature); + my $critical_mib = ($warning_mib + $2) / 2; $self->{components}->{temperature}->{total}++; - + $self->{output}->output_add(long_msg => sprintf( - "Temperature is %.1f C", - $temperature + "temperature '%s' is %.1f C [instance: %s]", + $instance, + $temperature, + $instance ) ); - my $exit = 'OK'; - if ($temperature >= $warning) { - $exit = 'WARNING'; - } - if ($temperature >= $critical) { - $exit = 'CRITICAL'; + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $temperature); + if ($checked == 0) { + $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warning_mib); + $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $critical_mib); + $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance); + $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance); + $exit = $self->{perfdata}->threshold_check( + value => $temperature, + threshold => [ + { label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' }, + { label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' } + ] + ); } + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add( severity => $exit, short_msg => sprintf( - "Temperature is %.1f C", + "Temperature '%s' is %.1f C", + $instance, $temperature ) ); } $self->{output}->perfdata_add( - label => 'temperature', unit => 'C', + unit => 'C', nlabel => 'hardware.temperature.celsius', instances => 'system', value => $temperature, - warning => $warning, - critical => $critical + warning => $warn, + critical => $crit ); } diff --git a/centreon-plugins/network/ibm/bladecenter/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/ibm/nos/snmp/mode/cpu.pm similarity index 74% rename from centreon-plugins/network/ibm/bladecenter/snmp/mode/cpu.pm rename to centreon-plugins/centreon/common/ibm/nos/snmp/mode/cpu.pm index ef7893af7..4363afd0b 100644 --- a/centreon-plugins/network/ibm/bladecenter/snmp/mode/cpu.pm +++ b/centreon-plugins/centreon/common/ibm/nos/snmp/mode/cpu.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::ibm::bladecenter::snmp::mode::cpu; +package centreon::common::ibm::nos::snmp::mode::cpu; use base qw(centreon::plugins::templates::counter); @@ -29,25 +29,25 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'cpu', type => 0, skipped_code => { -10 => 1 } }, + { name => 'cpu', type => 0, skipped_code => { -10 => 1 } } ]; $self->{maps_counters}->{cpu} = [ - { label => 'average', nlabel => 'cpu.utilization.percentage', set => { - key_values => [ { name => 'average' } ], - output_template => '%.2f %%', + { label => 'average-1m', nlabel => 'cpu.utilization.1m.percentage', set => { + key_values => [ { name => 'average_1m' } ], + output_template => 'CPU(s) average usage: %.2f %% (1min)', perfdatas => [ - { label => 'total_cpu_avg', value => 'average_absolute', template => '%.2f', - min => 0, max => 100, unit => '%' }, - ], + { value => 'average_1m_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' } + ] } - }, + } ]; } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; return $self; @@ -60,7 +60,7 @@ sub manage_selection { my $result = $options{snmp}->get_leef(oids => [$oid_mpCpuStatsUtil1Minute], nothing_quit => 1); $self->{cpu} = { - average => $result->{$oid_mpCpuStatsUtil1Minute}, + average_1m => $result->{$oid_mpCpuStatsUtil1Minute} } } @@ -74,11 +74,11 @@ Check CPU usage (over the last minute). =over 8 -=item B<--warning-average> +=item B<--warning-average-1m> Warning threshold average CPU utilization. -=item B<--critical-average> +=item B<--critical-average-1m> Critical threshold average CPU utilization. diff --git a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/disk.pm b/centreon-plugins/centreon/common/ibm/nos/snmp/mode/disk.pm similarity index 95% rename from centreon-plugins/network/lenovo/flexsystem/snmp/mode/disk.pm rename to centreon-plugins/centreon/common/ibm/nos/snmp/mode/disk.pm index 16ec7a79b..3a08b9161 100644 --- a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/disk.pm +++ b/centreon-plugins/centreon/common/ibm/nos/snmp/mode/disk.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::lenovo::flexsystem::snmp::mode::disk; +package centreon::common::ibm::nos::snmp::mode::disk; use base qw(snmp_standard::mode::storage); @@ -39,7 +39,7 @@ sub prefix_storage_output { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; return $self; @@ -51,7 +51,7 @@ __END__ =head1 MODE -Check disk. +Check disks. =over 8 diff --git a/centreon-plugins/network/ibm/bladecenter/snmp/mode/environment.pm b/centreon-plugins/centreon/common/ibm/nos/snmp/mode/environment.pm similarity index 69% rename from centreon-plugins/network/ibm/bladecenter/snmp/mode/environment.pm rename to centreon-plugins/centreon/common/ibm/nos/snmp/mode/environment.pm index 935e17f2d..c61f15ad4 100644 --- a/centreon-plugins/network/ibm/bladecenter/snmp/mode/environment.pm +++ b/centreon-plugins/centreon/common/ibm/nos/snmp/mode/environment.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::ibm::bladecenter::snmp::mode::environment; +package centreon::common::ibm::nos::snmp::mode::environment; use base qw(centreon::plugins::templates::hardware); @@ -27,32 +27,33 @@ use warnings; sub set_system { my ($self, %options) = @_; - - $self->{regexp_threshold_overload_check_section_option} = '^(faultled|temperature)$'; + + $self->{regexp_threshold_overload_check_section_option} = '^(faultled)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(?:temperature)$'; $self->{cb_hook2} = 'snmp_execute'; $self->{thresholds} = { 'faultled' => [ ['on', 'CRITICAL'], - ['off', 'OK'], - ], + ['off', 'OK'] + ] }; - $self->{components_path} = 'network::ibm::bladecenter::snmp::mode::components'; + $self->{components_path} = 'centreon::common::ibm::nos::snmp::mode::components'; $self->{components_module} = ['faultled', 'temperature']; } sub snmp_execute { my ($self, %options) = @_; - + $self->{snmp} = $options{snmp}; } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - + $options{options}->add_options(arguments => { }); @@ -79,6 +80,22 @@ Can be: 'faultled', 'temperature'. Return an error if no compenents are checked. If total (with skipped) is 0. (Default: 'critical' returns). +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='faulted,WARNING,on' + +=item B<--warning> + +Set warning threshold for temperatures (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,30' + +=item B<--critical> + +Set critical threshold for temperatures (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,40' + =back =cut diff --git a/centreon-plugins/network/ibm/bladecenter/snmp/mode/memory.pm b/centreon-plugins/centreon/common/ibm/nos/snmp/mode/memory.pm similarity index 82% rename from centreon-plugins/network/ibm/bladecenter/snmp/mode/memory.pm rename to centreon-plugins/centreon/common/ibm/nos/snmp/mode/memory.pm index 35c2279bd..fe9559cbc 100644 --- a/centreon-plugins/network/ibm/bladecenter/snmp/mode/memory.pm +++ b/centreon-plugins/centreon/common/ibm/nos/snmp/mode/memory.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::ibm::bladecenter::snmp::mode::memory; +package centreon::common::ibm::nos::snmp::mode::memory; use base qw(centreon::plugins::templates::counter); @@ -42,7 +42,7 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'memory', type => 0, skipped_code => { -10 => 1 } }, + { name => 'memory', type => 0, skipped_code => { -10 => 1 } } ]; $self->{maps_counters}->{memory} = [ @@ -50,35 +50,35 @@ sub set_counters { key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], closure_custom_output => $self->can('custom_usage_output'), perfdatas => [ - { label => 'used', value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', - unit => 'B', cast_int => 1 }, - ], + { value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1 } + ] } }, { label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => { key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], closure_custom_output => $self->can('custom_usage_output'), perfdatas => [ - { label => 'free', value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', - unit => 'B', cast_int => 1 }, - ], + { value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1 } + ] } }, { label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => { key_values => [ { name => 'prct_used' } ], - output_template => 'Used : %.2f %%', + output_template => 'Ram Used : %.2f %%', perfdatas => [ - { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, - unit => '%' }, - ], + { value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, + unit => '%' } + ] } - }, + } ]; } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; return $self; @@ -99,7 +99,7 @@ sub manage_selection { used => $total - $free, free => $free, prct_used => $prct_used, - prct_free => 100 - $prct_used, + prct_free => 100 - $prct_used } } diff --git a/centreon-plugins/network/ibm/bladecenter/snmp/mode/disk.pm b/centreon-plugins/network/ibm/bladecenter/snmp/mode/disk.pm deleted file mode 100644 index b8466a931..000000000 --- a/centreon-plugins/network/ibm/bladecenter/snmp/mode/disk.pm +++ /dev/null @@ -1,104 +0,0 @@ -# -# 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 network::ibm::bladecenter::snmp::mode::disk; - -use base qw(snmp_standard::mode::storage); - -use strict; -use warnings; - -sub default_storage_type { - my ($self, %options) = @_; - - return '^(?!(hrStorageRam)$)'; -} - -sub prefix_storage_output { - my ($self, %options) = @_; - - return "Disk '" . $options{instance_value}->{display} . "' "; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - return $self; -} - -1; - -__END__ - -=head1 MODE - -Check disk. - -=over 8 - -=item B<--warning-usage> - -Threshold warning. - -=item B<--critical-usage> - -Threshold critical. - -=item B<--units> - -Units of thresholds (Default: '%') ('%', 'B'). - -=item B<--free> - -Thresholds are on free space left. - -=item B<--storage> - -Set the storage (number expected) ex: 1, 2,... (empty means 'check all storage'). - -=item B<--name> - -Allows to use storage name with option --storage instead of storage oid index. - -=item B<--regexp> - -Allows to use regexp to filter storage (with option --name). - -=item B<--regexp-isensitive> - -Allows to use regexp non case-sensitive (with --regexp). - -=item B<--reload-cache-time> - -Time in minutes before reloading cache file (default: 180). - -=item B<--show-cache> - -Display cache storage datas. - -=item B<--filter-storage-type> - -Filter storage types with a regexp (Default: '^(?!(hrStorageRam)$)'). - -=back - -=cut diff --git a/centreon-plugins/network/ibm/bladecenter/snmp/plugin.pm b/centreon-plugins/network/ibm/bladecenter/snmp/plugin.pm index 4ec79937b..99f935054 100644 --- a/centreon-plugins/network/ibm/bladecenter/snmp/plugin.pm +++ b/centreon-plugins/network/ibm/bladecenter/snmp/plugin.pm @@ -30,16 +30,16 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - %{$self->{modes}} = ( - 'cpu' => 'network::ibm::bladecenter::snmp::mode::cpu', - 'disk' => 'network::ibm::bladecenter::snmp::mode::disk', - 'environment' => 'network::ibm::bladecenter::snmp::mode::environment', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::ibm::bladecenter::snmp::mode::memory', - 'time' => 'snmp_standard::mode::ntp', - 'uptime' => 'snmp_standard::mode::uptime', - ); + $self->{modes} = { + 'cpu' => 'centreon::common::ibm::nos::snmp::mode::cpu', + 'disk' => 'centreon::common::ibm::nos::snmp::mode::disk', + 'environment' => 'centreon::common::ibm::nos::snmp::mode::environment', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'centreon::common::ibm::nos::snmp::mode::memory', + 'time' => 'snmp_standard::mode::ntp', + 'uptime' => 'snmp_standard::mode::uptime' + }; return $self; } diff --git a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/faultled.pm b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/faultled.pm index b987d1162..d7635308a 100644 --- a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/faultled.pm +++ b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/faultled.pm @@ -31,7 +31,7 @@ sub check_faultled { my ($self, %options) = @_; $self->{components}->{faultled}->{total}++; - + $self->{output}->output_add(long_msg => sprintf( "Fault LED state is %s", @@ -52,13 +52,14 @@ sub check_faultled { sub check { my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking fault LED"); + + $self->{output}->output_add(long_msg => 'checking fault LED'); $self->{components}->{faultled} = { name => 'faultled', total => 0, skip => 0 }; return if ($self->check_filter(section => 'faultled')); my $oid_mmspFaultLED = '.1.3.6.1.4.1.20301.2.5.1.3.10.12.0'; - my $results = $self->{snmp}->get_leef(oids => [$oid_mmspFaultLED], nothing_quit => 1); + my $results = $self->{snmp}->get_leef(oids => [$oid_mmspFaultLED]); + return if (!defined($results->{$oid_mmspFaultLED})); check_faultled($self, value => $map_faultled_states{$results->{$oid_mmspFaultLED}}); } diff --git a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/temperature.pm b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/temperature.pm index 3fb804d38..76bc6ca46 100644 --- a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/temperature.pm +++ b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/temperature.pm @@ -23,64 +23,85 @@ package network::lenovo::flexsystem::snmp::mode::components::temperature; use strict; use warnings; -sub load {} +my $mapping = { + hwInfoTemperatureWarn => { oid => '.1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1.20' }, # "44 C (Warning at 66 C / Recover at 61 C)" + hwInfoTemperatureShut => { oid => '.1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1.21' }, # "44 C (Shutdown at 72 C / Recover at 67 C)" +}; +my $oid_hwInfoTableEntry = '.1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { + oid => $oid_hwInfoTableEntry, + start => $mapping->{hwInfoTemperatureWarn}->{oid}, + end => $mapping->{hwInfoTemperatureShut}->{oid} + }; +} sub check { my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking temperatures"); + + $self->{output}->output_add(long_msg => "checking temperatures"); $self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 }; return if ($self->check_filter(section => 'temperature')); - my $oid_hwTemperatureWarn = '.1.3.6.1.4.1.20301.2.5.1.3.1.22.0'; - my $oid_hwTemperatureShut = '.1.3.6.1.4.1.20301.2.5.1.3.1.23.0'; - my $results = $self->{snmp}->get_leef(oids => [$oid_hwTemperatureWarn, $oid_hwTemperatureShut], nothing_quit => 1); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_hwInfoTableEntry}})) { + next if ($oid !~ /^$mapping->{hwInfoTemperatureShut}->{oid}\.(\d+)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_hwInfoTableEntry}, instance => $instance); - # .1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1.20.1 = STRING: "44 C (Warning at 66 C / Recover at 61 C)" - # .1.3.6.1.4.1.20301.2.5.1.3.1.41.1.1.21.1 = STRING: "44 C (Shutdown at 72 C / Recover at 67 C)" - $results->{$oid_hwTemperatureWarn} =~ /^([.0-9]+)\s*C\s*\(Warn(?:ing)?\s*at\s*([.0-9]+)\s*C/i; - my $temperature = $1; - my $warning = $2; - $results->{$oid_hwTemperatureShut} =~ /^([.0-9]+)\s*C\s*\(Shutdown\s*at\s*([.0-9]+)\s*C/i; - if ($1 > $temperature) { - $temperature = $1; - } - my $critical = ($warning + $2) / 2; + next if ($self->check_filter(section => 'temperature', instance => $instance)); + $self->{components}->{temperature}->{total}++; - $self->{components}->{temperature}->{total}++; - - $self->{output}->output_add(long_msg => - sprintf( - "Temperature is %.1f C", - $temperature - ) - ); + $result->{hwInfoTemperatureWarn} =~ /^([.0-9]+)\s*C\s*\(Warn(?:ing)?\s*at\s*([.0-9]+)\s*C/i; + my ($temperature, $warning_mib) = ($1, $2); + $result->{hwInfoTemperatureShut} =~ /^([.0-9]+)\s*C\s*\(Shutdown\s*at\s*([.0-9]+)\s*C/i; + $temperature = $1 if ($1 > $temperature); + my $critical_mib = ($warning_mib + $2) / 2; - my $exit = 'OK'; - if ($temperature >= $warning) { - $exit = 'WARNING'; - } - if ($temperature >= $critical) { - $exit = 'CRITICAL'; - } - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add( - severity => $exit, - short_msg => sprintf( - "Temperature is %.1f C", - $temperature + long_msg => sprintf( + "temperature switch '%s' is %s C [instance: %s]", + $instance, + $temperature, + $instance ) ); - } - $self->{output}->perfdata_add( - label => 'temperature', unit => 'C', - nlabel => 'hardware.temperature.celsius', - instances => 'system', - value => $temperature, - warning => $warning, - critical => $critical - ); + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $temperature); + if ($checked == 0) { + $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warning_mib); + $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $critical_mib); + $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance); + $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance); + $exit = $self->{perfdata}->threshold_check( + value => $temperature, + threshold => [ + { label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' }, + { label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' } + ] + ); + } + + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "temperature switch '%s' is %s C", + $instance, + $temperature + ) + ); + } + $self->{output}->perfdata_add( + nlabel => 'hardware.temperature.celsius', unit => 'C', + instances => 'switch=' . $instance, + value => $temperature, + warning => $warn, + critical => $crit + ); + } } 1; diff --git a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/cpu.pm b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/cpu.pm index c17707bcb..c297f0eb3 100644 --- a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/cpu.pm +++ b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/cpu.pm @@ -29,73 +29,80 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'cpu', type => 1, cb_prefix_output => 'prefix_message_output', message_multiple => 'All CPU usages are ok' }, + { name => 'cpu', type => 1, cb_prefix_output => 'prefix_message_output', message_multiple => 'All CPU usages are ok' } ]; $self->{maps_counters}->{cpu} = [ - { label => 'average', nlabel => 'cpu.utilization.percentage', set => { - key_values => [ { name => 'average' }, { name => 'display' } ], - output_template => '%.2f %%', + { label => 'average-1min', nlabel => 'switch.cpu.utilization.1min.percentage', set => { + key_values => [ { name => 'average_1min' }, { name => 'display' } ], + output_template => '%.2f %% (1min)', perfdatas => [ - { label => 'total_cpu_avg', value => 'average_absolute', template => '%.2f', - min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + { value => 'average_1min_absolute', template => '%.2f', + min => 0, max => 100, unit => '%', label_extra_instance => 1 } + ] } }, + { label => 'average-5min', nlabel => 'switch.cpu.utilization.5min.percentage', set => { + key_values => [ { name => 'average_5min' }, { name => 'display' } ], + output_template => '%.2f %% (5min)', + perfdatas => [ + { value => 'average_5min_absolute', template => '%.2f', + min => 0, max => 100, unit => '%', label_extra_instance => 1 } + ] + } + } ]; } sub prefix_message_output { my ($self, %options) = @_; - return "Switch '" . $options{instance_value}->{display} . "' "; + return "Switch '" . $options{instance_value}->{display} . "' CPU average usage: "; } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { - 'filter:s' => { name => 'filter', default => '.*' } + 'filter-switch-num:s' => { name => 'filter_switch_num' } }); return $self; } +my $mapping = { + average_1min => { oid => '.1.3.6.1.4.1.20301.2.5.1.2.2.12.1.1.5' }, # mpCpuStatsUtil1MinuteSwRev + average_5min => { oid => '.1.3.6.1.4.1.20301.2.5.1.2.2.12.1.1.6' } # mpCpuStatsUtil5MinutesSwRev +}; + +my $oid_mpCpuStatsRevTableEntry = '.1.3.6.1.4.1.20301.2.5.1.2.2.12.1.1'; + sub manage_selection { my ($self, %options) = @_; - my $oid_mpCpuSwitchNumberRev = '.1.3.6.1.4.1.20301.2.5.1.2.2.12.1.1.1'; - my $oid_mpCpuStatsUtil1MinuteSwRev = '.1.3.6.1.4.1.20301.2.5.1.2.2.12.1.1.5'; - - my $result = $options{snmp}->get_table(oid => $oid_mpCpuSwitchNumberRev, nothing_quit => 1); - my @instance_oids = (); - foreach my $oid (keys %$result) { - if ($result->{$oid} =~ /$self->{option_results}->{filter}/i) { - push @instance_oids, $oid; - } - } - - if (scalar(@instance_oids) == 0) { - $self->{output}->add_option_msg(short_msg => "Cannot find switch number '$self->{option_results}->{filter}'."); - $self->{output}->option_exit(); - } - - $options{snmp}->load( - oids => [$oid_mpCpuStatsUtil1MinuteSwRev], - instances => \@instance_oids, - instance_regexp => "^" . $oid_mpCpuSwitchNumberRev . '\.(.+)' + my $snmp_result = $options{snmp}->get_table( + oid => $oid_mpCpuStatsRevTableEntry, + start => $mapping->{average_1min}->{oid}, + nothing_quit => 1 ); - my $result2 = $options{snmp}->get_leef(); - foreach my $instance (@instance_oids) { - $instance =~ /^$oid_mpCpuSwitchNumberRev\.(.+)/; - $instance = $1; - + $self->{cpu} = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{average_1min}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + if (defined($self->{option_results}->{filter_switch_num}) && $self->{option_results}->{filter_switch_num} ne '' && + $instance !~ /$self->{option_results}->{filter_switch_num}/) { + $self->{output}->output_add(long_msg => "skipping member '" . $instance . "': no matching filter.", debug => 1); + next; + } + $self->{cpu}->{$instance} = { - display => $result->{$oid_mpCpuSwitchNumberRev . '.' . $instance}, - average => $result2->{$oid_mpCpuStatsUtil1MinuteSwRev . '.' . $instance}, + display => $instance, + %$result }; } } @@ -110,17 +117,14 @@ Check CPU usage (over the last minute). =over 8 -=item B<--filter> +=item B<--filter-switch-num> -Filter switch number (Default: '.*'). +Filter switch number. -=item B<--warning-average> +=item B<--warning-*> B<--critical-*> -Warning threshold average CPU utilization. - -=item B<--critical-average> - -Critical threshold average CPU utilization. +Thresholds. +Can be: 'average-1min' (%), 'average-5min' (%). =back diff --git a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/environment.pm b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/environment.pm index 632d32a71..ff39352e7 100644 --- a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/environment.pm +++ b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/environment.pm @@ -27,15 +27,16 @@ use warnings; sub set_system { my ($self, %options) = @_; - - $self->{regexp_threshold_overload_check_section_option} = '^(faultled|temperature)$'; + + $self->{regexp_threshold_overload_check_section_option} = '^(?:faultled)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(?:temperature)$'; $self->{cb_hook2} = 'snmp_execute'; $self->{thresholds} = { 'faultled' => [ ['on', 'CRITICAL'], - ['off', 'OK'], - ], + ['off', 'OK'] + ] }; $self->{components_path} = 'network::lenovo::flexsystem::snmp::mode::components'; @@ -46,11 +47,12 @@ sub snmp_execute { my ($self, %options) = @_; $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { @@ -79,6 +81,22 @@ Can be: 'faultled', 'temperature'. Return an error if no compenents are checked. If total (with skipped) is 0. (Default: 'critical' returns). +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='faulted,WARNING,on' + +=item B<--warning> + +Set warning threshold for temperatures (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,30' + +=item B<--critical> + +Set critical threshold for temperatures (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,40' + =back =cut diff --git a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/memory.pm b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/memory.pm index 232a2c98e..c3eae2c60 100644 --- a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/memory.pm +++ b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/memory.pm @@ -46,33 +46,33 @@ sub set_counters { ]; $self->{maps_counters}->{memory} = [ - { label => 'usage', nlabel => 'memory.usage.bytes', set => { + { label => 'usage', nlabel => 'switch.memory.usage.bytes', set => { key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], closure_custom_output => $self->can('custom_usage_output'), perfdatas => [ - { label => 'used', value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', - unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + { value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1 } + ] } }, - { label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => { - key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + { label => 'usage-free', display_ok => 0, nlabel => 'switch.memory.free.bytes', set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], closure_custom_output => $self->can('custom_usage_output'), perfdatas => [ - { label => 'free', value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', - unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + { value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1 } + ] } }, - { label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => { - key_values => [ { name => 'prct_used' } ], - output_template => 'Used : %.2f %%', + { label => 'usage-prct', display_ok => 0, nlabel => 'switch.memory.usage.percentage', set => { + key_values => [ { name => 'prct_used' }, { name => 'display' } ], + output_template => 'Ram Used : %.2f %%', perfdatas => [ - { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, - unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + { value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1 } + ] } - }, + } ]; } @@ -84,57 +84,52 @@ sub prefix_message_output { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { - 'filter:s' => { name => 'filter', default => '.*' } + 'filter-switch-num:s' => { name => 'filter_switch_num' } }); return $self; } +my $mapping = { + total => { oid => '.1.3.6.1.4.1.20301.2.5.1.2.12.9.1.1.3' }, # totalMemoryStatsRev + free => { oid => '.1.3.6.1.4.1.20301.2.5.1.2.12.9.1.1.4' } # memoryFreeStatsRev +}; + +my $oid_memoryStatsEntry = '.1.3.6.1.4.1.20301.2.5.1.2.12.9.1.1'; + sub manage_selection { my ($self, %options) = @_; - my $oid_switchNumber = '.1.3.6.1.4.1.20301.2.5.1.2.12.9.1.1.1'; - my $oid_totalMemoryStatsRev = '.1.3.6.1.4.1.20301.2.5.1.2.12.9.1.1.3'; # in bytes - my $oid_memoryFreeStatsRev = '.1.3.6.1.4.1.20301.2.5.1.2.12.9.1.1.4'; # in bytes - - my $result = $options{snmp}->get_table(oid => $oid_switchNumber, nothing_quit => 1); - my @instance_oids = (); - foreach my $oid (keys %$result) { - if ($result->{$oid} =~ /$self->{option_results}->{filter}/i) { - push @instance_oids, $oid; - } - } - - if (scalar(@instance_oids) == 0) { - $self->{output}->add_option_msg(short_msg => "Cannot find switch number '$self->{option_results}->{filter}'."); - $self->{output}->option_exit(); - } - - $options{snmp}->load( - oids => [$oid_totalMemoryStatsRev, $oid_memoryFreeStatsRev], - instances => \@instance_oids, - instance_regexp => "^" . $oid_switchNumber . '\.(.+)' + my $snmp_result = $options{snmp}->get_table( + oid => $oid_memoryStatsEntry, + start => $mapping->{total}->{oid}, + end => $mapping->{free}->{oid}, + nothing_quit => 1 ); - my $result2 = $options{snmp}->get_leef(); - foreach my $instance (@instance_oids) { - $instance =~ /^$oid_switchNumber\.(.+)/; - $instance = $1; + $self->{memory} = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{free}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); - my $free = $result2->{$oid_memoryFreeStatsRev . '.' . $instance}; - my $total = $result2->{$oid_totalMemoryStatsRev . '.' . $instance}; - my $prct_used = ($total - $free) * 100 / $total; + if (defined($self->{option_results}->{filter_switch_num}) && $self->{option_results}->{filter_switch_num} ne '' && + $instance !~ /$self->{option_results}->{filter_switch_num}/) { + $self->{output}->output_add(long_msg => "skipping member '" . $instance . "': no matching filter.", debug => 1); + next; + } + + my $prct_used = ($result->{total} - $result->{free}) * 100 / $result->{total}; $self->{memory}->{$instance} = { - display => $result->{$oid_switchNumber . '.' . $instance}, - total => $total, - used => $total - $free, - free => $free, + display => $instance, prct_used => $prct_used, prct_free => 100 - $prct_used, + used => $result->{total} - $result->{free}, + %$result }; } } @@ -149,9 +144,9 @@ Check memory usage. =over 8 -=item B<--filter> +=item B<--filter-switch-num> -Filter switch number (Default: '.*'). +Filter switch number. =item B<--warning-*> B<--critical-*> diff --git a/centreon-plugins/network/lenovo/flexsystem/snmp/plugin.pm b/centreon-plugins/network/lenovo/flexsystem/snmp/plugin.pm index 15dfa65b6..e8a4cbf1b 100644 --- a/centreon-plugins/network/lenovo/flexsystem/snmp/plugin.pm +++ b/centreon-plugins/network/lenovo/flexsystem/snmp/plugin.pm @@ -31,14 +31,14 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::lenovo::flexsystem::snmp::mode::cpu', - 'disk' => 'network::lenovo::flexsystem::snmp::mode::disk', - 'environment' => 'network::lenovo::flexsystem::snmp::mode::environment', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::lenovo::flexsystem::snmp::mode::memory', - 'time' => 'snmp_standard::mode::ntp', - 'uptime' => 'snmp_standard::mode::uptime', + 'cpu' => 'network::lenovo::flexsystem::snmp::mode::cpu', + 'disk' => 'centreon::common::ibm::nos::snmp::mode::disk', + 'environment' => 'network::lenovo::flexsystem::snmp::mode::environment', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::lenovo::flexsystem::snmp::mode::memory', + 'time' => 'snmp_standard::mode::ntp', + 'uptime' => 'snmp_standard::mode::uptime', ); return $self; From 1868c35d8b6dc833e00b8fe293ca7e18c2472bec Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 10 Apr 2020 14:56:38 +0200 Subject: [PATCH 080/190] small indent fix --- .../cloud/aws/vpn/mode/listvpn.pm | 6 +++-- .../cloud/aws/vpn/mode/traffic.pm | 23 +++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/centreon-plugins/cloud/aws/vpn/mode/listvpn.pm b/centreon-plugins/cloud/aws/vpn/mode/listvpn.pm index 6cb8eb17d..6499d94e9 100644 --- a/centreon-plugins/cloud/aws/vpn/mode/listvpn.pm +++ b/centreon-plugins/cloud/aws/vpn/mode/listvpn.pm @@ -56,8 +56,10 @@ sub run { $_->{id}, $_->{name}, $_->{state} )); } - $self->{output}->output_add(severity => 'OK', - short_msg => 'List VPN connections:'); + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List VPN connections:' + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } diff --git a/centreon-plugins/cloud/aws/vpn/mode/traffic.pm b/centreon-plugins/cloud/aws/vpn/mode/traffic.pm index d23cd5552..7e8e458d9 100644 --- a/centreon-plugins/cloud/aws/vpn/mode/traffic.pm +++ b/centreon-plugins/cloud/aws/vpn/mode/traffic.pm @@ -29,8 +29,7 @@ my %metrics_mapping = ( 'TunnelState' => { 'output' => 'Tunnel State', 'label' => 'tunnel-state', - 'nlabel' => { - 'absolute' => 'vpn.tunnel.tunnelstate'}, + 'nlabel' => { 'absolute' => 'vpn.tunnel.tunnelstate' }, 'unit' => '' }, 'TunnelDataIn' => { @@ -38,7 +37,7 @@ my %metrics_mapping = ( 'label' => 'tunnel-datain', 'nlabel' => { 'absolute' => 'vpn.tunnel.datain.bytes', - 'per_second' => 'vpn.tunnel.datain.bytespersecond', + 'per_second' => 'vpn.tunnel.datain.bytespersecond' }, 'unit' => 'B' }, @@ -47,7 +46,7 @@ my %metrics_mapping = ( 'label' => 'tunnel-dataout', 'nlabel' => { 'absolute' => 'vpn.tunnel.dataout.bytes', - 'per_second' => 'vpn.tunnel.dataout.bytespersecond', + 'per_second' => 'vpn.tunnel.dataout.bytespersecond' }, 'unit' => 'B' } @@ -79,8 +78,10 @@ sub custom_metric_threshold { 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-' . $metrics_mapping{$self->{result_values}->{metric}}->{label} , exit_litteral => 'critical' }, - { label => 'warning-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'warning' } ] + threshold => [ + { label => 'critical-' . $metrics_mapping{$self->{result_values}->{metric}}->{label} , exit_litteral => 'critical' }, + { label => 'warning-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'warning' } + ] ); return $exit; } @@ -139,11 +140,9 @@ sub custom_metric_output { sub custom_metric_output_state { my ($self, %options) = @_; - my $msg = ""; my $value = $self->{result_values}->{value}; - $msg = sprintf("%s: %.2f", $metrics_mapping{$self->{result_values}->{metric}}->{output}, $value); - return $msg; + return sprintf("%s: %.2f", $metrics_mapping{$self->{result_values}->{metric}}->{output}, $value); } sub prefix_metric_output { @@ -199,9 +198,9 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'vpnid:s@' => { name => 'vpn_id' }, - 'per-sec' => { name => 'per_sec' }, - 'filter-metric:s' => { name => 'filter_metric' } + 'vpnid:s@' => { name => 'vpn_id' }, + 'per-sec' => { name => 'per_sec' }, + 'filter-metric:s' => { name => 'filter_metric' } }); return $self; From 0e41499df6eb5c18f78bfbc9228fad188890295c Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 10 Apr 2020 15:06:55 +0200 Subject: [PATCH 081/190] add --only-show-errors for azure cli --- centreon-plugins/cloud/azure/custom/azcli.pm | 76 +++++++++++--------- 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/centreon-plugins/cloud/azure/custom/azcli.pm b/centreon-plugins/cloud/azure/custom/azcli.pm index 5ae02540e..81dde133d 100644 --- a/centreon-plugins/cloud/azure/custom/azcli.pm +++ b/centreon-plugins/cloud/azure/custom/azcli.pm @@ -41,20 +41,20 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - "subscription:s" => { name => 'subscription' }, - "tenant:s" => { name => 'tenant' }, - "client-id:s" => { name => 'client_id' }, - "client-secret:s" => { name => 'client_secret' }, - "timeframe:s" => { name => 'timeframe' }, - "interval:s" => { name => 'interval' }, - "aggregation:s@" => { name => 'aggregation' }, - "zeroed" => { name => 'zeroed' }, - "timeout:s" => { name => 'timeout', default => 50 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'az' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '' }, - "proxyurl:s" => { name => 'proxyurl' }, + 'subscription:s' => { name => 'subscription' }, + 'tenant:s' => { name => 'tenant' }, + 'client-id:s' => { name => 'client_id' }, + 'client-secret:s' => { name => 'client_secret' }, + 'timeframe:s' => { name => 'timeframe' }, + 'interval:s' => { name => 'interval' }, + 'aggregation:s@' => { name => 'aggregation' }, + 'zeroed' => { name => 'zeroed' }, + 'timeout:s' => { name => 'timeout', default => 50 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'az' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '' }, + 'proxyurl:s' => { name => 'proxyurl' }, }); } $options{options}->add_help(package => __PACKAGE__, sections => 'AZCLI OPTIONS', once => 1); @@ -141,15 +141,21 @@ sub convert_duration { my $duration; if ($options{time_string} =~ /^P.*S$/) { - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'DateTime::Format::Duration::ISO8601', - error_msg => "Cannot load module 'DateTime::Format::Duration::ISO8601'."); + centreon::plugins::misc::mymodule_load( + output => $self->{output}, + module => 'DateTime::Format::Duration::ISO8601', + error_msg => "Cannot load module 'DateTime::Format::Duration::ISO8601'." + ); my $format = DateTime::Format::Duration::ISO8601->new; my $d = $format->parse_duration($options{time_string}); $duration = $d->minutes * 60 + $d->seconds; } elsif ($options{time_string} =~ /^(\d+):(\d+):(\d+)\.\d+$/) { - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'DateTime::Duration', - error_msg => "Cannot load module 'DateTime::Format::Duration'."); + centreon::plugins::misc::mymodule_load( + output => $self->{output}, + module => 'DateTime::Duration', + error_msg => "Cannot load module 'DateTime::Format::Duration'." + ); my $d = DateTime::Duration->new(hours => $1, minutes => $2, seconds => $3); $duration = $d->minutes * 60 + $d->seconds; @@ -162,9 +168,9 @@ sub azure_get_metrics_set_cmd { my ($self, %options) = @_; return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - + my $cmd_options = "monitor metrics list --metrics '" . join('\' \'', @{$options{metrics}}) . "' --start-time $options{start_time} --end-time $options{end_time} " . - "--interval $options{interval} --aggregation '" . join('\' \'', @{$options{aggregations}}) . "' --output json --resource '$options{resource}' " . + "--interval $options{interval} --aggregation '" . join('\' \'', @{$options{aggregations}}) . "' --only-show-errors --output json --resource '$options{resource}' " . "--resource-group '$options{resource_group}' --resource-type '$options{resource_type}' --resource-namespace '$options{resource_namespace}'"; $cmd_options .= " --subscription '$self->{subscription}'" if (defined($self->{subscription}) && $self->{subscription} ne ''); @@ -222,7 +228,7 @@ sub azure_list_resources_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "resource list --output json"; + my $cmd_options = "resource list --only-show-errors --output json"; $cmd_options .= " --namespace '$options{namespace}'" if (defined($options{namespace}) && $options{namespace} ne ''); $cmd_options .= " --resource-type '$options{resource_type}'" if (defined($options{resource_type}) && $options{resource_type} ne ''); $cmd_options .= " --location '$options{location}'" if (defined($options{location}) && $options{location} ne ''); @@ -246,7 +252,7 @@ sub azure_list_vm_sizes_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "vm list-sizes --location '$options{location}' --output json"; + my $cmd_options = "vm list-sizes --location '$options{location}' --only-show-errors --output json"; $cmd_options .= " --subscription '$self->{subscription}'" if (defined($self->{subscription}) && $self->{subscription} ne ''); return $cmd_options; @@ -266,7 +272,7 @@ sub azure_list_vms_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "vm list --output json"; + my $cmd_options = "vm list --only-show-errors --output json"; $cmd_options .= " --resource-group '$options{resource_group}'" if (defined($options{resource_group}) && $options{resource_group} ne ''); $cmd_options .= " --show-details" if (defined($options{show_details})); $cmd_options .= " --subscription '$self->{subscription}'" if (defined($self->{subscription}) && $self->{subscription} ne ''); @@ -288,7 +294,7 @@ sub azure_list_groups_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "group list --output json"; + my $cmd_options = "group list --only-show-errors --output json"; $cmd_options .= " --subscription '$self->{subscription}'" if (defined($self->{subscription}) && $self->{subscription} ne ''); return $cmd_options; @@ -308,7 +314,7 @@ sub azure_list_deployments_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "group deployment list --resource-group '$options{resource_group}' --output json"; + my $cmd_options = "group deployment list --resource-group '$options{resource_group}' --only-show-errors --output json"; $cmd_options .= " --subscription '$self->{subscription}'" if (defined($self->{subscription}) && $self->{subscription} ne ''); return $cmd_options; @@ -328,7 +334,7 @@ sub azure_list_vaults_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "backup vault list --output json"; + my $cmd_options = "backup vault list --only-show-errors --output json"; $cmd_options .= " --resource-group '$options{resource_group}'" if (defined($options{resource_group}) && $options{resource_group} ne ''); $cmd_options .= " --subscription '$self->{subscription}'" if (defined($self->{subscription}) && $self->{subscription} ne ''); @@ -349,7 +355,7 @@ sub azure_list_backup_jobs_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "backup job list --resource-group '$options{resource_group}' --vault-name '$options{vault_name}' --output json"; + my $cmd_options = "backup job list --resource-group '$options{resource_group}' --vault-name '$options{vault_name}' --only-show-errors --output json"; $cmd_options .= " --subscription '$self->{subscription}'" if (defined($self->{subscription}) && $self->{subscription} ne ''); return $cmd_options; @@ -369,7 +375,7 @@ sub azure_list_backup_items_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "backup item list --resource-group '$options{resource_group}' --vault-name '$options{vault_name}' --output json"; + my $cmd_options = "backup item list --resource-group '$options{resource_group}' --vault-name '$options{vault_name}' --only-show-errors --output json"; $cmd_options .= " --subscription '$self->{subscription}'" if (defined($self->{subscription}) && $self->{subscription} ne ''); return $cmd_options; @@ -389,7 +395,7 @@ sub azure_list_expressroute_circuits_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "network express-route list --output json"; + my $cmd_options = "network express-route list --only-show-errors --output json"; $cmd_options .= " --resource-group '$options{resource_group}'" if (defined($options{resource_group}) && $options{resource_group} ne ''); $cmd_options .= " --subscription '$self->{subscription}'" if (defined($self->{subscription}) && $self->{subscription} ne ''); @@ -410,7 +416,7 @@ sub azure_list_vpn_gateways_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "network vnet-gateway list --resource-group '$options{resource_group}' --output json"; + my $cmd_options = "network vnet-gateway list --resource-group '$options{resource_group}' --only-show-errors --output json"; $cmd_options .= " --subscription '$self->{subscription}'" if (defined($self->{subscription}) && $self->{subscription} ne ''); return $cmd_options; @@ -430,7 +436,7 @@ sub azure_list_virtualnetworks_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "network vnet list --output json"; + my $cmd_options = "network vnet list --only-show-errors --output json"; $cmd_options .= " --resource-group '$options{resource_group}'" if (defined($options{resource_group}) && $options{resource_group} ne ''); $cmd_options .= " --subscription '$self->{subscription}'" if (defined($self->{subscription}) && $self->{subscription} ne ''); @@ -451,7 +457,7 @@ sub azure_list_vnet_peerings_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "network vnet peering list --resource-group '$options{resource_group}' --vnet-name '$options{vnet_name}' --output json"; + my $cmd_options = "network vnet peering list --resource-group '$options{resource_group}' --vnet-name '$options{vnet_name}' --only-show-errors --output json"; $cmd_options .= " --subscription '$self->{subscription}'" if (defined($self->{subscription}) && $self->{subscription} ne ''); return $cmd_options; @@ -471,7 +477,7 @@ sub azure_list_sqlservers_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "sql server list --output json"; + my $cmd_options = "sql server list --only-show-errors --output json"; $cmd_options .= " --resource-group '$options{resource_group}'" if (defined($options{resource_group}) && $options{resource_group} ne ''); $cmd_options .= " --subscription '$self->{subscription}'" if (defined($self->{subscription}) && $self->{subscription} ne ''); @@ -492,7 +498,7 @@ sub azure_list_sqldatabases_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "sql db list --resource-group '$options{resource_group}' --server '$options{server}' --output json"; + my $cmd_options = "sql db list --resource-group '$options{resource_group}' --server '$options{server}' --only-show-errors --output json"; $cmd_options .= " --subscription '$self->{subscription}'" if (defined($self->{subscription}) && $self->{subscription} ne ''); return $cmd_options; @@ -512,7 +518,7 @@ sub azure_get_log_analytics_set_cmd { return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - my $cmd_options = "monitor log-analytics query --workspace '$options{workspace_id}' --analytics-query \"$options{query}\" --timespan '$options{interval}'"; + my $cmd_options = "monitor log-analytics query --workspace '$options{workspace_id}' --analytics-query \"$options{query}\" --timespan '$options{interval}' --only-show-errors"; return $cmd_options; } From 54a90b4b78adf2fd0ab17bbed55b7bb1bfff3841 Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Fri, 10 Apr 2020 15:23:50 +0200 Subject: [PATCH 082/190] Add NOS 5m CPU --- .../centreon/common/ibm/nos/snmp/mode/cpu.pm | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/centreon-plugins/centreon/common/ibm/nos/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/ibm/nos/snmp/mode/cpu.pm index 4363afd0b..5a8990d66 100644 --- a/centreon-plugins/centreon/common/ibm/nos/snmp/mode/cpu.pm +++ b/centreon-plugins/centreon/common/ibm/nos/snmp/mode/cpu.pm @@ -29,22 +29,37 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'cpu', type => 0, skipped_code => { -10 => 1 } } + { name => 'cpu', type => 0, cb_prefix_output => 'prefix_message_output', skipped_code => { -10 => 1 } } ]; $self->{maps_counters}->{cpu} = [ { label => 'average-1m', nlabel => 'cpu.utilization.1m.percentage', set => { key_values => [ { name => 'average_1m' } ], - output_template => 'CPU(s) average usage: %.2f %% (1min)', + output_template => '%.2f %% (1min)', perfdatas => [ { value => 'average_1m_absolute', template => '%.2f', min => 0, max => 100, unit => '%' } ] } + }, + { label => 'average-5m', nlabel => 'cpu.utilization.5m.percentage', set => { + key_values => [ { name => 'average_5m' } ], + output_template => '%.2f %% (5min)', + perfdatas => [ + { value => 'average_5m_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' } + ] + } } ]; } +sub prefix_message_output { + my ($self, %options) = @_; + + return "CPU average usage: "; +} + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); @@ -57,10 +72,12 @@ sub manage_selection { my ($self, %options) = @_; my $oid_mpCpuStatsUtil1Minute = '.1.3.6.1.4.1.26543.2.5.1.2.2.3.0'; - my $result = $options{snmp}->get_leef(oids => [$oid_mpCpuStatsUtil1Minute], nothing_quit => 1); + my $oid_mpCpuStatsUtil5Minutes = '.1.3.6.1.4.1.26543.2.5.1.2.2.6.0'; + my $result = $options{snmp}->get_leef(oids => [$oid_mpCpuStatsUtil1Minute, $oid_mpCpuStatsUtil5Minutes], nothing_quit => 1); $self->{cpu} = { average_1m => $result->{$oid_mpCpuStatsUtil1Minute} + average_5m => $result->{$oid_mpCpuStatsUtil5Minutes} } } @@ -74,13 +91,10 @@ Check CPU usage (over the last minute). =over 8 -=item B<--warning-average-1m> +=item B<--warning-*> B<--critical-*> -Warning threshold average CPU utilization. - -=item B<--critical-average-1m> - -Critical threshold average CPU utilization. +Thresholds. +Can be: 'average-1min' (%), 'average-5min' (%). =back From f227de3592407255b52069a2ac4fe4f82ba1bdf5 Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Fri, 10 Apr 2020 15:26:40 +0200 Subject: [PATCH 083/190] Typo --- centreon-plugins/centreon/common/ibm/nos/snmp/mode/cpu.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/centreon/common/ibm/nos/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/ibm/nos/snmp/mode/cpu.pm index 5a8990d66..786883678 100644 --- a/centreon-plugins/centreon/common/ibm/nos/snmp/mode/cpu.pm +++ b/centreon-plugins/centreon/common/ibm/nos/snmp/mode/cpu.pm @@ -76,7 +76,7 @@ sub manage_selection { my $result = $options{snmp}->get_leef(oids => [$oid_mpCpuStatsUtil1Minute, $oid_mpCpuStatsUtil5Minutes], nothing_quit => 1); $self->{cpu} = { - average_1m => $result->{$oid_mpCpuStatsUtil1Minute} + average_1m => $result->{$oid_mpCpuStatsUtil1Minute}, average_5m => $result->{$oid_mpCpuStatsUtil5Minutes} } } From 9d95b8de479982d2cb8b9ae6f1e325e2a2fa43fe Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 13 Apr 2020 18:02:59 +0200 Subject: [PATCH 084/190] enhance saleforce --- .../apps/salesforce/restapi/custom/api.pm | 19 ++++++++------ .../salesforce/restapi/mode/sfdcinstance.pm | 25 +++++++++++-------- .../apps/salesforce/restapi/plugin.pm | 2 +- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/centreon-plugins/apps/salesforce/restapi/custom/api.pm b/centreon-plugins/apps/salesforce/restapi/custom/api.pm index f70c32fc9..5ee420c07 100644 --- a/centreon-plugins/apps/salesforce/restapi/custom/api.pm +++ b/centreon-plugins/apps/salesforce/restapi/custom/api.pm @@ -41,9 +41,9 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "timeout:s" => { name => 'timeout' }, - "api-versions:s" => { name => 'api_version' }, + 'hostname:s' => { name => 'hostname' }, + 'timeout:s' => { name => 'timeout' }, + 'api-versions:s' => { name => 'api_version' } }); } $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); @@ -110,20 +110,24 @@ sub request_api { $self->settings(); - my $content = $self->{http}->request(method => 'GET', url_path => '/' . $self->{api_version} . $options{path}, - critical_status => '', warning_status => '', unknown_status => ''); + my $content = $self->{http}->request( + method => 'GET', + url_path => '/' . $self->{api_version} . $options{path}, + critical_status => '', + warning_status => '', + unknown_status => '' + ); my $decoded; eval { $decoded = decode_json($content); }; if ($@) { - $self->{output}->output_add(long_msg => $content, debug => 1); $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); $self->{output}->option_exit(); } if ($self->{http}->get_code() != 200) { - $self->{output}->add_option_msg(short_msg => "Connection issue: " . $decoded->{msg}); + $self->{output}->add_option_msg(short_msg => "Connection issue: " . $decoded->{message}); $self->{output}->option_exit(); } @@ -165,4 +169,3 @@ API base url path (Default: '/v1'). B. =cut - diff --git a/centreon-plugins/apps/salesforce/restapi/mode/sfdcinstance.pm b/centreon-plugins/apps/salesforce/restapi/mode/sfdcinstance.pm index ac941ada3..33ceafcc1 100644 --- a/centreon-plugins/apps/salesforce/restapi/mode/sfdcinstance.pm +++ b/centreon-plugins/apps/salesforce/restapi/mode/sfdcinstance.pm @@ -30,21 +30,26 @@ sub custom_status_output { my ($self, %options) = @_; return sprintf( - "Salesforce '%s' instance status is '%s' (active:'%s') ", - $self->{result_values}->{name}, + "status is '%s' (active:'%s') ", $self->{result_values}->{status}, $self->{result_values}->{active} ); } +sub prefix_volume_output { + my ($self, %options) = @_; + + return "Salesforce '" . $options{instance_value}->{name} . "' instance "; +} + sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'status', type => 1 }, + { name => 'salesforce', type => 1, cb_prefix_output => 'prefix_salesforce_output', message_multiple => 'All salesforce instances are ok' } ]; - $self->{maps_counters}->{status} = [ + $self->{maps_counters}->{salesforce} = [ { label => 'status', threshold => 0, set => { key_values => [ { name => 'status' }, { name => 'active' }, { name => 'name' } ], closure_custom_calc => \&catalog_status_calc, @@ -61,7 +66,7 @@ sub set_counters { min => 0, label_extra_instance => 1 }, ], } - }, + } ]; } @@ -75,8 +80,9 @@ sub new { 'alias' => { name => 'use_alias' }, 'unknown-status:s' => { name => 'unknown_status', default => '' }, 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /OK/' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /OK/' } }); + return $self; } @@ -85,7 +91,6 @@ sub check_options { $self->SUPER::check_options(%options); $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); - } sub manage_selection { @@ -96,14 +101,13 @@ sub manage_selection { foreach my $instance (@{$self->{option_results}->{instance}}) { my $result = $options{custom}->request_api(path => $instance_path . $instance . '/status'); - $self->{status}->{$instance} = { + $self->{salesforce}->{$instance} = { active => $result->{isActive}, incident => scalar(@{$result->{Incidents}}), name => $instance, - status => $result->{status}, + status => $result->{status} }; } - } 1; @@ -139,4 +143,3 @@ Set critical threshold for instance status (Default: '%{status} !~ /OK/'). =back =cut - diff --git a/centreon-plugins/apps/salesforce/restapi/plugin.pm b/centreon-plugins/apps/salesforce/restapi/plugin.pm index 3b2ae71cd..0fd4c57d3 100644 --- a/centreon-plugins/apps/salesforce/restapi/plugin.pm +++ b/centreon-plugins/apps/salesforce/restapi/plugin.pm @@ -31,7 +31,7 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'sfdc-instance' => 'apps::salesforce::restapi::mode::sfdcinstance', + 'sfdc-instance' => 'apps::salesforce::restapi::mode::sfdcinstance', ); $self->{custom_modes}{api} = 'apps::salesforce::restapi::custom::api'; return $self; From c0f1a91126504e65f7ebba85bb3e8f3c5b47553c Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 14 Apr 2020 09:02:30 +0200 Subject: [PATCH 085/190] fix salesforce --- centreon-plugins/apps/salesforce/restapi/mode/sfdcinstance.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/apps/salesforce/restapi/mode/sfdcinstance.pm b/centreon-plugins/apps/salesforce/restapi/mode/sfdcinstance.pm index 33ceafcc1..aea61d55c 100644 --- a/centreon-plugins/apps/salesforce/restapi/mode/sfdcinstance.pm +++ b/centreon-plugins/apps/salesforce/restapi/mode/sfdcinstance.pm @@ -36,7 +36,7 @@ sub custom_status_output { ); } -sub prefix_volume_output { +sub prefix_salesforce_output { my ($self, %options) = @_; return "Salesforce '" . $options{instance_value}->{name} . "' instance "; From 970f8ef6f3ead93713eeab1d07f39ee75f310125 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 14 Apr 2020 13:48:11 +0200 Subject: [PATCH 086/190] Ref #1923 --- .../cloud/azure/management/monitor/mode/alert.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/centreon-plugins/cloud/azure/management/monitor/mode/alert.pm b/centreon-plugins/cloud/azure/management/monitor/mode/alert.pm index 49a6ed10a..18aeddbfc 100644 --- a/centreon-plugins/cloud/azure/management/monitor/mode/alert.pm +++ b/centreon-plugins/cloud/azure/management/monitor/mode/alert.pm @@ -39,10 +39,10 @@ sub custom_perfdata { my ($self, %options) = @_; $self->{output}->perfdata_add( - nlabel => 'alerts.' . $self->{result_values}->{severity_aboluste} . '.count', + nlabel => 'alerts.' . lc($self->{result_values}->{severity_absolute}) . '.count', value => $self->{result_values}->{count_absolute}, warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}) ); } @@ -74,7 +74,7 @@ sub new { 'resource-group:s' => { name => 'resource_group', default => '' }, 'group-by:s' => { name => 'group_by', default => 'severity' }, 'time-range:s' => { name => 'time_range', default => '1h' }, - 'filter:s' => { name => 'filter', default => '.*' }, + 'filter:s' => { name => 'filter', default => '.*' } }); return $self; From 9b10d87a68567d175a453408f9a38cb349dda776 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 15 Apr 2020 10:48:27 +0200 Subject: [PATCH 087/190] Ref #1823 --- .../apps/proxmox/ve/restapi/mode/vmusage.pm | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/centreon-plugins/apps/proxmox/ve/restapi/mode/vmusage.pm b/centreon-plugins/apps/proxmox/ve/restapi/mode/vmusage.pm index a96770fa8..763ca117c 100644 --- a/centreon-plugins/apps/proxmox/ve/restapi/mode/vmusage.pm +++ b/centreon-plugins/apps/proxmox/ve/restapi/mode/vmusage.pm @@ -172,8 +172,8 @@ sub set_counters { output_use => 'prct_cpu', threshold_use => 'prct_cpu', perfdatas => [ { label => 'cpu', value => 'prct_cpu', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, - ], + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'memory', set => { @@ -181,7 +181,7 @@ sub set_counters { closure_custom_calc => $self->can('custom_memory_calc'), closure_custom_output => $self->can('custom_memory_output'), closure_custom_perfdata => $self->can('custom_memory_perfdata'), - closure_custom_threshold_check => $self->can('custom_memory_threshold'), + closure_custom_threshold_check => $self->can('custom_memory_threshold') } }, { label => 'read-iops', set => { @@ -190,8 +190,8 @@ sub set_counters { output_template => 'Read IOPs : %.2f', output_error_template => "Read IOPs : %s", perfdatas => [ { label => 'read_iops', value => 'read_io_per_second', template => '%.2f', - unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] } }, { label => 'write-iops', set => { @@ -200,8 +200,8 @@ sub set_counters { output_template => 'Write IOPs : %.2f', output_error_template => "Write IOPs : %s", perfdatas => [ { label => 'write_iops', value => 'write_io_per_second', template => '%.2f', - unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] } }, { label => 'swap', set => { @@ -209,9 +209,9 @@ sub set_counters { closure_custom_calc => $self->can('custom_swap_calc'), closure_custom_output => $self->can('custom_swap_output'), closure_custom_perfdata => $self->can('custom_swap_perfdata'), - closure_custom_threshold_check => $self->can('custom_swap_threshold'), + closure_custom_threshold_check => $self->can('custom_swap_threshold') } - }, + } ]; $self->{maps_counters}->{vms_traffic} = [ @@ -221,8 +221,8 @@ sub set_counters { output_template => 'Traffic In : %s %s/s', perfdatas => [ { label => 'traffic_in', value => 'traffic_in_per_second', template => '%.2f', - min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' } + ] } }, { label => 'traffic-out', set => { @@ -231,10 +231,10 @@ sub set_counters { output_template => 'Traffic Out : %s %s/s', perfdatas => [ { label => 'traffic_out', value => 'traffic_out_per_second', template => '%.2f', - min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' } + ] } - }, + } ]; } @@ -249,7 +249,7 @@ sub new { 'filter-name:s' => { name => 'filter_name' }, 'use-name' => { name => 'use_name' }, 'warning-vm-status:s' => { name => 'warning_vm_status', default => '' }, - 'critical-vm-status:s' => { name => 'critical_vm_status', default => '' }, + 'critical-vm-status:s' => { name => 'critical_vm_status', default => '' } }); $self->{statefile_cache_vms} = centreon::plugins::statefile->new(%options); return $self; @@ -308,7 +308,7 @@ sub manage_selection { memory_usage => $result->{$vm_id}->{Stats}->{mem}, memory_total => $result->{$vm_id}->{Stats}->{maxmem}, swap_usage => $result->{$vm_id}->{Stats}->{swap}, - swap_total => $result->{$vm_id}->{Stats}->{maxswap}, + swap_total => defined($result->{$vm_id}->{Stats}->{maxswap}) && $result->{$vm_id}->{Stats}->{maxswap} > 0 ? $result->{$vm_id}->{Stats}->{maxswap} : undef }; $self->{vms_traffic}->{$name} = { display => $name, From 4bc88b9b1c06db7438dde08e2092b1a142166412 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Wed, 15 Apr 2020 12:13:25 +0200 Subject: [PATCH 088/190] + add capability to NOT aggregate --- centreon-plugins/apps/centreon/sql/mode/virtualservice.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/centreon-plugins/apps/centreon/sql/mode/virtualservice.pm b/centreon-plugins/apps/centreon/sql/mode/virtualservice.pm index 389597712..911381522 100644 --- a/centreon-plugins/apps/centreon/sql/mode/virtualservice.pm +++ b/centreon-plugins/apps/centreon/sql/mode/virtualservice.pm @@ -323,7 +323,10 @@ sub manage_selection { $self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf( $config_data->{formatting}->{printf_metric_value}, max(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'max'); - $self->{vmetrics}->{$vcurve}->{aggregated_value} = eval "$self->{vmetrics}->{$vcurve}->{aggregated_value} $config_data->{virtualcurve}->{$vcurve}->{custom}" if (defined($config_data->{virtualcurve}->{$vcurve}->{custom})); + + $self->{vmetrics}->{$vcurve}->{aggregated_value} = ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'none' && defined($config_data->{virtualcurve}->{$vcurve}->{custom})) ? + eval "$config_data->{virtualcurve}->{$vcurve}->{custom}" : + eval "$self->{vmetrics}->{$vcurve}->{aggregated_value} $config_data->{virtualcurve}->{$vcurve}->{custom}"; $self->{vmetrics}->{$vcurve}->{unit} = (defined($config_data->{virtualcurve}->{$vcurve}->{unit})) ? $config_data->{virtualcurve}->{$vcurve}->{unit} : ''; $self->{vmetrics}->{$vcurve}->{min} = (defined($config_data->{virtualcurve}->{$vcurve}->{min})) ? $config_data->{virtualcurve}->{$vcurve}->{min} : ''; From 34d5d6ae971a440ef16a3a69de03b17921ba7546 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 15 Apr 2020 17:30:11 +0200 Subject: [PATCH 089/190] fix azure cpu mode --- centreon-plugins/cloud/azure/compute/virtualmachine/mode/cpu.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/cloud/azure/compute/virtualmachine/mode/cpu.pm b/centreon-plugins/cloud/azure/compute/virtualmachine/mode/cpu.pm index 8149deda8..d068f927e 100644 --- a/centreon-plugins/cloud/azure/compute/virtualmachine/mode/cpu.pm +++ b/centreon-plugins/cloud/azure/compute/virtualmachine/mode/cpu.pm @@ -81,7 +81,7 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments =>v{ + $options{options}->add_options(arguments => { 'resource:s@' => { name => 'resource' }, 'resource-group:s' => { name => 'resource_group' }, 'filter-metric:s' => { name => 'filter_metric' } From 1eabd9e240af09b107cbecf467bef5674db0f56d Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Thu, 16 Apr 2020 19:18:56 +0200 Subject: [PATCH 090/190] Better handle Blade/Flex temp thresholds --- .../common/ibm/nos/snmp/mode/components/temperature.pm | 5 +++++ .../lenovo/flexsystem/snmp/mode/components/temperature.pm | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/centreon-plugins/centreon/common/ibm/nos/snmp/mode/components/temperature.pm b/centreon-plugins/centreon/common/ibm/nos/snmp/mode/components/temperature.pm index 704bf3121..bba2b8448 100644 --- a/centreon-plugins/centreon/common/ibm/nos/snmp/mode/components/temperature.pm +++ b/centreon-plugins/centreon/common/ibm/nos/snmp/mode/components/temperature.pm @@ -47,6 +47,11 @@ sub check { $temperature = $1 if ($1 > $temperature); my $critical_mib = ($warning_mib + $2) / 2; + if ($warning_mib == $critical_mib) { #seen on some chassis ! + $warning_mib -= 10; + $critical_mib -= 5; + } + $self->{components}->{temperature}->{total}++; $self->{output}->output_add(long_msg => diff --git a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/temperature.pm b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/temperature.pm index 76bc6ca46..b7d0529b4 100644 --- a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/temperature.pm +++ b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/temperature.pm @@ -60,6 +60,11 @@ sub check { $temperature = $1 if ($1 > $temperature); my $critical_mib = ($warning_mib + $2) / 2; + if ($warning_mib == $critical_mib) { #seen on some chassis ! + $warning_mib -= 10; + $critical_mib -= 5; + } + $self->{output}->output_add( long_msg => sprintf( "temperature switch '%s' is %s C [instance: %s]", From bdcdfaf1159118017871a04933a816b4c9cca070 Mon Sep 17 00:00:00 2001 From: tcharles Date: Fri, 17 Apr 2020 00:48:34 +0200 Subject: [PATCH 091/190] add missing host output to notification --- centreon-plugins/notification/telegram/mode/alert.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/centreon-plugins/notification/telegram/mode/alert.pm b/centreon-plugins/notification/telegram/mode/alert.pm index ce452e6ae..2812f8bdc 100644 --- a/centreon-plugins/notification/telegram/mode/alert.pm +++ b/centreon-plugins/notification/telegram/mode/alert.pm @@ -111,7 +111,9 @@ sub host_message { } else { $self->{message} .= ' alert'; } - + if (defined($self->{option_results}->{host_output}) && $self->{option_results}->{host_output} ne '') { + $self->{message} .= "\n " . $self->{option_results}->{host_output}; + } if (defined($self->{option_results}->{link_url}) && $self->{option_results}->{link_url} ne '') { $self->{message} .= "\n {option_results}->{link_url} . "\">Link"; } From c53fc751fa0c6f765a8a0b39bb127d5d77af4c88 Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Fri, 17 Apr 2020 10:49:03 +0200 Subject: [PATCH 092/190] Blade/Flex use same time units --- .../centreon/common/ibm/nos/snmp/mode/cpu.pm | 6 ++--- .../lenovo/flexsystem/snmp/mode/cpu.pm | 26 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/centreon-plugins/centreon/common/ibm/nos/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/ibm/nos/snmp/mode/cpu.pm index 786883678..5260d01e6 100644 --- a/centreon-plugins/centreon/common/ibm/nos/snmp/mode/cpu.pm +++ b/centreon-plugins/centreon/common/ibm/nos/snmp/mode/cpu.pm @@ -35,7 +35,7 @@ sub set_counters { $self->{maps_counters}->{cpu} = [ { label => 'average-1m', nlabel => 'cpu.utilization.1m.percentage', set => { key_values => [ { name => 'average_1m' } ], - output_template => '%.2f %% (1min)', + output_template => '%.2f %% (1m)', perfdatas => [ { value => 'average_1m_absolute', template => '%.2f', min => 0, max => 100, unit => '%' } @@ -44,7 +44,7 @@ sub set_counters { }, { label => 'average-5m', nlabel => 'cpu.utilization.5m.percentage', set => { key_values => [ { name => 'average_5m' } ], - output_template => '%.2f %% (5min)', + output_template => '%.2f %% (5m)', perfdatas => [ { value => 'average_5m_absolute', template => '%.2f', min => 0, max => 100, unit => '%' } @@ -94,7 +94,7 @@ Check CPU usage (over the last minute). =item B<--warning-*> B<--critical-*> Thresholds. -Can be: 'average-1min' (%), 'average-5min' (%). +Can be: 'average-1m' (%), 'average-5m' (%). =back diff --git a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/cpu.pm b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/cpu.pm index c297f0eb3..9f3e87c16 100644 --- a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/cpu.pm +++ b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/cpu.pm @@ -33,20 +33,20 @@ sub set_counters { ]; $self->{maps_counters}->{cpu} = [ - { label => 'average-1min', nlabel => 'switch.cpu.utilization.1min.percentage', set => { - key_values => [ { name => 'average_1min' }, { name => 'display' } ], - output_template => '%.2f %% (1min)', + { label => 'average-1m', nlabel => 'switch.cpu.utilization.1m.percentage', set => { + key_values => [ { name => 'average_1m' }, { name => 'display' } ], + output_template => '%.2f %% (1m)', perfdatas => [ - { value => 'average_1min_absolute', template => '%.2f', + { value => 'average_1m_absolute', template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 } ] } }, - { label => 'average-5min', nlabel => 'switch.cpu.utilization.5min.percentage', set => { - key_values => [ { name => 'average_5min' }, { name => 'display' } ], - output_template => '%.2f %% (5min)', + { label => 'average-5m', nlabel => 'switch.cpu.utilization.5m.percentage', set => { + key_values => [ { name => 'average_5m' }, { name => 'display' } ], + output_template => '%.2f %% (5m)', perfdatas => [ - { value => 'average_5min_absolute', template => '%.2f', + { value => 'average_5m_absolute', template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 } ] } @@ -73,8 +73,8 @@ sub new { } my $mapping = { - average_1min => { oid => '.1.3.6.1.4.1.20301.2.5.1.2.2.12.1.1.5' }, # mpCpuStatsUtil1MinuteSwRev - average_5min => { oid => '.1.3.6.1.4.1.20301.2.5.1.2.2.12.1.1.6' } # mpCpuStatsUtil5MinutesSwRev + average_1m => { oid => '.1.3.6.1.4.1.20301.2.5.1.2.2.12.1.1.5' }, # mpCpuStatsUtil1MinuteSwRev + average_5m => { oid => '.1.3.6.1.4.1.20301.2.5.1.2.2.12.1.1.6' } # mpCpuStatsUtil5MinutesSwRev }; my $oid_mpCpuStatsRevTableEntry = '.1.3.6.1.4.1.20301.2.5.1.2.2.12.1.1'; @@ -84,13 +84,13 @@ sub manage_selection { my $snmp_result = $options{snmp}->get_table( oid => $oid_mpCpuStatsRevTableEntry, - start => $mapping->{average_1min}->{oid}, + start => $mapping->{average_1m}->{oid}, nothing_quit => 1 ); $self->{cpu} = {}; foreach my $oid (keys %$snmp_result) { - next if ($oid !~ /^$mapping->{average_1min}->{oid}\.(.*)$/); + next if ($oid !~ /^$mapping->{average_1m}->{oid}\.(.*)$/); my $instance = $1; my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); @@ -124,7 +124,7 @@ Filter switch number. =item B<--warning-*> B<--critical-*> Thresholds. -Can be: 'average-1min' (%), 'average-5min' (%). +Can be: 'average-1m' (%), 'average-5m' (%). =back From b2bdc1057899f7c435f2d64c80502e982f44606d Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Fri, 17 Apr 2020 10:56:30 +0200 Subject: [PATCH 093/190] Blade/Flex fix labels --- .../network/lenovo/flexsystem/snmp/mode/cpu.pm | 6 +++--- .../network/lenovo/flexsystem/snmp/mode/memory.pm | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/cpu.pm b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/cpu.pm index 9f3e87c16..869d1bdb6 100644 --- a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/cpu.pm +++ b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/cpu.pm @@ -33,7 +33,7 @@ sub set_counters { ]; $self->{maps_counters}->{cpu} = [ - { label => 'average-1m', nlabel => 'switch.cpu.utilization.1m.percentage', set => { + { label => 'average-1m', nlabel => 'cpu.utilization.1m.percentage', set => { key_values => [ { name => 'average_1m' }, { name => 'display' } ], output_template => '%.2f %% (1m)', perfdatas => [ @@ -42,7 +42,7 @@ sub set_counters { ] } }, - { label => 'average-5m', nlabel => 'switch.cpu.utilization.5m.percentage', set => { + { label => 'average-5m', nlabel => 'cpu.utilization.5m.percentage', set => { key_values => [ { name => 'average_5m' }, { name => 'display' } ], output_template => '%.2f %% (5m)', perfdatas => [ @@ -100,7 +100,7 @@ sub manage_selection { next; } - $self->{cpu}->{$instance} = { + $self->{cpu}->{'switch' . $instance} = { display => $instance, %$result }; diff --git a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/memory.pm b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/memory.pm index c3eae2c60..aeddb4205 100644 --- a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/memory.pm +++ b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/memory.pm @@ -46,7 +46,7 @@ sub set_counters { ]; $self->{maps_counters}->{memory} = [ - { label => 'usage', nlabel => 'switch.memory.usage.bytes', set => { + { label => 'usage', nlabel => 'memory.usage.bytes', set => { key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], closure_custom_output => $self->can('custom_usage_output'), perfdatas => [ @@ -55,7 +55,7 @@ sub set_counters { ] } }, - { label => 'usage-free', display_ok => 0, nlabel => 'switch.memory.free.bytes', set => { + { label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => { key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], closure_custom_output => $self->can('custom_usage_output'), perfdatas => [ @@ -64,7 +64,7 @@ sub set_counters { ] } }, - { label => 'usage-prct', display_ok => 0, nlabel => 'switch.memory.usage.percentage', set => { + { label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => { key_values => [ { name => 'prct_used' }, { name => 'display' } ], output_template => 'Ram Used : %.2f %%', perfdatas => [ @@ -124,7 +124,7 @@ sub manage_selection { } my $prct_used = ($result->{total} - $result->{free}) * 100 / $result->{total}; - $self->{memory}->{$instance} = { + $self->{memory}->{'switch' . $instance} = { display => $instance, prct_used => $prct_used, prct_free => 100 - $prct_used, From fbf1ba837fea1c7af6068d92e3a6cc759c5922b4 Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Fri, 17 Apr 2020 10:59:37 +0200 Subject: [PATCH 094/190] Typo --- .../lenovo/flexsystem/snmp/mode/components/temperature.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/temperature.pm b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/temperature.pm index 76bc6ca46..b590cc986 100644 --- a/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/temperature.pm +++ b/centreon-plugins/network/lenovo/flexsystem/snmp/mode/components/temperature.pm @@ -96,7 +96,7 @@ sub check { } $self->{output}->perfdata_add( nlabel => 'hardware.temperature.celsius', unit => 'C', - instances => 'switch=' . $instance, + instances => 'switch' . $instance, value => $temperature, warning => $warn, critical => $crit From a34598ec98be957b4dfdeb958b752f01e86bf303 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 17 Apr 2020 17:20:02 +0200 Subject: [PATCH 095/190] enhance cloud recovery azure --- .../recovery/mode/backupitemsstatus.pm | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/centreon-plugins/cloud/azure/management/recovery/mode/backupitemsstatus.pm b/centreon-plugins/cloud/azure/management/recovery/mode/backupitemsstatus.pm index fa04f48b9..c3960b30f 100644 --- a/centreon-plugins/cloud/azure/management/recovery/mode/backupitemsstatus.pm +++ b/centreon-plugins/cloud/azure/management/recovery/mode/backupitemsstatus.pm @@ -28,16 +28,17 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - - my $msg = sprintf("Pre-Check Status '%s', Last Backup Status '%s'", + + return sprintf( + "Pre-Check Status '%s', Last Backup Status '%s'", $self->{result_values}->{precheck_status}, - $self->{result_values}->{last_backup_status}); - return $msg; + $self->{result_values}->{last_backup_status} + ); } sub custom_status_calc { my ($self, %options) = @_; - + $self->{result_values}->{precheck_status} = $options{new_datas}->{$self->{instance} . '_precheck_status'}; $self->{result_values}->{last_backup_status} = $options{new_datas}->{$self->{instance} . '_last_backup_status'}; $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; @@ -52,16 +53,16 @@ sub prefix_global_output { sub prefix_item_output { my ($self, %options) = @_; - + return "Backup Item '" . $options{instance_value}->{display} . "' "; } sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', cb_init => 'skip_global' }, - { name => 'items', type => 1, cb_prefix_output => 'prefix_item_output', message_multiple => 'All items are ok' }, + { name => 'items', type => 1, cb_prefix_output => 'prefix_item_output', message_multiple => 'All items are ok' } ]; $self->{maps_counters}->{global} = [ @@ -69,18 +70,18 @@ sub set_counters { key_values => [ { name => 'completed' } ], output_template => "completed : %s", perfdatas => [ - { label => 'total_completed', value => 'completed_absolute', template => '%d', min => 0 }, - ], + { label => 'total_completed', value => 'completed_absolute', template => '%d', min => 0 } + ] } }, { label => 'total-failed', set => { key_values => [ { name => 'failed' } ], output_template => "failed : %s", perfdatas => [ - { label => 'total_failed', value => 'failed_absolute', template => '%d', min => 0 }, - ], + { label => 'total_failed', value => 'failed_absolute', template => '%d', min => 0 } + ] } - }, + } ]; $self->{maps_counters}->{items} = [ @@ -89,9 +90,9 @@ sub set_counters { closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold } - }, + } ]; } @@ -105,18 +106,17 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "vault-name:s" => { name => 'vault_name' }, - "resource-group:s" => { name => 'resource_group' }, - "filter-name:s" => { name => 'filter_name' }, - "filter-vmid:s" => { name => 'filter_vmid' }, - "filter-counters:s" => { name => 'filter_counters' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{precheck_status} ne "Passed" || %{last_backup_status} eq "Failed"' }, - }); - + + $options{options}->add_options(arguments => { + 'vault-name:s' => { name => 'vault_name' }, + 'resource-group:s' => { name => 'resource_group' }, + 'filter-name:s' => { name => 'filter_name' }, + 'filter-vmid:s' => { name => 'filter_vmid' }, + 'filter-counters:s' => { name => 'filter_counters' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{precheck_status} ne "Passed" || %{last_backup_status} eq "Failed"' } + }); + return $self; } @@ -139,33 +139,33 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - $self->{global} = { - completed => 0, failed => 0, inprogress => 0, - }; - $self->{items} = {}; my $items = $options{custom}->azure_list_backup_items( vault_name => $self->{option_results}->{vault_name}, resource_group => $self->{option_results}->{resource_group} ); + + $self->{global} = { + completed => 0, failed => 0, inprogress => 0 + }; + $self->{items} = {}; foreach my $item (@{$items}) { next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $item->{properties}->{friendlyName} !~ /$self->{option_results}->{filter_name}/); next if (defined($self->{option_results}->{filter_vmid}) && $self->{option_results}->{filter_vmid} ne '' && $item->{properties}->{virtualMachineId} !~ /$self->{option_results}->{filter_vmid}/); - + $self->{items}->{$item->{id}} = { display => $item->{properties}->{friendlyName}, precheck_status => $item->{properties}->{healthStatus}, - last_backup_status => $item->{properties}->{lastBackupStatus}, + last_backup_status => $item->{properties}->{lastBackupStatus} }; - foreach my $status (keys %{$self->{global}}) { - $self->{global}->{$status}++ if ($item->{properties}->{lastBackupStatus} =~ /$status/i); - } + $self->{global}->{ lc($item->{properties}->{lastBackupStatus}) }++ + if (defined($item->{properties}->{lastBackupStatus}) && defined($self->{global}->{ lc($item->{properties}->{lastBackupStatus}) })); } - + if (scalar(keys %{$self->{items}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "No backup items found."); + $self->{output}->add_option_msg(short_msg => 'No backup items found.'); $self->{output}->option_exit(); } } From aa89c020b02e1f1700b8965afb371a79ab808735 Mon Sep 17 00:00:00 2001 From: lenkoda Date: Sat, 18 Apr 2020 12:14:23 +0200 Subject: [PATCH 096/190] New plugin for TimeLink TMS6001 NTP server --- .../timelinkmicro/tms6001/snmp/mode/alarm.pm | 104 ++++++++++++++++++ .../tms6001/snmp/mode/antenna.pm | 93 ++++++++++++++++ .../tms6001/snmp/mode/frequency.pm | 104 ++++++++++++++++++ .../timelinkmicro/tms6001/snmp/mode/gnss.pm | 90 +++++++++++++++ .../tms6001/snmp/mode/satellites.pm | 104 ++++++++++++++++++ .../timelinkmicro/tms6001/snmp/mode/time.pm | 104 ++++++++++++++++++ .../timelinkmicro/tms6001/snmp/plugin.pm | 55 +++++++++ 7 files changed, 654 insertions(+) create mode 100644 centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarm.pm create mode 100644 centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/antenna.pm create mode 100644 centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/frequency.pm create mode 100644 centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/gnss.pm create mode 100644 centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/satellites.pm create mode 100644 centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/time.pm create mode 100644 centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/plugin.pm diff --git a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarm.pm b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarm.pm new file mode 100644 index 000000000..868f251a3 --- /dev/null +++ b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarm.pm @@ -0,0 +1,104 @@ +# +# Copyright 2019 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. +# +# Authors : Thomas Gourdin thomas.gourdin@gmail.com + +package hardware::devices::timelinkmicro::tms6001::snmp::mode::alarm; + +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 => + { + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } + +} + +sub run { + my ($self, %options) = @_; + $self->{snmp} = $options{snmp}; + $self->{hostname} = $self->{snmp}->get_hostname(); + + my $oid_qualityfrequency = '.1.3.6.1.4.1.22641.100.3.3.0'; + + my $result = $self->{snmp}->get_leef(oids => [ $oid_qualityfrequency ], nothing_quit => 1); + + my $value = $result->{$oid_qualityfrequency}; + + my $exit = $self->{perfdata}->threshold_check(value => $value, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("There is %s alarm(s).", $value)); + + $self->{output}->perfdata_add(label => 'value', unit => undef, + value => $value, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => undef, max => undef); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check quality of frequency generation + +=over 8 + +=item B<--warning> + +Threshold warning. + +=item B<--critical> + +Threshold critical. + +=back + +=cut diff --git a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/antenna.pm b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/antenna.pm new file mode 100644 index 000000000..73cf044a7 --- /dev/null +++ b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/antenna.pm @@ -0,0 +1,93 @@ +# +# Copyright 2019 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. +# +# Authors : Thomas Gourdin thomas.gourdin@gmail.com + +package hardware::devices::timelinkmicro::tms6001::snmp::mode::antenna; + +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 run { + my ($self, %options) = @_; + $self->{snmp} = $options{snmp}; + $self->{hostname} = $self->{snmp}->get_hostname(); + + my $oid_qualityfrequency = '.1.3.6.1.4.1.22641.100.4.1.4.0'; + + my $result = $self->{snmp}->get_leef(oids => [ $oid_qualityfrequency ], nothing_quit => 1); + + my $value = $result->{$oid_qualityfrequency}; + + if ($value eq 'C') { + $self->{output}->output_add(severity => 'OK', + short_msg => sprintf("Antenna is connected")); + } elsif ($value eq 'S') { + $self->{output}->output_add(severity => 'WARNING', + short_msg => sprintf("Antenna is shorted or powered off")); + } elsif ($value eq 'N') { + $self->{output}->output_add(severity => 'CRITICAL', + short_msg => sprintf("Antenna is not connected")); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check quality of frequency generation + +=over 8 + +=item B<--warning> + +Threshold warning. + +=item B<--critical> + +Threshold critical. + +=back + +=cut diff --git a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/frequency.pm b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/frequency.pm new file mode 100644 index 000000000..e443c5a7d --- /dev/null +++ b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/frequency.pm @@ -0,0 +1,104 @@ +# +# Copyright 2019 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. +# +# Authors : Thomas Gourdin thomas.gourdin@gmail.com + +package hardware::devices::timelinkmicro::tms6001::snmp::mode::frequency; + +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 => + { + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } + +} + +sub run { + my ($self, %options) = @_; + $self->{snmp} = $options{snmp}; + $self->{hostname} = $self->{snmp}->get_hostname(); + + my $oid_qualityfrequency = '.1.3.6.1.4.1.22641.100.3.6.0'; + + my $result = $self->{snmp}->get_leef(oids => [ $oid_qualityfrequency ], nothing_quit => 1); + + my $value = $result->{$oid_qualityfrequency}; + + my $exit = $self->{perfdata}->threshold_check(value => $value, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Quality of frequency generation is %s.", $value)); + + $self->{output}->perfdata_add(label => 'value', unit => undef, + value => $value, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => undef, max => undef); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check quality of frequency generation + +=over 8 + +=item B<--warning> + +Threshold warning. + +=item B<--critical> + +Threshold critical. + +=back + +=cut diff --git a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/gnss.pm b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/gnss.pm new file mode 100644 index 000000000..b9d9f7986 --- /dev/null +++ b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/gnss.pm @@ -0,0 +1,90 @@ +# +# Copyright 2019 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. +# +# Authors : Thomas Gourdin thomas.gourdin@gmail.com + +package hardware::devices::timelinkmicro::tms6001::snmp::mode::gnss; + +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 run { + my ($self, %options) = @_; + $self->{snmp} = $options{snmp}; + $self->{hostname} = $self->{snmp}->get_hostname(); + + my $oid_qualityfrequency = '.1.3.6.1.4.1.22641.100.4.1.2.0'; + + my $result = $self->{snmp}->get_leef(oids => [ $oid_qualityfrequency ], nothing_quit => 1); + + my $value = $result->{$oid_qualityfrequency}; + + if ($value eq 'Nominal') { + $self->{output}->output_add(severity => 'OK', + short_msg => sprintf("GNSS status is $value")); + } else { + $self->{output}->output_add(severity => 'CRITICAL', + short_msg => sprintf("GNSS status is $value")); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check quality of frequency generation + +=over 8 + +=item B<--warning> + +Threshold warning. + +=item B<--critical> + +Threshold critical. + +=back + +=cut diff --git a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/satellites.pm b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/satellites.pm new file mode 100644 index 000000000..9d6468be2 --- /dev/null +++ b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/satellites.pm @@ -0,0 +1,104 @@ +# +# Copyright 2019 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. +# +# Authors : Thomas Gourdin thomas.gourdin@gmail.com + +package hardware::devices::timelinkmicro::tms6001::snmp::mode::satellites; + +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 => + { + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } + +} + +sub run { + my ($self, %options) = @_; + $self->{snmp} = $options{snmp}; + $self->{hostname} = $self->{snmp}->get_hostname(); + + my $oid_qualityfrequency = '.1.3.6.1.4.1.22641.100.4.1.8.0'; + + my $result = $self->{snmp}->get_leef(oids => [ $oid_qualityfrequency ], nothing_quit => 1); + + my $value = $result->{$oid_qualityfrequency}; + + my $exit = $self->{perfdata}->threshold_check(value => $value, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Number of satellites seen is %s.", $value)); + + $self->{output}->perfdata_add(label => 'value', unit => undef, + value => $value, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => undef, max => undef); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check quality of frequency generation + +=over 8 + +=item B<--warning> + +Threshold warning. + +=item B<--critical> + +Threshold critical. + +=back + +=cut diff --git a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/time.pm b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/time.pm new file mode 100644 index 000000000..cdb10572e --- /dev/null +++ b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/time.pm @@ -0,0 +1,104 @@ +# +# Copyright 2019 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. +# +# Authors : Thomas Gourdin thomas.gourdin@gmail.com + +package hardware::devices::timelinkmicro::tms6001::snmp::mode::time; + +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 => + { + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } + +} + +sub run { + my ($self, %options) = @_; + $self->{snmp} = $options{snmp}; + $self->{hostname} = $self->{snmp}->get_hostname(); + + my $oid_qualityfrequency = '.1.3.6.1.4.1.22641.100.3.5.0'; + + my $result = $self->{snmp}->get_leef(oids => [ $oid_qualityfrequency ], nothing_quit => 1); + + my $value = $result->{$oid_qualityfrequency}; + + my $exit = $self->{perfdata}->threshold_check(value => $value, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Quality of time generation is %s.", $value)); + + $self->{output}->perfdata_add(label => 'value', unit => undef, + value => $value, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => undef, max => undef); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check quality of frequency generation + +=over 8 + +=item B<--warning> + +Threshold warning. + +=item B<--critical> + +Threshold critical. + +=back + +=cut diff --git a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/plugin.pm b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/plugin.pm new file mode 100644 index 000000000..799f11780 --- /dev/null +++ b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/plugin.pm @@ -0,0 +1,55 @@ +# +# Copyright 2015 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. +# +# Authors : Thomas Gourdin thomas.gourdin@gmail.com + +package hardware::devices::timelinkmicro::tms6001::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'frequency' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::frequency', + 'time' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::time', + 'satellites' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::satellites', + 'antenna' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::antenna', + 'gnss' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::gnss', + 'alarms' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::alarm', + + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check timelinkmicro TMS6001 NTP servers through SNMP + +=cut From 4ea48d3afe156d55156de2287598f142b5b4fff2 Mon Sep 17 00:00:00 2001 From: lenkoda Date: Sat, 18 Apr 2020 12:25:45 +0200 Subject: [PATCH 097/190] Modified descriptions --- .../devices/timelinkmicro/tms6001/snmp/mode/alarm.pm | 2 +- .../devices/timelinkmicro/tms6001/snmp/mode/antenna.pm | 10 +--------- .../devices/timelinkmicro/tms6001/snmp/mode/gnss.pm | 10 +--------- .../timelinkmicro/tms6001/snmp/mode/satellites.pm | 2 +- .../devices/timelinkmicro/tms6001/snmp/mode/time.pm | 2 +- 5 files changed, 5 insertions(+), 21 deletions(-) diff --git a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarm.pm b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarm.pm index 868f251a3..3f236e7d1 100644 --- a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarm.pm +++ b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarm.pm @@ -87,7 +87,7 @@ __END__ =head1 MODE -Check quality of frequency generation +Check number of alarms =over 8 diff --git a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/antenna.pm b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/antenna.pm index 73cf044a7..e548c2920 100644 --- a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/antenna.pm +++ b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/antenna.pm @@ -76,18 +76,10 @@ __END__ =head1 MODE -Check quality of frequency generation +Check antenna status =over 8 -=item B<--warning> - -Threshold warning. - -=item B<--critical> - -Threshold critical. - =back =cut diff --git a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/gnss.pm b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/gnss.pm index b9d9f7986..666fff461 100644 --- a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/gnss.pm +++ b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/gnss.pm @@ -73,18 +73,10 @@ __END__ =head1 MODE -Check quality of frequency generation +Check GNSS state =over 8 -=item B<--warning> - -Threshold warning. - -=item B<--critical> - -Threshold critical. - =back =cut diff --git a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/satellites.pm b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/satellites.pm index 9d6468be2..51635f0d2 100644 --- a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/satellites.pm +++ b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/satellites.pm @@ -87,7 +87,7 @@ __END__ =head1 MODE -Check quality of frequency generation +Check number of satellites seen =over 8 diff --git a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/time.pm b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/time.pm index cdb10572e..f061e0294 100644 --- a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/time.pm +++ b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/time.pm @@ -87,7 +87,7 @@ __END__ =head1 MODE -Check quality of frequency generation +Check quality of time generation =over 8 From 196c234f711e76628ffcea548139f08030c37ff3 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 20 Apr 2020 15:27:44 +0200 Subject: [PATCH 098/190] Fix #1952 --- .../apps/protocols/dns/lib/dns.pm | 48 +++++++------- .../apps/protocols/dns/mode/request.pm | 65 ++++++++++++------- 2 files changed, 63 insertions(+), 50 deletions(-) diff --git a/centreon-plugins/apps/protocols/dns/lib/dns.pm b/centreon-plugins/apps/protocols/dns/lib/dns.pm index 59ae923aa..d6b1e9b65 100644 --- a/centreon-plugins/apps/protocols/dns/lib/dns.pm +++ b/centreon-plugins/apps/protocols/dns/lib/dns.pm @@ -26,46 +26,44 @@ use Net::DNS; my $handle; -my %map_search_field = ( - MX => 'exchange', - SOA => 'mname', - NS => 'nsdname', - A => 'address', - PTR => 'name', - CNAME => 'cname', - TXT => 'txtdata', -); - sub search { my ($self, %options) = @_; - + + my $map_search_field = { + MX => 'exchange', + SOA => 'mname', + NS => 'nsdname', + A => 'address', + PTR => 'name', + CNAME => 'cname', + TXT => 'txtdata' + }; + my @results = (); my $search_type = $self->{option_results}->{search_type}; - if (defined($search_type) && !defined($map_search_field{$search_type})) { + if (defined($search_type) && !defined($map_search_field->{$search_type})) { $self->{output}->add_option_msg(short_msg => "search-type '$search_type' is unknown or unsupported"); $self->{output}->option_exit(); } - + + $map_search_field->{PTR} = 'ptrdname' if (defined($self->{option_results}->{use_ptr_fqdn})); + my $error_quit = defined($options{error_quit}) ? $options{error_quit} : undef; my $reply = $handle->search($self->{option_results}->{search}, $search_type); if ($reply) { foreach my $rr ($reply->answer) { - if (!defined($search_type)) { - push @results, $rr->address if ($rr->type eq 'A'); - push @results, $rr->name if ($rr->type eq 'PTR'); - push @results, $rr->txtdata if ($rr->type eq 'TXT'); - next; - } - - next if ($rr->type ne $search_type); - my $search_field = $map_search_field{$search_type}; - push @results, $rr->$search_field; + my $type = defined($search_type) ? $search_type : $rr->type; + next if ($type ne $rr->type); + my $attr = $map_search_field->{$type}; + push @results, $rr->$attr; } } else { if (defined($error_quit)) { - $self->{output}->output_add(severity => $error_quit, - short_msg => sprintf("DNS Query Failed: %s", $handle->errorstring)); + $self->{output}->output_add( + severity => $error_quit, + short_msg => sprintf('DNS query failed: %s', $handle->errorstring) + ); $self->{output}->display(); $self->{output}->exit(); } diff --git a/centreon-plugins/apps/protocols/dns/mode/request.pm b/centreon-plugins/apps/protocols/dns/mode/request.pm index 4a2306a13..d890249c4 100644 --- a/centreon-plugins/apps/protocols/dns/mode/request.pm +++ b/centreon-plugins/apps/protocols/dns/mode/request.pm @@ -34,18 +34,18 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "nameservers:s@" => { name => 'nameservers' }, - "searchlist:s@" => { name => 'searchlist' }, - "dns-options:s@" => { name => 'dns_options' }, - "search:s" => { name => 'search' }, - "search-type:s" => { name => 'search_type' }, - "expected-answer:s" => { name => 'expected_answer' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "memory" => { name => 'memory' }, - }); + $options{options}->add_options(arguments => { + 'nameservers:s@' => { name => 'nameservers' }, + 'searchlist:s@' => { name => 'searchlist' }, + 'dns-options:s@' => { name => 'dns_options' }, + 'search:s' => { name => 'search' }, + 'search-type:s' => { name => 'search_type' }, + 'use-ptr-fqdn' => { name => 'use_ptr_fqdn' }, + 'expected-answer:s' => { name => 'expected_answer' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' }, + 'memory' => { name => 'memory' } + }); $self->{statefile_cache} = centreon::plugins::statefile->new(%options); return $self; @@ -96,14 +96,20 @@ sub run { my $timeelapsed = tv_interval ($timing0, [gettimeofday]); my $result_str = join(', ', @results); - my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed, - threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Response time %.3f second(s) (answer: %s)", $timeelapsed, $result_str)); - $self->{output}->perfdata_add(label => "time", unit => 's', - value => sprintf('%.3f', $timeelapsed), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')); + my $exit = $self->{perfdata}->threshold_check( + value => $timeelapsed, + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ] + ); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Response time %.3f second(s) (answer: %s)", $timeelapsed, $result_str) + ); + $self->{output}->perfdata_add( + label => "time", unit => 's', + value => sprintf('%.3f', $timeelapsed), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') + ); if (defined($self->{option_results}->{expected_answer}) && $self->{option_results}->{expected_answer} ne '') { my $match = 0; @@ -114,8 +120,11 @@ sub run { } if ($match == 0) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("No result values match expected answer (answer: %s)", $result_str)); + $self->{output}->output_add( + severity => 'CRITICAL', + short_msg => sprintf("No result values match expected answer (answer: %s)", $result_str + ) + ); } } @@ -125,15 +134,17 @@ sub run { my $old_result = $self->{statefile_cache}->get(name => "result"); if (defined($old_result)) { if ($old_result ne $result_str) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Result has changed [answer: %s] [old answer: %s]", $result_str, $old_result)); + $self->{output}->output_add( + severity => 'CRITICAL', + short_msg => sprintf("Result has changed [answer: %s] [old answer: %s]", $result_str, $old_result) + ); } } else { $self->{output}->output_add(long_msg => 'cache file created.'); } $self->{statefile_cache}->write(data => $datas); } - + $self->{output}->display(); $self->{output}->exit(); } @@ -169,6 +180,10 @@ Set the search value (required). Set the search type. Can be: 'MX', 'SOA', 'NS', 'A', 'CNAME' or 'PTR'. 'A' or 'PTR' is used by default (depends if an IP or not). +=item B<--use-ptr-fqdn> + +Search is done on conical names for PTR type. + =item B<--expected-answer> What the server must answer (can be a regexp). From 3cb6f80cf9313a678e1a21829d334c3ced2d8a22 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Mon, 20 Apr 2020 15:36:37 +0200 Subject: [PATCH 099/190] add ec2 spot fleet instance ocunt ref #172 --- centreon-plugins/cloud/aws/custom/awscli.pm | 30 +++++ centreon-plugins/cloud/aws/custom/paws.pm | 30 ++++- .../cloud/aws/ec2/mode/spotactiveinstances.pm | 122 ++++++++++++++++++ centreon-plugins/cloud/aws/ec2/plugin.pm | 21 +-- 4 files changed, 190 insertions(+), 13 deletions(-) create mode 100644 centreon-plugins/cloud/aws/ec2/mode/spotactiveinstances.pm diff --git a/centreon-plugins/cloud/aws/custom/awscli.pm b/centreon-plugins/cloud/aws/custom/awscli.pm index ab62709fb..36510b5d2 100644 --- a/centreon-plugins/cloud/aws/custom/awscli.pm +++ b/centreon-plugins/cloud/aws/custom/awscli.pm @@ -369,6 +369,36 @@ sub ec2_get_instances_status { return $instance_results; } +sub ec2spot_get_active_instances_set_cmd { + my ($self, %options) = @_; + + return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); + + my $cmd_options = "ec2 describe-spot-fleet-instances --no-dry-run --region $options{region} --output json"; + $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); + $cmd_options .= " --spot-fleet-request-id " . $options{spot_fleet_request_id}; + + return $cmd_options; +} + +sub ec2spot_get_active_instances_status { + my ($self, %options) = @_; + + my $cmd_options = $self->ec2spot_get_active_instances_set_cmd(%options); + my $raw_results = $self->execute(cmd_options => $cmd_options); + + my $instance_results = {}; + foreach (@{$raw_results->{ActiveInstances}}) { + $instance_results->{$_->{InstanceId}} = { + health => $_->{InstanceHealth}, + type => $_->{InstanceType}, + request_id => $_->{SpotInstanceRequestId} + }; + } + + return $instance_results; +} + sub ec2_list_resources_set_cmd { my ($self, %options) = @_; diff --git a/centreon-plugins/cloud/aws/custom/paws.pm b/centreon-plugins/cloud/aws/custom/paws.pm index cc899ba34..a1cab9d9e 100644 --- a/centreon-plugins/cloud/aws/custom/paws.pm +++ b/centreon-plugins/cloud/aws/custom/paws.pm @@ -301,7 +301,31 @@ sub ec2_get_instances_status { foreach (@{$instances->{InstanceStatuses}}) { $instance_results->{$_->{InstanceId}} = { state => $_->{InstanceState}->{Name}, - status => => $_->{InstanceStatus}->{Status} }; + status => $_->{InstanceStatus}->{Status} }; + } + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "error: $@"); + $self->{output}->option_exit(); + } + + return $instance_results; +} + +sub ec2spot_get_active_instances { + my ($self, %options) = @_; + + my $instance_results = {}; + eval { + my $lwp_caller = new Paws::Net::LWPCaller(); + my $ec2 = Paws->service('EC2', caller => $lwp_caller, region => $options{region}); + my $instances = $ec2->DescribeSpotFleetInstances('SpotFleetRequestId' => $options{spot_fleet_request_id}, DryRun => 0, IncludeAllInstances => 1); + + foreach (@{$instances->{ActiveInstances}}) { + $instance_results->{$_->{InstanceId}} = { + health => $_->{InstanceHealth}, + type => $_->{InstanceType}, + request_id => $_->{SpotInstanceRequestId} }; } }; if ($@) { @@ -451,7 +475,7 @@ sub vpn_list_connections { my $connections_results = []; eval { my $lwp_caller = new Paws::Net::LWPCaller(); - my $rds = Paws->service('EC2', caller => $lwp_caller, region => $options{region}); + my $vpn = Paws->service('EC2', caller => $lwp_caller, region => $options{region}); my $list_vpn = $vpn->DescribeVpnConnections(); foreach my $connection (@{$list_vpn->{VpnConnections}}) { my @name_tags; @@ -531,4 +555,4 @@ Proxy URL if any B. -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/cloud/aws/ec2/mode/spotactiveinstances.pm b/centreon-plugins/cloud/aws/ec2/mode/spotactiveinstances.pm new file mode 100644 index 000000000..1b544efe8 --- /dev/null +++ b/centreon-plugins/cloud/aws/ec2/mode/spotactiveinstances.pm @@ -0,0 +1,122 @@ +# +# 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 cloud::aws::ec2::mode::spotactiveinstances; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + ]; + $self->{maps_counters}->{global} = [ + { label => 'active', nlabel => 'ec2.spot.instances.active.count', set => { + key_values => [ { name => 'active' } ], + output_template => 'Active instances : %s', + perfdatas => [ + { label => 'active', value => 'active_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'healthy', nlabel => 'ec2.spot.instances.unhealthy.count', set => { + key_values => [ { name => 'healthy' } ], + output_template => 'Healthy instances : %s', + perfdatas => [ + { label => 'healthy', value => 'healthy_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'unhealthy', nlabel => 'ec2.spot.instances.unhealthy.count', set => { + key_values => [ { name => 'unhealthy' } ], + output_template => 'Unhealty instances : %s', + perfdatas => [ + { label => 'unhealthy', value => 'unhealthy_absolute', template => '%s', + min => 0 }, + ], + } + }, + ] +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'region:s' => { name => 'region' }, + 'spot-fleet-request-id:s' => { name => 'spot_fleet_request_id' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{region}) || $self->{option_results}->{region} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --region option."); + $self->{output}->option_exit(); + } + + if (!defined($self->{option_results}->{spot_fleet_request_id}) || $self->{option_results}->{spot_fleet_request_id} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --spot-fleet-request-id option."); + $self->{output}->option_exit(); + } + +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = { active => 0, healthy => 0, unhealthy => 0 }; + $self->{instances} = $options{custom}->ec2spot_get_active_instances_status(region => $self->{option_results}->{region}, spot_fleet_request_id => $self->{option_results}->{spot_fleet_request_id}); + + foreach my $instance_id (keys %{$self->{instances}}) { + $self->{global}->{active}++; + $self->{global}->{lc($self->{instances}->{$instance_id}->{health})}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check EC2 Spot active instance for a specific fleet + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Warning and Critical thresholds. You can use 'active', 'healthy', 'unhealthy' + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/ec2/plugin.pm b/centreon-plugins/cloud/aws/ec2/plugin.pm index e8eabedaa..a359235ba 100644 --- a/centreon-plugins/cloud/aws/ec2/plugin.pm +++ b/centreon-plugins/cloud/aws/ec2/plugin.pm @@ -31,16 +31,17 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( - 'asg-status' => 'cloud::aws::ec2::mode::asgstatus', - 'cpu' => 'cloud::aws::ec2::mode::cpu', - 'discovery' => 'cloud::aws::ec2::mode::discovery', - 'diskio' => 'cloud::aws::ec2::mode::diskio', - 'instances-status' => 'cloud::aws::ec2::mode::instancesstatus', - 'instances-types' => 'cloud::aws::ec2::mode::instancestypes', - 'list-asg' => 'cloud::aws::ec2::mode::listasg', - 'list-instances' => 'cloud::aws::ec2::mode::listinstances', - 'network' => 'cloud::aws::ec2::mode::network', - 'status' => 'cloud::aws::ec2::mode::status', + 'asg-status' => 'cloud::aws::ec2::mode::asgstatus', + 'cpu' => 'cloud::aws::ec2::mode::cpu', + 'discovery' => 'cloud::aws::ec2::mode::discovery', + 'diskio' => 'cloud::aws::ec2::mode::diskio', + 'instances-status' => 'cloud::aws::ec2::mode::instancesstatus', + 'instances-types' => 'cloud::aws::ec2::mode::instancestypes', + 'list-asg' => 'cloud::aws::ec2::mode::listasg', + 'list-instances' => 'cloud::aws::ec2::mode::listinstances', + 'network' => 'cloud::aws::ec2::mode::network', + 'status' => 'cloud::aws::ec2::mode::status', + 'spot-active-instances' => 'cloud::aws::ec2::mode::spotactiveinstances' ); $self->{custom_modes}{paws} = 'cloud::aws::custom::paws'; From 8e4b17c66a3098bdb60908d84070b991b0a0d500 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 20 Apr 2020 17:53:03 +0200 Subject: [PATCH 100/190] Fix #1950 --- .../network/freebox/restapi/custom/api.pm | 15 ++-- .../network/freebox/restapi/mode/dslusage.pm | 55 +++++++------- .../network/freebox/restapi/mode/netusage.pm | 68 ++++++++--------- .../network/freebox/restapi/mode/system.pm | 74 +++++++++---------- 4 files changed, 100 insertions(+), 112 deletions(-) diff --git a/centreon-plugins/network/freebox/restapi/custom/api.pm b/centreon-plugins/network/freebox/restapi/custom/api.pm index 4140b571b..2b19aa9cc 100644 --- a/centreon-plugins/network/freebox/restapi/custom/api.pm +++ b/centreon-plugins/network/freebox/restapi/custom/api.pm @@ -214,15 +214,18 @@ sub get_performance { $encoded = encode_json($json_request); }; if ($@) { - $self->{output}->add_option_msg(short_msg => "Cannot encode json request"); + $self->{output}->add_option_msg(short_msg => 'Cannot encode json request'); $self->{output}->option_exit(); } $self->settings(); - my $content = $self->{http}->request(url_path => '/api/' . $self->{freebox_api_version} . '/' . $options{path}, - method => 'POST', query_form_post => $encoded, - critical_status => '', warning_status => '', unknown_status => ''); + my $content = $self->{http}->request( + url_path => '/api/' . $self->{freebox_api_version} . '/' . $options{path}, + method => 'POST', query_form_post => $encoded, + critical_status => '', warning_status => '', unknown_status => '' + ); my $decoded = $self->manage_response(content => $content); + my ($datas, $total) = ({}, 0); foreach my $data (@{$decoded->{result}->{data}}) { foreach my $label (keys %$data) { @@ -233,9 +236,7 @@ sub get_performance { $total++; } - foreach (keys %$datas) { - $datas->{$_} /= $total; - } + $datas->{$_} = $datas->{$_} / $total / 100 foreach (keys %$datas); return $datas; } diff --git a/centreon-plugins/network/freebox/restapi/mode/dslusage.pm b/centreon-plugins/network/freebox/restapi/mode/dslusage.pm index 84856a3ca..42d6ea608 100644 --- a/centreon-plugins/network/freebox/restapi/mode/dslusage.pm +++ b/centreon-plugins/network/freebox/restapi/mode/dslusage.pm @@ -27,7 +27,7 @@ use warnings; sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'global', type => 0 }, ]; @@ -38,9 +38,9 @@ sub set_counters { output_template => 'Dsl available upload bandwidth : %.2f %s/s', output_change_bytes => 2, perfdatas => [ - { label => 'rate_up', value => 'rate_up_absolute', template => '%.2f', - unit => 'b/s', min => 0 }, - ], + { label => 'rate_up', value => 'rate_up_absolute', template => '%s', + unit => 'b/s', min => 0 } + ] } }, { label => 'rate-down', set => { @@ -48,9 +48,9 @@ sub set_counters { output_template => 'Dsl available download bandwidth : %.2f %s/s', output_change_bytes => 2, perfdatas => [ - { label => 'rate_down', value => 'rate_down_absolute', template => '%.2f', - unit => 'b/s', min => 0 }, - ], + { label => 'rate_down', value => 'rate_down_absolute', template => '%s', + unit => 'b/s', min => 0 } + ] } }, { label => 'snr-up', set => { @@ -59,8 +59,8 @@ sub set_counters { output_change_bytes => 2, perfdatas => [ { label => 'snr_up', value => 'snr_up_absolute', template => '%.2f', - unit => 'dB' }, - ], + unit => 'dB' } + ] } }, { label => 'snr-down', set => { @@ -69,10 +69,10 @@ sub set_counters { output_change_bytes => 2, perfdatas => [ { label => 'snr_down', value => 'snr_down_absolute', template => '%.2f', - unit => 'dB' }, - ], + unit => 'dB' } + ] } - }, + } ]; } @@ -80,21 +80,23 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - }); - + + $options{options}->add_options(arguments => { + }); + return $self; } sub manage_selection { my ($self, %options) = @_; - - my $result = $options{custom}->get_performance(db => 'dsl', path => 'rrd/'); - $result->{snr_up} *= 10 if (defined($result->{snr_up})); - $result->{snr_down} *= 10 if (defined($result->{snr_down})); - $self->{global} = { %{$result} }; + + $self->{global} = $options{custom}->get_performance(db => 'dsl', path => 'rrd/'); + $self->{global}->{snr_up} *= 10 if (defined($self->{global}->{snr_up})); + $self->{global}->{snr_down} *= 10 if (defined($self->{global}->{snr_down})); + $self->{global}->{rate_up} *= int($self->{global}->{rate_up} * 8) + if (defined($self->{global}->{rate_up})); + $self->{global}->{rate_down} *= int($self->{global}->{rate_down} * 8) + if (defined($self->{global}->{rate_down})); } 1; @@ -112,14 +114,9 @@ Check dsl usage. Only display some counters (regexp can be used). Example: --filter-counters='^rate-up$' -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. -Can be: 'rate-up', 'rate-down', 'snr-up', 'snr-down'. - -=item B<--critical-*> - -Threshold critical. +Thresholds. Can be: 'rate-up', 'rate-down', 'snr-up', 'snr-down'. =back diff --git a/centreon-plugins/network/freebox/restapi/mode/netusage.pm b/centreon-plugins/network/freebox/restapi/mode/netusage.pm index 765ce1840..f0bc001ad 100644 --- a/centreon-plugins/network/freebox/restapi/mode/netusage.pm +++ b/centreon-plugins/network/freebox/restapi/mode/netusage.pm @@ -27,9 +27,9 @@ use warnings; sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ - { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'global', type => 0, skipped_code => { -10 => 1 } } ]; $self->{maps_counters}->{global} = [ @@ -38,9 +38,9 @@ sub set_counters { output_template => 'Upload available bandwidth : %.2f %s/s', output_change_bytes => 2, perfdatas => [ - { label => 'bw_up', value => 'bw_up_absolute', template => '%.2f', - unit => 'b/s', min => 0 }, - ], + { label => 'bw_up', value => 'bw_up_absolute', template => '%s', + unit => 'b/s', min => 0 } + ] } }, { label => 'bw-down', set => { @@ -48,9 +48,9 @@ sub set_counters { output_template => 'Download available bandwidth : %.2f %s/s', output_change_bytes => 2, perfdatas => [ - { label => 'bw_down', value => 'bw_down_absolute', template => '%.2f', - unit => 'b/s', min => 0 }, - ], + { label => 'bw_down', value => 'bw_down_absolute', template => '%s', + unit => 'b/s', min => 0 } + ] } }, { label => 'rate-up', set => { @@ -58,9 +58,9 @@ sub set_counters { output_template => 'Upload rate : %.2f %s/s', output_change_bytes => 2, perfdatas => [ - { label => 'rate_up', value => 'rate_up_absolute', template => '%.2f', - unit => 'b/s', min => 0 }, - ], + { label => 'rate_up', value => 'rate_up_absolute', template => '%s', + unit => 'b/s', min => 0 } + ] } }, { label => 'rate-down', set => { @@ -68,9 +68,9 @@ sub set_counters { output_template => 'Download rate : %.2f %s/s', output_change_bytes => 2, perfdatas => [ - { label => 'rate_down', value => 'rate_down_absolute', template => '%.2f', - unit => 'b/s', min => 0 }, - ], + { label => 'rate_down', value => 'rate_down_absolute', template => '%s', + unit => 'b/s', min => 0 } + ] } }, { label => 'vpn-rate-up', set => { @@ -78,21 +78,21 @@ sub set_counters { output_template => 'Vpn client upload rate : %.2f %s/s', output_change_bytes => 2, perfdatas => [ - { label => 'vpn_rate_up', value => 'vpn_rate_up_absolute', template => '%.2f', - unit => 'b/s', min => 0 }, - ], + { label => 'vpn_rate_up', value => 'vpn_rate_up_absolute', template => '%s', + unit => 'b/s', min => 0 } + ] } }, - { label => 'vpn-rate-down', set => { + { label => 'vpn-rate-down', set => { key_values => [ { name => 'vpn_rate_down' } ], output_template => 'Vpn client download rate : %.2f %s/s', output_change_bytes => 2, perfdatas => [ - { label => 'vpn_rate_down', value => 'vpn_rate_down_absolute', template => '%.2f', - unit => 'b/s', min => 0 }, - ], + { label => 'vpn_rate_down', value => 'vpn_rate_down_absolute', template => '%s', + unit => 'b/s', min => 0 } + ] } - }, + } ]; } @@ -100,19 +100,18 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - }); - + + $options{options}->add_options(arguments => { + }); + return $self; } sub manage_selection { my ($self, %options) = @_; - - my $result = $options{custom}->get_performance(db => 'net', path => 'rrd/'); - $self->{global} = { %{$result} }; + + $self->{global} = $options{custom}->get_performance(db => 'net', path => 'rrd/'); + $self->{global}->{$_} = int($self->{global}->{$_} * 8) foreach (keys %{$self->{global}}); } 1; @@ -130,14 +129,9 @@ Check network usage. Only display some counters (regexp can be used). Example: --filter-counters='^bw-up$' -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. -Can be: 'bw-up', 'bw-down', 'rate-up', 'rate-down', 'vpn-rate-up', 'vpn-rate-down'. - -=item B<--critical-*> - -Threshold critical. +Thresholds. Can be: 'bw-up', 'bw-down', 'rate-up', 'rate-down', 'vpn-rate-up', 'vpn-rate-down'. =back diff --git a/centreon-plugins/network/freebox/restapi/mode/system.pm b/centreon-plugins/network/freebox/restapi/mode/system.pm index 505985b88..a57c43ee1 100644 --- a/centreon-plugins/network/freebox/restapi/mode/system.pm +++ b/centreon-plugins/network/freebox/restapi/mode/system.pm @@ -28,20 +28,20 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'global', type => 0 }, { name => 'wifi', type => 1, cb_prefix_output => 'prefix_wifi_output', message_multiple => 'All wifis are ok' } ]; - + $self->{maps_counters}->{global} = [ { label => 'temperature-cpum', set => { key_values => [ { name => 'temp_cpum' } ], output_template => 'Temperature cpum : %s C', perfdatas => [ { label => 'temp_cpum', value => 'temp_cpum_absolute', template => '%s', - unit => 'C' }, - ], + unit => 'C' } + ] } }, { label => 'temperature-cpub', set => { @@ -49,8 +49,8 @@ sub set_counters { output_template => 'Temperature cpub : %s C', perfdatas => [ { label => 'temp_cpub', value => 'temp_cpub_absolute', template => '%s', - unit => 'C' }, - ], + unit => 'C' } + ] } }, { label => 'temperature-switch', set => { @@ -58,8 +58,8 @@ sub set_counters { output_template => 'Temperature switch : %s C', perfdatas => [ { label => 'temp_sw', value => 'temp_sw_absolute', template => '%s', - unit => 'C' }, - ], + unit => 'C' } + ] } }, { label => 'fan-speed', set => { @@ -67,8 +67,8 @@ sub set_counters { output_template => 'fan speed : %s rpm', perfdatas => [ { label => 'fan_rpm', value => 'fan_rpm_absolute', template => '%s', - min => 0, unit => 'rpm' }, - ], + min => 0, unit => 'rpm' } + ] } }, { label => 'disk-status', threshold => 0, set => { @@ -76,10 +76,9 @@ sub set_counters { closure_custom_calc => $self->can('custom_disk_status_calc'), closure_custom_output => $self->can('custom_disk_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold } - }, - + } ]; $self->{maps_counters}->{wifi} = [ @@ -88,17 +87,16 @@ sub set_counters { closure_custom_calc => $self->can('custom_wifi_status_calc'), closure_custom_output => $self->can('custom_wifi_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold } - }, + } ]; } sub custom_disk_status_output { my ($self, %options) = @_; - my $msg = 'Disk status : ' . $self->{result_values}->{status}; - return $msg; + return 'Disk status : ' . $self->{result_values}->{status}; } sub custom_disk_status_calc { @@ -110,9 +108,8 @@ sub custom_disk_status_calc { sub custom_wifi_status_output { my ($self, %options) = @_; - my $msg = "Wifi '" . $self->{result_values}->{display} . "' status : " . $self->{result_values}->{status}; - return $msg; + return "Wifi '" . $self->{result_values}->{display} . "' status : " . $self->{result_values}->{status}; } sub custom_wifi_status_calc { @@ -127,15 +124,14 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning-wifi-status:s" => { name => 'warning_wifi_status', default => '%{status} =~ /bad_param/i' }, - "critical-wifi-status:s" => { name => 'critical_wifi_status', default => '%{status} =~ /failed/i' }, - "warning-disk-status:s" => { name => 'warning_disk_status', default => '' }, - "critical-disk-status:s" => { name => 'critical_disk_status', default => '%{status} =~ /error/i' }, - }); - + + $options{options}->add_options(arguments => { + 'warning-wifi-status:s' => { name => 'warning_wifi_status', default => '%{status} =~ /bad_param/i' }, + 'critical-wifi-status:s' => { name => 'critical_wifi_status', default => '%{status} =~ /failed/i' }, + 'warning-disk-status:s' => { name => 'warning_disk_status', default => '' }, + 'critical-disk-status:s' => { name => 'critical_disk_status', default => '%{status} =~ /error/i' }, + }); + return $self; } @@ -143,18 +139,23 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $self->change_macros(macros => ['warning_wifi_status', 'critical_wifi_status', 'warning_disk_status', 'critical_disk_status']); + $self->change_macros( + macros => [ + 'warning_wifi_status', 'critical_wifi_status', + 'warning_disk_status', 'critical_disk_status' + ] + ); } sub manage_selection { my ($self, %options) = @_; - + my $result = $options{custom}->get_data(path => 'system/'); $self->{global} = { %{$result} }; - + $result = $options{custom}->get_data(path => 'wifi/ap/'); $self->{wifi} = {}; - + $result = [$result] if (ref($result) ne 'ARRAY'); foreach (@$result) { $self->{wifi}->{$_->{id}} = { @@ -199,14 +200,9 @@ Can used special variables like: %{status} Set critical threshold for disk status (Default: '%{status} =~ /error/i'). Can used special variables like: %{status} -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. -Can be: 'temperature-cpum', 'temperature-cpub', 'temperature-switch', 'fan-speed'. - -=item B<--critical-*> - -Threshold critical. +Thresholds. Can be: 'temperature-cpum', 'temperature-cpub', 'temperature-switch', 'fan-speed'. =back From 9fa7e90d7d413d60b36e75abfe74aff2a676306f Mon Sep 17 00:00:00 2001 From: thibaults-centreon Date: Mon, 20 Apr 2020 19:37:10 +0200 Subject: [PATCH 101/190] add(plugin): Mulesoft Restapi --- .../apps/mulesoft/restapi/custom/api.pm | 349 ++++++++++++++++++ .../mulesoft/restapi/mode/applications.pm | 198 ++++++++++ .../mulesoft/restapi/mode/listapplications.pm | 107 ++++++ .../apps/mulesoft/restapi/plugin.pm | 50 +++ .../centreon/plugins/script_custom.pm | 2 +- .../centreon/plugins/script_sql.pm | 2 +- 6 files changed, 706 insertions(+), 2 deletions(-) create mode 100644 centreon-plugins/apps/mulesoft/restapi/custom/api.pm create mode 100644 centreon-plugins/apps/mulesoft/restapi/mode/applications.pm create mode 100644 centreon-plugins/apps/mulesoft/restapi/mode/listapplications.pm create mode 100644 centreon-plugins/apps/mulesoft/restapi/plugin.pm diff --git a/centreon-plugins/apps/mulesoft/restapi/custom/api.pm b/centreon-plugins/apps/mulesoft/restapi/custom/api.pm new file mode 100644 index 000000000..b8f98d509 --- /dev/null +++ b/centreon-plugins/apps/mulesoft/restapi/custom/api.pm @@ -0,0 +1,349 @@ +# +# 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::mulesoft::restapi::custom::api; + +use strict; +use warnings; +use DateTime; +use centreon::plugins::http; +use centreon::plugins::statefile; +use JSON::XS; +use URI::Encode; +use Digest::MD5 qw(md5_hex); + +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' }, + 'environment-id:s' => { name => 'environment_id' }, + 'organization-id:s' => { name => 'organization_id' }, + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port' }, + 'proto:s' => { name => 'proto' }, + 'timeout:s' => { name => 'timeout' }, + 'reload-cache-time:s' => { name => 'reload_cache_time' }, + 'authent-endpoint:s' => { name => 'authent_endpoint'}, + 'monitoring-endpoint:s' => { name => 'monitoring_endpoint'}, + }); + } + $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); + $self->{cache} = centreon::plugins::statefile->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} : 'eu1.anypoint.mulesoft.com'; + $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443; + $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->{authent_endpoint} = (defined($self->{option_results}->{authent_endpoint})) ? $self->{option_results}->{authent_endpoint} : '/accounts/login'; + $self->{monitoring_endpoint} = (defined($self->{option_results}->{monitoring_endpoint})) ? $self->{option_results}->{monitoring_endpoint} : '/hybrid/api/v1'; + $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->{environment_id} = (defined($self->{option_results}->{environment_id})) ? $self->{option_results}->{environment_id} : ''; + $self->{organization_id} = (defined($self->{option_results}->{organization_id})) ? $self->{option_results}->{organization_id} : ''; + $self->{reload_cache_time} = (defined($self->{option_results}->{reload_cache_time})) ? $self->{option_results}->{reload_cache_time} : 180; + $self->{cache}->check_options(option_results => $self->{option_results}); + + if (!defined($self->{environment_id}) || $self->{environment_id} eq '' || !defined($self->{organization_id}) || $self->{organization_id} eq '' ) { + $self->{output}->add_option_msg(short_msg => "--environment-id and --organization-id must be set"); + $self->{output}->option_exit(); + } + if (!defined($self->{api_username}) || $self->{api_username} eq '' || !defined($self->{api_password}) || $self->{api_password} eq '' ) { + $self->{output}->add_option_msg(short_msg => "--api-username and --api-password must be set"); + $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}; + $self->{option_results}->{warning_status} = ''; + $self->{option_results}->{critical_status} = ''; + $self->{option_results}->{unknown_status} = '%{http_code} < 200 or %{http_code} > 400'; +} + +sub settings { + my ($self, %options) = @_; + + $self->build_options_for_httplib(); + $self->{http}->add_header(key => 'Accept', value => 'application/json'); + $self->{http}->add_header(key => 'Content-Type', value => $options{content_type}); + $self->{http}->add_header(key => 'Authorization', value => 'Bearer ' . $self->{access_token}) if (defined($self->{access_token})); + $self->{http}->add_header(key => 'X-ANYPNT-ENV-ID', value => $self->{environment_id}) if (defined $options{environment_header}); + $self->{http}->add_header(key => 'X-ANYPNT-ORG-ID', value => $self->{organization_id}) if (defined $options{organization_header}); + $self->{http}->set_options(%{$self->{option_results}}); +} + +sub get_access_token { + my ($self, %options) = @_; + + my $has_cache_file = $options{statefile}->read(statefile => 'mulesoft_api_' . md5_hex($self->{hostname}) . '_' . md5_hex($self->{api_username})); + my $expires_on = $options{statefile}->get(name => 'expires_on'); + my $access_token = $options{statefile}->get(name => 'access_token'); + if ( $has_cache_file == 0 || !defined($access_token) || (($expires_on - time()) < 10) ) { + #my ($username, $password) = ( $self->{api_username}, $self->{api_password} ); + my $login = { username => $self->{api_username}, password => $self->{api_password} }; + my $post_json = JSON::XS->new->utf8->encode($login); + + $self->settings(content_type => 'application/json'); + + my $content = $self->{http}->request( + method => 'POST', + query_form_post => $post_json, + url_path => $self->{authent_endpoint} + ); + + if (!defined($content) || $content eq '') { + $self->{output}->add_option_msg(short_msg => "Authentication endpoint 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}->output_add(long_msg => $content, debug => 1); + $self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)"); + $self->{output}->option_exit(); + } + if (defined($decoded->{error_code})) { + $self->{output}->output_add(long_msg => "Error message : " . $decoded->{error}, debug => 1); + $self->{output}->add_option_msg(short_msg => "Authentication endpoint returns error code '" . $decoded->{error_code} . "' (add --debug option for detailed message)"); + $self->{output}->option_exit(); + } + + $access_token = $decoded->{access_token}; + my $datas = { last_timestamp => time(), access_token => $decoded->{access_token}, expires_on => time() + 3600 }; + $options{statefile}->write(data => $datas); + } + + return $access_token; +} + +sub request_api { + my ($self, %options) = @_; + + if (!defined($self->{access_token})) { + $self->{access_token} = $self->get_access_token(statefile => $self->{cache}); + } + + $self->settings(content_type => 'application/x-www-form-urlencoded', environment_header => 1, organization_header => 1); + + $self->{output}->output_add(long_msg => "URL: '" . $self->{proto} . '://' . $self->{hostname} . ':' . $self->{port} . + $options{url_path} . "'", debug => 1); + + my $content = $self->{http}->request(%options); + + 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}->output_add(long_msg => $content, debug => 1); + $self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)"); + $self->{output}->option_exit(); + } + if (defined($decoded->{error_code})) { + $self->{output}->output_add(long_msg => "Error message : " . $decoded->{error}, debug => 1); + $self->{output}->add_option_msg(short_msg => "API returns error code '" . $decoded->{error_code} . "' (add --debug option for detailed message)"); + $self->{output}->option_exit(); + } + + return $decoded; +} + +sub list_applications { + my ($self, %options) = @_; + + my $url_path = $self->{monitoring_endpoint} . '/applications'; + my $response = $self->request_api(method => 'GET', url_path => $url_path); + + return $response->{data}; +} + +sub get_application_status { + my ($self, %options) = @_; + + my $url_path = $self->{monitoring_endpoint} . '/applications/' . $options{applicationId}; + my $response = $self->request_api(method => 'GET', url_path => $url_path); + + return $response->{data}; +} + +sub get_application_metrics { + my ($self, %options) = @_; + + my $url_path = $self->{monitoring_endpoint} . '/applications/flows/' . $options{applicationId}; + my $response = $self->request_api(method => 'GET', url_path => $url_path); + + return $response->{data}; +} + +sub list_servers { + my ($self, %options) = @_; + + my $url_path = '/servers'; + my $response = $self->request_api(method => 'GET', url_path => $url_path); + + return $response->{servers}; +} + +sub get_server_status { + my ($self, %options) = @_; + + my $url_path = $self->{monitoring_endpoint} . '/servers/' . $options{serverId}; + my $response = $self->request_api(method => 'GET', url_path => $url_path); + + return $response->{server}; +} + + +sub cache_hosts { + my ($self, %options) = @_; + + $self->{cache_hosts} = centreon::plugins::statefile->new(%options); + $self->{cache_hosts}->check_options(option_results => $self->{option_results}); + my $has_cache_file = $self->{cache_hosts}->read(statefile => 'cache_ovirt_hosts_' . md5_hex($self->{hostname}) . '_' . md5_hex($self->{api_username})); + my $timestamp_cache = $self->{cache_hosts}->get(name => 'last_timestamp'); + my $hosts = $self->{cache_hosts}->get(name => 'hosts'); + if ($has_cache_file == 0 || !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{reload_cache_time}) * 60))) { + $hosts = []; + my $datas = { last_timestamp => time(), hosts => $hosts }; + my $list = $self->list_hosts(); + foreach (@{$list}) { + push @{$hosts}, { id => $_->{id}, name => $_->{name} }; + } + $self->{cache_hosts}->write(data => $datas); + } + + return $hosts; +} + +1; + +__END__ + +=head1 NAME + +Mulesoft Rest API + +=head1 REST API OPTIONS + +Mulesoft Rest API + +=over 8 + +=item B<--hostname> + +Mulesoft API hostname (Default: anypoint.mulesoft.com). + +=item B<--port> + +Port used (Default: 443) + +=item B<--proto> + +Specify https if needed (Default: 'https') + +=item B<--api-username> + +Mulesoft API username (mandatory). + +=item B<--api-password> + +Mulesoft API password (mandatory). + +=item B<--environment-id> + +Mulesoft API Environment ID (mandatory). + +=item B<--organization-id> + +Mulesoft API Organization ID (mandatory). + +=item B<--timeout> + +Set timeout in seconds (Default: 10). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/apps/mulesoft/restapi/mode/applications.pm b/centreon-plugins/apps/mulesoft/restapi/mode/applications.pm new file mode 100644 index 000000000..31f8840c7 --- /dev/null +++ b/centreon-plugins/apps/mulesoft/restapi/mode/applications.pm @@ -0,0 +1,198 @@ +# +# 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::mulesoft::restapi::mode::applications; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use Data::Dumper; + +sub custom_status_output { + my ($self, %options) = @_; + return my $msg = sprintf('Id: %s, Status: %s', $self->{result_values}->{id}, $self->{result_values}->{status}); +} + +sub custom_status_calc { + my ($self, %options) = @_; + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{id} = $options{new_datas}->{$self->{instance} . '_id'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, + { name => 'applications', type => 1, cb_prefix_output => 'prefix_application_output', + message_multiple => 'All applications are ok' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total', nlabel => 'mulesoft.applications.total.count', set => { + key_values => [ { name => 'total' } ], + output_template => "Total : %s", + perfdatas => [ + { value => 'total_absolute', template => '%d', min => 0 }, + ], + } + }, + { label => 'started', nlabel => 'mulesoft.applications.status.started.count', set => { + key_values => [ { name => 'started' } ], + output_template => "Started : %s", + perfdatas => [ + { value => 'started_absolute', template => '%d', min => 0 }, + ], + } + }, + { label => 'stopped', nlabel => 'mulesoft.applications.status.stopped.count', set => { + key_values => [ { name => 'stopped' } ], + output_template => "Stopped : %s", + perfdatas => [ + { value => 'stopped_absolute', template => '%d', min => 0 }, + ], + } + }, + { label => 'failed', nlabel => 'mulesoft.applications.status.failed.count', set => { + key_values => [ { name => 'failed' } ], + output_template => "Failed : %s", + perfdatas => [ + { value => 'failed_absolute', template => '%d', min => 0 }, + ], + } + } + ]; + + $self->{maps_counters}->{applications} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'id' }, { name => 'status' }, { name => 'name'}, { name => 'display' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-name:s" => { name => 'filter_name' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} ne "STARTED"' }, + #"critical-status:s" => { name => 'critical_status', default => '' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return "Total applications "; +} + +sub prefix_application_output { + my ($self, %options) = @_; + + return "Application '" . $options{instance_value}->{name} . "' "; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = { started => 0, stopped => 0, failed => 0 }; + $self->{applications} = {}; + my $result = $options{custom}->list_applications(); + #print Dumper($result); + foreach my $application (@{$result}) { + next if ( defined($self->{option_results}->{filter_name}) + && $self->{option_results}->{filter_name} ne '' + && $application->{name} !~ /$self->{option_results}->{filter_name}/ ); + $self->{applications}->{$application} = { + display => $application, + id => $application->{id}, + name => $application->{name}, + status => $application->{lastReportedStatus}, + }; + $self->{global}->{started}++ if $application->{lastReportedStatus} =~ m/STARTED/; + $self->{global}->{stopped}++ if $application->{lastReportedStatus} =~ m/STOPPED/; + $self->{global}->{failed}++ if $application->{lastReportedStatus} =~ m/FAILED/; + #print Dumper($self->{applications}->{application}); + } + if (scalar(keys %{$self->{applications}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No application found."); + $self->{output}->option_exit(); + } + $self->{global}->{total} = scalar (keys %{$self->{applications}}); +} + +1; + +__END__ + +=head1 MODE + +Check Mulesoft Applications status. + +Example: +perl centreon_plugins.pl --plugin=apps::mulesoft::restapi::plugin --mode=applications +--environment-id='1234abc-56de-78fg-90hi-1234abcdefg' --organization-id='1234abcd-56ef-78fg-90hi-1234abcdefg' +--api-username='myapiuser' --api-password='myapipassword' --verbose + +More information on'https://anypoint.mulesoft.com/exchange/portals/anypoint-platform/'. + +=over 8 + +=item B<--filter-name> + +Filter by application name (Regexp can be used). +Example: --filter-name='^application1$' + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used. +Typical syntax: --warning-status=%{status} ne "STARTED" + +=item B<--critical-status> + +Set warning threshold for status (Default: ''). +Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used. +Typical syntax: --critical-status=%{status} ~= m/FAILED/" + + +=back + +=cut diff --git a/centreon-plugins/apps/mulesoft/restapi/mode/listapplications.pm b/centreon-plugins/apps/mulesoft/restapi/mode/listapplications.pm new file mode 100644 index 000000000..0e2b493aa --- /dev/null +++ b/centreon-plugins/apps/mulesoft/restapi/mode/listapplications.pm @@ -0,0 +1,107 @@ +# +# 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::mulesoft::restapi::mode::listapplications; + +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 => { + "filter-name:s" => { name => 'filter_name' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{data} = $options{custom}->list_applications(); +} + +sub run { + my ($self, %options) = @_; + + my $result = $options{custom}->list_applications(); + foreach my $application (@{$result}) { + #print $application->{id}; + next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' + && $application->{name} !~ /$self->{option_results}->{filter_name}/); + + $self->{output}->output_add(long_msg => sprintf("[id = %s][name = %s][status = %s]", + $application->{id}, + $application->{name}, + $application->{lastReportedStatus})); + } + + $self->{output}->output_add(severity => 'OK', + short_msg => 'Mulesoft Applications:'); + $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 => ['id', 'name', 'status']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $application (@{$self->{data}}) { + $self->{output}->add_disco_entry( + id => $application->{id}, + name => $application->{name}, + status => $application->{lastReportedStatus}, + ); + } +} + +1; + +__END__ + +=head1 MODE + +List Mulesoft applications. + +=over 8 + +=item B<--filter-name> + +Filter host name (Can be a regexp). + +=back + +=cut diff --git a/centreon-plugins/apps/mulesoft/restapi/plugin.pm b/centreon-plugins/apps/mulesoft/restapi/plugin.pm new file mode 100644 index 000000000..9abef19bd --- /dev/null +++ b/centreon-plugins/apps/mulesoft/restapi/plugin.pm @@ -0,0 +1,50 @@ +# +# 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::mulesoft::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} = '1.0'; + %{$self->{modes}} = ( + 'applications' => 'apps::mulesoft::restapi::mode::applications', + 'listapplications' => 'apps::mulesoft::restapi::mode::listapplications' + ); + + $self->{custom_modes}{restapi} = 'apps::mulesoft::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Mulesoft components using API. + +=cut diff --git a/centreon-plugins/centreon/plugins/script_custom.pm b/centreon-plugins/centreon/plugins/script_custom.pm index ca1f8aa63..636e1ff3b 100644 --- a/centreon-plugins/centreon/plugins/script_custom.pm +++ b/centreon-plugins/centreon/plugins/script_custom.pm @@ -294,7 +294,7 @@ List available custom modes. =item B<--multiple> -Multiple custom mode objects (some mode needs it). +Multiple custom mode objects (required by some specific modes) =item B<--pass-manager> diff --git a/centreon-plugins/centreon/plugins/script_sql.pm b/centreon-plugins/centreon/plugins/script_sql.pm index 383c70c51..e07be4f8d 100644 --- a/centreon-plugins/centreon/plugins/script_sql.pm +++ b/centreon-plugins/centreon/plugins/script_sql.pm @@ -291,7 +291,7 @@ List available sql modes. =item B<--multiple> -Multiple database connections (some mode needs it). +Multiple database connections (required by some specific modes). =item B<--pass-manager> From 36c2542cf206cf7c786959755391c2b7e74fbdb8 Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Mon, 20 Apr 2020 20:08:37 +0200 Subject: [PATCH 102/190] remove carriage return from edge description --- .../cloud/vmware/velocloud/restapi/mode/discovery.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/centreon-plugins/cloud/vmware/velocloud/restapi/mode/discovery.pm b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/discovery.pm index 4cd26f4b2..1f2e14110 100644 --- a/centreon-plugins/cloud/vmware/velocloud/restapi/mode/discovery.pm +++ b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/discovery.pm @@ -63,6 +63,7 @@ sub run { $edge{device_family} = $edge->{deviceFamily}; $edge{name} = $edge->{name}; $edge{description} = $edge->{description}; + $edge{description} =~ s/\n//g if (defined($edge{description})); $edge{edge_state} = $edge->{edgeState}; $edge{service_state} = $edge->{serviceState}; $edge{ha_state} = $edge->{haState}; From ea42a62eaa130a383fe0eb62d910a98fb313a2f3 Mon Sep 17 00:00:00 2001 From: Matthieu Kermagoret Date: Tue, 21 Apr 2020 09:20:09 +0200 Subject: [PATCH 103/190] limit build history to 50 items. --- centreon-plugins/Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/centreon-plugins/Jenkinsfile b/centreon-plugins/Jenkinsfile index 769994fd1..b80a35c3b 100644 --- a/centreon-plugins/Jenkinsfile +++ b/centreon-plugins/Jenkinsfile @@ -1,3 +1,5 @@ +properties([buildDiscarder(logRotator(numToKeepStr: '50'))]) + stage('Source') { node { sh 'setup_centreon_build.sh' From 7240f4905e00086004a8e3a7f7709b49f6e8e45f Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 21 Apr 2020 10:48:36 +0200 Subject: [PATCH 104/190] add voice-call for cisco vg --- centreon-plugins/network/cisco/vg/snmp/plugin.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/centreon-plugins/network/cisco/vg/snmp/plugin.pm b/centreon-plugins/network/cisco/vg/snmp/plugin.pm index 8ba0607cd..95a6eb0ee 100644 --- a/centreon-plugins/network/cisco/vg/snmp/plugin.pm +++ b/centreon-plugins/network/cisco/vg/snmp/plugin.pm @@ -34,6 +34,7 @@ sub new { 'interfaces' => 'snmp_standard::mode::interfaces', 'isdn-usage' => 'snmp_standard::mode::isdnusage', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'voice-call' => 'centreon::common::cisco::standard::snmp::mode::voicecall' ); return $self; From 035f1bb84791ef3ca280ed202089b7bb9c1040a7 Mon Sep 17 00:00:00 2001 From: thibaults-centreon Date: Tue, 21 Apr 2020 11:00:30 +0200 Subject: [PATCH 105/190] enh(plugin): Mulesoft cleanup and servers mode --- .../apps/mulesoft/restapi/custom/api.pm | 15 +- .../mulesoft/restapi/mode/applications.pm | 63 +++--- .../mulesoft/restapi/mode/listapplications.pm | 8 +- .../apps/mulesoft/restapi/mode/listservers.pm | 106 ++++++++++ .../apps/mulesoft/restapi/mode/servers.pm | 183 ++++++++++++++++++ .../apps/mulesoft/restapi/plugin.pm | 6 +- 6 files changed, 326 insertions(+), 55 deletions(-) create mode 100644 centreon-plugins/apps/mulesoft/restapi/mode/listservers.pm create mode 100644 centreon-plugins/apps/mulesoft/restapi/mode/servers.pm diff --git a/centreon-plugins/apps/mulesoft/restapi/custom/api.pm b/centreon-plugins/apps/mulesoft/restapi/custom/api.pm index b8f98d509..2b1a2f4f5 100644 --- a/centreon-plugins/apps/mulesoft/restapi/custom/api.pm +++ b/centreon-plugins/apps/mulesoft/restapi/custom/api.pm @@ -245,22 +245,13 @@ sub get_application_status { return $response->{data}; } -sub get_application_metrics { - my ($self, %options) = @_; - - my $url_path = $self->{monitoring_endpoint} . '/applications/flows/' . $options{applicationId}; - my $response = $self->request_api(method => 'GET', url_path => $url_path); - - return $response->{data}; -} - sub list_servers { my ($self, %options) = @_; - my $url_path = '/servers'; + my $url_path = $self->{monitoring_endpoint} . '/servers/'; my $response = $self->request_api(method => 'GET', url_path => $url_path); - return $response->{servers}; + return $response->{data}; } sub get_server_status { @@ -269,7 +260,7 @@ sub get_server_status { my $url_path = $self->{monitoring_endpoint} . '/servers/' . $options{serverId}; my $response = $self->request_api(method => 'GET', url_path => $url_path); - return $response->{server}; + return $response->{data}; } diff --git a/centreon-plugins/apps/mulesoft/restapi/mode/applications.pm b/centreon-plugins/apps/mulesoft/restapi/mode/applications.pm index 31f8840c7..890e75979 100644 --- a/centreon-plugins/apps/mulesoft/restapi/mode/applications.pm +++ b/centreon-plugins/apps/mulesoft/restapi/mode/applications.pm @@ -25,7 +25,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); -use Data::Dumper; sub custom_status_output { my ($self, %options) = @_; @@ -44,52 +43,43 @@ sub set_counters { $self->{maps_counters_type} = [ { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, - { name => 'applications', type => 1, cb_prefix_output => 'prefix_application_output', - message_multiple => 'All applications are ok' }, + { name => 'applications', type => 1, cb_prefix_output => 'prefix_application_output', message_multiple => 'All applications are ok' } ]; $self->{maps_counters}->{global} = [ { label => 'total', nlabel => 'mulesoft.applications.total.count', set => { - key_values => [ { name => 'total' } ], - output_template => "Total : %s", - perfdatas => [ - { value => 'total_absolute', template => '%d', min => 0 }, - ], + key_values => [ { name => 'total' } ], + output_template => "Total : %s", + perfdatas => [ { value => 'total_absolute', template => '%d', min => 0 } ], } }, { label => 'started', nlabel => 'mulesoft.applications.status.started.count', set => { - key_values => [ { name => 'started' } ], - output_template => "Started : %s", - perfdatas => [ - { value => 'started_absolute', template => '%d', min => 0 }, - ], + key_values => [ { name => 'started' } ], + output_template => "Started : %s", + perfdatas => [ { value => 'started_absolute', template => '%d', min => 0 } ] } }, { label => 'stopped', nlabel => 'mulesoft.applications.status.stopped.count', set => { - key_values => [ { name => 'stopped' } ], - output_template => "Stopped : %s", - perfdatas => [ - { value => 'stopped_absolute', template => '%d', min => 0 }, - ], + key_values => [ { name => 'stopped' } ], + output_template => "Stopped : %s", + perfdatas => [ { value => 'stopped_absolute', template => '%d', min => 0 } ] } }, { label => 'failed', nlabel => 'mulesoft.applications.status.failed.count', set => { - key_values => [ { name => 'failed' } ], - output_template => "Failed : %s", - perfdatas => [ - { value => 'failed_absolute', template => '%d', min => 0 }, - ], + key_values => [ { name => 'failed' } ], + output_template => "Failed : %s", + perfdatas => [ { value => 'failed_absolute', template => '%d', min => 0 } ] } } ]; $self->{maps_counters}->{applications} = [ { label => 'status', threshold => 0, set => { - key_values => [ { name => 'id' }, { name => 'status' }, { name => 'name'}, { name => 'display' } ], - closure_custom_calc => $self->can('custom_status_calc'), - closure_custom_output => $self->can('custom_status_output'), - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + key_values => [ { name => 'id' }, { name => 'status' }, { name => 'name'}, { name => 'display' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, } }, ]; @@ -101,10 +91,9 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} ne "STARTED"' }, - #"critical-status:s" => { name => 'critical_status', default => '' }, + "filter-name:s" => { name => 'filter_name' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '' } }); return $self; @@ -135,7 +124,7 @@ sub manage_selection { $self->{global} = { started => 0, stopped => 0, failed => 0 }; $self->{applications} = {}; my $result = $options{custom}->list_applications(); - #print Dumper($result); + foreach my $application (@{$result}) { next if ( defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' @@ -145,16 +134,18 @@ sub manage_selection { id => $application->{id}, name => $application->{name}, status => $application->{lastReportedStatus}, - }; + }; + $self->{global}->{started}++ if $application->{lastReportedStatus} =~ m/STARTED/; $self->{global}->{stopped}++ if $application->{lastReportedStatus} =~ m/STOPPED/; $self->{global}->{failed}++ if $application->{lastReportedStatus} =~ m/FAILED/; - #print Dumper($self->{applications}->{application}); } + if (scalar(keys %{$self->{applications}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No application found."); $self->{output}->option_exit(); } + $self->{global}->{total} = scalar (keys %{$self->{applications}}); } @@ -164,7 +155,7 @@ __END__ =head1 MODE -Check Mulesoft Applications status. +Check Mulesoft Anypoint Applications status. Example: perl centreon_plugins.pl --plugin=apps::mulesoft::restapi::plugin --mode=applications diff --git a/centreon-plugins/apps/mulesoft/restapi/mode/listapplications.pm b/centreon-plugins/apps/mulesoft/restapi/mode/listapplications.pm index 0e2b493aa..2b7641bec 100644 --- a/centreon-plugins/apps/mulesoft/restapi/mode/listapplications.pm +++ b/centreon-plugins/apps/mulesoft/restapi/mode/listapplications.pm @@ -53,7 +53,6 @@ sub run { my $result = $options{custom}->list_applications(); foreach my $application (@{$result}) { - #print $application->{id}; next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $application->{name} !~ /$self->{option_results}->{filter_name}/); @@ -63,8 +62,7 @@ sub run { $application->{lastReportedStatus})); } - $self->{output}->output_add(severity => 'OK', - short_msg => 'Mulesoft Applications:'); + $self->{output}->output_add(severity => 'OK', short_msg => 'Mulesoft Anypoint Applications:'); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -94,13 +92,13 @@ __END__ =head1 MODE -List Mulesoft applications. +List Mulesoft Anypoint applications. =over 8 =item B<--filter-name> -Filter host name (Can be a regexp). +Filter application name (Can be a regexp). =back diff --git a/centreon-plugins/apps/mulesoft/restapi/mode/listservers.pm b/centreon-plugins/apps/mulesoft/restapi/mode/listservers.pm new file mode 100644 index 000000000..e774d5b2d --- /dev/null +++ b/centreon-plugins/apps/mulesoft/restapi/mode/listservers.pm @@ -0,0 +1,106 @@ +# +# Copyright 2020 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and server 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::mulesoft::restapi::mode::listservers; + +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 => { + "filter-name:s" => { name => 'filter_name' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{data} = $options{custom}->list_servers(); +} + +sub run { + my ($self, %options) = @_; + + my $result = $options{custom}->list_servers(); + foreach my $server (@{$result}) { + next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' + && $server->{name} !~ /$self->{option_results}->{filter_name}/); + + $self->{output}->output_add(long_msg => sprintf("[id = %s][name = %s][status = %s]", + $server->{id}, + $server->{name}, + $server->{status} + )); + } + + $self->{output}->output_add(severity => 'OK', short_msg => 'Mulesoft Anypoint Servers:'); + $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 => ['id', 'name', 'status']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $server (@{$self->{data}}) { + $self->{output}->add_disco_entry( + id => $server->{id}, + name => $server->{name}, + status => $server->{status}, + ); + } +} + +1; + +__END__ + +=head1 MODE + +List Mulesoft Anypoint Servers. + +=over 8 + +=item B<--filter-name> + +Filter server name (Can be a regexp). + +=back + +=cut diff --git a/centreon-plugins/apps/mulesoft/restapi/mode/servers.pm b/centreon-plugins/apps/mulesoft/restapi/mode/servers.pm new file mode 100644 index 000000000..e84f937e6 --- /dev/null +++ b/centreon-plugins/apps/mulesoft/restapi/mode/servers.pm @@ -0,0 +1,183 @@ +# +# Copyright 2020 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and server 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::mulesoft::restapi::mode::servers; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use DateTime; + +sub custom_status_output { + my ($self, %options) = @_; + return my $msg = sprintf('Id: %s, Status: %s', $self->{result_values}->{id}, $self->{result_values}->{status}); +} + +sub custom_status_calc { + my ($self, %options) = @_; + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{id} = $options{new_datas}->{$self->{instance} . '_id'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, + { name => 'servers', type => 1, cb_prefix_output => 'prefix_server_output', message_multiple => 'All servers are ok' } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total', nlabel => 'mulesoft.servers.total.count', set => { + key_values => [ { name => 'total' } ], + output_template => "Total : %s", + perfdatas => [ { value => 'total_absolute', template => '%d', min => 0 } ], + } + }, + { label => 'running', nlabel => 'mulesoft.servers.status.running.count', set => { + key_values => [ { name => 'running' } ], + output_template => "Running : %s", + perfdatas => [ { value => 'running_absolute', template => '%d', min => 0 } ] + } + }, + { label => 'disconnected', nlabel => 'mulesoft.servers.status.disconnected.count', set => { + key_values => [ { name => 'disconnected' } ], + output_template => "Disconnected : %s", + perfdatas => [ { value => 'disconnected_absolute', template => '%d', min => 0 } ] + } + } + ]; + + $self->{maps_counters}->{servers} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'id' }, { name => 'status' }, { name => 'name'}, { name => 'display' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-name:s" => { name => 'filter_name' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return "Total servers "; +} + +sub prefix_server_output { + my ($self, %options) = @_; + + return "Server '" . $options{instance_value}->{name} . "' "; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = { started => 0, stopped => 0, failed => 0 }; + $self->{servers} = {}; + my $result = $options{custom}->list_servers(); + my $current_time = DateTime->now(); + foreach my $server (@{$result}) { + next if ( defined($self->{option_results}->{filter_name}) + && $self->{option_results}->{filter_name} ne '' + && $server->{name} !~ /$self->{option_results}->{filter_name}/ ); + $self->{servers}->{$server} = { + display => $server, + id => $server->{id}, + name => $server->{name}, + status => $server->{status}, + }; + + $self->{global}->{running}++ if $server->{status} =~ m/RUNNING/; + $self->{global}->{disconnected}++ if $server->{status} =~ m/DISCONNECTED/; + } + + if (scalar(keys %{$self->{servers}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No server found."); + $self->{output}->option_exit(); + } + + $self->{global}->{total} = scalar (keys %{$self->{servers}}); +} + +1; + +__END__ + +=head1 MODE + +Check Mulesoft Anypoint Servers status. + +Example: +perl centreon_plugins.pl --plugin=apps::mulesoft::restapi::plugin --mode=servers +--environment-id='1234abc-56de-78fg-90hi-1234abcdefg' --organization-id='1234abcd-56ef-78fg-90hi-1234abcdefg' +--api-username='myapiuser' --api-password='myapipassword' --verbose + +More information on'https://anypoint.mulesoft.com/exchange/portals/anypoint-platform/'. + +=over 8 + +=item B<--filter-name> + +Filter by server name (Regexp can be used). +Example: --filter-name='^server1$' + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used. +Typical syntax: --warning-status=%{status} ne "RUNNING" + +=item B<--critical-status> + +Set warning threshold for status (Default: ''). +Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used. +Typical syntax: --critical-status=%{status} ~= m/DISCONNECTED/" + + +=back + +=cut diff --git a/centreon-plugins/apps/mulesoft/restapi/plugin.pm b/centreon-plugins/apps/mulesoft/restapi/plugin.pm index 9abef19bd..e693c3dd0 100644 --- a/centreon-plugins/apps/mulesoft/restapi/plugin.pm +++ b/centreon-plugins/apps/mulesoft/restapi/plugin.pm @@ -31,8 +31,10 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'applications' => 'apps::mulesoft::restapi::mode::applications', - 'listapplications' => 'apps::mulesoft::restapi::mode::listapplications' + 'applications' => 'apps::mulesoft::restapi::mode::applications', + 'listapplications' => 'apps::mulesoft::restapi::mode::listapplications', + 'servers' => 'apps::mulesoft::restapi::mode::servers', + 'listservers' => 'apps::mulesoft::restapi::mode::listservers', ); $self->{custom_modes}{restapi} = 'apps::mulesoft::restapi::custom::api'; From 0671903f78356f28cf29a35f93bd9c6c9565d42d Mon Sep 17 00:00:00 2001 From: thibaults-centreon Date: Tue, 21 Apr 2020 11:02:23 +0200 Subject: [PATCH 106/190] Mulesoft cleanup --- centreon-plugins/apps/mulesoft/restapi/mode/applications.pm | 4 ++-- centreon-plugins/apps/mulesoft/restapi/mode/servers.pm | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/centreon-plugins/apps/mulesoft/restapi/mode/applications.pm b/centreon-plugins/apps/mulesoft/restapi/mode/applications.pm index 890e75979..82cdfe4ac 100644 --- a/centreon-plugins/apps/mulesoft/restapi/mode/applications.pm +++ b/centreon-plugins/apps/mulesoft/restapi/mode/applications.pm @@ -175,13 +175,13 @@ Example: --filter-name='^application1$' Set warning threshold for status (Default: ''). Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used. -Typical syntax: --warning-status=%{status} ne "STARTED" +Typical syntax: --warning-status='%{status} ne "STARTED"' =item B<--critical-status> Set warning threshold for status (Default: ''). Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used. -Typical syntax: --critical-status=%{status} ~= m/FAILED/" +Typical syntax: --critical-status='%{status} ~= m/FAILED/' =back diff --git a/centreon-plugins/apps/mulesoft/restapi/mode/servers.pm b/centreon-plugins/apps/mulesoft/restapi/mode/servers.pm index e84f937e6..a60cd7bc3 100644 --- a/centreon-plugins/apps/mulesoft/restapi/mode/servers.pm +++ b/centreon-plugins/apps/mulesoft/restapi/mode/servers.pm @@ -169,13 +169,13 @@ Example: --filter-name='^server1$' Set warning threshold for status (Default: ''). Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used. -Typical syntax: --warning-status=%{status} ne "RUNNING" +Typical syntax: --warning-status='%{status} ne "RUNNING"' =item B<--critical-status> Set warning threshold for status (Default: ''). Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used. -Typical syntax: --critical-status=%{status} ~= m/DISCONNECTED/" +Typical syntax: --critical-status='%{status} ~= m/DISCONNECTED/' =back From 228df502eb1529377c369df158a1517670565109 Mon Sep 17 00:00:00 2001 From: thibaults-centreon Date: Tue, 21 Apr 2020 11:13:47 +0200 Subject: [PATCH 107/190] cleanup --- centreon-plugins/apps/mulesoft/restapi/mode/servers.pm | 2 -- 1 file changed, 2 deletions(-) diff --git a/centreon-plugins/apps/mulesoft/restapi/mode/servers.pm b/centreon-plugins/apps/mulesoft/restapi/mode/servers.pm index a60cd7bc3..2bf7bc006 100644 --- a/centreon-plugins/apps/mulesoft/restapi/mode/servers.pm +++ b/centreon-plugins/apps/mulesoft/restapi/mode/servers.pm @@ -25,7 +25,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); -use DateTime; sub custom_status_output { my ($self, %options) = @_; @@ -119,7 +118,6 @@ sub manage_selection { $self->{global} = { started => 0, stopped => 0, failed => 0 }; $self->{servers} = {}; my $result = $options{custom}->list_servers(); - my $current_time = DateTime->now(); foreach my $server (@{$result}) { next if ( defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' From 27be9b360c643b902cf4ebb2753a1b8f83054378 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 21 Apr 2020 11:38:50 +0200 Subject: [PATCH 108/190] enhance performance dell idrac snmp --- .../idrac/snmp/mode/components/amperage.pm | 6 ++- .../snmp/mode/components/coolingdevice.pm | 6 ++- .../idrac/snmp/mode/components/coolingunit.pm | 8 +++- .../dell/idrac/snmp/mode/components/fru.pm | 8 +++- .../dell/idrac/snmp/mode/components/memory.pm | 8 +++- .../idrac/snmp/mode/components/network.pm | 8 +++- .../dell/idrac/snmp/mode/components/pci.pm | 10 +++-- .../idrac/snmp/mode/components/processor.pm | 12 ++++-- .../dell/idrac/snmp/mode/components/psu.pm | 8 +++- .../dell/idrac/snmp/mode/components/punit.pm | 10 +++-- .../dell/idrac/snmp/mode/components/slot.pm | 12 ++++-- .../snmp/mode/components/storagebattery.pm | 10 ++--- .../idrac/snmp/mode/components/storagectrl.pm | 10 ++--- .../snmp/mode/components/systembattery.pm | 37 +++++++++++++----- .../idrac/snmp/mode/components/temperature.pm | 6 ++- .../dell/idrac/snmp/mode/components/vdisk.pm | 38 +++++++++++-------- .../idrac/snmp/mode/components/voltage.pm | 24 ++++++++---- 17 files changed, 151 insertions(+), 70 deletions(-) diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/amperage.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/amperage.pm index 6b84180a5..6e13ed6ec 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/amperage.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/amperage.pm @@ -40,7 +40,11 @@ my $oid_amperageProbeTableEntry = '.1.3.6.1.4.1.674.10892.5.4.600.30.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_amperageProbeTableEntry }; + push @{$self->{request}}, { + oid => $oid_amperageProbeTableEntry, + start => $mapping->{amperageProbeStateSettings}->{oid}, + end => $mapping->{amperageProbeLowerCriticalThreshold}->{oid} + }; } sub check { diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/coolingdevice.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/coolingdevice.pm index e849908a1..a19636d72 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/coolingdevice.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/coolingdevice.pm @@ -39,7 +39,11 @@ my $oid_coolingDeviceTableEntry = '.1.3.6.1.4.1.674.10892.5.4.700.12.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_coolingDeviceTableEntry }; + push @{$self->{request}}, { + oid => $oid_coolingDeviceTableEntry, + start => $mapping->{coolingDeviceStateSettings}->{oid}, + end => $mapping->{coolingDeviceLowerCriticalThreshold}->{oid} + }; } sub check { diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/coolingunit.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/coolingunit.pm index fb899a871..3289be91f 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/coolingunit.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/coolingunit.pm @@ -34,7 +34,11 @@ my $oid_coolingUnitTableEntry = '.1.3.6.1.4.1.674.10892.5.4.700.10.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_coolingUnitTableEntry }; + push @{$self->{request}}, { + oid => $oid_coolingUnitTableEntry, + start => $mapping->{coolingUnitStateSettings}->{oid}, + end => $mapping->{coolingUnitStatus}->{oid} + }; } sub check { @@ -71,4 +75,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/fru.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/fru.pm index d41a8bba0..d005760b9 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/fru.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/fru.pm @@ -33,7 +33,11 @@ my $oid_fruTableEntry = '.1.3.6.1.4.1.674.10892.5.4.2000.10.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_fruTableEntry }; + push @{$self->{request}}, { + oid => $oid_fruTableEntry, + start => $mapping->{fruInformationStatus}->{oid}, + end => $mapping->{fruSerialNumberName}->{oid} + }; } sub check { @@ -63,4 +67,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/memory.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/memory.pm index f093ef9a8..3695e987b 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/memory.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/memory.pm @@ -34,7 +34,11 @@ my $oid_memoryDeviceTableEntry = '.1.3.6.1.4.1.674.10892.5.4.1100.50.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_memoryDeviceTableEntry }; + push @{$self->{request}}, { + oid => $oid_memoryDeviceTableEntry, + start => $mapping->{memoryDeviceStateSettings}->{oid}, + end => $mapping->{memoryDeviceLocationName}->{oid} + }; } sub check { @@ -71,4 +75,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/network.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/network.pm index f3ea07638..3fcd32279 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/network.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/network.pm @@ -33,7 +33,11 @@ my $oid_networkDeviceTableEntry = '.1.3.6.1.4.1.674.10892.5.4.1100.90.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_networkDeviceTableEntry }; + push @{$self->{request}}, { + oid => $oid_networkDeviceTableEntry, + start => $mapping->{networkDeviceStatus}->{oid}, + end => $mapping->{networkDeviceProductName}->{oid} + }; } sub check { @@ -63,4 +67,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/pci.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/pci.pm index 80498c2b5..68013cd4d 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/pci.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/pci.pm @@ -34,14 +34,18 @@ my $oid_pCIDeviceTableEntry = '.1.3.6.1.4.1.674.10892.5.4.1100.80.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_pCIDeviceTableEntry }; + push @{$self->{request}}, { + oid => $oid_pCIDeviceTableEntry, + start => $mapping->{pCIDeviceStateSettings}->{oid}, + end => $mapping->{pCIDeviceDescriptionName}->{oid} + }; } sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking pci"); - $self->{components}->{pci} = {name => 'pci', total => 0, skip => 0}; + $self->{components}->{pci} = { name => 'pci', total => 0, skip => 0 }; return if ($self->check_filter(section => 'pci')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_pCIDeviceTableEntry}})) { @@ -71,4 +75,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/processor.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/processor.pm index 49ed63c66..206f8ee4f 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/processor.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/processor.pm @@ -34,20 +34,24 @@ my $oid_processorDeviceTableEntry = '.1.3.6.1.4.1.674.10892.5.4.1100.30.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_processorDeviceTableEntry }; + push @{$self->{request}}, + { oid => $oid_processorDeviceTableEntry, start => $mapping->{processorDeviceStateSettings}->{oid}, end => $mapping->{processorDeviceStatus}->{oid} }, + { oid => $mapping->{processorDeviceFQDD}->{oid} } + ; } sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking processors"); - $self->{components}->{processor} = {name => 'processors', total => 0, skip => 0}; + $self->{components}->{processor} = { name => 'processors', total => 0, skip => 0 }; return if ($self->check_filter(section => 'processor')); - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_processorDeviceTableEntry}})) { + my $snmp_result = { %{$self->{results}->{ $oid_processorDeviceTableEntry }}, %{$self->{results}->{ $mapping->{processorDeviceFQDD}->{oid} }} }; + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) { next if ($oid !~ /^$mapping->{processorDeviceStatus}->{oid}\.(.*)$/); my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_processorDeviceTableEntry}, instance => $instance); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); next if ($self->check_filter(section => 'processor', instance => $instance)); $self->{components}->{processor}->{total}++; diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/psu.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/psu.pm index c46e39e36..b9e309b68 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/psu.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/psu.pm @@ -33,14 +33,18 @@ my $oid_powerSupplyTableEntry = '.1.3.6.1.4.1.674.10892.5.4.600.12.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_powerSupplyTableEntry }; + push @{$self->{request}}, { + oid => $oid_powerSupplyTableEntry, + start => $mapping->{powerSupplyStatus}->{oid}, + end => $mapping->{powerSupplyLocationName}->{oid} + }; } sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking power supplies"); - $self->{components}->{psu} = {name => 'power supplies', total => 0, skip => 0}; + $self->{components}->{psu} = { name => 'power supplies', total => 0, skip => 0 }; return if ($self->check_filter(section => 'psu')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_powerSupplyTableEntry}})) { diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/punit.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/punit.pm index 06815d7fb..a5a653a10 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/punit.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/punit.pm @@ -34,14 +34,18 @@ my $oid_powerUnitTableEntry = '.1.3.6.1.4.1.674.10892.5.4.600.10.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_powerUnitTableEntry }; + push @{$self->{request}}, { + oid => $oid_powerUnitTableEntry, + start => $mapping->{powerUnitStateSettings}->{oid}, + end => $mapping->{powerUnitStatus}->{oid} + }; } sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking power units"); - $self->{components}->{punit} = {name => 'power units', total => 0, skip => 0}; + $self->{components}->{punit} = { name => 'power units', total => 0, skip => 0 }; return if ($self->check_filter(section => 'punit')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_powerUnitTableEntry}})) { @@ -71,4 +75,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/slot.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/slot.pm index 2b4dc6b17..61b934acc 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/slot.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/slot.pm @@ -33,21 +33,25 @@ my $oid_systemSlotTableEntry = '.1.3.6.1.4.1.674.10892.5.4.1200.10.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_systemSlotTableEntry }; + push @{$self->{request}}, { + oid => $oid_systemSlotTableEntry, + start => $mapping->{systemSlotStatus}->{oid}, + end => $mapping->{systemSlotSlotExternalSlotName}->{oid} + }; } sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking slots"); - $self->{components}->{slot} = {name => 'slots', total => 0, skip => 0}; + $self->{components}->{slot} = { name => 'slots', total => 0, skip => 0 }; return if ($self->check_filter(section => 'slot')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_systemSlotTableEntry}})) { next if ($oid !~ /^$mapping->{systemSlotStatus}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_systemSlotTableEntry}, instance => $instance); - + next if ($self->check_filter(section => 'slot', instance => $instance)); $self->{components}->{slot}->{total}++; @@ -63,4 +67,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/storagebattery.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/storagebattery.pm index f1c28bb30..647e9e104 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/storagebattery.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/storagebattery.pm @@ -28,12 +28,11 @@ my $mapping = { batteryComponentStatus => { oid => '.1.3.6.1.4.1.674.10892.5.5.1.20.130.15.1.6', map => \%map_status }, batteryFQDD => { oid => '.1.3.6.1.4.1.674.10892.5.5.1.20.130.15.1.20' }, }; -my $oid_batteryTableEntry = '.1.3.6.1.4.1.674.10892.5.5.1.20.130.15.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_batteryTableEntry }; + push @{$self->{request}}, { oid => $mapping->{batteryComponentStatus}->{oid} }, { oid => $mapping->{batteryFQDD}->{oid} }; } sub check { @@ -43,10 +42,11 @@ sub check { $self->{components}->{storagebattery} = {name => 'storage batteries', total => 0, skip => 0}; return if ($self->check_filter(section => 'storagebattery')); - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_batteryTableEntry}})) { + my $snmp_result = { %{$self->{results}->{ $mapping->{batteryComponentStatus}->{oid} }}, %{$self->{results}->{ $mapping->{batteryFQDD}->{oid} }} }; + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) { next if ($oid !~ /^$mapping->{batteryComponentStatus}->{oid}\.(.*)$/); my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_batteryTableEntry}, instance => $instance); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); next if ($self->check_filter(section => 'storagebattery', instance => $instance)); $self->{components}->{storagebattery}->{total}++; @@ -63,4 +63,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/storagectrl.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/storagectrl.pm index d74062202..ee5afcd4a 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/storagectrl.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/storagectrl.pm @@ -28,12 +28,11 @@ my $mapping = { controllerComponentStatus => { oid => '.1.3.6.1.4.1.674.10892.5.5.1.20.130.1.1.38', map => \%map_status }, controllerFQDD => { oid => '.1.3.6.1.4.1.674.10892.5.5.1.20.130.1.1.78' }, }; -my $oid_controllerTableEntry = '.1.3.6.1.4.1.674.10892.5.5.1.20.130.1.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_controllerTableEntry }; + push @{$self->{request}}, { oid => $mapping->{controllerComponentStatus}->{oid} }, { oid => $mapping->{controllerFQDD}->{oid} }; } sub check { @@ -43,10 +42,11 @@ sub check { $self->{components}->{storagectrl} = {name => 'storage controllers', total => 0, skip => 0}; return if ($self->check_filter(section => 'storagectrl')); - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_controllerTableEntry}})) { + my $snmp_result = { %{$self->{results}->{ $mapping->{controllerComponentStatus}->{oid} }}, %{$self->{results}->{ $mapping->{controllerFQDD}->{oid} }} }; + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) { next if ($oid !~ /^$mapping->{controllerComponentStatus}->{oid}\.(.*)$/); my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_controllerTableEntry}, instance => $instance); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); next if ($self->check_filter(section => 'storagectrl', instance => $instance)); $self->{components}->{storagectrl}->{total}++; @@ -63,4 +63,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/systembattery.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/systembattery.pm index dc7621d06..3bc5e6c60 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/systembattery.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/systembattery.pm @@ -34,7 +34,11 @@ my $oid_systemBatteryTableEntry = '.1.3.6.1.4.1.674.10892.5.4.600.50.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_systemBatteryTableEntry }; + push @{$self->{request}}, { + oid => $oid_systemBatteryTableEntry, + start => $mapping->{systemBatteryStateSettings}->{oid}, + start => $mapping->{systemBatteryLocationName}->{oid} + }; } sub check { @@ -52,23 +56,36 @@ sub check { next if ($self->check_filter(section => 'systembattery', instance => $instance)); $self->{components}->{systembattery}->{total}++; - $self->{output}->output_add(long_msg => sprintf("system battery '%s' status is '%s' [instance = %s] [state = %s]", - $result->{systemBatteryLocationName}, $result->{systemBatteryStatus}, $instance, - $result->{systemBatteryStateSettings})); - + $self->{output}->output_add( + long_msg => sprintf( + "system battery '%s' status is '%s' [instance = %s] [state = %s]", + $result->{systemBatteryLocationName}, + $result->{systemBatteryStatus}, $instance, + $result->{systemBatteryStateSettings} + ) + ); + my $exit = $self->get_severity(label => 'default.state', section => 'systembattery.state', value => $result->{systemBatteryStateSettings}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("System battery '%s' state is '%s'", $result->{systemBatteryLocationName}, $result->{systemBatteryStateSettings})); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "System battery '%s' state is '%s'", $result->{systemBatteryLocationName}, $result->{systemBatteryStateSettings} + ) + ); next; } $exit = $self->get_severity(label => 'default.status', section => 'systembattery.status', value => $result->{systemBatteryStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("System battery '%s' status is '%s'", $result->{systemBatteryLocationName}, $result->{systemBatteryStatus})); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "System battery '%s' status is '%s'", $result->{systemBatteryLocationName}, $result->{systemBatteryStatus} + ) + ); } } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/temperature.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/temperature.pm index c68ab8677..dc09cdbe5 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/temperature.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/temperature.pm @@ -47,7 +47,11 @@ my $oid_temperatureProbeTableEntry = '.1.3.6.1.4.1.674.10892.5.4.700.20.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_temperatureProbeTableEntry, begin => $mapping->{temperatureProbeStateSettings}->{oid}, end => $mapping->{temperatureProbeLowerCriticalThreshold}->{oid} }; + push @{$self->{request}}, { + oid => $oid_temperatureProbeTableEntry, + start => $mapping->{temperatureProbeStateSettings}->{oid}, + end => $mapping->{temperatureProbeLowerCriticalThreshold}->{oid} + }; } sub check { diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/vdisk.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/vdisk.pm index 40d859a0f..272770c2d 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/vdisk.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/vdisk.pm @@ -26,42 +26,48 @@ use hardware::server::dell::idrac::snmp::mode::components::resources qw(%map_vdi my $mapping = { virtualDiskState => { oid => '.1.3.6.1.4.1.674.10892.5.5.1.20.140.1.1.4', map => \%map_vdisk_state }, - virtualDiskFQDD => { oid => '.1.3.6.1.4.1.674.10892.5.5.1.20.140.1.1.35' }, + virtualDiskFQDD => { oid => '.1.3.6.1.4.1.674.10892.5.5.1.20.140.1.1.35' } }; -my $oid_virtualDiskTableEntry = '.1.3.6.1.4.1.674.10892.5.5.1.20.140.1.1'; sub load { my ($self) = @_; - - push @{$self->{request}}, { oid => $oid_virtualDiskTableEntry }; + + push @{$self->{request}}, { oid => $mapping->{virtualDiskState}->{oid} }, { oid => $mapping->{virtualDiskFQDD}->{oid} }; } sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking virtual disks"); - $self->{components}->{vdisk} = {name => 'virtual disks', total => 0, skip => 0}; + $self->{components}->{vdisk} = { name => 'virtual disks', total => 0, skip => 0 }; return if ($self->check_filter(section => 'vdisk')); - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_virtualDiskTableEntry}})) { + my $snmp_result = { %{$self->{results}->{ $mapping->{virtualDiskState}->{oid} }}, %{$self->{results}->{ $mapping->{virtualDiskFQDD}->{oid} }} }; + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %$snmp_result)) { next if ($oid !~ /^$mapping->{virtualDiskState}->{oid}\.(.*)$/); my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_virtualDiskTableEntry}, instance => $instance); - + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + next if ($self->check_filter(section => 'vdisk', instance => $instance)); $self->{components}->{vdisk}->{total}++; - $self->{output}->output_add(long_msg => sprintf("virtual disk '%s' state is '%s' [instance = %s]", - $result->{virtualDiskFQDD}, $result->{virtualDiskState}, $instance, - )); - + $self->{output}->output_add( + long_msg => sprintf( + "virtual disk '%s' state is '%s' [instance = %s]", + $result->{virtualDiskFQDD}, $result->{virtualDiskState}, $instance, + ) + ); + my $exit = $self->get_severity(section => 'vdisk.state', value => $result->{virtualDiskState}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Virtual disk '%s' state is '%s'", $result->{virtualDiskFQDD}, $result->{virtualDiskState})); - next; + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Virtual disk '%s' state is '%s'", $result->{virtualDiskFQDD}, $result->{virtualDiskState} + ) + ); } } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/voltage.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/voltage.pm index 26d63d92f..8a95f9cb8 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/voltage.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/components/voltage.pm @@ -39,7 +39,11 @@ my $oid_voltageProbeTableEntry = '.1.3.6.1.4.1.674.10892.5.4.600.20.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_voltageProbeTableEntry }; + push @{$self->{request}}, { + oid => $oid_voltageProbeTableEntry, + start => $mapping->{voltageProbeStateSettings}->{oid}, + end => $mapping->{voltageProbeLowerCriticalThreshold}->{oid} + }; } sub check { @@ -58,10 +62,14 @@ sub check { $self->{components}->{voltage}->{total}++; $result->{voltageProbeReading} = (defined($result->{voltageProbeReading})) ? $result->{voltageProbeReading} / 1000 : 'unknown'; - $self->{output}->output_add(long_msg => sprintf("voltage '%s' status is '%s' [instance = %s] [state = %s] [value = %s]", - $result->{voltageProbeLocationName}, $result->{voltageProbeStatus}, $instance, - $result->{voltageProbeStateSettings}, $result->{voltageProbeReading})); - + $self->{output}->output_add( + long_msg => sprintf( + "voltage '%s' status is '%s' [instance = %s] [state = %s] [value = %s]", + $result->{voltageProbeLocationName}, $result->{voltageProbeStatus}, $instance, + $result->{voltageProbeStateSettings}, $result->{voltageProbeReading} + ) + ); + my $exit = $self->get_severity(label => 'default.state', section => 'voltage.state', value => $result->{voltageProbeStateSettings}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, @@ -98,8 +106,10 @@ sub check { } if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Voltage '%s' is %s V", $result->{voltageProbeLocationName}, $result->{voltageProbeReading})); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Voltage '%s' is %s V", $result->{voltageProbeLocationName}, $result->{voltageProbeReading}) + ); } $self->{output}->perfdata_add( label => 'voltage', unit => 'V', From ea2e5b7b1b64a254c680d1148ea717bacb8ae486 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 21 Apr 2020 14:14:22 +0200 Subject: [PATCH 109/190] enhance indent --- .../mulesoft/restapi/mode/applications.pm | 53 ++++++++----------- .../mulesoft/restapi/mode/listapplications.pm | 14 +++-- .../apps/mulesoft/restapi/mode/listservers.pm | 25 ++++----- .../apps/mulesoft/restapi/mode/servers.pm | 47 +++++++--------- 4 files changed, 63 insertions(+), 76 deletions(-) diff --git a/centreon-plugins/apps/mulesoft/restapi/mode/applications.pm b/centreon-plugins/apps/mulesoft/restapi/mode/applications.pm index 82cdfe4ac..e12a8d173 100644 --- a/centreon-plugins/apps/mulesoft/restapi/mode/applications.pm +++ b/centreon-plugins/apps/mulesoft/restapi/mode/applications.pm @@ -24,18 +24,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); sub custom_status_output { my ($self, %options) = @_; - return my $msg = sprintf('Id: %s, Status: %s', $self->{result_values}->{id}, $self->{result_values}->{status}); -} -sub custom_status_calc { - my ($self, %options) = @_; - $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; - $self->{result_values}->{id} = $options{new_datas}->{$self->{instance} . '_id'}; - return 0; + return sprintf('Id: %s, Status: %s', $self->{result_values}->{id}, $self->{result_values}->{status}); } sub set_counters { @@ -48,40 +42,40 @@ sub set_counters { $self->{maps_counters}->{global} = [ { label => 'total', nlabel => 'mulesoft.applications.total.count', set => { - key_values => [ { name => 'total' } ], - output_template => "Total : %s", - perfdatas => [ { value => 'total_absolute', template => '%d', min => 0 } ], + key_values => [ { name => 'total' } ], + output_template => "Total : %s", + perfdatas => [ { value => 'total_absolute', template => '%d', min => 0 } ] } }, { label => 'started', nlabel => 'mulesoft.applications.status.started.count', set => { - key_values => [ { name => 'started' } ], - output_template => "Started : %s", - perfdatas => [ { value => 'started_absolute', template => '%d', min => 0 } ] + key_values => [ { name => 'started' } ], + output_template => "Started : %s", + perfdatas => [ { value => 'started_absolute', template => '%d', min => 0 } ] } }, { label => 'stopped', nlabel => 'mulesoft.applications.status.stopped.count', set => { - key_values => [ { name => 'stopped' } ], - output_template => "Stopped : %s", - perfdatas => [ { value => 'stopped_absolute', template => '%d', min => 0 } ] + key_values => [ { name => 'stopped' } ], + output_template => "Stopped : %s", + perfdatas => [ { value => 'stopped_absolute', template => '%d', min => 0 } ] } }, { label => 'failed', nlabel => 'mulesoft.applications.status.failed.count', set => { - key_values => [ { name => 'failed' } ], - output_template => "Failed : %s", - perfdatas => [ { value => 'failed_absolute', template => '%d', min => 0 } ] + key_values => [ { name => 'failed' } ], + output_template => "Failed : %s", + perfdatas => [ { value => 'failed_absolute', template => '%d', min => 0 } ] } } ]; $self->{maps_counters}->{applications} = [ { label => 'status', threshold => 0, set => { - key_values => [ { name => 'id' }, { name => 'status' }, { name => 'name'}, { name => 'display' } ], - closure_custom_calc => $self->can('custom_status_calc'), - closure_custom_output => $self->can('custom_status_output'), - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + key_values => [ { name => 'id' }, { name => 'status' }, { name => 'name'}, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold } - }, + } ]; } @@ -91,9 +85,9 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' } + 'filter-name:s' => { name => 'filter_name' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' } }); return $self; @@ -183,7 +177,6 @@ Set warning threshold for status (Default: ''). Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used. Typical syntax: --critical-status='%{status} ~= m/FAILED/' - =back =cut diff --git a/centreon-plugins/apps/mulesoft/restapi/mode/listapplications.pm b/centreon-plugins/apps/mulesoft/restapi/mode/listapplications.pm index 2b7641bec..1d24344fa 100644 --- a/centreon-plugins/apps/mulesoft/restapi/mode/listapplications.pm +++ b/centreon-plugins/apps/mulesoft/restapi/mode/listapplications.pm @@ -31,7 +31,7 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, + 'filter-name:s' => { name => 'filter_name' }, }); return $self; @@ -56,10 +56,14 @@ sub run { next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $application->{name} !~ /$self->{option_results}->{filter_name}/); - $self->{output}->output_add(long_msg => sprintf("[id = %s][name = %s][status = %s]", - $application->{id}, - $application->{name}, - $application->{lastReportedStatus})); + $self->{output}->output_add( + long_msg => sprintf( + "[id = %s][name = %s][status = %s]", + $application->{id}, + $application->{name}, + $application->{lastReportedStatus} + ) + ); } $self->{output}->output_add(severity => 'OK', short_msg => 'Mulesoft Anypoint Applications:'); diff --git a/centreon-plugins/apps/mulesoft/restapi/mode/listservers.pm b/centreon-plugins/apps/mulesoft/restapi/mode/listservers.pm index e774d5b2d..664bfd697 100644 --- a/centreon-plugins/apps/mulesoft/restapi/mode/listservers.pm +++ b/centreon-plugins/apps/mulesoft/restapi/mode/listservers.pm @@ -31,7 +31,7 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, + 'filter-name:s' => { name => 'filter_name' }, }); return $self; @@ -42,12 +42,6 @@ sub check_options { $self->SUPER::init(%options); } -sub manage_selection { - my ($self, %options) = @_; - - $self->{data} = $options{custom}->list_servers(); -} - sub run { my ($self, %options) = @_; @@ -56,11 +50,14 @@ sub run { next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $server->{name} !~ /$self->{option_results}->{filter_name}/); - $self->{output}->output_add(long_msg => sprintf("[id = %s][name = %s][status = %s]", - $server->{id}, - $server->{name}, - $server->{status} - )); + $self->{output}->output_add( + long_msg => sprintf( + "[id = %s][name = %s][status = %s]", + $server->{id}, + $server->{name}, + $server->{status} + ) + ); } $self->{output}->output_add(severity => 'OK', short_msg => 'Mulesoft Anypoint Servers:'); @@ -77,8 +74,8 @@ sub disco_format { sub disco_show { my ($self, %options) = @_; - $self->manage_selection(%options); - foreach my $server (@{$self->{data}}) { + my $result = $options{custom}->list_servers(); + foreach my $server (@{$result}) { $self->{output}->add_disco_entry( id => $server->{id}, name => $server->{name}, diff --git a/centreon-plugins/apps/mulesoft/restapi/mode/servers.pm b/centreon-plugins/apps/mulesoft/restapi/mode/servers.pm index 2bf7bc006..a3db2385d 100644 --- a/centreon-plugins/apps/mulesoft/restapi/mode/servers.pm +++ b/centreon-plugins/apps/mulesoft/restapi/mode/servers.pm @@ -24,18 +24,11 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); sub custom_status_output { my ($self, %options) = @_; - return my $msg = sprintf('Id: %s, Status: %s', $self->{result_values}->{id}, $self->{result_values}->{status}); -} - -sub custom_status_calc { - my ($self, %options) = @_; - $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; - $self->{result_values}->{id} = $options{new_datas}->{$self->{instance} . '_id'}; - return 0; + return sprintf('Id: %s, Status: %s', $self->{result_values}->{id}, $self->{result_values}->{status}); } sub set_counters { @@ -48,21 +41,21 @@ sub set_counters { $self->{maps_counters}->{global} = [ { label => 'total', nlabel => 'mulesoft.servers.total.count', set => { - key_values => [ { name => 'total' } ], - output_template => "Total : %s", - perfdatas => [ { value => 'total_absolute', template => '%d', min => 0 } ], + key_values => [ { name => 'total' } ], + output_template => 'Total : %s', + perfdatas => [ { value => 'total_absolute', template => '%d', min => 0 } ] } }, { label => 'running', nlabel => 'mulesoft.servers.status.running.count', set => { - key_values => [ { name => 'running' } ], - output_template => "Running : %s", - perfdatas => [ { value => 'running_absolute', template => '%d', min => 0 } ] + key_values => [ { name => 'running' } ], + output_template => 'Running : %s', + perfdatas => [ { value => 'running_absolute', template => '%d', min => 0 } ] } }, { label => 'disconnected', nlabel => 'mulesoft.servers.status.disconnected.count', set => { - key_values => [ { name => 'disconnected' } ], - output_template => "Disconnected : %s", - perfdatas => [ { value => 'disconnected_absolute', template => '%d', min => 0 } ] + key_values => [ { name => 'disconnected' } ], + output_template => 'Disconnected : %s', + perfdatas => [ { value => 'disconnected_absolute', template => '%d', min => 0 } ] } } ]; @@ -70,12 +63,12 @@ sub set_counters { $self->{maps_counters}->{servers} = [ { label => 'status', threshold => 0, set => { key_values => [ { name => 'id' }, { name => 'status' }, { name => 'name'}, { name => 'display' } ], - closure_custom_calc => $self->can('custom_status_calc'), - closure_custom_output => $self->can('custom_status_output'), - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold } - }, + } ]; } @@ -85,9 +78,9 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, + 'filter-name:s' => { name => 'filter_name' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, }); return $self; @@ -122,6 +115,7 @@ sub manage_selection { next if ( defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $server->{name} !~ /$self->{option_results}->{filter_name}/ ); + $self->{servers}->{$server} = { display => $server, id => $server->{id}, @@ -175,7 +169,6 @@ Set warning threshold for status (Default: ''). Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used. Typical syntax: --critical-status='%{status} ~= m/DISCONNECTED/' - =back =cut From 8e8681a166d23cf3260143f89dfd1eb7836968e7 Mon Sep 17 00:00:00 2001 From: thibaults-centreon Date: Wed, 22 Apr 2020 10:51:19 +0200 Subject: [PATCH 110/190] enh(plugin): add cluster mode --- .../apps/mulesoft/restapi/custom/api.pm | 9 +- .../apps/mulesoft/restapi/mode/clusters.pm | 181 ++++++++++++++++++ .../apps/mulesoft/restapi/plugin.pm | 1 + 3 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 centreon-plugins/apps/mulesoft/restapi/mode/clusters.pm diff --git a/centreon-plugins/apps/mulesoft/restapi/custom/api.pm b/centreon-plugins/apps/mulesoft/restapi/custom/api.pm index 2b1a2f4f5..1b27bee3b 100644 --- a/centreon-plugins/apps/mulesoft/restapi/custom/api.pm +++ b/centreon-plugins/apps/mulesoft/restapi/custom/api.pm @@ -150,7 +150,6 @@ sub get_access_token { my $expires_on = $options{statefile}->get(name => 'expires_on'); my $access_token = $options{statefile}->get(name => 'access_token'); if ( $has_cache_file == 0 || !defined($access_token) || (($expires_on - time()) < 10) ) { - #my ($username, $password) = ( $self->{api_username}, $self->{api_password} ); my $login = { username => $self->{api_username}, password => $self->{api_password} }; my $post_json = JSON::XS->new->utf8->encode($login); @@ -263,6 +262,14 @@ sub get_server_status { return $response->{data}; } +sub list_clusters { + my ($self, %options) = @_; + + my $url_path = $self->{monitoring_endpoint} . '/clusters/'; + my $response = $self->request_api(method => 'GET', url_path => $url_path); + + return $response->{data}; +} sub cache_hosts { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/mulesoft/restapi/mode/clusters.pm b/centreon-plugins/apps/mulesoft/restapi/mode/clusters.pm new file mode 100644 index 000000000..5f1cfef53 --- /dev/null +++ b/centreon-plugins/apps/mulesoft/restapi/mode/clusters.pm @@ -0,0 +1,181 @@ +# +# Copyright 2020 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and cluster 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::mulesoft::restapi::mode::clusters; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub custom_status_output { + my ($self, %options) = @_; + return my $msg = sprintf('Id: %s, Status: %s', $self->{result_values}->{id}, $self->{result_values}->{status}); +} + +sub custom_status_calc { + my ($self, %options) = @_; + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{id} = $options{new_datas}->{$self->{instance} . '_id'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, + { name => 'clusters', type => 1, cb_prefix_output => 'prefix_cluster_output', message_multiple => 'All clusters are ok' } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total', nlabel => 'mulesoft.clusters.total.count', set => { + key_values => [ { name => 'total' } ], + output_template => "Total : %s", + perfdatas => [ { value => 'total_absolute', template => '%d', min => 0 } ], + } + }, + { label => 'running', nlabel => 'mulesoft.clusters.status.running.count', set => { + key_values => [ { name => 'running' } ], + output_template => "Running : %s", + perfdatas => [ { value => 'running_absolute', template => '%d', min => 0 } ] + } + }, + { label => 'disconnected', nlabel => 'mulesoft.clusters.status.disconnected.count', set => { + key_values => [ { name => 'disconnected' } ], + output_template => "Disconnected : %s", + perfdatas => [ { value => 'disconnected_absolute', template => '%d', min => 0 } ] + } + } + ]; + + $self->{maps_counters}->{clusters} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'id' }, { name => 'status' }, { name => 'name'}, { name => 'display' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-name:s" => { name => 'filter_name' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return "Total clusters "; +} + +sub prefix_cluster_output { + my ($self, %options) = @_; + + return "cluster '" . $options{instance_value}->{name} . "' "; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = { started => 0, stopped => 0, failed => 0 }; + $self->{clusters} = {}; + my $result = $options{custom}->list_clusters(); + foreach my $cluster (@{$result}) { + next if ( defined($self->{option_results}->{filter_name}) + && $self->{option_results}->{filter_name} ne '' + && $cluster->{name} !~ /$self->{option_results}->{filter_name}/ ); + $self->{clusters}->{$cluster} = { + display => $cluster, + id => $cluster->{id}, + name => $cluster->{name}, + status => $cluster->{status}, + }; + + $self->{global}->{running}++ if $cluster->{status} =~ m/RUNNING/; + $self->{global}->{disconnected}++ if $cluster->{status} =~ m/DISCONNECTED/; + } + + if (scalar(keys %{$self->{clusters}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No cluster found."); + $self->{output}->option_exit(); + } + + $self->{global}->{total} = scalar (keys %{$self->{clusters}}); +} + +1; + +__END__ + +=head1 MODE + +Check Mulesoft Anypoint clusters status. + +Example: +perl centreon_plugins.pl --plugin=apps::mulesoft::restapi::plugin --mode=clusters +--environment-id='1234abc-56de-78fg-90hi-1234abcdefg' --organization-id='1234abcd-56ef-78fg-90hi-1234abcdefg' +--api-username='myapiuser' --api-password='myapipassword' --verbose + +More information on'https://anypoint.mulesoft.com/exchange/portals/anypoint-platform/'. + +=over 8 + +=item B<--filter-name> + +Filter by cluster name (Regexp can be used). +Example: --filter-name='^cluster1$' + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used. +Typical syntax: --warning-status='%{status} ne "RUNNING"' + +=item B<--critical-status> + +Set warning threshold for status (Default: ''). +Threshold can be matched on %{name}, %{id} or %{status} and Regexp can be used. +Typical syntax: --critical-status='%{status} ~= m/DISCONNECTED/' + + +=back + +=cut diff --git a/centreon-plugins/apps/mulesoft/restapi/plugin.pm b/centreon-plugins/apps/mulesoft/restapi/plugin.pm index e693c3dd0..94ab8528c 100644 --- a/centreon-plugins/apps/mulesoft/restapi/plugin.pm +++ b/centreon-plugins/apps/mulesoft/restapi/plugin.pm @@ -35,6 +35,7 @@ sub new { 'listapplications' => 'apps::mulesoft::restapi::mode::listapplications', 'servers' => 'apps::mulesoft::restapi::mode::servers', 'listservers' => 'apps::mulesoft::restapi::mode::listservers', + 'clusters' => 'apps::mulesoft::restapi::mode::clusters' ); $self->{custom_modes}{restapi} = 'apps::mulesoft::restapi::custom::api'; From aa1d14c4607027b4f3ec0500ecaae32cc1771692 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 23 Apr 2020 11:23:52 +0200 Subject: [PATCH 111/190] Fix --- .../snmp_standard/mode/listspanningtrees.pm | 97 +++++++++++-------- .../snmp_standard/mode/spanningtree.pm | 73 ++++++++------ 2 files changed, 95 insertions(+), 75 deletions(-) diff --git a/centreon-plugins/snmp_standard/mode/listspanningtrees.pm b/centreon-plugins/snmp_standard/mode/listspanningtrees.pm index e8d3da959..0f3deff3f 100644 --- a/centreon-plugins/snmp_standard/mode/listspanningtrees.pm +++ b/centreon-plugins/snmp_standard/mode/listspanningtrees.pm @@ -29,12 +29,10 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "filter-port:s" => { name => 'filter_port' }, - }); - $self->{spanningtrees} = {}; + + $options{options}->add_options(arguments => { + 'filter-port:s' => { name => 'filter_port' }, + }); return $self; } @@ -44,32 +42,33 @@ sub check_options { $self->SUPER::init(%options); } -my %mapping_state = ( +my $mapping_state = { 1 => 'disabled', 2 => 'blocking', 3 => 'listening', 4 => 'learning', 5 => 'forwarding', 6 => 'broken', - 10 => 'not defined', -); -my %mapping_status = ( + 10 => 'not defined' +}; +my $mapping_status = { 1 => 'enabled', - 2 => 'disabled', -); + 2 => 'disabled' +}; my $mapping = { - dot1dStpPortState => { oid => '.1.3.6.1.2.1.17.2.15.1.3', map => \%mapping_state }, - dot1dStpPortEnable => { oid => '.1.3.6.1.2.1.17.2.15.1.4', map => \%mapping_status }, + dot1dStpPortState => { oid => '.1.3.6.1.2.1.17.2.15.1.3', map => $mapping_state }, + dot1dStpPortEnable => { oid => '.1.3.6.1.2.1.17.2.15.1.4', map => $mapping_status } }; my $oid_dot1dStpPortEntry = '.1.3.6.1.2.1.17.2.15.1'; my $oid_dot1dBasePortIfIndex = '.1.3.6.1.2.1.17.1.4.1.2'; -my %mapping_if_status = ( +my $mapping_if_status = { 1 => 'up', 2 => 'down', 3 => 'testing', 4 => 'unknown', 5 => 'dormant', 6 => 'notPresent', 7 => 'lowerLayerDown', -); + 100 => 'notfound' +}; my $oid_ifDesc = '.1.3.6.1.2.1.2.2.1.2'; my $oid_ifAdminStatus = '.1.3.6.1.2.1.2.2.1.7'; my $oid_ifOpStatus = '.1.3.6.1.2.1.2.2.1.8'; @@ -77,16 +76,17 @@ my $oid_ifOpStatus = '.1.3.6.1.2.1.2.2.1.8'; sub manage_selection { my ($self, %options) = @_; - my $results = $options{snmp}->get_table(oid => $oid_dot1dStpPortEntry, start => $mapping->{dot1dStpPortState}->{oid}, end => $mapping->{dot1dStpPortEnable}->{oid}, nothing_quit => 1); + my $results = {}; + my $snmp_results = $options{snmp}->get_table(oid => $oid_dot1dStpPortEntry, start => $mapping->{dot1dStpPortState}->{oid}, end => $mapping->{dot1dStpPortEnable}->{oid}, nothing_quit => 1); my @instances = (); - foreach my $oid (keys %{$results}) { + foreach my $oid (keys %$snmp_results) { next if ($oid !~ /^$mapping->{dot1dStpPortState}->{oid}\.(.*)/); my $instance = $1; - my $map_result = $options{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance); + my $map_result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_results, instance => $instance); if ($map_result->{dot1dStpPortEnable} =~ /disabled/) { - $self->{output}->output_add(long_msg => sprintf("Skipping interface '%d': Stp port disabled", $instance), debug => 1); + $self->{output}->output_add(long_msg => sprintf("skipping interface '%d': Stp port disabled", $instance), debug => 1); next; } push @instances, $instance; @@ -102,44 +102,55 @@ sub manage_selection { my $result_if = $options{snmp}->get_leef(); foreach my $instance (@instances) { - my $map_result = $options{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance); + my $map_result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_results, instance => $instance); my $state = (defined($map_result->{dot1dStpPortState})) ? $map_result->{dot1dStpPortState} : 'not defined'; my $description = (defined($result->{$oid_dot1dBasePortIfIndex . '.' . $instance}) && defined($result_if->{$oid_ifDesc . '.' . $result->{$oid_dot1dBasePortIfIndex . '.' . $instance}})) ? - $result_if->{$oid_ifDesc . '.' . $result->{$oid_dot1dBasePortIfIndex . '.' . $instance}} : 'unknown'; + $result_if->{$oid_ifDesc . '.' . $result->{$oid_dot1dBasePortIfIndex . '.' . $instance}} : $instance . '.unknown'; my $admin_status = (defined($result->{$oid_dot1dBasePortIfIndex . '.' . $instance}) && defined($result_if->{$oid_ifAdminStatus . '.' . $result->{$oid_dot1dBasePortIfIndex . '.' . $instance}})) ? - $result_if->{$oid_ifAdminStatus . '.' . $result->{$oid_dot1dBasePortIfIndex . '.' . $instance}} : 'unknown'; + $result_if->{$oid_ifAdminStatus . '.' . $result->{$oid_dot1dBasePortIfIndex . '.' . $instance}} : 100; my $op_status = (defined($result->{$oid_dot1dBasePortIfIndex . '.' . $instance}) && defined($result_if->{$oid_ifOpStatus . '.' . $result->{$oid_dot1dBasePortIfIndex . '.' . $instance}})) ? - $result_if->{$oid_ifOpStatus . '.' . $result->{$oid_dot1dBasePortIfIndex . '.' . $instance}} : 'unknown'; + $result_if->{$oid_ifOpStatus . '.' . $result->{$oid_dot1dBasePortIfIndex . '.' . $instance}} : 100; if (defined($self->{option_results}->{filter_port}) && $self->{option_results}->{filter_port} ne '' && $description !~ /$self->{option_results}->{filter_port}/) { - $self->{output}->output_add(long_msg => sprintf("Skipping interface '%s': filtered with options", $description), debug => 1); + $self->{output}->output_add(long_msg => sprintf("skipping interface '%s': filtered with options", $description), debug => 1); next; } - $self->{spanningtrees}->{$result->{$oid_dot1dBasePortIfIndex . '.' . $instance}} = { + $results->{$instance} = { state => $state, - admin_status => $mapping_if_status{$admin_status}, - op_status => $mapping_if_status{$op_status}, - index => $result->{$oid_dot1dBasePortIfIndex . '.' . $instance}, + admin_status => $mapping_if_status->{$admin_status}, + op_status => $mapping_if_status->{$op_status}, + index => defined($result->{$oid_dot1dBasePortIfIndex . '.' . $instance}) ? $result->{$oid_dot1dBasePortIfIndex . '.' . $instance} : 'notfound', description => $description }; } + + return $results; } sub run { my ($self, %options) = @_; - $self->manage_selection(%options); - foreach my $instance (sort keys %{$self->{spanningtrees}}) { - $self->{output}->output_add(long_msg => sprintf("[port = %s] [state = %s] [op_status = %s] [admin_status = %s] [index = %s]", - $self->{spanningtrees}->{$instance}->{description}, $self->{spanningtrees}->{$instance}->{state}, $self->{spanningtrees}->{$instance}->{op_status}, - $self->{spanningtrees}->{$instance}->{admin_status}, $self->{spanningtrees}->{$instance}->{index})); + my $results = $self->manage_selection(%options); + foreach my $instance (sort keys %$results) { + $self->{output}->output_add( + long_msg => sprintf( + "[port = %s] [state = %s] [op_status = %s] [admin_status = %s] [index = %s]", + $results->{$instance}->{description}, + $results->{$instance}->{state}, + $results->{$instance}->{op_status}, + $results->{$instance}->{admin_status}, + $results->{$instance}->{index} + ) + ); } - $self->{output}->output_add(severity => 'OK', - short_msg => 'List ports with Spanning Tree Protocol:'); + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List ports with spanning tree protocol:' + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -153,14 +164,14 @@ sub disco_format { sub disco_show { my ($self, %options) = @_; - $self->manage_selection(%options); - foreach my $instance (sort keys %{$self->{spanningtrees}}) { + my $results = $self->manage_selection(%options); + foreach my $instance (sort keys %$results) { $self->{output}->add_disco_entry( - port => $self->{spanningtrees}->{$instance}->{description}, - state => $self->{spanningtrees}->{$instance}->{state}, - op_status => $self->{spanningtrees}->{$instance}->{op_status}, - admin_status => $self->{spanningtrees}->{$instance}->{admin_status}, - index => $self->{spanningtrees}->{$instance}->{index} + port => $results->{$instance}->{description}, + state => $results->{$instance}->{state}, + op_status => $results->{$instance}->{op_status}, + admin_status => $results->{$instance}->{admin_status}, + index => $results->{$instance}->{index} ); } } diff --git a/centreon-plugins/snmp_standard/mode/spanningtree.pm b/centreon-plugins/snmp_standard/mode/spanningtree.pm index ea9cc88b4..ad31e156a 100644 --- a/centreon-plugins/snmp_standard/mode/spanningtree.pm +++ b/centreon-plugins/snmp_standard/mode/spanningtree.pm @@ -29,10 +29,11 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - my $msg = sprintf("spanning tree state is '%s' [op status: '%s'] [admin status: '%s'] [index: '%s']", + return sprintf( + "spanning tree state is '%s' [op status: '%s'] [admin status: '%s'] [index: '%s']", $self->{result_values}->{state}, $self->{result_values}->{op_status}, - $self->{result_values}->{admin_status}, $self->{result_values}->{index}); - return $msg; + $self->{result_values}->{admin_status}, $self->{result_values}->{index} + ) } sub custom_status_calc { @@ -52,10 +53,13 @@ sub set_counters { $self->{maps_counters_type} = [ { name => 'spanningtrees', type => 1, cb_prefix_output => 'prefix_peers_output', message_multiple => 'All spanning trees are ok' }, ]; + $self->{maps_counters}->{spanningtrees} = [ { label => 'status', threshold => 0, set => { - key_values => [ { name => 'state' }, { name => 'admin_status' }, { name => 'op_status' }, - { name => 'index' }, { name => 'description' } ], + key_values => [ + { name => 'state' }, { name => 'admin_status' }, { name => 'op_status' }, + { name => 'index' }, { name => 'description' } + ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, @@ -76,12 +80,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-port:s" => { name => 'filter_port' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{op_status} =~ /up/ && %{state} =~ /blocking|broken/' }, - }); + $options{options}->add_options(arguments => { + 'filter-port:s' => { name => 'filter_port' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{op_status} =~ /up/ && %{state} =~ /blocking|broken/' }, + }); return $self; } @@ -93,50 +96,51 @@ sub check_options { $self->change_macros(macros => ['warning_status', 'critical_status']); } -my %mapping_state = ( +my $mapping_state = { 1 => 'disabled', 2 => 'blocking', 3 => 'listening', 4 => 'learning', 5 => 'forwarding', 6 => 'broken', - 10 => 'not defined', -); -my %mapping_status = ( + 10 => 'not defined' +}; +my $mapping_status = { 1 => 'enabled', - 2 => 'disabled', -); + 2 => 'disabled' +}; my $mapping = { - dot1dStpPortState => { oid => '.1.3.6.1.2.1.17.2.15.1.3', map => \%mapping_state }, - dot1dStpPortEnable => { oid => '.1.3.6.1.2.1.17.2.15.1.4', map => \%mapping_status }, + dot1dStpPortState => { oid => '.1.3.6.1.2.1.17.2.15.1.3', map => $mapping_state }, + dot1dStpPortEnable => { oid => '.1.3.6.1.2.1.17.2.15.1.4', map => $mapping_status } }; my $oid_dot1dStpPortEntry = '.1.3.6.1.2.1.17.2.15.1'; my $oid_dot1dBasePortIfIndex = '.1.3.6.1.2.1.17.1.4.1.2'; -my %mapping_if_status = ( +my $mapping_if_status = { 1 => 'up', 2 => 'down', 3 => 'testing', 4 => 'unknown', 5 => 'dormant', 6 => 'notPresent', 7 => 'lowerLayerDown', -); + 100 => 'notfound' +}; my $oid_ifDesc = '.1.3.6.1.2.1.2.2.1.2'; my $oid_ifAdminStatus = '.1.3.6.1.2.1.2.2.1.7'; my $oid_ifOpStatus = '.1.3.6.1.2.1.2.2.1.8'; sub manage_selection { my ($self, %options) = @_; - + $self->{spanningtrees} = {}; my $results = $options{snmp}->get_table(oid => $oid_dot1dStpPortEntry, start => $mapping->{dot1dStpPortState}->{oid}, end => $mapping->{dot1dStpPortEnable}->{oid}, nothing_quit => 1); my @instances = (); - foreach my $oid (keys %{$results}) { + foreach my $oid (keys %$results) { next if ($oid !~ /^$mapping->{dot1dStpPortState}->{oid}\.(.*)/); my $instance = $1; my $map_result = $options{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance); if ($map_result->{dot1dStpPortEnable} =~ /disabled/) { - $self->{output}->output_add(long_msg => sprintf("Skipping interface '%d': Stp port disabled", $instance), debug => 1); + $self->{output}->output_add(long_msg => sprintf("skipping interface '%d': Stp port disabled", $instance), debug => 1); next; } push @instances, $instance; @@ -145,7 +149,7 @@ sub manage_selection { $options{snmp}->load(oids => [ $oid_dot1dBasePortIfIndex ], instances => [ @instances ]); my $result = $options{snmp}->get_leef(nothing_quit => 1); - foreach my $oid (keys %{$result}) { + foreach my $oid (keys %$result) { next if ($oid !~ /^$oid_dot1dBasePortIfIndex\./ || !defined($result->{$oid})); $options{snmp}->load(oids => [ $oid_ifDesc . "." . $result->{$oid}, $oid_ifAdminStatus . "." . $result->{$oid}, $oid_ifOpStatus . "." . $result->{$oid} ]); } @@ -156,22 +160,27 @@ sub manage_selection { my $state = (defined($map_result->{dot1dStpPortState})) ? $map_result->{dot1dStpPortState} : 'not defined'; my $description = (defined($result->{$oid_dot1dBasePortIfIndex . '.' . $instance}) && defined($result_if->{$oid_ifDesc . '.' . $result->{$oid_dot1dBasePortIfIndex . '.' . $instance}})) ? - $result_if->{$oid_ifDesc . '.' . $result->{$oid_dot1dBasePortIfIndex . '.' . $instance}} : 'unknown'; + $result_if->{$oid_ifDesc . '.' . $result->{$oid_dot1dBasePortIfIndex . '.' . $instance}} : $instance . '.unknown'; my $admin_status = (defined($result->{$oid_dot1dBasePortIfIndex . '.' . $instance}) && defined($result_if->{$oid_ifAdminStatus . '.' . $result->{$oid_dot1dBasePortIfIndex . '.' . $instance}})) ? - $result_if->{$oid_ifAdminStatus . '.' . $result->{$oid_dot1dBasePortIfIndex . '.' . $instance}} : 'unknown'; + $result_if->{$oid_ifAdminStatus . '.' . $result->{$oid_dot1dBasePortIfIndex . '.' . $instance}} : 100; my $op_status = (defined($result->{$oid_dot1dBasePortIfIndex . '.' . $instance}) && defined($result_if->{$oid_ifOpStatus . '.' . $result->{$oid_dot1dBasePortIfIndex . '.' . $instance}})) ? - $result_if->{$oid_ifOpStatus . '.' . $result->{$oid_dot1dBasePortIfIndex . '.' . $instance}} : 'unknown'; + $result_if->{$oid_ifOpStatus . '.' . $result->{$oid_dot1dBasePortIfIndex . '.' . $instance}} : 100; if (defined($self->{option_results}->{filter_port}) && $self->{option_results}->{filter_port} ne '' && $description !~ /$self->{option_results}->{filter_port}/) { - $self->{output}->output_add(long_msg => sprintf("Skipping interface '%s': filtered with options", $description), debug => 1); + $self->{output}->output_add(long_msg => sprintf("skipping interface '%s': filtered with options", $description), debug => 1); next; } - $self->{spanningtrees}->{$result->{$oid_dot1dBasePortIfIndex . '.' . $instance}} = { + if (!defined($result->{$oid_dot1dBasePortIfIndex . '.' . $instance})) { + $self->{output}->output_add(long_msg => sprintf("skipping spanning '%s': filtered with options", $instance), debug => 1); + next; + } + + $self->{spanningtrees}->{$instance} = { state => $state, - admin_status => $mapping_if_status{$admin_status}, - op_status => $mapping_if_status{$op_status}, + admin_status => $mapping_if_status->{$admin_status}, + op_status => $mapping_if_status->{$op_status}, index => $result->{$oid_dot1dBasePortIfIndex . '.' . $instance}, description => $description }; From 970ac3a65227b7134bc78dc902bdad1da300af17 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 23 Apr 2020 11:24:31 +0200 Subject: [PATCH 112/190] typo --- .../apps/vmware/connector/mode/countvmhost.pm | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/centreon-plugins/apps/vmware/connector/mode/countvmhost.pm b/centreon-plugins/apps/vmware/connector/mode/countvmhost.pm index ceafaf862..9b2878e27 100644 --- a/centreon-plugins/apps/vmware/connector/mode/countvmhost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/countvmhost.pm @@ -29,8 +29,7 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - my $msg = 'status ' . $self->{result_values}->{status}; - return $msg; + return 'status ' . $self->{result_values}->{status}; } sub custom_status_calc { @@ -45,7 +44,7 @@ sub set_counters { $self->{maps_counters_type} = [ { name => 'global', type => 0, skipped_code => { -10 => 1 } }, - { name => 'host', type => 1, cb_prefix_output => 'prefix_host_output', message_multiple => 'All ESX Hosts are ok' }, + { name => 'host', type => 1, cb_prefix_output => 'prefix_host_output', message_multiple => 'All ESX Hosts are ok' } ]; $self->{maps_counters}->{global} = [ @@ -54,8 +53,8 @@ sub set_counters { output_template => '%s VM(s) poweredon', perfdatas => [ { label => 'poweredon', value => 'poweredon_absolute', template => '%s', - min => 0, max => 'total_absolute' }, - ], + min => 0, max => 'total_absolute' } + ] } }, { label => 'total-off', nlabel => 'host.vm.poweredoff.current.count', set => { @@ -63,8 +62,8 @@ sub set_counters { output_template => '%s VM(s) poweredoff', perfdatas => [ { label => 'poweredoff', value => 'poweredoff_absolute', template => '%s', - min => 0, max => 'total_absolute' }, - ], + min => 0, max => 'total_absolute' } + ] } }, { label => 'total-suspended', nlabel => 'host.vm.suspended.current.count', set => { @@ -72,8 +71,8 @@ sub set_counters { output_template => '%s VM(s) suspended', perfdatas => [ { label => 'suspended', value => 'suspended_absolute', template => '%s', - min => 0, max => 'total_absolute' }, - ], + min => 0, max => 'total_absolute' } + ] } }, ]; @@ -84,7 +83,7 @@ sub set_counters { closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold } }, { label => 'on', nlabel => 'host.vm.poweredon.current.count', set => { @@ -92,8 +91,8 @@ sub set_counters { output_template => '%s VM(s) poweredon', perfdatas => [ { label => 'poweredon', value => 'poweredon_absolute', template => '%s', - min => 0, max => 'total_absolute', label_extra_instance => 1 }, - ], + min => 0, max => 'total_absolute', label_extra_instance => 1 } + ] } }, { label => 'off', nlabel => 'host.vm.poweredoff.current.count', set => { @@ -101,8 +100,8 @@ sub set_counters { output_template => '%s VM(s) poweredoff', perfdatas => [ { label => 'poweredoff', value => 'poweredoff_absolute', template => '%s', - min => 0, max => 'total_absolute', label_extra_instance => 1 }, - ], + min => 0, max => 'total_absolute', label_extra_instance => 1 } + ] } }, { label => 'suspended', nlabel => 'host.vm.suspended.current.count', set => { @@ -110,10 +109,10 @@ sub set_counters { output_template => '%s VM(s) suspended', perfdatas => [ { label => 'suspended', value => 'suspended_absolute', template => '%s', - min => 0, max => 'total_absolute', label_extra_instance => 1 }, - ], + min => 0, max => 'total_absolute', label_extra_instance => 1 } + ] } - }, + } ]; } @@ -153,8 +152,10 @@ sub manage_selection { $self->{global} = { poweredon => 0, poweredoff => 0, suspended => 0, total => 0 }; $self->{host} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'countvmhost'); + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'countvmhost' + ); foreach my $host_id (keys %{$response->{data}}) { my $host_name = $response->{data}->{$host_id}->{name}; @@ -170,7 +171,7 @@ sub manage_selection { $self->{global}->{poweredoff} += $response->{data}->{$host_id}->{poweredoff} if (defined($response->{data}->{$host_id}->{poweredoff})); $self->{global}->{suspended} += $response->{data}->{$host_id}->{suspended} if (defined($response->{data}->{$host_id}->{suspended})); } - + $self->{global}->{total} = $self->{global}->{poweredon} + $self->{global}->{poweredoff} + $self->{global}->{suspended}; } From 185e6fd5e8a0a77d196a5a31224df72744bf2b33 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 23 Apr 2020 13:30:17 +0200 Subject: [PATCH 113/190] Fix #1957 --- centreon-plugins/network/paloalto/ssh/mode/environment.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/centreon-plugins/network/paloalto/ssh/mode/environment.pm b/centreon-plugins/network/paloalto/ssh/mode/environment.pm index a5e4c6349..e38707463 100644 --- a/centreon-plugins/network/paloalto/ssh/mode/environment.pm +++ b/centreon-plugins/network/paloalto/ssh/mode/environment.pm @@ -37,7 +37,7 @@ sub set_system { $self->{thresholds} = { default => [ ['false', 'OK'], - ['.*', 'CRITICAL'], + ['.*', 'CRITICAL'] ] }; @@ -52,6 +52,7 @@ sub ssh_execute { ($self->{results}, $self->{exit_code}) = $options{custom}->execute_command( command => 'show system environmentals', + ForceArray => ['entry'] ); } From 0cbbca13bec191438c4bf11ef9272c05383b9a9a Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 23 Apr 2020 13:55:18 +0200 Subject: [PATCH 114/190] add ha state --- .../network/paloalto/ssh/mode/interfaces.pm | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/centreon-plugins/network/paloalto/ssh/mode/interfaces.pm b/centreon-plugins/network/paloalto/ssh/mode/interfaces.pm index 6f481507d..ac4d8e96d 100644 --- a/centreon-plugins/network/paloalto/ssh/mode/interfaces.pm +++ b/centreon-plugins/network/paloalto/ssh/mode/interfaces.pm @@ -43,7 +43,7 @@ sub set_counters { $self->{maps_counters_type} = [ { name => 'global', type => 0 }, - { name => 'interface', type => 1, cb_prefix_output => 'prefix_interface_output', message_multiple => 'All interface are ok', skipped_code => { -10 => 1 } }, + { name => 'interface', type => 1, cb_prefix_output => 'prefix_interface_output', message_multiple => 'All interface are ok', skipped_code => { -10 => 1 } } ]; $self->{maps_counters}->{global} = [ @@ -51,21 +51,24 @@ sub set_counters { key_values => [ { name => 'total' } ], output_template => 'total interfaces: %s', perfdatas => [ - { value => 'total_absolute', template => '%s', min => 0 }, - ], + { value => 'total_absolute', template => '%s', min => 0 } + ] } }, ]; $self->{maps_counters}->{interface} = [ { label => 'status', threshold => 0, set => { - key_values => [ { name => 'state' }, { name => 'type' }, { name => 'display' } ], + key_values => [ + { name => 'state' }, { name => 'type' }, + { name => 'ha_state' }, { name => 'display' } + ], closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold } - }, + } ]; } @@ -84,7 +87,7 @@ sub new { '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 => '%{state} ne "up"' }, + 'critical-status:s' => { name => 'critical_status', default => '%{state} ne "up"' } }); return $self; @@ -104,7 +107,10 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - my $result = $options{custom}->execute_command(command => 'show interface all', ForceArray => ['entry']); + my $result = $options{custom}->execute_command(command => 'show high-availability state'); + my $ha_state = defined($result->{group}->{'local-info'}->{state}) ? $result->{group}->{'local-info'}->{state} : 'disabled'; + + $result = $options{custom}->execute_command(command => 'show interface all', ForceArray => ['entry']); $self->{global} = { total => 0 }; $self->{interface} = {}; @@ -118,7 +124,8 @@ sub manage_selection { $self->{interface}->{$_->{name}} = { display => $_->{name}, type => $_->{type}, - state => $_->{state} + state => $_->{state}, + ha_state => $ha_state }; $self->{global}->{total}++; } @@ -141,17 +148,17 @@ Filter interface name (can be a regexp). =item B<--unknown-status> Set unknown threshold for status (Default: ''). -Can used special variables like: %{state}, %{type}, %{display} +Can used special variables like: %{state}, %{type}, %{ha_state}, %{display} =item B<--warning-status> Set warning threshold for status (Default: ''). -Can used special variables like: %{state}, %{type}, %{display} +Can used special variables like: %{state}, %{type}, %{ha_state}, %{display} =item B<--critical-status> Set critical threshold for status (Default: '%{state} ne "active"'). -Can used special variables like: %{state}, %{type}, %{display} +Can used special variables like: %{state}, %{type}, %{ha_state}, %{display} =item B<--warning-*> B<--critical-*> From 7b8ecfde8dfe98a559294f0ed64c4151f442bc90 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 23 Apr 2020 15:35:34 +0200 Subject: [PATCH 115/190] change vpn to ipsec mode for palo alto ssh --- .../paloalto/ssh/mode/{vpn.pm => ipsec.pm} | 75 +++++++++++-------- .../network/paloalto/ssh/plugin.pm | 4 +- 2 files changed, 45 insertions(+), 34 deletions(-) rename centreon-plugins/network/paloalto/ssh/mode/{vpn.pm => ipsec.pm} (58%) diff --git a/centreon-plugins/network/paloalto/ssh/mode/vpn.pm b/centreon-plugins/network/paloalto/ssh/mode/ipsec.pm similarity index 58% rename from centreon-plugins/network/paloalto/ssh/mode/vpn.pm rename to centreon-plugins/network/paloalto/ssh/mode/ipsec.pm index b4a7def7c..348ffc118 100644 --- a/centreon-plugins/network/paloalto/ssh/mode/vpn.pm +++ b/centreon-plugins/network/paloalto/ssh/mode/ipsec.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::paloalto::ssh::mode::vpn; +package network::paloalto::ssh::mode::ipsec; use base qw(centreon::plugins::templates::counter); @@ -30,12 +30,12 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold sub custom_status_output { my ($self, %options) = @_; - my $msg = sprintf( - 'state: %s [type: %s]', + return sprintf( + 'state: %s [monitor status: %s][ike phase1 state: %s]', $self->{result_values}->{state}, - $self->{result_values}->{type} + $self->{result_values}->{monitor_status}, + $self->{result_values}->{ike_phase1_state} ); - return $msg; } sub set_counters { @@ -43,36 +43,39 @@ sub set_counters { $self->{maps_counters_type} = [ { name => 'global', type => 0 }, - { name => 'vpn', type => 1, cb_prefix_output => 'prefix_vpn_output', message_multiple => 'All vpn are ok', skipped_code => { -10 => 1 } }, + { name => 'tunnels', type => 1, cb_prefix_output => 'prefix_ipsec_output', message_multiple => 'All ipsec tunnels are ok', skipped_code => { -10 => 1 } }, ]; $self->{maps_counters}->{global} = [ - { label => 'total-ipsec', nlabel => 'vpn.total.ipsec.count', display_ok => 0, set => { + { label => 'ipsec-total', nlabel => 'tunnels.ipsec.total.count', display_ok => 0, set => { key_values => [ { name => 'total_ipsec' } ], - output_template => 'total ipsec vpn: %s', + output_template => 'total ipsec tunnels: %s', perfdatas => [ - { value => 'total_ipsec_absolute', template => '%s', min => 0 }, - ], + { value => 'total_ipsec_absolute', template => '%s', min => 0 } + ] } - }, + } ]; - $self->{maps_counters}->{vpn} = [ + $self->{maps_counters}->{tunnels} = [ { label => 'status', threshold => 0, set => { - key_values => [ { name => 'state' }, { name => 'type' }, { name => 'display' } ], + key_values => [ + { name => 'state' }, { name => 'ike_phase1_state' }, + { name => 'monitor_status' }, { name => 'display' } + ], closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold } - }, + } ]; } -sub prefix_vpn_output { +sub prefix_ipsec_output { my ($self, %options) = @_; - return "vpn '" . $options{instance_value}->{display} . "' "; + return "Tunnel ipsec '" . $options{instance_value}->{display} . "' "; } sub new { @@ -83,7 +86,7 @@ sub new { $options{options}->add_options(arguments => { 'unknown-status:s' => { name => 'unknown_status', default => '' }, 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '%{state} ne "active"' }, + 'critical-status:s' => { name => 'critical_status', default => '%{ike_phase1_state} eq "down" or %{state} ne "active"' } }); return $self; @@ -103,18 +106,26 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - my $result = $options{custom}->execute_command(command => 'show vpn flow', ForceArray => ['entry']); + my $result = $options{custom}->execute_command(command => 'show vpn ike-sa', ForceArray => ['entry']); $self->{global} = { total_ipsec => 0 }; - $self->{vpn} = {}; - foreach (@{$result->{IPSec}->{entry}}) { - $self->{vpn}->{$_->{name}} = { + $self->{tunnels} = {}; + foreach (@{$result->{tunnels}}) { + $self->{tunnels}->{$_->{gwid}} = { display => $_->{name}, - type => 'ipsec', - state => $_->{state} + ike_phase1_state => defined($_->{created}) && $_->{created} ne '' ? 'up' : 'down', + monitor_status => 'unknown', # could be 'up', 'down', 'off' + state => 'unknown' }; + $self->{global}->{total_ipsec}++; } + + $result = $options{custom}->execute_command(command => 'show vpn flow', ForceArray => ['entry']); + foreach (@{$result->{IPSec}->{entry}}) { + $self->{tunnels}->{$_->{gwid}}->{state} = $_->{state}; + $self->{tunnels}->{$_->{gwid}}->{monitor_status} = $_->{mon}; + } } 1; @@ -123,29 +134,29 @@ __END__ =head1 MODE -Check vpn. +Check ipsec tunnels. =over 8 =item B<--unknown-status> -Set unknown threshold for status (Default: ''). -Can used special variables like: %{state}, %{type}, %{display} +Set unknown threshold for status. +Can used special variables like: %{ike_phase1_state}, %{state}, %{monitor_status}, %{display}. =item B<--warning-status> -Set warning threshold for status (Default: ''). -Can used special variables like: %{state}, %{type}, %{display} +Set warning threshold for status. +Can used special variables like: %{ike_phase1_state}, %{state}, %{monitor_status}, %{display}. =item B<--critical-status> -Set critical threshold for status (Default: '%{state} ne "active"'). -Can used special variables like: %{state}, %{type}, %{display} +Set critical threshold for status (Default: '%{ike_phase1_state} eq "down" or %{state} ne "active"'). +Can used special variables like: %{ike_phase1_state}, %{state}, %{monitor_status}, %{display}. =item B<--warning-*> B<--critical-*> Thresholds. -Can be: 'total-ipsec'. +Can be: 'ipsec-total'. =back diff --git a/centreon-plugins/network/paloalto/ssh/plugin.pm b/centreon-plugins/network/paloalto/ssh/plugin.pm index 14cdfa82f..52b69c872 100644 --- a/centreon-plugins/network/paloalto/ssh/plugin.pm +++ b/centreon-plugins/network/paloalto/ssh/plugin.pm @@ -34,8 +34,8 @@ sub new { 'environment' => 'network::paloalto::ssh::mode::environment', 'ha' => 'network::paloalto::ssh::mode::ha', 'interfaces' => 'network::paloalto::ssh::mode::interfaces', - 'system' => 'network::paloalto::ssh::mode::system', - 'vpn' => 'network::paloalto::ssh::mode::vpn', + 'ipsec' => 'network::paloalto::ssh::mode::ipsec', + 'system' => 'network::paloalto::ssh::mode::system' ); $self->{custom_modes}{ssh} = 'network::paloalto::ssh::custom::cli'; From 6129b2a13783e2ce4a68e812691eb9d1d80d6bde Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 23 Apr 2020 16:01:48 +0200 Subject: [PATCH 116/190] add fsp150 wip + palo alto ssh --- .../network/adva/fsp150/snmp/mode/alarms.pm | 326 +++++++++++++++ .../adva/fsp150/snmp/mode/interfaces.pm | 370 ++++++++++++++++++ .../adva/fsp150/snmp/mode/listinterfaces.pm | 160 ++++++++ .../network/adva/fsp150/snmp/plugin.pm | 52 +++ .../network/paloalto/ssh/mode/ipsec.pm | 2 +- 5 files changed, 909 insertions(+), 1 deletion(-) create mode 100644 centreon-plugins/network/adva/fsp150/snmp/mode/alarms.pm create mode 100644 centreon-plugins/network/adva/fsp150/snmp/mode/interfaces.pm create mode 100644 centreon-plugins/network/adva/fsp150/snmp/mode/listinterfaces.pm create mode 100644 centreon-plugins/network/adva/fsp150/snmp/plugin.pm diff --git a/centreon-plugins/network/adva/fsp150/snmp/mode/alarms.pm b/centreon-plugins/network/adva/fsp150/snmp/mode/alarms.pm new file mode 100644 index 000000000..7bbd27ee7 --- /dev/null +++ b/centreon-plugins/network/adva/fsp150/snmp/mode/alarms.pm @@ -0,0 +1,326 @@ +# +# 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 network::adva::fsp150::snmp::mode::alarms; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::misc; +use centreon::plugins::statefile; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("alarm %s [severity: %s] [type: %s] %s", $self->{result_values}->{label}, $self->{result_values}->{severity}, + $self->{result_values}->{type}, $self->{result_values}->{generation_time}); + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'}; + $self->{result_values}->{severity} = $options{new_datas}->{$self->{instance} . '_severity'}; + $self->{result_values}->{since} = $options{new_datas}->{$self->{instance} . '_since'}; + $self->{result_values}->{generation_time} = $options{new_datas}->{$self->{instance} . '_generation_time'}; + $self->{result_values}->{label} = $options{new_datas}->{$self->{instance} . '_label'}; + return 0; +} + + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'alarms', type => 2, message_multiple => '0 problem(s) detected', display_counter_problem => { label => 'alerts', min => 0 }, + group => [ { name => 'alarm', skipped_code => { -11 => 1 } } ] + } + ]; + + $self->{maps_counters}->{alarm} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'severity' }, { name => 'type' }, { name => 'label'}, { name => 'since' }, { name => 'generation_time' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => + { + "warning-status:s" => { name => 'warning_status', default => '%{severity} =~ /warning|minor/i' }, + "critical-status:s" => { name => 'critical_status', default => '%{severity} =~ /critical|major/i' }, + "memory" => { name => 'memory' }, + "timezone:s" => { name => 'timezone' }, + }); + + centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'DateTime', + error_msg => "Cannot load module 'DateTime'."); + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->check_options(%options); + } + + $self->{option_results}->{timezone} = 'GMT' if (!defined($self->{option_results}->{timezone}) || $self->{option_results}->{timezone} eq ''); +} + +my %map_type = ( + 0 => 'undefined', 5 => 'terminalLoopback', 6 => 'oosDisabled', 7 => 'oosManagement', 8 => 'oosMaintenance', 9 => 'oosAins', 10 => 'removed', + 11 => 'lossOfSignal', 12 => 'optInputPwrReceivedTooLow', 13 => 'optInputPwrReceivedTooHigh', 14 => 'laserTemperatureTooHigh', 15 => 'laserTemperatureTooLow', 16 => 'optOutputPowerTransTooLow', 17 => 'optOutputPowerTransTooHigh', + 18 => 'autoShutdownToHighTemp', 19 => 'autoShutdownToHighTxPwr', 20 => 'laserEndOfLife', 21 => 'serverSignalFailureVf', 22 => 'equalizationProgress', + 23 => 'uPortFailure', 24 => 'autoShutdownBlock', 25 => 'autoPowerShutdown', 26 => 'confOutPowerTransTooHigh', 27 => 'confOutPowerTransTooLow', + 28 => 'optSignalFailure', 29 => 'dsbdChannelPowerTooHigh', 30 => 'lossOfSignalCPort', 31 => 'lossOfSignalNPort', 32 => 'outputPowerFault', + 33 => 'eqlzAdjust', 34 => 'ampFailure', 35 => 'eqptProvMismatch', 36 => 'backreflectionTooHigh', 48 => 'fiberConnLos', 49 => 'fiberConnOptFault', + 50 => 'fiberConnInvalid', 51 => 'fiberConnMismatch', 52 => 'fiberConnCommError', 53 => 'fiberConnProtocolFailure', 54 => 'fiberConnDataFailure', + 55 => 'fiberAttenuationHigh', 57 => 'laserBiasCurrAbnormal', 58 => 'fiberConnInvalidTx', 59 => 'fiberConnMismatchTx', 60 => 'fiberAttenuationHighTx', + 61 => 'laserFailure', 62 => 'lossOfReceiverClockRecovery', 63 => 'fiberAttenuationCond', 64 => 'channelMismatch', 65 => 'alarmIndicationSignalLine', + 66 => 'alarmIndicationSignalLowerOrderPath', 67 => 'alarmIndicationSignalOdu', 68 => 'alarmIndicationSignalOpu', 69 => 'alarmIndicationSignalOtu', + 70 => 'alarmIndicationSignalHigherOrderPath', 71 => 'alarmIndicationSignalOduTcmA', 72 => 'alarmIndicationSignalOduTcmB', 73 => 'alarmIndicationSignalOduTcmC', 74 => 'virtualChannelAis', + 75 => 'amplifierAbnormal', 76 => 'automaticPowerReduction', 77 => 'automaticPowerReductionForEyeSafety', 80 => 'apsConfigMismatch', 81 => 'apsProtocolFailure', 82 => 'aseLow', + 83 => 'aseTableGenFailLow', 84 => 'aseTableGenFailHighBackreflection', 85 => 'aseTableGenFailOscMissing', 86 => 'aseTableGenFailPilot', 87 => 'aseTableGenFailSignalinput', + 88 => 'aseTableNotAvailable', 89 => 'aseTableGenProgress', 90 => 'encryptionPortAuthPasswdMissing', 92 => 'backwardDefectIndicationOdu', 93 => 'backwardDefectIndicationOtu', + 94 => 'backwardDefectIndicationOduTcmA', 95 => 'backwardDefectIndicationOduTcmB', 96 => 'backwardDefectIndicationOduTcmC', 97 => 'topologyDataCalculationInProgress', 99 => 'dispertionTunningCondition', 100 => 'lossOfCharSync', + 101 => 'lossOfCharSyncFromFarEnd', 103 => 'encryptionPortEncryptionSwitchOffEnabled', 104 => 'encryptionModuleCryPasswdMissing', 107 => 'encryptionModuleSelfTestStarted', 108 => 'encryptionPortEncryptionSwitchedOff', 109 => 'opuClientSignalFail', + 110 => 'databaseMismatch', 111 => 'databaseFailure', 112 => 'databaseNcuMismatch', 113 => 'dbReplicationIncompleted', 114 => 'databaseVersionMismatch', 115 => 'xfpDecisionThresSetFailed', 116 => 'duplexLinkFailure', 118 => 'singleFanFailure', + 119 => 'multipleFanFailure', 120 => 'lossOfSignalTransmitter', 122 => 'farEndIpAddressUnknown', 123 => 'farEndCommFailure', 125 => 'backupForcedToHalt', 127 => 'facilityForcedOn', 128 => 'fwdAseTableFailPilot', 129 => 'fwdAseTableOnPilot', + 131 => 'encryptionModuleFwpUpdateEnabled', 132 => 'fwpMismatchDownloadNotServiceAffecting', 133 => 'fwpMismatchDownloadServiceAffecting', 135 => 'gainTiltNotSettable', 136 => 'highBer', 137 => 'receiverOverloadProtection', 138 => 'hwInitializing', 139 => 'hwOprReachedHT', + 140 => 'hwDegrade', 141 => 'hwFailure', 142 => 'switchtoProtectionInhibited', 143 => 'switchtoWorkingInhibited', 148 => 'encryptionPortKeyInitExchgMissed', 149 => 'encryptionPortMaxKeyExchgFailuresReachedIs', 150 => 'encryptionPortMaxKeyExchgFailuresReachedOos', + 151 => 'encryptionPortKeyExchangedForced', 152 => 'laserOnDelay', 153 => 'lockedDefectOdu', 154 => 'lockedDefectOduTcmA', 155 => 'lockedDefectOduTcmB', 156 => 'lockedDefectOduTcmC', 157 => 'linkControlProtocolFailure', 158 => 'linkDown', 159 => 'autoShutdownSendingAisLine', + 160 => 'autoShutdownSendingAisOdu', 161 => 'autoShutdownSendingAisOpu', 162 => 'clientFailForwarding', 163 => 'autoShutdownAls', 164 => 'autoAmpShutdown', 165 => 'autoShutdownAmpAps', 166 => 'aseTableBuild', 167 => 'autoShutdownOpuClientSignalFail', 168 => 'autoShutdownSendingEPC', + 169 => 'autoShutdownSendingLckOdu', 170 => 'autoShutdownSendingOciOdu', 171 => 'autoShutdownLaserOffDueToErrFwd', 172 => 'autoShutdownTxRxLasersDueToHighTemp', 173 => 'localFault', 174 => 'localOscLevelAbnormal', 175 => 'lossOfGfpFrame', 176 => 'lossOfFrameMux', 177 => 'lossOfFrameOtu', + 178 => 'lossOfFrame', 179 => 'lossOfFrameLossOfMultiFrameOdu', 180 => 'lossOfLane', 181 => 'lossofMultiframeLowerOrderPath', 182 => 'lossOfMultiFrameOtu', 183 => 'lossofMultiframeHigherOrderPath', 184 => 'lossOfPointerLowerOrderPath', 185 => 'lossOfPointerHigherOrderPath', + 186 => 'losAttProgress', 187 => 'lossOsc', 188 => 'gfpLossOfClientSig', 189 => 'loopbackError', 190 => 'facilityLoopback', 191 => 'lossofTandemConnectionOduTcmA', 192 => 'lossofTandemConnectionOduTcmB', 193 => 'lossofTandemConnectionOduTcmC', 194 => 'mansw', 197 => 'equipmentNotAccepted', 198 => 'equipmentNotApproved', 199 => 'capabilityLevelMismatch', + 200 => 'equipmentMismatch', 201 => 'equipmentNotSupportedByPhysicalLayer', 202 => 'meaSwRevision', 203 => 'mismatch', 204 => 'midstageFault', 205 => 'multiplexStructureIdentifierMismatchOPU', 206 => 'backupNotResponding', 207 => 'openConnectionIndicationOdu', + 208 => 'openConnectionIndicationOduTcmA', 209 => 'openConnectionIndicationOduTcmB', 210 => 'openConnectionIndicationOduTcmC', 211 => 'oduTribMsiMismatch', 212 => 'transmitterDisabledOff', 213 => 'receiverDisabled', 214 => 'opmAbnormalCondition', 215 => 'faultOnOpm', 216 => 'thresOptPowerCtrlFailureHigh', + 217 => 'thresOptPowerCtrlFailureLow', 218 => 'txPowerLimited', 219 => 'oscOpticalPowerControlFailHigh', 220 => 'oscOpticalPowerControlFailLow', 221 => 'oTDRMeasuringinProgress', 222 => 'encryptionModuleCryPasswdError', 223 => 'peerLink', 224 => 'pilotReceiveLevelHigh', + 225 => 'lossOfPilotSignal', 226 => 'payloadMismatchGfp', 227 => 'payloadMismatchLowerOrderPath', 228 => 'payloadMismatchOPU', 229 => 'payloadMismatchHigherOrderPath', 230 => 'provPayloadMismatch', 231 => 'prbsLossOfSeqSynch', 232 => 'prbsRcvActivated', 233 => 'prbsTrmtActivated', 234 => 'protectionNotAvailable', 235 => 'powerSupplyUnitFailure', 236 => 'maxPowerConsProvModulesToHigh', + 237 => 'maxPowerConsEquipModulesToHigh', 238 => 'powerMissing', 239 => 'remoteDefectIndicationLine', 240 => 'remoteDefectIndicationLowerOrderPath', 241 => 'remoteDefectIndicationHigherOrderPath', 243 => 'dcnCommunicationFail', 244 => 'ntpForSchedEqlzRequired', 245 => 'signalDegradeOlm', 246 => 'signalDegradeLine', 247 => 'signalDegradationonLinkVector', + 248 => 'signalDegradeOdu', 249 => 'signalDegradeOtu', 250 => 'pcsSignalDegrade', 251 => 'signalDegradeScn', 252 => 'signalDegradeOduTcmA', 253 => 'signalDegradeOduTcmB', 254 => 'signalDegradeOduTcmC', 255 => 'encryptionModuleSelfTestFail', 256 => 'encryptionModuleSelfTestFailCritical', + 257 => 'signalFailureOnLink', 258 => 'signalFailureonLinkVector', 259 => 'signalFailureOPU', 260 => 'serverSignalFailTx', 261 => 'facilityDataRateNotSupported', 263 => 'lossofSequenceLowerOrderPath', 264 => 'lossofSequenceHigherOrderPath', 265 => 'serverSignalFail', 266 => 'serverSignalFailureGfp', + 267 => 'serverSignalFailureODU', 268 => 'serverSignalFailurePath', 269 => 'serverSignalFailureSectionRS', 272 => 'switchToDuplexInhibited', 274 => 'switchFailed', 276 => 'currentTooHigh', 277 => 'attOnReceiverFiberHigherThanMonitor', 278 => 'attOnReceiverFiberLowerThanMonitor', 279 => 'attOnTransmitterFiberHigherThanMonitor', + 280 => 'attOnTransmitterFiberLowerThanMonitor', 281 => 'thres15MinExceededOduBbe', 283 => 'thres15MinExceededOtuBbe', 285 => 'thres15MinExceededOduTcmABbe', 287 => 'thres15MinExceededOduTcmBBbe', 289 => 'thres15MinExceededOduTcmCBbe', 291 => 'thres15MinExceededFecBERCE', 293 => 'brPwrRxTooHigh', 294 => 'chromaticDispersionTooHigh', + 295 => 'chromaticDispersionTooLow', 296 => 'dispersionCompensationTooHigh', 297 => 'dispersionCompensationTooLow', 298 => 'thres15MinExceededFecCE', 300 => 'carrierFreqOffsetTooHigh', 301 => 'carrierFreqOffsetTooLow', 302 => 'thres15MinExceededSonetLineCV', 304 => 'thres15MinExceededPhysConvCV', + 306 => 'thres15MinExceededSonetSectCV', 308 => 'thres15MinExceededPhysConvDE', 310 => 'differentialGroupDelayTooHigh', 311 => 'thres15MinExceededFecES', 313 => 'thres15MinExceededSonetLineES', 315 => 'thres15MinExceededOduES', 317 => 'thres15MinExceededOtuES', + 319 => 'thres15MinExceededPhysConvES', 321 => 'thres15MinExceededSonetSectES', 323 => 'thres15MinExceededOduTcmAES', 325 => 'thres15MinExceededOduTcmBES', 327 => 'thres15MinExceededOduTcmCES', 329 => 'latencyTooHigh', 330 => 'latencyTooLow', 331 => 'laserBiasCurrentNormalizedtooHigh', 332 => 'localOscTemperatureTooHigh', 333 => 'localOscTemperatureTooLow', + 334 => 'pumpLaser1TempTooHigh', 335 => 'pumpLaser1TempTooLow', 336 => 'pumpLaser2TempTooHigh', 337 => 'pumpLaser2TempTooLow', 338 => 'pumpLaser3TempTooHigh', 339 => 'pumpLaser3TempTooLow', 340 => 'pumpLaser4TempTooHigh', 341 => 'pumpLaser4TempTooLow', 342 => 'oscPwrTooHigh', + 343 => 'oscPwrTooLow', 344 => 'ramanPumpPwrTooHigh', 345 => 'ramanPumpPwrTooLow', 346 => 'roundTripDelayTooHigh', 347 => 'roundTripDelayTooLow', 348 => 'thres15MinExceededSonetSectSEFS', 350 => 'thres15MinExceededFecSES', 352 => 'thres15MinExceededSonetLineSES', + 354 => 'thres15MinExceededOduSES', 356 => 'thres15MinExceededOtuSES', 358 => 'thres15MinExceededSonetSectSES', 360 => 'thres15MinExceededOduTcmASES', 362 => 'thres15MinExceededOduTcmBSES', 364 => 'thres15MinExceededOduTcmCSES', 366 => 'logicalLanesSkewTooHigh', + 367 => 'signalToNoiseRatioTooLow', 368 => 'subModuleTempTooHigh', 369 => 'temperatureTooHigh', 370 => 'temperatureTooLow', 371 => 'thres15MinExceededSonetLineUAS', 373 => 'thres15MinExceededOduUAS', 375 => 'thres15MinExceededOtuUAS', + 377 => 'thres15MinExceededOduTcmAUAS', 379 => 'thres15MinExceededOduTcmBUAS', 381 => 'thres15MinExceededOduTcmCUAS', 383 => 'thres15MinExceededFecUBE', 385 => 'encryptionModuleTamperDetected', 386 => 'thermoElectricCoolerEndOfLife', 387 => 'alarmInputTIF', 389 => 'traceIdentifierMismatchOdu', + 390 => 'traceIdentifierMismatchOtu', 391 => 'sectionTraceMismatch', 392 => 'traceIdentifierMismatchOduTcmA', 393 => 'traceIdentifierMismatchOduTcmB', 394 => 'traceIdentifierMismatchOduTcmC', 395 => 'turnupFailed', 396 => 'turnupCondition', 397 => 'unequippedLowerOrderPath', 398 => 'unequippedHigherOrderPath', 399 => 'voaControlFail', 400 => 'voltageOutOfRange', 401 => 'inputVoltageFailure', 402 => 'inputVoltageFailurePort1', + 403 => 'inputVoltageFailurePort2', 406 => 'wtrTimerRunning', 407 => 'lossOfLaneOtu', 408 => 'lossOfTestSeqSynchOpu', 409 => 'lossOfMfiOpu', 410 => 'oosDisabledLckOduTrmt', 411 => 'configurationMismatch', 412 => 'oduAutoShutdownRxAIS', 413 => 'oduAutoShutdownTxAIS', 414 => 'oosDisabledLckOduRx', 420 => 'thres15MinExceededBbePcs', + 422 => 'autoShutdownGAis', 423 => 'equipmentMismatchAllow', 424 => 'warmUp', 432 => 'networkPathRestricted', 434 => 'vfClientSignalFail', 435 => 'autoShutdownVfCSF', 439 => 'linkFailToPartner1', 440 => 'linkFailToPartner2', 441 => 'linkFailToPartner3', 442 => 'linkFailToPartner4', 443 => 'partnerUnavailable', + 445 => 'partner1Deleted', 446 => 'partner2Deleted', 447 => 'partner3Deleted', 448 => 'partner4Deleted', 450 => 'thres15MinExceededPhysConvSE', 452 => 'thres15MinExceededPhysConvCVDE', 456 => 'autoShutdownSendingOciOduTx', 457 => 'acpLinkLoss', 458 => 'acpChannelUnAvail', 459 => 'acpPartnerUnassigned', 460 => 'acpPartnerDeleted', 461 => 'thres15MinExceededCrcErrorsRcv', 463 => 'thres15MinExceededCrcFramesEgress', + 465 => 'autoServiceMismatch', 466 => 'batteryNoCharge', 469 => 'tagReceiveFail', 470 => 'tagReceiveFailMaxReached', 473 => 'internalEncryptionFail', 13006 => 'cfmRemoteDefectIndication', 13007 => 'cfmCcmMacStatus', 13008 => 'cfmCcmError', 13009 => 'cfmCcmLost', 13010 => 'cfmCcmXConn', 100005 => 'mepNotPresentL2', 100006 => 'priVidNotEqualExtVidL2', 100009 => 'sfCfmLevel0L2', 100010 => 'sfCfmLevel1L2', 100011 => 'sfCfmLevel2L2', + 100012 => 'sfCfmLevel3L2', 100013 => 'sfCfmLevel4L2 ', 100014 => 'sfCfmLevel5L2', 100015 => 'sfCfmLevel6L2', 100016 => 'sfCfmLevel7L2', 120004 => 'messageLossSpeq', 120005 => 'oscFiberMissingSpeq', 120006 => 'optLowSpeq', 120007 => 'ppcOutOfRangeSpeq', 120008 => 'gainTooHighSpeq', 120009 => 'gainTooLowSpeq', 120010 => 'gainAdoptFailedSpeq', 120011 => 'processLockedOutSpeq', 120012 => 'ppcLimitExceededSpeq', +); +my %map_severity = (1 => 'indeterminate', 2 => 'critical', 3 => 'major', 4 => 'minor', 5 => 'warning', 6 => 'cleared', 7 => 'notReported'); + +my $oids = { + alarmSysTable => { + oid => '.1.3.6.1.4.1.2544.1.11.7.4.1', label => 'sys', + mapping => { + severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.1.1.2', map => \%map_severity }, + timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.1.1.4' }, + } + }, + alarmEqptTable => { + oid => '.1.3.6.1.4.1.2544.1.11.7.4.5', label => 'eqpt', + mapping => { + severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.5.1.2', map => \%map_severity }, + timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.5.1.4' }, + } + }, + alarmFacilityTable => { + oid => '.1.3.6.1.4.1.2544.1.11.7.4.7', label => 'facility', + mapping => { + severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.7.1.2', map => \%map_severity }, + timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.7.1.4' }, + } + }, + alarmTerminPointTable => { + oid => '.1.3.6.1.4.1.2544.1.11.7.4.9', label => 'terminpoint', + mapping => { + severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.9.1.2', map => \%map_severity }, + timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.9.1.4' }, + } + }, + alarmExternalPortTable => { + oid => '.1.3.6.1.4.1.2544.1.11.7.4.11', label => 'externalport', + mapping => { + severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.11.1.2', map => \%map_severity }, + timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.11.1.4' }, + } + }, + alarmDcnTable => { + oid => '.1.3.6.1.4.1.2544.1.11.7.4.16', label => 'dcn', + mapping => { + severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.16.1.2', map => \%map_severity }, + timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.16.1.4' }, + } + }, + alarmEnvTable => { + oid => '.1.3.6.1.4.1.2544.1.11.7.4.20', label => 'env', + mapping => { + severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.20.1.2', map => \%map_severity }, + timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.20.1.4' }, + } + }, + alarmContainerTable => { + oid => '.1.3.6.1.4.1.2544.1.11.7.4.24', label => 'container', + mapping => { + severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.24.1.2', map => \%map_severity }, + timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.24.1.4' }, + } + }, + alarmOpticalMuxTable => { + oid => '.1.3.6.1.4.1.2544.1.11.7.4.28', label => 'opticalmux', + mapping => { + severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.28.1.2', map => \%map_severity }, + timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.28.1.4' }, + } + }, + alarmShelfConnTable => { + oid => '.1.3.6.1.4.1.2544.1.11.7.4.34', label => 'shelfconn', + mapping => { + severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.32.1.2', map => \%map_severity }, + timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.32.1.4' }, + } + }, + alarmNtpIPv4Table => { + oid => '.1.3.6.1.4.1.2544.1.11.7.4.36', label => 'ntpipv4', + mapping => { + severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.36.1.2', map => \%map_severity }, + timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.36.1.4' }, + } + }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_table(oid => '.1.3.6.1.4.1.2544.1.12.3.1.4.1.5'); + use Data::Dumper; print Data::Dumper::Dumper($snmp_result); + print unpack('B*', $snmp_result->{'.1.3.6.1.4.1.2544.1.12.3.1.4.1.5.1.1.5'}); + exit(1); + + $self->{alarms}->{global} = { alarm => {} }; + my $get_oids = []; + foreach (keys %$oids) { + push @$get_oids, { oid => $oids->{$_}->{oid} }; + } + my $snmp_result = $options{snmp}->get_multiple_table(oids => $get_oids); + + my $last_time; + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->read(statefile => "cache_adva_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port(). '_' . $self->{mode}); + $last_time = $self->{statefile_cache}->get(name => 'last_time'); + } + + my ($i, $current_time) = (1, time()); + + foreach (keys %$oids) { + my $branch_oid = $oids->{$_}->{oid}; + next if (!defined($snmp_result->{$branch_oid})); + + foreach my $oid (keys %{$snmp_result->{$branch_oid}}) { + next if ($oid !~ /^$oids->{$_}->{mapping}->{severity}->{oid}\.(.*)\.(.*?)$/); + my $instance = $1 . '.' . $2; + my $type = defined($map_type{$2}) ? $map_type{$2} : 'unknown'; + my $result = $options{snmp}->map_instance(mapping => $oids->{$_}->{mapping}, results => $snmp_result->{$branch_oid}, instance => $instance); + + my @date = unpack 'n C6 a C2', $result->{timestamp}; + my $timezone = $self->{option_results}->{timezone}; + if (defined($date[7])) { + $timezone = sprintf("%s%02d%02d", $date[7], $date[8], $date[9]); + } + + my $tz = centreon::plugins::misc::set_timezone(name => $timezone); + my $dt = DateTime->new(year => $date[0], month => $date[1], day => $date[2], hour => $date[3], minute => $date[4], second => $date[5], + %$tz); + + next if (defined($self->{option_results}->{memory}) && defined($last_time) && $last_time > $dt->epoch); + + my $diff_time = $current_time - $dt->epoch; + + $self->{alarms}->{global}->{alarm}->{$i} = { severity => $result->{severity}, + type => $type, since => $diff_time, + generation_time => centreon::plugins::misc::change_seconds(value => $diff_time), + label => $oids->{$_}->{label} + }; + $i++; + } + } + + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->write(data => { last_time => $current_time }); + } +} + +1; + +__END__ + +=head1 MODE + +Check alarms. + +=over 8 + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{severity} =~ /warning|minor/i') +Can used special variables like: %{severity}, %{type}, %{label}, %{since} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{severity} =~ /critical|major/i'). +Can used special variables like: %{severity}, %{type}, %{label}, %{since} + +=item B<--timezone> + +Timezone options (the date from the equipment overload that option). Default is 'GMT'. + +=item B<--memory> + +Only check new alarms. + +=back + +=cut diff --git a/centreon-plugins/network/adva/fsp150/snmp/mode/interfaces.pm b/centreon-plugins/network/adva/fsp150/snmp/mode/interfaces.pm new file mode 100644 index 000000000..c5d33d00f --- /dev/null +++ b/centreon-plugins/network/adva/fsp150/snmp/mode/interfaces.pm @@ -0,0 +1,370 @@ +# +# 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 network::adva::fsp3000::snmp::mode::interfaces; + +use base qw(snmp_standard::mode::interfaces); + +use strict; +use warnings; + +sub set_oids_traffic { + my ($self, %options) = @_; + + $self->{currentEthRx15minBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.52.1.5'; # in B + $self->{currentEthRx1dayBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.53.1.5'; # in B + $self->{currentEthTx15minBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.56.1.3'; # in B + $self->{currentEthTx1dayBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.57.1.3'; # in B + $self->{currentEthRxHighSpeed15minBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.88.1.4'; # in B + $self->{currentEthRxHighSpeed1dayBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.89.1.4'; # in B +} + +sub set_counters_traffic { + my ($self, %options) = @_; + + push @{$self->{maps_counters}->{int}}, + { label => 'traffic-in', filter => 'add_traffic', nlabel => 'interface.traffic.in.bitspersecond', set => { + key_values => [ { name => 'traffic_in_15min', diff => 1 }, { name => 'traffic_in_1day', diff => 1 }, { name => 'speed_in'}, { name => 'display' } ], + per_second => 1, + closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in' }, + closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic In : %s', + closure_custom_perfdata => $self->can('custom_traffic_perfdata'), + closure_custom_threshold_check => $self->can('custom_traffic_threshold'), + } + }, + { label => 'traffic-out', filter => 'add_traffic', nlabel => 'interface.traffic.out.bitspersecond', set => { + key_values => [ { name => 'traffic_out_15min', diff => 1 }, { name => 'traffic_out_1day', diff => 1 }, { name => 'speed_out'}, { name => 'display' } ], + per_second => 1, + closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out' }, + closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic Out : %s', + closure_custom_perfdata => $self->can('custom_traffic_perfdata'), + closure_custom_threshold_check => $self->can('custom_traffic_threshold'), + } + }, + ; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->SUPER::set_counters(%options); + + push @{$self->{maps_counters}->{int}}, + { label => 'laser-temp', filter => 'add_optical', nlabel => 'interface.laser.temperature.celsius', set => { + key_values => [ { name => 'laser_temp' }, { name => 'display' } ], + output_template => 'Laser Temperature : %.2f C', output_error_template => 'Laser Temperature : %.2f', + perfdatas => [ + { label => 'laser_temp', value => 'laser_temp_absolute', template => '%.2f', + unit => 'C', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'input-power', filter => 'add_optical', nlabel => 'interface.input.power.dbm', set => { + key_values => [ { name => 'input_power' }, { name => 'display' } ], + output_template => 'Input Power : %s dBm', output_error_template => 'Input Power : %s', + perfdatas => [ + { label => 'input_power', value => 'input_power_absolute', template => '%s', + unit => 'dBm', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'output-power', filter => 'add_optical', nlabel => 'interface.output.power.dbm', set => { + key_values => [ { name => 'output_power' }, { name => 'display' } ], + output_template => 'Output Power : %s dBm', output_error_template => 'Output Power : %s', + perfdatas => [ + { label => 'output_power', value => 'output_power_absolute', template => '%s', + unit => 'dBm', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ; +} + +sub custom_traffic_perfdata { + my ($self, %options) = @_; + + my ($warning, $critical); + if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { + $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); + $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { + $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}); + $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}); + } + + $self->{output}->perfdata_add( + label => 'traffic_' . $self->{result_values}->{label}, unit => 'b/s', + nlabel => $self->{nlabel}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + value => sprintf("%.2f", $self->{result_values}->{traffic_per_seconds}), + warning => $warning, + critical => $critical, + min => 0, max => $self->{result_values}->{speed} + ); +} + +sub custom_traffic_threshold { + my ($self, %options) = @_; + + my $exit = 'ok'; + if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { + $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_prct}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); + } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { + $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_per_seconds}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); + } + return $exit; +} + +sub custom_traffic_output { + my ($self, %options) = @_; + + my $label = $self->{result_values}->{label}; + $label =~ s/_/ /g; + $label =~ s/(\w+)/\u$1/g; + my ($traffic_value, $traffic_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic_per_seconds}, network => 1); + my $msg = sprintf("Traffic %s : %s/s (%s)", + $label, $traffic_value . $traffic_unit, + defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-'); + return $msg; +} + +sub custom_traffic_calc { + my ($self, %options) = @_; + + return -10 if (defined($self->{instance_mode}->{last_status}) && $self->{instance_mode}->{last_status} == 0); + + # we choose the performance value (1day is updated every 15 minutes. 15min is updated all the time but reset every 15min + my $counter = 'traffic_' . $options{extra_options}->{label_ref} . '_15min'; + if ($options{delta_time} >= 600) { + $counter = 'traffic_' . $options{extra_options}->{label_ref} . '_1day'; + } + + my $diff_traffic = ($options{new_datas}->{$self->{instance} . '_' . $counter} - $options{old_datas}->{$self->{instance} . '_' . $counter}); + + $self->{result_values}->{traffic_per_seconds} = $diff_traffic / $options{delta_time}; + if (defined($options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}}) && + $options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}} > 0) { + $self->{result_values}->{traffic_prct} = $self->{result_values}->{traffic_per_seconds} * 100 / $options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}}; + $self->{result_values}->{speed} = $options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}}; + } + + $self->{result_values}->{label} = $options{extra_options}->{label_ref}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_set_traffic => 1, no_errors => 1, no_cast => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'add-optical' => { name => 'add_optical' }, + } + ); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{checking} = ''; + foreach (('add_global', 'add_status', 'add_traffic', 'add_speed', 'add_volume', 'add_optical')) { + if (defined($self->{option_results}->{$_})) { + $self->{checking} .= $_; + } + } +} + +my $oid_opticalIfDiagLaserTemp = '.1.3.6.1.4.1.2544.1.11.2.4.3.5.1.2'; +my $oid_opticalIfDiagInputPower = '.1.3.6.1.4.1.2544.1.11.2.4.3.5.1.3'; +my $oid_opticalIfDiagOutputPower = '.1.3.6.1.4.1.2544.1.11.2.4.3.5.1.4'; + +sub custom_load { + my ($self, %options) = @_; + + return if (!defined($self->{option_results}->{add_optical})); + + $self->{snmp}->load(oids => [$oid_opticalIfDiagLaserTemp, $oid_opticalIfDiagInputPower, $oid_opticalIfDiagOutputPower], + instances => $self->{array_interface_selected}); +} + +sub custom_add_result { + my ($self, %options) = @_; + + return if (!defined($self->{option_results}->{add_optical})); + $self->{int}->{$options{instance}}->{laser_temp} = undef; + if (defined($self->{results}->{$oid_opticalIfDiagLaserTemp . '.' . $options{instance}}) && + $self->{results}->{$oid_opticalIfDiagLaserTemp . '.' . $options{instance}} != -2147483648) { + $self->{int}->{$options{instance}}->{laser_temp} = $self->{results}->{$oid_opticalIfDiagLaserTemp . '.' . $options{instance}} * 0.1; + } + + $self->{int}->{$options{instance}}->{input_power} = undef; + if (defined($self->{results}->{$oid_opticalIfDiagInputPower . '.' . $options{instance}}) && + $self->{results}->{$oid_opticalIfDiagInputPower . '.' . $options{instance}} != -65535) { + $self->{int}->{$options{instance}}->{input_power} = $self->{results}->{$oid_opticalIfDiagInputPower . '.' . $options{instance}} / 10; + } + + $self->{int}->{$options{instance}}->{output_power} = undef; + if (defined($self->{results}->{$oid_opticalIfDiagOutputPower . '.' . $options{instance}}) && + $self->{results}->{$oid_opticalIfDiagOutputPower . '.' . $options{instance}} != -65535) { + $self->{int}->{$options{instance}}->{output_power} = $self->{results}->{$oid_opticalIfDiagOutputPower . '.' . $options{instance}} / 10; + } +} + +sub load_traffic { + my ($self, %options) = @_; + + if ($self->{snmp}->is_snmpv1()) { + $self->{output}->add_option_msg(short_msg => "Can't check SNMP 64 bits counters with SNMPv1."); + $self->{output}->option_exit(); + } + + $self->set_oids_traffic(); + $self->{snmp}->load(oids => [$self->{currentEthRx15minBytes}, $self->{currentEthRx1dayBytes}, + $self->{currentEthTx15minBytes}, $self->{currentEthTx1dayBytes}, + $self->{currentEthRxHighSpeed15minBytes}, $self->{currentEthRxHighSpeed1dayBytes}], instances => $self->{array_interface_selected}); +} + +sub add_result_traffic { + my ($self, %options) = @_; + + $self->{int}->{$options{instance}}->{traffic_in_15min} = + defined($self->{results}->{$self->{currentEthRxHighSpeed15minBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthRxHighSpeed15minBytes} . '.' . $options{instance}} * 8 : + (defined($self->{results}->{$self->{currentEthRx15minBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthRx15minBytes} . '.' . $options{instance}} * 8 : undef); + $self->{int}->{$options{instance}}->{traffic_in_1day} = + defined($self->{results}->{$self->{currentEthRxHighSpeed1dayBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthRxHighSpeed1dayBytes} . '.' . $options{instance}} * 8 : + (defined($self->{results}->{$self->{currentEthRx1dayBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthRx1dayBytes} . '.' . $options{instance}} * 8 : undef); + $self->{int}->{$options{instance}}->{traffic_out_15min} = + defined($self->{results}->{$self->{currentEthTx15minBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthTx15minBytes} . '.' . $options{instance}} * 8 : undef; + $self->{int}->{$options{instance}}->{traffic_out_1day} = + defined($self->{results}->{$self->{currentEthTx1dayBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthTx1dayBytes} . '.' . $options{instance}} * 8 : undef; + + $self->{int}->{$options{instance}}->{speed_in} = 0; + $self->{int}->{$options{instance}}->{speed_out} = 0; + if ($self->{get_speed} == 0) { + if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') { + $self->{int}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed} * 1000000; + $self->{int}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed} * 1000000; + } + $self->{int}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed_in} * 1000000 if (defined($self->{option_results}->{speed_in}) && $self->{option_results}->{speed_in} ne ''); + $self->{int}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed_out} * 1000000 if (defined($self->{option_results}->{speed_out}) && $self->{option_results}->{speed_out} ne ''); + } +} + +1; + +__END__ + +=head1 MODE + +Check interfaces. + +=over 8 + +=item B<--add-status> + +Check interface status. + +=item B<--add-traffic> + +Check interface traffic. + +=item B<--add-optical> + +Check interface optical. + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{admstatus}, %{opstatus}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{admstatus} eq "up" and %{opstatus} ne "up"'). +Can used special variables like: %{admstatus}, %{opstatus}, %{display} + +=item B<--warning-*> + +Threshold warning. +Can be: 'laser-temp', 'input-power', 'output-power', 'traffic-in', 'traffic-out'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'laser-temp', 'input-power', 'output-power', 'traffic-in', 'traffic-out'. + +=item B<--units-traffic> + +Units of thresholds for the traffic (Default: '%') ('%', 'b/s'). + +=item B<--interface> + +Set the interface (number expected) ex: 1,2,... (empty means 'check all interface'). + +=item B<--name> + +Allows to use interface name with option --interface instead of interface oid index (Can be a regexp) + +=item B<--speed> + +Set interface speed for incoming/outgoing traffic (in Mb). + +=item B<--speed-in> + +Set interface speed for incoming traffic (in Mb). + +=item B<--speed-out> + +Set interface speed for outgoing traffic (in Mb). + +=item B<--reload-cache-time> + +Time in minutes before reloading cache file (default: 180). + +=item B<--oid-filter> + +Choose OID used to filter interface (default: ifName) (values: ifDesc, ifAlias, ifName). + +=item B<--oid-display> + +Choose OID used to display interface (default: ifName) (values: ifDesc, ifAlias, ifName). + +=item B<--oid-extra-display> + +Add an OID to display. + +=item B<--display-transform-src> + +Regexp src to transform display value. + +=item B<--display-transform-dst> + +Regexp dst to transform display value. + +=item B<--show-cache> + +Display cache interface datas. + +=back + +=cut diff --git a/centreon-plugins/network/adva/fsp150/snmp/mode/listinterfaces.pm b/centreon-plugins/network/adva/fsp150/snmp/mode/listinterfaces.pm new file mode 100644 index 000000000..167bfa0bc --- /dev/null +++ b/centreon-plugins/network/adva/fsp150/snmp/mode/listinterfaces.pm @@ -0,0 +1,160 @@ +# +# 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 network::adva::fsp3000::snmp::mode::listinterfaces; + +use base qw(snmp_standard::mode::listinterfaces); + +use strict; +use warnings; + +my $mapping = { + advaInventoryAidString => { oid => '.1.3.6.1.4.1.2544.1.11.7.10.1.1.6' }, + advaInventoryUnitName => { oid => '.1.3.6.1.4.1.2544.1.11.7.10.1.1.7' }, +}; + +sub set_oids_label { + my ($self, %options) = @_; + + $self->{oids_label} = { + 'ifdesc' => '.1.3.6.1.2.1.2.2.1.2', + 'ifalias' => '.1.3.6.1.2.1.31.1.1.1.18', + }; +} + +sub default_oid_filter_name { + my ($self, %options) = @_; + + return 'ifdesc'; +} + +sub default_oid_display_name { + my ($self, %options) = @_; + + return 'ifdesc'; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->SUPER::manage_selection(%options); + + my $oid_advaInventoryEntry = '.1.3.6.1.4.1.2544.1.11.7.10.1.1'; + my $snmp_result = $self->{snmp}->get_table( + oid => $oid_advaInventoryEntry, + begin => $mapping->{advaInventoryAidString}->{oid}, + end => $mapping->{advaInventoryUnitName}->{oid} + ); + + $self->{extra_oids}->{type} = { oid => $mapping->{advaInventoryUnitName}->{oid}, matching => '%{instance}$' }; + $self->{results}->{ $self->{extra_oids}->{type} } = {}; + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{advaInventoryUnitName}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + next if ($result->{advaInventoryUnitName} !~ /^(SFP|XFP)/i); + + # interface name example: CH-1-3-N1 + # inventory name example: PL-1-3-N1 + next if ($result->{advaInventoryAidString} !~ /(\d+-\d+-[^\-]+)$/); + my $lookup = $1; + + foreach (sort @{$self->{interface_id_selected}}) { + my $display_value = $self->get_display_value(id => $_); + + if ($display_value =~ /CH-$lookup$/) { + $self->{results}->{ $self->{extra_oids}->{type}->{oid} }->{ $self->{extra_oids}->{type}->{oid} . '.' . $_ } = $result->{advaInventoryUnitName}; + } + } + } +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{extra_oids}->{type} = { oid => $mapping->{advaInventoryUnitName}->{oid}, matching => '%{instance}$' }; + $self->SUPER::disco_format(%options); +} + +1; + +__END__ + +=head1 MODE + +=over 8 + +=item B<--interface> + +Set the interface (number expected) ex: 1,2,... (empty means 'check all interface'). + +=item B<--name> + +Allows to use interface name with option --interface instead of interface oid index (Can be a regexp) + +=item B<--speed> + +Set interface speed (in Mb). + +=item B<--skip-speed0> + +Don't display interface with speed 0. + +=item B<--filter-status> + +Display interfaces matching the filter (example: 'up'). + +=item B<--use-adminstatus> + +Display interfaces with AdminStatus 'up'. + +=item B<--oid-filter> + +Choose OID used to filter interface (default: ifDesc) (values: ifDesc, ifAlias). + +=item B<--oid-display> + +Choose OID used to display interface (default: ifDesc) (values: ifDesc, ifAlias). + +=item B<--display-transform-src> + +Regexp src to transform display value. (security risk!!!) + +=item B<--display-transform-dst> + +Regexp dst to transform display value. (security risk!!!) + +=item B<--add-extra-oid> + +Display an OID. +Example: --add-extra-oid='alias,.1.3.6.1.2.1.31.1.1.1.18' +or --add-extra-oid='vlan,.1.3.6.1.2.1.31.19,%{instance}\..*' + +=back + +=cut diff --git a/centreon-plugins/network/adva/fsp150/snmp/plugin.pm b/centreon-plugins/network/adva/fsp150/snmp/plugin.pm new file mode 100644 index 000000000..b4409a7e3 --- /dev/null +++ b/centreon-plugins/network/adva/fsp150/snmp/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 network::adva::fsp150::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'alarms' => 'network::adva::fsp150::snmp::mode::alarms', + 'interfaces' => 'network::adva::fsp3000::snmp::mode::interfaces', + 'list-interfaces' => 'network::adva::fsp3000::snmp::mode::listinterfaces', + 'memory' => 'snmp_standard::mode::memory', + 'uptime' => 'snmp_standard::mode::uptime' + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Adva fsp3000 equipments in SNMP. + +=cut diff --git a/centreon-plugins/network/paloalto/ssh/mode/ipsec.pm b/centreon-plugins/network/paloalto/ssh/mode/ipsec.pm index 348ffc118..a11e89aea 100644 --- a/centreon-plugins/network/paloalto/ssh/mode/ipsec.pm +++ b/centreon-plugins/network/paloalto/ssh/mode/ipsec.pm @@ -110,7 +110,7 @@ sub manage_selection { $self->{global} = { total_ipsec => 0 }; $self->{tunnels} = {}; - foreach (@{$result->{tunnels}}) { + foreach (@{$result->{entry}}) { $self->{tunnels}->{$_->{gwid}} = { display => $_->{name}, ike_phase1_state => defined($_->{created}) && $_->{created} ne '' ? 'up' : 'down', From 8575bc7477389a71e7de316ea06bd1acf08492f3 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 23 Apr 2020 17:15:32 +0200 Subject: [PATCH 117/190] patch ipsec palo alto ssh --- .../network/paloalto/ssh/mode/ipsec.pm | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/centreon-plugins/network/paloalto/ssh/mode/ipsec.pm b/centreon-plugins/network/paloalto/ssh/mode/ipsec.pm index a11e89aea..f1d752066 100644 --- a/centreon-plugins/network/paloalto/ssh/mode/ipsec.pm +++ b/centreon-plugins/network/paloalto/ssh/mode/ipsec.pm @@ -121,10 +121,21 @@ sub manage_selection { $self->{global}->{total_ipsec}++; } + $result = $options{custom}->execute_command(command => 'show vpn ipsec-sa', ForceArray => ['entry']); + foreach (@{$result->{entries}->{entry}}) { + if (defined($self->{tunnels}->{$_->{gwid}})) { + $self->{tunnels}->{$_->{gwid}}->{tid} = $_->{tid}; + } + } + $result = $options{custom}->execute_command(command => 'show vpn flow', ForceArray => ['entry']); - foreach (@{$result->{IPSec}->{entry}}) { - $self->{tunnels}->{$_->{gwid}}->{state} = $_->{state}; - $self->{tunnels}->{$_->{gwid}}->{monitor_status} = $_->{mon}; + foreach my $gwid (keys %{$self->{tunnels}}) { + next if (!defined($self->{tunnels}->{$gwid}->{tid})); + foreach (@{$result->{IPSec}->{entry}}) { + next if ($self->{tunnels}->{$gwid}->{tid} ne $_->{id}); + $self->{tunnels}->{$_->{gwid}}->{state} = $_->{state}; + $self->{tunnels}->{$_->{gwid}}->{monitor_status} = $_->{mon}; + } } } From 20681c93e06a9cae7ef04f140fefccc0b0aafaad Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 23 Apr 2020 18:05:45 +0200 Subject: [PATCH 118/190] Fix #1958 --- centreon-plugins/snmp_standard/mode/diskusage.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/centreon-plugins/snmp_standard/mode/diskusage.pm b/centreon-plugins/snmp_standard/mode/diskusage.pm index 8365d7f40..b51652272 100644 --- a/centreon-plugins/snmp_standard/mode/diskusage.pm +++ b/centreon-plugins/snmp_standard/mode/diskusage.pm @@ -122,7 +122,8 @@ sub new { 'display-transform-src:s' => { name => 'display_transform_src' }, 'display-transform-dst:s' => { name => 'display_transform_dst' }, 'show-cache' => { name => 'show_cache' }, - 'space-reservation:s' => { name => 'space_reservation' } + 'space-reservation:s' => { name => 'space_reservation' }, + 'force-use-mib-percent' => { name => 'force_use_mib_percent' } }); $self->{diskpath_id_selected} = []; @@ -156,6 +157,7 @@ sub check_options { my $mapping = { dskTotal32 => { oid => '.1.3.6.1.4.1.2021.9.1.6' }, # kB dskUsed32 => { oid => '.1.3.6.1.4.1.2021.9.1.8' }, # kB + dskPercent => { oid => '.1.3.6.1.4.1.2021.9.1.9' }, dskPercentNode => { oid => '.1.3.6.1.4.1.2021.9.1.10' }, dskTotalLow => { oid => '.1.3.6.1.4.1.2021.9.1.11' }, # kB dskTotalHigh => { oid => '.1.3.6.1.4.1.2021.9.1.12' }, # kB @@ -213,6 +215,7 @@ sub manage_selection { $prct_free = 0; } + $prct_used = $result->{dskPercent} if (defined($self->{option_results}->{force_use_mib_percent})); $self->{diskpath}->{$name_diskpath} = { display => $name_diskpath, total => $total_size, @@ -372,6 +375,10 @@ Display cache disk path datas. Some filesystem has space reserved (like ext4 for root). The value is in percent of total (Default: none) (results like 'df' command). +=item B<--force-use-mib-percent> + +Can be used if you have counters overload by big disks. + =back =cut From fdd8f1e84bcbe1e1785b323b8c174d42b9a73c17 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 23 Apr 2020 19:34:11 +0200 Subject: [PATCH 119/190] Fix #1959 --- .../juniper/common/junos/mode/interfaces.pm | 40 +++++++++---------- .../snmp_standard/mode/interfaces.pm | 4 +- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/centreon-plugins/network/juniper/common/junos/mode/interfaces.pm b/centreon-plugins/network/juniper/common/junos/mode/interfaces.pm index d05fad196..c2452c840 100644 --- a/centreon-plugins/network/juniper/common/junos/mode/interfaces.pm +++ b/centreon-plugins/network/juniper/common/junos/mode/interfaces.pm @@ -32,7 +32,7 @@ sub set_oids_errors { $self->{oid_ifInErrors} = '.1.3.6.1.2.1.2.2.1.14'; $self->{oid_ifOutDiscards} = '.1.3.6.1.2.1.2.2.1.19'; $self->{oid_ifOutErrors} = '.1.3.6.1.2.1.2.2.1.20'; - $self->{oid_dot3StatsFCSErrors} = '.1.3.6.1.2.1.10.7.2.1.3'; + $self->{oid_ifInFCSError} = '.1.3.6.1.2.1.10.7.2.1.3'; # dot3StatsFCSErrors } sub set_counters { @@ -41,15 +41,15 @@ sub set_counters { $self->SUPER::set_counters(%options); push @{$self->{maps_counters}->{int}}, - { label => 'fcs-errors', filter => 'add_errors', nlabel => 'interface.fcs.errors.count', set => { - key_values => [ { name => 'fcserror', diff => 1 }, { name => 'display' } ], - output_template => 'FCS Errors : %d', - perfdatas => [ - { value => 'fcserror_absolute', template => '%d', - label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + { label => 'fcs-errors', filter => 'add_errors', nlabel => 'interface.packets.in.fcs.errors.count', set => { + key_values => [ { name => 'infcserror', diff => 1 }, { name => 'total_in_packets', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], + closure_custom_calc => $self->can('custom_errors_calc'), + closure_custom_calc_extra_options => { label_ref1 => 'in', label_ref2 => 'fcserror' }, + closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets In FCS Error : %s', + closure_custom_perfdata => $self->can('custom_errors_perfdata'), + closure_custom_threshold_check => $self->can('custom_errors_threshold') } - }, + } ; push @{$self->{maps_counters}->{int}}, @@ -58,17 +58,17 @@ sub set_counters { output_template => 'Input Power : %s dBm', perfdatas => [ { value => 'input_power_absolute', template => '%s', - unit => 'dBm', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => 'dBm', label_extra_instance => 1, instance_use => 'display_absolute' } + ] } }, { label => 'bias-current', filter => 'add_optical', nlabel => 'interface.bias.current.milliampere', set => { key_values => [ { name => 'bias_current' }, { name => 'display' } ], output_template => 'Bias Current : %s mA', perfdatas => [ - { value => 'bias_current_absolute', template => '%s', + { value => 'bias_current_absolute', template => '%s' unit => 'mA', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + ] } }, { label => 'output-power', filter => 'add_optical', nlabel => 'interface.output.power.dbm', set => { @@ -76,8 +76,8 @@ sub set_counters { output_template => 'Output Power : %s dBm', perfdatas => [ { value => 'output_power_absolute', template => '%s', - unit => 'dBm', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => 'dBm', label_extra_instance => 1, instance_use => 'display_absolute' } + ] } }, { label => 'module-temperature', filter => 'add_optical', nlabel => 'interface.module.temperature.celsius', set => { @@ -85,10 +85,10 @@ sub set_counters { output_template => 'Module Temperature : %.2f C', perfdatas => [ { value => 'module_temperature_absolute', template => '%.2f', - unit => 'C', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => 'C', label_extra_instance => 1, instance_use => 'display_absolute' } + ] } - }, + } ; } @@ -127,7 +127,7 @@ sub load_errors { $self->{oid_ifInErrors}, $self->{oid_ifOutDiscards}, $self->{oid_ifOutErrors}, - $self->{oid_dot3StatsFCSErrors} + $self->{oid_ifInFCSError} ], instances => $self->{array_interface_selected} ); @@ -140,7 +140,7 @@ sub add_result_errors { $self->{int}->{$options{instance}}->{inerror} = $self->{results}->{$self->{oid_ifInErrors} . '.' . $options{instance}}; $self->{int}->{$options{instance}}->{outdiscard} = $self->{results}->{$self->{oid_ifOutDiscards} . '.' . $options{instance}}; $self->{int}->{$options{instance}}->{outerror} = $self->{results}->{$self->{oid_ifOutErrors} . '.' . $options{instance}}; - $self->{int}->{$options{instance}}->{fcserror} = $self->{results}->{$self->{oid_dot3StatsFCSErrors} . '.' . $options{instance}}; + $self->{int}->{$options{instance}}->{infcserror} = $self->{results}->{$self->{oid_ifInFCSError} . '.' . $options{instance}}; } my $oid_jnxDomCurrentRxLaserPower = '.1.3.6.1.4.1.2636.3.60.1.1.1.1.5'; diff --git a/centreon-plugins/snmp_standard/mode/interfaces.pm b/centreon-plugins/snmp_standard/mode/interfaces.pm index e31c986b1..7b9054b4d 100644 --- a/centreon-plugins/snmp_standard/mode/interfaces.pm +++ b/centreon-plugins/snmp_standard/mode/interfaces.pm @@ -200,9 +200,11 @@ sub custom_errors_perfdata { my ($self, %options) = @_; if ($self->{instance_mode}->{option_results}->{units_errors} eq '%') { + my $nlabel = $self->{nlabel}; + $nlabel =~ s/count/percentage/; $self->{output}->perfdata_add( label => 'packets_' . $self->{result_values}->{label2} . '_' . $self->{result_values}->{label1}, unit => '%', - nlabel => 'interface.packets.' . $self->{result_values}->{label1} . '.' . $self->{result_values}->{label2} . '.percentage', + nlabel => $nlabel, instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, value => sprintf("%.2f", $self->{result_values}->{prct}), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}), From c63c150840b91156a7dd4eb554a3b6507e054b7d Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Thu, 23 Apr 2020 20:11:37 +0200 Subject: [PATCH 120/190] Typos --- .../network/juniper/common/junos/mode/interfaces.pm | 10 +++++----- centreon-plugins/snmp_standard/mode/interfaces.pm | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/centreon-plugins/network/juniper/common/junos/mode/interfaces.pm b/centreon-plugins/network/juniper/common/junos/mode/interfaces.pm index c2452c840..30e027430 100644 --- a/centreon-plugins/network/juniper/common/junos/mode/interfaces.pm +++ b/centreon-plugins/network/juniper/common/junos/mode/interfaces.pm @@ -41,7 +41,7 @@ sub set_counters { $self->SUPER::set_counters(%options); push @{$self->{maps_counters}->{int}}, - { label => 'fcs-errors', filter => 'add_errors', nlabel => 'interface.packets.in.fcs.errors.count', set => { + { label => 'in-fcserror', filter => 'add_errors', nlabel => 'interface.packets.in.fcserror.count', set => { key_values => [ { name => 'infcserror', diff => 1 }, { name => 'total_in_packets', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'in', label_ref2 => 'fcserror' }, @@ -66,7 +66,7 @@ sub set_counters { key_values => [ { name => 'bias_current' }, { name => 'display' } ], output_template => 'Bias Current : %s mA', perfdatas => [ - { value => 'bias_current_absolute', template => '%s' + { value => 'bias_current_absolute', template => '%s', unit => 'mA', label_extra_instance => 1, instance_use => 'display_absolute' }, ] } @@ -259,7 +259,7 @@ Set critical threshold for all error counters. Threshold warning (will superseed --warning-errors). Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', -'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', 'fcs-errors', +'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', 'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%), 'speed' (b/s). @@ -269,11 +269,11 @@ And also: 'fcs-errors (%)', 'input-power' (dBm), 'bias-current' (mA), 'output-po Threshold critical (will superseed --warning-errors). Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', -'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', 'fcs-errors', +'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', 'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%), 'speed' (b/s). -And also: 'fcs-errors (%)', 'input-power' (dBm), 'bias-current' (mA), 'output-power' (dBm), 'module-temperature' (C). +And also: 'in-fcserror' (%), 'input-power' (dBm), 'bias-current' (mA), 'output-power' (dBm), 'module-temperature' (C). =item B<--units-traffic> diff --git a/centreon-plugins/snmp_standard/mode/interfaces.pm b/centreon-plugins/snmp_standard/mode/interfaces.pm index 7b9054b4d..ff1a38bfa 100644 --- a/centreon-plugins/snmp_standard/mode/interfaces.pm +++ b/centreon-plugins/snmp_standard/mode/interfaces.pm @@ -201,7 +201,7 @@ sub custom_errors_perfdata { if ($self->{instance_mode}->{option_results}->{units_errors} eq '%') { my $nlabel = $self->{nlabel}; - $nlabel =~ s/count/percentage/; + $nlabel =~ s/count$/percentage/; $self->{output}->perfdata_add( label => 'packets_' . $self->{result_values}->{label2} . '_' . $self->{result_values}->{label1}, unit => '%', nlabel => $nlabel, @@ -395,7 +395,7 @@ sub set_counters_errors { return if ($self->{no_errors} != 0 && $self->{no_set_errors} != 0); push @{$self->{maps_counters}->{int}}, - { label => 'in-discard', filter => 'add_errors', nlabel => 'interface.packets.in.discards.count', set => { + { label => 'in-discard', filter => 'add_errors', nlabel => 'interface.packets.in.discard.count', set => { key_values => [ { name => 'indiscard', diff => 1 }, { name => 'total_in_packets', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'in', label_ref2 => 'discard' }, closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets In Discard : %s', @@ -403,7 +403,7 @@ sub set_counters_errors { closure_custom_threshold_check => $self->can('custom_errors_threshold') } }, - { label => 'in-error', filter => 'add_errors', nlabel => 'interface.packets.in.errors.count', set => { + { label => 'in-error', filter => 'add_errors', nlabel => 'interface.packets.in.error.count', set => { key_values => [ { name => 'inerror', diff => 1 }, { name => 'total_in_packets', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'in', label_ref2 => 'error' }, closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets In Error : %s', @@ -411,7 +411,7 @@ sub set_counters_errors { closure_custom_threshold_check => $self->can('custom_errors_threshold') } }, - { label => 'out-discard', filter => 'add_errors', nlabel => 'interface.packets.out.discards.count', set => { + { label => 'out-discard', filter => 'add_errors', nlabel => 'interface.packets.out.discard.count', set => { key_values => [ { name => 'outdiscard', diff => 1 }, { name => 'total_out_packets', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'out', label_ref2 => 'discard' }, closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets Out Discard : %s', @@ -419,7 +419,7 @@ sub set_counters_errors { closure_custom_threshold_check => $self->can('custom_errors_threshold') } }, - { label => 'out-error', filter => 'add_errors', nlabel => 'interface.packets.out.errors.count', set => { + { label => 'out-error', filter => 'add_errors', nlabel => 'interface.packets.out.error.count', set => { key_values => [ { name => 'outerror', diff => 1 }, { name => 'total_out_packets', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], closure_custom_calc => $self->can('custom_errors_calc'), closure_custom_calc_extra_options => { label_ref1 => 'out', label_ref2 => 'error' }, closure_custom_output => $self->can('custom_errors_output'), output_error_template => 'Packets Out Error : %s', From a9e60e48e8dc702bf96b622f55b8f777487bc6ce Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 24 Apr 2020 11:18:13 +0200 Subject: [PATCH 121/190] update http response --- .../apps/protocols/http/mode/response.pm | 171 ++++++++++-------- 1 file changed, 93 insertions(+), 78 deletions(-) diff --git a/centreon-plugins/apps/protocols/http/mode/response.pm b/centreon-plugins/apps/protocols/http/mode/response.pm index 0423ac4c1..34505851c 100644 --- a/centreon-plugins/apps/protocols/http/mode/response.pm +++ b/centreon-plugins/apps/protocols/http/mode/response.pm @@ -20,115 +20,130 @@ package apps::protocols::http::mode::response; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); use Time::HiRes qw(gettimeofday tv_interval); use centreon::plugins::http; +sub custom_status_output { + my ($self, %options) = @_; + + return $self->{result_values}->{http_code} . ' ' . $self->{result_values}->{message}; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', threshold => 0, display_ok => 0, set => { + key_values => [ + { name => 'http_code' }, { name => 'message' } + ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + }, + { label => 'time', nlabel => 'http.response.time.seconds', set => { + key_values => [ { name => 'time' } ], + output_template => 'Response time %.3fs', + perfdatas => [ + { label => 'time', value => 'time_absolute', template => '%.3f', min => 0, unit => 's' } + ] + } + }, + { label => 'size', nlabel => 'http.response.size.count', display_ok => 0, set => { + key_values => [ { name => 'size' } ], + output_template => 'Content size : %s', + perfdatas => [ + { label => 'size', value => 'size_absolute', template => '%s', min => 0, unit => 'B' } + ] + } + } + ]; +} + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', }, - "method:s" => { name => 'method' }, - "proto:s" => { name => 'proto' }, - "urlpath:s" => { name => 'url_path' }, - "credentials" => { name => 'credentials' }, - "basic" => { name => 'basic' }, - "ntlmv2" => { name => 'ntlmv2' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout' }, - "no-follow" => { name => 'no_follow', }, - "cert-file:s" => { name => 'cert_file' }, - "key-file:s" => { name => 'key_file' }, - "cacert-file:s" => { name => 'cacert_file' }, - "cert-pwd:s" => { name => 'cert_pwd' }, - "cert-pkcs12" => { name => 'cert_pkcs12' }, - "header:s@" => { name => 'header' }, - "get-param:s@" => { name => 'get_param' }, - "post-param:s@" => { name => 'post_param' }, - "cookies-file:s" => { name => 'cookies_file' }, - "unknown-status:s" => { name => 'unknown_status', default => '' }, - "warning-status:s" => { name => 'warning_status' }, - "critical-status:s" => { name => 'critical_status', default => '%{http_code} < 200 or %{http_code} >= 300' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "warning-size:s" => { name => 'warning_size' }, - "critical-size:s" => { name => 'critical_size' }, + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port', }, + 'method:s' => { name => 'method' }, + 'proto:s' => { name => 'proto' }, + 'urlpath:s' => { name => 'url_path' }, + 'credentials' => { name => 'credentials' }, + 'basic' => { name => 'basic' }, + 'ntlmv2' => { name => 'ntlmv2' }, + 'username:s' => { name => 'username' }, + 'password:s' => { name => 'password' }, + 'timeout:s' => { name => 'timeout' }, + 'no-follow' => { name => 'no_follow', }, + 'cert-file:s' => { name => 'cert_file' }, + 'key-file:s' => { name => 'key_file' }, + 'cacert-file:s' => { name => 'cacert_file' }, + 'cert-pwd:s' => { name => 'cert_pwd' }, + 'cert-pkcs12' => { name => 'cert_pkcs12' }, + 'header:s@' => { name => 'header' }, + 'get-param:s@' => { name => 'get_param' }, + 'post-param:s@' => { name => 'post_param' }, + 'cookies-file:s' => { name => 'cookies_file' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status' }, + 'critical-status:s' => { name => 'critical_status', default => '%{http_code} < 200 or %{http_code} >= 300' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } }); - + $self->{http} = centreon::plugins::http->new(%options); return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'warning-size', value => $self->{option_results}->{warning_size})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-size threshold '" . $self->{option_results}->{warning_size} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical-size', value => $self->{option_results}->{critical_size})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-size threshold '" . $self->{option_results}->{critical_size} . "'."); - $self->{output}->option_exit(); + # Compat + if (defined($options{option_results}->{warning})) { + $options{option_results}->{'warning-time'} = $options{option_results}->{warning}; + $options{option_results}->{'warning-http-response-time-seconds'} = $options{option_results}->{warning}; } + if (defined($options{option_results}->{critical})) { + $options{option_results}->{'critical-time'} = $options{option_results}->{critical}; + $options{option_results}->{'critical-http-response-time-seconds'} = $options{option_results}->{critical}; + } + $self->SUPER::check_options(%options); + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); $self->{http}->set_options(%{$self->{option_results}}); } -sub run { +sub manage_selection { my ($self, %options) = @_; + $self->{global} = {}; my $timing0 = [gettimeofday]; - my $webcontent = $self->{http}->request(); - my $timeelapsed = tv_interval($timing0, [gettimeofday]); + my $webcontent = $self->{http}->request( + unknown_status => '', warning_status => '', critical_status => '' + ); + $self->{global}->{time} = tv_interval($timing0, [gettimeofday]); + $self->{global}->{http_code} = $self->{http}->get_code(); + $self->{global}->{message} = $self->{http}->get_message(); - $self->{output}->output_add(long_msg => $webcontent); - - my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed, - threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Response time %.3fs", $timeelapsed)); - $self->{output}->perfdata_add(label => "time", unit => 's', - value => sprintf('%.3f', $timeelapsed), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); - # Size check { require bytes; - my $content_size = bytes::length($webcontent); - $exit = $self->{perfdata}->threshold_check(value => $content_size, - threshold => [ { label => 'critical-size', exit_litteral => 'critical' }, { label => 'warning-size', exit_litteral => 'warning' } ]); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Content size : %s", $content_size)); - } - $self->{output}->perfdata_add(label => "size", unit => 'B', - value => $content_size, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-size'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-size'), - min => 0); + $self->{global}->{size} = bytes::length($webcontent); } - - $self->{output}->display(); - $self->{output}->exit(); } 1; @@ -241,11 +256,11 @@ Threshold warning for http response code Threshold critical for http response code (Default: '%{http_code} < 200 or %{http_code} >= 300') -=item B<--warning> +=item B<--warning-time> Threshold warning in seconds (Webpage response time) -=item B<--critical> +=item B<--critical-time> Threshold critical in seconds (Webpage response time) From faf04d994b321642e692b6adc073af2022ec91a5 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 24 Apr 2020 11:30:37 +0200 Subject: [PATCH 122/190] fix ssh cli --- centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm b/centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm index fd8290212..91101e489 100644 --- a/centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm +++ b/centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm @@ -57,7 +57,7 @@ sub check_options { $self->{output}->option_exit(); } - push @{$self->{ssh_option}}, '-o="BatchMode yes"'; + push @{$self->{ssh_option}}, '-o=BatchMode yes'; push @{$self->{ssh_option}}, '-l=' . $self->{ssh_username} if (defined($self->{ssh_username}) && $self->{ssh_username} ne ''); push @{$self->{ssh_option}}, '-p=' . $self->{ssh_port} if (defined($self->{ssh_port}) && $self->{ssh_port} ne ''); push @{$self->{ssh_option}}, '-i=' . $self->{ssh_priv_key} if (defined($self->{ssh_priv_key}) && $self->{ssh_priv_key} ne ''); From 0aff6dc72129ee102268f03a17f72e1861e125af Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Fri, 24 Apr 2020 12:23:13 +0200 Subject: [PATCH 123/190] 3CX, new version compat --- centreon-plugins/apps/voip/3cx/restapi/custom/api.pm | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/centreon-plugins/apps/voip/3cx/restapi/custom/api.pm b/centreon-plugins/apps/voip/3cx/restapi/custom/api.pm index 4e41dbb42..783d01e42 100644 --- a/centreon-plugins/apps/voip/3cx/restapi/custom/api.pm +++ b/centreon-plugins/apps/voip/3cx/restapi/custom/api.pm @@ -136,9 +136,11 @@ sub settings { $self->build_options_for_httplib(); $self->{http}->add_header(key => 'Content-Type', value => 'application/json;charset=UTF-8'); - if (defined($self->{cookie}) && defined($self->{xsrf})) { + if (defined($self->{cookie})) { $self->{http}->add_header(key => 'Cookie', value => '.AspNetCore.Cookies=' . $self->{cookie}); - $self->{http}->add_header(key => 'X-XSRF-TOKEN', value => $self->{xsrf}); + if (defined($self->{xsrf})) { + $self->{http}->add_header(key => 'X-XSRF-TOKEN', value => $self->{xsrf}); + } } $self->{http}->set_options(%{$self->{option_results}}); } @@ -171,12 +173,9 @@ sub authenticate { $self->{output}->add_option_msg(short_msg => "Error retrieving cookie"); $self->{output}->option_exit(); } + # 3CX 16.0.5.611 does not use XSRF-TOKEN anymore if (defined ($header) && $header =~ /(?:^| )XSRF-TOKEN=([^;]+);.*/) { $xsrf = $1; - } else { - $self->{output}->output_add(long_msg => $content, debug => 1); - $self->{output}->add_option_msg(short_msg => "Error retrieving xsrf-token"); - $self->{output}->option_exit(); } my $datas = { last_timestamp => time(), cookie => $cookie, xsrf => $xsrf, expires_on => time() + (3600 * 24) }; From c1f3d98990d7a0420c72478ba9cfb0e906da9c4b Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 24 Apr 2020 13:40:37 +0200 Subject: [PATCH 124/190] fix typo --- centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm b/centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm index 91101e489..159b871f2 100644 --- a/centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm +++ b/centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm @@ -33,7 +33,7 @@ sub new { $options{options}->add_options(arguments => { 'sshcli-command:s' => { name => 'sshcli_command', default => 'ssh' }, 'sshcli-path:s' => { name => 'sshcli_path' }, - 'sslcli-option:s@' => { name => 'sshcli_option' } + 'sshcli-option:s@' => { name => 'sshcli_option' } }); $options{options}->add_help(package => __PACKAGE__, sections => 'BACKEND SSHCLI OPTIONS', once => 1); } From 23595fffee9fa9a669738bbcc8e8d7dbb01f8f18 Mon Sep 17 00:00:00 2001 From: Simon Bomm Date: Fri, 24 Apr 2020 14:41:48 +0200 Subject: [PATCH 125/190] + fix typo in perfdata --- centreon-plugins/cloud/aws/ec2/mode/spotactiveinstances.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/cloud/aws/ec2/mode/spotactiveinstances.pm b/centreon-plugins/cloud/aws/ec2/mode/spotactiveinstances.pm index 1b544efe8..e343cec54 100644 --- a/centreon-plugins/cloud/aws/ec2/mode/spotactiveinstances.pm +++ b/centreon-plugins/cloud/aws/ec2/mode/spotactiveinstances.pm @@ -41,7 +41,7 @@ sub set_counters { ], } }, - { label => 'healthy', nlabel => 'ec2.spot.instances.unhealthy.count', set => { + { label => 'healthy', nlabel => 'ec2.spot.instances.healthy.count', set => { key_values => [ { name => 'healthy' } ], output_template => 'Healthy instances : %s', perfdatas => [ From 1756f69d69ef5067d140c4726fff596f6e18fcd2 Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Fri, 24 Apr 2020 16:43:36 +0200 Subject: [PATCH 126/190] fix interfaces discard counter --- centreon-plugins/snmp_standard/mode/interfaces.pm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/centreon-plugins/snmp_standard/mode/interfaces.pm b/centreon-plugins/snmp_standard/mode/interfaces.pm index ff1a38bfa..b46afc57b 100644 --- a/centreon-plugins/snmp_standard/mode/interfaces.pm +++ b/centreon-plugins/snmp_standard/mode/interfaces.pm @@ -1147,8 +1147,8 @@ sub manage_selection { foreach (@{$self->{array_interface_selected}}) { $self->add_result_status(instance => $_) if (defined($self->{option_results}->{add_status})); $self->add_result_traffic(instance => $_) if (defined($self->{option_results}->{add_traffic})); - $self->add_result_cast(instance => $_) if ($self->{no_cast} == 0 && (defined($self->{option_results}->{add_cast}) || defined($self->{option_results}->{add_errors}))); $self->add_result_errors(instance => $_) if (defined($self->{option_results}->{add_errors})); + $self->add_result_cast(instance => $_) if ($self->{no_cast} == 0 && (defined($self->{option_results}->{add_cast}) || defined($self->{option_results}->{add_errors}))); $self->add_result_speed(instance => $_) if (defined($self->{option_results}->{add_speed})); $self->add_result_volume(instance => $_) if (defined($self->{option_results}->{add_volume})); $self->$custom_add_result_method(instance => $_) if ($custom_add_result_method); @@ -1280,7 +1280,19 @@ sub add_result_cast { $self->{int}->{$options{instance}}->{$_} = 0 if (!defined($self->{int}->{$options{instance}}->{$_})); } + # https://tools.ietf.org/html/rfc3635 : The IF-MIB octet counters + # count the number of octets sent to or received from the layer below + # this interface, whereas the packet counters count the number of + # packets sent to or received from the layer above. Therefore, + # received MAC Control frames, ifInDiscards, and ifInUnknownProtos are + # counted by ifInOctets, but not ifInXcastPkts. Transmitted MAC + # Control frames are counted by ifOutOctets, but not ifOutXcastPkts. + # ifOutDiscards and ifOutErrors are counted by ifOutXcastPkts, but not + # ifOutOctets. $self->{int}->{$options{instance}}->{total_in_packets} = $self->{int}->{$options{instance}}->{iucast} + $self->{int}->{$options{instance}}->{imcast} + $self->{int}->{$options{instance}}->{ibcast}; + if (defined($self->{int}->{$options{instance}}->{indiscard})) { + $self->{int}->{$options{instance}}->{total_in_packets} += $self->{int}->{$options{instance}}->{indiscard}; + } $self->{int}->{$options{instance}}->{total_out_packets} = $self->{int}->{$options{instance}}->{oucast} + $self->{int}->{$options{instance}}->{omcast} + $self->{int}->{$options{instance}}->{obcast}; } From 2078e9eb30ad894155fedac518e0ba81bcaeb422 Mon Sep 17 00:00:00 2001 From: Simon Bomm Date: Fri, 24 Apr 2020 17:53:46 +0200 Subject: [PATCH 127/190] fix(plugin) avoid unwanted perl error in some case --- centreon-plugins/apps/centreon/sql/mode/virtualservice.pm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/centreon-plugins/apps/centreon/sql/mode/virtualservice.pm b/centreon-plugins/apps/centreon/sql/mode/virtualservice.pm index 911381522..e740df078 100644 --- a/centreon-plugins/apps/centreon/sql/mode/virtualservice.pm +++ b/centreon-plugins/apps/centreon/sql/mode/virtualservice.pm @@ -324,9 +324,11 @@ sub manage_selection { $config_data->{formatting}->{printf_metric_value}, max(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'max'); - $self->{vmetrics}->{$vcurve}->{aggregated_value} = ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'none' && defined($config_data->{virtualcurve}->{$vcurve}->{custom})) ? - eval "$config_data->{virtualcurve}->{$vcurve}->{custom}" : - eval "$self->{vmetrics}->{$vcurve}->{aggregated_value} $config_data->{virtualcurve}->{$vcurve}->{custom}"; + if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'none') { + $self->{vmetrics}->{$vcurve}->{aggregated_value} = ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'none' && defined($config_data->{virtualcurve}->{$vcurve}->{custom})) ? + eval "$config_data->{virtualcurve}->{$vcurve}->{custom}" : + eval "$self->{vmetrics}->{$vcurve}->{aggregated_value} $config_data->{virtualcurve}->{$vcurve}->{custom}"; + } $self->{vmetrics}->{$vcurve}->{unit} = (defined($config_data->{virtualcurve}->{$vcurve}->{unit})) ? $config_data->{virtualcurve}->{$vcurve}->{unit} : ''; $self->{vmetrics}->{$vcurve}->{min} = (defined($config_data->{virtualcurve}->{$vcurve}->{min})) ? $config_data->{virtualcurve}->{$vcurve}->{min} : ''; From 4617b358859f5040484e83e723053a921888d968 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 27 Apr 2020 10:55:55 +0200 Subject: [PATCH 128/190] wip: bluemind --- .../apps/bluemind/local/custom/api.pm | 183 +++++++++++++++ .../apps/bluemind/local/mode/core.pm | 158 +++++++++++++ .../apps/bluemind/local/mode/lmtpd.pm | 191 ++++++++++++++++ .../apps/bluemind/local/mode/xmpp.pm | 115 ++++++++++ .../apps/bluemind/{ => local}/plugin.pm | 15 +- .../apps/bluemind/mode/incoming.pm | 211 ------------------ 6 files changed, 656 insertions(+), 217 deletions(-) create mode 100644 centreon-plugins/apps/bluemind/local/custom/api.pm create mode 100644 centreon-plugins/apps/bluemind/local/mode/core.pm create mode 100644 centreon-plugins/apps/bluemind/local/mode/lmtpd.pm create mode 100644 centreon-plugins/apps/bluemind/local/mode/xmpp.pm rename centreon-plugins/apps/bluemind/{ => local}/plugin.pm (72%) delete mode 100644 centreon-plugins/apps/bluemind/mode/incoming.pm diff --git a/centreon-plugins/apps/bluemind/local/custom/api.pm b/centreon-plugins/apps/bluemind/local/custom/api.pm new file mode 100644 index 000000000..b0fb2d9fd --- /dev/null +++ b/centreon-plugins/apps/bluemind/local/custom/api.pm @@ -0,0 +1,183 @@ +# +# 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::bluemind::local::custom::api; + +use strict; +use warnings; +use centreon::plugins::ssh; +use centreon::plugins::misc; + +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 => { + 'hostname:s' => { name => 'hostname' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options' } + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'BLUEMIND OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{ssh} = centreon::plugins::ssh->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 get_hostname { + my ($self, %options) = @_; + + return defined($self->{option_results}->{hostname}) ? $self->{option_results}->{hostname} : 'local'; +} + +sub check_options { + my ($self, %options) = @_; + + if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { + $self->{ssh}->check_options(option_results => $self->{option_results}); + } + + return 0; +} + +sub execute_command { + my ($self, %options) = @_; + + my $content; + if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { + ($content) = $self->{ssh}->execute( + hostname => $self->{option_results}->{hostname}, + command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $options{command}, + command_path => $self->{option_results}->{command_path}, + command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef, + timeout => $self->{option_results}->{timeout}, + sudo => $self->{option_results}->{sudo} + ); + } else { + ($content) = centreon::plugins::misc::execute( + output => $self->{output}, + options => { timeout => $self->{option_results}->{timeout} }, + sudo => $self->{option_results}->{sudo}, + command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $options{command}, + command_path => $self->{option_results}->{command_path}, + command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef + ); + } + + my $results = {}; + foreach (split /\n/, $content) { + next if (! /$options{filter}/); + my ($key, $value_str) = split /\s/; + foreach my $value (split /,/, $value_str) { + my ($field1, $field2) = split /=/, $value; + $results->{$key}->{$field1} = $field2; + } + } + + return $results; +} + +1; + +__END__ + +=head1 NAME + +bluemind + +=head1 SYNOPSIS + +bluemind + +=head1 BLUEMIND OPTIONS + +=over 8 + +=item B<--hostname> + +Hostname to query. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information. Used it you have output in a file. + +=item B<--command-path> + +Command path. + +=item B<--command-options> + +Command options. + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/apps/bluemind/local/mode/core.pm b/centreon-plugins/apps/bluemind/local/mode/core.pm new file mode 100644 index 000000000..29d9a9898 --- /dev/null +++ b/centreon-plugins/apps/bluemind/local/mode/core.pm @@ -0,0 +1,158 @@ +# +# 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::bluemind::local::mode::core; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use bigint; + +sub prefix_core_output { + my ($self, %options) = @_; + + return 'Main engine '; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'bm_core', type => 0, cb_prefix_output => 'prefix_core_output' } + ]; + + $self->{maps_counters}->{bm_core} = [ + { label => 'calls-received-success', nlabel => 'core.calls.received.success.count', display_ok => 0, set => { + key_values => [ { name => 'calls_success', diff => 1 } ], + output_template => 'success calls received: %s', + perfdatas => [ + { value => 'calls_success_absolute', template => '%s', min => 0 } + ] + } + }, + { label => 'calls-received-failed', nlabel => 'core.calls.received.failure.count', set => { + key_values => [ { name => 'calls_failure', diff => 1 } ], + output_template => 'failure calls received: %s', + perfdatas => [ + { value => 'calls_failure_absolute', template => '%s', min => 0 } + ] + } + }, + { label => 'heartbeat-broadcast', nlabel => 'core.heartbeat.broadcast.running.count', display_ok => 0, set => { + key_values => [ { name => 'heartbeat_broadcast', diff => 1 } ], + output_template => 'broadcast heartbeat running: %s', + perfdatas => [ + { value => 'heartbeat_broadcast_absolute', template => '%s', min => 0 } + ] + } + }, + { label => 'directory-cluster-events', nlabel => 'core.directory.cluster.events.count', display_ok => 0, set => { + key_values => [ { name => 'cluster_events', diff => 1 } ], + output_template => 'directory cluster events: %s', + perfdatas => [ + { value => 'cluster_events_absolute', template => '%s', min => 0 } + ] + } + }, + { label => 'request-handling-total', nlabel => 'core.request.handling.total.milliseconds', set => { + key_values => [ { name => 'request_handling_time_total', diff => 1 } ], + output_template => 'total request handling: %s ms', + perfdatas => [ + { value => 'request_handling_time_total_absolute', template => '%s', min => 0, unit => 'ms' } + ] + } + }, + { label => 'request-handling-mean', nlabel => 'core.request.handling.mean.milliseconds', display_ok => 0, set => { + key_values => [ { name => 'request_handling_time_mean', diff => 1 } ], + output_template => 'mean request handling: %s ms', + perfdatas => [ + { value => 'request_handling_time_mean_absolute', template => '%s', min => 0, unit => 'ms' } + ] + } + } + ]; +} + +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 => { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + # bm-core.heartbeat.broadcast,state=core.state.running,meterType=Counter count=1854550 + # bm-core.handlingDuration,meterType=Timer count=695244256,totalTime=1911292590914929,mean=2749095 + # bm-core.callsCount,status=failure,meterType=Counter count=97 + # bm-core.callsCount,status=success,meterType=Counter count=125244086 + # bm-core.directory.cluster.events,meterType=Counter count=14300 + my $result = $options{custom}->execute_command( + command => 'curl --unix-socket /var/run/bm-metrics/bm-core.sock http://127.0.0.1/metrics', + filter => 'bm-core\.heartbeat\.broadcast|bm-core\.handlingDuration|bm-core\.callsCount|bm-core\.directory\.cluster\.events' + ); + + $self->{bm_core} = {}; + foreach (keys %$result) { + $self->{bm_core}->{'calls_' . $1} = $result->{$_}->{count} if (/bm-core.callsCount.*status=(failure|success)/); + $self->{bm_core}->{cluster_events} = $result->{$_}->{count} if (/bm-core\.directory\.cluster\.events/); + if (/bm-core\.handlingDuration/) { # in nanoseconds + $self->{bm_core}->{request_handling_time_total} = $result->{$_}->{totalTime} / 1000000; + $self->{bm_core}->{request_handling_time_mean} = $result->{$_}->{mean} / 1000000; + } + $self->{bm_core}->{heartbeat_broadcast} = $result->{$_}->{count} if (/bm-core\.heartbeat\.broadcast.*running/); + } + + $self->{cache_name} = 'bluemind_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check main bluemind engine. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^calls' + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'calls-received-success', 'calls-received-failed', +'heartbeat-broadcast', 'directory-cluster-events', +'request-handling-total', 'request-handling-mean'. + +=back + +=cut diff --git a/centreon-plugins/apps/bluemind/local/mode/lmtpd.pm b/centreon-plugins/apps/bluemind/local/mode/lmtpd.pm new file mode 100644 index 000000000..167d70c51 --- /dev/null +++ b/centreon-plugins/apps/bluemind/local/mode/lmtpd.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::bluemind::local::mode::lmtpd; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use bigint; + +sub prefix_lmtpd_output { + my ($self, %options) = @_; + + return 'Email delivery service '; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'bm_lmtpd', type => 0, cb_prefix_output => 'prefix_lmtpd_output' } + ]; + + $self->{maps_counters}->{bm_lmtpd} = [ + { label => 'connections-active', nlabel => 'lmtpd.connections.active.count', set => { + key_values => [ { name => 'active_connections' } ], + output_template => 'active connections: %s', + perfdatas => [ + { value => 'active_connections_absolute', template => '%s', min => 0 } + ] + } + }, + { label => 'connections-total', nlabel => 'lmtpd.connections.total.count', display_ok => 0, set => { + key_values => [ { name => 'connections', diff => 1 } ], + output_template => 'total connections: %s', + perfdatas => [ + { value => 'connections_absolute', template => '%s', min => 0 } + ] + } + }, + { label => 'deliveries-success', nlabel => 'lmtpd.deliveries.success.count', display_ok => 0, set => { + key_values => [ { name => 'deliveries_ok', diff => 1 } ], + output_template => 'success deliveries: %s', + perfdatas => [ + { value => 'deliveries_ok_absolute', template => '%s', min => 0 } + ] + } + }, + { label => 'deliveries-failure', nlabel => 'lmtpd.deliveries.failure.count', display_ok => 0, set => { + key_values => [ { name => 'deliveries_ko', diff => 1 } ], + output_template => 'failure deliveries: %s', + perfdatas => [ + { value => 'deliveries_ko_absolute', template => '%s', min => 0 } + ] + } + }, + { label => 'emails-size-total', nlabel => 'lmtpd.emails.size.total.count', display_ok => 0, set => { + key_values => [ { name => 'email_size', diff => 1 } ], + output_template => 'total emails size: %s %s', + output_change_bytes => 1, + perfdatas => [ + { value => 'email_size_absolute', template => '%s', min => 0, unit => 'B' } + ] + } + }, + { label => 'sessions-duration-total', nlabel => 'lmtpd.sessions.duration.total.milliseconds', set => { + key_values => [ { name => 'session_duration_total', diff => 1 } ], + output_template => 'total sessions duration: %s ms', + perfdatas => [ + { value => 'session_duration_total_absolute', template => '%s', min => 0, unit => 'ms' } + ] + } + }, + { label => 'sessions-duration-mean', nlabel => 'lmtpd.sessions.duration.mean.milliseconds', set => { + key_values => [ { name => 'session_duration_mean', diff => 1 } ], + output_template => 'mean sessions duration: %s ms', + perfdatas => [ + { value => 'session_duration_mean_absolute', template => '%s', min => 0, unit => 'ms' } + ] + } + }, + { label => 'traffic-transport-latency-total', nlabel => 'lmtpd.traffic.transport.latency.total.milliseconds', set => { + key_values => [ { name => 'traffic_latency_total', diff => 1 } ], + output_template => 'total traffic transport latency: %s ms', + perfdatas => [ + { value => 'traffic_latency_total_absolute', template => '%s', min => 0, unit => 'ms' } + ] + } + }, + { label => 'traffic-transport-latency-mean', nlabel => 'lmtpd.traffic.transport.latency.mean.milliseconds', set => { + key_values => [ { name => 'traffic_latency_mean', diff => 1 } ], + output_template => 'mean traffic transport latency: %s ms', + perfdatas => [ + { value => 'traffic_latency_mean_absolute', template => '%s', min => 0, unit => 'ms' } + ] + } + } + ]; +} + +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 => { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + # bm-lmtpd.activeConnections,meterType=Gauge value=0 + # bm-lmtpd.connectionCount,meterType=Counter count=1236057 + # bm-lmtpd.deliveries,status=ko,meterType=Counter count=410 + # bm-lmtpd.deliveries,status=ok,meterType=Counter count=1390933 + # bm-lmtpd.emailSize,meterType=DistSum count=5020456,totalAmount=1170102671020,mean=233067 + # bm-lmtpd.sessionDuration,meterType=Timer count=4941893,totalTime=1052591049892285,mean=212993492 + # bm-lmtpd.traffic.transportLatency,meterType=Timer count=5017208,totalTime=272844528075000000,mean=54381745400 + my $result = $options{custom}->execute_command( + command => 'curl --unix-socket /var/run/bm-metrics/bm-lmtpd.sock http://127.0.0.1/metrics', + filter => 'activeConnections|connectionCount|deliveries|emailSize|sessionDuration|traffic\.transportLatency' + ); + + $self->{bm_lmtpd} = {}; + foreach (keys %$result) { + $self->{bm_lmtpd}->{'deliveries_' . $1} = $result->{$_}->{count} if (/bm-lmtpd\.deliveries.*status=(ok|ko)/); + $self->{bm_lmtpd}->{active_connections} = $result->{$_}->{value} if (/bm-lmtpd\.activeConnections/); + $self->{bm_lmtpd}->{connections} = $result->{$_}->{count} if (/bm-lmtpd\.connectionCount/); + $self->{bm_lmtpd}->{email_size} = $result->{$_}->{totalAmount} if (/bm-lmtpd\.emailSize/); + if (/bm-lmtpd\.sessionDuration/) { + $self->{bm_lmtpd}->{session_duration_total} = $result->{$_}->{totalAmount} / 100000; + $self->{bm_lmtpd}->{session_duration_mean} = $result->{$_}->{mean} / 100000; + } + if (/bm-lmtpd\.traffic\.transportLatency/) { + $self->{bm_lmtpd}->{traffic_latency_total} = $result->{$_}->{totalAmount} / 100000; + $self->{bm_lmtpd}->{traffic_latency_mean} = $result->{$_}->{mean} / 100000; + } + } + + $self->{cache_name} = 'bluemind_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check email delivery service. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^deliveries' + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'connections-active', 'connections-total', +'deliveries-success', 'deliveries-failure', 'emails-size-total', +'sessions-duration-total', 'sessions-duration-mean', 'traffic-transport-latency-total', +'traffic-transport-latency-mean'. + +=back + +=cut diff --git a/centreon-plugins/apps/bluemind/local/mode/xmpp.pm b/centreon-plugins/apps/bluemind/local/mode/xmpp.pm new file mode 100644 index 000000000..5813b598e --- /dev/null +++ b/centreon-plugins/apps/bluemind/local/mode/xmpp.pm @@ -0,0 +1,115 @@ +# +# 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::bluemind::local::mode::xmpp; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use bigint; + +sub prefix_xmpp_output { + my ($self, %options) = @_; + + return 'Instant messaging service '; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'bm_xmpp', type => 0, cb_prefix_output => 'prefix_xmpp_output' } + ]; + + $self->{maps_counters}->{bm_xmpp} = [ + { label => 'packets-all', nlabel => 'xmpp.packets.all.count', set => { + key_values => [ { name => 'packets_all', diff => 1 } ], + output_template => 'all packets sent: %s', + perfdatas => [ + { value => 'packets_all_absolute', template => '%s', min => 0 } + ] + } + }, + { label => 'packets-chat', nlabel => 'xmpp.packets.chat.count', display_ok => 0, set => { + key_values => [ { name => 'packets_chat', diff => 1 } ], + output_template => 'chat packets sent: %s', + perfdatas => [ + { value => 'packets_chat_absolute', template => '%s', min => 0 } + ] + } + } + ]; +} + +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 => { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + # bm-xmpp.packetsCount,type=all,meterType=Counter count=517791 + # bm-xmpp.packetsCount,type=chat,meterType=Counter count=12 + my $result = $options{custom}->execute_command( + command => 'curl --unix-socket /var/run/bm-metrics/bm-xmpp.sock http://127.0.0.1/metrics', + filter => 'packetsCount' + ); + + $self->{bm_xmpp} = {}; + foreach (keys %$result) { + $self->{bm_xmpp}->{'packets_' . $1} = $result->{$_}->{count} if (/bm-xmpp\.packetsCount.*type=(all|chat)/); + } + + $self->{cache_name} = 'bluemind_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check instant Messaging Service. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='chat' + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'packets-all', 'packets-chat'. + +=back + +=cut diff --git a/centreon-plugins/apps/bluemind/plugin.pm b/centreon-plugins/apps/bluemind/local/plugin.pm similarity index 72% rename from centreon-plugins/apps/bluemind/plugin.pm rename to centreon-plugins/apps/bluemind/local/plugin.pm index 0e15a8010..3f136b7f1 100644 --- a/centreon-plugins/apps/bluemind/plugin.pm +++ b/centreon-plugins/apps/bluemind/local/plugin.pm @@ -18,11 +18,11 @@ # limitations under the License. # -package apps::bluemind::plugin; +package apps::bluemind::local::plugin; use strict; use warnings; -use base qw(centreon::plugins::script_simple); +use base qw(centreon::plugins::script_custom); sub new { my ($class, %options) = @_; @@ -31,10 +31,13 @@ sub new { bless $self, $class; $self->{version} = '0.1'; - %{$self->{modes}} = ( - 'incoming' => 'apps::bluemind::mode::incoming', - ); + $self->{modes} = { + 'core' => 'apps::bluemind::local::mode::core', + 'lmtpd' => 'apps::bluemind::local::mode::lmtpd', + 'xmpp' => 'apps::bluemind::local::mode::xmpp' + }; + $self->{custom_modes}{api} = 'apps::bluemind::local::custom::api'; return $self; } @@ -45,6 +48,6 @@ __END__ =head1 PLUGIN DESCRIPTION -Check BlueMind through InfluxDB API +Check BlueMind through bm-metrics sockets =cut diff --git a/centreon-plugins/apps/bluemind/mode/incoming.pm b/centreon-plugins/apps/bluemind/mode/incoming.pm deleted file mode 100644 index ef44860b2..000000000 --- a/centreon-plugins/apps/bluemind/mode/incoming.pm +++ /dev/null @@ -1,211 +0,0 @@ -# -# 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::bluemind::mode::incoming; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; -use centreon::plugins::http; -use centreon::plugins::statefile; -use JSON; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '8086'}, - "proto:s" => { name => 'proto' }, - "urlpath:s" => { name => 'url_path', default => "/db" }, - "database:s" => { name => 'database' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); - - $self->{statefile_value} = centreon::plugins::statefile->new(%options); - $self->{http} = centreon::plugins::http->new(%options); - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } - if (!defined($self->{option_results}->{database})) { - $self->{output}->add_option_msg(short_msg => "Please set the database option"); - $self->{output}->option_exit(); - } - if ((!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { - $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= option"); - $self->{output}->option_exit(); - } - - my $query = 'select sum("success") as "success_sum", sum("failure") as "failure_sum" from lmtpd.deliveries where time > '.$old_timestamp.'s and time < now()'; - $self->{option_results}->{url_path} = $self->{option_results}->{url_path}."/".$self->{option_results}->{database}."/series"; - $self->{option_results}->{get_param} = []; - push @{$self->{option_results}->{get_param}}, "q=" . $query, "p=" . $self->{option_results}->{password}, "u=" . $self->{option_results}->{username}; - - $self->{http}->set_options(%{$self->{option_results}}); - $self->{statefile_value}->check_options(%options); -} - -sub run { - my ($self, %options) = @_; - - $self->{statefile_value}->read(statefile => 'bluemind_' . $self->{option_results}->{hostname} . '_' . $self->{http}->get_port() . '_' . $self->{mode}); - my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp'); - - my $new_datas = {}; - $new_datas->{last_timestamp} = time(); - $self->{statefile_value}->write(data => $new_datas); - - if (!defined($old_timestamp)) { - $self->{output}->output_add(severity => 'OK', - short_msg => "Buffer creation..."); - $self->{output}->display(); - $self->{output}->exit(); - } - - my $jsoncontent = $self->{http}->request(); - - my $json = JSON->new; - my $webcontent; - - eval { - $webcontent = $json->decode($jsoncontent); - }; - - if ($@) { - $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); - $self->{output}->option_exit(); - } - - my $hwebcontent; - for my $ref (@{ $webcontent }) { - my $name = $ref->{name}; - my @columns = @{ $ref->{columns} }; - - for my $points (@{ $ref->{points} }) { - my %hash; - @hash{ @columns } = @$points; - push @{ $hwebcontent->{$name} }, \%hash; - } - } - - my $success_incoming_mails = defined($hwebcontent->{qw(lmtpd.deliveries)}->[0]->{success_sum}) ? $hwebcontent->{qw(lmtpd.deliveries)}->[0]->{success_sum} : '0'; - my $failure_incoming_mails = defined($hwebcontent->{qw(lmtpd.deliveries)}->[0]->{failure_sum}) ? $hwebcontent->{qw(lmtpd.deliveries)}->[0]->{failure_sum} : '0'; - - # If not present: failure and success incoming mails are 0 - if (!defined($success_incoming_mails)) { - $success_incoming_mails = 0; - } - - if (!defined($failure_incoming_mails)) { - $failure_incoming_mails = 0; - } - - my $exit = $self->{perfdata}->threshold_check(value => $failure_incoming_mails, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Success Incoming Mails: %d - Failure Incoming Mails: %d",$success_incoming_mails,$failure_incoming_mails)); - $self->{output}->perfdata_add(label => 'success', - value => sprintf("%d", $success_incoming_mails), - min => 0, - ); - $self->{output}->perfdata_add(label => 'failure', - value => sprintf("%d", $failure_incoming_mails), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, - ); - - $self->{output}->display(); - $self->{output}->exit(); - -} - -1; - -__END__ - -=head1 MODE - -Check Bluemind incoming_mails (success and failure) - -=over 8 - -=item B<--hostname> - -IP Addr/FQDN of the Bluemind host - -=item B<--port> - -Port used by InfluxDB API (Default: '8086') - -=item B<--proto> - -Specify https if needed (Default: 'http') - -=item B<--urlpath> - -Set path to get influxdb information (Default: '/db') - -=item B<--database> - -InfluxDB Database name - -=item B<--username> - -Specify username for API authentification - -=item B<--password> - -Specify password for API authentification - -=item B<--timeout> - -Threshold for HTTP timeout (Default: 5) - -=item B<--warning> - -Warning Threshold for failure incoming mails - -=item B<--critical> - -Critical Threshold for failure incoming mails - -=back - -=cut From ba2235f6a64e21b50437b8d7b421d15291bf7ac4 Mon Sep 17 00:00:00 2001 From: thibaults-centreon Date: Mon, 27 Apr 2020 13:24:06 +0200 Subject: [PATCH 129/190] fix(plugin): fix aws vpn --- centreon-plugins/cloud/aws/vpn/mode/traffic.pm | 2 +- centreon-plugins/cloud/aws/vpn/plugin.pm | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/centreon-plugins/cloud/aws/vpn/mode/traffic.pm b/centreon-plugins/cloud/aws/vpn/mode/traffic.pm index 7e8e458d9..db56097a3 100644 --- a/centreon-plugins/cloud/aws/vpn/mode/traffic.pm +++ b/centreon-plugins/cloud/aws/vpn/mode/traffic.pm @@ -187,7 +187,7 @@ sub set_counters { closure_custom_perfdata => ($metric =~ /State/) ? $self->can('custom_metric_perfdata_state') : $self->can('custom_metric_perfdata'), closure_custom_threshold_check => $self->can('custom_metric_threshold'), } - } + }; push @{$self->{maps_counters}->{statistics}}, $entry; } } diff --git a/centreon-plugins/cloud/aws/vpn/plugin.pm b/centreon-plugins/cloud/aws/vpn/plugin.pm index 208a13de7..d07982549 100644 --- a/centreon-plugins/cloud/aws/vpn/plugin.pm +++ b/centreon-plugins/cloud/aws/vpn/plugin.pm @@ -32,8 +32,7 @@ sub new { $self->{version} = '1.0'; %{ $self->{modes} } = ( 'traffic' => 'cloud::aws::vpn::mode::traffic', - 'listvpn' => 'cloud::aws::vpn::mode::listvpn', - 'discovery' => 'cloud::aws::vpn::mode::discovery' + 'listvpn' => 'cloud::aws::vpn::mode::listvpn' ); $self->{custom_modes}{paws} = 'cloud::aws::custom::paws'; From 030546e716dadc326587e0bd6f63d71313f6ba4f Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 27 Apr 2020 15:47:53 +0200 Subject: [PATCH 130/190] new version of bluemind plugin --- .../apps/bluemind/local/mode/core.pm | 4 +- .../apps/bluemind/local/mode/eas.pm | 128 +++++++++++ .../apps/bluemind/local/mode/hps.pm | 205 ++++++++++++++++++ .../apps/bluemind/local/mode/ips.pm | 96 ++++++++ .../apps/bluemind/local/mode/lmtpd.pm | 12 +- .../apps/bluemind/local/mode/milter.pm | 168 ++++++++++++++ .../apps/bluemind/local/mode/webserver.pm | 152 +++++++++++++ .../apps/bluemind/local/mode/xmpp.pm | 4 +- .../apps/bluemind/local/plugin.pm | 11 +- 9 files changed, 767 insertions(+), 13 deletions(-) create mode 100644 centreon-plugins/apps/bluemind/local/mode/eas.pm create mode 100644 centreon-plugins/apps/bluemind/local/mode/hps.pm create mode 100644 centreon-plugins/apps/bluemind/local/mode/ips.pm create mode 100644 centreon-plugins/apps/bluemind/local/mode/milter.pm create mode 100644 centreon-plugins/apps/bluemind/local/mode/webserver.pm diff --git a/centreon-plugins/apps/bluemind/local/mode/core.pm b/centreon-plugins/apps/bluemind/local/mode/core.pm index 29d9a9898..a266e1a23 100644 --- a/centreon-plugins/apps/bluemind/local/mode/core.pm +++ b/centreon-plugins/apps/bluemind/local/mode/core.pm @@ -82,7 +82,7 @@ sub set_counters { } }, { label => 'request-handling-mean', nlabel => 'core.request.handling.mean.milliseconds', display_ok => 0, set => { - key_values => [ { name => 'request_handling_time_mean', diff => 1 } ], + key_values => [ { name => 'request_handling_time_mean' } ], output_template => 'mean request handling: %s ms', perfdatas => [ { value => 'request_handling_time_mean_absolute', template => '%s', min => 0, unit => 'ms' } @@ -112,7 +112,7 @@ sub manage_selection { # bm-core.callsCount,status=success,meterType=Counter count=125244086 # bm-core.directory.cluster.events,meterType=Counter count=14300 my $result = $options{custom}->execute_command( - command => 'curl --unix-socket /var/run/bm-metrics/bm-core.sock http://127.0.0.1/metrics', + command => 'curl --unix-socket /var/run/bm-metrics/metrics-bm-core.sock http://127.0.0.1/metrics', filter => 'bm-core\.heartbeat\.broadcast|bm-core\.handlingDuration|bm-core\.callsCount|bm-core\.directory\.cluster\.events' ); diff --git a/centreon-plugins/apps/bluemind/local/mode/eas.pm b/centreon-plugins/apps/bluemind/local/mode/eas.pm new file mode 100644 index 000000000..058038c0a --- /dev/null +++ b/centreon-plugins/apps/bluemind/local/mode/eas.pm @@ -0,0 +1,128 @@ +# +# 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::bluemind::local::mode::eas; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use bigint; + +sub prefix_eas_output { + my ($self, %options) = @_; + + return 'Mobile connection service '; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'bm_eas', type => 0, cb_prefix_output => 'prefix_eas_output' } + ]; + + $self->{maps_counters}->{bm_eas} = [ + { label => 'responses-size-total', nlabel => 'eas.responses.size.total.count', display_ok => 0, set => { + key_values => [ { name => 'response_size', diff => 1 } ], + output_template => 'total responses size: %s %s', + output_change_bytes => 1, + perfdatas => [ + { value => 'response_size_absolute', template => '%s', min => 0, unit => 'B' } + ] + } + }, + { label => 'execution-total', nlabel => 'eas.execution.total.milliseconds', display_ok => 0, set => { + key_values => [ { name => 'execution_total', diff => 1 } ], + output_template => 'total execution: %s ms', + perfdatas => [ + { value => 'execution_total_absolute', template => '%s', min => 0, unit => 'ms' } + ] + } + }, + { label => 'execution-mean', nlabel => 'eas.execution.mean.milliseconds', set => { + key_values => [ { name => 'execution_mean' } ], + output_template => 'mean execution: %s ms', + perfdatas => [ + { value => 'execution_mean_absolute', template => '%s', min => 0, unit => 'ms' } + ] + } + } + ]; +} + +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 => { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + # bm-eas.executionTime,meterType=Timer count=23865528,totalTime=48394780739993049,mean=2027811022 + # bm-eas.responseSize,meterType=DistSum count=31508001,totalAmount=736453775233,mean=23373 + my $result = $options{custom}->execute_command( + command => 'curl --unix-socket /var/run/bm-metrics/metrics-bm-eas.sock http://127.0.0.1/metrics', + filter => 'executionTime|responseSize' + ); + + $self->{bm_eas} = {}; + foreach (keys %$result) { + $self->{bm_eas}->{response_size} = $result->{$_}->{totalAmount} if (/bm-eas.responseSize/); + if (/bm-eas\.executionTime/) { + $self->{bm_eas}->{execution_total} = $result->{$_}->{totalTime} / 100000; + $self->{bm_eas}->{execution_mean} = $result->{$_}->{mean} / 100000; + } + } + + $self->{cache_name} = 'bluemind_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check mobile connection service. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^execution' + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'responses-size-total', 'execution-total', 'execution-mean'. + +=back + +=cut diff --git a/centreon-plugins/apps/bluemind/local/mode/hps.pm b/centreon-plugins/apps/bluemind/local/mode/hps.pm new file mode 100644 index 000000000..235191345 --- /dev/null +++ b/centreon-plugins/apps/bluemind/local/mode/hps.pm @@ -0,0 +1,205 @@ +# +# 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::bluemind::local::mode::hps; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use bigint; + +sub prefix_hps_output { + my ($self, %options) = @_; + + return 'Authentication service '; +} +sub prefix_upstream_output { + my ($self, %options) = @_; + + return "Upstream '" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'bm_hps', type => 0, cb_prefix_output => 'prefix_hps_output' }, + { name => 'bm_hps_upstream', type => 1, cb_prefix_output => 'prefix_upstream_output', message_multiple => 'All upstreams are ok' } + ]; + + $self->{maps_counters}->{bm_hps} = [ + { label => 'authentication-success', nlabel => 'hps.authentication.success.count', display_ok => 0, set => { + key_values => [ { name => 'auth_success', diff => 1 } ], + output_template => 'success authentication: %s', + perfdatas => [ + { value => 'auth_success_absolute', template => '%s', min => 0 } + ] + } + }, + { label => 'authentication-failure', nlabel => 'hps.authentication.failure.count', set => { + key_values => [ { name => 'auth_failure', diff => 1 } ], + output_template => 'failure authentication: %s', + perfdatas => [ + { value => 'auth_failure_absolute', template => '%s', min => 0 } + ] + } + }, + { label => 'requests-protected', nlabel => 'hps.requests.protected.count', display_ok => 0, set => { + key_values => [ { name => 'requests_protected', diff => 1 } ], + output_template => 'protected requests: %s', + perfdatas => [ + { value => 'requests_protected_absolute', template => '%s', min => 0 } + ] + } + }, + { label => 'requests-maintenance', nlabel => 'hps.requests.maintenance.count', set => { + key_values => [ { name => 'requests_maintenance', diff => 1 } ], + output_template => 'maintenance requests: %s', + perfdatas => [ + { value => 'requests_maintenance_absolute', template => '%s', min => 0 } + ] + } + } + ]; + + $self->{maps_counters}->{bm_hps_upstream} = [ + { label => 'upstream-requests-time-total', nlabel => 'hps.upstream.requests.time.milliseconds', display_ok => 0, set => { + key_values => [ { name => 'requests_time_total', diff => 1 }, { name => 'display' } ], + output_template => 'total requests time: %s ms', + perfdatas => [ + { value => 'requests_time_total_absolute', template => '%s', min => 0, unit => 'ms', label_extra_instance => 1 } + ] + } + }, + { label => 'upstream-requests-time-mean', nlabel => 'hps.upstream.requests.time.mean.milliseconds', set => { + key_values => [ { name => 'requests_time_mean' }, { name => 'display' } ], + output_template => 'mean requests time: %s ms', + perfdatas => [ + { value => 'requests_time_mean_absolute', template => '%s', min => 0, unit => 'ms', label_extra_instance => 1 } + ] + } + }, + { label => 'upstream-requests-size-total', nlabel => 'hps.upstream.requests.size.total.bytes', display_ok => 0, set => { + key_values => [ { name => 'requests_size', diff => 1 } ], + output_template => 'total requests size: %s %s', + output_change_bytes => 1, + perfdatas => [ + { value => 'requests_size_absolute', template => '%s', min => 0, unit => 'B' } + ] + } + }, + { label => 'upstream-requests-total', nlabel => 'hps.upstream.requests.total.count', display_ok => 0, set => { + key_values => [ { name => 'requests', diff => 1 } ], + output_template => 'total requests: %s', + perfdatas => [ + { value => 'requests_absolute', template => '%s', min => 0 } + ] + } + } + ]; +} + +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-upstream:s' => { name => 'filter_upstream' } + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + # bm-hps.authCount,status=failure,meterType=Counter count=855 + # bm-hps.authCount,status=success,meterType=Counter count=11957 + # bm-hps.ftlTemplates.requests,meterType=Counter count=23064 + # bm-hps.requestsCount,kind=protected,meterType=Counter count=3080815 + # bm-hps.requestsCount,kind=maintenance,meterType=Counter count=1 + # bm-hps.upstreamRequestSize,path=/login,meterType=DistSum count=331977,totalAmount=0,mean=0 + # bm-hps.upstreamRequestTime,path=/login,meterType=Timer count=37864,totalTime=70405376220,mean=1859427 + # bm-hps.upstreamRequestsCount,path=/login,meterType=Counter count=1383 + my $result = $options{custom}->execute_command( + command => 'curl --unix-socket /var/run/bm-metrics/metrics-bm-hps.sock http://127.0.0.1/metrics', + filter => 'authCount|ftlTemplates\.requests|requestsCount|upstreamRequestSize|upstreamRequestTime|upstreamRequestsCount' + ); + + $self->{bm_hps} = {}; + $self->{bm_hps_upstream} = {}; + foreach (keys %$result) { + $self->{bm_hps}->{'auth_' . $1} = $result->{$_}->{count} if (/bm-hps\.authCount.*status=(failure|success)/); + $self->{bm_hps}->{'requests_' . $1} = $result->{$_}->{count} if (/bm-hps\.requestsCount.*kind=(maintenance|protected)/); + + if (/bm-hps\.upstreamRequestTime.*path=(.*?),/) { + my $upstream = $1; + if (defined($self->{option_results}->{filter_upstream}) && $self->{option_results}->{filter_upstream} ne '' && + $upstream !~ /$self->{option_results}->{filter_upstream}/) { + $self->{output}->output_add(long_msg => "skipping upstream '" . $upstream . "': no matching filter.", debug => 1); + next; + } + + $self->{bm_hps_upstream}->{$upstream} = { + display => $upstream, + requests_time_total => $result->{$_}->{totalTime} / 100000, + requests_time_mean => $result->{$_}->{mean} / 100000, + requests_size => $result->{"bm-hps.upstreamRequestSize,path=$upstream,meterType=DistSum"}->{totalAmount}, + requests => $result->{"bm-hps.upstreamRequestsCount,path=$upstream,meterType=Counter"}->{count} + }; + } + } + + $self->{cache_name} = 'bluemind_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check authentication service. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='maintenance' + +=item B<--filter-upstream> + +Filter upstream name (can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'authentication-success', 'authentication-failure', 'requests-protected', +'requests-maintenance', 'upstream-requests-time-total', 'upstream-requests-time-mean', +'upstream-requests-size-total, 'upstream-requests-total'. + +=back + +=cut diff --git a/centreon-plugins/apps/bluemind/local/mode/ips.pm b/centreon-plugins/apps/bluemind/local/mode/ips.pm new file mode 100644 index 000000000..8b7b58c66 --- /dev/null +++ b/centreon-plugins/apps/bluemind/local/mode/ips.pm @@ -0,0 +1,96 @@ +# +# 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::bluemind::local::mode::ips; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub prefix_ips_output { + my ($self, %options) = @_; + + return 'IMAP operations tracking '; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'bm_ips', type => 0, cb_prefix_output => 'prefix_ips_output' } + ]; + + $self->{maps_counters}->{bm_ips} = [ + { label => 'connections-active', nlabel => 'ips.connections.active.count', set => { + key_values => [ { name => 'active_connections' } ], + output_template => 'active connections: %s', + perfdatas => [ + { value => 'active_connections_absolute', template => '%s', min => 0 } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + # bm-ips.activeConnections,meterType=Gauge value=718 + my $result = $options{custom}->execute_command( + command => 'curl --unix-socket /var/run/bm-metrics/metrics-bm-ips.sock http://127.0.0.1/metrics', + filter => 'activeConnections' + ); + + $self->{bm_ips} = {}; + foreach (keys %$result) { + $self->{bm_ips}->{active_connections} = $result->{$_}->{value} if (/bm-ips\.activeConnections/); + } +} + +1; + +__END__ + +=head1 MODE + +Check IMAP operations tracking. + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'active-connections'. + +=back + +=cut diff --git a/centreon-plugins/apps/bluemind/local/mode/lmtpd.pm b/centreon-plugins/apps/bluemind/local/mode/lmtpd.pm index 167d70c51..0a985bc71 100644 --- a/centreon-plugins/apps/bluemind/local/mode/lmtpd.pm +++ b/centreon-plugins/apps/bluemind/local/mode/lmtpd.pm @@ -73,7 +73,7 @@ sub set_counters { ] } }, - { label => 'emails-size-total', nlabel => 'lmtpd.emails.size.total.count', display_ok => 0, set => { + { label => 'emails-size-total', nlabel => 'lmtpd.emails.size.total.bytes', display_ok => 0, set => { key_values => [ { name => 'email_size', diff => 1 } ], output_template => 'total emails size: %s %s', output_change_bytes => 1, @@ -91,7 +91,7 @@ sub set_counters { } }, { label => 'sessions-duration-mean', nlabel => 'lmtpd.sessions.duration.mean.milliseconds', set => { - key_values => [ { name => 'session_duration_mean', diff => 1 } ], + key_values => [ { name => 'session_duration_mean' } ], output_template => 'mean sessions duration: %s ms', perfdatas => [ { value => 'session_duration_mean_absolute', template => '%s', min => 0, unit => 'ms' } @@ -107,7 +107,7 @@ sub set_counters { } }, { label => 'traffic-transport-latency-mean', nlabel => 'lmtpd.traffic.transport.latency.mean.milliseconds', set => { - key_values => [ { name => 'traffic_latency_mean', diff => 1 } ], + key_values => [ { name => 'traffic_latency_mean' } ], output_template => 'mean traffic transport latency: %s ms', perfdatas => [ { value => 'traffic_latency_mean_absolute', template => '%s', min => 0, unit => 'ms' } @@ -139,7 +139,7 @@ sub manage_selection { # bm-lmtpd.sessionDuration,meterType=Timer count=4941893,totalTime=1052591049892285,mean=212993492 # bm-lmtpd.traffic.transportLatency,meterType=Timer count=5017208,totalTime=272844528075000000,mean=54381745400 my $result = $options{custom}->execute_command( - command => 'curl --unix-socket /var/run/bm-metrics/bm-lmtpd.sock http://127.0.0.1/metrics', + command => 'curl --unix-socket /var/run/bm-metrics/metrics-bm-lmtpd.sock http://127.0.0.1/metrics', filter => 'activeConnections|connectionCount|deliveries|emailSize|sessionDuration|traffic\.transportLatency' ); @@ -150,11 +150,11 @@ sub manage_selection { $self->{bm_lmtpd}->{connections} = $result->{$_}->{count} if (/bm-lmtpd\.connectionCount/); $self->{bm_lmtpd}->{email_size} = $result->{$_}->{totalAmount} if (/bm-lmtpd\.emailSize/); if (/bm-lmtpd\.sessionDuration/) { - $self->{bm_lmtpd}->{session_duration_total} = $result->{$_}->{totalAmount} / 100000; + $self->{bm_lmtpd}->{session_duration_total} = $result->{$_}->{totalTime} / 100000; $self->{bm_lmtpd}->{session_duration_mean} = $result->{$_}->{mean} / 100000; } if (/bm-lmtpd\.traffic\.transportLatency/) { - $self->{bm_lmtpd}->{traffic_latency_total} = $result->{$_}->{totalAmount} / 100000; + $self->{bm_lmtpd}->{traffic_latency_total} = $result->{$_}->{totalTime} / 100000; $self->{bm_lmtpd}->{traffic_latency_mean} = $result->{$_}->{mean} / 100000; } } diff --git a/centreon-plugins/apps/bluemind/local/mode/milter.pm b/centreon-plugins/apps/bluemind/local/mode/milter.pm new file mode 100644 index 000000000..a762467f5 --- /dev/null +++ b/centreon-plugins/apps/bluemind/local/mode/milter.pm @@ -0,0 +1,168 @@ +# +# 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::bluemind::local::mode::milter; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use bigint; + +sub prefix_milter_output { + my ($self, %options) = @_; + + return 'Milter service '; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'bm_milter', type => 0, cb_prefix_output => 'prefix_milter_output' } + ]; + + $self->{maps_counters}->{bm_milter} = [ + { label => 'connections-total', nlabel => 'milter.connections.total.count', set => { + key_values => [ { name => 'connections', diff => 1 } ], + output_template => 'total connections: %s', + perfdatas => [ + { value => 'connections_absolute', template => '%s', min => 0 } + ] + } + }, + { label => 'traffic-class-inbound', nlabel => 'milter.traffic.class.inbound.count', display_ok => 0, set => { + key_values => [ { name => 'traffic_class_inbound', diff => 1 } ], + output_template => 'traffic class inbound: %s', + perfdatas => [ + { value => 'traffic_class_inbound_absolute', template => '%s', min => 0 } + ] + } + }, + { label => 'traffic-class-outbound', nlabel => 'milter.traffic.class.outbound.count', display_ok => 0, set => { + key_values => [ { name => 'traffic_class_outbound', diff => 1 } ], + output_template => 'traffic class outbound: %s', + perfdatas => [ + { value => 'traffic_class_outbound_absolute', template => '%s', min => 0 } + ] + } + }, + { label => 'traffic-size-inbound', nlabel => 'milter.traffic.size.inbound.bytes', display_ok => 0, set => { + key_values => [ { name => 'traffic_size_inbound', diff => 1 } ], + output_template => 'traffic size inbound: %s %s', + output_change_bytes => 1, + perfdatas => [ + { value => 'traffic_size_inbound_absolute', template => '%s', min => 0, unit => 'B' } + ] + } + }, + { label => 'traffic-size-outbound', nlabel => 'milter.traffic.size.outbound.bytes', display_ok => 0, set => { + key_values => [ { name => 'traffic_size_outbound', diff => 1 } ], + output_template => 'traffic size outbound: %s %s', + output_change_bytes => 1, + perfdatas => [ + { value => 'traffic_size_outbound_absolute', template => '%s', min => 0, unit => 'B' } + ] + } + }, + { label => 'sessions-duration-total', nlabel => 'milter.sessions.duration.total.milliseconds', display_ok => 0, set => { + key_values => [ { name => 'session_duration_total', diff => 1 } ], + output_template => 'total sessions duration: %s ms', + perfdatas => [ + { value => 'session_duration_total_absolute', template => '%s', min => 0, unit => 'ms' } + ] + } + }, + { label => 'sessions-duration-mean', nlabel => 'milter.sessions.duration.mean.milliseconds', set => { + key_values => [ { name => 'session_duration_mean' } ], + output_template => 'mean sessions duration: %s ms', + perfdatas => [ + { value => 'session_duration_mean_absolute', template => '%s', min => 0, unit => 'ms' } + ] + } + } + ]; +} + +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 => { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + # bm-milter.connectionsCount,meterType=Counter count=2017123 + # bm-milter.sessionDuration,meterType=Timer count=11553431,totalTime=21943249233042775,mean=1899284224 + # bm-milter.traffic.class,type=INBOUND,meterType=Counter count=1289087 + # bm-milter.traffic.class,type=OUTBOUND,meterType=Counter count=415711 + # bm-milter.traffic.size,type=INBOUND,meterType=Counter count=29063863392 + # bm-milter.traffic.size,type=OUTBOUND,meterType=Counter count=10763275492 + my $result = $options{custom}->execute_command( + command => 'curl --unix-socket /var/run/bm-metrics/metrics-bm-milter.sock http://127.0.0.1/metrics', + filter => 'connectionsCount|sessionDuration|traffic\.class|traffic\.size' + ); + + $self->{bm_milter} = {}; + foreach (keys %$result) { + $self->{bm_milter}->{'traffic_class_' . lc($1)} = $result->{$_}->{count} if (/bm-milter\.traffic\.class.*type=(INBOUND|OUTBOUND)/i); + $self->{bm_milter}->{'traffic_size_' . lc($1)} = $result->{$_}->{count} if (/bm-milter\.traffic\.size.*type=(INBOUND|OUTBOUND)/i); + $self->{bm_milter}->{connections} = $result->{$_}->{count} if (/bm-milter\.connectionsCount/); + if (/bm-milter\.sessionDuration/) { + $self->{bm_milter}->{session_duration_total} = $result->{$_}->{totalTime} / 100000; + $self->{bm_milter}->{session_duration_mean} = $result->{$_}->{mean} / 100000; + } + } + + $self->{cache_name} = 'bluemind_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check milter service. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^deliveries' + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'connections-total', 'traffic-class-inbound', 'traffic-class-outbound', +'traffic-size-inbound', 'traffic-size-outbound', 'sessions-duration-total', 'sessions-duration-mean' . + +=back + +=cut diff --git a/centreon-plugins/apps/bluemind/local/mode/webserver.pm b/centreon-plugins/apps/bluemind/local/mode/webserver.pm new file mode 100644 index 000000000..3e2aede4a --- /dev/null +++ b/centreon-plugins/apps/bluemind/local/mode/webserver.pm @@ -0,0 +1,152 @@ +# +# 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::bluemind::local::mode::webserver; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use bigint; + +sub prefix_webserver_output { + my ($self, %options) = @_; + + return 'Web application server '; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'bm_webserver', type => 0, cb_prefix_output => 'prefix_webserver_output' }, + ]; + + $self->{maps_counters}->{bm_webserver} = [ + { label => 'requests-time-total', nlabel => 'webserver.requests.time.milliseconds', display_ok => 0, set => { + key_values => [ { name => 'requests_time_total', diff => 1 } ], + output_template => 'total requests time: %s ms', + perfdatas => [ + { value => 'requests_time_total_absolute', template => '%s', min => 0, unit => 'ms' } + ] + } + }, + { label => 'requests-time-mean', nlabel => 'webserver.requests.time.mean.milliseconds', set => { + key_values => [ { name => 'requests_time_mean' } ], + output_template => 'mean requests time: %s ms', + perfdatas => [ + { value => 'requests_time_mean_absolute', template => '%s', min => 0, unit => 'ms' } + ] + } + }, + { label => 'requests-total', nlabel => 'webserver.requests.total.count', set => { + key_values => [ { name => 'requests', diff => 1 } ], + output_template => 'total requests: %s', + perfdatas => [ + { value => 'requests_absolute', template => '%s', min => 0 } + ] + } + }, + { label => 'requests-status-200', nlabel => 'webserver.requests.status.200.count', display_ok => 0, set => { + key_values => [ { name => 'requests_200', diff => 1 } ], + output_template => 'total 200 requests: %s', + perfdatas => [ + { value => 'requests_200_absolute', template => '%s', min => 0 } + ] + } + }, + { label => 'requests-status-304', nlabel => 'webserver.requests.status.304.count', display_ok => 0, set => { + key_values => [ { name => 'requests_304', diff => 1 } ], + output_template => 'total 304 requests: %s', + perfdatas => [ + { value => 'requests_304_absolute', template => '%s', min => 0 } + ] + } + } + ]; +} + +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 => { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + # bm-webserver.appCache.requestTime,meterType=Timer count=91005,totalTime=46688008481,mean=513026 + # bm-webserver.appCache.requests,meterType=Counter count=8552 + # bm-webserver.staticFile.requests,status=200,meterType=Counter count=318881 + # bm-webserver.staticFile.requests,status=304,meterType=Counter count=3485778 + my $result = $options{custom}->execute_command( + command => 'curl --unix-socket /var/run/bm-metrics/metrics-bm-webserver.sock http://127.0.0.1/metrics', + filter => 'appCache|staticFile\.requests' + ); + + $self->{bm_webserver} = {}; + foreach (keys %$result) { + $self->{bm_webserver}->{'requests_' . $1} = $result->{$_}->{count} if (/bm-webserver\.staticFile\.requests.*,status=(200|304)/); + $self->{bm_webserver}->{requests} = $result->{$_}->{count} if (/bm-webserver\.appCache\.requests/); + + if (/bm-webserver\.appCache\.requestTime/) { + $self->{bm_webserver}->{requests_time_total} = $result->{$_}->{totalTime} / 100000; + $self->{bm_webserver}->{requests_time_mean} = $result->{$_}->{mean} / 100000; + } + } + + $self->{cache_name} = 'bluemind_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check web application server. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='requests-time-mean' + +=item B<--filter-upstream> + +Filter upstream name (can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'requests-time-total', 'requests-time-mean', 'requests-total', +'requests-status-200', 'requests-status-304'. + +=back + +=cut diff --git a/centreon-plugins/apps/bluemind/local/mode/xmpp.pm b/centreon-plugins/apps/bluemind/local/mode/xmpp.pm index 5813b598e..859d394ce 100644 --- a/centreon-plugins/apps/bluemind/local/mode/xmpp.pm +++ b/centreon-plugins/apps/bluemind/local/mode/xmpp.pm @@ -77,7 +77,7 @@ sub manage_selection { # bm-xmpp.packetsCount,type=all,meterType=Counter count=517791 # bm-xmpp.packetsCount,type=chat,meterType=Counter count=12 my $result = $options{custom}->execute_command( - command => 'curl --unix-socket /var/run/bm-metrics/bm-xmpp.sock http://127.0.0.1/metrics', + command => 'curl --unix-socket /var/run/bm-metrics/metrics-bm-xmpp.sock http://127.0.0.1/metrics', filter => 'packetsCount' ); @@ -96,7 +96,7 @@ __END__ =head1 MODE -Check instant Messaging Service. +Check instant messaging service. =over 8 diff --git a/centreon-plugins/apps/bluemind/local/plugin.pm b/centreon-plugins/apps/bluemind/local/plugin.pm index 3f136b7f1..7fb8c72db 100644 --- a/centreon-plugins/apps/bluemind/local/plugin.pm +++ b/centreon-plugins/apps/bluemind/local/plugin.pm @@ -32,9 +32,14 @@ sub new { $self->{version} = '0.1'; $self->{modes} = { - 'core' => 'apps::bluemind::local::mode::core', - 'lmtpd' => 'apps::bluemind::local::mode::lmtpd', - 'xmpp' => 'apps::bluemind::local::mode::xmpp' + 'core' => 'apps::bluemind::local::mode::core', + 'eas' => 'apps::bluemind::local::mode::eas', + 'hps' => 'apps::bluemind::local::mode::hps', + 'ips' => 'apps::bluemind::local::mode::ips', + 'lmtpd' => 'apps::bluemind::local::mode::lmtpd', + 'milter' => 'apps::bluemind::local::mode::milter', + 'webserver' => 'apps::bluemind::local::mode::webserver', + 'xmpp' => 'apps::bluemind::local::mode::xmpp' }; $self->{custom_modes}{api} = 'apps::bluemind::local::custom::api'; From b6a879d1eb3a0f4311692941acba988fe60ab715 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 27 Apr 2020 16:44:29 +0200 Subject: [PATCH 131/190] fix eas bluemind unit --- centreon-plugins/apps/bluemind/local/mode/eas.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/apps/bluemind/local/mode/eas.pm b/centreon-plugins/apps/bluemind/local/mode/eas.pm index 058038c0a..fec8f7651 100644 --- a/centreon-plugins/apps/bluemind/local/mode/eas.pm +++ b/centreon-plugins/apps/bluemind/local/mode/eas.pm @@ -41,7 +41,7 @@ sub set_counters { ]; $self->{maps_counters}->{bm_eas} = [ - { label => 'responses-size-total', nlabel => 'eas.responses.size.total.count', display_ok => 0, set => { + { label => 'responses-size-total', nlabel => 'eas.responses.size.total.bytes', display_ok => 0, set => { key_values => [ { name => 'response_size', diff => 1 } ], output_template => 'total responses size: %s %s', output_change_bytes => 1, From 9d0eec23d54b67006871cf46360d6d613d856f9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Rameau?= Date: Tue, 28 Apr 2020 10:59:57 +0200 Subject: [PATCH 132/190] Update disk.pm --- .../storage/emc/DataDomain/mode/components/disk.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/centreon-plugins/storage/emc/DataDomain/mode/components/disk.pm b/centreon-plugins/storage/emc/DataDomain/mode/components/disk.pm index 0bc969d3b..f519539d8 100644 --- a/centreon-plugins/storage/emc/DataDomain/mode/components/disk.pm +++ b/centreon-plugins/storage/emc/DataDomain/mode/components/disk.pm @@ -33,6 +33,9 @@ my %map_disk_status = ( 4 => 'failed', 5 => 'spare', # since OS 5.4 6 => 'available', # since OS 5.4 + 8 => 'raidReconstruction', # since OS 7.x + 9 => 'copyReconstruction', # since OS 7.x + 10 => 'system', # since OS 7.x ); sub load { @@ -74,4 +77,4 @@ sub check { } } -1; \ No newline at end of file +1; From c2484a5d340d6e68e11ad3159060724e655d0e7e Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 28 Apr 2020 10:59:58 +0200 Subject: [PATCH 133/190] adva fsp150 wip --- .../network/adva/fsp150/snmp/mode/alarms.pm | 326 --------------- .../adva/fsp150/snmp/mode/components/card.pm | 106 +++++ .../fsp150/snmp/mode/components/resources.pm | 123 ++++++ .../adva/fsp150/snmp/mode/components/shelf.pm | 116 ++++++ .../network/adva/fsp150/snmp/mode/hardware.pm | 108 +++++ .../adva/fsp150/snmp/mode/interfaces.pm | 370 ------------------ .../adva/fsp150/snmp/mode/listinterfaces.pm | 160 -------- .../network/adva/fsp150/snmp/plugin.pm | 10 +- 8 files changed, 457 insertions(+), 862 deletions(-) delete mode 100644 centreon-plugins/network/adva/fsp150/snmp/mode/alarms.pm create mode 100644 centreon-plugins/network/adva/fsp150/snmp/mode/components/card.pm create mode 100644 centreon-plugins/network/adva/fsp150/snmp/mode/components/resources.pm create mode 100644 centreon-plugins/network/adva/fsp150/snmp/mode/components/shelf.pm create mode 100644 centreon-plugins/network/adva/fsp150/snmp/mode/hardware.pm delete mode 100644 centreon-plugins/network/adva/fsp150/snmp/mode/interfaces.pm delete mode 100644 centreon-plugins/network/adva/fsp150/snmp/mode/listinterfaces.pm diff --git a/centreon-plugins/network/adva/fsp150/snmp/mode/alarms.pm b/centreon-plugins/network/adva/fsp150/snmp/mode/alarms.pm deleted file mode 100644 index 7bbd27ee7..000000000 --- a/centreon-plugins/network/adva/fsp150/snmp/mode/alarms.pm +++ /dev/null @@ -1,326 +0,0 @@ -# -# 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 network::adva::fsp150::snmp::mode::alarms; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; -use centreon::plugins::misc; -use centreon::plugins::statefile; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); - -sub custom_status_output { - my ($self, %options) = @_; - - my $msg = sprintf("alarm %s [severity: %s] [type: %s] %s", $self->{result_values}->{label}, $self->{result_values}->{severity}, - $self->{result_values}->{type}, $self->{result_values}->{generation_time}); - return $msg; -} - -sub custom_status_calc { - my ($self, %options) = @_; - - $self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'}; - $self->{result_values}->{severity} = $options{new_datas}->{$self->{instance} . '_severity'}; - $self->{result_values}->{since} = $options{new_datas}->{$self->{instance} . '_since'}; - $self->{result_values}->{generation_time} = $options{new_datas}->{$self->{instance} . '_generation_time'}; - $self->{result_values}->{label} = $options{new_datas}->{$self->{instance} . '_label'}; - return 0; -} - - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'alarms', type => 2, message_multiple => '0 problem(s) detected', display_counter_problem => { label => 'alerts', min => 0 }, - group => [ { name => 'alarm', skipped_code => { -11 => 1 } } ] - } - ]; - - $self->{maps_counters}->{alarm} = [ - { label => 'status', threshold => 0, set => { - key_values => [ { name => 'severity' }, { name => 'type' }, { name => 'label'}, { name => 'since' }, { name => 'generation_time' } ], - closure_custom_calc => $self->can('custom_status_calc'), - closure_custom_output => $self->can('custom_status_output'), - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, - } - }, - ]; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning-status:s" => { name => 'warning_status', default => '%{severity} =~ /warning|minor/i' }, - "critical-status:s" => { name => 'critical_status', default => '%{severity} =~ /critical|major/i' }, - "memory" => { name => 'memory' }, - "timezone:s" => { name => 'timezone' }, - }); - - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'DateTime', - error_msg => "Cannot load module 'DateTime'."); - $self->{statefile_cache} = centreon::plugins::statefile->new(%options); - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status']); - if (defined($self->{option_results}->{memory})) { - $self->{statefile_cache}->check_options(%options); - } - - $self->{option_results}->{timezone} = 'GMT' if (!defined($self->{option_results}->{timezone}) || $self->{option_results}->{timezone} eq ''); -} - -my %map_type = ( - 0 => 'undefined', 5 => 'terminalLoopback', 6 => 'oosDisabled', 7 => 'oosManagement', 8 => 'oosMaintenance', 9 => 'oosAins', 10 => 'removed', - 11 => 'lossOfSignal', 12 => 'optInputPwrReceivedTooLow', 13 => 'optInputPwrReceivedTooHigh', 14 => 'laserTemperatureTooHigh', 15 => 'laserTemperatureTooLow', 16 => 'optOutputPowerTransTooLow', 17 => 'optOutputPowerTransTooHigh', - 18 => 'autoShutdownToHighTemp', 19 => 'autoShutdownToHighTxPwr', 20 => 'laserEndOfLife', 21 => 'serverSignalFailureVf', 22 => 'equalizationProgress', - 23 => 'uPortFailure', 24 => 'autoShutdownBlock', 25 => 'autoPowerShutdown', 26 => 'confOutPowerTransTooHigh', 27 => 'confOutPowerTransTooLow', - 28 => 'optSignalFailure', 29 => 'dsbdChannelPowerTooHigh', 30 => 'lossOfSignalCPort', 31 => 'lossOfSignalNPort', 32 => 'outputPowerFault', - 33 => 'eqlzAdjust', 34 => 'ampFailure', 35 => 'eqptProvMismatch', 36 => 'backreflectionTooHigh', 48 => 'fiberConnLos', 49 => 'fiberConnOptFault', - 50 => 'fiberConnInvalid', 51 => 'fiberConnMismatch', 52 => 'fiberConnCommError', 53 => 'fiberConnProtocolFailure', 54 => 'fiberConnDataFailure', - 55 => 'fiberAttenuationHigh', 57 => 'laserBiasCurrAbnormal', 58 => 'fiberConnInvalidTx', 59 => 'fiberConnMismatchTx', 60 => 'fiberAttenuationHighTx', - 61 => 'laserFailure', 62 => 'lossOfReceiverClockRecovery', 63 => 'fiberAttenuationCond', 64 => 'channelMismatch', 65 => 'alarmIndicationSignalLine', - 66 => 'alarmIndicationSignalLowerOrderPath', 67 => 'alarmIndicationSignalOdu', 68 => 'alarmIndicationSignalOpu', 69 => 'alarmIndicationSignalOtu', - 70 => 'alarmIndicationSignalHigherOrderPath', 71 => 'alarmIndicationSignalOduTcmA', 72 => 'alarmIndicationSignalOduTcmB', 73 => 'alarmIndicationSignalOduTcmC', 74 => 'virtualChannelAis', - 75 => 'amplifierAbnormal', 76 => 'automaticPowerReduction', 77 => 'automaticPowerReductionForEyeSafety', 80 => 'apsConfigMismatch', 81 => 'apsProtocolFailure', 82 => 'aseLow', - 83 => 'aseTableGenFailLow', 84 => 'aseTableGenFailHighBackreflection', 85 => 'aseTableGenFailOscMissing', 86 => 'aseTableGenFailPilot', 87 => 'aseTableGenFailSignalinput', - 88 => 'aseTableNotAvailable', 89 => 'aseTableGenProgress', 90 => 'encryptionPortAuthPasswdMissing', 92 => 'backwardDefectIndicationOdu', 93 => 'backwardDefectIndicationOtu', - 94 => 'backwardDefectIndicationOduTcmA', 95 => 'backwardDefectIndicationOduTcmB', 96 => 'backwardDefectIndicationOduTcmC', 97 => 'topologyDataCalculationInProgress', 99 => 'dispertionTunningCondition', 100 => 'lossOfCharSync', - 101 => 'lossOfCharSyncFromFarEnd', 103 => 'encryptionPortEncryptionSwitchOffEnabled', 104 => 'encryptionModuleCryPasswdMissing', 107 => 'encryptionModuleSelfTestStarted', 108 => 'encryptionPortEncryptionSwitchedOff', 109 => 'opuClientSignalFail', - 110 => 'databaseMismatch', 111 => 'databaseFailure', 112 => 'databaseNcuMismatch', 113 => 'dbReplicationIncompleted', 114 => 'databaseVersionMismatch', 115 => 'xfpDecisionThresSetFailed', 116 => 'duplexLinkFailure', 118 => 'singleFanFailure', - 119 => 'multipleFanFailure', 120 => 'lossOfSignalTransmitter', 122 => 'farEndIpAddressUnknown', 123 => 'farEndCommFailure', 125 => 'backupForcedToHalt', 127 => 'facilityForcedOn', 128 => 'fwdAseTableFailPilot', 129 => 'fwdAseTableOnPilot', - 131 => 'encryptionModuleFwpUpdateEnabled', 132 => 'fwpMismatchDownloadNotServiceAffecting', 133 => 'fwpMismatchDownloadServiceAffecting', 135 => 'gainTiltNotSettable', 136 => 'highBer', 137 => 'receiverOverloadProtection', 138 => 'hwInitializing', 139 => 'hwOprReachedHT', - 140 => 'hwDegrade', 141 => 'hwFailure', 142 => 'switchtoProtectionInhibited', 143 => 'switchtoWorkingInhibited', 148 => 'encryptionPortKeyInitExchgMissed', 149 => 'encryptionPortMaxKeyExchgFailuresReachedIs', 150 => 'encryptionPortMaxKeyExchgFailuresReachedOos', - 151 => 'encryptionPortKeyExchangedForced', 152 => 'laserOnDelay', 153 => 'lockedDefectOdu', 154 => 'lockedDefectOduTcmA', 155 => 'lockedDefectOduTcmB', 156 => 'lockedDefectOduTcmC', 157 => 'linkControlProtocolFailure', 158 => 'linkDown', 159 => 'autoShutdownSendingAisLine', - 160 => 'autoShutdownSendingAisOdu', 161 => 'autoShutdownSendingAisOpu', 162 => 'clientFailForwarding', 163 => 'autoShutdownAls', 164 => 'autoAmpShutdown', 165 => 'autoShutdownAmpAps', 166 => 'aseTableBuild', 167 => 'autoShutdownOpuClientSignalFail', 168 => 'autoShutdownSendingEPC', - 169 => 'autoShutdownSendingLckOdu', 170 => 'autoShutdownSendingOciOdu', 171 => 'autoShutdownLaserOffDueToErrFwd', 172 => 'autoShutdownTxRxLasersDueToHighTemp', 173 => 'localFault', 174 => 'localOscLevelAbnormal', 175 => 'lossOfGfpFrame', 176 => 'lossOfFrameMux', 177 => 'lossOfFrameOtu', - 178 => 'lossOfFrame', 179 => 'lossOfFrameLossOfMultiFrameOdu', 180 => 'lossOfLane', 181 => 'lossofMultiframeLowerOrderPath', 182 => 'lossOfMultiFrameOtu', 183 => 'lossofMultiframeHigherOrderPath', 184 => 'lossOfPointerLowerOrderPath', 185 => 'lossOfPointerHigherOrderPath', - 186 => 'losAttProgress', 187 => 'lossOsc', 188 => 'gfpLossOfClientSig', 189 => 'loopbackError', 190 => 'facilityLoopback', 191 => 'lossofTandemConnectionOduTcmA', 192 => 'lossofTandemConnectionOduTcmB', 193 => 'lossofTandemConnectionOduTcmC', 194 => 'mansw', 197 => 'equipmentNotAccepted', 198 => 'equipmentNotApproved', 199 => 'capabilityLevelMismatch', - 200 => 'equipmentMismatch', 201 => 'equipmentNotSupportedByPhysicalLayer', 202 => 'meaSwRevision', 203 => 'mismatch', 204 => 'midstageFault', 205 => 'multiplexStructureIdentifierMismatchOPU', 206 => 'backupNotResponding', 207 => 'openConnectionIndicationOdu', - 208 => 'openConnectionIndicationOduTcmA', 209 => 'openConnectionIndicationOduTcmB', 210 => 'openConnectionIndicationOduTcmC', 211 => 'oduTribMsiMismatch', 212 => 'transmitterDisabledOff', 213 => 'receiverDisabled', 214 => 'opmAbnormalCondition', 215 => 'faultOnOpm', 216 => 'thresOptPowerCtrlFailureHigh', - 217 => 'thresOptPowerCtrlFailureLow', 218 => 'txPowerLimited', 219 => 'oscOpticalPowerControlFailHigh', 220 => 'oscOpticalPowerControlFailLow', 221 => 'oTDRMeasuringinProgress', 222 => 'encryptionModuleCryPasswdError', 223 => 'peerLink', 224 => 'pilotReceiveLevelHigh', - 225 => 'lossOfPilotSignal', 226 => 'payloadMismatchGfp', 227 => 'payloadMismatchLowerOrderPath', 228 => 'payloadMismatchOPU', 229 => 'payloadMismatchHigherOrderPath', 230 => 'provPayloadMismatch', 231 => 'prbsLossOfSeqSynch', 232 => 'prbsRcvActivated', 233 => 'prbsTrmtActivated', 234 => 'protectionNotAvailable', 235 => 'powerSupplyUnitFailure', 236 => 'maxPowerConsProvModulesToHigh', - 237 => 'maxPowerConsEquipModulesToHigh', 238 => 'powerMissing', 239 => 'remoteDefectIndicationLine', 240 => 'remoteDefectIndicationLowerOrderPath', 241 => 'remoteDefectIndicationHigherOrderPath', 243 => 'dcnCommunicationFail', 244 => 'ntpForSchedEqlzRequired', 245 => 'signalDegradeOlm', 246 => 'signalDegradeLine', 247 => 'signalDegradationonLinkVector', - 248 => 'signalDegradeOdu', 249 => 'signalDegradeOtu', 250 => 'pcsSignalDegrade', 251 => 'signalDegradeScn', 252 => 'signalDegradeOduTcmA', 253 => 'signalDegradeOduTcmB', 254 => 'signalDegradeOduTcmC', 255 => 'encryptionModuleSelfTestFail', 256 => 'encryptionModuleSelfTestFailCritical', - 257 => 'signalFailureOnLink', 258 => 'signalFailureonLinkVector', 259 => 'signalFailureOPU', 260 => 'serverSignalFailTx', 261 => 'facilityDataRateNotSupported', 263 => 'lossofSequenceLowerOrderPath', 264 => 'lossofSequenceHigherOrderPath', 265 => 'serverSignalFail', 266 => 'serverSignalFailureGfp', - 267 => 'serverSignalFailureODU', 268 => 'serverSignalFailurePath', 269 => 'serverSignalFailureSectionRS', 272 => 'switchToDuplexInhibited', 274 => 'switchFailed', 276 => 'currentTooHigh', 277 => 'attOnReceiverFiberHigherThanMonitor', 278 => 'attOnReceiverFiberLowerThanMonitor', 279 => 'attOnTransmitterFiberHigherThanMonitor', - 280 => 'attOnTransmitterFiberLowerThanMonitor', 281 => 'thres15MinExceededOduBbe', 283 => 'thres15MinExceededOtuBbe', 285 => 'thres15MinExceededOduTcmABbe', 287 => 'thres15MinExceededOduTcmBBbe', 289 => 'thres15MinExceededOduTcmCBbe', 291 => 'thres15MinExceededFecBERCE', 293 => 'brPwrRxTooHigh', 294 => 'chromaticDispersionTooHigh', - 295 => 'chromaticDispersionTooLow', 296 => 'dispersionCompensationTooHigh', 297 => 'dispersionCompensationTooLow', 298 => 'thres15MinExceededFecCE', 300 => 'carrierFreqOffsetTooHigh', 301 => 'carrierFreqOffsetTooLow', 302 => 'thres15MinExceededSonetLineCV', 304 => 'thres15MinExceededPhysConvCV', - 306 => 'thres15MinExceededSonetSectCV', 308 => 'thres15MinExceededPhysConvDE', 310 => 'differentialGroupDelayTooHigh', 311 => 'thres15MinExceededFecES', 313 => 'thres15MinExceededSonetLineES', 315 => 'thres15MinExceededOduES', 317 => 'thres15MinExceededOtuES', - 319 => 'thres15MinExceededPhysConvES', 321 => 'thres15MinExceededSonetSectES', 323 => 'thres15MinExceededOduTcmAES', 325 => 'thres15MinExceededOduTcmBES', 327 => 'thres15MinExceededOduTcmCES', 329 => 'latencyTooHigh', 330 => 'latencyTooLow', 331 => 'laserBiasCurrentNormalizedtooHigh', 332 => 'localOscTemperatureTooHigh', 333 => 'localOscTemperatureTooLow', - 334 => 'pumpLaser1TempTooHigh', 335 => 'pumpLaser1TempTooLow', 336 => 'pumpLaser2TempTooHigh', 337 => 'pumpLaser2TempTooLow', 338 => 'pumpLaser3TempTooHigh', 339 => 'pumpLaser3TempTooLow', 340 => 'pumpLaser4TempTooHigh', 341 => 'pumpLaser4TempTooLow', 342 => 'oscPwrTooHigh', - 343 => 'oscPwrTooLow', 344 => 'ramanPumpPwrTooHigh', 345 => 'ramanPumpPwrTooLow', 346 => 'roundTripDelayTooHigh', 347 => 'roundTripDelayTooLow', 348 => 'thres15MinExceededSonetSectSEFS', 350 => 'thres15MinExceededFecSES', 352 => 'thres15MinExceededSonetLineSES', - 354 => 'thres15MinExceededOduSES', 356 => 'thres15MinExceededOtuSES', 358 => 'thres15MinExceededSonetSectSES', 360 => 'thres15MinExceededOduTcmASES', 362 => 'thres15MinExceededOduTcmBSES', 364 => 'thres15MinExceededOduTcmCSES', 366 => 'logicalLanesSkewTooHigh', - 367 => 'signalToNoiseRatioTooLow', 368 => 'subModuleTempTooHigh', 369 => 'temperatureTooHigh', 370 => 'temperatureTooLow', 371 => 'thres15MinExceededSonetLineUAS', 373 => 'thres15MinExceededOduUAS', 375 => 'thres15MinExceededOtuUAS', - 377 => 'thres15MinExceededOduTcmAUAS', 379 => 'thres15MinExceededOduTcmBUAS', 381 => 'thres15MinExceededOduTcmCUAS', 383 => 'thres15MinExceededFecUBE', 385 => 'encryptionModuleTamperDetected', 386 => 'thermoElectricCoolerEndOfLife', 387 => 'alarmInputTIF', 389 => 'traceIdentifierMismatchOdu', - 390 => 'traceIdentifierMismatchOtu', 391 => 'sectionTraceMismatch', 392 => 'traceIdentifierMismatchOduTcmA', 393 => 'traceIdentifierMismatchOduTcmB', 394 => 'traceIdentifierMismatchOduTcmC', 395 => 'turnupFailed', 396 => 'turnupCondition', 397 => 'unequippedLowerOrderPath', 398 => 'unequippedHigherOrderPath', 399 => 'voaControlFail', 400 => 'voltageOutOfRange', 401 => 'inputVoltageFailure', 402 => 'inputVoltageFailurePort1', - 403 => 'inputVoltageFailurePort2', 406 => 'wtrTimerRunning', 407 => 'lossOfLaneOtu', 408 => 'lossOfTestSeqSynchOpu', 409 => 'lossOfMfiOpu', 410 => 'oosDisabledLckOduTrmt', 411 => 'configurationMismatch', 412 => 'oduAutoShutdownRxAIS', 413 => 'oduAutoShutdownTxAIS', 414 => 'oosDisabledLckOduRx', 420 => 'thres15MinExceededBbePcs', - 422 => 'autoShutdownGAis', 423 => 'equipmentMismatchAllow', 424 => 'warmUp', 432 => 'networkPathRestricted', 434 => 'vfClientSignalFail', 435 => 'autoShutdownVfCSF', 439 => 'linkFailToPartner1', 440 => 'linkFailToPartner2', 441 => 'linkFailToPartner3', 442 => 'linkFailToPartner4', 443 => 'partnerUnavailable', - 445 => 'partner1Deleted', 446 => 'partner2Deleted', 447 => 'partner3Deleted', 448 => 'partner4Deleted', 450 => 'thres15MinExceededPhysConvSE', 452 => 'thres15MinExceededPhysConvCVDE', 456 => 'autoShutdownSendingOciOduTx', 457 => 'acpLinkLoss', 458 => 'acpChannelUnAvail', 459 => 'acpPartnerUnassigned', 460 => 'acpPartnerDeleted', 461 => 'thres15MinExceededCrcErrorsRcv', 463 => 'thres15MinExceededCrcFramesEgress', - 465 => 'autoServiceMismatch', 466 => 'batteryNoCharge', 469 => 'tagReceiveFail', 470 => 'tagReceiveFailMaxReached', 473 => 'internalEncryptionFail', 13006 => 'cfmRemoteDefectIndication', 13007 => 'cfmCcmMacStatus', 13008 => 'cfmCcmError', 13009 => 'cfmCcmLost', 13010 => 'cfmCcmXConn', 100005 => 'mepNotPresentL2', 100006 => 'priVidNotEqualExtVidL2', 100009 => 'sfCfmLevel0L2', 100010 => 'sfCfmLevel1L2', 100011 => 'sfCfmLevel2L2', - 100012 => 'sfCfmLevel3L2', 100013 => 'sfCfmLevel4L2 ', 100014 => 'sfCfmLevel5L2', 100015 => 'sfCfmLevel6L2', 100016 => 'sfCfmLevel7L2', 120004 => 'messageLossSpeq', 120005 => 'oscFiberMissingSpeq', 120006 => 'optLowSpeq', 120007 => 'ppcOutOfRangeSpeq', 120008 => 'gainTooHighSpeq', 120009 => 'gainTooLowSpeq', 120010 => 'gainAdoptFailedSpeq', 120011 => 'processLockedOutSpeq', 120012 => 'ppcLimitExceededSpeq', -); -my %map_severity = (1 => 'indeterminate', 2 => 'critical', 3 => 'major', 4 => 'minor', 5 => 'warning', 6 => 'cleared', 7 => 'notReported'); - -my $oids = { - alarmSysTable => { - oid => '.1.3.6.1.4.1.2544.1.11.7.4.1', label => 'sys', - mapping => { - severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.1.1.2', map => \%map_severity }, - timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.1.1.4' }, - } - }, - alarmEqptTable => { - oid => '.1.3.6.1.4.1.2544.1.11.7.4.5', label => 'eqpt', - mapping => { - severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.5.1.2', map => \%map_severity }, - timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.5.1.4' }, - } - }, - alarmFacilityTable => { - oid => '.1.3.6.1.4.1.2544.1.11.7.4.7', label => 'facility', - mapping => { - severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.7.1.2', map => \%map_severity }, - timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.7.1.4' }, - } - }, - alarmTerminPointTable => { - oid => '.1.3.6.1.4.1.2544.1.11.7.4.9', label => 'terminpoint', - mapping => { - severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.9.1.2', map => \%map_severity }, - timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.9.1.4' }, - } - }, - alarmExternalPortTable => { - oid => '.1.3.6.1.4.1.2544.1.11.7.4.11', label => 'externalport', - mapping => { - severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.11.1.2', map => \%map_severity }, - timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.11.1.4' }, - } - }, - alarmDcnTable => { - oid => '.1.3.6.1.4.1.2544.1.11.7.4.16', label => 'dcn', - mapping => { - severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.16.1.2', map => \%map_severity }, - timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.16.1.4' }, - } - }, - alarmEnvTable => { - oid => '.1.3.6.1.4.1.2544.1.11.7.4.20', label => 'env', - mapping => { - severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.20.1.2', map => \%map_severity }, - timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.20.1.4' }, - } - }, - alarmContainerTable => { - oid => '.1.3.6.1.4.1.2544.1.11.7.4.24', label => 'container', - mapping => { - severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.24.1.2', map => \%map_severity }, - timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.24.1.4' }, - } - }, - alarmOpticalMuxTable => { - oid => '.1.3.6.1.4.1.2544.1.11.7.4.28', label => 'opticalmux', - mapping => { - severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.28.1.2', map => \%map_severity }, - timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.28.1.4' }, - } - }, - alarmShelfConnTable => { - oid => '.1.3.6.1.4.1.2544.1.11.7.4.34', label => 'shelfconn', - mapping => { - severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.32.1.2', map => \%map_severity }, - timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.32.1.4' }, - } - }, - alarmNtpIPv4Table => { - oid => '.1.3.6.1.4.1.2544.1.11.7.4.36', label => 'ntpipv4', - mapping => { - severity => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.36.1.2', map => \%map_severity }, - timestamp => { oid => '.1.3.6.1.4.1.2544.1.11.7.4.36.1.4' }, - } - }, -}; - -sub manage_selection { - my ($self, %options) = @_; - - my $snmp_result = $options{snmp}->get_table(oid => '.1.3.6.1.4.1.2544.1.12.3.1.4.1.5'); - use Data::Dumper; print Data::Dumper::Dumper($snmp_result); - print unpack('B*', $snmp_result->{'.1.3.6.1.4.1.2544.1.12.3.1.4.1.5.1.1.5'}); - exit(1); - - $self->{alarms}->{global} = { alarm => {} }; - my $get_oids = []; - foreach (keys %$oids) { - push @$get_oids, { oid => $oids->{$_}->{oid} }; - } - my $snmp_result = $options{snmp}->get_multiple_table(oids => $get_oids); - - my $last_time; - if (defined($self->{option_results}->{memory})) { - $self->{statefile_cache}->read(statefile => "cache_adva_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port(). '_' . $self->{mode}); - $last_time = $self->{statefile_cache}->get(name => 'last_time'); - } - - my ($i, $current_time) = (1, time()); - - foreach (keys %$oids) { - my $branch_oid = $oids->{$_}->{oid}; - next if (!defined($snmp_result->{$branch_oid})); - - foreach my $oid (keys %{$snmp_result->{$branch_oid}}) { - next if ($oid !~ /^$oids->{$_}->{mapping}->{severity}->{oid}\.(.*)\.(.*?)$/); - my $instance = $1 . '.' . $2; - my $type = defined($map_type{$2}) ? $map_type{$2} : 'unknown'; - my $result = $options{snmp}->map_instance(mapping => $oids->{$_}->{mapping}, results => $snmp_result->{$branch_oid}, instance => $instance); - - my @date = unpack 'n C6 a C2', $result->{timestamp}; - my $timezone = $self->{option_results}->{timezone}; - if (defined($date[7])) { - $timezone = sprintf("%s%02d%02d", $date[7], $date[8], $date[9]); - } - - my $tz = centreon::plugins::misc::set_timezone(name => $timezone); - my $dt = DateTime->new(year => $date[0], month => $date[1], day => $date[2], hour => $date[3], minute => $date[4], second => $date[5], - %$tz); - - next if (defined($self->{option_results}->{memory}) && defined($last_time) && $last_time > $dt->epoch); - - my $diff_time = $current_time - $dt->epoch; - - $self->{alarms}->{global}->{alarm}->{$i} = { severity => $result->{severity}, - type => $type, since => $diff_time, - generation_time => centreon::plugins::misc::change_seconds(value => $diff_time), - label => $oids->{$_}->{label} - }; - $i++; - } - } - - if (defined($self->{option_results}->{memory})) { - $self->{statefile_cache}->write(data => { last_time => $current_time }); - } -} - -1; - -__END__ - -=head1 MODE - -Check alarms. - -=over 8 - -=item B<--warning-status> - -Set warning threshold for status (Default: '%{severity} =~ /warning|minor/i') -Can used special variables like: %{severity}, %{type}, %{label}, %{since} - -=item B<--critical-status> - -Set critical threshold for status (Default: '%{severity} =~ /critical|major/i'). -Can used special variables like: %{severity}, %{type}, %{label}, %{since} - -=item B<--timezone> - -Timezone options (the date from the equipment overload that option). Default is 'GMT'. - -=item B<--memory> - -Only check new alarms. - -=back - -=cut diff --git a/centreon-plugins/network/adva/fsp150/snmp/mode/components/card.pm b/centreon-plugins/network/adva/fsp150/snmp/mode/components/card.pm new file mode 100644 index 000000000..5d799452e --- /dev/null +++ b/centreon-plugins/network/adva/fsp150/snmp/mode/components/card.pm @@ -0,0 +1,106 @@ +# +# 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 network::adva::fsp150::snmp::mode::components::card; + +use strict; +use warnings; +use network::adva::fsp150::snmp::mode::components::resources qw( + $map_card_type $oids + get_secondary_states +); + +my $mapping = { + slotEntityIndex => { oid => '.1.3.6.1.4.1.2544.1.12.3.1.3.1.2' }, + slotCardType => { oid => '.1.3.6.1.4.1.2544.1.12.3.1.3.1.4', map => $map_card_type }, + slotSecondaryState => { oid => '.1.3.6.1.4.1.2544.1.12.3.1.3.1.15' } +}; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, + { oid => $mapping->{slotEntityIndex}->{oid} }, + { oid => $mapping->{slotCardType}->{oid} }, + { oid => $mapping->{slotSecondaryState}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking cards'); + $self->{components}->{card} = { name => 'cards', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'card')); + + my $results = { + %{$self->{results}->{ $mapping->{slotEntityIndex}->{oid} }}, + %{$self->{results}->{ $mapping->{slotCardType}->{oid} }}, + %{$self->{results}->{ $mapping->{slotSecondaryState}->{oid} }} + }; + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %$results)) { + next if ($oid !~ /^$mapping->{slotEntityIndex}->{oid}\.(\d+)\.(\d+)\.(\d+)$/); + + my ($ne_index, $shelf_index, $card_index, $instance) = ($1, $2, $3, $1 . '.' . $2 . '.' . $3); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance); + + my $ne_name = $self->{results}->{ $oids->{neName} }->{ $oids->{neName} . '.' . $ne_index }; + my $entity_name = $self->{results}->{ $oids->{entPhysicalName} }->{ $oids->{entPhysicalName} . '.' . $result->{slotEntityIndex} }; + my $name = $ne_name . ':' . $entity_name; + my $secondary_states = get_secondary_states(state => $result->{slotSecondaryState}); + + my $secondary_str = join(',', @$secondary_states); + if ($secondary_str =~ /mainteance/) { + $self->{output}->output_add( + long_msg => sprintf("skipping card '%s': in maintenance mode", $name) + ); + next; + } + + next if ($self->check_filter(section => 'card', instance => $result->{slotCardType} . '.' . $instance)); + $self->{components}->{card}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "card '%s' secondary status is '%s' [instance: %s].", + $name, + $secondary_str, + $result->{slotCardType} . '.' . $instance + ) + ); + + my $exit = 'ok'; + foreach (@$secondary_states) { + my $exit_tmp = $self->get_severity(label => 'secondary', section => 'card', instance => $result->{slotCardType} . '.' . $instance, value => $_); + $exit = $self->{output}->get_most_critical(status => [ $exit, $exit_tmp ]); + } + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "card '%s' secondary status is '%s'", + $name, + $secondary_str + ) + ); + } + } +} + +1; diff --git a/centreon-plugins/network/adva/fsp150/snmp/mode/components/resources.pm b/centreon-plugins/network/adva/fsp150/snmp/mode/components/resources.pm new file mode 100644 index 000000000..8570326be --- /dev/null +++ b/centreon-plugins/network/adva/fsp150/snmp/mode/components/resources.pm @@ -0,0 +1,123 @@ +# +# 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 network::adva::fsp150::snmp::mode::components::resources; + +use strict; +use warnings; +use Exporter; + +our $map_admin_state; +our $map_oper_state; +our $bits_secondary_state; +our $map_card_type; +our $oids; + +our @ISA = qw(Exporter); +our @EXPORT_OK = qw( + $map_admin_state $map_oper_state $bits_secondary_state $map_card_type + $oids get_secondary_states +); + +$oids = { + neName => '.1.3.6.1.4.1.2544.1.12.3.1.1.1.2', + shelfEntityIndex => '.1.3.6.1.4.1.2544.1.12.3.1.2.1.2', + entPhysicalName => '.1.3.6.1.2.1.47.1.1.1.1.7' +}; + +$map_admin_state = { + 1 => 'in-service', 2 => 'management', + 3 => 'maintenance', 4 => 'disabled', + 5 => 'unassigned', 6 => 'monitored' +}; +$map_oper_state = { + 1 => 'normal', 2 => 'outage' +}; +$bits_secondary_state = { + 0 => 'not-applicable', 1 => 'active', + 2 => 'automaticinservice', 3 => 'facilityfailure', + 4 => 'fault', 5 => 'loopback', 6 => 'maintenance', + 7 => 'mismatchedeqpt', 8 => 'standbyhot', + 9 => 'supportingentityoutage', 10 => 'unassigned', + 11 => 'unequipped', 12 => 'disabled', + 13 => 'forcedoffline', 14 => 'initializing', + 15 => 'prtcl', 16 => 'blckd', 17 => 'mon-tx', + 18 => 'mir-rx', 19 => 'cema', 20 => 'lkdo', + 21 => 'nomber' +}; +$map_card_type = { + 1 => 'none', 2 => 'psu', 3 => 'fan', 4 => 'nemi', + 5 => 'scu', 6 => 'eth-10-100-1000-ntu', 7 => 'eth-cpmr', + 8 => 'eth-ge-101', 9 => 'eth-ge-206', 10 => 'eth-ge-201', + 11 => 'eth-ge-201se', 12 => 'eth-10-100-1000-nte', + 13 => 'scu-t', 14 => 'eth-ge-206f', 15 => 'eth-xg-1x', + 16 => 'swf-140g', 17 => 'stu', 18 => 'eth-ge-10s', + 19 => 'ami', 20 => 'sti', 21 => 'eth-ge-112', + 22 => 'eth-ge-114', 23 => 'eth-ge-206v', + 24 => 'eth-ge-4e-cc', 25 => 'eth-ge-4s-cc', + 26 => 'eth-xg-210', 27 => 'eth-xg-1x-cc', + 28 => 'eth-xg-1s-cc', 29 => 'stm1-4-et', + 30 => 'pwe3-ocnstm', 31 => 'pwe3-e1t1', 32 => 'eth-xg-1x-h', + 33 => 'eth-ge-10s-h', 34 => 'eth-t1804', 35 => 'eth-t3204', + 36 => 'eth-ge-syncprobe', 37 => 'eth-ge-8s-cc', + 38 => 'eth-ge-114h', 39 => 'eth-ge-114ph', + 40 => 'eth-fe-36e', 41 => 'eth-ge-114sh', + 42 => 'eth-ge-114s', 43 => 'sti-h', 44 => 'stu-h', + 45 => 'eth-ge-8e-cc', 46 => 'eth-sh1pcs', 47 => 'eth-osa5411', + 48 => 'ethGe112Pro', 49 => 'ethGe112ProM', + 50 => 'ethGe114Pro', 51 => 'ethGe114ProC', + 52 => 'ethGe114ProSH', 53 => 'ethGe114ProCSH', + 54 => 'ethGe114ProHE', 55 => 'ethGe112ProH', + 56 => 'eth-xg-210c', 57 => 'eth-ge-8sc-cc', + 58 => 'eth-osa5420', 59 => 'eth-osa5421', + 60 => 'bits-x16', 61 => 'eth-ge-114g', + 62 => 'ethGe114ProVmH', 63 => 'ethGe114ProVmCH', + 64 => 'ethGe114ProVmCSH', 65 => 'serverCard', + 66 => 'eth-ptpv2-osa', 67 => 'gnss-osa', + 68 => 'thc-osa', 69 => 'sgc-osa', 70 => 'pps-x16', + 71 => 'clk-x16', 72 => 'todAndPps-x16', 73 => 'eth-ge-101pro', + 74 => 'ethgo102proS',75 => 'ethgo102proSP', + 76 => 'ethcx101pro30A', 77 => 'ethcx102pro30A', + 78 => 'osa-ge-4s', 79 => 'eth-xg-116pro', + 80 => 'eth-xg-120pro', 81 => 'ethGe112ProVm', + 82 => 'eth-osa5401', 83 => 'eth-osa5405', + 84 => 'eth-csm', 85 => 'aux-osa', 86 => 'bits-x16-enhanced', + 87 => 'osa-ge-4s-protected', 88 => 'eth-ge-102pro-h', + 89 => 'eth-ge-102pro-efmh', 90 => 'eth-xg-116pro-h', + 91 => 'ethgo102proSM', 92 => 'eth-xg-118pro-sh', + 93 => 'eth-xg-118proac-sh', 94 => 'ethGe114ProVmSH', + 95 => 'ethGe104', 96 => 'eth-xg-120pro-sh' +}; + +sub get_secondary_states { + my (%options) = @_; + + my @bits_str = split //, unpack('B*', $options{state}); + my $results = []; + foreach (keys %$bits_secondary_state) { + if ($bits_str[$_]) { + push @$results, $bits_secondary_state->{$_}; + } + } + + return $results; +} + +1; diff --git a/centreon-plugins/network/adva/fsp150/snmp/mode/components/shelf.pm b/centreon-plugins/network/adva/fsp150/snmp/mode/components/shelf.pm new file mode 100644 index 000000000..e8de6f13b --- /dev/null +++ b/centreon-plugins/network/adva/fsp150/snmp/mode/components/shelf.pm @@ -0,0 +1,116 @@ +# +# 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 network::adva::fsp150::snmp::mode::components::shelf; + +use strict; +use warnings; +use network::adva::fsp150::snmp::mode::components::resources qw( + $map_admin_state $map_oper_state $oids + get_secondary_states +); + +my $mapping = { + shelfEntityIndex => { oid => $oids->{shelfEntityIndex} }, + shelfAdminState => { oid => '.1.3.6.1.4.1.2544.1.12.3.1.2.1.8', map => $map_admin_state }, + shelfOperationalState => { oid => '.1.3.6.1.4.1.2544.1.12.3.1.2.1.9', map => $map_oper_state }, + shelfSecondaryState => { oid => '.1.3.6.1.4.1.2544.1.12.3.1.2.1.10' } +}; +my $oid_shelfEntry = '.1.3.6.1.4.1.2544.1.12.3.1.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { + oid => $oid_shelfEntry, + start => $mapping->{shelfAdminState}->{oid}, + end => $mapping->{shelfSecondaryState}->{oid} + }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking shelfs'); + $self->{components}->{shelf} = { name => 'shelfs', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'shelf')); + + $self->{results}->{$oid_shelfEntry} = { %{$self->{results}->{$oid_shelfEntry}}, %{$self->{results}->{ $oids->{shelfEntityIndex} }} }; + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_shelfEntry}})) { + next if ($oid !~ /^$mapping->{shelfAdminState}->{oid}\.(.*?)\.(.*)$/); + + my ($ne_index, $shelf_index, $instance) = ($1, $2, $1 . '.' . $2); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_shelfEntry}, instance => $instance); + + my $ne_name = $self->{results}->{ $oids->{neName} }->{ $oids->{neName} . '.' . $ne_index }; + my $entity_name = $self->{results}->{ $oids->{entPhysicalName} }->{ $oids->{entPhysicalName} . '.' . $result->{shelfEntityIndex} }; + my $name = $ne_name . ':' . $entity_name; + + if ($result->{shelfAdminState} eq 'maintenance') { + $self->{output}->output_add( + long_msg => sprintf("skipping shelf '%s': in maintenance mode", $name) + ); + next; + } + + next if ($self->check_filter(section => 'shelf', instance => $instance)); + $self->{components}->{shelf}->{total}++; + + my $secondary_states = get_secondary_states(state => $result->{shelfSecondaryState}); + $self->{output}->output_add( + long_msg => sprintf( + "shelf '%s' operational status is '%s' [secondary status: %s][instance: %s].", + $name, + $result->{shelfOperationalState}, + join(',', @$secondary_states), + $instance + ) + ); + my $exit = $self->get_severity(label => 'operational', section => 'shelf', value => $result->{shelfOperationalState}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "shelf '%s' operational status is '%s'", + $name, + $result->{shelfOperationalState} + ) + ); + } + + $exit = 'ok'; + foreach (@$secondary_states) { + my $exit_tmp = $self->get_severity(label => 'secondary', section => 'shelf', instance => $instance, value => $_); + $exit = $self->{output}->get_most_critical(status => [ $exit, $exit_tmp ]); + } + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "shelf '%s' secondary status is '%s'", + $name, + join(',', @$secondary_states) + ) + ); + } + } +} + +1; diff --git a/centreon-plugins/network/adva/fsp150/snmp/mode/hardware.pm b/centreon-plugins/network/adva/fsp150/snmp/mode/hardware.pm new file mode 100644 index 000000000..82887d745 --- /dev/null +++ b/centreon-plugins/network/adva/fsp150/snmp/mode/hardware.pm @@ -0,0 +1,108 @@ +# +# 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 network::adva::fsp150::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; +use network::adva::fsp150::snmp::mode::components::resources qw($oids); + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = + '^(?:shefl|card)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + operational => [ + ['normal', 'OK'], + ['outage', 'CRITICAL'], + ], + secondary => [ + ['fault', 'CRITICAL'], + ['facilityfailure', 'CRITICAL'], + ['.*', 'OK'] + ] + }; + + $self->{components_path} = 'network::adva::fsp150::snmp::mode::components'; + $self->{components_module} = ['shelf', 'card']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + push @{$self->{request}}, + { oid => $oids->{neName} }, + { oid => $oids->{shelfEntityIndex} }, + { oid => $oids->{entPhysicalName} }; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'shelf', 'card'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=shelf) +Can also exclude specific instance: --filter=card,psu.1.1.4 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='card,WARNING,initializing' + +=back + +=cut diff --git a/centreon-plugins/network/adva/fsp150/snmp/mode/interfaces.pm b/centreon-plugins/network/adva/fsp150/snmp/mode/interfaces.pm deleted file mode 100644 index c5d33d00f..000000000 --- a/centreon-plugins/network/adva/fsp150/snmp/mode/interfaces.pm +++ /dev/null @@ -1,370 +0,0 @@ -# -# 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 network::adva::fsp3000::snmp::mode::interfaces; - -use base qw(snmp_standard::mode::interfaces); - -use strict; -use warnings; - -sub set_oids_traffic { - my ($self, %options) = @_; - - $self->{currentEthRx15minBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.52.1.5'; # in B - $self->{currentEthRx1dayBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.53.1.5'; # in B - $self->{currentEthTx15minBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.56.1.3'; # in B - $self->{currentEthTx1dayBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.57.1.3'; # in B - $self->{currentEthRxHighSpeed15minBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.88.1.4'; # in B - $self->{currentEthRxHighSpeed1dayBytes} = '.1.3.6.1.4.1.2544.1.11.2.6.2.89.1.4'; # in B -} - -sub set_counters_traffic { - my ($self, %options) = @_; - - push @{$self->{maps_counters}->{int}}, - { label => 'traffic-in', filter => 'add_traffic', nlabel => 'interface.traffic.in.bitspersecond', set => { - key_values => [ { name => 'traffic_in_15min', diff => 1 }, { name => 'traffic_in_1day', diff => 1 }, { name => 'speed_in'}, { name => 'display' } ], - per_second => 1, - closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in' }, - closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic In : %s', - closure_custom_perfdata => $self->can('custom_traffic_perfdata'), - closure_custom_threshold_check => $self->can('custom_traffic_threshold'), - } - }, - { label => 'traffic-out', filter => 'add_traffic', nlabel => 'interface.traffic.out.bitspersecond', set => { - key_values => [ { name => 'traffic_out_15min', diff => 1 }, { name => 'traffic_out_1day', diff => 1 }, { name => 'speed_out'}, { name => 'display' } ], - per_second => 1, - closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out' }, - closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic Out : %s', - closure_custom_perfdata => $self->can('custom_traffic_perfdata'), - closure_custom_threshold_check => $self->can('custom_traffic_threshold'), - } - }, - ; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->SUPER::set_counters(%options); - - push @{$self->{maps_counters}->{int}}, - { label => 'laser-temp', filter => 'add_optical', nlabel => 'interface.laser.temperature.celsius', set => { - key_values => [ { name => 'laser_temp' }, { name => 'display' } ], - output_template => 'Laser Temperature : %.2f C', output_error_template => 'Laser Temperature : %.2f', - perfdatas => [ - { label => 'laser_temp', value => 'laser_temp_absolute', template => '%.2f', - unit => 'C', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - { label => 'input-power', filter => 'add_optical', nlabel => 'interface.input.power.dbm', set => { - key_values => [ { name => 'input_power' }, { name => 'display' } ], - output_template => 'Input Power : %s dBm', output_error_template => 'Input Power : %s', - perfdatas => [ - { label => 'input_power', value => 'input_power_absolute', template => '%s', - unit => 'dBm', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - { label => 'output-power', filter => 'add_optical', nlabel => 'interface.output.power.dbm', set => { - key_values => [ { name => 'output_power' }, { name => 'display' } ], - output_template => 'Output Power : %s dBm', output_error_template => 'Output Power : %s', - perfdatas => [ - { label => 'output_power', value => 'output_power_absolute', template => '%s', - unit => 'dBm', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - ; -} - -sub custom_traffic_perfdata { - my ($self, %options) = @_; - - my ($warning, $critical); - if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { - $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); - $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); - } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { - $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}); - $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}); - } - - $self->{output}->perfdata_add( - label => 'traffic_' . $self->{result_values}->{label}, unit => 'b/s', - nlabel => $self->{nlabel}, - instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, - value => sprintf("%.2f", $self->{result_values}->{traffic_per_seconds}), - warning => $warning, - critical => $critical, - min => 0, max => $self->{result_values}->{speed} - ); -} - -sub custom_traffic_threshold { - my ($self, %options) = @_; - - my $exit = 'ok'; - if ($self->{instance_mode}->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { - $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_prct}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); - } elsif ($self->{instance_mode}->{option_results}->{units_traffic} eq 'b/s') { - $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_per_seconds}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); - } - return $exit; -} - -sub custom_traffic_output { - my ($self, %options) = @_; - - my $label = $self->{result_values}->{label}; - $label =~ s/_/ /g; - $label =~ s/(\w+)/\u$1/g; - my ($traffic_value, $traffic_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic_per_seconds}, network => 1); - my $msg = sprintf("Traffic %s : %s/s (%s)", - $label, $traffic_value . $traffic_unit, - defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-'); - return $msg; -} - -sub custom_traffic_calc { - my ($self, %options) = @_; - - return -10 if (defined($self->{instance_mode}->{last_status}) && $self->{instance_mode}->{last_status} == 0); - - # we choose the performance value (1day is updated every 15 minutes. 15min is updated all the time but reset every 15min - my $counter = 'traffic_' . $options{extra_options}->{label_ref} . '_15min'; - if ($options{delta_time} >= 600) { - $counter = 'traffic_' . $options{extra_options}->{label_ref} . '_1day'; - } - - my $diff_traffic = ($options{new_datas}->{$self->{instance} . '_' . $counter} - $options{old_datas}->{$self->{instance} . '_' . $counter}); - - $self->{result_values}->{traffic_per_seconds} = $diff_traffic / $options{delta_time}; - if (defined($options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}}) && - $options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}} > 0) { - $self->{result_values}->{traffic_prct} = $self->{result_values}->{traffic_per_seconds} * 100 / $options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}}; - $self->{result_values}->{speed} = $options{new_datas}->{$self->{instance} . '_speed_' . $options{extra_options}->{label_ref}}; - } - - $self->{result_values}->{label} = $options{extra_options}->{label_ref}; - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - return 0; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_set_traffic => 1, no_errors => 1, no_cast => 1); - bless $self, $class; - - $options{options}->add_options(arguments => { - 'add-optical' => { name => 'add_optical' }, - } - ); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->{checking} = ''; - foreach (('add_global', 'add_status', 'add_traffic', 'add_speed', 'add_volume', 'add_optical')) { - if (defined($self->{option_results}->{$_})) { - $self->{checking} .= $_; - } - } -} - -my $oid_opticalIfDiagLaserTemp = '.1.3.6.1.4.1.2544.1.11.2.4.3.5.1.2'; -my $oid_opticalIfDiagInputPower = '.1.3.6.1.4.1.2544.1.11.2.4.3.5.1.3'; -my $oid_opticalIfDiagOutputPower = '.1.3.6.1.4.1.2544.1.11.2.4.3.5.1.4'; - -sub custom_load { - my ($self, %options) = @_; - - return if (!defined($self->{option_results}->{add_optical})); - - $self->{snmp}->load(oids => [$oid_opticalIfDiagLaserTemp, $oid_opticalIfDiagInputPower, $oid_opticalIfDiagOutputPower], - instances => $self->{array_interface_selected}); -} - -sub custom_add_result { - my ($self, %options) = @_; - - return if (!defined($self->{option_results}->{add_optical})); - $self->{int}->{$options{instance}}->{laser_temp} = undef; - if (defined($self->{results}->{$oid_opticalIfDiagLaserTemp . '.' . $options{instance}}) && - $self->{results}->{$oid_opticalIfDiagLaserTemp . '.' . $options{instance}} != -2147483648) { - $self->{int}->{$options{instance}}->{laser_temp} = $self->{results}->{$oid_opticalIfDiagLaserTemp . '.' . $options{instance}} * 0.1; - } - - $self->{int}->{$options{instance}}->{input_power} = undef; - if (defined($self->{results}->{$oid_opticalIfDiagInputPower . '.' . $options{instance}}) && - $self->{results}->{$oid_opticalIfDiagInputPower . '.' . $options{instance}} != -65535) { - $self->{int}->{$options{instance}}->{input_power} = $self->{results}->{$oid_opticalIfDiagInputPower . '.' . $options{instance}} / 10; - } - - $self->{int}->{$options{instance}}->{output_power} = undef; - if (defined($self->{results}->{$oid_opticalIfDiagOutputPower . '.' . $options{instance}}) && - $self->{results}->{$oid_opticalIfDiagOutputPower . '.' . $options{instance}} != -65535) { - $self->{int}->{$options{instance}}->{output_power} = $self->{results}->{$oid_opticalIfDiagOutputPower . '.' . $options{instance}} / 10; - } -} - -sub load_traffic { - my ($self, %options) = @_; - - if ($self->{snmp}->is_snmpv1()) { - $self->{output}->add_option_msg(short_msg => "Can't check SNMP 64 bits counters with SNMPv1."); - $self->{output}->option_exit(); - } - - $self->set_oids_traffic(); - $self->{snmp}->load(oids => [$self->{currentEthRx15minBytes}, $self->{currentEthRx1dayBytes}, - $self->{currentEthTx15minBytes}, $self->{currentEthTx1dayBytes}, - $self->{currentEthRxHighSpeed15minBytes}, $self->{currentEthRxHighSpeed1dayBytes}], instances => $self->{array_interface_selected}); -} - -sub add_result_traffic { - my ($self, %options) = @_; - - $self->{int}->{$options{instance}}->{traffic_in_15min} = - defined($self->{results}->{$self->{currentEthRxHighSpeed15minBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthRxHighSpeed15minBytes} . '.' . $options{instance}} * 8 : - (defined($self->{results}->{$self->{currentEthRx15minBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthRx15minBytes} . '.' . $options{instance}} * 8 : undef); - $self->{int}->{$options{instance}}->{traffic_in_1day} = - defined($self->{results}->{$self->{currentEthRxHighSpeed1dayBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthRxHighSpeed1dayBytes} . '.' . $options{instance}} * 8 : - (defined($self->{results}->{$self->{currentEthRx1dayBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthRx1dayBytes} . '.' . $options{instance}} * 8 : undef); - $self->{int}->{$options{instance}}->{traffic_out_15min} = - defined($self->{results}->{$self->{currentEthTx15minBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthTx15minBytes} . '.' . $options{instance}} * 8 : undef; - $self->{int}->{$options{instance}}->{traffic_out_1day} = - defined($self->{results}->{$self->{currentEthTx1dayBytes} . '.' . $options{instance}}) ? $self->{results}->{$self->{currentEthTx1dayBytes} . '.' . $options{instance}} * 8 : undef; - - $self->{int}->{$options{instance}}->{speed_in} = 0; - $self->{int}->{$options{instance}}->{speed_out} = 0; - if ($self->{get_speed} == 0) { - if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') { - $self->{int}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed} * 1000000; - $self->{int}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed} * 1000000; - } - $self->{int}->{$options{instance}}->{speed_in} = $self->{option_results}->{speed_in} * 1000000 if (defined($self->{option_results}->{speed_in}) && $self->{option_results}->{speed_in} ne ''); - $self->{int}->{$options{instance}}->{speed_out} = $self->{option_results}->{speed_out} * 1000000 if (defined($self->{option_results}->{speed_out}) && $self->{option_results}->{speed_out} ne ''); - } -} - -1; - -__END__ - -=head1 MODE - -Check interfaces. - -=over 8 - -=item B<--add-status> - -Check interface status. - -=item B<--add-traffic> - -Check interface traffic. - -=item B<--add-optical> - -Check interface optical. - -=item B<--warning-status> - -Set warning threshold for status. -Can used special variables like: %{admstatus}, %{opstatus}, %{display} - -=item B<--critical-status> - -Set critical threshold for status (Default: '%{admstatus} eq "up" and %{opstatus} ne "up"'). -Can used special variables like: %{admstatus}, %{opstatus}, %{display} - -=item B<--warning-*> - -Threshold warning. -Can be: 'laser-temp', 'input-power', 'output-power', 'traffic-in', 'traffic-out'. - -=item B<--critical-*> - -Threshold critical. -Can be: 'laser-temp', 'input-power', 'output-power', 'traffic-in', 'traffic-out'. - -=item B<--units-traffic> - -Units of thresholds for the traffic (Default: '%') ('%', 'b/s'). - -=item B<--interface> - -Set the interface (number expected) ex: 1,2,... (empty means 'check all interface'). - -=item B<--name> - -Allows to use interface name with option --interface instead of interface oid index (Can be a regexp) - -=item B<--speed> - -Set interface speed for incoming/outgoing traffic (in Mb). - -=item B<--speed-in> - -Set interface speed for incoming traffic (in Mb). - -=item B<--speed-out> - -Set interface speed for outgoing traffic (in Mb). - -=item B<--reload-cache-time> - -Time in minutes before reloading cache file (default: 180). - -=item B<--oid-filter> - -Choose OID used to filter interface (default: ifName) (values: ifDesc, ifAlias, ifName). - -=item B<--oid-display> - -Choose OID used to display interface (default: ifName) (values: ifDesc, ifAlias, ifName). - -=item B<--oid-extra-display> - -Add an OID to display. - -=item B<--display-transform-src> - -Regexp src to transform display value. - -=item B<--display-transform-dst> - -Regexp dst to transform display value. - -=item B<--show-cache> - -Display cache interface datas. - -=back - -=cut diff --git a/centreon-plugins/network/adva/fsp150/snmp/mode/listinterfaces.pm b/centreon-plugins/network/adva/fsp150/snmp/mode/listinterfaces.pm deleted file mode 100644 index 167bfa0bc..000000000 --- a/centreon-plugins/network/adva/fsp150/snmp/mode/listinterfaces.pm +++ /dev/null @@ -1,160 +0,0 @@ -# -# 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 network::adva::fsp3000::snmp::mode::listinterfaces; - -use base qw(snmp_standard::mode::listinterfaces); - -use strict; -use warnings; - -my $mapping = { - advaInventoryAidString => { oid => '.1.3.6.1.4.1.2544.1.11.7.10.1.1.6' }, - advaInventoryUnitName => { oid => '.1.3.6.1.4.1.2544.1.11.7.10.1.1.7' }, -}; - -sub set_oids_label { - my ($self, %options) = @_; - - $self->{oids_label} = { - 'ifdesc' => '.1.3.6.1.2.1.2.2.1.2', - 'ifalias' => '.1.3.6.1.2.1.31.1.1.1.18', - }; -} - -sub default_oid_filter_name { - my ($self, %options) = @_; - - return 'ifdesc'; -} - -sub default_oid_display_name { - my ($self, %options) = @_; - - return 'ifdesc'; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - return $self; -} - -sub manage_selection { - my ($self, %options) = @_; - - $self->SUPER::manage_selection(%options); - - my $oid_advaInventoryEntry = '.1.3.6.1.4.1.2544.1.11.7.10.1.1'; - my $snmp_result = $self->{snmp}->get_table( - oid => $oid_advaInventoryEntry, - begin => $mapping->{advaInventoryAidString}->{oid}, - end => $mapping->{advaInventoryUnitName}->{oid} - ); - - $self->{extra_oids}->{type} = { oid => $mapping->{advaInventoryUnitName}->{oid}, matching => '%{instance}$' }; - $self->{results}->{ $self->{extra_oids}->{type} } = {}; - foreach my $oid (keys %{$snmp_result}) { - next if ($oid !~ /^$mapping->{advaInventoryUnitName}->{oid}\.(.*)$/); - my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); - - next if ($result->{advaInventoryUnitName} !~ /^(SFP|XFP)/i); - - # interface name example: CH-1-3-N1 - # inventory name example: PL-1-3-N1 - next if ($result->{advaInventoryAidString} !~ /(\d+-\d+-[^\-]+)$/); - my $lookup = $1; - - foreach (sort @{$self->{interface_id_selected}}) { - my $display_value = $self->get_display_value(id => $_); - - if ($display_value =~ /CH-$lookup$/) { - $self->{results}->{ $self->{extra_oids}->{type}->{oid} }->{ $self->{extra_oids}->{type}->{oid} . '.' . $_ } = $result->{advaInventoryUnitName}; - } - } - } -} - -sub disco_format { - my ($self, %options) = @_; - - $self->{extra_oids}->{type} = { oid => $mapping->{advaInventoryUnitName}->{oid}, matching => '%{instance}$' }; - $self->SUPER::disco_format(%options); -} - -1; - -__END__ - -=head1 MODE - -=over 8 - -=item B<--interface> - -Set the interface (number expected) ex: 1,2,... (empty means 'check all interface'). - -=item B<--name> - -Allows to use interface name with option --interface instead of interface oid index (Can be a regexp) - -=item B<--speed> - -Set interface speed (in Mb). - -=item B<--skip-speed0> - -Don't display interface with speed 0. - -=item B<--filter-status> - -Display interfaces matching the filter (example: 'up'). - -=item B<--use-adminstatus> - -Display interfaces with AdminStatus 'up'. - -=item B<--oid-filter> - -Choose OID used to filter interface (default: ifDesc) (values: ifDesc, ifAlias). - -=item B<--oid-display> - -Choose OID used to display interface (default: ifDesc) (values: ifDesc, ifAlias). - -=item B<--display-transform-src> - -Regexp src to transform display value. (security risk!!!) - -=item B<--display-transform-dst> - -Regexp dst to transform display value. (security risk!!!) - -=item B<--add-extra-oid> - -Display an OID. -Example: --add-extra-oid='alias,.1.3.6.1.2.1.31.1.1.1.18' -or --add-extra-oid='vlan,.1.3.6.1.2.1.31.19,%{instance}\..*' - -=back - -=cut diff --git a/centreon-plugins/network/adva/fsp150/snmp/plugin.pm b/centreon-plugins/network/adva/fsp150/snmp/plugin.pm index b4409a7e3..2f45f7132 100644 --- a/centreon-plugins/network/adva/fsp150/snmp/plugin.pm +++ b/centreon-plugins/network/adva/fsp150/snmp/plugin.pm @@ -31,11 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'alarms' => 'network::adva::fsp150::snmp::mode::alarms', - 'interfaces' => 'network::adva::fsp3000::snmp::mode::interfaces', - 'list-interfaces' => 'network::adva::fsp3000::snmp::mode::listinterfaces', - 'memory' => 'snmp_standard::mode::memory', - 'uptime' => 'snmp_standard::mode::uptime' + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'hardware' => 'network::adva::fsp150::snmp::mode::hardware' ); return $self; @@ -47,6 +45,6 @@ __END__ =head1 PLUGIN DESCRIPTION -Check Adva fsp3000 equipments in SNMP. +Check Adva fsp150 equipments in SNMP. =cut From d0905ce31a6ac58381843c766658501b04c9132b Mon Sep 17 00:00:00 2001 From: Simon Bomm Date: Tue, 28 Apr 2020 13:56:28 +0200 Subject: [PATCH 134/190] enh(form) small modification --- centreon-plugins/cloud/aws/vpn/plugin.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/cloud/aws/vpn/plugin.pm b/centreon-plugins/cloud/aws/vpn/plugin.pm index d07982549..ca99496d0 100644 --- a/centreon-plugins/cloud/aws/vpn/plugin.pm +++ b/centreon-plugins/cloud/aws/vpn/plugin.pm @@ -32,7 +32,7 @@ sub new { $self->{version} = '1.0'; %{ $self->{modes} } = ( 'traffic' => 'cloud::aws::vpn::mode::traffic', - 'listvpn' => 'cloud::aws::vpn::mode::listvpn' + 'list-vpn' => 'cloud::aws::vpn::mode::listvpn' ); $self->{custom_modes}{paws} = 'cloud::aws::custom::paws'; From 7c1ed37815f50202075f941963503041deb6d864 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 28 Apr 2020 14:55:55 +0200 Subject: [PATCH 135/190] add fsp150 snmp plugin --- .../network/adva/fsp150/snmp/mode/systems.pm | 212 ++++++++++++++++++ .../network/adva/fsp150/snmp/plugin.pm | 3 +- 2 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 centreon-plugins/network/adva/fsp150/snmp/mode/systems.pm diff --git a/centreon-plugins/network/adva/fsp150/snmp/mode/systems.pm b/centreon-plugins/network/adva/fsp150/snmp/mode/systems.pm new file mode 100644 index 000000000..d4a345c5e --- /dev/null +++ b/centreon-plugins/network/adva/fsp150/snmp/mode/systems.pm @@ -0,0 +1,212 @@ +# +# 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 network::adva::fsp150::snmp::mode::systems; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub prefix_system_output { + my ($self, %options) = @_; + + return "system '" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'systems', type => 1, cb_prefix_output => 'prefix_system_output', message_multiple => 'All systems are ok' } + ]; + + $self->{maps_counters}->{systems} = [ + { label => 'cpu-utilization-15min', nlabel => 'system.cpu.utilization.15min.percentage', set => { + key_values => [ + { name => 'cpu_average' }, { name => 'ne_name' }, { name => 'shelf_name' }, + { name => 'slot_name' }, { name => 'display' } + ], + output_template => 'cpu usage: %.2f%% (15min)', + closure_custom_perfdata => sub { + my ($self) = @_; + + $self->{output}->perfdata_add( + nlabel => $self->{nlabel}, + unit => '%', + instances => [ + $self->{result_values}->{ne_name_absolute}, + $self->{result_values}->{shelf_name_absolute}, + $self->{result_values}->{slot_name_absolute} + ], + value => sprintf('%.2f', $self->{result_values}->{cpu_average_absolute}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + min => 0, max => 100 + ); + } + } + }, + { label => 'memory-usage', nlabel => 'system.memory.usage.bytes', set => { + key_values => [ + { name => 'memory_used' }, { name => 'ne_name' }, { name => 'shelf_name' }, + { name => 'slot_name' }, { name => 'display' } + ], + output_template => 'memory used: %s%s', + output_change_bytes => 1, + closure_custom_perfdata => sub { + my ($self) = @_; + + $self->{output}->perfdata_add( + nlabel => $self->{nlabel}, + unit => 'B', + instances => [ + $self->{result_values}->{ne_name_absolute}, + $self->{result_values}->{shelf_name_absolute}, + $self->{result_values}->{slot_name_absolute} + ], + value => $self->{result_values}->{memory_used_absolute}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), + min => 0 + ); + } + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-network-element:s' => { name => 'filter_network_element' } + }); + + return $self; +} + +my $mapping = { + cpu_average => { oid => '.1.3.6.1.4.1.2544.1.12.5.1.75.1.5' }, # f3CardStatsACU + memory_used => { oid => '.1.3.6.1.4.1.2544.1.12.5.1.75.1.10' } # f3CardStatsIMU (KB) +}; +my $map_stat_index = { + 1 => '15min', 2 => '1day', 3 => 'rollover', 4 => '5min' +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $mapping->{cpu_average}->{oid} }, + { oid => $mapping->{memory_used}->{oid} } + ], + return_type => 1, + nothing_quit => 1 + ); + + my ($ne_indexes, $shelf_indexes, $slot_indexes) = ({}, {}, {}); + foreach (keys %$snmp_result) { + next if (! /^$mapping->{cpu_average}->{oid}\.(\d+)\.(\d+)\.(\d+)\./); + $ne_indexes->{$1} = 1; + $shelf_indexes->{$1 . '.' . $2} = 1; + $slot_indexes->{$1 . '.' . $2 . '.' . $3} = 1; + } + + my $oid_slotEntityIndex = '.1.3.6.1.4.1.2544.1.12.3.1.3.1.2'; + my $oid_shelfEntityIndex = '.1.3.6.1.4.1.2544.1.12.3.1.2.1.2'; + my $oid_neName = '.1.3.6.1.4.1.2544.1.12.3.1.1.1.2'; + my $snmp_indexes = $options{snmp}->get_leef( + oids => [ + map($oid_neName . '.' . $_, keys(%$ne_indexes)), + map($oid_shelfEntityIndex . '.' . $_, keys(%$shelf_indexes)), + map($oid_slotEntityIndex . '.' . $_, keys(%$slot_indexes)) + ] + ); + + my $entity_indexes = {}; + foreach (keys %$snmp_indexes) { + $entity_indexes->{$snmp_indexes->{$_}} = 1 if (/^(?:$oid_shelfEntityIndex|$oid_slotEntityIndex)\./); + } + + my $oid_entPhysicalName = '.1.3.6.1.2.1.47.1.1.1.1.7'; + my $snmp_entities = $options{snmp}->get_leef( + oids => [ + map($oid_entPhysicalName . '.' . $_, keys(%$entity_indexes)) + ] + ); + + $self->{systems} = {}; + foreach (keys %$snmp_result) { + next if (! /^$mapping->{cpu_average}->{oid}\.(\d+)\.(\d+)\.(\d+)\.1/); # we want 15min + my $instance = $1 . '.' . $2 . '.' . $3; + my $ne_name = $snmp_indexes->{ $oid_neName . '.' . $1 }; + my $shelf_name = $snmp_entities->{ $oid_entPhysicalName . '.' . $snmp_indexes->{ $oid_shelfEntityIndex . '.' . $1 . '.' . $2 } }; + my $slot_name = $snmp_entities->{ $oid_entPhysicalName . '.' . $snmp_indexes->{ $oid_slotEntityIndex . '.' . $1 . '.' . $2 . '.' . $3 } }; + + my $result = $options{snmp}->map_instance( + mapping => $mapping, + results => $snmp_result, + instance => $instance. '.1' + ); + $result->{memory_used} *= 1024; + my $display = $ne_name . ':' . $shelf_name . ':' . $slot_name; + + if (defined($self->{option_results}->{filter_network_element}) && $self->{option_results}->{filter_network_element} ne '' && + $ne_name !~ /$self->{option_results}->{filter_network_element}/) { + $self->{output}->output_add(long_msg => "skipping system '" . $display . "': no matching filter.", debug => 1); + next; + } + + $self->{systems}->{$instance} = { + display => $display, + ne_name => $ne_name, + shelf_name => $shelf_name, + slot_name => $slot_name, + %$result + }; + } +} + +1; + +__END__ + +=head1 MODE + +Check systems. + +=over 8 + +=item B<--filter-network-elemet> + +Filter by network element name (can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'cpu-utilization-15min', 'memory-usage'. + +=back + +=cut diff --git a/centreon-plugins/network/adva/fsp150/snmp/plugin.pm b/centreon-plugins/network/adva/fsp150/snmp/plugin.pm index 2f45f7132..3612f6536 100644 --- a/centreon-plugins/network/adva/fsp150/snmp/plugin.pm +++ b/centreon-plugins/network/adva/fsp150/snmp/plugin.pm @@ -31,9 +31,10 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( + 'hardware' => 'network::adva::fsp150::snmp::mode::hardware', 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'hardware' => 'network::adva::fsp150::snmp::mode::hardware' + 'systems' => 'network::adva::fsp150::snmp::mode::systems' ); return $self; From feb62638af454eafa3890aded4305dd4faed9ac7 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 28 Apr 2020 16:09:18 +0200 Subject: [PATCH 136/190] adva fsp150 finished --- .../network/adva/fsp150/snmp/mode/alarms.pm | 297 ++++++++++++++++++ .../network/adva/fsp150/snmp/plugin.pm | 1 + 2 files changed, 298 insertions(+) create mode 100644 centreon-plugins/network/adva/fsp150/snmp/mode/alarms.pm diff --git a/centreon-plugins/network/adva/fsp150/snmp/mode/alarms.pm b/centreon-plugins/network/adva/fsp150/snmp/mode/alarms.pm new file mode 100644 index 000000000..919b0d12c --- /dev/null +++ b/centreon-plugins/network/adva/fsp150/snmp/mode/alarms.pm @@ -0,0 +1,297 @@ +# +# 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 network::adva::fsp150::snmp::mode::alarms; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::misc; +use centreon::plugins::statefile; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + 'alarm %s [severity: %s] [type: %s] [object: %s] [description: %s] %s', + $self->{result_values}->{label}, + $self->{result_values}->{severity}, + $self->{result_values}->{type}, + $self->{result_values}->{object}, + $self->{result_values}->{description}, + $self->{result_values}->{generation_time} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'alarms', type => 2, message_multiple => '0 problem(s) detected', display_counter_problem => { label => 'alerts', min => 0 }, + group => [ { name => 'alarm', skipped_code => { -11 => 1 } } ] + } + ]; + + $self->{maps_counters}->{alarm} = [ + { label => 'status', threshold => 0, set => { + key_values => [ + { name => 'severity' }, { name => 'type' }, + { name => 'label'}, { name => 'since' }, + { name => 'object' }, { name => 'description' }, + { name => 'generation_time' } + ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{severity} eq "serviceAffecting"' }, + 'memory' => { name => 'memory' }, + 'timezone:s' => { name => 'timezone' } + }); + + centreon::plugins::misc::mymodule_load( + output => $self->{output}, + module => 'DateTime', + error_msg => "Cannot load module 'DateTime'." + ); + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->check_options(%options); + } + + $self->{option_results}->{timezone} = 'GMT' if (!defined($self->{option_results}->{timezone}) || $self->{option_results}->{timezone} eq ''); +} + +my $map_type = { + 0 => 'none', 1 => 'acoopr', 2 => 'hwinitedsysboot', 3 => 'userinitednemireboot', 4 => 'userinitedsysboot', + 5 => 'userinitedsysbootdefaultdb', 6 => 'userinitedsysbootdbrestore ', 7 => 'userinitedsysrebootswact', + 8 => 'sysrecoveryfailed', 9 => 'primntpsvrFailed', 10 => 'bckupntpsvrFailed', 11 => 'swdl-ftip', 12 => 'swdl-ftfail', + 13 => 'swdl-ftpass', 14 => 'swdl-instip', 15 => 'swdl-instfail', 16 => 'swdl-instpass', 17 => 'swdl-actip', + 18 => 'swdl-actfail', 19 => 'swdl-actpass', 20 => 'swdl-valip', 21 => 'swdl-valfail', 22 => 'swdl-valpass', + 23 => 'db-ftip', 24 => 'db-ftfail', 25 => 'db-ftpass', 26 => 'ctneqpt', 27 => 'eqptflt', 28 => 'forced', + 29 => 'lockout', 30 => 'manualswitch', 31 => 'wkswtopr', 32 => 'wkswbk', 33 => 'mismatch', 34 => 'psu1fail', + 35 => 'psu2fail', 36 => 'eqptremoved', 37 => 'autonegunknown', 38 => 'dyinggasp', 39 => 'efmfail', 40 => 'efmrce', + 41 => 'efmrld', 42 => 'efmrls', 43 => 'lnkdeactivated', 44 => 'lnkdownunisolated', 45 => 'lnkdowncablefault', + 46 => 'lnkdowncableremoved', 47 => 'lnkdownautonegfailed', 48 => 'lnkdownlpbkfault', 49 => 'lnkdowncabletestfault', + 50 => 'lnkdown', 51 => 'rfi', 52 => 'rxjabber', 53 => 'sfpmismatch', 54 => 'sfpremoved', 55 => 'sfptxfault', 56 => 'sfpinserted', + 57 => 'fan-a', 58 => 'fan-b', 59 => 'overtemp', 60 => 'undertemp', 61 => 'overvoltage', 62 => 'undervoltage', + 63 => 'shelfrmvd', 64 => 'rmtefmlpbkfail', 65 => 'inpwrflt', 66 => 'crossconnectccm', 67 => 'erroneousccm', + 68 => 'someremotemepccm', 69 => 'somemacstatus', 70 => 'somerdi', 71 => 'ais', 72 => 'syncref', 73 => 'esmcfail', + 74 => 'qlmismatch', 75 => 'freqoff', 76 => 'los', 77 => 'lof', 78 => 'qlsqlch', 79 => 'frngsync', 80 => 'fstsync', + 81 => 'hldovrsync', 82 => 'losloc', 83 => 'wtr', 84 => 'allsyncref', 85 => 'qlinvalid', 86 => 'snmpdghostunresolved', + 87 => 'snmpdghostresourcesbusy', 88 => 'bwexceedednegspeed', 89 => 'shaperbtd', 90 => 'sfpnonqualified', + 91 => 'avghldovrfrqnotrdy', 92 => 'lnkdownmasterslavecfg', 93 => 'pwrnoinputunitfault', 94 => 'ipaddrconflict', + 95 => 'nomoreresources', 96 => 'syncreflck', 97 => 'syncreffrc', 98 => 'syncrefman', 99 => 'syncrefwtr', + 100 => 'syncrefsw', 101 => 'lcpfail', 102 => 'lcploopback', 103 => 'authservernotreachable', 104 => 'excessiveinterrupts', + 105 => 'dbdowngradeip', 106 => 'testalarm', 107 => 'gen-filexfer-ip', 108 => 'gen-filexfer-fail', 109 => 'gen-filexfer-pass', + 110 => 'gen-oper-ip', 111 => 'gen-oper-fail', 112 => 'gen-oper-pass', 113 => 'trafficfail', 114 => 'clockfail', + 115 => 'rdncyswitchover', 116 => 'rdncyswvermismatch', 117 => 'rdncyoutofsync', 118 => 'rdncylockout', 119 => 'rdncymaintenance', + 120 => 'xfptxfault', 121 => 'xfpmismatch', 122 => 'xfpnonqualified', 123 => 'xfpremoved', 124 => 'xfpinserted', + 125 => 'lagmbrfail', 126 => 'swdl-proip', 127 => 'swdl-propass', 128 => 'swdl-profail', 129 => 'db-proip', + 130 => 'db-propass', 131 => 'db-profail', 132 => 'swdl-rvtip', 133 => 'swdl-rvtpass', 134 => 'swdl-rvtfail', + 135 => 'db-corruption', 136 => 'bpmismatch', 137 => 'popr-oovar', 138 => 'popr-oorange', 139 => 'popr-genfail', + 140 => 'popr-sfpnqual', 141 => 'popr-rta', 142 => 'modemmea', 143 => 'modemnonqualified', 144 => 'modemremoved', + 145 => 'nosimcard', 146 => 'env-genfail', 147 => 'env-misc', 148 => 'env-batterydischarge', 149 => 'env-batteryfail', + 150 => 'env-coolingfanfail', 151 => 'env-enginefail', 152 => 'env-fusefail', 153 => 'env-hightemp', 154 => 'env-intrusion', + 155 => 'env-lowbatteryvoltage', 156 => 'env-lowtemp', 157 => 'env-opendoor', 158 => 'env-powerfail', 159 => 'intctneqpt', + 160 => 'syncnotready', 161 => 'vcgfail', 162 => 'loa', 163 => 'plct', 164 => 'tlct', 165 => 'plcr', 166 => 'tlcr', 167 => 'sqnc', + 168 => 'ais-l', 169 => 'rfi-l', 170 => 'rei-l', 171 => 'exc-l', 172 => 'deg-l', 173 => 'tim-s', 174 => 'ais-p', 175 => 'lop-p', + 176 => 'tim-p', 177 => 'uneq-p', 178 => 'plm-p', 179 => 'lom-p', 180 => 'exc-p', 181 => 'deg-p', 182 => 'rei-p', 183 => 'rfi-p', + 184 => 'lcascrc', 185 => 'sqm', 186 => 'lom', 187 => 'gidmismatch', 188 => 'mnd', 189 => 'ais-v', 190 => 'lop-v', 191 => 'tim-v', + 192 => 'uneq-v', 193 => 'plm-v', 194 => 'exc-v', 195 => 'deg-v', 196 => 'rei-v', 197 => 'rfi-v', 198 => 'rmtinitlpbk', 199 => 'rai', + 200 => 'rei', 201 => 'idle', 202 => 'csf', 203 => 'gfplfd', 204 => 'gfpuplmismatch', 205 => 'gfpexhmismatch', 206 => 'vcat-lom', + 207 => 'fragileecc', 208 => 'elmi-seqnummismatch', 209 => 'elmi-notoper', 210 => 'pw-rlofs', 211 => 'pw-lof', 212 => 'pw-latefrm', + 213 => 'pw-jbovrn', 214 => 'allsoocsfailed', 215 => 'tsholdoverfrqnotready', 216 => 'tsfreerun', 217 => 'tsholdover', 218 => 'ptsflossofsync', + 219 => 'ptsflossofannounce', 220 => 'ptsfunusable', 221 => 'unresolvedsatop', 222 => 'rdi-v', 223 => 'autonegBypass', 224 => 'forcedOffline', + 225 => 'hwcfginconsistent', 226 => 'sjmtiemaskcross', 227 => 'sjoffsetfail', 228 => 'sjnotimelock', 229 => 'sjnofreqlock', 230 => 'sjmtiemargincross', + 231 => 'sjtestreferencefail', 232 => 'sjtestsourcefail', 233 => 'sjtestnotimestamp', 234 => 'sjtestnomessages', 235 => 'gpsantennafail', + 236 => 'ampNoPeer', 237 => 'ampProvFail', 238 => 'ampCfgFail', 239 => 'ltpFailure', 240 => 'ltpInprogress', 241 => 'pse-power-threshold-exceeded', + 242 => 'pse-power-fail', 243 => 'pse-poweroff-overcurrent', 244 => 'pse-poweroff-overvoltage', 245 => 'pse-poweroff-overload', + 246 => 'pse-poweroff-overtemp', 247 => 'pse-poweroff-short', 248 => 'erpFoPPM', 249 => 'erpFoPTO', 250 => 'erpBlockPort0RPL', 251 => 'erpBlockPort0SF', + 252 => 'erpBlockPort0MS', 253 => 'erpBlockPort0FS', 254 => 'erpBlockPort0WTR', 255 => 'erpBlockPort1RPL', 256 => 'erpBlockPort1SF', + 257 => 'erpBlockPort1MS', 258 => 'erpBlockPort1FS', 259 => 'erpBlockPort1WTR', 260 => 'ipv6addr-conflict', 261 => 'macAddrlearntblFull', + 262 => 'timeClockNotLocked', 263 => 'timeNotTraceAble', 264 => 'timeFreqNotTraceAble', 265 => 'timeHoldOver', 266 => 'timeFreqLock', + 267 => 'timeRefLock', 268 => 'timeRefUnavailable', 269 => 'timeRefDegraded', 270 => 'timeRefFrc', 271 => 'tsTimeFrun', 272 => 'tsTimeHoldOver', + 273 => 'timeRefUnavailableWTR', 274 => 'timeRefDegradedWTR', 275 => 'rmtInitSat', 276 => 'lldpRemoteTblChg', 277 => 'soocLck', 278 => 'ampProvSuccess', + 279 => 'ampCfgSuccess', 280 => 'soocSW', 281 => 'soocWTR', 282 => 'sjtealert', 283 => 'dataExportFtpFail', 284 => 'xfpWaveLengthMismatch', + 285 => 'cpmrUpgrading', 286 => 'beaconLightFailure', 287 => 'manualSwitchClear', 288 => 'loopbackActive', 289 => 'loopbackRequest', + 290 => 'trafficResourceLimitExceeded', 291 => 'oduAis', 292 => 'opuAis', 293 => 'otuAis', 294 => 'otnProtMsmtch', 295 => 'otnProtPrtclFail', + 296 => 'oduBdi', 297 => 'otuBdi', 298 => 'lossCharSync', 299 => 'berHigh', 300 => 'laserFail', 301 => 'laserCurrentAbnormal', 302 => 'oduLock', + 303 => 'autoShutdown', 304 => 'localFault', 305 => 'otuLof', 306 => 'otuLom', 307 => 'oduOci', 308 => 'opuPlm', 309 => 'oduSd', 310 => 'otuSd', + 311 => 'opuSf', 312 => 'optPowerHighRx', 313 => 'optPowerLowRx', 314 => 'optPowerHighTx', 315 => 'optPowerLowTx', 316 => 'oduTim', 317 => 'otuTim', + 318 => 'sjConstTeThrshld', 319 => 'sjInstTeThrshld', 320 => 'timeRefSW', 321 => 'aadcfailed', 322 => 'ptpfreqfrun', 323 => 'ptptimefrun', + 324 => 'ptpfreqhldovr', 325 => 'ptptimehldovr', 326 => 'ptptimenottraceable', 327 => 'ptpfreqnottraceable', 328 => 'synctimeout', 329 => 'announcetimeout', + 330 => 'delayresptimeout', 331 => 'multiplepeers', 332 => 'wrongdomain', 333 => 'nosatellitercv', 334 => 'trafficipifoutage', 335 => 'ptpportstatechanged', + 336 => 'physicalSelfLpbk', 337 => 'cfCardRWFail', 338 => 'maxexpectedslaves', 339 => 'external-alarm', 340 => 'maskcrossed', 341 => 'oof', + 342 => 'signalfail', 343 => 'timenottai', 344 => 'perffuncfailure', 345 => 'ptpportnotoper', 346 => 'leapsecondexpected', 347 => 'keyExchangeFail', + 348 => 'keyExchangeAuthPasswordMissing', 349 => 'secureRamCleared', 350 => 'noRouteResources', 351 => 'tamperSwitchOpen', 352 => 'bfdSessionDown', + 353 => 'destinationUnresolved', 354 => 'sjmaxtethrshld', 355 => 'trafficArpTableFull', 357 => 'erpRingSegmentation(356), gpsrcvrfail', + 358 => 'noActiveRoute', 359 => 'vxlanDMac2DIPTableFull', 360 => 'bwExceedLagMemberPortSpeed', 361 => 'greRemoteUnreachable', 362 => 'bweexceedsportspeed', + 363 => 'servicediscarded', 364 => 'bmcaError', 365 => 'freeze', 366 => 'gpsFwUpgrade', 367 => 'storageWearout', 368 => 'pps-not-generated', + 369 => 'min-sat-1-thrshld-crossed', 370 => 'min-sat-2-thrshld-crossed', 371 => 'gatewayNotReachable', 372 => 'pdop-mask-cross', 373 => 'nc-initInProgress', + 374 => 'primaryNtpSvr-auth-failed', 375 => 'backupNtpSvr-auth-failed', 376 => 'clock-class-mismatch', 377 => 'hpg-switch-force', 378 => 'hpg-switch-lockout', + 379 => 'hpg-switch-to-3gpp-path', 380 => 'hpg-switch-to-fixed-path', 381 => 'bgp-linkdown', 382 => 'ospf-neighbour-lost', 383 => 'traffic-ndptable-full', + 384 => 'dup-link-local-address', 385 => 'dup-unicast-address', 386 => 'ztp-failed', 387 => 'ztp-in-progress', 388 => 'nc-runningConfigLocked', + 389 => 'pwrnoinput2', 390 => 'keyExchangeStopped', 391 => 'security-error', 392 => 'pppoe-connection-failed', 393 => 'no-ipv6route-resource', + 394 => 'sfp-firmware-revision-mismatch', 395 => 'vrrp-new-master', 396 => 'nontpkeys', 397 => 'timesrcunavailable', 398 => 'syncsrcunavailable', + 399 => 'local-cooling-fail', 400 => 'jamming', 401 => 'spoofing', 402 => 'httpsSslCertExpiryPending', 403 => 'httpsSslCertExpired', 404 => 'srgb-collision', + 405 => 'sid-collision', 406 => 'sr-index-out-of-range' +}; +my $map_severity = { + 0 => 'none', 1 => 'nonServiceAffecting', 2 => 'serviceAffecting' +}; + +my $oids = { + cmSysAlmEntry => { + oid => '.1.3.6.1.4.1.2544.1.12.6.1.2.1', label => 'sys', + mapping => { + type => { oid => '.1.3.6.1.4.1.2544.1.12.6.1.2.1.2', map => $map_type }, # cmSysAlmType + severity => { oid => '.1.3.6.1.4.1.2544.1.12.6.1.2.1.3', map => $map_severity }, # cmSysAlmSrvEff + timestamp => { oid => '.1.3.6.1.4.1.2544.1.12.6.1.2.1.4' }, # cmSysAlmTime + description => { oid => '.1.3.6.1.4.1.2544.1.12.6.1.2.1.7' }, # cmSysAlmDescr + object => { oid => '.1.3.6.1.4.1.2544.1.12.6.1.2.1.9' }, # cmSysAlmObjectName + } + }, + cmNetworkElementAlmEntry => { + oid => '.1.3.6.1.4.1.2544.1.12.6.1.4.1', label => 'networkElement', + mapping => { + type => { oid => '.1.3.6.1.4.1.2544.1.12.6.1.4.1.2', map => $map_type }, # cmNetworkElementAlmType + severity => { oid => '.1.3.6.1.4.1.2544.1.12.6.1.4.1.3', map => $map_severity }, # cmNetworkElementAlmSrvEff + timestamp => { oid => '.1.3.6.1.4.1.2544.1.12.6.1.4.1.4' }, # cmNetworkElementAlmTime + description => { oid => '.1.3.6.1.4.1.2544.1.12.6.1.4.1.7' }, # cmNetworkElementAlmDescr + object => { oid => '.1.3.6.1.4.1.2544.1.12.6.1.4.1.9' }, # cmNetworkElementAlmObjectName + } + } +}; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{alarms}->{global} = { alarm => {} }; + my $get_oids = []; + foreach (keys %$oids) { + push @$get_oids, { + oid => $oids->{$_}->{oid}, + start => $oids->{$_}->{mapping}->{type}->{oid}, + end => $oids->{$_}->{mapping}->{object}->{oid} + }; + } + my $snmp_result = $options{snmp}->get_multiple_table(oids => $get_oids); + + my $last_time; + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->read(statefile => 'cache_adva_fsp150_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port(). '_' . $self->{mode}); + $last_time = $self->{statefile_cache}->get(name => 'last_time'); + } + + my ($i, $current_time) = (1, time()); + foreach (keys %$oids) { + my $branch_oid = $oids->{$_}->{oid}; + next if (!defined($snmp_result->{$branch_oid})); + + foreach my $oid (keys %{$snmp_result->{$branch_oid}}) { + next if ($oid !~ /^$oids->{$_}->{mapping}->{severity}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $oids->{$_}->{mapping}, results => $snmp_result->{$branch_oid}, instance => $instance); + + my @date = unpack 'n C6 a C2', $result->{timestamp}; + my $timezone = $self->{option_results}->{timezone}; + if (defined($date[7])) { + $timezone = sprintf("%s%02d%02d", $date[7], $date[8], $date[9]); + } + + my $tz = centreon::plugins::misc::set_timezone(name => $timezone); + my $dt = DateTime->new( + year => $date[0], month => $date[1], day => $date[2], hour => $date[3], minute => $date[4], second => $date[5], + %$tz + ); + + next if (defined($self->{option_results}->{memory}) && defined($last_time) && $last_time > $dt->epoch); + + my $diff_time = $current_time - $dt->epoch; + + $self->{alarms}->{global}->{alarm}->{$i} = { + since => $diff_time, + generation_time => centreon::plugins::misc::change_seconds(value => $diff_time), + label => $oids->{$_}->{label}, + %$result + }; + $i++; + } + } + + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->write(data => { last_time => $current_time }); + } +} + +1; + +__END__ + +=head1 MODE + +Check alarms. + +=over 8 + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{description}, %{object}, %{severity}, %{type}, %{label}, %{since} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{severity} eq "serviceAffecting"'). +Can used special variables like: {description}, %{object}, %{severity}, %{type}, %{label}, %{since} + +=item B<--timezone> + +Timezone options (the date from the equipment overload that option). Default is 'GMT'. + +=item B<--memory> + +Only check new alarms. + +=back + +=cut diff --git a/centreon-plugins/network/adva/fsp150/snmp/plugin.pm b/centreon-plugins/network/adva/fsp150/snmp/plugin.pm index 3612f6536..bb9bf77a6 100644 --- a/centreon-plugins/network/adva/fsp150/snmp/plugin.pm +++ b/centreon-plugins/network/adva/fsp150/snmp/plugin.pm @@ -31,6 +31,7 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( + 'alarms' => 'network::adva::fsp150::snmp::mode::alarms', 'hardware' => 'network::adva::fsp150::snmp::mode::hardware', 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', From 0fe6d543f5ca05cf9533906de4def4417a9f6104 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 28 Apr 2020 17:45:05 +0200 Subject: [PATCH 137/190] add unit component for hardwarefiberalliance mode --- .../mode/hardwarefibrealliance.pm | 112 +++++++++++++++--- 1 file changed, 98 insertions(+), 14 deletions(-) diff --git a/centreon-plugins/snmp_standard/mode/hardwarefibrealliance.pm b/centreon-plugins/snmp_standard/mode/hardwarefibrealliance.pm index 1d01547e9..404b432da 100644 --- a/centreon-plugins/snmp_standard/mode/hardwarefibrealliance.pm +++ b/centreon-plugins/snmp_standard/mode/hardwarefibrealliance.pm @@ -28,17 +28,24 @@ use warnings; sub set_system { my ($self, %options) = @_; - $self->{regexp_threshold_overload_check_section_option} = '^(sensors|port)$'; + $self->{regexp_threshold_overload_check_section_option} = '^(sensors|port|unit)$'; $self->{cb_hook2} = 'snmp_execute'; $self->{thresholds} = { + unit => [ + ['unknown', 'UNKNOWN'], + ['unused', 'OK'], + ['warning', 'WARNING'], + ['failed', 'CRITICAL'], + ['ok', 'OK'] + ], sensors => [ ['unknown', 'UNKNOWN'], ['other', 'UNKNOWN'], ['warning', 'WARNING'], ['failed', 'CRITICAL'], - ['ok', 'OK'], + ['ok', 'OK'] ], port => [ ['warning', 'WARNING'], @@ -46,18 +53,20 @@ sub set_system { ['unused', 'OK'], ['initializing', 'OK'], ['ready', 'OK'], - ['.*', 'UNKNOWN'], - ], + ['.*', 'UNKNOWN'] + ] }; $self->{components_path} = 'snmp_standard::mode::components'; - $self->{components_module} = ['sensors', 'port']; + $self->{components_module} = ['sensors', 'port', 'unit']; } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, - no_absent => 1, no_performance => 1, no_load_components => 1, force_new_perfdata => 1); + my $self = $class->SUPER::new( + package => __PACKAGE__, %options, + no_absent => 1, no_performance => 1, no_load_components => 1, force_new_perfdata => 1 + ); bless $self, $class; $options{options}->add_options(arguments => {}); @@ -84,7 +93,11 @@ http://www.emc.com/microsites/fibrealliance/index.htm =item B<--component> Which component to check (Default: '.*'). -Can be: 'sensors', 'port'. +Can be: 'unit', 'sensors', 'port'. + +=item B<--add-name-instance> + +Add literal description for instance value (used in filter, and threshold options). =item B<--filter> @@ -150,7 +163,7 @@ sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "checking sensors"); - $self->{components}->{sensors} = {name => 'sensors', total => 0, skip => 0}; + $self->{components}->{sensors} = { name => 'sensors', total => 0, skip => 0 }; return if ($self->check_filter(section => 'sensors')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_connUnitSensorEntry}})) { @@ -162,9 +175,9 @@ sub check { $self->{components}->{sensors}->{total}++; $self->{output}->output_add(long_msg => sprintf( - "sensor '%s' status is %s [msg: %s] [type: %s] [chara: %s] [instance: %s]", + "sensor '%s' status is %s [msg: %s] [type: %s] [chara: %s]", $result->{connUnitSensorName}, $result->{connUnitSensorStatus}, - $result->{connUnitSensorMessage}, $result->{connUnitSensorType}, $result->{connUnitSensorCharacteristic}, $instance) + $result->{connUnitSensorMessage}, $result->{connUnitSensorType}, $result->{connUnitSensorCharacteristic}) ); my $exit = $self->get_severity(section => 'sensors', name => $result->{connUnitSensorName}, value => $result->{connUnitSensorStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { @@ -208,7 +221,7 @@ sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "checking ports"); - $self->{components}->{port} = {name => 'ports', total => 0, skip => 0}; + $self->{components}->{port} = { name => 'ports', total => 0, skip => 0 }; return if ($self->check_filter(section => 'port')); foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping_port->{connUnitPortName}->{oid} }})) { @@ -222,8 +235,8 @@ sub check { $self->{components}->{port}->{total}++; $self->{output}->output_add( long_msg => sprintf( - "port '%s' status is %s [instance: %s]", - $name, $result->{connUnitPortStatus}, $instance + "port '%s' status is %s", + $name, $result->{connUnitPortStatus} ) ); my $exit = $self->get_severity(section => 'port', name => $name, value => $result->{connUnitPortStatus}); @@ -239,3 +252,74 @@ sub check { } } } + +package snmp_standard::mode::components::unit; + +use strict; +use warnings; + +my $map_unit_status = { + 1 => 'unknown', 2 => 'unused', 3 => 'ok', 4 => 'warning', 5 => 'failed' +}; +my $map_unit_type = { + 1 => 'unknown', 2 => 'other', 3 => 'hub', 4 => 'switch', 5 => 'gateway', + 6 => 'converter', 7 => 'hba', 8 => 'proxy-agent', 9 => 'storage-device', + 10 => 'host', 11 => 'storage-subsystem', 12 => 'module', 13 => 'swdriver', + 14 => 'storage-access-device', 15 => 'wdm', 16 => 'ups', 17 => 'nas' +}; + +my $mapping_unit = { + connUnitType => { oid => '.1.3.6.1.3.94.1.6.1.3', map => $map_unit_type }, + connUnitStatus => { oid => '.1.3.6.1.3.94.1.6.1.6', map => $map_unit_status }, + connUnitName => { oid => '.1.3.6.1.3.94.1.6.1.20' } +}; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, + { oid => $mapping_unit->{connUnitType}->{oid} }, + { oid => $mapping_unit->{connUnitStatus}->{oid} }, + { oid => $mapping_unit->{connUnitName}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "checking units"); + $self->{components}->{unit} = { name => 'units', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'unit')); + + my $results = { + %{$self->{results}->{ $mapping_unit->{connUnitType}->{oid} }}, + %{$self->{results}->{ $mapping_unit->{connUnitStatus}->{oid} }}, + %{$self->{results}->{ $mapping_unit->{connUnitName}->{oid} }}, + }; + foreach my $key ($self->{snmp}->oid_lex_sort(keys %$results)) { + next if ($key !~ /^$mapping_unit->{connUnitName}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping_unit, results => $results, instance => $instance); + my $name = $result->{connUnitType} . '.' . $result->{connUnitName}; + + next if ($self->check_filter(section => 'unit', instance => $instance, name => $name)); + + $self->{components}->{unit}->{total}++; + $self->{output}->output_add( + long_msg => sprintf( + "unit '%s' status is %s", + $name, $result->{connUnitStatus} + ) + ); + my $exit = $self->get_severity(section => 'unit', instance => $instance, name => $name, value => $result->{connUnitStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Unit '%s' status is %s", + $name, + $result->{connUnitStatus} + ) + ); + } + } +} From c7f6dfbd8cf914334582410e9ceb20036e590db8 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 29 Apr 2020 09:43:18 +0200 Subject: [PATCH 138/190] update fsp150 --- centreon-plugins/network/adva/fsp150/snmp/mode/alarms.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/centreon-plugins/network/adva/fsp150/snmp/mode/alarms.pm b/centreon-plugins/network/adva/fsp150/snmp/mode/alarms.pm index 919b0d12c..781e6cabb 100644 --- a/centreon-plugins/network/adva/fsp150/snmp/mode/alarms.pm +++ b/centreon-plugins/network/adva/fsp150/snmp/mode/alarms.pm @@ -46,7 +46,7 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'alarms', type => 2, message_multiple => '0 problem(s) detected', display_counter_problem => { label => 'alerts', min => 0 }, + { name => 'alarms', type => 2, message_multiple => '0 problem(s) detected', display_counter_problem => { nlabel => 'alerts.problems.current.count', min => 0 }, group => [ { name => 'alarm', skipped_code => { -11 => 1 } } ] } ]; @@ -70,7 +70,7 @@ sub set_counters { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { From 68bcc07574e0a94d4cc72d46811e737122f33f7b Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 29 Apr 2020 15:02:12 +0200 Subject: [PATCH 139/190] add remaining time enexus --- .../devices/eltek/enexus/snmp/mode/battery.pm | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/battery.pm b/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/battery.pm index 652603bde..d4e8a6500 100644 --- a/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/battery.pm +++ b/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/battery.pm @@ -208,6 +208,7 @@ my $mapping = { batteryRemainingCapacityValue => { oid => '.1.3.6.1.4.1.12148.10.10.9.5' }, # ah or % batteryRemainingCapacityMinorLowLevel => { oid => '.1.3.6.1.4.1.12148.10.10.9.6' }, batteryRemainingCapacityMajorLowLevel => { oid => '.1.3.6.1.4.1.12148.10.10.9.7' }, + loadCurrentValue => { oid => '.1.3.6.1.4.1.12148.10.9.2.5' }, # A or dA }; sub threshold_eltek_configured { @@ -246,9 +247,17 @@ sub manage_selection { charge_remaining_unit => $result->{powerSystemCapacityScale} }; # we can calculate the time remaining if unit is ah (amperehour) and current battery is discharging (negative value) - if ($result->{powerSystemCapacityScale} eq 'ah' && $result->{batteryCurrentsValue} < 0) { + my $current; + if ($result->{batteryCurrentsValue} < 0) { + $current = $result->{batteryCurrentsValue} * -1 + } elsif ($result->{loadCurrentValue} > 0) { + $current = $result->{loadCurrentValue}; + } + + + if ($result->{powerSystemCapacityScale} eq 'ah' && defined($current)) { $self->{battery}->{charge_remaining_time} = - int($result->{batteryRemainingCapacityValue} * 3600 / $result->{batteryCurrentsValue} * $scale_current * -1); + int($result->{batteryRemainingCapacityValue} * 3600 / $current * $scale_current); } $self->threshold_eltek_configured( From f8eaff38ec575fe100d8367cbaf3919ae1b275a6 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 30 Apr 2020 11:13:21 +0200 Subject: [PATCH 140/190] fix unit battery eltek enexus --- .../hardware/devices/eltek/enexus/snmp/mode/battery.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/battery.pm b/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/battery.pm index d4e8a6500..48c23c398 100644 --- a/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/battery.pm +++ b/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/battery.pm @@ -69,7 +69,7 @@ sub custom_charge_remaining_perfdata { my ($self, %options) = @_; $self->{output}->perfdata_add( - nlabel => 'battery.charge.remaining.' . ($self->{result_values}->{charge_remaining_unit_absolute} eq '%' ? '%' : 'amperehour'), + nlabel => 'battery.charge.remaining.' . ($self->{result_values}->{charge_remaining_unit_absolute} eq '%' ? 'percentage' : 'amperehour'), unit => $self->{result_values}->{charge_remaining_unit_absolute}, value => $self->{result_values}->{charge_remaining_absolute}, warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), From c600912f855632f558e4c4c4591687cd665f2a5a Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Thu, 30 Apr 2020 14:55:40 +0200 Subject: [PATCH 141/190] Fix UDP ping --- centreon-plugins/apps/protocols/snmp/mode/responsetime.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/apps/protocols/snmp/mode/responsetime.pm b/centreon-plugins/apps/protocols/snmp/mode/responsetime.pm index e2b65393a..c1a70cdda 100644 --- a/centreon-plugins/apps/protocols/snmp/mode/responsetime.pm +++ b/centreon-plugins/apps/protocols/snmp/mode/responsetime.pm @@ -127,7 +127,7 @@ sub manage_selection { } $self->{global} = { - rta => $total_time_elapsed * 1000 / $self->{option_packets}, + rta => $total_time_elapsed * 1000 / ($self->{option_packets} - $total_packet_lost), rtmax => $max_time_elapsed * 1000, rtmin => $min_time_elapsed * 1000, pl => int($total_packet_lost * 100 / $self->{option_packets}), From 40004648af5849e042f0370d78cc59ee7ee59ed8 Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Thu, 30 Apr 2020 15:03:13 +0200 Subject: [PATCH 142/190] fix division by 0 --- centreon-plugins/apps/protocols/snmp/mode/responsetime.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/apps/protocols/snmp/mode/responsetime.pm b/centreon-plugins/apps/protocols/snmp/mode/responsetime.pm index c1a70cdda..851394377 100644 --- a/centreon-plugins/apps/protocols/snmp/mode/responsetime.pm +++ b/centreon-plugins/apps/protocols/snmp/mode/responsetime.pm @@ -127,7 +127,7 @@ sub manage_selection { } $self->{global} = { - rta => $total_time_elapsed * 1000 / ($self->{option_packets} - $total_packet_lost), + rta => ($self->{option_packets} > $total_packet_lost) ? $total_time_elapsed * 1000 / ($self->{option_packets} - $total_packet_lost) : 0, rtmax => $max_time_elapsed * 1000, rtmin => $min_time_elapsed * 1000, pl => int($total_packet_lost * 100 / $self->{option_packets}), From 24773f7da0dff34018f98a9bc21f2a659572a956 Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Thu, 30 Apr 2020 15:48:11 +0200 Subject: [PATCH 143/190] fix snmp discovery desc --- centreon-plugins/os/linux/local/mode/discoverysnmp.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/centreon-plugins/os/linux/local/mode/discoverysnmp.pm b/centreon-plugins/os/linux/local/mode/discoverysnmp.pm index 65432577f..eb0b4786b 100644 --- a/centreon-plugins/os/linux/local/mode/discoverysnmp.pm +++ b/centreon-plugins/os/linux/local/mode/discoverysnmp.pm @@ -84,6 +84,7 @@ my $lookup_type = [ { type => 'stonesoft', re => qr/Forcepoint/i }, { type => 'redback', re => qr/Redback/i }, { type => 'palo alto', re => qr/Palo Alto/i }, + { type => 'hp procurve', re => qr/HP.*Switch/i }, { type => 'hp procurve', re => qr/HP ProCurve/i }, { type => 'hp standard', re => qr/HPE Comware/i }, { type => 'hp msl', re => qr/HP MSL/i }, @@ -152,6 +153,7 @@ sub run { my %host; $host{type} = $self->define_type(desc => $result->{$self->{oid_sysDescr}}); $host{desc} = $result->{$self->{oid_sysDescr}}; + $edge{desc} =~ s/\n/ /g if (defined($edge{desc})); $host{ip} = $ip->addr; $host{hostname} = $result->{$self->{oid_sysName}}; $host{snmp_version} = $last_version; From ce05234da71f66de6b1f0271dfae19e9ed324728 Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Thu, 30 Apr 2020 15:49:18 +0200 Subject: [PATCH 144/190] fix snmp discovery desc --- centreon-plugins/os/linux/local/mode/discoverysnmp.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/os/linux/local/mode/discoverysnmp.pm b/centreon-plugins/os/linux/local/mode/discoverysnmp.pm index eb0b4786b..ca661460b 100644 --- a/centreon-plugins/os/linux/local/mode/discoverysnmp.pm +++ b/centreon-plugins/os/linux/local/mode/discoverysnmp.pm @@ -153,7 +153,7 @@ sub run { my %host; $host{type} = $self->define_type(desc => $result->{$self->{oid_sysDescr}}); $host{desc} = $result->{$self->{oid_sysDescr}}; - $edge{desc} =~ s/\n/ /g if (defined($edge{desc})); + $host{desc} =~ s/\n/ /g if (defined($host{desc})); $host{ip} = $ip->addr; $host{hostname} = $result->{$self->{oid_sysName}}; $host{snmp_version} = $last_version; From 1ed4bcd8d6fa2375c1cbb3ce3a4f2f4c8bb8b090 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 30 Apr 2020 17:54:36 +0200 Subject: [PATCH 145/190] fix thresholds --- .../network/alcatel/oxe/snmp/mode/pbxrole.pm | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/centreon-plugins/network/alcatel/oxe/snmp/mode/pbxrole.pm b/centreon-plugins/network/alcatel/oxe/snmp/mode/pbxrole.pm index d6183c091..e08ae2de0 100644 --- a/centreon-plugins/network/alcatel/oxe/snmp/mode/pbxrole.pm +++ b/centreon-plugins/network/alcatel/oxe/snmp/mode/pbxrole.pm @@ -30,9 +30,9 @@ my $thresholds = { ['indeterminate', 'UNKNOWN'], ['main', 'OK'], ['stand-by', 'OK'], - ['active-pcs', 'CRITICAL'], ['inactive-pcs', 'CRITICAL'], - ], + ['active-pcs', 'CRITICAL'] + ] }; my %map_role = ( 0 => 'indeterminate', @@ -46,11 +46,11 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "threshold-overload:s@" => { name => 'threshold_overload' }, - }); + + $options{options}->add_options(arguments => { + 'threshold-overload:s@' => { name => 'threshold_overload' }, + }); + return $self; } @@ -82,12 +82,12 @@ sub run { my $oid_pbxRole = '.1.3.6.1.4.1.637.64.4400.1.4.0'; my $oid_pbxRole_buggy = '.1.3.6.1.4.1.637.64.4400.1.4'; my $result = $self->{snmp}->get_leef(oids => [$oid_pbxRole, $oid_pbxRole_buggy], nothing_quit => 1); - + my $pbx_role = defined($result->{$oid_pbxRole}) ? $map_role{$result->{$oid_pbxRole}} : $map_role{$result->{$oid_pbxRole_buggy}}; my $exit = $self->get_severity(section => 'role', value => $pbx_role); $self->{output}->output_add(severity => $exit, short_msg => sprintf("PBX Role is '%s'", $pbx_role)); - + $self->{output}->display(); $self->{output}->exit(); } @@ -95,7 +95,7 @@ sub run { sub get_severity { my ($self, %options) = @_; my $status = 'UNKNOWN'; # default - + if (defined($self->{overload_th}->{$options{section}})) { foreach (@{$self->{overload_th}->{$options{section}}}) { if ($options{value} =~ /$_->{filter}/i) { From a3ebe2cb2d6d54639ad6743ed0924312b77bee2a Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 30 Apr 2020 17:55:29 +0200 Subject: [PATCH 146/190] fix thresholds --- centreon-plugins/network/alcatel/oxe/snmp/mode/pbxrole.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/network/alcatel/oxe/snmp/mode/pbxrole.pm b/centreon-plugins/network/alcatel/oxe/snmp/mode/pbxrole.pm index e08ae2de0..0a72e677e 100644 --- a/centreon-plugins/network/alcatel/oxe/snmp/mode/pbxrole.pm +++ b/centreon-plugins/network/alcatel/oxe/snmp/mode/pbxrole.pm @@ -31,7 +31,7 @@ my $thresholds = { ['main', 'OK'], ['stand-by', 'OK'], ['inactive-pcs', 'CRITICAL'], - ['active-pcs', 'CRITICAL'] + ['active-pcs', 'WARNING'] ] }; my %map_role = ( From a57692525b65e325ef420f6a09b53dd18dc5828b Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 30 Apr 2020 17:58:09 +0200 Subject: [PATCH 147/190] fix thresholds alcatel oxe --- centreon-plugins/network/alcatel/oxe/snmp/mode/pbxrole.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/network/alcatel/oxe/snmp/mode/pbxrole.pm b/centreon-plugins/network/alcatel/oxe/snmp/mode/pbxrole.pm index 0a72e677e..e3a8790c4 100644 --- a/centreon-plugins/network/alcatel/oxe/snmp/mode/pbxrole.pm +++ b/centreon-plugins/network/alcatel/oxe/snmp/mode/pbxrole.pm @@ -30,7 +30,7 @@ my $thresholds = { ['indeterminate', 'UNKNOWN'], ['main', 'OK'], ['stand-by', 'OK'], - ['inactive-pcs', 'CRITICAL'], + ['inactive-pcs', 'OK'], ['active-pcs', 'WARNING'] ] }; From c1f26436901c8543846bd41f913abbd50c2d5ff7 Mon Sep 17 00:00:00 2001 From: Simon Bomm Date: Fri, 1 May 2020 18:00:24 +0200 Subject: [PATCH 148/190] enh(plugin)add ec2 spot fleet discovery (#1966) Co-authored-by: Thibault S <48209914+thibaults-centreon@users.noreply.github.com> --- centreon-plugins/cloud/aws/custom/awscli.pm | 29 +++++ centreon-plugins/cloud/aws/custom/paws.pm | 25 ++++ .../ec2/mode/discoveryspotfleetrequests.pm | 117 ++++++++++++++++++ .../aws/ec2/mode/listspotfleetrequests.pm | 96 ++++++++++++++ centreon-plugins/cloud/aws/ec2/plugin.pm | 24 ++-- 5 files changed, 280 insertions(+), 11 deletions(-) create mode 100644 centreon-plugins/cloud/aws/ec2/mode/discoveryspotfleetrequests.pm create mode 100644 centreon-plugins/cloud/aws/ec2/mode/listspotfleetrequests.pm diff --git a/centreon-plugins/cloud/aws/custom/awscli.pm b/centreon-plugins/cloud/aws/custom/awscli.pm index 36510b5d2..7c920e8fe 100644 --- a/centreon-plugins/cloud/aws/custom/awscli.pm +++ b/centreon-plugins/cloud/aws/custom/awscli.pm @@ -399,6 +399,35 @@ sub ec2spot_get_active_instances_status { return $instance_results; } +sub ec2spot_list_fleet_requests_set_cmd { + my ($self, %options) = @_; + + return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); + + my $cmd_options = "ec2 describe-spot-fleet-requests --no-dry-run --region $options{region} --output json"; + $cmd_options .= " --endpoint-url $self->{endpoint_url}" if (defined($self->{endpoint_url}) && $self->{endpoint_url} ne ''); + + return $cmd_options; +} + +sub ec2spot_list_fleet_requests { + my ($self, %options) = @_; + + my $cmd_options = $self->ec2spot_list_fleet_requests_set_cmd(%options); + my $raw_results = $self->execute(cmd_options => $cmd_options); + + my $resource_results = []; + foreach my $fleet_request (@{$raw_results->{SpotFleetRequestConfigs}}) { + push @{$resource_results}, { + SpotFleetRequestState => $fleet_request->{SpotFleetRequestState}, + SpotFleetRequestId => $fleet_request->{SpotFleetRequestId}, + ActivityStatus => $fleet_request->{ActivityStatus} + }; + } + + return $resource_results; +} + sub ec2_list_resources_set_cmd { my ($self, %options) = @_; diff --git a/centreon-plugins/cloud/aws/custom/paws.pm b/centreon-plugins/cloud/aws/custom/paws.pm index a1cab9d9e..06fcc5f29 100644 --- a/centreon-plugins/cloud/aws/custom/paws.pm +++ b/centreon-plugins/cloud/aws/custom/paws.pm @@ -336,6 +336,31 @@ sub ec2spot_get_active_instances { return $instance_results; } +sub ec2spot_list_fleet_requests { + my ($self, %options) = @_; + + my $resource_results = []; + eval { + my $lwp_caller = new Paws::Net::LWPCaller(); + my $ec2spot = Paws->service('EC2', caller => $lwp_caller, region => $options{region}); + my $spot_fleet_requests = $ec2spot->DescribeSpotFleetRequests(DryRun => 0); + + foreach (@{$spot_fleet_requests->{SpotFleetRequestConfigs}}) { + push @{$resource_results}, { + SpotFleetRequestState => $_->{SpotFleetRequestState}, + SpotFleetRequestId => $_->{SpotFleetRequestId}, + ActivityStatus => $_->{ActivityStatus} + }; + } + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "error: $@"); + $self->{output}->option_exit(); + } + + return $resource_results; +} + sub ec2_list_resources { my ($self, %options) = @_; diff --git a/centreon-plugins/cloud/aws/ec2/mode/discoveryspotfleetrequests.pm b/centreon-plugins/cloud/aws/ec2/mode/discoveryspotfleetrequests.pm new file mode 100644 index 000000000..64eeaf6f7 --- /dev/null +++ b/centreon-plugins/cloud/aws/ec2/mode/discoveryspotfleetrequests.pm @@ -0,0 +1,117 @@ +# +# 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 cloud::aws::ec2::mode::discoveryspotfleetrequests; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + "prettify" => { name => 'prettify' }, + "filter-state:s" => { name => 'filter_state' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + + my @disco_data; + my $disco_stats; + + $disco_stats->{start_time} = time(); + + my %asgs; + + my $spot_fleet_requests = $options{custom}->discovery( + region => $self->{option_results}->{region}, + service => 'ec2', + command => 'describe-spot-fleet-requests' + + ); + + foreach my $fleet_request (@{$spot_fleet_requests->{SpotFleetRequestConfigs}}) { + my %sfr; + $sfr{state} = $fleet_request->{SpotFleetRequestState}; + $sfr{id} = $fleet_request->{SpotFleetRequestId}; + $sfr{activity_status} = $fleet_request->{ActivityStatus}; + + push @disco_data, \%sfr unless (defined($self->{option_results}->{filter_state}) + && $sfr{state} !~ /$self->{option_results}->{filter_state}/); + } + + $disco_stats->{end_time} = time(); + $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; + $disco_stats->{discovered_items} = @disco_data; + $disco_stats->{results} = \@disco_data; + + my $encoded_data; + eval { + if (defined($self->{option_results}->{prettify})) { + $encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats); + } else { + $encoded_data = JSON::XS->new->utf8->encode($disco_stats); + } + }; + if ($@) { + $encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; + } + + $self->{output}->output_add(short_msg => $encoded_data); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +EC2 Spot Fleet Requests discovery. + + +=over 8 + +=item B<--filter-state> + +Filter on Spot Fleet Request state. + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/ec2/mode/listspotfleetrequests.pm b/centreon-plugins/cloud/aws/ec2/mode/listspotfleetrequests.pm new file mode 100644 index 000000000..340dc0bd9 --- /dev/null +++ b/centreon-plugins/cloud/aws/ec2/mode/listspotfleetrequests.pm @@ -0,0 +1,96 @@ +# +# 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 cloud::aws::ec2::mode::listspotfleetrequests; + +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) = @_; + + $self->{spot_fleet_requests} = $options{custom}->ec2spot_list_fleet_requests(region => $self->{option_results}->{region}); +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach (@{$self->{spot_fleet_requests}}) { + $self->{output}->output_add( + long_msg => sprintf("[id = %s][state = %s][status = %s]", + $_->{SpotFleetRequestId}, $_->{SpotFleetRequestState}, $_->{ActivityStatus})); + } + + $self->{output}->output_add(severity => 'OK', + short_msg => 'List spot fleet requests:'); + $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 => ['id', 'state', 'status']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach (@{$self->{spot_fleet_requests}}) { + $self->{output}->add_disco_entry( + id => $_->{SpotFleetRequestId}, + state => $_->{SpotFleetRequestState}, + status => $_->{ActivityStatus} + ); + } +} + +1; + +__END__ + +=head1 MODE + +List EC2 Spot Fleet Requests + +=over 8 + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/ec2/plugin.pm b/centreon-plugins/cloud/aws/ec2/plugin.pm index a359235ba..42d7cab05 100644 --- a/centreon-plugins/cloud/aws/ec2/plugin.pm +++ b/centreon-plugins/cloud/aws/ec2/plugin.pm @@ -31,17 +31,19 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( - 'asg-status' => 'cloud::aws::ec2::mode::asgstatus', - 'cpu' => 'cloud::aws::ec2::mode::cpu', - 'discovery' => 'cloud::aws::ec2::mode::discovery', - 'diskio' => 'cloud::aws::ec2::mode::diskio', - 'instances-status' => 'cloud::aws::ec2::mode::instancesstatus', - 'instances-types' => 'cloud::aws::ec2::mode::instancestypes', - 'list-asg' => 'cloud::aws::ec2::mode::listasg', - 'list-instances' => 'cloud::aws::ec2::mode::listinstances', - 'network' => 'cloud::aws::ec2::mode::network', - 'status' => 'cloud::aws::ec2::mode::status', - 'spot-active-instances' => 'cloud::aws::ec2::mode::spotactiveinstances' + 'asg-status' => 'cloud::aws::ec2::mode::asgstatus', + 'cpu' => 'cloud::aws::ec2::mode::cpu', + 'discovery' => 'cloud::aws::ec2::mode::discovery', + 'discovery-fleet-requests' => 'cloud::aws::ec2::mode::discoveryspotfleetrequests', + 'diskio' => 'cloud::aws::ec2::mode::diskio', + 'instances-status' => 'cloud::aws::ec2::mode::instancesstatus', + 'instances-types' => 'cloud::aws::ec2::mode::instancestypes', + 'list-asg' => 'cloud::aws::ec2::mode::listasg', + 'list-instances' => 'cloud::aws::ec2::mode::listinstances', + 'list-spot-fleet-requests' => 'cloud::aws::ec2::mode::listspotfleetrequests', + 'network' => 'cloud::aws::ec2::mode::network', + 'status' => 'cloud::aws::ec2::mode::status', + 'spot-active-instances' => 'cloud::aws::ec2::mode::spotactiveinstances' ); $self->{custom_modes}{paws} = 'cloud::aws::custom::paws'; From 9b32edb750d594f011a7b00b25d71f6856629bb6 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Sat, 2 May 2020 13:33:39 +0200 Subject: [PATCH 149/190] enh(plugin)add TargetGroup dimension elbv2 resolves #1968 --- .../cloud/aws/elb/application/mode/connections.pm | 5 +++++ centreon-plugins/cloud/aws/elb/application/mode/httpcodes.pm | 5 +++++ .../cloud/aws/elb/application/mode/targetshealth.pm | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/centreon-plugins/cloud/aws/elb/application/mode/connections.pm b/centreon-plugins/cloud/aws/elb/application/mode/connections.pm index e47d4ac8c..5b06a1705 100644 --- a/centreon-plugins/cloud/aws/elb/application/mode/connections.pm +++ b/centreon-plugins/cloud/aws/elb/application/mode/connections.pm @@ -115,6 +115,7 @@ sub new { "availability-zone:s" => { name => 'availability_zone' }, "filter-metric:s" => { name => 'filter_metric' }, "statistic:s@" => { name => 'statistic' }, + "target-group:s" => { name => 'target_group' } }); return $self; @@ -138,6 +139,10 @@ sub check_options { $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600; $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; + if (defined($self->{option_results}->{target_group}) && self->{option_results}->{target_group} ne '') { + push @{$self->{aws_dimensions}}, { Name => 'TargetGroup', Value => $self->{option_results}->{target_group} }; + } + $self->{aws_statistics} = ['Sum']; if (defined($self->{option_results}->{statistic})) { $self->{aws_statistics} = []; diff --git a/centreon-plugins/cloud/aws/elb/application/mode/httpcodes.pm b/centreon-plugins/cloud/aws/elb/application/mode/httpcodes.pm index 6ff8c5a45..6e0938fa8 100644 --- a/centreon-plugins/cloud/aws/elb/application/mode/httpcodes.pm +++ b/centreon-plugins/cloud/aws/elb/application/mode/httpcodes.pm @@ -129,6 +129,7 @@ sub new { "name:s@" => { name => 'name' }, "availability-zone:s" => { name => 'availability_zone' }, "filter-metric:s" => { name => 'filter_metric' }, + "target-group:s" => { name => 'target_group' } }); return $self; @@ -152,6 +153,10 @@ sub check_options { $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600; $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; + if (defined($self->{option_results}->{target_group}) && self->{option_results}->{target_group} ne '') { + push @{$self->{aws_dimensions}}, { Name => 'TargetGroup', Value => $self->{option_results}->{target_group} }; + } + $self->{aws_statistics} = ['Sum']; if (defined($self->{option_results}->{statistic})) { $self->{aws_statistics} = []; diff --git a/centreon-plugins/cloud/aws/elb/application/mode/targetshealth.pm b/centreon-plugins/cloud/aws/elb/application/mode/targetshealth.pm index e15525ae7..8ef5142f5 100644 --- a/centreon-plugins/cloud/aws/elb/application/mode/targetshealth.pm +++ b/centreon-plugins/cloud/aws/elb/application/mode/targetshealth.pm @@ -105,6 +105,7 @@ sub new { "availability-zone:s" => { name => 'availability_zone' }, "filter-metric:s" => { name => 'filter_metric' }, "statistic:s@" => { name => 'statistic' }, + "target-group:s" => { name => 'target_group' } }); return $self; @@ -128,6 +129,10 @@ sub check_options { $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600; $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; + if (defined($self->{option_results}->{target_group}) && self->{option_results}->{target_group} ne '') { + push @{$self->{aws_dimensions}}, { Name => 'TargetGroup', Value => $self->{option_results}->{target_group} }; + } + $self->{aws_statistics} = ['Average']; if (defined($self->{option_results}->{statistic})) { $self->{aws_statistics} = []; From 9c9644b8e8f9aa1b5ff49c0cdb3cce3dcdafcda7 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Sat, 2 May 2020 13:38:39 +0200 Subject: [PATCH 150/190] fix(plugin) missing $ previous commit --- centreon-plugins/cloud/aws/elb/application/mode/connections.pm | 2 +- centreon-plugins/cloud/aws/elb/application/mode/httpcodes.pm | 2 +- .../cloud/aws/elb/application/mode/targetshealth.pm | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/centreon-plugins/cloud/aws/elb/application/mode/connections.pm b/centreon-plugins/cloud/aws/elb/application/mode/connections.pm index 5b06a1705..903837b04 100644 --- a/centreon-plugins/cloud/aws/elb/application/mode/connections.pm +++ b/centreon-plugins/cloud/aws/elb/application/mode/connections.pm @@ -139,7 +139,7 @@ sub check_options { $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600; $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; - if (defined($self->{option_results}->{target_group}) && self->{option_results}->{target_group} ne '') { + if (defined($self->{option_results}->{target_group}) && $self->{option_results}->{target_group} ne '') { push @{$self->{aws_dimensions}}, { Name => 'TargetGroup', Value => $self->{option_results}->{target_group} }; } diff --git a/centreon-plugins/cloud/aws/elb/application/mode/httpcodes.pm b/centreon-plugins/cloud/aws/elb/application/mode/httpcodes.pm index 6e0938fa8..5838b084b 100644 --- a/centreon-plugins/cloud/aws/elb/application/mode/httpcodes.pm +++ b/centreon-plugins/cloud/aws/elb/application/mode/httpcodes.pm @@ -153,7 +153,7 @@ sub check_options { $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600; $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; - if (defined($self->{option_results}->{target_group}) && self->{option_results}->{target_group} ne '') { + if (defined($self->{option_results}->{target_group}) && $self->{option_results}->{target_group} ne '') { push @{$self->{aws_dimensions}}, { Name => 'TargetGroup', Value => $self->{option_results}->{target_group} }; } diff --git a/centreon-plugins/cloud/aws/elb/application/mode/targetshealth.pm b/centreon-plugins/cloud/aws/elb/application/mode/targetshealth.pm index 8ef5142f5..083139090 100644 --- a/centreon-plugins/cloud/aws/elb/application/mode/targetshealth.pm +++ b/centreon-plugins/cloud/aws/elb/application/mode/targetshealth.pm @@ -129,7 +129,7 @@ sub check_options { $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600; $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; - if (defined($self->{option_results}->{target_group}) && self->{option_results}->{target_group} ne '') { + if (defined($self->{option_results}->{target_group}) && $self->{option_results}->{target_group} ne '') { push @{$self->{aws_dimensions}}, { Name => 'TargetGroup', Value => $self->{option_results}->{target_group} }; } From 3b6140e991873659bbe27421b6d79f535625d50e Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 4 May 2020 09:58:32 +0200 Subject: [PATCH 151/190] Fix #1951 --- .../iomega/snmp/mode/components/disk.pm | 71 +++++++ .../lenovo/iomega/snmp/mode/components/fan.pm | 84 ++++++++ .../iomega/snmp/mode/components/raid.pm | 67 +++++++ .../snmp/mode/components/temperature.pm | 84 ++++++++ .../iomega/snmp/mode/components/voltage.pm | 84 ++++++++ .../lenovo/iomega/snmp/mode/hardware.pm | 117 +++++++++++ .../lenovo/iomega/snmp/mode/interfaces.pm | 187 ++++++++++++++++++ .../storage/lenovo/iomega/snmp/mode/memory.pm | 184 +++++++++++++++++ .../storage/lenovo/iomega/snmp/plugin.pm | 53 +++++ 9 files changed, 931 insertions(+) create mode 100644 centreon-plugins/storage/lenovo/iomega/snmp/mode/components/disk.pm create mode 100644 centreon-plugins/storage/lenovo/iomega/snmp/mode/components/fan.pm create mode 100644 centreon-plugins/storage/lenovo/iomega/snmp/mode/components/raid.pm create mode 100644 centreon-plugins/storage/lenovo/iomega/snmp/mode/components/temperature.pm create mode 100644 centreon-plugins/storage/lenovo/iomega/snmp/mode/components/voltage.pm create mode 100644 centreon-plugins/storage/lenovo/iomega/snmp/mode/hardware.pm create mode 100644 centreon-plugins/storage/lenovo/iomega/snmp/mode/interfaces.pm create mode 100644 centreon-plugins/storage/lenovo/iomega/snmp/mode/memory.pm create mode 100644 centreon-plugins/storage/lenovo/iomega/snmp/plugin.pm diff --git a/centreon-plugins/storage/lenovo/iomega/snmp/mode/components/disk.pm b/centreon-plugins/storage/lenovo/iomega/snmp/mode/components/disk.pm new file mode 100644 index 000000000..59455a96d --- /dev/null +++ b/centreon-plugins/storage/lenovo/iomega/snmp/mode/components/disk.pm @@ -0,0 +1,71 @@ +# +# 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 storage::lenovo::iomega::snmp::mode::components::disk; + +use strict; +use warnings; + +my $mapping = { + diskID => { oid => '.1.3.6.1.4.1.11369.10.4.3.1.2' }, + diskStatus => { oid => '.1.3.6.1.4.1.11369.10.4.3.1.4' }, +}; +my $oid_diskEntry = '.1.3.6.1.4.1.11369.10.4.3.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_diskEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking disks'); + $self->{components}->{disk} = { name => 'disks', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'disk')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $oid_diskEntry }})) { + next if ($oid !~ /^$mapping->{diskID}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $oid_diskEntry }, instance => $instance); + + next if ($self->check_filter(section => 'disk', instance => $instance)); + + $self->{components}->{disk}->{total}++; + $self->{output}->output_add( + long_msg => sprintf( + "disk '%s' status is '%s' [instance = %s]", + $result->{diskID}, $result->{diskStatus}, $instance + ) + ); + my $exit = $self->get_severity(section => 'disk', value => $result->{diskStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Disk '%s' status is '%s'", $result->{diskID}, $result->{diskStatus} + ) + ); + } + } +} + +1; diff --git a/centreon-plugins/storage/lenovo/iomega/snmp/mode/components/fan.pm b/centreon-plugins/storage/lenovo/iomega/snmp/mode/components/fan.pm new file mode 100644 index 000000000..6775f811d --- /dev/null +++ b/centreon-plugins/storage/lenovo/iomega/snmp/mode/components/fan.pm @@ -0,0 +1,84 @@ +# +# 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 storage::lenovo::iomega::snmp::mode::components::fan; + +use strict; +use warnings; + +my $mapping = { + fanName => { oid => '.1.3.6.1.4.1.11369.10.6.1.1.2' }, + fanValue => { oid => '.1.3.6.1.4.1.11369.10.6.1.1.3' } +}; +my $oid_fanEntry = '.1.3.6.1.4.1.11369.10.6.1.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { + oid => $oid_fanEntry, + start => $mapping->{fanName}->{oid} + }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking fans'); + $self->{components}->{fan} = { name => 'fans', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'fan')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $oid_fanEntry }})) { + next if ($oid !~ /^$mapping->{fanValue}->{oid}\.(.*)$/); + my $instance = $1; + + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $oid_fanEntry }, instance => $instance); + + next if ($self->check_filter(section => 'fan', instance => $instance)); + + $self->{components}->{fan}->{total}++; + $self->{output}->output_add( + long_msg => sprintf( + "fan '%s' speed is '%s' rpm [instance = %s]", + $result->{fanName}, $result->{fanValue}, $instance + ) + ); + + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{fanValue}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "fan '%s' speed is '%s' rpm", $result->{fanName}, $result->{fanValue} + ) + ); + } + $self->{output}->perfdata_add( + nlabel => 'hardware.fan.speed.rpm', + unit => 'rpm', + instances => $result->{fanName}, + value => $result->{fanValue}, + warning => $warn, + critical => $crit, min => 0 + ); + } +} + +1; diff --git a/centreon-plugins/storage/lenovo/iomega/snmp/mode/components/raid.pm b/centreon-plugins/storage/lenovo/iomega/snmp/mode/components/raid.pm new file mode 100644 index 000000000..0b6031253 --- /dev/null +++ b/centreon-plugins/storage/lenovo/iomega/snmp/mode/components/raid.pm @@ -0,0 +1,67 @@ +# +# 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 storage::lenovo::iomega::snmp::mode::components::raid; + +use strict; +use warnings; + +my $mapping = { + raidStatus => { oid => '.1.3.6.1.4.1.11369.10.4.1' } +}; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $mapping->{raidStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking raids'); + $self->{components}->{raid} = { name => 'raids', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'raid')); + + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $mapping->{raidStatus}->{oid} }, instance => '0'); + return if (!defined($result->{raidStatus})); + + my $instance = 1; + next if ($self->check_filter(section => 'raid', instance => $instance)); + $self->{components}->{raid}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "raid '%s' status is '%s' [instance = %s]", + $instance, $result->{raidStatus}, $instance + ) + ); + my $exit = $self->get_severity(section => 'raid', value => $result->{raidStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Raid '%s' status is '%s'", $instance, $result->{raidStatus} + ) + ); + } +} + +1; diff --git a/centreon-plugins/storage/lenovo/iomega/snmp/mode/components/temperature.pm b/centreon-plugins/storage/lenovo/iomega/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..84e2e93b2 --- /dev/null +++ b/centreon-plugins/storage/lenovo/iomega/snmp/mode/components/temperature.pm @@ -0,0 +1,84 @@ +# +# 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 storage::lenovo::iomega::snmp::mode::components::temperature; + +use strict; +use warnings; + +my $mapping = { + tempName => { oid => '.1.3.6.1.4.1.11369.10.6.2.1.2' }, + tempValue => { oid => '.1.3.6.1.4.1.11369.10.6.2.1.3' } +}; +my $oid_tempEntry = '.1.3.6.1.4.1.11369.10.6.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { + oid => $oid_tempEntry, + start => $mapping->{tempName}->{oid} + }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking temperatures'); + $self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'temperature')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $oid_tempEntry }})) { + next if ($oid !~ /^$mapping->{tempValue}->{oid}\.(.*)$/); + my $instance = $1; + + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $oid_tempEntry }, instance => $instance); + + next if ($self->check_filter(section => 'temperature', instance => $instance)); + + $self->{components}->{temperature}->{total}++; + $self->{output}->output_add( + long_msg => sprintf( + "temperature '%s' is '%s' celsius [instance = %s]", + $result->{tempName}, $result->{tempValue}, $instance + ) + ); + + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{tempValue}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "temperature '%s' is '%s' celsius", $result->{tempName}, $result->{tempValue} + ) + ); + } + $self->{output}->perfdata_add( + nlabel => 'hardware.temperature.celsius', + unit => 'C', + instances => $result->{tempName}, + value => $result->{tempValue}, + warning => $warn, + critical => $crit, min => 0 + ); + } +} + +1; diff --git a/centreon-plugins/storage/lenovo/iomega/snmp/mode/components/voltage.pm b/centreon-plugins/storage/lenovo/iomega/snmp/mode/components/voltage.pm new file mode 100644 index 000000000..d0df804a3 --- /dev/null +++ b/centreon-plugins/storage/lenovo/iomega/snmp/mode/components/voltage.pm @@ -0,0 +1,84 @@ +# +# 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 storage::lenovo::iomega::snmp::mode::components::voltage; + +use strict; +use warnings; + +my $mapping = { + voltName => { oid => '.1.3.6.1.4.1.11369.10.6.3.1.2' }, + voltValue => { oid => '.1.3.6.1.4.1.11369.10.6.3.1.3' } +}; +my $oid_voltEntry = '.1.3.6.1.4.1.11369.10.6.3.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { + oid => $oid_voltEntry, + start => $mapping->{voltName}->{oid} + }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking voltages'); + $self->{components}->{voltage} = { name => 'voltages', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'voltage')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $oid_voltEntry }})) { + next if ($oid !~ /^$mapping->{voltValue}->{oid}\.(.*)$/); + my $instance = $1; + + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $oid_voltEntry }, instance => $instance); + + next if ($self->check_filter(section => 'voltage', instance => $instance)); + + $self->{components}->{voltage}->{total}++; + $self->{output}->output_add( + long_msg => sprintf( + "voltage '%s' is '%s' mV [instance = %s]", + $result->{voltName}, $result->{voltValue}, $instance + ) + ); + + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, value => $result->{voltValue}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "voltage '%s' is '%s' mV", $result->{voltName}, $result->{voltValue} + ) + ); + } + $self->{output}->perfdata_add( + nlabel => 'hardware.voltage.millivolt', + unit => 'mV', + instances => $result->{voltName}, + value => $result->{voltValue}, + warning => $warn, + critical => $crit, min => 0 + ); + } +} + +1; diff --git a/centreon-plugins/storage/lenovo/iomega/snmp/mode/hardware.pm b/centreon-plugins/storage/lenovo/iomega/snmp/mode/hardware.pm new file mode 100644 index 000000000..08fbbe626 --- /dev/null +++ b/centreon-plugins/storage/lenovo/iomega/snmp/mode/hardware.pm @@ -0,0 +1,117 @@ +# +# 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 storage::lenovo::iomega::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(?:raid|disk)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(?:temperature|temperature|voltage)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + raid => [ + ['normal', 'OK'], + ['rebuilding', 'OK'], + ['degraded', 'WARNING'], + ['rebuildfs', 'OK'], + ['faulted', 'CRITICAL'] + ], + disk => [ + ['normal', 'OK'], + ['foreign', 'WARNING'], + ['faulted', 'CRITICAL'], + ['missing', 'OK'] + ] + }; + + $self->{components_path} = 'storage::lenovo::iomega::snmp::mode::components'; + $self->{components_module} = ['raid', 'disk', 'voltage', 'temperature', 'fan']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'raid', 'disk', 'voltage', 'temperature', 'fan'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=fan) +Can also exclude specific instance: --filter=fan,1 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='disk,WARNING,missing' + +=item B<--warning> + +Set warning threshold for 'temperature', 'voltage', 'fan' (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,40' + +=item B<--critical> + +Set critical threshold for 'temperature', 'voltage', 'fan' (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,50' + +=back + +=cut diff --git a/centreon-plugins/storage/lenovo/iomega/snmp/mode/interfaces.pm b/centreon-plugins/storage/lenovo/iomega/snmp/mode/interfaces.pm new file mode 100644 index 000000000..f33bf5d60 --- /dev/null +++ b/centreon-plugins/storage/lenovo/iomega/snmp/mode/interfaces.pm @@ -0,0 +1,187 @@ +# +# 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 storage::lenovo::iomega::snmp::mode::interfaces; + +use base qw(snmp_standard::mode::interfaces); + +use strict; +use warnings; + +sub default_oid_filter_name { + my ($self, %options) = @_; + + return 'ifdesc'; +} + +sub default_oid_display_name { + my ($self, %options) = @_; + + return 'ifdesc'; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + return $self; +} + + +1; + +__END__ + +=head1 MODE + +Check interfaces. + +=over 8 + +=item B<--add-global> + +Check global port statistics (By default if no --add-* option is set). + +=item B<--add-status> + +Check interface status. + +=item B<--add-duplex-status> + +Check duplex status (with --warning-status and --critical-status). + +=item B<--add-traffic> + +Check interface traffic. + +=item B<--add-errors> + +Check interface errors. + +=item B<--add-cast> + +Check interface cast. + +=item B<--add-speed> + +Check interface speed. + +=item B<--add-volume> + +Check interface data volume between two checks (not supposed to be graphed, useful for BI reporting). + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{admstatus} eq "up" and %{opstatus} ne "up"'). +Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} + +=item B<--warning-*> + +Threshold warning. +Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', +'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', +'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%), +'speed' (b/s). + +=item B<--critical-*> + +Threshold critical. +Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down', +'in-traffic', 'out-traffic', 'in-error', 'in-discard', 'out-error', 'out-discard', +'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%), +'speed' (b/s). + +=item B<--units-traffic> + +Units of thresholds for the traffic (Default: '%') ('%', 'b/s'). + +=item B<--units-errors> + +Units of thresholds for errors/discards (Default: '%') ('%', 'absolute'). + +=item B<--nagvis-perfdata> + +Display traffic perfdata to be compatible with nagvis widget. + +=item B<--interface> + +Set the interface (number expected) ex: 1,2,... (empty means 'check all interface'). + +=item B<--name> + +Allows to use interface name with option --interface instead of interface oid index (Can be a regexp) + +=item B<--speed> + +Set interface speed for incoming/outgoing traffic (in Mb). + +=item B<--speed-in> + +Set interface speed for incoming traffic (in Mb). + +=item B<--speed-out> + +Set interface speed for outgoing traffic (in Mb). + +=item B<--no-skipped-counters> + +Don't skip counters when no change. + +=item B<--force-counters32> + +Force to use 32 bits counters (even in snmp v2c and v3). Should be used when 64 bits counters are buggy. + +=item B<--reload-cache-time> + +Time in minutes before reloading cache file (default: 180). + +=item B<--oid-filter> + +Choose OID used to filter interface (default: ifDesc) (values: ifDesc, ifAlias, ifName, IpAddr). + +=item B<--oid-display> + +Choose OID used to display interface (default: ifDesc) (values: ifDesc, ifAlias, ifName, IpAddr). + +=item B<--oid-extra-display> + +Add an OID to display. + +=item B<--display-transform-src> + +Regexp src to transform display value. + +=item B<--display-transform-dst> + +Regexp dst to transform display value. + +=item B<--show-cache> + +Display cache interface datas. + +=back + +=cut diff --git a/centreon-plugins/storage/lenovo/iomega/snmp/mode/memory.pm b/centreon-plugins/storage/lenovo/iomega/snmp/mode/memory.pm new file mode 100644 index 000000000..41a997002 --- /dev/null +++ b/centreon-plugins/storage/lenovo/iomega/snmp/mode/memory.pm @@ -0,0 +1,184 @@ +# +# 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 storage::lenovo::iomega::snmp::mode::memory; + +use base qw(snmp_standard::mode::storage); + +use strict; +use warnings; + +sub custom_usage_output { + my ($self, %options) = @_; + + return sprintf( + 'Ram Total: %s %s Used (-buffers/cache): %s %s (%.2f%%) Free: %s %s (%.2f%%)', + $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}), + $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}), + $self->{result_values}->{prct_used_absolute}, + $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}), + $self->{result_values}->{prct_free_absolute} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'ram', type => 0, skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{ram} = [ + { label => 'usage', nlabel => 'memory.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1 } + ] + } + }, + { label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1 } + ] + } + }, + { label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => { + key_values => [ { name => 'prct_used' } ], + output_template => 'Ram Used : %.2f %%', + perfdatas => [ + { value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, + unit => '%' } + ] + } + }, + { label => 'buffer', nlabel => 'memory.buffer.bytes', set => { + key_values => [ { name => 'buffer' } ], + output_template => 'Buffer: %s %s', + output_change_bytes => 1, + perfdatas => [ + { value => 'buffer_absolute', template => '%d', + min => 0, unit => 'B' } + ] + } + }, + { label => 'cached', nlabel => 'memory.cached.bytes', set => { + key_values => [ { name => 'cached' } ], + output_template => 'Cached: %s %s', + output_change_bytes => 1, + perfdatas => [ + { value => 'cached_absolute', template => '%d', + min => 0, unit => 'B' } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + return $self; +} + +my $mapping = { + hrStorageDescr => { oid => '.1.3.6.1.2.1.25.2.3.1.3' }, + hrStorageAllocationUnits => { oid => '.1.3.6.1.2.1.25.2.3.1.4' }, + hrStorageSize => { oid => '.1.3.6.1.2.1.25.2.3.1.5' }, + hrStorageUsed => { oid => '.1.3.6.1.2.1.25.2.3.1.6' } +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_hrstoragetype = '.1.3.6.1.2.1.25.2.3.1.2'; + + my $snmp_result = $options{snmp}->get_table(oid => $oid_hrstoragetype, nothing_quit => 1); + my $storages = []; + foreach (keys %$snmp_result) { + next if ($snmp_result->{$_} !~ /(?:\.1|\.2)$/); + /^$oid_hrstoragetype\.(.*)$/; + push @$storages, $1; + } + + $options{snmp}->load( + oids => [map($_->{oid}, values(%$mapping))], + instances => $storages, + nothing_quit => 1 + ); + $snmp_result = $options{snmp}->get_leef(); + + my ($total, $used, $cached, $buffer); + #.1.3.6.1.2.1.25.2.3.1.3.1 = STRING: Physical memory + #.1.3.6.1.2.1.25.2.3.1.3.2 = STRING: Memory buffers + #.1.3.6.1.2.1.25.2.3.1.3.3 = STRING: Cached memory + foreach (@$storages) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + next if (!defined($result->{hrStorageUsed})); + my $current = $result->{hrStorageUsed} * $result->{hrStorageAllocationUnits}; + next if ($current < 0); + + if ($result->{hrStorageDescr} =~ /Cached\s+memory/i) { + $cached = $current; + } elsif ($result->{hrStorageDescr} =~ /Memory\s+buffers/i) { + $buffer = $current; + } elsif ($result->{hrStorageDescr} =~ /Physical\s+memory/i) { + $used = $current; + $total = $result->{hrStorageSize} * $result->{hrStorageAllocationUnits}; + } + } + + $used -= (defined($cached) ? $cached : 0) - (defined($buffer) ? $buffer : 0); + $self->{ram} = { + total => $total, + cached => $cached, + buffer => $buffer, + used => $used, + free => $total - $used, + prct_used => $used * 100 / $total, + prct_free => 100 - ($used * 100 / $total) + }; +} + +1; + +__END__ + +=head1 MODE + +Check memory. + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%), +'buffer' (B), 'cached' (B). + +=back + +=cut diff --git a/centreon-plugins/storage/lenovo/iomega/snmp/plugin.pm b/centreon-plugins/storage/lenovo/iomega/snmp/plugin.pm new file mode 100644 index 000000000..428dac58c --- /dev/null +++ b/centreon-plugins/storage/lenovo/iomega/snmp/plugin.pm @@ -0,0 +1,53 @@ +# +# 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 storage::lenovo::iomega::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'cpu' => 'snmp_standard::mode::cpu', + 'hardware' => 'storage::lenovo::iomega::snmp::mode::hardware', + 'interfaces' => 'storage::lenovo::iomega::snmp::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'storage::lenovo::iomega::snmp::mode::memory', + 'storage' => 'snmp_standard::mode::storage' + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Lenovo Nas Iomega (ix2) in SNMP. + +=cut From f4e46b2b2e3cedc65790084a265b001ea9b6b209 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 4 May 2020 10:34:20 +0200 Subject: [PATCH 152/190] add ignore permission errors --- .../cloudcontroller/restapi/custom/api.pm | 69 ++++++++++++++----- .../cloudcontroller/restapi/mode/discovery.pm | 22 ++++-- 2 files changed, 69 insertions(+), 22 deletions(-) diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm index 6e866a2f6..ca32a5106 100644 --- a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm @@ -43,12 +43,13 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - 'hostname:s' => { name => 'hostname' }, - 'port:s' => { name => 'port' }, - 'proto:s' => { name => 'proto' }, - 'api-token:s' => { name => 'api_token' }, - 'timeout:s' => { name => 'timeout' }, - 'reload-cache-time:s' => { name => 'reload_cache_time' } + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port' }, + 'proto:s' => { name => 'proto' }, + 'api-token:s' => { name => 'api_token' }, + 'timeout:s' => { name => 'timeout' }, + 'reload-cache-time:s' => { name => 'reload_cache_time' }, + 'ignore-permission-errors' => { name => 'ignore_permission_errors' } }); } $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); @@ -93,6 +94,7 @@ sub check_options { $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; $self->{api_token} = (defined($self->{option_results}->{api_token})) ? $self->{option_results}->{api_token} : ''; $self->{reload_cache_time} = (defined($self->{option_results}->{reload_cache_time})) ? $self->{option_results}->{reload_cache_time} : 180; + $self->{ignore_permission_errors} = (defined($self->{option_results}->{ignore_permission_errors})) ? 1 : 0; if (!defined($self->{hostname}) || $self->{hostname} eq '') { $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); @@ -168,7 +170,10 @@ sub request_api { unknown_status => '(%{http_code} < 200 or %{http_code} >= 300) and %{http_code} != 429' ); - if ($self->{http}->get_code() == 429) { + my $code = $self->{http}->get_code(); + return [] if ($code == 403 && $self->{ignore_permission_errors} == 1); + + if ($code == 429) { sleep(1); continue; } @@ -199,9 +204,17 @@ sub cache_meraki_entities { if ($has_cache_file == 0 || !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{reload_cache_time}) * 60))) { $self->{cache_organizations} = {}; - $self->{cache_organizations} = $self->get_organizations(disable_cache => 1); - $self->{cache_networks} = $self->get_networks(organizations => [keys %{$self->{cache_organizations}}], disable_cache => 1); - $self->{cache_devices} = $self->get_devices(organizations => [keys %{$self->{cache_organizations}}], disable_cache => 1); + $self->{cache_organizations} = $self->get_organizations( + disable_cache => 1 + ); + $self->{cache_networks} = $self->get_networks( + organizations => [keys %{$self->{cache_organizations}}], + disable_cache => 1 + ); + $self->{cache_devices} = $self->get_devices( + organizations => [keys %{$self->{cache_organizations}}], + disable_cache => 1 + ); $self->{cache}->write(data => { last_timestamp => time(), @@ -232,7 +245,9 @@ sub get_networks { my $results = {}; foreach my $id (keys %{$self->{cache_organizations}}) { - my $datas = $self->request_api(endpoint => '/organizations/' . $id . '/networks'); + my $datas = $self->request_api( + endpoint => '/organizations/' . $id . '/networks' + ); $results->{$_->{id}} = $_ foreach (@$datas); } @@ -247,7 +262,9 @@ sub get_devices { my $results = {}; foreach my $id (keys %{$self->{cache_organizations}}) { - my $datas = $self->request_api(endpoint => '/organizations/' . $id . '/devices'); + my $datas = $self->request_api( + endpoint => '/organizations/' . $id . '/devices' + ); $results->{$_->{serial}} = $_ foreach (@$datas); } @@ -316,7 +333,9 @@ sub get_networks_clients { $timespan = 1 if ($timespan <= 0); my $results = {}; foreach my $id (@$network_ids) { - my $datas = $self->request_api(endpoint => '/networks/' . $id . '/clients?timespan=' . $options{timespan}); + my $datas = $self->request_api( + endpoint => '/networks/' . $id . '/clients?timespan=' . $options{timespan}, + ); $results->{$id} = $datas; } @@ -330,7 +349,9 @@ sub get_organization_device_statuses { my $organization_ids = $self->filter_organizations(filter_name => $options{filter_name}); my $results = {}; foreach my $id (@$organization_ids) { - my $datas = $self->request_api(endpoint => '/organizations/' . $id . '/deviceStatuses'); + my $datas = $self->request_api( + endpoint => '/organizations/' . $id . '/deviceStatuses' + ); foreach (@$datas) { $results->{$_->{serial}} = $_; $results->{organizationId} = $id; @@ -350,7 +371,9 @@ sub get_organization_api_requests_overview { my $results = {}; foreach my $id (@$organization_ids) { - $results->{$id} = $self->request_api(endpoint => '/organizations/' . $id . '/apiRequests/overview?timespan=' . $options{timespan}); + $results->{$id} = $self->request_api( + endpoint => '/organizations/' . $id . '/apiRequests/overview?timespan=' . $options{timespan} + ); } return $results; @@ -370,7 +393,9 @@ sub get_network_device_connection_stats { my $results = {}; foreach (keys %{$options{devices}}) { - my $data = $self->request_api(endpoint => '/networks/' . $options{devices}->{$_} . '/devices/' . $_ . '/connectionStats?timespan=' . $options{timespan}); + my $data = $self->request_api( + endpoint => '/networks/' . $options{devices}->{$_} . '/devices/' . $_ . '/connectionStats?timespan=' . $options{timespan} + ); $results->{$_} = $data; } @@ -389,7 +414,9 @@ sub get_network_device_uplink { my $results = {}; foreach (keys %{$options{devices}}) { - my $data = $self->request_api(endpoint => '/networks/' . $options{devices}->{$_} . '/devices/' . $_ . '/uplink'); + my $data = $self->request_api( + endpoint => '/networks/' . $options{devices}->{$_} . '/devices/' . $_ . '/uplink' + ); $results->{$_} = $data; } @@ -410,7 +437,9 @@ sub get_device_clients { my $results = {}; foreach (keys %{$options{devices}}) { - my $data = $self->request_api(endpoint => '/devices/' . $_ . '/clients?timespan=' . $options{timespan}); + my $data = $self->request_api( + endpoint => '/devices/' . $_ . '/clients?timespan=' . $options{timespan} + ); $results->{$_} = $data; } @@ -457,6 +486,10 @@ Set HTTP timeout Time in minutes before reloading cache file (default: 180). +=item B<--ignore-permission-errors> + +Ignore permission errors (403 status code). + =back =head1 DESCRIPTION diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/discovery.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/discovery.pm index 2ceffee3c..fcc3047c3 100644 --- a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/discovery.pm +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/mode/discovery.pm @@ -30,9 +30,9 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { - 'prettify' => { name => 'prettify' }, + 'prettify' => { name => 'prettify' } }); return $self; @@ -50,8 +50,14 @@ sub run { $disco_stats->{start_time} = time(); my $organizations = $options{custom}->get_organizations(disable_cache => 1); - my $networks = $options{custom}->get_networks(organizations => [keys %{$self->{organizations}}], disable_cache => 1); - my $devices = $options{custom}->get_devices(organizations => [keys %{$self->{organizations}}], disable_cache => 1); + my $networks = $options{custom}->get_networks( + organizations => [keys %{$self->{organizations}}], + disable_cache => 1 + ); + my $devices = $options{custom}->get_devices( + organizations => [keys %{$self->{organizations}}], + disable_cache => 1 + ); my $devices_statuses = $options{custom}->get_organization_device_statuses(); $disco_stats->{end_time} = time(); @@ -109,6 +115,14 @@ Resources discovery. =over 8 +=item B<--prettify> + +Prettify JSON output. + +=item B<--ignore-permission-errors> + +Continue the discovery and ignore permission errors (403 status code). + =back =cut From 474f08d3023658f278d46896c3e4cf6ee07621d5 Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Mon, 4 May 2020 15:04:29 +0200 Subject: [PATCH 153/190] Interfaces typo --- centreon-plugins/network/atrica/snmp/mode/connections.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/centreon-plugins/network/atrica/snmp/mode/connections.pm b/centreon-plugins/network/atrica/snmp/mode/connections.pm index acc2972d4..01976643c 100644 --- a/centreon-plugins/network/atrica/snmp/mode/connections.pm +++ b/centreon-plugins/network/atrica/snmp/mode/connections.pm @@ -189,7 +189,7 @@ sub set_counters_errors { my ($self, %options) = @_; push @{$self->{maps_counters}->{int}}, - { label => 'in-eir-discard', filter => 'add_errors', nlabel => 'interface.packets.in.eir.discards.count', set => { + { label => 'in-eir-discard', filter => 'add_errors', nlabel => 'interface.packets.in.eir.discard.count', set => { key_values => [ { name => 'in_eir_discard', diff => 1 }, { name => 'speed_in'}, { name => 'display' } ], per_second => 1, closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in_eir_discard' }, @@ -198,7 +198,7 @@ sub set_counters_errors { closure_custom_threshold_check => $self->can('custom_traffic_threshold'), } }, - { label => 'out-eir-discard', filter => 'add_errors', nlabel => 'interface.packets.out.eir.discards.count', set => { + { label => 'out-eir-discard', filter => 'add_errors', nlabel => 'interface.packets.out.eir.discard.count', set => { key_values => [ { name => 'out_eir_discard', diff => 1 }, { name => 'speed_out'}, { name => 'display' } ], per_second => 1, closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out_eir_discard' }, From 512e1f8320f83c633dcc9cf24c9f1d3dde1fa7c6 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 4 May 2020 15:17:45 +0200 Subject: [PATCH 154/190] fix loop meraki --- .../cisco/meraki/cloudcontroller/restapi/custom/api.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm index ca32a5106..c70f0b2df 100644 --- a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm @@ -162,7 +162,7 @@ sub request_api { #403: Forbidden- You don't have permission to do that. #404: Not found- No such URL, or you don't have access to the API or organization at all. #429: Too Many Requests- You submitted more than 5 calls in 1 second to an Organization, triggering rate limiting. This also applies for API calls made across multiple organizations that triggers rate limiting for one of the organizations. - do { + while (1) { my $response = $self->{http}->request( url_path => '/api/v0' . $options{endpoint}, critical_status => '', @@ -186,8 +186,9 @@ sub request_api { $self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@"); $self->{output}->option_exit(); } + return ($content); - } while (1); + } } sub cache_meraki_entities { From 9c7524a68dfded738fb1b3169ef82528a9cedad1 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 4 May 2020 15:50:05 +0200 Subject: [PATCH 155/190] Fix #1937 --- .../zonedirector/snmp/mode/accesspoints.pm | 333 ++++++++++++++++++ .../snmp/mode/listaccesspoints.pm | 131 +++++++ .../ruckus/zonedirector/snmp/mode/system.pm | 292 +++++++++++++++ .../ruckus/zonedirector/snmp/plugin.pm | 50 +++ 4 files changed, 806 insertions(+) create mode 100644 centreon-plugins/network/ruckus/zonedirector/snmp/mode/accesspoints.pm create mode 100644 centreon-plugins/network/ruckus/zonedirector/snmp/mode/listaccesspoints.pm create mode 100644 centreon-plugins/network/ruckus/zonedirector/snmp/mode/system.pm create mode 100644 centreon-plugins/network/ruckus/zonedirector/snmp/plugin.pm diff --git a/centreon-plugins/network/ruckus/zonedirector/snmp/mode/accesspoints.pm b/centreon-plugins/network/ruckus/zonedirector/snmp/mode/accesspoints.pm new file mode 100644 index 000000000..cff5240fe --- /dev/null +++ b/centreon-plugins/network/ruckus/zonedirector/snmp/mode/accesspoints.pm @@ -0,0 +1,333 @@ +# +# 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 network::ruckus::zonedirector::snmp::mode::accesspoints; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf('zone directory connection status is %s', + $self->{result_values}->{zd_connection_status} + ); +} + +sub ap_long_output { + my ($self, %options) = @_; + + return "checking access point '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_ap_output { + my ($self, %options) = @_; + + return "access point '" . $options{instance_value}->{display} . "' "; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + return sprintf( + 'ram total: %s %s used: %s %s (%.2f%%) free: %s %s (%.2f%%)', + $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}), + $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}), + $self->{result_values}->{prct_used_absolute}, + $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}), + $self->{result_values}->{prct_free_absolute} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'accesspoints', type => 3, cb_prefix_output => 'prefix_ap_output', cb_long_output => 'ap_long_output', + indent_long_output => ' ', message_multiple => 'All access points are ok', + group => [ + { name => 'status', type => 0, skipped_code => { -10 => 1 } }, + { name => 'cpu', type => 0, skipped_code => { -10 => 1 } }, + { name => 'memory', type => 0, skipped_code => { -10 => 1 } }, + { name => 'connection', type => 0, skipped_code => { -10 => 1 } }, + { name => 'traffic', type => 0, skipped_code => { -10 => 1 } } + ] + } + ]; + + $self->{maps_counters}->{status} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'zd_connection_status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + } + ]; + + $self->{maps_counters}->{cpu} = [ + { label => 'cpu-utilization', nlabel => 'accesspoint.cpu.utilization.percentage', set => { + key_values => [ { name => 'cpu_util' }, { name => 'display' } ], + output_template => 'cpu usage: %.2f%%', + perfdatas => [ + { value => 'cpu_util_absolute', template => '%.2f', unit => '%', + min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + } + ]; + + $self->{maps_counters}->{memory} = [ + { label => 'memory-usage', nlabel => 'accesspoint.memory.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + }, + { label => 'usage-free', display_ok => 0, nlabel => 'accesspoint.memory.free.bytes', set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + }, + { label => 'usage-prct', display_ok => 0, nlabel => 'accesspoint.memory.usage.percentage', set => { + key_values => [ { name => 'prct_used' }, { name => 'display' } ], + output_template => 'ram used: %.2f %%', + perfdatas => [ + { value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, + label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + } + ]; + + $self->{maps_counters}->{connection} = [ + { label => 'connection-accesspoints', nlabel => 'accesspoint.connection.accesspoints.count', set => { + key_values => [ { name => 'ap' }, { name => 'display' } ], + output_template => 'access points connections: %d', + perfdatas => [ + { value => 'ap_absolute', template => '%d', min => 0 } + ] + } + }, + { label => 'connection-client-devices-authorized', nlabel => 'accesspoint.connection.client.devices.authorized.count', set => { + key_values => [ { name => 'authorized_clients' }, { name => 'display' } ], + output_template => 'client devices authorized connections: %d', + perfdatas => [ + { value => 'authorized_clients_absolute', template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + }, + { label => 'connection-rogue-devices', nlabel => 'accesspoint.connection.rogue.devices.count', display_ok => 0, set => { + key_values => [ { name => 'rogues' }, { name => 'display' } ], + output_template => 'rogue devices connections: %d', + perfdatas => [ + { value => 'rogues_absolute', template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + } + ]; + + $self->{maps_counters}->{traffic} = [ + { label => 'traffic-in', nlabel => 'accesspoint.traffic.in.bitspersecond', set => { + key_values => [ { name => 'traffic_in', diff => 1 }, { name => 'display' } ], + output_template => 'traffic in: %s%s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_in_per_second', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + }, + { label => 'traffic-out', nlabel => 'accesspoint.traffic.out.bitspersecond', set => { + key_values => [ { name => 'traffic_out', diff => 1 }, { name => 'display' } ], + output_template => 'traffic in: %s%s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_out_per_second', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + } + ]; +} + +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 => '' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); +} + +my $map_zd_connection_status = { + 0 => 'disconnected', 1 => 'connected', 2 => 'approvalPending', 3 => 'upgradingFirmware', 4 => 'provisioning' +}; + +my $mapping = { + zd_connection_status => { oid => '.1.3.6.1.4.1.25053.1.2.2.1.1.2.1.1.3', map => $map_zd_connection_status }, # ruckusZDWLANAPStatus + cpu_util => { oid => '.1.3.6.1.4.1.25053.1.2.2.1.1.2.1.1.29' }, # ruckusZDWLANAPCPUUtil + memory_used => { oid => '.1.3.6.1.4.1.25053.1.2.2.1.1.2.1.1.27' }, # ruckusZDWLANAPMemUtil (% or KB) + memory_size => { oid => '.1.3.6.1.4.1.25053.1.2.2.1.1.2.1.1.28' }, # ruckusZDWLANAPMemTotal (KB) + ap => { oid => '.1.3.6.1.4.1.25053.1.2.2.1.1.2.1.1.14' }, # ruckusZDWLANAPNumVAP + authorized_clients => { oid => '.1.3.6.1.4.1.25053.1.2.2.1.1.2.1.1.15' }, # ruckusZDWLANAPNumSta + rogues => { oid => '.1.3.6.1.4.1.25053.1.2.2.1.1.2.1.1.16' }, # ruckusZDWLANAPNumRogues + traffic_in => { oid => '.1.3.6.1.4.1.25053.1.2.2.1.1.2.1.1.21' }, # ruckusZDWLANAPLANStatsRXByte + traffic_out => { oid => '.1.3.6.1.4.1.25053.1.2.2.1.1.2.1.1.25' } # ruckusZDWLANAPLANStatsTXByte +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_ruckusZDWLANAPDescription = '.1.3.6.1.4.1.25053.1.2.2.1.1.2.1.1.2'; + my $oid_ruckusZDWLANAPSerialNumber = '.1.3.6.1.4.1.25053.1.2.2.1.1.2.1.1.5'; + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_ruckusZDWLANAPDescription }, + { oid => $oid_ruckusZDWLANAPSerialNumber } + ], + return_type => 1, + nothing_quit => 1 + ); + + $self->{accesspoints} = {}; + foreach (keys %$snmp_result) { + next if (! /^$oid_ruckusZDWLANAPDescription\.(.*)/); + my $instance = $1; + my $name = defined($snmp_result->{$_}) && $snmp_result->{$_} ne '' ? + $snmp_result->{$_} : $snmp_result->{$oid_ruckusZDWLANAPSerialNumber . '.' . $instance}; + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping access point '" . $name . "'.", debug => 1); + next; + } + + $self->{accesspoints}->{$instance} = { + display => $name, + status => { display => $name }, + cpu => { display => $name }, + memory => { display => $name }, + connection => { display => $name }, + traffic => { display => $name } + }; + } + + return if (scalar(keys %{$self->{accesspoints}}) <= 0); + + $options{snmp}->load( + oids => [ map($_->{oid}, values(%$mapping)) ], + instances => [ keys %{$self->{accesspoints}} ], + instance_regexp => '^(.*)$' + ); + $snmp_result = $options{snmp}->get_leef(); + foreach (keys %{$self->{accesspoints}}) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + + $self->{accesspoints}->{$_}->{status}->{zd_connection_status} = $result->{zd_connection_status}; + $self->{accesspoints}->{$_}->{cpu}->{cpu_util} = $result->{cpu_util}; + + my $memory_total = $result->{memory_size} * 1024; + my $memory_used = $result->{memory_used} <= 100 ? ($result->{memory_used} * $memory_total / 100) : $result->{memory_used} * 1024; + my $memory_used_prct = $result->{memory_used} <= 100 ? $result->{memory_used} : ($memory_used * 100 / $memory_total); + $self->{accesspoints}->{$_}->{memory}->{used} = $memory_used; + $self->{accesspoints}->{$_}->{memory}->{free} = $memory_total - $memory_used; + $self->{accesspoints}->{$_}->{memory}->{prct_used} = $memory_used_prct; + $self->{accesspoints}->{$_}->{memory}->{prct_free} = 100 - $memory_used_prct; + $self->{accesspoints}->{$_}->{memory}->{total} = $memory_total; + + $self->{accesspoints}->{$_}->{connection}->{ap} = $result->{ap}; + $self->{accesspoints}->{$_}->{connection}->{authorized_clients} = $result->{authorized_clients}; + $self->{accesspoints}->{$_}->{connection}->{rogues} = $result->{rogues}; + + $self->{accesspoints}->{$_}->{traffic}->{traffic_in} = $result->{traffic_in} * 8; + $self->{accesspoints}->{$_}->{traffic}->{traffic_out} = $result->{traffic_out} * 8; + } + + $self->{cache_name} = 'ruckus_zd_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_counters_block}) ? md5_hex($self->{option_results}->{filter_counters_block}) : md5_hex('all')) . '_' . + (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 access points. + +=over 8 + +=item B<--filter-name> + +Filter by access point name (can be a regexp). + +=item B<--unknown-status> + +Set unknown threshold for status. +Can used special variables like: %{zd_connection_status} + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{zd_connection_status} + +=item B<--critical-status> + +Set critical threshold for status. +Can used special variables like: %{zd_connection_status} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'memory-usage', 'usage-free', 'usage-prct', 'traffic-in', 'traffic-out', +'cpu-utilization', 'connection-accesspoints', 'connection-client-devices-authorized', +'connection-rogue-devices'. + +=back + +=cut diff --git a/centreon-plugins/network/ruckus/zonedirector/snmp/mode/listaccesspoints.pm b/centreon-plugins/network/ruckus/zonedirector/snmp/mode/listaccesspoints.pm new file mode 100644 index 000000000..93209a57e --- /dev/null +++ b/centreon-plugins/network/ruckus/zonedirector/snmp/mode/listaccesspoints.pm @@ -0,0 +1,131 @@ +# +# 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 network::ruckus::zonedirector::snmp::mode::listaccesspoints; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my $map_zd_connection_status = { + 0 => 'disconnected', 1 => 'connected', 2 => 'approvalPending', 3 => 'upgradingFirmware', 4 => 'provisioning' +}; + +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); +} + +my $mapping = { + description => { oid => '.1.3.6.1.4.1.25053.1.2.2.1.1.2.1.1.2' }, # ruckusZDWLANAPDescription + zd_connection_status => { oid => '.1.3.6.1.4.1.25053.1.2.2.1.1.2.1.1.3', map => $map_zd_connection_status }, # ruckusZDWLANAPStatus + model => { oid => '.1.3.6.1.4.1.25053.1.2.2.1.1.2.1.1.4' }, # ruckusZDWLANAPModel + serial_number => { oid => '.1.3.6.1.4.1.25053.1.2.2.1.1.2.1.1.5' }, # ruckusZDWLANAPSerialNumber +}; +my $oid_ruckusZDWLANAPEntry = '.1.3.6.1.4.1.25053.1.2.2.1.1.2.1.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_table( + oid => $oid_ruckusZDWLANAPEntry, + start => $mapping->{description}->{oid}, + end => $mapping->{serial_number}->{oid}, + nothing_quit => 1 + ); + + my $accesspoints = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{description}->{oid}\.(.*)$/); + my $instance = $1; + $accesspoints->{$instance} = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + } + + return $accesspoints; +} + +sub run { + my ($self, %options) = @_; + + my $accesspoints = $self->manage_selection(%options); + foreach (sort keys %$accesspoints) { + $self->{output}->output_add( + long_msg => sprintf( + '[description: %s] [serial number: %s] [model: %s] [zonedirector connection status: %s]', + $accesspoints->{$_}->{description}, + $accesspoints->{$_}->{serial_number}, + $accesspoints->{$_}->{model}, + $accesspoints->{$_}->{zd_connection_status} + + ) + ); + } + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List acess points:' + ); + $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 => [keys %$mapping]); +} + +sub disco_show { + my ($self, %options) = @_; + + my $accesspoints = $self->manage_selection(%options); + foreach (sort keys %$accesspoints) { + $self->{output}->add_disco_entry( + %{$accesspoints->{$_}} + ); + } +} + +1; + +__END__ + +=head1 MODE + +List acess points. + +=over 8 + +=back + +=cut + diff --git a/centreon-plugins/network/ruckus/zonedirector/snmp/mode/system.pm b/centreon-plugins/network/ruckus/zonedirector/snmp/mode/system.pm new file mode 100644 index 000000000..54f0886a6 --- /dev/null +++ b/centreon-plugins/network/ruckus/zonedirector/snmp/mode/system.pm @@ -0,0 +1,292 @@ +# +# 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 network::ruckus::zonedirector::snmp::mode::system; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf('system status is %s [peer status: %s]', + $self->{result_values}->{system_status}, + $self->{result_values}->{peer_connected_status} + ); +} + +sub system_long_output { + my ($self, %options) = @_; + + return 'checking system '; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + return sprintf( + 'ram total: %s %s used: %s %s (%.2f%%) free: %s %s (%.2f%%)', + $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}), + $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}), + $self->{result_values}->{prct_used_absolute}, + $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}), + $self->{result_values}->{prct_free_absolute} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'system', type => 3, cb_long_output => 'system_long_output', + indent_long_output => ' ', + group => [ + { name => 'status', type => 0, skipped_code => { -10 => 1 } }, + { name => 'cpu', type => 0, skipped_code => { -10 => 1 } }, + { name => 'memory', type => 0, skipped_code => { -10 => 1 } }, + { name => 'connection', type => 0, skipped_code => { -10 => 1 } }, + { name => 'traffic', type => 0, skipped_code => { -10 => 1 } } + ] + } + ]; + + $self->{maps_counters}->{status} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'system_status' }, { name => 'peer_connected_status' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + } + ]; + + $self->{maps_counters}->{cpu} = [ + { label => 'cpu-utilization', nlabel => 'system.cpu.utilization.percentage', set => { + key_values => [ { name => 'cpu_util' } ], + output_template => 'cpu usage: %.2f%%', + perfdatas => [ + { value => 'cpu_util_absolute', template => '%.2f', unit => '%', min => 0, max => 100 } + ] + } + } + ]; + + $self->{maps_counters}->{memory} = [ + { label => 'memory-usage', nlabel => 'system.memory.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1 } + ] + } + }, + { label => 'usage-free', display_ok => 0, nlabel => 'system.memory.free.bytes', set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1 } + ] + } + }, + { label => 'usage-prct', display_ok => 0, nlabel => 'system.memory.usage.percentage', set => { + key_values => [ { name => 'prct_used' } ], + output_template => 'ram used: %.2f %%', + perfdatas => [ + { value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100 } + ] + } + } + ]; + + $self->{maps_counters}->{connection} = [ + { label => 'connection-accesspoints', nlabel => 'system.connection.accesspoints.count', set => { + key_values => [ { name => 'ap' } ], + output_template => 'access points connections: %d', + perfdatas => [ + { value => 'ap_absolute', template => '%d', min => 0 } + ] + } + }, + { label => 'connection-client-devices-authorized', nlabel => 'system.connection.client.devices.authorized.count', set => { + key_values => [ { name => 'authorized_clients' } ], + output_template => 'client devices authorized connections: %d', + perfdatas => [ + { value => 'authorized_clients_absolute', template => '%d', min => 0 } + ] + } + }, + { label => 'connection-rogue-devices', nlabel => 'system.connection.rogue.devices.count', display_ok => 0, set => { + key_values => [ { name => 'rogues' } ], + output_template => 'rogue devices connections: %d', + perfdatas => [ + { value => 'rogues_absolute', template => '%d', min => 0 } + ] + } + } + ]; + + $self->{maps_counters}->{traffic} = [ + { label => 'traffic-in', nlabel => 'system.traffic.in.bitspersecond', set => { + key_values => [ { name => 'traffic_in', diff => 1 } ], + output_template => 'traffic in: %s%s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_in_per_second', template => '%s', + min => 0, unit => 'b/s' } + ] + } + }, + { label => 'traffic-out', nlabel => 'system.traffic.out.bitspersecond', set => { + key_values => [ { name => 'traffic_out', diff => 1 } ], + output_template => 'traffic in: %s%s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_out_per_second', template => '%s', + min => 0, unit => 'b/s' } + ] + } + } + ]; +} + +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 => { + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); +} + +my $map_system_status = { + 1 => 'master', 2 => 'standby', 3 => 'noredundancy' +}; +my $map_peer_connected_status = { + 1 => 'connected', 2 => 'disconnected' +}; + +my $mapping = { + system_status => { oid => '.1.3.6.1.4.1.25053.1.2.1.1.1.1.30', map => $map_system_status }, # ruckusZDSystemStatus + peer_connected_status => { oid => '.1.3.6.1.4.1.25053.1.2.1.1.1.1.31', map => $map_peer_connected_status }, # ruckusZDSystemPeerConnectedStatus + cpu_util => { oid => '.1.3.6.1.4.1.25053.1.2.1.1.1.5.58' }, # ruckusZDSystemCPUUtil + memory_used_prct => { oid => '.1.3.6.1.4.1.25053.1.2.1.1.1.5.59' }, # ruckusZDSystemMemoryUtil (%) + memory_size => { oid => '.1.3.6.1.4.1.25053.1.2.1.1.1.5.60' }, # ruckusZDSystemMemorySize (MB) + ap => { oid => '.1.3.6.1.4.1.25053.1.2.1.1.1.15.1' }, # ruckusZDSystemStatsNumAP + authorized_clients => { oid => '.1.3.6.1.4.1.25053.1.2.1.1.1.15.2' }, # ruckusZDSystemStatsNumSta + rogues => { oid => '.1.3.6.1.4.1.25053.1.2.1.1.1.15.3' }, # ruckusZDSystemStatsNumRogue + traffic_in => { oid => '.1.3.6.1.4.1.25053.1.2.1.1.1.15.6' }, # ruckusZDSystemStatsWLANTotalRxBytes + traffic_out => { oid => '.1.3.6.1.4.1.25053.1.2.1.1.1.15.9' } # ruckusZDSystemStatsWLANTotalTxBytes +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_leef( + oids => [ map($_->{oid} . '.0', values(%$mapping)) ], + nothing_quit => 1 + ); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => 0); + + my $memory_total = $result->{memory_size} * 1024 * 1024; + my $memory_used = $result->{memory_used_prct} * $memory_total / 100; + + $self->{system}->{global} = { + status => { + system_status => $result->{system_status}, + peer_connected_status => $result->{peer_connected_status} + }, + cpu => { cpu_util => $result->{cpu_util} }, + memory => { + used => $memory_used, + free => $memory_total - $memory_used, + prct_used => $result->{memory_used_prct}, + prct_free => 100 - $result->{memory_used_prct}, + total => $memory_total + }, + connection => { + ap => $result->{ap}, + authorized_clients => $result->{authorized_clients}, + rogues => $result->{rogues} + }, + traffic => { + traffic_in => $result->{traffic_in} * 8, + traffic_out => $result->{traffic_out} * 8 + } + }; + + $self->{cache_name} = 'ruckus_zd_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_counters_block}) ? md5_hex($self->{option_results}->{filter_counters_block}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check system. + +=over 8 + +=item B<--unknown-status> + +Set unknown threshold for status (Default: ''). +Can used special variables like: %{system_status}, %{peer_connected_status} + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{system_status}, %{peer_connected_status} + +=item B<--critical-status> + +Set critical threshold for status. +Can used special variables like: %{system_status}, %{peer_connected_status} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'memory-usage', 'usage-free', 'usage-prct', 'traffic-in', 'traffic-out', +'cpu-utilization', 'connection-accesspoints', 'connection-client-devices-authorized', +'connection-rogue-devices'. + +=back + +=cut diff --git a/centreon-plugins/network/ruckus/zonedirector/snmp/plugin.pm b/centreon-plugins/network/ruckus/zonedirector/snmp/plugin.pm new file mode 100644 index 000000000..fceea76f4 --- /dev/null +++ b/centreon-plugins/network/ruckus/zonedirector/snmp/plugin.pm @@ -0,0 +1,50 @@ +# +# 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 network::ruckus::zonedirector::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.5'; + %{$self->{modes}} = ( + 'access-points' => 'network::ruckus::zonedirector::snmp::mode::accesspoints', + 'list-access-points' => 'network::ruckus::zonedirector::snmp::mode::listaccesspoints', + 'system' => 'network::ruckus::zonedirector::snmp::mode::system' + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Ruckus ZoneDirector in SNMP. + +=cut From 029eedd1c677b0a8a1319433bf6907a9c56b954c Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 4 May 2020 16:20:16 +0200 Subject: [PATCH 156/190] Fix #1979 --- .../common/radlan/mode/components/fan.pm | 74 --------- .../common/radlan/mode/components/psu.pm | 74 --------- .../centreon/common/radlan/mode/cpu.pm | 148 ------------------ .../common/radlan/snmp/mode/components/fan.pm | 111 +++++++++++++ .../common/radlan/snmp/mode/components/psu.pm | 140 +++++++++++++++++ .../radlan/snmp/mode/components/resources.pm | 53 +++++++ .../snmp/mode/components/temperature.pm | 124 +++++++++++++++ .../centreon/common/radlan/snmp/mode/cpu.pm | 120 ++++++++++++++ .../radlan/{ => snmp}/mode/environment.pm | 81 +++++++--- .../network/dell/xseries/snmp/plugin.pm | 52 ++++++ .../snmp_standard/mode/loadaverage.pm | 19 +-- 11 files changed, 668 insertions(+), 328 deletions(-) delete mode 100644 centreon-plugins/centreon/common/radlan/mode/components/fan.pm delete mode 100644 centreon-plugins/centreon/common/radlan/mode/components/psu.pm delete mode 100644 centreon-plugins/centreon/common/radlan/mode/cpu.pm create mode 100644 centreon-plugins/centreon/common/radlan/snmp/mode/components/fan.pm create mode 100644 centreon-plugins/centreon/common/radlan/snmp/mode/components/psu.pm create mode 100644 centreon-plugins/centreon/common/radlan/snmp/mode/components/resources.pm create mode 100644 centreon-plugins/centreon/common/radlan/snmp/mode/components/temperature.pm create mode 100644 centreon-plugins/centreon/common/radlan/snmp/mode/cpu.pm rename centreon-plugins/centreon/common/radlan/{ => snmp}/mode/environment.pm (53%) create mode 100644 centreon-plugins/network/dell/xseries/snmp/plugin.pm diff --git a/centreon-plugins/centreon/common/radlan/mode/components/fan.pm b/centreon-plugins/centreon/common/radlan/mode/components/fan.pm deleted file mode 100644 index 79f793da8..000000000 --- a/centreon-plugins/centreon/common/radlan/mode/components/fan.pm +++ /dev/null @@ -1,74 +0,0 @@ -# -# 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 centreon::common::radlan::mode::components::fan; - -use strict; -use warnings; - -my %map_states = ( - 1 => 'normal', - 2 => 'warning', - 3 => 'critical', - 4 => 'shutdown', - 5 => 'notPresent', - 6 => 'notFunctioning', -); - -my $mapping = { - rlEnvMonFanStatusDescr => { oid => '.1.3.6.1.4.1.89.83.1.1.1.2' }, - rlEnvMonFanState => { oid => '.1.3.6.1.4.1.89.83.1.1.1.3', map => \%map_states }, -}; -my $oid_rlEnvMonFanStatusEntry = '.1.3.6.1.4.1.89.83.1.1.1'; - -sub load { - my ($self) = @_; - - push @{$self->{request}}, { oid => $oid_rlEnvMonFanStatusEntry }; -} - -sub check { - my ($self) = @_; - - $self->{output}->output_add(long_msg => 'checking fans'); - $self->{components}->{fan} = { name => 'fans', total => 0, skip => 0 }; - return if ($self->check_filter(section => 'fan')); - - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonFanStatusEntry}})) { - next if ($oid !~ /^$mapping->{rlEnvMonFanState}->{oid}\.(.*)$/); - my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rlEnvMonFanStatusEntry}, instance => $instance); - - next if ($self->check_filter(section => 'fan', instance => $instance, name => $result->{rlEnvMonFanStatusDescr})); - next if ($result->{rlEnvMonFanState} eq 'notPresent' && - $self->absent_problem(section => 'fan', instance => $instance, name => $result->{rlEnvMonFanStatusDescr})); - - $self->{components}->{fan}->{total}++; - $self->{output}->output_add(long_msg => sprintf("fan '%s' state is %s [instance: %s]", - $result->{rlEnvMonFanStatusDescr}, $result->{rlEnvMonFanState}, $instance)); - my $exit = $self->get_severity(section => 'fan', value => $result->{rlEnvMonFanState}); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Fan '%s' state is %s.", $result->{rlEnvMonFanStatusDescr}, $result->{rlEnvMonFanState})); - } - } -} - -1; diff --git a/centreon-plugins/centreon/common/radlan/mode/components/psu.pm b/centreon-plugins/centreon/common/radlan/mode/components/psu.pm deleted file mode 100644 index a87245b83..000000000 --- a/centreon-plugins/centreon/common/radlan/mode/components/psu.pm +++ /dev/null @@ -1,74 +0,0 @@ -# -# 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 centreon::common::radlan::mode::components::psu; - -use strict; -use warnings; - -my %map_states = ( - 1 => 'normal', - 2 => 'warning', - 3 => 'critical', - 4 => 'shutdown', - 5 => 'notPresent', - 6 => 'notFunctioning', -); - -my $mapping = { - rlEnvMonSupplyStatusDescr => { oid => '.1.3.6.1.4.1.89.83.1.2.1' }, - rlEnvMonSupplyState => { oid => '.1.3.6.1.4.1.89.83.1.2.1.3', map => \%map_states }, -}; -my $oid_rlEnvMonSupplyStatusEntry = '.1.3.6.1.4.1.89.83.1.2.1.2'; - -sub load { - my ($self) = @_; - - push @{$self->{request}}, { oid => $oid_rlEnvMonSupplyStatusEntry }; -} - -sub check { - my ($self) = @_; - - $self->{output}->output_add(long_msg => 'checking power supplies'); - $self->{components}->{psu} = { name => 'psus', total => 0, skip => 0 }; - return if ($self->check_filter(section => 'psu')); - - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonSupplyStatusEntry}})) { - next if ($oid !~ /^$mapping->{rlEnvMonSupplyState}->{oid}\.(.*)$/); - my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rlEnvMonSupplyStatusEntry}, instance => $instance); - - next if ($self->check_filter(section => 'psu', instance => $instance, name => $result->{rlEnvMonSupplyStatusDescr})); - next if ($result->{rlEnvMonSupplyState} eq 'notPresent' && - $self->absent_problem(section => 'psu', instance => $instance, name => $result->{rlEnvMonSupplyStatusDescr})); - - $self->{components}->{psu}->{total}++; - $self->{output}->output_add(long_msg => sprintf("power supply '%s' state is %s [instance: %s]", - $result->{rlEnvMonSupplyStatusDescr}, $result->{rlEnvMonSupplyState}, $instance)); - my $exit = $self->get_severity(section => 'psu', value => $result->{rlEnvMonSupplyState}); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Power supply '%s' state is %s.", $result->{rlEnvMonSupplyStatusDescr}, $result->{rlEnvMonSupplyState})); - } - } -} - -1; diff --git a/centreon-plugins/centreon/common/radlan/mode/cpu.pm b/centreon-plugins/centreon/common/radlan/mode/cpu.pm deleted file mode 100644 index 31ce8840c..000000000 --- a/centreon-plugins/centreon/common/radlan/mode/cpu.pm +++ /dev/null @@ -1,148 +0,0 @@ -# -# 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 centreon::common::radlan::mode::cpu; - -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 => - { - "warning:s" => { name => 'warning', default => '' }, - "critical:s" => { name => 'critical', default => '' }, - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - ($self->{warn1s}, $self->{warn1m}, $self->{warn5m}) = split /,/, $self->{option_results}->{warning}; - ($self->{crit1s}, $self->{crit1m}, $self->{crit5m}) = split /,/, $self->{option_results}->{critical}; - - if (($self->{perfdata}->threshold_validate(label => 'warn1s', value => $self->{warn1s})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning (1sec) threshold '" . $self->{warn1s} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'warn1m', value => $self->{warn1m})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning (1min) threshold '" . $self->{warn1m} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'warn5m', value => $self->{warn5m})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning (5min) threshold '" . $self->{warn5m} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'crit1s', value => $self->{crit1s})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical (1sec) threshold '" . $self->{crit1s} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'crit1m', value => $self->{crit1m})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical (1min) threshold '" . $self->{crit1m} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'crit5m', value => $self->{crit5})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical (5min) threshold '" . $self->{crit5m} . "'."); - $self->{output}->option_exit(); - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - my $oid_rlCpuUtilEnable = '.1.3.6.1.4.1.89.1.6.0'; - my $oid_rlCpuUtilDuringLastSecond = '.1.3.6.1.4.1.89.1.7.0'; - my $oid_rlCpuUtilDuringLastMinute = '.1.3.6.1.4.1.89.1.8.0'; - my $oid_rlCpuUtilDuringLast5Minutes = '.1.3.6.1.4.1.89.1.9.0'; - - $self->{result} = $self->{snmp}->get_leef(oids => [ $oid_rlCpuUtilEnable, $oid_rlCpuUtilDuringLastSecond, $oid_rlCpuUtilDuringLastMinute, $oid_rlCpuUtilDuringLast5Minutes ], - nothing_quit => 1); - - if (defined($self->{result}->{$oid_rlCpuUtilEnable}) && $self->{result}->{$oid_rlCpuUtilEnable} == 1) { - my $cpu1sec = $self->{result}->{$oid_rlCpuUtilDuringLastSecond}; - my $cpu1min = $self->{result}->{$oid_rlCpuUtilDuringLastMinute}; - my $cpu5min = $self->{result}->{$oid_rlCpuUtilDuringLast5Minutes}; - - my $exit1 = $self->{perfdata}->threshold_check(value => $cpu1sec, - threshold => [ { label => 'crit1s', exit_litteral => 'critical' }, { label => 'warn1s', exit_litteral => 'warning' } ]); - my $exit2 = $self->{perfdata}->threshold_check(value => $cpu1min, - threshold => [ { label => 'crit1m', exit_litteral => 'critical' }, { label => 'warn1m', exit_litteral => 'warning' } ]); - my $exit3 = $self->{perfdata}->threshold_check(value => $cpu5min, - threshold => [ { label => 'crit5m', exit_litteral => 'critical' }, { label => 'warn5m', exit_litteral => 'warning' } ]); - my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]); - - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("CPU Usage: %.2f%% (1sec), %.2f%% (1min), %.2f%% (5min)", - $cpu1sec, $cpu1min, $cpu5min)); - - $self->{output}->perfdata_add(label => "cpu_1s", unit => '%', - value => $cpu1sec, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1s'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1s'), - min => 0, max => 100); - $self->{output}->perfdata_add(label => "cpu_1m", unit => '%', - value => $cpu1min, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1m'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1m'), - min => 0, max => 100); - $self->{output}->perfdata_add(label => "cpu_5m", unit => '%', - value => $cpu5min, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5m'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5m'), - min => 0, max => 100); - } else { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => sprintf("CPU measurement is not enabled.")); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check cpu usage (RADLAN-rndMng). - -=over 8 - -=item B<--warning> - -Threshold warning in percent (1s,1min,5min). - -=item B<--critical> - -Threshold critical in percent (1s,1min,5min). - -=back - -=cut \ No newline at end of file diff --git a/centreon-plugins/centreon/common/radlan/snmp/mode/components/fan.pm b/centreon-plugins/centreon/common/radlan/snmp/mode/components/fan.pm new file mode 100644 index 000000000..153ae2448 --- /dev/null +++ b/centreon-plugins/centreon/common/radlan/snmp/mode/components/fan.pm @@ -0,0 +1,111 @@ +# +# 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 centreon::common::radlan::snmp::mode::components::fan; + +use strict; +use warnings; +use centreon::common::cisco::smallbusiness::snmp::mode::components::resources qw( + $rl_envmon_state + $oid_rlPhdUnitEnvParamMonitorAutoRecoveryEnable + $oid_rlPhdUnitEnvParamEntry +); + +my $mapping_stack = { + new => { + rlPhdUnitEnvParamFan1Status => { oid => '.1.3.6.1.4.1.89.53.15.1.4', map => $rl_envmon_state }, + rlPhdUnitEnvParamFan2Status => { oid => '.1.3.6.1.4.1.89.53.15.1.5', map => $rl_envmon_state }, + rlPhdUnitEnvParamFan3Status => { oid => '.1.3.6.1.4.1.89.53.15.1.6', map => $rl_envmon_state }, + rlPhdUnitEnvParamFan4Status => { oid => '.1.3.6.1.4.1.89.53.15.1.7', map => $rl_envmon_state }, + rlPhdUnitEnvParamFan5Status => { oid => '.1.3.6.1.4.1.89.53.15.1.8', map => $rl_envmon_state }, + rlPhdUnitEnvParamFan6Status => { oid => '.1.3.6.1.4.1.89.53.15.1.9', map => $rl_envmon_state } + }, + old => { + rlPhdUnitEnvParamFan1Status => { oid => '.1.3.6.1.4.1.89.53.15.1.4', map => $rl_envmon_state }, + rlPhdUnitEnvParamFan2Status => { oid => '.1.3.6.1.4.1.89.53.15.1.5', map => $rl_envmon_state }, + rlPhdUnitEnvParamFan3Status => { oid => '.1.3.6.1.4.1.89.53.15.1.6', map => $rl_envmon_state }, + rlPhdUnitEnvParamFan4Status => { oid => '.1.3.6.1.4.1.89.53.15.1.7', map => $rl_envmon_state }, + rlPhdUnitEnvParamFan5Status => { oid => '.1.3.6.1.4.1.89.53.15.1.8', map => $rl_envmon_state } + } +}; + +sub load { + my ($self) = @_; +} + +sub check_fan_stack { + my ($self) = @_; + + my $num_fans = 5; + $num_fans = 6 if ($self->{radlan_new} == 1); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlPhdUnitEnvParamEntry}})) { + next if ($oid !~ /^$mapping_stack->{new}->{rlPhdUnitEnvParamFan1Status}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance( + mapping => $self->{radlan_new} == 1 ? $mapping_stack->{new} : $mapping_stack->{old}, + results => $self->{results}->{$oid_rlPhdUnitEnvParamEntry}, + instance => $instance + ); + + for (my $i = 1; $i <= $num_fans; $i++) { + my $instance2 = 'stack.' . $instance . '.fan.' . $i; + my $name = 'rlPhdUnitEnvParamFan' . $i . 'Status'; + + next if ($self->check_filter(section => 'fan', instance => $instance2)); + next if ($result->{$name} =~ /notPresent/i && + $self->absent_problem(section => 'fan', instance => $instance2)); + + $self->{components}->{fan}->{total}++; + $self->{output}->output_add( + long_msg => sprintf( + "fan '%s' status is '%s' [instance: %s]", + $instance2, + $result->{$name}, + $instance2 + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'fan', value => $result->{$name}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Fan '%s' status is '%s'", + $instance2, + $result->{$name} + ) + ); + } + } + } +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking fans"); + $self->{components}->{fan} = { name => 'fan', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'fan')); + + check_fan_stack($self); +} + +1; diff --git a/centreon-plugins/centreon/common/radlan/snmp/mode/components/psu.pm b/centreon-plugins/centreon/common/radlan/snmp/mode/components/psu.pm new file mode 100644 index 000000000..343bc1d8f --- /dev/null +++ b/centreon-plugins/centreon/common/radlan/snmp/mode/components/psu.pm @@ -0,0 +1,140 @@ +# +# 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 centreon::common::radlan::snmp::mode::components::psu; + +use strict; +use warnings; +use centreon::common::radlan::snmp::mode::components::resources qw( + $rl_envmon_state + $oid_rlPhdUnitEnvParamEntry +); + +my $mapping_stack = { + rlPhdUnitEnvParamMainPSStatus => { oid => '.1.3.6.1.4.1.89.53.15.1.2', map => $rl_envmon_state }, + rlPhdUnitEnvParamRedundantPSStatus => { oid => '.1.3.6.1.4.1.89.53.15.1.3', map => $rl_envmon_state } +}; + +my $mapping = { + rlEnvMonSupplyStatusDescr => { oid => '.1.3.6.1.4.1.89.83.1.2.1.2' }, + rlEnvMonSupplyState => { oid => '.1.3.6.1.4.1.89.83.1.2.1.3', map => $rl_envmon_state } +}; +my $oid_rlEnvMonSupplyStatusEntry = '.1.3.6.1.4.1.89.83.1.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { + oid => $oid_rlEnvMonSupplyStatusEntry, + $mapping->{rlEnvMonSupplyStatusDescr}->{oid}, + $mapping->{rlEnvMonSupplyState}->{oid} + }; +} + +sub check_psu_stack { + my ($self) = @_; + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlPhdUnitEnvParamEntry}})) { + next if ($oid !~ /^$mapping_stack->{rlPhdUnitEnvParamMainPSStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping_stack, results => $self->{results}->{$oid_rlPhdUnitEnvParamEntry}, instance => $instance); + + foreach (['rlPhdUnitEnvParamMainPSStatus', 'main.psu'], ['rlPhdUnitEnvParamRedundantPSStatus', 'redundant.psu']) { + my $instance2 = 'stack.' . $instance . '.' . $_->[1]; + + next if ($self->check_filter(section => 'psu', instance => $instance2)); + next if ($result->{$_->[0]} =~ /notPresent/i && + $self->absent_problem(section => 'psu', instance => $instance2)); + + $self->{components}->{psu}->{total}++; + $self->{output}->output_add( + long_msg => sprintf( + "power supply '%s' status is '%s' [instance: %s]", + $instance2, + $result->{$_->[0]}, + $instance2 + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'psu', value => $result->{$_->[0]}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Power supply '%s' status is '%s'", + $instance2, + $result->{$_->[0]} + ) + ); + } + } + } +} + +sub check_psu { + my ($self) = @_; + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlEnvMonSupplyStatusEntry}})) { + next if ($oid !~ /^$mapping->{rlEnvMonSupplyState}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rlEnvMonSupplyStatusEntry}, instance => $instance); + + next if ($self->check_filter(section => 'psu', instance => $instance)); + if ($result->{rlEnvMonSupplyState} =~ /notPresent/i) { + $self->absent_problem(section => 'psu', instance => $instance); + next; + } + + $self->{components}->{psu}->{total}++; + $self->{output}->output_add( + long_msg => sprintf( + "power supply '%s' status is '%s' [instance: %s]", + $result->{rlEnvMonSupplyStatusDescr}, + $result->{rlEnvMonSupplyState}, + $instance + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'psu', value => $result->{rlEnvMonSupplyState}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Power supply '%s' status is '%s'", + $result->{rlEnvMonSupplyStatusDescr}, + $result->{rlEnvMonSupplyState} + ) + ); + } + } +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking power supplies"); + $self->{components}->{psu} = { name => 'psu', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'psu')); + + check_psu($self); + check_psu_stack($self); +} + +1; diff --git a/centreon-plugins/centreon/common/radlan/snmp/mode/components/resources.pm b/centreon-plugins/centreon/common/radlan/snmp/mode/components/resources.pm new file mode 100644 index 000000000..f06752667 --- /dev/null +++ b/centreon-plugins/centreon/common/radlan/snmp/mode/components/resources.pm @@ -0,0 +1,53 @@ +# +# 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 centreon::common::radlan::snmp::mode::components::resources; + +use strict; +use warnings; +use Exporter; + +our $rl_envmon_state; +our $oid_rlPhdUnitEnvParamMonitorAutoRecoveryEnable; +our $oid_rlPhdUnitEnvParamEntry; + +our @ISA = qw(Exporter); +our @EXPORT_OK = qw( + $rl_envmon_state + $oid_rlPhdUnitEnvParamMonitorAutoRecoveryEnable + $oid_rlPhdUnitEnvParamEntry +); + +$rl_envmon_state = { + 1 => 'normal', + 2 => 'warning', + 3 => 'critical', + 4 => 'shutdown', + 5 => 'notPresent', + 6 => 'notFunctioning', + 7 => 'notAvailable', + 8 => 'backingUp', + 9 => 'readingFailed' +}; + +$oid_rlPhdUnitEnvParamMonitorAutoRecoveryEnable = '.1.3.6.1.4.1.89.53.15.1.15'; +$oid_rlPhdUnitEnvParamEntry = '.1.3.6.1.4.1.89.53.15.1'; + +1; diff --git a/centreon-plugins/centreon/common/radlan/snmp/mode/components/temperature.pm b/centreon-plugins/centreon/common/radlan/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..fcc6bfa2f --- /dev/null +++ b/centreon-plugins/centreon/common/radlan/snmp/mode/components/temperature.pm @@ -0,0 +1,124 @@ +# +# 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 centreon::common::radlan::snmp::mode::components::temperature; + +use strict; +use warnings; +use centreon::common::radlan::snmp::mode::components::resources qw($oid_rlPhdUnitEnvParamEntry); + +my $map_entity_sensor = { 1 => 'ok', 2 => 'unavailable', 3 => 'nonoperational' }; + +my $mapping = { + new => { + rlPhdUnitEnvParamTempSensorValue => { oid => '.1.3.6.1.4.1.89.53.15.1.10' }, + rlPhdUnitEnvParamTempSensorStatus => { oid => '.1.3.6.1.4.1.89.53.15.1.11', map => $map_entity_sensor }, + rlPhdUnitEnvParamTempSensorWarningThresholdValue => { oid => '.1.3.6.1.4.1.89.53.15.1.12' }, + rlPhdUnitEnvParamTempSensorCriticalThresholdValue => { oid => '.1.3.6.1.4.1.89.53.15.1.13' } + }, + old => { + rlPhdUnitEnvParamTempSensorValue => { oid => '.1.3.6.1.4.1.89.53.15.1.9' }, + rlPhdUnitEnvParamTempSensorStatus => { oid => '.1.3.6.1.4.1.89.53.15.1.10', map => $map_entity_sensor }, + } +}; + +sub load {} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking temperatures"); + $self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'temperature')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rlPhdUnitEnvParamEntry}})) { + next if ($oid !~ /^$mapping->{new}->{rlPhdUnitEnvParamTempSensorValue}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance( + mapping => $self->{radlan_new} == 1 ? $mapping->{new} : $mapping->{old}, + results => $self->{results}->{$oid_rlPhdUnitEnvParamEntry}, + instance => $instance + ); + + next if ($self->check_filter(section => 'temperature', instance => $instance)); + $self->{components}->{temperature}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "temperature '%s' status is '%s' [instance = %s, value: %s degree centigrade]", + $instance, + $result->{rlPhdUnitEnvParamTempSensorStatus}, + $instance, + $result->{rlPhdUnitEnvParamTempSensorValue} + ) + ); + + my $exit = $self->get_severity(section => 'temperature', value => $result->{rlPhdUnitEnvParamTempSensorStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Temperature '%s' status is '%s'", + $instance, + $result->{rlPhdUnitEnvParamTempSensorStatus} + ) + ); + } + + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{rlPhdUnitEnvParamTempSensorValue}); + if ($checked == 0 && defined($result->{rlPhdUnitEnvParamTempSensorWarningThresholdValue})) { + my $warn_th = ':' . $result->{rlPhdUnitEnvParamTempSensorWarningThresholdValue}; + my $crit_th = ':' . $result->{rlPhdUnitEnvParamTempSensorCriticalThresholdValue}; + $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th); + $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th); + + $exit2 = $self->{perfdata}->threshold_check( + value => $result->{rlPhdUnitEnvParamTempSensorValue}, + threshold => [ + { label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' }, + { label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' } + ] + ); + $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance); + $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance); + } + + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit2, + short_msg => sprintf( + "Temperature '%s' is %s degree centigrade", + $instance, + $result->{rlPhdUnitEnvParamTempSensorValue} + ) + ); + } + $self->{output}->perfdata_add( + label => 'temp', unit => 'C', + nlabel => 'hardware.temperature.celsius', + instances => $instance, + value => $result->{rlPhdUnitEnvParamTempSensorValue}, + warning => $warn, + critical => $crit + ); + } +} + +1; diff --git a/centreon-plugins/centreon/common/radlan/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/radlan/snmp/mode/cpu.pm new file mode 100644 index 000000000..b30a23b0f --- /dev/null +++ b/centreon-plugins/centreon/common/radlan/snmp/mode/cpu.pm @@ -0,0 +1,120 @@ +# +# 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 centreon::common::radlan::snmp::mode::cpu; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'cpu', type => 0, cb_prefix_output => 'prefix_message_output', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{cpu} = [ + { label => 'average-1s', nlabel => 'cpu.utilization.1s.percentage', set => { + key_values => [ { name => 'average_1s' } ], + output_template => '%.2f %% (1s)', + perfdatas => [ + { value => 'average_1s_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' } + ] + } + }, + { label => 'average-1m', nlabel => 'cpu.utilization.1m.percentage', set => { + key_values => [ { name => 'average_1m' } ], + output_template => '%.2f %% (1m)', + perfdatas => [ + { value => 'average_1m_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' } + ] + } + }, + { label => 'average-5m', nlabel => 'cpu.utilization.5m.percentage', set => { + key_values => [ { name => 'average_5m' } ], + output_template => '%.2f %% (5m)', + perfdatas => [ + { value => 'average_5m_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' } + ] + } + } + ]; +} + +sub prefix_message_output { + my ($self, %options) = @_; + + return "CPU average usage: "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_rlCpuUtilDuringLastSecond = '.1.3.6.1.4.1.89.1.7.0'; + my $oid_rlCpuUtilDuringLastMinute = '.1.3.6.1.4.1.89.1.8.0'; + my $oid_rlCpuUtilDuringLast5Minutes = '.1.3.6.1.4.1.89.1.9.0'; + my $result = $options{snmp}->get_leef( + oids => [$oid_rlCpuUtilDuringLastSecond, $oid_rlCpuUtilDuringLastMinute, $oid_rlCpuUtilDuringLast5Minutes], + nothing_quit => 1 + ); + + $self->{cpu} = { + average_1s => $result->{$oid_rlCpuUtilDuringLastSecond}, + average_1m => $result->{$oid_rlCpuUtilDuringLastMinute}, + average_5m => $result->{$oid_rlCpuUtilDuringLast5Minutes} + } +} + + + +1; + +__END__ + +=head1 MODE + +Check cpu usage. + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'average-1s' (%), 'average-1m' (%), 'average-5m' (%). + +=back + +=cut diff --git a/centreon-plugins/centreon/common/radlan/mode/environment.pm b/centreon-plugins/centreon/common/radlan/snmp/mode/environment.pm similarity index 53% rename from centreon-plugins/centreon/common/radlan/mode/environment.pm rename to centreon-plugins/centreon/common/radlan/snmp/mode/environment.pm index 943b9c332..7e518b74d 100644 --- a/centreon-plugins/centreon/common/radlan/mode/environment.pm +++ b/centreon-plugins/centreon/common/radlan/snmp/mode/environment.pm @@ -18,49 +18,73 @@ # limitations under the License. # -package centreon::common::radlan::mode::environment; +package centreon::common::radlan::snmp::mode::environment; use base qw(centreon::plugins::templates::hardware); use strict; use warnings; +use centreon::common::radlan::snmp::mode::components::resources qw( + $oid_rlPhdUnitEnvParamEntry + $oid_rlPhdUnitEnvParamMonitorAutoRecoveryEnable +); sub set_system { my ($self, %options) = @_; - - $self->{regexp_threshold_overload_check_section_option} = '^fan|psu$'; - + + $self->{regexp_threshold_overload_check_section_option} = '^(?:fan|psu|temperature)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^temperature$'; + $self->{cb_hook2} = 'snmp_execute'; - - $self->{thresholds} = { + + $self->{thresholds} = { default => [ - ['shutdown', 'WARNING'], + ['normal', 'OK'], + ['notPresent', 'OK'], ['warning', 'WARNING'], ['critical', 'CRITICAL'], + ['shutdown', 'CRITICAL'], ['notFunctioning', 'CRITICAL'], - ['notPresent', 'OK'], - ['normal', 'OK'], ], + temperature => [ + ['ok', 'OK'], + ['unavailable', 'OK'], + ['nonoperational', 'CRITICAL'], + ] }; - - $self->{components_path} = 'centreon::common::radlan::mode::components'; - $self->{components_module} = ['fan', 'psu']; + + $self->{components_path} = 'centreon::common::radlan::snmp::mode::components'; + $self->{components_module} = ['psu', 'fan', 'temperature']; } sub snmp_execute { my ($self, %options) = @_; $self->{snmp} = $options{snmp}; + push @{$self->{request}}, { + oid => $oid_rlPhdUnitEnvParamEntry, + start => '.1.3.6.1.4.1.89.53.15.1.2', # rlPhdUnitEnvParamMainPSStatus + end => $oid_rlPhdUnitEnvParamMonitorAutoRecoveryEnable + }; $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); + + $self->{radlan_new} = 0; + foreach (keys %{$self->{results}->{$oid_rlPhdUnitEnvParamEntry}}) { + if (/^$oid_rlPhdUnitEnvParamMonitorAutoRecoveryEnable\./) { + $self->{radlan_new} = 1; + last; + } + } } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => {}); - + + $options{options}->add_options(arguments => { + }); + return $self; } @@ -70,24 +94,24 @@ __END__ =head1 MODE -Check environment (RADLAN-HWENVIROMENT). +Check environment. =over 8 =item B<--component> -Which component to check (Default: 'all'). -Can be: 'psu', 'fan'. +Which component to check (Default: '.*'). +Can be: 'fan', 'psu', 'temperature'. =item B<--filter> Exclude some parts (comma seperated list) (Example: --filter=psu) -Can also exclude specific instance: --filter=fan,1 +Can also exclude specific instance: --filter=psu,0 =item B<--absent-problem> Return an error if an entity is not 'present' (default is skipping) (comma seperated list) -Can be specific or global: --absent-problem=psu +Can be specific or global: --absent-problem=fan#2# =item B<--no-component> @@ -96,10 +120,21 @@ If total (with skipped) is 0. (Default: 'critical' returns). =item B<--threshold-overload> -Set to overload default threshold values (syntax: section,status,regexp) +Set to overload default threshold values (syntax: section,[instance,]status,regexp) It used before default thresholds (order stays). -Example: --threshold-overload='psu,CRITICAL,^(?!(normal)$)' +Example: --threshold-overload='fan,CRITICAL,^(?!(normal)$)' + +=item B<--warning> + +Set warning threshold (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,30' + +=item B<--critical> + +Set critical threshold (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,40' =back =cut + diff --git a/centreon-plugins/network/dell/xseries/snmp/plugin.pm b/centreon-plugins/network/dell/xseries/snmp/plugin.pm new file mode 100644 index 000000000..2a329586f --- /dev/null +++ b/centreon-plugins/network/dell/xseries/snmp/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 network::dell::xseries::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'cpu' => 'centreon::common::radlan::snmp::mode::cpu', + 'hardware' => 'centreon::common::radlan::snmp::mode::environment', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'uptime' => 'snmp_standard::mode::uptime' + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Dell X-Series in SNMP. + +=cut diff --git a/centreon-plugins/snmp_standard/mode/loadaverage.pm b/centreon-plugins/snmp_standard/mode/loadaverage.pm index 6104bf28a..4d5fbb3b2 100644 --- a/centreon-plugins/snmp_standard/mode/loadaverage.pm +++ b/centreon-plugins/snmp_standard/mode/loadaverage.pm @@ -30,12 +30,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', default => '' }, - "critical:s" => { name => 'critical', default => '' }, - "average" => { name => 'average' }, - }); + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning', default => '' }, + 'critical:s' => { name => 'critical', default => '' }, + 'average' => { name => 'average' }, + }); return $self; } @@ -83,7 +82,7 @@ sub run { my $oid_CpuLoad15m = '.1.3.6.1.4.1.2021.10.1.3.3'; my $result = $self->{snmp}->get_leef(oids => [$oid_CpuLoad1m, $oid_CpuLoad5m, $oid_CpuLoad15m], nothing_quit => 1); - + my ($msg, $cpu_load1, $cpu_load5, $cpu_load15); $result->{$oid_CpuLoad1m} =~ s/,/\./g; $result->{$oid_CpuLoad5m} =~ s/,/\./g; @@ -92,8 +91,10 @@ sub run { if (defined($self->{option_results}->{average})) { my $result2 = $self->{snmp}->get_table(oid => $oid_CountCpu); if (scalar(keys %$result2) <= 0){ - $self->{output}->output_add(severity => 'unknown', - short_msg => 'Unable to get number of CPUs'); + $self->{output}->output_add( + severity => 'unknown', + short_msg => 'Unable to get number of CPUs' + ); $self->{output}->display(); $self->{output}->exit(); } From f78a1294ea62cb45e490d33b060a4abb49a349bb Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 4 May 2020 16:21:23 +0200 Subject: [PATCH 157/190] Fix #1979 --- .../centreon/common/radlan/snmp/mode/components/fan.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/centreon/common/radlan/snmp/mode/components/fan.pm b/centreon-plugins/centreon/common/radlan/snmp/mode/components/fan.pm index 153ae2448..4685fe9ae 100644 --- a/centreon-plugins/centreon/common/radlan/snmp/mode/components/fan.pm +++ b/centreon-plugins/centreon/common/radlan/snmp/mode/components/fan.pm @@ -22,7 +22,7 @@ package centreon::common::radlan::snmp::mode::components::fan; use strict; use warnings; -use centreon::common::cisco::smallbusiness::snmp::mode::components::resources qw( +use centreon::common::radlan::snmp::mode::components::resources qw( $rl_envmon_state $oid_rlPhdUnitEnvParamMonitorAutoRecoveryEnable $oid_rlPhdUnitEnvParamEntry From 6b29740ef272a99a65c90f75fa9153c1c759c184 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 5 May 2020 09:01:26 +0200 Subject: [PATCH 158/190] Fix #1984 --- .../antivirus/kaspersky/snmp/mode/updates.pm | 75 +++++++++++-------- 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/updates.pm b/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/updates.pm index 684c21cc0..a05aa5a1e 100644 --- a/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/updates.pm +++ b/centreon-plugins/apps/antivirus/kaspersky/snmp/mode/updates.pm @@ -31,8 +31,7 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - my $msg = sprintf("Updates status is '%s'", $self->{result_values}->{status}); - return $msg; + return sprintf("Updates status is '%s'", $self->{result_values}->{status}); } sub custom_status_calc { @@ -45,26 +44,34 @@ sub custom_status_calc { sub custom_last_perfdata { my ($self, %options) = @_; - $self->{output}->perfdata_add(label => 'last_server_update', - value => $self->{result_values}->{diff}, - unit => 's', - min => 0); + $self->{output}->perfdata_add( + label => 'last_server_update', + value => $self->{result_values}->{diff}, + unit => 's', + min => 0 + ); } sub custom_last_threshold { my ($self, %options) = @_; - my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{diff}, - threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, - { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); + my $exit = $self->{perfdata}->threshold_check( + value => $self->{result_values}->{diff}, + threshold => [ + { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, + { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } + ] + ); return $exit; } sub custom_last_output { my ($self, %options) = @_; - my $msg = sprintf("Last server update: %s [%s]", centreon::plugins::misc::change_seconds(value => $self->{result_values}->{diff}), $self->{result_values}->{date_time}); - return $msg; + return sprintf( + 'Last server update: %s [%s]', + centreon::plugins::misc::change_seconds(value => $self->{result_values}->{diff}), $self->{result_values}->{date_time} + ); } sub custom_last_calc { @@ -80,7 +87,7 @@ sub custom_last_calc { hour => $4, minute => $5, second => $6, - %{$self->{tz}} + %{$self->{instance_mode}->{tz}} ); $self->{result_values}->{diff} = time() - $dt->epoch; $self->{result_values}->{date_time} = $dt->datetime(); @@ -93,7 +100,7 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'global', type => 0, message_separator => ' - ' }, + { name => 'global', type => 0, message_separator => ' - ' } ]; $self->{maps_counters}->{global} = [ @@ -102,7 +109,7 @@ sub set_counters { closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, + closure_custom_threshold_check => \&catalog_status_threshold } }, { label => 'last-server-update', set => { @@ -110,17 +117,17 @@ sub set_counters { closure_custom_calc => $self->can('custom_last_calc'), closure_custom_output => $self->can('custom_last_output'), closure_custom_threshold_check => $self->can('custom_last_threshold'), - closure_custom_perfdata => $self->can('custom_last_perfdata'), + closure_custom_perfdata => $self->can('custom_last_perfdata') } }, { label => 'not-updated', set => { key_values => [ { name => 'hostsNotUpdated' } ], output_template => '%d host(s) not up to date', perfdatas => [ - { label => 'not_updated', value => 'hostsNotUpdated_absolute', template => '%d', min => 0 }, - ], + { label => 'not_updated', value => 'hostsNotUpdated_absolute', template => '%d', min => 0 } + ] } - }, + } ]; } @@ -129,12 +136,12 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /Warning/i' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /Critical/i' }, - "timezone:s" => { name => 'timezone', default => 'GMT' }, - }); + $options{options}->add_options(arguments => { + 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /Warning/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /Critical/i' }, + 'timezone:s' => { name => 'timezone', default => 'GMT' } + }); + return $self; } @@ -146,12 +153,12 @@ sub check_options { $self->change_macros(macros => ['warning_status', 'critical_status']); } -my %map_status = ( +my $map_status = { 0 => 'OK', 1 => 'Info', 2 => 'Warning', - 3 => 'Critical', -); + 3 => 'Critical' +}; my $oid_updatesStatus = '.1.3.6.1.4.1.23668.1093.1.2.1'; my $oid_lastServerUpdateTime = '.1.3.6.1.4.1.23668.1093.1.2.3'; @@ -160,14 +167,16 @@ my $oid_hostsNotUpdated = '.1.3.6.1.4.1.23668.1093.1.2.4'; sub manage_selection { my ($self, %options) = @_; - my $snmp_result = $options{snmp}->get_leef(oids => [ $oid_updatesStatus, $oid_lastServerUpdateTime, - $oid_hostsNotUpdated ], - nothing_quit => 1); - - $self->{global} = {}; + my $snmp_result = $options{snmp}->get_leef( + oids => [ + $oid_updatesStatus, $oid_lastServerUpdateTime, + $oid_hostsNotUpdated + ], + nothing_quit => 1 + ); $self->{global} = { - updatesStatus => $map_status{$snmp_result->{$oid_updatesStatus}}, + updatesStatus => $map_status->{$snmp_result->{$oid_updatesStatus}}, lastServerUpdateTime => $snmp_result->{$oid_lastServerUpdateTime}, hostsNotUpdated => $snmp_result->{$oid_hostsNotUpdated}, }; From b146551ed986082709a2f8fa1f38624b197606be Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 5 May 2020 09:33:43 +0200 Subject: [PATCH 159/190] Fix #1879 --- .../network/paloalto/ssh/custom/cli.pm | 2 +- .../network/paloalto/ssh/mode/licenses.pm | 159 ++++++++++++++++++ .../network/paloalto/ssh/plugin.pm | 1 + 3 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 centreon-plugins/network/paloalto/ssh/mode/licenses.pm diff --git a/centreon-plugins/network/paloalto/ssh/custom/cli.pm b/centreon-plugins/network/paloalto/ssh/custom/cli.pm index d3f6d83d5..9871ffbb3 100644 --- a/centreon-plugins/network/paloalto/ssh/custom/cli.pm +++ b/centreon-plugins/network/paloalto/ssh/custom/cli.pm @@ -138,7 +138,7 @@ sub execute_command { return $stdout; } - if ($stdout !~ /(.*<\/response>)/ms) { + if ($stdout !~ /(.*<\/response>)/ms) { $self->{output}->add_option_msg(short_msg => "Cannot find xml response"); $self->{output}->option_exit(); } diff --git a/centreon-plugins/network/paloalto/ssh/mode/licenses.pm b/centreon-plugins/network/paloalto/ssh/mode/licenses.pm new file mode 100644 index 000000000..e4a2837e6 --- /dev/null +++ b/centreon-plugins/network/paloalto/ssh/mode/licenses.pm @@ -0,0 +1,159 @@ +# +# 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 network::paloalto::ssh::mode::licenses; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use DateTime; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("expired status is '%s'", $self->{result_values}->{expired}); + if ($self->{result_values}->{expiry_date} eq '') { + $msg .= ', never expires'; + } else { + $msg .= sprintf( + ", expires in %d days [%s]", + $self->{result_values}->{expiry_days}, + $self->{result_values}->{expiry_date} + ); + } + + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{feature} = $options{new_datas}->{$self->{instance} . '_feature'}; + $self->{result_values}->{expired} = $options{new_datas}->{$self->{instance} . '_expired'}; + $self->{result_values}->{expiry_date} = $options{new_datas}->{$self->{instance} . '_expiry_date'}; + $self->{result_values}->{expiry_seconds} = $options{new_datas}->{$self->{instance} . '_expiry_seconds'}; + $self->{result_values}->{expiry_days} = ($self->{result_values}->{expiry_seconds} ne '') ? $self->{result_values}->{expiry_seconds} / 86400 : 0; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'features', type => 1, cb_prefix_output => 'prefix_feature_output', message_multiple => 'All features licensing are ok' }, + ]; + + $self->{maps_counters}->{features} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'feature' }, { name => 'expired' }, { name => 'expiry_date' }, { name => 'expiry_seconds' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_feature_output { + my ($self, %options) = @_; + + return "Feature '" . $options{instance_value}->{feature} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{expired} eq "yes"' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $result = $options{custom}->execute_command(command => 'request license info', ForceArray => ['entry']); + + my $months = { + january => 1, february => 2, march => 3, april => 4, may => 5, june => 6, + july => 7, august => 8, september => 9, october => 10, november => 11, december => 12 + }; + + $self->{features} = {}; + foreach my $feature (@{$result->{licenses}->{entry}}) { + $feature->{expires} = lc($feature->{expires}); + + # January 30, 2022 + my $dt; + if ($feature->{expires} =~ /^(\w+)\s+(\d+).*?(\d+)$/) { + $dt = DateTime->new(year => $3, month => $months->{$1}, day => $2); + } + + $self->{features}->{$feature->{feature}} = { + feature => $feature->{feature}, + expired => $feature->{expired}, + expiry_date => $feature->{expires} ne 'never' ? $feature->{expires} : '', + expiry_seconds => $feature->{expires} ne 'never' ? $dt->epoch - time() : '' + }; + } + + if (scalar(keys %{$self->{features}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No features found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check features licensing. + +=over 8 + +=item B<--warning-status> + +Set warning threshold for status. +Can use special variables like: %{expired}, %{expiry_days}, %{feature} + +=item B<--critical-status> + +Set critical threshold for status. (Default: '%{expired} eq "yes"'). +Can use special variables like: %{expired}, %{expiry_days}, %{feature} + +=back + +=cut diff --git a/centreon-plugins/network/paloalto/ssh/plugin.pm b/centreon-plugins/network/paloalto/ssh/plugin.pm index 52b69c872..3773ac63c 100644 --- a/centreon-plugins/network/paloalto/ssh/plugin.pm +++ b/centreon-plugins/network/paloalto/ssh/plugin.pm @@ -35,6 +35,7 @@ sub new { 'ha' => 'network::paloalto::ssh::mode::ha', 'interfaces' => 'network::paloalto::ssh::mode::interfaces', 'ipsec' => 'network::paloalto::ssh::mode::ipsec', + 'licenses' => 'network::paloalto::ssh::mode::licenses', 'system' => 'network::paloalto::ssh::mode::system' ); From 0e51ccf5f00de20515916d7506d9b3374b017eec Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 5 May 2020 11:39:02 +0200 Subject: [PATCH 160/190] Fix #1927 --- .../foundry/snmp/mode/components/board.pm | 85 +++++++++++ .../foundry/snmp/mode/components/fan.pm | 77 ++++++++++ .../foundry/snmp/mode/components/psu.pm | 79 +++++++++++ .../foundry/snmp/mode/components/resources.pm | 36 +++++ .../snmp/mode/components/temperature.pm | 105 ++++++++++++++ .../centreon/common/foundry/snmp/mode/cpu.pm | 120 ++++++++++++++++ .../common/foundry/snmp/mode/hardware.pm | 119 ++++++++++++++++ .../common/foundry/snmp/mode/memory.pm | 133 ++++++++++++++++++ .../network/ruckus/icx/snmp/plugin.pm | 52 +++++++ 9 files changed, 806 insertions(+) create mode 100644 centreon-plugins/centreon/common/foundry/snmp/mode/components/board.pm create mode 100644 centreon-plugins/centreon/common/foundry/snmp/mode/components/fan.pm create mode 100644 centreon-plugins/centreon/common/foundry/snmp/mode/components/psu.pm create mode 100644 centreon-plugins/centreon/common/foundry/snmp/mode/components/resources.pm create mode 100644 centreon-plugins/centreon/common/foundry/snmp/mode/components/temperature.pm create mode 100644 centreon-plugins/centreon/common/foundry/snmp/mode/cpu.pm create mode 100644 centreon-plugins/centreon/common/foundry/snmp/mode/hardware.pm create mode 100644 centreon-plugins/centreon/common/foundry/snmp/mode/memory.pm create mode 100644 centreon-plugins/network/ruckus/icx/snmp/plugin.pm diff --git a/centreon-plugins/centreon/common/foundry/snmp/mode/components/board.pm b/centreon-plugins/centreon/common/foundry/snmp/mode/components/board.pm new file mode 100644 index 000000000..4f4cefa6b --- /dev/null +++ b/centreon-plugins/centreon/common/foundry/snmp/mode/components/board.pm @@ -0,0 +1,85 @@ +# +# 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 centreon::common::foundry::snmp::mode::components::board; + +use strict; +use warnings; + +my $mapping_board_status = { + 0 => 'moduleEmpty', 2 => 'moduleGoingDown', 3 => 'moduleRejected', + 4 => 'moduleBad', 8 => 'moduleConfigured', 9 => 'moduleComingUp', + 10 => 'moduleRunning' +}; + +my $mapping = { + snAgentBrdMainBrdDescription => { oid => '.1.3.6.1.4.1.1991.1.1.2.2.1.1.2' }, + snAgentBrdModuleStatus => { oid => '.1.3.6.1.4.1.1991.1.1.2.2.1.1.12', map => $mapping_board_status } +}; +sub load { + my ($self) = @_; + + push @{$self->{request}}, + { oid => $mapping->{snAgentBrdMainBrdDescription}->{oid} }, + { oid => $mapping->{snAgentBrdModuleStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking boards'); + $self->{components}->{board} = { name => 'boards', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'board')); + + my $result = { + %{$self->{results}->{ $mapping->{snAgentBrdMainBrdDescription}->{oid} }}, + %{$self->{results}->{ $mapping->{snAgentBrdModuleStatus}->{oid} }} + }; + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %$result)) { + next if ($oid !~ /^$mapping->{snAgentBrdModuleStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $result, instance => $instance); + + next if ($self->check_filter(section => 'board', instance => $instance)); + $self->{components}->{board}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "board '%s' status is '%s' [instance: %s].", + $result->{snAgentBrdMainBrdDescription}, + $result->{snAgentBrdModuleStatus}, + $instance + ) + ); + my $exit = $self->get_severity(section => 'board', value => $result->{snAgentBrdModuleStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "board '%s' status is '%s'", + $result->{snAgentBrdMainBrdDescription}, + $result->{snAgentBrdModuleStatus} + ) + ); + } + } +} + +1; diff --git a/centreon-plugins/centreon/common/foundry/snmp/mode/components/fan.pm b/centreon-plugins/centreon/common/foundry/snmp/mode/components/fan.pm new file mode 100644 index 000000000..9ee8b6ae2 --- /dev/null +++ b/centreon-plugins/centreon/common/foundry/snmp/mode/components/fan.pm @@ -0,0 +1,77 @@ +# +# 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 centreon::common::foundry::snmp::mode::components::fan; + +use strict; +use warnings; +use centreon::common::foundry::snmp::mode::components::resources qw($map_status); + +my $mapping = { + snChasFan2Description => { oid => '.1.3.6.1.4.1.1991.1.1.1.3.2.1.3' }, + snChasFan2OperStatus => { oid => '.1.3.6.1.4.1.1991.1.1.1.3.2.1.4', map => $map_status } +}; +my $oid_snChasFan2Entry = '.1.3.6.1.4.1.1991.1.1.1.3.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { + oid => $oid_snChasFan2Entry, + start => $mapping->{snChasFan2Description}->{oid} + }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking fans'); + $self->{components}->{fan} = { name => 'fans', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'fan')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_snChasFan2Entry}})) { + next if ($oid !~ /^$mapping->{snChasFan2OperStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_snChasFan2Entry}, instance => $instance); + + next if ($self->check_filter(section => 'fan', instance => $instance)); + + $self->{components}->{fan}->{total}++; + $self->{output}->output_add( + long_msg => sprintf( + "fan '%s' status is '%s' [instance = %s]", + $result->{snChasFan2Description}, $result->{snChasFan2OperStatus}, $instance + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'fan', value => $result->{snChasFan2OperStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "fan '%s' status is '%s'", + $result->{snChasFan2Description}, $result->{snChasFan2OperStatus} + ) + ); + } + } +} + +1; diff --git a/centreon-plugins/centreon/common/foundry/snmp/mode/components/psu.pm b/centreon-plugins/centreon/common/foundry/snmp/mode/components/psu.pm new file mode 100644 index 000000000..d1e8dad2a --- /dev/null +++ b/centreon-plugins/centreon/common/foundry/snmp/mode/components/psu.pm @@ -0,0 +1,79 @@ +# +# 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 centreon::common::foundry::snmp::mode::components::psu; + +use strict; +use warnings; +use centreon::common::foundry::snmp::mode::components::resources qw($map_status); + +my $mapping = { + snChasPwrSupply2Description => { oid => '.1.3.6.1.4.1.1991.1.1.1.2.2.1.3' }, + snChasPwrSupply2OperStatus => { oid => '.1.3.6.1.4.1.1991.1.1.1.2.2.1.4', map => $map_status } +}; +my $oid_snChasPwrSupply2Entry = '.1.3.6.1.4.1.1991.1.1.1.2.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { + oid => $oid_snChasPwrSupply2Entry, + start => $mapping->{snChasPwrSupply2Description}->{oid} + }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking power supplies'); + $self->{components}->{psu} = { name => 'psu', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'psu')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_snChasPwrSupply2Entry}})) { + next if ($oid !~ /^$mapping->{snChasPwrSupply2OperStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_snChasPwrSupply2Entry}, instance => $instance); + + next if ($self->check_filter(section => 'psu', instance => $instance)); + $self->{components}->{psu}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "power supply '%s' status is '%s' [instance: %s].", + $result->{snChasPwrSupply2Description}, + $result->{snChasPwrSupply2OperStatus}, + $instance + ) + ); + my $exit = $self->get_severity(label => 'default', section => 'psu', value => $result->{snChasPwrSupply2OperStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "power supply '%s' status is '%s'", + $result->{snChasPwrSupply2Description}, + $result->{snChasPwrSupply2OperStatus} + ) + ); + } + } +} + +1; diff --git a/centreon-plugins/centreon/common/foundry/snmp/mode/components/resources.pm b/centreon-plugins/centreon/common/foundry/snmp/mode/components/resources.pm new file mode 100644 index 000000000..b469e779a --- /dev/null +++ b/centreon-plugins/centreon/common/foundry/snmp/mode/components/resources.pm @@ -0,0 +1,36 @@ +# +# 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 centreon::common::foundry::snmp::mode::components::resources; + +use strict; +use warnings; +use Exporter; + +our $map_status; + +our @ISA = qw(Exporter); +our @EXPORT_OK = qw($map_status); + +$map_status = { + 1 => 'other', 2 => 'normal', 3 => 'failure' +}; + +1; diff --git a/centreon-plugins/centreon/common/foundry/snmp/mode/components/temperature.pm b/centreon-plugins/centreon/common/foundry/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..1a46b8dc0 --- /dev/null +++ b/centreon-plugins/centreon/common/foundry/snmp/mode/components/temperature.pm @@ -0,0 +1,105 @@ +# +# 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 centreon::common::foundry::snmp::mode::components::temperature; + +use strict; +use warnings; + +my $mapping = { + snChasActualTemperature => { oid => '.1.3.6.1.4.1.1991.1.1.1.1.18' }, + snChasWarningTemperature => { oid => '.1.3.6.1.4.1.1991.1.1.1.1.19' }, + snChasShutdownTemperature => { oid => '.1.3.6.1.4.1.1991.1.1.1.1.20' } +}; +my $oid_snChasGen = '.1.3.6.1.4.1.1991.1.1.1.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { + oid => $oid_snChasGen, + start => $mapping->{snChasActualTemperature}->{oid}, + end => $mapping->{snChasShutdownTemperature}->{oid} + }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'Checking temperatures'); + $self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'temperature')); + + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_snChasGen}, instance => '0'); + my ($name, $instance) = ('chassi', 1); + + next if ($self->check_filter(section => 'temperature', instance => $instance)); + + $self->{components}->{temperature}->{total}++; + + $result->{snChasActualTemperature} *= 0.5; + $result->{snChasWarningTemperature} *= 0.5; + $result->{snChasShutdownTemperature} *= 0.5; + $self->{output}->output_add( + long_msg => sprintf( + "temperature '%s' is %s celsius [instance = %s]", + $name, $result->{snChasActualTemperature}, $instance + ) + ); + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{snChasActualTemperature}); + if ($checked == 0) { + my $warn_th = defined($result->{snChasWarningTemperature}) ? $result->{snChasWarningTemperature} : ''; + my $crit_th = defined($result->{snChasShutdownTemperature}) ? $result->{snChasShutdownTemperature} : ''; + $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th); + $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th); + + $exit = $self->{perfdata}->threshold_check( + value => $result->{snChasActualTemperature}, + threshold => [ + { label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' }, + { label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' } + ] + ); + $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance); + $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance) + } + + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "temperature '%s' is %s celsius", + $name, + $result->{snChasActualTemperature} + ) + ); + } + + $self->{output}->perfdata_add( + nlabel => 'hardware.temperature.celsius', + unit => 'C', + instances => $name, + value => $result->{snChasActualTemperature}, + warning => $warn, + critical => $crit + ); +} + +1; diff --git a/centreon-plugins/centreon/common/foundry/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/foundry/snmp/mode/cpu.pm new file mode 100644 index 000000000..a778bd133 --- /dev/null +++ b/centreon-plugins/centreon/common/foundry/snmp/mode/cpu.pm @@ -0,0 +1,120 @@ +# +# 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 centreon::common::foundry::snmp::mode::cpu; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPUs are ok' } + ]; + + $self->{maps_counters}->{cpu} = [ + { label => 'utilization-5s', nlabel => 'cpu.utilization.5s.percentage', set => { + key_values => [ { name => 'cpu_5s' }, { name => 'display' } ], + output_template => '%.2f %% (5s)', + perfdatas => [ + { value => 'cpu_5s_absolute', template => '%.2f', + unit => '%', min => 0, max => 100, label_extra_instance => 1 } + ] + } + }, + { label => 'utilization-1m', nlabel => 'cpu.utilization.1m.percentage', set => { + key_values => [ { name => 'cpu_1m' }, { name => 'display' } ], + output_template => '%.2f %% (1m)', + perfdatas => [ + { value => 'cpu_1m_absolute', template => '%.2f', + unit => '%', min => 0, max => 100, label_extra_instance => 1 } + ] + } + }, + { label => 'utilization-5m', nlabel => 'cpu.utilization.5m.percentage', set => { + key_values => [ { name => 'cpu_5m' }, { name => 'display' } ], + output_template => '%.2f %% (5m)', + perfdatas => [ + { value => 'cpu_5m_absolute', template => '%.2f', + unit => '%', min => 0, max => 100, label_extra_instance => 1 } + ] + } + } + ]; +} + +sub prefix_cpu_output { + my ($self, %options) = @_; + + return "CPU '" . $options{instance_value}->{display} . "' usage: "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_snAgentCpuUtilPercent = '.1.3.6.1.4.1.1991.1.1.2.11.1.1.5'; + my $snmp_result = $options{snmp}->get_table(oid => $oid_snAgentCpuUtilPercent, nothing_quit => 1); + + $self->{cpu} = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$oid_snAgentCpuUtilPercent\.(.*?)\.(.*?)\.60/); + my $instance = "slot$1:cpu$2"; + + $self->{cpu}->{$instance} = { + display => $instance, + cpu_5s => $snmp_result->{ $oid_snAgentCpuUtilPercent . '.' . $1 . '.' . $2 . '.5' }, + cpu_1m => $snmp_result->{ $oid_snAgentCpuUtilPercent . '.' . $1 . '.' . $2 . '.60' }, + cpu_5m => $snmp_result->{ $oid_snAgentCpuUtilPercent . '.' . $1 . '.' . $2 . '.300' } + }; + } +} + +1; + +__END__ + +=head1 MODE + +Check CPU usage. + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'utilization-5s', 'utilization-1m', 'utilization-5m'. + +=back + +=cut diff --git a/centreon-plugins/centreon/common/foundry/snmp/mode/hardware.pm b/centreon-plugins/centreon/common/foundry/snmp/mode/hardware.pm new file mode 100644 index 000000000..f63ceb0af --- /dev/null +++ b/centreon-plugins/centreon/common/foundry/snmp/mode/hardware.pm @@ -0,0 +1,119 @@ +# +# 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 centreon::common::foundry::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(?:board|fan|psu|temperature)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(?:temperature)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + default => [ + ['other', 'UNKNOWN'], + ['normal', 'OK'], + ['failure', 'CRITICAL'] + ], + board => [ + ['moduleEmpty', 'OK'], + ['moduleGoingDown', 'WARNING'], + ['moduleRejected', 'CRITICAL'], + ['moduleBad', 'CRITICAL'], + ['moduleConfigured', 'OK'], + ['moduleComingUp', 'OK'], + ['moduleRunning', 'OK'] + ] + }; + + $self->{components_path} = 'centreon::common::foundry::snmp::mode::components'; + $self->{components_module} = ['board', 'fan', 'psu', 'temperature']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'board', 'fan', 'temperature', 'psu'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=fan --filter=psu) +Can also exclude specific instance: --filter=fan,1.1 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='psu,CRITICAL,fail' + +=item B<--warning> + +Set warning threshold for 'temperature' (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,30' + +=item B<--critical> + +Set critical threshold for 'temperature' (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,50' + +=back + +=cut + diff --git a/centreon-plugins/centreon/common/foundry/snmp/mode/memory.pm b/centreon-plugins/centreon/common/foundry/snmp/mode/memory.pm new file mode 100644 index 000000000..5d3c7c38d --- /dev/null +++ b/centreon-plugins/centreon/common/foundry/snmp/mode/memory.pm @@ -0,0 +1,133 @@ +# +# 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 centreon::common::foundry::snmp::mode::memory; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub custom_usage_output { + my ($self, %options) = @_; + + return sprintf( + 'Ram total: %s %s used: %s %s (%.2f%%) free: %s %s (%.2f%%)', + $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}), + $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}), + $self->{result_values}->{prct_used_absolute}, + $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}), + $self->{result_values}->{prct_free_absolute} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'memory', type => 0 } + ]; + + $self->{maps_counters}->{memory} = [ + { label => 'usage', nlabel => 'memory.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1 } + ] + } + }, + { label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1 } + ] + } + }, + { label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => { + key_values => [ { name => 'prct_used' } ], + output_template => 'Ram used: %.2f %%', + perfdatas => [ + { value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%' } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +my $mapping = { + total => { oid => '.1.3.6.1.4.1.20301.2.5.1.2.12.9.1.1.3' }, # totalMemoryStatsRev + free => { oid => '.1.3.6.1.4.1.20301.2.5.1.2.12.9.1.1.4' } # memoryFreeStatsRev +}; + +my $oid_memoryStatsEntry = '.1.3.6.1.4.1.20301.2.5.1.2.12.9.1.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_snAgGblDynMemUtil = '.1.3.6.1.4.1.1991.1.1.2.1.53.0'; # % + my $oid_snAgGblDynMemTotal = '.1.3.6.1.4.1.1991.1.1.2.1.54.0'; # Bytes + my $snmp_result = $options{snmp}->get_leef( + oids => [$oid_snAgGblDynMemUtil, $oid_snAgGblDynMemTotal], + nothing_quit => 1 + ); + + my $used = $snmp_result->{$oid_snAgGblDynMemUtil} * $snmp_result->{$oid_snAgGblDynMemTotal} / 100; + $self->{memory} = { + prct_used => $snmp_result->{$oid_snAgGblDynMemUtil}, + prct_free => 100 - $snmp_result->{$oid_snAgGblDynMemUtil}, + total => $snmp_result->{$oid_snAgGblDynMemTotal}, + used => $used, + free => $snmp_result->{$oid_snAgGblDynMemTotal} - $used + }; +} + +1; + +__END__ + +=head1 MODE + +Check memory usage. + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%). + +=back + +=cut diff --git a/centreon-plugins/network/ruckus/icx/snmp/plugin.pm b/centreon-plugins/network/ruckus/icx/snmp/plugin.pm new file mode 100644 index 000000000..bec60e747 --- /dev/null +++ b/centreon-plugins/network/ruckus/icx/snmp/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 network::ruckus::icx::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.5'; + %{$self->{modes}} = ( + 'cpu' => 'centreon::common::foundry::snmp::mode::cpu', + 'hardware' => 'centreon::common::foundry::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'centreon::common::foundry::snmp::mode::memory' + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Ruckus ICX series in SNMP. + +=cut From e72d07eea86dbc8da2ef5283988bf99e548c6d9b Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 5 May 2020 14:09:04 +0200 Subject: [PATCH 161/190] Fix #1751 --- .../smartzone/snmp/mode/accesspoints.pm | 247 ++++++++++++++++++ .../smartzone/snmp/mode/listaccesspoints.pm | 130 +++++++++ .../ruckus/smartzone/snmp/mode/system.pm | 152 +++++++++++ .../network/ruckus/smartzone/snmp/plugin.pm | 57 ++++ 4 files changed, 586 insertions(+) create mode 100644 centreon-plugins/network/ruckus/smartzone/snmp/mode/accesspoints.pm create mode 100644 centreon-plugins/network/ruckus/smartzone/snmp/mode/listaccesspoints.pm create mode 100644 centreon-plugins/network/ruckus/smartzone/snmp/mode/system.pm create mode 100644 centreon-plugins/network/ruckus/smartzone/snmp/plugin.pm diff --git a/centreon-plugins/network/ruckus/smartzone/snmp/mode/accesspoints.pm b/centreon-plugins/network/ruckus/smartzone/snmp/mode/accesspoints.pm new file mode 100644 index 000000000..15d0cf6af --- /dev/null +++ b/centreon-plugins/network/ruckus/smartzone/snmp/mode/accesspoints.pm @@ -0,0 +1,247 @@ +# +# 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 network::ruckus::smartzone::snmp::mode::accesspoints; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + "connection status is '%s' [config status: '%s'] [registration status: '%s']", + $self->{result_values}->{connection_status}, + $self->{result_values}->{config_status}, + $self->{result_values}->{registration_status} + ); +} + +sub ap_long_output { + my ($self, %options) = @_; + + return "checking access point '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_ap_output { + my ($self, %options) = @_; + + return "access point '" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'accesspoints', type => 3, cb_prefix_output => 'prefix_ap_output', cb_long_output => 'ap_long_output', + indent_long_output => ' ', message_multiple => 'All access points are ok', + group => [ + { name => 'status', type => 0, skipped_code => { -10 => 1 } }, + { name => 'connection', type => 0, skipped_code => { -10 => 1 } }, + { name => 'traffic', type => 0, skipped_code => { -10 => 1 } } + ] + } + ]; + + $self->{maps_counters}->{status} = [ + { label => 'status', threshold => 0, set => { + key_values => [ + { name => 'connection_status' }, { name => 'config_status' }, + { name => 'registration_status' }, { name => 'display' } + ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + } + ]; + + $self->{maps_counters}->{connection} = [ + { label => 'connection-client-devices-authorized', nlabel => 'accesspoint.connection.client.devices.authorized.count', set => { + key_values => [ { name => 'authorized_clients' }, { name => 'display' } ], + output_template => 'client devices authorized connections: %d', + perfdatas => [ + { value => 'authorized_clients_absolute', template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + } + ]; + + $self->{maps_counters}->{traffic} = [ + { label => 'traffic-in', nlabel => 'accesspoint.traffic.in.bitspersecond', set => { + key_values => [ { name => 'traffic_in', diff => 1 }, { name => 'display' } ], + output_template => 'traffic in: %s%s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_in_per_second', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + }, + { label => 'traffic-out', nlabel => 'accesspoint.traffic.out.bitspersecond', set => { + key_values => [ { name => 'traffic_out', diff => 1 }, { name => 'display' } ], + output_template => 'traffic in: %s%s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_out_per_second', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' } + ] + } + } + ]; +} + +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 => '' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); +} + +my $mapping = { + authorized_clients => { oid => '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.15' }, # ruckusSZAPNumSta + connection_status => { oid => '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.16' }, # ruckusSZAPConnStatus + registration_status => { oid => '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.17' }, # ruckusSZAPRegStatus + config_status => { oid => '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.18' }, # ruckusSZAPConfigStatus + traffic_out => { oid => '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.57' }, # ruckusSZAPIpsecTXBytes + traffic_in => { oid => '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.58' }, # ruckusSZAPIpsecRXBytes +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_ruckusSZAPName = '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.5'; + my $oid_ruckusSZAPSerial = '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.9'; + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_ruckusSZAPName }, + { oid => $oid_ruckusSZAPSerial } + ], + return_type => 1, + nothing_quit => 1 + ); + + $self->{accesspoints} = {}; + foreach (keys %$snmp_result) { + next if (! /^$oid_ruckusSZAPName\.(.*)/); + my $instance = $1; + my $name = defined($snmp_result->{$_}) && $snmp_result->{$_} ne '' ? + $snmp_result->{$_} : $snmp_result->{$oid_ruckusSZAPSerial . '.' . $instance}; + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping access point '" . $name . "'.", debug => 1); + next; + } + + $self->{accesspoints}->{$instance} = { + display => $name, + status => { display => $name }, + connection => { display => $name }, + traffic => { display => $name } + }; + } + + return if (scalar(keys %{$self->{accesspoints}}) <= 0); + + $options{snmp}->load( + oids => [ map($_->{oid}, values(%$mapping)) ], + instances => [ keys %{$self->{accesspoints}} ], + instance_regexp => '^(.*)$' + ); + $snmp_result = $options{snmp}->get_leef(); + foreach (keys %{$self->{accesspoints}}) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + + $self->{accesspoints}->{$_}->{status}->{connection_status} = $result->{connection_status}; + $self->{accesspoints}->{$_}->{status}->{registration_status} = $result->{registration_status}; + $self->{accesspoints}->{$_}->{status}->{config_status} = $result->{config_status}; + + $self->{accesspoints}->{$_}->{connection}->{authorized_clients} = $result->{authorized_clients}; + + $self->{accesspoints}->{$_}->{traffic}->{traffic_in} = $result->{traffic_in} * 8; + $self->{accesspoints}->{$_}->{traffic}->{traffic_out} = $result->{traffic_out} * 8; + } + + $self->{cache_name} = 'ruckus_smartzone_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_counters_block}) ? md5_hex($self->{option_results}->{filter_counters_block}) : md5_hex('all')) . '_' . + (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 access points. + +=over 8 + +=item B<--filter-name> + +Filter by access point name (can be a regexp). + +=item B<--unknown-status> + +Set unknown threshold for status. +Can used special variables like: %{config_status}, %{connection_status}, %{registration_status} + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{config_status}, %{connection_status}, %{registration_status} + +=item B<--critical-status> + +Set critical threshold for status. +Can used special variables like: %{config_status}, %{connection_status}, %{registration_status} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'memory-usage', 'usage-free', 'usage-prct', 'traffic-in', 'traffic-out', +'cpu-utilization', 'connection-accesspoints', 'connection-client-devices-authorized', +'connection-rogue-devices'. + +=back + +=cut diff --git a/centreon-plugins/network/ruckus/smartzone/snmp/mode/listaccesspoints.pm b/centreon-plugins/network/ruckus/smartzone/snmp/mode/listaccesspoints.pm new file mode 100644 index 000000000..e51950360 --- /dev/null +++ b/centreon-plugins/network/ruckus/smartzone/snmp/mode/listaccesspoints.pm @@ -0,0 +1,130 @@ +# +# 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 network::ruckus::smartzone::snmp::mode::listaccesspoints; + +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); +} + +my $mapping = { + name => { oid => '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.5' }, # ruckusSZAPName + model => { oid => '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.8' }, # ruckusSZAPModel + serial_number => { oid => '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.9' }, # ruckusSZAPSerial + connection_status => { oid => '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.16' }, # ruckusSZAPConnStatus + registration_status => { oid => '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.17' }, # ruckusSZAPRegStatus + config_status => { oid => '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1.18' }, # ruckusSZAPConfigStatus +}; +my $oid_ruckusSZAPEntry = '.1.3.6.1.4.1.25053.1.4.2.1.1.2.2.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_table( + oid => $oid_ruckusSZAPEntry, + start => $mapping->{name}->{oid}, + end => $mapping->{config_status}->{oid}, + nothing_quit => 1 + ); + + my $accesspoints = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{name}->{oid}\.(.*)$/); + my $instance = $1; + $accesspoints->{$instance} = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + } + + return $accesspoints; +} + +sub run { + my ($self, %options) = @_; + + my $accesspoints = $self->manage_selection(%options); + foreach (sort keys %$accesspoints) { + $self->{output}->output_add( + long_msg => sprintf( + '[name: %s] [serial number: %s] [model: %s] [connection status: %s] [config status: %s] [registration status: %s]', + $accesspoints->{$_}->{name}, + $accesspoints->{$_}->{serial_number}, + $accesspoints->{$_}->{model}, + $accesspoints->{$_}->{connection_status}, + $accesspoints->{$_}->{config_status}, + $accesspoints->{$_}->{registration_status} + ) + ); + } + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List acess points:' + ); + $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 => [keys %$mapping]); +} + +sub disco_show { + my ($self, %options) = @_; + + my $accesspoints = $self->manage_selection(%options); + foreach (sort keys %$accesspoints) { + $self->{output}->add_disco_entry( + %{$accesspoints->{$_}} + ); + } +} + +1; + +__END__ + +=head1 MODE + +List acess points. + +=over 8 + +=back + +=cut + diff --git a/centreon-plugins/network/ruckus/smartzone/snmp/mode/system.pm b/centreon-plugins/network/ruckus/smartzone/snmp/mode/system.pm new file mode 100644 index 000000000..42f89bb79 --- /dev/null +++ b/centreon-plugins/network/ruckus/smartzone/snmp/mode/system.pm @@ -0,0 +1,152 @@ +# +# 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 network::ruckus::smartzone::snmp::mode::system; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +sub system_long_output { + my ($self, %options) = @_; + + return 'checking system '; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'system', type => 3, cb_long_output => 'system_long_output', + indent_long_output => ' ', + group => [ + { name => 'connection', type => 0, skipped_code => { -10 => 1 } }, + { name => 'traffic', type => 0, skipped_code => { -10 => 1 } } + ] + } + ]; + + $self->{maps_counters}->{connection} = [ + { label => 'connection-accesspoints', nlabel => 'system.connection.accesspoints.count', set => { + key_values => [ { name => 'ap' } ], + output_template => 'access points connections: %d', + perfdatas => [ + { value => 'ap_absolute', template => '%d', min => 0 } + ] + } + }, + { label => 'connection-client-devices-authorized', nlabel => 'system.connection.client.devices.authorized.count', set => { + key_values => [ { name => 'authorized_clients' } ], + output_template => 'client devices authorized connections: %d', + perfdatas => [ + { value => 'authorized_clients_absolute', template => '%d', min => 0 } + ] + } + } + ]; + + $self->{maps_counters}->{traffic} = [ + { label => 'traffic-in', nlabel => 'system.traffic.in.bitspersecond', set => { + key_values => [ { name => 'traffic_in', diff => 1 } ], + output_template => 'traffic in: %s%s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_in_per_second', template => '%s', + min => 0, unit => 'b/s' } + ] + } + }, + { label => 'traffic-out', nlabel => 'system.traffic.out.bitspersecond', set => { + key_values => [ { name => 'traffic_out', diff => 1 } ], + output_template => 'traffic in: %s%s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_out_per_second', template => '%s', + min => 0, unit => 'b/s' } + ] + } + } + ]; +} + +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 => { + }); + + return $self; +} + +my $mapping = { + ap => { oid => '.1.3.6.1.4.1.25053.1.4.1.1.1.15.1' }, # ruckusSZSystemStatsNumAP + authorized_clients => { oid => '.1.3.6.1.4.1.25053.1.4.1.1.1.15.2' }, # ruckusSZSystemStatsNumSta + traffic_in => { oid => '.1.3.6.1.4.1.25053.1.4.1.1.1.15.6' }, # ruckusSZSystemStatsWLANTotalRxBytes + traffic_out => { oid => '.1.3.6.1.4.1.25053.1.4.1.1.1.15.9' } # ruckusSZSystemStatsWLANTotalTxBytes +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_leef( + oids => [ map($_->{oid} . '.0', values(%$mapping)) ], + nothing_quit => 1 + ); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => 0); + + $self->{system}->{global} = { + connection => { + ap => $result->{ap}, + authorized_clients => $result->{authorized_clients} + }, + traffic => { + traffic_in => $result->{traffic_in} * 8, + traffic_out => $result->{traffic_out} * 8 + } + }; + + $self->{cache_name} = 'ruckus_smartzone_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_counters_block}) ? md5_hex($self->{option_results}->{filter_counters_block}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check system. + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'traffic-in', 'traffic-out', 'connection-accesspoints', +'connection-client-devices-authorized'. + +=back + +=cut diff --git a/centreon-plugins/network/ruckus/smartzone/snmp/plugin.pm b/centreon-plugins/network/ruckus/smartzone/snmp/plugin.pm new file mode 100644 index 000000000..8edf382f3 --- /dev/null +++ b/centreon-plugins/network/ruckus/smartzone/snmp/plugin.pm @@ -0,0 +1,57 @@ +# +# 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 network::ruckus::smartzone::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.5'; + %{$self->{modes}} = ( + 'access-points' => 'network::ruckus::smartzone::snmp::mode::accesspoints', + 'cpu' => 'snmp_standard::mode::cpu', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-access-points' => 'network::ruckus::smartzone::snmp::mode::listaccesspoints', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-storages' => 'snmp_standard::mode::liststorages', + 'load' => 'snmp_standard::mode::loadaverage', + 'memory' => 'snmp_standard::mode::memory', + 'storage' => 'snmp_standard::mode::storage', + 'system' => 'network::ruckus::smartzone::snmp::mode::system', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Ruckus SmartZone in SNMP. + +=cut From 98a6f27272398c1fc85d321433f085d3d3e96ba4 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 5 May 2020 14:53:41 +0200 Subject: [PATCH 162/190] Break change: move netapp directories - can add some new plugins for netapp --- .../oncommandapi/custom/api.pm} | 12 +-- .../oncommandapi}/mode/aggregateraidstatus.pm | 19 +++-- .../oncommandapi}/mode/aggregatestatus.pm | 19 +++-- .../oncommandapi}/mode/aggregateusage.pm | 16 ++-- .../oncommandapi}/mode/clusterio.pm | 16 ++-- .../oncommandapi}/mode/clusterstatus.pm | 15 ++-- .../oncommandapi}/mode/clusterusage.pm | 14 +--- .../oncommandapi}/mode/diskfailed.pm | 11 ++- .../oncommandapi}/mode/diskspare.pm | 13 ++-- .../oncommandapi}/mode/fcportstatus.pm | 17 ++--- .../oncommandapi}/mode/listaggregates.pm | 17 ++--- .../oncommandapi}/mode/listclusters.pm | 13 ++-- .../oncommandapi}/mode/listfcports.pm | 17 ++--- .../oncommandapi}/mode/listluns.pm | 15 ++-- .../oncommandapi}/mode/listnodes.pm | 13 ++-- .../oncommandapi}/mode/listsnapmirrors.pm | 15 ++-- .../oncommandapi}/mode/listvolumes.pm | 15 ++-- .../oncommandapi}/mode/lunalignment.pm | 11 ++- .../oncommandapi}/mode/lunonline.pm | 11 ++- .../oncommandapi}/mode/lunusage.pm | 8 +- .../oncommandapi}/mode/nodefailoverstatus.pm | 17 ++--- .../oncommandapi}/mode/nodehardwarestatus.pm | 19 +++-- .../oncommandapi}/mode/qtreestatus.pm | 17 ++--- .../oncommandapi}/mode/snapmirrorstatus.pm | 17 ++--- .../oncommandapi}/mode/snapmirrorusage.pm | 9 +-- .../oncommandapi}/mode/volumeio.pm | 17 ++--- .../oncommandapi}/mode/volumestatus.pm | 13 ++-- .../oncommandapi}/mode/volumeusage.pm | 14 ++-- .../netapp/ontap/oncommandapi/plugin.pm | 75 +++++++++++++++++++ .../{ => ontap}/snmp/mode/aggregatestate.pm | 6 +- .../netapp/{ => ontap}/snmp/mode/cacheage.pm | 12 +-- .../snmp/mode/components/communication.pm | 2 +- .../snmp/mode/components/electronics.pm | 2 +- .../{ => ontap}/snmp/mode/components/fan.pm | 2 +- .../{ => ontap}/snmp/mode/components/psu.pm | 2 +- .../{ => ontap}/snmp/mode/components/raid.pm | 2 +- .../snmp/mode/components/temperature.pm | 2 +- .../snmp/mode/components/voltage.pm | 2 +- .../{ => ontap}/snmp/mode/cpstatistics.pm | 2 +- .../netapp/{ => ontap}/snmp/mode/cpuload.pm | 13 ++-- .../{ => ontap}/snmp/mode/diskfailed.pm | 11 ++- .../netapp/{ => ontap}/snmp/mode/failover.pm | 2 +- .../netapp/{ => ontap}/snmp/mode/fan.pm | 11 ++- .../netapp/{ => ontap}/snmp/mode/filesys.pm | 14 ++-- .../{ => ontap}/snmp/mode/globalstatus.pm | 2 +- .../{ => ontap}/snmp/mode/listfilesys.pm | 8 +- .../{ => ontap}/snmp/mode/listsnapvault.pm | 2 +- .../{ => ontap}/snmp/mode/ndmpsessions.pm | 13 ++-- .../netapp/{ => ontap}/snmp/mode/nvram.pm | 11 ++- .../{ => ontap}/snmp/mode/partnerstatus.pm | 11 ++- .../netapp/{ => ontap}/snmp/mode/psu.pm | 26 ++++--- .../{ => ontap}/snmp/mode/qtreeusage.pm | 14 ++-- .../{ => ontap}/snmp/mode/sharecalls.pm | 2 +- .../netapp/{ => ontap}/snmp/mode/shelf.pm | 11 ++- .../netapp/{ => ontap}/snmp/mode/sis.pm | 2 +- .../{ => ontap}/snmp/mode/snapmirrorlag.pm | 2 +- .../{ => ontap}/snmp/mode/snapshotage.pm | 17 ++--- .../{ => ontap}/snmp/mode/snapvaultusage.pm | 10 +-- .../{ => ontap}/snmp/mode/temperature.pm | 24 +++--- .../{ => ontap}/snmp/mode/volumeoptions.pm | 20 ++--- .../storage/netapp/ontap/snmp/plugin.pm | 72 ++++++++++++++++++ .../storage/netapp/restapi/plugin.pm | 75 ------------------- .../storage/netapp/snmp/plugin.pm | 72 ------------------ 63 files changed, 463 insertions(+), 501 deletions(-) rename centreon-plugins/storage/netapp/{restapi/custom/restapi.pm => ontap/oncommandapi/custom/api.pm} (96%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/aggregateraidstatus.pm (89%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/aggregatestatus.pm (89%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/aggregateusage.pm (96%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/clusterio.pm (92%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/clusterstatus.pm (90%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/clusterusage.pm (92%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/diskfailed.pm (93%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/diskspare.pm (93%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/fcportstatus.pm (90%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/listaggregates.pm (91%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/listclusters.pm (91%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/listfcports.pm (90%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/listluns.pm (91%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/listnodes.pm (91%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/listsnapmirrors.pm (91%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/listvolumes.pm (91%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/lunalignment.pm (95%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/lunonline.pm (94%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/lunusage.pm (96%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/nodefailoverstatus.pm (90%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/nodehardwarestatus.pm (89%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/qtreestatus.pm (89%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/snapmirrorstatus.pm (88%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/snapmirrorusage.pm (94%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/volumeio.pm (94%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/volumestatus.pm (88%) rename centreon-plugins/storage/netapp/{restapi => ontap/oncommandapi}/mode/volumeusage.pm (98%) create mode 100644 centreon-plugins/storage/netapp/ontap/oncommandapi/plugin.pm rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/aggregatestate.pm (97%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/cacheage.pm (90%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/components/communication.pm (97%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/components/electronics.pm (97%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/components/fan.pm (98%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/components/psu.pm (97%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/components/raid.pm (97%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/components/temperature.pm (98%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/components/voltage.pm (99%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/cpstatistics.pm (99%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/cpuload.pm (89%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/diskfailed.pm (93%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/failover.pm (99%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/fan.pm (96%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/filesys.pm (97%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/globalstatus.pm (99%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/listfilesys.pm (95%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/listsnapvault.pm (98%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/ndmpsessions.pm (89%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/nvram.pm (95%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/partnerstatus.pm (96%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/psu.pm (82%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/qtreeusage.pm (95%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/sharecalls.pm (98%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/shelf.pm (95%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/sis.pm (99%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/snapmirrorlag.pm (99%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/snapshotage.pm (93%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/snapvaultusage.pm (96%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/temperature.pm (84%) rename centreon-plugins/storage/netapp/{ => ontap}/snmp/mode/volumeoptions.pm (92%) create mode 100644 centreon-plugins/storage/netapp/ontap/snmp/plugin.pm delete mode 100644 centreon-plugins/storage/netapp/restapi/plugin.pm delete mode 100644 centreon-plugins/storage/netapp/snmp/plugin.pm diff --git a/centreon-plugins/storage/netapp/restapi/custom/restapi.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/custom/api.pm similarity index 96% rename from centreon-plugins/storage/netapp/restapi/custom/restapi.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/custom/api.pm index 79808d4c4..e231c59be 100644 --- a/centreon-plugins/storage/netapp/restapi/custom/restapi.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/custom/api.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::restapi::custom::restapi; +package storage::netapp::ontap::oncommandapi::custom::api; use strict; use warnings; @@ -48,10 +48,10 @@ sub new { "proto:s@" => { name => 'proto' }, "username:s@" => { name => 'username' }, "password:s@" => { name => 'password' }, - "timeout:s@" => { name => 'timeout' }, + "timeout:s@" => { name => 'timeout' } }); } - $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); + $options{options}->add_help(package => __PACKAGE__, sections => 'OnCommand API OPTIONS', once => 1); $self->{output} = $options{output}; $self->{mode} = $options{mode}; @@ -202,13 +202,13 @@ __END__ =head1 NAME -NetApp OnCommand REST API +NetApp OnCommand API =head1 SYNOPSIS -NetApp OnCommand Rest API custom mode +NetApp OnCommand API custom mode -=head1 REST API OPTIONS +=head1 OnCommand API OPTIONS =over 8 diff --git a/centreon-plugins/storage/netapp/restapi/mode/aggregateraidstatus.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/aggregateraidstatus.pm similarity index 89% rename from centreon-plugins/storage/netapp/restapi/mode/aggregateraidstatus.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/aggregateraidstatus.pm index 2e5fe5aab..efabba77d 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/aggregateraidstatus.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/aggregateraidstatus.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::restapi::mode::aggregateraidstatus; +package storage::netapp::ontap::oncommandapi::mode::aggregateraidstatus; use base qw(centreon::plugins::templates::counter); @@ -75,15 +75,14 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - "filter-node:s" => { name => 'filter_node' }, - "filter-cluster:s" => { name => 'filter_cluster' }, - "warning-status:s" => { name => 'warning_status' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /normal/i' }, - }); - + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'filter-node:s' => { name => 'filter_node' }, + 'filter-cluster:s' => { name => 'filter_cluster' }, + 'warning-status:s' => { name => 'warning_status' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /normal/i' } + }); + return $self; } diff --git a/centreon-plugins/storage/netapp/restapi/mode/aggregatestatus.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/aggregatestatus.pm similarity index 89% rename from centreon-plugins/storage/netapp/restapi/mode/aggregatestatus.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/aggregatestatus.pm index f8a3c302a..0b4cfc128 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/aggregatestatus.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/aggregatestatus.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::restapi::mode::aggregatestatus; +package storage::netapp::ontap::oncommandapi::mode::aggregatestatus; use base qw(centreon::plugins::templates::counter); @@ -74,15 +74,14 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - "filter-node:s" => { name => 'filter_node' }, - "filter-cluster:s" => { name => 'filter_cluster' }, - "warning-status:s" => { name => 'warning_status' }, - "critical-status:s" => { name => 'critical_status', default => '%{state} !~ /online/i' }, - }); - + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'filter-node:s' => { name => 'filter_node' }, + 'filter-cluster:s' => { name => 'filter_cluster' }, + 'warning-status:s' => { name => 'warning_status' }, + 'critical-status:s' => { name => 'critical_status', default => '%{state} !~ /online/i' } + }); + return $self; } diff --git a/centreon-plugins/storage/netapp/restapi/mode/aggregateusage.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/aggregateusage.pm similarity index 96% rename from centreon-plugins/storage/netapp/restapi/mode/aggregateusage.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/aggregateusage.pm index 0d40d551e..98343674c 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/aggregateusage.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/aggregateusage.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::restapi::mode::aggregateusage; +package storage::netapp::ontap::oncommandapi::mode::aggregateusage; use base qw(centreon::plugins::templates::counter); @@ -190,13 +190,13 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, - "filter-node:s" => { name => 'filter_node' }, - "filter-cluster:s" => { name => 'filter_cluster' }, - "filter-state:s" => { name => 'filter_state' }, - "filter-type:s" => { name => 'filter_type' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, + 'filter-name:s' => { name => 'filter_name' }, + 'filter-node:s' => { name => 'filter_node' }, + 'filter-cluster:s' => { name => 'filter_cluster' }, + 'filter-state:s' => { name => 'filter_state' }, + 'filter-type:s' => { name => 'filter_type' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' } }); return $self; diff --git a/centreon-plugins/storage/netapp/restapi/mode/clusterio.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/clusterio.pm similarity index 92% rename from centreon-plugins/storage/netapp/restapi/mode/clusterio.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/clusterio.pm index 8d1d7098b..93b09c122 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/clusterio.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/clusterio.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::restapi::mode::clusterio; +package storage::netapp::ontap::oncommandapi::mode::clusterio; use base qw(centreon::plugins::templates::counter); @@ -66,17 +66,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); - - return $self; -} + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' } + }); -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); + return $self; } sub manage_selection { diff --git a/centreon-plugins/storage/netapp/restapi/mode/clusterstatus.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/clusterstatus.pm similarity index 90% rename from centreon-plugins/storage/netapp/restapi/mode/clusterstatus.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/clusterstatus.pm index 204125de0..6669aaa4b 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/clusterstatus.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/clusterstatus.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::restapi::mode::clusterstatus; +package storage::netapp::ontap::oncommandapi::mode::clusterstatus; use base qw(centreon::plugins::templates::counter); @@ -77,13 +77,12 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /ok/i' }, - }); - + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'warning-status:s' => { name => 'warning_status' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /ok/i' }, + }); + return $self; } diff --git a/centreon-plugins/storage/netapp/restapi/mode/clusterusage.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/clusterusage.pm similarity index 92% rename from centreon-plugins/storage/netapp/restapi/mode/clusterusage.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/clusterusage.pm index e1fa5b455..a90f45f24 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/clusterusage.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/clusterusage.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::restapi::mode::clusterusage; +package storage::netapp::ontap::oncommandapi::mode::clusterusage; use base qw(centreon::plugins::templates::counter); @@ -65,19 +65,13 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' } + }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); -} - sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/storage/netapp/restapi/mode/diskfailed.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/diskfailed.pm similarity index 93% rename from centreon-plugins/storage/netapp/restapi/mode/diskfailed.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/diskfailed.pm index a889a8c3c..6ba8e3680 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/diskfailed.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/diskfailed.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::restapi::mode::diskfailed; +package storage::netapp::ontap::oncommandapi::mode::diskfailed; use base qw(centreon::plugins::templates::counter); @@ -59,11 +59,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-node:s" => { name => 'filter_node' }, - "filter-cluster:s" => { name => 'filter_cluster' }, - }); + $options{options}->add_options(arguments => { + 'filter-node:s' => { name => 'filter_node' }, + 'filter-cluster:s' => { name => 'filter_cluster' } + }); return $self; } diff --git a/centreon-plugins/storage/netapp/restapi/mode/diskspare.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/diskspare.pm similarity index 93% rename from centreon-plugins/storage/netapp/restapi/mode/diskspare.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/diskspare.pm index f374105f3..49fa4ffb1 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/diskspare.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/diskspare.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::restapi::mode::diskspare; +package storage::netapp::ontap::oncommandapi::mode::diskspare; use base qw(centreon::plugins::templates::counter); @@ -68,12 +68,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-node:s" => { name => 'filter_node' }, - "filter-cluster:s" => { name => 'filter_cluster' }, - }); - + $options{options}->add_options(arguments => { + 'filter-node:s' => { name => 'filter_node' }, + 'filter-cluster:s' => { name => 'filter_cluster' } + }); + return $self; } diff --git a/centreon-plugins/storage/netapp/restapi/mode/fcportstatus.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/fcportstatus.pm similarity index 90% rename from centreon-plugins/storage/netapp/restapi/mode/fcportstatus.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/fcportstatus.pm index 2fb447760..91e9892ea 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/fcportstatus.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/fcportstatus.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::restapi::mode::fcportstatus; +package storage::netapp::ontap::oncommandapi::mode::fcportstatus; use base qw(centreon::plugins::templates::counter); @@ -78,14 +78,13 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /online/i || %{state} !~ /online/i' }, - }); - + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'warning-status:s' => { name => 'warning_status' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /online/i || %{state} !~ /online/i' }, + }); + return $self; } diff --git a/centreon-plugins/storage/netapp/restapi/mode/listaggregates.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/listaggregates.pm similarity index 91% rename from centreon-plugins/storage/netapp/restapi/mode/listaggregates.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/listaggregates.pm index ad6d9523b..5ecff30f3 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/listaggregates.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/listaggregates.pm @@ -18,9 +18,9 @@ # limitations under the License. # -package storage::netapp::restapi::mode::listaggregates; +package storage::netapp::ontap::oncommandapi::mode::listaggregates; -use base qw(centreon::plugins::templates::counter); +use base qw(centreon::plugins::mode); use strict; use warnings; @@ -30,19 +30,18 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - "filter-node:s" => { name => 'filter_node' }, - "filter-cluster:s" => { name => 'filter_cluster' }, - }); + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'filter-node:s' => { name => 'filter_node' }, + 'filter-cluster:s' => { name => 'filter_cluster' } + }); return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::check_options(%options); + $self->SUPER::init(%options); } sub manage_selection { diff --git a/centreon-plugins/storage/netapp/restapi/mode/listclusters.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/listclusters.pm similarity index 91% rename from centreon-plugins/storage/netapp/restapi/mode/listclusters.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/listclusters.pm index e53c40921..8a37cfcdf 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/listclusters.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/listclusters.pm @@ -18,9 +18,9 @@ # limitations under the License. # -package storage::netapp::restapi::mode::listclusters; +package storage::netapp::ontap::oncommandapi::mode::listclusters; -use base qw(centreon::plugins::templates::counter); +use base qw(centreon::plugins::mode); use strict; use warnings; @@ -30,17 +30,16 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' } + }); return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::check_options(%options); + $self->SUPER::init(%options); } sub manage_selection { diff --git a/centreon-plugins/storage/netapp/restapi/mode/listfcports.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/listfcports.pm similarity index 90% rename from centreon-plugins/storage/netapp/restapi/mode/listfcports.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/listfcports.pm index cfa4d1f2a..6d6db9dc4 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/listfcports.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/listfcports.pm @@ -18,9 +18,9 @@ # limitations under the License. # -package storage::netapp::restapi::mode::listfcports; +package storage::netapp::ontap::oncommandapi::mode::listfcports; -use base qw(centreon::plugins::templates::counter); +use base qw(centreon::plugins::mode); use strict; use warnings; @@ -29,18 +29,17 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); - + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' } + }); + return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::check_options(%options); + $self->SUPER::init(%options); } sub manage_selection { diff --git a/centreon-plugins/storage/netapp/restapi/mode/listluns.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/listluns.pm similarity index 91% rename from centreon-plugins/storage/netapp/restapi/mode/listluns.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/listluns.pm index e32683eaa..f1573d14f 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/listluns.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/listluns.pm @@ -18,9 +18,9 @@ # limitations under the License. # -package storage::netapp::restapi::mode::listluns; +package storage::netapp::ontap::oncommandapi::mode::listluns; -use base qw(centreon::plugins::templates::counter); +use base qw(centreon::plugins::mode); use strict; use warnings; @@ -30,17 +30,16 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); - + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' } + }); + return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::check_options(%options); + $self->SUPER::init(%options); } sub manage_selection { diff --git a/centreon-plugins/storage/netapp/restapi/mode/listnodes.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/listnodes.pm similarity index 91% rename from centreon-plugins/storage/netapp/restapi/mode/listnodes.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/listnodes.pm index 2582ac4d5..3aa48728b 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/listnodes.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/listnodes.pm @@ -18,9 +18,9 @@ # limitations under the License. # -package storage::netapp::restapi::mode::listnodes; +package storage::netapp::ontap::oncommandapi::mode::listnodes; -use base qw(centreon::plugins::templates::counter); +use base qw(centreon::plugins::mode); use strict; use warnings; @@ -30,17 +30,16 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' } + }); return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::check_options(%options); + $self->SUPER::init(%options); } sub manage_selection { diff --git a/centreon-plugins/storage/netapp/restapi/mode/listsnapmirrors.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/listsnapmirrors.pm similarity index 91% rename from centreon-plugins/storage/netapp/restapi/mode/listsnapmirrors.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/listsnapmirrors.pm index 9c7fbdabf..4daaa6ec3 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/listsnapmirrors.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/listsnapmirrors.pm @@ -18,9 +18,9 @@ # limitations under the License. # -package storage::netapp::restapi::mode::listsnapmirrors; +package storage::netapp::ontap::oncommandapi::mode::listsnapmirrors; -use base qw(centreon::plugins::templates::counter); +use base qw(centreon::plugins::mode); use strict; use warnings; @@ -30,17 +30,16 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); - + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' } + }); + return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::check_options(%options); + $self->SUPER::init(%options); } sub manage_selection { diff --git a/centreon-plugins/storage/netapp/restapi/mode/listvolumes.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/listvolumes.pm similarity index 91% rename from centreon-plugins/storage/netapp/restapi/mode/listvolumes.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/listvolumes.pm index 5e691600f..9aef0f99b 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/listvolumes.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/listvolumes.pm @@ -18,9 +18,9 @@ # limitations under the License. # -package storage::netapp::restapi::mode::listvolumes; +package storage::netapp::ontap::oncommandapi::mode::listvolumes; -use base qw(centreon::plugins::templates::counter); +use base qw(centreon::plugins::mode); use strict; use warnings; @@ -30,17 +30,16 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); - + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' } + }); + return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::check_options(%options); + $self->SUPER::init(%options); } sub manage_selection { diff --git a/centreon-plugins/storage/netapp/restapi/mode/lunalignment.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/lunalignment.pm similarity index 95% rename from centreon-plugins/storage/netapp/restapi/mode/lunalignment.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/lunalignment.pm index 7107e6aca..b2604736a 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/lunalignment.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/lunalignment.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::restapi::mode::lunalignment; +package storage::netapp::ontap::oncommandapi::mode::lunalignment; use base qw(centreon::plugins::templates::counter); @@ -95,11 +95,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-volume:s" => { name => 'filter_volume' }, - }); - + $options{options}->add_options(arguments => { + 'filter-volume:s' => { name => 'filter_volume' } + }); + return $self; } diff --git a/centreon-plugins/storage/netapp/restapi/mode/lunonline.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/lunonline.pm similarity index 94% rename from centreon-plugins/storage/netapp/restapi/mode/lunonline.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/lunonline.pm index 4081006f1..b587ebed7 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/lunonline.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/lunonline.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::restapi::mode::lunonline; +package storage::netapp::ontap::oncommandapi::mode::lunonline; use base qw(centreon::plugins::templates::counter); @@ -77,11 +77,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-volume:s" => { name => 'filter_volume' }, - }); - + $options{options}->add_options(arguments => { + 'filter-volume:s' => { name => 'filter_volume' } + }); + return $self; } diff --git a/centreon-plugins/storage/netapp/restapi/mode/lunusage.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/lunusage.pm similarity index 96% rename from centreon-plugins/storage/netapp/restapi/mode/lunusage.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/lunusage.pm index bb29b6b78..670374608 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/lunusage.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/lunusage.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::restapi::mode::lunusage; +package storage::netapp::ontap::oncommandapi::mode::lunusage; use base qw(centreon::plugins::templates::counter); @@ -119,9 +119,9 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, + 'filter-name:s' => { name => 'filter_name' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' } }); return $self; diff --git a/centreon-plugins/storage/netapp/restapi/mode/nodefailoverstatus.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/nodefailoverstatus.pm similarity index 90% rename from centreon-plugins/storage/netapp/restapi/mode/nodefailoverstatus.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/nodefailoverstatus.pm index 284ff0f04..b29e252f9 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/nodefailoverstatus.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/nodefailoverstatus.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::restapi::mode::nodefailoverstatus; +package storage::netapp::ontap::oncommandapi::mode::nodefailoverstatus; use base qw(centreon::plugins::templates::counter); @@ -80,14 +80,13 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - "filter-cluster:s" => { name => 'filter_cluster' }, - "warning-status:s" => { name => 'warning_status' }, - "critical-status:s" => { name => 'critical_status', default => '%{state} !~ /connected/i || %{interconnect} !~ /up/i'}, - }); - + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'filter-cluster:s' => { name => 'filter_cluster' }, + 'warning-status:s' => { name => 'warning_status' }, + 'critical-status:s' => { name => 'critical_status', default => '%{state} !~ /connected/i || %{interconnect} !~ /up/i'} + }); + return $self; } diff --git a/centreon-plugins/storage/netapp/restapi/mode/nodehardwarestatus.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/nodehardwarestatus.pm similarity index 89% rename from centreon-plugins/storage/netapp/restapi/mode/nodehardwarestatus.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/nodehardwarestatus.pm index ca92f5068..73cff9aa7 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/nodehardwarestatus.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/nodehardwarestatus.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::restapi::mode::nodehardwarestatus; +package storage::netapp::ontap::oncommandapi::mode::nodehardwarestatus; use base qw(centreon::plugins::templates::counter); @@ -96,15 +96,14 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - "filter-cluster:s" => { name => 'filter_cluster' }, - "warning-status:s" => { name => 'warning_status' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /not healthy/i || ' . - '%{temperature} !~ /ok/i || %{battery_status} !~ /battery_ok|battery_fully_charge|battery_over_charged/i' }, - }); - + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'filter-cluster:s' => { name => 'filter_cluster' }, + 'warning-status:s' => { name => 'warning_status' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /not healthy/i || ' . + '%{temperature} !~ /ok/i || %{battery_status} !~ /battery_ok|battery_fully_charge|battery_over_charged/i' }, + }); + return $self; } diff --git a/centreon-plugins/storage/netapp/restapi/mode/qtreestatus.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/qtreestatus.pm similarity index 89% rename from centreon-plugins/storage/netapp/restapi/mode/qtreestatus.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/qtreestatus.pm index 28140e10b..f74c34678 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/qtreestatus.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/qtreestatus.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::restapi::mode::qtreestatus; +package storage::netapp::ontap::oncommandapi::mode::qtreestatus; use base qw(centreon::plugins::templates::counter); @@ -77,14 +77,13 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - "filter-volume:s" => { name => 'filter_volume' }, - "warning-status:s" => { name => 'warning_status' }, - "critical-status:s" => { name => 'critical_status' }, - }); - + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'filter-volume:s' => { name => 'filter_volume' }, + 'warning-status:s' => { name => 'warning_status' }, + 'critical-status:s' => { name => 'critical_status' } + }); + return $self; } diff --git a/centreon-plugins/storage/netapp/restapi/mode/snapmirrorstatus.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/snapmirrorstatus.pm similarity index 88% rename from centreon-plugins/storage/netapp/restapi/mode/snapmirrorstatus.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/snapmirrorstatus.pm index 11c42f7e0..e193f4ec2 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/snapmirrorstatus.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/snapmirrorstatus.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::restapi::mode::snapmirrorstatus; +package storage::netapp::ontap::oncommandapi::mode::snapmirrorstatus; use base qw(centreon::plugins::templates::counter); @@ -72,14 +72,13 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status' }, - "critical-status:s" => { name => 'critical_status', default => '%{state} !~ /snapmirrored/i || %{update} =~ /not healthy/i' }, - }); - + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'warning-status:s' => { name => 'warning_status' }, + 'critical-status:s' => { name => 'critical_status', default => '%{state} !~ /snapmirrored/i || %{update} =~ /not healthy/i' }, + }); + return $self; } diff --git a/centreon-plugins/storage/netapp/restapi/mode/snapmirrorusage.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/snapmirrorusage.pm similarity index 94% rename from centreon-plugins/storage/netapp/restapi/mode/snapmirrorusage.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/snapmirrorusage.pm index f10fd42eb..b035117fd 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/snapmirrorusage.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/snapmirrorusage.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::restapi::mode::snapmirrorusage; +package storage::netapp::ontap::oncommandapi::mode::snapmirrorusage; use base qw(centreon::plugins::templates::counter); @@ -75,10 +75,9 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' } + }); return $self; } diff --git a/centreon-plugins/storage/netapp/restapi/mode/volumeio.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/volumeio.pm similarity index 94% rename from centreon-plugins/storage/netapp/restapi/mode/volumeio.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/volumeio.pm index bef4bd515..674020deb 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/volumeio.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/volumeio.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::restapi::mode::volumeio; +package storage::netapp::ontap::oncommandapi::mode::volumeio; use base qw(centreon::plugins::templates::counter); @@ -110,14 +110,13 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - "filter-state:s" => { name => 'filter_state' }, - "filter-style:s" => { name => 'filter_style' }, - "filter-type:s" => { name => 'filter_type' }, - }); - + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'filter-state:s' => { name => 'filter_state' }, + 'filter-style:s' => { name => 'filter_style' }, + 'filter-type:s' => { name => 'filter_type' } + }); + return $self; } diff --git a/centreon-plugins/storage/netapp/restapi/mode/volumestatus.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/volumestatus.pm similarity index 88% rename from centreon-plugins/storage/netapp/restapi/mode/volumestatus.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/volumestatus.pm index 7d0788a35..be5fe5f38 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/volumestatus.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/volumestatus.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::restapi::mode::volumestatus; +package storage::netapp::ontap::oncommandapi::mode::volumestatus; use base qw(centreon::plugins::templates::counter); @@ -73,12 +73,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status' }, - "critical-status:s" => { name => 'critical_status', default => '%{state} !~ /online/i' }, - }); + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'warning-status:s' => { name => 'warning_status' }, + 'critical-status:s' => { name => 'critical_status', default => '%{state} !~ /online/i' }, + }); return $self; } diff --git a/centreon-plugins/storage/netapp/restapi/mode/volumeusage.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/volumeusage.pm similarity index 98% rename from centreon-plugins/storage/netapp/restapi/mode/volumeusage.pm rename to centreon-plugins/storage/netapp/ontap/oncommandapi/mode/volumeusage.pm index a17a9053b..8b0e6a76f 100644 --- a/centreon-plugins/storage/netapp/restapi/mode/volumeusage.pm +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/mode/volumeusage.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::restapi::mode::volumeusage; +package storage::netapp::ontap::oncommandapi::mode::volumeusage; use base qw(centreon::plugins::templates::counter); @@ -371,12 +371,12 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, - "filter-state:s" => { name => 'filter_state' }, - "filter-style:s" => { name => 'filter_style' }, - "filter-type:s" => { name => 'filter_type' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, + 'filter-name:s' => { name => 'filter_name' }, + 'filter-state:s' => { name => 'filter_state' }, + 'filter-style:s' => { name => 'filter_style' }, + 'filter-type:s' => { name => 'filter_type' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' } }); return $self; diff --git a/centreon-plugins/storage/netapp/ontap/oncommandapi/plugin.pm b/centreon-plugins/storage/netapp/ontap/oncommandapi/plugin.pm new file mode 100644 index 000000000..4ad4c4235 --- /dev/null +++ b/centreon-plugins/storage/netapp/ontap/oncommandapi/plugin.pm @@ -0,0 +1,75 @@ +# +# 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 storage::netapp::ontap::oncommandapi::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} = '1.0'; + %{$self->{modes}} = ( + 'aggregate-raid-status' => 'storage::netapp::ontap::oncommandapi::mode::aggregateraidstatus', + 'aggregate-status' => 'storage::netapp::ontap::oncommandapi::mode::aggregatestatus', + 'aggregate-usage' => 'storage::netapp::ontap::oncommandapi::mode::aggregateusage', + 'cluster-io' => 'storage::netapp::ontap::oncommandapi::mode::clusterio', + 'cluster-status' => 'storage::netapp::ontap::oncommandapi::mode::clusterstatus', + 'cluster-usage' => 'storage::netapp::ontap::oncommandapi::mode::clusterusage', + 'disk-failed' => 'storage::netapp::ontap::oncommandapi::mode::diskfailed', + 'disk-spare' => 'storage::netapp::ontap::oncommandapi::mode::diskspare', + 'fc-port-status' => 'storage::netapp::ontap::oncommandapi::mode::fcportstatus', + 'list-aggregates' => 'storage::netapp::ontap::oncommandapi::mode::listaggregates', + 'list-clusters' => 'storage::netapp::ontap::oncommandapi::mode::listclusters', + 'list-fc-ports' => 'storage::netapp::ontap::oncommandapi::mode::listfcports', + 'list-luns' => 'storage::netapp::ontap::oncommandapi::mode::listluns', + 'list-nodes' => 'storage::netapp::ontap::oncommandapi::mode::listnodes', + 'list-snapmirrors' => 'storage::netapp::ontap::oncommandapi::mode::listsnapmirrors', + 'list-volumes' => 'storage::netapp::ontap::oncommandapi::mode::listvolumes', + 'lun-alignment' => 'storage::netapp::ontap::oncommandapi::mode::lunalignment', + 'lun-online' => 'storage::netapp::ontap::oncommandapi::mode::lunonline', + 'lun-usage' => 'storage::netapp::ontap::oncommandapi::mode::lunusage', + 'node-failover-status' => 'storage::netapp::ontap::oncommandapi::mode::nodefailoverstatus', + 'node-hardware-status' => 'storage::netapp::ontap::oncommandapi::mode::nodehardwarestatus', + 'qtree-status' => 'storage::netapp::ontap::oncommandapi::mode::qtreestatus', + 'snapmirror-status' => 'storage::netapp::ontap::oncommandapi::mode::snapmirrorstatus', + 'snapmirror-usage' => 'storage::netapp::ontap::oncommandapi::mode::snapmirrorusage', + 'volume-io' => 'storage::netapp::ontap::oncommandapi::mode::volumeio', + 'volume-status' => 'storage::netapp::ontap::oncommandapi::mode::volumestatus', + 'volume-usage' => 'storage::netapp::ontap::oncommandapi::mode::volumeusage' + ); + + $self->{custom_modes}{api} = 'storage::netapp::ontap::oncommandapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check NetApp ONTAP with OnCommand API. + +=cut diff --git a/centreon-plugins/storage/netapp/snmp/mode/aggregatestate.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/aggregatestate.pm similarity index 97% rename from centreon-plugins/storage/netapp/snmp/mode/aggregatestate.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/aggregatestate.pm index a87b0d1bf..823eeab8e 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/aggregatestate.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/aggregatestate.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::aggregatestate; +package storage::netapp::ontap::snmp::mode::aggregatestate; use base qw(centreon::plugins::templates::counter); @@ -92,8 +92,8 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, + 'filter-name:s' => { name => 'filter_name' }, + 'threshold-overload:s@' => { name => 'threshold_overload' }, }); return $self; diff --git a/centreon-plugins/storage/netapp/snmp/mode/cacheage.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/cacheage.pm similarity index 90% rename from centreon-plugins/storage/netapp/snmp/mode/cacheage.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/cacheage.pm index 42a635250..4179acdfd 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/cacheage.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/cacheage.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::cacheage; +package storage::netapp::ontap::snmp::mode::cacheage; use base qw(centreon::plugins::mode); @@ -30,11 +30,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } + }); + return $self; } diff --git a/centreon-plugins/storage/netapp/snmp/mode/components/communication.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/components/communication.pm similarity index 97% rename from centreon-plugins/storage/netapp/snmp/mode/components/communication.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/components/communication.pm index af300bd00..7ade3583c 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/components/communication.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/components/communication.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::components::communication; +package storage::netapp::ontap::snmp::mode::components::communication; use base qw(centreon::plugins::mode); diff --git a/centreon-plugins/storage/netapp/snmp/mode/components/electronics.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/components/electronics.pm similarity index 97% rename from centreon-plugins/storage/netapp/snmp/mode/components/electronics.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/components/electronics.pm index baa71f596..26a46f461 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/components/electronics.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/components/electronics.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::components::electronics; +package storage::netapp::ontap::snmp::mode::components::electronics; use base qw(centreon::plugins::mode); diff --git a/centreon-plugins/storage/netapp/snmp/mode/components/fan.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/components/fan.pm similarity index 98% rename from centreon-plugins/storage/netapp/snmp/mode/components/fan.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/components/fan.pm index adaad1e0e..0bbb27e8d 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/components/fan.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/components/fan.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::components::fan; +package storage::netapp::ontap::snmp::mode::components::fan; use base qw(centreon::plugins::mode); diff --git a/centreon-plugins/storage/netapp/snmp/mode/components/psu.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/components/psu.pm similarity index 97% rename from centreon-plugins/storage/netapp/snmp/mode/components/psu.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/components/psu.pm index 976d6128d..af0e15c2c 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/components/psu.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/components/psu.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::components::psu; +package storage::netapp::ontap::snmp::mode::components::psu; use base qw(centreon::plugins::mode); diff --git a/centreon-plugins/storage/netapp/snmp/mode/components/raid.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/components/raid.pm similarity index 97% rename from centreon-plugins/storage/netapp/snmp/mode/components/raid.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/components/raid.pm index b45687a41..81f6d444d 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/components/raid.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/components/raid.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::components::raid; +package storage::netapp::ontap::snmp::mode::components::raid; use base qw(centreon::plugins::mode); diff --git a/centreon-plugins/storage/netapp/snmp/mode/components/temperature.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/components/temperature.pm similarity index 98% rename from centreon-plugins/storage/netapp/snmp/mode/components/temperature.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/components/temperature.pm index a65fe4520..07ab84fed 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/components/temperature.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/components/temperature.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::components::temperature; +package storage::netapp::ontap::snmp::mode::components::temperature; use strict; use warnings; diff --git a/centreon-plugins/storage/netapp/snmp/mode/components/voltage.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/components/voltage.pm similarity index 99% rename from centreon-plugins/storage/netapp/snmp/mode/components/voltage.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/components/voltage.pm index 44cb565d0..7c005ef84 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/components/voltage.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/components/voltage.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::components::voltage; +package storage::netapp::ontap::snmp::mode::components::voltage; use strict; use warnings; diff --git a/centreon-plugins/storage/netapp/snmp/mode/cpstatistics.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/cpstatistics.pm similarity index 99% rename from centreon-plugins/storage/netapp/snmp/mode/cpstatistics.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/cpstatistics.pm index ee376e7c6..bf5d06254 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/cpstatistics.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/cpstatistics.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::cpstatistics; +package storage::netapp::ontap::snmp::mode::cpstatistics; use base qw(centreon::plugins::templates::counter); diff --git a/centreon-plugins/storage/netapp/snmp/mode/cpuload.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/cpuload.pm similarity index 89% rename from centreon-plugins/storage/netapp/snmp/mode/cpuload.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/cpuload.pm index 3e72d960f..3618e3f55 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/cpuload.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/cpuload.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::cpuload; +package storage::netapp::ontap::snmp::mode::cpuload; use base qw(centreon::plugins::mode); @@ -30,11 +30,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } + }); return $self; } @@ -94,4 +93,4 @@ Threshold critical in percent. =back =cut - \ No newline at end of file + diff --git a/centreon-plugins/storage/netapp/snmp/mode/diskfailed.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/diskfailed.pm similarity index 93% rename from centreon-plugins/storage/netapp/snmp/mode/diskfailed.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/diskfailed.pm index 7bc508245..9d598479d 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/diskfailed.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/diskfailed.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::diskfailed; +package storage::netapp::ontap::snmp::mode::diskfailed; use base qw(centreon::plugins::mode); @@ -29,10 +29,9 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - }); + + $options{options}->add_options(arguments => { + }); return $self; } @@ -81,4 +80,4 @@ If you are in cluster mode, the following mode doesn't work. Ask to netapp to ad =back =cut - \ No newline at end of file + diff --git a/centreon-plugins/storage/netapp/snmp/mode/failover.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/failover.pm similarity index 99% rename from centreon-plugins/storage/netapp/snmp/mode/failover.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/failover.pm index af106abf5..cfb350a99 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/failover.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/failover.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::failover; +package storage::netapp::ontap::snmp::mode::failover; use base qw(centreon::plugins::templates::counter); diff --git a/centreon-plugins/storage/netapp/snmp/mode/fan.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/fan.pm similarity index 96% rename from centreon-plugins/storage/netapp/snmp/mode/fan.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/fan.pm index 4da8e0931..911d155b2 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/fan.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/fan.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::fan; +package storage::netapp::ontap::snmp::mode::fan; use base qw(centreon::plugins::mode); @@ -29,10 +29,9 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - }); + + $options{options}->add_options(arguments => { + }); return $self; } @@ -104,4 +103,4 @@ Check if fans are failed (not operating within the recommended RPM range). =back =cut - \ No newline at end of file + diff --git a/centreon-plugins/storage/netapp/snmp/mode/filesys.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/filesys.pm similarity index 97% rename from centreon-plugins/storage/netapp/snmp/mode/filesys.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/filesys.pm index ec864f19d..b197795b9 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/filesys.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/filesys.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::filesys; +package storage::netapp::ontap::snmp::mode::filesys; use base qw(centreon::plugins::templates::counter); @@ -186,12 +186,12 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'units:s' => { name => 'units', default => '%' }, - 'free' => { name => 'free' }, - 'filter-name:s' => { name => 'filter_name' }, - 'filter-type:s' => { name => 'filter_type' }, - 'filter-vserver:s' => { name => 'filter_vserver' }, - 'filter-vserver-state:s' => { name => 'filter_vserver_state' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' }, + 'filter-name:s' => { name => 'filter_name' }, + 'filter-type:s' => { name => 'filter_type' }, + 'filter-vserver:s' => { name => 'filter_vserver' }, + 'filter-vserver-state:s' => { name => 'filter_vserver_state' }, 'unknown-vserver-status:s' => { name => 'unknown_vserver_status', default => '' }, 'warning-vserver-status:s' => { name => 'warning_vserver_status', default => '' }, 'critical-vserver-status:s' => { name => 'critical_vserver_status', default => '' }, diff --git a/centreon-plugins/storage/netapp/snmp/mode/globalstatus.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/globalstatus.pm similarity index 99% rename from centreon-plugins/storage/netapp/snmp/mode/globalstatus.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/globalstatus.pm index 476f1a798..7aead567f 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/globalstatus.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/globalstatus.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::globalstatus; +package storage::netapp::ontap::snmp::mode::globalstatus; use base qw(centreon::plugins::templates::counter); diff --git a/centreon-plugins/storage/netapp/snmp/mode/listfilesys.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/listfilesys.pm similarity index 95% rename from centreon-plugins/storage/netapp/snmp/mode/listfilesys.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/listfilesys.pm index 606864535..3885646a9 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/listfilesys.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/listfilesys.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::listfilesys; +package storage::netapp::ontap::snmp::mode::listfilesys; use base qw(centreon::plugins::mode); @@ -31,9 +31,9 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'filter-name:s' => { name => 'filter_name' }, - 'filter-type:s' => { name => 'filter_type' }, - 'skip-total-zero' => { name => 'skip_total_zero' }, + 'filter-name:s' => { name => 'filter_name' }, + 'filter-type:s' => { name => 'filter_type' }, + 'skip-total-zero' => { name => 'skip_total_zero' } }); return $self; diff --git a/centreon-plugins/storage/netapp/snmp/mode/listsnapvault.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/listsnapvault.pm similarity index 98% rename from centreon-plugins/storage/netapp/snmp/mode/listsnapvault.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/listsnapvault.pm index 56b89f058..8c2ce7957 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/listsnapvault.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/listsnapvault.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::listsnapvault; +package storage::netapp::ontap::snmp::mode::listsnapvault; use base qw(centreon::plugins::mode); diff --git a/centreon-plugins/storage/netapp/snmp/mode/ndmpsessions.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/ndmpsessions.pm similarity index 89% rename from centreon-plugins/storage/netapp/snmp/mode/ndmpsessions.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/ndmpsessions.pm index 5876197c8..a84a75a2e 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/ndmpsessions.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/ndmpsessions.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::ndmpsessions; +package storage::netapp::ontap::snmp::mode::ndmpsessions; use base qw(centreon::plugins::mode); @@ -30,11 +30,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } + }); return $self; } @@ -94,4 +93,4 @@ Threshold critical. =back =cut - \ No newline at end of file + diff --git a/centreon-plugins/storage/netapp/snmp/mode/nvram.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/nvram.pm similarity index 95% rename from centreon-plugins/storage/netapp/snmp/mode/nvram.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/nvram.pm index 1251c00f9..822b8198d 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/nvram.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/nvram.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::nvram; +package storage::netapp::ontap::snmp::mode::nvram; use base qw(centreon::plugins::mode); @@ -56,10 +56,9 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "threshold-overload:s@" => { name => 'threshold_overload' }, - }); + $options{options}->add_options(arguments => { + 'threshold-overload:s@' => { name => 'threshold_overload' }, + }); return $self; } @@ -172,4 +171,4 @@ Example: --threshold-overload='nvram,CRITICAL,^(?!(ok)$)' =back =cut - \ No newline at end of file + diff --git a/centreon-plugins/storage/netapp/snmp/mode/partnerstatus.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/partnerstatus.pm similarity index 96% rename from centreon-plugins/storage/netapp/snmp/mode/partnerstatus.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/partnerstatus.pm index 04e8a4f01..f9fda6ba0 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/partnerstatus.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/partnerstatus.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::partnerstatus; +package storage::netapp::ontap::snmp::mode::partnerstatus; use base qw(centreon::plugins::mode); @@ -55,10 +55,9 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "threshold-overload:s@" => { name => 'threshold_overload' }, - }); + $options{options}->add_options(arguments => { + 'threshold-overload:s@' => { name => 'threshold_overload' }, + }); return $self; } @@ -196,4 +195,4 @@ Example: --threshold-overload='partner,CRITICAL,^(?!(ok)$)' =back =cut - \ No newline at end of file + diff --git a/centreon-plugins/storage/netapp/snmp/mode/psu.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/psu.pm similarity index 82% rename from centreon-plugins/storage/netapp/snmp/mode/psu.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/psu.pm index 9b922ce07..afc08db3a 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/psu.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/psu.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::psu; +package storage::netapp::ontap::snmp::mode::psu; use base qw(centreon::plugins::mode); @@ -30,9 +30,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - }); + $options{options}->add_options(arguments => { + }); return $self; } @@ -51,13 +50,16 @@ sub run { my $oid_nodeName = '.1.3.6.1.4.1.789.1.25.2.1.1'; my $oid_nodeEnvFailedPowerSupplyCount = '.1.3.6.1.4.1.789.1.25.2.1.21'; my $oid_nodeEnvFailedPowerSupplyMessage = '.1.3.6.1.4.1.789.1.25.2.1.22'; - my $results = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_envFailedPowerSupplyCount }, - { oid => $oid_envFailedPowerSupplyMessage }, - { oid => $oid_nodeName }, - { oid => $oid_nodeEnvFailedPowerSupplyCount }, - { oid => $oid_nodeEnvFailedPowerSupplyMessage } - ], nothing_quit => 1); + my $results = $self->{snmp}->get_multiple_table( + oids => [ + { oid => $oid_envFailedPowerSupplyCount }, + { oid => $oid_envFailedPowerSupplyMessage }, + { oid => $oid_nodeName }, + { oid => $oid_nodeEnvFailedPowerSupplyCount }, + { oid => $oid_nodeEnvFailedPowerSupplyMessage } + ], + nothing_quit => 1 + ); if (defined($results->{$oid_envFailedPowerSupplyCount}->{$oid_envFailedPowerSupplyCount . '.0'})) { $self->{output}->output_add(severity => 'OK', @@ -104,4 +106,4 @@ Check if power supplies are failed (in degraded mode). =back =cut - \ No newline at end of file + diff --git a/centreon-plugins/storage/netapp/snmp/mode/qtreeusage.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/qtreeusage.pm similarity index 95% rename from centreon-plugins/storage/netapp/snmp/mode/qtreeusage.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/qtreeusage.pm index 921dc4784..9271687a4 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/qtreeusage.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/qtreeusage.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::qtreeusage; +package storage::netapp::ontap::snmp::mode::qtreeusage; use base qw(centreon::plugins::templates::counter); @@ -136,12 +136,12 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, - "filter-vserver:s" => { name => 'filter_vserver' }, - "filter-volume:s" => { name => 'filter_volume' }, - "filter-qtree:s" => { name => 'filter_qtree' }, - "not-kbytes" => { name => 'not_kbytes' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' }, + 'filter-vserver:s' => { name => 'filter_vserver' }, + 'filter-volume:s' => { name => 'filter_volume' }, + 'filter-qtree:s' => { name => 'filter_qtree' }, + 'not-kbytes' => { name => 'not_kbytes' }, }); return $self; diff --git a/centreon-plugins/storage/netapp/snmp/mode/sharecalls.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/sharecalls.pm similarity index 98% rename from centreon-plugins/storage/netapp/snmp/mode/sharecalls.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/sharecalls.pm index 582e18395..f524fdfe6 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/sharecalls.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/sharecalls.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::sharecalls; +package storage::netapp::ontap::snmp::mode::sharecalls; use base qw(centreon::plugins::templates::counter); diff --git a/centreon-plugins/storage/netapp/snmp/mode/shelf.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/shelf.pm similarity index 95% rename from centreon-plugins/storage/netapp/snmp/mode/shelf.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/shelf.pm index 298eb8f31..86b80fa1b 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/shelf.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/shelf.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::shelf; +package storage::netapp::ontap::snmp::mode::shelf; use base qw(centreon::plugins::templates::hardware); @@ -79,7 +79,7 @@ sub set_system { ], }; - $self->{components_path} = 'storage::netapp::snmp::mode::components'; + $self->{components_path} = 'storage::netapp::ontap::snmp::mode::components'; $self->{components_module} = ['communication', 'psu', 'fan', 'temperature', 'voltage', 'electronics', 'raid']; } @@ -100,9 +100,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - }); + $options{options}->add_options(arguments => { + }); return $self; } @@ -162,4 +161,4 @@ Example: --critical='temperature,.*,25' --warning='temperature,.*,35' =back =cut - \ No newline at end of file + diff --git a/centreon-plugins/storage/netapp/snmp/mode/sis.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/sis.pm similarity index 99% rename from centreon-plugins/storage/netapp/snmp/mode/sis.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/sis.pm index 46e12663d..5b8ecd318 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/sis.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/sis.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::sis; +package storage::netapp::ontap::snmp::mode::sis; use base qw(centreon::plugins::templates::counter); diff --git a/centreon-plugins/storage/netapp/snmp/mode/snapmirrorlag.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/snapmirrorlag.pm similarity index 99% rename from centreon-plugins/storage/netapp/snmp/mode/snapmirrorlag.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/snapmirrorlag.pm index 3f5eb2087..da872b363 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/snapmirrorlag.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/snapmirrorlag.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::snapmirrorlag; +package storage::netapp::ontap::snmp::mode::snapmirrorlag; use base qw(centreon::plugins::templates::counter); diff --git a/centreon-plugins/storage/netapp/snmp/mode/snapshotage.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/snapshotage.pm similarity index 93% rename from centreon-plugins/storage/netapp/snmp/mode/snapshotage.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/snapshotage.pm index cc147816a..c0c30e266 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/snapshotage.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/snapshotage.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::snapshotage; +package storage::netapp::ontap::snmp::mode::snapshotage; use base qw(centreon::plugins::mode); @@ -38,15 +38,14 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "name:s" => { name => 'name' }, - "regexp" => { name => 'use_regexp' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); - $self->{snapshot_id_selected} = []; + $options{options}->add_options(arguments => { + 'name:s' => { name => 'name' }, + 'regexp' => { name => 'use_regexp' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' }, + }); + $self->{snapshot_id_selected} = []; return $self; } diff --git a/centreon-plugins/storage/netapp/snmp/mode/snapvaultusage.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/snapvaultusage.pm similarity index 96% rename from centreon-plugins/storage/netapp/snmp/mode/snapvaultusage.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/snapvaultusage.pm index 24ac978e7..e39bc7c0c 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/snapvaultusage.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/snapvaultusage.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::snapvaultusage; +package storage::netapp::ontap::snmp::mode::snapvaultusage; use base qw(centreon::plugins::templates::counter); @@ -111,10 +111,10 @@ sub new { 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 => '' }, + '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 => '' }, }); return $self; diff --git a/centreon-plugins/storage/netapp/snmp/mode/temperature.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/temperature.pm similarity index 84% rename from centreon-plugins/storage/netapp/snmp/mode/temperature.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/temperature.pm index 18100d5b5..75c4fbdad 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/temperature.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/temperature.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::temperature; +package storage::netapp::ontap::snmp::mode::temperature; use base qw(centreon::plugins::mode); @@ -34,10 +34,9 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - }); + + $options{options}->add_options(arguments => { + }); return $self; } @@ -54,11 +53,14 @@ sub run { my $oid_envOverTemperature = '.1.3.6.1.4.1.789.1.2.4.1'; my $oid_nodeName = '.1.3.6.1.4.1.789.1.25.2.1.1'; my $oid_nodeEnvOverTemperature = '.1.3.6.1.4.1.789.1.25.2.1.18'; - my $results = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_envOverTemperature }, - { oid => $oid_nodeName }, - { oid => $oid_nodeEnvOverTemperature }, - ], nothing_quit => 1); + my $results = $self->{snmp}->get_multiple_table( + oids => [ + { oid => $oid_envOverTemperature }, + { oid => $oid_nodeName }, + { oid => $oid_nodeEnvOverTemperature }, + ], + nothing_quit => 1 + ); if (defined($results->{$oid_envOverTemperature}->{$oid_envOverTemperature . '.0'})) { $self->{output}->output_add(severity => 'OK', @@ -101,4 +103,4 @@ Check if hardware is currently operating outside of its recommended temperature =back =cut - \ No newline at end of file + diff --git a/centreon-plugins/storage/netapp/snmp/mode/volumeoptions.pm b/centreon-plugins/storage/netapp/ontap/snmp/mode/volumeoptions.pm similarity index 92% rename from centreon-plugins/storage/netapp/snmp/mode/volumeoptions.pm rename to centreon-plugins/storage/netapp/ontap/snmp/mode/volumeoptions.pm index 07f308682..5bef56586 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/volumeoptions.pm +++ b/centreon-plugins/storage/netapp/ontap/snmp/mode/volumeoptions.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package storage::netapp::snmp::mode::volumeoptions; +package storage::netapp::ontap::snmp::mode::volumeoptions; use base qw(centreon::plugins::templates::counter); @@ -28,7 +28,7 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_options_threshold { my ($self, %options) = @_; - + my $status = catalog_status_threshold($self, %options); if (!$self->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) { $self->{instance_mode}->{global}->{failed}++; @@ -105,14 +105,14 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, - "filter-status:s" => { name => 'filter_status' }, - "unknown-status:s" => { name => 'unknown_status', default => '' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, - "unknown-options:s" => { name => 'unknown_options', default => '' }, - "warning-options:s" => { name => 'warning_options', default => '' }, - "critical-options:s" => { name => 'critical_options', default => '' }, + 'filter-name:s' => { name => 'filter_name' }, + 'filter-status:s' => { name => 'filter_status' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, + 'unknown-options:s' => { name => 'unknown_options', default => '' }, + 'warning-options:s' => { name => 'warning_options', default => '' }, + 'critical-options:s' => { name => 'critical_options', default => '' }, }); return $self; diff --git a/centreon-plugins/storage/netapp/ontap/snmp/plugin.pm b/centreon-plugins/storage/netapp/ontap/snmp/plugin.pm new file mode 100644 index 000000000..8eabd7c9e --- /dev/null +++ b/centreon-plugins/storage/netapp/ontap/snmp/plugin.pm @@ -0,0 +1,72 @@ +# +# 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 storage::netapp::ontap::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'aggregatestate' => 'storage::netapp::ontap::snmp::mode::aggregatestate', + 'cache-age' => 'storage::netapp::ontap::snmp::mode::cacheage', + 'cp-statistics' => 'storage::netapp::ontap::snmp::mode::cpstatistics', + 'cpuload' => 'storage::netapp::ontap::snmp::mode::cpuload', + 'diskfailed' => 'storage::netapp::ontap::snmp::mode::diskfailed', + 'failover' => 'storage::netapp::ontap::snmp::mode::failover', + 'fan' => 'storage::netapp::ontap::snmp::mode::fan', + 'filesys' => 'storage::netapp::ontap::snmp::mode::filesys', + 'list-filesys' => 'storage::netapp::ontap::snmp::mode::listfilesys', + 'list-snapvault' => 'storage::netapp::ontap::snmp::mode::listsnapvault', + 'global-status' => 'storage::netapp::ontap::snmp::mode::globalstatus', + 'ndmpsessions' => 'storage::netapp::ontap::snmp::mode::ndmpsessions', + 'nvram' => 'storage::netapp::ontap::snmp::mode::nvram', + 'partnerstatus' => 'storage::netapp::ontap::snmp::mode::partnerstatus', + 'psu' => 'storage::netapp::ontap::snmp::mode::psu', + 'qtree-usage' => 'storage::netapp::ontap::snmp::mode::qtreeusage', + 'share-calls' => 'storage::netapp::ontap::snmp::mode::sharecalls', + 'shelf' => 'storage::netapp::ontap::snmp::mode::shelf', + 'sis' => 'storage::netapp::ontap::snmp::mode::sis', + 'snapmirrorlag' => 'storage::netapp::ontap::snmp::mode::snapmirrorlag', + 'snapshotage' => 'storage::netapp::ontap::snmp::mode::snapshotage', + 'snapvault-usage' => 'storage::netapp::ontap::snmp::mode::snapvaultusage', + 'temperature' => 'storage::netapp::ontap::snmp::mode::temperature', + 'uptime' => 'snmp_standard::mode::uptime', + 'volumeoptions' => 'storage::netapp::ontap::snmp::mode::volumeoptions' + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Netapp ONTAP in SNMP. + +=cut diff --git a/centreon-plugins/storage/netapp/restapi/plugin.pm b/centreon-plugins/storage/netapp/restapi/plugin.pm deleted file mode 100644 index 64709c915..000000000 --- a/centreon-plugins/storage/netapp/restapi/plugin.pm +++ /dev/null @@ -1,75 +0,0 @@ -# -# 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 storage::netapp::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} = '1.0'; - %{$self->{modes}} = ( - 'aggregate-raid-status' => 'storage::netapp::restapi::mode::aggregateraidstatus', - 'aggregate-status' => 'storage::netapp::restapi::mode::aggregatestatus', - 'aggregate-usage' => 'storage::netapp::restapi::mode::aggregateusage', - 'cluster-io' => 'storage::netapp::restapi::mode::clusterio', - 'cluster-status' => 'storage::netapp::restapi::mode::clusterstatus', - 'cluster-usage' => 'storage::netapp::restapi::mode::clusterusage', - 'disk-failed' => 'storage::netapp::restapi::mode::diskfailed', - 'disk-spare' => 'storage::netapp::restapi::mode::diskspare', - 'fc-port-status' => 'storage::netapp::restapi::mode::fcportstatus', - 'list-aggregates' => 'storage::netapp::restapi::mode::listaggregates', - 'list-clusters' => 'storage::netapp::restapi::mode::listclusters', - 'list-fc-ports' => 'storage::netapp::restapi::mode::listfcports', - 'list-luns' => 'storage::netapp::restapi::mode::listluns', - 'list-nodes' => 'storage::netapp::restapi::mode::listnodes', - 'list-snapmirrors' => 'storage::netapp::restapi::mode::listsnapmirrors', - 'list-volumes' => 'storage::netapp::restapi::mode::listvolumes', - 'lun-alignment' => 'storage::netapp::restapi::mode::lunalignment', - 'lun-online' => 'storage::netapp::restapi::mode::lunonline', - 'lun-usage' => 'storage::netapp::restapi::mode::lunusage', - 'node-failover-status' => 'storage::netapp::restapi::mode::nodefailoverstatus', - 'node-hardware-status' => 'storage::netapp::restapi::mode::nodehardwarestatus', - 'qtree-status' => 'storage::netapp::restapi::mode::qtreestatus', - 'snapmirror-status' => 'storage::netapp::restapi::mode::snapmirrorstatus', - 'snapmirror-usage' => 'storage::netapp::restapi::mode::snapmirrorusage', - 'volume-io' => 'storage::netapp::restapi::mode::volumeio', - 'volume-status' => 'storage::netapp::restapi::mode::volumestatus', - 'volume-usage' => 'storage::netapp::restapi::mode::volumeusage', - ); - - $self->{custom_modes}{api} = 'storage::netapp::restapi::custom::restapi'; - return $self; -} - -1; - -__END__ - -=head1 PLUGIN DESCRIPTION - -Check NetApp with OnCommand API. - -=cut diff --git a/centreon-plugins/storage/netapp/snmp/plugin.pm b/centreon-plugins/storage/netapp/snmp/plugin.pm deleted file mode 100644 index 134b9e3c0..000000000 --- a/centreon-plugins/storage/netapp/snmp/plugin.pm +++ /dev/null @@ -1,72 +0,0 @@ -# -# 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 storage::netapp::snmp::plugin; - -use strict; -use warnings; -use base qw(centreon::plugins::script_snmp); - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.0'; - %{$self->{modes}} = ( - 'aggregatestate' => 'storage::netapp::snmp::mode::aggregatestate', - 'cache-age' => 'storage::netapp::snmp::mode::cacheage', - 'cp-statistics' => 'storage::netapp::snmp::mode::cpstatistics', - 'cpuload' => 'storage::netapp::snmp::mode::cpuload', - 'diskfailed' => 'storage::netapp::snmp::mode::diskfailed', - 'failover' => 'storage::netapp::snmp::mode::failover', - 'fan' => 'storage::netapp::snmp::mode::fan', - 'filesys' => 'storage::netapp::snmp::mode::filesys', - 'list-filesys' => 'storage::netapp::snmp::mode::listfilesys', - 'list-snapvault' => 'storage::netapp::snmp::mode::listsnapvault', - 'global-status' => 'storage::netapp::snmp::mode::globalstatus', - 'ndmpsessions' => 'storage::netapp::snmp::mode::ndmpsessions', - 'nvram' => 'storage::netapp::snmp::mode::nvram', - 'partnerstatus' => 'storage::netapp::snmp::mode::partnerstatus', - 'psu' => 'storage::netapp::snmp::mode::psu', - 'qtree-usage' => 'storage::netapp::snmp::mode::qtreeusage', - 'share-calls' => 'storage::netapp::snmp::mode::sharecalls', - 'shelf' => 'storage::netapp::snmp::mode::shelf', - 'sis' => 'storage::netapp::snmp::mode::sis', - 'snapmirrorlag' => 'storage::netapp::snmp::mode::snapmirrorlag', - 'snapshotage' => 'storage::netapp::snmp::mode::snapshotage', - 'snapvault-usage' => 'storage::netapp::snmp::mode::snapvaultusage', - 'temperature' => 'storage::netapp::snmp::mode::temperature', - 'uptime' => 'snmp_standard::mode::uptime', - 'volumeoptions' => 'storage::netapp::snmp::mode::volumeoptions', - ); - - return $self; -} - -1; - -__END__ - -=head1 PLUGIN DESCRIPTION - -Check Netapp in SNMP (Some Check needs ONTAP 8.x). - -=cut From 8c06abd354d06ddd0f3ecae58374150880c712c0 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 5 May 2020 16:05:35 +0200 Subject: [PATCH 163/190] fix eltek battery calc --- .../hardware/devices/eltek/enexus/snmp/mode/battery.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/battery.pm b/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/battery.pm index 48c23c398..c0582dea4 100644 --- a/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/battery.pm +++ b/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/battery.pm @@ -257,7 +257,7 @@ sub manage_selection { if ($result->{powerSystemCapacityScale} eq 'ah' && defined($current)) { $self->{battery}->{charge_remaining_time} = - int($result->{batteryRemainingCapacityValue} * 3600 / $current * $scale_current); + int(($result->{batteryRemainingCapacityValue} * 3600) / ($current * $scale_current)); } $self->threshold_eltek_configured( From a1293971e0414cfad68b0257ce3f7762dd090587 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 5 May 2020 17:25:32 +0200 Subject: [PATCH 164/190] change eltek power calc --- .../devices/eltek/enexus/snmp/mode/load.pm | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/load.pm b/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/load.pm index 5c80df04e..2c55a4048 100644 --- a/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/load.pm +++ b/centreon-plugins/hardware/devices/eltek/enexus/snmp/mode/load.pm @@ -25,12 +25,12 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); -use Digest::MD5 qw(md5_hex); sub custom_status_output { my ($self, %options) = @_; - return sprintf('status: %s', + return sprintf( + 'status: %s', $self->{result_values}->{status} ); } @@ -60,11 +60,11 @@ sub set_counters { ] } }, - { label => 'energy-delivered', nlabel => 'load.energy.delivered.watt', display_ok => 0, set => { - key_values => [ { name => 'energy', diff => 1 } ], - output_template => 'accumulated energy delivered: %s W', + { label => 'power', nlabel => 'load.power.watt', display_ok => 0, set => { + key_values => [ { name => 'power' } ], + output_template => 'power: %s W', perfdatas => [ - { value => 'energy_absolute', template => '%s', unit => 'W', min => 0 } + { value => 'power_absolute', template => '%s', unit => 'W', min => 0 } ] } } @@ -96,7 +96,7 @@ sub prefix_phase_output { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { @@ -135,6 +135,7 @@ my $mapping = { loadCurrentMajorHighLevel => { oid => '.1.3.6.1.4.1.12148.10.9.2.6' }, loadCurrentMinorHighLevel => { oid => '.1.3.6.1.4.1.12148.10.9.2.7' }, loadEnergyLogAccumulated => { oid => '.1.3.6.1.4.1.12148.10.9.8.1' }, # Watt + batteryVoltageValue => { oid => '.1.3.6.1.4.1.12148.10.10.5.5' } # not sure we should use that value }; sub threshold_eltek_configured { @@ -165,7 +166,7 @@ sub manage_selection { $scale_current = 0.1 if ($result->{powerSystemCurrentDecimalSetting} eq 'deciAmpere'); $self->{load} = { status => $result->{loadStatus}, - energy => $result->{loadEnergyLogAccumulated}, + power => $result->{loadCurrentValue} * $scale_current * ($result->{batteryVoltageValue} * 0.01), current => $result->{loadCurrentValue} * $scale_current }; @@ -182,9 +183,6 @@ sub manage_selection { /\.(\d+)$/; $self->{phase}->{$1} = { display => $1, voltage => $snmp_result->{$_} * 0.01 }; } - - $self->{cache_name} = 'eltek_enexus_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . - (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); } 1; @@ -215,7 +213,7 @@ Can used special variables like: %{status} =item B<--warning-*> B<--critical-*> Thresholds. -Can be: 'current', 'energy-delivered'. +Can be: 'current', 'power'. =back From 2b755bae1af7ed1c4c3ed9f1eb7815dec57e97be Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 5 May 2020 17:55:09 +0200 Subject: [PATCH 165/190] enhance cisco meraki --- .../network/cisco/meraki/cloudcontroller/restapi/custom/api.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm index c70f0b2df..86243d21c 100644 --- a/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm +++ b/centreon-plugins/network/cisco/meraki/cloudcontroller/restapi/custom/api.pm @@ -180,7 +180,7 @@ sub request_api { my $content; eval { - $content = JSON::XS->new->utf8->decode($response); + $content = JSON::XS->new->allow_nonref(1)->utf8->decode($response); }; if ($@) { $self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@"); From 7c9b7599c96a6a46af840bb56cb0f253d814cafd Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 6 May 2020 15:19:24 +0200 Subject: [PATCH 166/190] wip: netapp santricity --- .../netapp/santricity/restapi/custom/api.pm | 263 ++++++++++++++++++ .../restapi/mode/components/battery.pm | 67 +++++ .../restapi/mode/components/board.pm | 67 +++++ .../santricity/restapi/mode/components/cbd.pm | 67 +++++ .../santricity/restapi/mode/components/cmd.pm | 67 +++++ .../restapi/mode/components/ctrl.pm | 67 +++++ .../restapi/mode/components/drive.pm | 101 +++++++ .../santricity/restapi/mode/components/fan.pm | 67 +++++ .../santricity/restapi/mode/components/psu.pm | 67 +++++ .../restapi/mode/components/storage.pm | 58 ++++ .../restapi/mode/components/thsensor.pm | 67 +++++ .../santricity/restapi/mode/hardware.pm | 194 +++++++++++++ .../netapp/santricity/restapi/plugin.pm | 49 ++++ 13 files changed, 1201 insertions(+) create mode 100644 centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm create mode 100644 centreon-plugins/storage/netapp/santricity/restapi/mode/components/battery.pm create mode 100644 centreon-plugins/storage/netapp/santricity/restapi/mode/components/board.pm create mode 100644 centreon-plugins/storage/netapp/santricity/restapi/mode/components/cbd.pm create mode 100644 centreon-plugins/storage/netapp/santricity/restapi/mode/components/cmd.pm create mode 100644 centreon-plugins/storage/netapp/santricity/restapi/mode/components/ctrl.pm create mode 100644 centreon-plugins/storage/netapp/santricity/restapi/mode/components/drive.pm create mode 100644 centreon-plugins/storage/netapp/santricity/restapi/mode/components/fan.pm create mode 100644 centreon-plugins/storage/netapp/santricity/restapi/mode/components/psu.pm create mode 100644 centreon-plugins/storage/netapp/santricity/restapi/mode/components/storage.pm create mode 100644 centreon-plugins/storage/netapp/santricity/restapi/mode/components/thsensor.pm create mode 100644 centreon-plugins/storage/netapp/santricity/restapi/mode/hardware.pm create mode 100644 centreon-plugins/storage/netapp/santricity/restapi/plugin.pm diff --git a/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm b/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm new file mode 100644 index 000000000..ac5f26aa5 --- /dev/null +++ b/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm @@ -0,0 +1,263 @@ +# +# 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 storage::netapp::santricity::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' }, + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port' }, + 'proto:s' => { name => 'proto' }, + 'timeout:s' => { name => 'timeout' }, + 'api-path:s' => { name => 'api_path' }, + '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} : 8080; + $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'http'; + $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_path} = (defined($self->{option_results}->{api_path})) ? $self->{option_results}->{api_path} : '/devmgr/v2'; + $self->{unknown_http_status} = (defined($self->{option_results}->{unknown_http_status})) ? $self->{option_results}->{unknown_http_status} : '(%{http_code} < 200 or %{http_code} >= 300) and %{http_code} != 424'; + $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 (!defined($self->{hostname}) || $self->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); + $self->{output}->option_exit(); + } + if (!defined($self->{api_username}) || $self->{api_username} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-username option."); + $self->{output}->option_exit(); + } + if (!defined($self->{api_password}) || $self->{api_password} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-password 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}; + $self->{option_results}->{credentials} = 1; + $self->{option_results}->{basic} = 1; + $self->{option_results}->{username} = $self->{api_username}; + $self->{option_results}->{password} = $self->{api_password}; +} + +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}->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 $content = $self->{http}->request( + method => defined($options{method}) ? $options{method} : 'GET', + url_path => $self->{api_path} . '/' . $options{endpoint}, + unknown_status => $self->{unknown_http_status}, + warning_status => $self->{warning_http_status}, + critical_status => $self->{critical_http_status}, + cookies_file => '' # in memory + ); + + # code 424 = storageDevice offline + my $code = $self->{http}->get_code(); + 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(); + } + + return undef if ($code == 424); + + 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 { $options{name} => $decoded }; +} + +sub execute_storages_request { + my ($self, %options) = @_; + + my $content = do { + local $/ = undef; + if (!open my $fh, "<", '/home/qgarnier/clients/plugins/todo/santricity/test-inventory.txt') { + $self->{output}->add_option_msg(short_msg => "Could not open file $self->{option_results}->{$_} : $!"); + $self->{output}->option_exit(); + } + <$fh>; + }; + eval { + $content = JSON::XS->new->utf8->decode($content); + }; + return $content; + + my $storages = $self->request_api(name => 'storages', endpoint => '/storage-systems'); + for (my $i = 0; $i < scalar(@{$storages->{storages}}); $i++) { + next if (defined($options{filter_name}) && $options{filter_name} ne '' && + $storages->{storages}->{$i}->{name} !~ /$options{filter_name}/); + + my $info = $self->request_api(name => 'info', endpoint => '/' . $storages->{storages}->{$i}->{wwn} . '/' . $options{endpoint}); + $storages->{storages}->{$i}->{offline} = 0; + $storages->{storages}->{$i}->{offline} = 1 if (!defined($info)); + + $storages->{storages}->{$i}->{ $options{endpoint} } = defined($info) ? $info->{info} : undef; + } + + return $storages; +} + + + +1; + +__END__ + +=head1 NAME + +Netapp Santricity Rest API + +=head1 REST API OPTIONS + +Netapp Santricity Rest API + +=over 8 + +=item B<--hostname> + +Santricity hostname. + +=item B<--port> + +Port used (Default: 8080) + +=item B<--proto> + +Specify https if needed (Default: 'http') + +=item B<--api-username> + +Santricity API username. + +=item B<--api-password> + +Santricity API password. + +=item B<--api-path> + +Specify api path (Default: '/devmgr/v2') + +=item B<--timeout> + +Set timeout in seconds (Default: 10). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/storage/netapp/santricity/restapi/mode/components/battery.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/components/battery.pm new file mode 100644 index 000000000..0809ce812 --- /dev/null +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/components/battery.pm @@ -0,0 +1,67 @@ +# +# 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 storage::netapp::santricity::restapi::mode::components::battery; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking batteries'); + $self->{components}->{battery} = { name => 'batteries', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'battery')); + + return if (!defined($self->{json_results}->{storages})); + + foreach (@{$self->{json_results}->{storages}}) { + my $storage_name = $_->{name}; + + next if ($self->check_filter(section => 'storage', instance => $_->{chassisSerialNumber})); + + next if (!defined($_->{'/hardware-inventory'}->{batteries})); + + foreach my $entry (@{$_->{'/hardware-inventory'}->{batteries}}) { + my $instance = $entry->{batteryRef}; + my $name = $storage_name . ':' . $entry->{physicalLocation}->{locationPosition} . ':' . $entry->{physicalLocation}->{slot}; + + next if ($self->check_filter(section => 'battery', instance => $instance)); + $self->{components}->{battery}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "battery '%s' status is '%s' [instance = %s]", + $name, $entry->{status}, $instance + ) + ); + + my $exit = $self->get_severity(section => 'battery', instance => $instance, value => $entry->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Battery '%s' status is '%s'", $name, $entry->{status}) + ); + } + } + } +} + +1; diff --git a/centreon-plugins/storage/netapp/santricity/restapi/mode/components/board.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/components/board.pm new file mode 100644 index 000000000..99fc7f7a8 --- /dev/null +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/components/board.pm @@ -0,0 +1,67 @@ +# +# 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 storage::netapp::santricity::restapi::mode::components::board; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking boards'); + $self->{components}->{board} = { name => 'boards', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'board')); + + return if (!defined($self->{json_results}->{storages})); + + foreach (@{$self->{json_results}->{storages}}) { + my $storage_name = $_->{name}; + + next if ($self->check_filter(section => 'storage', instance => $_->{chassisSerialNumber})); + + next if (!defined($_->{'/hardware-inventory'}->{hostBoards})); + + foreach my $entry (@{$_->{'/hardware-inventory'}->{hostBoards}}) { + my $instance = $entry->{hostBoardRef}; + my $name = $storage_name . ':' . $entry->{physicalLocation}->{locationPosition} . ':' . $entry->{physicalLocation}->{slot}; + + next if ($self->check_filter(section => 'board', instance => $instance)); + $self->{components}->{board}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "board '%s' status is '%s' [instance = %s]", + $name, $entry->{status}, $instance + ) + ); + + my $exit = $self->get_severity(section => 'board', instance => $instance, value => $entry->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Board '%s' status is '%s'", $name, $entry->{status}) + ); + } + } + } +} + +1; diff --git a/centreon-plugins/storage/netapp/santricity/restapi/mode/components/cbd.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/components/cbd.pm new file mode 100644 index 000000000..299e036b6 --- /dev/null +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/components/cbd.pm @@ -0,0 +1,67 @@ +# +# 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 storage::netapp::santricity::restapi::mode::components::cbd; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking cache backup devices'); + $self->{components}->{cbd} = { name => 'cbd', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'cbd')); + + return if (!defined($self->{json_results}->{storages})); + + foreach (@{$self->{json_results}->{storages}}) { + my $storage_name = $_->{name}; + + next if ($self->check_filter(section => 'storage', instance => $_->{chassisSerialNumber})); + + next if (!defined($_->{'/hardware-inventory'}->{cacheBackupDevices})); + + foreach my $entry (@{$_->{'/hardware-inventory'}->{cacheBackupDevices}}) { + my $instance = $entry->{backupDeviceRef}; + my $name = $storage_name . ':' . $entry->{physicalLocation}->{locationPosition} . ':' . $entry->{physicalLocation}->{slot}; + + next if ($self->check_filter(section => 'cbd', instance => $instance)); + $self->{components}->{cbd}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "cache backup device '%s' status is '%s' [instance = %s]", + $name, $entry->{backupDeviceStatus}, $instance + ) + ); + + my $exit = $self->get_severity(section => 'cbd', instance => $instance, value => $entry->{backupDeviceStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Cache backup device '%s' status is '%s'", $name, $entry->{backupDeviceStatus}) + ); + } + } + } +} + +1; diff --git a/centreon-plugins/storage/netapp/santricity/restapi/mode/components/cmd.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/components/cmd.pm new file mode 100644 index 000000000..7be23cb11 --- /dev/null +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/components/cmd.pm @@ -0,0 +1,67 @@ +# +# 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 storage::netapp::santricity::restapi::mode::components::cmd; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking cache memory dimms'); + $self->{components}->{cmd} = { name => 'cmd', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'cmd')); + + return if (!defined($self->{json_results}->{storages})); + + foreach (@{$self->{json_results}->{storages}}) { + my $storage_name = $_->{name}; + + next if ($self->check_filter(section => 'storage', instance => $_->{chassisSerialNumber})); + + next if (!defined($_->{'/hardware-inventory'}->{cacheMemoryDimms})); + + foreach my $entry (@{$_->{'/hardware-inventory'}->{cacheMemoryDimms}}) { + my $instance = $entry->{cacheMemoryDimmRef}; + my $name = $storage_name . ':' . $entry->{physicalLocation}->{locationPosition} . ':' . $entry->{physicalLocation}->{slot}; + + next if ($self->check_filter(section => 'cmd', instance => $instance)); + $self->{components}->{cbd}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "cache memory dimm '%s' status is '%s' [instance = %s]", + $name, $entry->{status}, $instance + ) + ); + + my $exit = $self->get_severity(section => 'cmd', instance => $instance, value => $entry->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Cache memory dimm '%s' status is '%s'", $name, $entry->{status}) + ); + } + } + } +} + +1; diff --git a/centreon-plugins/storage/netapp/santricity/restapi/mode/components/ctrl.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/components/ctrl.pm new file mode 100644 index 000000000..25a2c7ab8 --- /dev/null +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/components/ctrl.pm @@ -0,0 +1,67 @@ +# +# 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 storage::netapp::santricity::restapi::mode::components::ctrl; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking controllers'); + $self->{components}->{ctrl} = { name => 'ctrl', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'ctrl')); + + return if (!defined($self->{json_results}->{storages})); + + foreach (@{$self->{json_results}->{storages}}) { + my $storage_name = $_->{name}; + + next if ($self->check_filter(section => 'storage', instance => $_->{chassisSerialNumber})); + + next if (!defined($_->{'/hardware-inventory'}->{controllers})); + + foreach my $entry (@{$_->{'/hardware-inventory'}->{controllers}}) { + my $instance = $entry->{controllerRef}; + my $name = $storage_name . ':' . $entry->{physicalLocation}->{locationPosition} . ':' . $entry->{physicalLocation}->{slot}; + + next if ($self->check_filter(section => 'ctrl', instance => $instance)); + $self->{components}->{ctrl}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "controller '%s' status is '%s' [instance = %s]", + $name, $entry->{status}, $instance + ) + ); + + my $exit = $self->get_severity(section => 'ctrl', instance => $instance, value => $entry->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Controller '%s' status is '%s'", $name, $entry->{status}) + ); + } + } + } +} + +1; diff --git a/centreon-plugins/storage/netapp/santricity/restapi/mode/components/drive.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/components/drive.pm new file mode 100644 index 000000000..a0ad52ccf --- /dev/null +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/components/drive.pm @@ -0,0 +1,101 @@ +# +# 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 storage::netapp::santricity::restapi::mode::components::drive; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking drives'); + $self->{components}->{drive} = { name => 'drive', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'drive')); + + return if (!defined($self->{json_results}->{storages})); + + foreach (@{$self->{json_results}->{storages}}) { + my $storage_name = $_->{name}; + + next if ($self->check_filter(section => 'storage', instance => $_->{chassisSerialNumber})); + + next if (!defined($_->{'/hardware-inventory'}->{drives})); + + foreach my $entry (@{$_->{'/hardware-inventory'}->{drives}}) { + my $instance = $entry->{driveRef}; + my $name = $storage_name . ':' . $entry->{physicalLocation}->{locationPosition} . ':' . $entry->{physicalLocation}->{slot}; + + next if ($self->check_filter(section => 'drive', instance => $instance)); + $self->{components}->{drive}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "drive '%s' status is '%s' [instance = %s] [temperature: %s]", + $name, $entry->{status}, $instance, $entry->{driveTemperature}->{currentTemp} + ) + ); + + my $exit = $self->get_severity(section => 'drive', instance => $instance, value => $entry->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Drive '%s' status is '%s'", $name, $entry->{status}) + ); + } + + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'drive.temperature', instance => $instance, value => $entry->{driveTemperature}->{currentTemp}); + if ($checked == 0) { + my $warn_th = ''; + my $crit_th = defined($entry->{driveTemperature}->{refTemp}) ? $entry->{driveTemperature}->{refTemp} : ''; + $self->{perfdata}->threshold_validate(label => 'warning-drive.temperature-instance-' . $instance, value => $warn_th); + $self->{perfdata}->threshold_validate(label => 'critical-drive.temperature-instance-' . $instance, value => $crit_th); + + $exit = $self->{perfdata}->threshold_check( + value => $entry->{driveTemperature}->{currentTemp}, + threshold => [ + { label => 'critical-drive.temperature-instance-' . $instance, exit_litteral => 'critical' }, + { label => 'warning-drive.temperature-instance-' . $instance, exit_litteral => 'warning' } + ] + ); + $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-drive.temperature-instance-' . $instance); + $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-drive.temperature-instance-' . $instance) + } + + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit2, + short_msg => sprintf("drive '%s' temperature is %s C", $name, $entry->{driveTemperature}->{currentTemp}) + ); + } + + $self->{output}->perfdata_add( + nlabel => 'hardware.drive.temperature.celsius', + unit => 'C', + instances => $name, + value => $entry->{driveTemperature}->{currentTemp}, + warning => $warn, + critical => $crit + ); + } + } +} + +1; diff --git a/centreon-plugins/storage/netapp/santricity/restapi/mode/components/fan.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/components/fan.pm new file mode 100644 index 000000000..d96ec6f6b --- /dev/null +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/components/fan.pm @@ -0,0 +1,67 @@ +# +# 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 storage::netapp::santricity::restapi::mode::components::fan; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking fans'); + $self->{components}->{fan} = { name => 'fans', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'fan')); + + return if (!defined($self->{json_results}->{storages})); + + foreach (@{$self->{json_results}->{storages}}) { + my $storage_name = $_->{name}; + + next if ($self->check_filter(section => 'storage', instance => $_->{chassisSerialNumber})); + + next if (!defined($_->{'/hardware-inventory'}->{fans})); + + foreach my $entry (@{$_->{'/hardware-inventory'}->{fans}}) { + my $instance = $entry->{fanRef}; + my $name = $storage_name . ':' . $entry->{physicalLocation}->{locationPosition} . ':' . $entry->{physicalLocation}->{slot}; + + next if ($self->check_filter(section => 'fan', instance => $instance)); + $self->{components}->{fan}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "fan '%s' status is '%s' [instance = %s]", + $name, $entry->{status}, $instance + ) + ); + + my $exit = $self->get_severity(section => 'fan', instance => $instance, value => $entry->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Fan '%s' status is '%s'", $name, $entry->{status}) + ); + } + } + } +} + +1; diff --git a/centreon-plugins/storage/netapp/santricity/restapi/mode/components/psu.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/components/psu.pm new file mode 100644 index 000000000..9178a4e52 --- /dev/null +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/components/psu.pm @@ -0,0 +1,67 @@ +# +# 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 storage::netapp::santricity::restapi::mode::components::psu; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking power supplies'); + $self->{components}->{psu} = { name => 'psu', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'psu')); + + return if (!defined($self->{json_results}->{storages})); + + foreach (@{$self->{json_results}->{storages}}) { + my $storage_name = $_->{name}; + + next if ($self->check_filter(section => 'storage', instance => $_->{chassisSerialNumber})); + + next if (!defined($_->{'/hardware-inventory'}->{powerSupplies})); + + foreach my $entry (@{$_->{'/hardware-inventory'}->{powerSupplies}}) { + my $instance = $entry->{powerSupplyRef}; + my $name = $storage_name . ':' . $entry->{physicalLocation}->{locationPosition} . ':' . $entry->{physicalLocation}->{slot}; + + next if ($self->check_filter(section => 'psu', instance => $instance)); + $self->{components}->{psu}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "power supply '%s' status is '%s' [instance = %s]", + $name, $entry->{status}, $instance, + ) + ); + + my $exit = $self->get_severity(section => 'psu', instance => $instance, value => $entry->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Power supply '%s' status is '%s'", $name, $entry->{status}) + ); + } + } + } +} + +1; diff --git a/centreon-plugins/storage/netapp/santricity/restapi/mode/components/storage.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/components/storage.pm new file mode 100644 index 000000000..0f4332dc9 --- /dev/null +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/components/storage.pm @@ -0,0 +1,58 @@ +# +# 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 storage::netapp::santricity::restapi::mode::components::storage; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking storages'); + $self->{components}->{storage} = { name => 'storages', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'storage')); + + return if (!defined($self->{json_results}->{storages})); + + foreach (@{$self->{json_results}->{storages}}) { + my $instance = $_->{chassisSerialNumber}; + + next if ($self->check_filter(section => 'storage', instance => $instance)); + $self->{components}->{storage}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "storage '%s' status is '%s' [instance = %s]", + $_->{name}, $_->{status}, $instance, + ) + ); + + my $exit = $self->get_severity(section => 'storage', instance => $instance, value => $_->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Storage '%s' status is '%s'", $_{name}, $_->{status}) + ); + } + } +} + +1; diff --git a/centreon-plugins/storage/netapp/santricity/restapi/mode/components/thsensor.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/components/thsensor.pm new file mode 100644 index 000000000..d97a07882 --- /dev/null +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/components/thsensor.pm @@ -0,0 +1,67 @@ +# +# 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 storage::netapp::santricity::restapi::mode::components::thsensor; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking thermal sensors'); + $self->{components}->{thsensor} = { name => 'thsensor', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'thsensor')); + + return if (!defined($self->{json_results}->{storages})); + + foreach (@{$self->{json_results}->{storages}}) { + my $storage_name = $_->{name}; + + next if ($self->check_filter(section => 'storage', instance => $_->{chassisSerialNumber})); + + next if (!defined($_->{'/hardware-inventory'}->{thermalSensors})); + + foreach my $entry (@{$_->{'/hardware-inventory'}->{thermalSensors}}) { + my $instance = $entry->{thermalSensorRef}; + my $name = $storage_name . ($entry->{physicalLocation}->{label} ne '' ? ':' . $entry->{physicalLocation}->{label} : '') . ':' . $entry->{physicalLocation}->{locationPosition} . ':' . $entry->{physicalLocation}->{slot}; + + next if ($self->check_filter(section => 'thsensor', instance => $instance)); + $self->{components}->{thsensor}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "thermal sensor '%s' status is '%s' [instance = %s]", + $name, $entry->{status}, $instance, + ) + ); + + my $exit = $self->get_severity(section => 'thsensor', instance => $instance, value => $entry->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Thermal sensor '%s' status is '%s'", $name, $entry->{status}) + ); + } + } + } +} + +1; diff --git a/centreon-plugins/storage/netapp/santricity/restapi/mode/hardware.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/hardware.pm new file mode 100644 index 000000000..fd025d731 --- /dev/null +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/hardware.pm @@ -0,0 +1,194 @@ +# +# 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 storage::netapp::santricity::restapi::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = + '^(?:storage|battery|cbd|cmd|boards|psu|fan|thsensor|ctrl|drive)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(?:drive.temperature)$'; + + $self->{cb_hook2} = 'execute_custom'; + + $self->{thresholds} = { + battery => [ + ['optimal', 'OK'], + ['fullCharging', 'OK'], + ['nearExpiration', 'WARNING'], + ['failed', 'CRITICAL'], + ['removed', 'OK'], + ['unknown', 'UNKNOWN'], + ['notInConfig', 'WARNING'], + ['configMismatch', 'WARNING'], + ['learning', 'OK'], + ['overtemp', ''], + ['expired', 'WARNING'], + ['maintenanceCharging', 'OK'], + ['replacementRequired', 'CRTICICAL'] + ], + board => [ + ['unknown', 'UNKNOWN'], + ['optimal', 'OK'], + ['needsAttention', 'WARNING'], + ['notPresent', 'OK'], + ['degraded', 'WARNING'], + ['failed', 'CRITICAL'], + ['diagInProgress', 'OK'] + ], + cbd => [ + ['unknown', 'UNKNOWN'], + ['optimal', 'OK'], + ['failed', 'CRITICAL'], + ['removed', 'OK'], + ['writeProtected', 'OK'], + ['incompatible', 'CRITICAL'] + ], + cmd => [ + ['unknown', 'UNKNOWN'], + ['optimal', 'OK'], + ['failed', 'CRITICAL'], + ['empty', 'OK'] + ], + ctrl => [ + ['unknown', 'UNKNOWN'], + ['optimal', 'OK'], + ['failed', 'CRITICAL'], + ['removed', 'OK'], + ['rpaParErr', 'WAARNING'], + ['serviceMode', 'OK'], + ['suspended', 'OK'], + ['degraded', 'WARNING'] + ], + drive => [ + ['optimal', 'OK'], + ['failed', 'CRITICAL'], + ['replaced', 'OK'], + ['bypassed', 'OK'], + ['unresponsive', 'WARNING'], + ['removed', 'OK'], + ['incompatible', 'WARNING'], + ['dataRelocation', 'OK'], + ['preFailCopy', 'WARNING'], + ['preFailCopyPending', 'WARNING'] + ], + fan => [ + ['optimal', 'OK'], + ['removed', 'OK'], + ['failed', 'CRITICAL'], + ['unknown', 'UNKNOWN'] + ], + psu => [ + ['optimal', 'OK'], + ['removed', 'OK'], + ['failed', 'CRITICAL'], + ['unknown', 'UNKNOWN'], + ['noinput', 'WARNING'] + ], + storage => [ + ['neverContacted', 'UNKNOWN'], + ['offline', 'OK'], + ['optimal', 'OK'], + ['needsAttn', 'WARNING'], + ['newDevice', 'OK'], + ['lockDown', 'WARNING'] + ], + thsensor => [ + ['optimal', 'OK'], + ['nominalTempExceed', 'WARNING'], + ['maxTempExceed', 'CRITICAL'], + ['unknown', 'UNKNOWN'], + ['removed', 'OK'] + ] + }; + + $self->{components_exec_load} = 0; + + $self->{components_path} = 'storage::netapp::santricity::restapi::mode::components'; + $self->{components_module} = [ + 'storage', 'ctrl', 'battery', 'board', 'cbd', 'cmd', 'drive', 'psu', 'fan', + 'thsensor' + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub execute_custom { + my ($self, %options) = @_; + + $self->{json_results} = $options{custom}->execute_storages_request(endpoint => '/hardware-inventory'); +} + +1; + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'storage', 'ctrl', 'battery', 'board', 'cbd', 'cmd', 'drive', 'psu', 'fan', 'thsensor'. + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter='drive,010000005000C500C244251B0000000000000000' + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='drive,OK,preFailCopy' + +=item B<--warning> + +Set warning threshold for 'temperature' (syntax: type,regexp,threshold) +Example: --warning='drive.temperature,.*,40' + +=item B<--critical> + +Set critical threshold for 'drive.temperature' (syntax: type,regexp,threshold) +Example: --critical='drive.temperature,.*,50' + +=back + +=cut diff --git a/centreon-plugins/storage/netapp/santricity/restapi/plugin.pm b/centreon-plugins/storage/netapp/santricity/restapi/plugin.pm new file mode 100644 index 000000000..d201c68c0 --- /dev/null +++ b/centreon-plugins/storage/netapp/santricity/restapi/plugin.pm @@ -0,0 +1,49 @@ +# +# 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 storage::netapp::santricity::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} } = ( + 'hardware' => 'storage::netapp::santricity::restapi::mode::hardware' + ); + + $self->{custom_modes}{api} = 'storage::netapp::santricity::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Netapp storages with Santricity using Rest API. + +=cut From e2141ca0740fc1c8f96413bf2826c80b6c0ad1f6 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 6 May 2020 16:25:22 +0200 Subject: [PATCH 167/190] enhance counter template --- .../centreon/plugins/templates/counter.pm | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/centreon-plugins/centreon/plugins/templates/counter.pm b/centreon-plugins/centreon/plugins/templates/counter.pm index 5b56573ea..4ab923489 100644 --- a/centreon-plugins/centreon/plugins/templates/counter.pm +++ b/centreon-plugins/centreon/plugins/templates/counter.pm @@ -441,8 +441,10 @@ sub run_group { $prefix_output = '' if (!defined($prefix_output)); if ($multiple == 0 && (!defined($group->{display}) || $group->{display} != 0)) { - $self->{output}->output_add(severity => $self->{most_critical_instance}, - short_msg => sprintf("${prefix_output}" . $format_output, $self->{lproblems})); + $self->{output}->output_add( + severity => $self->{most_critical_instance}, + short_msg => sprintf("${prefix_output}" . $format_output, $self->{lproblems}) + ); } } } @@ -450,8 +452,10 @@ sub run_group { if ($multiple == 1) { my $exit = $self->{output}->get_most_critical(status => [ @{$global_exit} ]); if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf($format_output, $total_problems)); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf($format_output, $total_problems) + ); } } @@ -476,12 +480,12 @@ sub run_multiple_instances { my $multiple_parent = defined($options{multiple_parent}) && $options{multiple_parent} == 1 ? $options{multiple_parent} : 0; my $indent_long_output = defined($options{indent_long_output}) ? $options{indent_long_output} : ''; my $no_message_multiple = 1; - + my $multiple = 1; if (scalar(keys %{$self->{$options{config}->{name}}}) <= 1) { $multiple = 0; } - + my $message_separator = defined($options{config}->{message_separator}) ? $options{config}->{message_separator} : ', '; my $sort_method = 'cmp'; @@ -506,8 +510,10 @@ sub run_multiple_instances { $no_message_multiple = 0; $obj->set(instance => $instance); - my ($value_check) = $obj->execute(new_datas => $self->{new_datas}, - values => $self->{$options{config}->{name}}->{$id}); + my ($value_check) = $obj->execute( + new_datas => $self->{new_datas}, + values => $self->{$options{config}->{name}}->{$id} + ); next if (defined($options{config}->{skipped_code}) && defined($options{config}->{skipped_code}->{$value_check})); if ($value_check != 0) { $long_msg .= $long_msg_append . $obj->output_error(); @@ -549,17 +555,19 @@ sub run_multiple_instances { } if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->run_multiple_prefix_output(severity => $exit, - short_msg => $prefix_output . $short_msg . $suffix_output); + $self->run_multiple_prefix_output( + severity => $exit, + short_msg => $prefix_output . $short_msg . $suffix_output + ); } - + if ($multiple == 0 && $multiple_parent == 0) { $self->run_multiple_prefix_output(severity => 'ok', short_msg => $prefix_output . $long_msg . $suffix_output); } } - + if ($no_message_multiple == 0 && $multiple == 1 && $multiple_parent == 0) { - $self->{output}->output_add(short_msg => $options{config}->{message_multiple}); + $self->run_multiple_prefix_output(severity => 'ok', short_msg => $options{config}->{message_multiple}); } } @@ -572,7 +580,7 @@ sub run_multiple_prefix_output { $self->{prefix_multiple_output_done}->{lc($options{severity})} = 1; $separator{separator} = ''; } - + $self->{output}->output_add(severity => $options{severity}, short_msg => "$options{short_msg}", %separator); } From 35e203806679436950dc77300f525853020c5304 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 6 May 2020 16:26:04 +0200 Subject: [PATCH 168/190] Fix #1807 --- .../netapp/santricity/restapi/custom/api.pm | 4 +- .../santricity/restapi/mode/storagepools.pm | 176 ++++++++++++++++ .../santricity/restapi/mode/storagesystems.pm | 194 ++++++++++++++++++ .../santricity/restapi/mode/storagevolumes.pm | 189 +++++++++++++++++ .../netapp/santricity/restapi/plugin.pm | 5 +- 5 files changed, 566 insertions(+), 2 deletions(-) create mode 100644 centreon-plugins/storage/netapp/santricity/restapi/mode/storagepools.pm create mode 100644 centreon-plugins/storage/netapp/santricity/restapi/mode/storagesystems.pm create mode 100644 centreon-plugins/storage/netapp/santricity/restapi/mode/storagevolumes.pm diff --git a/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm b/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm index ac5f26aa5..227aaeb99 100644 --- a/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm +++ b/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm @@ -184,7 +184,7 @@ sub execute_storages_request { my $content = do { local $/ = undef; - if (!open my $fh, "<", '/home/qgarnier/clients/plugins/todo/santricity/test-inventory.txt') { + if (!open my $fh, "<", '/home/qgarnier/clients/plugins/todo/santricity/test-storages.txt') { $self->{output}->add_option_msg(short_msg => "Could not open file $self->{option_results}->{$_} : $!"); $self->{output}->option_exit(); } @@ -196,6 +196,8 @@ sub execute_storages_request { return $content; my $storages = $self->request_api(name => 'storages', endpoint => '/storage-systems'); + return $storages if (!defined($options{endpoint})); + for (my $i = 0; $i < scalar(@{$storages->{storages}}); $i++) { next if (defined($options{filter_name}) && $options{filter_name} ne '' && $storages->{storages}->{$i}->{name} !~ /$options{filter_name}/); diff --git a/centreon-plugins/storage/netapp/santricity/restapi/mode/storagepools.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/storagepools.pm new file mode 100644 index 000000000..ce91c0354 --- /dev/null +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/storagepools.pm @@ -0,0 +1,176 @@ +# +# 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 storage::netapp::santricity::restapi::mode::storagepools; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + 'state: %s [raid status: %s]', + $self->{result_values}->{state}, + $self->{result_values}->{raid_status} + ); +} + +sub ss_long_output { + my ($self, %options) = @_; + + return "checking storage system '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_ss_output { + my ($self, %options) = @_; + + return "storage system '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_pool_output { + my ($self, %options) = @_; + + return "pool '" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'ss', type => 3, cb_prefix_output => 'prefix_ss_output', cb_long_output => 'ss_long_output', indent_long_output => ' ', message_multiple => 'All storage systems are ok', + group => [ + { name => 'pools', display_long => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'pools are ok', type => 1, skipped_code => { -10 => 1 } } + ] + } + ]; + + $self->{maps_counters}->{pools} = [ + { label => 'pool-status', threshold => 0, set => { + key_values => [ { name => 'raid_status' }, { name => 'state'}, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-storage-name:s' => { name => 'filter_storage_name' }, + 'filter-pool-name:s' => { name => 'filter_pool_name' }, + 'unknown-pool-status:s' => { name => 'unknown_pool_status', default => '' }, + 'warning-pool-status:s' => { name => 'warning_pool_status', default => '%{raid_status} =~ /degraded/i' }, + 'critical-pool-status:s' => { name => 'critical_pool_status', default => '%{raid_status} =~ /failed/i' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_pool_status', 'critical_pool_status', 'unknown_pool_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $results = $options{custom}->execute_storages_request( + endpoint => '/storage-pools', + filter_name => $self->{option_results}->{filter_storage_name} + ); + + $self->{ss} = {}; + foreach (@{$results->{storages}}) { + my $storage_name = $_->{name}; + + $self->{ss}->{$storage_name} = { + display => $storage_name, + pools => {} + }; + + next if (!defined($_->{'/storage-pools'})); + + foreach my $entry (@{$_->{'/storage-pools'}}) { + + next if (defined($self->{option_results}->{filter_pool_name}) && $self->{option_results}->{filter_pool_name} ne '' && + $entry->{name} !~ /$self->{option_results}->{filter_pool_name}/); + + $self->{ss}->{$storage_name}->{pools}->{ $entry->{name} } = { + display => $entry->{name}, + state => $entry->{state}, + raid_status => $entry->{raidStatus} + }; + } + } +} + +1; + +__END__ + +=head1 MODE + +Check storage pools. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^pool-status$' + +=item B<--filter-storage-name> + +Filter storage name (can be a regexp). + +=item B<--filter-pool-name> + +Filter pool name (can be a regexp). + +=item B<--unknown-pool-status> + +Set unknown threshold for status. +Can used special variables like: %{raid_status}, %{state}, %{display} + +=item B<--warning-pool-status> + +Set warning threshold for status (Default: '%{raid_status} =~ /degraded/i'). +Can used special variables like: %{raid_status}, %{state}, %{display} + +=item B<--critical-pool-status> + +Set critical threshold for status (Default: '%{raid_status} =~ /failed/i'). +Can used special variables like: %{raid_status}, %{state}, %{display} + +=back + +=cut diff --git a/centreon-plugins/storage/netapp/santricity/restapi/mode/storagesystems.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/storagesystems.pm new file mode 100644 index 000000000..a1ca67925 --- /dev/null +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/storagesystems.pm @@ -0,0 +1,194 @@ +# +# 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 storage::netapp::santricity::restapi::mode::storagesystems; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + 'status: %s', + $self->{result_values}->{status} + ); +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space_absolute}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space_absolute}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space_absolute}); + my $msg = sprintf( + 'space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)', + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_space_absolute}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space_absolute} + ); + return $msg; +} + +sub prefix_ss_output { + my ($self, %options) = @_; + + return "storage system '" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'ss', type => 1, cb_prefix_output => 'prefix_ss_output', message_multiple => 'All storage systems are ok' } + ]; + + $self->{maps_counters}->{ss} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + }, + { label => 'usage', nlabel => 'pool.space.usage.bytes', set => { + key_values => [ { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'used_space_absolute', template => '%d', min => 0, max => 'total_space_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1 } + ] + } + }, + { label => 'usage-free', nlabel => 'pool.space.free.bytes', display_ok => 0, set => { + key_values => [ { name => 'free_space' }, { name => 'used_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'free_space_absolute', template => '%d', min => 0, max => 'total_space_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1 } + ] + } + }, + { label => 'usage-prct', nlabel => 'pool.space.usage.percentage', display_ok => 0, set => { + key_values => [ { name => 'prct_used_space' }, { name => 'display' } ], + output_template => 'used : %.2f %%', + perfdatas => [ + { value => 'prct_used_space_absolute', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1 } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-storage-name:s' => { name => 'filter_storage_name' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /needsAttn/i' } + }); + + 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}->execute_storages_request(); + + $self->{ss} = {}; + foreach (@{$results->{storages}}) { + my $storage_name = $_->{name}; + + next if (defined($options{filter_storage_name}) && $options{filter_storage_name} ne '' && + $storage_name !~ /$options{filter_storage_name}/); + + $self->{ss}->{$storage_name} = { + display => $_->{name}, + status => $_->{status}, + total_space => $_->{usedPoolSpace} + $_->{freePoolSpace}, + used_space => $_->{usedPoolSpace}, + free_space => $_->{freePoolSpace}, + prct_used_space => + ($_->{usedPoolSpace} * 100 / ($_->{usedPoolSpace} + $_->{freePoolSpace})), + prct_free_space => + ($_->{freePoolSpace} * 100 / ($_->{usedPoolSpace} + $_->{freePoolSpace})) + }; + } +} + +1; + +__END__ + +=head1 MODE + +Check storage systems. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='status' + +=item B<--filter-storage-name> + +Filter storage name (can be a regexp). + +=item B<--unknown-status> + +Set unknown threshold for status. +Can used special variables like: %{status}, %{state}, %{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} =~ /needsAttn/i'). +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/storage/netapp/santricity/restapi/mode/storagevolumes.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/storagevolumes.pm new file mode 100644 index 000000000..1746a8052 --- /dev/null +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/storagevolumes.pm @@ -0,0 +1,189 @@ +# +# 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 storage::netapp::santricity::restapi::mode::storagevolumes; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + 'status: %s', + $self->{result_values}->{status} + ); +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space_absolute}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space_absolute}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space_absolute}); + my $msg = sprintf( + 'space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)', + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_space_absolute}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space_absolute} + ); + return $msg; +} + +sub ss_long_output { + my ($self, %options) = @_; + + return "checking storage system '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_ss_output { + my ($self, %options) = @_; + + return "storage system '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_volume_output { + my ($self, %options) = @_; + + return "volume '" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'ss', type => 3, cb_prefix_output => 'prefix_ss_output', cb_long_output => 'ss_long_output', indent_long_output => ' ', message_multiple => 'All storage systems are ok', + group => [ + { name => 'volumes', display_long => 1, cb_prefix_output => 'prefix_volume_output', message_multiple => 'volumes are ok', type => 1, skipped_code => { -10 => 1 } } + ] + } + ]; + + $self->{maps_counters}->{volumes} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-storage-name:s' => { name => 'filter_storage_name' }, + 'filter-volume-name:s' => { name => 'filter_volume_name' }, + 'unknown-volyme-status:s' => { name => 'unknown_volume_status', default => '' }, + 'warning-volume-status:s' => { name => 'warning_volume_status', default => '%{status} =~ /degraded/i' }, + 'critical-volume-status:s' => { name => 'critical_volume_status', default => '%{status} =~ /failed/i' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_volume_status', 'critical_volume_status', 'unknown_volume_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $results = $options{custom}->execute_storages_request( + endpoint => '/storage-volumes', + filter_name => $self->{option_results}->{filter_storage_name} + ); + + $self->{ss} = {}; + foreach (@{$results->{storages}}) { + my $storage_name = $_->{name}; + + $self->{ss}->{$storage_name} = { + display => $storage_name, + volumes => {} + }; + + next if (!defined($_->{'/storage-volumes'})); + + foreach my $entry (@{$_->{'/storage-volumes'}}) { + + next if (defined($options{filter_volume_name}) && $options{filter_volume_name} ne '' && + $entry->{name} !~ /$options{filter_volume_name}/); + + $self->{ss}->{$storage_name}->{volumes}->{ $entry->{name} } = { + display => $entry->{name}, + status => $entry->{status} + }; + } + } +} + +1; + +__END__ + +=head1 MODE + +Check storage volumes. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='volume-status' + +=item B<--filter-storage-name> + +Filter storage name (can be a regexp). + +=item B<--filter-volume-name> + +Filter volume name (can be a regexp). + +=item B<--unknown-volume-status> + +Set unknown threshold for status. +Can used special variables like: %{status}, %{display} + +=item B<--warning-volume-status> + +Set warning threshold for status (Default: '%{status} =~ /degraded/i'). +Can used special variables like: %{status}, %{display} + +=item B<--critical-volume-status> + +Set critical threshold for status (Default: '%{status} =~ /failed/i'). +Can used special variables like: %{status}, %{display} + +=back + +=cut diff --git a/centreon-plugins/storage/netapp/santricity/restapi/plugin.pm b/centreon-plugins/storage/netapp/santricity/restapi/plugin.pm index d201c68c0..1ede0b11e 100644 --- a/centreon-plugins/storage/netapp/santricity/restapi/plugin.pm +++ b/centreon-plugins/storage/netapp/santricity/restapi/plugin.pm @@ -31,7 +31,10 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( - 'hardware' => 'storage::netapp::santricity::restapi::mode::hardware' + 'hardware' => 'storage::netapp::santricity::restapi::mode::hardware', + 'storage-pools' => 'storage::netapp::santricity::restapi::mode::storagepools', + 'storage-systems' => 'storage::netapp::santricity::restapi::mode::storagesystems', + 'storage-volumes' => 'storage::netapp::santricity::restapi::mode::storagevolumes' ); $self->{custom_modes}{api} = 'storage::netapp::santricity::restapi::custom::api'; From ec4b758807fa5dd0a2f7c74771f1634e68c4904c Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 6 May 2020 16:27:31 +0200 Subject: [PATCH 169/190] Fix #1807 --- .../storage/netapp/santricity/restapi/custom/api.pm | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm b/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm index 227aaeb99..b74f810c7 100644 --- a/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm +++ b/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm @@ -182,19 +182,6 @@ sub request_api { sub execute_storages_request { my ($self, %options) = @_; - my $content = do { - local $/ = undef; - if (!open my $fh, "<", '/home/qgarnier/clients/plugins/todo/santricity/test-storages.txt') { - $self->{output}->add_option_msg(short_msg => "Could not open file $self->{option_results}->{$_} : $!"); - $self->{output}->option_exit(); - } - <$fh>; - }; - eval { - $content = JSON::XS->new->utf8->decode($content); - }; - return $content; - my $storages = $self->request_api(name => 'storages', endpoint => '/storage-systems'); return $storages if (!defined($options{endpoint})); From 7ed541126a5ad29f7ffb21dc11764c12ff305762 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 6 May 2020 17:21:23 +0200 Subject: [PATCH 170/190] wip netapp santricity --- .../storage/netapp/santricity/restapi/custom/api.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm b/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm index b74f810c7..d68cbec38 100644 --- a/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm +++ b/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm @@ -151,7 +151,7 @@ sub request_api { $self->settings(); my $content = $self->{http}->request( method => defined($options{method}) ? $options{method} : 'GET', - url_path => $self->{api_path} . '/' . $options{endpoint}, + url_path => $self->{api_path} . $options{endpoint}, unknown_status => $self->{unknown_http_status}, warning_status => $self->{warning_http_status}, critical_status => $self->{critical_http_status}, From 41d780387a1b5a8718cfdfeb84eab70c128ed9d0 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 6 May 2020 17:30:00 +0200 Subject: [PATCH 171/190] wip netapp santricity --- .../storage/netapp/santricity/restapi/custom/api.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm b/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm index d68cbec38..fb5df8190 100644 --- a/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm +++ b/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm @@ -189,11 +189,11 @@ sub execute_storages_request { next if (defined($options{filter_name}) && $options{filter_name} ne '' && $storages->{storages}->{$i}->{name} !~ /$options{filter_name}/); - my $info = $self->request_api(name => 'info', endpoint => '/' . $storages->{storages}->{$i}->{wwn} . '/' . $options{endpoint}); - $storages->{storages}->{$i}->{offline} = 0; - $storages->{storages}->{$i}->{offline} = 1 if (!defined($info)); + my $info = $self->request_api(name => 'info', endpoint => '/' . $storages->{storages}->[$i]->{wwn} . '/' . $options{endpoint}); + $storages->{storages}->[$i]->{offline} = 0; + $storages->{storages}->[$i]->{offline} = 1 if (!defined($info)); - $storages->{storages}->{$i}->{ $options{endpoint} } = defined($info) ? $info->{info} : undef; + $storages->{storages}->[$i]->{ $options{endpoint} } = defined($info) ? $info->{info} : undef; } return $storages; From 365fa3c34f7f8e8aa67a3fe451c8f05c3ac2ff34 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 6 May 2020 17:30:13 +0200 Subject: [PATCH 172/190] wip netapp santricity --- .../storage/netapp/santricity/restapi/custom/api.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm b/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm index fb5df8190..0fe7f72d7 100644 --- a/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm +++ b/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm @@ -187,7 +187,7 @@ sub execute_storages_request { for (my $i = 0; $i < scalar(@{$storages->{storages}}); $i++) { next if (defined($options{filter_name}) && $options{filter_name} ne '' && - $storages->{storages}->{$i}->{name} !~ /$options{filter_name}/); + $storages->{storages}->[$i]->{name} !~ /$options{filter_name}/); my $info = $self->request_api(name => 'info', endpoint => '/' . $storages->{storages}->[$i]->{wwn} . '/' . $options{endpoint}); $storages->{storages}->[$i]->{offline} = 0; From c4daf559f238696abbadbc8e0b9b6cf724afeac0 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 6 May 2020 17:35:16 +0200 Subject: [PATCH 173/190] wip netapp santricity --- .../storage/netapp/santricity/restapi/custom/api.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm b/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm index 0fe7f72d7..c6bbaa9d2 100644 --- a/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm +++ b/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm @@ -189,7 +189,7 @@ sub execute_storages_request { next if (defined($options{filter_name}) && $options{filter_name} ne '' && $storages->{storages}->[$i]->{name} !~ /$options{filter_name}/); - my $info = $self->request_api(name => 'info', endpoint => '/' . $storages->{storages}->[$i]->{wwn} . '/' . $options{endpoint}); + my $info = $self->request_api(name => 'info', endpoint => '/' . $storages->{storages}->[$i]->{wwn} . $options{endpoint}); $storages->{storages}->[$i]->{offline} = 0; $storages->{storages}->[$i]->{offline} = 1 if (!defined($info)); From 0492ade4effc535de8fdce39c2cdaf76ca99fffc Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 6 May 2020 17:45:24 +0200 Subject: [PATCH 174/190] wip netapp santricity --- .../storage/netapp/santricity/restapi/custom/api.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm b/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm index c6bbaa9d2..18ed368ae 100644 --- a/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm +++ b/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm @@ -189,7 +189,7 @@ sub execute_storages_request { next if (defined($options{filter_name}) && $options{filter_name} ne '' && $storages->{storages}->[$i]->{name} !~ /$options{filter_name}/); - my $info = $self->request_api(name => 'info', endpoint => '/' . $storages->{storages}->[$i]->{wwn} . $options{endpoint}); + my $info = $self->request_api(name => 'info', endpoint => '/storage-systems/' . $storages->{storages}->[$i]->{wwn} . $options{endpoint}); $storages->{storages}->[$i]->{offline} = 0; $storages->{storages}->[$i]->{offline} = 1 if (!defined($info)); From a3c27e3282d7cdc69419e502cfe54c659aac6868 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 6 May 2020 17:55:51 +0200 Subject: [PATCH 175/190] wip netapp santricity --- .../netapp/santricity/restapi/mode/storagevolumes.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/centreon-plugins/storage/netapp/santricity/restapi/mode/storagevolumes.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/storagevolumes.pm index 1746a8052..92a7df658 100644 --- a/centreon-plugins/storage/netapp/santricity/restapi/mode/storagevolumes.pm +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/storagevolumes.pm @@ -118,7 +118,7 @@ sub manage_selection { my ($self, %options) = @_; my $results = $options{custom}->execute_storages_request( - endpoint => '/storage-volumes', + endpoint => '/volumes', filter_name => $self->{option_results}->{filter_storage_name} ); @@ -131,9 +131,9 @@ sub manage_selection { volumes => {} }; - next if (!defined($_->{'/storage-volumes'})); + next if (!defined($_->{'/volumes'})); - foreach my $entry (@{$_->{'/storage-volumes'}}) { + foreach my $entry (@{$_->{'/volumes'}}) { next if (defined($options{filter_volume_name}) && $options{filter_volume_name} ne '' && $entry->{name} !~ /$options{filter_volume_name}/); From f107321dee7ef786d1cf970b41d07f50c0a443b4 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 7 May 2020 08:58:47 +0200 Subject: [PATCH 176/190] fix typo --- .../storage/netapp/santricity/restapi/mode/hardware.pm | 4 ++-- .../storage/netapp/santricity/restapi/mode/storagevolumes.pm | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/centreon-plugins/storage/netapp/santricity/restapi/mode/hardware.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/hardware.pm index fd025d731..0fb65c47c 100644 --- a/centreon-plugins/storage/netapp/santricity/restapi/mode/hardware.pm +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/hardware.pm @@ -48,7 +48,7 @@ sub set_system { ['overtemp', ''], ['expired', 'WARNING'], ['maintenanceCharging', 'OK'], - ['replacementRequired', 'CRTICICAL'] + ['replacementRequired', 'CRITICAL'] ], board => [ ['unknown', 'UNKNOWN'], @@ -78,7 +78,7 @@ sub set_system { ['optimal', 'OK'], ['failed', 'CRITICAL'], ['removed', 'OK'], - ['rpaParErr', 'WAARNING'], + ['rpaParErr', 'WARNING'], ['serviceMode', 'OK'], ['suspended', 'OK'], ['degraded', 'WARNING'] diff --git a/centreon-plugins/storage/netapp/santricity/restapi/mode/storagevolumes.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/storagevolumes.pm index 92a7df658..a3cac70db 100644 --- a/centreon-plugins/storage/netapp/santricity/restapi/mode/storagevolumes.pm +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/storagevolumes.pm @@ -80,7 +80,7 @@ sub set_counters { ]; $self->{maps_counters}->{volumes} = [ - { label => 'status', threshold => 0, set => { + { label => 'volume-status', threshold => 0, set => { key_values => [ { name => 'status' }, { name => 'display' } ], closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_status_output'), @@ -99,7 +99,7 @@ sub new { $options{options}->add_options(arguments => { 'filter-storage-name:s' => { name => 'filter_storage_name' }, 'filter-volume-name:s' => { name => 'filter_volume_name' }, - 'unknown-volyme-status:s' => { name => 'unknown_volume_status', default => '' }, + 'unknown-volume-status:s' => { name => 'unknown_volume_status', default => '' }, 'warning-volume-status:s' => { name => 'warning_volume_status', default => '%{status} =~ /degraded/i' }, 'critical-volume-status:s' => { name => 'critical_volume_status', default => '%{status} =~ /failed/i' } }); From 4d150c3ae670acfa16321a1570bca1d6db605438 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 7 May 2020 10:16:30 +0200 Subject: [PATCH 177/190] add some checks for netapp santricity --- .../netapp/santricity/restapi/custom/api.pm | 24 +- .../santricity/restapi/mode/hardware.pm | 4 +- .../restapi/mode/storagecontrollers.pm | 252 ++++++++++++++++++ .../santricity/restapi/mode/storagepools.pm | 2 +- .../santricity/restapi/mode/storagevolumes.pm | 82 ++++-- .../netapp/santricity/restapi/plugin.pm | 9 +- 6 files changed, 344 insertions(+), 29 deletions(-) create mode 100644 centreon-plugins/storage/netapp/santricity/restapi/mode/storagecontrollers.pm diff --git a/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm b/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm index 18ed368ae..2974c381a 100644 --- a/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm +++ b/centreon-plugins/storage/netapp/santricity/restapi/custom/api.pm @@ -182,18 +182,30 @@ sub request_api { sub execute_storages_request { my ($self, %options) = @_; - my $storages = $self->request_api(name => 'storages', endpoint => '/storage-systems'); - return $storages if (!defined($options{endpoint})); + my $storages = $self->request_api( + name => 'storages', + endpoint => '/storage-systems' + ); + return $storages if (!defined($options{endpoints})); for (my $i = 0; $i < scalar(@{$storages->{storages}}); $i++) { next if (defined($options{filter_name}) && $options{filter_name} ne '' && $storages->{storages}->[$i]->{name} !~ /$options{filter_name}/); - my $info = $self->request_api(name => 'info', endpoint => '/storage-systems/' . $storages->{storages}->[$i]->{wwn} . $options{endpoint}); $storages->{storages}->[$i]->{offline} = 0; - $storages->{storages}->[$i]->{offline} = 1 if (!defined($info)); - - $storages->{storages}->[$i]->{ $options{endpoint} } = defined($info) ? $info->{info} : undef; + + foreach (@{$options{endpoints}}) { + my $info = $self->request_api( + name => 'info', + endpoint => '/storage-systems/' . $storages->{storages}->[$i]->{wwn} . $_->{endpoint} . (defined($_->{get_param}) ? '?' . $_->{get_param} : '') + ); + if (!defined($info)) { + $storages->{storages}->[$i]->{offline} = 1; + last; + } + + $storages->{storages}->[$i]->{ $_->{endpoint} } = defined($info) ? $info->{info} : undef; + } } return $storages; diff --git a/centreon-plugins/storage/netapp/santricity/restapi/mode/hardware.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/hardware.pm index 0fb65c47c..e651fcb00 100644 --- a/centreon-plugins/storage/netapp/santricity/restapi/mode/hardware.pm +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/hardware.pm @@ -147,7 +147,9 @@ sub new { sub execute_custom { my ($self, %options) = @_; - $self->{json_results} = $options{custom}->execute_storages_request(endpoint => '/hardware-inventory'); + $self->{json_results} = $options{custom}->execute_storages_request( + endpoints => [ { endpoint => '/hardware-inventory' } ] + ); } 1; diff --git a/centreon-plugins/storage/netapp/santricity/restapi/mode/storagecontrollers.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/storagecontrollers.pm new file mode 100644 index 000000000..7ac1d81e9 --- /dev/null +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/storagecontrollers.pm @@ -0,0 +1,252 @@ +# +# 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 storage::netapp::santricity::restapi::mode::storagecontrollers; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use Digest::MD5 qw(md5_hex); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + 'status: %s', + $self->{result_values}->{status} + ); +} + +sub ss_long_output { + my ($self, %options) = @_; + + return "checking storage system '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_ss_output { + my ($self, %options) = @_; + + return "storage system '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_controller_output { + my ($self, %options) = @_; + + return "controller '" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'ss', type => 3, cb_prefix_output => 'prefix_ss_output', cb_long_output => 'ss_long_output', indent_long_output => ' ', message_multiple => 'All storage systems are ok', + group => [ + { name => 'controllers', display_long => 1, cb_prefix_output => 'prefix_controller_output', message_multiple => 'controllers are ok', type => 1, skipped_code => { -10 => 1 } } + ] + } + ]; + + $self->{maps_counters}->{controllers} = [ + { label => 'controller-status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + }, + { label => 'cpu-utilization', nlabel => 'volume.cpu.utilization.percentage', set => { + key_values => [ { name => 'cpu_util', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => 'cpu usage: %.2f %%', + perfdatas => [ + { value => 'cpu_util_per_second', template => '%d', + unit => '%', label_extra_instance => 1 } + ] + } + }, + { label => 'read', nlabel => 'volume.io.read.usage.bytespersecond', set => { + key_values => [ { name => 'read_bytes', diff => 1 }, { name => 'display' } ], + output_template => 'read: %s %s/s', + per_second => 1, output_change_bytes => 1, + perfdatas => [ + { value => 'read_bytes_per_second', template => '%d', + unit => 'B/s', label_extra_instance => 1 } + ] + } + }, + { label => 'write', nlabel => 'volume.io.write.usage.bytespersecond', set => { + key_values => [ { name => 'write_bytes', diff => 1 }, { name => 'display' } ], + output_template => 'write: %s %s/s', + per_second => 1, output_change_bytes => 1, + perfdatas => [ + { value => 'write_bytes_per_second', template => '%d', + unit => 'B/s', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'read-iops', nlabel => 'system.io.read.usage.iops', set => { + key_values => [ { name => 'read_iops', diff => 1 }, { name => 'display' } ], + output_template => 'read: %.2f iops', + per_second => 1, + perfdatas => [ + { value => 'read_iops_per_second', template => '%.2f', + unit => 'iops', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'write-iops', nlabel => 'system.io.write.usage.iops', set => { + key_values => [ { name => 'write_iops', diff => 1 }, { name => 'display' } ], + output_template => 'write: %.2f iops', + per_second => 1, + perfdatas => [ + { value => 'write_iops_per_second', template => '%.2f', + unit => 'iops', min => 0, 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-storage-name:s' => { name => 'filter_storage_name' }, + 'filter-controller-name:s' => { name => 'filter_controller_name' }, + 'unknown-controller-status:s' => { name => 'unknown_controller_status', default => '%{status} =~ /unknown/i' }, + 'warning-controller-status:s' => { name => 'warning_controller_status', default => '%{status} =~ /rpaParErr|degraded/i' }, + 'critical-controller-status:s' => { name => 'critical_controller_status', default => '%{status} =~ /failed/i' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_controller_status', 'critical_controller_status', 'unknown_controller_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $results = $options{custom}->execute_storages_request( + endpoints => [ + { endpoint => '/controllers' }, + { endpoint => '/controller-statistics', get_param => 'usecache=false' } + ], + filter_name => $self->{option_results}->{filter_storage_name} + ); + + my $mapping_controller = {}; + $self->{ss} = {}; + foreach (@{$results->{storages}}) { + my $storage_name = $_->{name}; + + $self->{ss}->{$storage_name} = { + display => $storage_name, + controllers => {} + }; + + next if (!defined($_->{'/controllers'})); + + foreach my $entry (@{$_->{'/controllers'}}) { + my $name = $entry->{physicalLocation}->{label} ne '' ? $entry->{physicalLocation}->{label} : + $entry->{physicalLocation}->{locationPosition} . ':' . $entry->{physicalLocation}->{slot}; + + next if (defined($options{filter_controller_name}) && $options{filter_controller_name} ne '' && + $name !~ /$options{filter_controller_name}/); + + $mapping_controller->{ $entry->{id} } = $name; + $self->{ss}->{$storage_name}->{controllers}->{ $name } = { + display => $name, + status => $entry->{status} + }; + } + + foreach my $entry (@{$_->{'/controller-statistics'}}) { + next if (!defined($mapping_controller->{ $entry->{controllerId} })); + + $self->{ss}->{$storage_name}->{controllers}->{ $mapping_controller->{ $entry->{controllerId} } }->{write_bytes} = $entry->{writeBytesTotal}; + $self->{ss}->{$storage_name}->{controllers}->{ $mapping_controller->{ $entry->{controllerId} } }->{read_bytes} = $entry->{readBytesTotal}; + $self->{ss}->{$storage_name}->{controllers}->{ $mapping_controller->{ $entry->{controllerId} } }->{read_iops} = $entry->{readIopsTotal}; + $self->{ss}->{$storage_name}->{controllers}->{ $mapping_controller->{ $entry->{controllerId} } }->{write_iops} = $entry->{writeIopsTotal}; + $self->{ss}->{$storage_name}->{controllers}->{ $mapping_controller->{ $entry->{controllerId} } }->{cpu_util} = $entry->{cpuUtilizationStats}->[0]->{sumCpuUtilization}; + } + } + + $self->{cache_name} = 'netapp_santricity' . $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_storage_name}) ? md5_hex($self->{option_results}->{filter_storage_name}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_controller_name}) ? md5_hex($self->{option_results}->{filter_controller_name}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check storage controllers. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='volume-status' + +=item B<--filter-storage-name> + +Filter storage name (can be a regexp). + +=item B<--filter-controller-name> + +Filter controller name (can be a regexp). + +=item B<--unknown-controller-status> + +Set unknown threshold for status (Default: '%{status} =~ /unknown/i'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-controller-status> + +Set warning threshold for status (Default: '%{status} =~ /rpaParErr|degraded/i'). +Can used special variables like: %{status}, %{display} + +=item B<--critical-controller-status> + +Set critical threshold for status (Default: '%{status} =~ /failed/i'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'read' (B/s), 'write' (B/s), 'read-iops', 'write-iops'. + +=back + +=cut diff --git a/centreon-plugins/storage/netapp/santricity/restapi/mode/storagepools.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/storagepools.pm index ce91c0354..752538a13 100644 --- a/centreon-plugins/storage/netapp/santricity/restapi/mode/storagepools.pm +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/storagepools.pm @@ -104,7 +104,7 @@ sub manage_selection { my ($self, %options) = @_; my $results = $options{custom}->execute_storages_request( - endpoint => '/storage-pools', + endpoints => [ { endpoint => '/storage-pools' } ], filter_name => $self->{option_results}->{filter_storage_name} ); diff --git a/centreon-plugins/storage/netapp/santricity/restapi/mode/storagevolumes.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/storagevolumes.pm index a3cac70db..544ef1b40 100644 --- a/centreon-plugins/storage/netapp/santricity/restapi/mode/storagevolumes.pm +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/storagevolumes.pm @@ -25,6 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use Digest::MD5 qw(md5_hex); sub custom_status_output { my ($self, %options) = @_; @@ -35,21 +36,6 @@ sub custom_status_output { ); } -sub custom_usage_output { - my ($self, %options) = @_; - - my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space_absolute}); - my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space_absolute}); - my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space_absolute}); - my $msg = sprintf( - 'space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)', - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_space_absolute}, - $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space_absolute} - ); - return $msg; -} - sub ss_long_output { my ($self, %options) = @_; @@ -87,13 +73,53 @@ sub set_counters { closure_custom_perfdata => sub { return 0; }, closure_custom_threshold_check => \&catalog_status_threshold } + }, + { label => 'read', nlabel => 'volume.io.read.usage.bytespersecond', set => { + key_values => [ { name => 'read_bytes', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_change_bytes => 1, output_template => 'read: %s %s/s', + perfdatas => [ + { value => 'read_bytes_per_second', template => '%d', + unit => 'B/s', label_extra_instance => 1 } + ] + } + }, + { label => 'write', nlabel => 'volume.io.write.usage.bytespersecond', set => { + key_values => [ { name => 'write_bytes', diff => 1 }, { name => 'display' } ], + output_template => 'write: %s %s/s', + per_second => 1, output_change_bytes => 1, + perfdatas => [ + { value => 'write_bytes_per_second', template => '%d', + unit => 'B/s', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'read-iops', nlabel => 'system.io.read.usage.iops', set => { + key_values => [ { name => 'read_iops', diff => 1 }, { name => 'display' } ], + output_template => 'read: %.2f iops', + per_second => 1, + perfdatas => [ + { value => 'read_iops_per_second', template => '%.2f', + unit => 'iops', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'write-iops', nlabel => 'system.io.write.usage.iops', set => { + key_values => [ { name => 'write_iops', diff => 1 }, { name => 'display' } ], + output_template => 'write: %.2f iops', + per_second => 1, + perfdatas => [ + { value => 'write_iops_per_second', template => '%.2f', + unit => 'iops', min => 0, label_extra_instance => 1 } + ] + } } ]; } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { @@ -118,7 +144,10 @@ sub manage_selection { my ($self, %options) = @_; my $results = $options{custom}->execute_storages_request( - endpoint => '/volumes', + endpoints => [ + { endpoint => '/volumes' }, + { endpoint => '/volume-statistics', get_param => 'usecache=false' } + ], filter_name => $self->{option_results}->{filter_storage_name} ); @@ -143,7 +172,21 @@ sub manage_selection { status => $entry->{status} }; } + + foreach my $entry (@{$_->{'/volume-statistics'}}) { + next if (!defined($self->{ss}->{$storage_name}->{volumes}->{ $entry->{volumeName} })); + + $self->{ss}->{$storage_name}->{volumes}->{ $entry->{volumeName} }->{write_bytes} = $entry->{writeBytes}; + $self->{ss}->{$storage_name}->{volumes}->{ $entry->{volumeName} }->{read_bytes} = $entry->{readBytes}; + $self->{ss}->{$storage_name}->{volumes}->{ $entry->{volumeName} }->{read_iops} = $entry->{readOps}; + $self->{ss}->{$storage_name}->{volumes}->{ $entry->{volumeName} }->{write_iops} = $entry->{writeOps}; + } } + + $self->{cache_name} = 'netapp_santricity' . $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_storage_name}) ? md5_hex($self->{option_results}->{filter_storage_name}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_volume_name}) ? md5_hex($self->{option_results}->{filter_volume_name}) : md5_hex('all')); } 1; @@ -184,6 +227,11 @@ Can used special variables like: %{status}, %{display} Set critical threshold for status (Default: '%{status} =~ /failed/i'). Can used special variables like: %{status}, %{display} +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'read' (B/s), 'write' (B/s), 'read-iops', 'write-iops'. + =back =cut diff --git a/centreon-plugins/storage/netapp/santricity/restapi/plugin.pm b/centreon-plugins/storage/netapp/santricity/restapi/plugin.pm index 1ede0b11e..20945ee97 100644 --- a/centreon-plugins/storage/netapp/santricity/restapi/plugin.pm +++ b/centreon-plugins/storage/netapp/santricity/restapi/plugin.pm @@ -31,10 +31,11 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( - 'hardware' => 'storage::netapp::santricity::restapi::mode::hardware', - 'storage-pools' => 'storage::netapp::santricity::restapi::mode::storagepools', - 'storage-systems' => 'storage::netapp::santricity::restapi::mode::storagesystems', - 'storage-volumes' => 'storage::netapp::santricity::restapi::mode::storagevolumes' + 'hardware' => 'storage::netapp::santricity::restapi::mode::hardware', + 'storage-controllers' => 'storage::netapp::santricity::restapi::mode::storagecontrollers', + 'storage-pools' => 'storage::netapp::santricity::restapi::mode::storagepools', + 'storage-systems' => 'storage::netapp::santricity::restapi::mode::storagesystems', + 'storage-volumes' => 'storage::netapp::santricity::restapi::mode::storagevolumes' ); $self->{custom_modes}{api} = 'storage::netapp::santricity::restapi::custom::api'; From 7cc4b4599412dc1fb341e395ba14f72d5d2234c1 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 7 May 2020 10:41:36 +0200 Subject: [PATCH 178/190] add dell me4 interfaces + typo --- .../dell/me4/restapi/mode/interfaces.pm | 265 ++++++++++++++++++ .../storage/dell/me4/restapi/plugin.pm | 3 +- .../restapi/mode/storagecontrollers.pm | 4 +- 3 files changed, 269 insertions(+), 3 deletions(-) create mode 100644 centreon-plugins/storage/dell/me4/restapi/mode/interfaces.pm diff --git a/centreon-plugins/storage/dell/me4/restapi/mode/interfaces.pm b/centreon-plugins/storage/dell/me4/restapi/mode/interfaces.pm new file mode 100644 index 000000000..5aee01ee5 --- /dev/null +++ b/centreon-plugins/storage/dell/me4/restapi/mode/interfaces.pm @@ -0,0 +1,265 @@ +# +# 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 storage::dell::me4::restapi::mode::interfaces; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + 'status: %s [health: %s]', + $self->{result_values}->{status}, + $self->{result_values}->{health} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'ports', type => 3, cb_prefix_output => 'prefix_port_output', cb_long_output => 'port_long_output', indent_long_output => ' ', message_multiple => 'All interfaces are ok', + group => [ + { name => 'port_global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'interfaces', display_long => 1, cb_prefix_output => 'prefix_interface_output', message_multiple => 'All interfaces are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + $self->{maps_counters}->{port_global} = [ + { label => 'port-status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'health'}, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + }, + { label => 'read-iops', nlabel => 'port.io.read.usage.iops', set => { + key_values => [ { name => 'number_of_reads', diff => 1 }, { name => 'display' } ], + output_template => 'read iops: %.2f', + per_second => 1, + perfdatas => [ + { value => 'number_of_reads_per_second', template => '%.2f', + unit => 'iops', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'write-iops', nlabel => 'port.io.write.usage.iops', set => { + key_values => [ { name => 'number_of_writes', diff => 1 }, { name => 'display' } ], + output_template => 'write iops: %.2f', + per_second => 1, + perfdatas => [ + { value => 'number_of_writes_per_second', template => '%.2f', + unit => 'iops', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'read-traffic', nlabel => 'port.traffic.read.usage.bitspersecond', set => { + key_values => [ { name => 'data_read_numeric', diff => 1 }, { name => 'display' } ], + output_template => 'read traffic: %s %s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'data_read_numeric_per_second', template => '%d', + unit => 'b/s', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'write-traffic', nlabel => 'port.traffic.write.usage.bitspersecond', set => { + key_values => [ { name => 'data_write_numeric' }, { name => 'display' } ], + output_template => 'write traffic: %s %s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { value => 'data_write_numeric_per_second', template => '%d', + unit => 'b/s', min => 0, label_extra_instance => 1 } + ] + } + } + ]; + + $self->{maps_counters}->{interfaces} = [ + { label => 'interface-disparity-errors', nlabel => 'port.interface.disparity.errors.count', set => { + key_values => [ { name => 'disparity_errors' }, { name => 'display' } ], + output_template => 'disparity errors: %s', + perfdatas => [ + { value => 'disparity_errors_absolute', template => '%d', + min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'interface-lost-dwords', nlabel => 'port.interface.lost.dwords.count', set => { + key_values => [ { name => 'lost_dwords' }, { name => 'display' } ], + output_template => 'lost dwords: %s', + perfdatas => [ + { value => 'lost_dwords_absolute', template => '%d', + min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'interface-invalid-dwords', nlabel => 'port.interface.invalid.dwords.count', set => { + key_values => [ { name => 'lost_dwords' }, { name => 'display' } ], + output_template => 'invalid dwords: %s', + perfdatas => [ + { value => 'invalid_dwords_absolute', template => '%d', + min => 0, label_extra_instance => 1 } + ] + } + } + ]; +} + +sub port_long_output { + my ($self, %options) = @_; + + return "checking port '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_port_output { + my ($self, %options) = @_; + + return "port '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_interface_output { + my ($self, %options) = @_; + + return "interface '" . $options{instance_value}->{display} . "' "; +} + +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 => { + 'unknown-port-status:s' => { name => 'unknown_port_status', default => '%{health} =~ /unknown/i' }, + 'warning-port-status:s' => { name => 'warning_port_status', default => '%{health} =~ /degraded/i' }, + 'critical-port-status:s' => { name => 'critical_port_status', default => '%{health} =~ /fault/i' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_port_status', 'critical_port_status', 'unknown_port_status']); +} + +my $mapping_status = { + 0 => 'up', + 1 => 'down', + 2 => 'notInstalled' +}; +my $mapping_health = { + 0 => 'ok', 1 => 'degraded', 2 => 'fault', 3 => 'unknown', 4 => 'notAvailable' +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $result_ports = $options{custom}->request_api(method => 'GET', url_path => '/api/show/ports'); + my $result_ports_stats = $options{custom}->request_api(method => 'GET', url_path => '/api/show/host-port-statistics'); + my $result_logical_interfaces = $options{custom}->request_api(method => 'GET', url_path => '/api/show/host-phy-statistics'); + + my $mapping_ports = {}; + + $self->{ports} = {}; + foreach my $port (@{$result_ports->{port}}) { + my $port_name = $port->{port}; + $mapping_ports->{ $port->{'durable-id'} } = $port_name; + + $self->{ports}->{$port_name} = { + display => $port_name, + port_global => { + display => $port_name, + health => $mapping_health->{ $port->{'health-numeric'} }, + status => $mapping_status->{ $port->{'status-numeric'} } + }, + interfaces => {} + }; + } + + foreach (@{$result_ports_stats->{'host-port-statistics'}}) { + next if (!defined($mapping_ports->{ $_->{'durable-id'} })); + + $self->{ports}->{ $mapping_ports->{ $_->{'durable-id'} } }->{port_global}->{number_of_reads} = $_->{'number-of-reads'}; + $self->{ports}->{ $mapping_ports->{ $_->{'durable-id'} } }->{port_global}->{number_of_writes} = $_->{'number-of-writes'}; + $self->{ports}->{ $mapping_ports->{ $_->{'durable-id'} } }->{port_global}->{data_read_numeric} = $_->{'data-read-numeric'}; + $self->{ports}->{ $mapping_ports->{ $_->{'durable-id'} } }->{port_global}->{data_write_numeric} = $_->{'data-write-numeric'}; + + } + + foreach (@{$result_logical_interfaces->{'sas-host-phy-statistics'}}) { + next if ($self->{ports}->{ $_->{port} }); + + $self->{ports}->{ $_->{port} }->{interfaces}->{ $_->{phy} } = { + display => $_->{phy}, + disparity_errors => $_->{'disparity-errors'}, + invalid_dwords => $_->{'invalid-dwords'}, + lost_dwords => $_->{'lost-dwords'} + }; + } + + $self->{cache_name} = 'dell_me4_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check interfaces. + +=over 8 + +=item B<--unknown-port-status> + +Set unknown threshold for status (Default: '%{status} =~ /unknown/i'). +Can used special variables like: %{status}, %{health}, %{display} + +=item B<--warning-port-status> + +Set warning threshold for status (Default: '%{status} =~ /degraded/i'). +Can used special variables like: %{status}, %{health}, %{display} + +=item B<--critical-port-status> + +Set critical threshold for status (Default: '%{status} =~ /fault/i'). +Can used special variables like: %{status}, %{health}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'read-iops', 'write-iops', 'read-traffic', 'write-traffic', +'interface-disparity-errors', 'interface-lost-dwords', 'interface-invalid-dwords'. + +=back + +=cut diff --git a/centreon-plugins/storage/dell/me4/restapi/plugin.pm b/centreon-plugins/storage/dell/me4/restapi/plugin.pm index e044c3d94..ddb9a2c2d 100644 --- a/centreon-plugins/storage/dell/me4/restapi/plugin.pm +++ b/centreon-plugins/storage/dell/me4/restapi/plugin.pm @@ -33,9 +33,10 @@ sub new { %{ $self->{modes} } = ( 'controller-statistics' => 'storage::dell::me4::restapi::mode::controllerstatistics', 'hardware' => 'storage::dell::me4::restapi::mode::hardware', + 'interfaces' => 'storage::dell::me4::restapi::mode::interfaces', 'list-controllers' => 'storage::dell::me4::restapi::mode::listcontrollers', 'list-volumes' => 'storage::dell::me4::restapi::mode::listvolumes', - 'volume-statistics' => 'storage::dell::me4::restapi::mode::volumestatistics', + 'volume-statistics' => 'storage::dell::me4::restapi::mode::volumestatistics' ); $self->{custom_modes}{api} = 'storage::dell::me4::restapi::custom::api'; diff --git a/centreon-plugins/storage/netapp/santricity/restapi/mode/storagecontrollers.pm b/centreon-plugins/storage/netapp/santricity/restapi/mode/storagecontrollers.pm index 7ac1d81e9..b8af42419 100644 --- a/centreon-plugins/storage/netapp/santricity/restapi/mode/storagecontrollers.pm +++ b/centreon-plugins/storage/netapp/santricity/restapi/mode/storagecontrollers.pm @@ -217,7 +217,7 @@ Check storage controllers. =item B<--filter-counters> Only display some counters (regexp can be used). -Example: --filter-counters='volume-status' +Example: --filter-counters='controller-status' =item B<--filter-storage-name> @@ -245,7 +245,7 @@ Can used special variables like: %{status}, %{display} =item B<--warning-*> B<--critical-*> Thresholds. -Can be: 'read' (B/s), 'write' (B/s), 'read-iops', 'write-iops'. +Can be: 'cpu-utilization' (%), 'read' (B/s), 'write' (B/s), 'read-iops', 'write-iops'. =back From 6f88000e295d04b4d0ea58038a7bfdce0ef5044d Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 7 May 2020 10:42:32 +0200 Subject: [PATCH 179/190] add dell me4 interfaces --- .../storage/dell/me4/restapi/mode/interfaces.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/centreon-plugins/storage/dell/me4/restapi/mode/interfaces.pm b/centreon-plugins/storage/dell/me4/restapi/mode/interfaces.pm index 5aee01ee5..0936724b2 100644 --- a/centreon-plugins/storage/dell/me4/restapi/mode/interfaces.pm +++ b/centreon-plugins/storage/dell/me4/restapi/mode/interfaces.pm @@ -219,9 +219,9 @@ sub manage_selection { $self->{ports}->{ $_->{port} }->{interfaces}->{ $_->{phy} } = { display => $_->{phy}, - disparity_errors => $_->{'disparity-errors'}, - invalid_dwords => $_->{'invalid-dwords'}, - lost_dwords => $_->{'lost-dwords'} + disparity_errors => int($_->{'disparity-errors'}), + invalid_dwords => int($_->{'invalid-dwords'}), + lost_dwords => int($_->{'lost-dwords'}) }; } From b879e3983c10417bd68d88bb9f1770f105f133e1 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 7 May 2020 11:04:56 +0200 Subject: [PATCH 180/190] update changelog --- centreon-plugins/changelog | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/centreon-plugins/changelog b/centreon-plugins/changelog index 9204b28dd..4b477357f 100644 --- a/centreon-plugins/changelog +++ b/centreon-plugins/changelog @@ -1,3 +1,17 @@ +2020-XX-XX Quentin Garnier + * Plugin added: Ruckus SmartZone SNMP + * Plugin added: Ruckus ZoneDirector SNMP + * Plugin added: Ruckus ICX SNMP + * Plugin added: Dell Xseries SNMP + * Plugin added: Adva FSP150 SNMP + * Plugin added: Lenovo Iomega SNMP + * Plugin added: Netapp Santricity Rest API + * Plugin added: Bluemind + * Plugin added: Mulesoft Rest API + * Plugin added: Salesforce Rest API + * Break: [netapp/snmp] move directory + * Break: [netapp/restapi] move directory + 2020-04-10 Quentin Garnier * Plugin added: Dell OS10 SNMP * Plugin added: Sirportly notification From 78f5dbc106af27b3e0970578479b6698ba1c9c60 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 7 May 2020 16:40:22 +0200 Subject: [PATCH 181/190] add unit for nethost --- .../apps/vmware/connector/mode/nethost.pm | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/centreon-plugins/apps/vmware/connector/mode/nethost.pm b/centreon-plugins/apps/vmware/connector/mode/nethost.pm index 61ac63ff1..dc2da0c98 100644 --- a/centreon-plugins/apps/vmware/connector/mode/nethost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/nethost.pm @@ -408,17 +408,11 @@ Can used special variables like: %{link_status}, %{display} Set critical threshold for status (Default: '%{link_status} !~ /up/'). Can used special variables like: %{link_status}, %{display} -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. -Can be: 'host-traffic-in', 'host-traffic-out', 'vswitch-traffic-in', 'vswitch-traffic-out', -'link-traffic-in', 'link-traffic-out', 'link-dropped-in', 'link-dropped-out'. - -=item B<--critical-*> - -Threshold critical. -Can be: 'host-traffic-in', 'host-traffic-out', 'vswitch-traffic-in', 'vswitch-traffic-out', -'link-traffic-in', 'link-traffic-out', 'link-dropped-in', 'link-dropped-out'. +Thresholds. +Can be: 'host-traffic-in' (b/s), 'host-traffic-out' (b/s), 'vswitch-traffic-in' (b/s), 'vswitch-traffic-out' (b/s), +'link-traffic-in' (%), 'link-traffic-out' (%), 'link-dropped-in', 'link-dropped-out'. =item B<--no-proxyswitch> From 28234170adeabce5a9bbb3f64d9ff47dc3b638bb Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 11 May 2020 09:46:59 +0200 Subject: [PATCH 182/190] Fix #1987 --- .../network/nortel/standard/snmp/mode/cpu.pm | 133 +++++++++++------- .../nortel/standard/snmp/mode/memory.pm | 117 +++++++++++---- 2 files changed, 171 insertions(+), 79 deletions(-) diff --git a/centreon-plugins/network/nortel/standard/snmp/mode/cpu.pm b/centreon-plugins/network/nortel/standard/snmp/mode/cpu.pm index 166bb8f0e..0801b93f9 100644 --- a/centreon-plugins/network/nortel/standard/snmp/mode/cpu.pm +++ b/centreon-plugins/network/nortel/standard/snmp/mode/cpu.pm @@ -33,94 +33,124 @@ sub set_counters { ]; $self->{maps_counters}->{cpu} = [ - { label => 'total', set => { - key_values => [ { name => 'total' }, { name => 'num' } ], - output_template => 'Total CPU Usage : %.2f %%', - perfdatas => [ - { label => 'cpu_total', value => 'total_absolute', template => '%.2f', min => 0, max => 100, unit => '%', - label_extra_instance => 1, instance_use => 'num_absolute' }, - ], - } - }, - { label => '1m', set => { + { label => '1m', nlabel => 'cpu.utilization.1m.percentage', set => { key_values => [ { name => '1m' }, { name => 'num' } ], - output_template => '1 minute : %.2f %%', + output_template => '%.2f %% (1min)', perfdatas => [ { label => 'cpu_1min', value => '1m_absolute', template => '%.2f', - min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' }, - ], + min => 0, max => 100, unit => '%', label_extra_instance => 1 } + ] } }, - { label => '10m', set => { + { label => '5m', nlabel => 'cpu.utilization.5m.percentage', set => { + key_values => [ { name => '5m' }, { name => 'num' } ], + output_template => '%.2f %% (5min)', + perfdatas => [ + { label => 'cpu_5min', value => '5m_absolute', template => '%.2f', + min => 0, max => 100, unit => '%', label_extra_instance => 1 } + ] + } + }, + { label => '10m', nlabel => 'cpu.utilization.10m.percentage', set => { key_values => [ { name => '10m' }, { name => 'num' } ], - output_template => '10 minutes : %.2f %%', + output_template => '%.2f %% (10min)', perfdatas => [ { label => 'cpu_10min', value => '10m_absolute', template => '%.2f', - min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' }, - ], + min => 0, max => 100, unit => '%', label_extra_instance => 1 } + ] } }, - { label => '1h', set => { + { label => '1h', nlabel => 'cpu.utilization.1h.percentage', set => { key_values => [ { name => '1h' }, { name => 'num' } ], - output_template => '1 hour : %.2f %%', + output_template => '%.2f %% (1h)', perfdatas => [ { label => 'cpu_1h', value => '1h_absolute', template => '%.2f', - min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num_absolute' }, - ], + min => 0, max => 100, unit => '%', label_extra_instance => 1 } + ] } - }, + } ]; } sub prefix_cpu_output { my ($self, %options) = @_; - - return "CPU '" . $options{instance_value}->{num} . "' "; + + return "CPU '" . $options{instance_value}->{num} . "' usage "; } sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - }); - + + $options{options}->add_options(arguments => { + }); + return $self; } my $mapping = { - s5ChasUtilTotalCPUUsage => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.4' }, s5ChasUtilCPUUsageLast1Minute => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.5' }, s5ChasUtilCPUUsageLast10Minutes => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.6' }, - s5ChasUtilCPUUsageLast1Hour => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.7' }, + s5ChasUtilCPUUsageLast1Hour => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.7' } }; my $oid_rcSysCpuUtil = '.1.3.6.1.4.1.2272.1.1.20'; # without .0 my $oid_s5ChasUtilEntry = '.1.3.6.1.4.1.45.1.6.3.8.1.1'; +sub check_khi { + my ($self, %options) = @_; + + my $oid_rcKhiSlotCpu5MinAve = '.1.3.6.1.4.1.2272.1.85.10.1.1.3'; + my $snmp_result = $options{snmp}->get_table( + oid => $oid_rcKhiSlotCpu5MinAve, + nothing_quit => 1 + ); + + foreach (keys %$snmp_result) { + /.(\d+)$/; + + $self->{cpu}->{'slot_' . $1} = { + num => 'slot_' . $1, + '5m' => $snmp_result->{$_} + }; + } +} + sub manage_selection { my ($self, %options) = @_; - $self->{results} = $options{snmp}->get_multiple_table(oids => [ - { oid => $oid_rcSysCpuUtil }, - { oid => $oid_s5ChasUtilEntry }, - ], nothing_quit => 1); - + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_rcSysCpuUtil }, + { + oid => $oid_s5ChasUtilEntry, + start => $mapping->{s5ChasUtilCPUUsageLast1Minute}->{oid}, + end => $mapping->{s5ChasUtilCPUUsageLast1Hour}->{oid} + } + ] + ); + $self->{cpu} = {}; - foreach my $oid (keys %{$self->{results}->{$oid_s5ChasUtilEntry}}) { - next if ($oid !~ /^$mapping->{s5ChasUtilTotalCPUUsage}->{oid}\.(.*)$/); + foreach my $oid (keys %{$snmp_result->{$oid_s5ChasUtilEntry}}) { + next if ($oid !~ /^$mapping->{s5ChasUtilCPUUsageLast1Minute}->{oid}\.(.*)$/); my $instance = $1; - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_s5ChasUtilEntry}, instance => $instance); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_s5ChasUtilEntry}, instance => $instance); - $self->{cpu}->{$instance} = { num => $instance, total => $result->{s5ChasUtilTotalCPUUsage}, - '1m' => $result->{s5ChasUtilCPUUsageLast1Minute}, '10m' => $result->{s5ChasUtilCPUUsageLast10Minutes}, - '1h' => $result->{s5ChasUtilCPUUsageLast1Hour} }; + $self->{cpu}->{$instance} = { + num => $instance, + '1m' => $result->{s5ChasUtilCPUUsageLast1Minute}, + '10m' => $result->{s5ChasUtilCPUUsageLast10Minutes}, + '1h' => $result->{s5ChasUtilCPUUsageLast1Hour} + }; } - - if (scalar(keys %{$self->{results}->{$oid_rcSysCpuUtil}}) > 0) { - $self->{cpu}->{0} = { num => 0, total => $self->{results}->{$oid_rcSysCpuUtil}->{$oid_rcSysCpuUtil . '.0'} }; + + if (scalar(keys %{$snmp_result->{$oid_rcSysCpuUtil}}) > 0) { + $self->{cpu}->{0} = { num => 0, total => $snmp_result->{$oid_rcSysCpuUtil}->{$oid_rcSysCpuUtil . '.0'} }; + } + + if (scalar(keys %{$self->{cpu}}) <= 0) { + $self->check_khi(snmp => $options{snmp}); } } @@ -137,17 +167,12 @@ Check CPU usages. =item B<--filter-counters> Only display some counters (regexp can be used). -Example: --filter-counters='^(1m|10m)$' +Example: --filter-counters='1m|10m' -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. -Can be: 'total', '1m', '5m', '10m', '1h'. - -=item B<--critical-*> - -Threshold critical. -Can be: 'total', '1m', '5m', '10m', '1h'. +Thresholds. +Can be: '1m', '5m', '10m', '1h'. =back diff --git a/centreon-plugins/network/nortel/standard/snmp/mode/memory.pm b/centreon-plugins/network/nortel/standard/snmp/mode/memory.pm index 0a89d76cb..6a18a407b 100644 --- a/centreon-plugins/network/nortel/standard/snmp/mode/memory.pm +++ b/centreon-plugins/network/nortel/standard/snmp/mode/memory.pm @@ -25,23 +25,54 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub custom_usage_output { + my ($self, %options) = @_; + + return sprintf( + 'total: %s %s used: %s %s (%.2f%%) free: %s %s (%.2f%%)', + $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}), + $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}), + $self->{result_values}->{prct_used_absolute}, + $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}), + $self->{result_values}->{prct_free_absolute} + ); +} + sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'memory', type => 1, cb_prefix_output => 'prefix_memory_output', message_multiple => 'All memory usages are ok' } + { name => 'memory', type => 1, cb_prefix_output => 'prefix_memory_output', message_multiple => 'All memory usages are ok', skipped_code => { -10 => 1 } } ]; $self->{maps_counters}->{memory} = [ - { label => 'usage', set => { - key_values => [ { name => 'used' }, { name => 'display' } ], - output_template => 'Used : %.2f %%', + { label => 'usage', display_ok => 0, nlabel => 'memory.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], + closure_custom_output => $self->can('custom_usage_output'), perfdatas => [ - { label => 'used', value => 'used_absolute', template => '%.2f', min => 0, max => 100, unit => '%', - label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + { value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1 } + ] } }, + { label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1 } + ] + } + }, + { label => 'usage-prct', nlabel => 'memory.usage.percentage', set => { + key_values => [ { name => 'prct_used' }, { name => 'display' } ], + output_template => 'used: %.2f %%', + perfdatas => [ + { value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%', + label_extra_instance => 1 }, + ] + } + } ]; } @@ -53,33 +84,72 @@ sub prefix_memory_output { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - }); - + + $options{options}->add_options(arguments => { + }); + return $self; } my $mapping = { - s5ChasUtilMemoryAvailable => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.9' }, + s5ChasUtilMemoryAvailable => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.9' } }; +my $mapping_khi = { + rcKhiSlotMemUsed => { oid => '.1.3.6.1.4.1.2272.1.85.10.1.1.6' }, # KB + rcKhiSlotMemFree => { oid => '.1.3.6.1.4.1.2272.1.85.10.1.1.7' } # KB +}; +my $oid_rcKhiSlotPerfEntry = '.1.3.6.1.4.1.2272.1.85.10.1.1'; + +sub check_khi { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_table( + oid => $oid_rcKhiSlotPerfEntry, + start => $mapping_khi->{rcKhiSlotMemUsed}->{oid}, + end => $mapping_khi->{rcKhiSlotMemFree}->{oid}, + nothing_quit => 1 + ); + + foreach (keys %$snmp_result) { + next if (! /^$mapping_khi->{rcKhiSlotMemUsed}->{oid}\.(\d+)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping_khi, results => $snmp_result, instance => $instance); + + my $total = $result->{rcKhiSlotMemUsed} * 1024 + $result->{rcKhiSlotMemFree} * 1024; + $self->{memory}->{'slot_' . $1} = { + display => 'slot_' . $1, + used => $result->{rcKhiSlotMemUsed} * 1024, + free => $result->{rcKhiSlotMemFree} * 1024, + prct_used => $result->{rcKhiSlotMemUsed} * 1024 / $total, + prct_free => $result->{rcKhiSlotMemFree} * 1024 / $total, + total => $total + }; + } +} sub manage_selection { my ($self, %options) = @_; + my $snmp_result = $options{snmp}->get_table( + oid => $mapping->{s5ChasUtilMemoryAvailable}->{oid}, + ); + $self->{memory} = {}; - $self->{results} = $options{snmp}->get_table(oid => $mapping->{s5ChasUtilMemoryAvailable}->{oid}, - nothing_quit => 1); foreach my $oid (keys %{$self->{results}}) { next if ($oid !~ /^$mapping->{s5ChasUtilMemoryAvailable}->{oid}\.(.*)/); my $instance = $1; - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); - $self->{memory}->{$instance} = { display => $instance, - used => 100 - $result->{s5ChasUtilMemoryAvailable}}; + $self->{memory}->{$instance} = { + display => $instance, + prct_used => 100 - $result->{s5ChasUtilMemoryAvailable} + }; + } + + if (scalar(keys %{$self->{memory}}) <= 0) { + $self->check_khi(snmp => $options{snmp}); } } @@ -93,13 +163,10 @@ Check memory usages. =over 8 -=item B<--warning-usage> +=item B<--warning-*> B<--critical-*> -Threshold warning (in percent). - -=item B<--critical-usage> - -Threshold critical (in percent). +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%). =back From a3f3478bf2167382b12c0959cb38a00adabc5726 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 11 May 2020 09:52:02 +0200 Subject: [PATCH 183/190] set back total for cpu nortel --- .../network/nortel/standard/snmp/mode/cpu.pm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/centreon-plugins/network/nortel/standard/snmp/mode/cpu.pm b/centreon-plugins/network/nortel/standard/snmp/mode/cpu.pm index 0801b93f9..f95ef9523 100644 --- a/centreon-plugins/network/nortel/standard/snmp/mode/cpu.pm +++ b/centreon-plugins/network/nortel/standard/snmp/mode/cpu.pm @@ -33,6 +33,15 @@ sub set_counters { ]; $self->{maps_counters}->{cpu} = [ + { label => 'total', nlabel => 'cpu.utilization.total.percentage', set => { + key_values => [ { name => 'total' }, { name => 'num' } ], + output_template => '%.2f %% (total)', + perfdatas => [ + { label => 'cpu_total', value => 'total_absolute', template => '%.2f', + min => 0, max => 100, unit => '%', label_extra_instance => 1 } + ] + } + }, { label => '1m', nlabel => 'cpu.utilization.1m.percentage', set => { key_values => [ { name => '1m' }, { name => 'num' } ], output_template => '%.2f %% (1min)', @@ -90,6 +99,7 @@ sub new { } my $mapping = { + s5ChasUtilTotalCPUUsage => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.4' }, s5ChasUtilCPUUsageLast1Minute => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.5' }, s5ChasUtilCPUUsageLast10Minutes => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.6' }, s5ChasUtilCPUUsageLast1Hour => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.7' } @@ -139,6 +149,7 @@ sub manage_selection { $self->{cpu}->{$instance} = { num => $instance, + total => $result->{s5ChasUtilTotalCPUUsage}, '1m' => $result->{s5ChasUtilCPUUsageLast1Minute}, '10m' => $result->{s5ChasUtilCPUUsageLast10Minutes}, '1h' => $result->{s5ChasUtilCPUUsageLast1Hour} @@ -172,7 +183,7 @@ Example: --filter-counters='1m|10m' =item B<--warning-*> B<--critical-*> Thresholds. -Can be: '1m', '5m', '10m', '1h'. +Can be: 'total', '1m', '5m', '10m', '1h'. =back From 0b53e4053bb9e5ee2ff7dd672097b7cd885e09e2 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 11 May 2020 11:01:46 +0200 Subject: [PATCH 184/190] add vernemq plugin --- .../apps/mq/vernemq/restapi/custom/api.pm | 220 ++++++++++++++++++ .../apps/mq/vernemq/restapi/mode/clusters.pm | 165 +++++++++++++ .../apps/mq/vernemq/restapi/mode/listeners.pm | 165 +++++++++++++ .../apps/mq/vernemq/restapi/mode/plugins.pm | 99 ++++++++ .../apps/mq/vernemq/restapi/mode/sessions.pm | 103 ++++++++ .../apps/mq/vernemq/restapi/plugin.pm | 52 +++++ 6 files changed, 804 insertions(+) create mode 100644 centreon-plugins/apps/mq/vernemq/restapi/custom/api.pm create mode 100644 centreon-plugins/apps/mq/vernemq/restapi/mode/clusters.pm create mode 100644 centreon-plugins/apps/mq/vernemq/restapi/mode/listeners.pm create mode 100644 centreon-plugins/apps/mq/vernemq/restapi/mode/plugins.pm create mode 100644 centreon-plugins/apps/mq/vernemq/restapi/mode/sessions.pm create mode 100644 centreon-plugins/apps/mq/vernemq/restapi/plugin.pm diff --git a/centreon-plugins/apps/mq/vernemq/restapi/custom/api.pm b/centreon-plugins/apps/mq/vernemq/restapi/custom/api.pm new file mode 100644 index 000000000..a4e498482 --- /dev/null +++ b/centreon-plugins/apps/mq/vernemq/restapi/custom/api.pm @@ -0,0 +1,220 @@ +# +# 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::mq::vernemq::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-key:s' => { name => 'api_key' }, + '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} : 8888; + $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'http'; + $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; + $self->{api_key} = (defined($self->{option_results}->{api_key})) ? $self->{option_results}->{api_key} : undef; + $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 (!defined($self->{hostname}) || $self->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); + $self->{output}->option_exit(); + } + if (!defined($self->{api_key}) || $self->{api_key} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-key option."); + $self->{output}->option_exit(); + } + + return 0; +} + +sub build_options_for_httplib { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = $self->{api_key} . '@' . $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}->set_options(%{$self->{option_results}}); + $self->{settings_done} = 1; +} + +sub get_hostname { + my ($self, %options) = @_; + + return $self->{hostname}; +} + +sub get_port { + my ($self, %options) = @_; + + return $self->{port}; +} + +sub request_api { + my ($self, %options) = @_; + + $self->settings(); + + my $content = do { + local $/ = undef; + if (!open my $fh, "<", '/tmp/plop.txt') { + $self->{output}->add_option_msg(short_msg => "Could not open file $self->{option_results}->{$_} : $!"); + $self->{output}->option_exit(); + } + <$fh>; + }; + #my $content = $self->{http}->request( + # method => defined($options{method}) ? $options{method} : 'GET', + # url_path => '/api/v1' . $options{endpoint}, + # unknown_status => $self->{unknown_http_status}, + # warning_status => $self->{warning_http_status}, + # critical_status => $self->{critical_http_status} + #); + + 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; +} + +1; + +__END__ + +=head1 NAME + +VerneMQ Rest API + +=head1 REST API OPTIONS + +VerneMQ Rest API + +=over 8 + +=item B<--hostname> + +Set hostname. + +=item B<--port> + +Port used (Default: 8888) + +=item B<--proto> + +Specify https if needed (Default: 'http') + +=item B<--api-key> + +VerneMQ API Token. + +=item B<--timeout> + +Set timeout in seconds (Default: 10). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/apps/mq/vernemq/restapi/mode/clusters.pm b/centreon-plugins/apps/mq/vernemq/restapi/mode/clusters.pm new file mode 100644 index 000000000..0dc8c8618 --- /dev/null +++ b/centreon-plugins/apps/mq/vernemq/restapi/mode/clusters.pm @@ -0,0 +1,165 @@ +# +# 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::mq::vernemq::restapi::mode::clusters; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return 'status: ' . $self->{result_values}->{status}; +} + +sub prefix_cluster_output { + my ($self, %options) = @_; + + return "Cluster '" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'clusters', type => 1, cb_prefix_output => 'prefix_cluster_output', message_multiple => 'All clusters are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'running', nlabel => 'clusters.running.count', display_ok => 0, set => { + key_values => [ { name => 'running' } ], + output_template => 'current clusters running: %s', + perfdatas => [ + { value => 'running_absolute', template => '%s', min => 0 } + ] + } + }, + { label => 'notrunning', nlabel => 'clusters.notrunning.count', display_ok => 0, set => { + key_values => [ { name => 'notrunning' } ], + output_template => 'current clusters not running: %s', + perfdatas => [ + { value => 'notrunning_absolute', template => '%s', min => 0 } + ] + } + } + ]; + + $self->{maps_counters}->{clusters} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, 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} eq "notRunning"' }, + }); + + 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 $clusters = $options{custom}->request_api(endpoint => '/cluster/show'); + + $self->{global} = { running => 0, notrunning => 0 }; + $self->{clusters} = {}; + foreach (@{$clusters->{table}}) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $_->{Node} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping cluster '" . $_->{Node} . "': no matching filter.", debug => 1); + next; + } + + $_->{Running} ? $self->{global}->{running}++ : $self->{global}->{notrunning}++; + $self->{clusters}->{$_->{Node}} = { + display => $_->{Node}, + status => $_->{Running} ? 'running' : 'notRunning' + }; + } + + if (scalar(keys %{$self->{clusters}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No cluster found"); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check clusters. + +=over 8 + +=item B<--filter-name> + +Filter cluster 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} eq "notRunning"'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'running', 'notrunning'. + +=back + +=cut diff --git a/centreon-plugins/apps/mq/vernemq/restapi/mode/listeners.pm b/centreon-plugins/apps/mq/vernemq/restapi/mode/listeners.pm new file mode 100644 index 000000000..8da916ebe --- /dev/null +++ b/centreon-plugins/apps/mq/vernemq/restapi/mode/listeners.pm @@ -0,0 +1,165 @@ +# +# 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::mq::vernemq::restapi::mode::listeners; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return 'status: ' . $self->{result_values}->{status}; +} + +sub prefix_listener_output { + my ($self, %options) = @_; + + return "Listener '" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'listeners', type => 1, cb_prefix_output => 'prefix_listener_output', message_multiple => 'All listeners are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'running', nlabel => 'listeners.running.count', display_ok => 0, set => { + key_values => [ { name => 'running' } ], + output_template => 'current listeners running: %s', + perfdatas => [ + { value => 'running_absolute', template => '%s', min => 0 } + ] + } + }, + { label => 'notrunning', nlabel => 'listeners.notrunning.count', display_ok => 0, set => { + key_values => [ { name => 'notrunning' } ], + output_template => 'current listeners not running: %s', + perfdatas => [ + { value => 'notrunning_absolute', template => '%s', min => 0 } + ] + } + } + ]; + + $self->{maps_counters}->{listeners} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-type:s' => { name => 'filter_type' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} ne "running"' }, + }); + + 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 $clusters = $options{custom}->request_api(endpoint => '/listener/show'); + + $self->{global} = { running => 0, notrunning => 0 }; + $self->{listeners} = {}; + foreach (@{$clusters->{table}}) { + if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && + $_->{type} !~ /$self->{option_results}->{filter_type}/) { + $self->{output}->output_add(long_msg => "skipping listeners '" . $_->{type} . "': no matching filter.", debug => 1); + next; + } + + $_->{status} eq 'running' ? $self->{global}->{running}++ : $self->{global}->{notrunning}++; + $self->{listeners}->{$_->{type}} = { + display => $_->{type}, + status => $_->{status} + }; + } + + if (scalar(keys %{$self->{listeners}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No listener found"); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check listeners. + +=over 8 + +=item B<--filter-type> + +Filter listener type (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} ne "running"'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'running', 'notrunning'. + +=back + +=cut diff --git a/centreon-plugins/apps/mq/vernemq/restapi/mode/plugins.pm b/centreon-plugins/apps/mq/vernemq/restapi/mode/plugins.pm new file mode 100644 index 000000000..49fef8ace --- /dev/null +++ b/centreon-plugins/apps/mq/vernemq/restapi/mode/plugins.pm @@ -0,0 +1,99 @@ +# +# 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::mq::vernemq::restapi::mode::plugins; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total', nlabel => 'plugins.total.count', set => { + key_values => [ { name => 'total' } ], + output_template => 'current total plugins: %s', + perfdatas => [ + { value => 'total_absolute', template => '%s', min => 0 } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' } + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $plugins = $options{custom}->request_api( + endpoint => '/plugin/show' + ); + + $self->{global} = { total => 0 }; + foreach (@{$plugins->{table}}) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $_->{Plugin} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping plugin '" . $_->{Plugin} . "': no matching filter.", debug => 1); + next; + } + + $self->{global}->{total}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check plugins. + +=over 8 + +=item B<--filter-name> + +Filter plugin name (can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'total'. + +=back + +=cut diff --git a/centreon-plugins/apps/mq/vernemq/restapi/mode/sessions.pm b/centreon-plugins/apps/mq/vernemq/restapi/mode/sessions.pm new file mode 100644 index 000000000..d3f2cdde7 --- /dev/null +++ b/centreon-plugins/apps/mq/vernemq/restapi/mode/sessions.pm @@ -0,0 +1,103 @@ +# +# 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::mq::vernemq::restapi::mode::sessions; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub prefix_session_output { + my ($self, %options) = @_; + + return 'Sessions '; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_session_output', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'online', nlabel => 'sessions.online.count', set => { + key_values => [ { name => 'online' } ], + output_template => 'current online: %s', + perfdatas => [ + { value => 'online_absolute', template => '%s', min => 0 } + ] + } + }, + { label => 'total', nlabel => 'sessions.total.count', set => { + key_values => [ { name => 'total' } ], + output_template => 'current total: %s', + perfdatas => [ + { value => 'total_absolute', template => '%s', min => 0 } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $sessions = $options{custom}->request_api( + endpoint => '/session/show' + ); + + $self->{global} = { total => 0, online => 0 }; + foreach (@{$sessions->{table}}) { + $self->{global}->{online}++ if ($_->{is_online}); + $self->{global}->{total}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check sessions. + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'total', 'online'. + +=back + +=cut diff --git a/centreon-plugins/apps/mq/vernemq/restapi/plugin.pm b/centreon-plugins/apps/mq/vernemq/restapi/plugin.pm new file mode 100644 index 000000000..a861913d3 --- /dev/null +++ b/centreon-plugins/apps/mq/vernemq/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::mq::vernemq::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} } = ( + 'clusters' => 'apps::mq::vernemq::restapi::mode::clusters', + 'listeners' => 'apps::mq::vernemq::restapi::mode::listeners', + 'plugins' => 'apps::mq::vernemq::restapi::mode::plugins', + 'sessions' => 'apps::mq::vernemq::restapi::mode::sessions' + ); + + $self->{custom_modes}{api} = 'apps::mq::vernemq::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check VerneMQ using Rest API. + +=cut From d048535db5d6e6060af9648748c91828738f0b54 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 11 May 2020 11:02:06 +0200 Subject: [PATCH 185/190] add vernemq plugin --- .../apps/mq/vernemq/restapi/custom/api.pm | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/centreon-plugins/apps/mq/vernemq/restapi/custom/api.pm b/centreon-plugins/apps/mq/vernemq/restapi/custom/api.pm index a4e498482..b59b70166 100644 --- a/centreon-plugins/apps/mq/vernemq/restapi/custom/api.pm +++ b/centreon-plugins/apps/mq/vernemq/restapi/custom/api.pm @@ -143,22 +143,13 @@ sub request_api { my ($self, %options) = @_; $self->settings(); - - my $content = do { - local $/ = undef; - if (!open my $fh, "<", '/tmp/plop.txt') { - $self->{output}->add_option_msg(short_msg => "Could not open file $self->{option_results}->{$_} : $!"); - $self->{output}->option_exit(); - } - <$fh>; - }; - #my $content = $self->{http}->request( - # method => defined($options{method}) ? $options{method} : 'GET', - # url_path => '/api/v1' . $options{endpoint}, - # unknown_status => $self->{unknown_http_status}, - # warning_status => $self->{warning_http_status}, - # critical_status => $self->{critical_http_status} - #); + my $content = $self->{http}->request( + method => defined($options{method}) ? $options{method} : 'GET', + url_path => '/api/v1' . $options{endpoint}, + unknown_status => $self->{unknown_http_status}, + warning_status => $self->{warning_http_status}, + critical_status => $self->{critical_http_status} + ); 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() . "']"); From eaa3a1423d345f7209419b08526b7bac4cede2a4 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 11 May 2020 13:54:40 +0200 Subject: [PATCH 186/190] add active msq --- .../java/solr/jmx/mode/requesthandlerusage.pm | 11 +- .../apps/mq/activemq/jmx/mode/brokers.pm | 284 ++++++++++++++++++ .../apps/mq/activemq/jmx/mode/listbrokers.pm | 116 +++++++ .../apps/mq/activemq/jmx/plugin.pm | 50 +++ 4 files changed, 455 insertions(+), 6 deletions(-) create mode 100644 centreon-plugins/apps/mq/activemq/jmx/mode/brokers.pm create mode 100644 centreon-plugins/apps/mq/activemq/jmx/mode/listbrokers.pm create mode 100644 centreon-plugins/apps/mq/activemq/jmx/plugin.pm diff --git a/centreon-plugins/apps/java/solr/jmx/mode/requesthandlerusage.pm b/centreon-plugins/apps/java/solr/jmx/mode/requesthandlerusage.pm index 735f5d26f..244f703de 100644 --- a/centreon-plugins/apps/java/solr/jmx/mode/requesthandlerusage.pm +++ b/centreon-plugins/apps/java/solr/jmx/mode/requesthandlerusage.pm @@ -77,12 +77,11 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name', default => '(/select|/update)$' }, - }); - + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name', default => '(/select|/update)$' } + }); + return $self; } diff --git a/centreon-plugins/apps/mq/activemq/jmx/mode/brokers.pm b/centreon-plugins/apps/mq/activemq/jmx/mode/brokers.pm new file mode 100644 index 000000000..b8f1c746b --- /dev/null +++ b/centreon-plugins/apps/mq/activemq/jmx/mode/brokers.pm @@ -0,0 +1,284 @@ +# +# 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::mq::activemq::jmx::mode::brokers; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'brokers', type => 3, cb_prefix_output => 'prefix_broker_output', cb_long_output => 'broker_long_output', indent_long_output => ' ', message_multiple => 'All brokers are ok', + group => [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'queues', display_long => 1, cb_prefix_output => 'prefix_queue_output', message_multiple => 'All queue destinations are ok', type => 1, skipped_code => { -10 => 1 } } + ] + } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'store-usage', nlabel => 'broker.store.usage.percentage', set => { + key_values => [ { name => 'StorePercentUsage' }, { name => 'display' } ], + output_template => 'store usage: %.2f %%', + perfdatas => [ + { value => 'StorePercentUsage_absolute', template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 } + ] + } + }, + { label => 'temporary-usage', nlabel => 'broker.temporary.usage.percentage', set => { + key_values => [ { name => 'TempPercentUsage' }, { name => 'display' } ], + output_template => 'temporary usage: %.2f %%', + perfdatas => [ + { value => 'TempPercentUsage_absolute', template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 } + ] + } + }, + { label => 'memory-usage', nlabel => 'broker.memory.usage.percentage', set => { + key_values => [ { name => 'MemoryPercentUsage' }, { name => 'display' } ], + output_template => 'memory usage: %.2f %%', + perfdatas => [ + { value => 'MemoryPercentUsage_absolute', template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 } + ] + } + } + ]; + + $self->{maps_counters}->{queues} = [ + { label => 'queue-average-enqueue-time', nlabel => 'broker.queue.average.enqueue.time.milliseconds', set => { + key_values => [ { name => 'AverageEnqueueTime' }, { name => 'display' } ], + output_template => 'average time messages remained enqueued: %.3f ms', + perfdatas => [ + { value => 'AverageEnqueueTime_absolute', + template => '%.3f', unit => 'ms', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'queue-consumers-connected', nlabel => 'broker.queue.consumers.connected.count', set => { + key_values => [ { name => 'ConsumerCount' }, { name => 'display' } ], + output_template => 'consumers connected: %s', + perfdatas => [ + { value => 'ConsumerCount_absolute', + template => '%s', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'queue-producers-connected', nlabel => 'broker.queue.producers.connected.count', display_ok => 0, set => { + key_values => [ { name => 'ProducerCount' }, { name => 'display' } ], + output_template => 'producers connected: %s', + perfdatas => [ + { value => 'ProducerCount_absolute', + template => '%s', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'queue-memory-usage', nlabel => 'broker.queue.memory.usage.percentage', display_ok => 0, set => { + key_values => [ { name => 'MemoryPercentUsage' }, { name => 'display' } ], + output_template => 'memory usage: %.2f %%', + perfdatas => [ + { value => 'MemoryPercentUsage_absolute', + template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 } + ] + } + }, + { label => 'queue-size', nlabel => 'broker.queue.size.count', set => { + key_values => [ { name => 'QueueSize' }, { name => 'display' } ], + output_template => 'queue size: %s', + perfdatas => [ + { value => 'QueueSize_absolute', + template => '%s', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'queue-enqueued', nlabel => 'broker.queue.enqueued.count', display_ok => 0, set => { + key_values => [ { name => 'EnqueueCount', diff => 1 }, { name => 'display' } ], + output_template => 'messages enqueued: %s', + perfdatas => [ + { value => 'EnqueueCount_absolute', + template => '%s', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'queue-dequeued', nlabel => 'broker.queue.dequeue.count', display_ok => 0, set => { + key_values => [ { name => 'DequeueCount', diff => 1 }, { name => 'display' } ], + output_template => 'messages dequeued: %s', + perfdatas => [ + { value => 'DequeueCount_absolute', + template => '%s', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'queue-expired', nlabel => 'broker.queue.expired.count', display_ok => 0, set => { + key_values => [ { name => 'ExpiredCount', diff => 1 }, { name => 'display' } ], + output_template => 'messages expired: %s', + perfdatas => [ + { value => 'ExpiredCount_absolute', + template => '%s', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'queue-inflighted', nlabel => 'broker.queue.inflighted.count', display_ok => 0, set => { + key_values => [ { name => 'InFlightCount', diff => 1 }, { name => 'display' } ], + output_template => 'messages in-flighted: %s', + perfdatas => [ + { value => 'InFlightCount_absolute', + template => '%s', min => 0, label_extra_instance => 1 } + ] + } + } + ]; +} + +sub broker_long_output { + my ($self, %options) = @_; + + return "checking broker '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_broker_output { + my ($self, %options) = @_; + + return "Broker '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_qeueue_output { + my ($self, %options) = @_; + + return "queue destination '" . $options{instance_value}->{display} . "' "; +} + +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-broker-name:s' => { name => 'filter_broker_name' }, + 'filter-destination-name:s' => { name => 'filter_destination_name' } + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $request = [ + { + mbean => 'org.apache.activemq:brokerName=*,destinationName=*,destinationType=Topic,type=Broker', + attributes => [ + { name => 'AverageEnqueueTime' }, { name => 'ConsumerCount' }, + { name => 'ProducerCount' }, { name => 'MemoryPercentUsage' }, + { name => 'QueueSize' }, { name => 'EnqueueCount' }, + { name => 'DequeueCount' }, { name => 'ExpiredCount' }, + { name => 'InFlightCount' } + ] + }, + { + mbean => 'org.apache.activemq:brokerName=*,type=Broker', + attributes => [ + { name => 'StorePercentUsage' }, { name => 'TempPercentUsage' }, + { name => 'MemoryPercentUsage' } + ] + } + ]; + my $result = $options{custom}->get_attributes(request => $request, nothing_quit => 1); + + $self->{cache_name} = 'activemq_' . $self->{mode} . '_' . md5_hex($options{custom}->get_connection_info()) . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_broker_name}) ? md5_hex($self->{option_results}->{filter_broker_name}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_destination_name}) ? md5_hex($self->{option_results}->{filter_destination_name}) : md5_hex('all')); + + $self->{brokers} = {}; + foreach my $mbean (keys %$result) { + next if ($mbean !~ /org.apache.activemq:brokerName=(.*?),(?:destinationName=(.*?),|type=Broker)/); + my ($broker_name, $destination_name) = ($1, $2); + + if (defined($self->{option_results}->{filter_broker_name}) && $self->{option_results}->{filter_broker_name} ne '' && + $broker_name !~ /$self->{option_results}->{filter_broker_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $broker_name . "': no matching filter.", debug => 1); + next; + } + + if (!defined($self->{brokers}->{$broker_name})) { + $self->{brokers}->{$broker_name} = { + display => $broker_name, + queues => {} + }; + } + + if (defined($destination_name)) { + if (defined($self->{option_results}->{filter_destination_name}) && $self->{option_results}->{filter_destination_name} ne '' && + $destination_name !~ /$self->{option_results}->{filter_destination_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $destination_name . "': no matching filter.", debug => 1); + next; + } + + $self->{brokers}->{$broker_name}->{queues}->{$destination_name} = { + display => $destination_name, + %{$result->{$mbean}} + }; + } else { + $self->{brokers}->{$broker_name}->{global} = { + display => $broker_name, + %{$result->{$mbean}} + }; + } + + } + + if (scalar(keys %{$self->{brokers}}) <= 0) { + $self->{output}->output_add(short_msg => 'no brokers found'); + } +} + +1; + +__END__ + +=head1 MODE + +Check brokers. + +=over 8 + +=item B<--filter-broker-name> + +Filter broker name (Can be a regexp). + +=item B<--filter-destination-name> + +Filter destination name (Can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'store-usage' (%), 'temporary-usage' (%), 'memory-usage' (%), +'queue-average-enqueue-time' (ms), 'queue-consumers-connected', +'queue-producers-connected', 'queue-memory-usage' (%), 'queue-size', +'queue-enqueued', 'queue-dequeued', 'queue-expired', 'queue-inflighted'. + +=back + +=cut diff --git a/centreon-plugins/apps/mq/activemq/jmx/mode/listbrokers.pm b/centreon-plugins/apps/mq/activemq/jmx/mode/listbrokers.pm new file mode 100644 index 000000000..0457cbae7 --- /dev/null +++ b/centreon-plugins/apps/mq/activemq/jmx/mode/listbrokers.pm @@ -0,0 +1,116 @@ +# +# 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::mq::activemq::jmx::mode::listbrokers; + +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) = @_; + + my $request = [ + { + mbean => 'org.apache.activemq:brokerName=*,type=Broker', + attributes => [ + { name => 'BrokerName' } + ] + } + ]; + my $datas = $options{custom}->get_attributes(request => $request); + + my $results = {}; + foreach (keys %$datas) { + $results->{$datas->{$_}->{BrokerName}} = { name => $datas->{$_}->{BrokerName} }; + } + + return $results; +} + +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]', + $_ + ) + ); + } + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List brokers:' + ); + $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']); +} + +sub disco_show { + my ($self, %options) = @_; + + my $results = $self->manage_selection(custom => $options{custom}); + foreach (sort keys %$results) { + $self->{output}->add_disco_entry( + name => $_ + ); + } +} + +1; + +__END__ + +=head1 MODE + +List brokers. + +=over 8 + +=back + +=cut + diff --git a/centreon-plugins/apps/mq/activemq/jmx/plugin.pm b/centreon-plugins/apps/mq/activemq/jmx/plugin.pm new file mode 100644 index 000000000..553b638e7 --- /dev/null +++ b/centreon-plugins/apps/mq/activemq/jmx/plugin.pm @@ -0,0 +1,50 @@ +# +# 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::mq::activemq::jmx::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}} = ( + 'brokers' => 'apps::mq::activemq::jmx::mode::brokers', + 'list-brokers' => 'apps::mq::activemq::jmx::mode::listbrokers' + ); + + $self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check ActiveMQ in JMX. Need Jolokia agent. + +=cut From 1b5720ae107d57e7637389c5c30e86e6c2c006ea Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 11 May 2020 14:51:11 +0200 Subject: [PATCH 187/190] update timelink --- .../timelinkmicro/tms6001/snmp/mode/alarm.pm | 104 ------------------ .../timelinkmicro/tms6001/snmp/mode/alarms.pm | 87 +++++++++++++++ .../tms6001/snmp/mode/antenna.pm | 95 +++++++++++----- .../tms6001/snmp/mode/frequency.pm | 86 ++++++--------- .../timelinkmicro/tms6001/snmp/mode/gnss.pm | 86 ++++++++++----- .../tms6001/snmp/mode/satellites.pm | 87 ++++++--------- .../timelinkmicro/tms6001/snmp/mode/time.pm | 85 ++++++-------- .../timelinkmicro/tms6001/snmp/plugin.pm | 17 ++- 8 files changed, 323 insertions(+), 324 deletions(-) delete mode 100644 centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarm.pm create mode 100644 centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarms.pm diff --git a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarm.pm b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarm.pm deleted file mode 100644 index 3f236e7d1..000000000 --- a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarm.pm +++ /dev/null @@ -1,104 +0,0 @@ -# -# Copyright 2019 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. -# -# Authors : Thomas Gourdin thomas.gourdin@gmail.com - -package hardware::devices::timelinkmicro::tms6001::snmp::mode::alarm; - -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 => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } - -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - - my $oid_qualityfrequency = '.1.3.6.1.4.1.22641.100.3.3.0'; - - my $result = $self->{snmp}->get_leef(oids => [ $oid_qualityfrequency ], nothing_quit => 1); - - my $value = $result->{$oid_qualityfrequency}; - - my $exit = $self->{perfdata}->threshold_check(value => $value, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("There is %s alarm(s).", $value)); - - $self->{output}->perfdata_add(label => 'value', unit => undef, - value => $value, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => undef, max => undef); - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check number of alarms - -=over 8 - -=item B<--warning> - -Threshold warning. - -=item B<--critical> - -Threshold critical. - -=back - -=cut diff --git a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarms.pm b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarms.pm new file mode 100644 index 000000000..d89a21330 --- /dev/null +++ b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/alarms.pm @@ -0,0 +1,87 @@ +# +# 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. +# +# Authors : Thomas Gourdin thomas.gourdin@gmail.com + +package hardware::devices::timelinkmicro::tms6001::snmp::mode::alarms; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total', nlabel => 'alarms.total.count', set => { + key_values => [ { name => 'alarms_count' } ], + output_template => 'current number of alarms: %s', + perfdatas => [ + { value => 'alarms_count_absolute', template => '%s', min => 0 } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_infoAlarmsCount = '.1.3.6.1.4.1.22641.100.3.3.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [ $oid_infoAlarmsCount ], nothing_quit => 1); + + $self->{global} = { + alarms_count => $snmp_result->{$oid_infoAlarmsCount} + }; +} + +1; + +__END__ + +=head1 MODE + +Check alarms. + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'total'. + +=back + +=cut diff --git a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/antenna.pm b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/antenna.pm index e548c2920..ea0a94a19 100644 --- a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/antenna.pm +++ b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/antenna.pm @@ -1,5 +1,5 @@ # -# Copyright 2019 Centreon (http://www.centreon.com/) +# 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 @@ -21,53 +21,73 @@ package hardware::devices::timelinkmicro::tms6001::snmp::mode::antenna; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return 'antenna status: ' . $self->{result_values}->{status}; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + } + ]; +} sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - }); + + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /shorted/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /notConnected/i' } + }); return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); + $self->SUPER::check_options(%options); + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); } -sub run { +my $mapping_status = { + C => 'connected', + S => 'shorted/poweroff', + N => 'notConnected' +}; + +sub manage_selection { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - my $oid_qualityfrequency = '.1.3.6.1.4.1.22641.100.4.1.4.0'; + my $oid_tsGNSSAntenna = '.1.3.6.1.4.1.22641.100.4.1.4.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [ $oid_tsGNSSAntenna ], nothing_quit => 1); - my $result = $self->{snmp}->get_leef(oids => [ $oid_qualityfrequency ], nothing_quit => 1); - - my $value = $result->{$oid_qualityfrequency}; - - if ($value eq 'C') { - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("Antenna is connected")); - } elsif ($value eq 'S') { - $self->{output}->output_add(severity => 'WARNING', - short_msg => sprintf("Antenna is shorted or powered off")); - } elsif ($value eq 'N') { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Antenna is not connected")); - } - - $self->{output}->display(); - $self->{output}->exit(); + $self->{global} = { + status => $mapping_status->{ $snmp_result->{$oid_tsGNSSAntenna} } + }; } 1; @@ -76,10 +96,25 @@ __END__ =head1 MODE -Check antenna status +Check antenna. =over 8 +=item B<--unknown-status> + +Set unknown threshold for status. +Can used special variables like: %{status} + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{status} =~ /shorted/i'). +Can used special variables like: %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /notConnected/i'). +Can used special variables like: %{status} + =back =cut diff --git a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/frequency.pm b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/frequency.pm index e443c5a7d..11072dd37 100644 --- a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/frequency.pm +++ b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/frequency.pm @@ -1,5 +1,5 @@ # -# Copyright 2019 Centreon (http://www.centreon.com/) +# 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 @@ -21,65 +21,52 @@ package hardware::devices::timelinkmicro::tms6001::snmp::mode::frequency; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'frequency-quality', nlabel => 'generation.frequency.quality.count', set => { + key_values => [ { name => 'qual_frequency' } ], + output_template => 'quality of frequency generation: %s', + perfdatas => [ + { value => 'qual_frequency_absolute', template => '%s' } + ] + } + } + ]; +} + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); + + $options{options}->add_options(arguments => { + }); return $self; } -sub check_options { +sub manage_selection { my ($self, %options) = @_; - $self->SUPER::init(%options); - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } - + my $oid_infoQualFreq = '.1.3.6.1.4.1.22641.100.3.6.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [ $oid_infoQualFreq ], nothing_quit => 1); + + $self->{global} = { + qual_frequency => $snmp_result->{$oid_infoQualFreq} + }; } -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - - my $oid_qualityfrequency = '.1.3.6.1.4.1.22641.100.3.6.0'; - - my $result = $self->{snmp}->get_leef(oids => [ $oid_qualityfrequency ], nothing_quit => 1); - - my $value = $result->{$oid_qualityfrequency}; - - my $exit = $self->{perfdata}->threshold_check(value => $value, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Quality of frequency generation is %s.", $value)); - - $self->{output}->perfdata_add(label => 'value', unit => undef, - value => $value, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => undef, max => undef); - - $self->{output}->display(); - $self->{output}->exit(); -} 1; @@ -91,13 +78,10 @@ Check quality of frequency generation =over 8 -=item B<--warning> +=item B<--warning-*> B<--critical-*> -Threshold warning. - -=item B<--critical> - -Threshold critical. +Thresholds. +Can be: 'frequency-quality'. =back diff --git a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/gnss.pm b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/gnss.pm index 666fff461..db5c06768 100644 --- a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/gnss.pm +++ b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/gnss.pm @@ -1,5 +1,5 @@ # -# Copyright 2019 Centreon (http://www.centreon.com/) +# 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 @@ -21,50 +21,67 @@ package hardware::devices::timelinkmicro::tms6001::snmp::mode::gnss; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return 'GNSS status: ' . $self->{result_values}->{status}; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + } + ]; +} sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - }); + + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /nominal/i' } + }); return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); + $self->SUPER::check_options(%options); + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); } -sub run { +sub manage_selection { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - my $oid_qualityfrequency = '.1.3.6.1.4.1.22641.100.4.1.2.0'; + my $oid_tsGNSSStatus = '.1.3.6.1.4.1.22641.100.4.1.2.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [ $oid_tsGNSSStatus ], nothing_quit => 1); - my $result = $self->{snmp}->get_leef(oids => [ $oid_qualityfrequency ], nothing_quit => 1); - - my $value = $result->{$oid_qualityfrequency}; - - if ($value eq 'Nominal') { - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("GNSS status is $value")); - } else { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("GNSS status is $value")); - } - - $self->{output}->display(); - $self->{output}->exit(); + $self->{global} = { + status => lc($snmp_result->{$oid_tsGNSSStatus}) + }; } 1; @@ -73,10 +90,25 @@ __END__ =head1 MODE -Check GNSS state +Check GNSS. =over 8 +=item B<--unknown-status> + +Set unknown threshold for status. +Can used special variables like: %{status} + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /nominal/i'). +Can used special variables like: %{status} + =back =cut diff --git a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/satellites.pm b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/satellites.pm index 51635f0d2..533a72e85 100644 --- a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/satellites.pm +++ b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/satellites.pm @@ -1,5 +1,5 @@ # -# Copyright 2019 Centreon (http://www.centreon.com/) +# 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 @@ -21,64 +21,50 @@ package hardware::devices::timelinkmicro::tms6001::snmp::mode::satellites; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'seen', nlabel => 'satellites.seen.count', set => { + key_values => [ { name => 'sat_count' } ], + output_template => 'current number of satellites seen: %s', + perfdatas => [ + { value => 'sat_count_absolute', template => '%s', min => 0 } + ] + } + } + ]; +} + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); + + $options{options}->add_options(arguments => { + }); return $self; } -sub check_options { +sub manage_selection { my ($self, %options) = @_; - $self->SUPER::init(%options); - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } - -} + my $oid_tsGNSSSatCount = '.1.3.6.1.4.1.22641.100.4.1.8.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [ $oid_tsGNSSSatCount ], nothing_quit => 1); -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - - my $oid_qualityfrequency = '.1.3.6.1.4.1.22641.100.4.1.8.0'; - - my $result = $self->{snmp}->get_leef(oids => [ $oid_qualityfrequency ], nothing_quit => 1); - - my $value = $result->{$oid_qualityfrequency}; - - my $exit = $self->{perfdata}->threshold_check(value => $value, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Number of satellites seen is %s.", $value)); - - $self->{output}->perfdata_add(label => 'value', unit => undef, - value => $value, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => undef, max => undef); - - $self->{output}->display(); - $self->{output}->exit(); + $self->{global} = { + sat_count => $snmp_result->{$oid_tsGNSSSatCount} + }; } 1; @@ -87,17 +73,14 @@ __END__ =head1 MODE -Check number of satellites seen +Check satellites. =over 8 -=item B<--warning> +=item B<--warning-*> B<--critical-*> -Threshold warning. - -=item B<--critical> - -Threshold critical. +Thresholds. +Can be: 'seen'. =back diff --git a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/time.pm b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/time.pm index f061e0294..c9c5b06f8 100644 --- a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/time.pm +++ b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/mode/time.pm @@ -21,64 +21,50 @@ package hardware::devices::timelinkmicro::tms6001::snmp::mode::time; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'time-quality', nlabel => 'generation.time.quality.count', set => { + key_values => [ { name => 'qual_time' } ], + output_template => 'quality of time generation: %s', + perfdatas => [ + { value => 'qual_time_absolute', template => '%s' } + ] + } + } + ]; +} + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); + + $options{options}->add_options(arguments => { + }); return $self; } -sub check_options { +sub manage_selection { my ($self, %options) = @_; - $self->SUPER::init(%options); - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } - -} + my $oid_infoQualTime = '.1.3.6.1.4.1.22641.100.3.5.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [ $oid_infoQualTime ], nothing_quit => 1); -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - - my $oid_qualityfrequency = '.1.3.6.1.4.1.22641.100.3.5.0'; - - my $result = $self->{snmp}->get_leef(oids => [ $oid_qualityfrequency ], nothing_quit => 1); - - my $value = $result->{$oid_qualityfrequency}; - - my $exit = $self->{perfdata}->threshold_check(value => $value, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Quality of time generation is %s.", $value)); - - $self->{output}->perfdata_add(label => 'value', unit => undef, - value => $value, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => undef, max => undef); - - $self->{output}->display(); - $self->{output}->exit(); + $self->{global} = { + qual_time => $snmp_result->{$oid_infoQualTime} + }; } 1; @@ -87,17 +73,14 @@ __END__ =head1 MODE -Check quality of time generation +Check quality of time generation. =over 8 -=item B<--warning> +=item B<--warning-*> B<--critical-*> -Threshold warning. - -=item B<--critical> - -Threshold critical. +Thresholds. +Can be: 'time-quality'. =back diff --git a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/plugin.pm b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/plugin.pm index 799f11780..b4bda3092 100644 --- a/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/plugin.pm +++ b/centreon-plugins/hardware/devices/timelinkmicro/tms6001/snmp/plugin.pm @@ -31,15 +31,14 @@ sub new { bless $self, $class; $self->{version} = '0.1'; - %{$self->{modes}} = ( - 'frequency' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::frequency', - 'time' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::time', - 'satellites' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::satellites', - 'antenna' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::antenna', - 'gnss' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::gnss', - 'alarms' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::alarm', - - ); + $self->{modes} = { + 'alarms' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::alarms', + 'antenna' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::antenna', + 'frequency' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::frequency', + 'gnss' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::gnss', + 'satellites' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::satellites', + 'time' => 'hardware::devices::timelinkmicro::tms6001::snmp::mode::time' + }; return $self; } From 727b9f499620ba77c8fade3fabbaca0b2a439d97 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 11 May 2020 15:11:38 +0200 Subject: [PATCH 188/190] add plugin in verbose --- centreon-plugins/apps/mq/vernemq/restapi/mode/plugins.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/centreon-plugins/apps/mq/vernemq/restapi/mode/plugins.pm b/centreon-plugins/apps/mq/vernemq/restapi/mode/plugins.pm index 49fef8ace..ad1919677 100644 --- a/centreon-plugins/apps/mq/vernemq/restapi/mode/plugins.pm +++ b/centreon-plugins/apps/mq/vernemq/restapi/mode/plugins.pm @@ -71,6 +71,7 @@ sub manage_selection { next; } + $self->{output}->output_add(long_msg => "plugin '" . $_->{Plugin} . "'"); $self->{global}->{total}++; } } From 8d10a005f29b78118f9d0fe502d298639bfa6712 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 11 May 2020 15:46:01 +0200 Subject: [PATCH 189/190] add average message size --- .../apps/mq/activemq/jmx/mode/brokers.pm | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/centreon-plugins/apps/mq/activemq/jmx/mode/brokers.pm b/centreon-plugins/apps/mq/activemq/jmx/mode/brokers.pm index b8f1c746b..53720030d 100644 --- a/centreon-plugins/apps/mq/activemq/jmx/mode/brokers.pm +++ b/centreon-plugins/apps/mq/activemq/jmx/mode/brokers.pm @@ -111,7 +111,7 @@ sub set_counters { ] } }, - { label => 'queue-enqueued', nlabel => 'broker.queue.enqueued.count', display_ok => 0, set => { + { label => 'queue-messages-enqueued', nlabel => 'broker.queue.messages.enqueued.count', display_ok => 0, set => { key_values => [ { name => 'EnqueueCount', diff => 1 }, { name => 'display' } ], output_template => 'messages enqueued: %s', perfdatas => [ @@ -120,7 +120,7 @@ sub set_counters { ] } }, - { label => 'queue-dequeued', nlabel => 'broker.queue.dequeue.count', display_ok => 0, set => { + { label => 'queue-messages-dequeued', nlabel => 'broker.queue.messages.dequeue.count', display_ok => 0, set => { key_values => [ { name => 'DequeueCount', diff => 1 }, { name => 'display' } ], output_template => 'messages dequeued: %s', perfdatas => [ @@ -129,7 +129,7 @@ sub set_counters { ] } }, - { label => 'queue-expired', nlabel => 'broker.queue.expired.count', display_ok => 0, set => { + { label => 'queue-messages-expired', nlabel => 'broker.queue.messages.expired.count', display_ok => 0, set => { key_values => [ { name => 'ExpiredCount', diff => 1 }, { name => 'display' } ], output_template => 'messages expired: %s', perfdatas => [ @@ -138,7 +138,7 @@ sub set_counters { ] } }, - { label => 'queue-inflighted', nlabel => 'broker.queue.inflighted.count', display_ok => 0, set => { + { label => 'queue-messages-inflighted', nlabel => 'broker.queue.messages.inflighted.count', display_ok => 0, set => { key_values => [ { name => 'InFlightCount', diff => 1 }, { name => 'display' } ], output_template => 'messages in-flighted: %s', perfdatas => [ @@ -146,6 +146,16 @@ sub set_counters { template => '%s', min => 0, label_extra_instance => 1 } ] } + }, + { label => 'queue-messages-size-average', nlabel => 'broker.queue.messages.size.average.bytes', display_ok => 0, set => { + key_values => [ { name => 'AverageMessageSize' }, { name => 'display' } ], + output_template => 'average messages size: %s %s', + output_change_bytes => 1, + perfdatas => [ + { value => 'AverageMessageSize_absolute', + template => '%s', unit => 'B', min => 0, label_extra_instance => 1 } + ] + } } ]; } @@ -192,7 +202,7 @@ sub manage_selection { { name => 'ProducerCount' }, { name => 'MemoryPercentUsage' }, { name => 'QueueSize' }, { name => 'EnqueueCount' }, { name => 'DequeueCount' }, { name => 'ExpiredCount' }, - { name => 'InFlightCount' } + { name => 'InFlightCount' }, { name => 'AverageMessageSize' } ] }, { @@ -277,7 +287,8 @@ Thresholds. Can be: 'store-usage' (%), 'temporary-usage' (%), 'memory-usage' (%), 'queue-average-enqueue-time' (ms), 'queue-consumers-connected', 'queue-producers-connected', 'queue-memory-usage' (%), 'queue-size', -'queue-enqueued', 'queue-dequeued', 'queue-expired', 'queue-inflighted'. +'queue-messages-enqueued', 'queue-messages-dequeued', 'queue-messages-expired', +'queue-messages-inflighted'. =back From 5675a540afda7c435b2054285e075155d33c7ffb Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 11 May 2020 16:16:43 +0200 Subject: [PATCH 190/190] enhance activemq --- .../apps/mq/activemq/jmx/mode/brokers.pm | 234 ++++++++++-------- 1 file changed, 131 insertions(+), 103 deletions(-) diff --git a/centreon-plugins/apps/mq/activemq/jmx/mode/brokers.pm b/centreon-plugins/apps/mq/activemq/jmx/mode/brokers.pm index 53720030d..7072d4500 100644 --- a/centreon-plugins/apps/mq/activemq/jmx/mode/brokers.pm +++ b/centreon-plugins/apps/mq/activemq/jmx/mode/brokers.pm @@ -33,7 +33,8 @@ sub set_counters { { name => 'brokers', type => 3, cb_prefix_output => 'prefix_broker_output', cb_long_output => 'broker_long_output', indent_long_output => ' ', message_multiple => 'All brokers are ok', group => [ { name => 'global', type => 0, skipped_code => { -10 => 1 } }, - { name => 'queues', display_long => 1, cb_prefix_output => 'prefix_queue_output', message_multiple => 'All queue destinations are ok', type => 1, skipped_code => { -10 => 1 } } + { name => 'queue', display_long => 1, cb_prefix_output => 'prefix_queue_output', message_multiple => 'All queues are ok', type => 1, skipped_code => { -10 => 1 } }, + { name => 'topic', display_long => 1, cb_prefix_output => 'prefix_topic_output', message_multiple => 'All topics are ok', type => 1, skipped_code => { -10 => 1 } } ] } ]; @@ -65,99 +66,101 @@ sub set_counters { } ]; - $self->{maps_counters}->{queues} = [ - { label => 'queue-average-enqueue-time', nlabel => 'broker.queue.average.enqueue.time.milliseconds', set => { - key_values => [ { name => 'AverageEnqueueTime' }, { name => 'display' } ], - output_template => 'average time messages remained enqueued: %.3f ms', - perfdatas => [ - { value => 'AverageEnqueueTime_absolute', - template => '%.3f', unit => 'ms', min => 0, label_extra_instance => 1 } - ] + foreach (('queue', 'topic')) { + $self->{maps_counters}->{$_} = [ + { label => $_ . '-average-enqueue-time', nlabel => 'broker.' . $_ . '.average.enqueue.time.milliseconds', set => { + key_values => [ { name => 'AverageEnqueueTime' }, { name => 'display' } ], + output_template => 'average time messages remained enqueued: %.3f ms', + perfdatas => [ + { value => 'AverageEnqueueTime_absolute', + template => '%.3f', unit => 'ms', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => $_ . '-consumers-connected', nlabel => 'broker.' . $_ . '.consumers.connected.count', set => { + key_values => [ { name => 'ConsumerCount' }, { name => 'display' } ], + output_template => 'consumers connected: %s', + perfdatas => [ + { value => 'ConsumerCount_absolute', + template => '%s', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => $_ . '-producers-connected', nlabel => 'broker.' . $_ . '.producers.connected.count', display_ok => 0, set => { + key_values => [ { name => 'ProducerCount' }, { name => 'display' } ], + output_template => 'producers connected: %s', + perfdatas => [ + { value => 'ProducerCount_absolute', + template => '%s', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => $_ . '-memory-usage', nlabel => 'broker.' . $_ . '.memory.usage.percentage', display_ok => 0, set => { + key_values => [ { name => 'MemoryPercentUsage' }, { name => 'display' } ], + output_template => 'memory usage: %.2f %%', + perfdatas => [ + { value => 'MemoryPercentUsage_absolute', + template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 } + ] + } + }, + { label => $_ . '-size', nlabel => 'broker.' . $_ . '.size.count', set => { + key_values => [ { name => 'QueueSize' }, { name => 'display' } ], + output_template => 'queue size: %s', + perfdatas => [ + { value => 'QueueSize_absolute', + template => '%s', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => $_ . '-messages-enqueued', nlabel => 'broker.' . $_ . '.messages.enqueued.count', display_ok => 0, set => { + key_values => [ { name => 'EnqueueCount', diff => 1 }, { name => 'display' } ], + output_template => 'messages enqueued: %s', + perfdatas => [ + { value => 'EnqueueCount_absolute', + template => '%s', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => $_ . '-messages-dequeued', nlabel => 'broker.' . $_ . '.messages.dequeue.count', display_ok => 0, set => { + key_values => [ { name => 'DequeueCount', diff => 1 }, { name => 'display' } ], + output_template => 'messages dequeued: %s', + perfdatas => [ + { value => 'DequeueCount_absolute', + template => '%s', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => $_ . '-messages-expired', nlabel => 'broker.' . $_ . '.messages.expired.count', display_ok => 0, set => { + key_values => [ { name => 'ExpiredCount', diff => 1 }, { name => 'display' } ], + output_template => 'messages expired: %s', + perfdatas => [ + { value => 'ExpiredCount_absolute', + template => '%s', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => $_ . '-messages-inflighted', nlabel => 'broker.' . $_ . '.messages.inflighted.count', display_ok => 0, set => { + key_values => [ { name => 'InFlightCount', diff => 1 }, { name => 'display' } ], + output_template => 'messages in-flighted: %s', + perfdatas => [ + { value => 'InFlightCount_absolute', + template => '%s', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => $_ . '-messages-size-average', nlabel => 'broker.' . $_ . '.messages.size.average.bytes', display_ok => 0, set => { + key_values => [ { name => 'AverageMessageSize' }, { name => 'display' } ], + output_template => 'average messages size: %s %s', + output_change_bytes => 1, + perfdatas => [ + { value => 'AverageMessageSize_absolute', + template => '%s', unit => 'B', min => 0, label_extra_instance => 1 } + ] + } } - }, - { label => 'queue-consumers-connected', nlabel => 'broker.queue.consumers.connected.count', set => { - key_values => [ { name => 'ConsumerCount' }, { name => 'display' } ], - output_template => 'consumers connected: %s', - perfdatas => [ - { value => 'ConsumerCount_absolute', - template => '%s', min => 0, label_extra_instance => 1 } - ] - } - }, - { label => 'queue-producers-connected', nlabel => 'broker.queue.producers.connected.count', display_ok => 0, set => { - key_values => [ { name => 'ProducerCount' }, { name => 'display' } ], - output_template => 'producers connected: %s', - perfdatas => [ - { value => 'ProducerCount_absolute', - template => '%s', min => 0, label_extra_instance => 1 } - ] - } - }, - { label => 'queue-memory-usage', nlabel => 'broker.queue.memory.usage.percentage', display_ok => 0, set => { - key_values => [ { name => 'MemoryPercentUsage' }, { name => 'display' } ], - output_template => 'memory usage: %.2f %%', - perfdatas => [ - { value => 'MemoryPercentUsage_absolute', - template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 } - ] - } - }, - { label => 'queue-size', nlabel => 'broker.queue.size.count', set => { - key_values => [ { name => 'QueueSize' }, { name => 'display' } ], - output_template => 'queue size: %s', - perfdatas => [ - { value => 'QueueSize_absolute', - template => '%s', min => 0, label_extra_instance => 1 } - ] - } - }, - { label => 'queue-messages-enqueued', nlabel => 'broker.queue.messages.enqueued.count', display_ok => 0, set => { - key_values => [ { name => 'EnqueueCount', diff => 1 }, { name => 'display' } ], - output_template => 'messages enqueued: %s', - perfdatas => [ - { value => 'EnqueueCount_absolute', - template => '%s', min => 0, label_extra_instance => 1 } - ] - } - }, - { label => 'queue-messages-dequeued', nlabel => 'broker.queue.messages.dequeue.count', display_ok => 0, set => { - key_values => [ { name => 'DequeueCount', diff => 1 }, { name => 'display' } ], - output_template => 'messages dequeued: %s', - perfdatas => [ - { value => 'DequeueCount_absolute', - template => '%s', min => 0, label_extra_instance => 1 } - ] - } - }, - { label => 'queue-messages-expired', nlabel => 'broker.queue.messages.expired.count', display_ok => 0, set => { - key_values => [ { name => 'ExpiredCount', diff => 1 }, { name => 'display' } ], - output_template => 'messages expired: %s', - perfdatas => [ - { value => 'ExpiredCount_absolute', - template => '%s', min => 0, label_extra_instance => 1 } - ] - } - }, - { label => 'queue-messages-inflighted', nlabel => 'broker.queue.messages.inflighted.count', display_ok => 0, set => { - key_values => [ { name => 'InFlightCount', diff => 1 }, { name => 'display' } ], - output_template => 'messages in-flighted: %s', - perfdatas => [ - { value => 'InFlightCount_absolute', - template => '%s', min => 0, label_extra_instance => 1 } - ] - } - }, - { label => 'queue-messages-size-average', nlabel => 'broker.queue.messages.size.average.bytes', display_ok => 0, set => { - key_values => [ { name => 'AverageMessageSize' }, { name => 'display' } ], - output_template => 'average messages size: %s %s', - output_change_bytes => 1, - perfdatas => [ - { value => 'AverageMessageSize_absolute', - template => '%s', unit => 'B', min => 0, label_extra_instance => 1 } - ] - } - } - ]; + ]; + } } sub broker_long_output { @@ -172,10 +175,16 @@ sub prefix_broker_output { return "Broker '" . $options{instance_value}->{display} . "' "; } -sub prefix_qeueue_output { +sub prefix_queue_output { my ($self, %options) = @_; - return "queue destination '" . $options{instance_value}->{display} . "' "; + return "queue '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_topic_output { + my ($self, %options) = @_; + + return "topic '" . $options{instance_value}->{display} . "' "; } sub new { @@ -185,7 +194,8 @@ sub new { $options{options}->add_options(arguments => { 'filter-broker-name:s' => { name => 'filter_broker_name' }, - 'filter-destination-name:s' => { name => 'filter_destination_name' } + 'filter-destination-name:s' => { name => 'filter_destination_name' }, + 'filter-destination-type:s' => { name => 'filter_destination_type' } }); return $self; @@ -196,7 +206,7 @@ sub manage_selection { my $request = [ { - mbean => 'org.apache.activemq:brokerName=*,destinationName=*,destinationType=Topic,type=Broker', + mbean => 'org.apache.activemq:brokerName=*,destinationName=*,destinationType=*,type=Broker', attributes => [ { name => 'AverageEnqueueTime' }, { name => 'ConsumerCount' }, { name => 'ProducerCount' }, { name => 'MemoryPercentUsage' }, @@ -218,34 +228,44 @@ sub manage_selection { $self->{cache_name} = 'activemq_' . $self->{mode} . '_' . md5_hex($options{custom}->get_connection_info()) . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_broker_name}) ? md5_hex($self->{option_results}->{filter_broker_name}) : md5_hex('all')) . '_' . - (defined($self->{option_results}->{filter_destination_name}) ? md5_hex($self->{option_results}->{filter_destination_name}) : md5_hex('all')); + (defined($self->{option_results}->{filter_destination_name}) ? md5_hex($self->{option_results}->{filter_destination_name}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_destination_type}) ? md5_hex($self->{option_results}->{filter_destination_type}) : md5_hex('all')); $self->{brokers} = {}; foreach my $mbean (keys %$result) { - next if ($mbean !~ /org.apache.activemq:brokerName=(.*?),(?:destinationName=(.*?),|type=Broker)/); - my ($broker_name, $destination_name) = ($1, $2); + next if ($mbean !~ /org.apache.activemq:brokerName=(.*?),(?:destinationName=(.*?),destinationType=(.*?),|type=Broker)/); + my ($broker_name, $destination_name, $destination_type) = ($1, $2, $3); if (defined($self->{option_results}->{filter_broker_name}) && $self->{option_results}->{filter_broker_name} ne '' && $broker_name !~ /$self->{option_results}->{filter_broker_name}/) { $self->{output}->output_add(long_msg => "skipping '" . $broker_name . "': no matching filter.", debug => 1); next; } + if (defined($self->{option_results}->{filter_destination_type}) && $self->{option_results}->{filter_destination_type} ne '' && + $destination_type !~ /$self->{option_results}->{filter_destination_type}/) { + $self->{output}->output_add(long_msg => "skipping '" . $broker_name . "': no matching filter.", debug => 1); + next; + } if (!defined($self->{brokers}->{$broker_name})) { $self->{brokers}->{$broker_name} = { display => $broker_name, - queues => {} + queue => {}, + topic => {} }; } if (defined($destination_name)) { + my $type = lc($destination_type); + next if ($type ne 'topic' && $type ne 'queue'); + if (defined($self->{option_results}->{filter_destination_name}) && $self->{option_results}->{filter_destination_name} ne '' && $destination_name !~ /$self->{option_results}->{filter_destination_name}/) { $self->{output}->output_add(long_msg => "skipping '" . $destination_name . "': no matching filter.", debug => 1); next; } - $self->{brokers}->{$broker_name}->{queues}->{$destination_name} = { + $self->{brokers}->{$broker_name}->{$type}->{$destination_name} = { display => $destination_name, %{$result->{$mbean}} }; @@ -281,6 +301,10 @@ Filter broker name (Can be a regexp). Filter destination name (Can be a regexp). +=item B<--filter-destination-type> + +Filter destination type (Can be a regexp). + =item B<--warning-*> B<--critical-*> Thresholds. @@ -288,7 +312,11 @@ Can be: 'store-usage' (%), 'temporary-usage' (%), 'memory-usage' (%), 'queue-average-enqueue-time' (ms), 'queue-consumers-connected', 'queue-producers-connected', 'queue-memory-usage' (%), 'queue-size', 'queue-messages-enqueued', 'queue-messages-dequeued', 'queue-messages-expired', -'queue-messages-inflighted'. +'queue-messages-inflighted', +'topic-average-enqueue-time' (ms), 'topic-consumers-connected', +'topic-producers-connected', 'topic-memory-usage' (%), 'topic-size', +'topic-messages-enqueued', 'topic-messages-dequeued', 'topic-messages-expired', +'topic-messages-inflighted'. =back