Example #1
0
        public MonitorRuleResult Execute(Monitor monitor)
        {
            MonitorRuleResult result = new MonitorRuleResult();
            int maxResponseTime      = 500; //Todo: remove hardcoded values

            if (!this.IsMaxResponseValid(monitor.ResponseTime, maxResponseTime))
            {
                result.AddMessage("MaxResponse failed(" + maxResponseTime + ") Actual value: " + monitor.ResponseTime);
                result.Status = MonitorStatus.RuleFailed;
            }

            return(result);
        }
Example #2
0
        /// <summary>
        /// Runs the rules the user have specified
        /// </summary>
        private void RunRules()
        {
            if (RuleList != null)
            {
                foreach (IMonitorRule rule in RuleList)
                {
                    MonitorRuleResult result = rule.Execute(this);

                    if (result.Messages.Count > 0)
                    {
                        foreach (string item in result.Messages)
                        {
                            this.infoText += item;
                        }
                        this.status = result.Status;
                    }
                }
            }



            //If the rule fails
            //if (!this.rules.IsMaxResponseValid(this.responseTime) && this.rules.RunMaxResponseRule)
            //{
            //    this.infoText = "MaxResponse failed(" + this.Rules.MaxResponseTime + ") Actual value: " + this.responseTime;
            //    this.status = MonitorStatus.RuleFailed;
            //}

            //Check if the HTML contains or dont contain some words
            //if (this.rules.RunHtmlContainsText)
            //{
            //    bool approved = true;
            //    string badWords = "";

            //    //MUST contatin
            //    for (int i = 0; i < this.rules.WordsListMust.Length; i++)
            //    {
            //        if (this.rules.WordsListMust[i].ToString().Trim() != "")
            //        {
            //            approved = this.rules.ContainsWordInHtml(this.rules.WordsListMust[i].ToString(), this.responseHtml);

            //            if (!approved)
            //                badWords += this.rules.WordsListMust[i].ToString() + " ";
            //        }
            //    }

            //    //CANNOT contain
            //    for (int i = 0; i < this.rules.WordsListCannot.Length; i++)
            //    {
            //        if (this.rules.WordsListCannot[i].ToString().Trim() != "")
            //        {
            //            approved = !this.rules.ContainsWordInHtml(this.rules.WordsListCannot[i].ToString(), this.responseHtml);

            //            if (!approved)
            //                badWords += this.rules.WordsListCannot[i].ToString() + " ";
            //        }
            //    }


            //    if (!approved)
            //    {
            //        this.infoText = "HTMLCheckWords failed: " +badWords;
            //        this.status = MonitorStatus.RuleFailed;
            //    }
                              
            //}
        }