/// <summary> /// Runs the specified service. /// </summary> /// <param name="service">The service.</param> /// <returns>a task</returns> private static async Task Run(Service service) { try { await service.Configurations.GetAllAsync(); } catch (AuthenticationFailureException) { Console.WriteLine("Can't get service configuration without logging in."); } await service.LogOnAsync(SdkHelper.Splunk.Username, SdkHelper.Splunk.Password); Console.WriteLine("List all configurations of the Splunk service:"); await service.Configurations.GetAllAsync(); foreach (Configuration config in service.Configurations) { Console.WriteLine(config.Id); } Console.WriteLine("Log off"); await service.LogOffAsync(); }
/// <summary> /// Runs the specified service. /// </summary> /// <param name="service">The service.</param> /// <returns>a task</returns> static async Task Run(Service service) { await service.LogOnAsync(SdkHelper.Splunk.Username, SdkHelper.Splunk.Password); try { //// This code shows how to execute a long-running search job. //// We query for the first 100,000 records from Splunk's _internal index and choose a 3 second //// delay to improve the chances our retry loop runs more than once. int delay = 3000; var job = await service.Jobs.CreateAsync("search index=_internal | head 100000", mode: ExecutionMode.Normal); for (int count = 1; ; ++count) { try { await job.TransitionAsync(DispatchState.Done, delay); break; } catch (TaskCanceledException) { // Consider logging the fact that the operation is taking a long time, around count * (delay / 1000) seconds so far // Also consider stopping the query, if it runs too long } // Consider increasing the delay on each iteration } //// Now that the search job is done we can print the results. //// This example shows how to fetch raw search results in a specific format: JSON. Select an alternative format by //// by selecting the OutputMode you like. using (var message = await job.GetSearchResponseMessageAsync(outputMode: OutputMode.Json)) { Console.Error.WriteLine("Search results (Press Control-C to cancel:"); var content = await message.Content.ReadAsStringAsync(); Console.WriteLine(content); } } finally { service.LogOffAsync().Wait(); } }
/// <summary> /// Runs the specified service. /// </summary> /// <param name="service">The service.</param> /// <returns>a task</returns> static async Task Run(Service service) { try { await service.LogOnAsync(SdkHelper.Splunk.Username, SdkHelper.Splunk.Password); Console.WriteLine("Data inputs:"); var collection = service.CreateEntityCollection("data", "inputs", "all"); int count = 0; await collection.GetAllAsync(); //// TODO: //// [X] 1. Make Entity<TResource>.Content public (It still must be assigned to a dynamic variable before use.) //// [X] 2. Write a convenience method on the Service object for getting an EntityCollection on some path: service.CreateEntityCollection("data", "inputs", "all") //// [X] 3. Write a convenience method on the Service object for getting an Entity on some path: something like service.CreateEntity("data", "inputs", "tcp", "ssl") //// [X] 4. Add service.CreateEntityCollectionCollection for completeness. //// [X] 5. Revert the access change to EntityCollection<Entity<TResource>, TResource>(service, new ResourceName("data", "inputs", "all")) because (2) makes it unnecessary. //// [X] 6. Revert the access change to Entity<TResource>(service, new ResourceName("data", "inputs", "all")) because (3) makes it unnecessary. //// [ ] 7. Enliven the example. //// [ ] 8. Fill holes in IService (holes are unrelated to this exercise) foreach (var entity in collection) { Console.WriteLine("{0:D5}. {1}", ++count, entity.Id); dynamic dataInput = entity.Content; Console.WriteLine(" Disabled: {0}", dataInput.Disabled); Console.WriteLine(" Index: {0}", dataInput.Index); Console.WriteLine(" Type: {0}", dataInput.Eai.Type); if (dataInput.Disabled == "0") { try { // Restart... await entity.SendAsync(HttpMethod.Post, "disable"); await entity.SendAsync(HttpMethod.Post, "enable"); } catch (Exception e) { Console.WriteLine("Could not restart '{0}': {1}", entity.Id, e.Message); } } } await service.LogOffAsync(); } catch (Exception e) { Console.WriteLine(e); } }