cancel
Showing results for 
Search instead for 
Did you mean: 
Login & Join the DevCentral Connects Group to watch the Recorded LiveStream (May 12) on Basic iControl Security - show notes included.

Problem this snippet solves:

This is a debugging application to help test an endpoint that implements the Management::EventNotification interface.

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-2005 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.
#----------------------------------------------------------------------------

#use SOAP::Lite + trace => qw(method debug);
use SOAP::Lite;
use Time::gmtime;
use MIME::Base64;

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

#----------------------------------------------------------------------------
# Validate Arguments
#----------------------------------------------------------------------------
my $sUrl = $ARGV[0];
my $sUID = $ARGV[1];
my $sPWD = $ARGV[2];

my $sProtocol = "https";

# Script specific variables

if ( ($sUrl eq "") or ($sUID eq "") or ($sPWD eq "") )
{
die ("Usage: EventNotification.pl url uid pwd\n");
}

#----------------------------------------------------------------------------
# Transport Information
#----------------------------------------------------------------------------
sub SOAP::Transport::HTTP::Client::get_basic_credentials-->
{
return "$sUID" => "$sPWD";
}


$EventNotification = SOAP::Lite
-> uri('urn
-> proxy("$sUrl");
eval { $EventNotification->transport->http_request->header
(
'Authorization' => 
'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')-->
); };

&sendNotification($sArg1);


#----------------------------------------------------------------------------
# checkResponse
#----------------------------------------------------------------------------
sub checkResponse()
{
my ($soapResponse) = (@_);
if ( $soapResponse->fault )
{
print $soapResponse->faultcode, " ", $soapResponse->faultstring, "\n";
exit();
}
}

#----------------------------------------------------------------------------
# sendNotification
#----------------------------------------------------------------------------
sub sendNotification()
{
$event_source =
{
system_id => "AAAABBBB-CCCC-DDDD-EEEE-FFFFGGGGHHHH",
url => "http://bogus_url_from_event_notification_test"
};

$subscription_id = "ZZZZYYYY-XXXX-WWWW-VVVV-UUUUTTTTSSSS",

$event_data_item_1 =
{
event_data_name => "test_string_data_item",
event_data_type => "DATATYPE_STRING",
event_data_value => "test_string_data_value"
};
$event_data_item_2 =
{
event_data_name => "test_IP_Address_data_item",
event_data_type => "DATATYPE_IP_ADDRESS",
event_data_value => "123.456.789.000"
};
$event_data_item_3 =
{
event_data_name => "test_long_data_item",
event_data_type => "DATATYPE_LONG",
event_data_value => "1234567890"
};

@event_data_item_list =
(
$event_data_item_1,
$event_data_item_2,
$event_data_item_3
);

$event_data_1 =
{
username => "joe",
sequence_number => 1,
event_type => "EVENTTYPE_TEST",
object_type => "OBJECTTYPE_UNKNOWN",
event_data_item_list => [@event_data_item_list]
};

@event_data_list =
(
$event_data_1
);
  
$time_stamp =
{
year => 1900+gmtime->year(),
month => gmtime->mon(),
day => gmtime->mday(),
hour => gmtime->hour(),
minute => gmtime->min(),
second => gmtime->sec()
};

print "Testing sUrl for compliance...\n";

$soapResponse = $EventNotification->events_occurred
(
SOAP::Data->name(event_source => $event_source),
SOAP::Data->name(subscription_id => $subscription_id),
SOAP::Data->name(event_data_list => [@event_data_list]),
SOAP::Data->name(time_stamp => $time_stamp)
);

#  &checkForError($EventNotification);
&checkResponse($soapResponse);

print "SUCCESS The endpoint is compliant with the EventNotification interface.\n";

}

sub checkForError()
{
my ($interface) = (@_);

$proxy = $interface->transport->{"_proxy"};
$is_success = $proxy->{"_is_success"};
$status = $proxy->{"_status"};
if (! $is_success )
{
print "Connection Error ($status)\n";
exit();
}
}
Version history
Last update:
‎07-Mar-2015 15:27
Updated by:
Contributors