Re: [Nagios-devel] Patch for checks.c - embedded Perl plugins do
Posted: Sat Dec 20, 2008 6:32 pm
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.=20
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=3D%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} =3D $2 if /^\s*(NAGIOS_\w+)=3D(.*?)\s*$/ } `env`;
=20
and the (correct) result was "sid=3Dnaprax".
I have no idea how this embedded perl works. Do you think, the %ENV can =
be
updated before run_package is called?
Gerhard
> -----Urspr=FCngliche Nachricht-----
> Von: Gerhard Lausser [mailto:[email protected]]=20
> Gesendet: Freitag, 19. Dezember 2008 19:46
> An: [email protected]
> Betreff: [Nagios-devel] Patch for checks.c - embedded Perl=20
> plugins do notsee custom macros as environment variables
>=20
> Hi,
>=20
> i wondered, why a plugin (which ran error-free through=20
> mini_epn) produced ePN-errors. What i found out is,=20
> environment variables which are made from custom macros are=20
> not visible by the embedded perl interpreter as they would be=20
> if the plugin was started as a separate process.
> I added a patch which adds=20
> set_all_macro_environment_vars(TRUE/FALSE); to the code after=20
> use_epn=3DTRUE, but i'm not sure wether i put the function=20
> calls to the right places. (At least at my test installation=20
> it's working) Can you have a look at it?
>=20
> Gerhard
>=20
> --- 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]=3Dprocessed_command+strlen(fname)+1;
> =20
> + /* set environment variables */
> + set_all_macro_environment_vars(TRUE);
> +
> ENTER;=20
> SAVETMPS;
> PUSHMARK(SP);
> @@ -607,6 +610,9 @@
> /* free check result memory */
> free_check_result(&check_result_info);
> =20
> + /* unset environment variables */
> + set_all_macro_environment_vars(FALSE);
> +
> return;
> }
> else{
> @@ -615,6 +621,9 @@
> =20
> log_debug_info(DEBUGL_CHECKS,1,"Embedded=20
> Perl successfully compiled %s and returned code ref to plugin=20
> handler\n",fname);
> =20
> + /* unset environment variables */
> + set_all_macro_environment_vars(FALSE);
> +
> PUTBACK ;
> FREETMPS ;
> LEAVE ;
>=20
>=20
>=20
> --------------------------------------------------------------
> ----------------
> _______________________________________________
> Nagios-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/lis ... gios-devel
>=20
This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
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.=20
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=3D%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} =3D $2 if /^\s*(NAGIOS_\w+)=3D(.*?)\s*$/ } `env`;
=20
and the (correct) result was "sid=3Dnaprax".
I have no idea how this embedded perl works. Do you think, the %ENV can =
be
updated before run_package is called?
Gerhard
> -----Urspr=FCngliche Nachricht-----
> Von: Gerhard Lausser [mailto:[email protected]]=20
> Gesendet: Freitag, 19. Dezember 2008 19:46
> An: [email protected]
> Betreff: [Nagios-devel] Patch for checks.c - embedded Perl=20
> plugins do notsee custom macros as environment variables
>=20
> Hi,
>=20
> i wondered, why a plugin (which ran error-free through=20
> mini_epn) produced ePN-errors. What i found out is,=20
> environment variables which are made from custom macros are=20
> not visible by the embedded perl interpreter as they would be=20
> if the plugin was started as a separate process.
> I added a patch which adds=20
> set_all_macro_environment_vars(TRUE/FALSE); to the code after=20
> use_epn=3DTRUE, but i'm not sure wether i put the function=20
> calls to the right places. (At least at my test installation=20
> it's working) Can you have a look at it?
>=20
> Gerhard
>=20
> --- 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]=3Dprocessed_command+strlen(fname)+1;
> =20
> + /* set environment variables */
> + set_all_macro_environment_vars(TRUE);
> +
> ENTER;=20
> SAVETMPS;
> PUSHMARK(SP);
> @@ -607,6 +610,9 @@
> /* free check result memory */
> free_check_result(&check_result_info);
> =20
> + /* unset environment variables */
> + set_all_macro_environment_vars(FALSE);
> +
> return;
> }
> else{
> @@ -615,6 +621,9 @@
> =20
> log_debug_info(DEBUGL_CHECKS,1,"Embedded=20
> Perl successfully compiled %s and returned code ref to plugin=20
> handler\n",fname);
> =20
> + /* unset environment variables */
> + set_all_macro_environment_vars(FALSE);
> +
> PUTBACK ;
> FREETMPS ;
> LEAVE ;
>=20
>=20
>=20
> --------------------------------------------------------------
> ----------------
> _______________________________________________
> Nagios-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/lis ... gios-devel
>=20
This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]