/// <summary> /// The main program /// </summary> /// <param name="argv">The command line arguments</param> static async Task Run(Service service) { Console.WriteLine("Login as admin"); string username = "******"; string password = "******"; await service.LoginAsync(username, password); Console.WriteLine("create a index"); string indexName = "user-index"; string source = "*\\splunkd.log"; string sourceType = "splunkd"; if (service.GetIndexesAsync().Result.Any(a => a.Name == indexName)) { await service.RemoveIndexAsync(indexName); } Index index = await service.CreateIndexAsync(indexName); try { await index.EnableAsync(); Receiver receiver = service.Receiver; ReceiverArgs args = new ReceiverArgs() { Index = indexName, Source = source, SourceType = sourceType, }; await receiver.SendAsync("Hello World.", args); await receiver.SendAsync("Goodbye world.", args); SearchResults results = service.SearchOneshotAsync( string.Format( "search index={0}",// source={2} sourcetype={3}", indexName //source, //sourceType )).Result; Console.WriteLine(results); } finally { service.RemoveIndexAsync(indexName).Wait(); } }
/// <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 async Task ClearIndex(Service service, string indexName, Index index) { SearchResults result = await service.SearchOneshotAsync(string.Format("search index={0} * | delete", indexName)); //StreamReader reader = new StreamReader(stream); //string message = reader.ReadToEnd(); //if (message.Contains("msg type=\"FATAL\"")) //{ // throw new ApplicationException(string.Format("web reqest return error: {0}", message)); //} WaitUntilEventCount(index, 0, 45); }