/usr/lib/python2.7/dist-packages/shinken/external_command.py is in shinken-common 1.4-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2009-2012:
# Gabes Jean, naparuba@gmail.com
# Gerhard Lausser, Gerhard.Lausser@consol.de
# Gregory Starck, g.starck@gmail.com
# Hartmut Goebel, h.goebel@goebel-consult.de
#
# This file is part of Shinken.
#
# Shinken is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Shinken 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Shinken. If not, see <http://www.gnu.org/licenses/>.
import os
import time
from shinken.util import to_int, to_bool
from shinken.downtime import Downtime
from shinken.contactdowntime import ContactDowntime
from shinken.comment import Comment
from shinken.commandcall import CommandCall
from shinken.log import logger, console_logger
from shinken.pollerlink import PollerLink
MODATTR_NONE = 0
MODATTR_NOTIFICATIONS_ENABLED = 1
MODATTR_ACTIVE_CHECKS_ENABLED = 2
MODATTR_PASSIVE_CHECKS_ENABLED = 4
MODATTR_EVENT_HANDLER_ENABLED = 8
MODATTR_FLAP_DETECTION_ENABLED = 16
MODATTR_FAILURE_PREDICTION_ENABLED = 32
MODATTR_PERFORMANCE_DATA_ENABLED = 64
MODATTR_OBSESSIVE_HANDLER_ENABLED = 128
MODATTR_EVENT_HANDLER_COMMAND = 256
MODATTR_CHECK_COMMAND = 512
MODATTR_NORMAL_CHECK_INTERVAL = 1024
MODATTR_RETRY_CHECK_INTERVAL = 2048
MODATTR_MAX_CHECK_ATTEMPTS = 4096
MODATTR_FRESHNESS_CHECKS_ENABLED = 8192
MODATTR_CHECK_TIMEPERIOD = 16384
MODATTR_CUSTOM_VARIABLE = 32768
MODATTR_NOTIFICATION_TIMEPERIOD = 65536
""" TODO: Add some comment about this class for the doc"""
class ExternalCommand:
my_type = 'externalcommand'
def __init__(self, cmd_line):
self.cmd_line = cmd_line
""" TODO: Add some comment about this class for the doc"""
class ExternalCommandManager:
commands = {
'CHANGE_CONTACT_MODSATTR': {'global': True, 'args': ['contact', None]},
'CHANGE_CONTACT_MODHATTR': {'global': True, 'args': ['contact', None]},
'CHANGE_CONTACT_MODATTR': {'global': True, 'args': ['contact', None]},
'CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD': {'global': True, 'args': ['contact', 'time_period']},
'ADD_SVC_COMMENT': {'global': False, 'args': ['service', 'to_bool', 'author', None]},
'ADD_HOST_COMMENT': {'global': False, 'args': ['host', 'to_bool', 'author', None]},
'ACKNOWLEDGE_SVC_PROBLEM': {'global': False, 'args': ['service', 'to_int', 'to_bool', 'to_bool', 'author', None]},
'ACKNOWLEDGE_HOST_PROBLEM': {'global': False, 'args': ['host', 'to_int', 'to_bool', 'to_bool', 'author', None]},
'ACKNOWLEDGE_SVC_PROBLEM_EXPIRE': {'global': False, 'args': ['service', 'to_int', 'to_bool', 'to_bool', 'to_int', 'author', None]},
'ACKNOWLEDGE_HOST_PROBLEM_EXPIRE': {'global': False, 'args': ['host', 'to_int', 'to_bool', 'to_bool', 'to_int', 'author', None]},
'CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD': {'global': True, 'args': ['contact', 'time_period']},
'CHANGE_CUSTOM_CONTACT_VAR': {'global': True, 'args': ['contact', None, None]},
'CHANGE_CUSTOM_HOST_VAR': {'global': False, 'args': ['host', None, None]},
'CHANGE_CUSTOM_SVC_VAR': {'global': False, 'args': ['service', None, None]},
'CHANGE_GLOBAL_HOST_EVENT_HANDLER': {'global': True, 'args': ['command']},
'CHANGE_GLOBAL_SVC_EVENT_HANDLER': {'global': True, 'args': ['command']},
'CHANGE_HOST_CHECK_COMMAND': {'global': False, 'args': ['host', 'command']},
'CHANGE_HOST_CHECK_TIMEPERIOD': {'global': False, 'args': ['host', 'time_period']},
'CHANGE_HOST_EVENT_HANDLER': {'global': False, 'args': ['host', 'command']},
'CHANGE_HOST_MODATTR': {'global': False, 'args': ['host', 'to_int']},
'CHANGE_MAX_HOST_CHECK_ATTEMPTS': {'global': False, 'args': ['host', 'to_int']},
'CHANGE_MAX_SVC_CHECK_ATTEMPTS': {'global': False, 'args': ['service', 'to_int']},
'CHANGE_NORMAL_HOST_CHECK_INTERVAL': {'global': False, 'args': ['host', 'to_int']},
'CHANGE_NORMAL_SVC_CHECK_INTERVAL': {'global': False, 'args': ['service', 'to_int']},
'CHANGE_RETRY_HOST_CHECK_INTERVAL': {'global': False, 'args': ['service', 'to_int']},
'CHANGE_RETRY_SVC_CHECK_INTERVAL': {'global': False, 'args': ['service', 'to_int']},
'CHANGE_SVC_CHECK_COMMAND': {'global': False, 'args': ['service', 'command']},
'CHANGE_SVC_CHECK_TIMEPERIOD': {'global': False, 'args': ['service', 'time_period']},
'CHANGE_SVC_EVENT_HANDLER': {'global': False, 'args': ['service', 'command']},
'CHANGE_SVC_MODATTR': {'global': False, 'args': ['service', 'to_int']},
'CHANGE_SVC_NOTIFICATION_TIMEPERIOD': {'global': False, 'args': ['service', 'time_period']},
'DELAY_HOST_NOTIFICATION': {'global': False, 'args': ['host', 'to_int']},
'DELAY_SVC_NOTIFICATION': {'global': False, 'args': ['service', 'to_int']},
'DEL_ALL_HOST_COMMENTS': {'global': False, 'args': ['host']},
'DEL_ALL_HOST_DOWNTIMES': {'global': False, 'args': ['host']},
'DEL_ALL_SVC_COMMENTS': {'global': False, 'args': ['service']},
'DEL_ALL_SVC_DOWNTIMES': {'global': False, 'args': ['service']},
'DEL_CONTACT_DOWNTIME': {'global': True, 'args': ['to_int']},
'DEL_HOST_COMMENT': {'global': True, 'args': ['to_int']},
'DEL_HOST_DOWNTIME': {'global': True, 'args': ['to_int']},
'DEL_SVC_COMMENT': {'global': True, 'args': ['to_int']},
'DEL_SVC_DOWNTIME': {'global': True, 'args': ['to_int']},
'DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST': {'global': False, 'args': ['host']},
'DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS': {'global': True, 'args': ['contact_group']},
'DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS': {'global': True, 'args': ['contact_group']},
'DISABLE_CONTACT_HOST_NOTIFICATIONS': {'global': True, 'args': ['contact']},
'DISABLE_CONTACT_SVC_NOTIFICATIONS': {'global': True, 'args': ['contact']},
'DISABLE_EVENT_HANDLERS': {'global': True, 'args': []},
'DISABLE_FAILURE_PREDICTION': {'global': True, 'args': []},
'DISABLE_FLAP_DETECTION': {'global': True, 'args': []},
'DISABLE_HOSTGROUP_HOST_CHECKS': {'global': True, 'args': ['host_group']},
'DISABLE_HOSTGROUP_HOST_NOTIFICATIONS': {'global': True, 'args': ['host_group']},
'DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS': {'global': True, 'args': ['host_group']},
'DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS': {'global': True, 'args': ['host_group']},
'DISABLE_HOSTGROUP_SVC_CHECKS': {'global': True, 'args': ['host_group']},
'DISABLE_HOSTGROUP_SVC_NOTIFICATIONS': {'global': True, 'args': ['host_group']},
'DISABLE_HOST_AND_CHILD_NOTIFICATIONS': {'global': False, 'args': ['host']},
'DISABLE_HOST_CHECK': {'global': False, 'args': ['host']},
'DISABLE_HOST_EVENT_HANDLER': {'global': False, 'args': ['host']},
'DISABLE_HOST_FLAP_DETECTION': {'global': False, 'args': ['host']},
'DISABLE_HOST_FRESHNESS_CHECKS': {'global': True, 'args': []},
'DISABLE_HOST_NOTIFICATIONS': {'global': False, 'args': ['host']},
'DISABLE_HOST_SVC_CHECKS': {'global': False, 'args': ['host']},
'DISABLE_HOST_SVC_NOTIFICATIONS': {'global': False, 'args': ['host']},
'DISABLE_NOTIFICATIONS': {'global': True, 'args': []},
'DISABLE_PASSIVE_HOST_CHECKS': {'global': False, 'args': ['host']},
'DISABLE_PASSIVE_SVC_CHECKS': {'global': False, 'args': ['service']},
'DISABLE_PERFORMANCE_DATA': {'global': True, 'args': []},
'DISABLE_SERVICEGROUP_HOST_CHECKS': {'global': True, 'args': ['service_group']},
'DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS': {'global': True, 'args': ['service_group']},
'DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS': {'global': True, 'args': ['service_group']},
'DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS': {'global': True, 'args': ['service_group']},
'DISABLE_SERVICEGROUP_SVC_CHECKS': {'global': True, 'args': ['service_group']},
'DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS': {'global': True, 'args': ['service_group']},
'DISABLE_SERVICE_FLAP_DETECTION': {'global': False, 'args': ['service']},
'DISABLE_SERVICE_FRESHNESS_CHECKS': {'global': True, 'args': []},
'DISABLE_SVC_CHECK': {'global': False, 'args': ['service']},
'DISABLE_SVC_EVENT_HANDLER': {'global': False, 'args': ['service']},
'DISABLE_SVC_FLAP_DETECTION': {'global': False, 'args': ['service']},
'DISABLE_SVC_NOTIFICATIONS': {'global': False, 'args': ['service']},
'ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST': {'global': False, 'args': ['host']},
'ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS': {'global': True, 'args': ['contact_group']},
'ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS': {'global': True, 'args': ['contact_group']},
'ENABLE_CONTACT_HOST_NOTIFICATIONS': {'global': True, 'args': ['contact']},
'ENABLE_CONTACT_SVC_NOTIFICATIONS': {'global': True, 'args': ['contact']},
'ENABLE_EVENT_HANDLERS': {'global': True, 'args': []},
'ENABLE_FAILURE_PREDICTION': {'global': True, 'args': []},
'ENABLE_FLAP_DETECTION': {'global': True, 'args': []},
'ENABLE_HOSTGROUP_HOST_CHECKS': {'global': True, 'args': ['host_group']},
'ENABLE_HOSTGROUP_HOST_NOTIFICATIONS': {'global': True, 'args': ['host_group']},
'ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS': {'global': True, 'args': ['host_group']},
'ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS': {'global': True, 'args': ['host_group']},
'ENABLE_HOSTGROUP_SVC_CHECKS': {'global': True, 'args': ['host_group']},
'ENABLE_HOSTGROUP_SVC_NOTIFICATIONS': {'global': True, 'args': ['host_group']},
'ENABLE_HOST_AND_CHILD_NOTIFICATIONS': {'global': False, 'args': ['host']},
'ENABLE_HOST_CHECK': {'global': False, 'args': ['host']},
'ENABLE_HOST_EVENT_HANDLER': {'global': False, 'args': ['host']},
'ENABLE_HOST_FLAP_DETECTION': {'global': False, 'args': ['host']},
'ENABLE_HOST_FRESHNESS_CHECKS': {'global': True, 'args': []},
'ENABLE_HOST_NOTIFICATIONS': {'global': False, 'args': ['host']},
'ENABLE_HOST_SVC_CHECKS': {'global': False, 'args': ['host']},
'ENABLE_HOST_SVC_NOTIFICATIONS': {'global': False, 'args': ['host']},
'ENABLE_NOTIFICATIONS': {'global': True, 'args': []},
'ENABLE_PASSIVE_HOST_CHECKS': {'global': False, 'args': ['host']},
'ENABLE_PASSIVE_SVC_CHECKS': {'global': False, 'args': ['service']},
'ENABLE_PERFORMANCE_DATA': {'global': True, 'args': []},
'ENABLE_SERVICEGROUP_HOST_CHECKS': {'global': True, 'args': ['service_group']},
'ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS': {'global': True, 'args': ['service_group']},
'ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS': {'global': True, 'args': ['service_group']},
'ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS': {'global': True, 'args': ['service_group']},
'ENABLE_SERVICEGROUP_SVC_CHECKS': {'global': True, 'args': ['service_group']},
'ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS': {'global': True, 'args': ['service_group']},
'ENABLE_SERVICE_FRESHNESS_CHECKS': {'global': True, 'args': []},
'ENABLE_SVC_CHECK': {'global': False, 'args': ['service']},
'ENABLE_SVC_EVENT_HANDLER': {'global': False, 'args': ['service']},
'ENABLE_SVC_FLAP_DETECTION': {'global': False, 'args': ['service']},
'ENABLE_SVC_NOTIFICATIONS': {'global': False, 'args': ['service']},
'PROCESS_FILE': {'global': True, 'args': [None, 'to_bool']},
'PROCESS_HOST_CHECK_RESULT': {'global': False, 'args': ['host', 'to_int', None]},
'PROCESS_HOST_OUTPUT': {'global': False, 'args': ['host', None]},
'PROCESS_SERVICE_CHECK_RESULT': {'global': False, 'args': ['service', 'to_int', None]},
'PROCESS_SERVICE_OUTPUT': {'global': False, 'args': ['service', None]},
'READ_STATE_INFORMATION': {'global': True, 'args': []},
'REMOVE_HOST_ACKNOWLEDGEMENT': {'global': False, 'args': ['host']},
'REMOVE_SVC_ACKNOWLEDGEMENT': {'global': False, 'args': ['service']},
'RESTART_PROGRAM': {'global': True, 'args': []},
'SAVE_STATE_INFORMATION': {'global': True, 'args': []},
'SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME': {'global': False, 'args': ['host', 'to_int', 'to_int', 'to_bool', 'to_int', 'to_int', 'author', None]},
'SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME': {'global': False, 'args': ['host', 'to_int', 'to_int', 'to_bool', 'to_int', 'to_int', 'author', None]},
'SCHEDULE_CONTACT_DOWNTIME': {'global': True, 'args': ['contact', 'to_int', 'to_int', 'author', None]},
'SCHEDULE_FORCED_HOST_CHECK': {'global': False, 'args': ['host', 'to_int']},
'SCHEDULE_FORCED_HOST_SVC_CHECKS': {'global': False, 'args': ['host', 'to_int']},
'SCHEDULE_FORCED_SVC_CHECK': {'global': False, 'args': ['service', 'to_int']},
'SCHEDULE_HOSTGROUP_HOST_DOWNTIME': {'global': True, 'args': ['host_group', 'to_int', 'to_int', 'to_bool', 'to_int', 'to_int', 'author', None]},
'SCHEDULE_HOSTGROUP_SVC_DOWNTIME': {'global': True, 'args': ['host_group', 'to_int', 'to_int', 'to_bool', 'to_int', 'to_int', 'author', None]},
'SCHEDULE_HOST_CHECK': {'global': False, 'args': ['host', 'to_int']},
'SCHEDULE_HOST_DOWNTIME': {'global': False, 'args': ['host', 'to_int', 'to_int', 'to_bool', 'to_int', 'to_int', 'author', None]},
'SCHEDULE_HOST_SVC_CHECKS': {'global': False, 'args': ['host', 'to_int']},
'SCHEDULE_HOST_SVC_DOWNTIME': {'global': False, 'args': ['host', 'to_int', 'to_int', 'to_bool', 'to_int', 'to_int', 'author', None]},
'SCHEDULE_SERVICEGROUP_HOST_DOWNTIME': {'global': True, 'args': ['service_group', 'to_int', 'to_int', 'to_bool', 'to_int', 'to_int', 'author', None]},
'SCHEDULE_SERVICEGROUP_SVC_DOWNTIME': {'global': True, 'args': ['service_group', 'to_int', 'to_int', 'to_bool', 'to_int', 'to_int', 'author', None]},
'SCHEDULE_SVC_CHECK': {'global': False, 'args': ['service', 'to_int']},
'SCHEDULE_SVC_DOWNTIME': {'global': False, 'args': ['service', 'to_int', 'to_int', 'to_bool', 'to_int', 'to_int', 'author', None]},
'SEND_CUSTOM_HOST_NOTIFICATION': {'global': False, 'args': ['host', 'to_int', 'author', None]},
'SEND_CUSTOM_SVC_NOTIFICATION': {'global': False, 'args': ['service', 'to_int', 'author', None]},
'SET_HOST_NOTIFICATION_NUMBER': {'global': False, 'args': ['host', 'to_int']},
'SET_SVC_NOTIFICATION_NUMBER': {'global': False, 'args': ['service', 'to_int']},
'SHUTDOWN_PROGRAM': {'global': True, 'args': []},
'START_ACCEPTING_PASSIVE_HOST_CHECKS': {'global': True, 'args': []},
'START_ACCEPTING_PASSIVE_SVC_CHECKS': {'global': True, 'args': []},
'START_EXECUTING_HOST_CHECKS': {'global': True, 'args': []},
'START_EXECUTING_SVC_CHECKS': {'global': True, 'args': []},
'START_OBSESSING_OVER_HOST': {'global': False, 'args': ['host']},
'START_OBSESSING_OVER_HOST_CHECKS': {'global': True, 'args': []},
'START_OBSESSING_OVER_SVC': {'global': False, 'args': ['service']},
'START_OBSESSING_OVER_SVC_CHECKS': {'global': True, 'args': []},
'STOP_ACCEPTING_PASSIVE_HOST_CHECKS': {'global': True, 'args': []},
'STOP_ACCEPTING_PASSIVE_SVC_CHECKS': {'global': True, 'args': []},
'STOP_EXECUTING_HOST_CHECKS': {'global': True, 'args': []},
'STOP_EXECUTING_SVC_CHECKS': {'global': True, 'args': []},
'STOP_OBSESSING_OVER_HOST': {'global': False, 'args': ['host']},
'STOP_OBSESSING_OVER_HOST_CHECKS': {'global': True, 'args': []},
'STOP_OBSESSING_OVER_SVC': {'global': False, 'args': ['service']},
'STOP_OBSESSING_OVER_SVC_CHECKS': {'global': True, 'args': []},
'LAUNCH_SVC_EVENT_HANDLER': {'global': False, 'args': ['service']},
'LAUNCH_HOST_EVENT_HANDLER': {'global': False, 'args': ['host']},
# Now internal calls
'ADD_SIMPLE_HOST_DEPENDENCY': {'global': False, 'args': ['host', 'host']},
'DEL_HOST_DEPENDENCY': {'global': False, 'args': ['host', 'host']},
'ADD_SIMPLE_POLLER': {'global': True, 'internal': True, 'args': [None, None, None, None]},
}
def __init__(self, conf, mode):
self.mode = mode
if conf:
self.conf = conf
self.hosts = conf.hosts
self.services = conf.services
self.contacts = conf.contacts
self.hostgroups = conf.hostgroups
self.commands = conf.commands
self.servicegroups = conf.servicegroups
self.contactgroups = conf.contactgroups
self.timeperiods = conf.timeperiods
self.pipe_path = conf.command_file
self.fifo = None
self.cmd_fragments = ''
if self.mode == 'dispatcher':
self.confs = conf.confs
# Will change for each command read, so if a command need it,
# it can get it
self.current_timestamp = 0
def load_scheduler(self, scheduler):
self.sched = scheduler
def load_arbiter(self, arbiter):
self.arbiter = arbiter
def load_receiver(self, receiver):
self.receiver = receiver
def open(self):
# At the first open del and create the fifo
if self.fifo is None:
if os.path.exists(self.pipe_path):
os.unlink(self.pipe_path)
if not os.path.exists(self.pipe_path):
os.umask(0)
try:
os.mkfifo(self.pipe_path, 0660)
open(self.pipe_path, 'w+', os.O_NONBLOCK)
except OSError, exp:
self.error("Pipe creation failed (%s): %s" % (self.pipe_path, str(exp)))
return None
self.fifo = os.open(self.pipe_path, os.O_NONBLOCK)
return self.fifo
def get(self):
buf = os.read(self.fifo, 8096)
r = []
fullbuf = len(buf) == 8096 and True or False
# If the buffer ended with a fragment last time, prepend it here
buf = self.cmd_fragments + buf
buflen = len(buf)
self.cmd_fragments = ''
if fullbuf and buf[-1] != '\n':
# The buffer was full but ends with a command fragment
r.extend([ExternalCommand(s) for s in (buf.split('\n'))[:-1] if s])
self.cmd_fragments = (buf.split('\n'))[-1]
elif buflen:
# The buffer is either half-filled or full with a '\n' at the end.
r.extend([ExternalCommand(s) for s in buf.split('\n') if s])
else:
# The buffer is empty. We "reset" the fifo here. It will be
# re-opened in the main loop.
os.close(self.fifo)
return r
def resolve_command(self, excmd):
# Maybe the command is invalid. Bailout
try:
command = excmd.cmd_line
except AttributeError, exp:
logger.debug("resolve_command:: error with command %s: %s" % (excmd, exp))
return
# Strip and get utf8 only strings
command = command.strip()
# Only log if we are in the Arbiter
if self.mode == 'dispatcher' and self.conf.log_external_commands:
logger.info('EXTERNAL COMMAND: ' + command.rstrip())
r = self.get_command_and_args(command, excmd)
# If we are a receiver, bail out here
if self.mode == 'receiver':
return
if r is not None:
is_global = r['global']
if not is_global:
c_name = r['c_name']
args = r['args']
logger.debug("Got commands %s %s" % (c_name, str(args)))
f = getattr(self, c_name)
apply(f, args)
else:
command = r['cmd']
self.dispatch_global_command(command)
# Ok the command is not for every one, so we search
# by the hostname which scheduler have the host. Then send
# the command
def search_host_and_dispatch(self, host_name, command, extcmd):
logger.debug("Calling search_host_and_dispatch for %s" % host_name)
# If we are a receiver, just look in the receiver
if self.mode == 'receiver':
logger.info("Receiver looking a scheduler for the external command %s %s" % (host_name, command))
sched = self.receiver.get_sched_from_hname(host_name)
logger.debug("Receiver found a scheduler: %s" % (sched))
if sched:
logger.info("Receiver pushing external command to scheduler %s" % (sched))
sched['external_commands'].append(extcmd)
return
host_found = False
for cfg in self.confs.values():
if cfg.hosts.find_by_name(host_name) is not None:
logger.debug("Host %s found in a configuration" % host_name)
if cfg.is_assigned:
host_found = True
sched = cfg.assigned_to
logger.debug("Sending command to the scheduler %s" % sched.get_name())
#sched.run_external_command(command)
sched.external_commands.append(command)
break
else:
logger.warning("Problem: a configuration is found, but is not assigned!")
if not host_found:
logger.warning("Passive check result was received for host '%s', but the host could not be found!" % host_name)
#print "Sorry but the host", host_name, "was not found"
# The command is global, so sent it to every schedulers
def dispatch_global_command(self, command):
for sched in self.conf.schedulers:
logger.debug("Sending a command '%s' to scheduler %s" % (command, sched))
if sched.alive:
#sched.run_external_command(command)
sched.external_commands.append(command)
# We need to get the first part, the command name, and the reference ext command object
def get_command_and_args(self, command, extcmd=None):
#safe_print("Trying to resolve", command)
command = command.rstrip()
elts = command.split(';') # danger!!! passive checkresults with perfdata
part1 = elts[0]
elts2 = part1.split(' ')
#print "Elts2:", elts2
if len(elts2) != 2:
logger.debug("Malformed command '%s'" % command)
return None
ts = elts2[0]
# Now we will get the timestamps as [123456]
if not ts.startswith('[') or not ts.endswith(']'):
logger.debug("Malformed command '%s'" % command)
return None
# Ok we remove the [ ]
ts = ts[1:-1]
try: # is an int or not?
self.current_timestamp = int(ts)
except ValueError:
logger.debug("Malformed command '%s'" % command)
return None
# Now get the command
c_name = elts2[1]
#safe_print("Get command name", c_name)
if c_name not in ExternalCommandManager.commands:
logger.debug("Command '%s' is not recognized, sorry" % c_name)
return None
# Split again based on the number of args we expect. We cannot split
# on every ; because this character may appear in the perfdata of
# passive check results.
entry = ExternalCommandManager.commands[c_name]
# Look if the command is purely internal or not
internal = False
if 'internal' in entry and entry['internal']:
internal = True
numargs = len(entry['args'])
if numargs and 'service' in entry['args']:
numargs += 1
elts = command.split(';', numargs)
logger.debug("mode= %s, global= %s" % (self.mode, str(entry['global'])))
if self.mode == 'dispatcher' and entry['global']:
if not internal:
logger.debug("Command '%s' is a global one, we resent it to all schedulers" % c_name)
return {'global': True, 'cmd': command}
#print "Is global?", c_name, entry['global']
#print "Mode:", self.mode
#print "This command have arguments:", entry['args'], len(entry['args'])
args = []
i = 1
in_service = False
tmp_host = ''
try:
for elt in elts[1:]:
logger.debug("Searching for a new arg: %s (%d)" % (elt, i))
val = elt.strip()
if val.endswith('\n'):
val = val[:-1]
logger.debug("For command arg: %s" % val)
if not in_service:
type_searched = entry['args'][i-1]
#safe_print("Search for a arg", type_searched)
if type_searched == 'host':
if self.mode == 'dispatcher' or self.mode == 'receiver':
self.search_host_and_dispatch(val, command, extcmd)
return None
h = self.hosts.find_by_name(val)
if h is not None:
args.append(h)
elif type_searched == 'contact':
c = self.contacts.find_by_name(val)
if c is not None:
args.append(c)
elif type_searched == 'time_period':
t = self.timeperiods.find_by_name(val)
if t is not None:
args.append(t)
elif type_searched == 'to_bool':
args.append(to_bool(val))
elif type_searched == 'to_int':
args.append(to_int(val))
elif type_searched in ('author', None):
args.append(val)
elif type_searched == 'command':
c = self.commands.find_by_name(val)
if c is not None:
# the find will be redone by
# the commandCall creation, but != None
# is useful so a bad command will be caught
args.append(val)
elif type_searched == 'host_group':
hg = self.hostgroups.find_by_name(val)
if hg is not None:
args.append(hg)
elif type_searched == 'service_group':
sg = self.servicegroups.find_by_name(val)
if sg is not None:
args.append(sg)
elif type_searched == 'contact_group':
cg = self.contact_groups.find_by_name(val)
if cg is not None:
args.append(cg)
# special case: service are TWO args host;service, so one more loop
# to get the two parts
elif type_searched == 'service':
in_service = True
tmp_host = elt.strip()
#safe_print("TMP HOST", tmp_host)
if tmp_host[-1] == '\n':
tmp_host = tmp_host[:-1]
if self.mode == 'dispatcher':
self.search_host_and_dispatch(tmp_host, command, extcmd)
return None
i += 1
else:
in_service = False
srv_name = elt
if srv_name[-1] == '\n':
srv_name = srv_name[:-1]
# If we are in a receiver, bailout now.
if self.mode == 'receiver':
self.search_host_and_dispatch(tmp_host, command, extcmd)
return None
#safe_print("Got service full", tmp_host, srv_name)
s = self.services.find_srv_by_name_and_hostname(tmp_host, srv_name)
if s is not None:
args.append(s)
else: # error, must be logged
logger.warning("A command was received for service '%s' on host '%s', but the service could not be found!" % (srv_name, tmp_host))
except IndexError:
logger.debug("Sorry, the arguments are not corrects")
return None
#safe_print('Finally got ARGS:', args)
if len(args) == len(entry['args']):
#safe_print("OK, we can call the command", c_name, "with", args)
return {'global': False, 'c_name': c_name, 'args': args}
#f = getattr(self, c_name)
#apply(f, args)
else:
logger.debug("Sorry, the arguments are not corrects (%s)" % str(args))
return None
# CHANGE_CONTACT_MODSATTR;<contact_name>;<value>
def CHANGE_CONTACT_MODSATTR(self, contact, value): # TODO
contact.modified_service_attributes = long(value)
# CHANGE_CONTACT_MODHATTR;<contact_name>;<value>
def CHANGE_CONTACT_MODHATTR(self, contact, value): # TODO
contact.modified_host_attributes = long(value)
# CHANGE_CONTACT_MODATTR;<contact_name>;<value>
def CHANGE_CONTACT_MODATTR(self, contact, value):
contact.modified_attributes = long(value)
# CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD;<contact_name>;<notification_timeperiod>
def CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD(self, contact, notification_timeperiod):
contact.modified_host_attributes |= MODATTR_NOTIFICATION_TIMEPERIOD
contact.host_notification_period = notification_timeperiod
self.sched.get_and_register_status_brok(contact)
# ADD_SVC_COMMENT;<host_name>;<service_description>;<persistent>;<author>;<comment>
def ADD_SVC_COMMENT(self, service, persistent, author, comment):
c = Comment(service, persistent, author, comment, 2, 1, 1, False, 0)
service.add_comment(c)
self.sched.add(c)
# ADD_HOST_COMMENT;<host_name>;<persistent>;<author>;<comment>
def ADD_HOST_COMMENT(self, host, persistent, author, comment):
c = Comment(host, persistent, author, comment, 1, 1, 1, False, 0)
host.add_comment(c)
self.sched.add(c)
# ACKNOWLEDGE_SVC_PROBLEM;<host_name>;<service_description>;<sticky>;<notify>;<persistent>;<author>;<comment>
def ACKNOWLEDGE_SVC_PROBLEM(self, service, sticky, notify, persistent, author, comment):
service.acknowledge_problem(sticky, notify, persistent, author, comment)
# ACKNOWLEDGE_HOST_PROBLEM;<host_name>;<sticky>;<notify>;<persistent>;<author>;<comment>
# TODO: add a better ACK management
def ACKNOWLEDGE_HOST_PROBLEM(self, host, sticky, notify, persistent, author, comment):
host.acknowledge_problem(sticky, notify, persistent, author, comment)
# ACKNOWLEDGE_SVC_PROBLEM_EXPIRE;<host_name>;<service_description>;<sticky>;<notify>;<persistent>;<end_time>;<author>;<comment>
def ACKNOWLEDGE_SVC_PROBLEM_EXPIRE(self, service, sticky, notify, persistent, end_time, author, comment):
service.acknowledge_problem(sticky, notify, persistent, author, comment, end_time=end_time)
# ACKNOWLEDGE_HOST_PROBLEM_EXPIRE;<host_name>;<sticky>;<notify>;<persistent>;<end_time>;<author>;<comment>
# TODO: add a better ACK management
def ACKNOWLEDGE_HOST_PROBLEM_EXPIRE(self, host, sticky, notify, persistent, end_time, author, comment):
host.acknowledge_problem(sticky, notify, persistent, author, comment, end_time=end_time)
# CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD;<contact_name>;<notification_timeperiod>
def CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD(self, contact, notification_timeperiod):
contact.modified_service_attributes |= MODATTR_NOTIFICATION_TIMEPERIOD
contact.service_notification_period = notification_timeperiod
self.sched.get_and_register_status_brok(contact)
# CHANGE_CUSTOM_CONTACT_VAR;<contact_name>;<varname>;<varvalue>
def CHANGE_CUSTOM_CONTACT_VAR(self, contact, varname, varvalue):
contact.modified_attributes |= MODATTR_CUSTOM_VARIABLE
contact.customs[varname.upper()] = varvalue
# CHANGE_CUSTOM_HOST_VAR;<host_name>;<varname>;<varvalue>
def CHANGE_CUSTOM_HOST_VAR(self, host, varname, varvalue):
host.modified_attributes |= MODATTR_CUSTOM_VARIABLE
host.customs[varname.upper()] = varvalue
# CHANGE_CUSTOM_SVC_VAR;<host_name>;<service_description>;<varname>;<varvalue>
def CHANGE_CUSTOM_SVC_VAR(self, service, varname, varvalue):
service.modified_attributes |= MODATTR_CUSTOM_VARIABLE
service.customs[varname.upper()] = varvalue
# CHANGE_GLOBAL_HOST_EVENT_HANDLER;<event_handler_command>
def CHANGE_GLOBAL_HOST_EVENT_HANDLER(self, event_handler_command):
# TODO: MODATTR_EVENT_HANDLER_COMMAND
pass
# CHANGE_GLOBAL_SVC_EVENT_HANDLER;<event_handler_command> # TODO
def CHANGE_GLOBAL_SVC_EVENT_HANDLER(self, event_handler_command):
# TODO: MODATTR_EVENT_HANDLER_COMMAND
pass
# CHANGE_HOST_CHECK_COMMAND;<host_name>;<check_command>
def CHANGE_HOST_CHECK_COMMAND(self, host, check_command):
host.modified_attributes |= MODATTR_CHECK_COMMAND
host.check_command = CommandCall(self.commands, check_command, poller_tag=host.poller_tag)
self.sched.get_and_register_status_brok(host)
# CHANGE_HOST_CHECK_TIMEPERIOD;<host_name>;<timeperiod>
def CHANGE_HOST_CHECK_TIMEPERIOD(self, host, timeperiod): # TODO is timeperiod a string or a Timeperiod object?
host.modified_attributes |= MODATTR_CHECK_TIMEPERIOD
host.check_period = timeperiod
self.sched.get_and_register_status_brok(host)
# CHANGE_HOST_EVENT_HANDLER;<host_name>;<event_handler_command>
def CHANGE_HOST_EVENT_HANDLER(self, host, event_handler_command):
host.modified_attributes |= MODATTR_EVENT_HANDLER_COMMAND
host.event_handler = CommandCall(self.commands, event_handler_command)
self.sched.get_and_register_status_brok(host)
# CHANGE_HOST_MODATTR;<host_name>;<value>
def CHANGE_HOST_MODATTR(self, host, value):
host.modified_attributes = long(value)
# CHANGE_MAX_HOST_CHECK_ATTEMPTS;<host_name>;<check_attempts>
def CHANGE_MAX_HOST_CHECK_ATTEMPTS(self, host, check_attempts):
host.modified_attributes |= MODATTR_MAX_CHECK_ATTEMPTS
host.max_check_attempts = check_attempts
if host.state_type == 'HARD' and host.state == 'UP' and host.attempt > 1:
host.attempt = host.max_check_attempts
self.sched.get_and_register_status_brok(host)
# CHANGE_MAX_SVC_CHECK_ATTEMPTS;<host_name>;<service_description>;<check_attempts>
def CHANGE_MAX_SVC_CHECK_ATTEMPTS(self, service, check_attempts):
service.modified_attributes |= MODATTR_MAX_CHECK_ATTEMPTS
service.max_check_attempts = check_attempts
if service.state_type == 'HARD' and service.state == 'OK' and service.attempt > 1:
service.attempt = service.max_check_attempts
self.sched.get_and_register_status_brok(service)
# CHANGE_NORMAL_HOST_CHECK_INTERVAL;<host_name>;<check_interval>
def CHANGE_NORMAL_HOST_CHECK_INTERVAL(self, host, check_interval):
host.modified_attributes |= MODATTR_NORMAL_CHECK_INTERVAL
old_interval = host.check_interval
host.check_interval = check_interval
# If there were no regular checks (interval=0), then schedule
# a check immediately.
if old_interval == 0 and host.checks_enabled:
host.schedule(force=False, force_time=int(time.time()))
self.sched.get_and_register_status_brok(host)
# CHANGE_NORMAL_SVC_CHECK_INTERVAL;<host_name>;<service_description>;<check_interval>
def CHANGE_NORMAL_SVC_CHECK_INTERVAL(self, service, check_interval):
service.modified_attributes |= MODATTR_NORMAL_CHECK_INTERVAL
old_interval = service.check_interval
service.check_interval = check_interval
# If there were no regular checks (interval=0), then schedule
# a check immediately.
if old_interval == 0 and service.checks_enabled:
service.schedule(force=False, force_time=int(time.time()))
self.sched.get_and_register_status_brok(service)
# CHANGE_RETRY_HOST_CHECK_INTERVAL;<host_name>;<check_interval>
def CHANGE_RETRY_HOST_CHECK_INTERVAL(self, host, check_interval):
host.modified_attributes |= MODATTR_RETRY_CHECK_INTERVAL
host.retry_interval = check_interval
self.sched.get_and_register_status_brok(host)
# CHANGE_RETRY_SVC_CHECK_INTERVAL;<host_name>;<service_description>;<check_interval>
def CHANGE_RETRY_SVC_CHECK_INTERVAL(self, service, check_interval):
service.modified_attributes |= MODATTR_RETRY_CHECK_INTERVAL
service.retry_interval = check_interval
self.sched.get_and_register_status_brok(service)
# CHANGE_SVC_CHECK_COMMAND;<host_name>;<service_description>;<check_command>
def CHANGE_SVC_CHECK_COMMAND(self, service, check_command):
service.modified_attributes |= MODATTR_CHECK_COMMAND
service.check_command = CommandCall(self.commands, check_command, poller_tag=service.poller_tag)
self.sched.get_and_register_status_brok(service)
# CHANGE_SVC_CHECK_TIMEPERIOD;<host_name>;<service_description>;<check_timeperiod>
def CHANGE_SVC_CHECK_TIMEPERIOD(self, service, check_timeperiod):
service.modified_attributes |= MODATTR_CHECK_TIMEPERIOD
service.check_period = check_timeperiod
self.sched.get_and_register_status_brok(service)
# CHANGE_SVC_EVENT_HANDLER;<host_name>;<service_description>;<event_handler_command>
def CHANGE_SVC_EVENT_HANDLER(self, service, event_handler_command):
service.modified_attributes |= MODATTR_EVENT_HANDLER_COMMAND
service.event_handler = CommandCall(self.commands, event_handler_command)
self.sched.get_and_register_status_brok(service)
# CHANGE_SVC_MODATTR;<host_name>;<service_description>;<value>
def CHANGE_SVC_MODATTR(self, service, value):
service.modified_attributes = long(value)
# CHANGE_SVC_NOTIFICATION_TIMEPERIOD;<host_name>;<service_description>;<notification_timeperiod>
def CHANGE_SVC_NOTIFICATION_TIMEPERIOD(self, service, notification_timeperiod):
service.modified_attributes |= MODATTR_NOTIFICATION_TIMEPERIOD
service.notification_period = notification_timeperiod
self.sched.get_and_register_status_brok(service)
# DELAY_HOST_NOTIFICATION;<host_name>;<notification_time>
def DELAY_HOST_NOTIFICATION(self, host, notification_time):
host.first_notification_delay = notification_time
self.sched.get_and_register_status_brok(host)
# DELAY_SVC_NOTIFICATION;<host_name>;<service_description>;<notification_time>
def DELAY_SVC_NOTIFICATION(self, service, notification_time):
service.first_notification_delay = notification_time
self.sched.get_and_register_status_brok(service)
# DEL_ALL_HOST_COMMENTS;<host_name>
def DEL_ALL_HOST_COMMENTS(self, host):
for c in host.comments:
self.DEL_HOST_COMMENT(c.id)
# DEL_ALL_HOST_COMMENTS;<host_name>
def DEL_ALL_HOST_DOWNTIMES(self, host):
for dt in host.downtimes:
self.DEL_HOST_DOWNTIME(dt.id)
# DEL_ALL_SVC_COMMENTS;<host_name>;<service_description>
def DEL_ALL_SVC_COMMENTS(self, service):
for c in service.comments:
self.DEL_SVC_COMMENT(c.id)
# DEL_ALL_SVC_COMMENTS;<host_name>;<service_description>
def DEL_ALL_SVC_DOWNTIMES(self, service):
for dt in service.downtimes:
self.DEL_SVC_DOWNTIME(dt.id)
# DEL_CONTACT_DOWNTIME;<downtime_id>
def DEL_CONTACT_DOWNTIME(self, downtime_id):
if downtime_id in self.sched.contact_downtimes:
self.sched.contact_downtimes[downtime_id].cancel()
# DEL_HOST_COMMENT;<comment_id>
def DEL_HOST_COMMENT(self, comment_id):
if comment_id in self.sched.comments:
self.sched.comments[comment_id].can_be_deleted = True
# DEL_HOST_DOWNTIME;<downtime_id>
def DEL_HOST_DOWNTIME(self, downtime_id):
if downtime_id in self.sched.downtimes:
self.sched.downtimes[downtime_id].cancel()
# DEL_SVC_COMMENT;<comment_id>
def DEL_SVC_COMMENT(self, comment_id):
if comment_id in self.sched.comments:
self.sched.comments[comment_id].can_be_deleted = True
# DEL_SVC_DOWNTIME;<downtime_id>
def DEL_SVC_DOWNTIME(self, downtime_id):
if downtime_id in self.sched.downtimes:
self.sched.downtimes[downtime_id].cancel()
# DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST;<host_name>
def DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST(self, host):
pass
# DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS;<contactgroup_name>
def DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS(self, contactgroup):
for contact in contactgroup:
self.DISABLE_CONTACT_HOST_NOTIFICATIONS(contact)
# DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS;<contactgroup_name>
def DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS(self, contactgroup):
for contact in contactgroup:
self.DISABLE_CONTACT_SVC_NOTIFICATIONS(contact)
# DISABLE_CONTACT_HOST_NOTIFICATIONS;<contact_name>
def DISABLE_CONTACT_HOST_NOTIFICATIONS(self, contact):
if contact.host_notifications_enabled:
contact.modified_attributes |= MODATTR_NOTIFICATIONS_ENABLED
contact.host_notifications_enabled = False
self.sched.get_and_register_status_brok(contact)
# DISABLE_CONTACT_SVC_NOTIFICATIONS;<contact_name>
def DISABLE_CONTACT_SVC_NOTIFICATIONS(self, contact):
if contact.service_notifications_enabled:
contact.modified_attributes |= MODATTR_NOTIFICATIONS_ENABLED
contact.service_notifications_enabled = False
self.sched.get_and_register_status_brok(contact)
# DISABLE_EVENT_HANDLERS
def DISABLE_EVENT_HANDLERS(self):
if self.conf.enable_event_handlers:
self.conf.modified_attributes |= MODATTR_EVENT_HANDLER_ENABLED
self.conf.enable_event_handlers = False
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# DISABLE_FAILURE_PREDICTION
def DISABLE_FAILURE_PREDICTION(self):
if self.conf.enable_failure_prediction:
self.conf.modified_attributes |= MODATTR_FAILURE_PREDICTION_ENABLED
self.conf.enable_failure_prediction = False
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# DISABLE_FLAP_DETECTION
def DISABLE_FLAP_DETECTION(self):
if self.conf.enable_flap_detection:
self.conf.modified_attributes |= MODATTR_FLAP_DETECTION_ENABLED
self.conf.enable_flap_detection = False
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# Is need, disable flap state for hosts and services
for service in self.conf.services:
if service.is_flapping:
service.is_flapping = False
service.flapping_changes = []
self.sched.get_and_register_status_brok(service)
for host in self.conf.hosts:
if host.is_flapping:
host.is_flapping = False
host.flapping_changes = []
self.sched.get_and_register_status_brok(host)
# DISABLE_HOSTGROUP_HOST_CHECKS;<hostgroup_name>
def DISABLE_HOSTGROUP_HOST_CHECKS(self, hostgroup):
for host in hostgroup:
self.DISABLE_HOST_CHECK(host)
# DISABLE_HOSTGROUP_HOST_NOTIFICATIONS;<hostgroup_name>
def DISABLE_HOSTGROUP_HOST_NOTIFICATIONS(self, hostgroup):
for host in hostgroup:
self.DISABLE_HOST_NOTIFICATIONS(host)
# DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS;<hostgroup_name>
def DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS(self, hostgroup):
for host in hostgroup:
self.DISABLE_PASSIVE_HOST_CHECKS(host)
# DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS;<hostgroup_name>
def DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS(self, hostgroup):
for host in hostgroup:
for service in host.services:
self.DISABLE_PASSIVE_SVC_CHECKS(service)
# DISABLE_HOSTGROUP_SVC_CHECKS;<hostgroup_name>
def DISABLE_HOSTGROUP_SVC_CHECKS(self, hostgroup):
for host in hostgroup:
for service in host.services:
self.DISABLE_SVC_CHECK(service)
# DISABLE_HOSTGROUP_SVC_NOTIFICATIONS;<hostgroup_name>
def DISABLE_HOSTGROUP_SVC_NOTIFICATIONS(self, hostgroup):
for host in hostgroup:
for service in host.services:
self.DISABLE_SVC_NOTIFICATIONS(service)
# DISABLE_HOST_AND_CHILD_NOTIFICATIONS;<host_name>
def DISABLE_HOST_AND_CHILD_NOTIFICATIONS(self, host):
pass
# DISABLE_HOST_CHECK;<host_name>
def DISABLE_HOST_CHECK(self, host):
if host.active_checks_enabled:
host.modified_attributes |= MODATTR_ACTIVE_CHECKS_ENABLED
host.disable_active_checks()
self.sched.get_and_register_status_brok(host)
# DISABLE_HOST_EVENT_HANDLER;<host_name>
def DISABLE_HOST_EVENT_HANDLER(self, host):
if host.event_handler_enabled:
host.modified_attributes |= MODATTR_EVENT_HANDLER_ENABLED
host.event_handler_enabled = False
self.sched.get_and_register_status_brok(host)
# DISABLE_HOST_FLAP_DETECTION;<host_name>
def DISABLE_HOST_FLAP_DETECTION(self, host):
if host.flap_detection_enabled:
host.modified_attributes |= MODATTR_FLAP_DETECTION_ENABLED
host.flap_detection_enabled = False
# Maybe the host was flapping, if so, stop flapping
if host.is_flapping:
host.is_flapping = False
host.flapping_changes = []
self.sched.get_and_register_status_brok(host)
# DISABLE_HOST_FRESHNESS_CHECKS
def DISABLE_HOST_FRESHNESS_CHECKS(self):
if self.conf.check_host_freshness:
self.conf.modified_attributes |= MODATTR_FRESHNESS_CHECKS_ENABLED
self.conf.check_host_freshness = False
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# DISABLE_HOST_NOTIFICATIONS;<host_name>
def DISABLE_HOST_NOTIFICATIONS(self, host):
if host.notifications_enabled:
host.modified_attributes |= MODATTR_NOTIFICATIONS_ENABLED
host.notifications_enabled = False
self.sched.get_and_register_status_brok(host)
# DISABLE_HOST_SVC_CHECKS;<host_name>
def DISABLE_HOST_SVC_CHECKS(self, host):
for s in host.services:
self.DISABLE_SVC_CHECK(s)
# DISABLE_HOST_SVC_NOTIFICATIONS;<host_name>
def DISABLE_HOST_SVC_NOTIFICATIONS(self, host):
for s in host.services:
self.DISABLE_SVC_NOTIFICATIONS(s)
self.sched.get_and_register_status_brok(s)
# DISABLE_NOTIFICATIONS
def DISABLE_NOTIFICATIONS(self):
if self.conf.enable_notifications:
self.conf.modified_attributes |= MODATTR_NOTIFICATIONS_ENABLED
self.conf.enable_notifications = False
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# DISABLE_PASSIVE_HOST_CHECKS;<host_name>
def DISABLE_PASSIVE_HOST_CHECKS(self, host):
if host.passive_checks_enabled:
host.modified_attributes |= MODATTR_PASSIVE_CHECKS_ENABLED
host.passive_checks_enabled = False
self.sched.get_and_register_status_brok(host)
# DISABLE_PASSIVE_SVC_CHECKS;<host_name>;<service_description>
def DISABLE_PASSIVE_SVC_CHECKS(self, service):
if service.passive_checks_enabled:
service.modified_attributes |= MODATTR_PASSIVE_CHECKS_ENABLED
service.passive_checks_enabled = False
self.sched.get_and_register_status_brok(service)
# DISABLE_PERFORMANCE_DATA
def DISABLE_PERFORMANCE_DATA(self):
if self.conf.process_performance_data:
self.conf.modified_attributes |= MODATTR_PERFORMANCE_DATA_ENABLED
self.conf.process_performance_data = False
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# DISABLE_SERVICEGROUP_HOST_CHECKS;<servicegroup_name>
def DISABLE_SERVICEGROUP_HOST_CHECKS(self, servicegroup):
for service in servicegroup:
self.DISABLE_HOST_CHECK(service.host)
# DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS;<servicegroup_name>
def DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS(self, servicegroup):
for service in servicegroup:
self.DISABLE_HOST_NOTIFICATIONS(service.host)
# DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS;<servicegroup_name>
def DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS(self, servicegroup):
for service in servicegroup:
self.DISABLE_PASSIVE_HOST_CHECKS(service.host)
# DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS;<servicegroup_name>
def DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS(self, servicegroup):
for service in servicegroup:
self.DISABLE_PASSIVE_SVC_CHECKS(service)
# DISABLE_SERVICEGROUP_SVC_CHECKS;<servicegroup_name>
def DISABLE_SERVICEGROUP_SVC_CHECKS(self, servicegroup):
for service in servicegroup:
self.DISABLE_SVC_CHECK(service)
# DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS;<servicegroup_name>
def DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS(self, servicegroup):
for service in servicegroup:
self.DISABLE_SVC_NOTIFICATIONS(service)
# DISABLE_SERVICE_FLAP_DETECTION;<host_name>;<service_description>
def DISABLE_SERVICE_FLAP_DETECTION(self, service):
if service.flap_detection_enabled:
service.modified_attributes |= MODATTR_FLAP_DETECTION_ENABLED
service.flap_detection_enabled = False
# Maybe the service was flapping, if so, stop flapping
if service.is_flapping:
service.is_flapping = False
service.flapping_changes = []
self.sched.get_and_register_status_brok(service)
# DISABLE_SERVICE_FRESHNESS_CHECKS
def DISABLE_SERVICE_FRESHNESS_CHECKS(self):
if self.conf.check_service_freshness:
self.conf.modified_attributes |= MODATTR_FRESHNESS_CHECKS_ENABLED
self.conf.check_service_freshness = False
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# DISABLE_SVC_CHECK;<host_name>;<service_description>
def DISABLE_SVC_CHECK(self, service):
if service.active_checks_enabled:
service.disable_active_checks()
service.modified_attributes |= MODATTR_ACTIVE_CHECKS_ENABLED
self.sched.get_and_register_status_brok(service)
# DISABLE_SVC_EVENT_HANDLER;<host_name>;<service_description>
def DISABLE_SVC_EVENT_HANDLER(self, service):
if service.event_handler_enabled:
service.modified_attributes |= MODATTR_EVENT_HANDLER_ENABLED
service.event_handler_enabled = False
self.sched.get_and_register_status_brok(service)
# DISABLE_SVC_FLAP_DETECTION;<host_name>;<service_description>
def DISABLE_SVC_FLAP_DETECTION(self, service):
self.DISABLE_SERVICE_FLAP_DETECTION(service)
# DISABLE_SVC_NOTIFICATIONS;<host_name>;<service_description>
def DISABLE_SVC_NOTIFICATIONS(self, service):
if service.notifications_enabled:
service.modified_attributes |= MODATTR_NOTIFICATIONS_ENABLED
service.notifications_enabled = False
self.sched.get_and_register_status_brok(service)
# ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST;<host_name>
def ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST(self, host):
pass
# ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS;<contactgroup_name>
def ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS(self, contactgroup):
for contact in contactgroup:
self.ENABLE_CONTACT_HOST_NOTIFICATIONS(contact)
# ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS;<contactgroup_name>
def ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS(self, contactgroup):
for contact in contactgroup:
self.ENABLE_CONTACT_SVC_NOTIFICATIONS(contact)
# ENABLE_CONTACT_HOST_NOTIFICATIONS;<contact_name>
def ENABLE_CONTACT_HOST_NOTIFICATIONS(self, contact):
if not contact.host_notifications_enabled:
contact.modified_attributes |= MODATTR_NOTIFICATIONS_ENABLED
contact.host_notifications_enabled = True
self.sched.get_and_register_status_brok(contact)
# ENABLE_CONTACT_SVC_NOTIFICATIONS;<contact_name>
def ENABLE_CONTACT_SVC_NOTIFICATIONS(self, contact):
if not contact.service_notifications_enabled:
contact.modified_attributes |= MODATTR_NOTIFICATIONS_ENABLED
contact.service_notifications_enabled = True
self.sched.get_and_register_status_brok(contact)
# ENABLE_EVENT_HANDLERS
def ENABLE_EVENT_HANDLERS(self):
if not self.conf.enable_event_handlers:
self.conf.modified_attributes |= MODATTR_EVENT_HANDLER_ENABLED
self.conf.enable_event_handlers = True
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# ENABLE_FAILURE_PREDICTION
def ENABLE_FAILURE_PREDICTION(self):
if not self.conf.enable_failure_prediction:
self.conf.modified_attributes |= MODATTR_FAILURE_PREDICTION_ENABLED
self.conf.enable_failure_prediction = True
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# ENABLE_FLAP_DETECTION
def ENABLE_FLAP_DETECTION(self):
if not self.conf.enable_flap_detection:
self.conf.modified_attributes |= MODATTR_FLAP_DETECTION_ENABLED
self.conf.enable_flap_detection = True
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# ENABLE_HOSTGROUP_HOST_CHECKS;<hostgroup_name>
def ENABLE_HOSTGROUP_HOST_CHECKS(self, hostgroup):
for host in hostgroup:
self.ENABLE_HOST_CHECK(host)
# ENABLE_HOSTGROUP_HOST_NOTIFICATIONS;<hostgroup_name>
def ENABLE_HOSTGROUP_HOST_NOTIFICATIONS(self, hostgroup):
for host in hostgroup:
self.ENABLE_HOST_NOTIFICATIONS(host)
# ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS;<hostgroup_name>
def ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS(self, hostgroup):
for host in hostgroup:
self.ENABLE_PASSIVE_HOST_CHECKS(host)
# ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS;<hostgroup_name>
def ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS(self, hostgroup):
for host in hostgroup:
for service in host.services:
self.ENABLE_PASSIVE_SVC_CHECKS(service)
# ENABLE_HOSTGROUP_SVC_CHECKS;<hostgroup_name>
def ENABLE_HOSTGROUP_SVC_CHECKS(self, hostgroup):
for host in hostgroup:
for service in host.services:
self.ENABLE_SVC_CHECK(service)
# ENABLE_HOSTGROUP_SVC_NOTIFICATIONS;<hostgroup_name>
def ENABLE_HOSTGROUP_SVC_NOTIFICATIONS(self, hostgroup):
for host in hostgroup:
for service in host.services:
self.ENABLE_SVC_NOTIFICATIONS(service)
# ENABLE_HOST_AND_CHILD_NOTIFICATIONS;<host_name>
def ENABLE_HOST_AND_CHILD_NOTIFICATIONS(self, host):
pass
# ENABLE_HOST_CHECK;<host_name>
def ENABLE_HOST_CHECK(self, host):
if not host.active_checks_enabled:
host.active_checks_enabled = True
host.modified_attributes |= MODATTR_ACTIVE_CHECKS_ENABLED
self.sched.get_and_register_status_brok(host)
# ENABLE_HOST_EVENT_HANDLER;<host_name>
def ENABLE_HOST_EVENT_HANDLER(self, host):
if not host.event_handler_enabled:
host.modified_attributes |= MODATTR_EVENT_HANDLER_ENABLED
host.event_handler_enabled = True
self.sched.get_and_register_status_brok(host)
# ENABLE_HOST_FLAP_DETECTION;<host_name>
def ENABLE_HOST_FLAP_DETECTION(self, host):
if not host.flap_detection_enabled:
host.modified_attributes |= MODATTR_FLAP_DETECTION_ENABLED
host.flap_detection_enabled = True
self.sched.get_and_register_status_brok(host)
# ENABLE_HOST_FRESHNESS_CHECKS
def ENABLE_HOST_FRESHNESS_CHECKS(self):
if not self.conf.check_host_freshness:
self.conf.modified_attributes |= MODATTR_FRESHNESS_CHECKS_ENABLED
self.conf.check_host_freshness = True
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# ENABLE_HOST_NOTIFICATIONS;<host_name>
def ENABLE_HOST_NOTIFICATIONS(self, host):
if not host.notifications_enabled:
host.modified_attributes |= MODATTR_NOTIFICATIONS_ENABLED
host.notifications_enabled = True
self.sched.get_and_register_status_brok(host)
# ENABLE_HOST_SVC_CHECKS;<host_name>
def ENABLE_HOST_SVC_CHECKS(self, host):
for s in host.services:
self.ENABLE_SVC_CHECK(s)
# ENABLE_HOST_SVC_NOTIFICATIONS;<host_name>
def ENABLE_HOST_SVC_NOTIFICATIONS(self, host):
for s in host.services:
self.ENABLE_SVC_NOTIFICATIONS(s)
self.sched.get_and_register_status_brok(s)
# ENABLE_NOTIFICATIONS
def ENABLE_NOTIFICATIONS(self):
if not self.conf.enable_notifications:
self.conf.modified_attributes |= MODATTR_NOTIFICATIONS_ENABLED
self.conf.enable_notifications = True
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# ENABLE_PASSIVE_HOST_CHECKS;<host_name>
def ENABLE_PASSIVE_HOST_CHECKS(self, host):
if not host.passive_checks_enabled:
host.modified_attributes |= MODATTR_PASSIVE_CHECKS_ENABLED
host.passive_checks_enabled = True
self.sched.get_and_register_status_brok(host)
# ENABLE_PASSIVE_SVC_CHECKS;<host_name>;<service_description>
def ENABLE_PASSIVE_SVC_CHECKS(self, service):
if not service.passive_checks_enabled:
service.modified_attributes |= MODATTR_PASSIVE_CHECKS_ENABLED
service.passive_checks_enabled = True
self.sched.get_and_register_status_brok(service)
# ENABLE_PERFORMANCE_DATA
def ENABLE_PERFORMANCE_DATA(self):
if not self.conf.process_performance_data:
self.conf.modified_attributes |= MODATTR_PERFORMANCE_DATA_ENABLED
self.conf.process_performance_data = True
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# ENABLE_SERVICEGROUP_HOST_CHECKS;<servicegroup_name>
def ENABLE_SERVICEGROUP_HOST_CHECKS(self, servicegroup):
for service in servicegroup:
self.ENABLE_HOST_CHECK(service.host)
# ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS;<servicegroup_name>
def ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS(self, servicegroup):
for service in servicegroup:
self.ENABLE_HOST_NOTIFICATIONS(service.host)
# ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS;<servicegroup_name>
def ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS(self, servicegroup):
for service in servicegroup:
self.ENABLE_PASSIVE_HOST_CHECKS(service.host)
# ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS;<servicegroup_name>
def ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS(self, servicegroup):
for service in servicegroup:
self.ENABLE_PASSIVE_SVC_CHECKS(service)
# ENABLE_SERVICEGROUP_SVC_CHECKS;<servicegroup_name>
def ENABLE_SERVICEGROUP_SVC_CHECKS(self, servicegroup):
for service in servicegroup:
self.ENABLE_SVC_CHECK(service)
# ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS;<servicegroup_name>
def ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS(self, servicegroup):
for service in servicegroup:
self.ENABLE_SVC_NOTIFICATIONS(service)
# ENABLE_SERVICE_FRESHNESS_CHECKS
def ENABLE_SERVICE_FRESHNESS_CHECKS(self):
if not self.conf.check_service_freshness:
self.conf.modified_attributes |= MODATTR_FRESHNESS_CHECKS_ENABLED
self.conf.check_service_freshness = True
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# ENABLE_SVC_CHECK;<host_name>;<service_description>
def ENABLE_SVC_CHECK(self, service):
if not service.active_checks_enabled:
service.modified_attributes |= MODATTR_ACTIVE_CHECKS_ENABLED
service.active_checks_enabled = True
self.sched.get_and_register_status_brok(service)
# ENABLE_SVC_EVENT_HANDLER;<host_name>;<service_description>
def ENABLE_SVC_EVENT_HANDLER(self, service):
if not service.event_handler_enabled:
service.modified_attributes |= MODATTR_EVENT_HANDLER_ENABLED
service.event_handler_enabled = True
self.sched.get_and_register_status_brok(service)
# ENABLE_SVC_FLAP_DETECTION;<host_name>;<service_description>
def ENABLE_SVC_FLAP_DETECTION(self, service):
if not service.flap_detection_enabled:
service.modified_attributes |= MODATTR_FLAP_DETECTION_ENABLED
service.flap_detection_enabled = True
self.sched.get_and_register_status_brok(service)
# ENABLE_SVC_NOTIFICATIONS;<host_name>;<service_description>
def ENABLE_SVC_NOTIFICATIONS(self, service):
if not service.notifications_enabled:
service.modified_attributes |= MODATTR_NOTIFICATIONS_ENABLED
service.notifications_enabled = True
self.sched.get_and_register_status_brok(service)
# PROCESS_FILE;<file_name>;<delete>
def PROCESS_FILE(self, file_name, delete):
pass
# TODO: say that check is PASSIVE
# PROCESS_HOST_CHECK_RESULT;<host_name>;<status_code>;<plugin_output>
def PROCESS_HOST_CHECK_RESULT(self, host, status_code, plugin_output):
#raise a PASSIVE check only if needed
if self.conf.log_passive_checks:
console_logger.info('PASSIVE HOST CHECK: %s;%d;%s'
% (host.get_name().decode('utf8', 'ignore'), status_code, plugin_output.decode('utf8', 'ignore')))
now = time.time()
cls = host.__class__
# If globally disable OR locally, do not launch
if cls.accept_passive_checks and host.passive_checks_enabled:
# Maybe the check is just too old, if so, bail out!
if self.current_timestamp < host.last_chk:
return
i = host.launch_check(now, force=True)
c = None
for chk in host.checks_in_progress:
if chk.id == i:
c = chk
# Should not be possible to not find the check, but if so, don't crash
if not c:
console_logger.error('Passive host check failed. Cannot find the check id %s' % i)
return
# Now we 'transform the check into a result'
# So exit_status, output and status is eaten by the host
c.exit_status = status_code
c.get_outputs(plugin_output, host.max_plugins_output_length)
c.status = 'waitconsume'
c.check_time = self.current_timestamp # we are using the external command timestamps
# Set the corresponding host's check_type to passive=1
c.set_type_passive()
self.sched.nb_check_received += 1
# Ok now this result will be read by scheduler the next loop
# PROCESS_HOST_OUTPUT;<host_name>;<plugin_output>
def PROCESS_HOST_OUTPUT(self, host, plugin_output):
self.PROCESS_HOST_CHECK_RESULT(host, host.state_id, plugin_output)
# PROCESS_SERVICE_CHECK_RESULT;<host_name>;<service_description>;<return_code>;<plugin_output>
def PROCESS_SERVICE_CHECK_RESULT(self, service, return_code, plugin_output):
# raise a PASSIVE check only if needed
if self.conf.log_passive_checks:
console_logger.info('PASSIVE SERVICE CHECK: %s;%s;%d;%s'
% (service.host.get_name().decode('utf8', 'ignore'), service.get_name().decode('utf8', 'ignore'),
return_code, plugin_output.decode('utf8', 'ignore')))
now = time.time()
cls = service.__class__
# If globally disable OR locally, do not launch
if cls.accept_passive_checks and service.passive_checks_enabled:
# Maybe the check is just too old, if so, bail out!
if self.current_timestamp < service.last_chk:
return
c = None
i = service.launch_check(now, force=True)
for chk in service.checks_in_progress:
if chk.id == i:
c = chk
# Should not be possible to not find the check, but if so, don't crash
if not c:
console_logger.error('Passive service check failed. Cannot find the check id %s' % i)
return
# Now we 'transform the check into a result'
# So exit_status, output and status is eaten by the service
c.exit_status = return_code
c.get_outputs(plugin_output, service.max_plugins_output_length)
c.status = 'waitconsume'
c.check_time = self.current_timestamp # we are using the external command timestamps
# Set the corresponding service's check_type to passive=1
c.set_type_passive()
self.sched.nb_check_received += 1
# Ok now this result will be reap by scheduler the next loop
# PROCESS_SERVICE_CHECK_RESULT;<host_name>;<service_description>;<plugin_output>
def PROCESS_SERVICE_OUTPUT(self, service, plugin_output):
self.PROCESS_SERVICE_CHECK_RESULT(service, service.state_id, plugin_output)
# READ_STATE_INFORMATION
def READ_STATE_INFORMATION(self):
pass
# REMOVE_HOST_ACKNOWLEDGEMENT;<host_name>
def REMOVE_HOST_ACKNOWLEDGEMENT(self, host):
host.unacknowledge_problem()
# REMOVE_SVC_ACKNOWLEDGEMENT;<host_name>;<service_description>
def REMOVE_SVC_ACKNOWLEDGEMENT(self, service):
service.unacknowledge_problem()
# RESTART_PROGRAM
def RESTART_PROGRAM(self):
pass
# SAVE_STATE_INFORMATION
def SAVE_STATE_INFORMATION(self):
pass
# SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME;<host_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
def SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME(self, host, start_time, end_time, fixed, trigger_id, duration, author, comment):
pass
# SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME;<host_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
def SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME(self, host, start_time, end_time, fixed, trigger_id, duration, author, comment):
pass
# SCHEDULE_CONTACT_DOWNTIME;<contact_name>;<start_time>;<end_time>;<author>;<comment>
def SCHEDULE_CONTACT_DOWNTIME(self, contact, start_time, end_time, author, comment):
dt = ContactDowntime(contact, start_time, end_time, author, comment)
contact.add_downtime(dt)
self.sched.add(dt)
self.sched.get_and_register_status_brok(contact)
# SCHEDULE_FORCED_HOST_CHECK;<host_name>;<check_time>
def SCHEDULE_FORCED_HOST_CHECK(self, host, check_time):
host.schedule(force=True, force_time=check_time)
self.sched.get_and_register_status_brok(host)
# SCHEDULE_FORCED_HOST_SVC_CHECKS;<host_name>;<check_time>
def SCHEDULE_FORCED_HOST_SVC_CHECKS(self, host, check_time):
for s in host.services:
self.SCHEDULE_FORCED_SVC_CHECK(s, check_time)
self.sched.get_and_register_status_brok(s)
# SCHEDULE_FORCED_SVC_CHECK;<host_name>;<service_description>;<check_time>
def SCHEDULE_FORCED_SVC_CHECK(self, service, check_time):
service.schedule(force=True, force_time=check_time)
self.sched.get_and_register_status_brok(service)
# SCHEDULE_HOSTGROUP_HOST_DOWNTIME;<hostgroup_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
def SCHEDULE_HOSTGROUP_HOST_DOWNTIME(self, hostgroup, start_time, end_time, fixed, trigger_id, duration, author, comment):
pass
# SCHEDULE_HOSTGROUP_SVC_DOWNTIME;<hostgroup_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
def SCHEDULE_HOSTGROUP_SVC_DOWNTIME(self, hostgroup, start_time, end_time, fixed, trigger_id, duration, author, comment):
pass
# SCHEDULE_HOST_CHECK;<host_name>;<check_time>
def SCHEDULE_HOST_CHECK(self, host, check_time):
host.schedule(force=False, force_time=check_time)
self.sched.get_and_register_status_brok(host)
# SCHEDULE_HOST_DOWNTIME;<host_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
def SCHEDULE_HOST_DOWNTIME(self, host, start_time, end_time, fixed, trigger_id, duration, author, comment):
dt = Downtime(host, start_time, end_time, fixed, trigger_id, duration, author, comment)
host.add_downtime(dt)
self.sched.add(dt)
self.sched.get_and_register_status_brok(host)
if trigger_id != 0 and trigger_id in self.sched.downtimes:
self.sched.downtimes[trigger_id].trigger_me(dt)
# SCHEDULE_HOST_SVC_CHECKS;<host_name>;<check_time>
def SCHEDULE_HOST_SVC_CHECKS(self, host, check_time):
for s in host.services:
self.SCHEDULE_SVC_CHECK(s, check_time)
self.sched.get_and_register_status_brok(s)
# SCHEDULE_HOST_SVC_DOWNTIME;<host_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
def SCHEDULE_HOST_SVC_DOWNTIME(self, host, start_time, end_time, fixed, trigger_id, duration, author, comment):
for s in host.services:
self.SCHEDULE_SVC_DOWNTIME(s, start_time, end_time, fixed, trigger_id, duration, author, comment)
# SCHEDULE_SERVICEGROUP_HOST_DOWNTIME;<servicegroup_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
def SCHEDULE_SERVICEGROUP_HOST_DOWNTIME(self, servicegroup, start_time, end_time, fixed, trigger_id, duration, author, comment):
for h in [s.host for s in servicegroup.get_services()]:
self.SCHEDULE_HOST_DOWNTIME(h, start_time, end_time, fixed, trigger_id, duration, author, comment)
# SCHEDULE_SERVICEGROUP_SVC_DOWNTIME;<servicegroup_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
def SCHEDULE_SERVICEGROUP_SVC_DOWNTIME(self, servicegroup, start_time, end_time, fixed, trigger_id, duration, author, comment):
for s in servicegroup.get_services():
self.SCHEDULE_SVC_DOWNTIME(s, start_time, end_time, fixed, trigger_id, duration, author, comment)
# SCHEDULE_SVC_CHECK;<host_name>;<service_description>;<check_time>
def SCHEDULE_SVC_CHECK(self, service, check_time):
service.schedule(force=False, force_time=check_time)
self.sched.get_and_register_status_brok(service)
# SCHEDULE_SVC_DOWNTIME;<host_name>;<service_description><start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
def SCHEDULE_SVC_DOWNTIME(self, service, start_time, end_time, fixed, trigger_id, duration, author, comment):
dt = Downtime(service, start_time, end_time, fixed, trigger_id, duration, author, comment)
service.add_downtime(dt)
self.sched.add(dt)
self.sched.get_and_register_status_brok(service)
if trigger_id != 0 and trigger_id in self.sched.downtimes:
self.sched.downtimes[trigger_id].trigger_me(dt)
# SEND_CUSTOM_HOST_NOTIFICATION;<host_name>;<options>;<author>;<comment>
def SEND_CUSTOM_HOST_NOTIFICATION(self, host, options, author, comment):
pass
# SEND_CUSTOM_SVC_NOTIFICATION;<host_name>;<service_description>;<options>;<author>;<comment>
def SEND_CUSTOM_SVC_NOTIFICATION(self, service, options, author, comment):
pass
# SET_HOST_NOTIFICATION_NUMBER;<host_name>;<notification_number>
def SET_HOST_NOTIFICATION_NUMBER(self, host, notification_number):
pass
# SET_SVC_NOTIFICATION_NUMBER;<host_name>;<service_description>;<notification_number>
def SET_SVC_NOTIFICATION_NUMBER(self, service, notification_number):
pass
# SHUTDOWN_PROGRAM
def SHUTDOWN_PROGRAM(self):
pass
# START_ACCEPTING_PASSIVE_HOST_CHECKS
def START_ACCEPTING_PASSIVE_HOST_CHECKS(self):
if not self.conf.accept_passive_host_checks:
self.conf.modified_attributes |= MODATTR_PASSIVE_CHECKS_ENABLED
self.conf.accept_passive_host_checks = True
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# START_ACCEPTING_PASSIVE_SVC_CHECKS
def START_ACCEPTING_PASSIVE_SVC_CHECKS(self):
if not self.conf.accept_passive_service_checks:
self.conf.modified_attributes |= MODATTR_PASSIVE_CHECKS_ENABLED
self.conf.accept_passive_service_checks = True
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# START_EXECUTING_HOST_CHECKS
def START_EXECUTING_HOST_CHECKS(self):
if not self.conf.execute_host_checks:
self.conf.modified_attributes |= MODATTR_ACTIVE_CHECKS_ENABLED
self.conf.execute_host_checks = True
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# START_EXECUTING_SVC_CHECKS
def START_EXECUTING_SVC_CHECKS(self):
if not self.conf.execute_service_checks:
self.conf.modified_attributes |= MODATTR_ACTIVE_CHECKS_ENABLED
self.conf.execute_service_checks = True
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# START_OBSESSING_OVER_HOST;<host_name>
def START_OBSESSING_OVER_HOST(self, host):
if not host.obsess_over_host:
host.modified_attributes |= MODATTR_OBSESSIVE_HANDLER_ENABLED
host.obsess_over_host = True
self.sched.get_and_register_status_brok(host)
# START_OBSESSING_OVER_HOST_CHECKS
def START_OBSESSING_OVER_HOST_CHECKS(self):
if not self.conf.obsess_over_hosts:
self.conf.modified_attributes |= MODATTR_OBSESSIVE_HANDLER_ENABLED
self.conf.obsess_over_hosts = True
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# START_OBSESSING_OVER_SVC;<host_name>;<service_description>
def START_OBSESSING_OVER_SVC(self, service):
if not service.obsess_over_service:
service.modified_attributes |= MODATTR_OBSESSIVE_HANDLER_ENABLED
service.obsess_over_service = True
self.sched.get_and_register_status_brok(service)
# START_OBSESSING_OVER_SVC_CHECKS
def START_OBSESSING_OVER_SVC_CHECKS(self):
if not self.conf.obsess_over_services:
self.conf.modified_attributes |= MODATTR_OBSESSIVE_HANDLER_ENABLED
self.conf.obsess_over_services = True
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# STOP_ACCEPTING_PASSIVE_HOST_CHECKS
def STOP_ACCEPTING_PASSIVE_HOST_CHECKS(self):
if self.conf.accept_passive_host_checks:
self.conf.modified_attributes |= MODATTR_PASSIVE_CHECKS_ENABLED
self.conf.accept_passive_host_checks = False
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# STOP_ACCEPTING_PASSIVE_SVC_CHECKS
def STOP_ACCEPTING_PASSIVE_SVC_CHECKS(self):
if self.conf.accept_passive_service_checks:
self.conf.modified_attributes |= MODATTR_PASSIVE_CHECKS_ENABLED
self.conf.accept_passive_service_checks = False
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# STOP_EXECUTING_HOST_CHECKS
def STOP_EXECUTING_HOST_CHECKS(self):
if self.conf.execute_host_checks:
self.conf.modified_attributes |= MODATTR_ACTIVE_CHECKS_ENABLED
self.conf.execute_host_checks = False
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# STOP_EXECUTING_SVC_CHECKS
def STOP_EXECUTING_SVC_CHECKS(self):
if self.conf.execute_service_checks:
self.conf.modified_attributes |= MODATTR_ACTIVE_CHECKS_ENABLED
self.conf.execute_service_checks = False
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# STOP_OBSESSING_OVER_HOST;<host_name>
def STOP_OBSESSING_OVER_HOST(self, host):
if host.obsess_over_host:
host.modified_attributes |= MODATTR_OBSESSIVE_HANDLER_ENABLED
host.obsess_over_host = False
self.sched.get_and_register_status_brok(host)
# STOP_OBSESSING_OVER_HOST_CHECKS
def STOP_OBSESSING_OVER_HOST_CHECKS(self):
if self.conf.obsess_over_hosts:
self.conf.modified_attributes |= MODATTR_OBSESSIVE_HANDLER_ENABLED
self.conf.obsess_over_hosts = False
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
# STOP_OBSESSING_OVER_SVC;<host_name>;<service_description>
def STOP_OBSESSING_OVER_SVC(self, service):
if service.obsess_over_service:
service.modified_attributes |= MODATTR_OBSESSIVE_HANDLER_ENABLED
service.obsess_over_service = False
self.sched.get_and_register_status_brok(service)
# STOP_OBSESSING_OVER_SVC_CHECKS
def STOP_OBSESSING_OVER_SVC_CHECKS(self):
if self.conf.obsess_over_services:
self.conf.modified_attributes |= MODATTR_OBSESSIVE_HANDLER_ENABLED
self.conf.obsess_over_services = False
self.conf.explode_global_conf()
self.sched.get_and_register_update_program_status_brok()
### Now the shinken specific ones
# LAUNCH_SVC_EVENT_HANDLER;<host_name>;<service_description>
def LAUNCH_SVC_EVENT_HANDLER(self, service):
service.get_event_handlers(externalcmd=True)
# LAUNCH_SVC_EVENT_HANDLER;<host_name>;<service_description>
def LAUNCH_HOST_EVENT_HANDLER(self, host):
host.get_event_handlers(externalcmd=True)
# ADD_SIMPLE_HOST_DEPENDENCY;<host_name>;<host_name>
def ADD_SIMPLE_HOST_DEPENDENCY(self, son, father):
if not son.is_linked_with_host(father):
logger.debug("Doing simple link between %s and %s" % (son.get_name(), father.get_name()))
# Flag them so the modules will know that a topology change
# happened
son.topology_change = True
father.topology_change = True
# Now do the work
# Add a dep link between the son and the father
son.add_host_act_dependency(father, ['w', 'u', 'd'], None, True)
self.sched.get_and_register_status_brok(son)
self.sched.get_and_register_status_brok(father)
# ADD_SIMPLE_HOST_DEPENDENCY;<host_name>;<host_name>
def DEL_HOST_DEPENDENCY(self, son, father):
if son.is_linked_with_host(father):
logger.debug("Removing simple link between %s and %s" % (son.get_name(), father.get_name()))
# Flag them so the modules will know that a topology change
# happened
son.topology_change = True
father.topology_change = True
# Now do the work
son.del_host_act_dependency(father)
self.sched.get_and_register_status_brok(son)
self.sched.get_and_register_status_brok(father)
# ADD_SIMPLE_POLLER;realm_name;poller_name;address;port
def ADD_SIMPLE_POLLER(self, realm_name, poller_name, address, port):
logger.debug("I need to add the poller (%s, %s, %s, %s)" % (realm_name, poller_name, address, port))
# First we look for the realm
r = self.conf.realms.find_by_name(realm_name)
if r is None:
logger.debug("Sorry, the realm %s is unknown" % realm_name)
return
logger.debug("We found the realm: %s" % str(r))
# TODO: backport this in the config class?
# We create the PollerLink object
t = {'poller_name': poller_name, 'address': address, 'port': port}
p = PollerLink(t)
p.fill_default()
p.pythonize()
p.prepare_for_conf()
parameters = {'max_plugins_output_length': self.conf.max_plugins_output_length}
p.add_global_conf_parameters(parameters)
self.arbiter.conf.pollers[p.id] = p
self.arbiter.dispatcher.elements.append(p)
self.arbiter.dispatcher.satellites.append(p)
r.pollers.append(p)
r.count_pollers()
r.fill_potential_pollers()
logger.debug("Poller %s added" % poller_name)
logger.debug("Potential %s" % str(r.get_potential_satellites_by_type('poller')))
if __name__ == '__main__':
FIFO_PATH = '/tmp/my_fifo'
if os.path.exists(FIFO_PATH):
os.unlink(FIFO_PATH)
if not os.path.exists(FIFO_PATH):
os.umask(0)
os.mkfifo(FIFO_PATH, 0660)
my_fifo = open(FIFO_PATH, 'w+')
logger.debug("my_fifo: %s" % (my_fifo))
logger.debug(open(FIFO_PATH, 'r').readline())
|