예제 #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;
        }
예제 #2
0
        public void TestLiveNamespace1()
        {
            Service service = Connect();

            String username = "******";
            String password = "******";
            String savedSearch = "sdk-test1";
            String searchString = "search index=main * | 10";

            // Setup a namespace
            Args splunkNameSpace = new Args();
            splunkNameSpace.Add("owner", username);
            splunkNameSpace.Add("app", "search");

            // Get all users, scrub and make our test user
            UserCollection users = service.GetUsers();
            if (users.ContainsKey(username))
            {
                users.Remove(username);
            }

            Assert.IsFalse(users.ContainsKey(username), "Expected users to not contain: " + username);
            users.Create(username, password, "user");
            Assert.IsTrue(users.ContainsKey(username), "Expected users to contain: " + username);

            // Get saved searches for our new namespace, scrub and make our test saved searches
            SavedSearchCollection savedSearches = service.GetSavedSearches(splunkNameSpace);
            if (savedSearches.ContainsKey(savedSearch))
            {
                savedSearches.Remove(savedSearch);
            }

            Assert.IsFalse(savedSearches.ContainsKey(savedSearch), "Expected the saved search to not contain " + savedSearch);

        }
예제 #3
0
        /// <summary>
        /// Establishes and returns a namespace.
        /// </summary>
        public Args CreateNamespace(String username, String appname)
        {
            Args splunkNamespace = new Args();

            splunkNamespace.Add("owner", username);
            splunkNamespace.Add("app", appname);

            return splunkNamespace;
        }
        public bool SendMessage(string message, string index = "main", string host = "localhost", 
            string source="dynaTrace", string sourcetype = "dynatrace/xml")
        {
            if (!connected) return false;

            Receiver splunkReceiver = new Receiver(service);
            
            var args = new Args();

            args.Add("host", host);
            args.Add("source", source);
            args.Add("sourcetype", sourcetype);

            splunkReceiver.Submit(index, args, message);

            return true;
        }
        public bool SendEvent()
        {
            Receiver splunkReceiver = new Receiver(service);


            var args = new Args();
            args.Add("host", "TodaysHostIs");
            args.Add("source", "dynaTrace");
            args.Add("sourcetype", "Monitoring");

            //splunkReceiver.Submit(args, "CurrentlyWorks");

            //The index needs to exist in the splunk database to work, otherwise a 400 error is thrown
            splunkReceiver.Submit("main", args, "EventType=4 Keywords=Classic, RecordNumber=number");

            Console.WriteLine("Submitted Successfully");

            return true;
        }
예제 #6
0
        public void TestStaticNameSpace()
        {
            Service service = Connect();

            Args splunkNameSpace = new Args();

            splunkNameSpace.Add("app", "search");
            Assert.AreEqual("/servicesNS/-/search/", service.Fullpath("", splunkNameSpace), "Expected the path URL to be /servicesNS/-/search/");

            splunkNameSpace.Clear();
            splunkNameSpace.Add("owner", "Bob");
            Assert.AreEqual("/servicesNS/Bob/-/", service.Fullpath("", splunkNameSpace), "Expected path URL to be /servicesNS/Bob/-/");

            splunkNameSpace.Clear();
            splunkNameSpace.Add("sharing", "app");
            Assert.AreEqual("/servicesNS/nobody/-/", service.Fullpath("", splunkNameSpace), "Expected path URL to be /servicesNS/nobody/-/");

            splunkNameSpace.Clear();
            splunkNameSpace.Add("sharing", "system");
            Assert.AreEqual("/servicesNS/nobody/system/", service.Fullpath("", splunkNameSpace), "Expected path URL to be /servicesNS/nobody/system/");
        }
예제 #7
0
        public void Message()
        {
            Service service = Connect();

            MessageCollection messageCollection = service.GetMessages();

            if (messageCollection.ContainsKey("sdk-test-message1"))
            {
                messageCollection.Remove("sdk-test-message1");
            }

            Assert.IsFalse(messageCollection.ContainsKey("sdk-test-message1"), this.assertRoot + "#1");

            if (messageCollection.ContainsKey("sdk-test-message2"))
            {
                messageCollection.Remove("sdk-test-message2");
            }

            Assert.IsFalse(messageCollection.ContainsKey("sdk-test-message2"), this.assertRoot + "#2");

            messageCollection.Create("sdk-test-message1", "hello.");
            Assert.IsTrue(messageCollection.ContainsKey("sdk-test-message1"), this.assertRoot + "#3");

            Message message = messageCollection.Get("sdk-test-message1");
            Assert.AreEqual("sdk-test-message1", message.Key, this.assertRoot + "#4");
            Assert.AreEqual("hello.", message.Value, this.assertRoot + "#5");

            Args args2 = new Args();
            args2.Add("value", "world.");
            messageCollection.Create("sdk-test-message2", args2);
            Assert.IsTrue(messageCollection.ContainsKey("sdk-test-message2"), this.assertRoot + "#6");

            message = messageCollection.Get("sdk-test-message2");
            Assert.AreEqual("sdk-test-message2", message.Key, this.assertRoot + "#7");
            Assert.AreEqual("world.", message.Value, this.assertRoot + "#8");

            messageCollection.Remove("sdk-test-message1");
            Assert.IsFalse(messageCollection.ContainsKey("sdk-test-message1"), this.assertRoot + "#9");

            messageCollection.Remove("sdk-test-message2");
            Assert.IsFalse(messageCollection.ContainsKey("sdk-test-message2"), this.assertRoot + "#10");
        }
        public bool OpenStream(string index = "main", string host = "localhost",
    string source = "dynaTrace", string sourcetype = "dynatrace/xml")
        {
            if (!connected) return false;

            Receiver splunkReceiver = new Receiver(service);

            var args = new Args();

            args.Add("host", host);
            args.Add("source", source);
            args.Add("sourcetype", sourcetype);

            iStream = splunkReceiver.Attach("main", args);

            Console.WriteLine("Opened Input Stream");
            return true;
        }
예제 #9
0
 /// <summary>
 /// Flattens this instance.
 /// </summary>
 public override void Flatten()
 {
     Args.Add("FirstName", Customer.FirstName);
     Args.Add("LastName", Customer.LastName);
 }
예제 #10
0
        public FFmpegInputArgs AddArg(string arg)
        {
            Args.Add(arg);

            return(this);
        }
