XML POST code is:
<?xml version="1.0" encoding="UTF-8"?>
<rs:model-request throttlesize="1000"
xmlns:rs="http://www.ca.com/spectrum/restful/schema/request"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.ca.com/spectrum/restful/schema/request ../../../xsd/Request.xsd">
<rs:target-models>
<rs:models-search>
<rs:search-criteria
xmlns="http://www.ca.com/spectrum/restful/schema/filter">
<devices-only-search/>
<filtered-models>
<greater-than>
<attribute id="0x129fa">
<value>0x000000</value>
</attribute>
</greater-than>
</filtered-models>
</rs:search-criteria>
</rs:models-search>
</rs:target-models>
<rs:requested-attribute id="0x1006e"/>
<rs:requested-attribute id="0x12d7f"/>
<rs:requested-attribute id="0x10032"/>
<rs:requested-attribute id="0x1000a"/>
<rs:requested-attribute id="0x11ee8"/>
<rs:requested-attribute id="0x10000"/>
</rs:model-request>
You can just extract the info you need:
<model mh="0x1f141a0"><attribute id="0x1006e">kdevs66</attribute><attribute id="0x12d7f">1.1.1.1</attribute><attribute id="0x10032"></attribute><attribute id="0x1000a">0</attribute><attribute id="0x11ee8">12</attribute><attribute id="0x10000">Pingable</attribute></model>
Each device's info is encompassed in <model> </model> tags.
You can do something like:
# Look through XML to get models
while ($restXml =~ /<model mh=\"(0x.*?)\">(.*?)<\/model>/g) {
($mh, $attribList) = ($1, $2);
# Now we iterate through each of the attributes
while ($attribList =~ /<attribute id=\"(0x.*?)\"(.*?\/.*?)>/g) {
($attr, $val) = ($1, $2);
# We need to cater for when the model doesn't have some attributes, eg. Pingable devices don't have community name and will return 'NoSuchAttribute'.
if ($val =~ / error=\"NoSuchAttribute\"\//) {
$val = '';
} elsif ($val =~ />(.*?)<\/attribute/) {
$val = $1;
}
print "Attribute '$attr' is '$val'\n";
}
You can also use:
http://<SERVER>:<PORT>/spectrum/restful/devices?attr=0x1006e&attr=0x12d7f
Which might be quicker if you want all devices on all servers. I normally use POST XML because you have more control over what devices you want to return. E.g. Instead of all devices, you can say for example all devices which contain the phrase 'core' in the name.
You can just add &attr= for additional attributes you may want to include.
Hope this helps