Exemple #1
0
        /// <summary>
        /// Initialize the RuleUniqueIdentity property of the monitor rule.
        /// </summary>
        /// <param name="tempRule">The specified monitor rule.</param>
        /// <param name="fileName">The file name of this monitor rule.</param>
        /// <returns>The MonitorRule with the RuleUniqueIdentity value.</returns>
        public static MonitorRule AutoMakeRuleUniqueIdentity(MonitorRule tempRule, string fileName)
        {
            string fileLocation = fileName.Split(new string[] { ConstStrings.MonitoringDllFolderName + "\\" }, StringSplitOptions.RemoveEmptyEntries)[1].Replace("\\", "_") + "_";

            tempRule.RuleUniqueIdentity = fileLocation + tempRule.RuleId;
            return(tempRule);
        }
        private static string GenerateDetailTable(MonitorRule rule, string result)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<table>");
            sb.Append(string.Format("<tr><td><b>Rule</b></td><td>{0}</td></tr>", rule.RuleId));
            sb.Append(string.Format("<tr><td><b>Severity</b></td><td>{0}</td></tr>", rule.AlertSeverity));
            sb.Append(string.Format("<tr><td><b>Alert Condition</b></td><td>{0}</td></tr>", rule.Operation + rule.Threshold));
            sb.Append(string.Format("<tr><td><b>Actual Result</b></td><td>{0}</td></tr>", result));
            sb.Append(string.Format("<tr><td><b>Rule Detail</b></td><td>{0}</td></tr>", JsonConvert.SerializeObject(rule, Formatting.Indented).Replace("\r\n", "<br>")));
            sb.Append("</table>");

            return(sb.ToString());
        }
Exemple #3
0
        /// <summary>
        /// Take Alert action: Send Email
        /// </summary>
        /// <param name="rule">The specified MonitorRule instance.</param>
        /// <param name="result">The value returned by ExcuteRule method.</param>
        public virtual void TakeAlertAction(MonitorRule rule, string result)
        {
            string subject = string.Format("Interop Monitoring Alert Fired:{0}", rule.RuleId);

            //Write the common method to fire the alert action, and this can also be overwritten by derived classed
            if ((DateTime.UtcNow - ExecutionInfoStore.GetLastActionTime(rule.RuleUniqueIdentity)).TotalMinutes > rule.AlertSuppressionWindowInMinutes)
            {
                Log.WriteInfoLog("Rule: {0} compare with last alert time and need alert, start to send alert mail.", rule.RuleUniqueIdentity);
                string ccEmail = ConfigurationManager.AppSettings[ConstStrings.ActionEmailServerity + rule.AlertSeverity.ToString()];
                var    body    = AlertMail.GenerateAlertMail(rule, result);
                EmailHelper.SendEmail(subject, body, rule.EmailNotificationAddress, ccEmail);
                ExecutionInfoStore.SetLastActionTime(rule.RuleUniqueIdentity, DateTime.UtcNow);
                Log.WriteInfoLog("Rule: {0} send rule alert mail done", rule.RuleUniqueIdentity);
            }
            else
            {
                Log.WriteInfoLog("Rule: {0} compare with last alert time and no need to alert", rule.RuleUniqueIdentity);
            }
        }
Exemple #4
0
 /// <summary>
 /// After querying, if we need alert, return true, otherwise return false
 /// </summary>
 /// <param name="rule">The specified MonitorRule instance.</param>
 /// <returns>If need alert, return true, otherwise return false.</returns>
 public abstract bool ExecuteRule(MonitorRule rule, out string result);
 /// <summary>
 /// Generate the alert mail
 /// </summary>
 /// <param name="rule">The specified MonitorRule instance.</param>
 /// <param name="result">The result of executing this monitor rule.</param>
 /// <returns>Generated alert mail content</returns>
 public static string GenerateAlertMail(MonitorRule rule, string result)
 {
     return(Resources.AlertMailTemplate.Replace(ConstStrings.AlertContentPlaceHolder_RuleId, rule.RuleId)
            .Replace(ConstStrings.AlertContentPlaceHolder_DetailTable, GenerateDetailTable(rule, result)));
 }
Exemple #6
0
 /// <summary>
 /// Replace AtLastQueryTime using the actual last query time in AlertQuery property.
 /// </summary>
 /// <param name="tempRule">The specified monitor rule.</param>
 /// <returns>The MonitorRule with the updated AlertQuery value.</returns>
 public static MonitorRule ReplaceAtLastQueryTime(MonitorRule tempRule)
 {
     tempRule.AlertQuery = tempRule.AlertQuery.Replace("@LastQueryTime", ExecutionInfoStore.GetLastQueryTime(tempRule.RuleUniqueIdentity).ToString());
     return(tempRule);
 }