Ad Widget

Collapse

Problems with LLD discovery using HTTP agent items

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • slarm
    Junior Member
    • Feb 2020
    • 13

    #1

    Problems with LLD discovery using HTTP agent items

    Hi all.

    I have an issue creating LLD discovery using HTTP agent item as a prototype.

    Short background:

    The idea is to create items based on panels in a Grafana dashboard using the Grafana HTTP API. My logic looks as follows:
    1. Use the Grafana alerting HTTP API to get all panels on a dashboard with configured alerts.
    2. Store the returned names and alert ids in LLD macros.
    3. Create items using panel name as item name and alert id as a part of the HTTP agent URL.

    (If anyone is interested in the Grafana API: https://grafana.com/docs/grafana/lat..._api/alerting/)


    To break it down with pictures, here's what the discovery rule looks like:
    Click image for larger version  Name:	2020-02-26 09_41_19-Zabbix_ Configuration of discovery rules.png Views:	0 Size:	37.3 KB ID:	396360
    with the LLD macros:
    Click image for larger version  Name:	2020-02-26 09_44_00-Zabbix_ Configuration of discovery rules.png Views:	0 Size:	11.0 KB ID:	396367

    And the item prototype:
    Click image for larger version

Name:	2020-02-26 11_04_36-Zabbix_ Configuration of item prototypes.png
Views:	3327
Size:	46.2 KB
ID:	396374
    with the following preprocessing steps:

    Click image for larger version  Name:	2020-02-26 09_49_00-Zabbix_ Configuration of item prototypes.png Views:	0 Size:	22.8 KB ID:	396363

    Step 1 works as it should. Or at least it seems like it. The returned JSON looks as such:
    [
    {
    "dashboardId": 74,
    "dashboardSlug": "dashboard-zabbix",
    "dashboardUid": "XXXXXXXX",
    "evalData": {},
    "evalDate": "0001-01-01T00:00:00Z",
    "executionError": "",
    "id": 39,
    "name": "alert name",
    "newStateDate": "2020-02-25T14:11:37+01:00",
    "panelId": 2,
    "state": "ok",
    "url": "/d/XXXXXXXX/dashboard-zabbix"
    }

    ]
    (I've masked some stuff here, obviously).

    And if I add a javascript preprocessing step with the following code
    Zabbix.Log(3, "Grafana response: " + value);
    return value;
    It shows up in the Zabbix Proxy log.

    The HTTP request in the item should get a response that looks as follows:

    {
    "Id": 39,
    "Version": 0,
    "OrgId": 1,
    "DashboardId": 74,
    "PanelId": 2,
    "Name": "alert name",
    "Message": "",
    "Severity": "",
    "State": "ok",
    "Handler": 1,
    "Silenced": false,
    "ExecutionError": " ",
    "Frequency": 900,
    "For": 900000000000,
    "EvalData": {},
    "NewStateDate": "2020-02-25T14:11:37+01:00",
    "StateChanges": 3,
    "Created": "2020-02-04T15:57:33+01:00",
    "Updated": "2020-02-25T13:57:48+01:00",
    "Settings": {
    "conditions": [
    {
    "evaluator": {
    "params": [
    400
    ],
    "type": "lt"
    },
    "operator": {
    "type": "and"
    },
    "query": {
    "datasourceId": 11,
    "model": {
    "bucketAggs": [
    {
    "field": "@timestamp",
    "id": "2",
    "settings": {
    "interval": "auto",
    "min_doc_count": 0,
    "trimEdges": 0
    },
    "type": "date_histogram"
    }
    ],
    "metrics": [
    {
    "field": "select field",
    "id": "1",
    "type": "count"
    }
    ],
    "query": "REDACTED",
    "refId": "A",
    "timeField": "@timestamp"
    },
    "params": [
    "A",
    "5m",
    "now-1m"
    ]
    },
    "reducer": {
    "params": [],
    "type": "count"
    },
    "type": "query"
    }
    ],
    "executionErrorState": "alerting",
    "for": "15m",
    "frequency": "15m",
    "handler": 1,
    "name": "alert name",
    "noDataState": "alerting",
    "notifications": []
    }
    }
    However, the item doesn't show up. If I add a similar preprocessing step with Zabbix.Log, I don't see anything in the log. I'm assuming it should be the proxy log here as well, but the documentation only states: "Writes <message> into Zabbix log using <loglevel> log level (see configuration file DebugLevel parameter)", and when using the test functionality it logs in the Zabbix Server log. (https://www.zabbix.com/documentation...script_objects)


    Does anyone have any idea of what's going on? Debugging of the proxy doesn't give me much either.




    Attached Files
    Last edited by slarm; 26-02-2020, 13:13.
  • slarm
    Junior Member
    • Feb 2020
    • 13

    #2
    Some updates:

    I fixed a type on the item key (missing curly bracket on the macro name).

    Also, creating the trigger manually works, so I'm assuming that it has to do with the LLD macro substitution part.

    Comment

    • slarm
      Junior Member
      • Feb 2020
      • 13

      #3
      Another update:
      Discovery rule now creates data JSON with the following code (based on https://blog.zabbix.com/monitoring-d...contents/6671/)
      value = value.slice(1,-1)
      var panels = value.split(",")
      var output = []
      var len = panels.length

      for (i = 0; i < len-1; i+=2)
      {
      var row = {}
      row["{#GRAID}"] = panels[i]
      row["{#GRPANEL}"] = panels[i+1].replace(/"/g,"")
      output.push(row)
      }

      output = JSON.stringify(output)
      Zabbix.Log(3, "Grafana alerts: " + output)
      return output
      Item prototype has been changed accordingly:
      Click image for larger version

Name:	new.png
Views:	3038
Size:	31.0 KB
ID:	396603
      And zabbix proxy logs:
      [{"{#GRAID}":"39","{#GRPANEL}":"panel name"}]

      Still no item created.

      Doing a tcpdump I only see the first call by the discovery rule, but nothing related to the items.

      Comment

      Working...