mirror of
https://gitlab.com/Hukuta47/cartrix.git
synced 2026-12-05 04:20:55 +00:00
33 lines
1.0 KiB
C#
33 lines
1.0 KiB
C#
using CartriX.Api.Interfaces;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace CartriX.Api.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class SnmpController : ControllerBase
|
|
{
|
|
private readonly ISnmpService _snmpService;
|
|
public SnmpController(ISnmpService snmpService)
|
|
{
|
|
_snmpService = snmpService;
|
|
}
|
|
[HttpGet(nameof(GetDataFromSnmp))] public async Task<IActionResult> GetDataFromSnmp([FromQuery] string IpOrHostname, [FromQuery] string Oid)
|
|
{
|
|
if (string.IsNullOrEmpty(IpOrHostname) || string.IsNullOrEmpty(Oid))
|
|
{
|
|
return BadRequest("ipAddress и Oid обязательны");
|
|
}
|
|
try
|
|
{
|
|
var result = await _snmpService.GetDataFromSnmp(IpOrHostname, Oid);
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(500, $"Ошибка: {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
}
|