One of the KEY points of Abiquo is that you can use its API to access ALL resources and actions available from the graphical user interface. This enables us to create an infinite number of external applications that you can integrate with your environment or platform. All the API resources are documented on our wiki.

In this article, we are going to present the Abiquo Events Notifier, a Python tool that monitors events performed in Abiquo and based on a configurable list of rules, sends notifications by email to the cloud administrators, enterprise administrators, etc. This tool can be very useful for the cloud administrator in tracking errors on the platform. Also, you can configure the tool to notify your users when a deploy is finished or if a virtual appliance they own has been undeployed. You can find the full documentation on Abiquo DevOps wiki

To serve this purpose, we only need to access two resources of the Abiquo API. First, we need to retrieve the list of Abiquo users.

To retrieve the user list for a certain enterprise, you just have to use the following REST resource:
[code lang=”bash” light=”true”]http://abiquo-server/api/admin/enterprises/[/code]

This Python code excerpt gives an example of how to perform a get on the above-mentioned REST resource:

Required Python libraries:

[code lang=”python” light=”true”] import pycurl
import StringIO
from xml.dom.minidom import parse, parseString

# User result array
user_list = []

# From a previous call, we get the EnterpriseID
enterprise_id = enterprise.getElementsByTagName("id")[0].childNodes[0].nodeValue

# API call requires a user with the appropriate privileges to request this information.
user_pwd = ‘%s:%s’ % (user, pwd)
# API call construction and execution
url = "http://%s:%s/api/admin/enterprises/%s/users" % (ip, port, enterprise_id)
response = StringIO.StringIO()
c = pycurl.Curl()
c.setopt(pycurl.WRITEFUNCTION, response.write)
c.setopt(pycurl.URL, str(url))
c.setopt(pycurl.USERPWD, user_pwd)
c.perform()
c.close()

# User list retrieved from the API call
try:
users_list = parseString(response.getvalue()).getElementsByTagName("user")
except Exception, e:
print("An error occurred when parsing the user list: %s" %(str(e)))
[/code]

Simplified call response sample:

[code lang=”xml” light=”true”] <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<users>
<totalSize>2</totalSize>
<user>
<active>true</active>
<authType>ABIQUO</authType>
<description>Main administrator</description>
<email>cloud-admin@abiquo.com</email>
<id>1</id>
<locale>en_US</locale>
<name>Cloud</name>
<nick>admin</nick>
<surname>Administrator</surname>
</user>
<user>
<active>true</active>
<authType>ABIQUO</authType>
<description>Standard user</description>
<email>cloud-user@abiquo.com</email>
<id>2</id>
<locale>en_US</locale>
<name>Standard</name>
<nick>user</nick>
<surname>User</surname>
</user>
</users>
[/code]

We also need to retrieve the events occurring on the Abiquo platform. This information can be retrieved from the following REST resource:

[code lang=”bash” light=”true”]http://abiquo-server/api/events[/code]

Required Python libraries:

[code lang=”xml” light=”true”] import pycurl
import StringIO
import time
from dateutil import parser
from xml.dom.minidom import parse, parseString
[/code]

This Python code excerpt is an example function which shows you how to retrieve events performed in Abiquo from a given date until now:

[code lang=”python” light=”true”] # get_net_events function
def get_new_events(last_event=None,limit = 100,ip=’127.0.0.1′,user=’admin’,pwd=”,port=’80’):

if last_event:
# Events filtered by date
url = "http://%s:%s/api/events?datefrom=%d" % (ip, port, int(last_event.get_timestamp())+1)
else:
# All events
url = "http://%s:%s/api/events" % (ip, port)

# API call requires an user with the adequate privileges to request this information.
user_pwd = ‘%s:%s’ % (user, pwd)
# API call construction and execution
response = StringIO.StringIO()
c = pycurl.Curl()
c.setopt(pycurl.WRITEFUNCTION, response.write)
c.setopt(pycurl.URL, url)
c.setopt(pycurl.USERPWD, user_pwd)
c.perform()

# Event list retrieved from the API call
events_list = parseString(response.getvalue()).getElementsByTagName("event")

events = [] for event in events_list:
events.append(Event(event=event))

# Returning all events
return events
[/code]

Simplified response sample:

[code lang=”xml” light=”true”] <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<events>
<totalSize></totalSize>
<event>
<actionPerformed>VAPP_CREATE</actionPerformed>
<component>VIRTUAL_APPLIANCE</component>
<enterprise>Abiquo</enterprise>
<id>22</id>
<idEnterprise>1</idEnterprise>
<idUser>1</idUser>
<idVirtualDatacenter>1</idVirtualDatacenter>
<performedBy>admin</performedBy>
<severity>INFO</severity>
<stacktrace>Virtual Appliance ‘WordPress vApp’ has been created.</stacktrace>
<timestamp>2013-02-11T10:06:36+01:00</timestamp>
<user>admin</user>
<virtualDatacenter>VirtualDataCenter</virtualDatacenter>
</event>
<event>
<actionPerformed>VDC_CREATE</actionPerformed>
<component>VIRTUAL_DATACENTER</component>
<enterprise>Abiquo</enterprise>
<id>20</id>
<idEnterprise>1</idEnterprise>
<idUser>1</idUser>
<performedBy>admin</performedBy>
<severity>INFO</severity>
<stacktrace>Virtual Datacenter ‘VirtualDataCenter’ has been created.</stacktrace>
<timestamp>2013-02-11T10:06:16+01:00</timestamp>
<user>admin</user>
</event>
<event>
<actionPerformed>VLAN_CREATED</actionPerformed>
<component>NETWORK</component>
<enterprise>Abiquo</enterprise>
<id>21</id>
<idEnterprise>1</idEnterprise>
<idUser>1</idUser>
<performedBy>admin</performedBy>
<severity>INFO</severity>
<stacktrace>A new Private VLAN with name ‘default_private_network’ has been created in Virtual Datacenter ‘VirtualDataCenter’.</stacktrace>
<timestamp>2013-02-11T10:06:16+01:00</timestamp>
<user>admin</user>
</event>
<event>
<actionPerformed>USER_CREATE</actionPerformed>
<component>USER</component>
<enterprise>Enterprise A</enterprise>
<id>19</id>
<idEnterprise>2</idEnterprise>
<idUser>1</idUser>
<performedBy>admin</performedBy>
<severity>INFO</severity>
<stacktrace>User ‘John’ has been created [Enterprise: ‘Enterprise A’ Name: ‘John’ Surname: ‘Test’ Role: ‘com.abiquo.server.core.enterprise.Role@764c3047’]</stacktrace>
<timestamp>2013-02-11T09:51:21+01:00</timestamp>
<user>admin</user>
</event>
</events>
[/code]

Some of the resources, such as events, can accept extra parameters with the GET method. This enables us to search among the events. Some of the extra parameters for events are, as an example:

  • DATEFROM-> shows events later than a defined date
  • PHYSICALMACHINE -> shows events only related to a certain hypervisor
  • SEVERITY -> filters by the severity of the event

Once we have collected all this information, we are now able to generate required notifications and send them to users.

You can take a look for yourself at the Abiquo Events Notifier code at:
https://github.com/abiquo/abiquo-events-notifier