ZabbixStatus mapZabbixStatus(event_struct events) { Int32 triggerId = events.triggerid; bool recovered = events.recovered; Int32 eventId = events.eventid; string description = string.Empty; UInt16 priority = 0; _logger.LogDebug($" TriggerId: {triggerId} recovered: {recovered}"); // find it in triggers for (int i = 0; i < TRIGGER_CACHE_SIZE; i++) { if (_triggers[i].triggerid == triggerId) { priority = _triggers[i].priority; description = _triggers[i].description; _logger.LogDebug("Found trigger!"); break; } } if (priority == 0) { // cache triggers var body = String.Format(@"{{ ""jsonrpc"": ""2.0"", ""method"": ""trigger.get"", ""params"": {{ ""output"":[""triggerid"",""priority"",""description""], ""triggerids"":{0} }}, ""id"": 2, ""auth"": ""{1}"" }}" , triggerId, _zabbixSessionId); _logger.LogDebug(body); var wc = new WebClient(); wc.Headers.Add(HttpRequestHeader.ContentType, "application/json"); var output = wc.UploadString(_zabbixUrl, body); if (!String.IsNullOrEmpty(output)) { dynamic root = JsonConvert.DeserializeObject(output); if (root != null) { _logger.LogInformation($"Trigger OK\nLength of triggers is {root.result.Count}"); for (int i = 0; i < root.result.Count; i++) { Int32 id = Int32.Parse(root.result[i].triggerid.ToString()); // already have it? int j; for (j = 0; j < TRIGGER_CACHE_SIZE && _triggers[j].triggerid != 0; j++) { if (_triggers[j].triggerid == id) { _logger.LogDebug($"Already have trigger id {id}"); priority = _triggers[j].priority; description = _triggers[j].description; break; } } if (_triggers[j].triggerid == 0) { _logger.LogDebug($"Added trigger {j} id of {id}"); _triggers[j].triggerid = id; _triggers[j].priority = (root.result[i].priority); _triggers[j].description = (root.result[i].description); if (id == triggerId) { _logger.LogDebug("Matched newly added one"); priority = _triggers[j].priority; description = _triggers[j].description; } } } } else { _logger.LogWarning($"Trigger failed: {output}"); } } } var ret = new ZabbixStatus(recovered ? (UInt16)0 : priority, description, String.Format(_zabbixLinkUrl, triggerId, eventId)); return(ret); }
public (IEnumerable <ContinuumStatus.PipelineStatus> ContinuumStatus, IEnumerable <UInt16> ZabbixStatus) StatusOnly(int count = 12) { (DateTime lastUpdate, IEnumerable <ContinuumStatus> ContinuumStatus, IEnumerable <ZabbixStatus> ZabbixStatus) = GetStatus(count); return(ContinuumStatus.Select(o => o.Status), ZabbixStatus.Select(o => o.Priority)); }