예제 #11
0
        public void Application()
        {
            string dummyString;
            bool dummyBool;
            int dummyInt;
            Service service = Connect();

            EntityCollection<Application> apps = service.GetApplications();
            foreach (Application app in apps.Values)
            {
                try
                {
                    ApplicationSetup applicationSetup = app.Setup();
                    string setupXml = applicationSetup.SetupXml;
                }
                catch (Exception)
                {
                    // silent exception, if setup doesn't exist, exception occurs
                }

                ApplicationArchive applicationArchive = app.Archive();
                dummyString = app.Author;
                dummyBool = app.CheckForUpdates;
                dummyString = app.Description;
                dummyString = app.Label;
                dummyBool = app.Refreshes;
                dummyString = app.Version;
                dummyBool = app.IsConfigured;
                if (service.VersionCompare("5.0") < 0)
                {
                    dummyBool = app.IsManageable;
                }
                dummyBool = app.IsVisible;
                dummyBool = app.StateChangeRequiresRestart;
                ApplicationUpdate applicationUpdate = app.AppUpdate();
                dummyString = applicationUpdate.Checksum;
                dummyString = applicationUpdate.ChecksumType;
                dummyString = applicationUpdate.Homepage;
                dummyInt = applicationUpdate.UpdateSize;
                dummyString = applicationUpdate.UpdateName;
                dummyString = applicationUpdate.AppUrl;
                dummyString = applicationUpdate.Version;
                dummyBool = applicationUpdate.IsImplicitIdRequired;
            }

            if (apps.ContainsKey("sdk-tests"))
            {
                service = this.CleanApp("sdk-tests", service);
            }

            apps = service.GetApplications();
            Assert.IsFalse(apps.ContainsKey("sdk-tests"), assertRoot + "#1");

            Args createArgs = new Args();
            createArgs.Add("author", "me");
            if (service.VersionCompare("4.2.4") >= 0)
            {
                createArgs.Add("configured", false);
            }
            createArgs.Add("description", "this is a description");
            createArgs.Add("label", "SDKTEST");
            if (service.VersionCompare("5.0") < 0)
            {
                createArgs.Add("manageable", false);
            }
            createArgs.Add("template", "barebones");
            createArgs.Add("visible", false);
            apps.Create("sdk-tests", createArgs);
            Assert.IsTrue(apps.ContainsKey("sdk-tests"), assertRoot + "#2");
            Application app2 = apps.Get("sdk-tests");

            dummyBool = app2.CheckForUpdates;
            Assert.AreEqual("SDKTEST", app2.Label, assertRoot + "#3");
            Assert.AreEqual("me", app2.Author, assertRoot + "#4");
            Assert.IsFalse(app2.IsConfigured, assertRoot + "#5");
            if (service.VersionCompare("5.0") < 0)
            {
                Assert.IsFalse(app2.IsManageable, assertRoot + "#6");
            }
            Assert.IsFalse(app2.IsVisible, assertRoot + "#7");

            // update the app
            app2.Author = "not me";
            app2.Description = "new description";
            app2.Label = "new label";
            app2.IsVisible = false;
            if (service.VersionCompare("5.0") < 0)
            {
                app2.IsManageable = false;
            }
            app2.Version = "5.0.0";
            app2.Update();

            // check to see if args took.
            Assert.AreEqual("not me", app2.Author, assertRoot + "#8");
            Assert.AreEqual("new description", app2.Description, assertRoot + "#9");
            Assert.AreEqual("new label", app2.Label, assertRoot + "#10");
            Assert.IsFalse(app2.IsVisible, assertRoot + "#11");
            Assert.AreEqual("5.0.0", app2.Version, assertRoot + "#12");

            // archive (package) the application
            ApplicationArchive appArchive = app2.Archive();
            Assert.IsTrue(appArchive.AppName.Length > 0, assertRoot + "#13");
            Assert.IsTrue(appArchive.FilePath.Length > 0, assertRoot + "#14");
            Assert.IsTrue(appArchive.Url.Length > 0, assertRoot + "#15");

            ApplicationUpdate appUpdate = app2.AppUpdate();
            Assert.IsTrue(appUpdate.ContainsKey("eai:acl"), assertRoot + "#16");

            service = this.CleanApp("sdk-tests", service);
            apps = service.GetApplications();
            Assert.IsFalse(apps.ContainsKey("sdk-tests"), assertRoot + "#17");
        }
예제 #12
0
        //This is an example of the implementation of the Parse method
        public override void Parse(TokensStack sTokens)
        {
            //We check that the first token is "function"
            Token tFunc = sTokens.Pop();

            if (!(tFunc is Statement) || ((Statement)tFunc).Name != "function")
            {
                throw new SyntaxErrorException("Expected function received: " + tFunc, tFunc);
            }
            //Now there should be the return type. We pop it from the stack, check for errors, and then set the field
            Token tType = sTokens.Pop();

            if (!(tType is VarType))
            {
                throw new SyntaxErrorException("Expected var type, received " + tType, tType);
            }
            ReturnType = VarDeclaration.GetVarType(tType);
            //Next is the function name
            Token tName = sTokens.Pop();

            if (!(tName is Identifier))
            {
                throw new SyntaxErrorException("Expected function name, received " + tType, tType);
            }
            Name = ((Identifier)tName).Name;

            //After the name there should be opening paranthesis for the arguments
            Token t = sTokens.Pop(); //(

            //Now we extract the arguments from the stack until we see a closing parathesis
            while (sTokens.Count > 0 && !(sTokens.Peek() is Parentheses))//)
            {
                //For each argument there should be a type, and a name
                if (sTokens.Count < 3)
                {
                    throw new SyntaxErrorException("Early termination ", t);
                }
                Token          tArgType = sTokens.Pop();
                Token          tArgName = sTokens.Pop();
                VarDeclaration vc       = new VarDeclaration(tArgType, tArgName);
                Args.Add(vc);
                //If there is a comma, then there is another argument
                if (sTokens.Count > 0 && sTokens.Peek() is Separator)//,
                {
                    sTokens.Pop();
                }
            }
            //Now we pop out the ) and the {. Note that you need to check that the stack contains the correct symbols here.
            if (sTokens.Count < 1 || !(sTokens.Peek() is Separator))
            {
                throw new SyntaxErrorException("not the right separator", sTokens.Pop());
            }
            t = sTokens.Pop();//)
            if (sTokens.Count < 1 || !(sTokens.Peek() is Separator))
            {
                throw new SyntaxErrorException("not the right separator", sTokens.Pop());
            }
            t = sTokens.Pop();//{

            //Now we parse the list of local variable declarations
            while (sTokens.Count > 0 && (sTokens.Peek() is Statement) && (((Statement)sTokens.Peek()).Name == "var"))
            {
                VarDeclaration local = new VarDeclaration();
                //We call the Parse method of the VarDeclaration, which is responsible to parsing the elements of the variable declaration
                local.Parse(sTokens);
                Locals.Add(local);
            }

            //Now we parse the list of statements
            while (sTokens.Count > 0 && !(sTokens.Peek() is Parentheses))
            {
                //We create the correct Statement type (if, while, return, let) based on the top token in the stack
                StatetmentBase s = StatetmentBase.Create(sTokens.Peek());
                //And call the Parse method of the statement to parse the different parts of the statement
                s.Parse(sTokens);
                Body.Add(s);
            }
            //Need to check here that the last statement is a return statement
            //Finally, the function should end with }
            Token tEnd = sTokens.Pop();//}
        }
예제 #13
0
        public void WindowsEventLogInputCRUD()
        {
            Service service = Connect();
            InputCollection inputCollection = service.GetInputs();
            ServiceInfo info = service.GetInfo();

            if (info.OsName.Equals("Windows"))
            {
                string name = "sdk-input-wel";
                Args args = new Args();

                if (inputCollection.ContainsKey(name))
                {
                    inputCollection.Remove(name);
                    inputCollection.Refresh();
                }
                Assert.IsFalse(inputCollection.ContainsKey(name), assertRoot + "#52");

                // CRUD Windows Event Log Input
                args.Add("lookup_host", service.Host);
                inputCollection.Create(name, InputKind.WindowsEventLog, args);
                Assert.IsTrue(inputCollection.ContainsKey(name), assertRoot + "#53");
                WindowsEventLogInput windowsEventLogInput = (WindowsEventLogInput)inputCollection.Get(name);

                windowsEventLogInput.Index = "main";
                windowsEventLogInput.LookupHost = service.Host;
                windowsEventLogInput.Hosts = "one.two.three,four.five.six";
                windowsEventLogInput.Update();

                Assert.AreEqual(service.Host, windowsEventLogInput.LookupHost, assertRoot + "#54");
                Assert.AreEqual("one.two.three,four.five.six", windowsEventLogInput.Hosts, assertRoot + "#55");
                Assert.AreEqual("main", windowsEventLogInput.Index, assertRoot + "#55");

                windowsEventLogInput.Remove();
                inputCollection.Refresh();
                Assert.IsFalse(inputCollection.ContainsKey(name), assertRoot + "#56");
            }
        }
예제 #14
0
        public void WindowsRegistryInputCRUD()
        {
            Service service = Connect();
            InputCollection inputCollection = service.GetInputs();
            ServiceInfo info = service.GetInfo();

            if (info.OsName.Equals("Windows"))
            {
                string name = "sdk-input-wr";
                Args args = new Args();

                if (service.VersionCompare("4.3") < 0)
                {
                    return;
                }

                if (inputCollection.ContainsKey(name))
                {
                    inputCollection.Remove(name);
                    inputCollection.Refresh();
                }
                Assert.IsFalse(inputCollection.ContainsKey(name), assertRoot + "#71");

                // CRUD Windows Registry Input
                args.Add("disabled", true);
                args.Add("baseline", false);
                args.Add("hive", "HKEY_USERS");
                args.Add("proc", "*");
                args.Add("type", "*");
                inputCollection.Create(name, InputKind.WindowsRegistry, args);
                Assert.IsTrue(inputCollection.ContainsKey(name), assertRoot + "#72");
                WindowsRegistryInput windowsRegistryInput =
                        (WindowsRegistryInput)inputCollection.Get(name);

                windowsRegistryInput.Index = "main";
                windowsRegistryInput.MonitorSubnodes = true;
                windowsRegistryInput.Update();

                Assert.IsFalse(windowsRegistryInput.Baseline, assertRoot + "#73");
                Assert.AreEqual("main", windowsRegistryInput.Index, assertRoot + "#74");

                // adjust a few of the arguments
                windowsRegistryInput.Type = new string[] { "create", "delete" };
                // touch the new Type (testing get after set)
                string[] foo = windowsRegistryInput.Type;
                windowsRegistryInput.Baseline = false;
                windowsRegistryInput.Update();

                Assert.AreEqual("*", windowsRegistryInput.Proc, assertRoot + "#75");
                Assert.IsTrue(windowsRegistryInput.Type.Contains("create"), assertRoot + "#76");
                Assert.IsTrue(windowsRegistryInput.Type.Contains("delete"), assertRoot + "#77");
                Assert.IsFalse(windowsRegistryInput.Baseline, assertRoot + "#78");

                windowsRegistryInput.Remove();
                inputCollection.Refresh();
                Assert.IsFalse(inputCollection.ContainsKey(name), assertRoot + "#79");
            }
        }
예제 #15
0
        public FFmpegOutputArgs AddArg(string Arg)
        {
            Args.Add(Arg);

            return(this);
        }
