cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
677
Views
0
Helpful
1
Replies

Using Macros to Obtain IP

Graeme Kay
Level 1
Level 1

I am trying to navigate to and obtain a devices IP address in a macro, but I am unable to get a result using the following code:

 

function init(){
  xapi.status.get('Network IPv4 Address').then((value) => {
    systemInfo.ipv4 = value;
  });
}

The result of which is:

'Unhandled promise rejection' { code: 0, message: 'not object coercible' }

 

I can access the Status/Network part of the API but am unable to move further to get the details that I need.

The Status/Network area of the API:

<Status product="Cisco Codec" version="ce9.9.0.46f7ea38fda" apiVersion="4">
  <Network item="1" maxOccurrence="n">
    <IPv4>
       <Address>xx.xx.xx.xx</Address>
    </IPv4>
  </Network>
</Status>
The attributes in the Network tag may be what is preventing navigation past that point, as they are not included in the path.
 

Additionally other parts of the API can be accessed in this way (e.g: Status/SystemUnit/Software/Version). Is there any way to access and collect the IP?

1 Reply 1

tomas_vll
Level 1
Level 1

This one is a bit strange. I reversed to only request the entire status command, then "status network" and loked at the output. The output is a array of objects ( Probably for codecs with multiple NICs ). Selecting the array element 0 allows you to dig further down the data. This gives me the IPv4 adress

 

function init(){
  xapi.status.get('Network').then((value) => {
     console.log(value[0]["IPv4"]["Address"]);
  });
}