--Apple-Mail-92--79955971
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="us-ascii"
Hi Andreas,
Please find attached a patch to support environment macros. I've amended =
it so that it uses the array method instead of the object method, so =
there is no structural change.
Random things:
* worker processes take the key/value information. I think I've got =
all the memory allocation/deallocation right, but I'd welcome a review =
of that
* There's an assumption that putenv() is available
* I've added an example in sample-config with notes:
# You can also define environment variables that will be passed to the =
command after expansion
# Unknown/invalid macros will get converted to an empty string (eg, =
service macros for a host check)
# This applies for checks, notifications, event handlers and performance =
handlers
define command{
command_name custom-notify-by-carrier-pigeon
command_line $USER1$/notify-script
env NAGIOS_SERVICESTATE=3D$SERVICESTATE$
env NAGIOS_HOSTALIAS=3D$HOSTALIAS$
env ORACLE_SID=3Ddb1
}
* CGIs do not have this command environment information, though I =
guess they could if you remove the relevant ifndefs
* Invalid macros in the env variable is treated differently from the =
command line. For instance, a host check with:=20
command_line check_tcp $SERVICEDESC$
will cause Nagios to run:
check_tcp $SERVICEDESC$
Which will probably get to the plugin as:
check_tcp $
But the old envvars would set NAGIOS_SERVICEDESC to an empty string. =
This patch will set to an empty string too. This is controlled by a new =
process macro option: SET_EMPTY_IF_INVALID.
Also wanted to say that the nagios library has made making functions =
available much easier and that the kvv stuff is very cool (though a pig =
to setup).
Ton
--Apple-Mail-92--79955971
Content-Disposition: attachment;
filename="nagios_command_environment_macros.patch"
Content-Type: application/octet-stream;
name="nagios_command_environment_macros.patch"
Content-Transfer-Encoding: quoted-printable
Index:=20xdata/xodtemplate.c=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A---=20=
xdata/xodtemplate.c=09(revision=202574)=0A+++=20xdata/xodtemplate.c=09=
(working=20copy)=0A@@=20-1309,6=20+1309,10=20@@=0A=20=09=09=09=09=
if((temp_command->command_line=20=3D=20(char=20*)strdup(value))=20=3D=3D=20=
NULL)=0A=20=09=09=09=09=09result=20=3D=20ERROR;=0A=20=09=09=09=09}=0A+=09=
=09=09else=20if(!strcmp(variable,=20"env"))=20{=0A+=09=09=09=09=
if(xodtemplate_add_commandenvironment(temp_command,=20value)=20=3D=3D=20=
NULL)=0A+=09=09=09=09=09result=20=3D=20ERROR;=0A+=09=09=09=09}=0A=20=09=09=
=09else=20if(!strcmp(variable,=20"register"))=0A=20=09=09=09=09=
temp_command->register_object=20=3D=20(atoi(value)=20>=200)=20?=20TRUE=20=
:=20FALSE;=0A=20=09=09=09else=20{=0A@@=20-3547,7=20+3551,30=20@@=0A=20=09=
}=0A=20=0A=20=0A+/*=20adds=20an=20envvar=20to=20a=20command=20definition=20=
*/=0A+xodtemplate_commandenvironment=20=
*xodtemplate_add_commandenvironment(xodtemplate_command=20*command,=20=
char=20*env)=20{=0A+=09xodtemplate_commandenvironment=20=
*new_commandenvironment=20=3D=20NULL;=0A=20=0A+=09/*=20make=20sure=20we=20=
have=20the=20data=20we=20need=20*/=0A+=09if(env=20=3D=3D=20NULL=20||=20=
!strcmp(env,=20""))=0A+=09=09return=20NULL;=0A+=0A+=09/*=20allocate=20=
memory=20for=20a=20new=20env=20*/=0A+=09if((new_commandenvironment=20=3D=20=
malloc(sizeof(xodtemplate_commandenvironment)))=20=3D=3D=20NULL)=0A+=09=09=
return=20NULL;=0A+=09if((new_commandenvironment->env=20=3D=20(char=20=
*)strdup(env))=20=3D=3D=20NULL)=20{=0A+=09=09=
my_free(new_commandenvironment);=0A+=09=09return=20NULL;=0A+=09=09}=0A+=0A=
+=09/*=20add=20the=20new=20member=20to=20the=20head=20of=20the=20member=20=
list=20*/=0A+=09new_commandenvironment->next=20=3D=20command->env;=0A+=09=
command->env=20=3D=20new_commandenvironment;=0A+=0A+=09return=20=
new_commandenvironment;=0A+=09}=0A+=0A+=0A=20/*=20par
...[email truncated]...
This post was automatically imported from historical nagios-devel mailing list archives
Original poster: ton.voon@opsview.com