Beispiel #1
0
        public static ActivityLogDto GetActivityLogAlertDtoMapping(ActivityLogAlert resource, ILogger log)
        {
            log.LogInformation(resource.ToString());

            log.LogInformation("GetActivityLogAlertDtoMapping");
            ResourceIDs resource_IDs = GetResourceIds(resource.data.essentials.alertTargetIDs[0]);
            var         resourceDto  = new ActivityLogDto();

            try{
                resourceDto.id                = resource_IDs.id;
                resourceDto.alertId           = resource.data.essentials.alertId;
                resourceDto.alertStatus       = resource.data.alertContext.status;
                resourceDto.resourceId        = resource_IDs.resourceId;
                resourceDto.alertStatus       = resource.data.alertContext.status;
                resourceDto.eventTimestamp    = resource.data.alertContext.eventTimestamp;
                resourceDto.correlationId     = resource.data.alertContext.correlationId;
                resourceDto.operationName     = resource.data.alertContext.operationName;
                resourceDto.operationId       = resource.data.alertContext.operationId;
                resourceDto.subscriptionId    = resource.data.essentials.alertTargetIDs[0].Split("/")[2];
                resourceDto.resourceName      = resource_IDs.resourceName;
                resourceDto.resourceType      = resource_IDs.resourceType;
                resourceDto.resourceGroupName = (resource.data.essentials.alertTargetIDs[0].Split("/")[4]).ToLower();
            }
            catch (Exception exe)
            {
                log.LogInformation(exe.Message);
            }
            return(resourceDto);
        }
Beispiel #2
0
        private IEnumerable <AlertRule> ReadAlertRules(IResourceGroup resourceGroup)
        {
            var alertRule  = new AlertRule(resourceGroup);
            var alertRules = new List <AlertRule> {
                alertRule
            };
            var azureAlertRules = _azure.AlertRules;

            foreach (var metricAlert in azureAlertRules.MetricAlerts.ListByResourceGroup(resourceGroup.Name))
            {
                MetricAlert metric = new MetricAlert(metricAlert.Name);
                alertRule.MetricAlerts.Add(metric);
            }

            // Microsoft.Azure.Management.Monitor.Fluent.Models.ErrorResponseException. v
            // Operation returned an invalid status code 'NotFound'
            foreach (var activityLogAlert in azureAlertRules.ActivityLogAlerts.ListByResourceGroup(resourceGroup.Name))
            {
                ActivityLogAlert activity = new ActivityLogAlert(activityLogAlert.Name);
                alertRule.ActivityLogAlerts.Add(activity);
            }

            return(alertRules);
        }