diff --git a/centreon/common/ingrian/snmp/mode/connections.pm b/centreon/common/ingrian/snmp/mode/connections.pm new file mode 100644 index 000000000..934149e2b --- /dev/null +++ b/centreon/common/ingrian/snmp/mode/connections.pm @@ -0,0 +1,119 @@ +# +# Copyright 2017 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::ingrian::snmp::mode::connections; + +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 => 'global', type => 0, message_separator => ' - ' } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total', set => { + key_values => [ { name => 'naeTotalTotalConnections', diff => 1 } ], + output_template => 'Total Connections : %s', + perfdatas => [ + { label => 'total', value => 'naeTotalTotalConnections_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'ssl', set => { + key_values => [ { name => 'naeTotalSSLConnections', diff => 1 } ], + output_template => 'Total SSL Connections : %s', + perfdatas => [ + { label => 'total_ssl', value => 'naeTotalSSLConnections_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'non-ssl', set => { + key_values => [ { name => 'naeTotalNonSSLConnections', diff => 1 } ], + output_template => 'Total non-SSL Connections : %s', + perfdatas => [ + { label => 'total_non_ssl', value => 'naeTotalNonSSLConnections_absolute', template => '%s', min => 0 }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +my $mapping = { + naeTotalTotalConnections => { oid => '.1.3.6.1.4.1.5595.3.5.1.4' }, + naeTotalNonSSLConnections => { oid => '.1.3.6.1.4.1.5595.3.5.1.5.4' }, + naeTotalSSLConnections => { oid => '.1.3.6.1.4.1.5595.3.5.1.6.4' }, +}; +my $oid_naeConnectionStats = '.1.3.6.1.4.1.5595.3.5'; + +sub manage_selection { + my ($self, %options) = @_; + + + my $snmp_result = $options{snmp}->get_table(oid => $oid_naeConnectionStats, + nothing_quit => 1); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); + $self->{global} = { %$result }; + + $self->{cache_name} = "ingrian_" . $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')); +} + +1; + +__END__ + +=head1 MODE + +Check connections. + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'total', 'ssl', 'non-ssl'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'total', 'ssl', 'non-ssl'. + +=back + +=cut diff --git a/centreon/common/ingrian/snmp/mode/cpu.pm b/centreon/common/ingrian/snmp/mode/cpu.pm new file mode 100644 index 000000000..db5058bcf --- /dev/null +++ b/centreon/common/ingrian/snmp/mode/cpu.pm @@ -0,0 +1,138 @@ +# +# Copyright 2017 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::ingrian::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 => 'global', type => 0, cb_init => 'skip_global', }, + { name => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPU usages are ok' } + ]; + $self->{maps_counters}->{global} = [ + { label => 'total', set => { + key_values => [ { name => 'total' } ], + output_template => 'Total CPU Usage : %.2f %%', + perfdatas => [ + { label => 'total_cpu_avg', value => 'total_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, + ], + } + }, + ]; + + $self->{maps_counters}->{cpu} = [ + { label => 'usage', set => { + key_values => [ { name => 'usage' }, { name => 'display' }, ], + output_template => 'Usage : %.2f %%', + perfdatas => [ + { label => 'cpu', value => 'usage_absolute', template => '%.2f', + min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub skip_global { + my ($self, %options) = @_; + + scalar(keys %{$self->{cpu}}) > 1 ? return(0) : return(1); +} + +sub prefix_cpu_output { + my ($self, %options) = @_; + + return "CPU '" . $options{instance_value}->{display} . "' "; +} + +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 => + { + }); + + return $self; +} + +my $mapping = { + naeSystemCPUDescr => { oid => '.1.3.6.1.4.1.5595.3.2.4.1.2' }, + naeSystemCPUUtilization => { oid => '.1.3.6.1.4.1.5595.3.2.4.1.3' }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_naeSystemStatCPUEntry = '.1.3.6.1.4.1.5595.3.2.4.1'; + my $oid_naeSystemStatCPU = '.1.3.6.1.4.1.5595.3.2.2'; # without .0 + my $snmp_result = $options{snmp}->get_multiple_table(oids => [ + { oid => $oid_naeSystemStatCPU }, + { oid => $oid_naeSystemStatCPUEntry }, + ], nothing_quit => 1); + + $self->{cpu} = {}; + foreach my $oid (keys %{$snmp_result->{$oid_naeSystemStatCPUEntry}}) { + next if ($oid !~ /^$mapping->{naeSystemCPUUtilization}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_naeSystemStatCPUEntry}, instance => $instance); + + $self->{cpu}->{$instance} = { display => $instance - 1, usage => $result->{naeSystemCPUUtilization} }; + } + + $self->{global} = { total => $snmp_result->{$oid_naeSystemStatCPU}->{$oid_naeSystemStatCPU . '.0'} }; +} + +1; + +__END__ + +=head1 MODE + +Check CPU usages. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^total$' + +=item B<--warning-*> + +Threshold warning. +Can be: 'total', 'usage'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'total', 'usage'. + +=back + +=cut diff --git a/centreon/common/ingrian/snmp/mode/disk.pm b/centreon/common/ingrian/snmp/mode/disk.pm new file mode 100644 index 000000000..a49265598 --- /dev/null +++ b/centreon/common/ingrian/snmp/mode/disk.pm @@ -0,0 +1,109 @@ +# +# Copyright 2017 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::ingrian::snmp::mode::disk; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'disk', type => 1, cb_prefix_output => 'prefix_disk_output', message_multiple => 'All disk usages are ok' } + ]; + + $self->{maps_counters}->{disk} = [ + { label => 'usage', set => { + key_values => [ { name => 'used' }, { name => 'display' } ], + output_template => 'Used : %.2f %%', + perfdatas => [ + { label => 'used', value => 'used_absolute', template => '%.2f', min => 0, max => 100, unit => '%', + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_disk_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; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +my $mapping = { + naeSystemDiskDescr => { oid => '.1.3.6.1.4.1.5595.3.2.7.1.2' }, + naeSystemDiskUtilization => { oid => '.1.3.6.1.4.1.5595.3.2.7.1.3' }, +}; +my $oid_naeSystemStatDiskEntry = '.1.3.6.1.4.1.5595.3.2.7.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{disk} = {}; + my $snmp_result = $options{snmp}->get_table(oid => $oid_naeSystemStatDiskEntry, + nothing_quit => 1); + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{naeSystemDiskUtilization}->{oid}\.(.*)/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + $self->{disk}->{$instance} = { display => $result->{naeSystemDiskDescr}, + used => $result->{naeSystemDiskUtilization}}; + } +} + +1; + +__END__ + +=head1 MODE + +Check disk usages. + +=over 8 + +=item B<--warning-usage> + +Threshold warning (in percent). + +=item B<--critical-usage> + +Threshold critical (in percent). + +=back + +=cut diff --git a/centreon/common/ingrian/snmp/mode/memory.pm b/centreon/common/ingrian/snmp/mode/memory.pm new file mode 100644 index 000000000..649d26669 --- /dev/null +++ b/centreon/common/ingrian/snmp/mode/memory.pm @@ -0,0 +1,135 @@ +# +# Copyright 2017 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::ingrian::snmp::mode::memory; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add(label => 'used', unit => 'B', + value => $self->{result_values}->{used}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, 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 ($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 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; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + $self->{result_values}->{prct_used} = $options{new_datas}->{$self->{instance} . '_prct_used'}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + $self->{result_values}->{used} = $self->{result_values}->{total} * $self->{result_values}->{prct_used} / 100; + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'memory', type => 0 } + ]; + + $self->{maps_counters}->{memory} = [ + { label => 'usage', set => { + key_values => [ { name => 'prct_used' }, { name => 'total' } ], + 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'), + } + }, + ]; +} + +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 => + { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_naeSystemStatUsedMem = '.1.3.6.1.4.1.5595.3.2.5.0'; + my $oid_naeSystemStatTotalMem = '.1.3.6.1.4.1.5595.3.2.6.0'; # in Bytes + my $snmp_result = $options{snmp}->get_leef(oids => [$oid_naeSystemStatUsedMem, $oid_naeSystemStatTotalMem], + nothing_quit => 1); + + $self->{memory} = { prct_used => $snmp_result->{$oid_naeSystemStatUsedMem}, total => $snmp_result->{$oid_naeSystemStatTotalMem} }; + +} + +1; + +__END__ + +=head1 MODE + +Check memory usages. + +=over 8 + +=item B<--warning-usage> + +Threshold warning (in percent). + +=item B<--critical-usage> + +Threshold critical (in percent). + +=back + +=cut diff --git a/centreon/common/ingrian/snmp/mode/requeststats.pm b/centreon/common/ingrian/snmp/mode/requeststats.pm new file mode 100644 index 000000000..0c8983424 --- /dev/null +++ b/centreon/common/ingrian/snmp/mode/requeststats.pm @@ -0,0 +1,152 @@ +# +# Copyright 2017 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::ingrian::snmp::mode::requeststats; + +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 => 'rq', type => 1, cb_prefix_output => 'prefix_disk_output', message_multiple => 'All request statistics are ok' } + ]; + + $self->{maps_counters}->{rq} = [ + { label => 'success', set => { + key_values => [ { name => 'success', diff => 1 }, { name => 'display' } ], + output_template => 'Success : %s', + perfdatas => [ + { label => 'success', value => 'success_absolute', template => '%s', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'fail', set => { + key_values => [ { name => 'fail', diff => 1 }, { name => 'display' } ], + output_template => 'Fail : %s', + perfdatas => [ + { label => 'fail', value => 'fail_absolute', template => '%s', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_disk_output { + my ($self, %options) = @_; + + return "'" . $options{instance_value}->{display} . "' requests "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-name:s" => { name => 'filter_name' }, + }); + + return $self; +} + +my @map = ( + { label => 'Total', suffix => 1 }, + { label => 'KeyGen', suffix => 2 }, + { label => 'KeyInfo', suffix => 3 }, + { label => 'KeyDel', suffix => 4 }, + { label => 'KeyQuery', suffix => 5 }, + { label => 'KeyImport', suffix => 6 }, + { label => 'KeyExport', suffix => 7 }, + { label => 'RandomGen', suffix => 8 }, + { label => 'Cryptographic', suffix => 9 }, + { label => 'Authenticate', suffix => 10 }, + { label => 'KeyModify', suffix => 11 }, + { label => 'KeyClone', suffix => 12 }, + { label => 'CertificateExport', suffix => 13 }, + { label => 'KeyVersionGenerate', suffix => 14 }, + { label => 'KeyVersionModify', suffix => 15 }, + { label => 'KeyCertificateExport', suffix => 16 }, + { label => 'RecordEvent', suffix => 17 }, + { label => 'PublicKeyExport', suffix => 18 }, + { label => 'CAExport', suffix => 19 }, +); +my $oid_naeServerStats = '.1.3.6.1.4.1.5595.3.3'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{rq} = {}; + my $snmp_result = $options{snmp}->get_table(oid => $oid_naeServerStats, + nothing_quit => 1); + foreach (@map) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $_->{label} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $_->{label} . "': no matching filter.", debug => 1); + next; + } + + $self->{rq}->{$_->{suffix}} = { + display => $_->{label}, + success => $snmp_result->{$oid_naeServerStats . '.' . $_->{suffix} . '.3.0'}, + fail => $snmp_result->{$oid_naeServerStats . '.' . $_->{suffix} . '.4.0'} + }; + } + + $self->{cache_name} = "ingrian_" . $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 request statistics. + +=over 8 + +=item B<--filter-name> + +Filter by name (can be a regexp). + +=item B<--warning-*> + +Threshold warning. +Can be: 'success', 'fail'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'success', 'fail'. + +=back + +=cut diff --git a/hardware/devices/safenet/keysecure/snmp/plugin.pm b/hardware/devices/safenet/keysecure/snmp/plugin.pm new file mode 100644 index 000000000..c732bb01b --- /dev/null +++ b/hardware/devices/safenet/keysecure/snmp/plugin.pm @@ -0,0 +1,54 @@ +# +# Copyright 2017 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::safenet::keysecure::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}} = ( + 'connections' => 'centreon::common::ingrian::snmp::mode::connections', + 'cpu' => 'centreon::common::ingrian::snmp::mode::cpu', + 'disk' => 'centreon::common::ingrian::snmp::mode::disk', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'centreon::common::ingrian::snmp::mode::memory', + 'request-stats' => 'centreon::common::ingrian::snmp::mode::requeststats', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Safenet Keysecure in SNMP. + +=cut