![]() |
Icinga-core 1.4.0
next gen monitoring
|
00001 /************************************************************************ 00002 * 00003 * CONVERTCFG.C - Config File Convertor 00004 * 00005 * Copyright (c) 2001-2005 Ethan Galstad (egalstad@nagios.org) 00006 * 00007 * License: 00008 * 00009 * This program is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License version 2 as 00011 * published by the Free Software Foundation. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00021 * 00022 ************************************************************************/ 00023 00024 #include <stdio.h> 00025 #include <stdlib.h> 00026 #include <string.h> 00027 00028 char *my_strsep(char **, const char *); 00029 00030 int main(int argc, char **argv){ 00031 FILE *fp; 00032 char *temp_ptr; 00033 char *temp_ptr2; 00034 char input[8096]; 00035 int notify_recovery; 00036 int notify_warning; 00037 int notify_critical; 00038 int notify_down; 00039 int notify_unreachable; 00040 int option; 00041 int have_template=0; 00042 int x=0,y=0; 00043 char *host_name; 00044 char *service_description; 00045 char *host_name2; 00046 char *service_description2; 00047 00048 if(argc!=3){ 00049 printf("Nagios Config File Converter\n"); 00050 printf("Written by Ethan Galstad (egalstad@nagios.org)\n"); 00051 printf("Last Modified: 08-12-2005\n"); 00052 printf("\n"); 00053 printf("Usage: %s <config file> <object type>\n",argv[0]); 00054 printf("\n"); 00055 printf("Valid object types include:\n"); 00056 printf("\n"); 00057 printf("\ttimeperiods\n"); 00058 printf("\tcommands\n"); 00059 printf("\tcontacts\n"); 00060 printf("\tcontactgroups\n"); 00061 printf("\thosts\n"); 00062 printf("\thostgroups\n"); 00063 printf("\thostgroupescalationss\n"); 00064 printf("\tservices\n"); 00065 printf("\tservicedependencies\n"); 00066 printf("\tserviceescalations\n"); 00067 printf("\n"); 00068 printf("\thostextinfo\n"); 00069 printf("\tserviceextinfo\n"); 00070 printf("\n"); 00071 printf("Notes:\n"); 00072 printf("\n"); 00073 printf("This utility is designed to aide you in converting your old 'host'\n"); 00074 printf("config file(s) to the new template-based config file style. It is\n"); 00075 printf("also capable of converting extended host and service information\n"); 00076 printf("definitions in your old CGI config file.\n"); 00077 printf("\n"); 00078 printf("Supply the name of your old 'host' config file (or your old CGI config\n"); 00079 printf("file if you're converting extended host/service definitions) on the\n"); 00080 printf("command line, along with the type of object you would like to produce\n"); 00081 printf("a new config file for. Your old config file is not overwritten - new\n"); 00082 printf("configuration data is printed to standard output, so you can redirect it\n"); 00083 printf("wherever you like.\n"); 00084 printf("\n"); 00085 printf("Please note that you can only specify one type of object at a time\n"); 00086 printf("on the command line.\n"); 00087 printf("\n"); 00088 printf("IMPORTANT: This utility will generate Nagios 1.x compliant config files.\n"); 00089 printf("However, the config files are not totally compatible with Nagios 2.x, so\n"); 00090 printf("you will have to do some manual tweaking.\n"); 00091 printf("\n"); 00092 return -1; 00093 } 00094 00095 fp=fopen(argv[1],"r"); 00096 if(fp==NULL){ 00097 printf("Error: Could not open file '%s' for reading.\n",argv[1]); 00098 return -1; 00099 } 00100 00101 for(fgets(input,sizeof(input)-1,fp);!feof(fp);fgets(input,sizeof(input)-1,fp)){ 00102 00103 /* skip blank lines and comments */ 00104 if(input[0]=='#' || input[0]=='\x0' || input[0]=='\n' || input[0]=='\r') 00105 continue; 00106 00107 /* timeperiods */ 00108 if(strstr(input,"timeperiod[") && !strcmp(argv[2],"timeperiods")){ 00109 00110 temp_ptr2=&input[0]; 00111 temp_ptr=my_strsep(&temp_ptr2,"["); 00112 temp_ptr=my_strsep(&temp_ptr2,"]"); 00113 00114 printf("# '%s' timeperiod definition\n",temp_ptr); 00115 printf("define timeperiod{\n"); 00116 /*printf("\tname\t\t%s\n",temp_ptr);*/ 00117 printf("\ttimeperiod_name\t%s\n",temp_ptr); 00118 00119 temp_ptr=my_strsep(&temp_ptr2,";"); 00120 printf("\talias\t\t%s\n",temp_ptr+1); 00121 00122 temp_ptr=my_strsep(&temp_ptr2,";"); 00123 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00124 printf("\tsunday\t\t%s\n",temp_ptr); 00125 00126 temp_ptr=my_strsep(&temp_ptr2,";"); 00127 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00128 printf("\tmonday\t\t%s\n",temp_ptr); 00129 00130 temp_ptr=my_strsep(&temp_ptr2,";"); 00131 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00132 printf("\ttuesday\t\t%s\n",temp_ptr); 00133 00134 temp_ptr=my_strsep(&temp_ptr2,";"); 00135 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00136 printf("\twednesday\t%s\n",temp_ptr); 00137 00138 temp_ptr=my_strsep(&temp_ptr2,";"); 00139 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00140 printf("\tthursday\t%s\n",temp_ptr); 00141 00142 temp_ptr=my_strsep(&temp_ptr2,";"); 00143 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00144 printf("\tfriday\t\t%s\n",temp_ptr); 00145 00146 temp_ptr=my_strsep(&temp_ptr2,";\r\n"); 00147 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00148 printf("\tsaturday\t%s\n",temp_ptr); 00149 00150 printf("\t}\n\n\n"); 00151 } 00152 00153 /* commands */ 00154 if(strstr(input,"command[") && !strcmp(argv[2],"commands")){ 00155 00156 temp_ptr=strtok(input,"["); 00157 temp_ptr=strtok(NULL,"]"); 00158 00159 printf("# '%s' command definition\n",temp_ptr); 00160 printf("define command{\n"); 00161 /*printf("\tname\t\t%s\n",temp_ptr);*/ 00162 printf("\tcommand_name\t%s\n",temp_ptr); 00163 00164 temp_ptr=strtok(NULL,"\n"); 00165 00166 printf("\tcommand_line\t%s\n",temp_ptr+1); 00167 00168 printf("\t}\n\n\n"); 00169 } 00170 00171 /* contacts */ 00172 if(strstr(input,"contact[") && !strcmp(argv[2],"contacts")){ 00173 00174 temp_ptr2=&input[0]; 00175 temp_ptr=my_strsep(&temp_ptr2,"["); 00176 temp_ptr=my_strsep(&temp_ptr2,"]"); 00177 00178 printf("# '%s' contact definition\n",temp_ptr); 00179 printf("define contact{\n"); 00180 /*printf("\tname\t\t\t\t%s\n",temp_ptr);*/ 00181 printf("\tcontact_name\t\t\t%s\n",temp_ptr); 00182 00183 temp_ptr=my_strsep(&temp_ptr2,";"); 00184 printf("\talias\t\t\t\t%s\n",temp_ptr+1); 00185 00186 temp_ptr=my_strsep(&temp_ptr2,";"); 00187 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00188 printf("\tservice_notification_period\t%s\n",temp_ptr); 00189 00190 temp_ptr=my_strsep(&temp_ptr2,";"); 00191 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00192 printf("\thost_notification_period\t%s\n",temp_ptr); 00193 00194 temp_ptr=my_strsep(&temp_ptr2,";"); 00195 notify_recovery=atoi(temp_ptr); 00196 temp_ptr=my_strsep(&temp_ptr2,";"); 00197 notify_critical=atoi(temp_ptr); 00198 temp_ptr=my_strsep(&temp_ptr2,";"); 00199 notify_warning=atoi(temp_ptr); 00200 00201 option=0; 00202 printf("\tservice_notification_options\t"); 00203 if(notify_recovery==1 || notify_critical==1 || notify_warning==1){ 00204 if(notify_warning==1){ 00205 printf("w,u"); 00206 option=1; 00207 } 00208 if(notify_critical==1){ 00209 if(option==1) 00210 printf(","); 00211 printf("c"); 00212 option=1; 00213 } 00214 if(notify_recovery==1){ 00215 if(option==1) 00216 printf(","); 00217 printf("r"); 00218 } 00219 } 00220 else 00221 printf("n"); 00222 printf("\n"); 00223 00224 temp_ptr=my_strsep(&temp_ptr2,";"); 00225 notify_recovery=atoi(temp_ptr); 00226 temp_ptr=my_strsep(&temp_ptr2,";"); 00227 notify_down=atoi(temp_ptr); 00228 temp_ptr=my_strsep(&temp_ptr2,";"); 00229 notify_unreachable=atoi(temp_ptr); 00230 00231 option=0; 00232 printf("\thost_notification_options\t"); 00233 if(notify_recovery==1 || notify_down==1 || notify_unreachable==1){ 00234 if(notify_down==1){ 00235 printf("d"); 00236 option=1; 00237 } 00238 if(notify_unreachable==1){ 00239 if(option==1) 00240 printf(","); 00241 printf("u"); 00242 option=1; 00243 } 00244 if(notify_recovery==1){ 00245 if(option==1) 00246 printf(","); 00247 printf("r"); 00248 } 00249 } 00250 else 00251 printf("n"); 00252 printf("\n"); 00253 00254 temp_ptr=my_strsep(&temp_ptr2,";"); 00255 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00256 printf("\tservice_notification_commands\t%s\n",temp_ptr); 00257 00258 temp_ptr=my_strsep(&temp_ptr2,";"); 00259 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00260 printf("\thost_notification_commands\t%s\n",temp_ptr); 00261 00262 temp_ptr=my_strsep(&temp_ptr2,";"); 00263 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00264 printf("\temail\t\t\t\t%s\n",temp_ptr); 00265 00266 temp_ptr=my_strsep(&temp_ptr2,";\r\n"); 00267 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00268 printf("\tpager\t\t\t\t%s\n",temp_ptr); 00269 00270 printf("\t}\n\n\n"); 00271 } 00272 00273 00274 /* contactgroups */ 00275 if(strstr(input,"contactgroup[") && !strcmp(argv[2],"contactgroups")){ 00276 00277 temp_ptr=strtok(input,"["); 00278 temp_ptr=strtok(NULL,"]"); 00279 00280 printf("# '%s' contact group definition\n",temp_ptr); 00281 printf("define contactgroup{\n"); 00282 /*printf("\tname\t\t\t%s\n",temp_ptr);*/ 00283 printf("\tcontactgroup_name\t%s\n",temp_ptr); 00284 00285 temp_ptr=strtok(NULL,";"); 00286 printf("\talias\t\t\t%s\n",temp_ptr+1); 00287 00288 temp_ptr=strtok(NULL,"\n"); 00289 00290 printf("\tmembers\t\t\t%s\n",temp_ptr); 00291 00292 printf("\t}\n\n\n"); 00293 } 00294 00295 /* hosts */ 00296 if(strstr(input,"host[") && !strcmp(argv[2],"hosts")){ 00297 00298 if(have_template==0){ 00299 00300 printf("# Generic host definition template\n"); 00301 printf("define host{\n"); 00302 printf("\tname\t\t\t\tgeneric-host\t; The name of this host template - referenced in other host definitions, used for template recursion/resolution\n"); 00303 printf("\tactive_checks_enabled\t\t1\t; Active host checks are enabled\n"); 00304 printf("\tpassive_checks_enabled\t\t1\t; Passive host checks are enabled/accepted\n"); 00305 printf("\tnotifications_enabled\t\t1\t; Host notifications are enabled\n"); 00306 printf("\tevent_handler_enabled\t\t1\t; Host event handler is enabled\n"); 00307 printf("\tflap_detection_enabled\t\t1\t; Flap detection is enabled\n"); 00308 /*printf("\tfailure_prediction_enabled\t1\t; Failure prediction is enabled\n");*/ 00309 printf("\tprocess_perf_data\t\t1\t; Process performance data\n"); 00310 printf("\tretain_status_information\t1\t; Retain status information across program restarts\n"); 00311 printf("\tretain_nonstatus_information\t1\t; Retain non-status information across program restarts\n"); 00312 printf("\n"); 00313 printf("\tregister\t\t\t0\t; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!\n"); 00314 printf("\t}\n\n"); 00315 00316 have_template=1; 00317 } 00318 00319 temp_ptr2=&input[0]; 00320 temp_ptr=my_strsep(&temp_ptr2,"["); 00321 temp_ptr=my_strsep(&temp_ptr2,"]"); 00322 00323 printf("# '%s' host definition\n",temp_ptr); 00324 printf("define host{\n"); 00325 printf("\tuse\t\t\tgeneric-host\t\t; Name of host template to use\n\n"); 00326 printf("\thost_name\t\t%s\n",temp_ptr); 00327 00328 temp_ptr=my_strsep(&temp_ptr2,";"); 00329 printf("\talias\t\t\t%s\n",temp_ptr+1); 00330 00331 temp_ptr=my_strsep(&temp_ptr2,";"); 00332 printf("\taddress\t\t\t%s\n",temp_ptr); 00333 00334 temp_ptr=my_strsep(&temp_ptr2,";"); 00335 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00336 printf("\tparents\t\t\t%s\n",temp_ptr); 00337 00338 temp_ptr=my_strsep(&temp_ptr2,";"); 00339 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00340 printf("\tcheck_command\t\t%s\n",temp_ptr); 00341 00342 temp_ptr=my_strsep(&temp_ptr2,";"); 00343 printf("\tmax_check_attempts\t%d\n",atoi(temp_ptr)); 00344 temp_ptr=my_strsep(&temp_ptr2,";"); 00345 printf("\tnotification_interval\t%d\n",atoi(temp_ptr)); 00346 00347 temp_ptr=my_strsep(&temp_ptr2,";"); 00348 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00349 printf("\tnotification_period\t%s\n",temp_ptr); 00350 00351 temp_ptr=my_strsep(&temp_ptr2,";"); 00352 notify_recovery=atoi(temp_ptr); 00353 temp_ptr=my_strsep(&temp_ptr2,";"); 00354 notify_down=atoi(temp_ptr); 00355 temp_ptr=my_strsep(&temp_ptr2,";"); 00356 notify_unreachable=atoi(temp_ptr); 00357 00358 option=0; 00359 printf("\tnotification_options\t"); 00360 if(notify_recovery==1 || notify_down==1 || notify_unreachable==1){ 00361 if(notify_down==1){ 00362 printf("d"); 00363 option=1; 00364 } 00365 if(notify_unreachable==1){ 00366 if(option==1) 00367 printf(","); 00368 printf("u"); 00369 option=1; 00370 } 00371 if(notify_recovery==1){ 00372 if(option==1) 00373 printf(","); 00374 printf("r"); 00375 } 00376 } 00377 else 00378 printf("n"); 00379 printf("\n"); 00380 00381 temp_ptr=my_strsep(&temp_ptr2,";\r\n"); 00382 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00383 printf("\tevent_handler\t\t%s\n",temp_ptr); 00384 00385 printf("\t}\n\n\n"); 00386 } 00387 00388 /* hostgroups */ 00389 if(strstr(input,"hostgroup[") && !strcmp(argv[2],"hostgroups")){ 00390 00391 temp_ptr=strtok(input,"["); 00392 temp_ptr=strtok(NULL,"]"); 00393 00394 printf("# '%s' host group definition\n",temp_ptr); 00395 printf("define hostgroup{\n"); 00396 /*printf("\tname\t\t%s\n",temp_ptr);*/ 00397 printf("\thostgroup_name\t%s\n",temp_ptr); 00398 00399 temp_ptr=strtok(NULL,";"); 00400 printf("\talias\t\t%s\n",temp_ptr+1); 00401 00402 temp_ptr=strtok(NULL,";"); 00403 /*printf("\tcontact_groups\t%s\n",temp_ptr);*/ 00404 00405 temp_ptr=strtok(NULL,"\n"); 00406 00407 printf("\tmembers\t\t%s\n",temp_ptr); 00408 00409 printf("\t}\n\n\n"); 00410 } 00411 00412 00413 /* services */ 00414 if(strstr(input,"service[") && !strcmp(argv[2],"services")){ 00415 00416 if(have_template==0){ 00417 00418 printf("# Generic service definition template\n"); 00419 printf("define service{\n"); 00420 printf("\tname\t\t\t\tgeneric-service\t; The 'name' of this service template, referenced in other service definitions\n"); 00421 printf("\tactive_checks_enabled\t\t1\t; Active service checks are enabled\n"); 00422 printf("\tpassive_checks_enabled\t\t1\t; Passive service checks are enabled/accepted\n"); 00423 printf("\tparallelize_check\t\t1\t; Active service checks should be parallelized (disabling this can lead to major performance problems)\n"); 00424 printf("\tobsess_over_service\t\t1\t; We should obsess over this service (if necessary)\n"); 00425 printf("\tcheck_freshness\t\t\t0\t; Default is to NOT check service 'freshness'\n"); 00426 printf("\tnotifications_enabled\t\t1\t; Service notifications are enabled\n"); 00427 printf("\tevent_handler_enabled\t\t1\t; Service event handler is enabled\n"); 00428 printf("\tflap_detection_enabled\t\t1\t; Flap detection is enabled\n"); 00429 /*printf("\tfailure_prediction_enabled\t1\t; Failure prediction is enabled\n");*/ 00430 printf("\tprocess_perf_data\t\t1\t; Process performance data\n"); 00431 printf("\tretain_status_information\t1\t; Retain status information across program restarts\n"); 00432 printf("\tretain_nonstatus_information\t1\t; Retain non-status information across program restarts\n"); 00433 printf("\n"); 00434 printf("\tregister\t\t\t0\t; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!\n"); 00435 printf("\t}\n\n"); 00436 00437 have_template=1; 00438 } 00439 00440 temp_ptr2=&input[0]; 00441 temp_ptr=my_strsep(&temp_ptr2,"["); 00442 temp_ptr=my_strsep(&temp_ptr2,"]"); 00443 00444 printf("# Service definition\n"); 00445 printf("define service{\n"); 00446 printf("\tuse\t\t\t\tgeneric-service\t\t; Name of service template to use\n\n"); 00447 printf("\thost_name\t\t\t%s\n",temp_ptr); 00448 00449 temp_ptr=my_strsep(&temp_ptr2,";"); 00450 printf("\tservice_description\t\t%s\n",temp_ptr+1); 00451 00452 temp_ptr=my_strsep(&temp_ptr2,";"); 00453 printf("\tis_volatile\t\t\t%d\n",atoi(temp_ptr)); 00454 00455 temp_ptr=my_strsep(&temp_ptr2,";"); 00456 printf("\tcheck_period\t\t\t%s\n",temp_ptr); 00457 00458 temp_ptr=my_strsep(&temp_ptr2,";"); 00459 printf("\tmax_check_attempts\t\t%d\n",atoi(temp_ptr)); 00460 00461 temp_ptr=my_strsep(&temp_ptr2,";"); 00462 printf("\tnormal_check_interval\t\t%d\n",atoi(temp_ptr)); 00463 00464 temp_ptr=my_strsep(&temp_ptr2,";"); 00465 printf("\tretry_check_interval\t\t%d\n",atoi(temp_ptr)); 00466 00467 temp_ptr=my_strsep(&temp_ptr2,";"); 00468 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00469 printf("\tcontact_groups\t\t\t%s\n",temp_ptr); 00470 00471 temp_ptr=my_strsep(&temp_ptr2,";"); 00472 printf("\tnotification_interval\t\t%d\n",atoi(temp_ptr)); 00473 00474 temp_ptr=my_strsep(&temp_ptr2,";"); 00475 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00476 printf("\tnotification_period\t\t%s\n",temp_ptr); 00477 00478 temp_ptr=my_strsep(&temp_ptr2,";"); 00479 notify_recovery=atoi(temp_ptr); 00480 temp_ptr=my_strsep(&temp_ptr2,";"); 00481 notify_critical=atoi(temp_ptr); 00482 temp_ptr=my_strsep(&temp_ptr2,";"); 00483 notify_warning=atoi(temp_ptr); 00484 00485 option=0; 00486 printf("\tnotification_options\t\t"); 00487 if(notify_recovery==1 || notify_critical==1 || notify_warning==1){ 00488 if(notify_warning==1){ 00489 printf("w,u"); 00490 option=1; 00491 } 00492 if(notify_critical==1){ 00493 if(option==1) 00494 printf(","); 00495 printf("c"); 00496 option=1; 00497 } 00498 if(notify_recovery==1){ 00499 if(option==1) 00500 printf(","); 00501 printf("r"); 00502 } 00503 } 00504 else 00505 printf("n"); 00506 printf("\n"); 00507 00508 temp_ptr=my_strsep(&temp_ptr2,";"); 00509 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00510 printf("\tevent_handler\t\t%s\n",temp_ptr); 00511 00512 temp_ptr=my_strsep(&temp_ptr2,";\r\n"); 00513 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00514 printf("\tcheck_command\t\t\t%s\n",temp_ptr); 00515 00516 printf("\t}\n\n\n"); 00517 } 00518 00519 /* hostgroup escalations */ 00520 if(strstr(input,"hostgroupescalation[") && !strcmp(argv[2],"hostgroupescalations")){ 00521 00522 x++; 00523 00524 temp_ptr2=&input[0]; 00525 temp_ptr=my_strsep(&temp_ptr2,"["); 00526 temp_ptr=my_strsep(&temp_ptr2,"]"); 00527 00528 printf("# Hostgroup '%s' escalation definition\n",temp_ptr); 00529 printf("define hostgroupescalation{\n"); 00530 00531 printf("\thostgroup_name\t\t%s\n",temp_ptr); 00532 00533 temp_ptr=my_strsep(&temp_ptr2,"-"); 00534 printf("\tfirst_notification\t\t%d\n",atoi(temp_ptr+1)); 00535 00536 temp_ptr=my_strsep(&temp_ptr2,";"); 00537 printf("\tlast_notification\t\t%d\n",atoi(temp_ptr)); 00538 00539 temp_ptr=my_strsep(&temp_ptr2,";"); 00540 printf("\tcontact_groups\t\t\t%s\n",temp_ptr); 00541 00542 temp_ptr=my_strsep(&temp_ptr2,";\r\n"); 00543 printf("\tnotification_interval\t\t%d\n",atoi(temp_ptr)); 00544 00545 printf("\t}\n\n\n"); 00546 } 00547 00548 /* service escalations */ 00549 if(strstr(input,"serviceescalation[") && !strcmp(argv[2],"serviceescalations")){ 00550 00551 x++; 00552 00553 printf("# Serviceescalation definition\n"); 00554 printf("define serviceescalation{\n"); 00555 00556 temp_ptr2=&input[0]; 00557 temp_ptr=my_strsep(&temp_ptr2,"["); 00558 host_name=my_strsep(&temp_ptr2,";"); 00559 service_description=my_strsep(&temp_ptr2,"]"); 00560 00561 printf("\thost_name\t\t%s\n",host_name); 00562 printf("\tservice_description\t\t%s\n",service_description); 00563 00564 temp_ptr=my_strsep(&temp_ptr2,"-"); 00565 printf("\tfirst_notification\t\t%d\n",atoi(temp_ptr+1)); 00566 00567 temp_ptr=my_strsep(&temp_ptr2,";"); 00568 printf("\tlast_notification\t\t%d\n",atoi(temp_ptr)); 00569 00570 temp_ptr=my_strsep(&temp_ptr2,";"); 00571 printf("\tcontact_groups\t\t\t%s\n",temp_ptr); 00572 00573 temp_ptr=my_strsep(&temp_ptr2,";\r\n"); 00574 printf("\tnotification_interval\t\t%d\n",atoi(temp_ptr)); 00575 00576 printf("\t}\n\n\n"); 00577 } 00578 00579 /* service dependencies */ 00580 if(strstr(input,"servicedependency[") && !strcmp(argv[2],"servicedependencies")){ 00581 00582 temp_ptr2=&input[0]; 00583 temp_ptr=my_strsep(&temp_ptr2,"["); 00584 host_name=my_strsep(&temp_ptr2,";"); 00585 service_description=my_strsep(&temp_ptr2,"]"); 00586 host_name2=my_strsep(&temp_ptr2,";")+1; 00587 service_description2=my_strsep(&temp_ptr2,";"); 00588 00589 temp_ptr=my_strsep(&temp_ptr2,";"); 00590 00591 x++; 00592 00593 printf("# Servicedependency definition\n"); 00594 printf("define servicedependency{\n"); 00595 00596 printf("\thost_name\t\t\t%s\n",host_name2); 00597 printf("\tservice_description\t\t%s\n",service_description2); 00598 printf("\tdependent_host_name\t\t%s\n",host_name); 00599 printf("\tdependent_service_description\t%s\n",service_description); 00600 00601 printf("\texecution_failure_criteria\t"); 00602 for(y=0;temp_ptr[y]!='\x0';y++) 00603 printf("%s%c",(y>0)?",":"",temp_ptr[y]); 00604 if(y==0) 00605 printf("n"); 00606 printf("\t; These are the criteria for which check execution will be suppressed\n"); 00607 00608 temp_ptr=my_strsep(&temp_ptr2,";\r\n"); 00609 00610 printf("\tnotification_failure_criteria\t"); 00611 for(y=0;temp_ptr[y]!='\x0';y++) 00612 printf("%s%c",(y>0)?",":"",temp_ptr[y]); 00613 if(y==0) 00614 printf("n"); 00615 printf("\t; These are the criteria for which notifications will be suppressed\n"); 00616 printf("\t}\n\n\n"); 00617 } 00618 00619 00620 /* extended host info */ 00621 if(strstr(input,"hostextinfo[") && !strcmp(argv[2],"hostextinfo")){ 00622 00623 temp_ptr2=&input[0]; 00624 temp_ptr=my_strsep(&temp_ptr2,"["); 00625 temp_ptr=my_strsep(&temp_ptr2,"]"); 00626 00627 printf("# '%s' hostextinfo definition\n",temp_ptr); 00628 printf("define hostextinfo{\n"); 00629 printf("\thost_name\t\t%s\t\t; The name of the host this data is associated with\n",temp_ptr); 00630 00631 temp_ptr=my_strsep(&temp_ptr2,";"); 00632 00633 if(temp_ptr+1!=NULL && strcmp(temp_ptr+1,"")) 00634 printf("\tnotes_url\t\t\t%s\n",temp_ptr+1); 00635 00636 temp_ptr=my_strsep(&temp_ptr2,";"); 00637 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00638 printf("\ticon_image\t\t%s\n",temp_ptr); 00639 00640 temp_ptr=my_strsep(&temp_ptr2,";"); 00641 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00642 printf("\tvrml_image\t\t%s\n",temp_ptr); 00643 00644 temp_ptr=my_strsep(&temp_ptr2,";"); 00645 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00646 printf("\tstatusmap_image\t\t%s\n",temp_ptr); 00647 00648 temp_ptr=my_strsep(&temp_ptr2,";"); 00649 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00650 printf("\ticon_image_alt\t\t%s\n",temp_ptr); 00651 00652 temp_ptr=my_strsep(&temp_ptr2,";"); 00653 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00654 printf("\t2d_coords\t\t%s\n",temp_ptr); 00655 00656 temp_ptr=my_strsep(&temp_ptr2,";\r\n"); 00657 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00658 printf("\t3d_coords\t\t%s\n",temp_ptr); 00659 00660 printf("\t}\n\n\n"); 00661 } 00662 00663 00664 /* extended service info */ 00665 if(strstr(input,"serviceextinfo[") && !strcmp(argv[2],"serviceextinfo")){ 00666 00667 temp_ptr2=&input[0]; 00668 temp_ptr=my_strsep(&temp_ptr2,"["); 00669 temp_ptr=my_strsep(&temp_ptr2,";"); 00670 00671 printf("# '%s' serviceextinfo definition\n",temp_ptr); 00672 printf("define serviceextinfo{\n"); 00673 printf("\thost_name\t\t%s\t\t; The name of the service this data is associated with\n",temp_ptr); 00674 00675 temp_ptr=my_strsep(&temp_ptr2,"]"); 00676 printf("\tservice_description\t%s\n",temp_ptr); 00677 00678 temp_ptr=my_strsep(&temp_ptr2,";"); 00679 00680 if(temp_ptr+1!=NULL && strcmp(temp_ptr+1,"")) 00681 printf("\tnotes_url\t\t%s\n",temp_ptr+1); 00682 00683 temp_ptr=my_strsep(&temp_ptr2,";"); 00684 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00685 printf("\ticon_image\t\t%s\n",temp_ptr); 00686 00687 temp_ptr=my_strsep(&temp_ptr2,";\r\n"); 00688 if(temp_ptr!=NULL && strcmp(temp_ptr,"")) 00689 printf("\ticon_image_alt\t\t%s\n",temp_ptr); 00690 00691 printf("\t}\n\n\n"); 00692 } 00693 00694 } 00695 00696 00697 fclose(fp); 00698 00699 return 0; 00700 } 00701 00702 00703 00704 /* fixes compiler problems under Solaris, since strsep() isn't included */ 00705 /* this code is taken from the glibc source */ 00706 char *my_strsep (char **stringp, const char *delim){ 00707 char *begin, *end; 00708 00709 begin = *stringp; 00710 if (begin == NULL) 00711 return NULL; 00712 00713 /* A frequent case is when the delimiter string contains only one 00714 character. Here we don't need to call the expensive `strpbrk' 00715 function and instead work using `strchr'. */ 00716 if(delim[0]=='\0' || delim[1]=='\0'){ 00717 char ch = delim[0]; 00718 00719 if(ch=='\0') 00720 end=NULL; 00721 else{ 00722 if(*begin==ch) 00723 end=begin; 00724 else 00725 end=strchr(begin+1,ch); 00726 } 00727 } 00728 00729 else 00730 /* Find the end of the token. */ 00731 end = strpbrk (begin, delim); 00732 00733 if(end){ 00734 00735 /* Terminate the token and set *STRINGP past NUL character. */ 00736 *end++='\0'; 00737 *stringp=end; 00738 } 00739 else 00740 /* No more delimiters; this is the last token. */ 00741 *stringp=NULL; 00742 00743 return begin; 00744 } 00745 00746