Пример #1
0
 private void runWebThread(web pinguedHost)
 {
     while (true)
     {
         processWebResult(pinguedHost.LocalPing());
         Thread.Sleep(5000);
     }
 }
Пример #2
0
 private void startWebPing(web pinguedWeb)
 {
     new Thread(() =>
     {
         Thread.CurrentThread.IsBackground = true;
         runWebThread(pinguedWeb);
     }).Start();
 }
Пример #3
0
        private void processWebResult(string[] result)
        {
            ProgressBar updatepb    = progressbars.Find(x => x.Name.Equals(result[1] + "pb"));
            Label       updatems    = mslabels.Find(x => x.Name.Equals(result[1] + "ms"));
            Label       updatelb    = labels.Find(x => x.Name.Equals(result[1] + "lb"));
            web         updatehHost = webs.Find(x => x.ip.Equals(result[1]));

            if (result[0].Equals("1") == true)
            {
                updatepb.Invoke(new Action(() => updatepb.Value     = timeout));
                updatepb.Invoke(new Action(() => updatepb.ForeColor = Color.Green));
                updatems.Invoke(new Action(() => updatems.Text      = "ONLINE"));
                updatems.Invoke(new Action(() => updatems.ForeColor = Color.Green));

                if (updatehHost.getFailures() < 5 && updatehHost.alerted == true)
                {
                    updatehHost.clearFailures();
                    //Console.WriteLine("Host " + updatehHost.getIp() + " RECUPERADO");

                    updatems.Invoke(new Action(() => updatems.ForeColor = Color.Green));
                    updatelb.Invoke(new Action(() => updatelb.ForeColor = Color.Black));

                    mailer alertmailer = new mailer(updatehHost.getFMail(), updatehHost.getTMail(), updatehHost.getMXserver());
                    if (alertmailer.sendRecoverAlert(updatehHost.getIp()))
                    {
                        Console.WriteLine("Recover sended: " + updatehHost.getIp());
                        logger.registerSendRecoverWeb(updatehHost.getIp());
                    }
                }
                else if (updatehHost.getFailures() > 0)
                {
                    updatehHost.decreaseFailures();
                }
                else if (updatehHost.getFailures() == 0)
                {
                    updatems.Invoke(new Action(() => updatems.ForeColor = Color.Green));
                    updatelb.Invoke(new Action(() => updatelb.ForeColor = Color.Black));
                }
            }
            else if (result[0].Equals("-1") == true || result[0].Equals("-2") == true)
            {
                if (updatehHost.getFailures() > 25)
                {
                    if (updatehHost.alerted == false)
                    {
                        updatehHost.alerted = true;
                        mailer alertmailer = new mailer(updatehHost.getFMail(), updatehHost.getTMail(), updatehHost.getMXserver());
                        if (alertmailer.sendDownAlert(updatehHost.getIp()))
                        {
                            Console.WriteLine("Alert sended: " + updatehHost.getIp());
                            logger.registerSendAlertWeb(updatehHost.getIp());
                        }
                    }
                }
                else
                {
                    updatehHost.registerFailure();
                }
                if (updatehHost.getFailures() > 10)
                {
                    if (result[0].Equals("-1") == true)
                    {
                        updatepb.Invoke(new Action(() => updatepb.Value     = timeout));
                        updatepb.Invoke(new Action(() => updatepb.ForeColor = Color.Red));
                        updatems.Invoke(new Action(() => updatems.Text      = "OFFLINE"));
                        updatems.Invoke(new Action(() => updatems.ForeColor = Color.Red));
                        updatelb.Invoke(new Action(() => updatelb.ForeColor = Color.Red));
                        logger.registerOfflineWeb(updatehHost.getIp());
                    }
                    else if (result[0].Equals("-2") == true)
                    {
                        updatepb.Invoke(new Action(() => updatepb.Value     = timeout));
                        updatepb.Invoke(new Action(() => updatepb.ForeColor = Color.DarkMagenta));
                        updatems.Invoke(new Action(() => updatems.Text      = "W/ERROR"));
                        updatems.Invoke(new Action(() => updatems.ForeColor = Color.DarkMagenta));
                        updatelb.Invoke(new Action(() => updatelb.ForeColor = Color.DarkMagenta));
                        logger.registerFailWeb(updatehHost.getIp());
                    }
                }
            }
        }