Example #1
0
        private void HandleFailure(IWebSiteElement el, Exception ex)
        {
            bool sendFailure = true;

            // if we've already sent a failure message, we can specify an interval before a repeat failure message is sent
            if (this.mFailedSites.ContainsKey(el.Name))
            {
                if (DateTime.Now > this.mFailedSites[el.Name].AddMinutes(this.mConfig.RepeatMessageInterval))
                {
                    this.mFailedSites.Remove(el.Name);
                }
                else
                {
                    mLog.AddLogEntry(String.Format("Site {0} still down but notification skipped due to repeat message interval", el.Name));
                    sendFailure = false;
                }
            }

            if (sendFailure)
            {
                mLog.LogError(ex, el.Url);
                SendEmail(el, ex);

                if (this.CheckFailed != null)
                {
                    SiteEventArgs se = new SiteEventArgs(el);
                    this.CheckFailed(this, se);
                }

                // record when this failure message was generated
                this.mFailedSites.Add(el.Name, DateTime.Now);
            }
        }
Example #2
0
        private void HandleIsOnline(IWebSiteElement el, int bytesReceived)
        {
            mLog.AddLogEntry(String.Format("Site OK - {0} bytes received.", bytesReceived));

            if (mFailedSites.ContainsKey(el.Name))
            {
                mFailedSites.Remove(el.Name);
                string        subject = String.Format("Site back up - {0}", el.Name);
                StringBuilder sb      = new StringBuilder();
                sb.AppendFormat("The website \"{0}\" at {1} was previously unreachable - it is now back online ({2} bytes received).",
                                el.Name, el.Url, bytesReceived);
                SendEmail(el.EmailNotificationList, subject, sb.ToString(), MailPriority.High);
            }
        }
Example #3
0
        private bool CheckSite(IWebSiteElement el)
        {
            bool success = false;

            mLog.AddLogEntry(String.Format("Testing {0} ({1})...", el.Name, el.Url));
            try
            {
                HttpWebRequest  request        = (HttpWebRequest)WebRequest.Create(el.Url);
                HttpWebResponse response       = (HttpWebResponse)request.GetResponse();
                Stream          responseStream = response.GetResponseStream();

                byte[] buffer = new byte[8192];
                //StringBuilder sb = new StringBuilder();

                int count      = 0;
                int totalBytes = 0;

                do
                {
                    count       = responseStream.Read(buffer, 0, buffer.Length);
                    totalBytes += count;

                    //if (count > 0)
                    //{
                    //    sb.Append(Encoding.ASCII.GetString(buffer, 0, count));
                    //}
                }while (count > 0);

                if ((totalBytes == 0) && (this.mConfig.ZeroBytesIsFailure))
                {
                    throw new ApplicationException("Zero bytes returned from site");
                }

                HandleIsOnline(el, totalBytes);

                success = true;
            }
            catch (Exception ex)
            {
                HandleFailure(el, ex);
            }

            mLog.NewLine();

            return(success);
        }
Example #4
0
        private void SendEmail(IWebSiteElement el, Exception ex)
        {
            string        subject;
            StringBuilder sb = new StringBuilder();

            if (ex is WebException)
            {
                subject = String.Format("SITE DOWN - {0}", el.Name);
                sb.AppendFormat("The web site at {0} is not responding - please investigate immediately.\n\n", el.Url);
            }
            else
            {
                subject = String.Format("Site check error - {0}", el.Name);
                sb.AppendFormat("An error occurred when checking the website at {0} - please investigate immediately", el.Url);
            }

            sb.AppendLine();
            sb.AppendFormat("Message: {0}\n\n", ex.Message);

            SendEmail(el.EmailNotificationList, subject, sb.ToString(), MailPriority.High);
        }
Example #5
0
 public SiteEventArgs(IWebSiteElement el)
 {
     this.mWebSite = el;
 }