#!/usr/bin/perl

#-------------------------------------------------------------
#use SOAP::Lite + trace => qw(method debug);
use SOAP::Lite;

BEGIN {push (@INC, "..");}
use iControlTypeCast;

#-----------------------------------------------------------

#-----------------------------------------------------------
#Arguments
#----------------------------------------------------------
my $iHost = $ARGV[0];
my $iPort = $ARGV[1];
my $iUser = $ARGV[2];
my $iPass = $ARGV[3];
my $iInterface = $ARGV[4];
#makes iControl connection to the bigip

sub SOAP::Transport::HTTP::Client::get_basic_credentials
{
        return "$iUser" => "$iPass";
}

$soap = SOAP::Lite
        -> uri('urn:iControl:Networking/Interfaces')
        -> proxy("https://$iHost:$iPort/iControl/iControlPortal.cgi");

#splits the intercases on comma
@interfaces = split(/,/,$iInterface);

#get the status of each interface entered into the script
foreach $interface(@interfaces)
{
  $soapResponse = $soap->get_media_status
  (
     SOAP::Data->name(interfaces => [$interface])
  );
  my @interfacestatus = @{$soapResponse->result};
  print "$interface = $interfacestatus[0]\n";
  #if the enterface is not up it marks the interface in a array 
  #and print out the failing arrays
  if ($interfacestatus[0] ne "MEDIA_STATUS_UP")
  {
     push (@output,$interface);
     $int_down = 1;
  }
}
#checks to see if the all interfaces are up of down
#if down send alert to nagios
if ($int_down == 1) {
   print "The following interfaces are down @output\n";
   exit 1;
}
else {
   print "All interfaces are up\n";
   exit 0;
}

   
