diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/auditlogs.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/auditlogs.pm deleted file mode 100644 index 937098777..000000000 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/auditlogs.pm +++ /dev/null @@ -1,217 +0,0 @@ -# -# Copyright 2021 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::server::cisco::ucs::mode::auditlogs; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -use centreon::plugins::misc; -use centreon::plugins::statefile; -use POSIX; - -my %severity_map = ( - 0 => 'cleared', - 1 => 'info', - 2 => 'condition', - 3 => 'warning', - 4 => 'minor', - 5 => 'major', - 6 => 'critical', -); - -my $oid_cucsAaaModLRDescr = '.1.3.6.1.4.1.9.9.719.1.2.17.1.9'; -my $oid_cucsAaaModLRCreated = '.1.3.6.1.4.1.9.9.719.1.2.17.1.8'; -my $oid_cucsAaaModLRSeverity = '.1.3.6.1.4.1.9.9.719.1.2.17.1.12'; -my $oid_cucsAaaModLRDn = '.1.3.6.1.4.1.9.9.719.1.2.17.1.2'; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => { - 'filter-severity:s@' => { name => 'filter_severity', }, - 'filter-message:s' => { name => 'filter_message' }, - 'retention:s' => { name => 'retention' }, - 'memory' => { name => 'memory' }, - }); - - $self->{statefile_cache} = centreon::plugins::statefile->new(%options); - $self->{severities} = {}; - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (defined($self->{option_results}->{memory})) { - $self->{statefile_cache}->check_options(%options); - } - foreach my $val (@{$self->{option_results}->{filter_severity}}) { - if ($val !~ /(.*?)=(.*)/) { - $self->{output}->add_option_msg(short_msg => "Wrong filter-severity option '" . $val . "'."); - $self->{output}->option_exit(); - } - - my ($filter, $threshold) = ($1, $2); - if ($self->{output}->is_litteral_status(status => $threshold) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong filter_severity status '" . $val . "'."); - $self->{output}->option_exit(); - } - - $self->{severities}->{$filter} = $threshold; - } - if (scalar(keys %{$self->{severities}}) == 0) { - $self->{severities} = { 'major|critical' => 'critical', 'minor|warning' => 'warning' }; - } -} - -sub get_timestamp { - my ($self, %options) = @_; - - my $value = unpack('H*', $options{value}); - $value =~ /^([0-9a-z]{4})([0-9a-z]{2})([0-9a-z]{2})([0-9a-z]{2})([0-9a-z]{2})([0-9a-z]{2})/; - - my $currentTmsp = mktime(hex($6), hex($5), hex($4), hex($3), hex($2) - 1, hex($1) - 1900); - return $currentTmsp; -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - $self->{snmp_port} = $self->{snmp}->get_port(); - my $datas = {}; - my ($start, $last_instance); - my ($num_eventlog_checked, $num_errors) = (0, 0); - my %oids = ($oid_cucsAaaModLRDescr => undef, $oid_cucsAaaModLRCreated => undef, $oid_cucsAaaModLRSeverity => undef, $oid_cucsAaaModLRDn => undef); - - if (defined($self->{option_results}->{memory})) { - $self->{statefile_cache}->read(statefile => "cache_ciscoucs_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode}); - $self->{output}->output_add(severity => 'OK', - short_msg => "No new problems detected."); - $start = $self->{statefile_cache}->get(name => 'start'); - $last_instance = $start; - if (defined($start)) { - foreach (keys %oids) { - $oids{$_} = $_ . '.' . $start; - } - } - } else { - $self->{output}->output_add(severity => 'OK', - short_msg => "No problems detected."); - } - - my $result = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_cucsAaaModLRDescr, start => $oids{$oid_cucsAaaModLRDescr} }, - { oid => $oid_cucsAaaModLRCreated, start => $oids{$oid_cucsAaaModLRCreated} }, - { oid => $oid_cucsAaaModLRSeverity, start => $oids{$oid_cucsAaaModLRSeverity} }, - { oid => $oid_cucsAaaModLRDn, start => $oids{$oid_cucsAaaModLRDn} }, - ] ); - my @exits_global; - foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$result->{$oid_cucsAaaModLRDn}})) { - next if ($key !~ /^$oid_cucsAaaModLRDn\.(\d+)$/); - my $instance = $1; - $last_instance = $instance; - - my $message = centreon::plugins::misc::trim($result->{$oid_cucsAaaModLRDescr}->{$oid_cucsAaaModLRDescr . '.' . $instance}); - my $severity = $result->{$oid_cucsAaaModLRSeverity}->{$oid_cucsAaaModLRSeverity . '.' . $instance}; - my $timestamp = $self->get_timestamp(value => $result->{$oid_cucsAaaModLRCreated}->{$oid_cucsAaaModLRCreated . '.' . $instance}); - my $dn = $result->{$oid_cucsAaaModLRDn}->{$oid_cucsAaaModLRDn . '.' . $instance}; - - if (defined($self->{option_results}->{retention})) { - next if (time() - $timestamp > $self->{option_results}->{retention}); - } - - $num_eventlog_checked++; - next if (defined($self->{option_results}->{filter_message}) && $self->{option_results}->{filter_message} ne '' && $message !~ /$self->{option_results}->{filter_message}/); - - my @exits; - foreach (keys %{$self->{severities}}) { - if ($severity_map{$severity} =~ /$_/) { - push @exits, $self->{severities}->{$_}; - push @exits_global, $self->{severities}->{$_}; - } - } - - my $exit = $self->{output}->get_most_critical(status => \@exits); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $num_errors++; - $self->{output}->output_add(long_msg => sprintf("%s : %s (%s)", - scalar(localtime($timestamp)), - $message, $dn - ) - ); - } - } - - $self->{output}->output_add(long_msg => sprintf("Number of message checked: %s", $num_eventlog_checked)); - if ($num_errors != 0) { - # Message problem - my $exit = $self->{output}->get_most_critical(status => \@exits_global); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("%d problem detected (use verbose for more details)", $num_errors) - ); - } - - if (defined($self->{option_results}->{memory})) { - $datas->{start} = $last_instance; - $self->{statefile_cache}->write(data => $datas); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check audit logs. - -=over 8 - -=item B<--memory> - -Only check new audit. - -=item B<--filter-severity> - -Filter on severity. (Default: 'critical|major=critical', 'warning|minor=warning') -Can be: critical, major, warning, minor, info, condition, cleared. - -=item B<--filter-message> - -Filter on event message. (Default: none) - -=item B<--retention> - -Event older (current time - retention time) is not checked (in seconds). - -=back - -=cut - diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/faults.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/faults.pm deleted file mode 100644 index 84299ba99..000000000 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/faults.pm +++ /dev/null @@ -1,222 +0,0 @@ -# -# Copyright 2021 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::server::cisco::ucs::mode::faults; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -use centreon::plugins::misc; -use centreon::plugins::statefile; -use POSIX; - -my %severity_map = ( - 0 => 'cleared', - 1 => 'info', - 3 => 'warning', - 4 => 'minor', - 5 => 'major', - 6 => 'critical', -); - -my $oid_cucsFaultDescription = '.1.3.6.1.4.1.9.9.719.1.1.1.1.11'; -my $oid_cucsFaultCreationTime = '.1.3.6.1.4.1.9.9.719.1.1.1.1.10'; -my $oid_cucsFaultSeverity = '.1.3.6.1.4.1.9.9.719.1.1.1.1.20'; -my $oid_cucsFaultDn = '.1.3.6.1.4.1.9.9.719.1.1.1.1.2'; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => - { - "filter-severity:s@" => { name => 'filter_severity', }, - "filter-message:s" => { name => 'filter_message' }, - "retention:s" => { name => 'retention' }, - "memory" => { name => 'memory' }, - }); - $self->{statefile_cache} = centreon::plugins::statefile->new(%options); - $self->{severities} = {}; - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (defined($self->{option_results}->{memory})) { - $self->{statefile_cache}->check_options(%options); - } - foreach my $val (@{$self->{option_results}->{filter_severity}}) { - if ($val !~ /(.*?)=(.*)/) { - $self->{output}->add_option_msg(short_msg => "Wrong filter-severity option '" . $val . "'."); - $self->{output}->option_exit(); - } - - my ($filter, $threshold) = ($1, $2); - if ($self->{output}->is_litteral_status(status => $threshold) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong filter_severity status '" . $val . "'."); - $self->{output}->option_exit(); - } - - $self->{severities}->{$filter} = $threshold; - } - if (scalar(keys %{$self->{severities}}) == 0) { - $self->{severities} = { 'major|critical' => 'critical', 'minor|warning' => 'warning' }; - } -} - -sub get_timestamp { - my ($self, %options) = @_; - - my $currentTmsp = 0; - my $value = $options{value}; - if ($value =~ /^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/) { - $currentTmsp = mktime($6, $5, $4, $3, $2 - 1, $1 - 1900); - } else { - $value = unpack('H*', $value); - $value =~ /^([0-9a-z]{4})([0-9a-z]{2})([0-9a-z]{2})([0-9a-z]{2})([0-9a-z]{2})([0-9a-z]{2})/; - $currentTmsp = mktime(hex($6), hex($5), hex($4), hex($3), hex($2) - 1, hex($1) - 1900); - } - - return $currentTmsp; -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - $self->{snmp_port} = $self->{snmp}->get_port(); - my $datas = {}; - my ($start, $last_instance); - my ($num_eventlog_checked, $num_errors) = (0, 0); - my %oids = ($oid_cucsFaultDescription => undef, $oid_cucsFaultCreationTime => undef, $oid_cucsFaultSeverity => undef, $oid_cucsFaultDn => undef); - - if (defined($self->{option_results}->{memory})) { - $self->{statefile_cache}->read(statefile => "cache_ciscoucs_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode}); - $self->{output}->output_add(severity => 'OK', - short_msg => "No new problems detected."); - $start = $self->{statefile_cache}->get(name => 'start'); - $last_instance = $start; - if (defined($start)) { - foreach (keys %oids) { - $oids{$_} = $_ . '.' . $start; - } - } - } else { - $self->{output}->output_add(severity => 'OK', - short_msg => "No problems detected."); - } - - my $result = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_cucsFaultDescription, start => $oids{$oid_cucsFaultDescription} }, - { oid => $oid_cucsFaultCreationTime, start => $oids{$oid_cucsFaultCreationTime} }, - { oid => $oid_cucsFaultSeverity, start => $oids{$oid_cucsFaultSeverity} }, - { oid => $oid_cucsFaultDn, start => $oids{$oid_cucsFaultDn} }, - ] ); - my @exits_global; - foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$result->{$oid_cucsFaultDn}})) { - next if ($key !~ /^$oid_cucsFaultDn\.(\d+)$/); - my $instance = $1; - $last_instance = $instance; - - my $message = centreon::plugins::misc::trim($result->{$oid_cucsFaultDescription}->{$oid_cucsFaultDescription . '.' . $instance}); - my $severity = $result->{$oid_cucsFaultSeverity}->{$oid_cucsFaultSeverity . '.' . $instance}; - my $timestamp = $self->get_timestamp(value => $result->{$oid_cucsFaultCreationTime}->{$oid_cucsFaultCreationTime . '.' . $instance}); - my $dn = $result->{$oid_cucsFaultDn}->{$oid_cucsFaultDn . '.' . $instance}; - - if (defined($self->{option_results}->{retention})) { - next if (time() - $timestamp > $self->{option_results}->{retention}); - } - - $num_eventlog_checked++; - next if (defined($self->{option_results}->{filter_message}) && $self->{option_results}->{filter_message} ne '' && $message !~ /$self->{option_results}->{filter_message}/); - - my @exits; - foreach (keys %{$self->{severities}}) { - if ($severity_map{$severity} =~ /$_/) { - push @exits, $self->{severities}->{$_}; - push @exits_global, $self->{severities}->{$_}; - } - } - - my $exit = $self->{output}->get_most_critical(status => \@exits); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $num_errors++; - $self->{output}->output_add(long_msg => sprintf("%s : %s (%s)", - scalar(localtime($timestamp)), - $message, $dn - ) - ); - } - } - - $self->{output}->output_add(long_msg => sprintf("Number of message checked: %s", $num_eventlog_checked)); - if ($num_errors != 0) { - # Message problem - my $exit = $self->{output}->get_most_critical(status => \@exits_global); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("%d problem detected (use verbose for more details)", $num_errors) - ); - } - - if (defined($self->{option_results}->{memory})) { - $datas->{start} = $last_instance; - $self->{statefile_cache}->write(data => $datas); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check faults. - -=over 8 - -=item B<--memory> - -Only check new fault. - -=item B<--filter-severity> - -Filter on severity. (Default: 'critical|major=critical', 'warning|minor=warning') -Can be: critical, major, warning, minor, info, cleared. - -=item B<--filter-message> - -Filter on event message. (Default: none) - -=item B<--retention> - -Event older (current time - retention time) is not checked (in seconds). - -=back - -=cut - diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/serviceprofile.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/serviceprofile.pm deleted file mode 100644 index 8c848f926..000000000 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/serviceprofile.pm +++ /dev/null @@ -1,145 +0,0 @@ -# -# Copyright 2021 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::server::cisco::ucs::mode::serviceprofile; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -my %error_status = ( - 1 => ["online", 'OK'], - 2 => ["offline", 'CRITICAL'], -); - -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' }, - "skip" => { name => 'skip' }, - }); - - 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}; - - my $oid_cucsLsBindingDn = '.1.3.6.1.4.1.9.9.719.1.26.2.1.2'; - my $oid_cucsLsBindingOperState = '.1.3.6.1.4.1.9.9.719.1.26.2.1.10'; - - my $result = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_cucsLsBindingDn }, - { oid => $oid_cucsLsBindingOperState }, - ], - nothing_quit => 1 - ); - - my $ls_online = 0; - my $ls_offline = 0; - - foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$result->{$oid_cucsLsBindingDn}})) { - # index - $key =~ /\.(\d+)$/; - my $ls_index = $1; - my $ls_name = $result->{$oid_cucsLsBindingDn}->{$oid_cucsLsBindingDn . '.' . $ls_index}; - my $ls_operstate = $result->{$oid_cucsLsBindingOperState}->{$oid_cucsLsBindingOperState . '.' . $ls_index}; - - if ($ls_operstate == 1) { - $ls_online++; - } else { - $ls_offline++; - } - - if ($ls_operstate == 2 && defined($self->{option_results}->{skip})) { - next; - } - if ($ls_operstate != 1) { - $self->{output}->output_add(severity => ${$error_status{$ls_operstate}}[1], - short_msg => sprintf("Service profile '%s' is %s", $ls_name, ${$error_status{$ls_operstate}}[0])); - } - } - - my $ls_total = $ls_online + $ls_offline; - my $exit = $self->{perfdata}->threshold_check(value => $ls_online, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("%d service profiles online", $ls_online)); - - $self->{output}->perfdata_add(label => "sp_online", - value => $ls_online, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, max => $ls_total); - - $self->{output}->perfdata_add(label => "sp_offline", - value => $ls_offline, - min => 0, max => $ls_total); - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check service profiles status. - -=over 8 - -=item B<--skip> - -Skip 'offline' service profiles. - -=item B<--warning> - -Threshold warning for 'online' service profiles. - -=item B<--critical> - -Threshold critical for 'online' service profiles. - -=back - -=cut - diff --git a/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/auditlogs.pm b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/auditlogs.pm new file mode 100644 index 000000000..2ca03b1ce --- /dev/null +++ b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/auditlogs.pm @@ -0,0 +1,235 @@ +# +# Copyright 2021 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::server::cisco::ucs::snmp::mode::auditlogs; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::misc; +use centreon::plugins::statefile; +use POSIX; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); + +my $map_severity = { + 0 => 'cleared', 1 => 'info', 2 => 'condition', + 3 => 'warning', 4 => 'minor', 5 => 'major', + 6 => 'critical' +}; + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + 'audit [severity: %s] [dn: %s] [description: %s] %s', + $self->{result_values}->{severity}, + $self->{result_values}->{dn}, + $self->{result_values}->{description}, + scalar(localtime($self->{result_values}->{created})) + ); +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return 'Audit '; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', }, + { name => 'alarms', type => 2, message_multiple => '0 problem(s) detected', display_counter_problem => { nlabel => 'audit.problems.current.count', min => 0 }, + group => [ { name => 'alarm', skipped_code => { -11 => 1 } } ] + } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'audit-total', nlabel => 'audit.total.count', display_ok => 0, set => { + key_values => [ { name => 'total' } ], + output_template => 'total: %s', + perfdatas => [ + { template => '%s', min => 0 } + ] + } + } + ]; + + foreach (values %$map_severity) { + push @{$self->{maps_counters}->{global}}, + { label => 'audit-' . $_, nlabel => 'audit.' . $_ . '.count', display_ok => 0, set => { + key_values => [ { name => $_ }, { name => 'total' } ], + output_template => $_ . ': %s', + perfdatas => [ + { template => '%s', min => 0, max => 'total' } + ] + } + }; + } + + $self->{maps_counters}->{alarm} = [ + { + label => 'status', + type => 2, + warning_default => '%{severity} =~ /minor|warning/', + critical_default => '%{severity} =~ /major|critical/', + set => { + key_values => [ + { name => 'dn' }, { name => 'severity' }, + { name => 'description' }, { name => 'created' } + ], + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold_ng + } + } + ]; +} + +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-message:s' => { name => 'filter_message' }, + 'retention:s' => { name => 'retention' }, + 'memory' => { name => 'memory' } + }); + + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->check_options(%options); + } +} + +sub get_timestamp { + my ($self, %options) = @_; + + my $value = unpack('H*', $options{value}); + $value =~ /^([0-9a-z]{4})([0-9a-z]{2})([0-9a-z]{2})([0-9a-z]{2})([0-9a-z]{2})([0-9a-z]{2})/; + + my $currentTmsp = mktime(hex($6), hex($5), hex($4), hex($3), hex($2) - 1, hex($1) - 1900); + return $currentTmsp; +} + +my $mapping = { + dn => { oid => '.1.3.6.1.4.1.9.9.719.1.2.17.1.2' }, # cucsAaaModLRDn + description => { oid => '.1.3.6.1.4.1.9.9.719.1.2.17.1.9' }, # cucsAaaModLRDescr + created => { oid => '.1.3.6.1.4.1.9.9.719.1.2.17.1.8' }, # cucsAaaModLRCreated + severity => { oid => '.1.3.6.1.4.1.9.9.719.1.2.17.1.12', map => $map_severity } # cucsAaaModLRSeverity +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $datas = {}; + my ($start, $last_instance); + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->read(statefile => 'cache_ciscoucs_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode}); + $start = $self->{statefile_cache}->get(name => 'start'); + $start = $start - 1 if (defined($start)); + } + + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ map({ oid => $_->{oid}, start => $_->{oid} . (defined($start) ? '.' . $start : '') }, values(%$mapping)) ], + return_type => 1 + ); + + $self->{global} = { + total => 0, cleared => 0, info => 0, condition => 0, + warning => 0, minor => 0, major => 0, critical => 0 + }; + $self->{alarms} = { global => { alarm => {} } }; + my ($i, $current_time) = (1, time()); + foreach my $oid ($options{snmp}->oid_lex_sort(keys %$snmp_result)) { + next if ($oid !~ /^$mapping->{dn}->{oid}\.(\d+)$/); + my $instance = $1; + if (defined($self->{option_results}->{memory})) { + $last_instance = $instance; + next if (defined($start) && ($start + 1) >= $instance); # we skip last one from previous check) + } + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + $result->{description} = centreon::plugins::misc::trim($result->{description}); + $result->{created} = $self->get_timestamp(value => $result->{created}); + if (defined($self->{option_results}->{retention})) { + next if ($current_time - $result->{created} > $self->{option_results}->{retention}); + } + + $self->{global}->{total}++; + next if (defined($self->{option_results}->{filter_message}) && $self->{option_results}->{filter_message} ne '' && $result->{description} !~ /$self->{option_results}->{filter_message}/); + + $self->{alarms}->{global}->{alarm}->{$i} = $result; + $self->{global}->{ $result->{severity} }++; + $i++; + } + + if (defined($self->{option_results}->{memory})) { + $datas->{start} = $last_instance; + $self->{statefile_cache}->write(data => $datas); + } +} + +1; + +__END__ + +=head1 MODE + +Check audit logs. + +=over 8 + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{severity} =~ /minor|warning/') +Can used special variables like: %{severity}, %{description}, %{dn} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{severity} =~ /major|critical/'). +Can used special variables like: %{severity}, %{description}, %{dn} + +=item B<--memory> + +Only check new audit. + +=item B<--filter-message> + +Filter on event message. (Default: none) + +=item B<--retention> + +Event older (current time - retention time) is not checked (in seconds). + +=back + +=cut + diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/blade.pm b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/blade.pm similarity index 93% rename from centreon-plugins/hardware/server/cisco/ucs/mode/components/blade.pm rename to centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/blade.pm index ddeee8b28..e152cd830 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/blade.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/blade.pm @@ -18,18 +18,18 @@ # limitations under the License. # -package hardware::server::cisco::ucs::mode::components::blade; +package hardware::server::cisco::ucs::snmp::mode::components::blade; use strict; use warnings; -use hardware::server::cisco::ucs::mode::components::resources qw(%mapping_presence %mapping_overall_status); +use hardware::server::cisco::ucs::snmp::mode::components::resources qw(%mapping_presence %mapping_overall_status); # In MIB 'CISCO-UNIFIED-COMPUTING-EQUIPMENT-MIB' my $mapping1 = { - cucsComputeBladePresence => { oid => '.1.3.6.1.4.1.9.9.719.1.9.2.1.45', map => \%mapping_presence }, + cucsComputeBladePresence => { oid => '.1.3.6.1.4.1.9.9.719.1.9.2.1.45', map => \%mapping_presence } }; my $mapping2 = { - cucsComputeBladeOperState => { oid => '.1.3.6.1.4.1.9.9.719.1.9.2.1.42', map => \%mapping_overall_status }, + cucsComputeBladeOperState => { oid => '.1.3.6.1.4.1.9.9.719.1.9.2.1.42', map => \%mapping_overall_status } }; my $oid_cucsComputeBladeDn = '.1.3.6.1.4.1.9.9.719.1.9.2.1.2'; diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/chassis.pm b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/chassis.pm similarity index 93% rename from centreon-plugins/hardware/server/cisco/ucs/mode/components/chassis.pm rename to centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/chassis.pm index 2bacbcd08..a700d8210 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/chassis.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/chassis.pm @@ -18,16 +18,16 @@ # limitations under the License. # -package hardware::server::cisco::ucs::mode::components::chassis; +package hardware::server::cisco::ucs::snmp::mode::components::chassis; use strict; use warnings; -use hardware::server::cisco::ucs::mode::components::resources qw(%mapping_operability); +use hardware::server::cisco::ucs::snmp::mode::components::resources qw(%mapping_operability); # In MIB 'CISCO-UNIFIED-COMPUTING-EQUIPMENT-MIB' # Don't do the 'presence'. Is 'unknown' ??!!! my $mapping1 = { - cucsEquipmentChassisOperState => { oid => '.1.3.6.1.4.1.9.9.719.1.15.7.1.27', map => \%mapping_operability }, + cucsEquipmentChassisOperState => { oid => '.1.3.6.1.4.1.9.9.719.1.15.7.1.27', map => \%mapping_operability } }; my $oid_cucsEquipmentChassisDn = '.1.3.6.1.4.1.9.9.719.1.15.7.1.2'; diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/cpu.pm b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/cpu.pm similarity index 93% rename from centreon-plugins/hardware/server/cisco/ucs/mode/components/cpu.pm rename to centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/cpu.pm index d37b62fd9..c1ac57da2 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/cpu.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/cpu.pm @@ -18,18 +18,18 @@ # limitations under the License. # -package hardware::server::cisco::ucs::mode::components::cpu; +package hardware::server::cisco::ucs::snmp::mode::components::cpu; use strict; use warnings; -use hardware::server::cisco::ucs::mode::components::resources qw(%mapping_presence %mapping_operability); +use hardware::server::cisco::ucs::snmp::mode::components::resources qw(%mapping_presence %mapping_operability); # In MIB 'CISCO-UNIFIED-COMPUTING-PROCESSOR-MIB' my $mapping1 = { - cucsProcessorUnitPresence => { oid => '.1.3.6.1.4.1.9.9.719.1.41.9.1.13', map => \%mapping_presence }, + cucsProcessorUnitPresence => { oid => '.1.3.6.1.4.1.9.9.719.1.41.9.1.13', map => \%mapping_presence } }; my $mapping2 = { - cucsProcessorUnitOperState => { oid => '.1.3.6.1.4.1.9.9.719.1.41.9.1.9', map => \%mapping_operability }, + cucsProcessorUnitOperState => { oid => '.1.3.6.1.4.1.9.9.719.1.41.9.1.9', map => \%mapping_operability } }; my $oid_cucsProcessorUnitDn = '.1.3.6.1.4.1.9.9.719.1.41.9.1.2'; diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/fan.pm b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/fan.pm similarity index 95% rename from centreon-plugins/hardware/server/cisco/ucs/mode/components/fan.pm rename to centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/fan.pm index 4e98c233e..ca4058f27 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/fan.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/fan.pm @@ -18,11 +18,11 @@ # limitations under the License. # -package hardware::server::cisco::ucs::mode::components::fan; +package hardware::server::cisco::ucs::snmp::mode::components::fan; use strict; use warnings; -use hardware::server::cisco::ucs::mode::components::resources qw(%mapping_presence %mapping_operability); +use hardware::server::cisco::ucs::snmp::mode::components::resources qw(%mapping_presence %mapping_operability); # In MIB 'CISCO-UNIFIED-COMPUTING-EQUIPMENT-MIB' my $mapping1 = { diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/fex.pm b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/fex.pm similarity index 95% rename from centreon-plugins/hardware/server/cisco/ucs/mode/components/fex.pm rename to centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/fex.pm index b9db34137..407909668 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/fex.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/fex.pm @@ -18,11 +18,11 @@ # limitations under the License. # -package hardware::server::cisco::ucs::mode::components::fex; +package hardware::server::cisco::ucs::snmp::mode::components::fex; use strict; use warnings; -use hardware::server::cisco::ucs::mode::components::resources qw(%mapping_presence %mapping_operability); +use hardware::server::cisco::ucs::snmp::mode::components::resources qw(%mapping_presence %mapping_operability); # In MIB 'CISCO-UNIFIED-COMPUTING-EQUIPMENT-MIB' my $mapping1 = { diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/iocard.pm b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/iocard.pm similarity index 95% rename from centreon-plugins/hardware/server/cisco/ucs/mode/components/iocard.pm rename to centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/iocard.pm index 7493a25a6..2611cdaa5 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/iocard.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/iocard.pm @@ -18,11 +18,11 @@ # limitations under the License. # -package hardware::server::cisco::ucs::mode::components::iocard; +package hardware::server::cisco::ucs::snmp::mode::components::iocard; use strict; use warnings; -use hardware::server::cisco::ucs::mode::components::resources qw(%mapping_presence %mapping_operability); +use hardware::server::cisco::ucs::snmp::mode::components::resources qw(%mapping_presence %mapping_operability); # In MIB 'CISCO-UNIFIED-COMPUTING-EQUIPMENT-MIB' my $mapping1 = { diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/localdisk.pm b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/localdisk.pm similarity index 93% rename from centreon-plugins/hardware/server/cisco/ucs/mode/components/localdisk.pm rename to centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/localdisk.pm index 2a6913b84..382d0c1ba 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/localdisk.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/localdisk.pm @@ -18,18 +18,18 @@ # limitations under the License. # -package hardware::server::cisco::ucs::mode::components::localdisk; +package hardware::server::cisco::ucs::snmp::mode::components::localdisk; use strict; use warnings; -use hardware::server::cisco::ucs::mode::components::resources qw(%mapping_presence %mapping_operability); +use hardware::server::cisco::ucs::snmp::mode::components::resources qw(%mapping_presence %mapping_operability); # In MIB 'CISCO-UNIFIED-COMPUTING-STORAGE-MIB' my $mapping1 = { - cucsStorageLocalDiskPresence => { oid => '.1.3.6.1.4.1.9.9.719.1.45.4.1.10', map => \%mapping_presence }, + cucsStorageLocalDiskPresence => { oid => '.1.3.6.1.4.1.9.9.719.1.45.4.1.10', map => \%mapping_presence } }; my $mapping2 = { - cucsStorageLocalDiskOperability => { oid => '.1.3.6.1.4.1.9.9.719.1.45.4.1.9', map => \%mapping_operability }, + cucsStorageLocalDiskOperability => { oid => '.1.3.6.1.4.1.9.9.719.1.45.4.1.9', map => \%mapping_operability } }; my $oid_cucsStorageLocalDiskDn = '.1.3.6.1.4.1.9.9.719.1.45.4.1.2'; diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/memory.pm b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/memory.pm similarity index 95% rename from centreon-plugins/hardware/server/cisco/ucs/mode/components/memory.pm rename to centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/memory.pm index 315a88ea1..79bcb5dd8 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/memory.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/memory.pm @@ -18,11 +18,11 @@ # limitations under the License. # -package hardware::server::cisco::ucs::mode::components::memory; +package hardware::server::cisco::ucs::snmp::mode::components::memory; use strict; use warnings; -use hardware::server::cisco::ucs::mode::components::resources qw(%mapping_presence %mapping_operability); +use hardware::server::cisco::ucs::snmp::mode::components::resources qw(%mapping_presence %mapping_operability); # In MIB 'CISCO-UNIFIED-COMPUTING-MEMORY-MIB' my $mapping1 = { diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/psu.pm b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/psu.pm similarity index 95% rename from centreon-plugins/hardware/server/cisco/ucs/mode/components/psu.pm rename to centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/psu.pm index d331df1f8..d58695302 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/psu.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/psu.pm @@ -18,11 +18,11 @@ # limitations under the License. # -package hardware::server::cisco::ucs::mode::components::psu; +package hardware::server::cisco::ucs::snmp::mode::components::psu; use strict; use warnings; -use hardware::server::cisco::ucs::mode::components::resources qw(%mapping_presence %mapping_operability); +use hardware::server::cisco::ucs::snmp::mode::components::resources qw(%mapping_presence %mapping_operability); # In MIB 'CISCO-UNIFIED-COMPUTING-EQUIPMENT-MIB' my $mapping1 = { diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/resources.pm b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/resources.pm similarity index 94% rename from centreon-plugins/hardware/server/cisco/ucs/mode/components/resources.pm rename to centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/resources.pm index a8d1d057d..bb642eb87 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/resources.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/components/resources.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package hardware::server::cisco::ucs::mode::components::resources; +package hardware::server::cisco::ucs::snmp::mode::components::resources; use strict; use warnings; @@ -47,7 +47,7 @@ our @EXPORT_OK = qw($thresholds %mapping_presence %mapping_operability %mapping_ 10 => 'unconfiguredBad', 11 => 'predictiveFailure', 12 => 'disabledForRemoval', - 13 => 'foreignConfiguration', + 13 => 'foreignConfiguration' ); %mapping_presence = ( 0 => 'unknown', @@ -60,7 +60,7 @@ our @EXPORT_OK = qw($thresholds %mapping_presence %mapping_operability %mapping_ 21 => 'mismatchIdentityUnestablishable', 30 => 'inaccessible', 40 => 'unauthorized', - 100 => 'notSupported', + 100 => 'notSupported' ); %mapping_operability = ( 0 => 'unknown', @@ -90,7 +90,7 @@ our @EXPORT_OK = qw($thresholds %mapping_presence %mapping_operability %mapping_ 105 => 'upgradeProblem', 106 => 'peerCommProblem', 107 => 'autoUpgrade', - 108 => 'linkActivateBlocked', + 108 => 'linkActivateBlocked' ); %mapping_overall_status = ( 0 => 'indeterminate', @@ -122,7 +122,7 @@ our @EXPORT_OK = qw($thresholds %mapping_presence %mapping_operability %mapping_ 201 => 'bios-restore', 202 => 'cmos-reset', 203 => 'diagnostics', - 204 => 'diagnostic-failed', + 204 => 'diagnostic-failed' ); $thresholds = { @@ -140,7 +140,7 @@ $thresholds = { ['unconfiguredBad', 'CRITICAL'], ['predictiveFailure', 'WARNING'], ['disabledForRemoval', 'OK'], - ['foreignConfiguration', 'OK'], + ['foreignConfiguration', 'OK'], ], 'default.presence' => [ ['unknown', 'UNKNOWN'], @@ -153,7 +153,7 @@ $thresholds = { ['mismatchIdentityUnestablishable', 'WARNING'], ['inaccessible', 'UNKNOWN'], ['unauthorized', 'UNKNOWN'], - ['notSupported', 'WARNING'], + ['notSupported', 'WARNING'] ], 'default.operability' => [ ['unknown', 'UNKNOWN'], @@ -182,7 +182,7 @@ $thresholds = { ['postFailure', 'WARNING'], ['upgradeProblem', 'WARNING'], ['peerCommProblem', 'WARNING'], - ['autoUpgrade', 'OK'], + ['autoUpgrade', 'OK'] ], 'default.overall_status' => [ ['indeterminate', 'UNKNOWN'], @@ -214,8 +214,8 @@ $thresholds = { ['bios-restore', 'WARNING'], ['cmos-reset', 'WARNING'], ['diagnostics', 'OK'], - ['diagnostic-failed', 'WARNING'], - ], + ['diagnostic-failed', 'WARNING'] + ] }; 1; diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/equipment.pm b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/equipment.pm similarity index 84% rename from centreon-plugins/hardware/server/cisco/ucs/mode/equipment.pm rename to centreon-plugins/hardware/server/cisco/ucs/snmp/mode/equipment.pm index 7c6435f8f..ee36388e1 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/equipment.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/equipment.pm @@ -18,13 +18,13 @@ # limitations under the License. # -package hardware::server::cisco::ucs::mode::equipment; +package hardware::server::cisco::ucs::snmp::mode::equipment; use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -use hardware::server::cisco::ucs::mode::components::resources qw($thresholds); +use hardware::server::cisco::ucs::snmp::mode::components::resources qw($thresholds); sub set_system { my ($self, %options) = @_; @@ -33,7 +33,7 @@ sub set_system { $self->{thresholds} = $thresholds; - $self->{components_path} = 'hardware::server::cisco::ucs::mode::components'; + $self->{components_path} = 'hardware::server::cisco::ucs::snmp::mode::components'; $self->{components_module} = ['fan', 'psu', 'chassis', 'iocard', 'blade', 'fex', 'cpu', 'memory', 'localdisk']; } @@ -46,7 +46,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 => {}); @@ -88,7 +88,9 @@ If total (with skipped) is 0. (Default: 'critical' returns). Set to overload default threshold values (syntax: section,[instance,]status,regexp) It used before default thresholds (order stays). -Example: --threshold-overload='fan.operability,OK,poweredOff|removed' +Eg: --threshold-overload='fan.operability,OK,poweredOff|removed' +--threshold-overload='presence,OK,missing' +--threshold-overload='operability,OK,removed' =back diff --git a/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/faults.pm b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/faults.pm new file mode 100644 index 000000000..f1e4b9671 --- /dev/null +++ b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/faults.pm @@ -0,0 +1,240 @@ +# +# Copyright 2021 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::server::cisco::ucs::snmp::mode::faults; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::misc; +use centreon::plugins::statefile; +use POSIX; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); + +my $map_severity = { + 0 => 'cleared', 1 => 'info', 2 => 'condition', + 3 => 'warning', 4 => 'minor', 5 => 'major', + 6 => 'critical' +}; + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + 'fault [severity: %s] [dn: %s] [description: %s] %s', + $self->{result_values}->{severity}, + $self->{result_values}->{dn}, + $self->{result_values}->{description}, + scalar(localtime($self->{result_values}->{created})) + ); +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return 'Faults '; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', }, + { name => 'faults', type => 2, message_multiple => '0 problem(s) detected', display_counter_problem => { nlabel => 'faults.problems.current.count', min => 0 }, + group => [ { name => 'fault', skipped_code => { -11 => 1 } } ] + } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'faults-total', nlabel => 'faults.total.count', display_ok => 0, set => { + key_values => [ { name => 'total' } ], + output_template => 'total: %s', + perfdatas => [ + { template => '%s', min => 0 } + ] + } + } + ]; + + foreach (values %$map_severity) { + push @{$self->{maps_counters}->{global}}, + { label => 'faults-' . $_, nlabel => 'faults.' . $_ . '.count', display_ok => 0, set => { + key_values => [ { name => $_ }, { name => 'total' } ], + output_template => $_ . ': %s', + perfdatas => [ + { template => '%s', min => 0, max => 'total' } + ] + } + }; + } + + $self->{maps_counters}->{fault} = [ + { + label => 'status', + type => 2, + warning_default => '%{severity} =~ /minor|warning/', + critical_default => '%{severity} =~ /major|critical/', + set => { + key_values => [ + { name => 'dn' }, { name => 'severity' }, + { name => 'description' }, { name => 'created' } + ], + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold_ng + } + } + ]; +} + +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-message:s' => { name => 'filter_message' }, + 'retention:s' => { name => 'retention' }, + 'memory' => { name => 'memory' } + }); + + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->check_options(%options); + } +} + +sub get_timestamp { + my ($self, %options) = @_; + + my $currentTmsp = 0; + my $value = $options{value}; + if ($value =~ /^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/) { + $currentTmsp = mktime($6, $5, $4, $3, $2 - 1, $1 - 1900); + } else { + $value = unpack('H*', $value); + $value =~ /^([0-9a-z]{4})([0-9a-z]{2})([0-9a-z]{2})([0-9a-z]{2})([0-9a-z]{2})([0-9a-z]{2})/; + $currentTmsp = mktime(hex($6), hex($5), hex($4), hex($3), hex($2) - 1, hex($1) - 1900); + } + + return $currentTmsp; +} + +my $mapping = { + dn => { oid => '.1.3.6.1.4.1.9.9.719.1.1.1.1.2' }, # cucsFaultDn + created => { oid => '.1.3.6.1.4.1.9.9.719.1.1.1.1.10' }, # cucsFaultCreationTime + description => { oid => '.1.3.6.1.4.1.9.9.719.1.1.1.1.11' }, # cucsFaultDescription + severity => { oid => '.1.3.6.1.4.1.9.9.719.1.1.1.1.20', map => $map_severity } # cucsFaultSeverity +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $datas = {}; + my ($start, $last_instance); + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->read(statefile => 'cache_ciscoucs_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode}); + $start = $self->{statefile_cache}->get(name => 'start'); + $start = $start - 1 if (defined($start)); + } + + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ map({ oid => $_->{oid}, start => $_->{oid} . (defined($start) ? '.' . $start : '') }, values(%$mapping)) ], + return_type => 1 + ); + + $self->{global} = { + total => 0, cleared => 0, info => 0, condition => 0, + warning => 0, minor => 0, major => 0, critical => 0 + }; + $self->{faults} = { global => { fault => {} } }; + my ($i, $current_time) = (1, time()); + foreach my $oid ($options{snmp}->oid_lex_sort(keys %$snmp_result)) { + next if ($oid !~ /^$mapping->{dn}->{oid}\.(\d+)$/); + my $instance = $1; + if (defined($self->{option_results}->{memory})) { + $last_instance = $instance; + next if (defined($start) && ($start + 1) >= $instance); # we skip last one from previous check) + } + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + $result->{description} = centreon::plugins::misc::trim($result->{description}); + $result->{created} = $self->get_timestamp(value => $result->{created}); + if (defined($self->{option_results}->{retention})) { + next if ($current_time - $result->{created} > $self->{option_results}->{retention}); + } + + $self->{global}->{total}++; + next if (defined($self->{option_results}->{filter_message}) && $self->{option_results}->{filter_message} ne '' && $result->{description} !~ /$self->{option_results}->{filter_message}/); + + $self->{faults}->{global}->{fault}->{$i} = $result; + $self->{global}->{ $result->{severity} }++; + $i++; + } + + if (defined($self->{option_results}->{memory})) { + $datas->{start} = $last_instance; + $self->{statefile_cache}->write(data => $datas); + } +} + +1; + +__END__ + +=head1 MODE + +Check faults. + +=over 8 + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{severity} =~ /minor|warning/') +Can used special variables like: %{severity}, %{description}, %{dn} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{severity} =~ /major|critical/'). +Can used special variables like: %{severity}, %{description}, %{dn} + +=item B<--memory> + +Only check new fault. + +=item B<--filter-message> + +Filter on event message. (Default: none) + +=item B<--retention> + +Event older (current time - retention time) is not checked (in seconds). + +=back + +=cut diff --git a/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/mgmtentities.pm b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/mgmtentities.pm new file mode 100644 index 000000000..12bd72200 --- /dev/null +++ b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/mgmtentities.pm @@ -0,0 +1,173 @@ +# +# Copyright 2021 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::server::cisco::ucs::snmp::mode::mgmtentities; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + 'status: %s [role: %s][services status: %s]', + $self->{result_values}->{status}, + $self->{result_values}->{role}, + $self->{result_values}->{services_status} + ); +} + +sub prefix_mgmt_output { + my ($self, %options) = @_; + + return sprintf( + "Management entity '%s' ", + $options{instance_value}->{dn} + ); +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return 'Management entities '; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', cb_prefix_output => 'prefix_global_output', type => 0 }, + { name => 'mgmt', type => 1, cb_prefix_output => 'prefix_mgmt_output', message_multiple => 'All management entities are ok' } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total', nlabel => 'management_entities.total.count', display_ok => 0, set => { + key_values => [ { name => 'total' } ], + output_template => 'total: %s', + perfdatas => [ + { template => '%s', min => 0 } + ] + } + } + ]; + + $self->{maps_counters}->{mgmt} = [ + { + label => 'status', type => 2, + unknown_default => '%{role} =~ /unknown/ or %{status} eq "unknown" or %{services_status} eq "unknown"', + critical_default => '%{role} =~ /electionFailed|inapplicable/ or %{status} eq "down" or %{services_status} eq "down"', + set => { + key_values => [ + { name => 'dn' }, { name => 'role' }, + { name => 'services_status' }, { name => 'status' }, + ], + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold_ng + } + } + ]; +} + +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 $map_role = { + 0 => 'unknown', 1 => 'primary', + 2 => 'subordinate', 3 => 'inapplicable', + 4 => 'electionInProgress', 5 => 'electionFailed' +}; +my $map_state = { + 0 => 'unknown', 1 => 'up', 2 => 'down' +}; +my $map_services_state = { + 0 => 'unknown', 1 => 'up', 2 => 'unresponsive', 3 => 'down', 4 => 'switchoverInProgress' +}; + +my $mapping = { + dn => { oid => '.1.3.6.1.4.1.9.9.719.1.31.8.1.2' }, # cucsMgmtEntityDn + role => { oid => '.1.3.6.1.4.1.9.9.719.1.31.8.1.14', map => $map_role }, # cucsMgmtEntityLeadership + services_status => { oid => '.1.3.6.1.4.1.9.9.719.1.31.8.1.15', map => $map_services_state }, # cucsMgmtEntityMgmtServicesState + status => { oid => '.1.3.6.1.4.1.9.9.719.1.31.8.1.17', map => $map_state } # cucsMgmtEntityState +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ map({ oid => $_->{oid} }, values(%$mapping)) ], + return_type => 1, + nothing_quit => 1 + ); + + $self->{global} = { total => 0, online => 0, offline => 0 }; + $self->{mgmt} = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{dn}->{oid}\.(.*)$/); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $1); + $self->{mgmt}->{ $result->{dn} } = $result; + $self->{global}->{total}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check management entities. + +=over 8 + +=item B<--unknown-status> + +Set unknown threshold for status (Default: '%{role} =~ /unknown/ or %{status} eq "unknown" or %{services_status} eq "unknown"') +Can used special variables like: %{dn}, %{role}, %{services_status}, %{status} + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{dn}, %{role}, %{services_status}, %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{role} =~ /electionFailed|inapplicable/ or %{status} eq "down" or %{services_status} eq "down"'). +Can used special variables like: %{dn}, %{role}, %{services_status}, %{status} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'total'. + +=back + +=cut diff --git a/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/serviceprofile.pm b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/serviceprofile.pm new file mode 100644 index 000000000..fcf2643e7 --- /dev/null +++ b/centreon-plugins/hardware/server/cisco/ucs/snmp/mode/serviceprofile.pm @@ -0,0 +1,169 @@ +# +# Copyright 2021 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::server::cisco::ucs::snmp::mode::serviceprofile; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + 'status: %s', + $self->{result_values}->{status} + ); +} + +sub prefix_sp_output { + my ($self, %options) = @_; + + return sprintf( + "Service profile '%s' ", + $options{instance_value}->{dn} + ); +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return 'Service profiles '; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', cb_prefix_output => 'prefix_global_output', type => 0 }, + { name => 'sp', type => 1, cb_prefix_output => 'prefix_sp_output', message_multiple => 'All service profiles are ok' } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total', nlabel => 'serviceprofiles.total.count', display_ok => 0, set => { + key_values => [ { name => 'total' } ], + output_template => 'total: %s', + perfdatas => [ + { template => '%s', min => 0 } + ] + } + }, + { label => 'online', nlabel => 'serviceprofiles.online.count', display_ok => 0, set => { + key_values => [ { name => 'online' }, { name => 'total' } ], + output_template => 'online: %s', + perfdatas => [ + { template => '%s', min => 0, max => 'total' } + ] + } + }, + { label => 'offline', nlabel => 'serviceprofiles.offline.count', display_ok => 0, set => { + key_values => [ { name => 'offline' }, { name => 'total' } ], + output_template => 'offline: %s', + perfdatas => [ + { template => '%s', min => 0, max => 'total' } + ] + } + } + ]; + + $self->{maps_counters}->{sp} = [ + { + label => 'status', type => 2, critical_default => '%{status} eq "offline"', + set => { + key_values => [ { name => 'dn' }, { name => 'status' } ], + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold_ng + } + } + ]; +} + +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 $map_status = { + 1 => 'online', + 2 => 'offline' +}; + +my $mapping = { + dn => { oid => '.1.3.6.1.4.1.9.9.719.1.26.2.1.2' }, # cucsLsBindingDn + status => { oid => '.1.3.6.1.4.1.9.9.719.1.26.2.1.10', map => $map_status } # cucsLsBindingOperState +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ map({ oid => $_->{oid} }, values(%$mapping)) ], + return_type => 1, + nothing_quit => 1 + ); + + $self->{global} = { total => 0, online => 0, offline => 0 }; + $self->{sp} = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{dn}->{oid}\.(.*)$/); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $1); + $self->{sp}->{ $result->{dn} } = $result; + $self->{global}->{ $result->{status} }++; + $self->{global}->{total}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check service profiles. + +=over 8 + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{dn}, %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} eq "offline"'). +Can used special variables like: %{dn}, %{status} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'total', 'online', 'offline'. + +=back + +=cut diff --git a/centreon-plugins/hardware/server/cisco/ucs/plugin.pm b/centreon-plugins/hardware/server/cisco/ucs/snmp/plugin.pm similarity index 68% rename from centreon-plugins/hardware/server/cisco/ucs/plugin.pm rename to centreon-plugins/hardware/server/cisco/ucs/snmp/plugin.pm index 636f840b4..4d313e1bd 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/plugin.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/snmp/plugin.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package hardware::server::cisco::ucs::plugin; +package hardware::server::cisco::ucs::snmp::plugin; use strict; use warnings; @@ -30,12 +30,13 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - %{$self->{modes}} = ( - 'equipment' => 'hardware::server::cisco::ucs::mode::equipment', - 'faults' => 'hardware::server::cisco::ucs::mode::faults', - 'audit-logs' => 'hardware::server::cisco::ucs::mode::auditlogs', - 'service-profile' => 'hardware::server::cisco::ucs::mode::serviceprofile', - ); + $self->{modes} = { + 'audit-logs' => 'hardware::server::cisco::ucs::snmp::mode::auditlogs', + 'equipment' => 'hardware::server::cisco::ucs::snmp::mode::equipment', + 'faults' => 'hardware::server::cisco::ucs::snmp::mode::faults', + 'mgmt-entities' => 'hardware::server::cisco::ucs::snmp::mode::mgmtentities', + 'service-profile' => 'hardware::server::cisco::ucs::snmp::mode::serviceprofile' + }; return $self; } diff --git a/centreon-plugins/network/brocade/snmp/mode/interfaces.pm b/centreon-plugins/network/brocade/snmp/mode/interfaces.pm index 677b10656..c07304027 100644 --- a/centreon-plugins/network/brocade/snmp/mode/interfaces.pm +++ b/centreon-plugins/network/brocade/snmp/mode/interfaces.pm @@ -294,12 +294,12 @@ Check interface optical. =item B<--warning-status> Set warning threshold for status. -Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{errdisable}, %{display} +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}, %{errdisable}, %{display} +Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display} =item B<--warning-*> B<--critical-*>