Using A Perl Script To Access The Nsm Api - Juniper NETWORK AND SECURITY MANAGER 2010.4 - API GUIDE REV 1 Manual

Api guide
Table of Contents

Advertisement

Using a Perl Script to Access the NSM API

Copyright © 2010, Juniper Networks, Inc.
This example shows how to log into the server and retrieve system information for the
server.
#!/usr/bin/perl -w
use SOAP::Lite +trace => 'all';
#use SOAP::Lite;
delete $ENV{'https_proxy'};
use constant NS_XSD=> 'http://www.w3.org/1999/XMLSchema'; #XSD 1999 schema
use constant NS_XSI=> 'http://www.w3.org/1999/XMLSchema-instance'; #XSI 1999
schema
our @NSM_SERVERS = qw(
10.157.39.201:8443
8443
);
our $LOGIN_TOKEN;
sub soap_call($$$) {
my $service = shift;
my $method = shift;
my $input = shift;
my $nbi_method = "https://";
my $nbi_uri = "/axis2/services";
my $jp_url = "http://juniper.net/webproxy";
if ( !defined $main::ACTIVE_SERVER ) {
if ( scalar @main::NSM_SERVERS == 0 ) {
print ("Couldn't connect to any NSM Servers", "\n");
exit 1;
} else {
$main::ACTIVE_SERVER = shift @main::NSM_SERVERS;
}
}
my $nsm_url = qq|${nbi_method}${main::ACTIVE_SERVER}${nbi_uri}|;
my $soap_service = SOAP::Lite
-> proxy ("$nsm_url/$service")
-> uri
( "$jp_url/" . lc($service) )
-> on_fault (
sub {
if ( $_[0]->transport->status =~ /^503/ ) {
}
}
) ;
my $soap_method = SOAP::Data->name($method)->attr( {'xmlns' => "$jp_url/" .
lc($service),'xmlns:xsd'=>NS_XSD, 'xmlns:xsi'=>NS_XSI} );
# Execute and grab response
my $response;
Chapter 6: Installing the Perl Client Environment
undef $main::ACTIVE_SERVER;
soap_call($service,$method,$input);
77

Advertisement

Table of Contents
loading

This manual is also suitable for:

Network and security manager 2010.4

Table of Contents