/// <summary> /// Create an instance of the SplunkViaHttp sink. /// </summary> /// <param name="context">Connection info.</param> /// <param name="index">The name of the splunk index to log to</param> /// <param name="userName">The username to authenticate with</param> /// <param name="password">The password to authenticate with</param> /// <param name="batchSizeLimit">The size of the batch prior to logging</param> /// <param name="batchInterval">The interval on which to log via http</param> /// <param name="resourceNamespace">The resource namespaces</param> /// <param name="transmitterArgs">The </param> /// <param name="formatProvider">The format provider to be used when rendering the message</param> public SplunkViaHttpSink( SplunkClient.Context context, string index, string userName, string password, int batchSizeLimit, TimeSpan batchInterval, SplunkClient.Namespace resourceNamespace = null, SplunkClient.TransmitterArgs transmitterArgs = null, IFormatProvider formatProvider = null ) { _index = index; _userName = userName; _password = password; _batchSizeLimit = batchSizeLimit; _transmitterArgs = transmitterArgs; _queue = new ConcurrentQueue <LogEvent>(); _jsonFormatter = new JsonFormatter(renderMessage: true, formatProvider: formatProvider); _service = resourceNamespace == null ? new SplunkClient.Service(context, new SplunkClient.Namespace("nobody", "search")) : new SplunkClient.Service(context, resourceNamespace); RepeatAction.OnInterval(batchInterval, () => ProcessQueue().Wait(), new CancellationToken()); }
/// <summary> /// Creates an instance of the SplunkViaHttp context /// </summary> public SplunkContext(SplunkClient.Context context, string index, string username, string password, SplunkClient.Namespace resourceNamespace = null, SplunkClient.TransmitterArgs transmitterArgs = null) : base(context.Scheme, context.Host, context.Port) { Index = index; Username = username; Password = password; ResourceNamespace = resourceNamespace; TransmitterArgs = transmitterArgs; }
/// <summary> /// Create an instance of the SplunkViaHttp sink. /// </summary> /// <param name="context">Connection info.</param> /// <param name="index">The name of the splunk index to log to</param> /// <param name="userName">The username to authenticate with</param> /// <param name="password">The password to authenticate with</param> /// <param name="batchSizeLimit">The size of the batch prior to logging</param> /// <param name="batchInterval">The interval on which to log via http</param> /// <param name="resourceNamespace">The resource namespaces</param> /// <param name="transmitterArgs">The </param> /// <param name="formatProvider">The format provider to be used when rendering the message</param> public SplunkViaHttpSink( SplunkClient.Context context, string index, string userName, string password, int batchSizeLimit, TimeSpan batchInterval, SplunkClient.Namespace resourceNamespace = null, SplunkClient.TransmitterArgs transmitterArgs = null, IFormatProvider formatProvider = null ) { _index = index; _userName = userName; _password = password; _batchSizeLimit = batchSizeLimit; _transmitterArgs = transmitterArgs; _queue = new ConcurrentQueue<LogEvent>(); _jsonFormatter = new JsonFormatter(renderMessage: true, formatProvider: formatProvider); _service = resourceNamespace == null ? new SplunkClient.Service(context, new SplunkClient.Namespace("nobody", "search")) : new SplunkClient.Service(context, resourceNamespace); RepeatAction.OnInterval(batchInterval, () => ProcessQueue().Wait(), new CancellationToken()); }
/// <inheritdoc/> public virtual async Task <SearchResult> SendAsync(string eventText, string indexName = null, TransmitterArgs args = null) { using (var content = new StringContent(eventText)) { var arguments = Enumerable.Empty <Argument>(); if (indexName != null) { arguments = arguments.Concat(new Argument[] { new Argument("index", indexName) }); } if (args != null) { arguments = arguments.Concat(args); } using (var response = await this.Context.PostAsync(this.Namespace, SimpleReceiver, content, arguments).ConfigureAwait(false)) { await response.EnsureStatusCodeAsync(HttpStatusCode.OK).ConfigureAwait(false); var reader = response.XmlReader; reader.Requires(await reader.MoveToDocumentElementAsync("response").ConfigureAwait(false)); await reader.ReadElementSequenceAsync("results", "result").ConfigureAwait(false); var result = new SearchResult(SearchResultMetadata.Missing); await result.ReadXmlAsync(reader).ConfigureAwait(false); await reader.ReadEndElementSequenceAsync("result", "results", "response").ConfigureAwait(false); return(result); } } }
/// <inheritdoc/> public virtual async Task SendAsync(Stream eventStream, string indexName = null, TransmitterArgs args = null) { using (var content = new StreamContent(eventStream)) { content.Headers.Add("x-splunk-input-mode", "streaming"); var arguments = Enumerable.Empty <Argument>(); if (indexName != null) { arguments = arguments.Concat(new Argument[] { new Argument("index", indexName) }); } if (args != null) { arguments = arguments.Concat(args); } using (var response = await this.Context.PostAsync(this.Namespace, StreamReceiver, content, arguments).ConfigureAwait(false)) { await response.EnsureStatusCodeAsync(HttpStatusCode.NoContent).ConfigureAwait(false); } } }
/// <summary> /// Asynchronously sends a single raw event to Splunk. /// </summary> /// <param name="eventText"> /// Raw event text. /// </param> /// <param name="indexName"> /// Name of the index. /// </param> /// <param name="args"> /// Arguments identifying the event type and destination. /// </param> /// <returns> /// An object representing the event created by Splunk. /// </returns> /// <seealso cref="M:Splunk.Client.ITransmitter.SendAsync(string,string,TransmitterArgs)"/> public Task <SearchResult> SendAsync(string eventText, string indexName = null, TransmitterArgs args = null) { Contract.Requires <ArgumentNullException>(eventText != null); return(default(Task <SearchResult>)); }
/// <summary> /// Asynchronously sends a stream of raw events to Splunk. /// </summary> /// <param name="eventStream"> /// The event stream. /// </param> /// <param name="indexName"> /// Name of the index. /// </param> /// <param name="args"> /// The arguments. /// </param> /// <returns> /// A <see cref="Stream"/> used to send events to Splunk. /// </returns> /// <seealso cref="M:Splunk.Client.ITransmitter.SendAsync(Stream,string,TransmitterArgs)"/> public Task SendAsync(Stream eventStream, string indexName = null, TransmitterArgs args = null) { Contract.Requires <ArgumentNullException>(eventStream != null); return(default(Task)); }