示例#1
0
            public static SlackAttachment Create(dynamic payload)
            {
                if (payload == null)
                {
                    throw new ArgumentNullException(nameof(payload));
                }

                var highlightAlert = HighlightAlert.Create(payload.problem.ToString());

                var attachment = new SlackAttachment {
                    title       = $"{highlightAlert.alertIcon} {payload.alertSummary}",
                    text        = $"{payload.problem} - <{payload.linkUrl}|More information>",
                    color       = highlightAlert.color,
                    markdown_in = "title, text"
                };

                return(attachment);
            }
示例#2
0
        /// <summary>
        /// Converts a HighlightAlertDTO object to the icon portal HighlightAlert object
        /// </summary>
        /// <param name="dto">The HighlightAlertDTO object to convert</param>
        /// <returns>A populated HighlightAlert object</returns>
        public static HighlightAlert GetHighlightAlertFromDTO(HighlightAlertDTO dto)
        {
            HighlightAlert lHighlightAlert = new HighlightAlert();

            lHighlightAlert.DateSent              = Convert.ToDateTime(dto.timeStampUtc.ToString());
            lHighlightAlert.Folder                = dto.folder.ToString().Replace("?", ">>");
            lHighlightAlert.Location              = dto.locationName.ToString();
            lHighlightAlert.WatchName             = dto.watchName.ToString();
            lHighlightAlert.WatchTypeName         = dto.watchTypeName.ToString();
            lHighlightAlert.Problem               = dto.problem.ToString();
            lHighlightAlert.AlertSummary          = dto.alertSummary.ToString();
            lHighlightAlert.Description           = dto.stabilityIssueDescription.ToString();
            lHighlightAlert.ReferenceText         = dto.referenceText.ToString();
            lHighlightAlert.LinkUrl               = dto.linkUrl.ToString();
            lHighlightAlert.SiteLinksUp           = Convert.ToInt32(dto.siteLinksUp);
            lHighlightAlert.HasStabilityIssue     = Convert.ToBoolean(dto.hasStabilityIssue);
            lHighlightAlert.IsBroadbandSpeedAlert = Convert.ToBoolean(dto.isBroadbandSpeedAlert);
            lHighlightAlert.IsWirelessAccessPoint = Convert.ToBoolean(dto.isWirelessAccessPoint);

            return(lHighlightAlert);
        }
示例#3
0
        /// <summary>
        /// Writes the supplied HighlightAlert object to the database
        /// </summary>
        /// <param name="highlightAlert" type="HighlightAlert">The populated HighlightAlert object to create</param>
        /// <returns>True if added correctly</returns>
        public int CreateEmailAlert(HighlightAlert highlightAlert)
        {
            var rtn = -1;

            try
            {
                using (SqlConnection con = new SqlConnection(connectionString))
                {
                    SqlCommand cmd = new SqlCommand("Highlight.WebhookAlerts_INSERT", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@DateSent", highlightAlert.DateSent);
                    cmd.Parameters.AddWithValue("@AlertSummary", highlightAlert.AlertSummary);
                    cmd.Parameters.AddWithValue("@LinkUrl", highlightAlert.LinkUrl);
                    cmd.Parameters.AddWithValue("@Description", highlightAlert.Description);
                    cmd.Parameters.AddWithValue("@Location", highlightAlert.Location.Replace("?", ">>"));
                    cmd.Parameters.AddWithValue("@Folder", highlightAlert.Folder);
                    cmd.Parameters.AddWithValue("@Problem", highlightAlert.Problem);
                    cmd.Parameters.AddWithValue("@ReferenceText", highlightAlert.ReferenceText);
                    cmd.Parameters.AddWithValue("@SiteLinksUp", highlightAlert.SiteLinksUp);
                    cmd.Parameters.AddWithValue("@WatchName", highlightAlert.WatchName);
                    cmd.Parameters.AddWithValue("@WatchTypeName", highlightAlert.WatchTypeName);
                    cmd.Parameters.AddWithValue("@HasStabilityIssue", highlightAlert.HasStabilityIssue);
                    cmd.Parameters.AddWithValue("@IsBroadbandSpeedAlert", highlightAlert.IsBroadbandSpeedAlert);
                    cmd.Parameters.AddWithValue("@IsWirelessAccessPoint", highlightAlert.IsWirelessAccessPoint);
                    cmd.Parameters.AddWithValue("@Id", 0);
                    cmd.Parameters[14].Direction = ParameterDirection.InputOutput;

                    con.Open();
                    cmd.ExecuteNonQuery();
                    rtn = Convert.ToInt32(cmd.Parameters[14].Value);
                    con.Close();
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            return(rtn);
        }
示例#4
0
 public ActionResult Post([FromBody] HighlightAlertDTO alertDTO)
 {
     logger.LogInformation("The Post call of the web hook controller");
     try {
         if (alertDTO != null)
         {
             HighlightAlert highlightAlert = DTOConvert.GetHighlightAlertFromDTO(alertDTO);
             logger.LogInformation("The Post call of the web hook controller contains alert: {alert}", JsonConvert.SerializeObject(highlightAlert));
             var id = _HighlightDB.CreateEmailAlert(highlightAlert);
             logger.LogInformation("Created new highlight alert with Id: {id}", id);
             return(StatusCode(204));
         }
         else
         {
             return(StatusCode(400));
         }
     }
     catch (System.Exception ex)
     {
         logger.LogCritical("The POST method of the web hook contoller produced the following error: {err}", ex.Message);
         throw ex;
     }
 }