How to find devices using filtering on certain Names with common aspects using REST
search cancel

How to find devices using filtering on certain Names with common aspects using REST

book

Article ID: 401820

calendar_today

Updated On:

Products

Network Observability CA Performance Management

Issue/Introduction

Searching for a number of similar devices that include shared aspects in their name. For example, all contain the letters _RW to indicate that they're routers. How can this search be implemented using REST in CA Performance Management (CAPM)?

Environment

DX NetOps CAPM all currently supported releases

Resolution

Create a file to contain the XML formatted filter. For example /tmp/filter.xml

This filter file will contain the filtering required, with the following syntax:

<FilterSelect xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="filter.xsd">
<Filter>
    <Item.Name type="CONTAINS">_RW</Item.Name>
</Filter>
<Select use="exclude" isa="exclude">
<Item use="exclude">
    <Name use="include" />
</Item>
<Device use="exclude">
    <HostName use="include" />
    <PrimaryIPAddress use="include" />
    <ContactStatus use="include" />
</Device>
<Lifecycle use="include"></Lifecycle>
</Select>
</FilterSelect>

The above filter code searches on the Item.Name for any discovered Items that CONTAINS the phrase _RW anywhere within the Item name.

The line <Select use="exclude" isa="exclude"> means exclude everything but note, the following lines then have includes that override the exclude for the attributes specified. So the section that follows:

<Item use="exclude">
    <Name use="include" />
</Item>

Means exclude all attributes of the Item Except its Name. Then the section after that:

<Device use="exclude">
    <HostName use="include" />
    <PrimaryIPAddress use="include" />
    <ContactStatus use="include" />
</Device>

Means exclude all device attributes Except the Hostname, IP address and Contact Status in the output.

 

You can run the above using either curl on the command line or a REST API client using a POST request.

Using curl in this example, the XML output is displayed as one long line without any formatting, making it very difficult to read, so pipe it into a command line formatting utility such as xmllint which will append a new line to each line of formatted XML output:

xmllint --format - 

 

So when you run it, add the xmllint utility through a pipe as follows:

curl -kv -u admin -s -X POST -d @/tmp/filter.xml  http://<DA_HOST>:8581/rest/devices/filtered --header "Content-Type: application/xml" | xmllint --format - > /tmp/output.xml

The above will output something similar to the following in the resulting /tmp/output.xml file:

<?xml version="1.0"?>

<DeviceList>

  <Device version="1.0.0">

    <ID>7235</ID>

    <ContactStatus>DOWN</ContactStatus>

    <PrimaryIPAddress>198.162.0.3</PrimaryIPAddress>

    <Lifecycle version="1.0.0">

      <TimeStamp>Thu Jan 1 0:00:00 1970 +0000</TimeStamp>

      <State>ACTIVE</State>

    </Lifecycle>

    <Item version="1.0.0">

      <Name>Sim-YYY_RW</Name>

    </Item>

  </Device>

  <Device version="1.0.0">

    <ID>7525</ID>

    <ContactStatus>UP</ContactStatus>

    <PrimaryIPAddress>198.162.0.2</PrimaryIPAddress>

    <Lifecycle version="1.0.0">

      <TimeStamp>Thu Jan 1 0:00:00 1970 +0000</TimeStamp>

      <State>ACTIVE</State>

    </Lifecycle>

    <Item version="1.0.0">

      <Name>Sim-XXX_RW</Name>

    </Item>

  </Device>

</DeviceList>