Check MK – Check Parameters Form Fields

No guarantee that I understood everything correctly. This site is not finished at all ;o)

In general

you set some default values in your check that should be used if no configuration via WATO was created for a service. For example there could be something like the following line nearly at the start of a check-script:

factory_settings["some_check_default_values"] = {
    'ignore_warnings':  False,
}

The corresponding check_parameters-file would be set up like this:

register_check_parameters(
    subgroup_applications,
    "some_check",
    _("Check something"),
    Dictionary(
        elements = [
             ( "ignore_warnings",
                 DropdownChoice(
                     title = _("Ignore warnings if something was not found"),
                     help = _('default is No'),
                     choices = [
                         ( False,  _("No") ),
                         ( True, _("Yes") ),
                     ],
                     default_value = "no",
                 )
             )
        ]
    ),
    None,
    "dict",
)

So this will tell Check_MK that the params-variable (that will be supplied to the defined check-function) will be a dictionary with one key called ignore_warnings with the value True or False. The default value will be “no” which corresponds to False.

This code will be transformed to a nice WATO service configuration web-page containing a checkbox. If activated a dropdown with the two options “No” and “Yes” will be shown.

Very nice. But what else can be configured? As nothing about this question is documented by Check_MK I searched and found the file ~/share/check_mk/web/htdocs/valuespec.py

I also had a look at ~/share/check_mk/web/plugins/wato/check_parameters.py where I searched for some usecases.

The class ValueSpec

First of all this one seems to define some “standard” elements you can define for each “Field” you use. Most used standard elements are for example:

  • _title
  • _help
  • default_value

“Wrappers”

I call them “Wrappers” because you “wrap” those checkboxes, password-fields, etc. into them to be useable. I found and already used some of them:

  • ListOfStrings(ValueSpec)
    ListOfStrings(
                  title = _("A List of some strings"),
                  help  = _("A List of strings"),
                  orientation = "horizontal"
                  )

    Initially shows one textfield, if clicked another field is added.

    • Usage example in rule: “Discovery of IPMI sensors”
  • ListOfIntegers(ListOfStrings) should be similar to ListOfStrings
    • Usage example in rule: none
  • ListOf(ValueSpec)
    ListOf(
           Tuple(
                 elements = [
                             TextAscii(title = _("AP name")),
                             MonitoringState(
                                             title=_("State when missing"),
                                             default_value = 2
                                             )
                             ]
                 ),
                 title = _("Access point name"),
                 add_label = _("Add name")
           )

    Combined mostly with “Tuple”. Initially will show an “Add …”-button. If clicked new defined fields will show up.

    • Usage example in rule: “Cisco WLAN AP”
  • ListOfMultiple(ValueSpec)
    • Usage example in rule: none
  • Transform(ValueSpec)
    Transform(
              Dictionary(
                         elements = [
                                     ( "deferred",
                                      Tuple(
                                            title = _("Some shortened title"),
                                            help = _("Some shortened help"),
                                            elements = [
                                                        Integer(title = _("Warning at"),
                                                                unit = _("bananas"),
                                                                default_value = 10
                                                                ),
                                                        Integer(title = _("Critical at"),
                                                                unit = _("bananas"),
                                                                default_value = 20
                                                                ),
                                                       ],
                                            ),
                                      ),
                                      ( "active",
                                       Tuple(
                                             title = _("Some other shorter title"),
                                             help = _("Some other shorter help"),
                                             elements = [
                                                         Integer(title = _("Warning at"),
                                                                 unit = _("bananas"),
                                                                 default_value = 800
                                                                 ),
                                                         Integer(title = _("Critical at"),
                                                                 unit = _("bananas"),
                                                                 default_value = 1000
                                                                 ),
                                                        ],
                                             ),
                                       ),
                                     ],
                         optional_keys = [ "active" ],
              ),
              forth = lambda old: type(old) != dict and { "deferred" : old } or old,
              ),

    Somehow can “transform” the values from one presentation into another. The comments in valuespec.py say:

    Transforms the value from one representation to
    another while being completely transparent to the user.
    forth: function that converts a value into the representation
           needed by the encapsulated vs
    back:  function that converts a value created by the encapsulated
           vs back to the outer representation
    • Usage example in rule: “Number of mails in outgoing mail queue”
  • Tuple
    • Usage example in rule: “Number of mails in outgoing mail queue”
  • Dictionary
    • Usage example in rule: “Number of mails in outgoing mail queue”
  • Optional
    • Usage example in rule: “Ruckus Access Points”
  • Alternative
    • Usage example in rule: “Volume Groups (LVM)”

Form Fields

With Usage Examples

  • FixedValue(ValueSpec)
    FixedValue(
               False,
               title = _("Always OK"),
               totext = _("Service will always be OK"),
               )

    For example if used in a dropdown the selection will have the text “Always OK” and next to this dropdown the totext will be shown.

    • Usage example in rule: “Number of used VMware licenses”
  • Age(ValueSpec)
    Age(
        title=_("Warning at"),
        default_value = 86400
        )

    Will create a line where you can type in days, hours, minutes and seconds. There are some optional parameters like display (with this you can define for example that only hours and minutes field should be shown.

    • Usage example in rule: “McAfee Anti-Virus Time Settings” or “State of NTP time synchronisation”
  • Integer(ValueSpec)
    Integer( 
            title = _(u"Warning at"),
            default_value = 100000
            )

    Creates a text-field where only integers may be typed in. Possible additional interesting options size (defines text-field size), minvalue, maxvalue, unit, label

    • Usage example in rule: “Fortigate Active Sessions”
  • Filesize(Integer)
    Filesize(
             title = _("Warning if below")
             )

    Shows a text-field for integers and a dropdown where you can select the unit Byte, KByte,…

    • Usage example in rule: “Size and age of single files”
  • TextAscii(ValueSpec)
    TextAscii(
              title = _("Some title"),
              help = _("Some help to this text-field)."),
              )

    Creates a simple text-field. Interesting optional options are size, allow_empty, label

    • Usage example in rule: “Active Directory Replication”
  • TextUnicode(TextAscii)
    seems to be similar to TextAscii but just in Unicode
    • Usage example in rule: “VPN Tunnel”
  • RegExp(TextAscii)
    RegExp(
           size = 50
           )

    Shows a text-field where regex can be used as far as I understood

    • Usage example in rule: “Process Discovery”
  • RegExpUnicode(TextUnicode, RegExp)
    RegExpUnicode(
                  title = _("Include Pattern")
                  )

    Similar to RegExp

    • Usage example in rule: “SAP Value Grouping Patterns”
  • IPv4Address
    • Usage example in rule: “VPN Tunnel”
  • Float
    • Usage example in rule: “Output Voltage of Power Supplies”
  • Percentage
    • Usage example in rule: “OpenHardwareMonitor S.M.A.R.T.”
  • Checkbox
    • Usage example in rule: “Discovery of Windows DHCP Pools”
  • DropdownChoice
    • Usage example in rule: “eWON Discovery”
  • MonitoringState
    • Usage example in rule: “State of Citrix VMs”
  • CascadingDropdown
    • Usage example in rule: “Main memory usage of simple devices”
  • RadioChoice
    • Usage example in rule: “Cisco quality of service”
  • ListChoice
    • Usage example in rule: “Allowed Network states on Bosch IP Cameras”
  • DualListChoice
    • Usage example in rule: “Network Interface and Switch Port Discovery”
  • OptionalDropdownChoice
    • Usage example in rule: “Fibrechannel Interfaces”
  • TimeofdayRanges
    • Usage example in rule: “Motion Detectors”

Without Usage Examples

  • ID(TextAscii)
    • Usage example in rule: none
  • UnicodeID(TextAscii)
    • Usage example in rule: none
  • UserID(TextAscii)
    • Usage example in rule: none
  • EmailAddress
    • Usage example in rule: none
  • EmailAddressUnicode
    • Usage example in rule: none
  • IPv4Network
    • Usage example in rule: none
  • Hostname
    • Usage example in rule: none
  • AbsoluteDirname
    • Usage example in rule: none
  • HTTPUrl
    • Usage example in rule: none
  • TextAreaUnicode
    • Usage example in rule: none
  • Filename
    • Usage example in rule: none
  • MultiSelect
    • Usage example in rule: none
  • Weekday
    • Usage example in rule: none
  • RelativeDate
    • Usage example in rule: none
  • AbsoluteDate
    • Usage example in rule: none
  • Timeofday
    • Usage example in rule: none
  • TimeofdayRange
    • Usage example in rule: none
  • TimeHelper
    • Usage example in rule: none
  • Timerange
    • Usage example in rule: none
  • OptionalEdit
    • Usage example in rule: none
  • ElementSelection
    • Usage example in rule: none
  • AutoTimestamp
    • Usage example in rule: none
  • Foldable
    • Usage example in rule: none
  • LDAPDistinguishedName
    • Usage example in rule: none
  • Password
    • Usage example in rule: none
  • PasswordSpec
    • Usage example in rule: none
  • FileUpload
    • Usage example in rule: none
  • UploadOrPasteTextFile
    • Usage example in rule: none
  • IconSelector
    • Usage example in rule: none
  • Color
    • Usage example in rule: none

Kommentar verfassen

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.