Hi,
I have put together a small example code for you to use as a reference:
using Genesyslab.Platform.Commons.Protocols;
using Genesyslab.Platform.Reporting.Protocols;
using Genesyslab.Platform.Reporting.Protocols.StatServer;
using Genesyslab.Platform.Reporting.Protocols.StatServer.Events;
using Genesyslab.Platform.Reporting.Protocols.StatServer.Requests;
using System;
using System.Collections.Generic;
namespace StatServerReasonCode
{
class Program
{
static Dictionary<int, Tuple<string, string>> referenceIds = new Dictionary<int, Tuple<string, string>>();
static void Main(string[] args)
{
string statServerHost = "10.131.3.101";
int statServerPort = 7000;
StatServerProtocol exampleProtocol = new StatServerProtocol(new Endpoint(statServerHost, statServerPort));
// Specifies a method to handle non-request related messages
exampleProtocol.Received += statServer_StatReceived;
exampleProtocol.Open();
// All your Groups that you want to monitor
HashSet<string> agentGroups = new HashSet<string>
{
"Group1",
"Group2",
"Group3",
"Group4"
};
// All filters that you want to apply to your Statistic Type in separate statistics
HashSet<string> filters = new HashSet<string>
{
"AUX_RC_1",
"AUX_RC_2",
"AUX_RC_3"
};
foreach (string groupName in agentGroups)
{
foreach (string filter in filters)
{
// This is used to get which object/filter when the EventInfo is received.
// Will later be added to the static dictionary referenceIds to be retreived later on the
// Message handler "statServer_StatReceived" method
Tuple<string, string> agentGroupAndFilter = new Tuple<string, string>(groupName, filter);
StatisticObject statObject = StatisticObject.Create();
statObject.ObjectType = StatisticObjectType.GroupAgents;
statObject.TenantName = "Environment";
statObject.ObjectId = agentGroupAndFilter.Item1;
StatisticMetric statMetric = StatisticMetric.Create();
statMetric.StatisticType = "CurrNumberNotReadyStatuses";
statMetric.Filter = agentGroupAndFilter.Item2;
Notification statNotification = Notification.Create();
statNotification.Mode = NotificationMode.Immediate;
statNotification.Insensitivity = 1;
RequestOpenStatistic requestOpenStatistic = RequestOpenStatistic.Create();
requestOpenStatistic.StatisticObject = statObject;
requestOpenStatistic.StatisticMetric = statMetric;
requestOpenStatistic.Notification = statNotification;
IMessage response = exampleProtocol.Request(requestOpenStatistic);
referenceIds.Add(requestOpenStatistic.ReferenceId, agentGroupAndFilter);
switch(response.Name)
{
case "EventStatisticOpened":
Console.WriteLine($"Registered statistic for object {groupName} and filter {filter}");
break;
case "EventError":
Console.WriteLine($"Error opening statistic for object {groupName} and filter {filter}");
break;
}
}
}
}
private static void statServer_StatReceived(object sender, EventArgs e)
{
IMessage message = ((MessageEventArgs)e).Message;
// Discard messages that are not of type "EventInfo" (message that contains statistic values)
if (!message.Name.Equals("EventInfo", StringComparison.InvariantCultureIgnoreCase)) return;
EventInfo eventInfo = (EventInfo)message;
// Discard messages that are not about a statistic that we are waiting for the data
if (!referenceIds.ContainsKey(eventInfo.ReferenceId)) return;
// Get the group/filter combination based on the ReferenceId of the received message
Tuple<string, string> agentGroupAndFilter = referenceIds[eventInfo.ReferenceId];
string groupName = agentGroupAndFilter.Item1;
string filter = agentGroupAndFilter.Item2;
Console.WriteLine($"Received current value of group {groupName}, filter {filter}: {eventInfo.IntValue}");
}
}
}
Regards,
HDS