DX NetOps

  • 1.  Querying a devices interfaces via REST API

    Posted Jan 16, 2013 11:52 PM
    Hi all,

    I'm trying to query the attributes of a device's interfaces via the REST API. Things like state (up/down) link speed etc. I can get a list of interfaces via the 0x100c5 attribute but I'm unsure as to how to enumerate the results or drill deeper.

    As an example, the following URL:

    http://<hostname>:<port>/spectrum/restful/model/0x70029d4?attr=0x100c5

    Results in this output:

    <model mh="0x70029d4">
    <attribute-list id="0x100c5">
    <instance value="Vlan1" oid="1"/>
    <instance value="Vlan261" oid="261"/>
    <instance value="StackPort1" oid="5179"/>
    <instance value="StackSub-St1-1" oid="5180"/>
    <instance value="StackSub-St1-2" oid="5181"/>
    <instance value="GigabitEthernet1/0/1" oid="10101"/>
    <instance value="GigabitEthernet1/0/2" oid="10102"/>
    <instance value="GigabitEthernet1/0/3" oid="10103"/>
    ....OUTPUT REMOVED....
    <instance value="GigabitEthernet1/1/2" oid="10126"/>
    <instance value="GigabitEthernet1/1/3" oid="10127"/>
    <instance value="GigabitEthernet1/1/4" oid="10128"/>
    <instance value="TenGigabitEthernet1/1/1" oid="10201"/>
    <instance value="TenGigabitEthernet1/1/2" oid="10202"/>
    <instance value="Null0" oid="14501"/>
    <instance value="FastEthernet0" oid="14502"/>
    </attribute-list>
    </model>
    </model-responses>
    </model-response-list>

    I assume I can use that OID somehow to go further? I'm hoping it can be achieved via a simple GET URL request and I don't have to go down the GET tunneling path, but I'll take anything that works :-)

    Any thoughts? Thanks in advance,

    Stuart.


  • 2.  RE: Querying a devices interfaces via REST API

    Posted Jan 18, 2013 08:43 AM
    The attributes ifAdminStatus and ifOperStatus will give you up/down status of all interfaces on a device. Most of the attributes that start with "if" will be a table of all instances of all interfaces on a device model.


  • 3.  RE: Querying a devices interfaces via REST API

    Posted Jan 18, 2013 06:40 PM
    Thanks for the input, those are definitely the attributes I wanted, I just couldn't figure out how to find the association between the device mh and the interfaces. All good now.


  • 4.  RE: Querying a devices interfaces via REST API
    Best Answer

    Posted Jan 18, 2013 11:58 AM
    Hi,

    To get the interface model handles, you would first need to query the device model:

    http://spock:8080/spectrum/restful/associations/relation/0x10004/model/0xdevHandle?side=left

    This will list all the model handles of the 'has_members' relation to the device (interfaces)

    You will then need to iterate through the list of model handles and use that to query the interface info.

    I found the easiest way to do this is to use the VNM Shell to find out what the attribute id's are:

    ./opt/spectrum/vnmsh/connect
    ./opt/spectrum/vnmsh/show attributes mh=0x70029d4

    If the model handle you show is an interface model you should get a long list of attributes with their values:

    [spectboy@speccy vnmsh]$ ./show attributes mh=0x211591
    Id Name Iid Value
    0x10000 Modeltype_Name Gen_IF_Port
    0x10001 Modeltype_Handle 0x220011
    0x10004 Contact_Status 1
    0x10009 Security_String SEC1
    0x1000a Condition 0
    0x1000b Condition_Value 0
    0x1000c Value_When_Yellow 1
    0x1000d Value_When_Orange 3
    0x1000e Value_When_Red 7
    0x1000f Composite_Condition 0
    0x10010 Yellow_Threshold 3
    0x10011 Orange_Threshold 6
    0x10012 Red_Threshold 10
    0x10013 Rollup_Condition 0
    0x10023 Agent_Port 161
    0x10024 Community_Name #v2/c0mmStr1n9

    The list is a log longer but if you find an attribute you like you can just add '&attr=<val1>&attr=<val2>' etc
    just keep adding '&attr=<val>' for each attribute you want to add in the URL you feed the REST API.

    You should get something similar to:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <model-response-list xmlns="http://www.ca.com/spectrum/restful/schema/response" error="EndOfResults" throttle="1" total-models="1">
    <model-responses>
    <model mh="0x211591">
    <attribute id="0x10004">1</attribute>
    <attribute id="0x129e0">FastEthernet0</attribute>
    <attribute id="0x11f7e"></attribute>
    <attribute id="0x110df">00:11:22:33:44:55</attribute>
    <attribute id="0x12d7f">1.1.100.79</attribute>
    <attribute id="0x11990">100000000</attribute>
    </model>
    </model-responses>
    </model-response-list>

    Hope this helps!

    Regards,

    Frank


  • 5.  RE: Querying a devices interfaces via REST API

    Posted Jan 18, 2013 06:37 PM
    Thankyou, this is exactly what I was after!

    Excuse my ignorance but I'm very new to spectrum so it didn't occur to me that interfaces themselves have model handles and attributes (I realise after reading your post that they are visible in oneclick too).

    The relationship URI is the real glue that puts it together though as I would have not been able to make that association via the other nouns (device and model).