Some Network Automation (NetMRI) WAPI calls

1. First of all you have to authenticate yourself

«Cookie» with auth data should be saved into file after the «-c» option. In my example it is saved into the auth.file.

2. You can’t export devices with interfaces. You can export devices and interfaces separately.
For example, command:

will export information about all devices. «select» option defines which fields should be exported.
You can limit list of exported devices with filters. Filters are described here: http://NA-IP/api/2.10/devices/docs#index. Index is most fastest function but it has limited filter capabilities.

Instead of index you can use find or search. Show request can be used to display information about specified device.

{“total”: 26, “start”: 0, “limit”: 1000, “current”: 26, “devices”: [{“DeviceID”: 1, “DeviceName”: “na”, “DeviceDNSName”: null, “DeviceIPDotted”: “192.168.42.211”, “DeviceVendor”: “Infoblox”, “DeviceModel”: “Campus”, “_class”: “Device”}, {“DeviceID”: 3, “DeviceName”: “sandbox”, “DeviceDNSName”: null, “DeviceIPDotted”: “192.168.42.212”, “DeviceVendor”: “Net-SNMP”, “DeviceModel”: null, “_class”: “Device”}, {“DeviceID”: 7, “DeviceName”: “PE1.vp-home.ru”, “DeviceDNSName”: null, “DeviceIPDotted”: “10.10.10.1”, “DeviceVendor”: “Cisco”, “DeviceModel”: “3640”, “_class”: “Device”}, {“DeviceID”: 8, “DeviceName”: “PE2.vp-home.ru”, “DeviceDNSName”: null, “DeviceIPDotted”: “10.10.10.2”, “DeviceVendor”: “Cisco”, “DeviceModel”: “3640”, “_class”: “Device”},

Interfaces are available on the request:

{“total”: 11, “start”: 0, “limit”: 1000, “current”: 11, “interfaces”: [{“DeviceID”: 8, “InterfaceID”: 106, “ifAdminStatus”: “up”, “ifDescr”: “### to CE2 ### “, “ifMAC”: “C4:01:09:D2:00:00”, “_class”: “Interface”}, {“DeviceID”: 8, “InterfaceID”: 107, “ifAdminStatus”: “up”, “ifDescr”: “### to CE1 ###”, “ifMAC”: “00:00:00:00:00:00”, “_class”: “Interface”}, {“DeviceID”: 8, “InterfaceID”: 108, “ifAdminStatus”: “up”, “ifDescr”: “### to PE3 ###”, “ifMAC”: “C4:01:09:D2:00:01”, “_class”: “Interface”}, {“DeviceID”: 8, “InterfaceID”: 109, “ifAdminStatus”: “up”, “ifDescr”: “### to PE1 ###”, “ifMAC”: “00:00:00:00:00:00”, “_class”: “Interface”},

Unfortunately IP addresses are stored in the different table. So we have to request them separately (example with xml).

<?xml version=”1.0″ encoding=”UTF-8″?>
<response>
<total type=”int”>1</total>
<start type=”int”>0</start>
<limit type=”int”>1000</limit>
<current type=”int”>1</current>
<if_addrs type=”array”>
<if_addr>
<AddrChangedCols nil=”true”/>
<AddrEndTime nil=”true”/>
<AddrStartTime type=”datetime”>2014-03-12 15:55:27</AddrStartTime>
<AddrTimestamp type=”datetime”>2014-12-08 18:45:50</AddrTimestamp>
<DataSourceID type=”int”>0</DataSourceID>
<DeviceID type=”int”>8</DeviceID>
<IfAddrID type=”int”>56</IfAddrID>
<InterfaceID type=”int”>107</InterfaceID>
<SubnetIPDotted>10.0.0.20</SubnetIPDotted>
<SubnetIPNumeric type=”int”>167772180</SubnetIPNumeric>
<ifIPDotted>10.0.0.21</ifIPDotted>
<ifIPNumeric type=”int”>167772181</ifIPNumeric>
<ifIndex type=”int”>2</ifIndex>
<ifNetMaskDotted>255.255.255.252</ifNetMaskDotted>
<ifNetMaskNumeric type=”int”>4294967292</ifNetMaskNumeric>
<_class>IfAddr</_class>
</if_addr>
</if_addrs>
</response>

DeviceID and InterfaceID are used to limit the output with specific device and interface.

3. Device components

{“total”: 20, “start”: 0, “limit”: 1000, “current”: 20, “device_physicals”: [{“PhysicalClass”: “chassis”, “PhysicalName”: “3745 chassis”, “_class”: “DevicePhysical”}, {“PhysicalClass”: “container”, “PhysicalName”: “3640 Chassis Slot 0”, “_class”: “DevicePhysical”}, {“PhysicalClass”: “module”, “PhysicalName”: “c3745 Motherboard with Fast Ethernet”, “_class”: “DevicePhysical”}, {“PhysicalClass”: “container”, “PhysicalName”: “DaughterCard Slot 0 on Card 0”, “_class”: “DevicePhysical”}, {“PhysicalClass”: “module”, “PhysicalName”: “WAN Interface Card – Serial 2T”, “_class”: “DevicePhysical”}, {“PhysicalClass”: “port”, “PhysicalName”: “Serial0/0”, “_class”: “DevicePhysical”}, {“PhysicalClass”: “port”, “PhysicalName”: “Serial0/1”, “_class”: “DevicePhysical”}, {“PhysicalClass”: “container”, “PhysicalName”: “DaughterCard Slot 1 on Card 0”, “_class”: “DevicePhysical”}, {“PhysicalClass”: “module”, “PhysicalName”: “WAN Interface Card – Serial 2T”, “_class”: “DevicePhysical”}, {“PhysicalClass”: “port”, “PhysicalName”: “Serial0/2”, “_class”: “DevicePhysical”}, {“PhysicalClass”: “port”, “PhysicalName”: “Serial0/3”, “_class”: “DevicePhysical”}, {“PhysicalClass”: “container”, “PhysicalName”: “DaughterCard Slot 2 on Card 0”, “_class”: “DevicePhysical”}, {“PhysicalClass”: “container”, “PhysicalName”: “AIM Container Slot 0”, “_class”: “DevicePhysical”}, {“PhysicalClass”: “container”, “PhysicalName”: “AIM Container Slot 1”, “_class”: “DevicePhysical”}, {“PhysicalClass”: “container”, “PhysicalName”: “3640 Chassis Slot 1”, “_class”: “DevicePhysical”}, {“PhysicalClass”: “container”, “PhysicalName”: “3640 Chassis Slot 2”, “_class”: “DevicePhysical”}, {“PhysicalClass”: “container”, “PhysicalName”: “3640 Chassis Slot 3”, “_class”: “DevicePhysical”}, {“PhysicalClass”: “container”, “PhysicalName”: “3640 Chassis Slot 4”, “_class”: “DevicePhysical”}, {“PhysicalClass”: “port”, “PhysicalName”: “FastEthernet0/0”, “_class”: “DevicePhysical”}, {“PhysicalClass”: “port”, “PhysicalName”: “FastEthernet0/1”, “_class”: “DevicePhysical”}]}

4. Device configuration
Request for configuration revisions:

<?xml version=”1.0″ encoding=”UTF-8″?>
<response>
<total type=”int”>3</total>
<start type=”int”>0</start>
<limit type=”int”>1000</limit>
<current type=”int”>3</current>
<config_revisions type=”array”>
<config_revision>
<ConfigDiffs type=”int”>1</ConfigDiffs>
<ConfigRevision>1.9</ConfigRevision>
<ConfigRevisionID type=”int”>363</ConfigRevisionID>
<ConfigTimestamp type=”datetime”>2014-12-08 22:16:54</ConfigTimestamp>
<ConfigType>Running</ConfigType>
<DataSourceID type=”int”>0</DataSourceID>
<DeviceID type=”int”>9</DeviceID>
<LastCollected type=”datetime”>2014-12-08 22:16:54</LastCollected>
<PreviousTimestamp type=”datetime”>2014-12-08 22:16:26</PreviousTimestamp>
<_class>ConfigRevision</_class>
</config_revision>
<config_revision>
<ConfigDiffs type=”int”>1</ConfigDiffs>
<ConfigRevision>1.10</ConfigRevision>
<ConfigRevisionID type=”int”>365</ConfigRevisionID>
<ConfigTimestamp type=”datetime”>2014-12-09 17:23:12</ConfigTimestamp>
<ConfigType>Running</ConfigType>
<DataSourceID type=”int”>0</DataSourceID>
<DeviceID type=”int”>9</DeviceID>
<LastCollected type=”datetime”>2014-12-09 17:23:12</LastCollected>
<PreviousTimestamp type=”datetime”>2014-12-08 22:16:54</PreviousTimestamp>
<_class>ConfigRevision</_class>
</config_revision>
<config_revision>
<ConfigDiffs type=”int”>0</ConfigDiffs>
<ConfigRevision>1.3</ConfigRevision>
<ConfigRevisionID type=”int”>366</ConfigRevisionID>
<ConfigTimestamp type=”datetime”>2014-12-09 17:23:12</ConfigTimestamp>
<ConfigType>Saved</ConfigType>
<DataSourceID type=”int”>0</DataSourceID>
<DeviceID type=”int”>9</DeviceID>
<LastCollected type=”datetime”>2014-12-09 17:23:12</LastCollected>
<PreviousTimestamp type=”datetime”>2014-12-08 22:16:54</PreviousTimestamp>
<_class>ConfigRevision</_class>
</config_revision>
</config_revisions>
</response>

Request of the configuration revision:

<?xml version=”1.0″ encoding=”UTF-8″?>
<response>
<text>version 12.4
service timestamps debug datetime msec localtime show-timezone
service timestamps log datetime msec localtime show-timezone
no service password-encryption
!
hostname CE1
!
boot-start-marker

5.  Run script with parameters:

6. Execute a command on a device

– open CLI session

 – send the command (we have to define session ID)

 – close CLI session

BR,
Vadim

Этот сайт использует Akismet для борьбы со спамом. Узнайте как обрабатываются ваши данные комментариев.