|
|
@ -264,17 +264,19 @@ public class NetworkStatusMonitor : INetworkStatusMonitor |
|
|
|
/// </summary>
|
|
|
|
/// <param name="comAddr">通信地址</param>
|
|
|
|
/// <param name="endPointType">端点类型</param>
|
|
|
|
private async Task<bool> CheckEndPointStatusAsync(string comAddr, string endPointType) |
|
|
|
/// <param name="commandType">命令类型</param>
|
|
|
|
/// <param name="operationType">操作类型</param>
|
|
|
|
private async Task<bool> CheckEndPointAsync(string comAddr, string endPointType, string commandType, string operationType) |
|
|
|
{ |
|
|
|
var command = $"{_appSettings.WebSocketJsPath} {comAddr} '{_appSettings.WebSocketCommands.Stats.ToJson()}'"; |
|
|
|
_logger.LogInformation("开始检查{EndPointType}端点状态,地址: {ComAddr}", endPointType, comAddr); |
|
|
|
var command = $"{_appSettings.WebSocketJsPath} {comAddr} '{commandType}'"; |
|
|
|
_logger.LogInformation("开始检查{EndPointType}端点{OperationType},地址: {ComAddr}", endPointType, operationType, comAddr); |
|
|
|
|
|
|
|
var result = await _commandExecutor.ExecuteCommandAsync(command, new CancellationTokenSource()); |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(result.Output)) |
|
|
|
{ |
|
|
|
_logger.LogWarning("{EndPointType}端点 {ComAddr} 状态检查失败: 返回数据为空", |
|
|
|
endPointType, comAddr); |
|
|
|
_logger.LogWarning("{EndPointType}端点 {ComAddr} {OperationType}检查失败: 返回数据为空", |
|
|
|
endPointType, comAddr, operationType); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
@ -288,35 +290,79 @@ public class NetworkStatusMonitor : INetworkStatusMonitor |
|
|
|
|
|
|
|
if (root.ValueKind == JsonValueKind.Object && root.EnumerateObject().Count() == 0) |
|
|
|
{ |
|
|
|
_logger.LogWarning("{EndPointType}端点 {ComAddr} 状态检查失败: 返回的JSON数据为空对象", |
|
|
|
endPointType, comAddr); |
|
|
|
_logger.LogWarning("{EndPointType}端点 {ComAddr} {OperationType}检查失败: 返回的JSON数据为空对象", |
|
|
|
endPointType, comAddr, operationType); |
|
|
|
return false; |
|
|
|
} |
|
|
|
if (root.ValueKind == JsonValueKind.Array && root.GetArrayLength() == 0) |
|
|
|
{ |
|
|
|
_logger.LogWarning("{EndPointType}端点 {ComAddr} 状态检查失败: 返回的JSON数据为空数组", |
|
|
|
endPointType, comAddr); |
|
|
|
_logger.LogWarning("{EndPointType}端点 {ComAddr} {OperationType}检查失败: 返回的JSON数据为空数组", |
|
|
|
endPointType, comAddr, operationType); |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
catch (JsonException) |
|
|
|
{ |
|
|
|
_logger.LogWarning("{EndPointType}端点 {ComAddr} 状态检查失败: 返回数据不是有效的JSON格式", |
|
|
|
endPointType, comAddr); |
|
|
|
_logger.LogWarning("{EndPointType}端点 {ComAddr} {OperationType}检查失败: 返回数据不是有效的JSON格式", |
|
|
|
endPointType, comAddr, operationType); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (result.IsSuccess) |
|
|
|
{ |
|
|
|
_logger.LogInformation("{EndPointType}端点 {ComAddr} 状态检查成功,返回数据: {Data}", |
|
|
|
endPointType, comAddr, parsedData); |
|
|
|
_logger.LogInformation("{EndPointType}端点 {ComAddr} {OperationType}检查成功,返回数据: {Data}", |
|
|
|
endPointType, comAddr, operationType, parsedData); |
|
|
|
return true; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var error = $"检查失败: {result.Error},返回数据: {result.Output}"; |
|
|
|
_logger.LogWarning("{EndPointType}端点 {ComAddr} 状态检查失败: {Error}", |
|
|
|
endPointType, comAddr, error); |
|
|
|
_logger.LogWarning("{EndPointType}端点 {ComAddr} {OperationType}检查失败: {Error}", |
|
|
|
endPointType, comAddr, operationType, error); |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 检查单个端点的状态
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="comAddr">通信地址</param>
|
|
|
|
/// <param name="endPointType">端点类型</param>
|
|
|
|
private async Task<bool> CheckEndPointStatusAsync(string comAddr, string endPointType) |
|
|
|
{ |
|
|
|
return await CheckEndPointAsync(comAddr, endPointType, _appSettings.WebSocketCommands.Stats.ToJson(), "状态"); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 检查单个端点的退出状态
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="comAddr">通信地址</param>
|
|
|
|
/// <param name="endPointType">端点类型</param>
|
|
|
|
private async Task<bool> CheckEndPointQuitAsync(string comAddr, string endPointType) |
|
|
|
{ |
|
|
|
return await CheckEndPointAsync(comAddr, endPointType, _appSettings.WebSocketCommands.Quit.ToJson(), "退出状态"); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 检查 RAN 端点退出状态
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="ranEndPoint">RAN 端点信息</param>
|
|
|
|
/// <returns>是否成功退出</returns>
|
|
|
|
public async Task<bool> CheckRanQuitAsync(RanIPEndPoint ranEndPoint) |
|
|
|
{ |
|
|
|
if (ranEndPoint == null) |
|
|
|
{ |
|
|
|
_logger.LogWarning("RAN 端点未配置"); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
return await CheckEndPointQuitAsync(ranEndPoint.ComAddr, "RAN"); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
_logger.LogError(ex, "检查 RAN 端点退出状态失败"); |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|