<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Push Splunk events from .NET application in All Apps and Add-ons</title>
    <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Push-Splunk-events-from-NET-application/m-p/35205#M69764</link>
    <description>&lt;P&gt;Honestly, it's probably easier and it will be &lt;EM&gt;far&lt;/EM&gt; more efficient and scalable to just send the events via a plain network port.&lt;/P&gt;</description>
    <pubDate>Mon, 23 Aug 2010 08:05:51 GMT</pubDate>
    <dc:creator>gkanapathy</dc:creator>
    <dc:date>2010-08-23T08:05:51Z</dc:date>
    <item>
      <title>Push Splunk events from .NET application</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Push-Splunk-events-from-NET-application/m-p/35201#M69760</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;

&lt;P&gt;We would like to be able to push Splunk event from a .NET application. There is a JAVA rest API to do the same: &lt;/P&gt;

&lt;P&gt;&lt;A href="http://code.google.com/p/splunk-java-sdk/wiki/UploadingEvents" rel="nofollow"&gt;http://code.google.com/p/splunk-java-sdk/wiki/UploadingEvents&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Does anyone know of an API available to do this with .NET, also I believe this could be achieved using UDP/TCP push from .NET has anyone attempted this? Any examples?&lt;/P&gt;

&lt;P&gt;Thanks,
Josh&lt;/P&gt;</description>
      <pubDate>Sun, 22 Aug 2010 16:03:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Push-Splunk-events-from-NET-application/m-p/35201#M69760</guid>
      <dc:creator>Josh</dc:creator>
      <dc:date>2010-08-22T16:03:34Z</dc:date>
    </item>
    <item>
      <title>Re: Push Splunk events from .NET application</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Push-Splunk-events-from-NET-application/m-p/35202#M69761</link>
      <description>&lt;P&gt;You could just use log4net, or write to a file, or simply open a network socket and send the text over it.&lt;/P&gt;</description>
      <pubDate>Sun, 22 Aug 2010 22:32:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Push-Splunk-events-from-NET-application/m-p/35202#M69761</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2010-08-22T22:32:15Z</dc:date>
    </item>
    <item>
      <title>Re: Push Splunk events from .NET application</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Push-Splunk-events-from-NET-application/m-p/35203#M69762</link>
      <description>&lt;P&gt;Hey guys I figured it out by looking at the Java source code from google.&lt;/P&gt;

&lt;P&gt;You can just post an event in .NET using the REST API by accessing the &lt;/P&gt;

&lt;P&gt;/services/receivers/simple or /services/receivers/stream endpoints.&lt;/P&gt;

&lt;P&gt;An simple example for anyone who is interested:&lt;/P&gt;

&lt;PRE&gt;
using System;
using System.IO;
using System.Net;
using System.Xml;
using System.Web;

namespace SplunkNetClient
{
    class SplunkTestClient
    {

        static XmlDocument executeRequest(string url, string sessionKey, string args, string httpMethod)
        {
            ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
            req.Method = httpMethod;
            if (!string.IsNullOrEmpty(sessionKey))
                req.Headers.Add("Authorization", "Splunk " + sessionKey);

            if (httpMethod == "POST")
            {
                if (!string.IsNullOrEmpty(args)) req.ContentLength = args.Length;
                req.ContentType = "application/x-www-form-urlencoded";
                Stream reqStream = req.GetRequestStream();
                StreamWriter sw = new StreamWriter(reqStream);
                sw.Write(args);
                sw.Close();
            }

            HttpWebResponse res = (HttpWebResponse)req.GetResponse();
            StreamReader sr = new StreamReader(res.GetResponseStream());
            if (sr.EndOfStream) return null;
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(sr);
            sr.Close();
            return xmlDoc;
        }


        static void Main(string[] args)
        {
            string baseurl = "https://localhost:8089";
            string user = "admin";
            string password = "changeme";
            string searchQuery = "host=josh";
            string index = "main";

            // Authenticate on the server and get the session key
            //
            string url = baseurl + "/services/auth/login";
            string reqArgs = string.Format("username={0}&amp;amp;password={1}", user, password);
            XmlDocument doc = executeRequest(url, null, reqArgs, "POST");
            string sessionKey = doc.SelectSingleNode("/response/sessionKey").InnerText;
            Console.WriteLine("Session key: " + sessionKey);

            //Upload an event to splunk
            url = baseurl + "/services/receivers/simple?index=main&amp;amp;sourcetype=wsdl&amp;amp;source=EDiscovery&amp;amp;host=josh";
            reqArgs = string.Format("env={0},url={1},response={2},app={3},version={4}", "\"EDEV\"","\"test\"", "\"200\"","\"dpsapap\"","\"1.0.7.5467\"");
            doc = executeRequest(url, sessionKey, reqArgs, "POST");


            // Dispatch a new search and return search id
            //
            url = baseurl + "/services/search/jobs";
            reqArgs = string.Format("search=search {0}", HttpUtility.UrlPathEncode(searchQuery));
            doc = executeRequest(url, sessionKey, reqArgs, "POST");
            string sid = doc.SelectSingleNode("/response/sid").InnerText;
            Console.WriteLine("Search id: " + sid);

            // Wait for search to finish
            //
            url = baseurl + "/services/search/jobs/" + sid;
            bool isDone = false;
            int eventCount = 0;
            do
            {
                doc = executeRequest(url, sessionKey, null, "GET");
                if (doc == null)
                {
                    System.Threading.Thread.Sleep(200);
                    continue;
                }
                XmlNamespaceManager context = new XmlNamespaceManager(doc.NameTable);
                context.AddNamespace("s", "http://dev.splunk.com/ns/rest");
                context.AddNamespace("feed", "http://www.w3.org/2005/Atom");
                XmlNode ecNode = doc.SelectSingleNode("//feed:entry/feed:content/s:dict/s:key[@name='eventCount'][1]", context);
                eventCount = int.Parse(ecNode.InnerText);
                XmlNode idNode = doc.SelectSingleNode("//feed:entry/feed:content/s:dict/s:key[@name='isDone'][1]", context);
                isDone = idNode.InnerText == "1" ? true : false;
            } while (!isDone);
            Console.WriteLine(string.Format("Search job is done, {0} results found", eventCount));

            // Get search results
            //
            if (eventCount &amp;gt; 0)
            {
                url = string.Format("{0}/services/search/jobs/{1}/results", baseurl, sid);
                doc = executeRequest(url, sessionKey, null, "GET");
                Console.WriteLine("Results: \n" + doc.InnerXml);
            }
            else
            {
                Console.WriteLine("Search returned zero results");
            }
        }
    }
}

&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Aug 2010 07:05:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Push-Splunk-events-from-NET-application/m-p/35203#M69762</guid>
      <dc:creator>Josh</dc:creator>
      <dc:date>2010-08-23T07:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: Push Splunk events from .NET application</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Push-Splunk-events-from-NET-application/m-p/35204#M69763</link>
      <description>&lt;P&gt;Hi yes that is correct, however this particular application is running on hundreds of client machines and collecting logfiles would not be the optimal solution, you could collect logs onto one server and Splunk the logs from ther, but having critical data come from the application itself would be great. Also this opens the door for both Java and .NET application becoming another form of scripted input &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2010 07:08:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Push-Splunk-events-from-NET-application/m-p/35204#M69763</guid>
      <dc:creator>Josh</dc:creator>
      <dc:date>2010-08-23T07:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: Push Splunk events from .NET application</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Push-Splunk-events-from-NET-application/m-p/35205#M69764</link>
      <description>&lt;P&gt;Honestly, it's probably easier and it will be &lt;EM&gt;far&lt;/EM&gt; more efficient and scalable to just send the events via a plain network port.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2010 08:05:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Push-Splunk-events-from-NET-application/m-p/35205#M69764</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2010-08-23T08:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: Push Splunk events from .NET application</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Push-Splunk-events-from-NET-application/m-p/35206#M69765</link>
      <description>&lt;P&gt;This is probably a lot more overhead than you need. All Splunk needs is plain text, either pushed over a plain TCP or UDP port, or read from a file. The REST API is much more expensive on the indexer and will limit scalability (which may not matter if you have low volume). I've never heard of anyone using this, and I can't really imagine many cases where I'd recommend it over a simple plain text socket output.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2010 08:17:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Push-Splunk-events-from-NET-application/m-p/35206#M69765</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2010-08-23T08:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: Push Splunk events from .NET application</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Push-Splunk-events-from-NET-application/m-p/35207#M69766</link>
      <description>&lt;P&gt;Do you have an exaple of how this can be done in .NET?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Sep 2010 01:40:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Push-Splunk-events-from-NET-application/m-p/35207#M69766</guid>
      <dc:creator>Josh</dc:creator>
      <dc:date>2010-09-16T01:40:44Z</dc:date>
    </item>
    <item>
      <title>Re: Push Splunk events from .NET application</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Push-Splunk-events-from-NET-application/m-p/35208#M69767</link>
      <description>&lt;P&gt;If the socket is used, how is it authenticated?&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2012 12:38:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Push-Splunk-events-from-NET-application/m-p/35208#M69767</guid>
      <dc:creator>mosmondor</dc:creator>
      <dc:date>2012-12-03T12:38:34Z</dc:date>
    </item>
  </channel>
</rss>

