Perl ARX Network

Problem this snippet solves:

This script is an example of how to use the iControl interfaces provided by an ARX to retrieve all networks and their configurations, statuses and statistics on an ARX.

How to use this snippet:

ARXNetworkExample.pl --url  --user  --pass 

Prerequisites

  1. SOAP::Lite perl module
  2. An F5 ARX system running release V6.02.000 or later and configured with at least one configured network.
  3. Management access on the ARX must be permitted for HTTPs-API or HTTP-API services.

Code :

#!/usr/bin/perl
#-------------------------------------------------------------------------------
# The contents of this file are subject to the "END USER LICENSE AGREEMENT 
# FOR F5 Software Development Kit for iControl"; you may not use this file 
# except in compliance with the License. The License is included in the 
# iControl Software Development Kit.
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is iControl Code and related documentation
# distributed by F5.
#
# The Initial Developer of the Original Code is F5 Networks,
# Inc. Seattle, WA, USA. Portions created by F5 are Copyright (C) 1996-2012
# F5 Networks, Inc. All Rights Reserved.  iControl (TM) is a registered 
# trademark of F5 Networks, Inc.
#
# Alternatively, the contents of this file may be used under the terms
# of the GNU General Public License (the "GPL"), in which case the
# provisions of GPL are applicable instead of those above.  If you wish
# to allow use of your version of this file only under the terms of the
# GPL and not to allow others to use your version of this file under the
# License, indicate your decision by deleting the provisions above and
# replace them with the notice and other provisions required by the GPL.
# If you do not delete the provisions above, a recipient may use your
# version of this file under either the License or the GPL.
#-------------------------------------------------------------------------------
#
# Description
#
# This script is an example of how to use the iControl interfaces provided by
# an ARX to retrieve all networks and their configurations, statuses and
# statistics on an ARX.
#
# Usage: ARXNetworkExample.pl --url  --user  --pass 
#
# Prerequisites:
#
# This script requires the following:
#
#   * SOAP::Lite perl module
#   * An F5 ARX system configured with at least one configured network.
#   * Management access on the ARX must be permitted for HTTP-API and HTTPS-API
#     services.
#
# For more information on ARX configuration, please consult the
# documentation that was provided with your ARX system.
#-------------------------------------------------------------------------------

# SOAP::Lite lets us send SOAP requests and parse them
use SOAP::Lite
    autotype => 0,
    default_ns => 'urn:iControl';

# If you need to debug problems with your script, you can use the +trace 
# option with SOAP::Lite and it will print the XML sent to and received from
# the server:
#
# use SOAP::Lite
#     autotype => 0,
#     default_ns => 'urn:iControl' + trace;

# Getopt::Long lets us easily parse command line options
use Getopt::Long;

use POSIX qw(strftime);

use Carp;

use strict;
use warnings;

#-------------------------------------------------------------------------------
# Main program logic
#-------------------------------------------------------------------------------

our ($url, $user, $pass);

# Load command line options - if the load fails, then we print the usage
# instructions and exit.
if (!GetOptions("url=s" =>  \$url,
                "user=s" => \$user,
                "pass=s" => \$pass)) {
    usage();
    exit(1);
}

# If any arguments were skipped, print the usage instructions and exit.
if (!defined $url || !defined $user || !defined $pass) {
    usage();
    exit(1);
}

# The service path for interface "Interface" is this:
#
# http://:/api/services/Interface
#
my $networkServiceUrl = $url . "/api/services/Network";

# In order for SOAP to access a web service, it needs to read the WSDL
# for the interface you want to use.  The WSDL file for an interface
# called "Interface" is available via http/https on the ARX at:
#
# http://:/api/services/Interface?wsdl
#
# If you need a WSDL 2.0 version, that is also available at:
#
# http://:/arx-api/wsdl/Interface.wsdl2
#
# In this case, we're using the Network interface and we're 
# interested in using the WSDL 1.1 version.
#
my $networkWsdlUrl = $networkServiceUrl . "?wsdl";

# Now we build our SOAP::Lite object using the service and WSDL
# URLs
my $networkSoap = SOAP::Lite->new(proxy   => $networkServiceUrl,
                                  service => $networkWsdlUrl);

#-------------------------------------------------------------------------------
# get_list
#-------------------------------------------------------------------------------

my @networkList = ();

print "Calling the \"get_list\" method of the ARX Network interface.\n\n";

# Build a security header 
our $securityHeader = getSecurityHeader($user, $pass);

my $networkSoapResult = $networkSoap->get_list($securityHeader);

if (defined $networkSoapResult->fault && $networkSoapResult->fault) {
    print("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n");
}
else {
    print "Printing the results of the call to the \"get_list\" method of the ARX Network interface.\n\n";

    @networkList = ($networkSoapResult->result, $networkSoapResult->paramsout);

    if ($#networkList < 0) {
        print("The list of networks returned from the call to the \"get_list\" method of the ARX Network interface was empty.\n");
    }
    else {
        print "Networks:\n";

        foreach my $network (@networkList) {
            print "$network\n";
        }

        print "\n";
    }
}

#-------------------------------------------------------------------------------
# get_stats
#-------------------------------------------------------------------------------

print "Calling the \"get_stats\" method of the ARX Network interface.\n\n";

