Arista AEM

AEM is the event handler for Arista. It can be used to automate tasks giving the user the ability to customise alerts and actions. There are three parts to ARM; Event Manager, Event Monitor and Linux Tools.

Send XMPP Message on Interface Change
Download script and execute if startup-config present
Using variables in AEM
Running Script Before EOS Has Finished Booting

Send XMPP Messages on Interface Change

This has been taken from a previous post about XMPP.

AEM is the event manager. It works as an event, trigger and action sequence. More details about AEM can be found on the Arista website.
This example will show a switch that reports a message when an interface status is changed.
All of the config is applied to the switch spine1 in the AEM config.

Shutting down the interface eth2 should trigger the event and send a message to the admin in the chat client. A no shut will also trigger the same message. This is due to the trigger being a change in interface state.

I did try to modify this to get the switch to send the message to the chat group. The command runs, but I do not get any output in the chat or any other switches. I cannot see anywhere in the documentation that states this is not possible. It would be nice for the switches to use the switch group to send the message. Running show commands works, it is just the messages that seem to fail.


Download Script and Execute if startup-config Present

This is an extension of the ZTP script that I wrote in a previous post. In this previous post, ZTP would not correctly run the Python script for an unknown reason. I did correct this by using a config file and AEM, details can be found here
In this example version, I have updated the python script to add in lines for AEM. The ZTP script is below, the difference here is the AEM configuration commands that will on startup check if there is a startup-conig. If so, it will trigger the action to download a file called startup-event-test.txt.

In the switch logs it shows that the AEM is run on boot. Below the log is the AEM configuration.

In the above example, the AEM is only downloading the file, it is not doing anything else with it. AEM can perform multiple actions in a single command. This example is taken from my previous ZTP post.

Using Variables in AEM

AEM can be used to assign the output of a command, EOS CLI or bash to a variable that may be used. For this demonstration I have taken the example of configuring the XMPP username. In a previous post I have configured XMPP, with each switch having a the XMPP username as the switch hostname. I did this so from the the IM client Gajim I can differentiate the switches. The all switches chat group is shown below to illustrate the usernames of each switch.

Configuring the XMPP username command is quite simple, but is yet another thing to be done manually, that can easily be done in the setup of a switch. I have two methods for the configuration;
– Apply the configuration as commands in EOS
– Create a temporary file containing the XMPP configuration, and then copy it to the running config

The first method of applying the configuration as commands in EOS uses;
– Regex in bash to create the hostname variable $HOSTNAME, but only selecting character 2 to end of the string
– Echos the hostname variable
– Multi line FastCli command that uses the $HOSTNAME variable to apply the configuration.

For the second method, this is to create the file and copy the contents into the running config file. The running config is a virtual file that commands are added or removed using the no command. Arista file configuration information can be found here.

Running Script Before EOS Has Finished Booting

This isn’t part of AEM, as it runs before EOS has finished booting. To run a script before EOS has finished booting, the script can be placed into a file named /mnt/flash/rc.eos. The contents of this file will be executed during the boot process. It allows for modifications to the device. The below example has been taken from Arista documentation. As shown, this is a bash script that is running a python script depending on the switch version.

Leave a Comment

Your email address will not be published. Required fields are marked *