Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^4: Broken Net::Telnet::Netscreen module?

by spivey49 (Monk)
on Aug 13, 2008 at 20:18 UTC ( #704205=note: print w/replies, xml ) Need Help??

in reply to Re^3: Broken Net::Telnet::Netscreen module?
in thread Broken Net::Telnet::Netscreen module?

The $value in unsetValue is ok. The command sent to the firewall will end up being <unset object name> or something like "unset address Autogen_x".

The regex used to check for the error is a little flawed though, it should be looking for "^-". I updated the methods with this, but the script still exits after the first command. The module does report errors correctly now though.

I've tried die, eval, and even clucking exit, at tye's suggestion. The script just exits silently.

Updated methods for Net::Telnet::Netscreen:

sub setValue { my ($self,$setting, $value) = @_; return $self->error("No setting specified") unless $setting; return $self->error("No value specified") unless $value; my @results=$self->cmd("set ".$setting." ".$value); foreach my $result (@results) { if ($result =\/^-/) { return $self->error($result); print STDERR "<<$result>>\n"; } } return 1; } sub unsetValue { my ($self,$setting, $value) = @_; return $self->error("No setting specified") unless $setting; return $self->error("No value specified") unless $value; my @results=$self->cmd("unset ".$setting." ".$value); foreach my $result (@results) { if ($result =\/^-/) { return $self->error($result); print STDERR "<<$result>>\n"; } } return 1; }

Replies are listed 'Best First'.
Re^5: Broken Net::Telnet::Netscreen module?
by jethro (Monsignor) on Aug 13, 2008 at 20:38 UTC

    Too bad, I thought I had the right idea

    You are not very clear about whether you get error messages or not. If you get any, please post them. Otherwise you could repeat the trace and show that output if it changed.

    I don't remember the regex syntax $result=\/^-/. Shouldn't the \ be ~ ?

    UPDATE: Also you might use Data::Dumper to print out everything in @result, just to be sure what you get back

      Well, we did fix another problem. Errors would have been returned incorrectly by the module with out revising the regex.

      =~/\^-/ works too.

      Data::Dumper returns what I expected, the command sent to the firewall. I tried commenting out the error check as well with the same results. The script exits silently, no warnings, no errors.

        The trace you showed before seems to show that the method error() from was called and the program died in line 535 of (there is a die statement there). If I'm right you have to find out why error() is called.

        You can do this for example with the debugger. Set a breakpoint at the foreach line in unsetValue() and single step from there. Where exactly does the program stop? If you never reach the breakpoint, move the breakpoint to a previous line on the next run. If the error shows up only on the second run through unsetValue() 'c'ontinue at the first breakpoint and single step at the next stop

        You can also do this testing if you put print statements (like print "1\n"; <statements>; print "2\n";) between crucial statements and watch what number you see last. But the debugger is ultimately faster

        UPDATE: Just to make sure, /\^-/ searches for a literal '^-' somewhere in the string, not for '-' at the start of the string. That is what you want, right? And hopefully you didn't post the real password of your netscreen firewall, especially if it is accessible from the internet

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://704205]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2019-12-05 15:14 GMT
Find Nodes?
    Voting Booth?
    Strict and warnings: which comes first?

    Results (151 votes). Check out past polls.