This file is indexed.

/usr/share/check_mk/web/plugins/wato/active_checks.py is in check-mk-multisite 1.2.8p16-1ubuntu0.1.

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
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
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software;  you can redistribute it and/or modify it
# under the  terms of the  GNU General Public License  as published by
# the Free Software Foundation in version 2.  check_mk is  distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
# tails. You should have  received  a copy of the  GNU  General Public
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.

register_rulegroup("activechecks",
    _("Active checks (HTTP, TCP, etc.)"),
    _("Configure active networking checks like HTTP and TCP"))
group = "activechecks"

# These elements are also used in check_parameters.py
check_icmp_params = [
   ( "rta",
     Tuple(
         title = _("Round trip average"),
         elements = [
             Float(title = _("Warning if above"), unit = "ms", default_value = 200.0),
             Float(title = _("Critical if above"), unit = "ms", default_value = 500.0),
         ])),
   ( "loss",
     Tuple(
         title = _("Packet loss"),
         help = _("When the percentage of lost packets is equal or greater then "
                  "this level, then the according state is triggered. The default for critical "
                  "is 100%. That means that the check is only critical if <b>all</b> packets "
                  "are lost."),
         elements = [
             Percentage(title = _("Warning at"), default_value = 80.0),
             Percentage(title = _("Critical at"), default_value = 100.0),
         ])),

    ( "packets",
      Integer(
          title = _("Number of packets"),
          help = _("Number ICMP echo request packets to send to the target host on each "
                   "check execution. All packets are sent directly on check execution. Afterwards "
                   "the check waits for the incoming packets."),
          minvalue = 1,
          maxvalue = 20,
          default_value = 5,
       )),

     ( "timeout",
       Integer(
           title = _("Total timeout of check"),
           help = _("After this time (in seconds) the check is aborted, regardless "
                    "of how many packets have been received yet."),
           minvalue = 1,
       )),
]

imap_parameters = Dictionary(
    title = "IMAP",
    optional_keys = [],
    elements = [
        ('server', TextAscii(
            title = _('IMAP Server'),
            allow_empty = False,
            help = _('You can specify a hostname or IP address different from the IP address '
                     'of the host this check will be assigned to.')
        )),
        ('ssl', CascadingDropdown(
            title = _('SSL Encryption'),
            default_value = (False, 143),
            choices = [
                (False, _('Use no encryption'),
                 Optional(Integer(
                     allow_empty = False,
                     default_value = 143,
                 ),
                     title = _('TCP Port'),
                     help = _('By default the standard IMAP Port 143 is used.'),
                 )),
                (True, _('Encrypt IMAP communication using SSL'),
                 Optional(Integer(
                     allow_empty = False,
                     default_value = 993,
                 ),
                     title = _('TCP Port'),
                     help = _('By default the standard IMAP/SSL Port 993 is used.'),
                 )),
            ],
        )),
        ('auth', Tuple(
            title = _('Authentication'),
            elements = [
                TextAscii(
                    title = _('Username'),
                    allow_empty = False,
                    size = 24
                ),
                Password(
                    title = _('Password'),
                    allow_empty = False,
                    size = 12
                ),
            ],
        )),
    ],
)

pop3_parameters = Dictionary(
    optional_keys = ['server'],
    elements = [
        ('server', TextAscii(
            title = _('POP3 Server'),
            allow_empty = False,
            help = _('You can specify a hostname or IP address different from the IP address '
                     'of the host this check will be assigned to.')
        )),
        ('ssl', CascadingDropdown(
            title = _('SSL Encryption'),
            default_value = (False, 110),
            choices = [
                (False, _('Use no encryption'),
                 Optional(Integer(
                     allow_empty = False,
                     default_value = 110,
                 ),
                     title = _('TCP Port'),
                     help = _('By default the standard POP3 Port 110 is used.'),
                 )),
                (True, _('Encrypt POP3 communication using SSL'),
                 Optional(Integer(
                     allow_empty = False,
                     default_value = 995,
                 ),
                     title = _('TCP Port'),
                     help = _('By default the standard POP3/SSL Port 995 is used.'),
                 )),
            ],
        )),
        ('auth', Tuple(
            title = _('Authentication'),
            elements = [
                TextAscii(
                    title = _('Username'),
                    allow_empty = False,
                    size = 24
                ),
                Password(
                    title = _('Password'),
                    allow_empty = False,
                    size = 12
                ),
            ],
        )),
    ],
)

mail_receiving_params = [
    ('fetch', CascadingDropdown(
        title = _('Mail Receiving'),
        choices = [
            ('IMAP', _('IMAP'), imap_parameters),
            ('POP3', _('POP3'), pop3_parameters),
        ]
    ))
]


register_rule(group,
    "active_checks:ssh",
    Dictionary(
        title = _("Check SSH service"),
        help = _("This rulset allow you to configure a SSH check for a host"),
        elements = [
            ("port",
               Integer(
                    title = _("TCP port number"),
                    default_value = 22),
            ),
            ("timeout",
                Integer(
                    title = _("Connect Timeout"),
                    help = _("Seconds before connection times out"),
                    default_value = 10),
            ),
            ("remote_version",
               TextAscii(
                    title = _("Version of Server"),
                    help = _("Warn if string doesn't match expected server version (ex: OpenSSH_3.9p1)"),
               )),
            ("remote_protocol",
                TextAscii(
                    title = _("Protocol of Server"),
                    help = _("Warn if protocol doesn't match expected protocol version (ex: 2.0)"),
                )),
        ]
    ),
    match="all")

register_rule(group,
    "active_checks:icmp",
    Dictionary(
        title = _("Check hosts with PING (ICMP Echo Request)"),
        help = _("This ruleset allows you to configure explicit PING monitoring of hosts. "
                 "Usually a PING is being used as a host check, so this is not neccessary. "
                 "There are some situations, however, where this can be useful. One of them "
                 "is when using the Check_MK Micro Core with SMART Ping and you want to "
                 "track performance data of the PING to some hosts, nevertheless."),
        elements = [
           ( "description",
             TextUnicode(
                 title = _("Service Description"),
                 allow_empty = False,
                 default_value = "PING",
           )),
           ( "address",
             CascadingDropdown(
                 title = _("Alternative address to ping"),
                 help = _("If you omit this setting then the configured IP address of that host "
                          "will be pinged. You can set an alternative address here (e.g. when "
                          "you want to check a secondary IP address of the host in question)."),
                 orientation = "horizontal",
                 choices = [
                     ( "address", _("Ping the normal IP address")),
                     ( "alias",   _("Use the alias as DNS name / IP address")),
                     ( "explicit", _("Ping the following explicity address / DNS name"),
                       Hostname()),
                 ]
           )),
        ] + check_icmp_params,
    ),
    match = "all",
)

# Several active checks just had crit levels as one integer
def transform_cert_days(cert_days):
    if type(cert_days) != tuple:
        return (cert_days, 0)
    else:
        return cert_days


register_rule(group,
    "active_checks:ftp",
    Transform(
        Dictionary(
            elements = [
                ("port",
                    Integer(
                        title = _("Portnumber"),
                        default_value = 21,
                        )
                ),
                ( "response_time",
                  Tuple(
                      title = _("Expected response time"),
                      elements = [
                          Float(
                              title = _("Warning if above"),
                              unit = "ms",
                              default_value = 100.0),
                          Float(
                              title = _("Critical if above"),
                              unit = "ms",
                              default_value = 200.0),
                      ])
                 ),
                 ( "timeout",
                   Integer(
                       title = _("Seconds before connection times out"),
                       unit = _("sec"),
                       default_value = 10,
                   )
                 ),
                 ( "refuse_state",
                   DropdownChoice(
                       title = _("State for connection refusal"),
                       choices = [ ('crit', _("CRITICAL")),
                                   ('warn', _("WARNING")),
                                   ('ok',   _("OK")),
                                 ])
                 ),

                 ( "send_string",
                   TextAscii(
                       title = _("String to send"),
                       size = 30)
                 ),
                 ( "expect",
                   ListOfStrings(
                       title = _("Strings to expect in response"),
                       orientation = "horizontal",
                       valuespec = TextAscii(size = 30),
                   )
                 ),

                 ( "ssl",
                   FixedValue(
                       value = True,
                       totext = _("use SSL"),
                       title = _("Use SSL for the connection."))

                 ),
                 ( "cert_days",
                   Transform(
                       Tuple(
                           title = _("SSL certificate validation"),
                           help = _("Minimum number of days a certificate has to be valid"),
                           elements = [
                               Integer(title = _("Warning at or below"), minvalue = 0, unit = _("days")),
                               Integer(title = _("Critical at or below"), minvalue = 0, unit = _("days")),
                           ],
                       ),
                       forth = transform_cert_days,
                   ),
                 ),
            ]),
            forth = lambda x: type(x) == tuple and x[1] or x,
            title = _("Check FTP Service"),
    ),
    match = "all",
)


register_rule(group,
    "active_checks:dns",
    Tuple(
        title = _("Check DNS service"),
        help = _("Check the resolution of a hostname into an IP address by a DNS server. "
                 "This check uses <tt>check_dns</tt> from the standard Nagios plugins."),
        elements = [
           TextAscii(
               title = _("Queried Hostname or IP address"),
               allow_empty = False,
               help = _('The name or IPv4 address you want to query')),
           Dictionary(
               title = _("Optional parameters"),
               elements = [
                   ("name",
                        TextUnicode(
                            title = _("Alternative Service description"),
                            help = _("The service description will be this name instead <i>DNS Servername</i>"),
                        )
                   ),
                   ( "server",
                        Alternative(
                            title = _("DNS Server"),
                            elements = [
                                FixedValue( value=None, totext=_("use local configuration"),
                                            title = _("Use local DNS configuration of monitoring site")),
                                TextAscii(
                                    title = _("Specify DNS Server"),
                                    allow_empty = False,
                                    help = _("Optional DNS server you want to use for the lookup")),
                             ])
                   ),
                   ( "expected_address",
                     Transform(
                         ListOfStrings(
                             title = _("Expected answer (IP address or hostname)"),
                             help = _("List all allowed expected answers here. If query for an "
                                      "IP address then the answer will be host names, that end "
                                      "with a dot."),
                         ),
                         forth = lambda old: type(old) in (str, unicode) and [old] or old,
                     ),
                   ),
                   ( "expected_authority",
                     FixedValue(
                         value  = True,
                         title  = _("Expect Authoritative DNS Server"),
                         totext = _("Expect Authoritative"),
                     )
                   ),
                   ( "response_time",
                     Tuple(
                         title = _("Expected response time"),
                         elements = [
                             Float(
                                 title = _("Warning if above"),
                                 unit = _("sec"),
                                 default_value = 1),
                             Float(
                                 title = _("Critical if above"),
                                 unit = _("sec"),
                                 default_value = 2),
                         ])
                    ),
                   ( "timeout",
                      Integer(
                          title = _("Seconds before connection times out"),
                          unit = _("sec"),
                          default_value = 10,
                      )
                    ),
                ]),
        ]
    ),
    match = 'all'
)

register_rule(group,
    "active_checks:sql",
    Dictionary(
        title = _("Check SQL Database"),
        help = _("This check connects to the specified database, sends a custom SQL-statement "
                 "or starts a procedure, and checks that the result has a defined format "
                 "containing three columns, a number, a text, and performance data. Upper or "
                 "lower levels may be defined here.  If they are not defined the number is taken "
                 "as the state of the check.  If a procedure is used, input parameters of the "
                 "procedures may by given as comma separated list. "
                 "This check uses the active check <tt>check_sql</tt>."),
        optional_keys = [ "levels", "levels_low", "perfdata", "port", "procedure" ],
        elements = [
            ( "description",
              TextUnicode(title = _("Service Description"),
                 help = _("The name of this active service to be displayed."),
                 allow_empty = False,
            )),
            ( "dbms",
               DropdownChoice(
                   title = _("Type of Database"),
                   choices = [
                      ("mysql",    _("MySQL")),
                      ("postgres", _("PostgreSQL")),
                      ("mssql",    _("MSSQL")),
                      ("oracle",   _("Oracle")),
                      ("db2",      _("DB2")),
                   ],
                   default_value = "postgres",
               ),
            ),
            ( "port",
               Integer(title = _("Database Port"), allow_empty = True,
                      help = _('The port the DBMS listens to'))
            ),
            ( "name",
               TextAscii(title = _("Database Name"), allow_empty = False,
                      help = _('The name of the database on the DBMS'))
            ),
            ( "user",
               TextAscii(title = _("Database User"), allow_empty = False,
                      help = _('The username used to connect to the database'))
            ),
            ( "password",
               Password(title = _("Database Password"), allow_empty = False,
                      help = _('The password used to connect to the database'))
            ),
            ( "sql",
              TextAscii(title = _("SQL-statement or procedure name"), allow_empty = False,
                      help = _('The SQL-statement or procedure name which is executed on the DBMS. It must return '
                               'a result table with one row and at least two columns. The first column must be '
                               'an integer and is interpreted as the state (0 is OK, 1 is WARN, 2 is CRIT). '
                               'Alternatively the first column can be interpreted as number value and you can '
                               'define levels for this number. The '
                               'second column is used as check output. The third column is optional and can '
                               'contain performance data.'))
            ),
            ( "procedure",
            Dictionary(
                optional_keys = [ "input" ],
                title = _("Use procedure call instead of SQL statement"),
                help = _("If you activate this option, a name of a stored "
                    "procedure is used instead of an SQL statement. "
                    "The procedure should return one output variable, "
                    "which is evaluated in the check. If input parameters "
                    "are required, they may be specified below."),
                elements = [
                        ("useprocs",
                        FixedValue(
                            value = True,
                            totext = _("procedure call is used"),
                        )),
                        ("input",
                        TextAscii(
                            title = _("Input Parameters"),
                            allow_empty = True,
                            help = _("Input parameters, if required by the database procedure. "
                                     "If several parameters are required, use commas to separate them."),
                        )),
                    ]
                ),
            ),
            ( "levels",
            Tuple(
                title = _("Upper levels for first output item"),
                elements = [
                    Float( title = _("Warning if above")),
                    Float( title = _("Critical if above"))
                ])
            ),
            ( "levels_low",
            Tuple(
                title = _("Lower levels for first output item"),
                elements = [
                    Float( title = _("Warning if below")),
                    Float( title = _("Critical if below"))
                ])
            ),
            ( "perfdata",
              FixedValue(True, totext=_("Store output value into RRD database"), title = _("Performance Data"), ),
            )
        ]
    ),
    match = 'all'
)

register_rule(group,
    "active_checks:tcp",
    Tuple(
        title = _("Check connecting to a TCP port"),
        help = _("This check tests the connection to a TCP port. It uses "
                 "<tt>check_tcp</tt> from the standard Nagios plugins."),
        elements = [
           Integer(title = _("TCP Port"), minvalue=1, maxvalue=65535),
           Dictionary(
               title = _("Optional parameters"),
               elements = [
                   ( "svc_description",
                     TextUnicode(
                         title = _("Service description"),
                         allow_empty = False,
                         help = _("Here you can specify a service description. "
                                  "If this parameter is not set, the service is named <tt>TCP Port {Portnumber}</tt>"))),
                   ( "hostname",
                     TextAscii(
                         title = _("DNS Hostname"),
                         allow_empty = False,
                         help = _("If you specify a hostname here, then a dynamic DNS lookup "
                                  "will be done instead of using the IP address of the host "
                                  "as configured in your host properties."))),
                   ( "response_time",
                     Tuple(
                         title = _("Expected response time"),
                         elements = [
                             Float(
                                 title = _("Warning if above"),
                                 unit = "ms",
                                 default_value = 100.0),
                             Float(
                                 title = _("Critical if above"),
                                 unit = "ms",
                                 default_value = 200.0),
                         ])
                    ),
                    ( "timeout",
                      Integer(
                          title = _("Seconds before connection times out"),
                          unit = _("sec"),
                          default_value = 10,
                      )
                    ),
                    ( "refuse_state",
                      DropdownChoice(
                          title = _("State for connection refusal"),
                          choices = [ ('crit', _("CRITICAL")),
                                      ('warn', _("WARNING")),
                                      ('ok',   _("OK")),
                                    ])
                    ),

                    ( "send_string",
                      TextAscii(
                          title = _("String to send"),
                          size = 30)
                    ),
                    ( "escape_send_string",
                      FixedValue(
                          value = True,
                          title = _("Expand <tt>\\n</tt>, <tt>\\r</tt> and <tt>\\t</tt> in the sent string"),
                          totext = _("expand escapes"))
                    ),
                    ( "expect",
                      ListOfStrings(
                          title = _("Strings to expect in response"),
                          orientation = "horizontal",
                          valuespec = TextAscii(size = 30),
                      )
                    ),
                    ( "expect_all",
                      FixedValue(
                          value = True,
                          totext = _("expect all"),
                          title = _("Expect <b>all</b> of those strings in the response"))
                    ),
                    ( "jail",
                      FixedValue(
                          value = True,
                          title = _("Hide response from socket"),
                          help = _("As soon as you configure expected strings in "
                                   "the response the check will output the response - "
                                   "as long as you do not hide it with this option"),
                          totext = _("hide response"))
                    ),
                    ( "mismatch_state",
                      DropdownChoice(
                          title = _("State for expected string mismatch"),
                          choices = [ ('crit', _("CRITICAL")),
                                      ('warn', _("WARNING")),
                                      ('ok',   _("OK")),
                                    ])
                    ),
                    ( "delay",
                      Integer(
                          title = _("Seconds to wait before polling"),
                          help = _("Seconds to wait between sending string and polling for response"),
                          unit = _("sec"),
                          default_value = 0,
                      )
                    ),
                    ( "maxbytes",
                      Integer(
                          title = _("Maximum number of bytes to receive"),
                          help = _("Close connection once more than this number of "
                                   "bytes are received. Per default the number of "
                                   "read bytes is not limited. This setting is only "
                                   "used if you expect strings in the response."),
                          default_value = 1024,
                      ),
                    ),

                    ( "ssl",
                      FixedValue(
                          value = True,
                          totext = _("use SSL"),
                          title = _("Use SSL for the connection."))

                    ),
                    ( "cert_days",
                      Transform(
                          Tuple(
                              title = _("SSL certificate validation"),
                              help = _("Minimum number of days a certificate has to be valid"),
                              elements = [
                                  Integer(title = _("Warning at or below"), minvalue = 0, unit = _("days")),
                                  Integer(title = _("Critical at or below"), minvalue = 0, unit = _("days")),
                              ],
                          ),
                          forth = transform_cert_days,
                      ),
                    ),

                    ( "quit_string",
                      TextAscii(
                          title = _("Final string to send"),
                          help = _("String to send server to initiate a clean close of "
                                   "the connection"),
                          size = 30)
                    ),
                ]),
        ]
    ),
    match = 'all'
)

register_rule(group,
    "active_checks:uniserv", Dictionary(
        title = _("Check uniserv service"), optional_keys = False, elements = [
            ("port",
                Integer(title = _("Port") )),
            ("service",
              TextAscii(
                  title = _("Service Name"),
                  help = _("Enter the uniserve service name here (has nothing to do with service description).")
            )),
            ("job",
                CascadingDropdown(
                    title = _("Mode of the Check"),
                    help = _("Choose, whether you just want to query the version number,"
                             " or if you want to check the response to an address query."),
                    choices = [
                        ("version", _("Check for Version")),
                        ("address", _("Check for an Address"),
                            Dictionary(
                                title = _("Address Check mode"),
                                optional_keys = False,
                                elements = [
                                    ( "street",
                                        TextAscii( title = _("Street name"))),
                                    ( "street_no",
                                        Integer( title = _("Street number"))),
                                    ( "city",
                                        TextAscii( title = _("City name"))),
                                    ( "search_regex",
                                        TextAscii( title = _("Check City against Regex"),
                                        help = _( "The city name from the response will be checked against "
                                                  "the regular expression specified here"),
                                        )),
                                ]
                        )),
                    ]
                )),

        ]))

ip_address_family_element = ("address_family",
        DropdownChoice(
            title = _("IP Address Family"),
            choices = [
                (None,   _("Primary Address Family") ),
                ('ipv4', _("Enforce IPv4") ),
                ('ipv6', _("Enforce IPv6") ),
            ],
            default_value = None
        ),
    )

register_rule(group,
    "active_checks:http",
    Tuple(
        title = _("Check HTTP service"),
        help = _("Check HTTP/HTTPS service using the plugin <tt>check_http</tt> "
                 "from the standard Monitoring Plugins. "
                 "This plugin tests the HTTP service on the specified host. "
                 "It can test normal (HTTP) and secure (HTTPS) servers, follow "
                 "redirects, search for strings and regular expressions, check "
                 "connection times, and report on certificate expiration times."),
        elements = [
            TextUnicode(
                title = _("Name"),
                help = _("Will be used in the service description. If the name starts with "
                         "a caret (<tt>^</tt>), the service description will not be prefixed with <tt>HTTP</tt>." ),
                allow_empty = False),
            Alternative(
                title = _("Mode of the Check"),
                help = _("Perform a check of the URL or the certificate expiration."),
                elements = [
                    Dictionary(
                        title = _("Check the URL"),
                        elements = [
                            ( "virthost",
                                Tuple(
                                    title = _("Virtual host"),
                                    elements = [
                                        TextAscii(
                                            title = _("Name of the virtual host"),
                                            help = _("Set this in order to specify the name of the "
                                                     "virtual host for the query (using HTTP/1.1). If you "
                                                     "leave this empty, then the IP address of the host "
                                                     "will be used instead."),
                                            allow_empty = False
                                        ),
                                        Checkbox(
                                            label = _("Omit specifying an IP address"),
                                            help = _("Usually Check_MK will nail this check to the "
                                                     "IP address of the host it is attached to. With this "
                                                     "option you can have the check use the name of the "
                                                     "virtual host instead and do a dynamic DNS lookup."),
                                            true_label = _("omit IP address"),
                                            false_label = _("specify IP address"),
                                        ),
                                    ]
                                )
                            ),
                            ( "uri",
                                TextAscii(
                                    title = _("URI to fetch (default is <tt>/</tt>)"),
                                    allow_empty = False,
                                    default_value = "/"
                                )
                            ),
                            ( "port",
                                Integer(
                                    title = _("TCP Port"),
                                    minvalue = 1,
                                    maxvalue = 65535,
                                    default_value = 80
                                )
                            ),
                            ip_address_family_element,
                            ("ssl", Transform(
                                DropdownChoice(
                                    title = _("Use SSL/HTTPS for the connection"),
                                    choices = [
                                        ("auto",  _("Use SSL with auto negotiation")),
                                        ("1",     _("Use SSL, enforce TLSv1")),
                                        ("2",     _("Use SSL, enforce SSLv2")),
                                        ("3",     _("Use SSL, enforce SSLv3")),
                                    ],
                                    default_value = "auto",
                                ),
                                forth = lambda x: x == True and "auto" or x,
                            )),
                            ( "sni",
                                FixedValue(
                                    value = True,
                                    totext = _("enable SNI"),
                                    title = _("Enable SSL/TLS hostname extension support (SNI)"),
                                )
                            ),
                            ( "response_time",
                                Tuple(
                                    title = _("Expected response time"),
                                    elements = [
                                        Float(
                                            title = _("Warning if above"),
                                            unit = "ms",
                                            default_value = 100.0
                                        ),
                                        Float(
                                            title = _("Critical if above"),
                                            unit = "ms",
                                            default_value = 200.0
                                        ),
                                    ]
                                )
                            ),
                            ( "timeout",
                                Integer(
                                    title = _("Seconds before connection times out"),
                                    unit = _("sec"),
                                    default_value = 10,
                                )
                            ),
                            ( "user_agent",
                                TextAscii(
                                    title = _("User Agent"),
                                    help = _("String to be sent in http header as \"User Agent\""),
                                    allow_empty = False,
                                ),
                            ),
                            ( "add_headers",
                                ListOfStrings(
                                    title = _("Additional header lines"),
                                    orientation = "vertical",
                                    valuespec = TextAscii(size = 40),
                                ),
                            ),
                            ( "auth",
                                Tuple(
                                    title = _("Authorization"),
                                    help = _("Credentials for HTTP Basic Authentication"),
                                    elements = [
                                        TextAscii(
                                            title = _("Username"),
                                            size = 12,
                                            allow_empty = False
                                        ),
                                        Password(
                                            title = _("Password"),
                                            size = 12,
                                            allow_empty = False
                                        ),
                                    ]
                                )
                            ),
                            ( "proxy_auth",
                                Tuple(
                                    title = _("Proxy-Authorization"),
                                    help = _("Credentials for HTTP Proxy with basic authentication"),
                                    elements = [
                                        TextAscii(
                                            title = _("Username"),
                                            size = 12,
                                            allow_empty = False
                                        ),
                                        Password(
                                            title = _("Password"),
                                            size = 12,
                                            allow_empty = False
                                        ),
                                    ]
                                )
                            ),
                            ( "onredirect",
                                DropdownChoice(
                                    title = _("How to handle redirect"),
                                    choices = [
                                        ( 'ok',         _("Make check OK") ),
                                        ( 'warning',    _("Make check WARNING") ),
                                        ( 'critical',   _("Make check CRITICAL") ),
                                        ( 'follow',     _("Follow the redirection") ),
                                        ( 'sticky',     _("Follow, but stay to same IP address") ),
                                        ( 'stickyport', _("Follow, but stay to same IP-address and port") ),
                                    ],
                                    default_value = 'follow'
                                ),
                            ),
                            ( "expect_response_header",
                                TextAscii(
                                    title = _("String to expect in response headers"),
                                )
                            ),
                            ( "expect_response",
                                ListOfStrings(
                                    title = _("Strings to expect in server response"),
                                    help = _("At least one of these strings is expected in "
                                             "the first (status) line of the server response "
                                             "(default: <tt>HTTP/1.</tt>). If specified skips "
                                             "all other status line logic (ex: 3xx, 4xx, 5xx "
                                             "processing)"),
                                )
                            ),
                            ( "expect_string",
                                TextAscii(
                                    title = _("Fixed string to expect in the content"),
                                    allow_empty = False,
                                )
                            ),
                            ( "expect_regex",
                                Transform(
                                    Tuple(
                                        orientation = "vertical",
                                        show_titles = False,
                                        elements = [
                                            RegExp(label = _("Regular expression: ")),
                                            Checkbox(label = _("Case insensitive")),
                                            Checkbox(label = _("return CRITICAL if found, OK if not")),
                                            Checkbox(label = _("Multiline string matching")),
                                        ]
                                    ),
                                    forth = lambda x: len(x) == 3 and tuple(list(x) + [False]) or x,
                                    title = _("Regular expression to expect in content"),
                                ),
                            ),
                            ( "post_data",
                                Tuple(
                                    title = _("Send HTTP POST data"),
                                    elements = [
                                        TextUnicode(
                                            title = _("HTTP POST data"),
                                            help = _("Data to send via HTTP POST method. "
                                                     "Please make sure, that the data is URL-encoded."),
                                            size = 40,
                                        ),
                                        TextAscii(
                                            title = _("Content-Type"),
                                            default_value = "text/html"),
                                    ]
                                )
                            ),
                            ( "method",
                                DropdownChoice(
                                    title = _("HTTP Method"),
                                    default_value = "GET",
                                    choices = [
                                        ( "GET", "GET" ),
                                        ( "POST", "POST" ),
                                        ( "OPTIONS", "OPTIONS" ),
                                        ( "TRACE", "TRACE" ),
                                        ( "PUT", "PUT" ),
                                        ( "DELETE", "DELETE" ),
                                        ( "HEAD", "HEAD" ),
                                        ( "CONNECT", "CONNECT" ),
                                    ]
                                )
                            ),
                            ( "no_body",
                                FixedValue(
                                    value = True,
                                    title = _("Don't wait for document body"),
                                    help = _("Note: this still does an HTTP GET or POST, not a HEAD."),
                                    totext = _("don't wait for body")
                                )
                            ),
                            ( "page_size",
                                Tuple(
                                    title = _("Page size to expect"),
                                    elements = [
                                        Integer(title = _("Minimum"), unit=_("Bytes")),
                                        Integer(title = _("Maximum"), unit=_("Bytes")),
                                    ]
                                )
                            ),
                            ( "max_age",
                                Age(
                                    title = _("Maximum age"),
                                    help = _("Warn, if the age of the page is older than this"),
                                    default_value = 3600 * 24,
                                )
                            ),
                            ( "urlize",
                                FixedValue(
                                    value = True,
                                    title = _("Clickable URLs"),
                                    totext = _("Format check output as hyperlink"),
                                    help = _("With this option the check produces an output that is a valid hyperlink "
                                             "to the checked URL and this clickable."),
                                )
                            ),
                            ("extended_perfdata", FixedValue(
                                value = True,
                                totext = _("Extended perfdata"),
                                title = _("Record additional performance data"),
                                help = _("This option makes the HTTP check produce more detailed performance data values "
                                         "like the connect time, header time, time till first byte received and the "
                                         "transfer time."),
                            )),
                        ]
                    ),

                    Dictionary(
                        title = _("Check SSL Certificate Age"),
                        elements = [
                            ( "cert_days",
                                Transform(
                                    Tuple(
                                        title = _("Age"),
                                        help = _("Minimum number of days a certificate has to be valid. "
                                                 "Port defaults to 443. When this option is used the URL "
                                                 "is not checked."),
                                        elements = [
                                            Integer(title = _("Warning at or below"), minvalue = 0, unit = _("days")),
                                            Integer(title = _("Critical at or below"), minvalue = 0, unit = _("days")),
                                        ],
                                    ),
                                    forth = transform_cert_days,
                                ),
                            ),
                            ( "cert_host",
                                TextAscii(
                                    title = _("Check Certificate of different IP / DNS Name"),
                                    help = _("For each SSL certificate on a host, a different IP address is needed. "
                                             "Here, you can specify the address if it differs from the  "
                                             "address from the host primary address."),
                                ),
                            ),
                            ( "port",
                                Integer(
                                    title = _("TCP Port"),
                                    minvalue = 1,
                                    maxvalue = 65535,
                                    default_value = 443,
                                ),
                            ),
                            ip_address_family_element,
                            ( "sni",
                                FixedValue(
                                    value = True,
                                    totext = _("enable SNI"),
                                    title = _("Enable SSL/TLS hostname extension support (SNI)"),
                                ),
                            ),
                        ],
                        required_keys = [ "cert_days" ],
                    ),
                ]
            ),
        ]
    ),
    match = 'all'
)

register_rule(group,
    "active_checks:ldap",
    Tuple(
        title = _("Check access to LDAP service"),
        help = _("This check uses <tt>check_ldap</tt> from the standard "
                "Nagios plugins in order to try the response of an LDAP "
                "server."),
        elements = [
            TextUnicode(
                title = _("Name"),
                help = _("The service description will be <b>LDAP</b> plus this name. If the name starts with "
                         "a caret (<tt>^</tt>), the service description will not be prefixed with <tt>LDAP</tt>." ),
                allow_empty = False),
            TextAscii(
                title = _("Base DN"),
                help = _("LDAP base, e.g. ou=Development, o=Mathias Kettner GmbH, c=de"),
                allow_empty = False,
                size = 60),
            Dictionary(
               title = _("Optional parameters"),
               elements = [
                   ( "attribute",
                     TextAscii(
                         title = _("Attribute to search"),
                         help = _("LDAP attribute to search, "
                                  "The default is <tt>(objectclass=*)</tt>."),
                         size = 40,
                         allow_empty = False,
                         default_value = "(objectclass=*)",
                     )
                   ),
                   ( "authentication",
                     Tuple(
                         title = _("Authentication"),
                         elements = [
                             TextAscii(
                                 title = _("Bind DN"),
                                 help = _("Distinguished name for binding"),
                                 allow_empty = False,
                                 size = 60,
                             ),
                             Password(
                                 title = _("Password"),
                                 help = _("Password for binding, if your server requires an authentication"),
                                 allow_empty = False,
                                 size = 20,
                             )
                        ]
                      )
                   ),
                   ( "port",
                     Integer(
                       title = _("TCP Port"),
                       help = _("Default is 389 for normal connections and 636 for SSL connections."),
                       minvalue = 1,
                       maxvalue = 65535,
                       default_value = 389)
                   ),
                   ( "ssl",
                      FixedValue(
                          value = True,
                          totext = _("Use SSL"),
                          title = _("Use LDAPS (SSL)"),
                          help = _("Use LDAPS (LDAP SSLv2 method). This sets the default port number to 636"))

                   ),
                   ( "hostname",
                     TextAscii(
                         title = _("Alternative Hostname"),
                         help = _("Use a alternative field as Hostname in case of SSL Certificate Problems (eg. the Hostalias )"),
                         size = 40,
                         allow_empty = False,
                         default_value = "$HOSTALIAS$",
                     )
                   ),
                   ( "version",
                     DropdownChoice(
                        title = _("LDAP Version"),
                        help = _("The default is to use version 2"),
                        choices = [
                            ( "v2", _("Version 2") ),
                            ( "v3", _("Version 3") ),
                            ( "v3tls", _("Version 3 and TLS") ),
                        ],
                        default_value = "v2",
                      )
                   ),
                   ( "response_time",
                     Tuple(
                         title = _("Expected response time"),
                         elements = [
                             Float(
                                 title = _("Warning if above"),
                                 unit = "ms",
                                 default_value = 1000.0),
                             Float(
                                 title = _("Critical if above"),
                                 unit = "ms",
                                 default_value = 2000.0),
                         ])
                    ),
                    ( "timeout",
                      Integer(
                          title = _("Seconds before connection times out"),
                          unit = _("sec"),
                          default_value = 10,
                      )
                    ),
                ])
        ]),
    match = 'all'
)

def transform_smtp_address_family(val):
    if "ip_version" in val:
        val["address_family"] = val.pop("ip_version")
    return val

register_rule(group,
    "active_checks:smtp",
    Tuple(
        title = _("Check access to SMTP services"),
        help = _("This check uses <tt>check_smtp</tt> from the standard "
                "Nagios plugins in order to try the response of an SMTP "
                "server."),
        elements = [
            TextUnicode(
                title = _("Name"),
                help = _("The service description will be <b>SMTP</b> plus this name. If the name starts with "
                         "a caret (<tt>^</tt>), the service description will not be prefixed with <tt>SMTP</tt>." ),
                allow_empty = False),
            Transform(
                Dictionary(
                   title = _("Optional parameters"),
                   elements = [
                       ( "hostname",
                         TextAscii(
                             title = _("DNS Hostname or IP address"),
                             allow_empty = False,
                             help = _("You can specify a hostname or IP address different from the IP address "
                                      "of the host as configured in your host properties."))),
                       ( "port",
                         Transform(
                             Integer(
                                 title = _("TCP Port to connect to"),
                                 help = _("The TCP Port the SMTP server is listening on. "
                                          "The default is <tt>25</tt>."),
                                 size = 5,
                                 minvalue = 1,
                                 maxvalue = 65535,
                                 default_value = "25",
                             ),
                             forth = int,
                          )
                       ),
                       ip_address_family_element,
                       ( "expect",
                         TextAscii(
                             title = _("Expected String"),
                             help = _("String to expect in first line of server response. "
                                      "The default is <tt>220</tt>."),
                             size = 8,
                             allow_empty = False,
                             default_value = "220",
                         )
                       ),
                       ('commands',
                         ListOfStrings(
                             title = _("SMTP Commands"),
                             help = _("SMTP commands to execute."),
                         )
                       ),
                       ('command_responses',
                         ListOfStrings(
                             title = _("SMTP Responses"),
                             help = _("Expected responses to the given SMTP commands."),
                         )
                       ),
                       ("from",
                         TextAscii(
                             title = _("FROM-Address"),
                             help = _("FROM-address to include in MAIL command, required by Exchange 2000"),
                             size = 20,
                             allow_empty = True,
                             default_value = "",
                         )
                       ),
                       ("fqdn",
                         TextAscii(
                             title = _("FQDN"),
                             help = _("FQDN used for HELO"),
                             size = 20,
                             allow_empty = True,
                             default_value = "",
                         )
                       ),
                       ( "cert_days",
                         Transform(
                             Tuple(
                                 title = _("Minimum Certificate Age"),
                                 help = _("Minimum number of days a certificate has to be valid"),
                                 elements = [
                                     Integer(title = _("Warning at or below"), minvalue = 0, unit = _("days")),
                                     Integer(title = _("Critical at or below"), minvalue = 0, unit = _("days")),
                                 ],
                             ),
                             forth = transform_cert_days,
                       )),
                       ("starttls",
                          FixedValue(
                              True,
                              totext = _("STARTTLS enabled."),
                              title = _("Use STARTTLS for the connection.")
                          )
                       ),
                       ( "auth",
                         Tuple(
                             title = _("Enable SMTP AUTH (LOGIN)"),
                             help = _("SMTP AUTH type to check (default none, only LOGIN supported)"),
                             elements = [
                                 TextAscii(
                                     title = _("Username"),
                                     size = 12,
                                     allow_empty = False),
                                 Password(
                                     title = _("Password"),
                                     size = 12,
                                     allow_empty = False),
                             ]
                         )
                       ),
                       ("response_time",
                         Tuple(
                             title = _("Expected response time"),
                             elements = [
                                 Integer(
                                     title = _("Warning if above"),
                                     unit = _("sec")
                                 ),
                                 Integer(
                                     title = _("Critical if above"),
                                     unit = _("sec")
                                 ),
                             ])
                        ),
                        ( "timeout",
                          Integer(
                              title = _("Seconds before connection times out"),
                              unit = _("sec"),
                              default_value = 10,
                          )
                        ),
                    ]
                ),
                forth=transform_smtp_address_family,
            )
        ]
    ),
    match = 'all'
)

register_rule(group,
    "active_checks:disk_smb",
    Dictionary(
        title = _("Check access to SMB share"),
        help = _("This ruleset helps you to configure the classical Nagios "
                 "plugin <tt>check_disk_smb</tt> that checks the access to "
                 "filesystem shares that are exported via SMB/CIFS."),
        elements = [
            ( "share",
              TextUnicode(
                  title = _("SMB share to check"),
                  help = _("Enter the plain name of the share only, e. g. <tt>iso</tt>, <b>not</b> "
                           "the full UNC like <tt>\\\\servername\\iso</tt>"),
                  size = 32,
                  allow_empty = False,
            )),
            ( "workgroup",
              TextUnicode(
                  title = _("Workgroup"),
                  help = _("Workgroup or domain used (defaults to <tt>WORKGROUP</tt>)"),
                  size = 32,
                  allow_empty = False,
            )),
            ( "host",
              TextAscii(
                  title = _("NetBIOS name of the server"),
                  help = _("If omitted then the IP address is being used."),
                  size = 32,
                  allow_empty = False,
            )),
            ( "port",
              Integer(
                  title = _("TCP Port"),
                  help = _("TCP port number to connect to. Usually either 139 or 445."),
                  default_value = 445,
                  minvalue = 1,
                  maxvalue = 65535,
            )),
            ( "levels",
              Tuple(
                  title = _("Levels for used disk space"),
                  elements = [
                      Percentage(title = _("Warning if above"), default_value = 85,  allow_int = True),
                      Percentage(title = _("Critical if above"), default_value = 95, allow_int = True),
                  ]
            )),
            ( "auth",
              Tuple(
                  title = _("Authorization"),
                  elements = [
                      TextAscii(
                          title = _("Username"),
                          allow_empty = False,
                          size = 24),
                      Password(
                          title = _("Password"),
                          allow_empty = False,
                          size = 12),
                  ],
            )),
        ],
        required_keys = [ "share", "levels" ],
    ),
    match = 'all'
)

def PluginCommandLine(addhelp = ""):
    return TextAscii(
          title = _("Command line"),
          help = _("Please enter the complete shell command including "
                   "path name and arguments to execute. You can use monitoring "
                   "macros here. The most important are:<ul>"
                   "<li><tt>$HOSTADDRESS$</tt>: The IP address of the host</li>"
                   "<li><tt>$HOSTNAME$</tt>: The name of the host</li>"
                   "<li><tt>$USER1$</tt>: user macro 1 (usually path to shipped plugins)</li>"
                   "<li><tt>$USER2$</tt>: user marco 2 (usually path to your own plugins)</li>"
                   "</ul>"
                   "If you are using OMD, you can omit the path and just specify "
                   "the command (e.g. <tt>check_foobar</tt>). This command will be "
                   "searched first in the local plugins directory "
                   "(<tt>~/local/lib/nagios/plugins</tt>) and then in the shipped plugins "
                   "directory (<tt>~/lib/nagios/plugins</tt>) within your site directory."),
          size = "max",
       )

register_rule(group,
    "custom_checks",
    Dictionary(
        title = _("Classical active and passive Monitoring checks"),
        help = _("With this ruleset you can configure &quot;classical Monitoring checks&quot; "
                 "to be executed directly on your monitoring server. These checks "
                 "will not use Check_MK. It is also possible to configure passive "
                 "checks that are fed with data from external sources via the "
                 "command pipe of the monitoring core."),
        elements = [
            ( "service_description",
              TextUnicode(
                  title = _("Service description"),
                  help = _("Please make sure that this is unique per host "
                         "and does not collide with other services."),
                  allow_empty = False,
                  default_value = _("Customcheck"))
            ),
            ( "command_line",
              PluginCommandLine(addhelp = _("<br><br>"
                   "<b>Passive checks</b>: Do no specify a command line if you want "
                   "to define passive checks.")),
            ),
            ( "command_name",
              TextAscii(
                  title = _("Internal command name"),
                  help = _("If you want, you can specify a name that will be used "
                           "in the <tt>define command</tt> section for these checks. This "
                           "allows you to a assign a custom PNP template for the performance "
                           "data of the checks. If you omit this, then <tt>check-mk-custom</tt> "
                           "will be used."),
                  size = 32)
            ),
            ( "has_perfdata",
              FixedValue(
                  title = _("Performance data"),
                  value = True,
                  totext = _("process performance data"),
              )
            ),
            ( "freshness",
              Dictionary(
                  title = _("Check freshness"),
                  help = _("Freshness checking is only useful for passive checks when the staleness feature "
                           "is not enough for you. It changes the state of a check to a configurable other state "
                           "when the check results are not arriving in time. Staleness will still grey out the "
                           "test after the corrsponding interval. If you don't want that, you might want to adjust "
                           "the staleness interval as well. The staleness interval is calculated from the normal "
                           "check interval multiplied by the staleness value in the <tt>Global Settings</tt>. "
                           "The normal check interval can be configured in a separate rule for your check."),
                  optional_keys = False,
                  elements = [
                      ( "interval",
                        Integer(
                            title = _("Expected update interval"),
                            label = _("Updates are expected at least every"),
                            unit = _("minutes"),
                            minvalue = 1,
                            default_value = 10,
                      )),
                      ( "state",
                        DropdownChoice(
                            title = _("State in case of absent updates"),
                            choices =  [
                               ( 1, _("WARN") ),
                               ( 2, _("CRIT") ),
                               ( 3, _("UNKNOWN") ),
                            ],
                            default_value = 3,
                      )),
                      ( "output",
                        TextUnicode(
                            title = _("Plugin output in case of absent updates"),
                            size = 40,
                            allow_empty = False,
                            default_value = _("Check result did not arrive in time")
                      )),
                  ],
               )
            ),

        ],
        required_keys = [ "service_description" ],
    ),
    match = 'all'
)

register_rule(group,
    "active_checks:bi_aggr",
    Tuple(
        title = _("Check State of BI Aggregation"),
        help = _("Connect to the local or a remote monitoring host, which uses Check_MK BI to aggregate "
                 "several states to a single BI aggregation, which you want to show up as a single "
                 "service."),
        elements = [
            TextAscii(
                title = _("Base URL (OMD Site)"),
                help = _("The base URL to the monitoring instance. For example <tt>http://mycheckmk01/mysite</tt>. You can use "
                         "macros like <tt>$HOSTADDRESS$</tt> and <tt>$HOSTNAME$</tt> within this URL to make them be replaced by "
                         "the hosts values."),
                size = 60,
                allow_empty = False
            ),
            TextAscii(
                title = _("Aggregation Name"),
                help = _("The name of the aggregation to fetch. It will be added to the service description. You can use "
                         "macros like <tt>$HOSTADDRESS$</tt> and <tt>$HOSTNAME$</tt> within this parameter to make them be replaced by "
                         "the hosts values."),
                allow_empty = False
            ),
            TextAscii(
                title = _("Username"),
                help = _("The name of the user account to use for fetching the BI aggregation via HTTP. When "
                         "using the cookie based authentication mode (default), this must be a user where "
                         "authentication is set to \"Automation Secret\" based authentication."),
                allow_empty = False
            ),
            Password(
                title = _("Password / Secret"),
                help = _("Valid automation secret or password for the user, depending on the chosen "
                         "authentication mode."),
                allow_empty = False
            ),
            Dictionary(
                title = _("Optional parameters"),
                elements = [
                    ("auth_mode", DropdownChoice(
                        title = _('Authentication Mode'),
                        default_value = 'cookie',
                        choices = [
                            ('cookie', _('Form (Cookie) based')),
                            ('basic',  _('HTTP Basic')),
                            ('digest', _('HTTP Digest')),
                        ],
                    )),
                    ("timeout", Integer(
                        title = _("Seconds before connection times out"),
                        unit = _("sec"),
                        default_value = 60,
                    )),
                    ("in_downtime",
                      RadioChoice(
                          title = _("State, if BI aggregate is in scheduled downtime"),
                          orientation = "vertical",
                          choices = [
                            ( None, _("Use normal state, ignore downtime") ),
                            ( "ok", _("Force to be OK") ),
                            ( "warn", _("Force to be WARN, if aggregate is not OK") ),
                          ]
                    )),
                    ("acknowledged",
                      RadioChoice(
                          title = _("State, if BI aggregate is acknowledged"),
                          orientation = "vertical",
                          choices = [
                            ( None, _("Use normal state, ignore acknowledgement") ),
                            ( "ok", _("Force to be OK") ),
                            ( "warn", _("Force to be WARN, if aggregate is not OK") ),
                          ]
                    )),
                    ("track_downtimes",
                     Checkbox(
                        title = _("Track downtimes"),
                        label = _("Automatically track downtimes of aggregation"),
                        help = _("If this is active, the check will automatically go into downtime "
                                "whenever the aggregation does. This downtime is also cleaned up "
                                "automatically when the aggregation leaves downtime. "
                                "Downtimes you set manually for this check are unaffected."),
                    )),
                ]
            ),
        ]
    ),
    match = 'all'
)

register_rule(group,
    "active_checks:form_submit",
    Tuple(
        title = _("Check HTML Form Submit"),
        help = _("Check submission of HTML forms via HTTP/HTTPS using the plugin <tt>check_form_submit</tt> "
                 "provided with Check_MK. This plugin provides more functionality as <tt>check_http</tt>, "
                 "as it automatically follows HTTP redirect, accepts and uses cookies, parses forms "
                 "from the requested pages, changes vars and submits them to check the response "
                 "afterwards."),
        elements = [
            TextUnicode(
                title = _("Name"),
                help = _("The name will be used in the service description"),
                allow_empty = False
            ),
            Dictionary(
                title = _("Check the URL"),
                elements = [
                    ("hosts", ListOfStrings(
                        title = _('Check specific host(s)'),
                        help = _('By default, if you do not specify any host addresses here, '
                                 'the host address of the host this service is assigned to will '
                                 'be used. But by specifying one or several host addresses here, '
                                 'it is possible to let the check monitor one or multiple hosts.')
                    )),
                    ("virthost", TextAscii(
                        title = _("Virtual host"),
                        help = _("Set this in order to specify the name of the "
                         "virtual host for the query (using HTTP/1.1). When you "
                         "leave this empty, then the IP address of the host "
                         "will be used instead."),
                        allow_empty = False,
                    )),
                    ("uri", TextAscii(
                        title = _("URI to fetch (default is <tt>/</tt>)"),
                        allow_empty = False,
                        default_value = "/",
                        regex = '^/.*',
                    )),
                    ("port", Integer(
                        title = _("TCP Port"),
                        minvalue = 1,
                        maxvalue = 65535,
                        default_value = 80,
                    )),
                    ("ssl", FixedValue(
                        value = True,
                        totext = _("use SSL/HTTPS"),
                        title = _("Use SSL/HTTPS for the connection."))
                    ),
                    ("timeout", Integer(
                        title = _("Seconds before connection times out"),
                        unit = _("sec"),
                        default_value = 10,
                    )),
                    ("expect_regex", RegExp(
                        title = _("Regular expression to expect in content"),
                    )),
                    ("form_name", TextAscii(
                        title = _("Name of the form to populate and submit"),
                        help = _("If there is only one form element on the requested page, you "
                                 "do not need to provide the name of that form here. But if you "
                                 "have several forms on that page, you need to provide the name "
                                 "of the form here, to enable the check to identify the correct "
                                 "form element."),
                        allow_empty = True,
                    )),
                    ("query", TextAscii(
                        title = _("Send HTTP POST data"),
                        help = _("Data to send via HTTP POST method. Please make sure, that the data "
                                 "is URL-encoded (for example \"key1=val1&key2=val2\")."),
                        size = 40,
                    )),
                    ("num_succeeded", Tuple(
                        title = _("Multiple Hosts: Number of successful results"),
                        elements = [
                            Integer(title = _("Warning if equal or below")),
                            Integer(title = _("Critical if equal or below")),
                        ]
                    )),
                ]
            ),
        ]
    ),
    match = 'all'
)

register_rule(group,
    "active_checks:notify_count",
    Tuple(
        title = _("Check Number of Notifications per Contact"),
        help = _("Check the number of sent notifications per contact using the plugin <tt>check_notify_count</tt> "
                 "provided with Check_MK. This plugin counts the total number of notifications sent by the local "
                 "monitoring core and creates graphs for each individual contact. You can configure thresholds "
                 "on the number of notifications per contact in a defined time interval. "
                 "This plugin queries livestatus to extract the notification related log entries from the "
                 "log file of your monitoring core."),
        elements = [
            TextUnicode(
                title = _("Service Description"),
                help = _("The name that will be used in the service description"),
                allow_empty = False
            ),
            Integer(
                title = _("Interval to monitor"),
                label = _("notifications within last"),
                unit = _("minutes"),
                minvalue = 1,
                default_value = 60,
            ),
            Dictionary(
                title = _("Optional parameters"),
                elements = [
                    ("num_per_contact", Tuple(
                        title = _("Thresholds for Notifications per Contact"),
                        elements = [
                            Integer(title = _("Warning if above"), default_value = 20),
                            Integer(title = _("Critical if above"), default_value = 50),
                        ]
                    )),
                ]
            ),
        ]
    ),
    match = 'all'
)

register_rule(group,
    "active_checks:traceroute",
    Dictionary(
        title = _("Check current routing (uses <tt>traceroute</tt>)"),
        help = _("This active check uses <tt>traceroute</tt> in order to determine the current "
                 "routing from the monitoring host to the target host. You can specify any number "
                 "of missing or expected routes in that way detect e.g. an (unintended) failover "
                 "to a secondary route."),
        elements = [
            ( "dns",
              Checkbox(
                  title = _("Name resolution"),
                  label = _("Use DNS to convert IP addresses into hostnames"),
                  help = _("If you use this option, then <tt>traceroute</tt> is <b>not</b> being "
                           "called with the option <tt>-n</tt>. That means that all IP addresses "
                           "are tried to be converted into names. This usually adds additional "
                           "execution time. Also DNS resolution might fail for some addresses."),
            )),
            ( "routers",
              ListOf(
                  Tuple(
                      elements = [
                          TextAscii(
                              title = _("Router (FQDN, IP-Address)"),
                              allow_empty = False,
                          ),
                          DropdownChoice(
                              title = _("How"),
                              choices = [
                                 ( 'W', _("WARN - if this router is not being used") ),
                                 ( 'C', _("CRIT - if this router is not being used") ),
                                 ( 'w', _("WARN - if this router is being used") ),
                                 ( 'c', _("CRIT - if this router is being used") ),
                              ]
                         ),
                      ]
                  ),
                  title = _("Router that must or must not be used"),
                  add_label = _("Add Condition"),
              )
            ),
            ( "method",
              DropdownChoice(
                  title = _("Method of probing"),
                  choices = [
                      ( None,   _("UDP (default behaviour of tcpdump)") ),
                      ( "icmp", _("ICMP Echo Request") ),
                      ( "tcp",  _("TCP SYN") ),
                  ]
              )
            ),
        ],
        optional_keys = False,
    ),
    match = 'all'
)

register_rule(group,
    'active_checks:mail_loop',
    Dictionary(
        title = _('Check Email Delivery'),
        help = _('This active check sends out special E-Mails to a defined mail address using '
                 'the SMTP protocol and then tries to receive these mails back by querying the '
                 'inbox of a IMAP or POP3 mailbox. With this check you can verify that your whole '
                 'mail delivery progress is working.'),
        optional_keys = ['smtp_server', 'smtp_tls', 'smtp_port', 'smtp_auth', 'imap_tls', 'connect_timeout', 'delete_messages', 'duration'],
        elements = [
            ('item', TextUnicode(
                title = _('Name'),
                help = _('The service description will be <b>Mail Loop</b> plus this name'),
                allow_empty = False
            )),
            ('smtp_server', TextAscii(
                title = _('SMTP Server'),
                allow_empty = False,
                help = _('You can specify a hostname or IP address different from the IP address '
                         'of the host this check will be assigned to.')
            )),
            ('smtp_tls', FixedValue(True,
                title = _('Use TLS over SMTP'),
                totext = _('Encrypt SMTP communication using TLS'),
            )),
            ('imap_tls', FixedValue(True,
                title = _('Use TLS for IMAP authentification'),
                totext = _('IMAP authentification uses TLS'),
            )),
            ('smtp_port', Integer(
                title = _('SMTP TCP Port to connect to'),
                help = _('The TCP Port the SMTP server is listening on. Defaulting to <tt>25</tt>.'),
                allow_empty = False,
                default_value = 25,
            )),
            ('smtp_auth', Tuple(
                title = _('SMTP Authentication'),
                elements = [
                    TextAscii(
                        title = _('Username'),
                        allow_empty = False,
                        size = 24
                    ),
                    Password(
                        title = _('Password'),
                        allow_empty = False,
                        size = 12
                    ),
                ],
            )),
        ] + mail_receiving_params + [
            ('mail_from', EmailAddress(
                title = _('From: email address'),
            )),
            ('mail_to', EmailAddress(
                title = _('Destination email address'),
            )),
            ('connect_timeout', Integer(
                title = _('Connect Timeout'),
                minvalue = 1,
                default_value = 10,
                unit = _('sec'),
            )),
            ("duration", Tuple(
                title = _("Loop duration"),
                elements = [
                    Age(title = _("Warning at")),
                    Age(title = _("Critical at")),
                ])
            ),
            ('delete_messages', FixedValue(True,
                title = _('Delete processed messages'),
                totext = _('Delete all processed message belonging to this check'),
                help = _('Delete all messages identified as being related to this '
                         'check. This is disabled by default, which will make '
                         'your mailbox grow when you not clean it up on your own.'),
            )),
        ]
    ),
    match = 'all'
)

register_rule(group,
    'active_checks:mail',
    Dictionary(
        title = _('Check Email'),
        help = _('The basic function of this check is to log in into an IMAP or POP3 mailbox to '
                 'monitor whether or not the login is possible. A extended feature is, that the '
                 'check can fetch all (or just some) from the mailbox and forward them as events '
                 'to the Event Console.'),
        required_keys = [ 'service_description', 'fetch' ],
        elements = [
            ('service_description',
              TextUnicode(
                  title = _('Service description'),
                  help = _('Please make sure that this is unique per host '
                           'and does not collide with other services.'),
                  allow_empty = False,
                  default_value = "Email")
            )
        ] + mail_receiving_params + [
            ('connect_timeout', Integer(
                title = _('Connect Timeout'),
                minvalue = 1,
                default_value = 10,
                unit = _('sec'),
            )),
            ('forward', Dictionary(
                title = _("Forward mails as events to Event Console"),
                elements = [
                    ('method', Alternative(
                        title = _("Forwarding Method"),
                        elements = [
                            Alternative(
                                title = _("Send events to local event console"),
                                elements = [
                                    FixedValue(
                                        "",
                                        totext = _("Directly forward to event console"),
                                        title = _("Send events to local event console in same OMD site"),
                                    ),
                                    TextAscii(
                                        title = _("Send events to local event console into unix socket"),
                                        allow_empty = False,
                                    ),

                                    FixedValue(
                                        "spool:",
                                        totext = _("Spool to event console"),
                                        title = _("Spooling: Send events to local event console in same OMD site"),
                                    ),
                                    Transform(
                                        TextAscii(),
                                        title = _("Spooling: Send events to local event console into given spool directory"),
                                        allow_empty = False,
                                        forth = lambda x: x[6:],        # remove prefix
                                        back  = lambda x: "spool:" + x, # add prefix
                                    ),
                                ],
                                match = lambda x: x and (x == 'spool:' and 2 or x.startswith('spool:') and 3 or 1) or 0
                            ),
                            Tuple(
                                title = _("Send events to remote syslog host"),
                                elements = [
                                    DropdownChoice(
                                        choices = [
                                            ('udp', _('UDP')),
                                            ('tcp', _('TCP')),
                                        ],
                                        title = _("Protocol"),
                                    ),
                                    TextAscii(
                                        title = _("Address"),
                                        allow_empty = False,
                                    ),
                                    Integer(
                                        title = _("Port"),
                                        allow_empty = False,
                                        default_value = 514,
                                        minvalue = 1,
                                        maxvalue = 65535,
                                        size = 6,
                                    ),
                                ]
                            ),
                        ],
                    )),
                    ('match_subject', RegExpUnicode(
                        title = _('Only process mails with matching subject'),
                        help = _('Use this option to not process all messages found in the inbox, '
                                 'but only the those whose subject matches the given regular expression.'),
                    )),
                    ('facility', DropdownChoice(
                        title = _("Events: Syslog facility"),
                        help = _("Use this syslog facility for all created events"),
                        choices = syslog_facilities,
                        default_value = 2, # mail
                    )),
                    ('application', Alternative(
                        title = _("Events: Syslog application"),
                        help = _("Use this syslog application for all created events"),
                        elements = [
                            FixedValue(None,
                                title = _("Use the mail subject"),
                                totext = _("The mail subject is used as syslog appliaction"),
                            ),
                            TextUnicode(
                                title = _("Specify the application"),
                                help = _("Use this text as application. You can use macros like <tt>\\1</tt>, <tt>\\2</tt>, ... "
                                         "here when you configured <i>subject matching</i> in this rule with a regular expression "
                                         "that declares match groups (using braces)."),
                                allow_empty = False,
                            ),
                        ]
                    )),
                    ('host', TextAscii(
                        title = _('Events: Hostname'),
                        help = _('Use this hostname for all created events instead of the name of the mailserver'),
                    )),
                    ('body_limit', Integer(
                        title = _('Limit length of mail body'),
                        help = _('When forwarding mails from the mailbox to the event console, the '
                                 'body of the mail is limited to the given number of characters.'),
                        default_value = 1000,
                    )),
                    ('cleanup', Alternative(
                        title = _("Cleanup messages"),
                        help = _("The handled messages (see <i>subject matching</i>) can be cleaned up by either "
                                 "deleting them or moving them to a subfolder. By default nothing is cleaned up."),
                        elements = [
                            FixedValue(True,
                                title = _('Delete messages'),
                                totext = _('Delete all processed message belonging to this check'),
                            ),
                            TextUnicode(
                                title = _("Move to subfolder"),
                                help = _("Specify the destination path in the format <tt>Path/To/Folder</tt>, for example"
                                         "<tt>INBOX/Processed_Mails</tt>."),
                                allow_empty = False,
                            ),
                        ]
                    )),
                ]
            )),
        ]
    ),
    match = 'all'
)

register_rule(group,
    'active_checks:mailboxes',
    Dictionary(
        title = _('Check IMAP Mailboxes'),
        help = _('This check monitors count and age of mails in mailboxes.'),
        elements = [
            ('service_description',
              TextUnicode(
                  title = _('Service description'),
                  help = _('Please make sure that this is unique per host '
                           'and does not collide with other services.'),
                  allow_empty = False,
                  default_value = "Mailboxes")
            ),
            ('imap_parameters', imap_parameters),
            ('connect_timeout', Integer(
                title = _('Connect Timeout'),
                minvalue = 1,
                default_value = 10,
                unit = _('sec'),
            )),
            ('age', Tuple(
                title = _("Message Age"),
                elements = [
                    Age(title = _("Warning at")),
                    Age(title = _("Critical at"))
                ])),
            ('count', Tuple(
                title = _("Message Count"),
                elements = [
                    Integer(title = _("Warning at")),
                    Integer(title = _("Critical at"))
                ])),
            ('mailboxes', ListOfStrings(
                        title = _('Check only the listed mailboxes'),
                        help = _('By default, all mailboxes are checked with these parameters. '
                                 'If you specify mailboxes here, only those are monitored.')
                    ))
        ],
        required_keys = [ 'service_description', 'imap_parameters' ]
    ),
    match = 'all'
)