From: <buc...@us...> - 2008-12-31 12:56:20
|
Revision: 105 http://devmon.svn.sourceforge.net/devmon/?rev=105&view=rev Author: buchanmilne Date: 2008-12-31 12:56:15 +0000 (Wed, 31 Dec 2008) Log Message: ----------- Add INDEX transform Modified Paths: -------------- trunk/docs/TEMPLATES trunk/modules/dm_templates.pm trunk/modules/dm_tests.pm Modified: trunk/docs/TEMPLATES =================================================================== --- trunk/docs/TEMPLATES 2008-12-08 22:04:34 UTC (rev 104) +++ trunk/docs/TEMPLATES 2008-12-31 12:56:15 UTC (rev 105) @@ -396,6 +396,29 @@ seconds provided as input to the transform. + 'INDEX' transform: + This transform allows you to access the index part of a + numerical OID in a repeater OID. + + For example, in the cdpCache table for the Cisco CDP MIB, + walking the cdpCacheDevicePort OID will return values such as: + + CISCO-CDP-MIB::cdpCacheDevicePort.4.3 = STRING: GigabitEthernet4/41 + CISCO-CDP-MIB::cdpCacheDevicePort.9.1 = STRING: GigabitEthernet2/16 + CISCO-CDP-MIB::cdpCacheDevicePort.12.14 = STRING: Serial2/2 + + The value is the interface on the remote side, and there is no + OID for the interface on the local side. To get the interface + on the local side, you must use the last value in the index + (e.g. 3 for GigabitEthernet4/41) and look in the ifTable: + + IF-MIB::ifName.3 = STRING: Fa0/0 + + The index transform allows you to get the index value (4.3 + in this case) as an OID value. Any operations you need to + do on the index value should be possible with existing + transforms. + 'MATH' transform: The MATH transform performs a mathematical expression defined Modified: trunk/modules/dm_templates.pm =================================================================== --- trunk/modules/dm_templates.pm 2008-12-08 22:04:34 UTC (rev 104) +++ trunk/modules/dm_templates.pm 2008-12-31 12:56:15 UTC (rev 105) @@ -651,6 +651,14 @@ last CASE; }; + $func_type eq 'index' and do { + $temp =~ s/\s*\{\s*\S+?\s*\}|\s*,\s*//g; + do_log("INDEX transform uses only a single oid at " . + "$trans_file, line $l_num", 0) + and next LINE if $temp ne ''; + last CASE; + }; + do_log("Unknown function '$func_type' at $trans_file, line $l_num", 0); next LINE; } Modified: trunk/modules/dm_tests.pm =================================================================== --- trunk/modules/dm_tests.pm 2008-12-08 22:04:34 UTC (rev 104) +++ trunk/modules/dm_tests.pm 2008-12-31 12:56:15 UTC (rev 105) @@ -1593,8 +1593,67 @@ } + # Return index values ###################################################### + # In some cases, the index value in a repeating OID is useful data to have + # Examples of this are the index in the cdp table, which refer to the + # ifIndex (the only way to get the near side interface name), another + # example is some load balancer MIBs which include vserver/real server + # detail only in the index + # This is more or less the inverse of the chain operator + sub trans_index { + my ($device, $oids, $oid, $thr) = @_; + my $oid_h = \%{$oids->{$oid}}; + # Extract our parent oids from the expression, first + my ($src_oid) = $oid_h->{'trans_data'} =~ /\{(.+?)}/g; + validate_deps($device, $oids, $oid, [$src_oid], '.+') ; + # Validate our dependencies, have to do them seperately + # validate_deps($device, $oids, 'tmp', [$trg_oid]) or return; + # validate_deps($device, $oids, $oid, [$src_oid], '^\.?(\d+\.)?\d+$') + # or return; + do_log("Transforming $src_oid to $oid via index transform",0) if $g{'debug'}; + + my $src_h = \%{$oids->{$src_oid}}; + + # This transform should probably only work for repeater sources + if(!$src_h->{'repeat'}) { + do_log("Trying to index a non-repeater source on $device ($@)", 0); + return; + } + + else { + # Tag the target as a repeater + $oid_h->{'repeat'} = 2; + for my $leaf (keys %{$src_h->{'val'}}) { + + # Skip if our source oid is freaky-deaky + next if $oid_h->{'error'}{$leaf}; + + # Our oid sub leaf + # my $oid_idx = $src_h->{'val'}{$leaf}; + + if(!defined $leaf) { + $oid_h->{'val'}{$leaf} = 'Target val missing - index'; + $oid_h->{'time'}{$leaf} = time; + $oid_h->{'color'}{$leaf} = 'yellow'; + $oid_h->{'error'}{$leaf} = 1; + next; + } + + $oid_h->{'val'}{$leaf} = $leaf; + $oid_h->{'time'}{$leaf} = $src_h->{'time'}{$leaf}; + $oid_h->{'color'}{$leaf} = $src_h->{'color'}{$leaf}; + $oid_h->{'error'}{$leaf} = $src_h->{'error'}{$leaf}; + } + + # Apply thresholds + apply_thresh_rep($oids, $thr, $oid); + } + + } + + # Create our outbound message ############################################## sub render_msg { my ($device, $tmpl, $test, $oids) = @_; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |