~yolanda.robla/ubuntu/saucy/nagios3/dep-8-tests

« back to all changes in this revision

Viewing changes to common/statusdata.c

  • Committer: Package Import Robot
  • Author(s): Alexander Wirt
  • Date: 2012-06-16 09:05:19 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20120616090519-ne14zejkhhyboolc
Tags: 3.4.1-1
* [28e077b] Imported Upstream version 3.3.1
* [d5314e0] don't call updatepo in clean target
* [45b3eb9] Don't remove config foo
* [54e3dff] Don't fix permissions in cgi postinst
* [d7be9db] Build-depend on libpng-dev (Closes: #662441)
* [4c47006] Add dutch po translation (Closes: #654855)
* [2b6573b] Refresh 10_p1_pl_shebang.dpatch
* [316fd7a] Update 40_fix_spurious_dollar_signs_added_to_command_lines
* [5ff2780] Refresh 55_strip_logarchivepath.dpatch
* [811d269] Refresh 60_fix_p1.pl_patch_mini_epn.dpatch
* [39a1e9c] Remove now unneeded patch 98_fix_XSS_CVE-2011-2179
* [785a4e8] Remove unneded patch 99_fix_XSS_CVE-2011-1523
* [6ce98ef] Remove unneeded patchs from 00list
* [1d18266] Imported Upstream version 3.4.0
* [05584c8] Refresh patches
* [58098cd] Imported Upstream version 3.4.1
* [3e9e07a] Bump standards version
* [fe991e2] wrap-and-sort
* [1ba78f7] Also create /var/run/nagios in cgi package (Closes: #626854)

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
#endif
50
50
 
51
51
#ifdef NSCGI
52
 
hoststatus      *hoststatus_list=NULL;
53
 
hoststatus      *hoststatus_list_tail=NULL;
54
 
servicestatus   *servicestatus_list=NULL;
55
 
servicestatus   *servicestatus_list_tail=NULL;
 
52
hoststatus      *hoststatus_list = NULL;
 
53
hoststatus      *hoststatus_list_tail = NULL;
 
54
servicestatus   *servicestatus_list = NULL;
 
55
servicestatus   *servicestatus_list_tail = NULL;
56
56
 
57
 
hoststatus      **hoststatus_hashlist=NULL;
58
 
servicestatus   **servicestatus_hashlist=NULL;
 
57
hoststatus      **hoststatus_hashlist = NULL;
 
58
servicestatus   **servicestatus_hashlist = NULL;
59
59
 
60
60
extern int      use_pending_states;
61
61
#endif
69
69
/******************************************************************/
70
70
 
71
71
/* initializes status data at program start */
72
 
int initialize_status_data(char *config_file){
73
 
        int result=OK;
 
72
int initialize_status_data(char *config_file) {
 
73
        int result = OK;
74
74
 
75
75
        /**** IMPLEMENTATION-SPECIFIC CALLS ****/
76
76
#ifdef USE_XSDDEFAULT
77
 
        result=xsddefault_initialize_status_data(config_file);
 
77
        result = xsddefault_initialize_status_data(config_file);
78
78
#endif
79
79
 
80
80
        return result;
81
 
        }
 
81
        }
82
82
 
83
83
 
84
84
/* update all status data (aggregated dump) */
85
 
int update_all_status_data(void){
86
 
        int result=OK;
 
85
int update_all_status_data(void) {
 
86
        int result = OK;
87
87
 
88
88
#ifdef USE_EVENT_BROKER
89
89
        /* send data to event broker */
90
 
        broker_aggregated_status_data(NEBTYPE_AGGREGATEDSTATUS_STARTDUMP,NEBFLAG_NONE,NEBATTR_NONE,NULL);
 
90
        broker_aggregated_status_data(NEBTYPE_AGGREGATEDSTATUS_STARTDUMP, NEBFLAG_NONE, NEBATTR_NONE, NULL);
91
91
#endif
92
92
 
93
93
        /**** IMPLEMENTATION-SPECIFIC CALLS ****/
94
94
#ifdef USE_XSDDEFAULT
95
 
        result=xsddefault_save_status_data();
 
95
        result = xsddefault_save_status_data();
96
96
#endif
97
97
 
98
98
#ifdef USE_EVENT_BROKER
99
99
        /* send data to event broker */
100
 
        broker_aggregated_status_data(NEBTYPE_AGGREGATEDSTATUS_ENDDUMP,NEBFLAG_NONE,NEBATTR_NONE,NULL);
 
100
        broker_aggregated_status_data(NEBTYPE_AGGREGATEDSTATUS_ENDDUMP, NEBFLAG_NONE, NEBATTR_NONE, NULL);
101
101
#endif
102
102
 
103
 
        if(result!=OK)
 
103
        if(result != OK)
104
104
                return ERROR;
105
105
 
106
106
        return OK;
107
 
        }
 
107
        }
108
108
 
109
109
 
110
110
/* cleans up status data before program termination */
111
 
int cleanup_status_data(char *config_file,int delete_status_data){
112
 
        int result=OK;
 
111
int cleanup_status_data(char *config_file, int delete_status_data) {
 
112
        int result = OK;
113
113
 
114
114
        /**** IMPLEMENTATION-SPECIFIC CALLS ****/
115
115
#ifdef USE_XSDDEFAULT
116
 
        result=xsddefault_cleanup_status_data(config_file,delete_status_data);
 
116
        result = xsddefault_cleanup_status_data(config_file, delete_status_data);
117
117
#endif
118
118
 
119
119
        return result;
120
 
        }
 
120
        }
121
121
 
122
122
 
123
123
 
124
124
/* updates program status info */
125
 
int update_program_status(int aggregated_dump){
 
125
int update_program_status(int aggregated_dump) {
126
126
 
127
127
#ifdef USE_EVENT_BROKER
128
128
        /* send data to event broker (non-aggregated dumps only) */
129
 
        if(aggregated_dump==FALSE)
130
 
                broker_program_status(NEBTYPE_PROGRAMSTATUS_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,NULL);
 
129
        if(aggregated_dump == FALSE)
 
130
                broker_program_status(NEBTYPE_PROGRAMSTATUS_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, NULL);
131
131
#endif
132
132
 
133
133
        /* currently a noop if aggregated updates is TRUE */
134
134
 
135
135
        /* update all status data if we're not aggregating updates */
136
 
        if(aggregate_status_updates==FALSE)
 
136
        if(aggregate_status_updates == FALSE)
137
137
                update_all_status_data();
138
138
 
139
139
        return OK;
140
 
        }
 
140
        }
141
141
 
142
142
 
143
143
 
144
144
/* updates host status info */
145
 
int update_host_status(host *hst,int aggregated_dump){
 
145
int update_host_status(host *hst, int aggregated_dump) {
146
146
 
147
147
#ifdef USE_EVENT_BROKER
148
148
        /* send data to event broker (non-aggregated dumps only) */
149
 
        if(aggregated_dump==FALSE)
150
 
                  broker_host_status(NEBTYPE_HOSTSTATUS_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,hst,NULL);
 
149
        if(aggregated_dump == FALSE)
 
150
                broker_host_status(NEBTYPE_HOSTSTATUS_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, NULL);
151
151
#endif
152
152
 
153
153
        /* currently a noop if aggregated updates is TRUE */
154
154
 
155
155
        /* update all status data if we're not aggregating updates */
156
 
        if(aggregate_status_updates==FALSE)
 
156
        if(aggregate_status_updates == FALSE)
157
157
                update_all_status_data();
158
158
 
159
159
        return OK;
160
 
        }
 
160
        }
161
161
 
162
162
 
163
163
 
164
164
/* updates service status info */
165
 
int update_service_status(service *svc,int aggregated_dump){
 
165
int update_service_status(service *svc, int aggregated_dump) {
166
166
 
167
167
#ifdef USE_EVENT_BROKER
168
168
        /* send data to event broker (non-aggregated dumps only) */
169
 
        if(aggregated_dump==FALSE)
170
 
                broker_service_status(NEBTYPE_SERVICESTATUS_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,svc,NULL);
 
169
        if(aggregated_dump == FALSE)
 
170
                broker_service_status(NEBTYPE_SERVICESTATUS_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, NULL);
171
171
#endif
172
172
 
173
173
        /* currently a noop if aggregated updates is TRUE */
174
174
 
175
175
        /* update all status data if we're not aggregating updates */
176
 
        if(aggregate_status_updates==FALSE)
 
176
        if(aggregate_status_updates == FALSE)
177
177
                update_all_status_data();
178
178
 
179
179
        return OK;
180
 
        }
 
180
        }
181
181
 
182
182
 
183
183
 
184
184
/* updates contact status info */
185
 
int update_contact_status(contact *cntct,int aggregated_dump){
 
185
int update_contact_status(contact *cntct, int aggregated_dump) {
186
186
 
187
187
#ifdef USE_EVENT_BROKER
188
188
        /* send data to event broker (non-aggregated dumps only) */
189
 
        if(aggregated_dump==FALSE)
190
 
                broker_contact_status(NEBTYPE_CONTACTSTATUS_UPDATE,NEBFLAG_NONE,NEBATTR_NONE,cntct,NULL);
 
189
        if(aggregated_dump == FALSE)
 
190
                broker_contact_status(NEBTYPE_CONTACTSTATUS_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, cntct, NULL);
191
191
#endif
192
192
 
193
193
        /* currently a noop if aggregated updates is TRUE */
194
194
 
195
195
        /* update all status data if we're not aggregating updates */
196
 
        if(aggregate_status_updates==FALSE)
 
196
        if(aggregate_status_updates == FALSE)
197
197
                update_all_status_data();
198
198
 
199
199
        return OK;
200
 
        }
 
200
        }
201
201
#endif
202
202
 
203
203
 
212
212
 
213
213
 
214
214
/* reads in all status data */
215
 
int read_status_data(char *config_file,int options){
216
 
        int result=OK;
 
215
int read_status_data(char *config_file, int options) {
 
216
        int result = OK;
217
217
 
218
218
        /**** IMPLEMENTATION-SPECIFIC CALLS ****/
219
219
#ifdef USE_XSDDEFAULT
220
 
        result=xsddefault_read_status_data(config_file,options);
 
220
        result = xsddefault_read_status_data(config_file, options);
221
221
#endif
222
222
#ifdef USE_XSDDB
223
 
        result=xsddb_read_status_data(config_file,options);
 
223
        result = xsddb_read_status_data(config_file, options);
224
224
#endif
225
225
 
226
226
        return result;
227
 
        }
 
227
        }
228
228
 
229
229
 
230
230
 
233
233
/******************************************************************/
234
234
 
235
235
/* adds hoststatus to hash list in memory */
236
 
int add_hoststatus_to_hashlist(hoststatus *new_hoststatus){
237
 
        hoststatus *temp_hoststatus=NULL;
238
 
        hoststatus *lastpointer=NULL;
239
 
        int hashslot=0;
240
 
        int i=0;
 
236
int add_hoststatus_to_hashlist(hoststatus *new_hoststatus) {
 
237
        hoststatus *temp_hoststatus = NULL;
 
238
        hoststatus *lastpointer = NULL;
 
239
        int hashslot = 0;
 
240
        int i = 0;
241
241
 
242
242
        /* initialize hash list */
243
 
        if(hoststatus_hashlist==NULL){
 
243
        if(hoststatus_hashlist == NULL) {
244
244
 
245
 
                hoststatus_hashlist=(hoststatus **)malloc(sizeof(hoststatus *)*HOSTSTATUS_HASHSLOTS);
246
 
                if(hoststatus_hashlist==NULL)
 
245
                hoststatus_hashlist = (hoststatus **)malloc(sizeof(hoststatus *) * HOSTSTATUS_HASHSLOTS);
 
246
                if(hoststatus_hashlist == NULL)
247
247
                        return 0;
248
 
                
249
 
                for(i=0;i<HOSTSTATUS_HASHSLOTS;i++)
250
 
                        hoststatus_hashlist[i]=NULL;
251
 
                }
 
248
 
 
249
                for(i = 0; i < HOSTSTATUS_HASHSLOTS; i++)
 
250
                        hoststatus_hashlist[i] = NULL;
 
251
                }
252
252
 
253
253
        if(!new_hoststatus)
254
254
                return 0;
255
255
 
256
 
        hashslot=hashfunc(new_hoststatus->host_name,NULL,HOSTSTATUS_HASHSLOTS);
257
 
        lastpointer=NULL;
258
 
        for(temp_hoststatus=hoststatus_hashlist[hashslot];temp_hoststatus && compare_hashdata(temp_hoststatus->host_name,NULL,new_hoststatus->host_name,NULL)<0;temp_hoststatus=temp_hoststatus->nexthash)
259
 
                lastpointer=temp_hoststatus;
 
256
        hashslot = hashfunc(new_hoststatus->host_name, NULL, HOSTSTATUS_HASHSLOTS);
 
257
        lastpointer = NULL;
 
258
        for(temp_hoststatus = hoststatus_hashlist[hashslot]; temp_hoststatus && compare_hashdata(temp_hoststatus->host_name, NULL, new_hoststatus->host_name, NULL) < 0; temp_hoststatus = temp_hoststatus->nexthash)
 
259
                lastpointer = temp_hoststatus;
260
260
 
261
 
        if(!temp_hoststatus || (compare_hashdata(temp_hoststatus->host_name,NULL,new_hoststatus->host_name,NULL)!=0)){
 
261
        if(!temp_hoststatus || (compare_hashdata(temp_hoststatus->host_name, NULL, new_hoststatus->host_name, NULL) != 0)) {
262
262
                if(lastpointer)
263
 
                        lastpointer->nexthash=new_hoststatus;
 
263
                        lastpointer->nexthash = new_hoststatus;
264
264
                else
265
 
                        hoststatus_hashlist[hashslot]=new_hoststatus;
266
 
                new_hoststatus->nexthash=temp_hoststatus;
 
265
                        hoststatus_hashlist[hashslot] = new_hoststatus;
 
266
                new_hoststatus->nexthash = temp_hoststatus;
267
267
 
268
268
                return 1;
269
 
                }
 
269
                }
270
270
 
271
271
        /* else already exists */
272
272
        return 0;
273
 
        }
274
 
 
275
 
 
276
 
int add_servicestatus_to_hashlist(servicestatus *new_servicestatus){
277
 
        servicestatus *temp_servicestatus=NULL, *lastpointer=NULL;
278
 
        int hashslot=0;
279
 
        int i=0;
 
273
        }
 
274
 
 
275
 
 
276
int add_servicestatus_to_hashlist(servicestatus *new_servicestatus) {
 
277
        servicestatus *temp_servicestatus = NULL, *lastpointer = NULL;
 
278
        int hashslot = 0;
 
279
        int i = 0;
280
280
 
281
281
        /* initialize hash list */
282
 
        if(servicestatus_hashlist==NULL){
 
282
        if(servicestatus_hashlist == NULL) {
283
283
 
284
 
                servicestatus_hashlist=(servicestatus **)malloc(sizeof(servicestatus *)*SERVICESTATUS_HASHSLOTS);
285
 
                if(servicestatus_hashlist==NULL)
 
284
                servicestatus_hashlist = (servicestatus **)malloc(sizeof(servicestatus *) * SERVICESTATUS_HASHSLOTS);
 
285
                if(servicestatus_hashlist == NULL)
286
286
                        return 0;
287
 
                
288
 
                for(i=0;i< SERVICESTATUS_HASHSLOTS;i++)
289
 
                        servicestatus_hashlist[i]=NULL;
290
 
                }
 
287
 
 
288
                for(i = 0; i < SERVICESTATUS_HASHSLOTS; i++)
 
289
                        servicestatus_hashlist[i] = NULL;
 
290
                }
291
291
 
292
292
        if(!new_servicestatus)
293
293
                return 0;
294
294
 
295
 
        hashslot=hashfunc(new_servicestatus->host_name,new_servicestatus->description,SERVICESTATUS_HASHSLOTS);
296
 
        lastpointer=NULL;
297
 
        for(temp_servicestatus=servicestatus_hashlist[hashslot];temp_servicestatus && compare_hashdata(temp_servicestatus->host_name,temp_servicestatus->description,new_servicestatus->host_name,new_servicestatus->description)<0;temp_servicestatus=temp_servicestatus->nexthash)
298
 
                lastpointer=temp_servicestatus;
 
295
        hashslot = hashfunc(new_servicestatus->host_name, new_servicestatus->description, SERVICESTATUS_HASHSLOTS);
 
296
        lastpointer = NULL;
 
297
        for(temp_servicestatus = servicestatus_hashlist[hashslot]; temp_servicestatus && compare_hashdata(temp_servicestatus->host_name, temp_servicestatus->description, new_servicestatus->host_name, new_servicestatus->description) < 0; temp_servicestatus = temp_servicestatus->nexthash)
 
298
                lastpointer = temp_servicestatus;
299
299
 
300
 
        if(!temp_servicestatus || (compare_hashdata(temp_servicestatus->host_name,temp_servicestatus->description,new_servicestatus->host_name,new_servicestatus->description)!=0)){
 
300
        if(!temp_servicestatus || (compare_hashdata(temp_servicestatus->host_name, temp_servicestatus->description, new_servicestatus->host_name, new_servicestatus->description) != 0)) {
301
301
                if(lastpointer)
302
 
                        lastpointer->nexthash=new_servicestatus;
 
302
                        lastpointer->nexthash = new_servicestatus;
303
303
                else
304
 
                        servicestatus_hashlist[hashslot]=new_servicestatus;
305
 
                new_servicestatus->nexthash=temp_servicestatus;
 
304
                        servicestatus_hashlist[hashslot] = new_servicestatus;
 
305
                new_servicestatus->nexthash = temp_servicestatus;
306
306
 
307
307
 
308
308
                return 1;
309
 
                }
 
309
                }
310
310
 
311
311
        /* else already exists */
312
312
        return 0;
313
 
        }
 
313
        }
314
314
 
315
315
 
316
316
 
320
320
 
321
321
 
322
322
/* adds a host status entry to the list in memory */
323
 
int add_host_status(hoststatus *new_hoststatus){
 
323
int add_host_status(hoststatus *new_hoststatus) {
324
324
        char date_string[MAX_DATETIME_LENGTH];
325
325
 
326
326
        /* make sure we have what we need */
327
 
        if(new_hoststatus==NULL)
 
327
        if(new_hoststatus == NULL)
328
328
                return ERROR;
329
 
        if(new_hoststatus->host_name==NULL)
 
329
        if(new_hoststatus->host_name == NULL)
330
330
                return ERROR;
331
331
 
332
332
        /* massage host status a bit */
333
 
        if(new_hoststatus!=NULL){
334
 
                switch(new_hoststatus->status){
335
 
                case 0:
336
 
                        new_hoststatus->status=HOST_UP;
337
 
                        break;
338
 
                case 1:
339
 
                        new_hoststatus->status=HOST_DOWN;
340
 
                        break;
341
 
                case 2:
342
 
                        new_hoststatus->status=HOST_UNREACHABLE;
343
 
                        break;
344
 
                default:
345
 
                        new_hoststatus->status=HOST_UP;
346
 
                        break;
347
 
                        }
348
 
                if(new_hoststatus->has_been_checked==FALSE){
349
 
                        if(use_pending_states==TRUE)
350
 
                                new_hoststatus->status=HOST_PENDING;
 
333
        if(new_hoststatus != NULL) {
 
334
                switch(new_hoststatus->status) {
 
335
                        case 0:
 
336
                                new_hoststatus->status = HOST_UP;
 
337
                                break;
 
338
                        case 1:
 
339
                                new_hoststatus->status = HOST_DOWN;
 
340
                                break;
 
341
                        case 2:
 
342
                                new_hoststatus->status = HOST_UNREACHABLE;
 
343
                                break;
 
344
                        default:
 
345
                                new_hoststatus->status = HOST_UP;
 
346
                                break;
 
347
                        }
 
348
                if(new_hoststatus->has_been_checked == FALSE) {
 
349
                        if(use_pending_states == TRUE)
 
350
                                new_hoststatus->status = HOST_PENDING;
351
351
                        my_free(new_hoststatus->plugin_output);
352
 
                        if(new_hoststatus->should_be_scheduled==TRUE){
353
 
                                get_time_string(&new_hoststatus->next_check,date_string,sizeof(date_string),LONG_DATE_TIME);
354
 
                                asprintf(&new_hoststatus->plugin_output,"Host check scheduled for %s",date_string);
355
 
                                }
356
 
                        else{
 
352
                        if(new_hoststatus->should_be_scheduled == TRUE) {
 
353
                                get_time_string(&new_hoststatus->next_check, date_string, sizeof(date_string), LONG_DATE_TIME);
 
354
                                asprintf(&new_hoststatus->plugin_output, "Host check scheduled for %s", date_string);
 
355
                                }
 
356
                        else {
357
357
                                /* passive-only hosts that have just been scheduled for a forced check */
358
 
                                if(new_hoststatus->checks_enabled==FALSE && new_hoststatus->next_check!=(time_t)0L && (new_hoststatus->check_options & CHECK_OPTION_FORCE_EXECUTION)){
359
 
                                        get_time_string(&new_hoststatus->next_check,date_string,sizeof(date_string),LONG_DATE_TIME);
360
 
                                        asprintf(&new_hoststatus->plugin_output,"Forced host check scheduled for %s",date_string);
 
358
                                if(new_hoststatus->checks_enabled == FALSE && new_hoststatus->next_check != (time_t)0L && (new_hoststatus->check_options & CHECK_OPTION_FORCE_EXECUTION)) {
 
359
                                        get_time_string(&new_hoststatus->next_check, date_string, sizeof(date_string), LONG_DATE_TIME);
 
360
                                        asprintf(&new_hoststatus->plugin_output, "Forced host check scheduled for %s", date_string);
361
361
                                        }
362
362
                                /* passive-only hosts not scheduled to be checked */
363
363
                                else
364
 
                                        new_hoststatus->plugin_output=(char *)strdup("Host is not scheduled to be checked...");
 
364
                                        new_hoststatus->plugin_output = (char *)strdup("Host is not scheduled to be checked...");
365
365
                                }
366
 
                        }
367
 
                }
 
366
                        }
 
367
                }
368
368
 
369
 
        new_hoststatus->next=NULL;
370
 
        new_hoststatus->nexthash=NULL;
 
369
        new_hoststatus->next = NULL;
 
370
        new_hoststatus->nexthash = NULL;
371
371
 
372
372
        /* add new hoststatus to hoststatus chained hash list */
373
373
        if(!add_hoststatus_to_hashlist(new_hoststatus))
374
374
                return ERROR;
375
375
 
376
376
        /* object cache file is already sorted, so just add new items to end of list */
377
 
        if(hoststatus_list==NULL){
378
 
                hoststatus_list=new_hoststatus;
379
 
                hoststatus_list_tail=new_hoststatus;
380
 
                }
381
 
        else{
382
 
                hoststatus_list_tail->next=new_hoststatus;
383
 
                hoststatus_list_tail=new_hoststatus;
384
 
                }
 
377
        if(hoststatus_list == NULL) {
 
378
                hoststatus_list = new_hoststatus;
 
379
                hoststatus_list_tail = new_hoststatus;
 
380
                }
 
381
        else {
 
382
                hoststatus_list_tail->next = new_hoststatus;
 
383
                hoststatus_list_tail = new_hoststatus;
 
384
                }
385
385
 
386
386
        return OK;
387
 
        }
 
387
        }
388
388
 
389
389
 
390
390
/* adds a service status entry to the list in memory */
391
 
int add_service_status(servicestatus *new_svcstatus){
 
391
int add_service_status(servicestatus *new_svcstatus) {
392
392
        char date_string[MAX_DATETIME_LENGTH];
393
393
 
394
394
        /* make sure we have what we need */
395
 
        if(new_svcstatus==NULL)
 
395
        if(new_svcstatus == NULL)
396
396
                return ERROR;
397
 
        if(new_svcstatus->host_name==NULL || new_svcstatus->description==NULL)
 
397
        if(new_svcstatus->host_name == NULL || new_svcstatus->description == NULL)
398
398
                return ERROR;
399
399
 
400
400
 
401
401
        /* massage service status a bit */
402
 
        if(new_svcstatus!=NULL){
403
 
                switch(new_svcstatus->status){
404
 
                case 0:
405
 
                        new_svcstatus->status=SERVICE_OK;
406
 
                        break;
407
 
                case 1:
408
 
                        new_svcstatus->status=SERVICE_WARNING;
409
 
                        break;
410
 
                case 2:
411
 
                        new_svcstatus->status=SERVICE_CRITICAL;
412
 
                        break;
413
 
                case 3:
414
 
                        new_svcstatus->status=SERVICE_UNKNOWN;
415
 
                        break;
416
 
                default:
417
 
                        new_svcstatus->status=SERVICE_OK;
418
 
                        break;
419
 
                        }
420
 
                if(new_svcstatus->has_been_checked==FALSE){
421
 
                        if(use_pending_states==TRUE)
422
 
                                new_svcstatus->status=SERVICE_PENDING;
 
402
        if(new_svcstatus != NULL) {
 
403
                switch(new_svcstatus->status) {
 
404
                        case 0:
 
405
                                new_svcstatus->status = SERVICE_OK;
 
406
                                break;
 
407
                        case 1:
 
408
                                new_svcstatus->status = SERVICE_WARNING;
 
409
                                break;
 
410
                        case 2:
 
411
                                new_svcstatus->status = SERVICE_CRITICAL;
 
412
                                break;
 
413
                        case 3:
 
414
                                new_svcstatus->status = SERVICE_UNKNOWN;
 
415
                                break;
 
416
                        default:
 
417
                                new_svcstatus->status = SERVICE_OK;
 
418
                                break;
 
419
                        }
 
420
                if(new_svcstatus->has_been_checked == FALSE) {
 
421
                        if(use_pending_states == TRUE)
 
422
                                new_svcstatus->status = SERVICE_PENDING;
423
423
                        my_free(new_svcstatus->plugin_output);
424
 
                        if(new_svcstatus->should_be_scheduled==TRUE){
425
 
                                get_time_string(&new_svcstatus->next_check,date_string,sizeof(date_string),LONG_DATE_TIME);
426
 
                                asprintf(&new_svcstatus->plugin_output,"Service check scheduled for %s",date_string);
427
 
                                }
428
 
                        else{
 
424
                        if(new_svcstatus->should_be_scheduled == TRUE) {
 
425
                                get_time_string(&new_svcstatus->next_check, date_string, sizeof(date_string), LONG_DATE_TIME);
 
426
                                asprintf(&new_svcstatus->plugin_output, "Service check scheduled for %s", date_string);
 
427
                                }
 
428
                        else {
429
429
                                /* passive-only services that have just been scheduled for a forced check */
430
 
                                if(new_svcstatus->checks_enabled==FALSE && new_svcstatus->next_check!=(time_t)0L && (new_svcstatus->check_options & CHECK_OPTION_FORCE_EXECUTION)){
431
 
                                        get_time_string(&new_svcstatus->next_check,date_string,sizeof(date_string),LONG_DATE_TIME);
432
 
                                        asprintf(&new_svcstatus->plugin_output,"Forced service check scheduled for %s",date_string);
 
430
                                if(new_svcstatus->checks_enabled == FALSE && new_svcstatus->next_check != (time_t)0L && (new_svcstatus->check_options & CHECK_OPTION_FORCE_EXECUTION)) {
 
431
                                        get_time_string(&new_svcstatus->next_check, date_string, sizeof(date_string), LONG_DATE_TIME);
 
432
                                        asprintf(&new_svcstatus->plugin_output, "Forced service check scheduled for %s", date_string);
433
433
                                        }
434
434
                                /* passive-only services not scheduled to be checked */
435
435
                                else
436
 
                                        new_svcstatus->plugin_output=(char *)strdup("Service is not scheduled to be checked...");
 
436
                                        new_svcstatus->plugin_output = (char *)strdup("Service is not scheduled to be checked...");
437
437
                                }
438
 
                        }
439
 
                }
 
438
                        }
 
439
                }
440
440
 
441
 
        new_svcstatus->next=NULL;
442
 
        new_svcstatus->nexthash=NULL;
 
441
        new_svcstatus->next = NULL;
 
442
        new_svcstatus->nexthash = NULL;
443
443
 
444
444
        /* add new servicestatus to servicestatus chained hash list */
445
445
        if(!add_servicestatus_to_hashlist(new_svcstatus))
446
446
                return ERROR;
447
447
 
448
448
        /* object cache file is already sorted, so just add new items to end of list */
449
 
        if(servicestatus_list==NULL){
450
 
                servicestatus_list=new_svcstatus;
451
 
                servicestatus_list_tail=new_svcstatus;
452
 
                }
453
 
        else{
454
 
                servicestatus_list_tail->next=new_svcstatus;
455
 
                servicestatus_list_tail=new_svcstatus;
456
 
                }
 
449
        if(servicestatus_list == NULL) {
 
450
                servicestatus_list = new_svcstatus;
 
451
                servicestatus_list_tail = new_svcstatus;
 
452
                }
 
453
        else {
 
454
                servicestatus_list_tail->next = new_svcstatus;
 
455
                servicestatus_list_tail = new_svcstatus;
 
456
                }
457
457
 
458
458
        return OK;
459
 
        }
 
459
        }
460
460
 
461
461
 
462
462
 
468
468
 
469
469
 
470
470
/* free all memory for status data */
471
 
void free_status_data(void){
472
 
        hoststatus *this_hoststatus=NULL;
473
 
        hoststatus *next_hoststatus=NULL;
474
 
        servicestatus *this_svcstatus=NULL;
475
 
        servicestatus *next_svcstatus=NULL;
 
471
void free_status_data(void) {
 
472
        hoststatus *this_hoststatus = NULL;
 
473
        hoststatus *next_hoststatus = NULL;
 
474
        servicestatus *this_svcstatus = NULL;
 
475
        servicestatus *next_svcstatus = NULL;
476
476
 
477
477
        /* free memory for the host status list */
478
 
        for(this_hoststatus=hoststatus_list;this_hoststatus!=NULL;this_hoststatus=next_hoststatus){
479
 
                next_hoststatus=this_hoststatus->next;
 
478
        for(this_hoststatus = hoststatus_list; this_hoststatus != NULL; this_hoststatus = next_hoststatus) {
 
479
                next_hoststatus = this_hoststatus->next;
480
480
                my_free(this_hoststatus->host_name);
481
481
                my_free(this_hoststatus->plugin_output);
482
482
                my_free(this_hoststatus->long_plugin_output);
483
483
                my_free(this_hoststatus->perf_data);
484
484
                my_free(this_hoststatus);
485
 
                }
 
485
                }
486
486
 
487
487
        /* free memory for the service status list */
488
 
        for(this_svcstatus=servicestatus_list;this_svcstatus!=NULL;this_svcstatus=next_svcstatus){
489
 
                next_svcstatus=this_svcstatus->next;
 
488
        for(this_svcstatus = servicestatus_list; this_svcstatus != NULL; this_svcstatus = next_svcstatus) {
 
489
                next_svcstatus = this_svcstatus->next;
490
490
                my_free(this_svcstatus->host_name);
491
491
                my_free(this_svcstatus->description);
492
492
                my_free(this_svcstatus->plugin_output);
493
493
                my_free(this_svcstatus->long_plugin_output);
494
494
                my_free(this_svcstatus->perf_data);
495
495
                my_free(this_svcstatus);
496
 
                }
 
496
                }
497
497
 
498
498
        /* free hash lists reset list pointers */
499
499
        my_free(hoststatus_hashlist);
500
500
        my_free(servicestatus_hashlist);
501
 
        hoststatus_list=NULL;
502
 
        servicestatus_list=NULL;
 
501
        hoststatus_list = NULL;
 
502
        servicestatus_list = NULL;
503
503
 
504
504
        return;
505
 
        }
 
505
        }
506
506
 
507
507
 
508
508
 
513
513
 
514
514
 
515
515
/* find a host status entry */
516
 
hoststatus *find_hoststatus(char *host_name){
517
 
        hoststatus *temp_hoststatus=NULL;
 
516
hoststatus *find_hoststatus(char *host_name) {
 
517
        hoststatus *temp_hoststatus = NULL;
518
518
 
519
 
        if(host_name==NULL || hoststatus_hashlist==NULL)
 
519
        if(host_name == NULL || hoststatus_hashlist == NULL)
520
520
                return NULL;
521
521
 
522
 
        for(temp_hoststatus=hoststatus_hashlist[hashfunc(host_name,NULL,HOSTSTATUS_HASHSLOTS)];temp_hoststatus && compare_hashdata(temp_hoststatus->host_name,NULL,host_name,NULL)<0;temp_hoststatus=temp_hoststatus->nexthash);
 
522
        for(temp_hoststatus = hoststatus_hashlist[hashfunc(host_name, NULL, HOSTSTATUS_HASHSLOTS)]; temp_hoststatus && compare_hashdata(temp_hoststatus->host_name, NULL, host_name, NULL) < 0; temp_hoststatus = temp_hoststatus->nexthash);
523
523
 
524
 
        if(temp_hoststatus && (compare_hashdata(temp_hoststatus->host_name,NULL,host_name,NULL)==0))
 
524
        if(temp_hoststatus && (compare_hashdata(temp_hoststatus->host_name, NULL, host_name, NULL) == 0))
525
525
                return temp_hoststatus;
526
526
 
527
527
        return NULL;
528
 
        }
 
528
        }
529
529
 
530
530
 
531
531
/* find a service status entry */
532
 
servicestatus *find_servicestatus(char *host_name,char *svc_desc){
533
 
        servicestatus *temp_servicestatus=NULL;
 
532
servicestatus *find_servicestatus(char *host_name, char *svc_desc) {
 
533
        servicestatus *temp_servicestatus = NULL;
534
534
 
535
 
        if(host_name==NULL || svc_desc==NULL || servicestatus_hashlist==NULL)
 
535
        if(host_name == NULL || svc_desc == NULL || servicestatus_hashlist == NULL)
536
536
                return NULL;
537
537
 
538
 
        for(temp_servicestatus=servicestatus_hashlist[hashfunc(host_name,svc_desc,SERVICESTATUS_HASHSLOTS)];temp_servicestatus && compare_hashdata(temp_servicestatus->host_name,temp_servicestatus->description,host_name,svc_desc)<0;temp_servicestatus=temp_servicestatus->nexthash);
 
538
        for(temp_servicestatus = servicestatus_hashlist[hashfunc(host_name, svc_desc, SERVICESTATUS_HASHSLOTS)]; temp_servicestatus && compare_hashdata(temp_servicestatus->host_name, temp_servicestatus->description, host_name, svc_desc) < 0; temp_servicestatus = temp_servicestatus->nexthash);
539
539
 
540
 
        if(temp_servicestatus && (compare_hashdata(temp_servicestatus->host_name,temp_servicestatus->description,host_name,svc_desc)==0))
 
540
        if(temp_servicestatus && (compare_hashdata(temp_servicestatus->host_name, temp_servicestatus->description, host_name, svc_desc) == 0))
541
541
                return temp_servicestatus;
542
542
 
543
543
        return NULL;
544
 
        }
 
544
        }
545
545
 
546
546
 
547
547
 
552
552
 
553
553
 
554
554
/* gets the total number of services of a certain state for a specific host */
555
 
int get_servicestatus_count(char *host_name, int type){
556
 
        servicestatus *temp_status=NULL;
557
 
        int count=0;
 
555
int get_servicestatus_count(char *host_name, int type) {
 
556
        servicestatus *temp_status = NULL;
 
557
        int count = 0;
558
558
 
559
 
        if(host_name==NULL)
 
559
        if(host_name == NULL)
560
560
                return 0;
561
561
 
562
 
        for(temp_status=servicestatus_list;temp_status!=NULL;temp_status=temp_status->next){
563
 
                if(temp_status->status & type){
564
 
                        if(!strcmp(host_name,temp_status->host_name))
 
562
        for(temp_status = servicestatus_list; temp_status != NULL; temp_status = temp_status->next) {
 
563
                if(temp_status->status & type) {
 
564
                        if(!strcmp(host_name, temp_status->host_name))
565
565
                                count++;
566
 
                        }
567
 
                }
 
566
                        }
 
567
                }
568
568
 
569
569
        return count;
570
 
        }
 
570
        }
571
571
 
572
572
 
573
573