Ejemplo n.º 1
1
        /// <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;
        }
Ejemplo n.º 2
0
        /// <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;

        }
Ejemplo n.º 4
0
 /// <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;
 }
Ejemplo n.º 5
0
 /// <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();
 }
Ejemplo n.º 6
0
        /// <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))
 {
 }
Ejemplo n.º 8
0
 /// <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)
 {
 }
Ejemplo n.º 9
0
 /// <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")
 {
 }
Ejemplo n.º 10
0
 /// <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);
 }
Ejemplo n.º 11
0
        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)
 {
 }
Ejemplo n.º 13
0
 /// <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);
 }
Ejemplo n.º 14
0
 /// <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)
 {
 }
Ejemplo n.º 15
0
 /// <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)
 {
 }
Ejemplo n.º 16
0
 /// <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)
 {
 }
Ejemplo n.º 17
0
 /// <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)
 {
 }
Ejemplo n.º 18
0
 /// <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;
 }
Ejemplo n.º 19
0
 /// <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)
 {
 }
Ejemplo n.º 20
0
 /// <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)
 {
 }
Ejemplo n.º 21
0
 /// <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;
 }
Ejemplo n.º 22
0
 /// <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)
 {
 }
Ejemplo n.º 23
0
 /// <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)
 {
 }
Ejemplo n.º 24
0
 /// <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)
 {
 }
Ejemplo n.º 26
0
 /// <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);
 }
Ejemplo n.º 27
0
 /// <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) 
 {
 }
Ejemplo n.º 28
0
 /// <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")   
 {
 }
Ejemplo n.º 30
0
 /// <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)
 {
 }
Ejemplo n.º 31
0
 /// <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)
 {
 }
Ejemplo n.º 32
0
 /// <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))
 {
 }