async Task CanConstructConfiguration() { var feed = await TestAtomFeed.ReadFeed(Path.Combine(TestAtomFeed.Directory, "Configuration.GetAsync.xml")); using (var context = new Context(Scheme.Https, "localhost", 8089)) { var expectedConfigurationStanzaNames = new string[] { "default", "email", "populate_lookup", "rss", "script", "summary_index" }; var configuration = new Configuration(context, feed); Assert.Equal(expectedConfigurationStanzaNames, from configurationStanza in configuration select configurationStanza.Title); Assert.Equal(expectedConfigurationStanzaNames.Length, configuration.Count); for (int i = 0; i < configuration.Count; i++) { Assert.Equal(expectedConfigurationStanzaNames[i], configuration[i].Title); Assert.DoesNotThrow(() => { var value = configuration[i].GeneratorVersion; }); Assert.DoesNotThrow(() => { var value = configuration[i].Id; }); Assert.DoesNotThrow(() => { var value = configuration[i].Updated; }); Assert.Equal(0, configuration[i].Count); Assert.Throws<ArgumentOutOfRangeException>(() => { var value = configuration[i][0]; }); } } }
/// <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()); }
async Task CanConstructApplicationCollection() { var feed = await TestAtomFeed.ReadFeed(Path.Combine(TestAtomFeed.Directory, "ApplicationCollection.GetAsync.xml")); using (var context = new Context(Scheme.Https, "localhost", 8089)) { var expectedApplicationNames = new string[] { "delete-me-cc314e4eda254dec885f9465e55729e5", "delete-me-db1bc2678174495a9f91d0c2360f53bc", "delete-me-decd5a97569440768914cd0629c5501d", "delete-me-e341f711346a4898b15accd7f77c5c92", "framework", "gettingstarted", "introspection_generator_addon", "launcher", "learned", "legacy", "sample_app", "search", "splunk_datapreview", "SplunkForwarder", "SplunkLightForwarder" }; var applications = new ApplicationCollection(context, feed); Assert.Equal(expectedApplicationNames, from application in applications select application.Title); Assert.Equal(expectedApplicationNames.Length, applications.Count); for (int i = 0; i < applications.Count; i++) { Assert.Equal(expectedApplicationNames[i], applications[i].Title); Assert.DoesNotThrow(() => { Version value = applications[i].GeneratorVersion; Assert.NotNull(value); }); Assert.DoesNotThrow(() => { Uri value = applications[i].Id; Assert.NotNull(value); }); Assert.DoesNotThrow(() => { string value = applications[i].Title; Assert.NotNull(value); }); Assert.DoesNotThrow(() => { DateTime value = applications[i].Updated; Assert.NotEqual(DateTime.MinValue, value); }); } } }
async Task CanConstructApplication() { var feed = await TestAtomFeed.ReadFeed(Path.Combine(TestAtomFeed.Directory, "Application.GetAsync.xml")); using (var context = new Context(Scheme.Https, "localhost", 8089)) { Assert.DoesNotThrow(() => new Application(context, feed)); } }
/// <summary> /// Initializes a new instance of the <see cref="Service"/> class. /// </summary> /// <param name="context"> /// The context for requests by the new <see cref="Service"/>. /// </param> /// <param name="namespace"> /// The namespace for requests by the new <see cref="Service"/>. The /// default value is <c>null</c> indicating that <see cref= /// "Namespace.Default"/> should be used. /// </param> /// <exception cref="ArgumentNullException"> /// <see cref="context"/> is <c>null</c>. /// </exception> public Service(Context context, Namespace @namespace = null) { Contract.Requires<ArgumentNullException>(context != null, "context"); this.context = context; this.@namespace = @namespace ?? Namespace.Default; this.receiver = new Receiver(context, this.Namespace); this.server = new Server(context, this.Namespace); }
public async Task CanConstructResource() { var feed = await TestAtomFeed.ReadFeed(Path.Combine(TestAtomFeed.Directory, "JobCollection.GetAsync.xml")); using (var context = new Context(Scheme.Https, "localhost", 8089)) { dynamic collection = new ResourceCollection(feed); CheckCommonStaticPropertiesOfResource(collection); //// Static property checks Assert.Equal("jobs", collection.Title); Assert.Throws<RuntimeBinderException>(() => { var p = collection.Links; }); Assert.Throws<RuntimeBinderException>(() => { var p = collection.Messages; }); Assert.DoesNotThrow(() => { Pagination p = collection.Pagination; Assert.Equal(14, p.TotalResults); Assert.Equal(0, p.StartIndex); Assert.Equal(0, p.ItemsPerPage); }); Assert.DoesNotThrow(() => { ReadOnlyCollection<Resource> p = collection.Resources; Assert.Equal(14, p.Count); }); foreach (var resource in collection.Resources) { CheckCommonStaticPropertiesOfResource(resource); CheckExistenceOfJobProperties(resource); Assert.IsType(typeof(Resource), resource); } { dynamic resource = collection.Resources[0]; CheckCommonStaticPropertiesOfResource(resource); Assert.IsType(typeof(Uri), resource.Id); Assert.Equal("https://localhost:8089/services/search/jobs/scheduler__admin__search__RMD50aa4c13eb03d1730_at_1401390000_866", resource.Id.ToString()); Assert.IsType(typeof(string), resource.Content.Sid); Assert.Equal("scheduler__admin__search__RMD50aa4c13eb03d1730_at_1401390000_866", resource.Content.Sid); Assert.IsType(typeof(string), resource.Title); Assert.Equal("search search index=_internal | head 1000", resource.Title); Assert.NotNull(resource.Links); Assert.IsType(typeof(ReadOnlyDictionary<string, Uri>), resource.Links); Assert.Equal(new string[] { "alternate", "search.log", "events", "results", "results_preview", "timeline", "summary", "control" }, resource.Links.Keys); CheckExistenceOfJobProperties(resource); } } }
void CanConstructServer() { using (var context = new Context(Scheme.Https, "localhost", 8089)) { var server = new Server(context, Namespace.Default); Assert.Equal(Pagination.None, server.Messages.Pagination); Assert.Equal(0, server.Messages.Count); } }
/// <summary> /// Creates an instance of the SplunkViaHttp context /// </summary> public SplunkContext(Context context, string index, string username, string password, Namespace resourceNamespace = null, TransmitterArgs transmitterArgs = null) :base(context.Scheme, context.Host, context.Port) { Index = index; Username = username; Password = password; ResourceNamespace = resourceNamespace; TransmitterArgs = transmitterArgs; }
/// <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; }
static void Main() { ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true; //Generally it is not advised to log to Splunk via HTTP/HTTPS due to volume of data //This is available for mobile apps and other special cases. const string host = "127.0.0.1"; //Only used for HTTP/HTTPS scenarios var generalSplunkContext = new Context(Scheme.Https, host, 8089); var transmitterArgs = new TransmitterArgs { Source = "Splunk.Sample", SourceType = "Splunk Sample Source" }; const string username = "******"; const string password = "******"; const string splunkIndex = "mysplunktest"; var serilogContext = new SplunkContext(generalSplunkContext, splunkIndex, username, password, null, transmitterArgs); Log.Logger = new LoggerConfiguration() .Enrich.With(new ThreadIdEnricher()) .Enrich.WithMachineName() .WriteTo.ColoredConsole() .WriteTo.SplunkViaHttp(serilogContext, 10, TimeSpan.FromSeconds(5)) //See http://docs.splunk.com/Documentation/Splunk/6.1.3/Data/Monitornetworkports .WriteTo.SplunkViaUdp(host, 10000) .WriteTo.SplunkViaTcp(host, 10001) .CreateLogger(); var serilogLogger = Log.ForContext <Program>(); serilogLogger.Information("Hello from Serilog, running as {Username}!", Environment.UserName); var items = Enumerable.Range(1, 1000); foreach (var item in items) { serilogLogger.Information("Logging an int, what fun {Item}", item); } Console.WriteLine("OK"); Console.ReadLine(); }
/// <summary> /// Adds a sink that writes log events as to a Splunk instance via http. /// </summary> /// <param name="loggerConfiguration">The logger configuration.</param> /// <param name="context">The Splunk context to log to</param> /// <param name="password"></param> /// <param name="resourceNameSpace"></param> /// <param name="transmitterArgs"></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="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param> /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> /// <param name="index"></param> /// <param name="userName"></param> /// <returns>Logger configuration, allowing configuration to continue.</returns> /// <exception cref="ArgumentNullException">A required parameter is null.</exception> /// <remarks>TODO: Add link to splunk configuration and wiki</remarks> public static LoggerConfiguration SplunkViaHttp( this LoggerSinkConfiguration loggerConfiguration, Context context, string index, string userName, string password, int batchSizeLimit, TimeSpan batchInterval, Namespace resourceNameSpace, TransmitterArgs transmitterArgs, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, IFormatProvider formatProvider = null) { var sink = new SplunkViaHttpSink(new SplunkContext(context, index, userName, password, resourceNameSpace, transmitterArgs), batchSizeLimit,batchInterval, formatProvider); return loggerConfiguration.Sink(sink, restrictedToMinimumLevel); }
/// <summary> /// Adds a sink that writes log events as to a Splunk instance via http. /// </summary> /// <param name="loggerConfiguration">The logger configuration.</param> /// <param name="context">The Splunk context to log to</param> /// <param name="password">The password of the Splunk user</param> /// <param name="resourceNameSpace"></param> /// <param name="transmitterArgs"></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="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param> /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> /// <param name="index">The name of the Splunk index</param> /// <param name="userName">The name of the Splunk user</param> /// <param name="renderTemplate">If ture, the message template is rendered</param> /// <returns>Logger configuration, allowing configuration to continue.</returns> /// <exception cref="ArgumentNullException">A required parameter is null.</exception> /// <remarks>TODO: Add link to splunk configuration and wiki</remarks> public static LoggerConfiguration SplunkViaHttp( this LoggerSinkConfiguration loggerConfiguration, Splunk.Client.Context context, string index, string userName, string password, int batchSizeLimit, TimeSpan batchInterval, Namespace resourceNameSpace, TransmitterArgs transmitterArgs, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, IFormatProvider formatProvider = null, bool renderTemplate = true) { var sink = new SplunkViaHttpSink(new SplunkContext(context, index, userName, password, resourceNameSpace, transmitterArgs), batchSizeLimit, batchInterval, formatProvider); return(loggerConfiguration.Sink(sink, restrictedToMinimumLevel)); }
async Task CanConstructServerSettings() { var feed = await TestAtomFeed.ReadFeed(Path.Combine(TestAtomFeed.Directory, "ServerSettings.GetAsync.xml")); using (var context = new Context(Scheme.Https, "localhost", 8089)) { var serverSettings = new ServerSettings(feed); //// TODO: Match contents of feed to contents of resource; in this case serverInfo Assert.DoesNotThrow(() => { bool canList = serverSettings.Eai.Acl.CanList; string app = serverSettings.Eai.Acl.App; dynamic eai = serverSettings.Eai; Assert.Equal(app, eai.Acl.App); Assert.Equal(canList, eai.Acl.CanList); }); } }
/// <summary> /// Initializes a new instance of the <see cref="Server"/> class. /// </summary> /// <param name="context"> /// An object representing a Splunk server session. /// </param> /// <param name="ns"> /// An object identifying a Splunk services namespace. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="context"/> or <paramref name="ns"/> are <c>null</c>. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="ns"/> is not specific. /// </exception> internal Server(Context context, Namespace ns) : base(context, ns, ClassResourceName) { this.messages = new ServerMessageCollection(context, ns); }
async Task CanConstructConfigurationCollection() { var feed = await TestAtomFeed.ReadFeed(Path.Combine(TestAtomFeed.Directory, "ConfigurationCollection.GetAsync.xml")); using (var context = new Context(Scheme.Https, "localhost", 8089)) { var expectedConfigurationNames = new string[] { "alert_actions", "app", "audit", "authentication", "authorize", "commands", "conf", "crawl", "datatypesbnf", "default-mode", "delete-me-0af59d05d0124e4ab915398500a45262", "delete-me-1c58e9c0851d435aba8b5c53b0c73959", "delete-me-233bbea06392457c9f38b629a912baff", "delete-me-24d778d67e7b4f4e9704c8118e9cbc75", "delete-me-2a38f8d7bfa542c9a09b201ee29da2a8", "delete-me-2f884142c52b4c0883399dfa30fff5bf", "delete-me-3322c0339fb849d98605559cf119a369", "delete-me-33bc32518a364599a08d4bfb226a0975", "delete-me-35a847f36e8a491d962d04a037310dfd", "delete-me-42cecdc8e72f4645b75616c94cd93399", "delete-me-446ee1261b424ae3aec66b67e391df69", "delete-me-4d5457f77b6d49479d518cc4204f300d", "delete-me-59aa7746422549368e550e1bded488af", "delete-me-6d374e8b93014515b506918ada66026e", "delete-me-6d4d46fe88f0444cb330f2a6f022477a", "delete-me-71e7fd0fc0fc420e9dd034a3fd6ae989", "delete-me-7311a03780674f5dbff082fe5f09b458", "delete-me-7a48db483d73412480efd9883af53001", "delete-me-7a4ad0da232f45dab041343c2235a5b0", "delete-me-980b1cb1b2f34884a972ed8bf0c680e2", "delete-me-9940cceaeaf74309b415c43e648ff9eb", "delete-me-9bd517dbec464d32a3b0b51f79bcdad9", "delete-me-9d0b6101094141eab7a69d0daabdce76", "delete-me-9fd99ef85a3641b09a2d5a512bc692c0", "delete-me-a017f23857f14f9fa66e060fbdbd0b37", "delete-me-a5999e197618423ab0c9afffd052c7a9", "delete-me-b8b05d95822a4552bc9c67f863975f0f", "delete-me-c5c6edfa1ccc470981e794d50f2940c6", "delete-me-c6d66b4d921242608962431036860b50", "delete-me-d7e1572f83644e658ccc926c1a736a7f", "delete-me-d8dc0fb200ab4be9862d7e042e919b2c", "delete-me-f8565b63b2af4c0993481440e81ee018", "delete-me-fd46773243cc4b5a8b731483a13e55fb", "distsearch", "event_renderers", "eventdiscoverer", "eventtypes", "fields", "indexes", "inputs", "launcher", "limits", "literals", "lookups", "macros", "manager", "migration", "multikv", "nav", "outputs", "pdf_server", "prefs", "procmon-filters", "props", "quickstart", "restmap", "savedsearches", "searchbnf", "searchscripts", "segmenters", "server", "serverclass", "source-classifier", "sourcetypes", "times", "transactiontypes", "transforms", "ui-prefs", "user-prefs", "views", "viewstates", "web", "workflow_actions" }; var configurations = new ConfigurationCollection(context, feed); Assert.Equal(expectedConfigurationNames, from configuration in configurations select configuration.Title); Assert.Equal(expectedConfigurationNames.Length, configurations.Count); for (int i = 0; i < configurations.Count; i++) { Assert.Equal(expectedConfigurationNames[i], configurations[i].Title); Assert.DoesNotThrow(() => { var value = configurations[i].GeneratorVersion; }); Assert.DoesNotThrow(() => { var value = configurations[i].Id; }); Assert.DoesNotThrow(() => { var value = configurations[i].Updated; }); } } }
/// <summary> /// Initializes a new instance of the <see cref="Transmitter"/> class. /// </summary> /// <param name="context"> /// An object representing a Splunk server session. /// </param> /// /// ### <param name="ns"> /// An object identifying a Splunk services namespace. /// </param> /// ### <param name="name"> /// An object identifying a Splunk resource within <paramref name="ns"/>. /// </param> /// ### <exception cref="ArgumentNullException"> /// <paramref name="context"/> or <paramref name="ns"/> are <c>null</c>. /// </exception> /// ### <exception cref="ArgumentOutOfRangeException"> /// <paramref name="ns"/> is not specific. /// </exception> protected internal Transmitter(Context context) : base(context, Namespace.Default, ClassResourceName) { }
async Task CanConstructConfigurationStanza() { var feed = await TestAtomFeed.ReadFeed(Path.Combine(TestAtomFeed.Directory, "ConfigurationStanza.GetAsync.xml")); using (var context = new Context(Scheme.Https, "localhost", 8089)) { var expectedConfigurationSettingNames = new string[] { "_name", "command", "hostname", "inline", "maxresults", "maxtime", "track_alert", "ttl" }; var configurationStanza = new ConfigurationStanza(context, feed); Assert.Equal(expectedConfigurationSettingNames, from setting in configurationStanza select setting.Title); Assert.Equal(expectedConfigurationSettingNames.Length, configurationStanza.Count); for (int i = 0; i < configurationStanza.Count; i++) { Assert.Equal(expectedConfigurationSettingNames[i], configurationStanza[i].Title); Assert.DoesNotThrow(() => { var value = configurationStanza[i].Id; }); Assert.DoesNotThrow(() => { var value = configurationStanza[i].Links; }); Assert.DoesNotThrow(() => { var value = configurationStanza[i].Updated; }); Assert.DoesNotThrow(() => { var value = configurationStanza[i].Value; }); } } }