Page 1 of 1

[Nagios-devel] patch: servicegroup members expansion

Posted: Mon Mar 29, 2004 12:53 am
by Guest
--=-LpjBBuKwPrN7bGXfgSas
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

This patch adds a fallback to attempt hostgroup expansion during the
recombobulate phase for servicegroups before it errors out.

This stems from trying the hostgroup and servicegroup macro expansion
that Christompher Gurnee submitted with check_cluster2. It works great,
but the problem I had is that my hosts don't share a common naming
scheme to easily servicegroup them with a regex (plus I'm lazy and don't
want to enumerate them all by hand).

One solution was to use the servicegroup line in my HTTP service
definitions, but this meant I could only specify one hostgroup and
servicegroup pair in each definition to keep the cluster results apart,
resulting in an extra 6 service definitions for the clustered checks.

But if we expand a hostgroup I can do simply:

define servicegroup {
servicegroup_name pod1_http
alias Pod 1 Apaches
members pod1,HTTP
}

;defs for pod2,3 etc.

define service {
use service-cluster
hostgroup_name pod1,pod2,pod3,pod4,pod5,pod6,core
service_description HTTP
check_command check_http_pods!1!3!/keepalive.html!Alive
notification_options n
}

define service {
use service-critical
host_name nagiosmaster
service_description POD1_HTTP
check_command
check_service_cluster!"HTTP"!1!2!$SERVICESTATEID:pod1_http:,$
}

;defs for pod2,3 etc.

Saves me some more static values to update and reduces the number of
HTTP service definitions for clustering in my config from 7 to 1.

Thoughts?

--
Matthew Kent \ SA \ bravenet.com \ 1-250-954-3203 ext 108

--=-LpjBBuKwPrN7bGXfgSas
Content-Disposition: attachment; filename=nagios-2.0a1-servicegroupmembers.patch
Content-Type: text/x-patch; name=nagios-2.0a1-servicegroupmembers.patch; charset=
Content-Transfer-Encoding: 7bit

--- nagios-cvs_orig/xdata/xodtemplate.c Wed Mar 24 17:03:56 2004
+++ nagios-cvs/xdata/xodtemplate.c Mon Mar 29 00:20:10 2004
@@ -6435,6 +6435,9 @@
xodtemplate_servicegroup *temp_servicegroup;
xodtemplate_servicelist *temp_servicelist;
xodtemplate_servicelist *this_servicelist;
+ xodtemplate_hostgroup *temp_hostgroup;
+ xodtemplate_hostlist *temp_hostlist;
+ xodtemplate_hostlist *this_hostlist;
char *servicegroup_names;
char *member_names;
char *host_name=NULL;
@@ -6456,9 +6459,8 @@
if(temp_servicegroup->members==NULL)
continue;

- member_names=strdup(temp_servicegroup->members);
- if(member_names==NULL)
- return ERROR;
+ member_names=temp_servicegroup->members;
+ temp_servicegroup->members = NULL;

for(temp_ptr=member_names;temp_ptr;temp_ptr=strchr(temp_ptr+1,',')){

@@ -6482,43 +6484,99 @@
strip(host_name);
strip(service_description);

- /* get list of services in the servicegroup */
- temp_servicelist=xodtemplate_expand_servicegroups_and_services(NULL,host_name,service_description);
+ /* check if this is a hostgroup */
+ temp_hostgroup=xodtemplate_find_real_hostgroup(host_name);

- /* add all members to the service group */
- if(temp_servicelist==NULL){
+ if(temp_hostgroup!=NULL){
+ /* get list of services in the servicegroup */
+ temp_hostlist=xodtemplate_expand_hostgroups_and_hosts(host_name,NULL);
+ if(temp_hostlist==NULL){
#ifdef NSCORE
- snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not expand member services specified in servicegroup (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_servicegroup->_config_file),temp_servicegroup->_start_line);
- temp_buffer[sizeof(temp_buffer)-1]='\x0';
- write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
+ snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not expand hostgroup members specified in servicegroup (config file '%s', starting on line %d)\n",xodtemplate_config_file_name(temp_hostgroup->_config_file),temp_hostgroup->_start_line);
+ temp_buffer[sizeof(temp_buffer)-1]='\x0';
+ write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE);
#endif
- free(member_names);
-

...[email truncated]...


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