From 3f28cd25dc736364fcd5dd4201f69184188c9b35 Mon Sep 17 00:00:00 2001 From: itoussies Date: Mon, 27 Jan 2025 17:45:56 +0100 Subject: [PATCH 1/2] fix(chapsvision): update OIDs Refs:MON-156386 --- .../crossing/snmp/mode/antivirus.pm | 59 +++++++++++++------ 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/src/network/chapsvision/crossing/snmp/mode/antivirus.pm b/src/network/chapsvision/crossing/snmp/mode/antivirus.pm index e137914d4e..6ee5e11b80 100644 --- a/src/network/chapsvision/crossing/snmp/mode/antivirus.pm +++ b/src/network/chapsvision/crossing/snmp/mode/antivirus.pm @@ -172,48 +172,68 @@ 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)'); } } @@ -221,7 +241,10 @@ 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 ); From eacfa319f0a4e6365a7d377f93b7db89622f843e Mon Sep 17 00:00:00 2001 From: itoussies Date: Mon, 27 Jan 2025 17:47:04 +0100 Subject: [PATCH 2/2] test(chapsvision): add antivirus test Refs:MON-156386 --- .../chapsvision/crossing/snmp/antivirus.robot | 36 +++++++++++++++++++ .../crossing/snmp/chapsvision.snmpwalk | 9 +++++ 2 files changed, 45 insertions(+) create mode 100644 tests/network/chapsvision/crossing/snmp/antivirus.robot create mode 100644 tests/network/chapsvision/crossing/snmp/chapsvision.snmpwalk diff --git a/tests/network/chapsvision/crossing/snmp/antivirus.robot b/tests/network/chapsvision/crossing/snmp/antivirus.robot new file mode 100644 index 0000000000..ef3f6e29d2 --- /dev/null +++ b/tests/network/chapsvision/crossing/snmp/antivirus.robot @@ -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; \ No newline at end of file diff --git a/tests/network/chapsvision/crossing/snmp/chapsvision.snmpwalk b/tests/network/chapsvision/crossing/snmp/chapsvision.snmpwalk new file mode 100644 index 0000000000..da0973a1e8 --- /dev/null +++ b/tests/network/chapsvision/crossing/snmp/chapsvision.snmpwalk @@ -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 +