Created
April 30, 2012 18:42
-
-
Save softlayer/2560998 to your computer and use it in GitHub Desktop.
Identify status of LB resources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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