Ad Widget

Collapse

Zabbix Monitor Traefik Services API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fpires
    Junior Member
    • Aug 2021
    • 1

    #1

    Zabbix Monitor Traefik Services API

    Hi! I'm trying to monitor Traefik HTTP Services using it's API ( https://doc.traefik.io/traefik/operations/api/). Accessing "http://traefik-host:8080/api/http/services/API-NAME" I receive the following JSON:
    Code:
    {
    "loadBalancer": {
    "servers": [
    {
    "url": "http://10.0.1.102:8080"
    },
    {
    "url": "http://10.0.1.104:8080"
    }
    ],
    "passHostHeader": true
    },
    "status": "enabled",
    "usedBy": [
    "API-NAME"
    ],
    "serverStatus": {
    "http://10.0.1.102:8080": "UP",
    "http://10.0.1.104:8080": "UP"
    },
    "name": "API-NAME",
    "provider": "docker",
    "type": "loadbalancer"
    }
    ​
    My idea is:
    1. Create a HTTP Agent Item to grab this JSON (done)
    2. Create a "Dependent Item" (pointing to previous item) to get the size of "servers" array (JSONPath -> $.loadBalancer.servers.length() ) (done)
    3. Create another "Dependent Item" (also from the first one), filtering by all attributes on "serverStatus" with "UP" value (and get its count), so I can create a trigger when the value of Item 3 is lower than of Item 2.
    What I have tried so far:
    1. $.serverStatus
    2. .length() - brings the total of lines, but no filtering at all.
    3. $.serverStatus[?(
    4. == 'UP')].length()
    5. $.serverStatus[?($.serverStatus
    6. == 'UP')].length()
    7. many other combinations
    Mostly, my error is something around this:
    Code:
    cannot extract value from json by path "$.serverStatus[?([*] == 'UP')]": unsupported construct in jsonpath starting with: "[*] == 'UP')]"
    Any hints? What I'm trying is possible with JSONPath?
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    I doubt jsonpath allows you to do "give me count of objects which value is "UP"". It allows you to do "give me count of objects named "X" which value is "UP""

    So I guess you may be better off to do a discovery... get all of those servers ({#URL} -> $.loadBalancer.servers.url) and create dependent items for serverstatuses ($.serverStatus["{#URL}"]) and then do that counting of "UP"-s in Zabbix...

    Comment

    Working...