diff --git a/lib/SNMP/Info/Layer2/Ubiquiti.pm b/lib/SNMP/Info/Layer2/Ubiquiti.pm index a2ff2fe0..4acd6ef5 100644 --- a/lib/SNMP/Info/Layer2/Ubiquiti.pm +++ b/lib/SNMP/Info/Layer2/Ubiquiti.pm @@ -70,14 +70,14 @@ sub os { my $prod = $names->{$iid}; next unless defined $prod; # Product names that match AirOS products - if((lc $prod) =~ /station/ or (lc $prod) =~ /beam/ or (lc $prod) =~ /grid/){ - return 'AirOS'; - # Product names that match UAP - }elsif((lc $prod) =~ /uap/){ - return 'UniFi'; - }else{ - # Continue below to find OS name - } + if((lc $prod) =~ /station/ or (lc $prod) =~ /beam/ or (lc $prod) =~ /grid/){ + return 'AirOS'; + # Product names that match UAP + }elsif((lc $prod) =~ /uap/){ + return 'UniFi'; + }else{ + # Continue below to find OS name + } } ## EdgeMAX OS (EdgeSwitch and EdgeRouter) name is first field split by space @@ -89,31 +89,50 @@ sub os { } sub os_ver { - my $dot11 = shift; + my $ubnt = shift; - my $versions = $dot11->dot11_prod_ver(); + my $versions = $ubnt->dot11_prod_ver(); foreach my $iid ( keys %$versions ) { my $ver = $versions->{$iid}; next unless defined $ver; + my $os = $ubnt->os; + if($os == 'AirOS'){ + ## pretty up the version reporting for AirOS to include hardware (XW, XM, etc) and three major groups of firmware + my @firmware = split(/v/, $ver); + my @firmwareSplit = split(/\./, $firmware[1]); + my @prefix = split(/\./, $ver); + $ver = $prefix[0] . '-v' . join('.', @firmwareSplit[0,1,2]); + } return $ver; ## Not sure what this function does, it seems to be extraneous being in the same code block after a return statement? - if ( $ver =~ /([\d\.]+)/ ) { - return $1; - } + #if ( $ver =~ /([\d\.]+)/ ) { + # return $1; + #} } - my $ver = $dot11->description() || ''; - if($ver =~ /^edgeswitch/){ - ## EdgeSwitch OS version is second field split by comma - my @myver = split(/, /, $ver); - return $myver[1]; + my $ver = $ubnt->description() || ''; + if((lc $ver) =~ /^edgeswitch/){ + ## EdgeSwitch OS version is second field split by comma and bootcode version is last + my @myver = split(/, /, $ver); + my @firmware = split(/\./, $myver[1]); + my @bootcode = split(/\./, $myver[-1]); + + ## Return only three major version groupings and include bootcode version + return join('.', @firmware[0,1,2]) . '.-b' . join('.', @bootcode[0,1,2]); + } ## EdgeRouter OS version is second field split by space my @myver = split(/ /, $ver); + my @firmware = split(/\./, $myver[1]); - return $myver[1]; + if($firmware[2] =~ /hotfix$/){ + # edge case where EdgeOS has hotfix versions in format "EdgeOS v1.9.7+hotfix.4.5024004.171005.0403" + $firmware[2] = $firmware[2] . '.' . $firmware[3] + } + ## Return only three major version groupings + return join('.', @firmware[0,1,2]); } sub vendor { @@ -142,7 +161,7 @@ sub model { if(!((lc $desc) =~ /edgeos/)){ # Not sure what type of device this is to get Model # Wireless devices report dot11_prod_name - # EdgeSwitch includes mode directly and edgeos logic is in else statement + # EdgeSwitch includes model directly and edgeos logic is in else statement return ; }else{ ## do some logic to determine ER model based on tech specs from ubnt: