Skip to content

Commit d9c6636

Browse files
authored
fix(java, c#): Telegraf configuration to create uses TelegrafPluginRequest model (#38)
1 parent e898cee commit d9c6636

File tree

5 files changed

+463
-4
lines changed

5 files changed

+463
-4
lines changed

generate-csharp.sh

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ set -ex
44

55
SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
66

7+
if [ -f "$SCRIPT_PATH"/influxdb-client-csharp.patch ]; then
8+
(cd "$SCRIPT_PATH"/build/influxdb-client-csharp/ && git apply "$SCRIPT_PATH"/influxdb-client-csharp.patch)
9+
fi
10+
711
rm ./build/influxdb-client-csharp/Client/InfluxDB.Client.Api/Domain/*.cs || true
812
rm ./build/influxdb-client-csharp/Client/InfluxDB.Client.Api/Service/*.cs || true
913
rm ./build/influxdb-client-csharp/Client/InfluxDB.Client.Api/Client/*.cs || true

influxdb-client-csharp.patch

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
diff --git a/Client.Test/ItTelegrafsApiTest.cs b/Client.Test/ItTelegrafsApiTest.cs
2+
index ca5df13..168f574 100644
3+
--- a/Client.Test/ItTelegrafsApiTest.cs
4+
+++ b/Client.Test/ItTelegrafsApiTest.cs
5+
@@ -37,7 +37,7 @@ namespace InfluxDB.Client.Test
6+
{"report_active", false},
7+
{"avoid_null", null},
8+
};
9+
- return new TelegrafPlugin(TelegrafPlugin.TypeEnum.Inputs, "cpu", config: config);
10+
+ return new TelegrafPlugin(TelegrafPlugin.TypeEnum.Input, "cpu", config: config);
11+
}
12+
13+
private static TelegrafPlugin NewOutputPlugin()
14+
@@ -50,7 +50,7 @@ namespace InfluxDB.Client.Test
15+
{"urls", new List<string> {"http://localhost:9999"}}
16+
};
17+
18+
- return new TelegrafPlugin(TelegrafPlugin.TypeEnum.Outputs, "influxdb_v2", "my instance",
19+
+ return new TelegrafPlugin(TelegrafPlugin.TypeEnum.Output, "influxdb_v2", "my instance",
20+
config);
21+
}
22+
23+
diff --git a/Client/TelegrafsApi.cs b/Client/TelegrafsApi.cs
24+
index fbaa0df..60fe11f 100644
25+
--- a/Client/TelegrafsApi.cs
26+
+++ b/Client/TelegrafsApi.cs
27+
@@ -112,8 +112,17 @@ namespace InfluxDB.Client
28+
config.Append("\n");
29+
}
30+
31+
- var request = new TelegrafRequest(name: name, description: description, orgID: orgId,
32+
- config: config.ToString());
33+
+ var pluginsList = plugins
34+
+ .Select(it => new TelegrafPluginRequestPlugins(
35+
+ it.Type.ToString().ToLower(),
36+
+ it.Name,
37+
+ description: it.Description,
38+
+ config: it.Config)
39+
+ )
40+
+ .ToList();
41+
+
42+
+ var request = new TelegrafPluginRequest(name, description, orgID: orgId, config: config.ToString(),
43+
+ plugins: pluginsList);
44+
45+
return CreateTelegrafAsync(request);
46+
}
47+
@@ -126,11 +135,12 @@ namespace InfluxDB.Client
48+
/// <param name="org">The organization that owns this config</param>
49+
/// <param name="config">ConfigTOML contains the raw toml config</param>
50+
/// <param name="metadata">Metadata for the config</param>
51+
+ /// <param name="plugins">Plugins to use.</param>
52+
/// <returns>Telegraf config created</returns>
53+
public Task<Telegraf> CreateTelegrafAsync(string name, string description, Organization org,
54+
- string config, TelegrafRequestMetadata metadata)
55+
+ string config, TelegrafRequestMetadata metadata, List<TelegrafPluginRequestPlugins> plugins)
56+
{
57+
- return CreateTelegrafAsync(name, description, org.Id, config, metadata);
58+
+ return CreateTelegrafAsync(name, description, org.Id, config, metadata, plugins);
59+
}
60+
61+
/// <summary>
62+
@@ -141,11 +151,12 @@ namespace InfluxDB.Client
63+
/// <param name="orgId">The organization that owns this config</param>
64+
/// <param name="config">ConfigTOML contains the raw toml config</param>
65+
/// <param name="metadata">Metadata for the config</param>
66+
+ /// <param name="plugins">Plugins to use.</param>
67+
/// <returns>Telegraf config created</returns>
68+
public Task<Telegraf> CreateTelegrafAsync(string name, string description, string orgId,
69+
- string config, TelegrafRequestMetadata metadata)
70+
+ string config, TelegrafRequestMetadata metadata, List<TelegrafPluginRequestPlugins> plugins)
71+
{
72+
- var request = new TelegrafRequest(name, description, metadata, config, orgId);
73+
+ var request = new TelegrafPluginRequest(name, description, plugins, metadata, config, orgId);
74+
75+
return CreateTelegrafAsync(request);
76+
}
77+
@@ -155,7 +166,7 @@ namespace InfluxDB.Client
78+
/// </summary>
79+
/// <param name="telegrafRequest">Telegraf Configuration to create</param>
80+
/// <returns>Telegraf config created</returns>
81+
- public Task<Telegraf> CreateTelegrafAsync(TelegrafRequest telegrafRequest)
82+
+ public Task<Telegraf> CreateTelegrafAsync(TelegrafPluginRequest telegrafRequest)
83+
{
84+
Arguments.CheckNotNull(telegrafRequest, nameof(telegrafRequest));
85+
86+
@@ -201,7 +212,7 @@ namespace InfluxDB.Client
87+
{
88+
Arguments.CheckNotNull(telegraf, nameof(telegraf));
89+
90+
- var request = new TelegrafRequest(telegraf.Name, telegraf.Description, telegraf.Metadata, telegraf.Config,
91+
+ var request = new TelegrafPluginRequest(telegraf.Name, telegraf.Description, default, telegraf.Metadata, telegraf.Config,
92+
telegraf.OrgID);
93+
94+
return UpdateTelegrafAsync(telegraf.Id, request);
95+
@@ -213,7 +224,7 @@ namespace InfluxDB.Client
96+
/// <param name="telegrafId">ID of telegraf config</param>
97+
/// <param name="telegrafRequest">telegraf config update to apply</param>
98+
/// <returns>An updated telegraf</returns>
99+
- public Task<Telegraf> UpdateTelegrafAsync(string telegrafId, TelegrafRequest telegrafRequest)
100+
+ public Task<Telegraf> UpdateTelegrafAsync(string telegrafId, TelegrafPluginRequest telegrafRequest)
101+
{
102+
Arguments.CheckNonEmptyString(telegrafId, nameof(telegrafId));
103+
Arguments.CheckNotNull(telegrafRequest, nameof(telegrafRequest));
104+
@@ -272,7 +283,7 @@ namespace InfluxDB.Client
105+
Arguments.CheckNonEmptyString(clonedName, nameof(clonedName));
106+
Arguments.CheckNotNull(telegraf, nameof(telegraf));
107+
108+
- var cloned = new TelegrafRequest(clonedName, telegraf.Description, telegraf.Metadata, telegraf.Config,
109+
+ var cloned = new TelegrafPluginRequest(clonedName, telegraf.Description, default, telegraf.Metadata, telegraf.Config,
110+
telegraf.OrgID);
111+
112+
var created = await CreateTelegrafAsync(cloned).ConfigureAwait(false);

0 commit comments

Comments
 (0)