Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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


In reply to Getting a NetSNMP::TrapReceiver registered function to accept a command line argument by Limbic~Region

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (13)
    As of 2015-07-31 17:08 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (279 votes), past polls