diff --git a/network/barracuda/cloudgen/snmp/mode/boxservice.pm b/network/barracuda/cloudgen/snmp/mode/boxservice.pm new file mode 100644 index 000000000..4f04ba371 --- /dev/null +++ b/network/barracuda/cloudgen/snmp/mode/boxservice.pm @@ -0,0 +1,212 @@ +# +# 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 network::barracuda::cloudgen::snmp::mode::boxservice; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +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 = "status is '" . $self->{result_values}->{status} . "'"; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_boxServiceState'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'services', type => 1, cb_prefix_output => 'prefix_services_output', message_multiple => 'All box services are ok' } + ]; + + $self->{maps_counters}->{services} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'boxServiceState' }, { 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 => $self->can('custom_status_threshold'), + } + }, + ]; +} + +sub prefix_services_output { + my ($self, %options) = @_; + + return "Box service '" . $options{instance_value}->{display} . "' "; +} + +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' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /^started$/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +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; + } + } +} + +my %map_status = ( + -1 => 'unknown', + 0 => 'stopped', + 1 => 'started', + 2 => 'blocked', + 4 => 'removed', +); + +my $oid_boxServiceName = '.1.3.6.1.4.1.10704.1.0.1.1'; +my $mapping = { + boxServiceState => { oid => '.1.3.6.1.4.1.10704.1.0.1.2', map => \%map_status }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + if ($options{snmp}->is_snmpv1()) { + $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); + $self->{output}->option_exit(); + } + + my $snmp_result = $options{snmp}->get_table(oid => $oid_boxServiceName, nothing_quit => 1); + $self->{services} = {}; + foreach my $oid (keys %{$snmp_result}) { + $oid =~ /^$oid_boxServiceName\.(.*)$/; + my $instance = $1; + $snmp_result->{$oid} =~ s/\\//g; + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $snmp_result->{$oid} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping service '" . $snmp_result->{$oid} . "'.", debug => 1); + next; + } + + $self->{services}->{$instance} = { display => $snmp_result->{$oid} }; + } + + $options{snmp}->load(oids => [$mapping->{boxServiceState}->{oid}], instances => [keys %{$self->{services}}], instance_regexp => '^(.*)$'); + $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); + + foreach (keys %{$self->{services}}) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + + foreach my $name (keys %$mapping) { + $self->{services}->{$_}->{$name} = $result->{$name}; + } + } + + if (scalar(keys %{$self->{services}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No services found."); + $self->{output}->option_exit(); + } + + $self->{cache_name} = "barracuda_cloudgen_" . $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')) . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check box services status. + +=over 8 + +=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} !~ /^started$/i'). +Can used special variables like: %{status}, %{display} + +=item B<--filter-name> + +Filter by service name (Can be a regexp). + +=back + +=cut diff --git a/network/barracuda/cloudgen/snmp/mode/components/fan.pm b/network/barracuda/cloudgen/snmp/mode/components/fan.pm new file mode 100644 index 000000000..21c8c1c35 --- /dev/null +++ b/network/barracuda/cloudgen/snmp/mode/components/fan.pm @@ -0,0 +1,74 @@ +# +# 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 network::barracuda::cloudgen::snmp::mode::components::fan; + +use strict; +use warnings; + +my $mapping = { + hwSensorName => { oid => '.1.3.6.1.4.1.10704.1.4.1.1' }, + hwSensorType => { oid => '.1.3.6.1.4.1.10704.1.4.1.2' }, + hwSensorValue => { oid => '.1.3.6.1.4.1.10704.1.4.1.3' }, +}; +my $oid_HwSensorsEntry = '.1.3.6.1.4.1.10704.1.4.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_HwSensorsEntry }; +} + +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_HwSensorsEntry}})) { + next if ($oid !~ /^$mapping->{hwSensorType}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_HwSensorsEntry}, instance => $instance); + + next if ($self->check_filter(section => 'fan', instance => $instance)); + next if ($result->{hwSensorType} != 1); #Fans + $self->{components}->{fan}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Fan '%s' speed is '%s' RPM", + $result->{hwSensorName}, $result->{hwSensorValue})); + + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{hwSensorValue}); + 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->{hwSensorName}, $result->{hwSensorValue})); + } + + my $perf_label = $result->{hwSensorName}; + $perf_label =~ s/ /_/g; + $self->{output}->perfdata_add(label => 'speed_' . $perf_label, unit => 'rpm', + value => $result->{hwSensorValue}, + warning => $warn, + critical => $crit + ); + } +} + +1; \ No newline at end of file diff --git a/network/barracuda/cloudgen/snmp/mode/components/psu.pm b/network/barracuda/cloudgen/snmp/mode/components/psu.pm new file mode 100644 index 000000000..07896cecc --- /dev/null +++ b/network/barracuda/cloudgen/snmp/mode/components/psu.pm @@ -0,0 +1,72 @@ +# +# 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 network::barracuda::cloudgen::snmp::mode::components::psu; + +use strict; +use warnings; + +my %map_status = ( + 0 => 'critical', + 1 => 'ok', + 2 => 'critical', +); + +my $mapping = { + hwSensorName => { oid => '.1.3.6.1.4.1.10704.1.4.1.1' }, + hwSensorType => { oid => '.1.3.6.1.4.1.10704.1.4.1.2' }, + hwSensorValue => { oid => '.1.3.6.1.4.1.10704.1.4.1.3', map => \%map_status }, +}; +my $oid_HwSensorsEntry = '.1.3.6.1.4.1.10704.1.4.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_HwSensorsEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking power supplies"); + $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_HwSensorsEntry}})) { + next if ($oid !~ /^$mapping->{hwSensorType}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_HwSensorsEntry}, instance => $instance); + + next if ($self->check_filter(section => 'psu', instance => $instance)); + next if ($result->{hwSensorType} != 3); #PSU + $self->{components}->{psu}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is '%s'", + $result->{hwSensorName}, $result->{hwSensorValue})); + + my $exit = $self->get_severity(label => 'psu', section => 'psu', value => $result->{hwSensorValue}); + 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->{hwSensorName}, $result->{hwSensorValue})); + } + } +} + +1; \ No newline at end of file diff --git a/network/barracuda/cloudgen/snmp/mode/components/temperature.pm b/network/barracuda/cloudgen/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..f890e0934 --- /dev/null +++ b/network/barracuda/cloudgen/snmp/mode/components/temperature.pm @@ -0,0 +1,74 @@ +# +# 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 network::barracuda::cloudgen::snmp::mode::components::temperature; + +use strict; +use warnings; + +my $mapping = { + hwSensorName => { oid => '.1.3.6.1.4.1.10704.1.4.1.1' }, + hwSensorType => { oid => '.1.3.6.1.4.1.10704.1.4.1.2' }, + hwSensorValue => { oid => '.1.3.6.1.4.1.10704.1.4.1.3' }, +}; +my $oid_HwSensorsEntry = '.1.3.6.1.4.1.10704.1.4.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_HwSensorsEntry }; +} + +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_HwSensorsEntry}})) { + next if ($oid !~ /^$mapping->{hwSensorType}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_HwSensorsEntry}, instance => $instance); + + next if ($self->check_filter(section => 'temperature', instance => $instance)); + next if ($result->{hwSensorType} != 2); #Temperatures + $self->{components}->{temperature}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Temperature '%s' is '%s' celsius degrees", + $result->{hwSensorName}, $result->{hwSensorValue} / 1000)); + + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{hwSensorValue} / 1000); + 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 degrees", $result->{hwSensorName}, $result->{hwSensorValue} / 1000)); + } + + my $perf_label = $result->{hwSensorName}; + $perf_label =~ s/ /_/g; + $self->{output}->perfdata_add(label => 'temperature_' . $perf_label, unit => 'C', + value => $result->{hwSensorValue} / 1000, + warning => $warn, + critical => $crit + ); + } +} + +1; \ No newline at end of file diff --git a/network/barracuda/cloudgen/snmp/mode/components/voltage.pm b/network/barracuda/cloudgen/snmp/mode/components/voltage.pm new file mode 100644 index 000000000..5ee3b9f34 --- /dev/null +++ b/network/barracuda/cloudgen/snmp/mode/components/voltage.pm @@ -0,0 +1,74 @@ +# +# 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 network::barracuda::cloudgen::snmp::mode::components::voltage; + +use strict; +use warnings; + +my $mapping = { + hwSensorName => { oid => '.1.3.6.1.4.1.10704.1.4.1.1' }, + hwSensorType => { oid => '.1.3.6.1.4.1.10704.1.4.1.2' }, + hwSensorValue => { oid => '.1.3.6.1.4.1.10704.1.4.1.3' }, +}; +my $oid_HwSensorsEntry = '.1.3.6.1.4.1.10704.1.4.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_HwSensorsEntry }; +} + +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_HwSensorsEntry}})) { + next if ($oid !~ /^$mapping->{hwSensorType}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_HwSensorsEntry}, instance => $instance); + + next if ($self->check_filter(section => 'voltage', instance => $instance)); + next if ($result->{hwSensorType} != 0); #Voltages + $self->{components}->{voltage}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Voltage '%s' is '%s' mV", + $result->{hwSensorName}, $result->{hwSensorValue})); + + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, value => $result->{hwSensorValue}); + 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->{hwSensorName}, $result->{hwSensorValue})); + } + + my $perf_label = $result->{hwSensorName}; + $perf_label =~ s/ /_/g; + $self->{output}->perfdata_add(label => 'voltage_' . $perf_label, unit => 'mV', + value => $result->{hwSensorValue}, + warning => $warn, + critical => $crit + ); + } +} + +1; \ No newline at end of file diff --git a/network/barracuda/cloudgen/snmp/mode/hardware.pm b/network/barracuda/cloudgen/snmp/mode/hardware.pm new file mode 100644 index 000000000..b963905d0 --- /dev/null +++ b/network/barracuda/cloudgen/snmp/mode/hardware.pm @@ -0,0 +1,111 @@ +# +# 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 network::barracuda::cloudgen::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_numeric_check_section_option} = '^(fan|temperature|voltage)$'; + $self->{regexp_threshold_overload_check_section_option} = '^(psu)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + 'psu' => [ + ['ok', 'OK'], + ['critical', 'CRITICAL'], + ['unknown', 'UNKNOWN'], + ], + }; + + $self->{components_path} = 'network::barracuda::cloudgen::snmp::mode::components'; + $self->{components_module} = ['fan', 'temperature', 'psu', 'voltage']; +} + +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); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check hardware components. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'fan', 'temperature', 'psu', 'voltage'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=psu) +Can also exclude specific instance: --filter=psu,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,^(?!(ok)$)' + +=item B<--warning> + +Set warning threshold (syntax: type,regexp,threshold) +Example: --warning='fan,.*,300' + +=item B<--critical> + +Set critical threshold (syntax: type,regexp,threshold) +Example: --critical='fan,.*,400' + +=back + +=cut diff --git a/network/barracuda/cloudgen/snmp/mode/listvpns.pm b/network/barracuda/cloudgen/snmp/mode/listvpns.pm new file mode 100644 index 000000000..50828193d --- /dev/null +++ b/network/barracuda/cloudgen/snmp/mode/listvpns.pm @@ -0,0 +1,132 @@ +# +# 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 network::barracuda::cloudgen::snmp::mode::listvpns; + +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; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-name:s" => { name => 'filter_name' }, + }); + $self->{vpn} = {}; + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +my %map_status = ( + -1 => 'down', + 0 => 'down-disabled', + 1 => 'active', +); + +my $mapping = { + vpnName => { oid => '.1.3.6.1.4.1.10704.1.6.1.1' }, + vpnState => { oid => '.1.3.6.1.4.1.10704.1.6.1.2', map => \%map_status }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $mapping->{vpnName}->{oid} }, + { oid => $mapping->{vpnState}->{oid} }, + ], + return_type => 1, nothing_quit => 1); + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{vpnName}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + $result->{vpnName} =~ s/\\//g; + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{vpnName} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{vpnName} . "': no matching filter.", debug => 1); + next; + } + + $self->{vpn}->{$instance} = { + name => $result->{vpnName}, status => $result->{vpnState} }; + } +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $instance (sort keys %{$self->{vpn}}) { + $self->{output}->output_add(long_msg => '[name = ' . $self->{vpn}->{$instance}->{name} . + "] [status = " . $self->{vpn}->{$instance}->{status} . ']' + ); + } + + $self->{output}->output_add(severity => 'OK', + short_msg => 'List VPNs:'); + $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', 'status']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $instance (sort keys %{$self->{vpn}}) { + $self->{output}->add_disco_entry(name => $self->{vpn}->{$instance}->{name}, + status => $self->{vpn}->{$instance}->{status}); + } +} + +1; + +__END__ + +=head1 MODE + +List VPNs. + +=over 8 + +=item B<--filter-name> + +Filter by VPN name (can be a regexp). + +=back + +=cut + diff --git a/network/barracuda/cloudgen/snmp/mode/serverservice.pm b/network/barracuda/cloudgen/snmp/mode/serverservice.pm new file mode 100644 index 000000000..6282d4d48 --- /dev/null +++ b/network/barracuda/cloudgen/snmp/mode/serverservice.pm @@ -0,0 +1,212 @@ +# +# 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 network::barracuda::cloudgen::snmp::mode::serverservice; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +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 = "status is '" . $self->{result_values}->{status} . "'"; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_serverServiceState'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'services', type => 1, cb_prefix_output => 'prefix_services_output', message_multiple => 'All server services are ok' } + ]; + + $self->{maps_counters}->{services} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'serverServiceState' }, { 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 => $self->can('custom_status_threshold'), + } + }, + ]; +} + +sub prefix_services_output { + my ($self, %options) = @_; + + return "Server service '" . $options{instance_value}->{display} . "' "; +} + +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' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /^started$/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +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; + } + } +} + +my %map_status = ( + -1 => 'unknown', + 0 => 'stopped', + 1 => 'started', + 2 => 'blocked', + 4 => 'removed', +); + +my $oid_serverServiceName = '.1.3.6.1.4.1.10704.1.1.1.1'; +my $mapping = { + serverServiceState => { oid => '.1.3.6.1.4.1.10704.1.1.1.2', map => \%map_status }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + if ($options{snmp}->is_snmpv1()) { + $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); + $self->{output}->option_exit(); + } + + my $snmp_result = $options{snmp}->get_table(oid => $oid_serverServiceName, nothing_quit => 1); + $self->{services} = {}; + foreach my $oid (keys %{$snmp_result}) { + $oid =~ /^$oid_serverServiceName\.(.*)$/; + my $instance = $1; + $snmp_result->{$oid} =~ s/\\//g; + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $snmp_result->{$oid} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping service '" . $snmp_result->{$oid} . "'.", debug => 1); + next; + } + + $self->{services}->{$instance} = { display => $snmp_result->{$oid} }; + } + + $options{snmp}->load(oids => [$mapping->{serverServiceState}->{oid}], instances => [keys %{$self->{services}}], instance_regexp => '^(.*)$'); + $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); + + foreach (keys %{$self->{services}}) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + + foreach my $name (keys %$mapping) { + $self->{services}->{$_}->{$name} = $result->{$name}; + } + } + + if (scalar(keys %{$self->{services}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No services found."); + $self->{output}->option_exit(); + } + + $self->{cache_name} = "barracuda_cloudgen_" . $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')) . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check server services status. + +=over 8 + +=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} !~ /^started$/i'). +Can used special variables like: %{status}, %{display} + +=item B<--filter-name> + +Filter by service name (Can be a regexp). + +=back + +=cut diff --git a/network/barracuda/cloudgen/snmp/mode/vpnstatus.pm b/network/barracuda/cloudgen/snmp/mode/vpnstatus.pm new file mode 100644 index 000000000..eed62b2d0 --- /dev/null +++ b/network/barracuda/cloudgen/snmp/mode/vpnstatus.pm @@ -0,0 +1,210 @@ +# +# 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 network::barracuda::cloudgen::snmp::mode::vpnstatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +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 = "status is '" . $self->{result_values}->{status} . "'"; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_vpnState'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'vpns', type => 1, cb_prefix_output => 'prefix_vpns_output', message_multiple => 'All VPNs are ok' } + ]; + + $self->{maps_counters}->{vpns} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'vpnState' }, { 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 => $self->can('custom_status_threshold'), + } + }, + ]; +} + +sub prefix_vpns_output { + my ($self, %options) = @_; + + return "VPN '" . $options{instance_value}->{display} . "' "; +} + +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' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /^down$/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +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; + } + } +} + +my %map_status = ( + -1 => 'down', + 0 => 'down-disabled', + 1 => 'active', +); + +my $oid_vpnName = '.1.3.6.1.4.1.10704.1.6.1.1'; +my $mapping = { + vpnState => { oid => '.1.3.6.1.4.1.10704.1.6.1.2', map => \%map_status }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + if ($options{snmp}->is_snmpv1()) { + $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); + $self->{output}->option_exit(); + } + + my $snmp_result = $options{snmp}->get_table(oid => $oid_vpnName, nothing_quit => 1); + $self->{vpns} = {}; + foreach my $oid (keys %{$snmp_result}) { + $oid =~ /^$oid_vpnName\.(.*)$/; + my $instance = $1; + $snmp_result->{$oid} =~ s/\\//g; + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $snmp_result->{$oid} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping VPN '" . $snmp_result->{$oid} . "'.", debug => 1); + next; + } + + $self->{vpns}->{$instance} = { display => $snmp_result->{$oid} }; + } + + $options{snmp}->load(oids => [$mapping->{vpnState}->{oid}], instances => [keys %{$self->{vpns}}], instance_regexp => '^(.*)$'); + $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); + + foreach (keys %{$self->{vpns}}) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + + foreach my $name (keys %$mapping) { + $self->{vpns}->{$_}->{$name} = $result->{$name}; + } + } + + if (scalar(keys %{$self->{vpns}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No VPNs found."); + $self->{output}->option_exit(); + } + + $self->{cache_name} = "barracuda_cloudgen_" . $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')) . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check VPNs status. + +=over 8 + +=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} =~ /^down$/i'). +Can used special variables like: %{status}, %{display} + +=item B<--filter-name> + +Filter by VPN name (Can be a regexp). + +=back + +=cut diff --git a/network/barracuda/cloudgen/snmp/plugin.pm b/network/barracuda/cloudgen/snmp/plugin.pm new file mode 100644 index 000000000..b98fa84a5 --- /dev/null +++ b/network/barracuda/cloudgen/snmp/plugin.pm @@ -0,0 +1,60 @@ +# +# 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 network::barracuda::cloudgen::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', + 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'box-service' => 'network::barracuda::cloudgen::snmp::mode::boxservice', + 'hardware' => 'network::barracuda::cloudgen::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-vpns' => 'network::barracuda::cloudgen::snmp::mode::listvpns', + 'load' => 'snmp_standard::mode::loadaverage', + 'memory' => 'snmp_standard::mode::memory', + 'server-service' => 'network::barracuda::cloudgen::snmp::mode::serverservice', + 'storage' => 'snmp_standard::mode::storage', + 'uptime' => 'snmp_standard::mode::uptime', + 'vpn-status' => 'network::barracuda::cloudgen::snmp::mode::vpnstatus', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Barracuda CloudGen firewalls in SNMP. + +=cut