Skip to content

Commit 378acd7

Browse files
committed
Initial commit.
0 parents  commit 378acd7

File tree

17 files changed

+1075
-0
lines changed

17 files changed

+1075
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
*.[Rr]e[Ss]harper
2+
*[Rr]e[Ss]harper.user
3+
_[Rr]e[Ss]harper.*/
4+
5+
[Ss]tyle[Cc]op.[Cc]ache
6+
7+
[Dd]ebug/
8+
[Rr]elease/
9+
[Bb]in/
10+
[Oo]bj/
11+
[Bb]uild/
12+
[Dd]ist/
13+
[Cc]lient[Bb]in/
14+
[Pp]ublish/
15+
[Pp]ackages/
16+
17+
*.suo
18+
*.sln.cache
19+
*.user
20+
*.vssscc
21+
*.vspscc
22+
*.[Pp]ublish.xml
23+
24+
[Tt]est[Rr]esults/
25+
[Tt]est[Rr]esult.xml
26+
27+
*.dotCover
28+
*.ndproj
29+
/NDependOut
30+
.idea
31+
.dbshell
32+
/src/web/acord
33+
connections.config
34+
accustat-connections.config
35+
secure.config
36+
web_deploy.pem
37+
accustat-migrations.config
38+
*.vspx
39+
*.psess

SyslogProxy.sln

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.31101.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SyslogProxy", "src\SyslogProxy\SyslogProxy.csproj", "{3845001E-9600-4CB4-A3E9-1D8E3C7AB0F5}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SyslogProxy.UnitTests", "test\SyslogProxy.UnitTests\SyslogProxy.UnitTests.csproj", "{9FA10B4F-A41F-405D-9F82-C440E9478DAB}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{3845001E-9600-4CB4-A3E9-1D8E3C7AB0F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{3845001E-9600-4CB4-A3E9-1D8E3C7AB0F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{3845001E-9600-4CB4-A3E9-1D8E3C7AB0F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{3845001E-9600-4CB4-A3E9-1D8E3C7AB0F5}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{9FA10B4F-A41F-405D-9F82-C440E9478DAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{9FA10B4F-A41F-405D-9F82-C440E9478DAB}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{9FA10B4F-A41F-405D-9F82-C440E9478DAB}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{9FA10B4F-A41F-405D-9F82-C440E9478DAB}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
EndGlobal

SyslogProxy.sln.DotSettings

Lines changed: 581 additions & 0 deletions
Large diffs are not rendered by default.

src/SyslogProxy/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
6+
</configuration>

src/SyslogProxy/Facility.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace SyslogProxy
2+
{
3+
public enum Facility
4+
{
5+
KernelMessages = 0,
6+
UserLevelMessages = 1,
7+
MailSystem = 2,
8+
SystemDaemons = 3,
9+
SecurityOrAuthorizationMessages1 = 4,
10+
InternalMessages = 5,
11+
LinePrinterSubsystem = 6,
12+
NetworkNewsSubsystem = 7,
13+
UUCPSubsystem = 8,
14+
ClockDaemon1 = 9,
15+
SecurityOrAuthorizationMessages2 = 10,
16+
FTPDaemon = 11,
17+
NTPSubsystem = 12,
18+
LogAudit = 13,
19+
LogAlert = 14,
20+
ClockDaemon2 = 15,
21+
LocalUse0 = 16,
22+
LocalUse1 = 17,
23+
LocalUse2 = 18,
24+
LocalUse3 = 19,
25+
LocalUse4 = 20,
26+
LocalUse5 = 21,
27+
LocalUse6 = 22,
28+
LocalUse7 = 23
29+
}
30+
}

src/SyslogProxy/Program.cs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
namespace SyslogProxy
2+
{
3+
using System;
4+
using System.Net;
5+
using System.Net.Http;
6+
using System.Net.Sockets;
7+
using System.Text;
8+
using System.Threading;
9+
using System.Threading.Tasks;
10+
11+
public class Program
12+
{
13+
static void Main(string[] args)
14+
{
15+
var tcp = new TcpListener(IPAddress.Any, 6514);
16+
17+
tcp.Start();
18+
AcceptConnection(tcp);
19+
while (true)
20+
{
21+
Thread.Sleep(10000);
22+
}
23+
}
24+
25+
static async Task AcceptConnection(TcpListener listener)
26+
{
27+
while (true)
28+
{
29+
var client = await listener.AcceptTcpClientAsync().ConfigureAwait(false);
30+
EchoAsync(client);
31+
}
32+
}
33+
34+
static async Task EchoAsync(TcpClient client)
35+
{
36+
Console.WriteLine("New client connected.");
37+
using (client)
38+
{
39+
var buf = new byte[4096];
40+
var stream = client.GetStream();
41+
while (true)
42+
{
43+
var timeoutTask = Task.Delay(TimeSpan.FromSeconds(15));
44+
var amountReadTask = stream.ReadAsync(buf, 0, buf.Length);
45+
var completedTask = await Task.WhenAny(timeoutTask, amountReadTask)
46+
.ConfigureAwait(false);
47+
if (completedTask == timeoutTask)
48+
{
49+
Console.WriteLine("Client timed out");
50+
break;
51+
}
52+
53+
var amountRead = amountReadTask.Result;
54+
if (amountRead == 0) break; //end of stream.
55+
// stuff buff into a json thing
56+
await WriteToSeq(new SyslogJson(Encoding.UTF8.GetString(buf).TrimEnd('\0')));
57+
}
58+
}
59+
Console.WriteLine("Client disconnected");
60+
}
61+
62+
public static async Task WriteToSeq(SyslogJson syslog)
63+
{
64+
using (var http = new HttpClient())
65+
{
66+
using (var content = new StringContent("{\"events\":[" +syslog.ToString() + "]}", Encoding.UTF8, "application/json"))
67+
{
68+
var response = await http.PostAsync("http://10.2.10.156:5341/api/events/raw", content);
69+
if (!response.IsSuccessStatusCode)
70+
{
71+
Console.WriteLine("ERROR: Could not send to SEQ.");
72+
}
73+
}
74+
}
75+
}
76+
}
77+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("AccuAgency.SyslogProxy")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("AccuAgency.SyslogProxy")]
13+
[assembly: AssemblyCopyright("Copyright © 2015")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("91b6d5b5-9bcf-45f3-a399-b103fe9bc30f")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

src/SyslogProxy/SeqEvent.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace SyslogProxy
2+
{
3+
public class SeqEvent
4+
{
5+
public string Timestamp { get; set; }
6+
7+
public string Level { get; set; }
8+
9+
public object Properties { get; set; }
10+
11+
public string MessageTemplate { get; set; }
12+
}
13+
}

src/SyslogProxy/Severity.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace SyslogProxy
2+
{
3+
public enum Severity
4+
{
5+
Emergency = 0,
6+
Alert = 1,
7+
Critical = 2,
8+
Error = 3,
9+
Warning = 4,
10+
Notice = 5,
11+
Informational = 6,
12+
Debug = 7
13+
}
14+
}

0 commit comments

Comments
 (0)