This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dnoble/Example-of-calling-endpoints-we-do-not-support' …
…into develop Conflicts: splunk-sdk-csharp-pcl.sln src/Splunk.Client/Splunk/Client/Service.cs
- Loading branch information
Showing
31 changed files
with
824 additions
and
722 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright 2013 Splunk, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"): you may | ||
* not use this file except in compliance with the License. You may obtain | ||
* a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
namespace Splunk.Examples.GetSplunkDataInputs | ||
{ | ||
using Splunk.Client; | ||
using Splunk.Client.Helpers; | ||
using System; | ||
using System.Dynamic; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
/// <summary> | ||
/// An example program to access the set of data inputs running on a Splunk instance. | ||
/// </summary> | ||
public class Program | ||
{ | ||
/// <summary> | ||
/// Main. | ||
/// </summary> | ||
/// <param name="args">The arguments.</param> | ||
static void Main(string[] args) | ||
{ | ||
var ns = new Namespace(user: args[0], app: args[1]); | ||
|
||
using (var service = new Service(SdkHelper.Splunk.Scheme, SdkHelper.Splunk.Host, SdkHelper.Splunk.Port, ns)) | ||
{ | ||
Console.WriteLine("Splunk management port: {0}", service.Context); | ||
Console.WriteLine("Namespace: {0}", service.Namespace); | ||
Run(service).Wait(); | ||
} | ||
|
||
Console.Write("Press enter to exit: "); | ||
Console.ReadLine(); | ||
} | ||
|
||
/// <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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
[assembly: AssemblyTitle("Get-SplunkDataInput")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("Splunk, Inc")] | ||
[assembly: AssemblyProduct("Splunk SDK for C#")] | ||
[assembly: AssemblyCopyright("Copyright © 2014")] | ||
[assembly: AssemblyTrademark("Splunk®")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
[assembly: AssemblyVersion("2.1.2.0")] | ||
[assembly: AssemblyFileVersion("2.1.2.0")] | ||
|
||
[assembly: ComVisible(false)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<StyleCopSettings Version="105"> | ||
<GlobalSettings> | ||
<StringProperty Name="LinkedSettingsFile">..\..\splunk-sdk-csharp-pcl.StyleCop</StringProperty> | ||
<StringProperty Name="MergeSettingsFiles">Linked</StringProperty> | ||
</GlobalSettings> | ||
</StyleCopSettings> |
70 changes: 70 additions & 0 deletions
70
examples/Get-SplunkDataInput/get-splunk-data-inputs.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<ProjectGuid>{443CB5CF-1086-40E3-B60C-6B35D7DFCF90}</ProjectGuid> | ||
<AssemblyName>Get-SplunkDataInput</AssemblyName> | ||
<OutputType>Exe</OutputType> | ||
<Platform>AnyCPU</Platform> | ||
<TargetFrameworkProfile /> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> | ||
<ErrorReport>prompt</ErrorReport> | ||
<FileAlignment>512</FileAlignment> | ||
<RootNamespace /> | ||
<RunCodeAnalysis>False</RunCodeAnalysis> | ||
<StyleCopEnabled Condition=" '$(StyleCopEnabled)' == '' ">False</StyleCopEnabled> | ||
<StyleCopTreatErrorsAsWarnings>False</StyleCopTreatErrorsAsWarnings> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Splunk.Client.Helpers\Splunk.Client.Helpers.csproj"> | ||
<Project>{0b0c43f2-ea9c-45ee-a8f7-7a2916dd1717}</Project> | ||
<Name>Splunk.Client.Helpers</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\..\src\Splunk.Client\Splunk.Client.csproj"> | ||
<Project>{de65f0d5-7753-483e-8933-e6db22350f04}</Project> | ||
<Name>Splunk.Client</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.