/// <summary>Generates the incident object</summary> /// <returns>resulting value</returns> private AlertSourceIncident GetIncidentToSend(IcmIncident incident) { DateTime now = incident.IncidentTime ?? DateTime.UtcNow; var description = $"{incident.Description}" + (incident.Machines is null ? string.Empty : $"\n\nMachines: {string.Join(", ", incident.Machines!)}\n") + (incident.CorrelationIds is null ? string.Empty : $"\n\nCorrelation IDs: {string.Join(", ", incident.CorrelationIds!)}"); return(new AlertSourceIncident { Source = new AlertSourceInfo { CreatedBy = "*****@*****.**", Origin = "Monitor", CreateDate = now, ModifiedDate = now, IncidentId = Guid.NewGuid().ToString("N"), }, RoutingId = "CloudBuild/DRI/Cache", OwningTeamId = "DRI - CloudBuild - Cache", OccurringLocation = new IncidentLocation { DataCenter = incident.Stamp, DeviceName = incident.Machines?.FirstOrDefault() ?? "Cache Monitor", Environment = incident.Environment, }, RaisingLocation = new IncidentLocation { DeviceName = "CacheMonitor", }, Severity = incident.Severity, Status = IncidentStatus.Active, DescriptionEntries = new[] { new DescriptionEntry { Cause = DescriptionEntryCause.Created, Date = now, ChangedBy = "Cache Monitor", SubmitDate = now, SubmittedBy = "Cache Monitor", RenderType = DescriptionTextRenderType.Plaintext, Text = description, } }, Title = incident.Title, }); }
public async Task EmitIncidentAsync(IcmIncident incident) { var cert = await _keyVault.GetCertificateAsync(_connectorCertificateName); var incidentToSend = GetIncidentToSend(incident); using var client = ConnectorClientFactory.CreateClient(_uri, cert); try { var result = client.AddOrUpdateIncident2(_connectorId, incidentToSend, RoutingOptions.None); if (result.Status != IncidentAddUpdateStatus.AddedNew) { throw new Exception($"Result status does not indicate success: {result.Status}."); } } catch (Exception e) { Console.WriteLine("Failed to submit incident to IcM:\n" + e.ToString()); throw; } }
public async Task EmitIncidentAsync(IcmIncident incident) { if (incident.CacheTimeToLive is not null) { if (_cachedIcms.Contains(incident.Title)) { // Update TTL and return. _cachedIcms.Add(incident.Title, incident.CacheTimeToLive.Value); return; } else { // Add to cached incidents. _cachedIcms.Add(incident.Title, incident.CacheTimeToLive.Value); } } var cert = await _keyVault.GetCertificateAsync(_connectorCertificateName); var incidentToSend = GetIncidentToSend(incident); using var client = ConnectorClientFactory.CreateClient(_uri, cert); try { var result = client.AddOrUpdateIncident2(_connectorId, incidentToSend, RoutingOptions.None); if (result.Status != IncidentAddUpdateStatus.AddedNew && // Discarded means that we're updating hit count or it was suppressed because it's too soon // since we updated hit count last and the incident is still active. result.Status != IncidentAddUpdateStatus.Discarded) { throw new Exception($"Result status does not indicate success: {result.Status}."); } } catch (Exception e) { Console.WriteLine("Failed to submit incident to IcM:\n" + e.ToString()); throw; } }
public Task EmitIncidentAsync(IcmIncident incident) { Incidents.Add(incident); return(Task.CompletedTask); }