Skip to content

Commit fa30c2d

Browse files
committed
Merge pull request #17 from merbla/dev
Epoch change from #15. Added build file.
2 parents 519e217 + e284f1d commit fa30c2d

File tree

6 files changed

+79
-6
lines changed

6 files changed

+79
-6
lines changed

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ image: Visual Studio 2015
33
configuration: Release
44
install:
55
- ps: mkdir -Force ".\build\" | Out-Null
6-
- ps: Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/install.ps1" -OutFile ".\build\installcli.ps1"
6+
- ps: Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/dotnet-install.ps1" -OutFile ".\build\installcli.ps1"
77
- ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetcli"
88
- ps: '& .\build\installcli.ps1 -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath'
99
- ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path"

build.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
dotnet restore
3+
for path in src/*/project.json; do
4+
dirname="$(dirname "${path}")"
5+
dotnet build ${dirname} -c Release
6+
done
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2016 Serilog Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace Serilog.Sinks.Splunk
16+
{
17+
using System;
18+
19+
internal static class EpochExtensions
20+
{
21+
private static DateTimeOffset Epoch = new DateTimeOffset(1970,1,1,0,0,0,TimeSpan.Zero);
22+
23+
public static double ToEpoch(this DateTimeOffset value)
24+
{
25+
// From Splunk HTTP Collector Protocol
26+
// The default time format is epoch time format, in the format <sec>.<ms>.
27+
// For example, 1433188255.500 indicates 1433188255 seconds and 500 milliseconds after epoch,
28+
// or Monday, June 1, 2015, at 7:50:55 PM GMT.
29+
// See: http://dev.splunk.com/view/SP-CAAAE6P
30+
31+
return Math.Round((value - Epoch).TotalSeconds, 3, MidpointRounding.AwayFromZero);
32+
}
33+
}
34+
}

src/Serilog.Sinks.Splunk/Sinks/Splunk/EventCollectorClient.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// Copyright 2016 Serilog Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
116
using System;
217
using System.Net.Http;
318
using System.Net.Http.Headers;

src/Serilog.Sinks.Splunk/Sinks/Splunk/EventCollectorRequest.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// Copyright 2016 Serilog Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
116
using System;
217
using System.Net.Http;
318
using System.Text;
@@ -8,7 +23,7 @@ internal class SplunkEvent
823
{
924
private string _payload;
1025

11-
internal SplunkEvent(string logEvent, string source, string sourceType, string host, string index)
26+
internal SplunkEvent(string logEvent, string source, string sourceType, string host, string index, double time)
1227
{
1328
_payload = string.Empty;
1429

@@ -32,6 +47,11 @@ internal SplunkEvent(string logEvent, string source, string sourceType, string h
3247
jsonPayLoad = jsonPayLoad + @",""index"":""" + index + @"""";
3348
}
3449

50+
if (time > 0)
51+
{
52+
jsonPayLoad = jsonPayLoad + @",""time"":" + time;
53+
}
54+
3555
jsonPayLoad = jsonPayLoad + "}";
3656
_payload = jsonPayLoad;
3757
}
@@ -46,10 +66,9 @@ internal class EventCollectorRequest : HttpRequestMessage
4666
{
4767
internal EventCollectorRequest(string splunkHost, string jsonPayLoad)
4868
{
49-
var hostUrl = $@"{splunkHost}/services/collector/event";
5069

5170
var stringContent = new StringContent(jsonPayLoad, Encoding.UTF8, "application/json");
52-
RequestUri = new Uri(hostUrl);
71+
RequestUri = new Uri(splunkHost);
5372
Content = stringContent;
5473
Method = HttpMethod.Post;
5574
}

src/Serilog.Sinks.Splunk/Sinks/Splunk/EventCollectorSink.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
// Copyright 2016 Serilog Contributors
32
//
43
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -180,7 +179,7 @@ private async Task Send(IEnumerable<LogEvent> events)
180179

181180
var serialisedEvent = sw.ToString();
182181

183-
var splunkEvent = new SplunkEvent(serialisedEvent, _source, _sourceType, _host, _index);
182+
var splunkEvent = new SplunkEvent(serialisedEvent, _source, _sourceType, _host, _index, logEvent.Timestamp.ToEpoch());
184183

185184
allEvents = $"{allEvents}{splunkEvent.Payload}";
186185
}

0 commit comments

Comments
 (0)