예제 #16
0
        public bool TryDivide(string fullCmd)
        {
            CommandName = fullCmd.Split(' ')[0].Trim();
            ArgString   = fullCmd.IndexOf(" ", StringComparison.Ordinal) == -1
                ? ""
                : fullCmd.Substring(fullCmd.IndexOf(" ", StringComparison.Ordinal) + 1,
                                    fullCmd.Length - CommandName.Length - 1).Trim();
            List <string> splitedParam = new List <string>();

            SimpleArgs = ArgString.Split(' ').ToList();
            if (ArgString == "")
            {
                return(false);
            }
            try
            {
                splitedParam.AddRange(ArgString.Split(' '));
                foreach (var item in splitedParam)
                {
                    if (Quote.Any(q => ContainsChar(q, item)))
                    {
                        throw new ArgumentException();
                    }
                }

                bool combined = true;
                foreach (var item in Quote)
                {
                    for (int i = 0; i < splitedParam.Count - 1; i++)
                    {
                        string cur = splitedParam[i], next = splitedParam[i + 1];

                        if (cur.StartsWith(item) && !cur.EndsWith(item))
                        {
                            combined        = false;
                            splitedParam[i] = cur + " " + next;
                            splitedParam.Remove(next);
                            if (splitedParam[i].EndsWith(item))
                            {
                                combined = true;
                            }
                            i--;
                        }
                    }
                    if (!combined)
                    {
                        throw new ArgumentException("Expect '" + item + "'.");
                    }
                }

                string tmpKey = null, tmpValue;
                bool   isLastKeyOrValue = false;

                splitedParam.Add("-");
                foreach (var item in splitedParam)
                {
                    tmpValue = null;
                    if (item.StartsWith('-'))
                    {
                        if (tmpKey != null)
                        {
                            Switches.Add(tmpKey, tmpKey);
                        }

                        tmpKey           = item.Remove(0, 1);
                        isLastKeyOrValue = true;
                    }
                    else
                    {
                        foreach (var q in Quote)
                        {
                            tmpValue = tmpValue == null?item.Trim(q) : tmpValue.Trim(q);
                        }
                        if (!isLastKeyOrValue)
                        {
                            FreeArgs.Add(tmpValue);
                            //throw new ArgumentException("Expect key.");
                        }
                        else
                        {
                            Args.Add(tmpKey, tmpValue);
                            tmpKey           = null;
                            tmpValue         = null;
                            isLastKeyOrValue = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Debug(ex.Message);
                return(false);
            }

            return(true);
        }
예제 #17
0
 /// <summary>
 /// Creates an event type.
 /// </summary>
 /// <param name="name">The name of the event.</param>
 /// <param name="search">The search string.</param>
 /// <param name="args">The arguments.</param>
 /// <returns>The event type.</returns>
 public EventType Create(string name, string search, Args args)
 {
     args = Args.Create(args);
     args.Add("search", search);
     return(base.Create(name, args));
 }
예제 #18
0
 public override void Normalize()
 {
     Args.Add(nameof(Banco.Id), Banco.Id);
 }
예제 #19
0
        //public string ReturnArgument(string argName)
        //{
        //    return Args.Select(m => m).Where(x => x.Key == argName).Select(k => k.Value).First();
        //}

        public void AddArgument(string argValue)
        {
            Args.Add(argValue);
        }
예제 #20
0
 public override void Normalize()
 {
     Args.Add(nameof(Fornecedor.Id), Fornecedor.Id);
 }
예제 #21
0
        public void TestLiveNameSpace()
        {
            Service service = Connect();

            String search = "search *";

            // Establish naming convention for separate namespaces
            String searchName = "sdk-test-search";
            String username = "******";
            String appname = "sdk-app";

            Args splunkNameSpace1 = new Args();
            Args splunkNameSpace2 = new Args();

            splunkNameSpace1.Add("owner", username);
            splunkNameSpace1.Add("app", appname);

            splunkNameSpace2.Add("owner", "-");
            splunkNameSpace2.Add("app", appname);

            // Scrub to ensure apps doesn't already exist and then creates a new app with give appname
            this.CreateApp(appname);
            
            // Scrub to ensure users doesn't already exist
            UserCollection users = service.GetUsers();
            if (users.ContainsKey(username))
            {
                users.Remove(username);
            }
            Assert.IsFalse(users.ContainsKey(username), "Expected users to not contain the username: "******"abc", "user");

            // Create namespace specific UNIQUE searches
            SavedSearchCollection savedSearches1 = service.GetSavedSearches(splunkNameSpace1);
            SavedSearchCollection savedSearches2 = service.GetSavedSearches(splunkNameSpace2);



            // FIXME: figure out why create doesn't work.
            //apps.Create("sdk-user", splunkNameSpace);
        }
예제 #22
0
        /// <summary>
        /// Gets old values from given index, skip saving paths and things we cannot write
        /// </summary>
        /// <param name="index">The Index</param>
        /// <returns>The argument getIndexProperties</returns>
        private Args GetIndexProperties(Index index)
        {
            Args indexProperties = new Args();

            indexProperties.Add("blockSignSize", index.BlockSignSize);
            indexProperties.Add("frozenTimePeriodInSecs", index.FrozenTimePeriodInSecs);
            indexProperties.Add("maxConcurrentOptimizes", index.MaxConcurrentOptimizes);
            indexProperties.Add("maxDataSize", index.MaxDataSize);
            indexProperties.Add("maxHotBuckets", index.MaxHotBuckets);
            indexProperties.Add("maxHotIdleSecs", index.MaxHotIdleSecs);
            indexProperties.Add("maxHotSpanSecs", index.MaxHotSpanSecs);
            indexProperties.Add("maxMemMB", index.MaxMemMB);
            indexProperties.Add("maxMetaEntries", index.MaxMetaEntries);
            indexProperties.Add("maxTotalDataSizeMB", index.MaxTotalDataSizeMB);
            indexProperties.Add("maxWarmDBCount", index.MaxWarmDBCount);
            indexProperties.Add("minRawFileSyncSecs", index.MinRawFileSyncSecs);
            indexProperties.Add("partialServiceMetaPeriod", index.PartialServiceMetaPeriod);
            indexProperties.Add("quarantineFutureSecs", index.QuarantineFutureSecs);
            indexProperties.Add("quarantinePastSecs", index.QuarantinePastSecs);
            indexProperties.Add("rawChunkSizeBytes", index.RawChunkSizeBytes);
            indexProperties.Add("rotatePeriodInSecs", index.RotatePeriodInSecs);
            indexProperties.Add("serviceMetaPeriod", index.ServiceMetaPeriod);
            indexProperties.Add("syncMeta", index.SyncMeta);
            indexProperties.Add("throttleCheckPeriod", index.ThrottleCheckPeriod);

            return indexProperties;
        }
예제 #23
0
 /// <summary>
 /// Parses a search query with additional arguments and returns a 
 /// semantic map for the search in JSON format.
 /// </summary>
 /// <param name="query">The search query.</param>
 /// <param name="args">The arguments.</param>
 /// <returns>A parse <see cref="ResponseMessage"/>.</returns>
 public ResponseMessage Parse(string query, Args args)
 {
     args = Args.Create(args);
     args.Add("q", query);
     return this.Get("search/parser", args);
 }
예제 #24
0
        public void ScriptInputCRUD()
        {
            Service service = Connect();
            InputCollection inputCollection = service.GetInputs();
            ServiceInfo info = service.GetInfo();

            // CRUD Script input
            string filename;
            if (info.OsName.Equals("Windows"))
            {
                filename = "echo.bat";
            }
            else
            {
                filename = "echo.sh";
            }

            Args args = new Args();
            args.Clear();
            args.Add("interval", "60");
            if (inputCollection.Get(filename) != null)
            {
                inputCollection.Remove(filename);
            }

            inputCollection.Create(filename, InputKind.Script, args);
            Assert.IsTrue(inputCollection.ContainsKey(filename), assertRoot + "#11");
            ScriptInput scriptInput = (ScriptInput)inputCollection.Get(filename);

            scriptInput.Host = "three.four.com";
            scriptInput.Index = "main";
            scriptInput.Interval = "120";
            if (service.VersionCompare("4.2.4") >= 0)
            {
                scriptInput.PassAuth = "admin";
            }

            scriptInput.RenameSource = "renamedSource";
            scriptInput.Source = "source";
            scriptInput.SourceType = "script";
            scriptInput.Update();

            Assert.AreEqual("three.four.com", scriptInput.Host, assertRoot + "#12");
            Assert.AreEqual("main", scriptInput.Index, assertRoot + "#13");
            Assert.AreEqual("120", scriptInput.Interval, assertRoot + "#14");
            if (service.VersionCompare("4.2.4") >= 0)
            {
                Assert.AreEqual("admin", scriptInput.PassAuth, assertRoot + "#15");
            }

            if (service.VersionCompare("5.0") >= 0)
            {
                Assert.AreEqual("source", scriptInput.Source, assertRoot + "#16");
            }
            else
            {
                Assert.AreEqual("renamedSource", scriptInput.Source, assertRoot + "#16");
            }

            Assert.AreEqual("script", scriptInput.SourceType, assertRoot + "#17");

            scriptInput.Remove();
            inputCollection.Refresh();
            Assert.IsFalse(inputCollection.ContainsKey(filename), assertRoot + "#18");
        }
예제 #25
0
        public void User()
        {
            Service service = Connect();

            string username = "******";
            string password = "******";

            UserCollection users = service.GetUsers();

            // Cleanup potential prior failed test run.
            users.Remove(username);
            Debug.Assert(!users.ContainsKey(username), this.assertRoot + "#14");

            // Create user using base create method
            Args args = new Args();
            args.Add("password", password);
            args.Add("roles", "power");
            User user = users.Create(username, args);
            Debug.Assert(users.ContainsKey(username), this.assertRoot + "#15");
            Debug.Assert(username.Equals(user.Name), this.assertRoot + "#16");
            Debug.Assert(1 == user.Roles.Length, this.assertRoot + "#17");
            Debug.Assert(this.Contains(user.Roles, "power"), this.assertRoot + "#18");

            users.Remove(username);
            Debug.Assert(!users.ContainsKey(username), this.assertRoot + "#19");

            // Create user using derived create method 
            user = users.Create(username, password, "power");
            Debug.Assert(users.ContainsKey(username), this.assertRoot + "#21");
            Debug.Assert(username.Equals(user.Name), this.assertRoot + "#22");
            Debug.Assert(1 == user.Roles.Length, this.assertRoot + "#23");
            Debug.Assert(this.Contains(user.Roles, "power"), this.assertRoot + "#24");

            users.Remove(username);
            Debug.Assert(!users.ContainsKey(username), this.assertRoot + "#25");

            // Create using derived method with multiple roles
            user = users.Create(
                username, password, new string[] { "power", "user" });
            Debug.Assert(users.ContainsKey(username), this.assertRoot + "#26");
            Debug.Assert(username.Equals(user.Name), this.assertRoot + "#27");
            Debug.Assert(2 == user.Roles.Length, this.assertRoot + "#28");
            Debug.Assert(this.Contains(user.Roles, "power"), this.assertRoot + "#29");
            Debug.Assert(this.Contains(user.Roles, "user"), this.assertRoot + "#30");

            users.Remove(username);
            Debug.Assert(!users.ContainsKey(username), this.assertRoot + "#31");

            // Create using drived method with multiple roles and extra properties
            args = new Args();
            args.Add("realname", "Renzo");
            args.Add("email", "*****@*****.**");
            args.Add("defaultApp", "search");
            user = users.Create(
                username, password, new string[] { "power", "user" }, args);
            Debug.Assert(users.ContainsKey(username), this.assertRoot + "#32");
            Debug.Assert(username.Equals(user.Name), this.assertRoot + "#33");
            Debug.Assert(2 == user.Roles.Length, this.assertRoot + "#34");
            Debug.Assert(this.Contains(user.Roles, "power"), this.assertRoot + "#35");
            Debug.Assert(this.Contains(user.Roles, "user"), this.assertRoot + "#36");
            Debug.Assert("Renzo".Equals(user.RealName), this.assertRoot + "#37");
            Debug.Assert("*****@*****.**".Equals(user.Email), this.assertRoot + "#38");
            Debug.Assert("search".Equals(user.DefaultApp), this.assertRoot + "#39");
            string dummyGet = user.Tz;

            // update user using setters
            user.DefaultApp = "search";
            user.Email = "*****@*****.**";
            user.Password = "******";
            user.RealName = "SDK-name";
            if (service.VersionCompare("4.3") >= 0)
            {
                user.RestartBackgroundJobs = false;
            }
            user.Roles = new string[] { "power" };
            user.Update();
            user.Refresh();

            Debug.Assert(1 == user.Roles.Length, this.assertRoot + "#40");
            Debug.Assert(this.Contains(user.Roles, "power"), this.assertRoot + "#41");
            Debug.Assert("SDK-name".Equals(user.RealName), this.assertRoot + "#42");
            Debug.Assert("*****@*****.**".Equals(user.Email), this.assertRoot + "#43");
            Debug.Assert("search".Equals(user.DefaultApp), this.assertRoot + "#44");

            users.Remove(username);
            Debug.Assert(!users.ContainsKey(username), this.assertRoot + "#45");

            Debug.Assert(!users.ContainsKey("sdk-user"), this.assertRoot + "#46");
            if (users.ContainsKey("SDK-user"))
            {
                users.Remove("SDK-user");
            }
            Debug.Assert(!users.ContainsKey("SDK-user"), this.assertRoot + "#47");

            args = new Args();
            args.Add("password", password);
            args.Add("roles", "power");
            Debug.Assert(username.Equals(user.Name), this.assertRoot + "#48");
            Debug.Assert(!users.ContainsKey("SDK-user"), this.assertRoot + "#49");
            users.Remove(username);
            Debug.Assert(!users.ContainsKey(username), this.assertRoot + "#50");
        }
예제 #26
0
        public void WindowsPerfmonInputCRUD()
        {
            Service service = Connect();
            InputCollection inputCollection = service.GetInputs();
            ServiceInfo info = service.GetInfo();

            if (info.OsName.Equals("Windows"))
            {
                string name = "sdk-input-wp";
                Args args = new Args();

                if (inputCollection.ContainsKey(name))
                {
                    inputCollection.Remove(name);
                    inputCollection.Refresh();
                }
                Assert.IsFalse(inputCollection.ContainsKey(name), assertRoot + "#57");

                // CRUD Windows Perfmon Input
                args.Add("interval", 600);
                args.Add("object", "Server");
                inputCollection.Create(name, InputKind.WindowsPerfmon, args);
                Assert.IsTrue(inputCollection.ContainsKey(name), assertRoot + "#58");
                WindowsPerfmonInput windowsPerfmonInput = (WindowsPerfmonInput)inputCollection.Get(name);

                windowsPerfmonInput.Index = "main";
                windowsPerfmonInput.Counters = new string[] { "% Privileged Time" };
                windowsPerfmonInput.Instances = new string[] { "wininit" };
                windowsPerfmonInput.Object = "Process";
                windowsPerfmonInput.Interval = 1200;
                windowsPerfmonInput.Update();

                Assert.AreEqual(1, windowsPerfmonInput.Counters.Length, assertRoot + "#59");
                Assert.IsTrue(this.Contains(windowsPerfmonInput.Counters, "% Privileged Time"), assertRoot + "#60");
                Assert.AreEqual(windowsPerfmonInput.Index, "main", assertRoot + "#60.1");
                Assert.IsTrue(this.Contains(windowsPerfmonInput.Instances, "wininit"), assertRoot + "#61");
                Assert.AreEqual(1200, windowsPerfmonInput.Interval, assertRoot + "#62");
                Assert.AreEqual("Process", windowsPerfmonInput.Object, assertRoot + "#63");

                // set multi-series values and update.
                windowsPerfmonInput.Counters = new string[] { "% Privileged Time", "% User Time" };
                windowsPerfmonInput.Instances = new string[] { "smss", "csrss" };
                windowsPerfmonInput.Update();

                Assert.AreEqual(2, windowsPerfmonInput.Counters.Length, assertRoot + "#64");
                Assert.IsTrue(this.Contains(windowsPerfmonInput.Counters, "% Privileged Time"), assertRoot + "#65");
                Assert.IsTrue(this.Contains(windowsPerfmonInput.Counters, "% User Time"), assertRoot + "#66");

                Assert.AreEqual(2, windowsPerfmonInput.Instances.Length, assertRoot + "#67");
                Assert.IsTrue(this.Contains(windowsPerfmonInput.Instances, "smss"), assertRoot + "#68");
                Assert.IsTrue(this.Contains(windowsPerfmonInput.Instances, "csrss"), assertRoot + "#69");

                windowsPerfmonInput.Remove();
                inputCollection.Refresh();
                Assert.IsFalse(inputCollection.ContainsKey(name), assertRoot + "#70");
            }
        }
예제 #27
0
 public override void Flatten()
 {
     Args.Add("UserId", User.Id);
     Args.Add("OldUserName", _oldUserName);
     Args.Add("NewUserName", User.UserName);
 }
예제 #28
0
        public void WindowsWMIInputCRUD()
        {
            Service service = Connect();
            InputCollection inputCollection = service.GetInputs();
            ServiceInfo info = service.GetInfo();

            if (info.OsName.Equals("Windows"))
            {
                string name = "sdk-input-wmi";
                Args args = new Args();

                if (inputCollection.ContainsKey(name))
                {
                    inputCollection.Remove(name);
                    inputCollection.Refresh();
                }

                Assert.IsFalse(inputCollection.ContainsKey(name), assertRoot + "#80");

                // CRUD Windows Wmi Input
                args.Add("classes", "PerfOS_Processor");
                args.Add("interval", 600);
                args.Add("lookup_host", service.Host);
                inputCollection.Create(name, InputKind.WindowsWmi, args);
                Assert.IsTrue(inputCollection.ContainsKey(name), assertRoot + "#81");
                WindowsWmiInput windowsWmiInput = (WindowsWmiInput)inputCollection.Get(name);

                Assert.AreEqual("Win32_PerfFormattedData_PerfOS_Processor", windowsWmiInput.Classes, assertRoot + "#82");
                Assert.AreEqual(600, windowsWmiInput.Interval, assertRoot + "#83");
                Assert.AreEqual(windowsWmiInput.LookupHost, service.Host, assertRoot + "#84");

                windowsWmiInput.Classes = "PerfDisk_LogicalDisk";
                windowsWmiInput.Fields = new string[] { "Caption" };
                windowsWmiInput.Index = "main";
                windowsWmiInput.Interval = 1200;
                windowsWmiInput.Instances = new string[] { "_Total" };
                windowsWmiInput.Servers = "host1.splunk.com,host2.splunk.com";
                windowsWmiInput.Update();

                Assert.AreEqual("Win32_PerfFormattedData_PerfDisk_LogicalDisk", windowsWmiInput.Classes, assertRoot + "#85");
                Assert.AreEqual(1, windowsWmiInput.Fields.Length, assertRoot + "#86");
                Assert.IsTrue(this.Contains(windowsWmiInput.Fields, "Caption"), assertRoot + "#87");
                Assert.AreEqual("main", windowsWmiInput.Index, assertRoot + "#88");
                Assert.AreEqual(1200, windowsWmiInput.Interval, assertRoot + "#89");
                Assert.AreEqual(1, windowsWmiInput.Instances.Length, assertRoot + "#90");
                Assert.IsTrue(this.Contains(windowsWmiInput.Instances, "_Total"), assertRoot + "#91");
                Assert.AreEqual("host1.splunk.com,host2.splunk.com", windowsWmiInput.Servers, assertRoot + "#92");

                // set list fields
                windowsWmiInput.Fields = new string[] { "Caption", "Description" };
                windowsWmiInput.Update();

                Assert.AreEqual(2, windowsWmiInput.Fields.Length, assertRoot + "#93");
                Assert.IsTrue(this.Contains(windowsWmiInput.Fields, "Caption"), assertRoot + "#94");
                Assert.IsTrue(this.Contains(windowsWmiInput.Fields, "Description"), assertRoot + "#95");

                windowsWmiInput.Remove();
                inputCollection.Refresh();
                Assert.IsFalse(inputCollection.ContainsKey(name), assertRoot + "#96");
            }
        }
예제 #29
0
        public void ConfCRUD()
        {
            Service service;
            string app = "sdk-tests";
            string owner = "nobody";
            // Create a fresh app to use as the container for confs that we will
            // create in this test. There is no way to delete a conf once it's
            // created so we make sure to create in the context of this test app
            // and then we delete the app when we are done to make everything go
            // away.
            this.CreateApp(app);
            service = this.Connect();
            Assert.IsTrue(service.GetApplications().ContainsKey(app), assertRoot + "#8");

            // Create an app specific service instance
            Args args = new Args(this.SetUp().Opts);
            args.Add("app", app);
            args.Add("owner", owner);
            service = Service.Connect(args);

            ConfCollection confs = service.GetConfs();
            Assert.IsFalse(confs.ContainsKey("testconf"), assertRoot + "#9");
            confs.Create("testconf");
            Assert.IsTrue(confs.ContainsKey("testconf"), assertRoot + "#10");

            EntityCollection<Entity> stanzas = confs.Get("testconf");
            Assert.AreEqual(0, stanzas.Size, assertRoot + "#11");

            stanzas.Create("stanza1");
            stanzas.Create("stanza2");
            stanzas.Create("stanza3");
            Assert.AreEqual(3, stanzas.Size, assertRoot + "#12");
            Assert.IsTrue(stanzas.ContainsKey("stanza1"), assertRoot + "#13");
            Assert.IsTrue(stanzas.ContainsKey("stanza2"), assertRoot + "#14");
            Assert.IsTrue(stanzas.ContainsKey("stanza3"), assertRoot + "#15");

            // Grab the new stanza and check its content
            Entity stanza1 = stanzas.Get("stanza1");
            Assert.IsFalse(stanza1.IsEmpty, "Expected stanza1 to be non-empty");
            Assert.AreEqual(5, stanza1.Size, "Expected stanza1 to have 5 elements");
            Assert.AreEqual("nobody", stanza1.Get("eai:userName"), assertRoot + "#16");
            Assert.AreEqual(app, stanza1.Get("eai:appName"), assertRoot + "#17");
            Assert.IsFalse(stanza1.ContainsKey("key1"), assertRoot + "#18");
            Assert.IsFalse(stanza1.ContainsKey("key2"), assertRoot + "#19");
            Assert.IsFalse(stanza1.ContainsKey("key3"), assertRoot + "#20");

            // Add a couple of properties
            args = new Args();
            args.Add("key1", "value1");
            args.Add("key2", 42);
            stanza1.Update(args);

            // Make sure the properties showed up
            Assert.AreEqual("value1", stanza1.Get("key1"), assertRoot + "#21");
            Assert.AreEqual("42", stanza1.Get("key2"), assertRoot + "#22");
            Assert.IsFalse(stanza1.ContainsKey("key3"), assertRoot + "#23");

            // Update an existing property
            args = new Args();
            args.Add("key1", "value2");
            stanza1.Update(args);

            // Make sure the updated property shows up (and no other changes).
            Assert.AreEqual("value2", stanza1.Get("key1"), assertRoot + "#24");
            Assert.AreEqual("42", stanza1.Get("key2"), assertRoot + "#25");
            Assert.IsFalse(stanza1.ContainsKey("key3"), assertRoot + "#26");
            Assert.IsTrue(stanza1.ContainsValue("value2"), "Expected stanza1 to contain the value value2");
            Assert.IsTrue(stanza1.ContainsValue("42"), "Expected stanza1 to contain the value 42");

            // Delete the stanzas
            stanzas.Remove("stanza3");
            Assert.AreEqual(2, stanzas.Size, assertRoot + "#27");
            Assert.IsTrue(stanzas.ContainsKey("stanza1"), assertRoot + "#28");
            Assert.IsTrue(stanzas.ContainsKey("stanza2"), assertRoot + "#29");
            Assert.IsFalse(stanzas.ContainsKey("stanza3"), assertRoot + "#30");

            stanzas.Remove("stanza2");
            Assert.AreEqual(1, stanzas.Size, assertRoot + "#31");
            Assert.IsTrue(stanzas.ContainsKey("stanza1"), assertRoot + "#32");
            Assert.IsFalse(stanzas.ContainsKey("stanza2"), assertRoot + "#33");
            Assert.IsFalse(stanzas.ContainsKey("stanza3"), assertRoot + "#34");

            stanzas.Remove("stanza1");
            Assert.AreEqual(0, stanzas.Size, assertRoot + "#35");
            Assert.IsFalse(stanzas.ContainsKey("stanza1"), assertRoot + "#36");
            Assert.IsFalse(stanzas.ContainsKey("stanza2"), assertRoot + "#37");
            Assert.IsFalse(stanzas.ContainsKey("stanza3"), assertRoot + "#38");

            // Cleanup after ourselves
            this.RemoveApp(app);
        }
예제 #30
0
 public override void Normalize()
 {
     Args.Add(nameof(Marca.Id), Marca.Id);
 }
예제 #31
0
 public override void Normalize()
 {
     Args.Add("Data do Estorno", DateTime.Now);
 }
예제 #32
0
 /// <summary>
 /// Creates a oneshot synchronous search using search arguments.
 /// </summary>
 /// <param name="query">The search query.</param>
 /// <param name="inputArgs">The input arguments.</param>
 /// <returns>An I/O stream.</returns>
 public Stream Oneshot(string query, Args inputArgs)
 {
     inputArgs = (inputArgs == null) ? Args.Create() : inputArgs;
     inputArgs = Args.Create(inputArgs);
     inputArgs.Add("search", query);
     inputArgs.Add("exec_mode", "oneshot");
     SetSegmentationDefault(ref inputArgs);
     ResponseMessage response = this.Post("search/jobs", inputArgs);
     return response.Content;
 }
예제 #33
0
 public Ast_Length(Token token) : base(token)
 {
     Args.Add(new Ast_Variable(new Token {
         Lexeme = "arg"
     }));
 }
예제 #34
0
파일: Browser.cs 프로젝트: keenua/Browsing
        public Args ExtractArgs(HtmlNode formNode, out string action)
        {
            action = "";
            if (formNode == null) return null;

            action = formNode.GetAttributeValue("action", "");

            Args args = new Args();
            args.enc = Encoding;

            List<HtmlNode> inputs = formNode.Descendants("input").ToList();
            inputs.AddRange(formNode.Descendants("select"));
            inputs.AddRange(formNode.Descendants("textarea"));
            inputs.AddRange(formNode.Descendants("button"));

            if (inputs == null) return null;

            foreach (HtmlNode i in inputs)
            {
                string name = i.GetAttributeValue("name", "");
                string value = i.GetAttributeValue("value", "");

                if (name != "")
                {
                    Arg arg = new Arg(name, value, Encoding);

                    arg.options = ExtractOptions(i);

                    args.Add(arg);
                }
            }

            return args;
        }
예제 #35
0
파일: Browser.cs 프로젝트: keenua/Browsing
        /// <summary>
        /// Posts data to the specified url
        /// </summary>
        /// <param name="url">Url to post data to</param>
        /// <param name="args">Arguments</param>
        /// <param name="withBoundary">Whether to use boundary as a separator</param>
        /// <param name="files">Files to post (Key = argument name, Value = file path)</param>
        /// <param name="contentType">Files content type, i.e. "application/octet-stream", "image/jpeg", etc. When the value is "", image content type is automatically determined</param>
        public string PostRaw(string url, Args args, bool withBoundary, NameValueCollection files, string contentType)
        {
            if (files != null)
                foreach (string key in files.Keys)
                {
                    List<string> urls = new List<string>();

                    foreach (string u in files[key].Split(',')) urls.Add(u);

                    foreach (string fileUrl in urls)
                    {
                        string fileName = Path.GetFileName(fileUrl);

                        byte[] fileBytes = new byte[0];

                        if (fileUrl != "")
                        {
                            fileBytes = DownloadData(fileUrl);
                        }

                        NameValueCollection additional = new NameValueCollection();
                        additional.Add("filename", fileName);

                        if (contentType == "") contentType = DetermineImageContentType(fileUrl);

                        args.Add(key, fileBytes, additional, contentType);
                    }
                }

            return PostRaw(url, args, withBoundary, false);
        }
예제 #36
0
        /// <summary>
        /// Cleans this index, removing all events, with specific timeout 
        /// value.
        /// </summary>
        /// <param name="maxSeconds">The maximum number of seconds to wait 
        /// before returning. A value of "-1" indicates to Splunk that it 
        /// should wait forever.</param>
        /// <returns>The <see cref="Index"/>.</returns>
        public Index Clean(int maxSeconds)
        {
            Args saved = new Args();
            saved.Add("maxTotalDataSizeMB", this.MaxTotalDataSizeMB);
            saved.Add("frozenTimePeriodInSecs", this.FrozenTimePeriodInSecs);

            Args reset = new Args();
            reset.Add("maxTotalDataSizeMB", "1");
            reset.Add("frozenTimePeriodInSecs", "1");
            this.Update(reset);
            this.RollHotBuckets();

            while (maxSeconds != 0)
            {
                Thread.Sleep(1000); // 1000ms (1 second sleep)
                maxSeconds = maxSeconds - 1;
                if (this.TotalEventCount == 0)
                {
                    this.Update(saved);
                    return this;
                }
                this.Refresh();
            }
            throw new SplunkException(
                SplunkException.TIMEOUT, "Index cleaning timed out");
        }
예제 #37
0
        public void Parse(string[] args)
        {
            _trace.Info(nameof(Parse));
            ArgUtil.NotNull(args, nameof(args));
            _trace.Info("Parsing {0} args", args.Length);

            string argScope = null;

            foreach (string arg in args)
            {
                _trace.Info("parsing argument");

                HasArgs = HasArgs || arg.StartsWith("--");
                _trace.Info("HasArgs: {0}", HasArgs);

                if (string.Equals(arg, "/?", StringComparison.Ordinal))
                {
                    Flags.Add("help");
                }
                else if (!HasArgs)
                {
                    _trace.Info("Adding Command: {0}", arg);
                    Commands.Add(arg.Trim());
                }
                else
                {
                    // it's either an arg, an arg value or a flag
                    if (arg.StartsWith("--") && arg.Length > 2)
                    {
                        string argVal = arg.Substring(2);
                        _trace.Info("arg: {0}", argVal);

                        // this means two --args in a row which means previous was a flag
                        if (argScope != null)
                        {
                            _trace.Info("Adding flag: {0}", argScope);
                            Flags.Add(argScope.Trim());
                        }

                        argScope = argVal;
                    }
                    else if (!arg.StartsWith("-"))
                    {
                        // we found a value - check if we're in scope of an arg
                        if (argScope != null && !Args.ContainsKey(argScope = argScope.Trim()))
                        {
                            if (SecretArgNames.Contains(argScope))
                            {
                                _secretMasker.AddValue(arg);
                            }

                            _trace.Info("Adding option '{0}': '{1}'", argScope, arg);
                            // ignore duplicates - first wins - below will be val1
                            // --arg1 val1 --arg1 val1
                            Args.Add(argScope, arg);
                            argScope = null;
                        }
                    }
                    else
                    {
                        //
                        // ignoring the second value for an arg (val2 below)
                        // --arg val1 val2

                        // ignoring invalid things like empty - and --
                        // --arg val1 -- --flag
                        _trace.Info("Ignoring arg");
                    }
                }
            }

            _trace.Verbose("done parsing arguments");

            // handle last arg being a flag
            if (argScope != null)
            {
                Flags.Add(argScope);
            }

            _trace.Verbose("Exiting parse");
        }