Getting Started With Perl

jzhen
  • jzhen's picture
Getting Started With Perl

The LogLogic Web Services Development Kit for Perl (aka "Perl DevKit") can be downloaded from the Google Code Project Hosting website.

Required Software

The following software is required to use the Perl DevKit:

  • Perl 5.0 (or later)
  • SOAP::Lite for Perl and dependent modules. SOAP::Lite is a collection of Perl modules which provide a lightweight implementation of the Simple Object Access Protocol (SOAP). The LogLogic Perl Client Samples use SOAP::Lite for connectivity to the LogLogic appliance.

Note: SOAP::Lite depends on other Perl modules distributed independently from Perl. See the SOAP::Lite README for prerequisite modules.

Perl Client Samples Overview

The Perl DevKit provides a number of Sample client programs to demonstrate typical appliance integration capabilities. The Perl samples can be found in the DevKit under /devkit/perl/.

Admin Services Perl Samples

The Admin Services Perl Samples are located in /devkit/perl/admin/:

Alert Rules Management

  • alertmgmt/createAlert.pl
  • alertmgmt/getAlert.pl
  • alertmgmt/getAlertList.pl

Device Management

  • devicemgmt/createDevice.pl
  • devicemgmt/getDevice.pl
  • devicemgmt/getDeviceList.pl

Message Routing

  • msgrouting/createMsgRouting.pl
  • msgrouting/getMsgRouting.pl
  • msgrouting/getMsgRoutingList.pl

Search Filter Management

  • searchfilters/createSearchFilter.pl
  • searchfilters/getSearchFilter.pl
  • searchfilters/getSearchFilterList.pl

User Account Management

  • usermgmt/createUser.pl
  • usermgmt/getUser.pl
  • usermgmt/getUserList.pl
  • usermgmt/updateUser.pl

Report and Search Services Perl Samples

The Report and Search Services Perl Samples are located in /devkit/perl/reporting/:

  • R1_RunAnyReportLastHour.pl
  • R2_RunSimpleReport.pl
  • R3_RunSimpleReportWithFilters.pl
  • R4_ListReports.pl
  • R5_RunCustomReport.pl
  • R6_RunCustomReportSpecificTime.pl
  • R7_RunSearchReport.pl
  • reportutil.pm

Note: reportutil.pm contains a number of subroutines used by the Report and Search samples which may be useful in developing your own Perl clients.

Running Perl Samples

Grant Web Services Access

All LogLogic Web Service APIs require authentication with the appliance using a valid User Account on the appliance. To enable a User Account to connect using Web Services, you must set Web Services the user on the LogLogic appliance.

  1. Log on to the LogLogic appliance with administrator privileges.
  2. In the navigation menu, click Administration > Manage Users.
  3. Click the "admin" user to view/edit details.
  4. Select the "Allow this user account to connect to the Appliance via Web Services" checkbox to grant Web Service access for the "admin" user.
  5. Click the Update button to save the changes

Enable Web Services Access Screenshot

Running the Samples

For a description and command parameters for each Perl-based sample, see the contents of the corresponding script.

Developing Client Applications

For more information on developing LogLogic Web Service client applications using Perl, including specific API operations and parameters, see the LogLogic Web Services Implementation Guide.

0
Your rating: None



lluser

I got the following error testing out the CreateMsgRouting.pl. What does the 15001 error mean?

"Connecting to ... http://x.x.x.x/logapp20/services/AuthenticationService...Connected.
Connecting to ... http://x.x.x.x/logapp20/services/MsgRoutingService...Connected.

=== create search filter, Received 0 records, statusCode is 5000, and statusMessage is ERROR: Failed to update message routing - Sample_MsgRouting - Server error encountered. Code - 15001==="



jzhen
  • jzhen's picture

lluser, can you paste in the code you are using? Wrap it in <code> </code>block would be great.

thx



lluser

jzhen, I tested the code sample - CreateMessageRouting.pl from the devkit above using the parameters below. No code modifications were been done except for the parameters passed to the script. Thanks.

PARAMETERS used:
x.x.x.x user passwd "MsgRouting" "All General Syslog" "x.x.x.x" "514" "UDP Syslog" yes "All" "syslog" "None" no no no true

#!perl
#
# Copyright (c) 2007 LogLogic, Inc. San Jose, CA, USA. All rights reserved.
#
# Example Usage:
#  perl createMsgRouting.pl 10.1.1.220 admin admin123 "MsgRouting Demo" "All Cisco Pix" "10.1.1.230" "344" "UDP Syslog" yes "Emergency/Notice" "Clock/Printer/Auth" "None" no no yes true
#

