DX NetOps

 View Only
  • 1.  CA Spectrum Web Service via Perl

    Posted Nov 10, 2016 12:13 AM

    Dear Team,

     

    Can anyone please guide me on how to update alarm field in CA Spectrum via web service call in perl?

    i tried giving curl command in Perl code but its just running find with no error but i dont see any update in the alarm field

     

    Regards

    Ajit C



  • 2.  Re: CA Spectrum Web Service via Perl

    Posted Nov 11, 2016 04:06 PM

    It would be much easier to help if we had an example of what you are doing.  We have some people that are using curl, but mainly for performing gets, not posts or puts.  I tend to use the perl http libraries because they provide more flexibility in how to format the information going over.   (Actually, most of my work now is in Ruby.)

     

    Here is a little routine that I have used in multiple perl scripts.

     

     

    #
    #--------------------------------------------------------------------------------------------------------------------
    # WSsubmitRequest
    #
    # This routine calls the Spectrum web service to perform some type of work as specified by the parameters
    #
    # input parameters
    # username - the username to use for authentication
    # password - the password to use for authentication
    # message - the message to pass via http
    # URL - the URL to use for talking to the web server
    # wsType - the type of http message to formulate (POST, GET, PUT)
    # dbg - debug flag
    #
    # other variables
    # userAgent - pointer to the HTTP request submission
    # req - hash of information to pass to HTTP as the request
    # results - results from submitting the request
    #
    # output parameters
    # returns the results from the WebService request
    #
    # calls:
    # Perl HTTP module
    #--------------------------------------------------------------------------------------------------------------------
    sub wsSubmitRequest{
    my $username = shift;
    my $password = shift;
    my $message = shift;
    my $URL = shift;
    my $wsType = shift;
    my $dbg = shift;
    #
    my $userAgent = '';
    my $req = '';
    my $result = '';
    #
    if($dbg > 0){print DEBUG "submitRequest:sending to:$URL, Message=$message\n";}
    $userAgent = LWP::UserAgent->new;
    #
    $req = HTTP::Request->new($wsType => $URL);
    $req->content_type('application/xml');
    $req->content($message);
    $req->authorization_basic($username, $password);
    #
    $result = $userAgent->request($req)->as_string();

    # $result = wsBuildResult($result, $username, $password, $dbg);
    if($dbg > 0){print DEBUG "submitRequest:Response=$result\n";}
    return($result);
    }

     

     

    I used this in a routine to update IPs by setting the variables:

    my $wsSvcUpdate          = 'spectrum/restful/model';

    my $IPAttr      = "0x12d7f";

    my $wsMessage = "";
    my $wsType = "PUT";
    my $wsService = $wsSvcUpdate . "/" . $modelHandle . "?attr=" . $IPAttr . "&val=" . $IP;
    my $URL = "http://" . $wsHost . ":" . $wsPort . "/" . $wsService;
    if($dbg > 5){print DEBUG "updateModelIP:created URL for updating IP:$URL\n";}
    #
    my $result = wsSubmitRequest($wsUser, $wsPw, $wsMessage, $URL, $wsType, $dbg);

     

     

     

    Hope this helps to provide an alternative that may work for you.



  • 3.  Re: CA Spectrum Web Service via Perl

    Posted Dec 16, 2016 05:38 AM

    Hi William,

     

    Thanks for reply, i figured it out how to do it.

     

    Regards

    Ajit C