Page 1 of 1

[Nagios-devel] New feature patch: using hostgroups or servicegroups as arguments to on-demand macros

Posted: Fri Mar 26, 2004 5:44 pm
by Guest
This is a multi-part message in MIME format.

------=_NextPart_000_004A_01C41372.E3381740
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit


On-demand macros are a great thing, and the check_cluster2 plug-in is a
great way to use them. Unfortunately, if you want to use more than a few
on-demand macros on a single line, it can be a bit of a pain (but of
course, works just fine). This patch lets you use a hostgroup or
servicegroup name as an argument to an on-demand macro, and then expands
the macro appropriately with respect to all the members of the group.
For example, instead of saying:

check_command
check_service_cluster!"DNS"!1!5!$SERVICESTATEID:dns-server-1:DNS$,$SERVI
CESTATEID:dns-server-2:DNS$,...

you can define a service group (using regular expressions in this case):

define servicegroup{
servicegroup_name All-DNS
alias All DNS services
members dns-server-[0-9]*,DNS
}

and then replace all of the SERVICESTATEID macros in the check_command
with:

$SERVICESTATEID:All-DNS:,$

This will expand to all of the SERVICESTATEIDs of all of the services in
the All-DNS servicegroup, separated by commas. After this patch, there
are 4 ways to use on-demand macros:

$HOSTMACRO:host$
$HOSTMACRO:hostgroup:delimiter$
$SERVICEMACRO:host:service$
$SERVICEMACRO:servicegroup:delimiter$

The delimiter is used to separate the results after expanded (it doesn't
have to be a single character, but it will usually just be a comma).
Note that this adds an ambiguity with on-demand service macros. In order
to differentiate in between the last two lines above, Nagios will first
try to expand an on-demand service macro as a
$SERVICEMACRO:host:service$, and if that doesn't work (if host:service
doesn't exist), then Nagios will try it as
$SERVICEMACRO:servicegroup:delimiter$.

Please be forewarned; although I've done a little testing, I can't be
sure this doesn't introduce some new bug....

Regards,
Chris

------=_NextPart_000_004A_01C41372.E3381740
Content-Type: application/octet-stream;
name="nagios-groups-for-on-demand-macros.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="nagios-groups-for-on-demand-macros.patch"

*** ../nagios-orig/base/utils.c Fri Mar 26 14:34:08 2004=0A=
--- base/utils.c Fri Mar 26 19:28:56 2004=0A=
***************=0A=
*** 1086,1096 ****=0A=
/* grab an on-demand host or service macro */=0A=
int grab_on_demand_macro(char *str){=0A=
char *macro=3DNULL;=0A=
! char *host_name=3DNULL;=0A=
! char *service_description=3DNULL;=0A=
host *temp_host;=0A=
service *temp_service;=0A=
char *ptr;=0A=
=0A=
#ifdef DEBUG0=0A=
printf("grab_on_demand_macro() start\n");=0A=
--- 1086,1103 ----=0A=
/* grab an on-demand host or service macro */=0A=
int grab_on_demand_macro(char *str){=0A=
char *macro=3DNULL;=0A=
! char *first_arg=3DNULL;=0A=
! char *second_arg=3DNULL;=0A=
! char result_buffer[MAX_INPUT_BUFFER];=0A=
! int result_buffer_len, delimiter_len;=0A=
host *temp_host;=0A=
+ hostgroup *temp_hostgroup;=0A=
+ hostgroupmember *temp_hostgroupmember;=0A=
service *temp_service;=0A=
+ servicegroup *temp_servicegroup;=0A=
+ servicegroupmember *temp_servicegroupmember;=0A=
char *ptr;=0A=
+ int return_val=3DERROR;=0A=
=0A=
#ifdef DEBUG0=0A=
printf("grab_on_demand_macro() start\n");=0A=
***************=0A=
*** 1102,1108 ****=0A=
macro_ondemand=3DNULL;=0A=
}=0A=
=0A=
! /* get the macro name */=0A=
macro=3Dstrdup(str);=0A=
if(macro=3D=3DNULL)=0A=
return ERROR;=0A=
--- 1109,1115 ----=0A=
macro_ondemand=3DNULL;=0A=
}=0A=
=0A=
! /* get the first argument */=0A=
macro=3Dstrdup(str);=0A=
if(macro=3D=3DNULL)=0A=
return ERROR;=0A=
***************=0A=
*** 1109,1156 ****=0A=
=0A=
/* get the host name */=0A=
ptr=3Dstrchr(macro,':');=0A=
! if(ptr=3D=3DNULL)=0A=
! return ERROR;=0A=
! /* terminate the macro name at the host name delimiter */=0A=
! ptr[0]=3D'\x0';=0A=
! host_name=3Dstrdup(ptr+1);=0A=
! if(host_name=3D=3DNULL){=0A=
free(macro);=0A=
return ERROR;=0A=
}=0A=
=0A=
! /* get the service description (if applicable) */=0A=
! ptr=3Dstrchr(host_

...[email truncated]...


This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]