perlquestion
Limbic~Region
All,
<br />
Consider this trivial modification to the example in the [mod://NetSNMP::TrapReceiver] documentation.
<CODE>
#!/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";
</CODE>
With the following trivial modification to the snmprapd.conf file.
<c>
perl do "/usr/local/share/snmp/mytrapd.pl hello";
</c>
<p>
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?
</p>
<p>
<b>Update:</b> I have received the following response from the module author which may mean what I am trying to accomplish is impossible unless <c>kill -HUP <pid></c> causes the snmptrapd daemon to re-read the configuration file and re-register the function.
</p>
<c>
That won't work. The perl 'do' command only expects a filename.
Instead, you can either define a subroutine in the file rather than have
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");
</c>
<p>
<b>Update 2:</b> The author has told me that <c>kill -HUP <pid></c> 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.
</p>
<div class="pmsig"><div class="pmsig-180961">
<p>
Cheers - [Limbic~Region|L~R]
</p>
</div></div>