diff --git a/src/network/chapsvision/crossing/snmp/mode/antivirus.pm b/src/network/chapsvision/crossing/snmp/mode/antivirus.pm index e137914d4..6b622ace6 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 $antivirus_mapping = defined($options{snmp_result}->{ $mapping->{new}->{ $options{label} }->{name} }) ? $mapping->{new}->{ $options{label} } : $mapping->{old}->{ $options{label} }; + my $name = $options{snmp_result}->{ $antivirus_mapping->{name} }; $self->{antivirus}->{$name} = { name => $name, - version => $options{snmp_result}->{ $mapping->{ $options{label} }->{version} } + version => $options{snmp_result}->{ $antivirus_mapping->{version} } }; - if ($options{snmp_result}->{ $mapping->{ $options{label} }->{expiration} } =~ /permanent/i) { + if ($options{snmp_result}->{ $antivirus_mapping->{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}->{ $antivirus_mapping->{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}->{ $antivirus_mapping->{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}->{ $antivirus_mapping->{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}->{ $antivirus_mapping->{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 ); diff --git a/tests/network/chapsvision/crossing/snmp/antivirus.robot b/tests/network/chapsvision/crossing/snmp/antivirus.robot new file mode 100644 index 000000000..f3a59c6cf --- /dev/null +++ b/tests/network/chapsvision/crossing/snmp/antivirus.robot @@ -0,0 +1,60 @@ +*** Settings *** +Documentation Check Chapsvision antivirus +Resource ${CURDIR}${/}..${/}..${/}..${/}..${/}resources/import.resource + +Test Timeout 120s + + +*** Variables *** +${cmd} ${CENTREON_PLUGINS} +... --plugin=network::chapsvision::crossing::snmp::plugin +... --mode=antivirus +... --hostname=${HOSTNAME} +... --snmp-version=${SNMPVERSION} +... --snmp-port=${SNMPPORT} +... --snmp-timeout=1 + + +*** Test Cases *** +Antivirus new ${tc} + [Documentation] Check the antivirus with the new OIDs + [Tags] network chapvision crossing + ${command} Catenate + ... ${cmd} + ... --snmp-community=network/chapsvision/crossing/snmp/chapsvision + ... ${extra_options} + + + Ctn Run Command And Check Result As Regexp ${command} ${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 [\\\\dyMwdms ]*- antivirus 'Anonymized 106' license expires in [\\\\dyMwdms ]*| '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 [\\\\dyMwdms ]*- antivirus 'Anonymized 106' license expires in [\\\\dyMwdms ]*| '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 [\\\\dyMwdms ]*- antivirus 'Anonymized 106' database last update [\\\\dyMwdms ]*| '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 [\\\\dyMwdms ]*- antivirus 'Anonymized 106' database last update [\\\\dyMwdms ]*| '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; + + +Antivirus old ${tc} + [Documentation] Check the antivirus with the old OIDs + [Tags] network chapvision crossing + ${command} Catenate + ... ${cmd} + ... --snmp-community=network/chapsvision/crossing/snmp/chapsvision_old_oids + ... ${extra_options} + + + Ctn Run Command And Check Result As Regexp ${command} ${expected_result} + + Examples: tc extra_options expected_result -- + ... 1 ${empty} OK: All antivirus are ok | 'antivirus.database.lastupdate.seconds'=\\\\d+s;;;0; 'Anonymized 008-old#antivirus.license.expires.seconds'=\\\\d+s;;;0; 'antivirus.database.lastupdate.seconds'=\\\\d+s;;;0; 'Anonymized 106-old#antivirus.license.expires.seconds'=\\\\d+s;;;0; + ... 2 --warning-version='1' WARNING: antivirus 'Anonymized 008-old' version: 27031 - antivirus 'Anonymized 106-old' version: 26868 | 'antivirus.database.lastupdate.seconds'=\\\\d+s;;;0; 'Anonymized 008-old#antivirus.license.expires.seconds'=\\\\d+s;;;0; 'antivirus.database.lastupdate.seconds'=\\\\d+s;;;0; 'Anonymized 106-old#antivirus.license.expires.seconds'=\\\\d+s;;;0; + ... 3 --critical-version='2' CRITICAL: antivirus 'Anonymized 008-old' version: 27031 - antivirus 'Anonymized 106-old' version: 26868 | 'antivirus.database.lastupdate.seconds'=\\\\d+s;;;0; 'Anonymized 008-old#antivirus.license.expires.seconds'=\\\\d+s;;;0; 'antivirus.database.lastupdate.seconds'=\\\\d+s;;;0; 'Anonymized 106-old#antivirus.license.expires.seconds'=\\\\d+s;;;0; + ... 4 --warning-license-expires='1' WARNING: antivirus 'Anonymized 008-old' license expires in [\\\\dyMwdms ]* - antivirus 'Anonymized 106-old' license expires in [\\\\dyMwdms ]*| 'antivirus.database.lastupdate.seconds'=\\\\d+s;;;0; 'Anonymized 008-old#antivirus.license.expires.seconds'=\\\\d+s;0:1;;0; 'antivirus.database.lastupdate.seconds'=\\\\d+s;;;0; 'Anonymized 106-old#antivirus.license.expires.seconds'=\\\\d+s;0:1;;0; + ... 5 --critical-license-expires='1' CRITICAL: antivirus 'Anonymized 008-old' license expires in [\\\\dyMwdms ]* - antivirus 'Anonymized 106-old' license expires in [\\\\dyMwdms ]*| 'antivirus.database.lastupdate.seconds'=\\\\d+s;;;0; 'Anonymized 008-old#antivirus.license.expires.seconds'=\\\\d+s;;0:1;0; 'antivirus.database.lastupdate.seconds'=\\\\d+s;;;0; 'Anonymized 106-old#antivirus.license.expires.seconds'=\\\\d+s;;0:1;0; + ... 6 --warning-database-last-update='1' WARNING: antivirus 'Anonymized 008-old' database last update [\\\\dyMwdms ]*- antivirus 'Anonymized 106-old' database last update [\\\\dyMwdms ]*| 'antivirus.database.lastupdate.seconds'=\\\\d+s;0:1;;0; 'Anonymized 008-old#antivirus.license.expires.seconds'=\\\\d+s;;;0; 'antivirus.database.lastupdate.seconds'=\\\\d+s;0:1;;0; 'Anonymized 106-old#antivirus.license.expires.seconds'=\\\\d+s;;;0; + ... 7 --critical-database-last-update='1' CRITICAL: antivirus 'Anonymized 008-old' database last update [\\\\dyMwdms ]*- antivirus 'Anonymized 106-old' database last update [\\\\dyMwdms ]*| 'antivirus.database.lastupdate.seconds'=\\\\d+s;;0:1;0; 'Anonymized 008-old#antivirus.license.expires.seconds'=\\\\d+s;;;0; 'antivirus.database.lastupdate.seconds'=\\\\d+s;;0:1;0; 'Anonymized 106-old#antivirus.license.expires.seconds'=\\\\d+s;;;0; + + diff --git a/tests/network/chapsvision/crossing/snmp/chapsvision.snmpwalk b/tests/network/chapsvision/crossing/snmp/chapsvision.snmpwalk new file mode 100644 index 000000000..da0973a1e --- /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 + diff --git a/tests/network/chapsvision/crossing/snmp/chapsvision_old_oids.snmpwalk b/tests/network/chapsvision/crossing/snmp/chapsvision_old_oids.snmpwalk new file mode 100644 index 000000000..091f0c033 --- /dev/null +++ b/tests/network/chapsvision/crossing/snmp/chapsvision_old_oids.snmpwalk @@ -0,0 +1,9 @@ +.1.3.6.1.4.1.50853.1.2.6.1.1 = STRING: Anonymized 106-old +.1.3.6.1.4.1.50853.1.2.6.1.2 = STRING: "26868" +.1.3.6.1.4.1.50853.1.2.6.1.3 = STRING: 2025/01/01 +.1.3.6.1.4.1.50853.1.2.6.1.4 = STRING: 2030/01/01 +.1.3.6.1.4.1.50853.1.2.6.2.1 = STRING: Anonymized 008-old +.1.3.6.1.4.1.50853.1.2.6.2.2 = STRING: "27031" +.1.3.6.1.4.1.50853.1.2.6.2.3 = STRING: 2025/01/01 +.1.3.6.1.4.1.50853.1.2.6.2.4 = STRING: 2030/01/01 +