if ($#networkList < 0) {
    print("The list of networks returned from the call to the \"get_list\" method of the ARX Network interface was empty.\n");
}
else {
    # Build a security header 
    $securityHeader = getSecurityHeader($user, $pass);

    $networkSoapResult = $networkSoap->get_stats(SOAP::Data->name('interface_ids')->value(@networkList), 
                                                 $securityHeader);

    if (defined $networkSoapResult->fault && $networkSoapResult->fault) {
        confess("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n");
    }
    else {
        print "Printing the results of the call to the \"get_stats\" method of the ARX Network interface.\n\n";

        my @networkStats = ($networkSoapResult->result, $networkSoapResult->paramsout);

        foreach my $networkStat (@networkStats) {
            my $id = $networkStat->{'id'};

            print "----------------------------------------------\n";
            print "Network: ", $id, "\n";
            print "----------------------------------------------\n\n";

            print "id: ", $id, "\n";

            my $collisions = $networkStat->{'collisions'};
            print "collisions: ", $collisions, "\n";

            my $crc_errors = $networkStat->{'crc_errors'};
            print "crc_errors: ", $crc_errors, "\n";

            my $discarded = $networkStat->{'discarded'};
            print "discarded: ", $discarded, "\n";


            my $rx_broadcast = $networkStat->{'rx_broadcast'};
            print "rx_broadcast: ", $rx_broadcast, "\n";

            my $rx_multicast = $networkStat->{'rx_multicast'};
            print "rx_multicast: ", $rx_multicast, "\n";

            my $rx_octets = $networkStat->{'rx_octets'};
            print "rx_octets: ", $rx_octets, "\n";

            my $rx_total = $networkStat->{'rx_total'};
            print "rx_total: ", $rx_total, "\n";

            my $rx_unicast = $networkStat->{'rx_unicast'};
            print "rx_unicast: ", $rx_unicast, "\n";

            my $tx_broadcast = $networkStat->{'tx_broadcast'};
            print "tx_broadcast: ", $tx_broadcast, "\n";

            my $tx_multicast = $networkStat->{'tx_multicast'};
            print "tx_multicast: ", $tx_multicast, "\n";

            my $tx_octets = $networkStat->{'tx_octets'};
            print "tx_octets: ", $tx_octets, "\n";

            my $tx_total = $networkStat->{'tx_total'};
            print "tx_total: ", $tx_total, "\n";

            my $tx_unicast = $networkStat->{'tx_unicast'};
            print "tx_unicast: ", $tx_unicast, "\n";
            print "\n";
        }

        print "\n";
    }
}

#-------------------------------------------------------------------------------
# get_gigabit_interface_list
#-------------------------------------------------------------------------------

my @gigabitNetworkList = ();

print "Calling the \"get_gigabit_interface_list\" method of the ARX Network interface.\n\n";

# Build a security header 
$securityHeader = getSecurityHeader($user, $pass);

$networkSoapResult = $networkSoap->get_gigabit_interface_list($securityHeader);

if (defined $networkSoapResult->fault && $networkSoapResult->fault) {
    print("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n");
}
else {
    print "Printing the results of the call to the \"get_gigabit_interface_list\" method of the ARX Network interface.\n\n";

    @gigabitNetworkList = ($networkSoapResult->result, $networkSoapResult->paramsout);

    if ($#gigabitNetworkList < 0) {
        print("The list of networks returned from the call to the \"get_gigabit_interface_list\" method of the ARX Network interface was empty.\n");
    }
    else {
        print "Gigabit Network Ports:\n";

        foreach my $gigabitNetworkPort (@gigabitNetworkList) {
            my $slot = $gigabitNetworkPort->{'slot'};
            print "slot: ", $slot, "\n";

            my $port = $gigabitNetworkPort->{'port'};
            print "port: ", $port, "\n";
            print "\n";
        }

        print "\n";
    }
}

#-------------------------------------------------------------------------------
# get_gigabit_interface_configuration
#-------------------------------------------------------------------------------

print "Calling the \"get_gigabit_interface_configuration\" method of the ARX Network interface.\n\n";

if ($#gigabitNetworkList < 0) {
    print("The list of networks returned from the call to the \"get_gigabit_interface_list\" method of the ARX Network interface was empty.\n");
}
else {
    my @soapGigabitNetworkList = ConvertNetworkPortToSoapData(\@gigabitNetworkList);

    # Build a security header 
    $securityHeader = getSecurityHeader($user, $pass);

    $networkSoapResult = $networkSoap->get_gigabit_interface_configuration(SOAP::Data->name('ports')->value(@soapGigabitNetworkList), 
                                                                           $securityHeader);

    if (defined $networkSoapResult->fault && $networkSoapResult->fault) {
        confess("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n");
    }
    else {
        print "Printing the results of the call to the \"get_gigabit_interface_configuration\" method of the ARX Network interface.\n\n";

        my @gigabitInterfaceConfigs = ($networkSoapResult->result, $networkSoapResult->paramsout);

        foreach my $gigabitInterfaceConfig (@gigabitInterfaceConfigs) {
            if (exists $gigabitInterfaceConfig->{'port'}) {
                my $gigabitInterfacePort = $gigabitInterfaceConfig->{'port'};

                my $slot = $gigabitInterfacePort->{'slot'};
                my $port = $gigabitInterfacePort->{'port'};

                print "----------------------------------------------\n";
                print "Gigabit Interface: slot: ", $slot, ", port: ", $port, "\n";
                print "----------------------------------------------\n\n";

                print "port:\n";
                print " slot: ", $slot, "\n";
                print " port: ", $port, "\n";
            }

            my $description = $gigabitInterfaceConfig->{'description'};
            print "description: ", $description, "\n";

            my $flow_control_receive = $gigabitInterfaceConfig->{'flow_control_receive'};
            print "flow_control_receive: ", $flow_control_receive, "\n";

            my $flow_control_send = $gigabitInterfaceConfig->{'flow_control_send'};
            print "flow_control_send: ", $flow_control_send, "\n";

            my $redundancy_protocol = $gigabitInterfaceConfig->{'redundancy_protocol'};
            print "redundancy_protocol: ", $redundancy_protocol, "\n";

            my $speed = $gigabitInterfaceConfig->{'speed'};
            print "speed: ", $speed, "\n";

            my $enable = $gigabitInterfaceConfig->{'enable'};
            print "enable: ", $enable, "\n";
            print "\n";
        }

        print "\n";
    }
}

