EPN/DB plugin question

Stanley Hopcroft stanleyhopcroft at gmail.com
Thu Oct 19 00:26:33 CEST 2006


Dear Sir,

I am writing to thank you for your letter and your patience in waiting
for a reply (it is partly 'Warnock applies' in respect of no one
having anything helpful to say I think)

On 28/09/06, Tal Cohen <tcohen at sitespect.com> wrote:
>
> I am creating plugins that interface with a mysql database. I know that in
> mod_perl there is a way to maintain and share database connections (thereby
> avoiding the connect/disconnect overhead). Is there a similar method using
> epn?

Apart from the same precautions that apply to coding mod_perl and ePN
client code (ie use strict, be careful with globals since they will be
captured by closures and live forever, initialise everything where it
makes sense ... see the Stas Bekman recommendations or the notes in
the Nag docco), mod_perl and ePN have very little in common, apart
from the intent.

However, to attempt an answer, why not simply avoid shutting down the
connection and check if the DB and statement handles are instantiated
before constructing them ? (ie write a nasty looking thing that is
intended for use in a persistent environment).

An example that is similar (but not unfortch like your case) is only
constructing objects the first time the plugin is run.

  unless ( $sock ) {

                                                        # Conditional
object construction
                                                        # to try and
reduce memory use
                                                        # in embedded
Perl applications.

    $sock = IO::Socket::INET->new(
                        LocalAddr       => inet_ntoa(INADDR_ANY),
                        LocalPort       => 68,
                        Proto             => 'udp',
                        Type              => SOCK_DGRAM,
                        Broadcast      => 1,
                ) or do {
      print "Cannot create socket or bind to priviledged port: $!\n" ;
      exit $ERRORS{UNKNOWN}
    }

  }

  $hispaddr = sockaddr_in(67, inet_aton($subnet_bcast) || INADDR_BROADCAST) ;


This is part of a private DHCP check (yep, every one has to write
their own DHCP check at least once) that only creates the DHCP object
if it doesn't already have a value that is retained from the last time
the plugin runs.

This has been working for me (Perl 5.8.0/RH EL3/Nag 2.5) for some
months without problem. Oops ! It works because the object _is_
constructed each time since this is a suid plugin that is called from
a C wrapper and therefore doesn't bother ePN at all. However, I think
it would or could be made to work with ePN.

Unlike mod_perl which could well systematically cache such things,
there is no support in ePN for caching application data structures.
OTOH,  you may be able to get away with a hack like that above.

You could also consider porting the mod_perl stuff to ePN. I would
consider it but looking at the mod_perl code makes my head hurt.

Yours sincerely.

>
> Thanks,
> Tal

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list