Added StdIn input
This commit is contained in:
@@ -19,6 +19,7 @@ The current supported Input format sources are:
|
||||
2. [Tcp](https://github.com/efontana/TimberWinR/blob/master/TimberWinR/mdocs/TcpInput.md) (listens on a port for JSON messages)
|
||||
3. [IISW3C](https://github.com/efontana/TimberWinR/blob/master/TimberWinR/mdocs/IISW3CInput.md)(Internet Information Services W3C Format)
|
||||
4. [WindowsEvents](https://github.com/efontana/TimberWinR/blob/master/TimberWinR/mdocs/WindowsEvents.md) (Windows Event Viewer)
|
||||
5. [Stdin](https://github.com/efontana/TimberWinR/blob/master/TimberWinR/mdocs/StdInput.md) (Standard Input for Debugging)
|
||||
|
||||
## Filters
|
||||
The current list of supported filters are:
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
{
|
||||
"TimberWinR": {
|
||||
"Inputs": {
|
||||
"Stdin": [
|
||||
{
|
||||
"codec": "json"
|
||||
}
|
||||
],
|
||||
"WindowsEvents": [
|
||||
{
|
||||
"source": "System,Application",
|
||||
|
||||
@@ -58,6 +58,13 @@ namespace TimberWinR
|
||||
get { return _iisw3clogs; }
|
||||
}
|
||||
|
||||
|
||||
private List<Stdin> _stdins = new List<Stdin>();
|
||||
public IEnumerable<Stdin> Stdins
|
||||
{
|
||||
get { return _stdins; }
|
||||
}
|
||||
|
||||
private List<LogstashFilter> _filters = new List<LogstashFilter>();
|
||||
|
||||
public IEnumerable<LogstashFilter> Filters
|
||||
@@ -95,6 +102,8 @@ namespace TimberWinR
|
||||
c._events = x.TimberWinR.Inputs.WindowsEvents.ToList();
|
||||
if (x.TimberWinR.Inputs.IISW3CLogs != null)
|
||||
c._iisw3clogs = x.TimberWinR.Inputs.IISW3CLogs.ToList();
|
||||
if (x.TimberWinR.Inputs.Stdins != null)
|
||||
c._stdins = x.TimberWinR.Inputs.Stdins.ToList();
|
||||
if (x.TimberWinR.Inputs.Logs != null)
|
||||
c._logs = x.TimberWinR.Inputs.Logs.ToList();
|
||||
if (x.TimberWinR.Inputs.Tcps != null)
|
||||
|
||||
48
TimberWinR/Inputs/StdinListener.cs
Normal file
48
TimberWinR/Inputs/StdinListener.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NLog;
|
||||
|
||||
namespace TimberWinR.Inputs
|
||||
{
|
||||
public class StdinListener : InputListener
|
||||
{
|
||||
private Thread _listenThread;
|
||||
|
||||
public StdinListener(CancellationToken cancelToken)
|
||||
: base(cancelToken, "Win32-Console")
|
||||
{
|
||||
_listenThread = new Thread(new ThreadStart(ListenToStdin));
|
||||
_listenThread.Start();
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
}
|
||||
|
||||
private void ListenToStdin()
|
||||
{
|
||||
LogManager.GetCurrentClassLogger().Info("StdIn Ready");
|
||||
|
||||
while (!CancelToken.IsCancellationRequested)
|
||||
{
|
||||
string line = Console.ReadLine();
|
||||
if (line != null)
|
||||
{
|
||||
string msg = ToPrintable(line);
|
||||
JObject jo = new JObject();
|
||||
jo["message"] = msg;
|
||||
ProcessJson(jo);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
Finished();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,6 +107,16 @@ namespace TimberWinR
|
||||
foreach (var output in Outputs)
|
||||
output.Connect(elistner);
|
||||
}
|
||||
|
||||
|
||||
foreach (var tcp in Config.Stdins)
|
||||
{
|
||||
var elistner = new StdinListener(cancelToken);
|
||||
Listeners.Add(elistner);
|
||||
foreach (var output in Outputs)
|
||||
output.Connect(elistner);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -275,6 +275,14 @@ namespace TimberWinR.Parser
|
||||
}
|
||||
}
|
||||
|
||||
public class Stdin : IValidateSchema
|
||||
{
|
||||
public void Validate()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class Log : IValidateSchema
|
||||
{
|
||||
[JsonProperty(PropertyName = "location")]
|
||||
@@ -432,6 +440,9 @@ namespace TimberWinR.Parser
|
||||
|
||||
[JsonProperty("IISW3CLogs")]
|
||||
public IISW3CLog[] IISW3CLogs { get; set; }
|
||||
|
||||
[JsonProperty("Stdin")]
|
||||
public Stdin[] Stdins { get; set; }
|
||||
}
|
||||
|
||||
public partial class Grok : LogstashFilter, IValidateSchema
|
||||
|
||||
@@ -74,6 +74,7 @@
|
||||
<Compile Include="Inputs\InputBase.cs" />
|
||||
<Compile Include="Inputs\InputListener.cs" />
|
||||
<Compile Include="Inputs\ParameterDefinitions.cs" />
|
||||
<Compile Include="Inputs\StdinListener.cs" />
|
||||
<Compile Include="Inputs\TcpInputListener.cs" />
|
||||
<Compile Include="Inputs\LogsListener.cs" />
|
||||
<Compile Include="Inputs\WindowsEvtInputListener.cs" />
|
||||
|
||||
28
TimberWinR/mdocs/StdinInput.md
Normal file
28
TimberWinR/mdocs/StdinInput.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Input: Stdin
|
||||
|
||||
The Stdin Input will read from the console (Console.ReadLine) and build a simple message for testing.
|
||||
|
||||
## Parameters
|
||||
There are no Parameters at this time.
|
||||
|
||||
```json
|
||||
{
|
||||
"TimberWinR": {
|
||||
"Inputs": {
|
||||
"Stdin": [
|
||||
{
|
||||
"_comment": "Read from Console"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
## Fields
|
||||
|
||||
A field: "type": "Win32-Stdin" is automatically appended, and the entire JSON is passed on vertabim
|
||||
| Name | Type | Description |
|
||||
| ---- |:-----| :-----------------------------------------------------------------------|
|
||||
| type | STRING |Win32-Stdin
|
||||
| message | STRING | The message typed in |
|
||||
|
||||
Reference in New Issue
Block a user