#-------------------------------------------------------------------------------
# get_gigabit_interface_status
#-------------------------------------------------------------------------------

print "Calling the \"get_gigabit_interface_status\" method of the ARX Network interface.\n\n";

if ($#gigabitNetworkList < 0) {
    print("The list of networks returned from the call to the \"get_gigabit_interface_list\" method of the ARX Network interface was empty.\n");
}
else {
    my @soapGigabitNetworkList = ConvertNetworkPortToSoapData(\@gigabitNetworkList);

    # Build a security header 
    $securityHeader = getSecurityHeader($user, $pass);

    $networkSoapResult = $networkSoap->get_gigabit_interface_status(SOAP::Data->name('ports')->value(@soapGigabitNetworkList), 
                                                                    $securityHeader);

    if (defined $networkSoapResult->fault && $networkSoapResult->fault) {
        confess("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n");
    }
    else {
        print "Printing the results of the call to the \"get_gigabit_interface_status\" method of the ARX Network interface.\n\n";

        my @gigabitInterfaceStatuses = ($networkSoapResult->result, $networkSoapResult->paramsout);

        foreach my $gigabitInterfaceStatus (@gigabitInterfaceStatuses) {
            if (exists $gigabitInterfaceStatus->{'port'}) {
                my $gigabitInterfacePort = $gigabitInterfaceStatus->{'port'};

                my $slot = $gigabitInterfacePort->{'slot'};
                my $port = $gigabitInterfacePort->{'port'};

                print "----------------------------------------------\n";
                print "Gigabit Interface: slot: ", $slot, ", port: ", $port, "\n";
                print "----------------------------------------------\n\n";

                print "port:\n";
                print " slot: ", $slot, "\n";
                print " port: ", $port, "\n";
            }

            my $type = $gigabitInterfaceStatus->{'type'};
            print "type: ", $type, "\n";

            my $mode = $gigabitInterfaceStatus->{'mode'};
            print "mode: ", $mode, "\n";

            my $enabled = $gigabitInterfaceStatus->{'enabled'};
            print "enabled: ", $enabled, "\n";

            my $link_status = $gigabitInterfaceStatus->{'link_status'};
            print "link_status: ", $link_status, "\n";

            my $speed = $gigabitInterfaceStatus->{'speed'};
            print "speed: ", $speed, "\n";

            my $mac = $gigabitInterfaceStatus->{'mac'};
            print "mac: ", $mac, "\n";

            my $accept_all_frame = $gigabitInterfaceStatus->{'accept_all_frame'};
            print "accept_all_frame: ", $accept_all_frame, "\n";

            my $mtu_size = $gigabitInterfaceStatus->{'mtu_size'};
            print "mtu_size: ", $mtu_size, "\n";
            print "\n";
        }

        print "\n";
    }
}

#-------------------------------------------------------------------------------
# get_ten_gigabit_interface_list
#-------------------------------------------------------------------------------

my @tenGigabitNetworkList = ();

print "Calling the \"get_ten_gigabit_interface_list\" method of the ARX Network interface.\n\n";

# Build a security header 
$securityHeader = getSecurityHeader($user, $pass);

$networkSoapResult = $networkSoap->get_ten_gigabit_interface_list($securityHeader);

if (defined $networkSoapResult->fault && $networkSoapResult->fault) {
    print("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n");
}
else {
    print "Printing the results of the call to the \"get_ten_gigabit_interface_list\" method of the ARX Network interface.\n\n";

    @tenGigabitNetworkList = ($networkSoapResult->result, $networkSoapResult->paramsout);

    if ($#tenGigabitNetworkList < 0) {
        print("The list of networks returned from the call to the \"get_ten_gigabit_interface_list\" method of the ARX Network interface was empty.\n");
    }
    else {
        print "Ten Gigabit Network Ports:\n";

        foreach my $tenGigabitNetworkPort (@tenGigabitNetworkList) {
            my $slot = $tenGigabitNetworkPort->{'slot'};
            print "slot: ", $slot, "\n";

            my $port = $tenGigabitNetworkPort->{'port'};
            print "port: ", $port, "\n";
            print "\n";
        }

        print "\n";
    }
}

#-------------------------------------------------------------------------------
# get_ten_gigabit_interface_configuration
#-------------------------------------------------------------------------------

