Skip to content

Instantly share code, notes, and snippets.

@softlayer
Created April 30, 2012 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save softlayer/2560998 to your computer and use it in GitHub Desktop.
Save softlayer/2560998 to your computer and use it in GitHub Desktop.
Identify status of LB resources
#!/usr/bin perl
use warnings;
use strict;
use SoftLayer::API::SOAP;
# Set SLAPI User and Key
my $api_username = '';
my $api_key = '';
# ID of LoadBalancer to poll
my $loadBalancerVipId = 0;
# Create API client and set object mask
my $vipService = SoftLayer::API::SOAP->new('SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_VirtualIpAddress', $loadBalancerVipId, $api_username, $api_key);
my $objectMask = {
'ipAddress' => {},
'virtualServers' => {
'serviceGroups' => {
'services' => {
'ipAddress' => {}
},
}
}
};
$vipService->setObjectMask($objectMask);
my $result = $vipService->getObject();
if ($result->fault) {
die 'There was an error: ' . $result->faultstring;
}
my $services = $result->result->{virtualServers}[0]->{serviceGroups}[0]->{services};
my $totalServicesUp = 0;
my $totalServicesDown = 0;
my $i = 0;
print "VIP ".$result->result->{ipAddress}->{ipAddress}."(".$loadBalancerVipId.") retrieved.\n";
for my $i (0 .. $#{$services}) {
my $service = $services->[$i];
print $service->{id};
if ($service->{status} eq 'UP') {
$totalServicesUp = $totalServicesUp + 1;
print '[ UP ] ' . $service->{ipAddress}->{ipAddress} . "\n";
} else {
$totalServicesDown = $totalServicesDown +1;
print '[DOWN] ' . $service->{ipAddress}->{ipAddress} . "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment