Example #1
0
        public void Run()
        {
            using (var db = new DALdbContext(_config.DatabaseConnectionString))
            {
                var hosts = db.Hosts.Include(a => a.User).Where(a => a.Active).ToList();

                foreach (var host in hosts)
                {
                    var alive = IsAlive(host);

                    var hostLog = new HostCheckLog
                    {
                        HostID = host.ID,
                        IsUp   = alive
                    };

                    db.HostLog.Add(hostLog);
                    db.SaveChanges();

                    if (host.AlertsEnabled)
                    {
                        if (!alive)
                        {
                            ProcessFailure(host);
                        }
                        else
                        {
                            ProcessSuccess(host);
                        }
                    }
                }
            }
        }
Example #2
0
        private void ProcessFailure(Hosts host)
        {
            using (var db = new DALdbContext(_config.DatabaseConnectionString))
            {
                var lastLog = db.HostLog.Where(a => a.HostID == host.ID && a.Active && a.IsUp).OrderByDescending(a => a.Created).FirstOrDefault();

                var lastUp = host.Created.DateTime;

                if (lastLog != null)
                {
                    lastUp = lastLog.Created.DateTime;
                }

                SendEmail(host.User.Username, host.HostName, $"Dead Server {host} - down since {lastUp} eom");
            }
        }
Example #3
0
        void ProcessSuccess(Hosts host)
        {
            using (var db = new DALdbContext(_config.DatabaseConnectionString))
            {
                var lastLog = db.HostLog.Where(a => a.HostID == host.ID && a.Active && a.IsUp).OrderByDescending(a => a.Created).FirstOrDefault();

                var lastUp = host.Created.DateTime;

                if (lastLog == null)
                {
                    return;
                }

                lastUp = lastLog.Modified.DateTime;

                if (DateTime.Now.Subtract(lastUp).TotalMinutes < host.AllowableDowntimeMinutes)
                {
                    return;
                }

                SendEmail(host.User.Username, host.HostName, $"Restored Server {host.HostName} - down since {lastUp} eom");
            }
        }
 public HostsController(DALdbContext dbContext) : base(dbContext)
 {
 }
Example #5
0
 public BaseController(DALdbContext dbContext = null)
 {
     this.dbContext = dbContext;
 }
 public AccountController(DALdbContext dbContext) : base(dbContext)
 {
 }