From ca0627a64efb609eab20a2bbc2ccb8be5164ed6b Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Mon, 31 Dec 2018 11:38:40 +0100 Subject: [PATCH] add avid isis plugin --- storage/avid/isis/snmp/mode/performance.pm | 201 ++++++++++++++++++ storage/avid/isis/snmp/mode/status.pm | 182 +++++++++++++++++ storage/avid/isis/snmp/mode/usage.pm | 225 +++++++++++++++++++++ storage/avid/isis/snmp/plugin.pm | 51 +++++ 4 files changed, 659 insertions(+) create mode 100644 storage/avid/isis/snmp/mode/performance.pm create mode 100644 storage/avid/isis/snmp/mode/status.pm create mode 100644 storage/avid/isis/snmp/mode/usage.pm create mode 100644 storage/avid/isis/snmp/plugin.pm diff --git a/storage/avid/isis/snmp/mode/performance.pm b/storage/avid/isis/snmp/mode/performance.pm new file mode 100644 index 000000000..61d84d9e8 --- /dev/null +++ b/storage/avid/isis/snmp/mode/performance.pm @@ -0,0 +1,201 @@ +# +# Copyright 2018 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::avid::isis::snmp::mode::performance; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_client_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add(label => 'active_clients', + value => $self->{result_values}->{active}, + unit => 'clients', + min => 0, + max => $self->{result_values}->{maximum}); +} + +sub custom_client_threshold { + my ($self, %options) = @_; + + my ($exit, $threshold_value); + $threshold_value = defined($instance_mode->{option_results}->{percent}) ? $self->{result_values}->{prct_active} : $self->{result_values}->{active} ; + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, + threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, + { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_client_output { + my ($self, %options) = @_; + + my $msg = sprintf("Active clients: %d/%d (%.2f%%)", + $self->{result_values}->{active}, $self->{result_values}->{maximum}, $self->{result_values}->{prct_active}); + return $msg; +} + +sub custom_client_calc { + my ($self, %options) = @_; + + $self->{result_values}->{active} = $options{new_datas}->{$self->{instance} . '_ActiveClientCount'}; + $self->{result_values}->{maximum} = $options{new_datas}->{$self->{instance} . '_MaximumClientCount'}; + $self->{result_values}->{prct_active} = ($self->{result_values}->{maximum} != 0) ? $self->{result_values}->{active} * 100 / $self->{result_values}->{maximum} : 0; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'active-clients', set => { + key_values => [ { name => 'ActiveClientCount' }, { name => 'MaximumClientCount' } ], + closure_custom_calc => $self->can('custom_client_calc'), + closure_custom_output => $self->can('custom_client_output'), + closure_custom_threshold_check => $self->can('custom_client_threshold'), + closure_custom_perfdata => $self->can('custom_client_perfdata'), + } + }, + { label => 'open-files', set => { + key_values => [ { name => 'OpenFiles' } ], + output_template => 'Open files: %s files', + perfdatas => [ + { label => 'open_files', value => 'OpenFiles_absolute', + template => '%s', min => 0, unit => 'files' }, + ], + } + }, + { label => 'processing-speed', set => { + key_values => [ { name => 'MessagesPerSecond' } ], + output_template => 'Message processing speed: %s messages/s', + perfdatas => [ + { label => 'processing_speed', value => 'MessagesPerSecond_absolute', + template => '%s', min => 0, unit => 'messages/s' }, + ], + } + }, + { label => 'read-throughput', set => { + key_values => [ { name => 'ReadMegabytesPerSecond' } ], + output_template => 'Read throughput: %s %s/s', + output_change_bytes => 1, + perfdatas => [ + { label => 'read_throughput', value => 'ReadMegabytesPerSecond_absolute', + template => '%s', min => 0, unit => 'B/s' }, + ], + } + }, + { label => 'write-throughput', set => { + key_values => [ { name => 'WriteMegabytesPerSecond' } ], + output_template => 'Write throughput: %s %s/s', + output_change_bytes => 1, + perfdatas => [ + { label => 'write_throughput', value => 'WriteMegabytesPerSecond_absolute', + template => '%s', min => 0, unit => 'B/s' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "percent" => { name => 'percent' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; +} + +my $oid_ReadMegabytesPerSecond = '.1.3.6.1.4.1.526.20.3.2.0'; +my $oid_WriteMegabytesPerSecond = '.1.3.6.1.4.1.526.20.3.3.0'; +my $oid_MessagesPerSecond = '.1.3.6.1.4.1.526.20.3.4.0'; +my $oid_OpenFiles = '.1.3.6.1.4.1.526.20.3.5.0'; +my $oid_ActiveClientCount = '.1.3.6.1.4.1.526.20.3.6.0'; +my $oid_MaximumClientCount = '.1.3.6.1.4.1.526.20.3.7.0'; + +sub manage_selection { + my ($self, %options) = @_; + + my $results = $options{snmp}->get_leef(oids => [ $oid_ReadMegabytesPerSecond, $oid_WriteMegabytesPerSecond, + $oid_MessagesPerSecond, $oid_OpenFiles, + $oid_ActiveClientCount, $oid_MaximumClientCount ], + nothing_quit => 1); + + $self->{global} = {}; + + $self->{global} = { + ReadMegabytesPerSecond => $results->{$oid_ReadMegabytesPerSecond} * 1024 * 1024, + WriteMegabytesPerSecond => $results->{$oid_WriteMegabytesPerSecond} * 1024 * 1024, + MessagesPerSecond => $results->{$oid_MessagesPerSecond}, + OpenFiles => $results->{$oid_OpenFiles}, + ActiveClientCount => $results->{$oid_ActiveClientCount}, + MaximumClientCount => $results->{$oid_MaximumClientCount}, + }; +} + +1; + +__END__ + +=head1 MODE + +Check client performances. + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'active-clients' (counter or %), 'open-files', +'processing-speed', 'read-throughput', 'write-throughput'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'active-clients' (counter or %), 'open-files', +'processing-speed', 'read-throughput', 'write-throughput'. + +=item B<--percent> + +Set this option if you want to use percent on active clients thresholds. + +=back + +=cut diff --git a/storage/avid/isis/snmp/mode/status.pm b/storage/avid/isis/snmp/mode/status.pm new file mode 100644 index 000000000..ebe3bdf05 --- /dev/null +++ b/storage/avid/isis/snmp/mode/status.pm @@ -0,0 +1,182 @@ +# +# Copyright 2018 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::avid::isis::snmp::mode::status; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("System Director state is '%s'", $self->{result_values}->{status}); + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_SystemDirectorState'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, message_separator => ' - ' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', set => { + key_values => [ { name => 'SystemDirectorState' } ], + 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_status_threshold'), + } + }, + { label => 'redistributing-count', set => { + key_values => [ { name => 'WorkspaceRedistributingCount' } ], + output_template => 'Workspace redistributing count: %d', + perfdatas => [ + { label => 'redistributing_count', value => 'WorkspaceRedistributingCount_absolute', + template => '%d', min => 0 }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /Online/i' }, + }); + return $self; +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +my %map_status = ( + 0 => 'Online', + 1 => 'Offline', + 2 => 'Standby', + 3 => 'Unknown', +); + +my $oid_SystemDirectorState = '.1.3.6.1.4.1.526.20.2.1.0'; +my $oid_WorkspaceRedistributingCount = '.1.3.6.1.4.1.526.20.2.4.0'; + +sub manage_selection { + my ($self, %options) = @_; + + my $results = $options{snmp}->get_leef(oids => [ $oid_SystemDirectorState, $oid_WorkspaceRedistributingCount ], + nothing_quit => 1); + + $self->{global} = {}; + + $self->{global} = { + SystemDirectorState => $map_status{$results->{$oid_SystemDirectorState}}, + WorkspaceRedistributingCount => $results->{$oid_WorkspaceRedistributingCount}, + }; +} + +1; + +__END__ + +=head1 MODE + +Check System Director state and workspaces redistributing count. + +=over 8 + +=item B<--warning-status> + +Set warning threshold for status. (Default: ''). +Can use special variables like: %{state} + +=item B<--critical-status> + +Set critical threshold for status. (Default: '%{state} !~ /Online/i'). +Can use special variables like: %{state} + +=item B<--warning-redistributing-count> + +Threshold warning for number of workspaces redistributing. + +=item B<--critical-redistributing-count> + +Threshold critical for number of workspaces redistributing. + +=back + +=cut diff --git a/storage/avid/isis/snmp/mode/usage.pm b/storage/avid/isis/snmp/mode/usage.pm new file mode 100644 index 000000000..5e3a30f83 --- /dev/null +++ b/storage/avid/isis/snmp/mode/usage.pm @@ -0,0 +1,225 @@ +# +# Copyright 2018 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::avid::isis::snmp::mode::usage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + my $label = 'used'; + my $value_perf = $self->{result_values}->{used}; + if (defined($instance_mode->{option_results}->{free})) { + $label = 'free'; + $value_perf = $self->{result_values}->{free}; + } + my %total_options = (); + if ($instance_mode->{option_results}->{units} eq '%') { + $total_options{total} = $self->{result_values}->{allocated}; + $total_options{cast_int} = 1; + } + + $self->{output}->perfdata_add(label => $label, unit => 'B', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{allocated}); + + $self->{output}->perfdata_add(label => 'allocated', unit => 'B', + value => $self->{result_values}->{allocated}, + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my ($exit, $threshold_value); + $threshold_value = $self->{result_values}->{used}; + $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); + if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{prct_used}; + $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, + { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my $msg; + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($total_allocated_value, $total_allocated_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{allocated}); + 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}); + $msg = sprintf("Total: %s Allocated: %s (%.2f%%) Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_allocated_value . " " . $total_allocated_unit, $self->{result_values}->{prct_allocated},, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_TotalSystemMB'} * 1024 * 1024; + $self->{result_values}->{allocated} = $options{new_datas}->{$self->{instance} . '_TotalAllocatedMB'} * 1024 * 1024; + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_TotalUsedMB'} * 1024 * 1024; + + $self->{result_values}->{prct_allocated} = $self->{result_values}->{allocated} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{allocated}; + + $self->{result_values}->{free} = $self->{result_values}->{allocated} - $self->{result_values}->{used}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'usage', set => { + key_values => [ { name => 'TotalSystemMB' }, { name => 'TotalAllocatedMB' }, { name => 'TotalUsedMB' } ], + 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'), + } + }, + { label => 'workspace-count', set => { + key_values => [ { name => 'WorkspaceCount' } ], + output_template => 'Workspace count: %d', + perfdatas => [ + { label => 'workspace_count', value => 'WorkspaceCount_absolute', + template => '%d', min => 0 }, + ], + } + }, + { label => 'folder-count', set => { + key_values => [ { name => 'FolderCount' } ], + output_template => 'Folder count: %d', + perfdatas => [ + { label => 'folder_count', value => 'FolderCount_absolute', + template => '%d', min => 0 }, + ], + } + }, + { label => 'file-count', set => { + key_values => [ { name => 'FileCount' } ], + output_template => 'File count: %d', + perfdatas => [ + { label => 'file_count', value => 'FileCount_absolute', + template => '%d', min => 0 }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; +} + +my $oid_TotalSystemMB = '.1.3.6.1.4.1.526.20.4.2.0'; +my $oid_TotalAllocatedMB = '.1.3.6.1.4.1.526.20.4.3.0'; +my $oid_TotalUsedMB = '.1.3.6.1.4.1.526.20.4.4.0'; +my $oid_FileCount = '.1.3.6.1.4.1.526.20.4.5.0'; +my $oid_FolderCount = '.1.3.6.1.4.1.526.20.4.6.0'; +my $oid_WorkspaceCount = '.1.3.6.1.4.1.526.20.4.7.0'; + +sub manage_selection { + my ($self, %options) = @_; + + my $results = $options{snmp}->get_leef(oids => [ $oid_TotalSystemMB, $oid_TotalAllocatedMB, + $oid_TotalUsedMB, $oid_FileCount, + $oid_FolderCount, $oid_WorkspaceCount ], + nothing_quit => 1); + + $self->{global} = {}; + + $self->{global} = { + TotalSystemMB => $results->{$oid_TotalSystemMB}, + TotalAllocatedMB => $results->{$oid_TotalAllocatedMB}, + TotalUsedMB => $results->{$oid_TotalUsedMB}, + FileCount => $results->{$oid_FileCount}, + FolderCount => $results->{$oid_FolderCount}, + WorkspaceCount => $results->{$oid_WorkspaceCount}, + }; +} + +1; + +__END__ + +=head1 MODE + +Check storage usage. + +=over 8 + +=item B<--warning-usage> + +Threshold warning for used allocated storage. + +=item B<--critical-usage> + +Threshold critical for used allocated storage. + +=item B<--units> + +Units of thresholds (Default: '%') ('%', 'B'). + +=item B<--free> + +Thresholds are on free space left. + +=back + +=cut diff --git a/storage/avid/isis/snmp/plugin.pm b/storage/avid/isis/snmp/plugin.pm new file mode 100644 index 000000000..0deb104d4 --- /dev/null +++ b/storage/avid/isis/snmp/plugin.pm @@ -0,0 +1,51 @@ +# +# Copyright 2018 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::avid::isis::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}} = ( + 'performance' => 'storage::avid::isis::snmp::mode::performance', + 'status' => 'storage::avid::isis::snmp::mode::status', + 'usage' => 'storage::avid::isis::snmp::mode::usage', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Avid ISIS storage (5xxx, 7xxx) through SNMP + +=cut