Using API’s for Custom Auto-Discovery

If you find that there are auto-discovery methods that you need and that aren’t provided by Device42, you can create you own auto-discovery tools that use Device42’s API’s to load data into a Device42 instance.

Device42 provides a number of sample scripts that you can use as a basis for your own custom auto-discovery tools. These tools are available at Device42’s Auto-Discovery Tools Site and include the following scripts:

api-sample.py : Runs against a single windows server and uploads info to the Device42 appliance.

ad-sample.py : Runs against Active Directory computers, servers or a list of IP addresses, and upload discovered systems’ info to the Device42 appliance.

d42_api_linux_upload_sample_script.py : Runs on a single *nix based system and uploads info to the Device42 appliance.

sample-script-facter-facts-to-d42.py : Runs on a Puppet master and uploads nodes info from facter fact files to the Device42 appliance.

d42_api_solaris_sample_script.py: Runs on an individual Solaris system and uploads info to the Device42 appliance.

linux_auto_dics_multi.py: Run on a *nix system with paramiko to get inventory using ssh from an IP range and upload to the Device42 appliance.

winservice.py : Can run against Active directory computers, servers or a list of IP addresses and upload discovered services as application components to the Device42 appliance.

All of these scripts are written in Python but you can use any programming language that can call RESTful API’s.

The remainder of this document will show an example of how to use one of these scripts. We wil use Iron Python for this example because it is simple to install. You can just drop the executables into a folder and as long as you have the .NET 4 framework installed, you are good to go.

Requirements:

1. Install IronPython Binaries

1. Install IronPython Binaries

Assuming that you have Powershell and the .Net 4 framework installed already, you can just download the Installer or Binaries for IronPython. We suggest the binaries because you can just unzip the folder and you are ready to go.

2. Download the sample script (api-sample.py)

2. Download the sample script (api-sample.py)

You can download the latest script at https://github.com/device42/Device42-API/tree/master/src.

Once you click on the script file, you can click on download and save that file (File>Save Page As…); preferably in same folder as binaries for IronPython are unzipped.

3. Get Sample Script ready for your environment

3. Get Sample Script ready for your environment

Edit the script and change these sections:
BASE_URL: Change this to the url for the Device42 appliance. Please make sure there is no trailing ‘/’ at the end of the url.
Example: BASE_URL=’https://d42app.device42.pvt’

USER & PASSWORD should be credentials for an Administrator who has access to log into the Device42 appliance.

Make just these changes and you are ready to run the script.

4. Running the script

4. Running the script

From command line, go the folder where binaries for IronPython are and run ipy.exe passing the script name as the argument as highlighted in image above.
If all goes well, you should see the device added in the Device42 portal along with the IP and MAC address details.