DX NetOps

  • 1.  Sample perl script using spectrum restful services

    Posted Nov 14, 2012 10:41 PM
      |   view attached
    Hi people,

    been playing with the restful web services in spectrum. Don't like Java so thought I'd have a go at a simple perl script.

    Here is my experiment for anyone who is interested.
    If you try it out try it in a dev environment first.
    To use: [font=Courier New]perl extract_all_device_ips.pl oneclickhostname userid password throttlesize[font]

    oneclickhostname = the oneclick host name
    userid and password are the one you use to login to oneclick
    throttlesize = the number of devices returned. It is option. If you don't specify it will return 1000

    What does it do? Not a lot. Basically it returns the network address of each of the devices in spectrum.

    My next experiment will be to create a script that uses the Get Tunnelling and choose the devices to export via one of those xml gizmos

    The lib.zip file contains addtional perl modules that aren't part of the standard perl libraries. If you have them already, you don't need the lib.zip contents.
    They includes:
    REST::Client and its dependencies
    XML::Tidy and its dependecies
    Math::BaseCnv
    Path::Class

    Also this script was tested with ActiveStae Perl on Windows. I haven't tested it directly with the cygwin perl on the oneclick server

    Have fun and once again TRY IT IN TEST FIRST

    NOTE the file should be called extract_all_device_ips.pl
    Remove the .txt off the end after downloading. It was put there to bypass the file extention restrictions on the CA communities.
    Also I will upload the lib.zip only if wanted. The post bombed when I tried to attach even though it is only 71k

    Attachment(s)



  • 2.  RE: Sample perl script using spectrum restful services

    Posted Nov 14, 2012 10:46 PM
      |   view attached
    This only required if you don't have the dependent libraries:

    Attachment(s)

    zip
    lib.zip   70 KB 1 version


  • 3.  RE: Sample perl script using spectrum restful services

    Posted Dec 03, 2012 01:06 PM

    Andrew1 wrote:

    Hi people,

    been playing with the restful web services in spectrum. (snip)
    Good stuff, Andrew.

    I had a follow-up example which you and others might find interesting: how to post Events to Spectrum using the RESTful API.

    DISCLAIMER: As of this posting, on 2012-12-03, CA has not updated the PDF manual[font=Courier New] Spectrum_Web_Services_API_Ref_ENU.pdf [font]to indicate any formal support for Event creation,
    but based on a hint of possibility on the bottom of page 55 (first appearing in the manual with v9.2.2),
    I tested the following, and it appears to function properly. YMMV.

    1 - modify your code slightly, from:
    $client->GET('spectrum/restful/devices?attr=0x12d7f&throttlesize=' . $HowMany);
    to:
    $client->POST('spectrum/restful/events', $xmlbody, undef );
    2 - populate my extra variable [font=Courier New] $xmlbody [font]
    with code from[font=Courier New] $SPECROOT/RestfulExamples/xml/Events/CreateEventByModelHandleList.xml [font]
    This CA-supplied sample code, which is installed on OneClick servers of v9.2.2 and newer, sets event[font=Courier New] 0x10f06 [font](High Memory Utilization) on a model.

    3 - edit[font=Courier New] $xmlbody [font]:
    In the line shown below, set the model handle to the model to which you want to send the event:
    <rs:model mh="0x1026ff"/>
    4 - execute as you describe, and your event magically appears on your model !
    NOTE: of course, you should test this fully in a non-Production environment before trying it in Production !!!

    HTH,
    --Mark S
    Mark Serencha – Inforonics Global Services, LLC – (m) +1-781-439-0519 – Mark.Serencha_AT_inforonics.com