예제 #1
0
        public async Task <string> ProcessDynatraceAlert()
        {
            Log.Info("In ProcessDynatraceAlert(), notificationObject.ImpactedEnties: " + this.NotificationObject?.ImpactedEntities);
            FixedEvent[] fixedEvents = await fixMostRecentDeploymentsOnEntities(NotificationObject?.ImpactedEntities, DEFAULT_TIME_SPAN);

            Log.Info("fixed events, updating problem ticket");
            // we have our information and can now iterate and update the problem ticket
            foreach (var fixedEvent in fixedEvents)
            {
                Log.Info("fixedEvent: " + fixedEvent);
                // create comment body
                var commentBody = new FixedEventComment
                {
                    comment = "Triggered release " + fixedEvent.OrigEvent?.deploymentName.Value + " " + fixedEvent.RollbackReleaseId + " in project " + fixedEvent.OrigEvent?.deploymentProject.Value,
                    user    = "******",
                    context = "Azure Function"
                };
                Log.Info("Created FixedEventComment object: " + JsonConvert.SerializeObject(commentBody));

                // post comment body to dynatrace problem comments
                var fullUrl = this.DTTenantUrl + "/api/v1/problem/details/" + this.NotificationObject?.PID.Value + "/comments";
                Log.Info("full url: " + fullUrl);
                var response = await DynatraceAPIHelper.Post(fullUrl, this.DTApiToken, JsonConvert.SerializeObject(commentBody));

                var statusCode = response.StatusCode;
                var data       = await response.Content.ReadAsStringAsync();

                this.Log.Info("Push comment to Dynatrace: " + fullUrl + " " + statusCode + "-" + data);
            }


            return("Executed Handler successfully!");
        }
        public async Task <string> ProcessDynatraceAlert()
        {
            var DTTimeSpanMS = 60 * 1000 * Int32.Parse(this.DTTimeSpanMinutes);

            Log.Info("ProcessDynatraceAlert: notificationObject.ImpactedEnties: " + this.NotificationObject?.ImpactedEntities);

            FixedEvent[] fixedEvents = await fixMostRecentDeploymentsOnEntities(NotificationObject?.ImpactedEntities, DTTimeSpanMS);

            Log.Info("ProcessDynatraceAlert: fixed events, updating problem ticket");

            // we have our information and can now iterate and update the problem ticket
            if (fixedEvents.Length > 0)
            {
                foreach (var fixedEvent in fixedEvents)
                {
                    Log.Info("ProcessDynatraceAlert: fixedEvent: " + fixedEvent);
                    // create comment body
                    var commentBody = new FixedEventComment
                    {
                        comment = "Triggered release deploymentName: " + fixedEvent.OrigEvent?.deploymentName.Value + " RollbackReleaseId: " + fixedEvent.RollbackReleaseId + " in project " + fixedEvent.OrigEvent?.deploymentProject.Value,
                        user    = "******",
                        context = "Azure Function"
                    };
                    Log.Info("ProcessDynatraceAlert: Created FixedEventComment object: " + JsonConvert.SerializeObject(commentBody));

                    // post comment body to dynatrace problem comments
                    var fullUrl = this.DTTenantUrl + "/api/v1/problem/details/" + this.NotificationObject?.PID.Value + "/comments";
                    Log.Info("full url: " + fullUrl);
                    var response = await DynatraceAPIHelper.Post(fullUrl, this.DTApiToken, JsonConvert.SerializeObject(commentBody));

                    var statusCode = response.StatusCode;
                    var data       = await response.Content.ReadAsStringAsync();

                    this.Log.Info("ProcessDynatraceAlert: Push comment to Dynatrace: " + fullUrl + " " + statusCode + "-" + data);
                    if ((int)statusCode != 200)
                    {
                        throw new Exception("ProcessDynatraceAlert: Error udpating Dynatrace deployment entity: " + data);
                    }
                }
            }
            else
            {
                throw new Exception("ProcessDynatraceAlert: There are no recent Dynatrace deployment entities to update");
            }

            return("Executed Handler successfully!");
        }