Reputation: 454
I am trying to use the .NET API to disable servers in my Netscaler. I am able to get a list of VIPs and get a list of servers associated with those VIPs. However, some VIPs have service groups associated with them. This is where I am running into an issue. When I reach a VIP that has a service group, I get a null exception error. I am not sure where the service group information is stored in the VIP. Here is my code:
nitro_service session = new nitro_service("<netscaler-IP>");
session.login("<username>", "<password>");
var lbServers = lbvserver.get(session);
foreach (var vip in lbServers)
{
foreach (var service in lbvserver_servicegroup_binding.get(session, vip.name))
{
Console.WriteLine(vip.name);
Console.Write(service.servicegroupname);
Console.WriteLine(service.servicename);
Console.ReadLine();
}
}
I have tried checking to see if servicegroupname is null but it is always null, regardless if there is a service group or server associated with the VIP.
I have also tried to just get the service group without the VIP but lbvserver_servicegroup_binding only takes 2 arguments.
Upvotes: 0
Views: 512
Reputation: 454
I figured it out.
I defined my servicegroup before my foreach.
var serviceGroups = lbvserver_servicegroup_binding.get(session, vip.name);
Then added an if serviceGroups !=null
Upvotes: 1