Ejemplo n.º 1
0
        private async Task <IActionResult> ProcessWebHook(AzureAlertNotification notification, string code)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                return(BadRequest(ErrorResponse.Create("The WebHook verification request must contain a 'code' query parameter.")));
            }

            if (notification == null)
            {
                return(BadRequest(ErrorResponse.Create("The request has no content")));
            }

            try
            {
                if (code != _settings.Secret)
                {
                    const string msg = "The code query parameter provided in the HTTP request did not match the expected value.";
                    await _log.WriteWarningAsync(nameof(WebHookReceiversController), nameof(ProcessWebHook), "Executing", msg);

                    return(BadRequest(ErrorResponse.Create(msg)));
                }
                await _sendService.Send(notification);

                return(Ok());
            }
            catch (Exception rex)
            {
                await _log.WriteWarningAsync(nameof(WebHookReceiversController), nameof(ProcessWebHook), "Executing", rex.Message);

                return(StatusCode(
                           (int)HttpStatusCode.InternalServerError,
                           ErrorResponse.Create(rex.Message)));
            }
        }
        public override Task ExecuteAsync(string generator, WebHookHandlerContext context)
        {
            // For more information about Azure Alert WebHook payloads, please see
            // 'https://azure.microsoft.com/en-us/documentation/articles/insights-webhooks-alerts/'
            AzureAlertNotification notification = context.GetDataOrDefault <AzureAlertNotification>();

            // Get the notification status
            string status = notification.Status;

            // Get the notification name
            string name = notification.Context.Name;

            // Get the name of the metric that caused the event
            string author = notification.Context.Condition.MetricName;

            return(Task.FromResult(true));
        }
Ejemplo n.º 3
0
        public IActionResult AzureAlertForIt(AzureAlertNotification data)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Get the notification status
            var status = data.Status;

            // Get the notification name
            var name = data.Context.Name;

            // Get the name of the metric that caused the event
            var author = data.Context.Condition.MetricName;

            return(Ok());
        }
        public override Task ExecuteAsync(string generator, WebHookHandlerContext context)
        {
            // Convert to POCO type
            AzureAlertNotification notification = context.GetDataOrDefault <AzureAlertNotification>();

            // Get the notification status
            string status = notification.Status;

            // Get the notification name
            string name = notification.Context.Name;

            // Get the name of the metric that caused the event
            string author = notification.Context.Condition.MetricName;

            //context.Response = context.Request.

            return(Task.FromResult(true));
        }
Ejemplo n.º 5
0
        private static string FormatMessage(AzureAlertNotification notification)
        {
            var cond = notification.Context.Condition;

            return($"Alarm status [{notification.Status}]. Metric name [{cond.MetricName}] value is [{cond.MetricValue} {cond.MetricUnit}]. Operator [{cond.Operator}]. Threshold value is [{cond.Threshold} {cond.MetricUnit}]");
        }
Ejemplo n.º 6
0
 public async Task Send(AzureAlertNotification notification)
 {
     var sender = notification.Context.ResourceName;
     var msg    = FormatMessage(notification);
     await _slackNotificationsSender.SendAsync(Const.SlackMsgType, sender, msg);
 }
Ejemplo n.º 7
0
 public Task <IActionResult> Post([FromBody] AzureAlertNotification notification, [FromQuery] string code)
 {
     return(ProcessWebHook(notification, code));
 }