private async void TrapMessageReceived(object sender, TrapV2MessageReceivedEventArgs e) { using var scope = _serviceProvider.CreateScope(); var store = scope.ServiceProvider.GetRequiredService <ISNMPMessageStore>(); _logger.LogInformation("TRAP version {0}: {1}", e.TrapV2Message.Version, e.TrapV2Message); var message = new SNMPMessage { Type = SNMPMessageType.TRAP, Version = (Data.Models.VersionCode)e.TrapV2Message.Version, TimeStamp = e.TrapV2Message.TimeStamp, ContextName = e.TrapV2Message.Scope.ContextName.ToString(), MessageId = e.TrapV2Message.Header.MessageId, Enterprise = e.TrapV2Message.Enterprise.ToString(), UserName = e.TrapV2Message.Parameters.UserName.ToString() }; foreach (var variable in e.TrapV2Message.Variables()) { message.Variables.Add(new SNMPMessageVariable { VariableId = variable.Id.ToString(), Value = variable.Data.ToString() }); } await store.Add(message); }
private static void WatcherTrapV2Received(object sender, TrapV2MessageReceivedEventArgs e) { Console.WriteLine("TRAP version {0}: {1}", e.TrapV2Message.Version, e.TrapV2Message); foreach (var variable in e.TrapV2Message.Variables()) { Console.WriteLine(variable); } }
private static void TrapV2Received(object sender, TrapV2MessageReceivedEventArgs e) { _context.Post(delegate { if (!_closed) { var pdu = e.TrapV2Message.Pdu(); //if (pdu.ErrorStatus.ToInt32() == 0) { foreach (var v in pdu.Variables) { TrapReceived(v.Id.ToString(), v.Data, e.Sender); } } } }, "SnmpAgent.TrapV2Received"); }
private async void TrapMessageReceived(object sender, TrapV2MessageReceivedEventArgs e) { try { using var scope = _serviceProvider.CreateScope(); var store = scope.ServiceProvider.GetRequiredService <ISNMPMessageStore>(); _logger.LogInformation("TRAP version {0}: {1}", e.TrapV2Message.Version, e.TrapV2Message); var message = new SNMPMessage { Type = SNMPMessageType.TRAP, Version = (VersionCode)e.TrapV2Message.Version, TimeStamp = e.TrapV2Message.TimeStamp, ContextName = e.TrapV2Message.Scope?.ContextName?.ToString() ?? "", MessageId = e.TrapV2Message.Header?.MessageId ?? 0, Enterprise = e.TrapV2Message.Enterprise?.ToString() ?? "", UserName = e.TrapV2Message.Parameters?.UserName?.ToString() ?? "" }; foreach (var variable in e.TrapV2Message.Variables()) { message.Variables.Add(new SNMPMessageVariable { VariableId = variable.Id?.ToString() ?? "", Value = variable.Data?.ToString() ?? "" }); } await store.Add(message); } catch (Exception exception) { _logger.LogError(exception.Message); } }
private static void WatcherTrapV2Received(object sender, TrapV2MessageReceivedEventArgs e) { Console.WriteLine(e.TrapV2Message); }
private void ListenerTrapV2Received(object sender, TrapV2MessageReceivedEventArgs e) { LogMessage(string.Format(CultureInfo.InvariantCulture, StrSends, DateTime.Now, e.Sender, e.TrapV2Message.ToString(Objects))); }