~ubuntu-branches/ubuntu/saucy/nagios3/saucy-proposed

« back to all changes in this revision

Viewing changes to xdata/xodtemplate.c

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Wirt
  • Date: 2009-08-16 14:14:23 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090816141423-efjzq1r3jekwd7l7
Tags: 3.2.0-1
* New upstream release (Closes: #542957)
  - Timeperiods should work as expected now (Closes: #539882)
  - Recovery notifications fixed (Closes: #543657)
* Update standards version 
  - Add README.source
* Manpage errors fixed (Closes: #540554)
* Split up the webfrontend into its own package (Closes: #479338, #485466)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *
3
3
 * XODTEMPLATE.C - Template-based object configuration data input routines
4
4
 *
5
 
 * Copyright (c) 2001-2008 Ethan Galstad (egalstad@nagios.org)
6
 
 * Last Modified: 06-23-2008
 
5
 * Copyright (c) 2001-2009 Ethan Galstad (egalstad@nagios.org)
 
6
 * Last Modified: 01-01-2009
7
7
 *
8
8
 * Description:
9
9
 *
124
124
 
125
125
int presorted_objects=FALSE;
126
126
 
 
127
/*
 
128
 * Macro magic used to determine if a service is assigned
 
129
 * via hostgroup_name or host_name. Those assigned via host_name
 
130
 * take precedence.
 
131
 */
 
132
#define X_SERVICE_IS_FROM_HOSTGROUP      (1 << 1)  /* flag to know if service come from a hostgroup def, apply on srv->have_initial_state */
 
133
#define xodtemplate_set_service_is_from_hostgroup(srv) \
 
134
        srv->have_initial_state |= X_SERVICE_IS_FROM_HOSTGROUP
 
135
#define xodtemplate_unset_service_is_from_hostgroup(srv) \
 
136
        srv->have_initial_state &= ~X_SERVICE_IS_FROM_HOSTGROUP
 
137
#define xodtemplate_is_service_is_from_hostgroup(srv) \
 
138
        ((srv->have_initial_state & X_SERVICE_IS_FROM_HOSTGROUP) != 0)
 
139
 
127
140
 
128
141
/******************************************************************/
129
142
/************* TOP-LEVEL CONFIG DATA INPUT FUNCTION ***************/
145
158
        int result=OK;
146
159
 
147
160
 
148
 
        if(main_config_file==NULL)
 
161
        if(main_config_file==NULL){
 
162
#ifdef NSCORE
 
163
                printf("Error: No main config file passed to object routines!\n");
 
164
#endif
149
165
                return ERROR;
 
166
                }
150
167
 
151
168
        /* get variables from main config file */
152
169
        xodtemplate_grab_config_info(main_config_file);
176
193
        /* allocate memory for 256 config files (increased dynamically) */
177
194
        xodtemplate_current_config_file=0;
178
195
        xodtemplate_config_files=(char **)malloc(256*sizeof(char **));
179
 
        if(xodtemplate_config_files==NULL)
 
196
        if(xodtemplate_config_files==NULL){
 
197
#ifdef NSCORE
 
198
                printf("Unable to allocate memory!\n");
 
199
#endif
180
200
                return ERROR;
 
201
                }
181
202
 
182
203
        /* are the objects we're reading already pre-sorted? */
183
204
        presorted_objects=FALSE;
199
220
                /* determine the directory of the main config file */
200
221
                if((config_file=(char *)strdup(main_config_file))==NULL){
201
222
                        my_free(xodtemplate_config_files);
 
223
#ifdef NSCORE
 
224
                        printf("Unable to allocate memory!\n");
 
225
#endif
202
226
                        return ERROR;
203
227
                        }
204
228
                config_base_dir=(char *)strdup(dirname(config_file));
208
232
                if((thefile=mmap_fopen(main_config_file))==NULL){
209
233
                        my_free(config_base_dir);
210
234
                        my_free(xodtemplate_config_files);
 
235
#ifdef NSCORE
 
236
                        printf("Unable to open main config file '%s'\n",main_config_file);
 
237
#endif
211
238
                        return ERROR;
212
239
                        }
213
240
 
535
562
        register int x=0;
536
563
        struct stat stat_buf;
537
564
 
 
565
#ifdef NSCORE
 
566
        if(verify_config==TRUE)
 
567
                printf("Processing object config directory '%s'...\n",dirname);
 
568
#endif
 
569
 
538
570
        /* open the directory for reading */
539
571
        dirp=opendir(dirname);
540
572
        if(dirp==NULL){
616
648
        char *ptr=NULL;
617
649
 
618
650
 
 
651
#ifdef NSCORE
 
652
        if(verify_config==TRUE)
 
653
                printf("Processing object config file '%s'...\n",filename);
 
654
#endif
 
655
 
619
656
        /* save config file name */
620
657
        xodtemplate_config_files[xodtemplate_current_config_file++]=(char *)strdup(filename);
621
658
 
1605
1642
                new_service->have_service_groups=FALSE;
1606
1643
                new_service->check_command=NULL;
1607
1644
                new_service->have_check_command=FALSE;
 
1645
                new_service->have_important_check_command=FALSE;
1608
1646
                new_service->check_period=NULL;
1609
1647
                new_service->have_check_period=FALSE;
1610
1648
                new_service->event_handler=NULL;
1691
1729
                new_service->custom_variables=NULL;
1692
1730
                new_service->has_been_resolved=FALSE;
1693
1731
                new_service->register_object=TRUE;
 
1732
                /* true service, so is not from host group, must be set AFTER have_initial_state*/
 
1733
                xodtemplate_unset_service_is_from_hostgroup(new_service);
1694
1734
 
1695
1735
                new_service->_config_file=config_file;
1696
1736
                new_service->_start_line=start_line;
3815
3855
                        }
3816
3856
                else if(!strcmp(variable,"check_command")){
3817
3857
                        if(strcmp(value,XODTEMPLATE_NULL)){
3818
 
                                if((temp_service->check_command=(char *)strdup(value))==NULL)
 
3858
                                if(value[0] == '!') {
 
3859
                                        temp_service->have_important_check_command=TRUE;
 
3860
                                        temp_ptr=value+1;
 
3861
                                        }
 
3862
                                else
 
3863
                                        temp_ptr=value;
 
3864
                                if((temp_service->check_command=(char *)strdup(temp_ptr))==NULL)
3819
3865
                                        result=ERROR;
3820
3866
                                }
3821
3867
                        temp_service->have_check_command=TRUE;
5129
5175
 
5130
5176
#ifdef NSCORE
5131
5177
 
5132
 
 
5133
5178
/* duplicates service definitions */
5134
5179
int xodtemplate_duplicate_services(void){
5135
5180
        int result=OK;
5197
5242
        /* SKIPLIST STUFF FOR FAST SORT/SEARCH */
5198
5243
        /***************************************/
5199
5244
 
 
5245
        /* First loop for single host service definition*/
 
5246
        for(temp_service=xodtemplate_service_list;temp_service!=NULL;temp_service=temp_service->next){
 
5247
 
 
5248
                /* skip services that shouldn't be registered */
 
5249
                if(temp_service->register_object==FALSE)
 
5250
                        continue;
 
5251
 
 
5252
                /* skip service definitions without enough data */
 
5253
                if(temp_service->host_name==NULL || temp_service->service_description==NULL)
 
5254
                        continue;
 
5255
 
 
5256
                if(xodtemplate_is_service_is_from_hostgroup(temp_service)){
 
5257
                        continue;
 
5258
                }
 
5259
 
 
5260
 
 
5261
                result=skiplist_insert(xobject_skiplists[X_SERVICE_SKIPLIST],(void *)temp_service);
 
5262
                switch(result){
 
5263
                case SKIPLIST_ERROR_DUPLICATE:
 
5264
#ifdef NSCORE
 
5265
                        logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: Duplicate definition found for service '%s' on host '%s' (config file '%s', starting on line %d)\n",temp_service->service_description,temp_service->host_name,xodtemplate_config_file_name(temp_service->_config_file),temp_service->_start_line);
 
5266
#endif
 
5267
                        result=ERROR;
 
5268
                        break;
 
5269
                case SKIPLIST_OK:
 
5270
                        result=OK;
 
5271
                        break;
 
5272
                default:
 
5273
                        result=ERROR;
 
5274
                        break;
 
5275
                        }
 
5276
                }
 
5277
 
 
5278
 
 
5279
        /* second loop for host group service definition*/
5200
5280
        /* add services to skiplist for fast searches */
5201
5281
        for(temp_service=xodtemplate_service_list;temp_service!=NULL;temp_service=temp_service->next){
5202
5282
 
5208
5288
                if(temp_service->host_name==NULL || temp_service->service_description==NULL)
5209
5289
                        continue;
5210
5290
 
 
5291
                if(!xodtemplate_is_service_is_from_hostgroup(temp_service)){
 
5292
                        continue;
 
5293
                }
 
5294
                /*The flag X_SERVICE_IS_FROM_HOSTGROUP is set, unset it*/
 
5295
                xodtemplate_unset_service_is_from_hostgroup(temp_service);
 
5296
 
5211
5297
                result=skiplist_insert(xobject_skiplists[X_SERVICE_SKIPLIST],(void *)temp_service);
5212
5298
                switch(result){
5213
5299
                case SKIPLIST_ERROR_DUPLICATE:
6095
6181
        new_service->register_object=temp_service->register_object;
6096
6182
        new_service->_config_file=temp_service->_config_file;
6097
6183
        new_service->_start_line=temp_service->_start_line;
 
6184
        /*tag service apply on host group*/
 
6185
        xodtemplate_set_service_is_from_hostgroup(new_service);
6098
6186
 
6099
6187
        /* string defaults */
6100
6188
        new_service->hostgroup_name=NULL;
8038
8126
                xodtemplate_get_inherited_string(&template_service->have_contact_groups,&template_service->contact_groups,&this_service->have_contact_groups,&this_service->contact_groups);
8039
8127
                xodtemplate_get_inherited_string(&template_service->have_contacts,&template_service->contacts,&this_service->have_contacts,&this_service->contacts);
8040
8128
 
8041
 
                if(this_service->have_check_command==FALSE && template_service->have_check_command==TRUE){
8042
 
                        if(this_service->check_command==NULL && template_service->check_command!=NULL)
8043
 
                                this_service->check_command=(char *)strdup(template_service->check_command);
8044
 
                        this_service->have_check_command=TRUE;
8045
 
                        }
 
8129
                if(template_service->have_check_command==TRUE){
 
8130
                        if(template_service->have_important_check_command==TRUE){
 
8131
                                my_free(this_service->check_command);
 
8132
                                this_service->have_check_command=FALSE;
 
8133
                                }
 
8134
                        if(this_service->have_check_command==FALSE){
 
8135
                                if(this_service->check_command==NULL && template_service->check_command!=NULL)
 
8136
                                        this_service->check_command=(char *)strdup(template_service->check_command);
 
8137
                                this_service->have_check_command=TRUE;
 
8138
                                }
 
8139
                        }
8046
8140
                if(this_service->have_check_period==FALSE && template_service->have_check_period==TRUE){
8047
8141
                        if(this_service->check_period==NULL && template_service->check_period!=NULL)
8048
8142
                                this_service->check_period=(char *)strdup(template_service->check_period);
10049
10143
                return ERROR;
10050
10144
                }
10051
10145
#endif
10052
 
        for(contact_name=strtok(this_contactgroup->members,",");contact_name!=NULL;contact_name=strtok(NULL,",")){
10053
 
                strip(contact_name);
10054
 
                new_contactsmember=add_contact_to_contactgroup(new_contactgroup,contact_name);
10055
 
                if(new_contactsmember==NULL){
 
10146
        /* Need to check for NULL because strtok could use a NULL value to check the previous string's token value */
 
10147
        if(this_contactgroup->members!=NULL){
 
10148
                for(contact_name=strtok(this_contactgroup->members,",");contact_name!=NULL;contact_name=strtok(NULL,",")){
 
10149
                        strip(contact_name);
 
10150
                        new_contactsmember=add_contact_to_contactgroup(new_contactgroup,contact_name);
 
10151
                        if(new_contactsmember==NULL){
10056
10152
#ifdef NSCORE
10057
 
                        logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add contact '%s' to contactgroup (config file '%s', starting on line %d)\n",contact_name,xodtemplate_config_file_name(this_contactgroup->_config_file),this_contactgroup->_start_line);
 
10153
                                logit(NSLOG_CONFIG_ERROR,TRUE,"Error: Could not add contact '%s' to contactgroup (config file '%s', starting on line %d)\n",contact_name,xodtemplate_config_file_name(this_contactgroup->_config_file),this_contactgroup->_start_line);
10058
10154
#endif
10059
 
                        return ERROR;
10060
 
                        }
10061
 
                }
 
10155
                                return ERROR;
 
10156
                                }
 
10157
                        }
 
10158
                }
10062
10159
 
10063
10160
        return OK;
10064
10161
        }
11592
11689
 
11593
11690
                                switch(temp_daterange->type){
11594
11691
                                case DATERANGE_CALENDAR_DATE:
11595
 
                                        fprintf(fp,"\t%d-%02d-%02d",temp_daterange->syear,temp_daterange->smon,temp_daterange->smday);
 
11692
                                        fprintf(fp,"\t%d-%02d-%02d",temp_daterange->syear,temp_daterange->smon+1,temp_daterange->smday);
11596
11693
                                        if((temp_daterange->smday!=temp_daterange->emday) || (temp_daterange->smon!=temp_daterange->emon) || (temp_daterange->syear!=temp_daterange->eyear))
11597
 
                                                fprintf(fp," - %d-%02d-%02d",temp_daterange->eyear,temp_daterange->emon,temp_daterange->emday);
 
11694
                                                fprintf(fp," - %d-%02d-%02d",temp_daterange->eyear,temp_daterange->emon+1,temp_daterange->emday);
11598
11695
                                        if(temp_daterange->skip_interval>1)
11599
11696
                                                fprintf(fp," / %d",temp_daterange->skip_interval);
11600
11697
                                        break;