print "Calling the \"get_ten_gigabit_interface_configuration\" method of the ARX Network interface.\n\n";

if ($#tenGigabitNetworkList < 0) {
    print("The list of networks returned from the call to the \"get_ten_gigabit_interface_list\" method of the ARX Network interface was empty.\n");
}
else {
    my @soapTenGigabitNetworkList = ConvertNetworkPortToSoapData(\@tenGigabitNetworkList);

    # Build a security header 
    $securityHeader = getSecurityHeader($user, $pass);

    $networkSoapResult = $networkSoap->get_ten_gigabit_interface_configuration(SOAP::Data->name('ports')->value(@soapTenGigabitNetworkList), 
                                                                               $securityHeader);

    if (defined $networkSoapResult->fault && $networkSoapResult->fault) {
        confess("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n");
    }
    else {
        print "Printing the results of the call to the \"get_ten_gigabit_interface_configuration\" method of the ARX Network interface.\n\n";

        my @tenGigabitInterfaceConfigs = ($networkSoapResult->result, $networkSoapResult->paramsout);

        foreach my $tenGigabitInterfaceConfig (@tenGigabitInterfaceConfigs) {
            if (exists $tenGigabitInterfaceConfig->{'port'}) {
                my $tenGigabitInterfacePort = $tenGigabitInterfaceConfig->{'port'};

                my $slot = $tenGigabitInterfacePort->{'slot'};
                my $port = $tenGigabitInterfacePort->{'port'};

                print "----------------------------------------------\n";
                print "Ten Gigabit Interface: slot: ", $slot, ", port: ", $port, "\n";
                print "----------------------------------------------\n\n";

                print "port:\n";
                print " slot: ", $slot, "\n";
                print " port: ", $port, "\n";
            }

            my $description = $tenGigabitInterfaceConfig->{'description'};
            print "description: ", $description, "\n";

            my $flow_control_receive = $tenGigabitInterfaceConfig->{'flow_control_receive'};
            print "flow_control_receive: ", $flow_control_receive, "\n";

            my $flow_control_send = $tenGigabitInterfaceConfig->{'flow_control_send'};
            print "flow_control_send: ", $flow_control_send, "\n";

            my $redundancy_protocol = $tenGigabitInterfaceConfig->{'redundancy_protocol'};
            print "redundancy_protocol: ", $redundancy_protocol, "\n";

            my $enable = $tenGigabitInterfaceConfig->{'enable'};
            print "enable: ", $enable, "\n";
            print "\n";
        }

        print "\n";
    }
}

#-------------------------------------------------------------------------------
# get_ten_gigabit_interface_status
#-------------------------------------------------------------------------------

print "Calling the \"get_ten_gigabit_interface_status\" method of the ARX Network interface.\n\n";

if ($#tenGigabitNetworkList < 0) {
    print("The list of networks returned from the call to the \"get_ten_gigabit_interface_list\" method of the ARX Network interface was empty.\n");
}
else {
    my @soapTenGigabitNetworkList = ConvertNetworkPortToSoapData(\@tenGigabitNetworkList);

    # Build a security header 
    $securityHeader = getSecurityHeader($user, $pass);

    $networkSoapResult = $networkSoap->get_ten_gigabit_interface_status(SOAP::Data->name('ports')->value(@soapTenGigabitNetworkList), 
                                                                        $securityHeader);

    if (defined $networkSoapResult->fault && $networkSoapResult->fault) {
        confess("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n");
    }
    else {
        print "Printing the results of the call to the \"get_ten_gigabit_interface_status\" method of the ARX Network interface.\n\n";

        my @tenGigabitInterfaceStatuses = ($networkSoapResult->result, $networkSoapResult->paramsout);

        foreach my $tenGigabitInterfaceStatus (@tenGigabitInterfaceStatuses) {
            if (exists $tenGigabitInterfaceStatus->{'port'}) {
                my $tenGigabitInterfacePort = $tenGigabitInterfaceStatus->{'port'};

                my $slot = $tenGigabitInterfacePort->{'slot'};
                my $port = $tenGigabitInterfacePort->{'port'};

                print "----------------------------------------------\n";
                print "Ten Gigabit Interface: slot: ", $slot, ", port: ", $port, "\n";
                print "----------------------------------------------\n\n";

                print "port:\n";
                print " slot: ", $slot, "\n";
                print " port: ", $port, "\n";
            }

            my $type = $tenGigabitInterfaceStatus->{'type'};
            print "type: ", $type, "\n";

            my $mode = $tenGigabitInterfaceStatus->{'mode'};
            print "mode: ", $mode, "\n";

            my $enabled = $tenGigabitInterfaceStatus->{'enabled'};
            print "enabled: ", $enabled, "\n";

            my $link_status = $tenGigabitInterfaceStatus->{'link_status'};
            print "link_status: ", $link_status, "\n";

            my $speed = $tenGigabitInterfaceStatus->{'speed'};
            print "speed: ", $speed, "\n";

            my $mac = $tenGigabitInterfaceStatus->{'mac'};
            print "mac: ", $mac, "\n";

            my $accept_all_frame = $tenGigabitInterfaceStatus->{'accept_all_frame'};
            print "accept_all_frame: ", $accept_all_frame, "\n";

            my $mtu_size = $tenGigabitInterfaceStatus->{'mtu_size'};
            print "mtu_size: ", $mtu_size, "\n";
            print "\n";
        }

        print "\n";
    }
}

