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); } } } } }
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"); } }
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) { }
public BaseController(DALdbContext dbContext = null) { this.dbContext = dbContext; }
public AccountController(DALdbContext dbContext) : base(dbContext) { }