Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chapsvision): Update OIDs #5413

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 41 additions & 18 deletions src/network/chapsvision/crossing/snmp/mode/antivirus.pm
Original file line number Diff line number Diff line change
Expand Up @@ -172,56 +172,79 @@ sub check_options {
}

my $mapping = {
antivirus1 => {
name => '.1.3.6.1.4.1.50853.1.2.6.1.1',
version => '.1.3.6.1.4.1.50853.1.2.6.1.2',
date => '.1.3.6.1.4.1.50853.1.2.6.1.3',
expiration => '.1.3.6.1.4.1.50853.1.2.6.1.4'
new => {
antivirus1 => {
name => '.1.3.6.1.4.1.50853.1.2.6.1.1.0',
version => '.1.3.6.1.4.1.50853.1.2.6.1.2.0',
date => '.1.3.6.1.4.1.50853.1.2.6.1.3.0',
expiration => '.1.3.6.1.4.1.50853.1.2.6.1.4.0'
},

antivirus2 => {
name => '.1.3.6.1.4.1.50853.1.2.6.2.1.0',
version => '.1.3.6.1.4.1.50853.1.2.6.2.2.0',
date => '.1.3.6.1.4.1.50853.1.2.6.2.3.0',
expiration => '.1.3.6.1.4.1.50853.1.2.6.2.4.0'
}
},
antivirus2 => {
name => '.1.3.6.1.4.1.50853.1.2.6.2.1',
version => '.1.3.6.1.4.1.50853.1.2.6.2.2',
date => '.1.3.6.1.4.1.50853.1.2.6.2.3',
expiration => '.1.3.6.1.4.1.50853.1.2.6.2.4'

old => {
antivirus1 => {
name => '.1.3.6.1.4.1.50853.1.2.6.1.1',
version => '.1.3.6.1.4.1.50853.1.2.6.1.2',
date => '.1.3.6.1.4.1.50853.1.2.6.1.3',
expiration => '.1.3.6.1.4.1.50853.1.2.6.1.4'
},

antivirus2 => {
name => '.1.3.6.1.4.1.50853.1.2.6.2.1',
version => '.1.3.6.1.4.1.50853.1.2.6.2.2',
date => '.1.3.6.1.4.1.50853.1.2.6.2.3',
expiration => '.1.3.6.1.4.1.50853.1.2.6.2.4'
}
}
};

sub add_antivirus {
my ($self, %options) = @_;

my $name = $options{snmp_result}->{ $mapping->{ $options{label} }->{name} };
my $crossing_version = defined($options{snmp_result}->{ $mapping->{new}->{ $options{label} }->{name} }) ? 'new' : 'old';
my $name = $options{snmp_result}->{ $mapping->{$crossing_version}->{ $options{label} }->{name} };
$self->{antivirus}->{$name} = {
name => $name,
version => $options{snmp_result}->{ $mapping->{ $options{label} }->{version} }
version => $options{snmp_result}->{ $mapping->{$crossing_version}->{ $options{label} }->{version} }
};

if ($options{snmp_result}->{ $mapping->{ $options{label} }->{expiration} } =~ /permanent/i) {
if ($options{snmp_result}->{ $mapping->{$crossing_version}->{ $options{label} }->{expiration} } =~ /permanent/i) {
$self->{antivirus}->{$name}->{expires_seconds} = 'permanent';
$self->{antivirus}->{$name}->{expires_human} = '-';
} else {
my $dt = $self->{ $options{label} . '_strp' }->parse_datetime($options{snmp_result}->{ $mapping->{ $options{label} }->{expiration} });
my $dt = $self->{ $options{label} . '_strp' }->parse_datetime($options{snmp_result}->{ $mapping->{$crossing_version}->{ $options{label} }->{expiration} });
if (defined($dt)) {
$self->{antivirus}->{$name}->{expires_seconds} = $dt->epoch() - time();
$self->{antivirus}->{$name}->{expires_seconds} = 0 if ($self->{antivirus}->{$name}->{expires_seconds} < 0);
$self->{antivirus}->{$name}->{expires_human} = centreon::plugins::misc::change_seconds(value => $self->{antivirus}->{$name}->{expires_seconds});
} else {
$self->{output}->output_add(long_msg => "cannot parse date: " . $options{snmp_result}->{ $mapping->{ $options{label} }->{expiration} } . ' (please use option --' . $options{label} . '-date-format)');
$self->{output}->output_add(long_msg => "cannot parse date: " . $options{snmp_result}->{ $mapping->{$crossing_version}->{ $options{label} }->{expiration} } . ' (please use option --' . $options{label} . '-date-format)');
}
}

my $dt = $self->{ $options{label} . '_strp' }->parse_datetime($options{snmp_result}->{ $mapping->{ $options{label} }->{date} });
my $dt = $self->{ $options{label} . '_strp' }->parse_datetime($options{snmp_result}->{ $mapping->{$crossing_version}->{ $options{label} }->{date} });
if (defined($dt)) {
$self->{antivirus}->{$name}->{db_lastupdate_time} = time() - $dt->epoch();
} else {
$self->{output}->output_add(long_msg => "cannot parse date: " . $options{snmp_result}->{ $mapping->{ $options{label} }->{date} } . ' (please use option --' . $options{label} . '-date-format)');
$self->{output}->output_add(long_msg => "cannot parse date: " . $options{snmp_result}->{ $mapping->{$crossing_version}->{ $options{label} }->{date} } . ' (please use option --' . $options{label} . '-date-format)');
}
}

sub manage_selection {
my ($self, %options) = @_;

my $snmp_result = $options{snmp}->get_leef(
oids => [ map($_, values(%{$mapping->{antivirus1}}), values(%{$mapping->{antivirus2}})) ],
oids => [
map($_, values(%{$mapping->{new}->{antivirus1}}), values(%{$mapping->{new}->{antivirus2}})),
map($_, values(%{$mapping->{old}->{antivirus1}}), values(%{$mapping->{old}->{antivirus2}}))
],
nothing_quit => 1
);

Expand Down
36 changes: 36 additions & 0 deletions tests/network/chapsvision/crossing/snmp/antivirus.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
*** Settings ***
Documentation Check Chapsvision antivirus
Resource ${CURDIR}${/}..${/}..${/}..${/}..${/}resources/import.resource

Test Timeout 120s


*** Variables ***
${CMD} ${CENTREON_PLUGINS} --plugin=network::chapsvision::crossing::snmp::plugin


*** Test Cases ***
Antivirus ${tc}
[Tags] os linux
${command} Catenate
... ${CMD}
... --mode=antivirus
... --hostname=${HOSTNAME}
... --snmp-version=${SNMPVERSION}
... --snmp-port=${SNMPPORT}
... --snmp-community=network/chapsvision/crossing/snmp/chapsvision
... --snmp-timeout=1
... ${extra_options}

${output} Run ${command}
${output} Strip String ${output}
Should Match Regexp ${output} ${expected_result}

Examples: tc extra_options expected_result --
... 1 ${empty} OK: All antivirus are ok \\\\| 'antivirus.database.lastupdate.seconds'=\\\\d+s;;;0; 'Anonymized 008#antivirus.license.expires.seconds'=\\\\d+s;;;0; 'antivirus.database.lastupdate.seconds'=\\\\d+s;;;0; 'Anonymized 106#antivirus.license.expires.seconds'=\\\\d+s;;;0;
... 2 --warning-version='1' WARNING: antivirus 'Anonymized 008' version: 27031 - antivirus 'Anonymized 106' version: 26868 \\\\| 'antivirus.database.lastupdate.seconds'=\\\\d+s;;;0; 'Anonymized 008#antivirus.license.expires.seconds'=\\\\d+s;;;0; 'antivirus.database.lastupdate.seconds'=\\\\d+s;;;0; 'Anonymized 106#antivirus.license.expires.seconds'=\\\\d+s;;;0;
... 3 --critical-version='2' CRITICAL: antivirus 'Anonymized 008' version: 27031 - antivirus 'Anonymized 106' version: 26868 \\\\| 'antivirus.database.lastupdate.seconds'=\\\\d+s;;;0; 'Anonymized 008#antivirus.license.expires.seconds'=\\\\d+s;;;0; 'antivirus.database.lastupdate.seconds'=\\\\d+s;;;0; 'Anonymized 106#antivirus.license.expires.seconds'=\\\\d+s;;;0;
... 4 --warning-license-expires='1' WARNING: antivirus 'Anonymized 008' license expires in \\\\d+y \\\\d+M \\\\d+d \\\\d+h \\\\d+m \\\\d+s - antivirus 'Anonymized 106' license expires in \\\\d+y \\\\d+M \\\\d+d \\\\d+h \\\\d+m \\\\d+s \\\\| 'antivirus.database.lastupdate.seconds'=\\\\d+s;;;0; 'Anonymized 008#antivirus.license.expires.seconds'=\\\\d+s;0:1;;0; 'antivirus.database.lastupdate.seconds'=\\\\d+s;;;0; 'Anonymized 106#antivirus.license.expires.seconds'=\\\\d+s;0:1;;0;
... 5 --critical-license-expires='1' CRITICAL: antivirus 'Anonymized 008' license expires in \\\\d+y \\\\d+M \\\\d+d \\\\d+h \\\\d+m \\\\d+s - antivirus 'Anonymized 106' license expires in \\\\d+y \\\\d+M \\\\d+d \\\\d+h \\\\d+m \\\\d+s \\\\| 'antivirus.database.lastupdate.seconds'=\\\\d+s;;;0; 'Anonymized 008#antivirus.license.expires.seconds'=\\\\d+s;;0:1;0; 'antivirus.database.lastupdate.seconds'=\\\\d+s;;;0; 'Anonymized 106#antivirus.license.expires.seconds'=\\\\d+s;;0:1;0;
... 6 --warning-database-last-update='1' WARNING: antivirus 'Anonymized 008' database last update \\\\d+w \\\\d+d \\\\d+h \\\\d+m \\\\d+s - antivirus 'Anonymized 106' database last update \\\\d+w \\\\d+d \\\\d+h \\\\d+m \\\\d+s \\\\| 'antivirus.database.lastupdate.seconds'=\\\\d+s;0:1;;0; 'Anonymized 008#antivirus.license.expires.seconds'=\\\\d+s;;;0; 'antivirus.database.lastupdate.seconds'=\\\\d+s;0:1;;0; 'Anonymized 106#antivirus.license.expires.seconds'=\\\\d+s;;;0;
... 7 --critical-database-last-update='1' CRITICAL: antivirus 'Anonymized 008' database last update \\\\d+w \\\\d+d \\\\d+h \\\\d+m \\\\d+s - antivirus 'Anonymized 106' database last update \\\\d+w \\\\d+d \\\\d+h \\\\d+m \\\\d+s \\\\| 'antivirus.database.lastupdate.seconds'=\\\\d+s;;0:1;0; 'Anonymized 008#antivirus.license.expires.seconds'=\\\\d+s;;;0; 'antivirus.database.lastupdate.seconds'=\\\\d+s;;0:1;0; 'Anonymized 106#antivirus.license.expires.seconds'=\\\\d+s;;;0;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.1.3.6.1.4.1.50853.1.2.6.1.1.0 = STRING: Anonymized 106
.1.3.6.1.4.1.50853.1.2.6.1.2.0 = STRING: "26868"
.1.3.6.1.4.1.50853.1.2.6.1.3.0 = STRING: 2025/01/01
.1.3.6.1.4.1.50853.1.2.6.1.4.0 = STRING: 2030/01/01
.1.3.6.1.4.1.50853.1.2.6.2.1.0 = STRING: Anonymized 008
.1.3.6.1.4.1.50853.1.2.6.2.2.0 = STRING: "27031"
.1.3.6.1.4.1.50853.1.2.6.2.3.0 = STRING: 2025/01/01
.1.3.6.1.4.1.50853.1.2.6.2.4.0 = STRING: 2030/01/01

Loading