mirror of
https://github.com/tribufu/ServerManagers
synced 2026-06-01 09:42:39 +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.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace ServerManager.WebApplication.Controllers
|
namespace ServerManager.WebApplication.Controllers;
|
||||||
{
|
|
||||||
[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
|
[Route("api/plugin")]
|
||||||
[HttpGet()]
|
[ApiController]
|
||||||
[Route("call/{pluginCode}/{ipString}", Name = "PluginCall_V1")]
|
[ApiVersion("1.0")]
|
||||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
[Produces("application/json")]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
public class PluginController : ControllerBase
|
||||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
{
|
||||||
public ActionResult<bool> PluginCall_V1([FromRoute] string pluginCode, [FromRoute] string ipString)
|
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);
|
||||||
{
|
}
|
||||||
return Ok(true);
|
catch
|
||||||
}
|
{
|
||||||
catch
|
return StatusCode(StatusCodes.Status500InternalServerError, false);
|
||||||
{
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,72 +8,71 @@ using ServerManager.WebApplication.Services;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
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")]
|
private readonly IServerQueryService _serverQueryService;
|
||||||
[ApiController]
|
|
||||||
[ApiVersion("1.0")]
|
public ServerController(IServerQueryService serverQueryService)
|
||||||
[Produces("application/json")]
|
|
||||||
public class ServerController : ControllerBase
|
|
||||||
{
|
{
|
||||||
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
|
try
|
||||||
[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
|
var result = _serverQueryService.CheckServerStatus(managerCode, managerVersion, ipString, port);
|
||||||
{
|
var response = new ServerStatusResponse { Available = result.ToString() };
|
||||||
return Ok(true);
|
return Ok(response);
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
catch (ServerManagerApiException ex)
|
||||||
// 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
|
var response = new ErrorResponse { Errors = ex.Messages };
|
||||||
if (_serverQueryService == null)
|
return StatusCode(ex.StatusCode, response);
|
||||||
{
|
}
|
||||||
var response = new ErrorResponse { Errors = new List<string> { "Server query service not available." } };
|
catch (Exception ex)
|
||||||
return StatusCode(StatusCodes.Status503ServiceUnavailable, response);
|
{
|
||||||
}
|
var response = new ErrorResponse { Errors = new List<string> { ex.Message } };
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError, 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue