Table of Contents

Building a GQI data source that retrieves data from a DMS

In this tutorial, you will learn how you can create a GQI data source that retrieves the version info of the Agents in your DMS.

Expected duration: 15 minutes.

Prerequisites

Overview

Step 1: Create the ad hoc data source

  1. Create a new class that implements the IGQIDatasource interface.

    Note

    If certain types cannot be found in the file, verify if the Skyline.DataMiner.Dev.Automation NuGet package has the correct version. Go to Tools > NuGet Package Manager > Manage NuGet Packages for Solution. Select Skyline.DataMiner.Dev.Automation, and verify whether the version installed for the current project is at least 10.3.4.

  2. Implement the GetColumns method to define the columns of the data source.

    The data source will include two columns: an Agent ID column of type Int and a Version column of type String.

  3. Implement the GetNextPage method to provide the actual data.

    For now, leave it empty, as you still need to retrieve the data from the DMS.

[GQIMetaData(Name = "Agent Versions")]
public class AgentVersions : IGQIDataSource
{
    public GQIColumn[] GetColumns()
    {
        return new GQIColumn[]
        {
            new GQIIntColumn("Agent ID"),
            new GQIStringColumn("Version"),
        };
    }

    public GQIPage GetNextPage(GetNextPageInputArgs args)
    {
        // TODO: Fetch the data
        return default;
    }
}
Note

Above the class, a GQIMetaData attribute was added to configure the name of the data source as displayed in the Dashboards app or Low-Code Apps.

Step 2: Fetch the Agents in the DMS

To retrieve the Agent information, the data source will have to communicate with the DMS. The information can be retrieved using the OnInitInputArgs argument of the OnInit method, by implementing the IGQIOnInit interface. Depending on the DataMiner version used, a different approach will be needed.

  1. Go to Tools > NuGet Package Manager > Manage NuGet Packages for Solution.

  2. Select Browse and search for Skyline.DataMiner.Core.DataMinerSystem.Common, and install the latest version of the class library.

  3. Add the IGQIOnInit interface to the class.

  4. Implement the OnInit method, which receives OnInitInputArgs as parameters.

  5. Store the IDms object as a field of the class for later use.

    [GQIMetaData(Name = "Agent Versions")]
    public class AgentVersions : IGQIDataSource
    {
        private IDms _dms;
    
        public OnInitOutputArgs OnInit(OnInitInputArgs args)
        {
            _dms = args.DMS.GetConnection().GetDms();
            return default;
        }
    }
    
  6. Use the IDms object to retrieve information from the DMS.

    Retrieve the Agents by calling the GetAgents method. The response will be a collection of IDma objects.

    public GQIPage GetNextPage(GetNextPageInputArgs args)
    {
        var agents = _dms.GetAgents();
        return default;
    }
    

Step 3: Transform the DMS response into a GQIPage

Transform the response into a GQIPage. Each Agent in the cluster will be converted into a row. Again, a different approach will be needed depending on the DataMiner version used.

public GQIPage GetNextPage(GetNextPageInputArgs args)
{
    var agents = _dms.GetAgents();
    var rows = new List<GQIRow>();
    foreach (var agent in agents)
    {
        rows.Add(new GQIRow(agent.Id.ToString(), new GQICell[]
        {
            new GQICell { Value = agent.Id },
            new GQICell { Value = agent.VersionInfo },
        }));
    }

    return new GQIPage(rows.ToArray());
}

Step 4: Configure the script to compile as a library

In order for GQI to work, the script must be configured to compile as a library.

To do so:

  • If you use DIS, add the following to the Script.Exe tag in the script XML:

       <Param type="preCompile">true</Param>
       <Param type="libraryName">Agent_Versions</Param>
    
    Note

    Avoid placing '.' in the library name. As this makes the script un-editable in cube.

  • If you do not use DIS, in the Automation module in Cube, select the Compile as library option. See Compiling a C# code block as a library.