use strict;
use Data::Dumper; $Data::Dumper::Terse = 1; $Data::Dumper::Indent = 1;

select(STDOUT); $| = 1;  # make unbuffered

@ARGV or die "Usage: $0 appliance-ip-address loginName loginPassword debug\n";
my($ip,
    $loginName,
    $loginPassword,
    $routingName ,
    $sourceDevice,
    $destinationIp,
    $destinationPort,
    $routingProtocol,
    $enabled,
    $severity,
    $facility,
    $searchFilterName,
    $compressionEnabled,
    $encryptionEnabled,
    $authenticationEnabled,
    $debug)
  =
  (shift, shift, shift, shift, shift, shift,
    shift, shift, shift, shift, shift, shift, shift, shift, shift);

if ($debug) {
    eval "use SOAP::Lite +trace => 'debug';";
} else {
    eval "use SOAP::Lite;";
}

my $hosturl = "http://" . $ip . "/logapp20/services";
my $hostUserURL = $hosturl . "/MsgRoutingService";
my $hostAuthURL = $hosturl   . "/AuthenticationService";

printf('Connecting to ... ' . $hostAuthURL . '...');
my $soapAuth = SOAP::Lite->proxy($hostAuthURL)->on_fault(sub{});
printf('Connected.' . "\n");

my $authResult = $soapAuth->getAuthenticationToken($loginName, $loginPassword);

my $authToken = $authResult->valueof('//token');

printf('Connecting to ... ' . $hostUserURL . '...');
my $soap = SOAP::Lite->proxy($hostUserURL)->on_fault(sub{});
printf('Connected.' . "\n");

my $res = $soap->createMsgRouting(SOAP::Data->name('authToken' => $authToken)  ->type('xsd:string') ,
                           SOAP::Data->name('routingName' => $routingName)  ->type('xsd:string') ,
                           SOAP::Data->name('sourceDevice' => $sourceDevice)  ->type('xsd:string') ,
                           SOAP::Data->name('destinationIp' => $destinationIp)  ->type('xsd:string') ,
                           SOAP::Data->name('destinationPort'           => $destinationPort)  ->type('xsd:string') ,
                           SOAP::Data->name('routingProtocol'           => $routingProtocol)  ->type('xsd:string') ,
                           SOAP::Data->name('enabled' => $enabled)  ->type('xsd:string') ,
                           SOAP::Data->name('severity'                  => $severity)  ->type('xsd:string') ,
                           SOAP::Data->name('facility'                  => $facility)           ->type('xsd:string') ,
                           SOAP::Data->name('searchFilterName' => $searchFilterName)  ->type('xsd:string') ,
                           SOAP::Data->name('compressionEnabled'        => $compressionEnabled)  ->type('xsd:string') ,
                           SOAP::Data->name('encryptionEnabled'        => $encryptionEnabled)  ->type('xsd:string') ,
                           SOAP::Data->name('authenticationEnabled' => $authenticationEnabled) ->type('xsd:string') );

if ($@) {
    print("--- SYNTAX ERROR ---\n" . $@ . "\n");
}

if (defined($res) && $res->fault) {
    print("--- SOAP FAULT ---\n" . $res->faultcode . "\n" . $res->faultstring . "\n");
}

if ( !$soap->transport->is_success ) {
    print("--- TRANSPORT ERROR ---\n" . $soap->transport->status . "\n");
}

if ( $@ ) { exit; }

#printf ("The result from getting user list ".Dumper($res->paramsall)." \n");

my $statusCode  = $res->valueof('//statusCode');
my $statusMessage   = $res->valueof('//statusMessage');
my $recordCount = $res->valueof('//resultCount');
if ( ! $recordCount) {
    $recordCount = 0;
}

print("\n=== create search filter, Received " . $recordCount . " records, statusCode is $statusCode, and statusMessage is $statusMessage===\n");
   
   print "-----------------------------\n";
  
    for (my $i = 1; $i < $recordCount+1; $i++) {
        print "Search Filter $i << ";
print '[ ' . $res->valueof('//resultSet/['.$i.']/routingName') . ' ]';
print '[ ' . $res->valueof('//resultSet/['.$i.']/sourceDevice') . ' ]';
print '[ ' . $res->valueof('//resultSet/['.$i.']/desctinationIP') . ' ]';
print '[ ' . $res->valueof('//resultSet/['.$i.']/destinationPort') . ' ]';
print '[ ' . $res->valueof('//resultSet/['.$i.']/routingProtocol') . ' ]';
print '[ ' . $res->valueof('//resultSet/['.$i.']/severity') . ' ]';
print '[ ' . $res->valueof('//resultSet/['.$i.']/facility') . ' ]';
        print " >>\n";
    }