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!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...