CAPC RESTful Web Services

Document created by Stuart_Weenig on Mar 21, 2013Last modified by SamCreek on Dec 17, 2016
Version 3Show Document
  • View in full screen mode

Using RESTful Web Services

Group creation and associating rules to them would be performing a POST to the CAPC webservice. Creating discovery profiles would be performing a POST on the DA webservice. For both of these you'd need to pass the webservice some XML.

Here's an example of XML to create a group in the Default tenant and to create a rule under them to add devices in a certain IP range (please remove comments before posting this XML to the webservice):

<GroupTree path="/All Groups"> <!---This is the insertion point --> <Group name="ABC Corp" inherit="true" desc="ABC Corp"> <!---This defines the group name-->  <Rules allowDeletes="true" saveRules="true">  <!---Now we are setting up the Rule to add devices to the group automatically,  set saveRules to false to add the matching members but not save the rules (similar to adding members manually)-->   <Rule add="device" name="Add Devices">    <Match>     <Compare readOnly="true" using="MEMBER_OF">      <Property name="ItemID" type="Device"/> <!--- 1st matching criteria defines where to look for devices - which groups - in this case look in 'All Groups ' -->      <Value reference="/All Groups">1</Value>     </Compare>     <Compare readOnly="false" using="BETWEEN">       <Property name="Address" type="Device"/>      <ValueList> <!--- 2nd matching criteria is to check if the 'Address' of a Device is between 192.168.12.1 and 192.168.12.255 -->       <Value>192.168.12.1</Value>       <Value>192.168.12.255</Value>      </ValueList>     </Compare>    </Match>   </Rule>  </Rules> </Group> </GroupTree>

If you wanted to create the group in a different tenant than the default, the GroupTree tag would change. So if you wanted to create a group in tenant XYZ, then your GroupTree tag would be: <GroupTree path="/All Groups/Defined Tenants/XYZ/Groups">

If you wanted to create a SITE, you would change the GROUP tag as follows: <Group name="South Africa" inherit="true" desc="South Africa" type="site" location="Africa">

The above XML would be a POST to the PC webservice and you would POST to /pc/center/webservice/groups/false/false.

Here's an example if you were to use Perl to accomplish this:

use strict; use warnings; use REST::Client;  my $client = REST::Client->new(); $client->setHost('http://admin:admin@192.168.81.245:8181'); #Creates a connection to the webservice $client->addHeader('Accept', 'application/xml');  #Next you would define your XML that you would like to pass to the webservice my $body = '<GroupTree path="/All Groups">' . "\n" . '<Group name="ABC Corp" inherit="true" desc="ABC Corp">' ......... #add the rest of the body  $client->POST('/pc/center/webservice/groups/false/false', $body); # This will POST your XML to the groups web service. 

The next example contains the XML to create and run a discovery profile - this particular example adds the profile to the default ip domain:

<DiscoveryProfile version="1.0.0"> <IPListList> <IPList>192.168.24.22</IPList>  <IPList>192.168.24.19</IPList> <!--- Defines a list of IP addresses to be discovered--> <IPList>192.168.24.24</IPList> </IPListList> <RunStatus>START</RunStatus> <!--- Tells that this discovery profile will run as soon as its added. Change it to READY if you don't want it running immediately.--> <ActivationStatus>true</ActivationStatus> <Item version="1.0.0"> <Name>Discovery profile NAME</Name> <!--- Name of the discovery profile--> </Item> <IPDomainMember version="1.0.0"> <IPDomainID>2</IPDomainID> <!--- IP Domain that this discovery profile will be part of (default IP domain id is 2).--> </IPDomainMember> </DiscoveryProfile>

If you wanted to define an ip range instead of a list of IPs, replace the <IPListList> section with:

<IPRangesList> <IPRanges>192.168.210.1-192.168.210.255</IPRanges>  </IPRangesList>

 

If you want to get a list of IP Domain IDs available in an evironment, go to the following DA webservice URL: http://<DATA_AGGREGATOR>:8581/rest/ipdomains The above XML would be a POST to the Data Aggregator webservice and you would POST to /rest/tenant/1/discoveryprofiles/ - this would POST it to the Default Tenant (1). If you want to create this discovery profile in a different tenant than the Default, then you would change the tenant id - to get a list of tenant IDs go to the following DA webservice URL: http://<DATA_AGGREGATOR>:8581/rest/tenants Here's an example if you were to use Perl to accomplish this:

use strict; use warnings; use REST::Client;  my $client = REST::Client->new(); $client->setHost('http://IM-DA:8581'); #Connection to the Data aggregator web service. $client->addHeader('Accept', 'application/xml');  #Next you would define your discovery profile XML that you would like to pass to the webservice my $body = '<DiscoveryProfile version="1.0.0">' . "\n" . '<IPListList>' ...... #add the rest of the body  $client->POST('/rest/tenant/1/discoveryprofiles/', $body); #This will create the discovery profile in the default tenant as the tenant id is set to 1. 

Attachments

    Outcomes