![]() |
Icinga-core 1.4.0
next gen monitoring
|
00001 /***************************************************************************** 00002 * 00003 * COMMENTS.C - Comment functions for Icinga 00004 * 00005 * Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org) 00006 * Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors 00007 * Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org) 00008 * 00009 * License: 00010 * 00011 * This program is free software; you can redistribute it and/or modify 00012 * it under the terms of the GNU General Public License version 2 as 00013 * published by the Free Software Foundation. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with this program; if not, write to the Free Software 00022 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00023 * 00024 *****************************************************************************/ 00025 00026 #include "../include/config.h" 00027 #include "../include/common.h" 00028 #include "../include/comments.h" 00029 #include "../include/objects.h" 00030 00031 /***** IMPLEMENTATION-SPECIFIC INCLUDES *****/ 00032 00033 #ifdef USE_XCDDEFAULT 00034 #include "../xdata/xcddefault.h" 00035 #endif 00036 00037 #ifdef NSCORE 00038 #include "../include/icinga.h" 00039 #include "../include/broker.h" 00040 #endif 00041 00042 #ifdef NSCGI 00043 #include "../include/cgiutils.h" 00044 #endif 00045 00046 00047 comment *comment_list=NULL; 00048 int defer_comment_sorting = 0; 00049 comment **comment_hashlist=NULL; 00050 00051 00052 00053 00054 #ifdef NSCORE 00055 00056 /******************************************************************/ 00057 /**************** INITIALIZATION/CLEANUP FUNCTIONS ****************/ 00058 /******************************************************************/ 00059 00060 00061 /* initializes comment data */ 00062 int initialize_comment_data(char *config_file){ 00063 int result=OK; 00064 00065 /**** IMPLEMENTATION-SPECIFIC CALLS ****/ 00066 #ifdef USE_XCDDEFAULT 00067 result=xcddefault_initialize_comment_data(config_file); 00068 #endif 00069 00070 return result; 00071 } 00072 00073 00074 /* removes old/invalid comments */ 00075 int cleanup_comment_data(char *config_file){ 00076 int result=OK; 00077 00078 /**** IMPLEMENTATION-SPECIFIC CALLS ****/ 00079 #ifdef USE_XCDDEFAULT 00080 result=xcddefault_cleanup_comment_data(config_file); 00081 #endif 00082 00083 return result; 00084 } 00085 00086 00087 00088 /******************************************************************/ 00089 /****************** COMMENT OUTPUT FUNCTIONS **********************/ 00090 /******************************************************************/ 00091 00092 00093 /* adds a new host or service comment */ 00094 int add_new_comment(int type, int entry_type, char *host_name, char *svc_description, time_t entry_time, char *author_name, char *comment_data, int persistent, int source, int expires, time_t expire_time, unsigned long *comment_id){ 00095 int result=OK; 00096 unsigned long new_comment_id=0L; 00097 00098 if(type==HOST_COMMENT) 00099 result=add_new_host_comment(entry_type,host_name,entry_time,author_name,comment_data,persistent,source,expires,expire_time,&new_comment_id); 00100 else 00101 result=add_new_service_comment(entry_type,host_name,svc_description,entry_time,author_name,comment_data,persistent,source,expires,expire_time,&new_comment_id); 00102 00103 /* add an event to expire comment data if necessary... */ 00104 if(expires==TRUE) 00105 schedule_new_event(EVENT_EXPIRE_COMMENT,FALSE,expire_time,FALSE,0,NULL,TRUE,(void *)new_comment_id,NULL,0); 00106 00107 /* save comment id */ 00108 if(comment_id!=NULL) 00109 *comment_id=new_comment_id; 00110 00111 return result; 00112 } 00113 00114 00115 /* adds a new host comment */ 00116 int add_new_host_comment(int entry_type, char *host_name, time_t entry_time, char *author_name, char *comment_data, int persistent, int source, int expires, time_t expire_time, unsigned long *comment_id){ 00117 int result=OK; 00118 unsigned long new_comment_id=0L; 00119 00120 /**** IMPLEMENTATION-SPECIFIC CALLS ****/ 00121 #ifdef USE_XCDDEFAULT 00122 result=xcddefault_add_new_host_comment(entry_type,host_name,entry_time,author_name,comment_data,persistent,source,expires,expire_time,&new_comment_id); 00123 #endif 00124 00125 /* save comment id */ 00126 if(comment_id!=NULL) 00127 *comment_id=new_comment_id; 00128 00129 #ifdef USE_EVENT_BROKER 00130 /* send data to event broker */ 00131 broker_comment_data(NEBTYPE_COMMENT_ADD,NEBFLAG_NONE,NEBATTR_NONE,HOST_COMMENT,entry_type,host_name,NULL,entry_time,author_name,comment_data,persistent,source,expires,expire_time,new_comment_id,NULL); 00132 #endif 00133 00134 return result; 00135 } 00136 00137 00138 /* adds a new service comment */ 00139 int add_new_service_comment(int entry_type, char *host_name, char *svc_description, time_t entry_time, char *author_name, char *comment_data, int persistent, int source, int expires, time_t expire_time, unsigned long *comment_id){ 00140 int result=OK; 00141 unsigned long new_comment_id=0L; 00142 00143 /**** IMPLEMENTATION-SPECIFIC CALLS ****/ 00144 #ifdef USE_XCDDEFAULT 00145 result=xcddefault_add_new_service_comment(entry_type,host_name,svc_description,entry_time,author_name,comment_data,persistent,source,expires,expire_time,&new_comment_id); 00146 #endif 00147 00148 /* save comment id */ 00149 if(comment_id!=NULL) 00150 *comment_id=new_comment_id; 00151 00152 #ifdef USE_EVENT_BROKER 00153 /* send data to event broker */ 00154 broker_comment_data(NEBTYPE_COMMENT_ADD,NEBFLAG_NONE,NEBATTR_NONE,SERVICE_COMMENT,entry_type,host_name,svc_description,entry_time,author_name,comment_data,persistent,source,expires,expire_time,new_comment_id,NULL); 00155 #endif 00156 00157 return result; 00158 } 00159 00160 00161 00162 /******************************************************************/ 00163 /***************** COMMENT DELETION FUNCTIONS *********************/ 00164 /******************************************************************/ 00165 00166 00167 /* deletes a host or service comment */ 00168 int delete_comment(int type, unsigned long comment_id){ 00169 int result=OK; 00170 comment *this_comment=NULL; 00171 comment *last_comment=NULL; 00172 comment *next_comment=NULL; 00173 int hashslot=0; 00174 comment *this_hash=NULL; 00175 comment *last_hash=NULL; 00176 00177 /* find the comment we should remove */ 00178 for(this_comment=comment_list,last_comment=comment_list;this_comment!=NULL;this_comment=next_comment){ 00179 next_comment=this_comment->next; 00180 00181 /* we found the comment we should delete */ 00182 if(this_comment->comment_id==comment_id && this_comment->comment_type==type) 00183 break; 00184 00185 last_comment=this_comment; 00186 } 00187 00188 /* remove the comment from the list in memory */ 00189 if(this_comment!=NULL){ 00190 00191 #ifdef USE_EVENT_BROKER 00192 /* send data to event broker */ 00193 broker_comment_data(NEBTYPE_COMMENT_DELETE,NEBFLAG_NONE,NEBATTR_NONE,type,this_comment->entry_type,this_comment->host_name,this_comment->service_description,this_comment->entry_time,this_comment->author,this_comment->comment_data,this_comment->persistent,this_comment->source,this_comment->expires,this_comment->expire_time,comment_id,NULL); 00194 #endif 00195 00196 /* first remove from chained hash list */ 00197 hashslot=hashfunc(this_comment->host_name,NULL,COMMENT_HASHSLOTS); 00198 last_hash=NULL; 00199 for(this_hash=comment_hashlist[hashslot];this_hash;this_hash=this_hash->nexthash){ 00200 if(this_hash==this_comment){ 00201 if(last_hash){ 00202 last_hash->nexthash=this_hash->nexthash; 00203 } else { 00204 if (this_hash->nexthash){ 00205 comment_hashlist[hashslot]=this_hash->nexthash; 00206 } else { 00207 comment_hashlist[hashslot]=NULL; 00208 } 00209 } 00210 break; 00211 } 00212 last_hash=this_hash; 00213 } 00214 00215 /* then removed from linked list */ 00216 if(comment_list==this_comment) 00217 comment_list=this_comment->next; 00218 else 00219 last_comment->next=next_comment; 00220 00221 /* free memory */ 00222 my_free(this_comment->host_name); 00223 my_free(this_comment->service_description); 00224 my_free(this_comment->author); 00225 my_free(this_comment->comment_data); 00226 my_free(this_comment); 00227 00228 result=OK; 00229 } 00230 else 00231 result=ERROR; 00232 00233 /**** IMPLEMENTATION-SPECIFIC CALLS ****/ 00234 #ifdef USE_XCDDEFAULT 00235 if(type==HOST_COMMENT) 00236 result=xcddefault_delete_host_comment(comment_id); 00237 else 00238 result=xcddefault_delete_service_comment(comment_id); 00239 #endif 00240 00241 return result; 00242 } 00243 00244 00245 /* deletes a host comment */ 00246 int delete_host_comment(unsigned long comment_id){ 00247 int result=OK; 00248 00249 /* delete the comment from memory */ 00250 result=delete_comment(HOST_COMMENT,comment_id); 00251 00252 return result; 00253 } 00254 00255 00256 00257 /* deletes a service comment */ 00258 int delete_service_comment(unsigned long comment_id){ 00259 int result=OK; 00260 00261 /* delete the comment from memory */ 00262 result=delete_comment(SERVICE_COMMENT,comment_id); 00263 00264 return result; 00265 } 00266 00267 00268 /* deletes all comments for a particular host or service */ 00269 int delete_all_comments(int type, char *host_name, char *svc_description){ 00270 int result=OK; 00271 00272 if(type==HOST_COMMENT) 00273 result=delete_all_host_comments(host_name); 00274 else 00275 result=delete_all_service_comments(host_name,svc_description); 00276 00277 return result; 00278 } 00279 00280 00281 /* deletes all comments for a particular host */ 00282 int delete_all_host_comments(char *host_name){ 00283 int result=OK; 00284 comment *temp_comment=NULL; 00285 00286 if(host_name==NULL) 00287 return ERROR; 00288 00289 /* delete host comments from memory */ 00290 for(temp_comment=get_first_comment_by_host(host_name);temp_comment!=NULL;temp_comment=get_next_comment_by_host(host_name,temp_comment)){ 00291 if(temp_comment->comment_type==HOST_COMMENT) 00292 delete_comment(HOST_COMMENT,temp_comment->comment_id); 00293 } 00294 00295 return result; 00296 } 00297 00298 00299 /* deletes all non-persistent acknowledgement comments for a particular host */ 00300 int delete_host_acknowledgement_comments(host *hst){ 00301 int result=OK; 00302 comment *temp_comment=NULL; 00303 00304 if(hst==NULL) 00305 return ERROR; 00306 00307 /* delete comments from memory */ 00308 for(temp_comment=get_first_comment_by_host(hst->name);temp_comment!=NULL;temp_comment=get_next_comment_by_host(hst->name,temp_comment)){ 00309 if(temp_comment->comment_type==HOST_COMMENT && temp_comment->entry_type==ACKNOWLEDGEMENT_COMMENT && temp_comment->persistent==FALSE) 00310 delete_comment(HOST_COMMENT,temp_comment->comment_id); 00311 } 00312 00313 return result; 00314 } 00315 00316 00317 /* deletes all comments for a particular service */ 00318 int delete_all_service_comments(char *host_name, char *svc_description){ 00319 int result=OK; 00320 comment *temp_comment=NULL; 00321 comment *next_comment=NULL; 00322 00323 if(host_name==NULL || svc_description==NULL) 00324 return ERROR; 00325 00326 /* delete service comments from memory */ 00327 for(temp_comment=comment_list;temp_comment!=NULL;temp_comment=next_comment){ 00328 next_comment=temp_comment->next; 00329 if(temp_comment->comment_type==SERVICE_COMMENT && !strcmp(temp_comment->host_name,host_name) && !strcmp(temp_comment->service_description,svc_description)) 00330 delete_comment(SERVICE_COMMENT,temp_comment->comment_id); 00331 } 00332 00333 return result; 00334 } 00335 00336 00337 /* deletes all non-persistent acknowledgement comments for a particular service */ 00338 int delete_service_acknowledgement_comments(service *svc){ 00339 int result=OK; 00340 comment *temp_comment=NULL; 00341 comment *next_comment=NULL; 00342 00343 if(svc==NULL) 00344 return ERROR; 00345 00346 /* delete comments from memory */ 00347 for(temp_comment=comment_list;temp_comment!=NULL;temp_comment=next_comment){ 00348 next_comment=temp_comment->next; 00349 if(temp_comment->comment_type==SERVICE_COMMENT && !strcmp(temp_comment->host_name,svc->host_name) && !strcmp(temp_comment->service_description,svc->description) && temp_comment->entry_type==ACKNOWLEDGEMENT_COMMENT && temp_comment->persistent==FALSE) 00350 delete_comment(SERVICE_COMMENT,temp_comment->comment_id); 00351 } 00352 00353 return result; 00354 } 00355 00356 00357 /* checks for an expired comment (and removes it) */ 00358 int check_for_expired_comment(unsigned long comment_id){ 00359 comment *temp_comment=NULL; 00360 00361 /* check all comments */ 00362 for(temp_comment=comment_list;temp_comment!=NULL;temp_comment=temp_comment->next){ 00363 00364 /* delete the now expired comment */ 00365 if(temp_comment->comment_id==comment_id && temp_comment->expires==TRUE && temp_comment->expire_time<time(NULL)){ 00366 delete_comment(temp_comment->comment_type,comment_id); 00367 break; 00368 } 00369 } 00370 00371 return OK; 00372 } 00373 00374 00375 #endif 00376 00377 00378 00379 00380 00381 /******************************************************************/ 00382 /****************** CHAINED HASH FUNCTIONS ************************/ 00383 /******************************************************************/ 00384 00385 /* adds comment to hash list in memory */ 00386 int add_comment_to_hashlist(comment *new_comment){ 00387 comment *temp_comment=NULL; 00388 comment *lastpointer=NULL; 00389 int hashslot=0; 00390 00391 /* initialize hash list */ 00392 if(comment_hashlist==NULL){ 00393 int i; 00394 00395 comment_hashlist=(comment **)malloc(sizeof(comment *)*COMMENT_HASHSLOTS); 00396 if(comment_hashlist==NULL) 00397 return 0; 00398 00399 for(i=0;i<COMMENT_HASHSLOTS;i++) 00400 comment_hashlist[i]=NULL; 00401 } 00402 00403 if(!new_comment) 00404 return 0; 00405 00406 hashslot=hashfunc(new_comment->host_name,NULL,COMMENT_HASHSLOTS); 00407 lastpointer=NULL; 00408 for(temp_comment=comment_hashlist[hashslot];temp_comment && compare_hashdata(temp_comment->host_name,NULL,new_comment->host_name,NULL)<0;temp_comment=temp_comment->nexthash){ 00409 if(compare_hashdata(temp_comment->host_name,NULL,new_comment->host_name,NULL)>=0) 00410 break; 00411 lastpointer=temp_comment; 00412 } 00413 00414 /* multiples are allowed */ 00415 if(lastpointer) 00416 lastpointer->nexthash=new_comment; 00417 else 00418 comment_hashlist[hashslot]=new_comment; 00419 new_comment->nexthash=temp_comment; 00420 00421 return 1; 00422 } 00423 00424 00425 00426 /******************************************************************/ 00427 /******************** ADDITION FUNCTIONS **************************/ 00428 /******************************************************************/ 00429 00430 00431 /* adds a host comment to the list in memory */ 00432 int add_host_comment(int entry_type, char *host_name, time_t entry_time, char *author, char *comment_data, unsigned long comment_id, int persistent, int expires, time_t expire_time, int source){ 00433 int result=OK; 00434 00435 result=add_comment(HOST_COMMENT,entry_type,host_name,NULL,entry_time,author,comment_data,comment_id,persistent,expires,expire_time,source); 00436 00437 return result; 00438 } 00439 00440 00441 00442 /* adds a service comment to the list in memory */ 00443 int add_service_comment(int entry_type, char *host_name, char *svc_description, time_t entry_time, char *author, char *comment_data, unsigned long comment_id, int persistent, int expires, time_t expire_time, int source){ 00444 int result=OK; 00445 00446 result=add_comment(SERVICE_COMMENT,entry_type,host_name,svc_description,entry_time,author,comment_data,comment_id,persistent,expires,expire_time,source); 00447 00448 return result; 00449 } 00450 00451 00452 00453 /* adds a comment to the list in memory */ 00454 int add_comment(int comment_type, int entry_type, char *host_name, char *svc_description, time_t entry_time, char *author, char *comment_data, unsigned long comment_id, int persistent, int expires, time_t expire_time, int source){ 00455 comment *new_comment=NULL; 00456 comment *last_comment=NULL; 00457 comment *temp_comment=NULL; 00458 int result=OK; 00459 00460 /* make sure we have the data we need */ 00461 if(host_name==NULL || author==NULL || comment_data==NULL || (comment_type==SERVICE_COMMENT && svc_description==NULL)) 00462 return ERROR; 00463 00464 /* allocate memory for the comment */ 00465 if((new_comment=(comment *)calloc(1, sizeof(comment)))==NULL) 00466 return ERROR; 00467 00468 /* duplicate vars */ 00469 if((new_comment->host_name=(char *)strdup(host_name))==NULL) 00470 result=ERROR; 00471 if(comment_type==SERVICE_COMMENT){ 00472 if((new_comment->service_description=(char *)strdup(svc_description))==NULL) 00473 result=ERROR; 00474 } 00475 if((new_comment->author=(char *)strdup(author))==NULL) 00476 result=ERROR; 00477 if((new_comment->comment_data=(char *)strdup(comment_data))==NULL) 00478 result=ERROR; 00479 00480 new_comment->comment_type=comment_type; 00481 new_comment->entry_type=entry_type; 00482 new_comment->source=source; 00483 new_comment->entry_time=entry_time; 00484 new_comment->comment_id=comment_id; 00485 new_comment->persistent=(persistent==TRUE)?TRUE:FALSE; 00486 new_comment->expires=(expires==TRUE)?TRUE:FALSE; 00487 new_comment->expire_time=expire_time; 00488 00489 /* add comment to hash list */ 00490 if(result==OK){ 00491 if(!add_comment_to_hashlist(new_comment)) 00492 result=ERROR; 00493 } 00494 00495 /* handle errors */ 00496 if(result==ERROR){ 00497 my_free(new_comment->comment_data); 00498 my_free(new_comment->author); 00499 my_free(new_comment->service_description); 00500 my_free(new_comment->host_name); 00501 my_free(new_comment); 00502 return ERROR; 00503 } 00504 00505 if(defer_comment_sorting){ 00506 new_comment->next=comment_list; 00507 comment_list=new_comment; 00508 } 00509 else{ 00510 /* add new comment to comment list, sorted by comment id */ 00511 last_comment=comment_list; 00512 for(temp_comment=comment_list;temp_comment!=NULL;temp_comment=temp_comment->next){ 00513 if(new_comment->comment_id<temp_comment->comment_id){ 00514 new_comment->next=temp_comment; 00515 if(temp_comment==comment_list) 00516 comment_list=new_comment; 00517 else 00518 last_comment->next=new_comment; 00519 break; 00520 } 00521 else 00522 last_comment=temp_comment; 00523 } 00524 if(comment_list==NULL){ 00525 new_comment->next=NULL; 00526 comment_list=new_comment; 00527 } 00528 else if(temp_comment==NULL){ 00529 new_comment->next=NULL; 00530 last_comment->next=new_comment; 00531 } 00532 } 00533 00534 #ifdef NSCORE 00535 #ifdef USE_EVENT_BROKER 00536 /* send data to event broker */ 00537 broker_comment_data(NEBTYPE_COMMENT_LOAD,NEBFLAG_NONE,NEBATTR_NONE,comment_type,entry_type,host_name,svc_description,entry_time,author,comment_data,persistent,source,expires,expire_time,comment_id,NULL); 00538 #endif 00539 #endif 00540 00541 return OK; 00542 } 00543 00544 static int comment_compar(const void *p1, const void *p2){ 00545 comment *c1 = *(comment **)p1; 00546 comment *c2 = *(comment **)p2; 00547 return (c1->comment_id < c2->comment_id) ? -1 : (c1->comment_id - c2->comment_id); 00548 } 00549 00550 int sort_comments(void){ 00551 comment **array, *temp_comment; 00552 unsigned long i=0, unsorted_comments=0; 00553 00554 if(!defer_comment_sorting) 00555 return OK; 00556 defer_comment_sorting=0; 00557 00558 temp_comment = comment_list; 00559 while(temp_comment!=NULL) { 00560 temp_comment = temp_comment->next; 00561 unsorted_comments++; 00562 } 00563 00564 if(!unsorted_comments) 00565 return OK; 00566 00567 if(!(array=malloc(sizeof(*array)*unsorted_comments))) 00568 return ERROR; 00569 while(comment_list){ 00570 array[i++]=comment_list; 00571 comment_list=comment_list->next; 00572 } 00573 00574 qsort((void *)array, i, sizeof(*array), comment_compar); 00575 comment_list = temp_comment = array[0]; 00576 for (i=1; i<unsorted_comments;i++){ 00577 temp_comment->next = array[i]; 00578 temp_comment = temp_comment->next; 00579 } 00580 temp_comment->next = NULL; 00581 my_free(array); 00582 return OK; 00583 } 00584 00585 /******************************************************************/ 00586 /********************* CLEANUP FUNCTIONS **************************/ 00587 /******************************************************************/ 00588 00589 /* frees memory allocated for the comment data */ 00590 void free_comment_data(void){ 00591 comment *this_comment=NULL; 00592 comment *next_comment=NULL; 00593 00594 /* free memory for the comment list */ 00595 for(this_comment=comment_list;this_comment!=NULL;this_comment=next_comment){ 00596 next_comment=this_comment->next; 00597 my_free(this_comment->host_name); 00598 my_free(this_comment->service_description); 00599 my_free(this_comment->author); 00600 my_free(this_comment->comment_data); 00601 my_free(this_comment); 00602 } 00603 00604 /* free hash list and reset list pointer */ 00605 my_free(comment_hashlist); 00606 comment_hashlist=NULL; 00607 comment_list=NULL; 00608 00609 return; 00610 } 00611 00612 00613 00614 00615 /******************************************************************/ 00616 /********************* UTILITY FUNCTIONS **************************/ 00617 /******************************************************************/ 00618 00619 /* get the number of comments associated with a particular host */ 00620 int number_of_host_comments(char *host_name){ 00621 comment *temp_comment=NULL; 00622 int total_comments=0; 00623 00624 if(host_name==NULL) 00625 return 0; 00626 00627 for(temp_comment=get_first_comment_by_host(host_name);temp_comment!=NULL;temp_comment=get_next_comment_by_host(host_name,temp_comment)){ 00628 if(temp_comment->comment_type==HOST_COMMENT) 00629 total_comments++; 00630 } 00631 00632 return total_comments; 00633 } 00634 00635 00636 /* get the number of comments associated with a particular service */ 00637 int number_of_service_comments(char *host_name, char *svc_description){ 00638 comment *temp_comment=NULL; 00639 int total_comments=0; 00640 00641 if(host_name==NULL || svc_description==NULL) 00642 return 0; 00643 00644 for(temp_comment=get_first_comment_by_host(host_name);temp_comment!=NULL;temp_comment=get_next_comment_by_host(host_name,temp_comment)){ 00645 if(temp_comment->comment_type==SERVICE_COMMENT && !strcmp(temp_comment->service_description,svc_description)) 00646 total_comments++; 00647 } 00648 00649 return total_comments; 00650 } 00651 00652 00653 00654 /******************************************************************/ 00655 /********************* TRAVERSAL FUNCTIONS ************************/ 00656 /******************************************************************/ 00657 00658 comment *get_first_comment_by_host(char *host_name){ 00659 00660 return get_next_comment_by_host(host_name,NULL); 00661 } 00662 00663 00664 comment *get_next_comment_by_host(char *host_name, comment *start){ 00665 comment *temp_comment=NULL; 00666 00667 if(host_name==NULL || comment_hashlist==NULL) 00668 return NULL; 00669 00670 if(start==NULL) 00671 temp_comment=comment_hashlist[hashfunc(host_name,NULL,COMMENT_HASHSLOTS)]; 00672 else 00673 temp_comment=start->nexthash; 00674 00675 for(;temp_comment && compare_hashdata(temp_comment->host_name,NULL,host_name,NULL)<0;temp_comment=temp_comment->nexthash); 00676 00677 if(temp_comment && compare_hashdata(temp_comment->host_name,NULL,host_name,NULL)==0) 00678 return temp_comment; 00679 00680 return NULL; 00681 } 00682 00683 00684 00685 /******************************************************************/ 00686 /********************** SEARCH FUNCTIONS **************************/ 00687 /******************************************************************/ 00688 00689 /* find a service comment by id */ 00690 comment *find_service_comment(unsigned long comment_id){ 00691 00692 return find_comment(comment_id,SERVICE_COMMENT); 00693 } 00694 00695 00696 /* find a host comment by id */ 00697 comment *find_host_comment(unsigned long comment_id){ 00698 00699 return find_comment(comment_id,HOST_COMMENT); 00700 } 00701 00702 00703 /* find a comment by id */ 00704 comment *find_comment(unsigned long comment_id, int comment_type){ 00705 comment *temp_comment=NULL; 00706 00707 for(temp_comment=comment_list;temp_comment!=NULL;temp_comment=temp_comment->next){ 00708 if(comment_type!=ANY_COMMENT && temp_comment->comment_type!=comment_type) 00709 continue; 00710 if(temp_comment->comment_id==comment_id) 00711 return temp_comment; 00712 } 00713 00714 return NULL; 00715 } 00716 00717 /* find a comment by comment_type, host_name, service_desc (NULL if hostcomment), entry_time, author, comment_data */ 00718 comment *find_comment_by_similar_content(int comment_type, char *hostname, char *service_description, char *author, char *comment_data){ 00719 comment *temp_comment=NULL; 00720 00721 for(temp_comment=comment_list;temp_comment!=NULL;temp_comment=temp_comment->next){ 00722 if(temp_comment->comment_type==comment_type 00723 && strcmp(temp_comment->host_name,hostname)==0 00724 && (service_description==NULL || strcmp(temp_comment->service_description,service_description)==0) 00725 && strcmp(temp_comment->author,author)==0 00726 && strcmp(temp_comment->comment_data,comment_data)==0) 00727 return temp_comment; 00728 } 00729 return NULL; 00730 } 00731 00732 00733