Exemple #1
0
        /// <summary>
        /// Create an instance of the Splunk sink.
        /// </summary>
        /// <param name="batchSizeLimit">The maximum number of log events to send in a single batch.</param>
        /// <param name="period">The time allowed to elapse before a non-empty buffer of events will be flushed.</param>
        /// <param name="connectionInfo">Connection info.</param>
        public SplunkSink(int batchSizeLimit, TimeSpan period, SplunkConnectionInfo connectionInfo)
            : base(batchSizeLimit, period)
        {
            _connectionInfo = connectionInfo;
            _service = new Service(connectionInfo.ServiceArgs);

            _receiveSubmitArgs = new ReceiverSubmitArgs
            {
                Source = _connectionInfo.SplunkSource,
                SourceType = _connectionInfo.SplunkEventType
            };
        }
Exemple #2
0
        /// <summary>
        /// The main program
        /// </summary>
        /// <param name="argv">The command line arguments</param>
        public static void Main(string[] argv)
        {
            // Load connection info for Splunk server in .splunkrc file.
            var cli = Command.Splunk("submit");
            cli.Parse(argv);
            var service = Service.Connect(cli.Opts);

            var args = new ReceiverSubmitArgs
            {
                Source = "splunk-sdk-tests",
                SourceType = "splunk-sdk-test-event",
            };

            var receiver = new Receiver(service);

            // Submit to default index
            receiver.Submit(args, "Hello World.");
            receiver.Submit(args, "Goodbye world.");
        }
Exemple #3
0
 /// <summary>
 /// Submits the data using HTTP post, using variable arguments to the
 /// default index.
 /// </summary>
 /// <param name="args">The variable arguments.</param>
 /// <param name="data">The data.</param>
 public void Submit(ReceiverSubmitArgs args, string data)
 {
     this.Submit((Args)args, data);
 }
Exemple #4
0
 /// <summary>
 /// Submits the data using HTTP post, using variable arguments to the 
 /// default index.
 /// </summary>
 /// <param name="args">The variable arguments.</param>
 /// <param name="data">The data.</param>
 public void Submit(ReceiverSubmitArgs args, string data)
 {
     this.Submit((Args) args, data);
 }
        public void IndexArgs()
        {
            string indexName = "sdk-tests2";
            DateTimeOffset offset = new DateTimeOffset(DateTime.Now);
            string now = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss") +
                string.Format("{0}{1} ", offset.Offset.Hours.ToString("D2"), offset.Offset.Minutes.ToString("D2"));

            Service service = this.Connect();
            Index index = service.GetIndexes().Get(indexName);

            index.Enable();
            Assert.IsFalse(index.IsDisabled);

            Args indexProperties = GetIndexProperties(index);

            ClearIndex(service, indexName, index);

            // submit event to index using variable arguments
            index.Submit(indexProperties, now + " Hello World. \u0150");
            index.Submit(indexProperties, now + " Goodbye World. \u0150");
            WaitUntilEventCount(index, 2, 45);

            ClearIndex(service, indexName, index);

            // stream event to index with variable arguments
            Stream streamArgs = index.Attach(indexProperties);
            streamArgs.Write(Encoding.UTF8.GetBytes(now + " Hello World again. \u0150\r\n"));
            streamArgs.Write(Encoding.UTF8.GetBytes(now + " Goodbye World again.\u0150\r\n"));
            streamArgs.Close();
            WaitUntilEventCount(index, 2, 45);

            // submit event using ReceiverSubmitArgs
            const string Source = "splunk-sdk-tests";
            const string SourceType = "splunk-sdk-test-event";
            const string Host = "test-host";
            var args = new ReceiverSubmitArgs
            {
                Index = indexName,
                Host = Host,
                Source = Source,
                SourceType = SourceType,
            };
            var receiver = service.GetReceiver();
            receiver.Submit(args, "Hello World.");
            receiver.Submit(args, "Goodbye world.");
            WaitUntilEventCount(index, 4, 45);
            // verify the fields of events in the index matching the args.
            using (var stream =
                service.Oneshot(
                string.Format(
                    "search index={0} host={1} source={2} sourcetype={3}",
                    indexName,
                    Host,
                    Source,
                    SourceType)))
            using (var reader = new ResultsReaderXml(stream))
            {
                Assert.AreEqual(2, reader.Count());
            }

            ClearIndex(service, indexName, index);
            index.Clean(180);
            Assert.AreEqual(0, index.TotalEventCount, "Expected the total event count to be 0");
        }