Exemple #1
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());
                    }
                }
            }
        }
Exemple #2
0
        private void processPingResult(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"));
            host        updatehHost = hosts.Find(x => x.ip.Equals(result[1]));

            try
            {
                if (result[0].Equals("1") == true)
                {
                    int mstemp  = Int32.Parse(result[2]);
                    int mspaint = 0;
                    if (mstemp <= 0)
                    {
                        mstemp = 1;
                    }
                    if (mstemp <= 9)
                    {
                        mspaint = 9;
                    }
                    else if (mstemp >= timeout)
                    {
                        mspaint = timeout;
                    }
                    else
                    {
                        mspaint = mstemp;
                    }

                    updatepb.Invoke(new Action(() => updatepb.Value = mspaint));
                    updatems.Invoke(new Action(() => updatems.Text  = mstemp + " ms"));
                    if (mspaint < (timeout / 2) - 50)
                    {
                        updatepb.Invoke(new Action(() => updatepb.ForeColor = Color.Green));
                    }
                    else if (mspaint > (timeout / 2) + 150)
                    {
                        updatepb.Invoke(new Action(() => updatepb.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.Black));
                        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.registerSendRecoveryhost(updatehHost.getIp());
                        }
                    }
                    else if (updatehHost.getFailures() > 0)
                    {
                        updatehHost.decreaseFailures();
                    }
                    else if (updatehHost.getFailures() == 0)
                    {
                        updatems.Invoke(new Action(() => updatems.ForeColor = Color.Black));
                        updatelb.Invoke(new Action(() => updatelb.ForeColor = Color.Black));
                    }
                }
                else if (result[0].Equals("-1") == true)
                {
                    if (updatehHost.getFailures() > 150)
                    {
                        if (updatehHost.alerted == false)
                        {
                            updatehHost.alerted = true;
                            //MessageBox.Show("Host " + updatehHost.getIp() + " ha caido!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            //Console.WriteLine("Host " + updatehHost.getIp() + " ha caido!");

                            mailer alertmailer = new mailer(updatehHost.getFMail(), updatehHost.getTMail(), updatehHost.getMXserver(), updatehHost.getName());
                            if (alertmailer.sendDownAlert(updatehHost.getIp()))
                            {
                                //Console.WriteLine("Alert sended: " + updatehHost.getIp());
                                logger.registerSendAlertHost(updatehHost.getIp());
                            }
                        }
                    }
                    else
                    {
                        updatehHost.registerFailure();
                    }
                    if (updatehHost.getFailures() > 10)
                    {
                        updatepb.Invoke(new Action(() => updatepb.Value     = timeout));
                        updatepb.Invoke(new Action(() => updatepb.ForeColor = Color.Red));
                        updatems.Invoke(new Action(() => updatems.Text      = "Down!"));
                        updatems.Invoke(new Action(() => updatems.ForeColor = Color.Red));
                        updatelb.Invoke(new Action(() => updatelb.ForeColor = Color.Red));
                        logger.registerOfflineHost(updatehHost.getIp());
                    }
                }
            }catch (Exception e)
            {
                //todo
            }
        }