Splunk Search

searcing in splunk c# sdk 2.0 freezes

igala123123
New Member

using splunk 6.2 and c# sdk 2.0
first sdk 2.0 wasn't compiling,
there wasn't binaries bundled with it,
also the async api is very clumsy, needs also a sync api option too,

this is what i do:

    public static void Search()
    {
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
        ServicePointManager.ServerCertificateValidationCallback = (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => true;

        using (var service = new Service(Scheme.Https, "server-name", 8089, new Namespace(user: "nobody", app: "search")))
        {
            Run(service).Wait();
        }
    }


    static async Task Run(Service service)
    {
        try
        {
            var logon = service.LogOnAsync("Administrator", GetEncryptedString("AŦ9ɥʹѣզठ5Ŧܱठ"));
            logon.Wait();

            var search =  service.SearchOneShotAsync("search index=myIndex | where field2 == 61C27391748E8C8808AF75D852C4A9012E100722");
            search.Wait();
            SearchResultStream stream = search.Result;

            using (stream)
            {
                    foreach (SearchResult result in stream)
                    {
                    }
            }
        }
        catch (Exception e)
        {
        }
    }

when i call service.SearchOneShotAsync()
or service.Search() and try to get it's results
it freezes

tried sdk 1.0 ,
api seems more comfortable and was compiling,
but it's obsolete, as the rest paths doesn't exists in splunk 6.2 version

so i'm kind of stuck with it
index contains 200 entries so it shouldn't take too long

found some examples of the sdk here
searchcode.com/codesearch/view/90180186

what can i do to fix it?
thanks

0 Karma

igala123123
New Member

i think i found the problem/solution

on the service ctor , i removed the: new Namespace(user: "nobody", app: "search") arg

and
on this line:
var search = service.SearchOneShotAsync("search index=myIndex | where field2 == 61C27391748E8C8808AF75D852C4A9012E100722");

changed to
var search = service.SearchOneShotAsync("search index=myIndex | where field2 == \"61C27391748E8C8808AF75D852C4A9012E100722*\"*"); // escaping with \ "

0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

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