//Development usage // public async Task<IActionResult> Seed() // { // _dbContext.Servers.Add(new Server // { // Name = "Example Machine", // Architect = "HyperV", // VCPU = "4", // Memory = "1024MB", // DiskSize = "200GB", // InnerIP = "172.16.1.1", // OutterIP = "202.118.17.65", // Owner = "Anduin", // OS = "Windows Server 2016", // UsageA = "This is an Example", // UsageB = "Ohhhh WTF!@??", // VMArchitect = "HyperV", // InDomainName = "Example.MyDomain.com" // }); // await _dbContext.SaveChangesAsync(); // return RedirectToAction(nameof(Index)); // } public async Task <IActionResult> Restart(int id) { var server = await _dbContext.Servers.SingleOrDefaultAsync(t => t.Id == id); if (server == null) { return(NotFound()); } var result = await _restartTrigger.Restart(server); if (result.Contains("Successfully")) { _dbContext.AuditLogs.Add(new AuditLog { Action = $"成功重启了{server.Name}.", Operator = User.Identity.Name, IPAddress = HttpContext.Connection.RemoteIpAddress.ToString() }); await _dbContext.SaveChangesAsync(); return(Json(new { code = 0, message = "Success!" })); } else { _dbContext.AuditLogs.Add(new AuditLog { Action = $"失败重启了{server.Name}.", Operator = User.Identity.Name, IPAddress = HttpContext.Connection.RemoteIpAddress.ToString() }); await _dbContext.SaveChangesAsync(); return(Json(new { code = -1, message = "Failed!", Reason = result })); } }
public async Task <IActionResult> Add(AddViewModel model) { var hm = new HealthMonitor { MonitorName = model.MonitorName, RequestPath = model.RequestPath, IsPostMethod = model.IsPostMethod, Form = model.Form, ExpectedStatusCode = model.ExpectedStatusCode, ExpectedContent = model.ExpectedContent }; _dbContext.MonitorTemplates.Add(hm); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }