// https://help.ubuntu.com/community/UFW#Interpreting_Log_Entries private void OutputDataReceivedOccured(object sender, DataReceivedEventArgs e) { try { if (string.IsNullOrEmpty(e.Data)) { return; } var packet = new NMS.API.DTO.PacketDroppedEvent(); var timeString = e.Data.Substring(0, 15); var format = "MMM d HH:mm:ss"; DateTimeOffset result; if (DateTimeOffset.TryParseExact(timeString, format, CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out result)) { packet.Time = result; } else { packet.Time = DateTimeOffset.Now; } packet.LocalAddress = MatchAndRetrieve(@"DST=\d+\.\d+\.\d+\.\d+", e.Data); packet.LocalPort = Convert.ToUInt16(MatchAndRetrieve(@"DPT=\d+", e.Data)); packet.RemoteAddress = MatchAndRetrieve(@"SRC=\d+\.\d+\.\d+\.\d+", e.Data); packet.RemotePort = Convert.ToUInt16(MatchAndRetrieve(@"SPT=\d+", e.Data)); Console.WriteLine($"{name}: STDOUT: {packet.ToString()}"); using (NmsApiClient client = new NmsApiClient()) { client.SendEvent(packet).Wait(); } } catch (Exception ex) { Console.WriteLine($"{name}: ERROR in STDOUT: Message: {ex.Message}"); Console.WriteLine($"{name}: ERROR in STDOUT: Message: {e.Data}"); } }
private void OutputDataReceivedOccured(object sender, DataReceivedEventArgs e) { try { if (string.IsNullOrEmpty(e.Data)) { return; } Console.WriteLine($"{name}: STDOUT: {e.Data}"); var parts = e.Data.Split('|'); if (parts.Length < 2) { return; } using (NmsApiClient client = new NmsApiClient()) { client.SendEvent(new NMS.API.DTO.PacketDroppedEvent() { Time = DateTimeOffset.Now, LocalAddress = parts[1], LocalPort = Convert.ToUInt16(parts[3]), RemoteAddress = parts[0], RemotePort = Convert.ToUInt16(parts[2]) }).Wait(); } } catch (Exception ex) { Console.WriteLine($"{name}: ERROR in STDOUT: Message: {ex.Message}"); Console.WriteLine($"{name}: ERROR in STDOUT: Message: {e.Data}"); } }