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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...