'inventory_function': discover()

Hallo,

ich schau mir gerade existierende Checks als Basis für eigene an und bin dabei immer wieder über diese Definition gestolpert:
'inventory_function': discover(),

Nachdem discover() im Check nicht definiert ist, würde mich interessieren woher diese Funktion kommt und was genau sie macht?

Ich konnte dazu weder in der Doku noch via Google auch nur den kleinsten Hinweis dazu finden.
Vielleicht kann mich ja hier wer dazu “erleuchten”. :grin:

LG
Mario

Hi Mario.

Welchen Check hast du dir denn angesehen? Sieht nach alten checks aus. Vielleicht kannst du mal ein wenig mehr Licht ins dunkele bringen.

VG, Christian

Also wenn ich auf meiner 2.0.0p33 Installation schaue gibt’s da ca. 100 Checks die das so Implementiert haben.
Ein Beispiel wäre mssql_tablespaces…

check_info['mssql_tablespaces'] = {
    'parse_function': parse_mssql_tablespaces,
    'inventory_function': discover(),
    'check_function': check_mssql_tablespaces,
    'service_description': 'MSSQL %s Sizes',
    'group': 'mssql_tablespaces',
    'has_perfdata': True,
    'default_levels_variable': 'mssql_tablespace_default_levels',
}

Hi.

Die Funktion discover() kann zur Serviceerkennung von Key/Value Paaren verwendet werden. Hier der Text aus dem Code:

Helper function to assist with service discoveries

    The discovery function is in many cases just a boilerplate function to
    recognize services listed in your parsed dictionary or the info
    list. It in general looks like

        def inventory_check(parsed):
            for key, value in parsed.items():
                if some_condition_based_on(key, value):
                    yield key, parameters


    The idea of this helper is to allow you only to worry about the logic
    function that decides if an entry is a service to be discovered or not.


    Keyword Arguments:
    selector       -- Filtering function (default lambda entry: entry[0])
        Default: Uses the key or first item of info variable
    default_params -- Default parameters for discovered items (default {})

    Possible uses:

        If your discovery function recognizes every entry of your parsed
        dictionary or every row of the info list as a service, then you
        just need to call discover().

            check_info["chk"] = {'inventory_function': discover()}

        In case you want to have a simple filter function when dealing with
        the info list, you can directly give a lambda function. If this
        function returns a Boolean the first item of every entry is taken
        as the service name, if the function returns a string that will be
        taken as the service name. For this example we discover as services
        entries where item3 is positive and name the service according to
        item2.

            check_info["chk"] = {'inventory_function': discover(selector=lambda line: line[2] if line[3]>0 else False)}

        In case you have a more complicated selector condition and also
        want to include default parameters you may use a decorator.

        Please note: that this discovery function does not work with the
        whole parsed/info data but only implements the logic for selecting
        each individual entry as a service.

        In the next example, we will process each entry of the parsed data
        dictionary. Use as service name the capitalized key when the
        corresponding value has certain keywords.

            @discover(default_params="the_check_default_levels")
            def inventory_thecheck(key, value):
                required_entries = ["used", "ready", "total", "uptime"]
                if all(data in value for data in required_entries):
                    return key.upper()

            check_info["chk"] = {'inventory_function': inventory_thecheck}

Ich hoffe das hilft dir weiter.

VG, Christian

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.