#-------------------------------------------------------------------------------
# get_interface_spanning_tree_configuration
#-------------------------------------------------------------------------------

print "Calling the \"get_interface_spanning_tree_configuration\" method of the ARX Network interface.\n\n";

if ($#gigabitNetworkList < 0) {
    print("The list of networks returned from the call to the \"get_interface_spanning_tree_configuration\" method of the ARX Network interface was empty.\n");
}
else {
    my @soapGigabitNetworkList = ConvertNetworkPortToSoapData(\@gigabitNetworkList);

    # Build a security header 
    $securityHeader = getSecurityHeader($user, $pass);

    $networkSoapResult = $networkSoap->get_interface_spanning_tree_configuration(SOAP::Data->name('ports')->value(@soapGigabitNetworkList), 
                                                                                 $securityHeader);

    if (defined $networkSoapResult->fault && $networkSoapResult->fault) {
        confess("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n");
    }
    else {
        print "Printing the results of the call to the \"get_interface_spanning_tree_configuration\" method of the ARX Network interface.\n\n";

        my @networkIfSpanningTreeConfigs = ($networkSoapResult->result, $networkSoapResult->paramsout);

        foreach my $networkIfSpanningTreeConfig (@networkIfSpanningTreeConfigs) {
            if (exists $networkIfSpanningTreeConfig->{'port'}) {
                my $networkIfSpanningTreePort = $networkIfSpanningTreeConfig->{'port'};

                my $slot = $networkIfSpanningTreePort->{'slot'};
                my $port = $networkIfSpanningTreePort->{'port'};

                print "----------------------------------------------\n";
                print "Gigabit Interface: slot: ", $slot, ", port: ", $port, "\n";
                print "----------------------------------------------\n\n";

                print "port:\n";
                print " slot: ", $slot, "\n";
                print " port: ", $port, "\n";
            }

            my $spanning_tree_cost = $networkIfSpanningTreeConfig->{'spanning_tree_cost'};
            print "spanning_tree_cost: ", $spanning_tree_cost, "\n";

            my $spanning_tree_priority = $networkIfSpanningTreeConfig->{'spanning_tree_priority'};
            print "spanning_tree_priority: ", $spanning_tree_priority, "\n";

            my $spanning_tree_edgeport = $networkIfSpanningTreeConfig->{'spanning_tree_edgeport'};
            print "spanning_tree_edgeport: ", $spanning_tree_edgeport, "\n";

            my $spanning_tree_force_migration = $networkIfSpanningTreeConfig->{'spanning_tree_force_migration'};
            print "spanning_tree_force_migration: ", $spanning_tree_force_migration, "\n";

            my $spanning_tree_enable = $networkIfSpanningTreeConfig->{'spanning_tree_enable'};
            print "spanning_tree_enable: ", $spanning_tree_enable, "\n";
            print "\n";
        }

        print "\n";
    }
}

#-------------------------------------------------------------------------------
# get_interface_spanning_tree_configuration
#-------------------------------------------------------------------------------

print "Calling the \"get_interface_spanning_tree_configuration\" method of the ARX Network interface.\n\n";

if ($#tenGigabitNetworkList < 0) {
    print("The list of networks returned from the call to the \"get_interface_spanning_tree_configuration\" method of the ARX Network interface was empty.\n");
}
else {
    my @soapTenGigabitNetworkList = ConvertNetworkPortToSoapData(\@tenGigabitNetworkList);

    # Build a security header 
    $securityHeader = getSecurityHeader($user, $pass);

    $networkSoapResult = $networkSoap->get_interface_spanning_tree_configuration(SOAP::Data->name('ports')->value(@soapTenGigabitNetworkList), 
                                                                                 $securityHeader);

    if (defined $networkSoapResult->fault && $networkSoapResult->fault) {
        confess("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n");
    }
    else {
        print "Printing the results of the call to the \"get_interface_spanning_tree_configuration\" method of the ARX Network interface.\n\n";

        my @networkIfSpanningTreeConfigs = ($networkSoapResult->result, $networkSoapResult->paramsout);

        foreach my $networkIfSpanningTreeConfig (@networkIfSpanningTreeConfigs) {
            if (exists $networkIfSpanningTreeConfig->{'port'}) {
                my $networkIfSpanningTreePort = $networkIfSpanningTreeConfig->{'port'};

                my $slot = $networkIfSpanningTreePort->{'slot'};
                my $port = $networkIfSpanningTreePort->{'port'};

                print "----------------------------------------------\n";
                print "Ten Gigabit Interface: slot: ", $slot, ", port: ", $port, "\n";
                print "----------------------------------------------\n\n";

                print "port:\n";
                print " slot: ", $slot, "\n";
                print " port: ", $port, "\n";
            }

            my $spanning_tree_cost = $networkIfSpanningTreeConfig->{'spanning_tree_cost'};
            print "spanning_tree_cost: ", $spanning_tree_cost, "\n";

            my $spanning_tree_priority = $networkIfSpanningTreeConfig->{'spanning_tree_priority'};
            print "spanning_tree_priority: ", $spanning_tree_priority, "\n";

            my $spanning_tree_edgeport = $networkIfSpanningTreeConfig->{'spanning_tree_edgeport'};
            print "spanning_tree_edgeport: ", $spanning_tree_edgeport, "\n";

            my $spanning_tree_force_migration = $networkIfSpanningTreeConfig->{'spanning_tree_force_migration'};
            print "spanning_tree_force_migration: ", $spanning_tree_force_migration, "\n";

            my $spanning_tree_enable = $networkIfSpanningTreeConfig->{'spanning_tree_enable'};
            print "spanning_tree_enable: ", $spanning_tree_enable, "\n";
            print "\n";
        }

        print "\n";
    }
}

