Skip to content

Instantly share code, notes, and snippets.

@isaqueprofeta
Last active July 6, 2022 23:42
Show Gist options
  • Select an option

  • Save isaqueprofeta/be0de6b37d3b7c12b225c93af88b5508 to your computer and use it in GitHub Desktop.

Select an option

Save isaqueprofeta/be0de6b37d3b7c12b225c93af88b5508 to your computer and use it in GitHub Desktop.

Revisions

  1. isaqueprofeta renamed this gist Jul 6, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. isaqueprofeta created this gist Jul 6, 2022.
    9 changes: 9 additions & 0 deletions CONTEXT.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    - Where?
    https://t.me/ZabbixTech

    - Question:
    Hi team...is there any query where we can get the count of alarms raised per day?

    - Answer:
    Since version 6.0 you can create an API key and then do an JavaScript Script Item to check the information from Zabbix API using time_from and time_till parameters to filter the day before.
    Didn't tested, just prototyped the idea below, and before trying the code, remember to add the "url" and "apikey" to the item Parameters, (and please use a macro with vault for your apikey), in this case I'd configure the item interval as an scheduled one to run everyday at 1 or 2 AM:
    43 changes: 43 additions & 0 deletions alertsOfDayBefore.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@

    try {
    var parameters = JSON.parse(value);
    var req = new CurlHttpRequest();

    var yesterdayStart = new Date();
    yesterdayStart.setHours(0, 0, 0);
    var start = yesterdayStart.setDate(yesterdayStart.getDate() - 1);

    var yesterdayEnd = new Date();
    yesterdayEnd.setHours(23, 59, 59);
    var end = yesterdayEnd.setDate(yesterdayEnd.getDate() - 1);

    var jsonZabbix = {
    "jsonrpc": "2.0",
    "method": "event.get",
    "params": {
    "countOutput": true,
    "time_from": start,
    "time_till": end,
    },
    "auth": parameters.apikey,
    "id": 1
    };

    req.AddHeader('Content-Type: application/json');

    resp = req.Post(
    parameters.url,
    JSON.stringify(jsonZabbix)
    );

    if (resp.Status() != 200) {
    throw 'Response code: '+resp.Status();
    }

    var results = JSON.parse(resp);
    return(JSON.stringify(results));

    } catch (error) {
    Zabbix.Log(3, "Error 'warning': "+error);
    return "";
    }