Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Getting a NetSNMP::TrapReceiver registered function to accept a command line argument

by Limbic~Region (Chancellor)
on Oct 21, 2011 at 14:26 UTC ( #932914=perlquestion: print w/ replies, xml ) Need Help??
Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:

All,
Consider this trivial modification to the example in the NetSNMP::TrapReceiver documentation.
#!/usr/bin/perl my $greeting = $ARGV[0] // '********** PERL RECEIVED A NOTIFICATION:'; sub my_receiver { print $greeting, "\n"; } NetSNMP::TrapReceiver::register("all", \&my_receiver) || warn "failed +to register\n"; print STDERR "Loaded the example perl snmptrapd handler\n";
With the following trivial modification to the snmprapd.conf file.
perl do "/usr/local/share/snmp/mytrapd.pl hello";

This modification doesn't work (no output is produced and as far as I can tell, my handler is not being called). In my real world scenario, the command line argument happens to be a configuration file that contains extensive configuration information that I don't want hard coded into the code. I could of course hard code the path to the configuration file which I have done as a work around but I am wondering if anyone knows how to make this DWIM?

Update: I have received the following response from the module author which may mean what I am trying to accomplish is impossible unless kill -HUP <pid> causes the snmptrapd daemon to re-read the configuration file and re-register the function.

That won't work. The perl 'do' command only expects a filename. Instead, you can either define a subroutine in the file rather than ha +ve the file itself do something. IE, in the file if you put: sub foo { print "$_[0]\n"; } and then put these lines in the snmptrapd.conf file: perl do /path/to/script perl foo("hello world"); perl foo("now I am passing something different");

Update 2: The author has told me that kill -HUP <pid> doesn't do what I want so the best I can hope for is hard coding the path to the configuration file in the script and then having the function periodically reload it.

Cheers - L~R

Comment on Getting a NetSNMP::TrapReceiver registered function to accept a command line argument
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://932914]
Approved by BrowserUk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (11)
As of 2014-12-26 15:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls