Showing posts with label odm. Show all posts
Showing posts with label odm. Show all posts

19 February, 2014

Cisco IOS empty XML output issue

Noticed a weird issue with using the | format command. The switch had been idle for about 16 hours since last connection.

Issued command:
DLS2#sh cdp neighbors detail | format

Got reply:
<?xml version="1.0" encoding="UTF-8"?>
  <show_cdp_neighbors_detail xmlns="ODM://flash:/finalspan.odm//show_cdp_neighbors_detail">
    <SpecVersion>built-in</SpecVersion>
  </show_cdp_neighbors_detail>

No output of CDP whatsoever. I issued the same command again, 5 seconds later without any config alteration:
DLS2#sh cdp neighbors detail | format

Got reply:
<?xml version="1.0" encoding="UTF-8"?>
  <show_cdp_neighbors_detail xmlns="ODM://flash:/finalspan.odm//show_cdp_neighbors_detail">
    <SpecVersion>built-in</SpecVersion>
    <beginner>
      <remote_hostname>DLS1</remote_hostname>
      <remote_ip_addr>10.1.1.11</remote_ip_addr>
      <local_int>FastEthernet0/12,</local_int>
      <remote_int>FastEthernet1/0/12</remote_int>
    </beginner>
    <beginner>
      <remote_hostname>DLS1</remote_hostname>
      <remote_ip_addr>10.1.1.11</remote_ip_addr>
      <local_int>FastEthernet0/11,</local_int>
      <remote_int>FastEthernet1/0/11</remote_int>
    </beginner>
    <beginner>
      <remote_hostname>ALS2</remote_hostname>
      <remote_ip_addr>10.1.1.14</remote_ip_addr>
      <local_int>FastEthernet0/8,</local_int>
      <remote_int>FastEthernet0/8</remote_int>
    </beginner>
    <beginner>
      <remote_hostname>ALS2</remote_hostname>
      <remote_ip_addr>10.1.1.14</remote_ip_addr>
      <local_int>FastEthernet0/7,</local_int>
      <remote_int>FastEthernet0/7</remote_int>
    </beginner>
    <beginner>
      <remote_hostname>ALS1</remote_hostname>
      <remote_ip_addr>10.1.1.13</remote_ip_addr>
      <local_int>FastEthernet0/10,</local_int>
      <remote_int>FastEthernet0/10</remote_int>
    </beginner>
    <beginner>
      <remote_hostname>ALS1</remote_hostname>
      <remote_ip_addr>10.1.1.13</remote_ip_addr>
      <local_int>FastEthernet0/9,</local_int>
      <remote_int>FastEthernet0/9</remote_int>
    </beginner>
  </show_cdp_neighbors_detail>

Exact same anomaly occured on my other switch.
Affected hardware is running on:
c3560-ipservicesk9-mz.122-55.SE7.bin
c3750-ipservicesk9-mz.122-55.SE8.bin

14 February, 2014

Spanning-tree output formatting to XML

Formatting spanning-tree output into (almost) structured XML.
Can be used to query entire list of VLANs or just the desired ones.
The content of temp4.odm:

###
show spanning-tree
show spanning-tree vlan *
<?xml version="1.0" encoding="UTF-8"?>
<ODMSpec>
<SpecVersion>built-in</SpecVersion>
<Command><Name>show spanning-tree</Name></Command>
<DataModel>
<Container name="ShowSpanningtree">
<Container name="VLAN" alias = "VLANNER" dynamic = "true">
<Property name="VLAN" alias = "VLAN" distance = "0" length = "1" type = "String"/>
<Container name="Priority" alias = "Root_ID" dynamic = "false">
<Property name="Priority" alias = "Root_Priority" distance = "1" length = "1" type = "String"/>
<Property name="Address" alias = "Root_Address" distance = "1" length = "1" end-delimiter = "," type = "String"/>
<Property name="This" alias = "am_root" distance = "4" length = "1" type = "String"/>
</Container>
<Container name="Priority" alias = "Bridge_ID" dynamic = "false">
<Property name="Priority" alias = "Bridge_Priority" distance = "1" length = "1" type = "String"/>
<Property name="Address" alias = "Bridge_Address" distance = "1" length = "1" end-delimiter = "," type = "String"/>
</Container>
<Table name="Interfaces">
<Header name="Interface" type="String" start="0" end="18"/>
<Header name="Role" type="String" start="20" end="23"/>
<Header name="Sts" type="String" start="25" end="27"/>
<Header name="Cost" type="String" start="29" end="37"/>
<Header name="Prio.Nbr" type="String" start="39" end="46"/>
<Header name="Type" type="String" start="48" end="69"/>
</Table>
</Container>
</Container>
</DataModel>
</ODMSpec>

13 February, 2014

XML-PI property variables.

<Property name="Priority" alias = "Priority" distance = "2" length = "-1" type = "String"/>

Trying to figure out how exactly the distance and length values influence the XML output and format.


-update-

The <property> tag matches a row.
The "distance" parameter dictates where the matching of data (inside the row) should begin.
The "length" parameter dictates where the matching of data (inside the row) should end.
The value of "distance" can be any positive integer.
The value of "length" can range from -1 to any other positive integer (-1 covers entire row to the end).
Delimiter for counting numbers is the space key.

For example row:
              1           2          3          4         5

Priority    32769  (priority 32768 sys-id-ext 1)

and
<Property name="Priority" alias = "Priority" distance = "3" length = "-1" type = "String"/>

results in a match of
<Priority>32768 sys-id-ext 1</Priority>

11 February, 2014

Cisco c3750-24TS-E spec-file odm netconf

I need my CLI output in a structured format, for example in XML.
The switch needs to convert the text-block output to a structured XML format.

The available CLI commands that can produce structured XML output can be shown with 
#show format


On c3750-24TS-E, by default, there are three possible CLI commands that can produce XML output:
#show inventory
#show ip interface brief
#show running-config

The rules for generating the XML output are defined in a so-called Spec File. Every IOS device comes with a builtin Spec File with a limited amount of available CLI commands.
Spec files can be replaced with custom spec files, which use the .ODM file extension.

The .odm spec file can easily be customized by investigating the template for odm files. The template can be seen with
#show odm-format

To make the investigation easier it is possible to compare the show odm-format output with one of the built-in definitions:
#sh format cli show ip interface brief
The previous command shows the rules for parsing text-block output of show ip int brief.

To see if a CLI command's output can be shown in XML, you can issue:
#show ip interface brief | format
If the command is defined in the spec file then you are given the output in XML structure. If the command is not defined then you are given an error:
#show arp | format
%unable to find the specified cli, spec file: built-in, cli: show arp
% Incomplete command before pipe.

The odm spec files must be local to the switch. You can't use a remote spec file.


The spec-file is also used when querying for XML-structured information via netconf:
<?xml version="1.0" encoding="UTF-8"?>
<rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" 
xmlns:cpi="http://www.cisco.com/cpi_10/schema">
<get>
 <filter>
<oper-data-format-xml>
<show>inventory</show>
</oper-data-format-xml>
</filter>
</get>
</rpc>]]>]]>

I haven't found an easy way to view the contents of a built-in spec file. One way is to upload an empty file to the switch (emptyfile.odm for example) and then issue the command, which overwrites the empty file with the contents of its' built-in spec file:
#spec-file install flash:/emptyfile.odm built-in

An example of the built-in spec file of a c3750-24TS-E switch:
DLS1#more flash:/emptyfile.odm
###
show inventory
<?xml version="1.0" encoding="UTF-8"?>
<ODMSpec>
<SpecVersion>built-in</SpecVersion>
<Command><Name>show inventory</Name></Command>
<DataModel>
<Container name="ShowInventory">
<Container name="NAME:" alias = "InventoryEntry" dynamic = "true">
<Property name="NAME:" alias = "ChassisName" distance = "1" length = "1" end-delimiter = "," type = "String"/>
<Property name="DESCR:" alias = "Description" distance = "1" length = "-1" type = "String"/>
<Property name="PID:" alias="PID" distance = "1" length = "5" end-delimiter = "," type = "String"/>
<Property name="VID:" alias="VID" distance = "1" length = "1" end-delimiter = "," type = "String"/>
<Property name="SN:" alias="SN" distance = "1" length = "1" end-delimiter = "," type = "String"/>
</Container>
</Container>
</DataModel>
</ODMSpec>
###
show ip interface brief
<?xml version="1.0" encoding="UTF-8"?>
<ODMSpec>
<SpecVersion>built-in</SpecVersion>
<Command><Name>show ip interface brief</Name></Command>
<DataModel>
<Container name="ShowIpInterfaceBrief">
<Table name="IPInterfaces">
<Header name="Interface" type="String" start="0" end="22"/>
<Header name="IP-Address" type="IpAddress" start="23" end="38"/>
<Header name="OK" type="String" start="39" end="42"/>
<Header name="Method" type="String" start="43" end="49"/>
<Header name="Status" type="String" start="50" end="71"/>
<Header name="Protocol" type="String" start="72" end="-1"/>
</Table>
</Container>
</DataModel>
</ODMSpec>

To build a custom ODM spec file (in this case betaspec.odm) for sh arp :
###
show arp
<?xml version="1.0" encoding="UTF-8"?>
<ODMSpec>
<SpecVersion>built-in</SpecVersion>
<Command><Name>show arp</Name></Command>
<DataModel>
<Container name="ShowArp">
<Table name="ARPtable">
<Header name="Protocol" type="String" start="0" end="9"/>
<Header name="Address" type="IpAddress" start="10" end="26"/>
<Header name="Age (min)" type="String" start="27" end="37"/>
<Header name="Hardware Addr" type="String" start="38" end="53"/>
<Header name="Type" type="String" start="54" end="60"/>
<Header name="Interface" type="String" start="61" end="-1"/>
</Table>
</Container>
</DataModel>
</ODMSpec>

To import a modified spec file:
#(config)#format global flash:/betaspec.odm
#sh format flash:/betaspec.odm validate

You can customize the shown fields as desired. In this case entire output of sh arp is parsed to XML 
(notice you don't have to specify the custom spec file if configured as global):
DLS1#show arp | format flash:/betaspec.odm
<?xml version="1.0" encoding="UTF-8"?>
  <ShowArp xmlns="ODM://flash:/betaspec.odm//show_arp">
    <SpecVersion>built-in</SpecVersion>
    <ARPtable>
      <entry>
        <Protocol>Internet</Protocol>
        <Address>10.1.1.11</Address>
        <Agemin>-</Agemin>
        <HardwareAddr>0014.a905.2c41</HardwareAddr>
        <Type>ARPA</Type>
        <Interface>Vlan99</Interface>
      </entry>
      <entry>
        <Protocol>Internet</Protocol>
        <Address>10.1.1.12</Address>
        <Agemin>59</Agemin>
        <HardwareAddr>0017.5983.c1c1</HardwareAddr>
        <Type>ARPA</Type>
        <Interface>Vlan99</Interface>
      </entry>
      <entry>
        <Protocol>Internet</Protocol>
        <Address>10.1.1.1</Address>
        <Agemin>20</Agemin>
        <HardwareAddr>503d.e52b.a206</HardwareAddr>
        <Type>ARPA</Type>
        <Interface>Vlan99</Interface>
      </entry>
    </ARPtable>
  </ShowArp>

Now the custom spec file has been imported and made global.
You can now issue a netconf query using the <oper-data-format-xml> tags. For example the oper-data-format-xml works only if the command is presented in the global spec file. After the query you get a reply in structured XML.

query:
<?xml version="1.0" encoding="UTF-8"?>
<rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" 
xmlns:cpi="http://www.cisco.com/cpi_10/schema">
 <get>
  <filter>
   <oper-data-format-xml>
    <show>arp</show>
   </oper-data-format-xml>
  </filter>
 </get>
</rpc>]]>]]>

response:
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply message-id="101" xmlns="urn:ietf:params:netconf:base:1.0">
<data>
<cli-config-data-block>
here was show running config for some reason. to be investigated...
</cli-config-data-block>

<xml-oper-data>
<item>
<show>arp</show>
<response>
  <ShowArp xmlns="ODM://flash:/betaspec.odm//show_arp">
    <SpecVersion>built-in</SpecVersion>
    <ARPtable>
      <entry>
        <Protocol>Internet</Protocol>
        <Address>10.1.1.11</Address>
        <Agemin>-</Agemin>
        <HardwareAddr>0014.a905.2c41</HardwareAddr>
        <Type>ARPA</Type>
        <Interface>Vlan99</Interface>
      </entry>
      <entry>
        <Protocol>Internet</Protocol>
        <Address>10.1.1.12</Address>
        <Agemin>66</Agemin>
        <HardwareAddr>0017.5983.c1c1</HardwareAddr>
        <Type>ARPA</Type>
        <Interface>Vlan99</Interface>
      </entry>
      <entry>
        <Protocol>Internet</Protocol>
        <Address>10.1.1.1</Address>
        <Agemin>27</Agemin>
        <HardwareAddr>503d.e52b.a206</HardwareAddr>
        <Type>ARPA</Type>
        <Interface>Vlan99</Interface>
      </entry>
    </ARPtable>
  </ShowArp>
</response>
</item>
</xml-oper-data>
</data>
</rpc-reply>]]>]]>


useful links: