public async Task OnAsync(Event<LogEventData> evt) { if (evt == null) throw new ArgumentNullException(nameof(evt)); var message = _generateMessage.Render(evt); var description = _generateDescription.Render(evt); var priority = ComputePriority(evt); var tags = ComputeTags(evt); var responders = ComputeResponders(evt); var alert = new OpsgenieAlert( message, evt.Id, description, priority.ToString(), responders, Host.BaseUri, tags); var log = Log.ForContext("Notification", Guid.NewGuid().ToString("n")); try { // Log our intent to alert OpsGenie with details that could be re-fired to another app if needed log.ForContext("Alert", alert, true) .Debug("Sending alert to OpsGenie API"); var result = await ApiClient.CreateAsync(alert); //Log the result with details that could be re-fired to another app if needed log.Debug("OpsGenie API responded {Result}/{Reason}", result.StatusCode, result.ReasonPhrase); } catch (Exception ex) { //Log an error which could be fired to another app (eg. alert via email of an OpsGenie alert failure, or raise a Jira) and include details of the alert log .ForContext("Alert", alert, true) .Error(ex, "OpsGenie alert creation failed"); } }
public async Task OnAsync(Event <LogEventData> evt) { if (evt == null) { throw new ArgumentNullException(nameof(evt)); } var suppressDiff = DateTime.UtcNow - _lastAlert; if (suppressDiff.TotalSeconds < _suppressionTime.TotalSeconds) { return; } var message = _generateMessage.Render(evt); var description = _generateDescription.Render(evt); var priority = ComputePriority(evt); var tags = ComputeTags(evt); var responders = ComputeResponders(evt); var notification = Guid.NewGuid().ToString("n"); var alert = new OpsgenieAlert( message, evt.Id, description, priority.ToString(), responders, new Dictionary <string, string> { { "Seq Host Name", Host.InstanceName }, { "Seq Host URL", Host.BaseUri }, { "Seq App Instance", App.Title }, { "Seq App Instance Id", App.Id }, { "Seq ID", evt.Id }, { "Seq URL", !string.IsNullOrEmpty(evt.Id) && !string.IsNullOrEmpty(Host.BaseUri) ? string.Concat(Host.BaseUri, "#/events?filter=@Id%20%3D%20'", evt.Id, "'&show=expanded") : "" }, { "Seq Timestamp UTC", evt.TimestampUtc.ToString("O") }, { "Seq Event Type", evt.EventType.ToString() }, { "Seq Notification Id", notification } }, Host.BaseUri, tags); var log = Log.ForContext("Notification", notification); var result = new OpsGenieResult(); try { // Log our intent to alert OpsGenie with details that could be re-fired to another app if needed log.ForContext("Alert", alert, destructureObjects: true) .Debug("Sending alert to OpsGenie API"); result = await ApiClient.CreateAsync(alert); //Log the result with details that could be re-fired to another app if needed log .ForContext("Alert", alert, destructureObjects: true) .ForContext("Result", result, destructureObjects: true) .Debug("OpsGenie API responded with {Response}: {ResultCode}/{Reason}", result.Response.Result, result.HttpResponse.StatusCode, result.HttpResponse.ReasonPhrase); _lastAlert = DateTime.UtcNow; } catch (Exception ex) { //Log an error which could be fired to another app (eg. alert via email of an OpsGenie alert failure, or raise a Jira) and include details of the alert log .ForContext("Alert", alert, destructureObjects: true) .ForContext("Result", result, destructureObjects: true) .Error(ex, "OpsGenie alert creation failed"); } }