Abiquo events catcher
This app enables you to execute commands when a new event of a concrete type is generated by Abiquo. This allows, for example, send an email when an user performs a login.
You can use the API to know the current event types https://wiki.abiquo.com/api/latest/EventsResource.html#list-events-types
Usage
Code Block | ||
---|---|---|
| ||
--api-endpoint (-ae) VAL : Abiquo API URL to connect
--api-password (-ap) VAL : Abiquo API password
--api-username (-au) VAL : Abiquo API username
--api-version (-av) VAL : Override Abiquo version on API requests (default: current version)
--database-file (-df) VAL : Event-catcher Database file (default: ./catcherdb)
--fetch-interval (-fi) N : Fetch interval in minutes (default: 10)
--first-fetch-delay (-ffd) N : Delay of first event fetch in minutes (default: 0)
--first-fetch-range (-ffr) N : First fetch range in minutes (default: 60)
--receivers-file (-rf) VAL : Receivers INI file (default: ./receivers.ini) |
How to configure catchers
It looks by default for receivers.ini
in CWD. An example:
Code Block |
---|
[example-catch-1]
actions=TAGS_SYNC, LOGIN
command=echo.sh
[example-cath-2]
actions=LOGIN
command=sendemail.sh |
Note that you can add as many catchers as you like.
Each command defined will executed by events-catcher with the following arguments:
First argument is the complete event JSON (https://wiki.abiquo.com/api/latest/event.html)
Second argument is the JSON of the entity related to the event. This can be empty.
Code Block | ||
---|---|---|
| ||
> sh echo.sh "event_json" "entity_json" |
Deployment
Create the working folder at /opt/abiquo/eventscatcher
that contains:
The app
eventscatcher.jar
The receivers config file
receivers.ini
The bash scripts for the commands (like
echo.sh
,sendemail.sh
or your own scripts)
Add a new service to systemd to run eventscatcher.
Let's create a new file called /etc/systemd/system/eventscatcher.service
:
Code Block |
---|
[Unit]
Description=Abiquo eventscatcher systemd service
After=network.target
[Service]
Type=simple
User=tomcat
WorkingDirectory=/opt/abiquo/eventscatcher
ExecStart=/bin/java -jar /opt/abiquo/eventscatcher/eventscatcher.jar --api-endpoint {api.endpoint} --api-username {api.username} --api-password {api.password}
[Install]
WantedBy=multi-user.target |
You will need:
Set the actual username after
User=
(make sure that the user has permissions on/opt/abiquo/eventscatcher
)Set the proper app args after
--api-endpoint
,--api-username
and--api-password
Set the correct
java
binary afterExecStart
Just execute:
systemctl start eventscatcher.service
to start the servicesystemctl status eventscatcher.service
to check the statussystemctl enable eventscatcher.service
to start service on boot
Logging
There are two logs:
The app general log in CWD and named
eventscatcher.log
The command executions log in CWD and name
eventscatcher-executions.log