Issue
Script for retrive alerts from SolarEdge site
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.7.34221.43
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "console_solaredge", "console_SolarEdge\console_solaredge.csproj", "{E3C07904-13C9-42E6-A15B-1A0B0061105C}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{E3C07904-13C9-42E6-A15B-1A0B0061105C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{E3C07904-13C9-42E6-A15B-1A0B0061105C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{E3C07904-13C9-42E6-A15B-1A0B0061105C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{E3C07904-13C9-42E6-A15B-1A0B0061105C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {0DF57379-1702-48D4-98CF-858B9906CA9A}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace console_solaredge
|
||||||
|
{
|
||||||
|
public class Model
|
||||||
|
{
|
||||||
|
public class SolarEdgeModel
|
||||||
|
{
|
||||||
|
[JsonProperty("count")]
|
||||||
|
public long Count { get; set; }
|
||||||
|
[JsonProperty("alerts")]
|
||||||
|
public List<Alert>? Alerts { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Alert
|
||||||
|
{
|
||||||
|
[JsonProperty("alertId")]
|
||||||
|
public long AlertId { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("siteId")]
|
||||||
|
public long SiteId { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("creationDate")]
|
||||||
|
public long CreationDate { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("category")]
|
||||||
|
public string? Category { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("impact")]
|
||||||
|
public long Impact { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("componentType")]
|
||||||
|
public string? ComponentType { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("alertType")]
|
||||||
|
public string? AlertType { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("reporterId")]
|
||||||
|
public long ReporterId { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("reporterSerialNumber")]
|
||||||
|
public string? ReporterSerialNumber { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("status")]
|
||||||
|
public string? Status { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("serverStatus")]
|
||||||
|
public string? ServerStatus { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("muted")]
|
||||||
|
public bool Muted { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("lastTrigger")]
|
||||||
|
public long LastTrigger { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("open")]
|
||||||
|
public bool Open { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("timeOffset")]
|
||||||
|
public long TimeOffset { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("units")]
|
||||||
|
public List<object>? Units { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("description")]
|
||||||
|
public string? Description { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("resolution")]
|
||||||
|
public string? Resolution { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("isSupportAlert")]
|
||||||
|
public bool IsSupportAlert { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Text;
|
||||||
|
using static console_solaredge.Model;
|
||||||
|
|
||||||
|
SolarEdgeModel result = new();
|
||||||
|
var credential = Convert.ToBase64String(Encoding.ASCII.GetBytes($"ced@pal.it:#zPG6tax1yuiWU*8iw"));
|
||||||
|
var handler = new HttpClientHandler();
|
||||||
|
handler.CookieContainer = new CookieContainer();
|
||||||
|
|
||||||
|
using (var client = new HttpClient(handler))
|
||||||
|
{
|
||||||
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credential);
|
||||||
|
var response = await client.GetAsync("https://monitoring.solaredge.com/solaredge-web/p/site/3834979/#/dashboard");
|
||||||
|
var cookies = handler.CookieContainer.GetCookies(new Uri("https://monitoring.solaredge.com"));
|
||||||
|
|
||||||
|
string csrfToken = null;
|
||||||
|
foreach (Cookie cookie in cookies)
|
||||||
|
{
|
||||||
|
if (cookie.Name == "CSRF-TOKEN")
|
||||||
|
{
|
||||||
|
csrfToken = cookie.Value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ArgumentNullException.ThrowIfNull(csrfToken);
|
||||||
|
|
||||||
|
var alertRequest = new HttpRequestMessage(HttpMethod.Post, "https://monitoring.solaredge.com/solaredge-apigw/api/rna/v1.0/site/3834979/alerts?count=20&page=1");
|
||||||
|
alertRequest.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0");
|
||||||
|
alertRequest.Headers.Add("Accept", "application/json, text/plain, */*");
|
||||||
|
alertRequest.Headers.Add("Accept-Language", "it,it-IT;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6");
|
||||||
|
alertRequest.Headers.Add("Connection", "keep-alive");
|
||||||
|
alertRequest.Headers.Add("Origin", "https://monitoring.solaredge.com");
|
||||||
|
alertRequest.Headers.Add("Referer", "https://monitoring.solaredge.com/solaredge-web/p/site/3834979/");
|
||||||
|
alertRequest.Headers.Add("Sec-Fetch-Dest", "empty");
|
||||||
|
alertRequest.Headers.Add("Sec-Fetch-Mode", "cors");
|
||||||
|
alertRequest.Headers.Add("Sec-Fetch-Site", "same-origin");
|
||||||
|
alertRequest.Headers.Add("X-CSRF-TOKEN", csrfToken);
|
||||||
|
alertRequest.Headers.Add("sec-ch-ua", "\"Microsoft Edge\";v=\"119\", \"Chromium\";v=\"119\", \"Not?A_Brand\";v=\"24\"");
|
||||||
|
alertRequest.Headers.Add("sec-ch-ua-mobile", "?0");
|
||||||
|
alertRequest.Headers.Add("sec-ch-ua-platform", "Windows");
|
||||||
|
alertRequest.Content = new StringContent("[{\"fieldFilterOperator\":\"IN\",\"fieldName\":\"status\",\"fieldValue\":[\"OPEN\"]}]", Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
|
var alertResponse = await client.SendAsync(alertRequest);
|
||||||
|
string responseText = await alertResponse.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
|
var apiResult = JsonConvert.DeserializeObject<SolarEdgeModel>(responseText);
|
||||||
|
var groupOpenAlert = apiResult.Alerts.Where(x => x.Open == true).ToList();
|
||||||
|
|
||||||
|
result.Count = groupOpenAlert.Count;
|
||||||
|
result.Alerts = new List<Alert>();
|
||||||
|
|
||||||
|
foreach (var alert in groupOpenAlert)
|
||||||
|
{
|
||||||
|
result.Alerts.Add(alert);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.Count > 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Alert Count: " + result.Count);
|
||||||
|
Console.WriteLine("");
|
||||||
|
|
||||||
|
foreach (var alert in result.Alerts)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[{ result.Alerts.ToList().IndexOf(alert) + 1}]");
|
||||||
|
Console.WriteLine("Type :\t\t" + alert.AlertType);
|
||||||
|
Console.WriteLine("Impact :\t" + alert.Impact);
|
||||||
|
Console.WriteLine("Device :\t" + alert.ComponentType);
|
||||||
|
Console.WriteLine("Device S\\N :\t" + alert.ReporterSerialNumber);
|
||||||
|
Console.WriteLine("On Date :\t" + DateTimeOffset.FromUnixTimeMilliseconds(alert.CreationDate).ToLocalTime().ToString("dd/MM/yyyy HH:mm"));
|
||||||
|
Console.WriteLine("Last Trigger :\t" + DateTimeOffset.FromUnixTimeMilliseconds(alert.LastTrigger).ToLocalTime().ToString("dd/MM/yyyy HH:mm"));
|
||||||
|
Console.WriteLine("");
|
||||||
|
}
|
||||||
|
|
||||||
|
Environment.Exit(2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("System run without alert!");
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="HtmlAgilityPack" Version="1.11.54" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
Reference in New Issue
Block a user