Splunk Dev

How do I connect to Splunk using C# SDK?

japeter89
New Member

I went to this link http://dev.splunk.com/view/csharp-sdk/SP-CAAAEQE
and I need help with each step. I do not know how to create an instance of the service args class. I don't know where to write all of this. Which file do I use?

Tags (4)
0 Karma

szymon_cwieka
Explorer

Well, basicly it sounds like you in general need to sharp your c# 😉
I hope you are using visual studio.

But i'll do all i can.

using Splunk;//<-- this is on top of all your program

/// <summary>
/// An example program to authenticate to the server 
/// and print the received token.
/// </summary>
public class Program
{
    public static void Main()
    {
        // Create new ServiceArgs object to store 
        // connection info
        var connectArgs = new ServiceArgs
        {
            Host = "localhost", //<-- here you write ip of your splunk server. If you have it on your local computer then it's 127.0.0.1
            Port = 8089 //<-- if you haven't change it on your splunk server, then it stay as it is.
            Scheme = "https" //<-- it is my guess. But might be "http".
            // See ServiceArgs documentation for full
            // list of properties
        };

        // Create new Service object
        Service service = new Service(connectArgs);

        // Use the Login method to connect
        service.Login("admin", "changeme"); //<-- those are just login/password. Same as you login to your splunk server.

        //if you are using console application, then this might stay as it is. If you are using forms, then i suggest using MessageBox.Show instead of System.Console.WriteLine.
        // Print received token to verify login
        System.Console.WriteLine("Token: ");
        System.Console.WriteLine(" " + service.Token);
        //use code above or below
        MessageBox.Show("My login token is:" + Environment.NewLine + service.Token);// <-- like this.
    }
}

If there will pop up window with strange numbers and letters, then you are logged in. What you want to do with it is up to you 🙂 Good luck!

Cheers!

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...