From: <ma...@us...> - 2006-08-02 20:21:29
|
Revision: 4587 Author: marz Date: 2006-08-02 13:21:26 -0700 (Wed, 02 Aug 2006) ViewCVS: http://svn.sourceforge.net/net-policy/?rev=4587&view=rev Log Message: ----------- fixing bugs Modified Paths: -------------- trunk/net-policy/modules/notification-mib/config-notification-filters.pm Modified: trunk/net-policy/modules/notification-mib/config-notification-filters.pm =================================================================== --- trunk/net-policy/modules/notification-mib/config-notification-filters.pm 2006-07-07 12:56:59 UTC (rev 4586) +++ trunk/net-policy/modules/notification-mib/config-notification-filters.pm 2006-08-02 20:21:26 UTC (rev 4587) @@ -7,56 +7,59 @@ np_setup_mib('SNMP-NOTIFICATION-MIB', ['snmpNotifyTable']); + np_setup_mib('SNMP-TARGET-MIB', ['snmpTargetAddrTable', 'snmpTargetParamsTable']); + np_setup_mib('SNMP-COMMUNITY-MIB', ['snmpNotifyFilterProfileTable', 'snmpNotifyFilterTable']); add_config_node("SNMP Administration:", 70, - "map_filter_profiles", - "Apply Filter Profile to Target"); + "map_profile_target", + "Apply Notification Filter Profile to Destination"); add_config_node("SNMP Administration:", 70, "manage_filter_profiles", "Manage Notification Filter Profiles"); -add_primary('map_filter_profiles', - title => "Mapping a notification filter profile to a target", - actions_descr => ['Add the notification filter profile'], +add_primary('map_profile_target', + title => "Map a Notification Filter Profile to a Destination", + actions_descr => ['Add the Notification Filter Profile'], actions => [ - sub { print STDERR "actions\n"; + sub { print STDERR "map_profile_target: actions\n"; my $wiz = shift; - my $profile = qwparam('profile') or qwparam('map_profile'); + my $profile = qwparam('profile'); print STDERR "map_filter_profiles: actions: target == ", qwparam('target'), " profile == $profile\n"; - my $ret = np_set_policy_data( - $wiz, qwparam('policiespicked'), - 'snmpNotifyFilterProfileTable', - ['snmpTargetParamsName', - 'snmpNotifyFilterProfileName', - 'snmpNotifyFilterProfileStorType', - 'snmpNotifyFilterProfileRowStatus'], - qwparam('target'), - $profile, - qwparam('storage_type'), - $SNMP::MIB{snmpNotifyFilterProfileRowStatus}{enums}{createAndGo}); - return($ret =~/\d+/?'OK':$ret); + if ($profile and $profile ne $CREATE_NEW) { + my $ret = np_set_policy_data( + $wiz, qwparam('policiespicked'), + 'snmpNotifyFilterProfileTable', + ['snmpTargetParamsName', + 'snmpNotifyFilterProfileName', + 'snmpNotifyFilterProfileStorType', + 'snmpNotifyFilterProfileRowStatus'], + qwparam('target'), + $profile, + qwparam('storage_type'), + $SNMP::MIB{snmpNotifyFilterProfileRowStatus}{enums}{createAndGo}); + return($ret =~/\d+/?'OK':$ret); + } + return 'FAIL'; }, 'Mapping notification filter profile to target' ], questions => [ { name => 'target', type => 'menu', - text => 'Notification Target', + text => 'Notification Destination', helptext => 'The name of an existing notification target to which the filter profile will be applied. If no target exists, a new one may be created.', default => $CREATE_NEW, values => sub { - my @params; my $params = net_policy_select("select distinct snmpTargetParamsName from netpolicyconfig.snmpTargetParamsTable"); - push(@params, @$params) if ref $params eq 'ARRAY'; - unshift(@params, $CREATE_NEW); - return \@params; + unshift(@$params, $CREATE_NEW); + return $params; }, 'submit' => 1, 'check_value' => sub { @@ -68,20 +71,21 @@ qwparam('curTarget', qwparam('target')); my $vals = np_get_policy_data($wiz, - qwparam('policiespicked'), - 'snmpNotifyFilterProfileTable', - ['snmpNotifyFilterProfileName', - 'id'], - 'order by id desc limit 1', - 'snmpTargetParamsName = ?', qwparam('target')); + qwparam('policiespicked'), + 'snmpNotifyFilterProfileTable', + ['snmpNotifyFilterProfileName', + 'id'], + 'order by id desc limit 1', + 'snmpTargetParamsName = ?', + qwparam('target')); if (defined $vals and ref($vals) eq 'ARRAY' and ref($vals->[0]) eq 'ARRAY') { # grab most recent entry from table @$vals = @{$vals->[0]}; - qwparam('profile', shift @$vals); + qwparam('map_profile', shift @$vals); } else { - qwparam('profile', $CREATE_NEW); + qwparam('map_profile', $CREATE_NEW); } return 'REDISPLAY'; } @@ -102,10 +106,26 @@ default => sub { qwparam('map_profile') || $CREATE_NEW; }, values => sub { my @params; - my $params = - net_policy_select("select distinct snmpNotifyFilterProfileName from netpolicyconfig.snmpNotifyFilterTable"); - push(@params, @$params) - if ref $params eq 'ARRAY'; + my $vals = np_get_policy_data($wiz, + qwparam('policiespicked'), + 'snmpNotifyFilterProfileTable', + ['snmpNotifyFilterProfileName', + 'id'], + 'order by id desc'); + if (defined $vals and ref($vals) eq 'ARRAY') { + my %names; + # push all snmpNotifyFilterProfileName's from this policy + foreach my $val (@$vals) { + print STDERR "map_profile: profile: $val->[0]\n"; + + print STDERR "map_profile: dup profile: $val->[0]\n" + if exists $names{$val->[0]}; + + $names{$val->[0]} = 1; + push(@params, $val->[0]) if ref $val eq 'ARRAY'; + } + } + unshift(@params, $CREATE_NEW); return \@params; }, @@ -136,8 +156,8 @@ $wiz->add_todos('notification_destinations'); } } else { - #some how delete mapping - print STDERR "map_filter_profiles: delete mapping\n"; + #some how delete mapping + print STDERR "map_filter_profiles: delete mapping\n"; } return 'OK'; } @@ -156,15 +176,31 @@ }, 'Updating the notification filter profile @profile@'], questions => [ - { name => 'profile', + { name => 'mgr_profile', type => 'menu', text => 'Profile Name', - default => sub { qwparam('profile') || $CREATE_NEW; }, + default => sub { qwparam('mgr_profile') || $CREATE_NEW; }, values => sub { my @params; - my $params = - net_policy_select("select distinct snmpNotifyFilterProfileName from netpolicyconfig.snmpNotifyFilterTable"); - push(@params, @$params) if ref $params eq 'ARRAY'; + my $vals = np_get_policy_data($wiz, + qwparam('policiespicked'), + 'snmpNotifyFilterProfileTable', + ['snmpNotifyFilterProfileName', + 'id'], + 'order by id desc'); + + if (defined $vals and ref($vals) eq 'ARRAY') { + my %names; + # push all snmpNotifyFilterProfileName's from this policy + foreach my $val (@$vals) { + print STDERR "profile: profile: $val->[0]\n"; + + print STDERR "profile: duplicate profile: $val->[0]\n" + if exists $names{$val->[0]}; + $names{$val->[0]} = 1; + push(@params, $val->[0]) if ref $val eq 'ARRAY'; + } + } unshift(@params, $CREATE_NEW); return \@params; }, @@ -193,11 +229,11 @@ ); sub checkbox { - my ($id, $prefix) = @_; - return { type => 'checkbox', - name => "$prefix$id", - values => [ '1' ], - default => '' }; + my ($id, $prefix) = @_; + return { type => 'checkbox', + name => "$prefix$id", + values => [ '1' ], + default => '' }; } # converts a table as returned by get_policy_data into a table with @@ -205,95 +241,96 @@ # is done using the translate function which is passed in ($func). See # translate_access for an example of a translate function. sub translate_table { - (my $tbl, my $func) = @_; + (my $tbl, my $func) = @_; - for my $i (0 .. $#$tbl) { - $$tbl[$i] = $func->($$tbl[$i]); - } + for my $i (0 .. $#$tbl) { + $$tbl[$i] = $func->($$tbl[$i]); + } - return [$tbl]; + return [$tbl]; } #converts an OID and mask to wildcard form for display to the user sub mask_to_wildcard { - my ($tree, $mask) = @_; - my @objs = split (/\./, $tree); - my $oid; - my $len = 0; my $ans = ""; + my ($tree, $mask) = @_; + my @objs = split (/\./, $tree); + my $oid; + my $len = 0; my $ans = ""; - #for now, ensure that the mask is a string containing a hex - #value starting with "0x", since that's what get_mask returns - # FIXME: allow other encodings? - return $tree unless ($mask =~ /^0x[0-9a-f]*$/); + #for now, ensure that the mask is a string containing a hex + #value starting with "0x", since that's what get_mask returns + # FIXME: allow other encodings? + return $tree unless ($mask =~ /^0x[0-9a-f]*$/); - #convert the mask to a list of bits - my @bits = map (split (//, sprintf("%04b", hex $_)), split (//, substr($mask, 2))); - my $bitlen = $#bits; + #convert the mask to a list of bits + my @bits = map (split (//, sprintf("%04b", hex $_)), split (//, substr($mask, 2))); + my $bitlen = $#bits; - foreach my $obj (@objs) { - if (length $obj) { - if ($obj =~ /^\d*$/) { - if (($len > $bitlen) || shift @bits) { - $ans .= ".$obj"; - } else { - $ans .= ".*"; - } - $len++; - } else { - $oid = new NetSNMP::OID($obj); - if ($oid) { - $ans .= "." if $len > 0; - $ans .= $obj; - foreach my $i (($len + 1) .. $oid->length()) { - shift @bits; - } - $len = $oid->length(); - } else { - return $tree; - } - } + foreach my $obj (@objs) { + if (length $obj) { + if ($obj =~ /^\d*$/) { + if (($len > $bitlen) || shift @bits) { + $ans .= ".$obj"; + } else { + $ans .= ".*"; } + $len++; + } else { + $oid = new NetSNMP::OID($obj); + if ($oid) { + $ans .= "." if $len > 0; + $ans .= $obj; + foreach my $i (($len + 1) .. $oid->length()) { + shift @bits; + } + $len = $oid->length(); + } else { + return $tree; + } + } } + } - return $ans; + return $ans; } # returns an array of data that is specific to the currently # selected policy (or just returns the query string when the -query option # is used) sub get_policy_data { - my $wiz = shift; + my $wiz = shift; - if (qwparam('pickpolicy_type') ne 'existp') { - return []; #since we just created a new policy, there shouldn't be any data in it - } elsif (qwparam('appendpolicy')) { + if (qwparam('pickpolicy_type') ne 'existp') { + return []; #since we just created a new policy, there shouldn't be any data in it + } elsif (qwparam('appendpolicy')) { - my $optFlat = 0; - my $optQuery = 0; + my $optFlat = 0; + my $optQuery = 0; - # Process options - while ($_[0] =~ /^-/) { - if ($_[0] eq '-flat') { - $optFlat = 1; - shift; - } elsif ($_[0] eq '-query') { - $optQuery = 1; - shift; - } - } + # Process options + while ($_[0] =~ /^-/) { + if ($_[0] eq '-flat') { + $optFlat = 1; + shift; + } elsif ($_[0] eq '-query') { + $optQuery = 1; + shift; + } + } - my ($table, $fields, @other) = @_; + my ($table, $fields, @other) = @_; - if ($optQuery) { - return np_get_policy_data($wiz, -query, qwparam('appendpolicy'), $table, $fields, "", @other); - } - elsif ($optFlat) { - return np_get_policy_data($wiz, -flat, qwparam('appendpolicy'), $table, $fields, "", @other); - } - else { - return np_get_policy_data($wiz, qwparam('appendpolicy'), $table, $fields, "", @other); - } + if ($optQuery) { + return np_get_policy_data($wiz, -query, qwparam('appendpolicy'), + $table, $fields, "", @other); + } elsif ($optFlat) { + return np_get_policy_data($wiz, -flat, qwparam('appendpolicy'), + $table, $fields, "", @other); + } else { + return np_get_policy_data($wiz, qwparam('appendpolicy'), + $table, $fields, "", @other); } + } } @@ -302,39 +339,54 @@ actions_descr => ['Update notification profile filters @profile@'], actions => [ - sub { print STDERR "manage_profile_filters: actions\n"; - my $wiz = shift; + sub { + print STDERR "manage_profile_filters: actions\n"; + my $wiz = shift; - return('OK'); - }, 'Updating the notification profile filters'], + return('OK'); + }, 'Updating the notification profile filters'], questions => [ { name => 'profile', type => 'text', text => 'Profile Name', + default => sub {print STDERR "manage_profile_filters: profile: default:",qwparam('mgr_profile'),":",qwparam('map_profile'),":\n"; + qwparam('mgr_profile') or + qwparam('map_profile');} }, { type => 'table', headers => [['', 'Filter subtree', 'Included', 'Excluded']], values => - [ sub { - my $wiz = shift; - my $ans = get_policy_data($wiz, "snmpNotifyFilterTable", - ['id', "snmpNotifyFilterSubtree", - 'snmpNotifyFilterMask', - "snmpNotifyFilterType"], - "snmpNotifyFilterProfileName = ?", - qwparam('profile')); - my @tbl = sort {my $oida = new NetSNMP::OID($$a[1]); - my $oidb = new NetSNMP::OID($$b[1]); - ($oida <=> $oidb) } @$ans; - return translate_table(\@tbl, - sub { my $row = shift; - return [checkbox($$row[0], "filt_"), - mask_to_wildcard($$row[1], - $$row[2]), - ($$row[3] == 1 ? 'X' : ''), - ($$row[3] == 2 ? 'X' : '')]; } - ) } + [ + sub { + my $wiz = shift; + my $profile = qwparam('profile'); + my @tbl; + if ($profile and $profile ne $CREATE_NEW) { + my $ans = np_get_policy_data($wiz, + qwparam('policiespicked'), + "snmpNotifyFilterTable", + ['id', "snmpNotifyFilterSubtree", + 'snmpNotifyFilterMask', + "snmpNotifyFilterType"], + 'order by id desc', + "snmpNotifyFilterProfileName = ?", + $profile); + + @tbl = sort {my $oida = new NetSNMP::OID($$a[1]); + my $oidb = new NetSNMP::OID($$b[1]); + ($oida <=> $oidb) } @$ans; + + } + return translate_table(\@tbl, + sub { + my $row = shift; + return [checkbox($$row[0], "filt_"), + mask_to_wildcard($$row[1], $$row[2]), + ($$row[3] == 1 ? 'X' : ''), + ($$row[3] == 2 ? 'X' : '')]; + }); + } ], check_value => [ @@ -353,12 +405,14 @@ ], post_answers => [ - sub { my $wiz = shift; - if (qwparam('operation') eq 'add') { - $wiz->add_todos('profile_filter'); - } - return 'OK'; - } + sub { + my $wiz = shift; + if (qwparam('operation') eq 'add') { + $wiz->add_todos('profile_filter'); + } + # need XXX del/del all case + return 'OK'; + } ], ); @@ -367,8 +421,10 @@ actions_descr => ['Add the notification filter'], actions => [ - sub { print STDERR "actions\n"; + sub { print STDERR "profile_filter: actions\n"; my $wiz = shift; + my $tree = qwparam('subtree') || qwparam('subtree_tree'); + my $mask = get_mask($tree); my $ret = np_set_policy_data( $wiz, qwparam('policiespicked'), 'snmpNotifyFilterTable', @@ -380,8 +436,8 @@ 'snmpNotifyFilterRowStatus', ], qwparam('name'), - qwparam('subtree'), - qwparam('mask'), + $tree, + $mask, qwparam('type'), qwparam('storage_type'), $SNMP::MIB{snmpNotifyFilterRowStatus}{enums}{createAndGo}); @@ -402,7 +458,8 @@ parent => \&mib_parent, children => \&mib_children }, - { type => 'text', + { name => 'subtree', + type => 'text', text => 'or type in a subtree', helptext => "Enter an OID in this field to include it and its subtrees @@ -411,24 +468,24 @@ that any subidentifier value matches that section of the OID. For example, 'sysContact.0', '.1.3', and 'ifEntry.*.1' are all valid OIDs.", - name => 'subtree', check_value => - sub { my $wiz = shift; - my $tmp = qwparam('subtree') || return; - #wildcards can only exist surrounded by periods - if ($tmp =~ /[^.]\*[^.]/ || $tmp =~ /\*$/ || - $tmp =~ /^\*/ || $tmp =~ /^\.\*/) { - return 'Invalid wildcard usage'; - } + sub { + my $wiz = shift; + my $tmp = qwparam('subtree') || return; + #wildcards can only exist surrounded by periods + if ($tmp =~ /[^.]\*[^.]/ || $tmp =~ /\*$/ || + $tmp =~ /^\*/ || $tmp =~ /^\.\*/) { + return 'Invalid wildcard usage'; + } - #translate wildcards to zeros for verification - $tmp =~ s/\*/0/g; + #translate wildcards to zeros for verification + $tmp =~ s/\*/0/g; - return 'Invalid or unknown MIB subtree' - unless (new NetSNMP::OID($tmp)); + return 'Invalid or unknown MIB subtree' + unless (new NetSNMP::OID($tmp)); - return; - } + return; + } }, { name => 'type', frommib => 'snmpNotifyFilterType', This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |