This file is indexed.

/usr/share/check_mk/web/plugins/wato/datasource_programs.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
#!/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("datasource_programs",
    _("Datasource Programs"),
    _("Specialized agents, e.g. check via SSH, ESX vSphere, SAP R/3"))
group = "datasource_programs"

register_rule(group,
    "datasource_programs",
    TextAscii(
        title = _("Individual program call instead of agent access"),
        help = _("For agent based checks Check_MK allows you to specify an alternative "
                 "program that should be called by Check_MK instead of connecting the agent "
                 "via TCP. That program must output the agent's data on standard output in "
                 "the same format the agent would do. This is for example useful for monitoring "
                 "via SSH. The command line may contain the placeholders <tt>&lt;IP&gt;</tt> and "
                 "<tt>&lt;HOST&gt;</tt>."),
        label = _("Command line to execute"),
        empty_text = _("Access Check_MK Agent via TCP"),
        size = 80,
        attrencode = True))

register_rule(group,
    "special_agents:vsphere",
     Transform(
         valuespec = Dictionary(
            elements = [
                ( "user",
                  TextAscii(
                      title = _("vSphere User name"),
                      allow_empty = False,
                  )
                ),
                ( "secret",
                  Password(
                      title = _("vSphere secret"),
                      allow_empty = False,
                  )
                ),
                ( "tcp_port",
                  Integer(
                       title = _("TCP Port number"),
                       help = _("Port number for HTTPS connection to vSphere"),
                       default_value = 443,
                       minvalue = 1,
                       maxvalue = 65535,
                  )
                ),
                ( "ssl",
                  Alternative(
                        title = _("SSL certificate checking"),
                        elements = [
                            FixedValue( False, title = _("Deactivated"), totext=""),
                            FixedValue( True,  title = _("Use hostname"), totext=""),
                            TextAscii(  title = _("Use other hostname"),
                                        help = _("The IP of the other hostname needs to be the same IP as the host address")
                            )
                        ],
                        default_value = False
                  )
                ),
                ( "timeout",
                  Integer(
                      title = _("Connect Timeout"),
                      help = _("The network timeout in seconds when communicating with vSphere or "
                               "to the Check_MK Agent. The default is 60 seconds. Please note that this "
                               "is not a total timeout but is applied to each individual network transation."),
                      default_value = 60,
                      minvalue = 1,
                      unit = _("seconds"),
                  )
                ),
                ( "infos",
                  Transform(
                      ListChoice(
                         choices = [
                             ( "hostsystem",     _("Host Systems") ),
                             ( "virtualmachine", _("Virtual Machines") ),
                             ( "datastore",      _("Datastores") ),
                             ( "counters",       _("Performance Counters") ),
                             ( "licenses",       _("License Usage") ),
                         ],
                         default_value = [ "hostsystem", "virtualmachine", "datastore", "counters" ],
                         allow_empty = False,
                       ),
                       forth = lambda v: [ x.replace("storage", "datastore") for x in v ],
                       title = _("Retrieve information about..."),
                    )
                 ),
                 ( "host_pwr_display",
                   DropdownChoice(
                       title = _("Display ESX Host power state on"),
                       choices = [
                           ( None,      _("The queried ESX system (vCenter / Host)") ),
                           ( "esxhost", _("The ESX Host") ),
                           ( "vm",      _("The Virtual Machine") ),
                       ],
                       default = None,
                   )
                 ),
                 ( "vm_pwr_display",
                   DropdownChoice(
                       title = _("Display VM power state on"),
                       choices = [
                           ( None,      _("The queried ESX system (vCenter / Host)") ),
                           ( "esxhost", _("The ESX Host") ),
                           ( "vm",      _("The Virtual Machine") ),
                       ],
                       default = None,
                   )
                 ),
                 ( "spaces",
                   DropdownChoice(
                       title = _("Spaces in hostnames"),
                       choices = [
                           ( "cut",        _("Cut everything after first space") ),
                           ( "underscore", _("Replace with underscores") ),
                       ],
                       default = "underscore",
                   )
                 ),
                 ( "direct",
                   DropdownChoice(
                       title = _("Type of query"),
                       choices = [
                           ( True,    _("Queried host is a host system" ) ),
                           ( False,   _("Queried host is the vCenter") ),
                           ( "agent", _("Queried host is the vCenter with Check_MK Agent installed") ),
                       ],
                       default = True,
                   )
                ),
                ( "skip_placeholder_vms",
                   Checkbox(
                       title = _("Placeholder VMs"),
                       label = _("Do no monitor placeholder VMs"),
                       default_value = True,
                       true_label = _("ignore"),
                       false_label = _("monitor"),
                       help = _("Placeholder VMs are created by the Site Recovery Manager(SRM) and act as backup "
                                "virtual machines in case the default vm is unable to start. This option tells the "
                                "vsphere agent to exclude placeholder vms in its output."
                       ))
                ),
                ( "use_pysphere",
                  Checkbox(
                    title = _("Compatibility mode"),
                    label = _("Support ESX 4.1 (using slower PySphere implementation)"),
                    true_label = _("Support 4.1"),
                    false_label = _("fast"),
                    help = _("The current very performant implementation of the ESX special agent "
                             "does not support older ESX versions than 5.0. Please use the slow "
                             "compatibility mode for those old hosts."),
                  )
                ),
            ],
            optional_keys = [ "tcp_port", "timeout", "vm_pwr_display", "host_pwr_display" ],
        ),
        title = _("Check state of VMWare ESX via vSphere"),
        help = _("This rule selects the vSphere agent instead of the normal Check_MK Agent "
                 "and allows monitoring of VMWare ESX via the vSphere API. You can configure "
                 "your connection settings here."),
        forth = lambda a: dict([("skip_placeholder_vms", True), ("ssl", False), ("use_pysphere" , False), ("spaces", "underscore")] + a.items())
    ),
    factory_default = FACTORY_DEFAULT_UNUSED, # No default, do not use setting if no rule matches
    match = 'first')

register_rule(group,
    "special_agents:hp_msa",
    Dictionary(
        elements = [
            ( "username",
              TextAscii(
                  title = _("Username"),
                  allow_empty = False,
              )
            ),
            ( "password",
              TextAscii(
                  title = _("Password"),
                  allow_empty = False,
              )
            )
        ],
        optional_keys = False
    ),
    title = _("Check HP MSA via Web Interface"),
    help = _("This rule selects the Agent HP MSA instead of the normal Check_MK Agent "
             "which collects the data through the HP MSA web interface"),
    match = 'first')

register_rule(group,
    "special_agents:ipmi_sensors",
    Dictionary(
        elements = [
            ( "username",
              TextAscii(
                  title = _("Username"),
                  allow_empty = False,
              )
            ),
            ( "password",
              Password(
                  title = _("Password"),
                  allow_empty = False,
              )
            ),
            ( "privilege_lvl",
              TextAscii(
                  title = _("Privilege Level"),
                  help = _("Possible are 'user', 'operator', 'admin'"),
                  allow_empty = False,
              )
            )
        ],
        optional_keys = False
    ),
    title = _("Check IPMI Sensors via Freeipmi"),
    help = _("This rule selects the Agent IPMI Sensors instead of the normal Check_MK Agent "
             "which collects the data through the Freeipmi command"),
    match = 'first')

register_rule(group,
    "special_agents:netapp",
    Transform(
        Dictionary(
                title = _("Username and password for the NetApp Filer."),
                elements = [
                    ( "username",
                      TextAscii(
                          title = _("Username"),
                          allow_empty = False,
                      )
                    ),
                    ( "password",
                      Password(
                          title = _("Password"),
                          allow_empty = False,
                      )
                    ),
                    ( "skip_elements",
                        ListChoice(
                           choices = [
                                ("ctr_volumes",  _("Do not query volume performance counters")),
                           ],
                        title = _("Performance improvements"),
                        help = _("Here you can configure whether the performance counters should get queried. "
                                 "This can save quite a lot of CPU load on larger systems."),
                        ),
                    )
                ],
                optional_keys = False
        ),
        forth = lambda x: dict([("skip_elements", [])] + x.items())
    ),
    title = _("Check NetApp via WebAPI"),
    help  = _("This rule set selects the NetApp special agent instead of the normal Check_MK Agent "
              "and allows monitoring via the NetApp Web API. Important: To get this agent running, you need to "
              "install two additional python files (<tt>NaServer.py</tt>, <tt>NaElement.py</tt>) from the "
              "NetApp Manageabiltiy SDK into the <tt>~/local/lib/python</tt> directory. To access the data the "
              "user requires permissions to several API classes. They are shown when you call the agent with "
              "<tt>agent_netapp --help</tt>. The agent itself is located in the site directory under "
              "<tt>~/share/check_mk/agents/special</tt>."),
    match = 'first')

register_rule(group,
    "special_agents:activemq",
    Tuple(
        title = _("Apache ActiveMQ queues"),
        help = _( "Configure the Server Address and the Portnumber of the target server"),
        elements = [
           TextAscii(title = _("Server Name")),
           Integer( title = _("Port Number"), default_value=8161 ),
           ListChoice(
              choices = [
                ("piggybag",  _("Run in piggyback mode")),
              ],
              allow_empty = True
           )
        ]
    ),
    factory_default = FACTORY_DEFAULT_UNUSED, # No default, do not use setting if no rule matches
    match = "first")

register_rule(group,
    "special_agents:emcvnx",
     Dictionary(
        title = _("Check state of EMC VNX storage systems"),
        help = _("This rule selects the EMC VNX agent instead of the normal Check_MK Agent "
                 "and allows monitoring of EMC VNX storage systems by calling naviseccli "
                 "commandline tool locally on the monitoring system. Make sure it is installed "
                 "and working. You can configure your connection settings here."
                 ),
        elements = [
            ( "user",
              TextAscii(
                  title = _("EMC VNX admin user name"),
                  allow_empty = True,
                  help = _("If you leave user name and password empty, the special agent tries to "
                           "authenticate against the EMC VNX device by Security Files. "
                           "These need to be created manually before using. Therefor run as "
                           "instance user (if using OMD) or Nagios user (if not using OMD) "
                           "a command like "
                           "<tt>naviseccli -AddUserSecurity -scope 0 -password PASSWORD -user USER</tt> "
                           "This creates <tt>SecuredCLISecurityFile.xml</tt> and "
                           "<tt>SecuredCLIXMLEncrypted.key</tt> in the home directory of the user "
                           "and these files are used then."
                           ),
              )
            ),
            ( "password",
              Password(
                  title = _("EMC VNX admin user password"),
                  allow_empty = True,
              )
            ),
            ( "infos",
              Transform(
                  ListChoice(
                     choices = [
                         ( "disks",          _("Disks") ),
                         ( "hba",            _("iSCSI HBAs") ),
                         ( "hwstatus",       _("Hardware Status") ),
                         ( "raidgroups",     _("RAID Groups") ),
                         ( "agent",          _("Model and Revsion") ),
                         ( "sp_util",        _("Storage Processor Utilization") ),
                         ( "writecache",     _("Write Cache State") ),
                     ],
                     default_value = [ "disks", "hba", "hwstatus", ],
                     allow_empty = False,
                   ),
                   title = _("Retrieve information about..."),
                )
             ),
        ],
        optional_keys = [ ],
    ),
    factory_default = FACTORY_DEFAULT_UNUSED, # No default, do not use setting if no rule matches
    match = 'first')

register_rule(group,
    "special_agents:ibmsvc",
     Dictionary(
        title = _("Check state of IBM SVC / V7000 storage systems"),
        help = _("This rule set selects the <tt>ibmsvc</tt> agent instead of the normal Check_MK Agent "
                 "and allows monitoring of IBM SVC / V7000 storage systems by calling "
                 "ls* commands there over SSH. "
                 "Make sure you have SSH key authentication enabled for your monitoring user. "
                 "That means: The user your monitoring is running under on the monitoring "
                 "system must be able to ssh to the storage system as the user you gave below "
                 "without password."
                 ),
        elements = [
            ( "user",
              TextAscii(
                  title = _("IBM SVC / V7000 user name"),
                  allow_empty = True,
                  help = _("User name on the storage system. Read only permissions are sufficient."),
              )
            ),
            ( "accept-any-hostkey",
               Checkbox(
                   title = _("Accept any SSH Host Key"),
                   label = _("Accept any SSH Host Key"),
                   default_value = False,
                   help = _("Accepts any SSH Host Key presented by the storage device. "
                            "Please note: This might be a security issue because man-in-the-middle "
                            "attacks are not recognized! Better solution would be to add the "
                            "SSH Host Key of the monitored storage devices to the .ssh/known_hosts "
                            "file for the user your monitoring is running under (on OMD: the site user)"
                   ))
            ),
            ( "infos",
              Transform(
                  ListChoice(
                     choices = [
                         ( "lshost",          _("Hosts Connected") ),
                         ( "lslicense",       _("Licensing Status") ),
                         ( "lsmdisk",         _("MDisks") ),
                         ( "lsmdiskgrp",      _("MDisksGrps") ),
                         ( "lsnode",          _("IO Groups") ),
                         ( "lsnodestats",     _("Node Stats") ),
                         ( "lssystem",        _("System Info") ),
                         ( "lssystemstats",   _("System Stats") ),
                         ( "lseventlog",      _("Event Log") ),
                         ( "lsportfc",        _("FC Ports") ),
                         ( "lsportsas",       _("SAS Ports") ),
                         ( "lsenclosure",     _("Enclosures") ),
                         ( "lsenclosurestats", _("Enclosure Stats") ),
                         ( "lsarray",         _("RAID Arrays") ),
                         ( "disks",           _("Physical Disks") ),
                     ],
                     default_value = [ "lshost", "lslicense", "lsmdisk", "lsmdiskgrp", "lsnode",
                                       "lsnodestats", "lssystem", "lssystemstats", "lsportfc",
                                       "lsenclosure", "lsenclosurestats", "lsarray", "disks" ],
                     allow_empty = False,
                   ),
                   title = _("Retrieve information about..."),
                )
             ),
        ],
        optional_keys = [ ],
    ),
    factory_default = FACTORY_DEFAULT_UNUSED, # No default, do not use setting if no rule matches
    match = 'first')


register_rule(group,
    "special_agents:random",
     FixedValue(
        {},
        title = _("Create random monitoring data"),
        help = _("By configuring this rule for a host - instead of the normal "
                 "Check_MK agent random monitoring data will be created."),
        totext = _("Create random monitoring data"),
    ),
    factory_default = FACTORY_DEFAULT_UNUSED, # No default, do not use setting if no rule matches
    match = 'first')

register_rule(group,
    "special_agents:acme_sbc",
     FixedValue(
        {},
        title = _("Check ACME Session Border Controller"),
        help = _("This rule activates an agent who connects "
                 "to an ACME Session Border Controller (SBC). This agent uses SSH, this "
                 "means that you have to exchange an SSH key to make a passwordless "
                 "connect possible"),
        totext = _("Connect to ACME SBC"),
    ),
    factory_default = FACTORY_DEFAULT_UNUSED, # No default, do not use setting if no rule matches
    match = 'first')

register_rule(group,
    "special_agents:fritzbox",
     Dictionary(
        title = _("Check state of Fritz!Box Devices"),
        help = _("This rule selects the Fritz!Box agent, which uses UPNP to gather information "
                 "about configuration and connection status information."),
        elements = [
            ( "timeout",
              Integer(
                  title = _("Connect Timeout"),
                  help = _("The network timeout in seconds when communicating via UPNP. "
                           "The default is 10 seconds. Please note that this "
                           "is not a total timeout, instead it is applied to each API call."),
                  default_value = 10,
                  minvalue = 1,
                  unit = _("seconds"),
              )
            ),
        ],
        optional_keys = [ "timeout" ],
    ),
    factory_default = FACTORY_DEFAULT_UNUSED, # No default, do not use setting if no rule matches
    match = 'first')


register_rulegroup("datasource_programs",
    _("Datasource Programs"),
    _("Specialized agents, e.g. check via SSH, ESX vSphere, SAP R/3"))

group = "datasource_programs"


