From: <buc...@us...> - 2014-11-27 13:19:10
|
Revision: 246 http://sourceforge.net/p/devmon/code/246 Author: buchanmilne Date: 2014-11-27 13:19:01 +0000 (Thu, 27 Nov 2014) Log Message: ----------- Add a new 'PACK' transform, which does exactly the inverse of the UNPACK transform Modified Paths: -------------- trunk/docs/TEMPLATES trunk/modules/dm_templates.pm trunk/modules/dm_tests.pm Modified: trunk/docs/TEMPLATES =================================================================== --- trunk/docs/TEMPLATES 2014-11-27 12:53:57 UTC (rev 245) +++ trunk/docs/TEMPLATES 2014-11-27 13:19:01 UTC (rev 246) @@ -522,7 +522,11 @@ (i.e. 300549.3420). The default value is 2 precision characters. To remove the decimal characters alltogether, specify a value of 0. + 'UNPACK' transform: + The inverse of the 'PACK' transform. + Introduced in 0.3.1 + 'REGSUB' transform: One of the most powerful and complicated transforms, the regsub Modified: trunk/modules/dm_templates.pm =================================================================== --- trunk/modules/dm_templates.pm 2014-11-27 12:53:57 UTC (rev 245) +++ trunk/modules/dm_templates.pm 2014-11-27 13:19:01 UTC (rev 246) @@ -560,6 +560,26 @@ last CASE; }; + $func_type eq 'pack' and do { + $temp =~ s/^\s*\{\s*\S+?\s*\}\s+(\S+)(\s+.+)?//; + my $type = $1; + my $validChars = 'aAbBcCdDfFhHiIjJlLnNsSvVuUwxZ'; + do_log("PACK transform uses only a single oid,an encode type, " . + "and an optional seperator at $trans_file, line $l_num", 0) + and next LINE if $temp ne ''; + do_log("No encode type at $trans_file, line $l_num", 0) + and next LINE if !defined $type; + while($type =~ s/\((.+?)\)(\d+|\*)?//) { + my $bit = $1; + do_log("Bad encode type ($bit) at $trans_file, line $l_num", 0) + and next LINE if $bit !~ /^([$validChars](\d+|\*)?)+$/i; + } + do_log("Bad encode type ($type) at $trans_file, line $l_num", 0) + and next LINE if $type ne '' and + $type !~ /^([$validChars](\d+|\*)?)+$/i; + last CASE; + }; + $func_type eq 'regsub' and do { $temp =~ s/^\{\s*\S+?\s*\}\s*\/.+\/.*\/\s*$//g; do_log("REGSUB transform should be a perl regex substitution at " . Modified: trunk/modules/dm_tests.pm =================================================================== --- trunk/modules/dm_tests.pm 2014-11-27 12:53:57 UTC (rev 245) +++ trunk/modules/dm_tests.pm 2014-11-27 13:19:01 UTC (rev 246) @@ -773,8 +773,55 @@ } + sub trans_pack { + my ($device, $oids, $oid, $thr) = @_; + my $oid_h = \%{$oids->{$oid}}; + my ($dep_oid, $type, $seperator) = ($1, $2, $3 || '') + if $oid_h->{'trans_data'} =~ /\{(.+)\}\s+(\S+)(?:\s+"(.+)")?/; + my $dep_oid_h = \%{$oids->{$dep_oid}}; + # Validate our dependencies + validate_deps($device, $oids, $oid, [$dep_oid]) or return; + + # See if we are a repeating variable type datum + # (such as that generated by snmpwalking a table) + if($oid_h->{'repeat'}) { + + # Unpack ze data + for my $leaf (keys %{$dep_oid_h->{'val'}}) { + # Skip if we got a dependency error for this leaf + next if $oid_h->{'error'}{$leaf}; + + my @packed = split $seperator, $dep_oid_h->{'val'}{$leaf}; + my $val = pack $type, @packed; + + do_log("Transformed $dep_oid_h->{'val'}{$leaf}, first val $packed[0], to $val via pack transform type $type, seperator $seperator ",0) if $g{'debug'}; + + $oid_h->{'val'}{$leaf} = $val; + $oid_h->{'time'}{$leaf} = time; + } + + # Apply thresholds + apply_thresh_rep($oids, $thr, $oid); + } + + # Otherwise we are a single entry datum + else { + my $packed = $dep_oid_h->{'val'}; + my @vars = pack $type, $packed; + + $oid_h->{'val'} = join $seperator, @vars; + $oid_h->{'time'} = time; + + # Apply thresholds + apply_thresh($oids, $thr, $oid); + } + + } + + + # Translate hex or octal data into decimal ################################## sub trans_unpack { my ($device, $oids, $oid, $thr) = @_; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |