/// <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 a new instance of the sink /// </summary> /// <param name="splunkHost">The host of the Splunk instance with the Event collector configured</param> /// <param name="eventCollectorToken">The token to use when authenticating with the event collector</param> /// <param name="uriPath">Change the default endpoint of the Event Collector e.g. services/collector/event</param> /// <param name="batchSizeLimit">The size of the batch when sending to the event collector</param> /// <param name="batchIntervalInSeconds">The interval in seconds that batching should occur</param> /// <param name="jsonFormatter">The text formatter used to render log events into a JSON format for consumption by Splunk</param> /// <param name="messageHandler">The handler used to send HTTP requests</param> public EventCollectorSink( string splunkHost, string eventCollectorToken, string uriPath, int batchIntervalInSeconds, int batchSizeLimit, ITextFormatter jsonFormatter, HttpMessageHandler messageHandler = null) { _uriPath = uriPath; _splunkHost = splunkHost; _queue = new ConcurrentQueue <LogEvent>(); _jsonFormatter = jsonFormatter; _batchSizeLimitLimit = batchSizeLimit; var batchInterval = TimeSpan.FromSeconds(batchIntervalInSeconds); _httpClient = messageHandler != null ? new EventCollectorClient(eventCollectorToken, messageHandler) : new EventCollectorClient(eventCollectorToken); var cancellationToken = new CancellationToken(); RepeatAction.OnInterval( batchInterval, async() => await ProcessQueue(), cancellationToken); }
/// <summary> /// Creates a new instance of the sink /// </summary> /// <param name="splunkHost">The host of the Splunk instance with the Event collector configured</param> /// <param name="eventCollectorToken">The token to use when authenticating with the event collector</param> /// <param name="uriPath">Change the default endpoint of the Event Collector e.g. services/collector/event</param> /// <param name="batchSizeLimit">The size of the batch when sending to the event collector</param> /// <param name="formatProvider">The format provider used when rendering the message</param> /// <param name="renderTemplate">Whether to render the message template</param> /// <param name="batchIntervalInSeconds">The interval in seconds that batching should occur</param> /// <param name="index">The Splunk index to log to</param> /// <param name="source">The source of the event</param> /// <param name="sourceType">The source type of the event</param> /// <param name="host">The host of the event</param> /// <param name="messageHandler">The handler used to send HTTP requests</param> public EventCollectorSink( string splunkHost, string eventCollectorToken, string uriPath, string source, string sourceType, string host, string index, int batchIntervalInSeconds, int batchSizeLimit, IFormatProvider formatProvider = null, bool renderTemplate = true, HttpMessageHandler messageHandler = null) { _uriPath = uriPath; _splunkHost = splunkHost; _queue = new ConcurrentQueue <LogEvent>(); _jsonFormatter = new SplunkJsonFormatter(renderTemplate, formatProvider, source, sourceType, host, index); _batchSizeLimitLimit = batchSizeLimit; var batchInterval = TimeSpan.FromSeconds(batchIntervalInSeconds); _httpClient = messageHandler != null ? new EventCollectorClient(eventCollectorToken, messageHandler) : new EventCollectorClient(eventCollectorToken); var cancellationToken = new CancellationToken(); RepeatAction.OnInterval( batchInterval, async() => await ProcessQueue(), cancellationToken); }
/// <summary> /// Creates a new instance of the sink /// </summary> /// <param name="splunkHost">The host of the Splunk instance with the Event collector configured</param> /// <param name="eventCollectorToken">The token to use when authenticating with the event collector</param> /// <param name="batchSizeLimit">The size of the batch when sending to the event collector</param> /// <param name="formatProvider">The format provider used when rendering the message</param> /// <param name="renderTemplate">Whether to render the message template</param> /// <param name="batchIntervalInSeconds">The interval in seconds that batching should occur</param> public EventCollectorSink( string splunkHost, string eventCollectorToken, int batchIntervalInSeconds = 5, int batchSizeLimit = 100, IFormatProvider formatProvider = null, bool renderTemplate = true ) { _splunkHost = splunkHost; _eventCollectorToken = eventCollectorToken; _queue = new ConcurrentQueue <LogEvent>(); _jsonFormatter = new SplunkJsonFormatter(renderMessage: true, formatProvider: formatProvider, renderTemplate: renderTemplate); _batchSizeLimitLimit = batchSizeLimit; var batchInterval = TimeSpan.FromSeconds(batchIntervalInSeconds); _httpClient = new EventCollectorClient(_eventCollectorToken); var cancellationToken = new CancellationToken(); RepeatAction.OnInterval( batchInterval, async() => await ProcessQueue(), cancellationToken); }