Finishing up Auto-discovery module Part – III

This post in in continuation from earlier posts from Raj regarding auto-discovery.

In release 2.1.1 we have added 2 APIs to import devices and IP addresses to device42 appliance.

Currently the APIs support form encoded data format, application/x-www-form-urlencoded, we will support json, xml, csv formats in future releases. If you use some other data format let us know we will try to include that too.

For example, importing device using curl

curl -k \
--user user:passwd \
--data "manufacturer=Dell&os=Red+Hat+Enterprise+Linux&osver=6.1&memory=8589934592&osserial=716G-OJY0-BMPQ-TDW2&osverno=2.6.32-131&name=Kilauea&serial_no=HF3W-CZY6-U47D-IRPE&osmanufacturer=Red+Hat&hardware=PowerEdge+T710" \
http://your-device42-host/api/device/

make sure data is url encoded, and note the trailing / at the end of url.

This will result in following http request and response

Request

POST /api/device/ HTTP/1.1
Authorization: Basic bXl1c2VyOm15cGFzc3dvcmQ=
Content-Type: application/x-www-form-urlencoded

manufacturer=Dell&os=Red+Hat+Enterprise+Linux&osver=6.1&memory=8589934592&osserial=716G-OJY0-BMPQ-TDW2&osverno=2.6.32-131&name=Kilauea&serial_no=HF3W-CZY6-U47D-IRPE&osmanufacturer=Red+Hat&hardware=PowerEdge+T710

Response, http 200 is success.

HTTP/1.0 200 OK
Date: Mon, 06 Feb 2012 15:48:02 GMT
Content-Type: application/json
Allow: POST, HEAD

{"msg": "device added or updated", "code": 0}

similarly, for ip import

curl -k \
--user myuser:mypasswd \
--data "macaddress=DC-D1-4F-6C-BA-59&device=Kilauea&ipaddress=129.10.215.039" \
http://your-device42-host/api/ip/

Request

POST /api/ip/ HTTP/1.1
Authorization: Basic bXl1c2VyOm15cGFzc3dvcmQ=
Content-Type: application/x-www-form-urlencoded

macaddress=DC-D1-4F-6C-BA-59&device=Kilauea&ipaddress=129.10.215.039

Response, http 200 is success.

HTTP/1.0 200 OK
Date: Mon, 06 Feb 2012 15:49:37 GMT
Content-Type: application/json
Allow: POST, HEAD

{"msg": "ip added or updated", "code": 0}
[/pre]

all the responses with http code not 200 are error responses.

HTTP/1.0 403 FORBIDDEN
Date: Mon, 06 Feb 2012 15:23:15 GMT
Content-Type: application/json
Allow: POST, HEAD

{“detail”: “You do not have permission to access this resource. You may need to login or otherwise authenticate the request.”}
[/pre]

HTTP/1.0 500 INTERNAL SERVER ERROR
Date: Mon, 06 Feb 2012 15:23:37 GMT
Content-Type: application/json
Allow: POST, HEAD

{"msg": "Required parameter missing, name", "code": 1}
HTTP/1.0 500 INTERNAL SERVER ERROR
Date: Mon, 06 Feb 2012 15:48:57 GMT
Content-Type: application/json
Allow: POST, HEAD

{"msg": "{'ipadd': [u'Enter a valid IPv4 or IPv6 address.']}", "code": 1}

Here is a sample script using powershell and ironpython to automate import.

Comments/feedback are appreciated.

If you haven’t started using device42 yet, get your copy here; and current customers can click here to get the latest update.