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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Introducing Splunk 10.0: Smarter, Faster, and More Powerful Than Ever

Now On Demand Whether you're managing complex deployments or looking to future-proof your data ...