Added StdIn input

This commit is contained in:
Eric Fontana
2014-07-31 09:37:01 -04:00
parent b761765012
commit dac02cb311
8 changed files with 113 additions and 0 deletions

View File

@@ -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) 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) 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) 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 ## Filters
The current list of supported filters are: The current list of supported filters are:

View File

@@ -1,6 +1,11 @@
{ {
"TimberWinR": { "TimberWinR": {
"Inputs": { "Inputs": {
"Stdin": [
{
"codec": "json"
}
],
"WindowsEvents": [ "WindowsEvents": [
{ {
"source": "System,Application", "source": "System,Application",

View File

@@ -58,6 +58,13 @@ namespace TimberWinR
get { return _iisw3clogs; } get { return _iisw3clogs; }
} }
private List<Stdin> _stdins = new List<Stdin>();
public IEnumerable<Stdin> Stdins
{
get { return _stdins; }
}
private List<LogstashFilter> _filters = new List<LogstashFilter>(); private List<LogstashFilter> _filters = new List<LogstashFilter>();
public IEnumerable<LogstashFilter> Filters public IEnumerable<LogstashFilter> Filters
@@ -95,6 +102,8 @@ namespace TimberWinR
c._events = x.TimberWinR.Inputs.WindowsEvents.ToList(); c._events = x.TimberWinR.Inputs.WindowsEvents.ToList();
if (x.TimberWinR.Inputs.IISW3CLogs != null) if (x.TimberWinR.Inputs.IISW3CLogs != null)
c._iisw3clogs = x.TimberWinR.Inputs.IISW3CLogs.ToList(); 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) if (x.TimberWinR.Inputs.Logs != null)
c._logs = x.TimberWinR.Inputs.Logs.ToList(); c._logs = x.TimberWinR.Inputs.Logs.ToList();
if (x.TimberWinR.Inputs.Tcps != null) if (x.TimberWinR.Inputs.Tcps != null)

View 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();
}
}
}

View File

@@ -107,6 +107,16 @@ namespace TimberWinR
foreach (var output in Outputs) foreach (var output in Outputs)
output.Connect(elistner); 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> /// <summary>

View File

@@ -275,6 +275,14 @@ namespace TimberWinR.Parser
} }
} }
public class Stdin : IValidateSchema
{
public void Validate()
{
}
}
public class Log : IValidateSchema public class Log : IValidateSchema
{ {
[JsonProperty(PropertyName = "location")] [JsonProperty(PropertyName = "location")]
@@ -432,6 +440,9 @@ namespace TimberWinR.Parser
[JsonProperty("IISW3CLogs")] [JsonProperty("IISW3CLogs")]
public IISW3CLog[] IISW3CLogs { get; set; } public IISW3CLog[] IISW3CLogs { get; set; }
[JsonProperty("Stdin")]
public Stdin[] Stdins { get; set; }
} }
public partial class Grok : LogstashFilter, IValidateSchema public partial class Grok : LogstashFilter, IValidateSchema

View File

@@ -74,6 +74,7 @@
<Compile Include="Inputs\InputBase.cs" /> <Compile Include="Inputs\InputBase.cs" />
<Compile Include="Inputs\InputListener.cs" /> <Compile Include="Inputs\InputListener.cs" />
<Compile Include="Inputs\ParameterDefinitions.cs" /> <Compile Include="Inputs\ParameterDefinitions.cs" />
<Compile Include="Inputs\StdinListener.cs" />
<Compile Include="Inputs\TcpInputListener.cs" /> <Compile Include="Inputs\TcpInputListener.cs" />
<Compile Include="Inputs\LogsListener.cs" /> <Compile Include="Inputs\LogsListener.cs" />
<Compile Include="Inputs\WindowsEvtInputListener.cs" /> <Compile Include="Inputs\WindowsEvtInputListener.cs" />

View 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 |