#-------------------------------------------------------------------------------
# get_mgmt_interface_configuration
#-------------------------------------------------------------------------------

print "Calling the \"get_mgmt_interface_configuration\" method of the ARX Network interface.\n\n";

# Build a security header 
$securityHeader = getSecurityHeader($user, $pass);

$networkSoapResult = $networkSoap->get_mgmt_interface_configuration($securityHeader);

if (defined $networkSoapResult->fault && $networkSoapResult->fault) {
    print("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n");
}
else {
    print "Printing the results of the call to the \"get_mgmt_interface_configuration\" method of the ARX Network interface.\n\n";

    my $mgmtIfConfig = $networkSoapResult->result;

    if (exists $mgmtIfConfig->{'port'}) {
        my $mgmtIfPort = $mgmtIfConfig->{'port'};

        my $slot = $mgmtIfPort->{'slot'};
        my $port = $mgmtIfPort->{'port'};

        print "----------------------------------------------\n";
        print "Management Interface: slot: ", $slot, ", port: ", $port, "\n";
        print "----------------------------------------------\n\n";

        print "port:\n";
        print " slot: ", $slot, "\n";
        print " port: ", $port, "\n";
    }

    my $description = $mgmtIfConfig->{'description'};
    print "description: ", $description, "\n";

    my $ip_address = $mgmtIfConfig->{'ip_address'};
    print "ip_address: ", $ip_address, "\n";

    my $ip_mask = $mgmtIfConfig->{'ip_mask'};
    print "ip_mask: ", $ip_mask, "\n";

    my $speed = $mgmtIfConfig->{'speed'};
    print "speed: ", $speed, "\n";

    my $enable = $mgmtIfConfig->{'enable'};
    print "enable: ", $enable, "\n";
    print "\n";
}

#-------------------------------------------------------------------------------
# get_mgmt_interface_status
#-------------------------------------------------------------------------------

print "Calling the \"get_mgmt_interface_status\" method of the ARX Network interface.\n\n";

# Build a security header 
$securityHeader = getSecurityHeader($user, $pass);

$networkSoapResult = $networkSoap->get_mgmt_interface_status($securityHeader);

if (defined $networkSoapResult->fault && $networkSoapResult->fault) {
    print("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n");
}
else {
    print "Printing the results of the call to the \"get_mgmt_interface_status\" method of the ARX Network interface.\n\n";

    my $mgmtIfStatus = $networkSoapResult->result;

    if (exists $mgmtIfStatus->{'port'}) {
        my $mgmtIfPort = $mgmtIfStatus->{'port'};

        my $slot = $mgmtIfPort->{'slot'};
        my $port = $mgmtIfPort->{'port'};

        print "----------------------------------------------\n";
        print "Management Interface: slot: ", $slot, ", port: ", $port, "\n";
        print "----------------------------------------------\n\n";

        print "port:\n";
        print " slot: ", $slot, "\n";
        print " port: ", $port, "\n";
    }

    my $type = $mgmtIfStatus->{'type'};
    print "type: ", $type, "\n";

    my $mode = $mgmtIfStatus->{'mode'};
    print "mode: ", $mode, "\n";

    my $enabled = $mgmtIfStatus->{'enabled'};
    print "enabled: ", $enabled, "\n";

    my $link_status = $mgmtIfStatus->{'link_status'};
    print "link_status: ", $link_status, "\n";

    my $speed = $mgmtIfStatus->{'speed'};
    print "speed: ", $speed, "\n";

    my $mac = $mgmtIfStatus->{'mac'};
    print "mac: ", $mac, "\n";

    my $accept_all_frame = $mgmtIfStatus->{'accept_all_frame'};
    print "accept_all_frame: ", $accept_all_frame, "\n";

    my $mtu_size = $mgmtIfStatus->{'mtu_size'};
    print "mtu_size: ", $mtu_size, "\n";
    print "\n";
}

#-------------------------------------------------------------------------------
# get_vlan_interface_list
#-------------------------------------------------------------------------------

my @vlanList = ();

print "Calling the \"get_vlan_interface_list\" method of the ARX Network interface.\n\n";

# Build a security header 
$securityHeader = getSecurityHeader($user, $pass);

$networkSoapResult = $networkSoap->get_vlan_interface_list($securityHeader);

if (defined $networkSoapResult->fault && $networkSoapResult->fault) {
    print("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n");
}
else {
    print "Printing the results of the call to the \"get_vlan_interface_list\" method of the ARX Network interface.\n\n";

    @vlanList = ($networkSoapResult->result, $networkSoapResult->paramsout);

    if ($#vlanList < 0) {
        print("The list of VLAN interfaces returned from the call to the \"get_vlan_interface_list\" method of the ARX Network interface was empty.\n");
    }
    else {
        print "VLAN Interfaces:\n";

        foreach my $vlan (@vlanList) {
            print "$vlan\n";
        }

        print "\n";
    }
}

#-------------------------------------------------------------------------------
# get_vlan_interface_configuration
#-------------------------------------------------------------------------------

print "Calling the \"get_vlan_interface_configuration\" method of the ARX Network interface.\n\n";

if ($#vlanList < 0) {
    print("The list of VLAN interfaces returned from the call to the \"get_vlan_interface_list\" method of the ARX Network interface was empty.\n");
}
else {
    # Build a security header 
    $securityHeader = getSecurityHeader($user, $pass);

    $networkSoapResult = $networkSoap->get_vlan_interface_configuration(SOAP::Data->name('ids')->value(@vlanList), 
                                                                        $securityHeader);

    if (defined $networkSoapResult->fault && $networkSoapResult->fault) {
        confess("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n");
    }
    else {
        print "Printing the results of the call to the \"get_vlan_interface_configuration\" method of the ARX Network interface.\n\n";

        my @vlanConfigs = ($networkSoapResult->result, $networkSoapResult->paramsout);

        foreach my $vlanConfig (@vlanConfigs) {
            my $id = $vlanConfig->{'id'};

            print "----------------------------------------------\n";
            print "VLAN Interface: ", $id, "\n";
            print "----------------------------------------------\n\n";

            print "id: ", $id, "\n";

            my $description = $vlanConfig->{'description'};
            print "description: ", $description, "\n";

            my $ip_address = $vlanConfig->{'ip_address'};
            print "ip_address: ", $ip_address, "\n";

            my $ip_mask = $vlanConfig->{'ip_mask'};
            print "ip_mask: ", $ip_mask, "\n";

            my $redundancy = $vlanConfig->{'redundancy'};
            print "redundancy: ", $redundancy, "\n";

            my $enable = $vlanConfig->{'enable'};
            print "enable: ", $enable, "\n";
            print "\n";
        }

        print "\n";
    }
}

#-------------------------------------------------------------------------------
# get_ip_proxy_list
#-------------------------------------------------------------------------------

my @ipProxyList = ();

print "Calling the \"get_ip_proxy_list\" method of the ARX Network interface.\n\n";

# Build a security header 
$securityHeader = getSecurityHeader($user, $pass);

$networkSoapResult = $networkSoap->get_ip_proxy_list($securityHeader);

if (defined $networkSoapResult->fault && $networkSoapResult->fault) {
    print("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n");
}
else {
    print "Printing the results of the call to the \"get_ip_proxy_list\" method of the ARX Network interface.\n\n";

    @ipProxyList = ($networkSoapResult->result, $networkSoapResult->paramsout);

    if ($#ipProxyList < 0) {
        print("The list of IP Proxies returned from the call to the \"get_ip_proxy_list\" method of the ARX Network interface was empty.\n");
    }
    else {
        print "IP Proxies:\n";

        foreach my $ipProxy (@ipProxyList) {
            print "$ipProxy\n";
        }

        print "\n";
    }
}

#-------------------------------------------------------------------------------
# get_ip_proxy_configuration
#-------------------------------------------------------------------------------

print "Calling the \"get_ip_proxy_configuration\" method of the ARX Network interface.\n\n";

if ($#ipProxyList < 0) {
    print("The list of IP Proxies returned from the call to the \"get_ip_proxy_list\" method of the ARX Network interface was empty.\n");
}
else {
    # Build a security header 
    $securityHeader = getSecurityHeader($user, $pass);

    $networkSoapResult = $networkSoap->get_ip_proxy_configuration(SOAP::Data->name('ip_address')->value(@ipProxyList), 
                                                                  $securityHeader);

    if (defined $networkSoapResult->fault && $networkSoapResult->fault) {
        confess("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n");
    }
    else {
        print "Printing the results of the call to the \"get_ip_proxy_configuration\" method of the ARX Network interface.\n\n";

        my @ipProxyConfigs = ($networkSoapResult->result, $networkSoapResult->paramsout);

        foreach my $ipProxyConfig (@ipProxyConfigs) {
            my $proxy_address = $ipProxyConfig->{'proxy_address'};

            print "----------------------------------------------\n";
            print "IP Proxy Address: ", $proxy_address, "\n";
            print "----------------------------------------------\n\n";

            print "proxy_address: ", $proxy_address, "\n";

            my $mask = $ipProxyConfig->{'mask'};
            print "mask: ", $mask, "\n";

            my $mac = $ipProxyConfig->{'mac'};
            print "mac: ", $mac, "\n";

            if (exists $ipProxyConfig->{'processor'}) {
                my $ipProxyProc = $ipProxyConfig->{'processor'};
                print "processor:\n";

                my $slot = $ipProxyProc->{'slot'};
                print " slot: ", $slot, "\n";

                my $processor = $ipProxyProc->{'processor'};
                print " processor: ", $processor, "\n";
                print "\n";
            }

            my $vlan = $ipProxyConfig->{'vlan'};
            print "vlan: ", $vlan, "\n";
            print "\n";
        }

        print "\n";
    }
}

#-------------------------------------------------------------------------------
# get_ip_proxy_status
#-------------------------------------------------------------------------------

print "Calling the \"get_ip_proxy_status\" method of the ARX Network interface.\n\n";

if ($#ipProxyList < 0) {
    print("The list of IP Proxies returned from the call to the \"get_ip_proxy_list\" method of the ARX Network interface was empty.\n");
}
else {
    # Build a security header 
    $securityHeader = getSecurityHeader($user, $pass);

    $networkSoapResult = $networkSoap->get_ip_proxy_status(SOAP::Data->name('ip_address')->value(@ipProxyList), 
                                                           $securityHeader);

    if (defined $networkSoapResult->fault && $networkSoapResult->fault) {
        confess("SOAP request failed:\n" . objdump($networkSoapResult->fault) . "\n");
    }
    else {
        print "Printing the results of the call to the \"get_ip_proxy_status\" method of the ARX Network interface.\n\n";

        my @ipProxyStatuses = ($networkSoapResult->result, $networkSoapResult->paramsout);

        foreach my $ipProxyStatus (@ipProxyStatuses) {
            my $proxy_address = $ipProxyStatus->{'proxy_address'};
            print "proxy_address: ", $proxy_address, "\n";

            my $mac = $ipProxyStatus->{'mac'};
            print "mac: ", $mac, "\n";

            my $owner = $ipProxyStatus->{'owner'};
            print "owner: ", $owner, "\n";

            my $in_use_by = $ipProxyStatus->{'in_use_by'};
            print "in_use_by: ", $in_use_by, "\n";
            print "\n";
        }

        print "\n";
    }
}


#-------------------------------------------------------------------------------
# End of main program logic
#-------------------------------------------------------------------------------


#-------------------------------------------------------------------------------
# sub usage
#-------------------------------------------------------------------------------
sub usage
{
    print "\nUsage: ARXNetworkExample.pl --url  --user  --pass \n";
    print "\n";
    print "Argument  Description\n";
    print "--------  -----------\n";
    print "--url     The base URL of the web service on the ARX. Both http and https\n";
    print "          are supported. The format is:\n";
    print "\n";
    print "          http(s)://:\n";
    print "\n";
    print "          : DNS resolvable hostname or IP address\n";
    print "          :     83 for http or 843 for https\n";
    print "\n";
    print "--user    The username for authentication.\n";
    print "--pass    The password for authentication.\n";
    print "\n";
}

#-------------------------------------------------------------------------------
# sub getSecurityHeader(user, pass)
#
# This subroutine builds a security header that will be used for
# authentication.  This type of security header is required for all calls to
# iControl::ARX interfaces, so it makes sense to have this subroutine stored in
# a library for common access.
#-------------------------------------------------------------------------------
sub getSecurityHeader
{
    my $user = shift;
    my $pass = shift;
    my $now = time();
    my $then = time() + 60;
    my $created = strftime("%Y-%m-%dT%H:%M:%S", gmtime($now)) . 'Z';
    my $expires = strftime("%Y-%m-%dT%H:%M:%S", gmtime($then)) . 'Z';

    my $secExt = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
    my $secUtil = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
    my $securityHeader = SOAP::Header->name("wsse:Security")->attr(
            {
                'xmlns:wsse'=> $secExt,
                'xmlns:wsu'=> $secUtil
            }
    );
    my $timestamp = SOAP::Data->name("wsu:Timestamp" =>
                            \SOAP::Data->value(
                                SOAP::Data->name('wsu:Created')->value($created)
                                                               ->type(''),
                                SOAP::Data->name('wsu:Expires')->value($expires)
                                                               ->type('')));
    my $usernameTokenType = 
        "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText";
    my $usernameToken = SOAP::Data->name("wsse:UsernameToken" =>
                            \SOAP::Data->value(
                                SOAP::Data->name('wsse:Username')->value($user)
                                                                 ->type(''),
                                SOAP::Data->name('wsse:Password')->value($pass)
                                                                 ->type('')
                                                                 ->attr({'Type'=>$usernameTokenType})));

    $securityHeader->value(\SOAP::Data->value($timestamp, $usernameToken));

    return $securityHeader;
}

sub objdump
{
    my ($obj, $indent) = @_;
    my $content = '';

    if (!defined $obj) {
        return $content;
    }

    if (!defined $indent) {
        $indent = '    ';
    }

    my $type = ref $obj;

    if (!defined $type || $type eq '' || $type eq 'SCALAR') {
        $content = $content . $indent . $obj . "\n";
    }
    elsif ($type eq 'ARRAY') {
        foreach my $node (@$obj) {
            $content = $content . objdump($node, $indent);
        }
    }
    else {
        my $key;
        my $value;

        while (($key, $value) = each %$obj) {
            my $type2 = ref $value;
            if (!defined $type2 || $type2 eq '' || $type2 eq 'SCALAR') {
                $content = $content . $indent . "\'$key\' => $value;\n";
            }
            else {
                $content = $content . $indent . "\'$key\' => {\n";
                $content = $content . objdump($value, $indent.'    ');
                $content = $content . $indent . "}\n";
            }
        }
    }

    return $content;
}

sub ConvertNetworkPortToSoapData
{
    my ($portListRef) = @_;
    my @dataArray;
    
    foreach my $port (@$portListRef) {
        my $sport = SOAP::Data->name("ports")->value(\SOAP::Data->value(
                                                    SOAP::Data->name("slot")->value($port->{'slot'}),
                                                    SOAP::Data->name("port")->value($port->{'port'})));
         push(@dataArray, $sport);
    }
    
    return @dataArray;
}
Updated Jun 06, 2023
Version 3.0

Was this article helpful?

No CommentsBe the first to comment