Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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:

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/ 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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2018-12-16 19:35 GMT
Find Nodes?
    Voting Booth?
    How many stories does it take before you've heard them all?

    Results (71 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!