Hi.
I want to create a dashboard, indicating:
- The number of elements by DMA.
- The number of element licences by DMA but I don't know where to find this data.
Kind regards.
Hi. It seem that in 10.6 releease we could do without SLNET call.
For the moment as I'm not in this release I've resolv all my needs withthis code:
using Skyline.DataMiner.Analytics.GenericInterface;
using Skyline.DataMiner.Net.Messages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
{
private GQIDMS _dms; // SLNet via GQI
// --- Types internes ---
private sealed class DmaRow
{
public string Name { get; set; }
public int Id { get; set; }
public int Max { get; set; }
public int Active { get; set; }
public int Present { get; set; }
public int Available => Math.Max(0, Max - Active); // status actuel
public int AvailableTA => Math.Max(0, Max - Present); // status si tout actif
}
private sealed class AgentInfo
{
public int Id { get; set; }
public string Name { get; set; }
}
// --- Colonnes ---
private readonly GQIStringColumn _cName = new GQIStringColumn("Agent");
private readonly GQIIntColumn _cId = new GQIIntColumn("Agent ID");
private readonly GQIIntColumn _cMax = new GQIIntColumn("Licences (MAX)");
private readonly GQIIntColumn _cActive = new GQIIntColumn("Licences (Actives)");
private readonly GQIIntColumn _cPresent = new GQIIntColumn("Éléments (Présents)");
private readonly GQIIntColumn _cAvail = new GQIIntColumn("Licences (Disponibles)");
private readonly GQIIntColumn _cAvailTA = new GQIIntColumn("Licences (Quand tous actifs)");
public OnInitOutputArgs OnInit(OnInitInputArgs args)
{
_dms = args.DMS;
return default;
}
public GQIColumn[] GetColumns() =>
new GQIColumn[] { _cName, _cId, _cMax, _cActive, _cPresent, _cAvail, _cAvailTA };
public GQIPage GetNextPage(GetNextPageInputArgs args)
{
var agents = GetAllAgents(); // Liste des DMAs (Id/Name)
var elementsByDmaId = GetElementsCountPerDma(); // Nombre d’éléments par DMA
var rows = new List<GQIRow>(agents.Count);
foreach (var a in agents)
{
int id = a.Id;
int present = elementsByDmaId.TryGetValue(id, out var cnt) ? cnt : 0;
int max = GetElementsMaxViaLicenses(id);
int active = GetElementsActiveViaActivatedCounters(id);
var cells = new[]
{
new GQICell { Value = a.Name },
new GQICell { Value = id },
new GQICell { Value = max },
new GQICell { Value = active },
new GQICell { Value = present },
new GQICell { Value = ( max - active) },
new GQICell { Value = ( max - present) },
};
rows.Add(new GQIRow(cells));
}
return new GQIPage(rows.ToArray());
}
// ----------- SLNet helpers -----------
// Récupère 1 réponse par agent : GetDataMinerInfoResponseMessage
private List<AgentInfo> GetAllAgents()
{
var result = new List<AgentInfo>();
try
{
var responses = _dms.SendMessages(new GetInfoMessage { Type = InfoType.DataMinerInfo });
foreach (var r in responses.OfType<GetDataMinerInfoResponseMessage>())
{
result.Add(new AgentInfo { Id = r.ID, Name = r.AgentName });
}
}
catch { }
return result
.GroupBy(x => x.Id)
.Select(g => new AgentInfo
{
Id = g.Key,
Name = g.Select(x => x.Name).FirstOrDefault(n => !String.IsNullOrWhiteSpace(n)) ?? $"DMA {g.Key}",
})
.ToList();
}
private Dictionary<int, int> GetElementsCountPerDma()
{
var dict = new Dictionary<int, int>();
try
{
var responses = _dms.SendMessages(new GetInfoMessage { Type = InfoType.ElementInfo });
var groups = responses.OfType<ElementInfoEventMessage>()
.GroupBy(e => e.DataMinerID);
foreach (var g in groups)
{
dict[g.Key] = g.Count();
}
}
catch { }
return dict;
}
private int GetElementsMaxViaLicenses(int dmaId)
{
try
{
var resp = (GetLicensesResponseMessage)_dms.SendMessage(
new GetInfoMessage { DataMinerID = dmaId, Type = InfoType.Licenses });
var line = resp?.Licenses?
.FirstOrDefault(s => !String.IsNullOrWhiteSpace(s) &&
s.Trim().StartsWith("ELEMENTS", StringComparison.OrdinalIgnoreCase));
if (!String.IsNullOrEmpty(line))
{
var m = Regex.Match(line, @"ELEMENTS\s*(\d+)", RegexOptions.IgnoreCase);
if (m.Success && Int32.TryParse(m.Groups[1].Value, out var parsed)) return parsed;
}
}
catch { }
return 0;
}
private int GetElementsActiveViaActivatedCounters(int dmaId)
{
try
{
var resp = (GetActivatedLicenseCountersResponseMessage)_dms.SendMessage(
new GetInfoMessage { DataMinerID = dmaId, Type = InfoType.ActivatedLicenseCounters });
var line = resp?.ActivatedLicenseCounters?
.FirstOrDefault(s => !String.IsNullOrWhiteSpace(s) &&
s.Trim().StartsWith("elements", StringComparison.OrdinalIgnoreCase));
if (!String.IsNullOrEmpty(line))
{
var m = Regex.Match(line, @"elements\s*[:=]\s*(\d+)", RegexOptions.IgnoreCase);
if (m.Success && Int32.TryParse(m.Groups[1].Value, out var parsed)) return parsed;
var m2 = Regex.Match(line, @"(\d+)");
if (m2.Success && Int32.TryParse(m2.Value, out var parsed2)) return parsed2;
}
}
catch { }
return 0;
}
}