public static MediaOrigin BuildOriginFromIStreamingEndpoint(IStreamingEndpoint endpoint) { var origin = new MediaOrigin { Id = endpoint.Id.NimbusIdToRawGuid(), Name = endpoint.Name, NameShort = endpoint.Name.Substring(0, Math.Min(6, endpoint.Name.Length)).ToUpper(), Description = endpoint.Description, HostName = endpoint.HostName, LastModified = endpoint.LastModified, Created = endpoint.Created, State = endpoint.State.ToString(), ReservedUnits = (endpoint.ScaleUnits.HasValue ? endpoint.ScaleUnits.Value : 0), Health = endpoint.State == StreamingEndpointState.Running ? HealthStatus.Healthy : HealthStatus.Ignore, MaxAge = endpoint.CacheControl?.MaxAge }; if (endpoint.AccessControl != null) { if (endpoint.AccessControl.IPAllowList != null) { origin.IPAllowList = string.Join(";", endpoint.AccessControl.IPAllowList .Select(iprange => string.Format("{0}/{1}", iprange.Address, iprange.SubnetPrefixLength))); } if (endpoint.AccessControl.AkamaiSignatureHeaderAuthenticationKeyList != null) { origin.AuthenticationKeys = endpoint.AccessControl?.AkamaiSignatureHeaderAuthenticationKeyList?.ToList(); } } return(origin); }
private List <Alert> GetOriginAlerts(MediaOrigin origin) { var alerts = new List <Alert>(); if (MediaService.Config.TelemetryStorage != null) { var telemetryHelper = new TelemetryHelper(MediaService.Config, null, origin.Id); var metrics = telemetryHelper.GetOriginTelemetry(origin.ReservedUnits); var account = GetAccount(MediaService.Credentials.ClientId); long ticks = 0; foreach (var metric in metrics) { if (ticks == 0) { ticks = metric.Timestamp.Ticks; } var healthState = metric.ComputeHealthState(); if (healthState.Level == HealthStatus.Warning || healthState.Level == HealthStatus.Critical) { alerts.Add(new Alert { AlertTypeID = 3, AccountId = account.AccountId, OriginID = origin.Id, MetricType = MetricType.Origin.ToString(), MetricName = metric.Metric.DisplayName, AlertValue = metric.Value, ErrorLevel = healthState.Level.ToString(), Details = healthState.Details, AlertDate = DateTime.UtcNow.Date, AlertTime = DateTime.UtcNow.TimeOfDay }); } } ; } if (alerts.Count > 0) { origin.Health = (HealthStatus)alerts.Max(alert => Enum.Parse(typeof(HealthStatus), alert.ErrorLevel)); } else { origin.Health = HealthStatus.Healthy; } return(alerts); }
private void Compare(IStreamingEndpoint endpoint, MediaOrigin origin) { Assert.AreEqual(endpoint.Id.Substring(12), origin.Id); Assert.AreEqual(endpoint.Name, origin.Name); Assert.AreEqual(endpoint.HostName, origin.HostName); Assert.AreEqual(endpoint.Created, origin.Created); Assert.AreEqual(endpoint.LastModified, origin.LastModified); Assert.AreEqual(endpoint.ScaleUnits, origin.ReservedUnits); Assert.AreEqual(endpoint.State.ToString(), origin.State); Assert.AreEqual(endpoint.CacheControl?.MaxAge, origin.MaxAge); if (endpoint.AccessControl != null) { var ipAllowList = string.Join(";", endpoint.AccessControl.IPAllowList.Select(iprange => string.Format("{0}/{1}", iprange.Address, iprange.SubnetPrefixLength))); Assert.AreEqual(ipAllowList, origin.IPAllowList); } }
private void PersistOriginState(MediaOrigin origin, List <Alert> originAlerts) { string acctName = MediaService.Credentials.ClientId; var acct = GetAccount(MediaService.Credentials.ClientId); var dbOrigin = DataAccess.GetOrigin(origin.Id); if (dbOrigin == null) { dbOrigin = new Origin { OriginId = origin.Id.NimbusIdToRawGuid(), AccountId = DataAccess.GetAccount(acctName).AccountId, OriginName = origin.Name, Created = origin.Created }; DataAccess.SaveOrigin(dbOrigin, acctName); } if (originAlerts != null && originAlerts.Count > 0) { DataAccess.SaveAlerts(originAlerts, acctName); } }