register_rule(group,
    "special_agents:innovaphone",
    Tuple(
        title = _("Innovaphone Gateways"),
        help = _( "Please specify the user and password needed to access the xml interface"),
        elements = [
           TextAscii(title = _("Username")),
           Password( title = _("Password")),
        ]
    ),
    factory_default = FACTORY_DEFAULT_UNUSED,
    match = "first")

register_rule(group,
    "special_agents:hivemanager",
    Tuple(
        title = _("Aerohive HiveManager"),
        help = _( "Activate monitoring of host via a HTTP connect to the HiveManager"),
        elements = [
           TextAscii(title = _("Username")),
           Password( title = _("Password")),
        ]
    ),
    factory_default = FACTORY_DEFAULT_UNUSED,
    match = "first")

register_rule(group,
    "special_agents:allnet_ip_sensoric",
     Dictionary(
        title = _("Check state of ALLNET IP Sensoric Devices"),
        help = _("This rule selects the ALLNET IP Sensoric agent, which fetches "
                 "/xml/sensordata.xml from the device by HTTP and extracts the "
                 "needed monitoring information from this file."),
        elements = [
            ( "timeout",
              Integer(
                  title = _("Connect Timeout"),
                  help = _("The network timeout in seconds when communicating via HTTP. "
                           "The default is 10 seconds."),
                  default_value = 10,
                  minvalue = 1,
                  unit = _("seconds"),
              )
            ),
        ],
        optional_keys = [ "timeout" ],
    ),
    factory_default = FACTORY_DEFAULT_UNUSED, # No default, do not use setting if no rule matches
    match = 'first')


register_rule(group,
    "special_agents:ucs_bladecenter",
    Dictionary(
        elements = [
            ( "username",
              TextAscii(
                  title = _("Username"),
                  allow_empty = False,
              )
            ),
            ( "password",
              Password(
                  title = _("Password"),
                  allow_empty = False,
              )
            ),
        ],
        optional_keys = False
    ),
    title = _("Check state of UCS Bladecenter"),
    help = _("This rule selects the UCS Bladecenter agent instead of the normal Check_MK Agent "
             "which collects the data through the UCS Bladecenter Web API"),
    match = 'first')


def validate_siemens_plc_values(value, varprefix):
    valuetypes = {}
    for index, (db_number, address, datatype, valuetype, ident) in enumerate(value):
        valuetypes.setdefault(valuetype, [])
        if ident in valuetypes[valuetype]:
            raise MKUserError("%s_%d_%d" % (varprefix, index+1, 4),
                              _("The ident of a value needs to be unique per valuetype."))
        valuetypes[valuetype].append(ident)

_siemens_plc_value = [
    Transform(
        CascadingDropdown(
            title = _("The Area"),
            choices = [
                ("db", _("Datenbaustein"),
                    Integer(
                        title = "<nobr>%s</nobr>" % _("DB Number"),
                        minvalue = 1,
                    )
                ),
                ("input",   _("Input")),
                ("output",  _("Output")),
                ("merker",  _("Merker")),
                ("timer",   _("Timer")),
                ("counter", _("Counter")),
            ],
            orientation = "horizontal",
            sorted = True,
        ),
        # Transform old Integer() value spec to new cascading dropdown value
        forth = lambda x: type(x) == int and ("db", x) or x,
    ),
    Float(
        title = _("Address"),
        display_format = "%.1f",
        help = _("Addresses are specified with a dot notation, where number "
                 "before the dot specify the byte to fetch and the number after the "
                 "dot specifies the bit to fetch. The number of the bit is always "
                 "between 0 and 7."),
    ),
    CascadingDropdown(
        title = _("Datatype"),
        choices = [
            ("dint", _("Double Integer (DINT)")),
            ("real", _("Real Number (REAL)")),
            ("bit",  _("Single Bit (BOOL)")),
            ("str",  _("String (STR)"), Integer(
                minvalue = 1,
                title = _("Size"),
                unit = _("Bytes"),
            )),
            ("raw",  _("Raw Bytes (HEXSTR)"), Integer(
                minvalue = 1,
                title = _("Size"),
                unit = _("Bytes"),
            )),
        ],
        orientation = "horizontal",
        sorted = True,
    ),
    DropdownChoice(
        title = _("Type of the value"),
        choices = [
            (None,                    _("Unclassified")),
            ("temp",                  _("Temperature")),
            ("hours_operation",       _("Hours of operation")),
            ("hours_since_service",   _("Hours since service")),
            ("hours",                 _("Hours")),
            ("seconds_operation",     _("Seconds of operation")),
            ("seconds_since_service", _("Seconds since service")),
            ("seconds",               _("Seconds")),
            ("counter",               _("Increasing counter")),
            ("flag",                  _("State flag (on/off)")),
            ("text",                  _("Text")),
        ],
        sorted = True,
    ),
    ID(
        title = _("Ident of the value"),
        help = _(" An identifier of your choice. This identifier "
                 "is used by the Check_MK checks to access "
                 "and identify the single values. The identifier "
                 "needs to be unique within a group of VALUETYPES."),
    ),
]

group = "datasource_programs"
register_rule(group,
    "special_agents:siemens_plc",
    Dictionary(
        elements = [
            ("devices", ListOf(
                Dictionary(
                    elements = [
                        ('host_name', TextAscii(
                            title = _('Name of the PLC'),
                            allow_empty = False,
                            help = _('Specify the logical name, e.g. the hostname, of the PLC. This name '
                                     'is used to name the resulting services.')
                        )),
                        ('host_address', TextAscii(
                            title = _('Network Address'),
                            allow_empty = False,
                            help = _('Specify the hostname or IP address of the PLC to communicate with.')
                        )),
                        ("rack", Integer(
                            title = _("Number of the Rack"),
                            minvalue = 0,
                        )),
                        ("slot", Integer(
                            title = _("Number of the Slot"),
                            minvalue = 0,
                        )),
                        ("tcp_port", Integer(
                            title = _("TCP Port number"),
                            help = _("Port number for communicating with the PLC"),
                            default_value = 102,
                            minvalue = 1,
                            maxvalue = 65535,
                        )),
                        ("timeout", Integer(
                            title = _("Connect Timeout"),
                            help = _("The connect timeout in seconds when establishing a connection "
                                     "with the PLC."),
                            default_value = 60,
                            minvalue = 1,
                            unit = _("seconds"),
                        )),
                        ("values", ListOf(
                            Tuple(
                                elements = _siemens_plc_value,
                                orientation = "horizontal",
                            ),
                            title = _("Values to fetch from this device"),
                            validate = validate_siemens_plc_values,
                            magic = '@?@',
                        )),
                    ],
                    optional_keys = ["timeout"],
                ),
                title = _("Devices to fetch information from"),
            )),
            ("values", ListOf(
                Tuple(
                    elements = _siemens_plc_value,
                    orientation = "horizontal",
                ),
                title = _("Values to fetch from all devices"),
                validate = validate_siemens_plc_values,
            )),
        ],
        optional_keys = ["timeout"],
        title = _("Siemens PLC (SPS)"),
        help = _("This rule selects the Siemens PLC agent instead of the normal Check_MK Agent "
                 "and allows monitoring of Siemens PLC using the Snap7 API. You can configure "
                 "your connection settings and values to fetch here."),
    ),
    factory_default = FACTORY_DEFAULT_UNUSED, # No default, do not use setting if no rule matches
    match = 'first')

register_rule(group,
    "special_agents:ruckus_spot",
    Dictionary(
        elements = [
            ( "address",
              Alternative(
                  title = _("Server Address"),
                  help  = _("Here you can set a manual address if the server differs from the host"),
                  elements = [
                    FixedValue(True, title = _("Use host address"), totext = ""),
                    TextAscii(title = _("Enter address"))
                  ],
                  default_value = True
              )
            ),
            ( "port",
              Integer(
                  title = _("Port"),
                  allow_empty = False,
                  default_value = 8443
              )
            ),
            ( "venueid",
              TextAscii(
                  title = _("Venue ID"),
                  allow_empty = False,
              )
            ),
            ( "api_key",
              TextAscii(
                  title = _("API key"),
                  allow_empty = False,
                  size = 70
              )
            ),
        ],
        optional_keys = False
    ),
    title = _("Agent for Ruckus Spot"),
    help = _("This rule selects the Agent Ruckus Spot agent instead of the normal Check_MK Agent "
             "which collects the data through the Ruckus Spot web interface"),
    match = 'first')


group = 'datasource_programs'
register_rule(group,
    'special_agents:appdynamics',
    Dictionary(
        elements = [
            ( 'username',
              TextAscii(
                  title = _('AppDynamics login username'),
                  allow_empty = False,
              )
            ),
            ( 'password',
              Password(
                  title = _('AppDynamics login password'),
                  allow_empty = False,
              )
            ),
            ( 'application',
              TextAscii(
                  title = _('AppDynamics application name'),
                  help = _('This is the application name used in the URL. If you enter for example the application '
                           'name <tt>foobar</tt>, this would result in the URL being used to contact the REST API: '
                           '<tt>/controller/rest/applications/foobar/metric-data</tt>'),
                  allow_empty = False,
                  size = 40,
              )
            ),
            ( 'port',
              Integer(
                   title = _('TCP port number'),
                   help = _('Port number that AppDynamics is listening on. The default is 8090.'),
                   default_value = 8090,
                   minvalue = 1,
                   maxvalue = 65535,
              )
            ),
            ( 'timeout',
              Integer(
                  title = _('Connection timeout'),
                  help = _('The network timeout in seconds when communicating with AppDynamics.'
                           'The default is 30 seconds.'),
                  default_value = 30,
                  minvalue = 1,
                  unit = _('seconds'),
              )
            ),
        ],
        optional_keys = [ 'port', 'timeout' ],
    ),
    title = _('AppDynamics via REST API'),
    help = _('This rule allows querying an AppDynamics server for information about Java applications '
             'via the AppDynamics REST API. You can configure your connection settings here.'),
    factory_default = FACTORY_DEFAULT_UNUSED, # No default, do not use setting if no rule matches
    match = 'first')

mk_jolokia_elements = [
   ( "port",
     Integer(
         title = _("TCP port for connection"),
         default_value = 8080,
         minvalue = 1,
         maxvalue = 65535,
     )
   ),
   ( "login",
       Tuple(
           title = _("Optional login (if required)"),
           elements = [
             TextAscii(
                 title = _("User ID for web login (if login required)"),
                 default_value = "monitoring",
             ),
             Password(
                 title = _("Password for this user")
             ),
             DropdownChoice(
                 title = _("Login mode"),
                 choices = [
                    ( "basic",  _("HTTP Basic Authentication") ),
                    ( "digest", _("HTTP Digest") ),
                 ]
             )
           ]
       )
   ),
   ( "suburi",
     TextAscii(
         title = _("relative URI under which Jolokia is visible"),
         default_value = "jolokia",
         size = 30,
     )
   ),
   ( "instance",
     TextUnicode(
         title = _("Name of the instance in the monitoring"),
         help = _("If you do not specify a name here, then the TCP port number "
                  "will be used as an instance name.")
     ),
   ),
]

group = 'datasource_programs'
register_rule(group,
    'special_agents:jolokia',
    Dictionary(
        elements = mk_jolokia_elements,
    ),
    title = _('Jolokia'),
    help = _('This rule allows querying the Jolokia web API.'),
    factory_default = FACTORY_DEFAULT_UNUSED, # No default, do not use setting if no rule matches
    match = 'first')

register_rule(group,
    "special_agents:tinkerforge",
    Dictionary(
        title = _("Settings for Tinkerforge agent"),
        elements = [
            ( "port",
            Integer(
                title = _('TCP port number'),
                help = _('Port number that AppDynamics is listening on. The default is 8090.'),
                default_value = 4223,
                minvalue = 1,
                maxvalue = 65535
            )
            ),
            ( "segment_display_uid",
            TextAscii(
                title = _("7-segment display uid"),
            )
            ),
            ( "segment_display_brightness",
            Integer(
                title = _("7-segment display brightness"),
                minvalue = 0,
                maxvalue = 7
            )
            )
        ],
    ),
    title = _("Tinkerforge"),
    match = 'first')