diff --git a/Changes b/Changes index 469dc6cdd..7b0875cd1 100644 --- a/Changes +++ b/Changes @@ -40,6 +40,7 @@ netdiscovery/netinventory: * fix #769: Added Intelbras devices support * don't send discovery xml to server target for remoteinventory task event initiated from toolbox +* fix #781: Filter invalid firmware date on HP peripherals deploy: * Fix checks on command run and clarify reason of success or failure. This fixes diff --git a/lib/GLPI/Agent/SNMP/Device.pm b/lib/GLPI/Agent/SNMP/Device.pm index 33b6075b9..4799baf00 100644 --- a/lib/GLPI/Agent/SNMP/Device.pm +++ b/lib/GLPI/Agent/SNMP/Device.pm @@ -144,7 +144,7 @@ sub getFirmwareDateByMibSupport { return unless $self->{MIBSUPPORT}; - return $self->{MIBSUPPORT}->getMethod('getFirmwareDate'); + return getCanonicalDate($self->{MIBSUPPORT}->getMethod('getFirmwareDate')); } sub getMacAddressByMibSupport { @@ -333,7 +333,7 @@ sub setFirmware { NAME => $self->{MODEL} || 'device', DESCRIPTION => 'device firmware', TYPE => 'device', - DATE => $self->getFirmwareDateByMibSupport(), + DATE => $self->getFirmwareDateByMibSupport() // undef, VERSION => $self->{FIRMWARE}, MANUFACTURER => $self->{MANUFACTURER} }); diff --git a/lib/GLPI/Agent/Tools/SNMP.pm b/lib/GLPI/Agent/Tools/SNMP.pm index b074aff09..7955abb37 100644 --- a/lib/GLPI/Agent/Tools/SNMP.pm +++ b/lib/GLPI/Agent/Tools/SNMP.pm @@ -15,6 +15,7 @@ our @EXPORT = qw( getCanonicalConstant getCanonicalMemory getCanonicalCount + getCanonicalDate isInteger getRegexpOidMatch ); @@ -150,6 +151,63 @@ sub getRegexpOidMatch { return qr/^$match/; } +my %M = qw(Jan 1 Feb 2 Mar 3 Apr 4 May 5 Jun 6 Jul 7 Aug 8 Sep 9 Oct 10 Nov 11 Dec 12); +my $months = join('|', keys(%M)); +my $days = "Mon|Tue|Wed|Thu|Fri|Sat|Sun"; +my $first = join("|", map { "0?$_" } 1..9); +my $month = join("|", $first, 10..12); +my $month2 = join("|", map { sprintf("%02d", $_) } 1..12); +my $day = join("|", $first, 10..31); +my $day2 = join("|", map { sprintf("%02d", $_) } 1..31); +my $hour = join("|", map { sprintf("%02d", $_) } 0..23); +my $min = join("|", map { sprintf("%02d", $_) } 0..59); +my $sec = $min; +my $year = "[1-9][0-9]{3}"; + +# Return date if possible +sub getCanonicalDate { + my ($value) = @_; + + return if empty($value); + + # Match on 'D M d H:i:s Y' + if ($value =~ /^(?:$days) ($months) +($day) (?:$hour):(?:$min):(?:$sec) .*($year)$/) { + return sprintf("%4d-%02d-%02d", $3, $M{$1}, $2); + } + + # Match 'D M d, Y H:i:s' as in "Wed Aug 01, 2012 05:50:43PM" + if ($value =~ /^(?:$days) ($months) +($day), ($year) /) { + return sprintf("%4d-%02d-%02d", $3, $M{$1}, $2); + } + + # Match on 'Y-m-d\TH:i:sZ' and others with same prefix + if ($value =~ /^($year)-($month)-($day)/) { + return sprintf("%4d-%02d-%02d", $1, $2, $3); + } + + # Match on 'd/m/Y H:i:s' and others + if ($value =~ m{^($day)/($month)/($year)} ) { + return sprintf("%4d-%02d-%02d", $3, $2, $1); + } + + # Match on 'm/d/Y' + if ($value =~ m{^($month)/($day)/($year)} ) { + return sprintf("%4d-%02d-%02d", $3, $1, $2); + } + + # Match on 'd.m.Y' + if ($value =~ /^($day)\.($month)\.($year)/ ) { + return sprintf("%4d-%02d-%02d", $3, $2, $1); + } + + # Match on 'Ymd' + if ($value =~ /^($year)($month2)($day2)$/ ) { + return sprintf("%4d-%02d-%02d", $1, $2, $3); + } + + return; +} + 1; __END__