This commit is contained in:
Michal 2024-08-18 02:01:27 +01:00
parent 9451138fe5
commit 7767455a38
9 changed files with 38 additions and 6 deletions

View File

@ -25,7 +25,7 @@ namespace PrometheusExporterEdenic
private readonly HttpClient _client;
private readonly string _authToken;
private readonly string _orgid;
private readonly string _apimainurl = "https://api.edenic.io/api/v1/device";
private readonly string _apimainurl = "https://api.edenic.io/api/v1";
private string _devicename;
public string DeviceId { get; private set; }
@ -48,8 +48,9 @@ namespace PrometheusExporterEdenic
{
try
{
HttpResponseMessage response = await _client.GetAsync($"{_apimainurl}/{_orgid}{path}");
HttpResponseMessage response = await _client.GetAsync($"{_apimainurl}{path}");
Console.WriteLine($"Request send to: {_apimainurl}{path}");
if (response.IsSuccessStatusCode)
{
string content = await response.Content.ReadAsStringAsync();
@ -75,7 +76,7 @@ namespace PrometheusExporterEdenic
{
try
{
dynamic result = await MakeApiRequest<object>("");
dynamic result = await MakeApiRequest<object>($"/device/{_orgid}");
string jsonString = result.ToString(); // Convert dynamic to string
Console.WriteLine($"Raw JSON: {jsonString}"); // Debug output
@ -100,6 +101,37 @@ namespace PrometheusExporterEdenic
return null;
}
}
public async Task<string> GetTelemetry()
{
try
{
dynamic result = await MakeApiRequest<object>($"/telemetry/{DeviceId}");
string jsonString = result.ToString(); // Convert dynamic to string
Console.WriteLine($"Raw JSON: {jsonString}"); // Debug output
return jsonString;
// var devices = JsonSerializer.Deserialize<List<Device>>(jsonString);
// Console.WriteLine($"Deserialized {devices.Count} devices"); // Debug output
//
// var targetDevice = devices.FirstOrDefault(d => d.label == name);
// if (targetDevice != null)
// {
// Console.WriteLine($"Found device: {targetDevice.label}, ID: {targetDevice.id}"); // Debug output
// return targetDevice.id;
// }
// else
// {
// Console.WriteLine($"No device found with label: {name}"); // Debug output
// return null;
// }
}
catch (Exception ex)
{
Console.WriteLine($"Error in GetDeviceIdByName: {ex.Message}"); // Debug output
return null;
}
}
}
public class Program

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("EdenicExporter")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f1be1e80b9c9b26103bc6df1148538674cdf99b9")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9451138fe5f22ab586beafbc14d8ed95103e23f5")]
[assembly: System.Reflection.AssemblyProductAttribute("EdenicExporter")]
[assembly: System.Reflection.AssemblyTitleAttribute("EdenicExporter")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
119886f42dc5b610e5b763673658a8f8230bdd04e244e8c6f0c34a054a44ab6b
184710734eedccb7e8218a40f90b97508609f3208f7414d1463795baa0b9e857