Patch for checks.c - embedded Perl plugins do notsee custom macros as environment variables

Gerhard Lausser Gerhard.Lausser at consol.de
Sat Dec 20 19:32:14 CET 2008


Hi,
please forget what i wrote yesterday. I was barking up the wrong tree. The
calls to set_all_macro_environment_vars are already in the right places. 
When the precompiled Perl-code is executed, it's environment is ok. 
But: the $ENV hash which isn't. Maybe because it's filled when the plugin is
first compiled.

Example:

#! /usr/bin/perl -w
# +epn

if (exists $ENV{NAGIOS__SERVICEORACLE_SID}) {
  if (defined $ENV{NAGIOS__SERVICEORACLE_SID}) {
    printf "sid=%s\n", $ENV{NAGIOS__SERVICEORACLE_SID};
  } else {
    printf "sid is not defined\n";
  }
} else {
  printf "sid does not exist\n";
}
exit 0;

always showed "sid does not exist" on the Nagios webpage.
But when i called something like system("env"), the Nagios-Environment was
clearly visible.
Then i added this at the beginning of the plugin:

map { $ENV{$1} = $2 if /^\s*(NAGIOS_\w+)=(.*?)\s*$/ } `env`;
 
and the (correct) result was "sid=naprax".
I have no idea how this embedded perl works. Do you think, the %ENV can be
updated before run_package is called?

Gerhard


> -----Ursprüngliche Nachricht-----
> Von: Gerhard Lausser [mailto:Gerhard.Lausser at consol.de] 
> Gesendet: Freitag, 19. Dezember 2008 19:46
> An: nagios-devel at lists.sourceforge.net
> Betreff: [Nagios-devel] Patch for checks.c - embedded Perl 
> plugins do notsee custom macros as environment variables
> 
> Hi,
> 
> i wondered, why a plugin (which ran error-free through 
> mini_epn) produced ePN-errors. What i found out is, 
> environment variables which are made from custom macros are 
> not visible by the embedded perl interpreter as they would be 
> if the plugin was started as a separate process.
> I added a patch which adds 
> set_all_macro_environment_vars(TRUE/FALSE); to the code after 
> use_epn=TRUE, but i'm not sure wether i put the function 
> calls to the right places. (At least at my test installation 
> it's working) Can you have a look at it?
> 
> Gerhard
> 
> --- nagios-3.0.6/base/checks.c  2008-11-30 18:22:58.000000000 +0100
> +++ nagios-3.0.6-epn-and-custom-macros/base/checks.c    2008-12-19
> 19:27:05.000000000 +0100
> @@ -539,6 +539,9 @@
>                 else
>                  args[3]=processed_command+strlen(fname)+1;
>  
> +               /* set environment variables */
> +               set_all_macro_environment_vars(TRUE);
> +
>                 ENTER; 
>                 SAVETMPS;
>                 PUSHMARK(SP);
> @@ -607,6 +610,9 @@
>                  /* free check result memory */
>                  free_check_result(&check_result_info);
>  
> +                /* unset environment variables */
> +                set_all_macro_environment_vars(FALSE);
> +
>                  return;
>                  }
>                 else{
> @@ -615,6 +621,9 @@
>  
>                  log_debug_info(DEBUGL_CHECKS,1,"Embedded 
> Perl successfully compiled %s and returned code ref to plugin 
> handler\n",fname);
>  
> +                /* unset environment variables */
> +                set_all_macro_environment_vars(FALSE);
> +
>                  PUTBACK ;
>                  FREETMPS ;
>                  LEAVE ;
> 
> 
> 
> --------------------------------------------------------------
> ----------------
> _______________________________________________
> Nagios-devel mailing list
> Nagios-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/nagios-devel
> 


------------------------------------------------------------------------------




More information about the Developers mailing list