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 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849
|
/**************************************************************************
*
* CMD.C - Nagios Command CGI
*
*
* 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/comments.h"
#include "../include/downtime.h"
#include "../include/cgiutils.h"
#include "../include/cgiauth.h"
#include "../include/getcgi.h"
extern char main_config_file[MAX_FILENAME_LENGTH];
extern char url_html_path[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH];
extern char command_file[MAX_FILENAME_LENGTH];
extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
extern int nagios_process_state;
extern int use_authentication;
extern int lock_author_names;
extern int ack_no_sticky;
extern int ack_no_send;
#define MAX_AUTHOR_LENGTH 64
#define MAX_COMMENT_LENGTH 1024
#define HTML_CONTENT 0
#define WML_CONTENT 1
char *host_name = "";
char *hostgroup_name = "";
char *servicegroup_name = "";
char *service_desc = "";
char *comment_author = "";
char *comment_data = "";
char *start_time_string = "";
char *end_time_string = "";
char *cookie_form_id = NULL, *form_id = NULL;
unsigned long comment_id = 0;
unsigned long downtime_id = 0;
int notification_delay = 0;
int schedule_delay = 0;
int persistent_comment = FALSE;
int sticky_ack = FALSE;
int send_notification = FALSE;
int force_check = FALSE;
int plugin_state = STATE_OK;
char plugin_output[MAX_INPUT_BUFFER] = "";
char performance_data[MAX_INPUT_BUFFER] = "";
time_t start_time = 0L;
time_t end_time = 0L;
int affect_host_and_services = FALSE;
int propagate_to_children = FALSE;
int fixed = FALSE;
unsigned long duration = 0L;
unsigned long triggered_by = 0L;
int child_options = 0;
int force_notification = 0;
int broadcast_notification = 0;
int command_type = CMD_NONE;
int command_mode = CMDMODE_REQUEST;
int content_type = HTML_CONTENT;
int display_header = TRUE;
authdata current_authdata;
void show_command_help(int);
void request_command_data(int);
void commit_command_data(int);
int print_comment_field(int cmd_id);
int commit_command(int);
int write_command_to_file(char *);
void clean_comment_data(char *);
void cgicfg_callback(const char*, const char*);
void document_header(int);
void document_footer(void);
int process_cgivars(void);
int string_to_time(char *, time_t *);
int main(void) {
int result = OK;
int formid_ok = OK;
/* Initialize shared configuration variables */
init_shared_cfg_vars(1);
/* get the arguments passed in the URL */
process_cgivars();
/* reset internal variables */
reset_cgi_vars();
/* read the CGI configuration file */
result = read_cgi_config_file(get_cgi_config_location(), cgicfg_callback);
if(result == ERROR) {
document_header(FALSE);
if(content_type == WML_CONTENT)
printf("<p>Error: Could not open CGI config file!</p>\n");
else
cgi_config_file_error(get_cgi_config_location());
document_footer();
return ERROR;
}
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if(result == ERROR) {
document_header(FALSE);
if(content_type == WML_CONTENT)
printf("<p>Error: Could not open main config file!</p>\n");
else
main_config_file_error(main_config_file);
document_footer();
return ERROR;
}
/* This requires the date_format parameter in the main config file */
if(strcmp(start_time_string, ""))
string_to_time(start_time_string, &start_time);
if(strcmp(end_time_string, ""))
string_to_time(end_time_string, &end_time);
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if(result == ERROR) {
document_header(FALSE);
if(content_type == WML_CONTENT)
printf("<p>Error: Could not read object config data!</p>\n");
else
object_data_error();
document_footer();
return ERROR;
}
document_header(TRUE);
/* get authentication information */
get_authentication_information(¤t_authdata);
if(display_header == TRUE) {
/* begin top table */
printf("<table border=0 width=100%%>\n");
printf("<tr>\n");
/* left column of the first row */
printf("<td align=left valign=top width=33%%>\n");
display_info_table("External Command Interface", FALSE, ¤t_authdata);
printf("</td>\n");
/* center column of the first row */
printf("<td align=center valign=top width=33%%>\n");
printf("</td>\n");
/* right column of the first row */
printf("<td align=right valign=bottom width=33%%>\n");
/* display context-sensitive help */
if(command_mode == CMDMODE_COMMIT)
display_context_help(CONTEXTHELP_CMD_COMMIT);
else
display_context_help(CONTEXTHELP_CMD_INPUT);
printf("</td>\n");
/* end of top table */
printf("</tr>\n");
printf("</table>\n");
}
/* authorized_for_read_only should take priority */
if(is_authorized_for_read_only(¤t_authdata) == TRUE) {
printf("<P><DIV CLASS='errorMessage'>It appears as though you do not have permission to submit the command you requested...</DIV></P>\n");
printf("<P><DIV CLASS='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
printf("and check the authorization options in your CGI configuration file.</DIV></P>\n");
document_footer();
/* free allocated memory */
free_memory();
free_object_data();
return OK;
}
if (cookie_form_id && *cookie_form_id) {
formid_ok = ERROR;
if (form_id && *form_id) {
if (!strcmp(form_id, cookie_form_id))
formid_ok = OK;
}
}
/* if no command was specified... */
if(command_type == CMD_NONE) {
if(content_type == WML_CONTENT)
printf("<p>Error: No command specified!</p>\n");
else
printf("<P><DIV CLASS='errorMessage'>Error: No command was specified</DIV></P>\n");
}
/* if this is the first request for a command, present option */
else if(command_mode == CMDMODE_REQUEST)
request_command_data(command_type);
/* the user wants to commit the command */
else if(command_mode == CMDMODE_COMMIT) {
if (formid_ok == ERROR) /* we're expecting an id but it wasn't there... */
printf("<p>Error: Invalid form id!</p>\n");
else
commit_command_data(command_type);
}
document_footer();
/* free allocated memory */
free_memory();
free_object_data();
return OK;
}
void cgicfg_callback(const char *var, const char *val)
{
struct nagios_extcmd *ecmd;
const char *cp = val;
if (strncmp(var, "CMT_", 4))
return;
ecmd = extcmd_get_command_name(&var[4]);
if (!ecmd)
return;
if (!isdigit(*val))
return;
ecmd->cmt_opt = atoi(val);
while (isdigit(*cp) || *cp == ',' || *cp == ' ' || *cp == '\t')
++cp;
if (!*cp)
return;
ecmd->default_comment = strdup(cp);
strip_html_brackets(ecmd->default_comment);
}
void document_header(int use_stylesheet) {
if(content_type == WML_CONTENT) {
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("<card id='card1' title='Command Results'>\n");
}
else {
printf("Content-type: text/html; charset=utf-8\r\n\r\n");
printf("<html>\n");
printf("<head>\n");
printf("<link rel=\"shortcut icon\" href=\"%sfavicon.ico\" type=\"image/ico\">\n", url_images_path);
printf("<title>\n");
printf("External Command Interface\n");
printf("</title>\n");
if(use_stylesheet == TRUE) {
printf("<LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'>\n", url_stylesheets_path, COMMON_CSS);
printf("<LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'>\n", url_stylesheets_path, COMMAND_CSS);
}
printf("</head>\n");
printf("<body CLASS='cmd'>\n");
/* include user SSI header */
include_ssi_files(COMMAND_CGI, SSI_HEADER);
}
return;
}
void document_footer(void) {
if(content_type == WML_CONTENT) {
printf("</card>\n");
printf("</wml>\n");
}
else {
/* include user SSI footer */
include_ssi_files(COMMAND_CGI, SSI_FOOTER);
printf("</body>\n");
printf("</html>\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 command type */
else if(!strcmp(variables[x], "cmd_typ")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
command_type = atoi(variables[x]);
}
/* we found the command mode */
else if(!strcmp(variables[x], "cmd_mod")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
command_mode = atoi(variables[x]);
}
/* we found the comment id */
else if(!strcmp(variables[x], "com_id")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
comment_id = strtoul(variables[x], NULL, 10);
}
/* we found the downtime id */
else if(!strcmp(variables[x], "down_id")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
downtime_id = strtoul(variables[x], NULL, 10);
}
/* we found the notification delay */
else if(!strcmp(variables[x], "not_dly")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
notification_delay = atoi(variables[x]);
}
/* we found the schedule delay */
else if(!strcmp(variables[x], "sched_dly")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
schedule_delay = atoi(variables[x]);
}
/* we found the comment author */
else if(!strcmp(variables[x], "com_author")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
if((comment_author = (char *)strdup(variables[x])) == NULL)
comment_author = "";
strip_html_brackets(comment_author);
}
/* we found the comment data */
else if(!strcmp(variables[x], "com_data")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
if((comment_data = (char *)strdup(variables[x])) == NULL)
comment_data = "";
strip_html_brackets(comment_data);
}
/* we found the host name */
else if(!strcmp(variables[x], "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 hostgroup name */
else if(!strcmp(variables[x], "hostgroup")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
if((hostgroup_name = (char *)strdup(variables[x])) == NULL)
hostgroup_name = "";
strip_html_brackets(hostgroup_name);
}
/* we found the service name */
else if(!strcmp(variables[x], "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 servicegroup name */
else if(!strcmp(variables[x], "servicegroup")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
if((servicegroup_name = (char *)strdup(variables[x])) == NULL)
servicegroup_name = "";
strip_html_brackets(servicegroup_name);
}
/* we got the persistence option for a comment */
else if(!strcmp(variables[x], "persistent"))
persistent_comment = TRUE;
/* we got the notification option for an acknowledgement */
else if(!strcmp(variables[x], "send_notification"))
send_notification = TRUE;
/* we got the acknowledgement type */
else if(!strcmp(variables[x], "sticky_ack"))
sticky_ack = TRUE;
/* we got the service check force option */
else if(!strcmp(variables[x], "force_check"))
force_check = TRUE;
/* we got the option to affect host and all its services */
else if(!strcmp(variables[x], "ahas"))
affect_host_and_services = TRUE;
/* we got the option to propagate to child hosts */
else if(!strcmp(variables[x], "ptc"))
propagate_to_children = TRUE;
/* we got the option for fixed downtime */
else if(!strcmp(variables[x], "fixed")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
fixed = (atoi(variables[x]) > 0) ? TRUE : FALSE;
}
/* we got the triggered by downtime option */
else if(!strcmp(variables[x], "trigger")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
triggered_by = strtoul(variables[x], NULL, 10);
}
/* we got the child options */
else if(!strcmp(variables[x], "childoptions")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
child_options = atoi(variables[x]);
}
/* we found the plugin output */
else if(!strcmp(variables[x], "plugin_output")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
/* protect against buffer overflows */
if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
error = TRUE;
break;
}
else
strcpy(plugin_output, variables[x]);
}
/* we found the performance data */
else if(!strcmp(variables[x], "performance_data")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
/* protect against buffer overflows */
if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
error = TRUE;
break;
}
else
strcpy(performance_data, variables[x]);
}
/* we found the plugin state */
else if(!strcmp(variables[x], "plugin_state")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
plugin_state = atoi(variables[x]);
}
/* we found the hour duration */
else if(!strcmp(variables[x], "hours")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
if(atoi(variables[x]) < 0) {
error = TRUE;
break;
}
duration += (unsigned long)(atoi(variables[x]) * 3600);
}
/* we found the minute duration */
else if(!strcmp(variables[x], "minutes")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
if(atoi(variables[x]) < 0) {
error = TRUE;
break;
}
duration += (unsigned long)(atoi(variables[x]) * 60);
}
/* we found the start time */
else if(!strcmp(variables[x], "start_time")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
start_time_string = (char *)malloc(strlen(variables[x]) + 1);
if(start_time_string == NULL)
start_time_string = "";
else
strcpy(start_time_string, variables[x]);
}
/* we found the end time */
else if(!strcmp(variables[x], "end_time")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
end_time_string = (char *)malloc(strlen(variables[x]) + 1);
if(end_time_string == NULL)
end_time_string = "";
else
strcpy(end_time_string, variables[x]);
}
/* we found the content type argument */
else if(!strcmp(variables[x], "content")) {
x++;
if(variables[x] == NULL) {
error = TRUE;
break;
}
if(!strcmp(variables[x], "wml")) {
content_type = WML_CONTENT;
display_header = FALSE;
}
else
content_type = HTML_CONTENT;
}
/* we found the forced notification option */
else if(!strcmp(variables[x], "force_notification"))
force_notification = NOTIFICATION_OPTION_FORCED;
/* we found the broadcast notification option */
else if(!strcmp(variables[x], "broadcast_notification"))
broadcast_notification = NOTIFICATION_OPTION_BROADCAST;
/* we found the cookie form id */
else if (!strcmp(variables[x], "NagFormId")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
cookie_form_id = (char*)strdup(variables[x]);
}
/* we found the form id on the form */
else if (!strcmp(variables[x], "nagFormId")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
form_id = (char*)strdup(variables[x]);
}
}
/* free memory allocated to the CGI variables */
free_cgivars(variables);
return error;
}
void request_command_data(int cmd) {
time_t t;
char start_time_str[MAX_DATETIME_LENGTH];
char buffer[MAX_INPUT_BUFFER];
contact *temp_contact;
scheduled_downtime *temp_downtime;
/* get default name to use for comment author */
temp_contact = find_contact(current_authdata.username);
if(temp_contact != NULL && temp_contact->alias != NULL)
comment_author = temp_contact->alias;
else
comment_author = current_authdata.username;
printf("<P><DIV ALIGN=CENTER CLASS='cmdType'>You are requesting to ");
switch(cmd) {
case CMD_ADD_HOST_COMMENT:
case CMD_ADD_SVC_COMMENT:
printf("add a %s comment", (cmd == CMD_ADD_HOST_COMMENT) ? "host" : "service");
break;
case CMD_DEL_HOST_COMMENT:
case CMD_DEL_SVC_COMMENT:
printf("delete a %s comment", (cmd == CMD_DEL_HOST_COMMENT) ? "host" : "service");
break;
case CMD_DELAY_HOST_NOTIFICATION:
case CMD_DELAY_SVC_NOTIFICATION:
printf("delay a %s notification", (cmd == CMD_DELAY_HOST_NOTIFICATION) ? "host" : "service");
break;
case CMD_SCHEDULE_SVC_CHECK:
printf("schedule a service check");
break;
case CMD_ENABLE_SVC_CHECK:
case CMD_DISABLE_SVC_CHECK:
printf("%s active checks of a particular service", (cmd == CMD_ENABLE_SVC_CHECK) ? "enable" : "disable");
break;
case CMD_ENABLE_NOTIFICATIONS:
case CMD_DISABLE_NOTIFICATIONS:
printf("%s notifications", (cmd == CMD_ENABLE_NOTIFICATIONS) ? "enable" : "disable");
break;
case CMD_SHUTDOWN_PROCESS:
case CMD_RESTART_PROCESS:
printf("%s the Nagios process", (cmd == CMD_SHUTDOWN_PROCESS) ? "shutdown" : "restart");
break;
case CMD_ENABLE_HOST_SVC_CHECKS:
case CMD_DISABLE_HOST_SVC_CHECKS:
printf("%s active checks of all services on a host", (cmd == CMD_ENABLE_HOST_SVC_CHECKS) ? "enable" : "disable");
break;
case CMD_SCHEDULE_HOST_SVC_CHECKS:
printf("schedule a check of all services for a host");
break;
case CMD_DEL_ALL_HOST_COMMENTS:
case CMD_DEL_ALL_SVC_COMMENTS:
printf("delete all comments for a %s", (cmd == CMD_DEL_ALL_HOST_COMMENTS) ? "host" : "service");
break;
case CMD_ENABLE_SVC_NOTIFICATIONS:
case CMD_DISABLE_SVC_NOTIFICATIONS:
printf("%s notifications for a service", (cmd == CMD_ENABLE_SVC_NOTIFICATIONS) ? "enable" : "disable");
break;
case CMD_ENABLE_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOST_NOTIFICATIONS:
printf("%s notifications for a host", (cmd == CMD_ENABLE_HOST_NOTIFICATIONS) ? "enable" : "disable");
break;
case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
printf("%s notifications for all hosts and services beyond a host", (cmd == CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST) ? "enable" : "disable");
break;
case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
printf("%s notifications for all services on a host", (cmd == CMD_ENABLE_HOST_SVC_NOTIFICATIONS) ? "enable" : "disable");
break;
case CMD_ACKNOWLEDGE_HOST_PROBLEM:
case CMD_ACKNOWLEDGE_SVC_PROBLEM:
printf("acknowledge a %s problem", (cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM) ? "host" : "service");
break;
case CMD_START_EXECUTING_SVC_CHECKS:
case CMD_STOP_EXECUTING_SVC_CHECKS:
printf("%s executing active service checks", (cmd == CMD_START_EXECUTING_SVC_CHECKS) ? "start" : "stop");
break;
case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
printf("%s accepting passive service checks", (cmd == CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS) ? "start" : "stop");
break;
case CMD_ENABLE_PASSIVE_SVC_CHECKS:
case CMD_DISABLE_PASSIVE_SVC_CHECKS:
printf("%s accepting passive service checks for a particular service", (cmd == CMD_ENABLE_PASSIVE_SVC_CHECKS) ? "start" : "stop");
break;
case CMD_ENABLE_EVENT_HANDLERS:
case CMD_DISABLE_EVENT_HANDLERS:
printf("%s event handlers", (cmd == CMD_ENABLE_EVENT_HANDLERS) ? "enable" : "disable");
break;
case CMD_ENABLE_HOST_EVENT_HANDLER:
case CMD_DISABLE_HOST_EVENT_HANDLER:
printf("%s the event handler for a particular host", (cmd == CMD_ENABLE_HOST_EVENT_HANDLER) ? "enable" : "disable");
break;
case CMD_ENABLE_SVC_EVENT_HANDLER:
case CMD_DISABLE_SVC_EVENT_HANDLER:
printf("%s the event handler for a particular service", (cmd == CMD_ENABLE_SVC_EVENT_HANDLER) ? "enable" : "disable");
break;
case CMD_ENABLE_HOST_CHECK:
case CMD_DISABLE_HOST_CHECK:
printf("%s active checks of a particular host", (cmd == CMD_ENABLE_HOST_CHECK) ? "enable" : "disable");
break;
case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
case CMD_START_OBSESSING_OVER_SVC_CHECKS:
printf("%s obsessing over service checks", (cmd == CMD_STOP_OBSESSING_OVER_SVC_CHECKS) ? "stop" : "start");
break;
case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
printf("remove a %s acknowledgement", (cmd == CMD_REMOVE_HOST_ACKNOWLEDGEMENT) ? "host" : "service");
break;
case CMD_SCHEDULE_HOST_DOWNTIME:
case CMD_SCHEDULE_SVC_DOWNTIME:
printf("schedule downtime for a particular %s", (cmd == CMD_SCHEDULE_HOST_DOWNTIME) ? "host" : "service");
break;
case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
printf("schedule downtime for all services for a particular host");
break;
case CMD_PROCESS_HOST_CHECK_RESULT:
case CMD_PROCESS_SERVICE_CHECK_RESULT:
printf("submit a passive check result for a particular %s", (cmd == CMD_PROCESS_HOST_CHECK_RESULT) ? "host" : "service");
break;
case CMD_ENABLE_HOST_FLAP_DETECTION:
case CMD_DISABLE_HOST_FLAP_DETECTION:
printf("%s flap detection for a particular host", (cmd == CMD_ENABLE_HOST_FLAP_DETECTION) ? "enable" : "disable");
break;
case CMD_ENABLE_SVC_FLAP_DETECTION:
case CMD_DISABLE_SVC_FLAP_DETECTION:
printf("%s flap detection for a particular service", (cmd == CMD_ENABLE_SVC_FLAP_DETECTION) ? "enable" : "disable");
break;
case CMD_ENABLE_FLAP_DETECTION:
case CMD_DISABLE_FLAP_DETECTION:
printf("%s flap detection for hosts and services", (cmd == CMD_ENABLE_FLAP_DETECTION) ? "enable" : "disable");
break;
case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
printf("%s notifications for all services in a particular hostgroup", (cmd == CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS) ? "enable" : "disable");
break;
case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
printf("%s notifications for all hosts in a particular hostgroup", (cmd == CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS) ? "enable" : "disable");
break;
case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
printf("%s active checks of all services in a particular hostgroup", (cmd == CMD_ENABLE_HOSTGROUP_SVC_CHECKS) ? "enable" : "disable");
break;
case CMD_DEL_HOST_DOWNTIME:
case CMD_DEL_SVC_DOWNTIME:
printf("cancel scheduled downtime for a particular %s", (cmd == CMD_DEL_HOST_DOWNTIME) ? "host" : "service");
break;
case CMD_ENABLE_PERFORMANCE_DATA:
case CMD_DISABLE_PERFORMANCE_DATA:
printf("%s performance data processing for hosts and services", (cmd == CMD_ENABLE_PERFORMANCE_DATA) ? "enable" : "disable");
break;
case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
printf("schedule downtime for all hosts in a particular hostgroup");
break;
case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
printf("schedule downtime for all services in a particular hostgroup");
break;
case CMD_START_EXECUTING_HOST_CHECKS:
case CMD_STOP_EXECUTING_HOST_CHECKS:
printf("%s executing host checks", (cmd == CMD_START_EXECUTING_HOST_CHECKS) ? "start" : "stop");
break;
case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
printf("%s accepting passive host checks", (cmd == CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS) ? "start" : "stop");
break;
case CMD_ENABLE_PASSIVE_HOST_CHECKS:
case CMD_DISABLE_PASSIVE_HOST_CHECKS:
printf("%s accepting passive checks for a particular host", (cmd == CMD_ENABLE_PASSIVE_HOST_CHECKS) ? "start" : "stop");
break;
case CMD_START_OBSESSING_OVER_HOST_CHECKS:
case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
printf("%s obsessing over host checks", (cmd == CMD_START_OBSESSING_OVER_HOST_CHECKS) ? "start" : "stop");
break;
case CMD_SCHEDULE_HOST_CHECK:
printf("schedule a host check");
break;
case CMD_START_OBSESSING_OVER_SVC:
case CMD_STOP_OBSESSING_OVER_SVC:
printf("%s obsessing over a particular service", (cmd == CMD_START_OBSESSING_OVER_SVC) ? "start" : "stop");
break;
case CMD_START_OBSESSING_OVER_HOST:
case CMD_STOP_OBSESSING_OVER_HOST:
printf("%s obsessing over a particular host", (cmd == CMD_START_OBSESSING_OVER_HOST) ? "start" : "stop");
break;
case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
printf("%s notifications for all services in a particular servicegroup", (cmd == CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS) ? "enable" : "disable");
break;
case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
printf("%s notifications for all hosts in a particular servicegroup", (cmd == CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS) ? "enable" : "disable");
break;
case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
printf("%s active checks of all services in a particular servicegroup", (cmd == CMD_ENABLE_SERVICEGROUP_SVC_CHECKS) ? "enable" : "disable");
break;
case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
printf("schedule downtime for all hosts in a particular servicegroup");
break;
case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
printf("schedule downtime for all services in a particular servicegroup");
break;
case CMD_CLEAR_HOST_FLAPPING_STATE:
case CMD_CLEAR_SVC_FLAPPING_STATE:
printf("clear flapping state for a %s", (cmd == CMD_CLEAR_HOST_FLAPPING_STATE) ? "host" : "service");
break;
case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
printf("send a custom %s notification", (cmd == CMD_SEND_CUSTOM_HOST_NOTIFICATION) ? "host" : "service");
break;
default:
printf("execute an unknown command. Shame on you!</DIV>");
return;
}
printf("</DIV></p>\n");
printf("<p>\n");
printf("<div align='center'>\n");
printf("<table border=0 width=90%%>\n");
printf("<tr>\n");
printf("<td align=center valign=top>\n");
printf("<DIV ALIGN=CENTER CLASS='optBoxTitle'>Command Options</DIV>\n");
printf("<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=1 CLASS='optBox'>\n");
printf("<TR><TD CLASS='optBoxItem'>\n");
printf("<form method='post' action='%s'>\n", COMMAND_CGI);
if (cookie_form_id && *cookie_form_id)
printf("<INPUT TYPE='hidden' NAME='nagFormId' VALUE='%s'\n", cookie_form_id);
printf("<TABLE CELLSPACING=0 CELLPADDING=0 CLASS='optBox'>\n");
printf("<tr><td><INPUT TYPE='HIDDEN' NAME='cmd_typ' VALUE='%d'><INPUT TYPE='HIDDEN' NAME='cmd_mod' VALUE='%d'></td></tr>\n", cmd, CMDMODE_COMMIT);
switch(cmd) {
case CMD_ADD_HOST_COMMENT:
case CMD_ACKNOWLEDGE_HOST_PROBLEM:
printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
printf("</b></td></tr>\n");
if(cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM) {
printf("<tr><td CLASS='optBoxItem'>Sticky Acknowledgement:</td><td><b>");
printf("<INPUT TYPE='checkbox' NAME='sticky_ack' %s>", (ack_no_sticky == TRUE) ? "" : "CHECKED");
printf("</b></td></tr>\n");
printf("<tr><td CLASS='optBoxItem'>Send Notification:</td><td><b>");
printf("<INPUT TYPE='checkbox' NAME='send_notification' %s>", (ack_no_send == TRUE) ? "" : "CHECKED");
printf("</b></td></tr>\n");
}
printf("<tr><td CLASS='optBoxItem'>Persistent%s:</td><td><b>", (cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM) ? " Comment" : "");
printf("<INPUT TYPE='checkbox' NAME='persistent' %s>", (cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM) ? "" : "CHECKED");
printf("</b></td></tr>\n");
print_comment_field(cmd);
break;
case CMD_ADD_SVC_COMMENT:
case CMD_ACKNOWLEDGE_SVC_PROBLEM:
printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
printf("</b></td></tr>\n");
printf("<tr><td CLASS='optBoxRequiredItem'>Service:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='service' VALUE='%s'>", escape_string(service_desc));
if(cmd == CMD_ACKNOWLEDGE_SVC_PROBLEM) {
printf("<tr><td CLASS='optBoxItem'>Sticky Acknowledgement:</td><td><b>");
printf("<INPUT TYPE='checkbox' NAME='sticky_ack' %s>", (ack_no_sticky == TRUE) ? "" : "CHECKED");
printf("</b></td></tr>\n");
printf("<tr><td CLASS='optBoxItem'>Send Notification:</td><td><b>");
printf("<INPUT TYPE='checkbox' NAME='send_notification' %s>", (ack_no_send == TRUE) ? "" : "CHECKED");
printf("</b></td></tr>\n");
}
printf("<tr><td CLASS='optBoxItem'>Persistent%s:</td><td><b>", (cmd == CMD_ACKNOWLEDGE_SVC_PROBLEM) ? " Comment" : "");
printf("<INPUT TYPE='checkbox' NAME='persistent' %s>", (cmd == CMD_ACKNOWLEDGE_SVC_PROBLEM) ? "" : "CHECKED");
printf("</b></td></tr>\n");
print_comment_field(cmd);
break;
case CMD_DEL_HOST_COMMENT:
case CMD_DEL_SVC_COMMENT:
printf("<tr><td CLASS='optBoxRequiredItem'>Comment ID:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='com_id' VALUE='%lu'>", comment_id);
printf("</b></td></tr>\n");
break;
case CMD_DELAY_HOST_NOTIFICATION:
printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
printf("</b></td></tr>\n");
printf("<tr><td CLASS='optBoxRequiredItem'>Notification Delay (minutes from now):</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='not_dly' VALUE='%d'>", notification_delay);
printf("</b></td></tr>\n");
print_comment_field(cmd);
break;
case CMD_DELAY_SVC_NOTIFICATION:
printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
printf("</b></td></tr>\n");
printf("<tr><td CLASS='optBoxRequiredItem'>Service:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='service' VALUE='%s'>", escape_string(service_desc));
printf("<tr><td CLASS='optBoxRequiredItem'>Notification Delay (minutes from now):</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='not_dly' VALUE='%d'>", notification_delay);
printf("</b></td></tr>\n");
print_comment_field(cmd);
break;
case CMD_SCHEDULE_SVC_CHECK:
case CMD_SCHEDULE_HOST_CHECK:
case CMD_SCHEDULE_HOST_SVC_CHECKS:
printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
printf("</b></td></tr>\n");
if(cmd == CMD_SCHEDULE_SVC_CHECK) {
printf("<tr><td CLASS='optBoxRequiredItem'>Service:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='service' VALUE='%s'>", escape_string(service_desc));
printf("</b></td></tr>\n");
}
time(&t);
get_time_string(&t, buffer, sizeof(buffer) - 1, SHORT_DATE_TIME);
printf("<tr><td CLASS='optBoxRequiredItem'>Check Time:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='start_time' VALUE='%s'>", buffer);
printf("</b></td></tr>\n");
print_comment_field(cmd);
printf("<tr><td CLASS='optBoxItem'>Force Check:</td><td><b>");
printf("<INPUT TYPE='checkbox' NAME='force_check' %s>", (force_check == TRUE) ? "CHECKED" : "");
printf("</b></td></tr>\n");
break;
case CMD_ENABLE_SVC_CHECK:
case CMD_DISABLE_SVC_CHECK:
case CMD_DEL_ALL_SVC_COMMENTS:
case CMD_ENABLE_SVC_NOTIFICATIONS:
case CMD_DISABLE_SVC_NOTIFICATIONS:
case CMD_ENABLE_PASSIVE_SVC_CHECKS:
case CMD_DISABLE_PASSIVE_SVC_CHECKS:
case CMD_ENABLE_SVC_EVENT_HANDLER:
case CMD_DISABLE_SVC_EVENT_HANDLER:
case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
case CMD_ENABLE_SVC_FLAP_DETECTION:
case CMD_DISABLE_SVC_FLAP_DETECTION:
case CMD_START_OBSESSING_OVER_SVC:
case CMD_STOP_OBSESSING_OVER_SVC:
case CMD_CLEAR_SVC_FLAPPING_STATE:
printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
printf("</b></td></tr>\n");
printf("<tr><td CLASS='optBoxRequiredItem'>Service:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='service' VALUE='%s'>", escape_string(service_desc));
printf("</b></td></tr>\n");
print_comment_field(cmd);
break;
case CMD_ENABLE_HOST_SVC_CHECKS:
case CMD_DISABLE_HOST_SVC_CHECKS:
case CMD_DEL_ALL_HOST_COMMENTS:
case CMD_ENABLE_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOST_NOTIFICATIONS:
case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
case CMD_ENABLE_HOST_EVENT_HANDLER:
case CMD_DISABLE_HOST_EVENT_HANDLER:
case CMD_ENABLE_HOST_CHECK:
case CMD_DISABLE_HOST_CHECK:
case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
case CMD_ENABLE_HOST_FLAP_DETECTION:
case CMD_DISABLE_HOST_FLAP_DETECTION:
case CMD_ENABLE_PASSIVE_HOST_CHECKS:
case CMD_DISABLE_PASSIVE_HOST_CHECKS:
case CMD_START_OBSESSING_OVER_HOST:
case CMD_STOP_OBSESSING_OVER_HOST:
case CMD_CLEAR_HOST_FLAPPING_STATE:
printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
printf("</b></td></tr>\n");
print_comment_field(cmd);
if(cmd == CMD_ENABLE_HOST_SVC_CHECKS || cmd == CMD_DISABLE_HOST_SVC_CHECKS || cmd == CMD_ENABLE_HOST_SVC_NOTIFICATIONS || cmd == CMD_DISABLE_HOST_SVC_NOTIFICATIONS) {
printf("<tr><td CLASS='optBoxItem'>%s For Host Too:</td><td><b>", (cmd == CMD_ENABLE_HOST_SVC_CHECKS || cmd == CMD_ENABLE_HOST_SVC_NOTIFICATIONS) ? "Enable" : "Disable");
printf("<INPUT TYPE='checkbox' NAME='ahas'>");
printf("</b></td></tr>\n");
}
if(cmd == CMD_ENABLE_HOST_NOTIFICATIONS || cmd == CMD_DISABLE_HOST_NOTIFICATIONS) {
printf("<tr><td CLASS='optBoxItem'>%s Notifications For Child Hosts Too:</td><td><b>", (cmd == CMD_ENABLE_HOST_NOTIFICATIONS) ? "Enable" : "Disable");
printf("<INPUT TYPE='checkbox' NAME='ptc'>");
printf("</b></td></tr>\n");
}
break;
case CMD_ENABLE_NOTIFICATIONS:
case CMD_DISABLE_NOTIFICATIONS:
case CMD_SHUTDOWN_PROCESS:
case CMD_RESTART_PROCESS:
case CMD_START_EXECUTING_SVC_CHECKS:
case CMD_STOP_EXECUTING_SVC_CHECKS:
case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_ENABLE_EVENT_HANDLERS:
case CMD_DISABLE_EVENT_HANDLERS:
case CMD_START_OBSESSING_OVER_SVC_CHECKS:
case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
case CMD_ENABLE_FLAP_DETECTION:
case CMD_DISABLE_FLAP_DETECTION:
case CMD_ENABLE_PERFORMANCE_DATA:
case CMD_DISABLE_PERFORMANCE_DATA:
case CMD_START_EXECUTING_HOST_CHECKS:
case CMD_STOP_EXECUTING_HOST_CHECKS:
case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
case CMD_START_OBSESSING_OVER_HOST_CHECKS:
case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
if (print_comment_field(cmd) == FALSE)
printf("<tr><td CLASS='optBoxItem' colspan=2>There are no options for this command.<br>Click the 'Commit' button to submit the command.</td></tr>");
break;
case CMD_PROCESS_HOST_CHECK_RESULT:
case CMD_PROCESS_SERVICE_CHECK_RESULT:
printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
printf("</b></td></tr>\n");
if(cmd == CMD_PROCESS_SERVICE_CHECK_RESULT) {
printf("<tr><td CLASS='optBoxRequiredItem'>Service:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='service' VALUE='%s'>", escape_string(service_desc));
printf("</b></td></tr>\n");
}
printf("<tr><td CLASS='optBoxRequiredItem'>Check Result:</td><td><b>");
printf("<SELECT NAME='plugin_state'>");
if(cmd == CMD_PROCESS_SERVICE_CHECK_RESULT) {
printf("<OPTION VALUE=%d SELECTED>OK\n", STATE_OK);
printf("<OPTION VALUE=%d>WARNING\n", STATE_WARNING);
printf("<OPTION VALUE=%d>UNKNOWN\n", STATE_UNKNOWN);
printf("<OPTION VALUE=%d>CRITICAL\n", STATE_CRITICAL);
}
else {
printf("<OPTION VALUE=0 SELECTED>UP\n");
printf("<OPTION VALUE=1>DOWN\n");
printf("<OPTION VALUE=2>UNREACHABLE\n");
}
printf("</SELECT>\n");
printf("</b></td></tr>\n");
printf("<tr><td CLASS='optBoxRequiredItem'>Check Output:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='plugin_output' VALUE=''>");
printf("</b></td></tr>\n");
printf("<tr><td CLASS='optBoxItem'>Performance Data:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='performance_data' VALUE=''>");
printf("</b></td></tr>\n");
break;
case CMD_SCHEDULE_HOST_DOWNTIME:
case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
case CMD_SCHEDULE_SVC_DOWNTIME:
printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
printf("</b></td></tr>\n");
if(cmd == CMD_SCHEDULE_SVC_DOWNTIME) {
printf("<tr><td CLASS='optBoxRequiredItem'>Service:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='service' VALUE='%s'>", escape_string(service_desc));
}
print_comment_field(cmd);
printf("<tr><td CLASS='optBoxItem'><br></td></tr>\n");
printf("<tr><td CLASS='optBoxItem'>Triggered By:</td><td>\n");
printf("<select name='trigger'>\n");
printf("<option value='0'>N/A\n");
for(temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = temp_downtime->next) {
if(temp_downtime->type != HOST_DOWNTIME)
continue;
printf("<option value='%lu'>", temp_downtime->downtime_id);
get_time_string(&temp_downtime->start_time, start_time_str, sizeof(start_time_str), SHORT_DATE_TIME);
printf("ID: %lu, Host '%s' starting @ %s\n", temp_downtime->downtime_id, temp_downtime->host_name, start_time_str);
}
for(temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = temp_downtime->next) {
if(temp_downtime->type != SERVICE_DOWNTIME)
continue;
printf("<option value='%lu'>", temp_downtime->downtime_id);
get_time_string(&temp_downtime->start_time, start_time_str, sizeof(start_time_str), SHORT_DATE_TIME);
printf("ID: %lu, Service '%s' on host '%s' starting @ %s \n", temp_downtime->downtime_id, temp_downtime->service_description, temp_downtime->host_name, start_time_str);
}
printf("</select>\n");
printf("</td></tr>\n");
printf("<tr><td CLASS='optBoxItem'><br></td></tr>\n");
time(&t);
get_time_string(&t, buffer, sizeof(buffer) - 1, SHORT_DATE_TIME);
printf("<tr><td CLASS='optBoxRequiredItem'>Start Time:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='start_time' VALUE='%s'>", buffer);
printf("</b></td></tr>\n");
t += (unsigned long)7200;
get_time_string(&t, buffer, sizeof(buffer) - 1, SHORT_DATE_TIME);
printf("<tr><td CLASS='optBoxRequiredItem'>End Time:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='end_time' VALUE='%s'>", buffer);
printf("</b></td></tr>\n");
printf("<tr><td CLASS='optBoxItem'>Type:</td><td><b>");
printf("<SELECT NAME='fixed'>");
printf("<OPTION VALUE=1>Fixed\n");
printf("<OPTION VALUE=0>Flexible\n");
printf("</SELECT>\n");
printf("</b></td></tr>\n");
printf("<tr><td CLASS='optBoxItem'>If Flexible, Duration:</td><td>");
printf("<table border=0><tr>\n");
printf("<td align=right><INPUT TYPE='TEXT' NAME='hours' VALUE='2' SIZE=2 MAXLENGTH=2></td>\n");
printf("<td align=left>Hours</td>\n");
printf("<td align=right><INPUT TYPE='TEXT' NAME='minutes' VALUE='0' SIZE=2 MAXLENGTH=2></td>\n");
printf("<td align=left>Minutes</td>\n");
printf("</tr></table>\n");
printf("</td></tr>\n");
printf("<tr><td CLASS='optBoxItem'><br></td></tr>\n");
if(cmd == CMD_SCHEDULE_HOST_DOWNTIME) {
printf("<tr><td CLASS='optBoxItem'>Child Hosts:</td><td><b>");
printf("<SELECT name='childoptions'>");
printf("<option value='0'>Do nothing with child hosts\n");
printf("<option value='1'>Schedule triggered downtime for all child hosts\n");
printf("<option value='2'>Schedule non-triggered downtime for all child hosts\n");
printf("</SELECT>\n");
printf("</b></td></tr>\n");
}
printf("<tr><td CLASS='optBoxItem'><br></td></tr>\n");
break;
case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
printf("<tr><td CLASS='optBoxRequiredItem'>Hostgroup Name:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='hostgroup' VALUE='%s'>", escape_string(hostgroup_name));
printf("</b></td></tr>\n");
if(cmd == CMD_ENABLE_HOSTGROUP_SVC_CHECKS || cmd == CMD_DISABLE_HOSTGROUP_SVC_CHECKS || cmd == CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS || cmd == CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS) {
printf("<tr><td CLASS='optBoxItem'>%s For Hosts Too:</td><td><b>", (cmd == CMD_ENABLE_HOSTGROUP_SVC_CHECKS || cmd == CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS) ? "Enable" : "Disable");
printf("<INPUT TYPE='checkbox' NAME='ahas'>");
printf("</b></td></tr>\n");
}
print_comment_field(cmd);
break;
case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
printf("<tr><td CLASS='optBoxRequiredItem'>Servicegroup Name:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='servicegroup' VALUE='%s'>", escape_string(servicegroup_name));
printf("</b></td></tr>\n");
if(cmd == CMD_ENABLE_SERVICEGROUP_SVC_CHECKS || cmd == CMD_DISABLE_SERVICEGROUP_SVC_CHECKS || cmd == CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS || cmd == CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS) {
printf("<tr><td CLASS='optBoxItem'>%s For Hosts Too:</td><td><b>", (cmd == CMD_ENABLE_SERVICEGROUP_SVC_CHECKS || cmd == CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS) ? "Enable" : "Disable");
printf("<INPUT TYPE='checkbox' NAME='ahas'>");
printf("</b></td></tr>\n");
}
print_comment_field(cmd);
break;
case CMD_DEL_HOST_DOWNTIME:
case CMD_DEL_SVC_DOWNTIME:
printf("<tr><td CLASS='optBoxRequiredItem'>Scheduled Downtime ID:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='down_id' VALUE='%lu'>", downtime_id);
printf("</b></td></tr>\n");
print_comment_field(cmd);
break;
case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
if(cmd == CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME) {
printf("<tr><td CLASS='optBoxRequiredItem'>Hostgroup Name:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='hostgroup' VALUE='%s'>", escape_string(hostgroup_name));
printf("</b></td></tr>\n");
}
else {
printf("<tr><td CLASS='optBoxRequiredItem'>Servicegroup Name:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='servicegroup' VALUE='%s'>", escape_string(servicegroup_name));
printf("</b></td></tr>\n");
}
print_comment_field(cmd);
time(&t);
get_time_string(&t, buffer, sizeof(buffer) - 1, SHORT_DATE_TIME);
printf("<tr><td CLASS='optBoxRequiredItem'>Start Time:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='start_time' VALUE='%s'>", buffer);
printf("</b></td></tr>\n");
t += (unsigned long)7200;
get_time_string(&t, buffer, sizeof(buffer) - 1, SHORT_DATE_TIME);
printf("<tr><td CLASS='optBoxRequiredItem'>End Time:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='end_time' VALUE='%s'>", buffer);
printf("</b></td></tr>\n");
printf("<tr><td CLASS='optBoxItem'>Type:</td><td><b>");
printf("<SELECT NAME='fixed'>");
printf("<OPTION VALUE=1>Fixed\n");
printf("<OPTION VALUE=0>Flexible\n");
printf("</SELECT>\n");
printf("</b></td></tr>\n");
printf("<tr><td CLASS='optBoxItem'>If Flexible, Duration:</td><td>");
printf("<table border=0><tr>\n");
printf("<td align=right><INPUT TYPE='TEXT' NAME='hours' VALUE='2' SIZE=2 MAXLENGTH=2></td>\n");
printf("<td align=left>Hours</td>\n");
printf("<td align=right><INPUT TYPE='TEXT' NAME='minutes' VALUE='0' SIZE=2 MAXLENGTH=2></td>\n");
printf("<td align=left>Minutes</td>\n");
printf("</tr></table>\n");
printf("</td></tr>\n");
if(cmd == CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME || cmd == CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME) {
printf("<tr><td CLASS='optBoxItem'>Schedule Downtime For Hosts Too:</td><td><b>");
printf("<INPUT TYPE='checkbox' NAME='ahas'>");
printf("</b></td></tr>\n");
}
break;
case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
printf("</b></td></tr>\n");
if(cmd == CMD_SEND_CUSTOM_SVC_NOTIFICATION) {
printf("<tr><td CLASS='optBoxRequiredItem'>Service:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='service' VALUE='%s'>", escape_string(service_desc));
printf("</b></td></tr>\n");
}
printf("<tr><td CLASS='optBoxItem'>Forced:</td><td><b>");
printf("<INPUT TYPE='checkbox' NAME='force_notification' ");
printf("</b></td></tr>\n");
printf("<tr><td CLASS='optBoxItem'>Broadcast:</td><td><b>");
printf("<INPUT TYPE='checkbox' NAME='broadcast_notification' ");
printf("</b></td></tr>\n");
print_comment_field(cmd);
break;
default:
printf("<tr><td CLASS='optBoxItem'>This should not be happening... :-(</td><td></td></tr>\n");
}
printf("<tr><td CLASS='optBoxItem' COLSPAN=2></td></tr>\n");
printf("<tr><td CLASS='optBoxItem'></td><td CLASS='optBoxItem'><INPUT TYPE='submit' NAME='btnSubmit' VALUE='Commit'> <INPUT TYPE='reset' VALUE='Reset'></td></tr>\n");
printf("</table>\n");
printf("</form>\n");
printf("</td>\n");
printf("</tr>\n");
printf("</table>\n");
printf("</td>\n");
printf("<td align=center valign=top width=50%%>\n");
/* show information about the command... */
show_command_help(cmd);
printf("</td>\n");
printf("</tr>\n");
printf("</table>\n");
printf("</div>\n");
printf("</p>\n");
printf("<P><DIV CLASS='infoMessage'>Please enter all required information before committing the command.<br>Required fields are marked in red.<br>Failure to supply all required values will result in an error.</DIV></P>");
return;
}
int print_comment_field(int cmd_id)
{
char *reqtext = "optBoxItem";
char *comment = comment_data;
struct nagios_extcmd *ecmd = extcmd_get_command_id(cmd_id);
if (!ecmd || ecmd->cmt_opt == 0)
return FALSE;
if (ecmd->cmt_opt == 2)
reqtext = "optBoxRequiredItem";
if (!comment || !*comment) {
if (ecmd->default_comment)
comment = ecmd->default_comment;
}
printf("<tr><td CLASS='%s'>Author (Your Name):</td><td><b>", reqtext);
printf("<INPUT TYPE='TEXT' NAME='com_author' VALUE='%s' %s>", escape_string(comment_author), (lock_author_names == TRUE) ? "READONLY DISABLED" : "");
printf("</b></td></tr>\n");
printf("<tr><td CLASS='%s'>Comment:</td><td><b>", reqtext);
printf("<INPUT TYPE='TEXT' NAME='com_data' VALUE='%s' SIZE=40>", escape_string(comment));
printf("</b></td></tr>\n");
return TRUE;
}
void commit_command_data(int cmd) {
char *error_string = NULL;
int result = OK;
int authorized = FALSE;
service *temp_service;
host *temp_host;
hostgroup *temp_hostgroup;
nagios_comment *temp_comment;
scheduled_downtime *temp_downtime;
servicegroup *temp_servicegroup = NULL;
contact *temp_contact = NULL;
struct nagios_extcmd *ecmd = extcmd_get_command_id(cmd);
/* get authentication information */
get_authentication_information(¤t_authdata);
/* get name to use for author */
if(lock_author_names == TRUE) {
temp_contact = find_contact(current_authdata.username);
if(temp_contact != NULL && temp_contact->alias != NULL) {
comment_author = temp_contact->alias;
}
else {
comment_author = current_authdata.username;
}
}
if (ecmd->cmt_opt == 2 && *comment_data == '\0') {
if(!error_string) {
error_string = strdup("Comment was not entered");
}
}
clean_comment_data(comment_data);
if (*comment_data != '\0' && *comment_author == '\0') {
if(!error_string) {
error_string = strdup("Author was not entered");
}
}
clean_comment_data(comment_author);
switch(cmd) {
case CMD_ADD_HOST_COMMENT:
case CMD_ACKNOWLEDGE_HOST_PROBLEM:
/* see if the user is authorized to issue a command... */
temp_host = find_host(host_name);
if(is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE) {
authorized = TRUE;
}
break;
case CMD_ADD_SVC_COMMENT:
case CMD_ACKNOWLEDGE_SVC_PROBLEM:
/* see if the user is authorized to issue a command... */
temp_service = find_service(host_name, service_desc);
if(is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE) {
authorized = TRUE;
}
break;
case CMD_DEL_HOST_COMMENT:
case CMD_DEL_SVC_COMMENT:
/* check the sanity of the comment id */
if(comment_id == 0) {
if(!error_string) {
error_string = strdup("Comment id cannot be 0");
}
}
/* find the comment */
if(cmd == CMD_DEL_HOST_COMMENT) {
temp_comment = find_host_comment(comment_id);
}
else {
temp_comment = find_service_comment(comment_id);
}
/* see if the user is authorized to issue a command... */
if(cmd == CMD_DEL_HOST_COMMENT && temp_comment != NULL) {
temp_host = find_host(temp_comment->host_name);
if(is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE) {
authorized = TRUE;
}
}
if(cmd == CMD_DEL_SVC_COMMENT && temp_comment != NULL) {
temp_service = find_service(temp_comment->host_name, temp_comment->service_description);
if(is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE) {
authorized = TRUE;
}
}
/* free comment data */
free_comment_data();
break;
case CMD_DEL_HOST_DOWNTIME:
case CMD_DEL_SVC_DOWNTIME:
/* check the sanity of the downtime id */
if(downtime_id == 0) {
if(!error_string) {
error_string = strdup("Downtime id cannot be 0");
}
}
/* find the downtime entry */
if(cmd == CMD_DEL_HOST_DOWNTIME) {
temp_downtime = find_host_downtime(downtime_id);
}
else {
temp_downtime = find_service_downtime(downtime_id);
}
/* see if the user is authorized to issue a command... */
if(cmd == CMD_DEL_HOST_DOWNTIME && temp_downtime != NULL) {
temp_host = find_host(temp_downtime->host_name);
if(is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE) {
authorized = TRUE;
}
}
if(cmd == CMD_DEL_SVC_DOWNTIME && temp_downtime != NULL) {
temp_service = find_service(temp_downtime->host_name, temp_downtime->service_description);
if(is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE) {
authorized = TRUE;
}
}
/* free downtime data */
free_downtime_data();
break;
case CMD_SCHEDULE_SVC_CHECK:
case CMD_ENABLE_SVC_CHECK:
case CMD_DISABLE_SVC_CHECK:
case CMD_DEL_ALL_SVC_COMMENTS:
case CMD_ENABLE_SVC_NOTIFICATIONS:
case CMD_DISABLE_SVC_NOTIFICATIONS:
case CMD_ENABLE_PASSIVE_SVC_CHECKS:
case CMD_DISABLE_PASSIVE_SVC_CHECKS:
case CMD_ENABLE_SVC_EVENT_HANDLER:
case CMD_DISABLE_SVC_EVENT_HANDLER:
case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
case CMD_PROCESS_SERVICE_CHECK_RESULT:
case CMD_SCHEDULE_SVC_DOWNTIME:
case CMD_DELAY_SVC_NOTIFICATION:
case CMD_ENABLE_SVC_FLAP_DETECTION:
case CMD_DISABLE_SVC_FLAP_DETECTION:
case CMD_START_OBSESSING_OVER_SVC:
case CMD_STOP_OBSESSING_OVER_SVC:
case CMD_CLEAR_SVC_FLAPPING_STATE:
/* see if the user is authorized to issue a command... */
temp_service = find_service(host_name, service_desc);
if(is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE) {
authorized = TRUE;
}
/* make sure we have passive check info (if necessary) */
if(cmd == CMD_PROCESS_SERVICE_CHECK_RESULT && !strcmp(plugin_output, "")) {
if(!error_string) {
error_string = strdup("Plugin output cannot be blank");
}
}
/* make sure we have a notification delay (if necessary) */
if(cmd == CMD_DELAY_SVC_NOTIFICATION && notification_delay <= 0) {
if(!error_string) {
error_string = strdup("Notification delay must be greater than 0");
}
}
/* make sure we have check time (if necessary) */
if(cmd == CMD_SCHEDULE_SVC_CHECK && start_time == (time_t)0) {
if(!error_string) {
error_string = strdup("Start time must be non-zero or bad format has been submitted.");
}
}
/* make sure we have start/end times for downtime (if necessary) */
if(cmd == CMD_SCHEDULE_SVC_DOWNTIME && (start_time == (time_t)0 || end_time == (time_t)0 || end_time < start_time)) {
if(!error_string) {
error_string = strdup("Start or end time not valid");
}
}
break;
case CMD_ENABLE_NOTIFICATIONS:
case CMD_DISABLE_NOTIFICATIONS:
case CMD_SHUTDOWN_PROCESS:
case CMD_RESTART_PROCESS:
case CMD_START_EXECUTING_SVC_CHECKS:
case CMD_STOP_EXECUTING_SVC_CHECKS:
case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_ENABLE_EVENT_HANDLERS:
case CMD_DISABLE_EVENT_HANDLERS:
case CMD_START_OBSESSING_OVER_SVC_CHECKS:
case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
case CMD_ENABLE_FLAP_DETECTION:
case CMD_DISABLE_FLAP_DETECTION:
case CMD_ENABLE_PERFORMANCE_DATA:
case CMD_DISABLE_PERFORMANCE_DATA:
case CMD_START_EXECUTING_HOST_CHECKS:
case CMD_STOP_EXECUTING_HOST_CHECKS:
case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
case CMD_START_OBSESSING_OVER_HOST_CHECKS:
case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
/* see if the user is authorized to issue a command... */
if(is_authorized_for_system_commands(¤t_authdata) == TRUE) {
authorized = TRUE;
}
break;
case CMD_ENABLE_HOST_SVC_CHECKS:
case CMD_DISABLE_HOST_SVC_CHECKS:
case CMD_DEL_ALL_HOST_COMMENTS:
case CMD_SCHEDULE_HOST_SVC_CHECKS:
case CMD_ENABLE_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOST_NOTIFICATIONS:
case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
case CMD_ENABLE_HOST_EVENT_HANDLER:
case CMD_DISABLE_HOST_EVENT_HANDLER:
case CMD_ENABLE_HOST_CHECK:
case CMD_DISABLE_HOST_CHECK:
case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
case CMD_SCHEDULE_HOST_DOWNTIME:
case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
case CMD_DELAY_HOST_NOTIFICATION:
case CMD_ENABLE_HOST_FLAP_DETECTION:
case CMD_DISABLE_HOST_FLAP_DETECTION:
case CMD_PROCESS_HOST_CHECK_RESULT:
case CMD_ENABLE_PASSIVE_HOST_CHECKS:
case CMD_DISABLE_PASSIVE_HOST_CHECKS:
case CMD_SCHEDULE_HOST_CHECK:
case CMD_START_OBSESSING_OVER_HOST:
case CMD_STOP_OBSESSING_OVER_HOST:
case CMD_CLEAR_HOST_FLAPPING_STATE:
/* see if the user is authorized to issue a command... */
temp_host = find_host(host_name);
if(is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE) {
authorized = TRUE;
}
/* make sure we have a notification delay (if necessary) */
if(cmd == CMD_DELAY_HOST_NOTIFICATION && notification_delay <= 0) {
if(!error_string) {
error_string = strdup("Notification delay must be greater than 0");
}
}
/* make sure we have start/end times for downtime (if necessary) */
if((cmd == CMD_SCHEDULE_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOST_SVC_DOWNTIME) && (start_time == (time_t)0 || end_time == (time_t)0 || start_time > end_time)) {
if(!error_string) {
error_string = strdup("Start or end time not valid");
}
}
/* make sure we have check time (if necessary) */
if((cmd == CMD_SCHEDULE_HOST_CHECK || cmd == CMD_SCHEDULE_HOST_SVC_CHECKS) && start_time == (time_t)0) {
if(!error_string) {
error_string = strdup("Start time must be non-zero or bad format has been submitted.");
}
}
/* make sure we have passive check info (if necessary) */
if(cmd == CMD_PROCESS_HOST_CHECK_RESULT && !strcmp(plugin_output, "")) {
if(!error_string) {
error_string = strdup("Plugin output cannot be blank");
}
}
break;
case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
/* make sure we have start/end times for downtime */
if((cmd == CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME) && (start_time == (time_t)0 || end_time == (time_t)0 || start_time > end_time)) {
if(!error_string) {
error_string = strdup("Start or end time not valid");
}
}
/* see if the user is authorized to issue a command... */
temp_hostgroup = find_hostgroup(hostgroup_name);
if(is_authorized_for_hostgroup_commands(temp_hostgroup, ¤t_authdata) == TRUE) {
authorized = TRUE;
}
break;
case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
/* make sure we have start/end times for downtime */
if((cmd == CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME || cmd == CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME) && (start_time == (time_t)0 || end_time == (time_t)0 || start_time > end_time)) {
if(!error_string) {
error_string = strdup("Start or end time not valid");
}
}
/* see if the user is authorized to issue a command... */
temp_servicegroup = find_servicegroup(servicegroup_name);
if(is_authorized_for_servicegroup_commands(temp_servicegroup, ¤t_authdata) == TRUE) {
authorized = TRUE;
}
break;
case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
/* see if the user is authorized to issue a command... */
if(cmd == CMD_SEND_CUSTOM_HOST_NOTIFICATION) {
temp_host = find_host(host_name);
if(is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE) {
authorized = TRUE;
}
}
else {
temp_service = find_service(host_name, service_desc);
if(is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE) {
authorized = TRUE;
}
}
break;
default:
if(!error_string) {
error_string = strdup("An error occurred while processing your command!");
}
}
/* to be safe, we are going to REQUIRE that the authentication functionality is enabled... */
if(use_authentication == FALSE) {
if(content_type == WML_CONTENT) {
printf("<p>Error: Authentication is not enabled!</p>\n");
}
else {
printf("<P>\n");
printf("<DIV CLASS='errorMessage'>Sorry Dave, I can't let you do that...</DIV><br>");
printf("<DIV CLASS='errorDescription'>");
printf("It seems that you have chosen to not use the authentication functionality of the CGIs.<br><br>");
printf("I don't want to be personally responsible for what may happen as a result of allowing unauthorized users to issue commands to Nagios,");
printf("so you'll have to disable this safeguard if you are really stubborn and want to invite trouble.<br><br>");
printf("<strong>Read the section on CGI authentication in the HTML documentation to learn how you can enable authentication and why you should want to.</strong>\n");
printf("</DIV>\n");
printf("</P>\n");
}
}
/* the user is not authorized to issue the given command */
else if(authorized == FALSE) {
if(content_type == WML_CONTENT) {
printf("<p>Error: You're not authorized to commit that command!</p>\n");
}
else {
printf("<P><DIV CLASS='errorMessage'>Sorry, but you are not authorized to commit the specified command.</DIV></P>\n");
printf("<P><DIV CLASS='errorDescription'>Read the section of the documentation that deals with authentication and authorization in the CGIs for more information.<BR><BR>\n");
printf("<A HREF='javascript:window.history.go(-2)'>Return from whence you came</A></DIV></P>\n");
}
}
/* some error occurred (data was probably missing) */
else if(error_string) {
if(content_type == WML_CONTENT) {
printf("<p>%s</p>\n", error_string);
}
else {
printf("<P><DIV CLASS='errorMessage'>%s</DIV></P>\n", error_string);
printf("<P><DIV CLASS='errorDescription'>Go <A HREF='javascript:window.history.go(-1)'>back</A> and verify that you entered all required information correctly.<BR>\n");
printf("<A HREF='javascript:window.history.go(-2)'>Return from whence you came</A></DIV></P>\n");
}
}
/* if Nagios isn't checking external commands, don't do anything... */
else if(check_external_commands == FALSE) {
if(content_type == WML_CONTENT) {
printf("<p>Error: Nagios is not checking external commands!</p>\n");
}
else {
printf("<P><DIV CLASS='errorMessage'>Sorry, but Nagios is currently not checking for external commands, so your command will not be committed!</DIV></P>\n");
printf("<P><DIV CLASS='errorDescription'>Read the documentation for information on how to enable external commands...<BR><BR>\n");
printf("<A HREF='javascript:window.history.go(-2)'>Return from whence you came</A></DIV></P>\n");
}
}
/* everything looks okay, so let's go ahead and commit the command... */
else {
/* commit the command */
result = commit_command(cmd);
if(result == OK) {
if(content_type == WML_CONTENT) {
printf("<p>Your command was submitted successfully...</p>\n");
}
else {
printf("<P><DIV CLASS='infoMessage'>Your command request was successfully submitted to Nagios for processing.<BR><BR>\n");
printf("Note: It may take a while before the command is actually processed.<BR><BR>\n");
printf("<A HREF='javascript:window.history.go(-2)'>Done</A></DIV></P>");
}
}
else {
if(content_type == WML_CONTENT) {
printf("<p>An error occurred while committing your command!</p>\n");
}
else {
printf("<P><DIV CLASS='errorMessage'>An error occurred while attempting to commit your command for processing.<BR><BR>\n");
printf("<A HREF='javascript:window.history.go(-2)'>Return from whence you came</A></DIV></P>\n");
}
}
}
my_free(error_string);
}
__attribute__((format(printf, 2, 3)))
static int cmd_submitf(int id, const char *fmt, ...) {
char cmd[MAX_EXTERNAL_COMMAND_LENGTH];
const char *command_name;
int len;
int len2;
va_list ap;
command_name = extcmd_get_name(id);
/*
* We disallow sending 'CHANGE' commands from the cgi's
* until we do proper session handling to prevent cross-site
* request forgery
*/
if(!command_name || (strlen(command_name) > 6 && !memcmp("CHANGE", command_name, 6)))
return ERROR;
len = snprintf(cmd, sizeof(cmd), "[%lu] %s;", time(NULL), command_name);
if(len < 0 || len >= sizeof(cmd))
return ERROR;
if(fmt) {
va_start(ap, fmt);
len2 = vsnprintf(cmd + len, sizeof(cmd) - len, fmt, ap);
va_end(ap);
len += len2;
if(len2 < 0 || len >= sizeof(cmd))
return ERROR;
}
if (*comment_data != '\0') {
len2 = snprintf(cmd + len, sizeof(cmd) - len, ";%s;%s", comment_author, comment_data);
len += len2;
if(len2 < 0 || len >= sizeof(cmd))
return ERROR;
}
cmd[len] = 0; /* 0 <= len < sizeof(cmd) */
return write_command_to_file(cmd);
}
/* commits a command for processing */
int commit_command(int cmd) {
time_t current_time;
time_t scheduled_time;
time_t notification_time;
int result;
/* get the current time */
time(¤t_time);
/* get the scheduled time */
scheduled_time = current_time + (schedule_delay * 60);
/* get the notification time */
notification_time = current_time + (notification_delay * 60);
/*
* these are supposed to be implanted inside the
* completed commands shipped off to nagios and
* must therefore never contain ';'
*/
if(host_name && strchr(host_name, ';'))
return ERROR;
if(service_desc && strchr(service_desc, ';'))
return ERROR;
if(comment_author && strchr(comment_author, ';'))
return ERROR;
if(hostgroup_name && strchr(hostgroup_name, ';'))
return ERROR;
if(servicegroup_name && strchr(servicegroup_name, ';'))
return ERROR;
/* decide how to form the command line... */
switch(cmd) {
/* commands without arguments */
case CMD_START_EXECUTING_SVC_CHECKS:
case CMD_STOP_EXECUTING_SVC_CHECKS:
case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_ENABLE_EVENT_HANDLERS:
case CMD_DISABLE_EVENT_HANDLERS:
case CMD_START_OBSESSING_OVER_SVC_CHECKS:
case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
case CMD_ENABLE_FLAP_DETECTION:
case CMD_DISABLE_FLAP_DETECTION:
case CMD_ENABLE_PERFORMANCE_DATA:
case CMD_DISABLE_PERFORMANCE_DATA:
case CMD_START_EXECUTING_HOST_CHECKS:
case CMD_STOP_EXECUTING_HOST_CHECKS:
case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
case CMD_START_OBSESSING_OVER_HOST_CHECKS:
case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
result = cmd_submitf(cmd, NULL);
break;
/** simple host commands **/
case CMD_ENABLE_HOST_FLAP_DETECTION:
case CMD_DISABLE_HOST_FLAP_DETECTION:
case CMD_ENABLE_PASSIVE_HOST_CHECKS:
case CMD_DISABLE_PASSIVE_HOST_CHECKS:
case CMD_START_OBSESSING_OVER_HOST:
case CMD_STOP_OBSESSING_OVER_HOST:
case CMD_DEL_ALL_HOST_COMMENTS:
case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_ENABLE_HOST_EVENT_HANDLER:
case CMD_DISABLE_HOST_EVENT_HANDLER:
case CMD_ENABLE_HOST_CHECK:
case CMD_DISABLE_HOST_CHECK:
case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
case CMD_CLEAR_HOST_FLAPPING_STATE:
result = cmd_submitf(cmd, "%s", host_name);
break;
/** simple service commands **/
case CMD_ENABLE_SVC_FLAP_DETECTION:
case CMD_DISABLE_SVC_FLAP_DETECTION:
case CMD_ENABLE_PASSIVE_SVC_CHECKS:
case CMD_DISABLE_PASSIVE_SVC_CHECKS:
case CMD_START_OBSESSING_OVER_SVC:
case CMD_STOP_OBSESSING_OVER_SVC:
case CMD_DEL_ALL_SVC_COMMENTS:
case CMD_ENABLE_SVC_NOTIFICATIONS:
case CMD_DISABLE_SVC_NOTIFICATIONS:
case CMD_ENABLE_SVC_EVENT_HANDLER:
case CMD_DISABLE_SVC_EVENT_HANDLER:
case CMD_ENABLE_SVC_CHECK:
case CMD_DISABLE_SVC_CHECK:
case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
case CMD_CLEAR_SVC_FLAPPING_STATE:
result = cmd_submitf(cmd, "%s;%s", host_name, service_desc);
break;
case CMD_ADD_HOST_COMMENT:
result = cmd_submitf(cmd, "%s;%d", host_name, persistent_comment);
break;
case CMD_ADD_SVC_COMMENT:
result = cmd_submitf(cmd, "%s;%s;%d", host_name, service_desc, persistent_comment);
break;
case CMD_DEL_HOST_COMMENT:
case CMD_DEL_SVC_COMMENT:
result = cmd_submitf(cmd, "%lu", comment_id);
break;
case CMD_DELAY_HOST_NOTIFICATION:
result = cmd_submitf(cmd, "%s;%lu", host_name, notification_time);
break;
case CMD_DELAY_SVC_NOTIFICATION:
result = cmd_submitf(cmd, "%s;%s;%lu", host_name, service_desc, notification_time);
break;
case CMD_SCHEDULE_SVC_CHECK:
case CMD_SCHEDULE_FORCED_SVC_CHECK:
if(force_check == TRUE)
cmd = CMD_SCHEDULE_FORCED_SVC_CHECK;
result = cmd_submitf(cmd, "%s;%s;%lu", host_name, service_desc, start_time);
break;
case CMD_DISABLE_NOTIFICATIONS:
case CMD_ENABLE_NOTIFICATIONS:
case CMD_SHUTDOWN_PROCESS:
case CMD_RESTART_PROCESS:
result = cmd_submitf(cmd, "%lu", scheduled_time);
break;
case CMD_ENABLE_HOST_SVC_CHECKS:
case CMD_DISABLE_HOST_SVC_CHECKS:
result = cmd_submitf(cmd, "%s", host_name);
if(affect_host_and_services == TRUE) {
cmd = (cmd == CMD_ENABLE_HOST_SVC_CHECKS) ? CMD_ENABLE_HOST_CHECK : CMD_DISABLE_HOST_CHECK;
result |= cmd_submitf(cmd, "%s", host_name);
}
break;
case CMD_SCHEDULE_HOST_SVC_CHECKS:
if(force_check == TRUE)
cmd = CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS;
result = cmd_submitf(cmd, "%s;%lu", host_name, scheduled_time);
break;
case CMD_ENABLE_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOST_NOTIFICATIONS:
if(propagate_to_children == TRUE)
cmd = (cmd == CMD_ENABLE_HOST_NOTIFICATIONS) ? CMD_ENABLE_HOST_AND_CHILD_NOTIFICATIONS : CMD_DISABLE_HOST_AND_CHILD_NOTIFICATIONS;
result = cmd_submitf(cmd, "%s", host_name);
break;
case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
result = cmd_submitf(cmd, "%s", host_name);
if(affect_host_and_services == TRUE) {
cmd = (cmd == CMD_ENABLE_HOST_SVC_NOTIFICATIONS) ? CMD_ENABLE_HOST_NOTIFICATIONS : CMD_DISABLE_HOST_NOTIFICATIONS;
result |= cmd_submitf(cmd, "%s", host_name);
}
break;
case CMD_ACKNOWLEDGE_HOST_PROBLEM:
result = cmd_submitf(cmd, "%s;%d;%d;%d", host_name, (sticky_ack == TRUE) ? ACKNOWLEDGEMENT_STICKY : ACKNOWLEDGEMENT_NORMAL, send_notification, persistent_comment);
break;
case CMD_ACKNOWLEDGE_SVC_PROBLEM:
result = cmd_submitf(cmd, "%s;%s;%d;%d;%d", host_name, service_desc, (sticky_ack == TRUE) ? ACKNOWLEDGEMENT_STICKY : ACKNOWLEDGEMENT_NORMAL, send_notification, persistent_comment);
break;
case CMD_PROCESS_SERVICE_CHECK_RESULT:
result = cmd_submitf(cmd, "%s;%s;%d;%s|%s", host_name, service_desc, plugin_state, plugin_output, performance_data);
break;
case CMD_PROCESS_HOST_CHECK_RESULT:
result = cmd_submitf(cmd, "%s;%d;%s|%s", host_name, plugin_state, plugin_output, performance_data);
break;
case CMD_SCHEDULE_HOST_DOWNTIME:
if(child_options == 1)
cmd = CMD_SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME;
else if(child_options == 2)
cmd = CMD_SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME;
result = cmd_submitf(cmd, "%s;%lu;%lu;%d;%lu;%lu", host_name, start_time, end_time, fixed, triggered_by, duration);
break;
case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
result = cmd_submitf(cmd, "%s;%lu;%lu;%d;%lu;%lu", host_name, start_time, end_time, fixed, triggered_by, duration);
break;
case CMD_SCHEDULE_SVC_DOWNTIME:
result = cmd_submitf(cmd, "%s;%s;%lu;%lu;%d;%lu;%lu", host_name, service_desc, start_time, end_time, fixed, triggered_by, duration);
break;
case CMD_DEL_HOST_DOWNTIME:
case CMD_DEL_SVC_DOWNTIME:
result = cmd_submitf(cmd, "%lu", downtime_id);
break;
case CMD_SCHEDULE_HOST_CHECK:
if(force_check == TRUE)
cmd = CMD_SCHEDULE_FORCED_HOST_CHECK;
result = cmd_submitf(cmd, "%s;%lu", host_name, start_time);
break;
case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
result = cmd_submitf(cmd, "%s;%d", host_name, (force_notification | broadcast_notification));
break;
case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
result = cmd_submitf(cmd, "%s;%s;%d", host_name, service_desc, (force_notification | broadcast_notification));
break;
/***** HOSTGROUP COMMANDS *****/
case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
result = cmd_submitf(cmd, "%s", hostgroup_name);
if(affect_host_and_services == TRUE) {
cmd = (cmd == CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS) ? CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS : CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS;
result |= cmd_submitf(cmd, "%s", hostgroup_name);
}
break;
case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
result = cmd_submitf(cmd, "%s", hostgroup_name);
break;
case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
result = cmd_submitf(cmd, "%s", hostgroup_name);
if(affect_host_and_services == TRUE) {
cmd = (cmd == CMD_ENABLE_HOSTGROUP_SVC_CHECKS) ? CMD_ENABLE_HOSTGROUP_HOST_CHECKS : CMD_DISABLE_HOSTGROUP_HOST_CHECKS;
result |= cmd_submitf(cmd, "%s", hostgroup_name);
}
break;
case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
result = cmd_submitf(cmd, "%s;%lu;%lu;%d;0;%lu", hostgroup_name, start_time, end_time, fixed, duration);
break;
case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
result = cmd_submitf(cmd, "%s;%lu;%lu;%d;0;%lu", hostgroup_name, start_time, end_time, fixed, duration);
if(affect_host_and_services == TRUE)
result |= cmd_submitf(CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME, "%s;%lu;%lu;%d;0;%lu", hostgroup_name, start_time, end_time, fixed, duration);
break;
/***** SERVICEGROUP COMMANDS *****/
case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
result = cmd_submitf(cmd, "%s", servicegroup_name);
if(affect_host_and_services == TRUE) {
cmd = (cmd == CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS) ? CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS : CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS;
result |= cmd_submitf(cmd, "%s", servicegroup_name);
}
break;
case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
result = cmd_submitf(cmd, "%s", servicegroup_name);
break;
case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
result = cmd_submitf(cmd, "%s", servicegroup_name);
if(affect_host_and_services == TRUE) {
cmd = (cmd == CMD_ENABLE_SERVICEGROUP_SVC_CHECKS) ? CMD_ENABLE_SERVICEGROUP_HOST_CHECKS : CMD_DISABLE_SERVICEGROUP_HOST_CHECKS;
result |= cmd_submitf(cmd, "%s", servicegroup_name);
}
break;
case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
result = cmd_submitf(cmd, "%s;%lu;%lu;%d;0;%lu", servicegroup_name, start_time, end_time, fixed, duration);
break;
case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
result = cmd_submitf(cmd, "%s;%lu;%lu;%d;0;%lu", servicegroup_name, start_time, end_time, fixed, duration);
if(affect_host_and_services == TRUE)
result |= cmd_submitf(CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME, "%s;%lu;%lu;%d;0;%lu", servicegroup_name, start_time, end_time, fixed, duration);
break;
default:
return ERROR;
break;
}
return result;
}
/* write a command entry to the command file */
int write_command_to_file(char *cmd) {
FILE *fp;
struct stat statbuf;
/*
* Commands are not allowed to have newlines in them, as
* that allows malicious users to hand-craft requests that
* bypass the access-restrictions.
*/
if(!cmd || !*cmd || strchr(cmd, '\n'))
return ERROR;
/* bail out if the external command file doesn't exist */
if(stat(command_file, &statbuf)) {
if(content_type == WML_CONTENT)
printf("<p>Error: Could not stat() external command file!</p>\n");
else {
printf("<P><DIV CLASS='errorMessage'>Error: Could not stat() command file '%s'!</DIV></P>\n", command_file);
printf("<P><DIV CLASS='errorDescription'>");
printf("The external command file may be missing, Nagios may not be running, and/or Nagios may not be checking external commands.\n");
printf("</DIV></P>\n");
}
return ERROR;
}
/* open the command for writing (since this is a pipe, it will really be appended) */
fp = fopen(command_file, "w");
if(fp == NULL) {
if(content_type == WML_CONTENT)
printf("<p>Error: Could not open command file for update!</p>\n");
else {
printf("<P><DIV CLASS='errorMessage'>Error: Could not open command file '%s' for update!</DIV></P>\n", command_file);
printf("<P><DIV CLASS='errorDescription'>");
printf("The permissions on the external command file and/or directory may be incorrect. Read the FAQs on how to setup proper permissions.\n");
printf("</DIV></P>\n");
}
return ERROR;
}
/* write the command to file */
fprintf(fp, "%s\n", cmd);
/* flush buffer */
fflush(fp);
fclose(fp);
return OK;
}
/* strips out semicolons from comment data */
void clean_comment_data(char *buffer) {
int x;
int y;
if (!buffer || !*buffer)
return;
y = (int)strlen(buffer);
for(x = 0; x < y; x++) {
if(buffer[x] == ';')
buffer[x] = ' ';
}
return;
}
/* display information about a command */
void show_command_help(int cmd) {
printf("<DIV ALIGN=CENTER CLASS='descriptionTitle'>Command Description</DIV>\n");
printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 CLASS='commandDescription'>\n");
printf("<TR><TD CLASS='commandDescription'>\n");
/* decide what information to print out... */
switch(cmd) {
case CMD_ADD_HOST_COMMENT:
printf("This command is used to add a comment for the specified host. If you work with other administrators, you may find it useful to share information about a host\n");
printf("that is having problems if more than one of you may be working on it. If you do not check the 'persistent' option, the comment will be automatically be deleted\n");
printf("the next time Nagios is restarted.\n");
break;
case CMD_ADD_SVC_COMMENT:
printf("This command is used to add a comment for the specified service. If you work with other administrators, you may find it useful to share information about a host\n");
printf("or service that is having problems if more than one of you may be working on it. If you do not check the 'persistent' option, the comment will automatically be\n");
printf("deleted the next time Nagios is restarted.\n");
break;
case CMD_DEL_HOST_COMMENT:
printf("This command is used to delete a specific host comment.\n");
break;
case CMD_DEL_SVC_COMMENT:
printf("This command is used to delete a specific service comment.\n");
break;
case CMD_DELAY_HOST_NOTIFICATION:
printf("This command is used to delay the next problem notification that is sent out for the specified host. The notification delay will be disregarded if\n");
printf("the host changes state before the next notification is scheduled to be sent out. This command has no effect if the host is currently UP.\n");
break;
case CMD_DELAY_SVC_NOTIFICATION:
printf("This command is used to delay the next problem notification that is sent out for the specified service. The notification delay will be disregarded if\n");
printf("the service changes state before the next notification is scheduled to be sent out. This command has no effect if the service is currently in an OK state.\n");
break;
case CMD_SCHEDULE_SVC_CHECK:
printf("This command is used to schedule the next check of a particular service. Nagios will re-queue the service to be checked at the time you specify.\n");
printf("If you select the <i>force check</i> option, Nagios will force a check of the service regardless of both what time the scheduled check occurs and whether or not checks are enabled for the service.\n");
break;
case CMD_ENABLE_SVC_CHECK:
printf("This command is used to enable active checks of a service.\n");
break;
case CMD_DISABLE_SVC_CHECK:
printf("This command is used to disable active checks of a service.\n");
break;
case CMD_DISABLE_NOTIFICATIONS:
printf("This command is used to disable host and service notifications on a program-wide basis.\n");
break;
case CMD_ENABLE_NOTIFICATIONS:
printf("This command is used to enable host and service notifications on a program-wide basis.\n");
break;
case CMD_SHUTDOWN_PROCESS:
printf("This command is used to shutdown the Nagios process. Note: Once the Nagios has been shutdown, it cannot be restarted via the web interface!\n");
break;
case CMD_RESTART_PROCESS:
printf("This command is used to restart the Nagios process. Executing a restart command is equivalent to sending the process a HUP signal.\n");
printf("All information will be flushed from memory, the configuration files will be re-read, and Nagios will start monitoring with the new configuration information.\n");
break;
case CMD_ENABLE_HOST_SVC_CHECKS:
printf("This command is used to enable active checks of all services associated with the specified host. This <i>does not</i> enable checks of the host unless you check the 'Enable for host too' option.\n");
break;
case CMD_DISABLE_HOST_SVC_CHECKS:
printf("This command is used to disable active checks of all services associated with the specified host. When a service is disabled Nagios will not monitor the service. Doing this will prevent any notifications being sent out for\n");
printf("the specified service while it is disabled. In order to have Nagios check the service in the future you will have to re-enable the service.\n");
printf("Note that disabling service checks may not necessarily prevent notifications from being sent out about the host which those services are associated with. This <i>does not</i> disable checks of the host unless you check the 'Disable for host too' option.\n");
break;
case CMD_SCHEDULE_HOST_SVC_CHECKS:
printf("This command is used to scheduled the next check of all services on the specified host. If you select the <i>force check</i> option, Nagios will force a check of all services on the host regardless of both what time the scheduled checks occur and whether or not checks are enabled for those services.\n");
break;
case CMD_DEL_ALL_HOST_COMMENTS:
printf("This command is used to delete all comments associated with the specified host.\n");
break;
case CMD_DEL_ALL_SVC_COMMENTS:
printf("This command is used to delete all comments associated with the specified service.\n");
break;
case CMD_ENABLE_SVC_NOTIFICATIONS:
printf("This command is used to enable notifications for the specified service. Notifications will only be sent out for the\n");
printf("service state types you defined in your service definition.\n");
break;
case CMD_DISABLE_SVC_NOTIFICATIONS:
printf("This command is used to prevent notifications from being sent out for the specified service. You will have to re-enable notifications\n");
printf("for this service before any alerts can be sent out in the future.\n");
break;
case CMD_ENABLE_HOST_NOTIFICATIONS:
printf("This command is used to enable notifications for the specified host. Notifications will only be sent out for the\n");
printf("host state types you defined in your host definition. Note that this command <i>does not</i> enable notifications\n");
printf("for services associated with this host.\n");
break;
case CMD_DISABLE_HOST_NOTIFICATIONS:
printf("This command is used to prevent notifications from being sent out for the specified host. You will have to re-enable notifications for this host\n");
printf("before any alerts can be sent out in the future. Note that this command <i>does not</i> disable notifications for services associated with this host.\n");
break;
case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
printf("This command is used to enable notifications for all hosts and services that lie \"beyond\" the specified host\n");
printf("(from the view of Nagios).\n");
break;
case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
printf("This command is used to temporarily prevent notifications from being sent out for all hosts and services that lie\n");
printf("\"beyond\" the specified host (from the view of Nagios).\n");
break;
case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
printf("This command is used to enable notifications for all services on the specified host. Notifications will only be sent out for the\n");
printf("service state types you defined in your service definition. This <i>does not</i> enable notifications for the host unless you check the 'Enable for host too' option.\n");
break;
case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
printf("This command is used to prevent notifications from being sent out for all services on the specified host. You will have to re-enable notifications for\n");
printf("all services associated with this host before any alerts can be sent out in the future. This <i>does not</i> prevent notifications from being sent out about the host unless you check the 'Disable for host too' option.\n");
break;
case CMD_ACKNOWLEDGE_HOST_PROBLEM:
printf("This command is used to acknowledge a host problem. When a host problem is acknowledged, future notifications about problems are temporarily disabled until the host changes from its current state.\n");
printf("If you want acknowledgement to disable notifications until the host recovers, check the 'Sticky Acknowledgement' checkbox.\n");
printf("Contacts for this host will receive a notification about the acknowledgement, so they are aware that someone is working on the problem. Additionally, a comment will also be added to the host.\n");
printf("Make sure to enter your name and fill in a brief description of what you are doing in the comment field. If you would like the host comment to remain once the acknowledgement is removed, check\n");
printf("the 'Persistent Comment' checkbox. If you do not want an acknowledgement notification sent out to the appropriate contacts, uncheck the 'Send Notification' checkbox.\n");
break;
case CMD_ACKNOWLEDGE_SVC_PROBLEM:
printf("This command is used to acknowledge a service problem. When a service problem is acknowledged, future notifications about problems are temporarily disabled until the service changes from its current state.\n");
printf("If you want acknowledgement to disable notifications until the service recovers, check the 'Sticky Acknowledgement' checkbox.\n");
printf("Contacts for this service will receive a notification about the acknowledgement, so they are aware that someone is working on the problem. Additionally, a comment will also be added to the service.\n");
printf("Make sure to enter your name and fill in a brief description of what you are doing in the comment field. If you would like the service comment to remain once the acknowledgement is removed, check\n");
printf("the 'Persistent Comment' checkbox. If you do not want an acknowledgement notification sent out to the appropriate contacts, uncheck the 'Send Notification' checkbox.\n");
break;
case CMD_START_EXECUTING_SVC_CHECKS:
printf("This command is used to resume execution of active service checks on a program-wide basis. Individual services which are disabled will still not be checked.\n");
break;
case CMD_STOP_EXECUTING_SVC_CHECKS:
printf("This command is used to temporarily stop Nagios from actively executing any service checks. This will have the side effect of preventing any notifications from being sent out (for any and all services and hosts).\n");
printf("Service checks will not be executed again until you issue a command to resume service check execution.\n");
break;
case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
printf("This command is used to make Nagios start accepting passive service check results that it finds in the external command file\n");
break;
case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
printf("This command is use to make Nagios stop accepting passive service check results that it finds in the external command file. All passive check results that are found will be ignored.\n");
break;
case CMD_ENABLE_PASSIVE_SVC_CHECKS:
printf("This command is used to allow Nagios to accept passive service check results that it finds in the external command file for this particular service.\n");
break;
case CMD_DISABLE_PASSIVE_SVC_CHECKS:
printf("This command is used to stop Nagios accepting passive service check results that it finds in the external command file for this particular service. All passive check results that are found for this service will be ignored.\n");
break;
case CMD_ENABLE_EVENT_HANDLERS:
printf("This command is used to allow Nagios to run host and service event handlers.\n");
break;
case CMD_DISABLE_EVENT_HANDLERS:
printf("This command is used to temporarily prevent Nagios from running any host or service event handlers.\n");
break;
case CMD_ENABLE_SVC_EVENT_HANDLER:
printf("This command is used to allow Nagios to run the service event handler for a particular service when necessary (if one is defined).\n");
break;
case CMD_DISABLE_SVC_EVENT_HANDLER:
printf("This command is used to temporarily prevent Nagios from running the service event handler for a particular service.\n");
break;
case CMD_ENABLE_HOST_EVENT_HANDLER:
printf("This command is used to allow Nagios to run the host event handler for a particular service when necessary (if one is defined).\n");
break;
case CMD_DISABLE_HOST_EVENT_HANDLER:
printf("This command is used to temporarily prevent Nagios from running the host event handler for a particular host.\n");
break;
case CMD_ENABLE_HOST_CHECK:
printf("This command is used to enable active checks of this host.\n");
break;
case CMD_DISABLE_HOST_CHECK:
printf("This command is used to temporarily prevent Nagios from actively checking the status of a particular host. If Nagios needs to check the status of this host, it will assume that it is in the same state that it was in before checks were disabled.\n");
break;
case CMD_START_OBSESSING_OVER_SVC_CHECKS:
printf("This command is used to have Nagios start obsessing over service checks. Read the documentation on distributed monitoring for more information on this.\n");
break;
case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
printf("This command is used stop Nagios from obsessing over service checks.\n");
break;
case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
printf("This command is used to remove an acknowledgement for a particular host problem. Once the acknowledgement is removed, notifications may start being\n");
printf("sent out about the host problem. \n");
break;
case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
printf("This command is used to remove an acknowledgement for a particular service problem. Once the acknowledgement is removed, notifications may start being\n");
printf("sent out about the service problem.\n");
break;
case CMD_PROCESS_SERVICE_CHECK_RESULT:
printf("This command is used to submit a passive check result for a particular service. It is particularly useful for resetting security-related services to OK states once they have been dealt with.\n");
break;
case CMD_PROCESS_HOST_CHECK_RESULT:
printf("This command is used to submit a passive check result for a particular host.\n");
break;
case CMD_SCHEDULE_HOST_DOWNTIME:
printf("This command is used to schedule downtime for a particular host. During the specified downtime, Nagios will not send notifications out about the host.\n");
printf("When the scheduled downtime expires, Nagios will send out notifications for this host as it normally would. Scheduled downtimes are preserved\n");
printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n");
printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n");
printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when the host goes down or becomes unreachable (sometime between the\n");
printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed downtime.\n");
break;
case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
printf("This command is used to schedule downtime for all services on a particular host. During the specified downtime, Nagios will not send notifications out about the host.\n");
printf("Normally, a host in downtime will not send alerts about any services in a failed state. This option will explicitly set downtime for all services for this host.\n");
printf("When the scheduled downtime expires, Nagios will send out notifications for this host as it normally would. Scheduled downtimes are preserved\n");
printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n");
printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n");
printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when the host goes down or becomes unreachable (sometime between the\n");
printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed downtime.\n");
break;
case CMD_SCHEDULE_SVC_DOWNTIME:
printf("This command is used to schedule downtime for a particular service. During the specified downtime, Nagios will not send notifications out about the service.\n");
printf("When the scheduled downtime expires, Nagios will send out notifications for this service as it normally would. Scheduled downtimes are preserved\n");
printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n");
printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n");
printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when the service enters a non-OK state (sometime between the\n");
printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed downtime.\n");
break;
case CMD_ENABLE_HOST_FLAP_DETECTION:
printf("This command is used to enable flap detection for a specific host. If flap detection is disabled on a program-wide basis, this will have no effect,\n");
break;
case CMD_DISABLE_HOST_FLAP_DETECTION:
printf("This command is used to disable flap detection for a specific host.\n");
break;
case CMD_ENABLE_SVC_FLAP_DETECTION:
printf("This command is used to enable flap detection for a specific service. If flap detection is disabled on a program-wide basis, this will have no effect,\n");
break;
case CMD_DISABLE_SVC_FLAP_DETECTION:
printf("This command is used to disable flap detection for a specific service.\n");
break;
case CMD_ENABLE_FLAP_DETECTION:
printf("This command is used to enable flap detection for hosts and services on a program-wide basis. Individual hosts and services may have flap detection disabled.\n");
break;
case CMD_DISABLE_FLAP_DETECTION:
printf("This command is used to disable flap detection for hosts and services on a program-wide basis.\n");
break;
case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
printf("This command is used to enable notifications for all services in the specified hostgroup. Notifications will only be sent out for the\n");
printf("service state types you defined in your service definitions. This <i>does not</i> enable notifications for the hosts in this hostgroup unless you check the 'Enable for hosts too' option.\n");
break;
case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
printf("This command is used to prevent notifications from being sent out for all services in the specified hostgroup. You will have to re-enable notifications for\n");
printf("all services in this hostgroup before any alerts can be sent out in the future. This <i>does not</i> prevent notifications from being sent out about the hosts in this hostgroup unless you check the 'Disable for hosts too' option.\n");
break;
case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
printf("This command is used to enable notifications for all hosts in the specified hostgroup. Notifications will only be sent out for the\n");
printf("host state types you defined in your host definitions.\n");
break;
case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
printf("This command is used to prevent notifications from being sent out for all hosts in the specified hostgroup. You will have to re-enable notifications for\n");
printf("all hosts in this hostgroup before any alerts can be sent out in the future.\n");
break;
case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
printf("This command is used to enable active checks of all services in the specified hostgroup. This <i>does not</i> enable active checks of the hosts in the hostgroup unless you check the 'Enable for hosts too' option.\n");
break;
case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
printf("This command is used to disable active checks of all services in the specified hostgroup. This <i>does not</i> disable checks of the hosts in the hostgroup unless you check the 'Disable for hosts too' option.\n");
break;
case CMD_DEL_HOST_DOWNTIME:
printf("This command is used to cancel active or pending scheduled downtime for the specified host.\n");
break;
case CMD_DEL_SVC_DOWNTIME:
printf("This command is used to cancel active or pending scheduled downtime for the specified service.\n");
break;
case CMD_ENABLE_PERFORMANCE_DATA:
printf("This command is used to enable the processing of performance data for hosts and services on a program-wide basis. Individual hosts and services may have performance data processing disabled.\n");
break;
case CMD_DISABLE_PERFORMANCE_DATA:
printf("This command is used to disable the processing of performance data for hosts and services on a program-wide basis.\n");
break;
case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
printf("This command is used to schedule downtime for all hosts in a particular hostgroup. During the specified downtime, Nagios will not send notifications out about the hosts.\n");
printf("When the scheduled downtime expires, Nagios will send out notifications for the hosts as it normally would. Scheduled downtimes are preserved\n");
printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n");
printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n");
printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when a host goes down or becomes unreachable (sometime between the\n");
printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed downtime.\n");
break;
case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
printf("This command is used to schedule downtime for all services in a particular hostgroup. During the specified downtime, Nagios will not send notifications out about the services.\n");
printf("When the scheduled downtime expires, Nagios will send out notifications for the services as it normally would. Scheduled downtimes are preserved\n");
printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n");
printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n");
printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when a service enters a non-OK state (sometime between the\n");
printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed downtime.\n");
printf("Note that scheduling downtime for services does not automatically schedule downtime for the hosts those services are associated with. If you want to also schedule downtime for all hosts in the hostgroup, check the 'Schedule downtime for hosts too' option.\n");
break;
case CMD_START_EXECUTING_HOST_CHECKS:
printf("This command is used to enable active host checks on a program-wide basis.\n");
break;
case CMD_STOP_EXECUTING_HOST_CHECKS:
printf("This command is used to disable active host checks on a program-wide basis.\n");
break;
case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
printf("This command is used to have Nagios start obsessing over host checks. Read the documentation on distributed monitoring for more information on this.\n");
break;
case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
printf("This command is used to stop Nagios from obsessing over host checks.\n");
break;
case CMD_ENABLE_PASSIVE_HOST_CHECKS:
printf("This command is used to allow Nagios to accept passive host check results that it finds in the external command file for a particular host.\n");
break;
case CMD_DISABLE_PASSIVE_HOST_CHECKS:
printf("This command is used to stop Nagios from accepting passive host check results that it finds in the external command file for a particular host. All passive check results that are found for this host will be ignored.\n");
break;
case CMD_START_OBSESSING_OVER_HOST_CHECKS:
printf("This command is used to have Nagios start obsessing over host checks. Read the documentation on distributed monitoring for more information on this.\n");
break;
case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
printf("This command is used to stop Nagios from obsessing over host checks.\n");
break;
case CMD_SCHEDULE_HOST_CHECK:
printf("This command is used to schedule the next check of a particular host. Nagios will re-queue the host to be checked at the time you specify.\n");
printf("If you select the <i>force check</i> option, Nagios will force a check of the host regardless of both what time the scheduled check occurs and whether or not checks are enabled for the host.\n");
break;
case CMD_START_OBSESSING_OVER_SVC:
printf("This command is used to have Nagios start obsessing over a particular service.\n");
break;
case CMD_STOP_OBSESSING_OVER_SVC:
printf("This command is used to stop Nagios from obsessing over a particular service.\n");
break;
case CMD_START_OBSESSING_OVER_HOST:
printf("This command is used to have Nagios start obsessing over a particular host.\n");
break;
case CMD_STOP_OBSESSING_OVER_HOST:
printf("This command is used to stop Nagios from obsessing over a particular host.\n");
break;
case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
printf("This command is used to enable notifications for all services in the specified servicegroup. Notifications will only be sent out for the\n");
printf("service state types you defined in your service definitions. This <i>does not</i> enable notifications for the hosts in this servicegroup unless you check the 'Enable for hosts too' option.\n");
break;
case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
printf("This command is used to prevent notifications from being sent out for all services in the specified servicegroup. You will have to re-enable notifications for\n");
printf("all services in this servicegroup before any alerts can be sent out in the future. This <i>does not</i> prevent notifications from being sent out about the hosts in this servicegroup unless you check the 'Disable for hosts too' option.\n");
break;
case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
printf("This command is used to enable notifications for all hosts in the specified servicegroup. Notifications will only be sent out for the\n");
printf("host state types you defined in your host definitions.\n");
break;
case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
printf("This command is used to prevent notifications from being sent out for all hosts in the specified servicegroup. You will have to re-enable notifications for\n");
printf("all hosts in this servicegroup before any alerts can be sent out in the future.\n");
break;
case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
printf("This command is used to enable active checks of all services in the specified servicegroup. This <i>does not</i> enable active checks of the hosts in the servicegroup unless you check the 'Enable for hosts too' option.\n");
break;
case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
printf("This command is used to disable active checks of all services in the specified servicegroup. This <i>does not</i> disable checks of the hosts in the servicegroup unless you check the 'Disable for hosts too' option.\n");
break;
case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
printf("This command is used to schedule downtime for all hosts in a particular servicegroup. During the specified downtime, Nagios will not send notifications out about the hosts.\n");
printf("When the scheduled downtime expires, Nagios will send out notifications for the hosts as it normally would. Scheduled downtimes are preserved\n");
printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n");
printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n");
printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when a host goes down or becomes unreachable (sometime between the\n");
printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed downtime.\n");
break;
case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
printf("This command is used to schedule downtime for all services in a particular servicegroup. During the specified downtime, Nagios will not send notifications out about the services.\n");
printf("When the scheduled downtime expires, Nagios will send out notifications for the services as it normally would. Scheduled downtimes are preserved\n");
printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n");
printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n");
printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when a service enters a non-OK state (sometime between the\n");
printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed downtime.\n");
printf("Note that scheduling downtime for services does not automatically schedule downtime for the hosts those services are associated with. If you want to also schedule downtime for all hosts in the servicegroup, check the 'Schedule downtime for hosts too' option.\n");
break;
case CMD_CLEAR_HOST_FLAPPING_STATE:
case CMD_CLEAR_SVC_FLAPPING_STATE:
printf("This command is used to reset the flapping state for the specified %s.\n",
(cmd == CMD_CLEAR_HOST_FLAPPING_STATE) ? "host" : "service");
printf("All state history for the specified %s will be cleared.\n",
(cmd == CMD_CLEAR_HOST_FLAPPING_STATE) ? "host" : "service");
break;
case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
printf("This command is used to send a custom notification about the specified %s. Useful in emergencies when you need to notify admins of an issue regarding a monitored system or service.\n", (cmd == CMD_SEND_CUSTOM_HOST_NOTIFICATION) ? "host" : "service");
printf("Custom notifications normally follow the regular notification logic in Nagios. Selecting the <i>Forced</i> option will force the notification to be sent out, regardless of the time restrictions, whether or not notifications are enabled, etc. Selecting the <i>Broadcast</i> option causes the notification to be sent out to all normal (non-escalated) and escalated contacts. These options allow you to override the normal notification logic if you need to get an important message out.\n");
break;
default:
printf("Sorry, but no information is available for this command.");
}
printf("</TD></TR>\n");
printf("</TABLE>\n");
return;
}
/* converts a time string to a UNIX timestamp, respecting the date_format option */
int string_to_time(char *buffer, time_t *t) {
struct tm lt;
int ret = 0;
/* Initialize some variables just in case they don't get parsed
by the sscanf() call. A better solution is to also check the
CGI input for validity, but this should suffice to prevent
strange problems if the input is not valid.
Jan 15 2003 Steve Bonds */
lt.tm_mon = 0;
lt.tm_mday = 1;
lt.tm_year = 1900;
lt.tm_hour = 0;
lt.tm_min = 0;
lt.tm_sec = 0;
lt.tm_wday = 0;
lt.tm_yday = 0;
if(date_format == DATE_FORMAT_EURO)
ret = sscanf(buffer, "%02d-%02d-%04d %02d:%02d:%02d", <.tm_mday, <.tm_mon, <.tm_year, <.tm_hour, <.tm_min, <.tm_sec);
else if(date_format == DATE_FORMAT_ISO8601 || date_format == DATE_FORMAT_STRICT_ISO8601)
ret = sscanf(buffer, "%04d-%02d-%02d%*[ T]%02d:%02d:%02d", <.tm_year, <.tm_mon, <.tm_mday, <.tm_hour, <.tm_min, <.tm_sec);
else
ret = sscanf(buffer, "%02d-%02d-%04d %02d:%02d:%02d", <.tm_mon, <.tm_mday, <.tm_year, <.tm_hour, <.tm_min, <.tm_sec);
if(ret != 6)
return ERROR;
lt.tm_mon--;
lt.tm_year -= 1900;
/* tell mktime() to try and compute DST automatically */
lt.tm_isdst = -1;
*t = mktime(<);
return OK;
}
|