Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: NNM Nonsense

by cengineer (Pilgrim)
on Aug 09, 2007 at 15:42 UTC ( [id://631593]=note: print w/replies, xml ) Need Help??


in reply to NNM Nonsense

Can you post some code showing what you have tried so far?

Replies are listed 'Best First'.
Re^2: NNM Nonsense
by Perl_Pursuer (Initiate) on Aug 09, 2007 at 20:23 UTC
    I sure can. Don't laugh too hard, I'm fairly new at this and I kind of sort of "inherited" this from my predecessor who ha moved on to greener pastures.
    #!/usr/local/bin/perl # node_down.pl # Called from the OV_Node_Down event use File::Basename; require "/opt/ov_action_scripts/send_trap.pl"; $ENV{'PATH'} = '/usr/sbin:/usr/bin:/usr/ucb:/usr/local/bin:/opt/OV/bin +'; $argv0 = basename($0); ($sn) = ($argv0 =~ /(\w+)\./); $date = $ARGV[0]; $time = $ARGV[1]; $device = $ARGV[2]; $LOGFILE = "/opt/ov_action_scripts/logs/$sn.log"; $COREFILE = "/opt/ov_action_scripts/core_dev_list"; $INTERFACE = "/opt/ov_action_scripts/interface_dev_list"; $match = 0; # # See if device is in the core device list # open(CF, $COREFILE) || die "Can't open $COREFILE for read: $!\n"; while (<CF>) { $match = 1 if (/^$device/); } close(CF); open(CF, $INTERFACE) || die "Can't open $COREFILE for read: $!\n"; while (<CF>) { $match = 2 if (/^$interface/); } close(CF); snmpget $device .1.3.6.1.2.1.2.2.1.2.$interface if ($match) { ($shortname) = ($device =~ /^\d+\./ $interface =~ /^\d+\./) ? $dev +ice : ($device =~ /^(\w+)/); $summary = "$shortname Down"; $descr = "Node Down"; $intfc = "Interface Name"; # Forward trap to the Common Event Path by sending another trap # to the host # Trap args: # Event Source Device # Short Description (Summary) Device Down # Description Node Down # TrapData1 NODE_DOWN $rc = sendtrap("$device", "$summary", "$descr", $intfc" "NODE_DOWN +"); $ti = ($rc) ? "Trap NOT forwarded" : "Trap forwarded"; # Log it open(LF, ">>$LOGFILE") || die "Can't open $LOGFILE for write: $!\n +"; print LF "$date: $time: $device down ($ti)\n"; close(LF); }

      snmpget $device .1.3.6.1.2.1.2.2.1.2.$interface
      Perl is not a shell script interpreter. Assuming this is a command line for a program you need to call, you need to make it a string, and actually execute it, either by system or by backticks(``) or qx. Plus, it needs a semicolon between statements.

      So, start by changing this line to

      `snmpget $device .1.3.6.1.2.1.2.2.1.2.$interface`;
      or
      system("snmpget $device .1.3.6.1.2.1.2.2.1.2.$interface");
      depending on what you want to do with the output.

      I don't know this particular protocol so you'll probably have to tweak it some more before it actually becomes usable.

      Apart from the problem cited by bart, there are a couple other syntax errors in the code you posted. This first line inside the if ($match) block is missing something:
      ($shortname) = ($device =~ /^\d+\./ $interface =~ /^\d+\./) ? ...
      It's checking two regex matches, but there should be an "and" or "or" (or && or ||) between them -- or else there should be only one regex test. (Do you know what the intention is there? I don't.)

      Then this line just after the lengthy comment is obviously bad:

      $rc = sendtrap("$device", "$summary", "$descr", $intfc" "NODE_DOWN");
      You're missing a comma before "NODE_DOWN", and you have an odd number of quotation marks. (You could actually get rid of all the double-quotes in that line except for the ones around "NODE_DOWN", but you need the missing comma.)

      Running the script without fixing those (and the line pointed to by bart) will just generate a bunch of syntax errors. Is that what you meant by "I cannot get this to work correctly"? Or did you make mistakes in posting your code, and the version you're actually running has some other problem(s)?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-04-23 10:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found