Splunk Dev

Can someone show an example of sending data through TCP to a Splunk server using the C# SDK?

ConnorG
Path Finder

Could someone show an example of sending data through a TCP connection to a Splunk server using the C# sdk?

There are examples for python and Java, but none for C#.

I'm currently using the event streaming method with receiver.attach, but it's much too slow for my requirements.

Tags (3)
1 Solution

ConnorG
Path Finder

Figured it out. Turned out to be pretty simple to implement. Just have to be sure to set up Splunk for receiving on the specific TCP port.

        oSocket = service.Open(portNumber);
        var bytes = Encoding.UTF8.GetBytes(message);
        oSocket.Send(bytes);

View solution in original post

ConnorG
Path Finder

Figured it out. Turned out to be pretty simple to implement. Just have to be sure to set up Splunk for receiving on the specific TCP port.

        oSocket = service.Open(portNumber);
        var bytes = Encoding.UTF8.GetBytes(message);
        oSocket.Send(bytes);

demodav
Path Finder

@ConnorG Could you post your whole solution?

0 Karma

paulwrussell
Explorer

Has anyone figured out how to do this in C#?

0 Karma

ConnorG
Path Finder

@demodav you can find my solution here:

https://github.com/ConnorRules/Dynatrace-Plugin-Splunk-Forwarder/blob/master/src/com/compuware/Splun...

The parts you'll want to look at in particular are:
line 106 - setting up the login arguments
line 113 - creating a service instance that is connected to the splunk server
line 184 - getting the output stream to a specific index
line 214 - writing to that stream

Should be pretty self explanatory. Let me know if you have any questions.

0 Karma

s2_splunk
Splunk Employee
Splunk Employee

Does the 'submit' example here not meet that need?

ConnorG
Path Finder

The submit example from the SDK is using HTTP Post (REST API) to ship the data. This method is insufficient for moving large amounts of data to the Splunk server.

0 Karma
Get Updates on the Splunk Community!

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...