mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
Added new health endpoint
This commit is contained in:
parent
7addb5b6f7
commit
95c8da2053
3 changed files with 108 additions and 83 deletions
|
|
@ -0,0 +1,27 @@
|
|||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace ServerManager.WebApplication.Controllers;
|
||||
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
[ApiVersion("1.0")]
|
||||
[Produces("application/json")]
|
||||
public class HealthController : ControllerBase
|
||||
{
|
||||
[HttpGet()]
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public IActionResult Get()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +1,33 @@
|
|||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace ServerManager.WebApplication.Controllers
|
||||
{
|
||||
[Route("api/plugin")]
|
||||
[ApiController]
|
||||
[ApiVersion("1.0")]
|
||||
[Produces("application/json")]
|
||||
public class PluginController : ControllerBase
|
||||
{
|
||||
public PluginController()
|
||||
{
|
||||
}
|
||||
namespace ServerManager.WebApplication.Controllers;
|
||||
|
||||
// GET: api/plugin/call/00000000-0000-0000-0000-000000000000/192.168.1.1
|
||||
[HttpGet()]
|
||||
[Route("call/{pluginCode}/{ipString}", Name = "PluginCall_V1")]
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public ActionResult<bool> PluginCall_V1([FromRoute] string pluginCode, [FromRoute] string ipString)
|
||||
[Route("api/plugin")]
|
||||
[ApiController]
|
||||
[ApiVersion("1.0")]
|
||||
[Produces("application/json")]
|
||||
public class PluginController : ControllerBase
|
||||
{
|
||||
public PluginController()
|
||||
{
|
||||
}
|
||||
|
||||
// GET: api/plugin/call/00000000-0000-0000-0000-000000000000/192.168.1.1
|
||||
[HttpGet()]
|
||||
[Route("call/{pluginCode}/{ipString}", Name = "PluginCall_V1")]
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public ActionResult<bool> PluginCall_V1([FromRoute] string pluginCode, [FromRoute] string ipString)
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, false);
|
||||
}
|
||||
return Ok(true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,72 +8,71 @@ using ServerManager.WebApplication.Services;
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ServerManager.WebApplication.Controllers
|
||||
namespace ServerManager.WebApplication.Controllers;
|
||||
|
||||
[Route("api/server")]
|
||||
[ApiController]
|
||||
[ApiVersion("1.0")]
|
||||
[Produces("application/json")]
|
||||
public class ServerController : ControllerBase
|
||||
{
|
||||
[Route("api/server")]
|
||||
[ApiController]
|
||||
[ApiVersion("1.0")]
|
||||
[Produces("application/json")]
|
||||
public class ServerController : ControllerBase
|
||||
private readonly IServerQueryService _serverQueryService;
|
||||
|
||||
public ServerController(IServerQueryService serverQueryService)
|
||||
{
|
||||
private readonly IServerQueryService _serverQueryService;
|
||||
_serverQueryService = serverQueryService;
|
||||
}
|
||||
|
||||
public ServerController(IServerQueryService serverQueryService)
|
||||
// GET: api/server/call/00000000-0000-0000-0000-000000000000/192.168.1.1
|
||||
[HttpGet()]
|
||||
[Route("call/{managerCode}/{ipString}", Name = "ServerCall")]
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public ActionResult<bool> ServerCall([FromRoute] string managerCode, [FromRoute] string ipString)
|
||||
{
|
||||
try
|
||||
{
|
||||
_serverQueryService = serverQueryService;
|
||||
return Ok(true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, false);
|
||||
}
|
||||
}
|
||||
|
||||
// GET: api/server/00000000-0000-0000-0000-000000000000/1.0/192.168.1.1/27017
|
||||
[HttpGet()]
|
||||
[Route("{managerCode}/{managerVersion}/{ipString}/{port}", Name = "GetServerStatus")]
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[ProducesResponseType(StatusCodes.Status503ServiceUnavailable)]
|
||||
public ActionResult<ServerStatusResponse> GetServerStatus([FromRoute] string managerCode, [FromRoute] string managerVersion, [FromRoute] string ipString, [FromRoute] int port)
|
||||
{
|
||||
// check for valid service
|
||||
if (_serverQueryService == null)
|
||||
{
|
||||
var response = new ErrorResponse { Errors = new List<string> { "Server query service not available." } };
|
||||
return StatusCode(StatusCodes.Status503ServiceUnavailable, response);
|
||||
}
|
||||
|
||||
// GET: api/server/call/00000000-0000-0000-0000-000000000000/192.168.1.1
|
||||
[HttpGet()]
|
||||
[Route("call/{managerCode}/{ipString}", Name = "ServerCall")]
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public ActionResult<bool> ServerCall([FromRoute] string managerCode, [FromRoute] string ipString)
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, false);
|
||||
}
|
||||
var result = _serverQueryService.CheckServerStatus(managerCode, managerVersion, ipString, port);
|
||||
var response = new ServerStatusResponse { Available = result.ToString() };
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
// GET: api/server/00000000-0000-0000-0000-000000000000/1.0/192.168.1.1/27017
|
||||
[HttpGet()]
|
||||
[Route("{managerCode}/{managerVersion}/{ipString}/{port}", Name = "GetServerStatus")]
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[ProducesResponseType(StatusCodes.Status503ServiceUnavailable)]
|
||||
public ActionResult<ServerStatusResponse> GetServerStatus([FromRoute] string managerCode, [FromRoute] string managerVersion, [FromRoute] string ipString, [FromRoute] int port)
|
||||
catch (ServerManagerApiException ex)
|
||||
{
|
||||
// check for valid service
|
||||
if (_serverQueryService == null)
|
||||
{
|
||||
var response = new ErrorResponse { Errors = new List<string> { "Server query service not available." } };
|
||||
return StatusCode(StatusCodes.Status503ServiceUnavailable, response);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var result = _serverQueryService.CheckServerStatus(managerCode, managerVersion, ipString, port);
|
||||
var response = new ServerStatusResponse { Available = result.ToString() };
|
||||
return Ok(response);
|
||||
}
|
||||
catch (ServerManagerApiException ex)
|
||||
{
|
||||
var response = new ErrorResponse { Errors = ex.Messages };
|
||||
return StatusCode(ex.StatusCode, response);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var response = new ErrorResponse { Errors = new List<string> { ex.Message } };
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, response);
|
||||
}
|
||||
var response = new ErrorResponse { Errors = ex.Messages };
|
||||
return StatusCode(ex.StatusCode, response);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var response = new ErrorResponse { Errors = new List<string> { ex.Message } };
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue