This commit is contained in:
Quentin Garnier 2014-08-04 15:13:01 +02:00
parent 9623619901
commit 528efcadc1
2 changed files with 237 additions and 2 deletions

View File

@ -0,0 +1,234 @@
################################################################################
# Copyright 2005-2013 MERETHIS
# Centreon is developped by : Julien Mathis and Romain Le Merlus under
# GPL Licence 2.0.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation ; either version 2 of the License.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, see <http://www.gnu.org/licenses>.
#
# Linking this program statically or dynamically with other modules is making a
# combined work based on this program. Thus, the terms and conditions of the GNU
# General Public License cover the whole combination.
#
# As a special exception, the copyright holders of this program give MERETHIS
# permission to link this program with independent modules to produce an executable,
# regardless of the license terms of these independent modules, and to copy and
# distribute the resulting executable under terms of MERETHIS choice, provided that
# MERETHIS also meet, for each linked independent module, the terms and conditions
# of the license of that module. An independent module is a module which is not
# derived from this program. If you modify this program, you may extend this
# exception to your version of the program, but you are not obliged to do so. If you
# do not wish to do so, delete this exception statement from your version.
#
# For more information : contact@centreon.com
# Authors : Quentin Garnier <qgarnier@merethis.com>
#
####################################################################################
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;
$self->{version} = '1.0';
$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) = @_;
# $options{snmp} = snmp object
$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

View File

@ -47,8 +47,9 @@ sub new {
$self->{version} = '1.0';
%{$self->{modes}} = (
'equipment' => 'hardware::server::cisco::ucs::mode::equipment',
'faults' => 'hardware::server::cisco::ucs::mode::faults',
'equipment' => 'hardware::server::cisco::ucs::mode::equipment',
'faults' => 'hardware::server::cisco::ucs::mode::faults',
'audit-logs' => 'hardware::server::cisco::ucs::mode::auditlogs',
);
return $self;