Retrieving data from DataMiner
GQI extensions can retrieve data from the DataMiner System (DMS) using DMSMessage objects.
Important
DMS messages are subject to change without notice. If you can implement an alternative using the built-in data sources, we highly recommend that you do so instead.
Choosing an approach
Choose the approach based on the API you use, the lifetime of the code that needs the connection, and whether the connection should be reusable.
- Injecting IConnection: Use this when you need direct access to an active SLNet connection, for example in short-lived extensions or services, or to use existing DataMiner libraries that require an
IConnection. - Injecting IGQIDMSInterface: Use this when you want to request a live connection when needed. This is useful for longer-running extensions or services, because
GetConnection()can be called again if the connection was dropped. - Using OnInitInputArgs.DMS: Use this with the legacy
SLAnalyticsTypesAPI or when constructor injection is not available.
Tip
To share or cache retrieved data across different GQI sessions, IGQIDMSInterface and IConnection can also be used via user-scoped GQI services. For more information, see Retrieving data from DataMiner in services.
Injecting IConnection
From DataMiner 10.5.0 [CU18]/10.6.0 [CU6]/10.6.9 onwards, extensions using the Skyline.DataMiner.Core.GQI.Extensions API and the GQI DxM can use constructor injection to receive an IConnection instance.
This is the most direct option: the constructor receives an active connection that can be used immediately. This is ideal for short-lived extensions or services.
Tip
Because of its complexity, instead of interacting directly with the IConnection interface, the best way you can use it is by integrating with existing DataMiner libraries.
using System.Collections.Generic;
using System.Linq;
using Skyline.DataMiner.Core.GQI.Extensions;
using Skyline.DataMiner.Net;
using Skyline.DataMiner.Net.Messages;
[GQIMetaData(Name = "Client connections")]
public sealed class ClientConnectionSource : IGQIDataSource
{
private readonly IConnection _connection;
public ClientConnectionSource(IConnection connection)
{
_connection = connection;
}
public GQIColumn[] GetColumns() => ...;
public GQIPage GetNextPage(GetNextPageInputArgs args)
{
var connections = GetConnections();
var rows = connections.Select(CreateRow).ToArray();
return new GQIPage(rows);
}
private IEnumerable<LoginInfoResponseMessage> GetConnections()
{
var request = new GetInfoMessage(InfoType.ClientList);
var responses = _connection.HandleMessage(request);
return responses.OfType<LoginInfoResponseMessage>();
}
private GQIRow CreateRow(LoginInfoResponseMessage connection) => ...;
}
Injecting IGQIDMSInterface
From DataMiner 10.5.0 [CU18]/10.6.0 [CU6]/10.6.9 onwards, extensions using the Skyline.DataMiner.Core.GQI.Extensions API and the GQI DxM can use constructor injection to receive an IGQIDMSInterface instance.
This option is slightly more indirect: call GetConnection() to get a live IConnection. For longer-running extensions or services, this allows you to request a fresh connection if the previous connection was dropped.
using System.Collections.Generic;
using System.Linq;
using Skyline.DataMiner.Core.GQI.Extensions;
using Skyline.DataMiner.Net.Messages;
[GQIMetaData(Name = "Client connections")]
public sealed class ClientConnectionSource : IGQIDataSource
{
private readonly IGQIDMSInterface _dmsInterface;
public ClientConnectionSource(IGQIDMSInterface dmsInterface)
{
_dmsInterface = dmsInterface;
}
public GQIColumn[] GetColumns() => ...;
public GQIPage GetNextPage(GetNextPageInputArgs args)
{
var connections = GetConnections();
var rows = connections.Select(CreateRow).ToArray();
return new GQIPage(rows);
}
private IEnumerable<LoginInfoResponseMessage> GetConnections()
{
var request = new GetInfoMessage(InfoType.ClientList);
var connection = _dmsInterface.GetConnection();
var responses = connection.HandleMessage(request);
return responses.OfType<LoginInfoResponseMessage>();
}
private GQIRow CreateRow(LoginInfoResponseMessage connection) => ...;
}
Using OnInitInputArgs.DMS
From DataMiner 10.3.4/10.4.0 onwards, ad hoc data sources can use the DMS property of OnInitInputArgs. To access this property, implement IGQIOnInit.
From DataMiner 10.5.0 [CU18]/10.6.0 [CU6]/10.6.9 onwards, when using the GQI DxM, GQIDMS.GetConnection() can be called again to receive a fresh connection if the underlying SLNet connection was dropped.
Important
GQIDMS can only be used during the lifetime of the associated extension instance. Do not store or reuse it outside that lifetime.
using System.Collections.Generic;
using System.Linq;
using Skyline.DataMiner.Analytics.GenericInterface;
using Skyline.DataMiner.Net.Messages;
[GQIMetaData(Name = "Client connections")]
public class ClientConnectionSource : IGQIDataSource, IGQIOnInit
{
private GQIDMS _dms;
public OnInitOutputArgs OnInit(OnInitInputArgs args)
{
_dms = args.DMS;
return default;
}
public GQIColumn[] GetColumns() => ...;
public GQIPage GetNextPage(GetNextPageInputArgs args)
{
var connections = GetConnections();
var rows = connections.Select(CreateRow).ToArray();
return new GQIPage(rows);
}
private IEnumerable<LoginInfoResponseMessage> GetConnections()
{
var request = new GetInfoMessage(InfoType.ClientList);
var responses = _dms.SendMessages(request);
return responses.OfType<LoginInfoResponseMessage>();
}
private GQIRow CreateRow(LoginInfoResponseMessage connection) => ...;
}