
Automation is key to the modern enterprise. Automox wants to help with that by providing an API to its users. The API interface is protected with a key which can be found in the console.
There are a number of API features to use which can be found here: https://docs.automox.com/api/ . In this example we will go over using the Events API using python. Be sure to log in to the console, navigate to Settings, and you’ll find the API Key at the bottom of the page.
The data from the API is in JSON format. In this example we will look at the Events call in the API . The fields in the Events JSON are:
{ “create_time”: “2018-06-12T14:33:17.455Z”, “data”: { “firstname”: “string”, “lastname”: “string”, “email”: “string”, “orgname”: “string”, “ip”: “string”, “os”: “string”, “systemname”: “string”, “text”: “string”, “status”: 0, “patches”: “string” }, “id”: 0, “name”: “system.add”, “policy_id”: 0, “policy_name”: “string”, “policy_type_name”: “string”, “server_id”: 0, “server_name”: “string”, “user_id”: 0 } ] |
Sample output from calling events is below:
{ ‘create_time’: ‘2018-06-11T07:00:14+0000’, ‘data’: { ‘status’: ‘1’, ‘text’: ‘Failed to apply patches (“kubectl”)}, ‘id’: 4284390, ‘name’: ‘system.policy.action’, ‘organization_id’: 1, ‘policy_id’: 212, ‘policy_name’: ‘Nightly Patch’, ‘policy_type_name’: ‘patch’, ‘server_id’: 434, ‘server_name’: ‘example.com’, ‘user_id’: None} |
To access the data we will use Python and the requests package. The simplest example would be to just return all the data to the screen.
import requests pageText=requests.get(“https://console.automox.com/api/events?api_key=yourKey”).json() print(pageText) |
You may notice is that it is a bit hard to read, since it is just a JSON dump. Lets go over converting some select data to CSV.
This will create a file with the time stamp in the name with all events in it. This would make for easy parsing in your SEIM or even in Excel.
from datetime import datetime |
You could go further and only show errors by checking the status of the message, allowing for a table output or CSV. And of course you may not want to hardcode the API Key, instead provide them on the command line using argparse. Also adding in to limit to the most X recent errors.
#!/usr/bin/env python3 import json parser = argparse.ArgumentParser(description=’Automox API Example’) def formatCell(x): baseUrl=”https://console.automox.com/api/events?api_key=” i=0 if args.csv: if args.limit: if args.table: |
Usage:
events.py [-h] [–limit LIMIT] [–csv] [–table] [–errors] apiKey Automox API Example positional arguments: optional arguments: |
This just scratches the surface of what you can do with the Aumox API. I hope this helps you out with automating your use of Automox. Please let me know if you have any questions.