jebbett / zabbix-wled

Zabbix Media Type to trigger basic alerts to WLED
3 stars 1 forks source link

Zabbix 7.0 compatible #1

Closed circool closed 7 hours ago

circool commented 7 hours ago
try {
  var params = JSON.parse(value);

  switch (params.event_severity) {
    case 'Not classified':
      colour = eval('[' + params.ColourNotClassified + ']');
      break;
    case 'Information':
      colour = eval('[' + params.ColourInformation + ']');
      break;
    case 'Warning':
      colour = eval('[' + params.ColourWarning + ']');
      break;
    case 'Average':
      colour = eval('[' + params.ColourAverage + ']');
      break;
    case 'High':
      colour = eval('[' + params.ColourHigh + ']');
      break;
    case 'Disaster':
      colour = eval('[' + params.ColourDisaster + ']');
      break;
  }

  var defcol = eval('[' + params.DefaultColour + ']');
  var ranges = eval('[' + params.LEDRanges + ']');
  var hosts = eval('[' + params.HostsList + ']');

  hosts.forEach(function (value, i) {
    if (value == params.host_name) {
      if (params.event_value == 0) { setColour = defcol; } else { setColour = colour; }

      wstart = ranges[i][0] - 1;
      wend = ranges[i][1];

      var wledparams = {
        "seg": {
          "i": [wstart, wend, setColour]
        }
      },
        data,
        response,
        request = new HttpRequest(),
        url = 'http://' + params.IPAddress + '/json/state/';

      request.addHeader('Content-Type: application/json');
      data = JSON.stringify(wledparams);

      // Log file.
      Zabbix.Log(4, '[WLED Webhook] params: ' + data);
      response = request.post(url, data);
      Zabbix.Log(4, '[WLED Webhook] HTTP code: ' + request.getStatus());
    }
  });
  return 'OK';
} catch (error) {
  Zabbix.Log(4, '[WLED Webhook] notification failed: ' + error);
  throw 'Sending failed: ' + error + '.';
}
jebbett commented 7 hours ago

Thanks, I'm surprised anyone is using this, however split to V5 and V7 versions!