Search code examples
pythonarraysapipython-3.xzabbix

Python Zabbix API trigger get with array


According to Zabbix API documentation the parameter 'search' "Accepts an array, where the keys are property names, and the values are strings to search for. "

So what I'm trying to do in the code below is search for text fields that contain the word "Access" or "XSD".

for h in HostID:
    gatilho = zapi.trigger.get(
        host='apacheserver01',
        expandDescription = 'true',
        output='extend',
        search={'description':['Access','XSD']},
)

Somebody can help me to do that.


Solution

  • In Zabbix API the parameter search={'description':['Access','XSD']}, will search for 'Access' and 'XSD' in the same description field.

    So the result will be: description: 'Access to XSD failed'

    But what I want is a "OR":

    description: 'Access to XSD failed'

    description: 'XSD log ERROR'

    description: 'Acces to system XPTO failed'

    To do that another parameter is needed: searchByAny='true', this tell to search for any word in search parameter.

    for h in HostID:
        gatilho = zapi.trigger.get(
            host='apacheserver01',
            expandDescription = 'true',
            output='extend',
            searchByAny='true'
            search={'description':['Access','XSD']},
    )