1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512
|
/**************************************************************************
*
* STATUSWML.C - Nagios Status CGI for WAP-enabled devices
*
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*************************************************************************/
#include "../include/config.h"
#include "../include/common.h"
#include "../include/objects.h"
#include "../include/statusdata.h"
#include "../include/cgiutils.h"
#include "../include/getcgi.h"
#include "../include/cgiauth.h"
extern char main_config_file[MAX_FILENAME_LENGTH];
extern char *status_file;
extern hoststatus *hoststatus_list;
extern servicestatus *servicestatus_list;
extern int use_ssl_authentication;
extern int nagios_process_state;
extern char *ping_syntax;
#define DISPLAY_HOST 0
#define DISPLAY_SERVICE 1
#define DISPLAY_HOSTGROUP 2
#define DISPLAY_INDEX 3
#define DISPLAY_PING 4
#define DISPLAY_TRACEROUTE 5
#define DISPLAY_QUICKSTATS 6
#define DISPLAY_PROCESS 7
#define DISPLAY_ALL_PROBLEMS 8
#define DISPLAY_UNHANDLED_PROBLEMS 9
#define DISPLAY_HOSTGROUP_SUMMARY 0
#define DISPLAY_HOSTGROUP_OVERVIEW 1
#define DISPLAY_HOST_SUMMARY 0
#define DISPLAY_HOST_SERVICES 1
void document_header(void);
void document_footer(void);
int process_cgivars(void);
int validate_arguments(void);
int is_valid_hostip(char *hostip);
int display_type = DISPLAY_INDEX;
int hostgroup_style = DISPLAY_HOSTGROUP_SUMMARY;
int host_style = DISPLAY_HOST_SUMMARY;
void display_index(void);
void display_host(void);
void display_host_services(void);
void display_service(void);
void display_hostgroup_summary(void);
void display_hostgroup_overview(void);
void display_ping(void);
void display_traceroute(void);
void display_quick_stats(void);
void display_process(void);
void display_problems(void);
char *host_name = "";
char *hostgroup_name = "";
char *service_desc = "";
char *ping_address = "";
char *traceroute_address = "";
int show_all_hostgroups = TRUE;
authdata current_authdata;
int main(void) {
int result = OK;
/* get the arguments passed in the URL */
process_cgivars();
/* reset internal variables */
reset_cgi_vars();
/* Initialize shared configuration variables */
init_shared_cfg_vars(1);
document_header();
/* validate arguments in URL */
result = validate_arguments();
if(result == ERROR) {
document_footer();
return ERROR;
}
/* read the CGI configuration file */
result = read_cgi_config_file(get_cgi_config_location(), NULL);
if(result == ERROR) {
printf("<P>Error: Could not open CGI configuration file '%s' for reading!</P>\n", get_cgi_config_location());
document_footer();
return ERROR;
}
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if(result == ERROR) {
printf("<P>Error: Could not open main configuration file '%s' for reading!</P>\n", main_config_file);
document_footer();
return ERROR;
}
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if(result == ERROR) {
printf("<P>Error: Could not read some or all object configuration data!</P>\n");
document_footer();
return ERROR;
}
/* read all status data */
result = read_all_status_data(status_file, READ_ALL_STATUS_DATA);
if(result == ERROR) {
printf("<P>Error: Could not read host and service status information!</P>\n");
document_footer();
free_memory();
return ERROR;
}
/* get authentication information */
get_authentication_information(¤t_authdata);
/* decide what to display to the user */
if(display_type == DISPLAY_HOST && host_style == DISPLAY_HOST_SERVICES)
display_host_services();
else if(display_type == DISPLAY_HOST)
display_host();
else if(display_type == DISPLAY_SERVICE)
display_service();
else if(display_type == DISPLAY_HOSTGROUP && hostgroup_style == DISPLAY_HOSTGROUP_OVERVIEW)
display_hostgroup_overview();
else if(display_type == DISPLAY_HOSTGROUP && hostgroup_style == DISPLAY_HOSTGROUP_SUMMARY)
display_hostgroup_summary();
else if(display_type == DISPLAY_PING)
display_ping();
else if(display_type == DISPLAY_TRACEROUTE)
display_traceroute();
else if(display_type == DISPLAY_QUICKSTATS)
display_quick_stats();
else if(display_type == DISPLAY_PROCESS)
display_process();
else if(display_type == DISPLAY_ALL_PROBLEMS || display_type == DISPLAY_UNHANDLED_PROBLEMS)
display_problems();
else
display_index();
document_footer();
/* free all allocated memory */
free_memory();
return OK;
}
void document_header(void) {
char date_time[MAX_DATETIME_LENGTH];
time_t expire_time;
time_t current_time;
time(¤t_time);
printf("Cache-Control: no-store\r\n");
printf("Pragma: no-cache\r\n");
get_time_string(¤t_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME);
printf("Last-Modified: %s\r\n", date_time);
expire_time = (time_t)0L;
get_time_string(&expire_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME);
printf("Expires: %s\r\n", date_time);
printf("Content-type: text/vnd.wap.wml\r\n\r\n");
printf("<?xml version=\"1.0\"?>\n");
printf("<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" \"http://www.wapforum.org/DTD/wml_1.1.xml\">\n");
printf("<wml>\n");
printf("<head>\n");
printf("<meta forua=\"true\" http-equiv=\"Cache-Control\" content=\"max-age=0\"/>\n");
printf("</head>\n");
return;
}
void document_footer(void) {
printf("</wml>\n");
return;
}
int process_cgivars(void) {
char **variables;
int error = FALSE;
int x;
variables = getcgivars();
for(x = 0; variables[x]; x++) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */
if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
continue;
}
/* we found the hostgroup argument */
else if(!strcmp(variables[x], "hostgroup")) {
display_type = DISPLAY_HOSTGROUP;
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
if((hostgroup_name = (char *)strdup(variables[x])) == NULL)
hostgroup_name = "";
strip_html_brackets(hostgroup_name);
if(!strcmp(hostgroup_name, "all"))
show_all_hostgroups = TRUE;
else
show_all_hostgroups = FALSE;
}
/* we found the host argument */
else if(!strcmp(variables[x], "host")) {
display_type = DISPLAY_HOST;
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
if((host_name = (char *)strdup(variables[x])) == NULL)
host_name = "";
strip_html_brackets(host_name);
}
/* we found the service argument */
else if(!strcmp(variables[x], "service")) {
display_type = DISPLAY_SERVICE;
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
if((service_desc = (char *)strdup(variables[x])) == NULL)
service_desc = "";
strip_html_brackets(service_desc);
}
/* we found the hostgroup style argument */
else if(!strcmp(variables[x], "style")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
if(!strcmp(variables[x], "overview"))
hostgroup_style = DISPLAY_HOSTGROUP_OVERVIEW;
else if(!strcmp(variables[x], "summary"))
hostgroup_style = DISPLAY_HOSTGROUP_SUMMARY;
else if(!strcmp(variables[x], "servicedetail"))
host_style = DISPLAY_HOST_SERVICES;
else if(!strcmp(variables[x], "processinfo"))
display_type = DISPLAY_PROCESS;
else if(!strcmp(variables[x], "aprobs"))
display_type = DISPLAY_ALL_PROBLEMS;
else if(!strcmp(variables[x], "uprobs"))
display_type = DISPLAY_UNHANDLED_PROBLEMS;
else
display_type = DISPLAY_QUICKSTATS;
}
/* we found the ping argument */
else if(!strcmp(variables[x], "ping")) {
display_type = DISPLAY_PING;
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
if((ping_address = (char *)strdup(variables[x])) == NULL)
ping_address = "";
strip_html_brackets(ping_address);
}
/* we found the traceroute argument */
else if(!strcmp(variables[x], "traceroute")) {
display_type = DISPLAY_TRACEROUTE;
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
if((traceroute_address = (char *)strdup(variables[x])) == NULL)
traceroute_address = "";
strip_html_brackets(traceroute_address);
}
}
/* free memory allocated to the CGI variables */
free_cgivars(variables);
return error;
}
int validate_arguments(void) {
int result = OK;
if((strcmp(ping_address, "")) && !is_valid_hostip(ping_address)) {
printf("<p>Invalid host name/ip</p>\n");
result = ERROR;
}
if(strcmp(traceroute_address, "") && !is_valid_hostip(traceroute_address)) {
printf("<p>Invalid host name/ip</p>\n");
result = ERROR;
}
return result;
}
int is_valid_hostip(char *hostip) {
char *valid_domain_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-";
if(strcmp(hostip, "") && strlen(hostip) == strspn(hostip, valid_domain_chars) && hostip[0] != '-' && hostip[strlen(hostip) - 1] != '-')
return TRUE;
return FALSE;
}
/* main intro screen */
void display_index(void) {
/**** MAIN MENU SCREEN (CARD 1) ****/
printf("<card id='card1' title='Nagios WAP Interface'>\n");
printf("<p align='center' mode='nowrap'>\n");
printf("<b>Nagios</b><br/><b>WAP Interface</b><br/>\n");
printf("<b><anchor title='Quick Stats'>Quick Stats<go href='%s'><postfield name='style' value='quickstats'/></go></anchor></b><br/>\n", STATUSWML_CGI);
printf("<b><anchor title='Status Summary'>Status Summary<go href='%s'><postfield name='hostgroup' value='all'/><postfield name='style' value='summary'/></go></anchor></b><br/>\n", STATUSWML_CGI);
printf("<b><anchor title='Status Overview'>Status Overview<go href='%s'><postfield name='hostgroup' value='all'/><postfield name='style' value='overview'/></go></anchor></b><br/>\n", STATUSWML_CGI);
printf("<b><anchor title='All Problems'>All Problems<go href='%s'><postfield name='style' value='aprobs'/></go></anchor></b><br/>\n", STATUSWML_CGI);
printf("<b><anchor title='Unhandled Problems'>Unhandled Problems<go href='%s'><postfield name='style' value='uprobs'/></go></anchor></b><br/>\n", STATUSWML_CGI);
printf("<b><anchor title='Process Info'>Process Info<go href='%s'><postfield name='style' value='processinfo'/></go></anchor></b><br/>\n", STATUSWML_CGI);
printf("<b><anchor title='Network Tools'>Tools<go href='#card2'/></anchor></b><br/>\n");
printf("<b><anchor title='About'>About<go href='#card3'/></anchor></b><br/>\n");
printf("</p>\n");
printf("</card>\n");
/**** TOOLS SCREEN (CARD 2) ****/
printf("<card id='card2' title='Network Tools'>\n");
printf("<p align='center' mode='nowrap'>\n");
printf("<b>Network Tools:</b><br/>\n");
printf("<b><anchor title='Ping Host'>Ping<go href='%s'><postfield name='ping' value=''/></go></anchor></b><br/>\n", STATUSWML_CGI);
printf("<b><anchor title='Traceroute'>Traceroute<go href='%s'><postfield name='traceroute' value=''/></go></anchor></b><br/>\n", STATUSWML_CGI);
printf("<b><anchor title='View Host'>View Host<go href='#card4'/></anchor></b><br/>\n");
printf("<b><anchor title='View Hostgroup'>View Hostgroup<go href='#card5'/></anchor></b><br/>\n");
printf("</p>\n");
printf("</card>\n");
/**** ABOUT SCREEN (CARD 3) ****/
printf("<card id='card3' title='About'>\n");
printf("<p align='center' mode='nowrap'>\n");
printf("<b>About</b><br/>\n");
printf("</p>\n");
printf("<p align='center' mode='wrap'>\n");
printf("<b>Nagios %s</b><br/><b>WAP Interface</b><br/>\n", PROGRAM_VERSION);
printf("Copyright (C) 2001 Ethan Galstad<br/>\n");
printf("egalstad@nagios.org<br/><br/>\n");
printf("License: <b>GPL</b><br/><br/>\n");
printf("Based in part on features found in AskAround's Wireless Network Tools<br/>\n");
printf("<b>www.askaround.com</b><br/>\n");
printf("</p>\n");
printf("</card>\n");
/**** VIEW HOST SCREEN (CARD 4) ****/
printf("<card id='card4' title='View Host'>\n");
printf("<p align='center' mode='nowrap'>\n");
printf("<b>View Host</b><br/>\n");
printf("</p>\n");
printf("<p align='center' mode='wrap'>\n");
printf("<b>Host Name:</b><br/>\n");
printf("<input name='hname'/>\n");
printf("<do type='accept'>\n");
printf("<go href='%s' method='post'><postfield name='host' value='$(hname)'/></go>\n", STATUSWML_CGI);
printf("</do>\n");
printf("</p>\n");
printf("</card>\n");
/**** VIEW HOSTGROUP SCREEN (CARD 5) ****/
printf("<card id='card5' title='View Hostgroup'>\n");
printf("<p align='center' mode='nowrap'>\n");
printf("<b>View Hostgroup</b><br/>\n");
printf("</p>\n");
printf("<p align='center' mode='wrap'>\n");
printf("<b>Hostgroup Name:</b><br/>\n");
printf("<input name='gname'/>\n");
printf("<do type='accept'>\n");
printf("<go href='%s' method='post'><postfield name='hostgroup' value='$(gname)'/><postfield name='style' value='overview'/></go>\n", STATUSWML_CGI);
printf("</do>\n");
printf("</p>\n");
printf("</card>\n");
return;
}
/* displays process info */
void display_process(void) {
/**** MAIN SCREEN (CARD 1) ****/
printf("<card id='card1' title='Process Info'>\n");
printf("<p align='center' mode='nowrap'>\n");
printf("<b>Process Info</b><br/><br/>\n");
/* check authorization */
if(is_authorized_for_system_information(¤t_authdata) == FALSE) {
printf("<b>Error: Not authorized for process info!</b>\n");
printf("</p>\n");
printf("</card>\n");
return;
}
if(nagios_process_state == STATE_OK)
printf("Nagios process is running<br/>\n");
else
printf("<b>Nagios process may not be running</b><br/>\n");
if(enable_notifications == TRUE)
printf("Notifications are enabled<br/>\n");
else
printf("<b>Notifications are disabled</b><br/>\n");
if(execute_service_checks == TRUE)
printf("Check execution is enabled<br/>\n");
else
printf("<b>Check execution is disabled</b><br/>\n");
printf("<br/>\n");
printf("<b><anchor title='Process Commands'>Process Commands<go href='#card2'/></anchor></b>\n");
printf("</p>\n");
printf("</card>\n");
/**** COMMANDS SCREEN (CARD 2) ****/
printf("<card id='card2' title='Process Commands'>\n");
printf("<p align='center' mode='nowrap'>\n");
printf("<b>Process Commands</b><br/>\n");
if(enable_notifications == FALSE)
printf("<b><anchor title='Enable Notifications'>Enable Notifications<go href='%s' method='post'><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", COMMAND_CGI, CMD_ENABLE_NOTIFICATIONS, CMDMODE_COMMIT);
else
printf("<b><anchor title='Disable Notifications'>Disable Notifications<go href='%s' method='post'><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", COMMAND_CGI, CMD_DISABLE_NOTIFICATIONS, CMDMODE_COMMIT);
if(execute_service_checks == FALSE)
printf("<b><anchor title='Enable Check Execution'>Enable Check Execution<go href='%s' method='post'><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", COMMAND_CGI, CMD_START_EXECUTING_SVC_CHECKS, CMDMODE_COMMIT);
else
printf("<b><anchor title='Disable Check Execution'>Disable Check Execution<go href='%s' method='post'><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", COMMAND_CGI, CMD_STOP_EXECUTING_SVC_CHECKS, CMDMODE_COMMIT);
printf("</p>\n");
printf("</card>\n");
return;
}
/* displays quick stats */
void display_quick_stats(void) {
host *temp_host;
hoststatus *temp_hoststatus;
service *temp_service;
servicestatus *temp_servicestatus;
int hosts_unreachable = 0;
int hosts_down = 0;
int hosts_up = 0;
int hosts_pending = 0;
int services_critical = 0;
int services_unknown = 0;
int services_warning = 0;
int services_ok = 0;
int services_pending = 0;
/**** MAIN SCREEN (CARD 1) ****/
printf("<card id='card1' title='Quick Stats'>\n");
printf("<p align='center' mode='nowrap'>\n");
printf("<b>Quick Stats</b><br/>\n");
printf("</p>\n");
/* check all hosts */
for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
if(is_authorized_for_host(temp_host, ¤t_authdata) == FALSE)
continue;
temp_hoststatus = find_hoststatus(temp_host->name);
if(temp_hoststatus == NULL)
continue;
if(temp_hoststatus->status == SD_HOST_UNREACHABLE)
hosts_unreachable++;
else if(temp_hoststatus->status == SD_HOST_DOWN)
hosts_down++;
else if(temp_hoststatus->status == HOST_PENDING)
hosts_pending++;
else
hosts_up++;
}
/* check all services */
for(temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) {
if(is_authorized_for_service(temp_service, ¤t_authdata) == FALSE)
continue;
temp_servicestatus = find_servicestatus(temp_service->host_name, temp_service->description);
if(temp_servicestatus == NULL)
continue;
if(temp_servicestatus->status == SERVICE_CRITICAL)
services_critical++;
else if(temp_servicestatus->status == SERVICE_UNKNOWN)
services_unknown++;
else if(temp_servicestatus->status == SERVICE_WARNING)
services_warning++;
else if(temp_servicestatus->status == SERVICE_PENDING)
services_pending++;
else
services_ok++;
}
printf("<p align='left' mode='nowrap'>\n");
printf("<b>Host Totals</b>:<br/>\n");
printf("%d UP<br/>\n", hosts_up);
printf("%d DOWN<br/>\n", hosts_down);
printf("%d UNREACHABLE<br/>\n", hosts_unreachable);
printf("%d PENDING<br/>\n", hosts_pending);
printf("<br/>\n");
printf("<b>Service Totals:</b><br/>\n");
printf("%d OK<br/>\n", services_ok);
printf("%d WARNING<br/>\n", services_warning);
printf("%d UNKNOWN<br/>\n", services_unknown);
printf("%d CRITICAL<br/>\n", services_critical);
printf("%d PENDING<br/>\n", services_pending);
printf("</p>\n");
printf("</card>\n");
return;
}
/* displays hostgroup status overview */
void display_hostgroup_overview(void) {
hostgroup *temp_hostgroup;
hostsmember *temp_member;
host *temp_host;
hoststatus *temp_hoststatus;
/**** MAIN SCREEN (CARD 1) ****/
printf("<card id='card1' title='Status Overview'>\n");
printf("<p align='center' mode='nowrap'>\n");
printf("<b><anchor title='Status Overview'>Status Overview<go href='%s' method='post'><postfield name='hostgroup' value='%s'/><postfield name='style' value='summary'/></go></anchor></b><br/><br/>\n", STATUSWML_CGI, escape_string(hostgroup_name));
/* check all hostgroups */
for(temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {
if(show_all_hostgroups == FALSE && strcmp(temp_hostgroup->group_name, hostgroup_name))
continue;
if(is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == FALSE)
continue;
printf("<b>%s</b>\n", temp_hostgroup->alias);
printf("<table columns='2' align='LL'>\n");
/* check all hosts in this hostgroup */
for(temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {
temp_host = find_host(temp_member->host_name);
if(temp_host == NULL)
continue;
if(is_host_member_of_hostgroup(temp_hostgroup, temp_host) == FALSE)
continue;
temp_hoststatus = find_hoststatus(temp_host->name);
if(temp_hoststatus == NULL)
continue;
printf("<tr><td><anchor title='%s'>", temp_host->name);
if(temp_hoststatus->status == SD_HOST_UP)
printf("UP");
else if(temp_hoststatus->status == HOST_PENDING)
printf("PND");
else if(temp_hoststatus->status == SD_HOST_DOWN)
printf("DWN");
else if(temp_hoststatus->status == SD_HOST_UNREACHABLE)
printf("UNR");
else
printf("???");
printf("<go href='%s' method='post'><postfield name='host' value='%s'/></go></anchor></td>", STATUSWML_CGI, temp_host->name);
printf("<td>%s</td></tr>\n", temp_host->name);
}
printf("</table>\n");
printf("<br/>\n");
}
if(show_all_hostgroups == FALSE)
printf("<b><anchor title='View All Hostgroups'>View All Hostgroups<go href='%s' method='post'><postfield name='hostgroup' value='all'/><postfield name='style' value='overview'/></go></anchor></b>\n", STATUSWML_CGI);
printf("</p>\n");
printf("</card>\n");
return;
}
/* displays hostgroup status summary */
void display_hostgroup_summary(void) {
hostgroup *temp_hostgroup;
hostsmember *temp_member;
host *temp_host;
hoststatus *temp_hoststatus;
service *temp_service;
servicestatus *temp_servicestatus;
int hosts_unreachable = 0;
int hosts_down = 0;
int hosts_up = 0;
int hosts_pending = 0;
int services_critical = 0;
int services_unknown = 0;
int services_warning = 0;
int services_ok = 0;
int services_pending = 0;
int found = 0;
/**** MAIN SCREEN (CARD 1) ****/
printf("<card id='card1' title='Status Summary'>\n");
printf("<p align='center' mode='nowrap'>\n");
printf("<b><anchor title='Status Summary'>Status Summary<go href='%s' method='post'><postfield name='hostgroup' value='%s'/><postfield name='style' value='overview'/></go></anchor></b><br/><br/>\n", STATUSWML_CGI, escape_string(hostgroup_name));
/* check all hostgroups */
for(temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {
if(show_all_hostgroups == FALSE && strcmp(temp_hostgroup->group_name, hostgroup_name))
continue;
if(is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == FALSE)
continue;
printf("<b><anchor title='%s'>%s<go href='%s' method='post'><postfield name='hostgroup' value='%s'/><postfield name='style' value='overview'/></go></anchor></b>\n", temp_hostgroup->group_name, temp_hostgroup->alias, STATUSWML_CGI, temp_hostgroup->group_name);
printf("<table columns='2' align='LL'>\n");
hosts_up = 0;
hosts_pending = 0;
hosts_down = 0;
hosts_unreachable = 0;
services_ok = 0;
services_pending = 0;
services_warning = 0;
services_unknown = 0;
services_critical = 0;
/* check all hosts in this hostgroup */
for(temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {
temp_host = find_host(temp_member->host_name);
if(temp_host == NULL)
continue;
if(is_host_member_of_hostgroup(temp_hostgroup, temp_host) == FALSE)
continue;
temp_hoststatus = find_hoststatus(temp_host->name);
if(temp_hoststatus == NULL)
continue;
if(temp_hoststatus->status == SD_HOST_UNREACHABLE)
hosts_unreachable++;
else if(temp_hoststatus->status == SD_HOST_DOWN)
hosts_down++;
else if(temp_hoststatus->status == HOST_PENDING)
hosts_pending++;
else
hosts_up++;
/* check all services on this host */
for(temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) {
if(strcmp(temp_service->host_name, temp_host->name))
continue;
if(is_authorized_for_service(temp_service, ¤t_authdata) == FALSE)
continue;
temp_servicestatus = find_servicestatus(temp_service->host_name, temp_service->description);
if(temp_servicestatus == NULL)
continue;
if(temp_servicestatus->status == SERVICE_CRITICAL)
services_critical++;
else if(temp_servicestatus->status == SERVICE_UNKNOWN)
services_unknown++;
else if(temp_servicestatus->status == SERVICE_WARNING)
services_warning++;
else if(temp_servicestatus->status == SERVICE_PENDING)
services_pending++;
else
services_ok++;
}
}
printf("<tr><td>Hosts:</td><td>");
found = 0;
if(hosts_unreachable > 0) {
printf("%d UNR", hosts_unreachable);
found = 1;
}
if(hosts_down > 0) {
printf("%s%d DWN", (found == 1) ? ", " : "", hosts_down);
found = 1;
}
if(hosts_pending > 0) {
printf("%s%d PND", (found == 1) ? ", " : "", hosts_pending);
found = 1;
}
printf("%s%d UP", (found == 1) ? ", " : "", hosts_up);
printf("</td></tr>\n");
printf("<tr><td>Services:</td><td>");
found = 0;
if(services_critical > 0) {
printf("%d CRI", services_critical);
found = 1;
}
if(services_warning > 0) {
printf("%s%d WRN", (found == 1) ? ", " : "", services_warning);
found = 1;
}
if(services_unknown > 0) {
printf("%s%d UNK", (found == 1) ? ", " : "", services_unknown);
found = 1;
}
if(services_pending > 0) {
printf("%s%d PND", (found == 1) ? ", " : "", services_pending);
found = 1;
}
printf("%s%d OK", (found == 1) ? ", " : "", services_ok);
printf("</td></tr>\n");
printf("</table>\n");
printf("<br/>\n");
}
if(show_all_hostgroups == FALSE)
printf("<b><anchor title='View All Hostgroups'>View All Hostgroups<go href='%s' method='post'><postfield name='hostgroup' value='all'/><postfield name='style' value='summary'/></go></anchor></b>\n", STATUSWML_CGI);
printf("</p>\n");
printf("</card>\n");
return;
}
/* displays host status */
void display_host(void) {
host *temp_host;
hoststatus *temp_hoststatus;
char last_check[MAX_DATETIME_LENGTH];
int days;
int hours;
int minutes;
int seconds;
time_t current_time;
time_t t;
char state_duration[48];
int found;
/**** MAIN SCREEN (CARD 1) ****/
printf("<card id='card1' title='Host Status'>\n");
printf("<p align='center' mode='nowrap'>\n");
printf("<b>Host '%s'</b><br/>\n", host_name);
/* find the host */
temp_host = find_host(host_name);
temp_hoststatus = find_hoststatus(host_name);
if(temp_host == NULL || temp_hoststatus == NULL) {
printf("<b>Error: Could not find host!</b>\n");
printf("</p>\n");
printf("</card>\n");
return;
}
/* check authorization */
if(is_authorized_for_host(temp_host, ¤t_authdata) == FALSE) {
printf("<b>Error: Not authorized for host!</b>\n");
printf("</p>\n");
printf("</card>\n");
return;
}
printf("<table columns='2' align='LL'>\n");
printf("<tr><td>Status:</td><td>");
if(temp_hoststatus->status == SD_HOST_UP)
printf("UP");
else if(temp_hoststatus->status == HOST_PENDING)
printf("PENDING");
else if(temp_hoststatus->status == SD_HOST_DOWN)
printf("DOWN");
else if(temp_hoststatus->status == SD_HOST_UNREACHABLE)
printf("UNREACHABLE");
else
printf("?");
printf("</td></tr>\n");
printf("<tr><td>Info:</td><td>%s</td></tr>\n", temp_hoststatus->plugin_output);
get_time_string(&temp_hoststatus->last_check, last_check, sizeof(last_check) - 1, SHORT_DATE_TIME);
printf("<tr><td>Last Check:</td><td>%s</td></tr>\n", last_check);
current_time = time(NULL);
if(temp_hoststatus->last_state_change == (time_t)0)
t = current_time - program_start;
else
t = current_time - temp_hoststatus->last_state_change;
get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds);
snprintf(state_duration, sizeof(state_duration) - 1, "%2dd %2dh %2dm %2ds%s", days, hours, minutes, seconds, (temp_hoststatus->last_state_change == (time_t)0) ? "+" : "");
printf("<tr><td>Duration:</td><td>%s</td></tr>\n", state_duration);
printf("<tr><td>Properties:</td><td>");
found = 0;
if(temp_hoststatus->checks_enabled == FALSE) {
printf("%sChecks disabled", (found == 1) ? ", " : "");
found = 1;
}
if(temp_hoststatus->notifications_enabled == FALSE) {
printf("%sNotifications disabled", (found == 1) ? ", " : "");
found = 1;
}
if(temp_hoststatus->problem_has_been_acknowledged == TRUE) {
printf("%sProblem acknowledged", (found == 1) ? ", " : "");
found = 1;
}
if(temp_hoststatus->scheduled_downtime_depth > 0) {
printf("%sIn scheduled downtime", (found == 1) ? ", " : "");
found = 1;
}
if(found == 0)
printf("N/A");
printf("</td></tr>\n");
printf("</table>\n");
printf("<br/>\n");
printf("<b><anchor title='View Services'>View Services<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='style' value='servicedetail'/></go></anchor></b>\n", STATUSWML_CGI, escape_string(host_name));
printf("<b><anchor title='Host Commands'>Host Commands<go href='#card2'/></anchor></b>\n");
printf("</p>\n");
printf("</card>\n");
/**** COMMANDS SCREEN (CARD 2) ****/
printf("<card id='card2' title='Host Commands'>\n");
printf("<p align='center' mode='nowrap'>\n");
printf("<b>Host Commands</b><br/>\n");
printf("<b><anchor title='Ping Host'>Ping Host<go href='%s' method='post'><postfield name='ping' value='%s'/></go></anchor></b>\n", STATUSWML_CGI, temp_host->address);
printf("<b><anchor title='Traceroute'>Traceroute<go href='%s' method='post'><postfield name='traceroute' value='%s'/></go></anchor></b>\n", STATUSWML_CGI, temp_host->address);
if(temp_hoststatus->status != SD_HOST_UP && temp_hoststatus->status != HOST_PENDING)
printf("<b><anchor title='Acknowledge Problem'>Acknowledge Problem<go href='#card3'/></anchor></b>\n");
if(temp_hoststatus->checks_enabled == FALSE)
printf("<b><anchor title='Enable Host Checks'>Enable Host Checks<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", COMMAND_CGI, escape_string(host_name), CMD_ENABLE_HOST_CHECK, CMDMODE_COMMIT);
else
printf("<b><anchor title='Disable Host Checks'>Disable Host Checks<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", COMMAND_CGI, escape_string(host_name), CMD_DISABLE_HOST_CHECK, CMDMODE_COMMIT);
if(temp_hoststatus->notifications_enabled == FALSE)
printf("<b><anchor title='Enable Host Notifications'>Enable Host Notifications<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", COMMAND_CGI, escape_string(host_name), CMD_ENABLE_HOST_NOTIFICATIONS, CMDMODE_COMMIT);
else
printf("<b><anchor title='Disable Host Notifications'>Disable Host Notifications<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", COMMAND_CGI, escape_string(host_name), CMD_DISABLE_HOST_NOTIFICATIONS, CMDMODE_COMMIT);
printf("<b><anchor title='Enable All Service Checks'>Enable All Service Checks<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", COMMAND_CGI, escape_string(host_name), CMD_ENABLE_HOST_SVC_CHECKS, CMDMODE_COMMIT);
printf("<b><anchor title='Disable All Service Checks'>Disable All Service Checks<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", COMMAND_CGI, escape_string(host_name), CMD_DISABLE_HOST_SVC_CHECKS, CMDMODE_COMMIT);
printf("<b><anchor title='Enable All Service Notifications'>Enable All Service Notifications<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", COMMAND_CGI, escape_string(host_name), CMD_ENABLE_HOST_SVC_NOTIFICATIONS, CMDMODE_COMMIT);
printf("<b><anchor title='Disable All Service Notifications'>Disable All Service Notifications<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", COMMAND_CGI, escape_string(host_name), CMD_DISABLE_HOST_SVC_NOTIFICATIONS, CMDMODE_COMMIT);
printf("</p>\n");
printf("</card>\n");
/**** ACKNOWLEDGEMENT SCREEN (CARD 3) ****/
printf("<card id='card3' title='Acknowledge Problem'>\n");
printf("<p align='center' mode='nowrap'>\n");
printf("<b>Acknowledge Problem</b><br/>\n");
printf("</p>\n");
printf("<p align='center' mode='wrap'>\n");
printf("<b>Your Name:</b><br/>\n");
printf("<input name='name' value='%s' /><br/>\n", ((use_ssl_authentication) ? (getenv("SSL_CLIENT_S_DN_CN")) : (getenv("REMOTE_USER"))));
printf("<b>Comment:</b><br/>\n");
printf("<input name='comment' value='acknowledged by WAP'/>\n");
printf("<do type='accept'>\n");
printf("<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='com_author' value='$(name)'/><postfield name='com_data' value='$(comment)'/><postfield name='persistent' value=''/><postfield name='send_notification' value=''/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go>\n", COMMAND_CGI, escape_string(host_name), CMD_ACKNOWLEDGE_HOST_PROBLEM, CMDMODE_COMMIT);
printf("</do>\n");
printf("</p>\n");
printf("</card>\n");
return;
}
/* displays services on a host */
void display_host_services(void) {
service *temp_service;
servicestatus *temp_servicestatus;
/**** MAIN SCREEN (CARD 1) ****/
printf("<card id='card1' title='Host Services'>\n");
printf("<p align='center' mode='nowrap'>\n");
printf("<b>Host <anchor title='%s'>", url_encode(host_name));
printf("'%s'<go href='%s' method='post'><postfield name='host' value='%s'/></go></anchor> Services</b><br/>\n", host_name, STATUSWML_CGI, escape_string(host_name));
printf("<table columns='2' align='LL'>\n");
/* check all services */
for(temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) {
if(strcmp(temp_service->host_name, host_name))
continue;
if(is_authorized_for_service(temp_service, ¤t_authdata) == FALSE)
continue;
temp_servicestatus = find_servicestatus(temp_service->host_name, temp_service->description);
if(temp_servicestatus == NULL)
continue;
printf("<tr><td><anchor title='%s'>", temp_service->description);
if(temp_servicestatus->status == SERVICE_OK)
printf("OK");
else if(temp_servicestatus->status == SERVICE_PENDING)
printf("PND");
else if(temp_servicestatus->status == SERVICE_WARNING)
printf("WRN");
else if(temp_servicestatus->status == SERVICE_UNKNOWN)
printf("UNK");
else if(temp_servicestatus->status == SERVICE_CRITICAL)
printf("CRI");
else
printf("???");
printf("<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='service' value='%s'/></go></anchor></td>", STATUSWML_CGI, temp_service->host_name, temp_service->description);
printf("<td>%s</td></tr>\n", temp_service->description);
}
printf("</table>\n");
printf("</p>\n");
printf("</card>\n");
return;
}
/* displays service status */
void display_service(void) {
service *temp_service;
servicestatus *temp_servicestatus;
char last_check[MAX_DATETIME_LENGTH];
int days;
int hours;
int minutes;
int seconds;
time_t current_time;
time_t t;
char state_duration[48];
int found;
/**** MAIN SCREEN (CARD 1) ****/
printf("<card id='card1' title='Service Status'>\n");
printf("<p align='center' mode='nowrap'>\n");
printf("<b>Service '%s' on host '%s'</b><br/>\n", service_desc, host_name);
/* find the service */
temp_service = find_service(host_name, service_desc);
temp_servicestatus = find_servicestatus(host_name, service_desc);
if(temp_service == NULL || temp_servicestatus == NULL) {
printf("<b>Error: Could not find service!</b>\n");
printf("</p>\n");
printf("</card>\n");
return;
}
/* check authorization */
if(is_authorized_for_service(temp_service, ¤t_authdata) == FALSE) {
printf("<b>Error: Not authorized for service!</b>\n");
printf("</p>\n");
printf("</card>\n");
return;
}
printf("<table columns='2' align='LL'>\n");
printf("<tr><td>Status:</td><td>");
if(temp_servicestatus->status == SERVICE_OK)
printf("OK");
else if(temp_servicestatus->status == SERVICE_PENDING)
printf("PENDING");
else if(temp_servicestatus->status == SERVICE_WARNING)
printf("WARNING");
else if(temp_servicestatus->status == SERVICE_UNKNOWN)
printf("UNKNOWN");
else if(temp_servicestatus->status == SERVICE_CRITICAL)
printf("CRITICAL");
else
printf("?");
printf("</td></tr>\n");
printf("<tr><td>Info:</td><td>%s</td></tr>\n", temp_servicestatus->plugin_output);
get_time_string(&temp_servicestatus->last_check, last_check, sizeof(last_check) - 1, SHORT_DATE_TIME);
printf("<tr><td>Last Check:</td><td>%s</td></tr>\n", last_check);
current_time = time(NULL);
if(temp_servicestatus->last_state_change == (time_t)0)
t = current_time - program_start;
else
t = current_time - temp_servicestatus->last_state_change;
get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds);
snprintf(state_duration, sizeof(state_duration) - 1, "%2dd %2dh %2dm %2ds%s", days, hours, minutes, seconds, (temp_servicestatus->last_state_change == (time_t)0) ? "+" : "");
printf("<tr><td>Duration:</td><td>%s</td></tr>\n", state_duration);
printf("<tr><td>Properties:</td><td>");
found = 0;
if(temp_servicestatus->checks_enabled == FALSE) {
printf("%sChecks disabled", (found == 1) ? ", " : "");
found = 1;
}
if(temp_servicestatus->notifications_enabled == FALSE) {
printf("%sNotifications disabled", (found == 1) ? ", " : "");
found = 1;
}
if(temp_servicestatus->problem_has_been_acknowledged == TRUE) {
printf("%sProblem acknowledged", (found == 1) ? ", " : "");
found = 1;
}
if(temp_servicestatus->scheduled_downtime_depth > 0) {
printf("%sIn scheduled downtime", (found == 1) ? ", " : "");
found = 1;
}
if(found == 0)
printf("N/A");
printf("</td></tr>\n");
printf("</table>\n");
printf("<br/>\n");
printf("<b><anchor title='View Host'>View Host<go href='%s' method='post'><postfield name='host' value='%s'/></go></anchor></b>\n", STATUSWML_CGI, escape_string(host_name));
printf("<b><anchor title='Service Commands'>Svc. Commands<go href='#card2'/></anchor></b>\n");
printf("</p>\n");
printf("</card>\n");
/**** COMMANDS SCREEN (CARD 2) ****/
printf("<card id='card2' title='Service Commands'>\n");
printf("<p align='center' mode='nowrap'>\n");
printf("<b>Service Commands</b><br/>\n");
if(temp_servicestatus->status != SERVICE_OK && temp_servicestatus->status != SERVICE_PENDING)
printf("<b><anchor title='Acknowledge Problem'>Acknowledge Problem<go href='#card3'/></anchor></b>\n");
if(temp_servicestatus->checks_enabled == FALSE) {
printf("<b><anchor title='Enable Checks'>Enable Checks<go href='%s' method='post'><postfield name='host' value='%s'/>", COMMAND_CGI, escape_string(host_name));
printf("<postfield name='service' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", escape_string(service_desc), CMD_ENABLE_SVC_CHECK, CMDMODE_COMMIT);
}
else {
printf("<b><anchor title='Disable Checks'>Disable Checks<go href='%s' method='post'><postfield name='host' value='%s'/>", COMMAND_CGI, escape_string(host_name));
printf("<postfield name='service' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", escape_string(service_desc), CMD_DISABLE_SVC_CHECK, CMDMODE_COMMIT);
printf("<b><anchor title='Schedule Immediate Check'>Schedule Immediate Check<go href='%s' method='post'><postfield name='host' value='%s'/>", COMMAND_CGI, escape_string(host_name));
printf("<postfield name='service' value='%s'/><postfield name='start_time' value='%llu'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", escape_string(service_desc), (unsigned long long)current_time, CMD_SCHEDULE_SVC_CHECK, CMDMODE_COMMIT);
}
if(temp_servicestatus->notifications_enabled == FALSE) {
printf("<b><anchor title='Enable Notifications'>Enable Notifications<go href='%s' method='post'><postfield name='host' value='%s'/>", COMMAND_CGI, escape_string(host_name));
printf("<postfield name='service' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", escape_string(service_desc), CMD_ENABLE_SVC_NOTIFICATIONS, CMDMODE_COMMIT);
}
else {
printf("<b><anchor title='Disable Notifications'>Disable Notifications<go href='%s' method='post'><postfield name='host' value='%s'/>", COMMAND_CGI, escape_string(host_name));
printf("<postfield name='service' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", escape_string(service_desc), CMD_DISABLE_SVC_NOTIFICATIONS, CMDMODE_COMMIT);
}
printf("</p>\n");
printf("</card>\n");
/**** ACKNOWLEDGEMENT SCREEN (CARD 3) ****/
printf("<card id='card3' title='Acknowledge Problem'>\n");
printf("<p align='center' mode='nowrap'>\n");
printf("<b>Acknowledge Problem</b><br/>\n");
printf("</p>\n");
printf("<p align='center' mode='wrap'>\n");
printf("<b>Your Name:</b><br/>\n");
printf("<input name='name' value='%s' /><br/>\n", ((use_ssl_authentication) ? (getenv("SSL_CLIENT_S_DN_CN")) : (getenv("REMOTE_USER"))));
printf("<b>Comment:</b><br/>\n");
printf("<input name='comment' value='acknowledged by WAP'/>\n");
printf("<do type='accept'>\n");
printf("<go href='%s' method='post'><postfield name='host' value='%s'/>", COMMAND_CGI, escape_string(host_name));
printf("<postfield name='service' value='%s'/><postfield name='com_author' value='$(name)'/><postfield name='com_data' value='$(comment)'/><postfield name='persistent' value=''/><postfield name='send_notification' value=''/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go>\n", escape_string(service_desc), CMD_ACKNOWLEDGE_SVC_PROBLEM, CMDMODE_COMMIT);
printf("</do>\n");
printf("</p>\n");
printf("</card>\n");
return;
}
/* displays ping results */
void display_ping(void) {
char input_buffer[MAX_INPUT_BUFFER];
char buffer[MAX_INPUT_BUFFER];
char *temp_ptr;
FILE *fp;
int odd = 0;
int in_macro = FALSE;
/**** MAIN SCREEN (CARD 1) ****/
printf("<card id='card1' title='Ping'>\n");
if(!strcmp(ping_address, "")) {
printf("<p align='center' mode='nowrap'>\n");
printf("<b>Ping Host</b><br/>\n");
printf("</p>\n");
printf("<p align='center' mode='wrap'>\n");
printf("<b>Host Name/Address:</b><br/>\n");
printf("<input name='address'/>\n");
printf("<do type='accept'>\n");
printf("<go href='%s'><postfield name='ping' value='$(address)'/></go>\n", STATUSWML_CGI);
printf("</do>\n");
printf("</p>\n");
}
else {
printf("<p align='center' mode='nowrap'>\n");
printf("<b>Results For Ping Of %s:</b><br/>\n", ping_address);
printf("</p>\n");
printf("<p mode='nowrap'>\n");
if(ping_syntax == NULL)
printf("ping_syntax in CGI config file is NULL!\n");
else {
/* process macros in the ping syntax */
strcpy(buffer, "");
strncpy(input_buffer, ping_syntax, sizeof(input_buffer) - 1);
input_buffer[strlen(ping_syntax) - 1] = '\x0';
for(temp_ptr = my_strtok(input_buffer, "$"); temp_ptr != NULL; temp_ptr = my_strtok(NULL, "$")) {
if(in_macro == FALSE) {
if(strlen(buffer) + strlen(temp_ptr) < sizeof(buffer) - 1) {
strncat(buffer, temp_ptr, sizeof(buffer) - strlen(buffer) - 1);
buffer[sizeof(buffer) - 1] = '\x0';
}
in_macro = TRUE;
}
else {
if(strlen(buffer) + strlen(temp_ptr) < sizeof(buffer) - 1) {
if(!strcmp(temp_ptr, "HOSTADDRESS"))
strncat(buffer, ping_address, sizeof(buffer) - strlen(buffer) - 1);
}
in_macro = FALSE;
}
}
/* run the ping command */
fp = popen(buffer, "r");
if(fp) {
while(1) {
fgets(buffer, sizeof(buffer) - 1, fp);
if(feof(fp))
break;
strip(buffer);
if(odd) {
odd = 0;
printf("%s<br/>\n", buffer);
}
else {
odd = 1;
printf("<b>%s</b><br/>\n", buffer);
}
}
}
else
printf("Error executing ping!\n");
pclose(fp);
}
printf("</p>\n");
}
printf("</card>\n");
return;
}
/* displays traceroute results */
void display_traceroute(void) {
char buffer[MAX_INPUT_BUFFER];
FILE *fp;
int odd = 0;
/**** MAIN SCREEN (CARD 1) ****/
printf("<card id='card1' title='Traceroute'>\n");
if(!strcmp(traceroute_address, "")) {
printf("<p align='center' mode='nowrap'>\n");
printf("<b>Traceroute</b><br/>\n");
printf("</p>\n");
printf("<p align='center' mode='wrap'>\n");
printf("<b>Host Name/Address:</b><br/>\n");
printf("<input name='address'/>\n");
printf("<do type='accept'>\n");
printf("<go href='%s'><postfield name='traceroute' value='$(address)'/></go>\n", STATUSWML_CGI);
printf("</do>\n");
printf("</p>\n");
}
else {
printf("<p align='center' mode='nowrap'>\n");
printf("<b>Results For Traceroute To %s:</b><br/>\n", traceroute_address);
printf("</p>\n");
printf("<p mode='nowrap'>\n");
snprintf(buffer, sizeof(buffer) - 1, "%s %s", TRACEROUTE_COMMAND, traceroute_address);
buffer[sizeof(buffer) - 1] = '\x0';
fp = popen(buffer, "r");
if(fp) {
while(1) {
fgets(buffer, sizeof(buffer) - 1, fp);
if(feof(fp))
break;
strip(buffer);
if(odd) {
odd = 0;
printf("%s<br/>\n", buffer);
}
else {
odd = 1;
printf("<b>%s</b><br/>\n", buffer);
}
}
}
else
printf("Error executing traceroute!\n");
pclose(fp);
printf("</p>\n");
}
printf("</card>\n");
return;
}
/* displays problems */
void display_problems(void) {
host *temp_host;
service *temp_service;
hoststatus *temp_hoststatus;
int total_host_problems = 0;
servicestatus *temp_servicestatus;
int total_service_problems = 0;
/**** MAIN SCREEN (CARD 1) ****/
printf("<card id='card1' title='%s Problems'>\n", (display_type == DISPLAY_ALL_PROBLEMS) ? "All" : "Unhandled");
printf("<p align='center' mode='nowrap'>\n");
printf("<b>%s Problems</b><br/><br/>\n", (display_type == DISPLAY_ALL_PROBLEMS) ? "All" : "Unhandled");
printf("<b>Host Problems:</b>\n");
printf("<table columns='2' align='LL'>\n");
/* check all hosts */
for(temp_hoststatus = hoststatus_list; temp_hoststatus != NULL; temp_hoststatus = temp_hoststatus->next) {
temp_host = find_host(temp_hoststatus->host_name);
if(temp_host == NULL)
continue;
if(is_authorized_for_host(temp_host, ¤t_authdata) == FALSE)
continue;
if(temp_hoststatus->status == SD_HOST_UP || temp_hoststatus->status == HOST_PENDING)
continue;
if(display_type == DISPLAY_UNHANDLED_PROBLEMS) {
if(temp_hoststatus->problem_has_been_acknowledged == TRUE)
continue;
if(temp_hoststatus->notifications_enabled == FALSE)
continue;
if(temp_hoststatus->scheduled_downtime_depth > 0)
continue;
}
total_host_problems++;
printf("<tr><td><anchor title='%s'>", temp_host->name);
if(temp_hoststatus->status == SD_HOST_DOWN)
printf("DWN");
else if(temp_hoststatus->status == SD_HOST_UNREACHABLE)
printf("UNR");
else
printf("???");
printf("<go href='%s' method='post'><postfield name='host' value='%s'/></go></anchor></td>", STATUSWML_CGI, temp_host->name);
printf("<td>%s</td></tr>\n", temp_host->name);
}
if(total_host_problems == 0)
printf("<tr><td>No problems</td></tr>\n");
printf("</table>\n");
printf("<br/>\n");
printf("<b>Svc Problems:</b>\n");
printf("<table columns='2' align='LL'>\n");
/* check all services */
for(temp_servicestatus = servicestatus_list; temp_servicestatus != NULL; temp_servicestatus = temp_servicestatus->next) {
temp_service = find_service(temp_servicestatus->host_name, temp_servicestatus->description);
if(temp_service == NULL)
continue;
if(is_authorized_for_service(temp_service, ¤t_authdata) == FALSE)
continue;
if(temp_servicestatus->status == SERVICE_OK || temp_servicestatus->status == SERVICE_PENDING)
continue;
if(display_type == DISPLAY_UNHANDLED_PROBLEMS) {
if(temp_servicestatus->problem_has_been_acknowledged == TRUE)
continue;
if(temp_servicestatus->notifications_enabled == FALSE)
continue;
if(temp_servicestatus->scheduled_downtime_depth > 0)
continue;
if((temp_hoststatus = find_hoststatus(temp_service->host_name))) {
if(temp_hoststatus->scheduled_downtime_depth > 0)
continue;
if(temp_hoststatus->problem_has_been_acknowledged == TRUE)
continue;
}
}
total_service_problems++;
printf("<tr><td><anchor title='%s'>", temp_servicestatus->description);
if(temp_servicestatus->status == SERVICE_CRITICAL)
printf("CRI");
else if(temp_servicestatus->status == SERVICE_WARNING)
printf("WRN");
else if(temp_servicestatus->status == SERVICE_UNKNOWN)
printf("UNK");
else
printf("???");
printf("<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='service' value='%s'/></go></anchor></td>", STATUSWML_CGI, temp_service->host_name, temp_service->description);
printf("<td>%s/%s</td></tr>\n", temp_service->host_name, temp_service->description);
}
if(total_service_problems == 0)
printf("<tr><td>No problems</td></tr>\n");
printf("</table>\n");
printf("</p>\n");
printf("</card>\n");
return;
}
|