/// <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 override bool ExecuteRule(MonitorRule rule, out string result)
        {
            object value = null;

            result = string.Empty;
            try
            {
                //Then there is the code to execute the Kusto query based on rule
                var         client = KustoClientFactory.CreateCslQueryProvider(rule.DataSource);
                IDataReader reader = client.ExecuteQuery(rule.AlertQuery);
                while (reader.Read())
                {
                    value = reader.GetValue(0);
                }
            }
            catch (Exception ex)
            {
                Log.WriteErrorLog("{0} throw exception : {1}", rule.RuleUniqueIdentity, ex.ToString());
                return(false);
            }

            result = value.ToString();
            Double.TryParse(result, out double returnObj);
            return(CommonHelper.CheckResult(rule.Operation, returnObj, rule.Threshold, rule.RuleUniqueIdentity));
        }
Esempio n. 2
0
        public void VerifyOneWay()
        {
            var rule = new MonitorRule
            {
                JsonMatcher = "json",
                SesMessage  = "ses",
                Regex       = "regex",
                Name        = "name",
                Id          = 1
            };

            var created = rule.Create();

            Assert.Equal(created.JsonMatcher, rule.JsonMatcher);
            Assert.Equal(created.Regex, rule.Regex);
            Assert.Equal(created.SesMessage, rule.SesMessage);
            Assert.Equal(created.Name, rule.Name);
            Assert.Equal(created.Id, rule.Id);
        }
        public IActionResult Post([FromBody] MonitorRule rule)
        {
            if (rule == null ||
                string.IsNullOrEmpty(rule.Regex) ||
                string.IsNullOrEmpty(rule.JsonMatcher) ||
                string.IsNullOrEmpty(rule.Name))
            {
                return(BadRequest("Invalid rule specified"));
            }


            if (!Enum.TryParse <SesMessageTypes>(rule.SesMessage, out _))
            {
                return(BadRequest("Invalid ses message"));
            }

            var dbRule = rule.Create();

            _monitorRuleRepository.Save(dbRule);

            return(Ok(dbRule.Create()));
        }
Esempio n. 4
0
 public void Delete(MonitorRule rule)
 {
     Session.Delete(rule);
 }
Esempio n. 5
0
 public void Save(MonitorRule rule)
 {
     Session.Save(rule);
 }