/// <summary> /// Creates a new Nulunk instance. /// </summary> public Nulunk(string sourceType = "nulunk", int forceFlushCount = 100) { _cqueue = new ConcurrentQueue<string>(); _args = new Args(); Command cli = Command.Splunk("search"); _service = Service.Connect(cli.Opts); _receiver = new Receiver(_service); _args.Add("sourcetype", sourceType); _forceFlushCount = forceFlushCount; }
/// <summary> /// Initializes a new instance of the <see cref="Resource"/> class, /// adding optional arguments for namespace and other endpoint /// arguments. /// </summary> /// <param name="service">The service.</param> /// <param name="path">The path of this resource.</param> /// <param name="args">The variable arguments.</param> public Resource(Service service, string path, Args args) { this.Service = service; /* Pull out namespace items (app, owner, sharing) from the args, and * then use to create the full path. */ Args clonedArgs = new Args(args); Args splunkNamespace = new Args(); if (args.ContainsKey("app")) { splunkNamespace.Set("app", args["app"].ToString()); clonedArgs.Remove("app"); } if (args.ContainsKey("owner")) { splunkNamespace.Set("owner", args["owner"].ToString()); clonedArgs.Remove("owner"); } if (args.ContainsKey("sharing")) { splunkNamespace.Set( "sharing", args["sharing"].ToString()); clonedArgs.Remove("sharing"); } if (!clonedArgs.ContainsKey("count")) { clonedArgs.Set("count", "-1"); } this.RefreshArgs = clonedArgs; this.Path = service.Fullpath( path, splunkNamespace.Count == 0 ? null : splunkNamespace); this.MaybeValid = false; }
public bool Connect(string hostname, string username, string pass) { // Create new ServiceArgs object to store // connection info var connectArgs = new ServiceArgs { Host = hostname, Port = 8089 }; service = new Service(connectArgs); // Use the Login method to connect service.Login(username, pass); // Print received token to verify login System.Console.WriteLine("Token: "); System.Console.WriteLine(" " + service.Token); connected = true; //receiver = new Receiver(service); return connected; }
/// <summary> /// Initializes a new instance of the <see cref="Resource"/> class. /// </summary> /// <param name="service">The service.</param> /// <param name="path">The path of the resource.</param> public Resource(Service service, string path) { this.Path = service.Fullpath(path); this.PartialPath = path; this.Service = service; this.RefreshArgs = new Args("count", "-1"); this.MaybeValid = false; }
/// <summary> /// Cleans an application from Splunk -- requires a restart /// </summary> /// <param name="appName">The app name</param> /// <param name="service">The connected service</param> /// <returns>The new connection</returns> private Service CleanApp(string appName, Service service) { this.SplunkRestart(); service = this.Connect(); EntityCollection<Application> apps = service.GetApplications(); apps.Remove(appName); this.SplunkRestart(); return this.Connect(); }
/// <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 }; }
/// <summary> /// Initializes a new instance of the <see cref="MessageCollection"/> /// class. /// </summary> /// <param name="service">The service</param> /// <param name="args">The optional arguments</param> public MessageCollection(Service service, Args args) : base(service, "messages", args, typeof(Message)) { }
/// <summary> /// Initializes a new instance of the <see cref="Index"/> class. /// </summary> /// <param name="service">The connected service</param> /// <param name="path">The path</param> public Index(Service service, string path) : base(service, path) { }
/// <summary> /// Initializes a new instance of the <see cref="ApplicationSetup"/> /// class. /// </summary> /// <param name="service">The connected service.</param> /// <param name="path">The path.</param> public ApplicationSetup(Service service, string path) : base(service, path + "/setup") { }
/// <summary> /// Run the given query and wait for the job to complete. /// </summary> /// <param name="service">The service</param> /// <param name="query">The search query</param> /// <returns>The job</returns> private Job RunWait(Service service, string query) { return this.RunWait(service, query, null); }
public void ServiceLogin() { ResponseMessage response; Service service = new Service(this.SetUp().Host, this.SetUp().Port, this.SetUp().Scheme); // Not logged in, should fail with 401 try { response = service.Get("/services/authentication/users"); Assert.Fail("Expected HttpException"); } catch (WebException ex) { Assert.AreEqual(401, ((HttpWebResponse)ex.Response).StatusCode.GetHashCode(), this.assertRoot + "#6"); } // Logged in, request should succeed service.Login(this.SetUp().Username, this.SetUp().Password); response = service.Get("/services/authentication/users"); this.CheckResponse(response); // Logout, the request should fail with a 401 service.Logout(); try { response = service.Get("/services/authentication/users"); Assert.Fail("Expected HttpException"); } catch (WebException ex) { Assert.AreEqual(401, ((HttpWebResponse)ex.Response).StatusCode.GetHashCode(), this.assertRoot + "#6"); } }
/// <summary> /// Initializes a new instance of the /// <see cref="WindowsActiveDirectoryInput"/> class. /// </summary> /// <param name="service">The connected service.</param> /// <param name="path">The path.</param> public WindowsActiveDirectoryInput(Service service, string path) : base(service, path) { }
/// <summary> /// Clear the index /// </summary> /// <param name="service">A service</param> /// <param name="indexName">The index name</param> /// <param name="index">The index object</param> private void ClearIndex(Service service, string indexName, Index index) { service.Oneshot(string.Format("search index={0} * | delete", indexName)); WaitUntilEventCount(index, 0, 45); }
/// <summary> /// Initializes a new instance of the <see cref="Job" /> class. /// </summary> /// <param name="service">The service.</param> /// <param name="path">The endpoint path.</param> public Job(Service service, string path) : base(service, path) { }
/// <summary> /// Initializes a new instance of the <see cref="Logger"/> class. /// </summary> /// <param name="service">The service.</param> /// <param name="path">The path.</param> public Logger(Service service, string path) : base(service, path) { }
/// <summary> /// Initializes a new instance of the <see cref="ScriptInput"/> class. /// </summary> /// <param name="service">The connected service.</param> /// <param name="path">The path.</param> public ScriptInput(Service service, string path) : base(service, path) { }
/// <summary> /// Initializes a new instance of the <see cref="SavedSearch"/> class. /// </summary> /// <param name="service">The connected service.</param> /// <param name="path">The path.</param> public SavedSearch(Service service, string path) : base(service, path) { }
/// <summary> /// Initializes a new instance of the <see cref="Receiver"/> class. /// </summary> /// <param name="service">The <see cref="Service"/>.</param> public Receiver(Service service) { this.service = service; }
/// <summary> /// Initializes a new instance of the <see cref="UdpInput"/> class. /// </summary> /// <param name="service">The connected service.</param> /// <param name="path">The path.</param> public UdpInput(Service service, string path) : base(service, path) { }
/// <summary> /// Establishes a connection to a Splunk service using a map of /// arguments. /// </summary> /// <param name="args">The connection arguments.</param> /// <returns>A new <see cref="Service"/> instance.</returns> /// <remarks> /// This method creates a new <see cref="Service"/> instance and /// authenticates the session using credentials passed in from the args /// dictionary. /// </remarks> public static Service Connect(Dictionary<string, object> args) { Service service = new Service(args); if (args.ContainsKey("username")) { string username = Args.Get(args, "username", null); string password = Args.Get(args, "password", null); service.Login(username, password); } return service; }
/// <summary> /// Initializes a new instance of the <see cref="EventType"/> class. /// </summary> /// <param name="service">The connected service.</param> /// <param name="path">The path.</param> public EventType(Service service, string path) : base(service, path) { }
/// <summary> /// Initializes a new instance of the <see cref="WindowsWmiInput"/> /// class. /// </summary> /// <param name="service">The connected service.</param> /// <param name="path">The path.</param> public WindowsWmiInput(Service service, string path) : base(service, path) { }
/// <summary> /// Run the given query with the given query args. /// </summary> /// <param name="service">The service</param> /// <param name="query">The search query</param> /// <param name="args">The args</param> /// <returns>The job</returns> private Job Run(Service service, string query, JobArgs args) { return service.GetJobs().Create(query, args); }
/// <summary> /// Initializes a new instance of the /// <see cref="WindowsEventLogInput"/> class. /// </summary> /// <param name="service">The connected service.</param> /// <param name="path">The path.</param> public WindowsEventLogInput(Service service, string path) : base(service, path) { }
/// <summary> /// Run the given query with the given query args and wait for the job to /// complete. /// </summary> /// <param name="service">The service</param> /// <param name="query">The search query</param> /// <param name="args">The args</param> /// <returns>The job</returns> private Job RunWait(Service service, string query, Args args) { Job job = service.GetJobs().Create(query, args); return this.Wait(job); }
/// <summary> /// Initializes a new instance of the <see cref="Role"/> class. /// </summary> /// <param name="service">The service.</param> /// <param name="path">The endpoint path.</param> public Role(Service service, string path) : base(service, path) { }
/// <summary> /// Initializes a new instance of the <see cref="WindowsRegistryInput"/> /// class. /// </summary> /// <param name="service">The connected service.</param> /// <param name="path">The path.</param> public WindowsRegistryInput(Service service, string path) : base(service, path) { }
/// <summary> /// Initializes a new instance of the <see cref="ApplicationUpdate"/> /// class. /// </summary> /// <param name="service">The connected service.</param> /// <param name="path">The path.</param> public ApplicationUpdate(Service service, string path) : base(service, path + "/update") { }
/// <summary> /// Initializes a new instance of the <see cref="Credential"/> class. /// </summary> /// <param name="service">The service.</param> /// <param name="path">The path.</param> public Credential(Service service, string path) : base(service, path) { }
/// <summary> /// Initializes a new instance of the <see cref="Upload"/> class. /// </summary> /// <param name="service">The connected service.</param> /// <param name="path">The path.</param> public Upload(Service service, string path) : base(service, path) { }
/// <summary> /// Initializes a new instance of the <see cref="Entity"/> class. /// </summary> /// <param name="service">The service.</param> /// <param name="path">The resource's path.</param> public Entity(Service service, string path) : base(service, path) { }
/// <summary> /// Initializes a new instance of the <see cref="MessageCollection"/> /// class. /// </summary> /// <param name="service">The service</param> public MessageCollection(Service service) : base(service, "messages", typeof(Message)) { }