69
69
/******************************************************************/
71
71
/* initializes status data at program start */
72
int initialize_status_data(char *config_file){
72
int initialize_status_data(char *config_file) {
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);
84
84
/* update all status data (aggregated dump) */
85
int update_all_status_data(void){
85
int update_all_status_data(void) {
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);
93
93
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
94
94
#ifdef USE_XSDDEFAULT
95
result=xsddefault_save_status_data();
95
result = xsddefault_save_status_data();
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);
110
110
/* cleans up status data before program termination */
111
int cleanup_status_data(char *config_file,int delete_status_data){
111
int cleanup_status_data(char *config_file, int delete_status_data) {
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);
124
124
/* updates program status info */
125
int update_program_status(int aggregated_dump){
125
int update_program_status(int aggregated_dump) {
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);
133
133
/* currently a noop if aggregated updates is TRUE */
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();
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) {
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);
153
153
/* currently a noop if aggregated updates is TRUE */
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();
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) {
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);
173
173
/* currently a noop if aggregated updates is TRUE */
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();
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) {
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);
193
193
/* currently a noop if aggregated updates is TRUE */
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();
233
233
/******************************************************************/
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;
236
int add_hoststatus_to_hashlist(hoststatus *new_hoststatus) {
237
hoststatus *temp_hoststatus = NULL;
238
hoststatus *lastpointer = NULL;
242
242
/* initialize hash list */
243
if(hoststatus_hashlist==NULL){
243
if(hoststatus_hashlist == NULL) {
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)
249
for(i=0;i<HOSTSTATUS_HASHSLOTS;i++)
250
hoststatus_hashlist[i]=NULL;
249
for(i = 0; i < HOSTSTATUS_HASHSLOTS; i++)
250
hoststatus_hashlist[i] = NULL;
253
253
if(!new_hoststatus)
256
hashslot=hashfunc(new_hoststatus->host_name,NULL,HOSTSTATUS_HASHSLOTS);
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);
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;
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)) {
263
lastpointer->nexthash=new_hoststatus;
263
lastpointer->nexthash = new_hoststatus;
265
hoststatus_hashlist[hashslot]=new_hoststatus;
266
new_hoststatus->nexthash=temp_hoststatus;
265
hoststatus_hashlist[hashslot] = new_hoststatus;
266
new_hoststatus->nexthash = temp_hoststatus;
271
271
/* else already exists */
276
int add_servicestatus_to_hashlist(servicestatus *new_servicestatus){
277
servicestatus *temp_servicestatus=NULL, *lastpointer=NULL;
276
int add_servicestatus_to_hashlist(servicestatus *new_servicestatus) {
277
servicestatus *temp_servicestatus = NULL, *lastpointer = NULL;
281
281
/* initialize hash list */
282
if(servicestatus_hashlist==NULL){
282
if(servicestatus_hashlist == NULL) {
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)
288
for(i=0;i< SERVICESTATUS_HASHSLOTS;i++)
289
servicestatus_hashlist[i]=NULL;
288
for(i = 0; i < SERVICESTATUS_HASHSLOTS; i++)
289
servicestatus_hashlist[i] = NULL;
292
292
if(!new_servicestatus)
295
hashslot=hashfunc(new_servicestatus->host_name,new_servicestatus->description,SERVICESTATUS_HASHSLOTS);
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);
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;
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)) {
302
lastpointer->nexthash=new_servicestatus;
302
lastpointer->nexthash = new_servicestatus;
304
servicestatus_hashlist[hashslot]=new_servicestatus;
305
new_servicestatus->nexthash=temp_servicestatus;
304
servicestatus_hashlist[hashslot] = new_servicestatus;
305
new_servicestatus->nexthash = temp_servicestatus;
311
311
/* else already exists */
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];
326
326
/* make sure we have what we need */
327
if(new_hoststatus==NULL)
327
if(new_hoststatus == NULL)
329
if(new_hoststatus->host_name==NULL)
329
if(new_hoststatus->host_name == NULL)
332
332
/* massage host status a bit */
333
if(new_hoststatus!=NULL){
334
switch(new_hoststatus->status){
336
new_hoststatus->status=HOST_UP;
339
new_hoststatus->status=HOST_DOWN;
342
new_hoststatus->status=HOST_UNREACHABLE;
345
new_hoststatus->status=HOST_UP;
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) {
336
new_hoststatus->status = HOST_UP;
339
new_hoststatus->status = HOST_DOWN;
342
new_hoststatus->status = HOST_UNREACHABLE;
345
new_hoststatus->status = HOST_UP;
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);
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);
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);
362
362
/* passive-only hosts not scheduled to be checked */
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...");
369
new_hoststatus->next=NULL;
370
new_hoststatus->nexthash=NULL;
369
new_hoststatus->next = NULL;
370
new_hoststatus->nexthash = NULL;
372
372
/* add new hoststatus to hoststatus chained hash list */
373
373
if(!add_hoststatus_to_hashlist(new_hoststatus))
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;
382
hoststatus_list_tail->next=new_hoststatus;
383
hoststatus_list_tail=new_hoststatus;
377
if(hoststatus_list == NULL) {
378
hoststatus_list = new_hoststatus;
379
hoststatus_list_tail = new_hoststatus;
382
hoststatus_list_tail->next = new_hoststatus;
383
hoststatus_list_tail = new_hoststatus;
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];
394
394
/* make sure we have what we need */
395
if(new_svcstatus==NULL)
395
if(new_svcstatus == NULL)
397
if(new_svcstatus->host_name==NULL || new_svcstatus->description==NULL)
397
if(new_svcstatus->host_name == NULL || new_svcstatus->description == NULL)
401
401
/* massage service status a bit */
402
if(new_svcstatus!=NULL){
403
switch(new_svcstatus->status){
405
new_svcstatus->status=SERVICE_OK;
408
new_svcstatus->status=SERVICE_WARNING;
411
new_svcstatus->status=SERVICE_CRITICAL;
414
new_svcstatus->status=SERVICE_UNKNOWN;
417
new_svcstatus->status=SERVICE_OK;
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) {
405
new_svcstatus->status = SERVICE_OK;
408
new_svcstatus->status = SERVICE_WARNING;
411
new_svcstatus->status = SERVICE_CRITICAL;
414
new_svcstatus->status = SERVICE_UNKNOWN;
417
new_svcstatus->status = SERVICE_OK;
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);
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);
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);
434
434
/* passive-only services not scheduled to be checked */
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...");
441
new_svcstatus->next=NULL;
442
new_svcstatus->nexthash=NULL;
441
new_svcstatus->next = NULL;
442
new_svcstatus->nexthash = NULL;
444
444
/* add new servicestatus to servicestatus chained hash list */
445
445
if(!add_servicestatus_to_hashlist(new_svcstatus))
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;
454
servicestatus_list_tail->next=new_svcstatus;
455
servicestatus_list_tail=new_svcstatus;
449
if(servicestatus_list == NULL) {
450
servicestatus_list = new_svcstatus;
451
servicestatus_list_tail = new_svcstatus;
454
servicestatus_list_tail->next = new_svcstatus;
455
servicestatus_list_tail = new_svcstatus;
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;
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);
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);
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;
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;
519
if(host_name==NULL || hoststatus_hashlist==NULL)
519
if(host_name == NULL || hoststatus_hashlist == NULL)
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);
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;
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;
535
if(host_name==NULL || svc_desc==NULL || servicestatus_hashlist==NULL)
535
if(host_name == NULL || svc_desc == NULL || servicestatus_hashlist == NULL)
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);
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;