using System; using System.Net.Http; namespace EonaCat.Logger.SplunkServer { // This file is part of the EonaCat project(s) which is released under the Apache License. // See the LICENSE file or go to https://EonaCat.com/License for full license details. /// /// Splunk Server. /// public class SplunkServer { /// /// SplunkHecUrl /// public string SplunkHecUrl { get { return _splunkHecUrl; } set { if (!string.IsNullOrWhiteSpace(_splunkHecUrl) && !_splunkHecUrl.ToLower().Contains("http")) { value = $"http://{value}"; } _splunkHecUrl = value; } } public bool IsHttpsHecUrl => HasHecUrl && _splunkHecUrl.ToLower().StartsWith("https"); /// /// SplunkHecToken /// public string SplunkHecToken { get { return _splunkHecToken; } set { _splunkHecToken = value; } } public HttpClientHandler SplunkClientHandler { get; internal set; } internal readonly object SendLock = new object(); private string _splunkHecUrl = "https://127.0.0.1:8088/services/collector"; private string _splunkHecToken = "splunk-hec-token"; public bool HasHecToken => !string.IsNullOrWhiteSpace(SplunkHecToken) && SplunkHecToken != "splunk-hec-token"; public bool HasHecUrl => !string.IsNullOrWhiteSpace(SplunkHecUrl); public bool IsLocalHost => HasHecUrl && (SplunkHecUrl.ToLower().Contains("127.0.0.1") || SplunkHecUrl.ToLower().Contains("localhost")); /// /// Instantiate the object. /// /// splunkHecUrl. /// splunkHecToken. /// httpClientHandler. (optional) public SplunkServer(string splunkHecUrl, string splunkHecToken, HttpClientHandler httpClientHandler = null) { SplunkHecUrl = splunkHecUrl; SplunkHecToken = splunkHecToken; SplunkClientHandler = httpClientHandler; } /// /// Disables SSL validation (can be used for insecure https urls) /// This overwrites your own httpClientHandler /// public void DisableSSLValidation() { HttpClientHandler clientHandler = new HttpClientHandler() { ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true }; SplunkClientHandler = clientHandler; } } }