Easy Infrastructure Monitoring uses small "scripts" to handle service checks and alert actions. These scripts are written in JavaScript.
Technically, a JavaScript execution engine is created from the javax.script package as follows:
import javax.script.*;
.....
ScriptEngineManager factory = new ScriptEngineManager();
// create a JavaScript engine
engineJS = factory.getEngineByName("JavaScript");
You can read more technical information about the scripting engine in the JavaDoc of javax.script package and in this small Programmer's guide.
A good JavaScript tutorial can be found here.
Apart from the standard JavaScript functionality, Easy Infrastructure Monitoring also adds several pre-defined functions and objects.
The following objects are available:
* service is a reference to the Java implementation of the service object
* host is a reference to the Java implementation of the host object
* conf is a reference to the Java implementation of the application configuration object
Depending on the context, some of these objects can be null. For example, a script for handling a host alert will have a null service object. The only object that is guaranteed not to be null is the "conf" object. This is available for all scripts.
The following functions are available:
* runCommand(connection_name,command) allows connecting to the current host, using the connection indicated, and running the command given as a string. It will return, as a string, the result from executing the specified command.
* Linux_getMemoryPercent(connection_name) allows connecting to the current host, using the connection indicated, and will retrieve the percent of used memory on that host.
* Linux_getCPUPercent(connection_name) allows connecting to the current host, using the connection indicated, and will retrieve the percent of used CPU on that host.
* Linux_getDiskPercent(connection_name,disk) allows connecting to the current host, using the connection indicated, and will retrieve the percent of used disk space on that host, for a given disk (actually on Linux systems this is not necessarily to be an actual disk, but rather a mountpoint).
* Linux_getInterfacePercent(connection_name,iface,direction,speedMBits) allows connecting to the current host, using the connection indicated, and will retrieve the percent of used bandwidth on the specified interface for a certain direction (rx/tx).
* sendEmailToGroup(server,group,subject,message) sends an email using the indicated server, to the specified group with the given subject and message body.
As it can be easily guessed, the commands starting with "Linux" are intended to be executed against a Linux host (regardless of the actual operating system) or at least against a host offering some "Linux-like" environment.
Examples:
runCommand('default','service httpd restart');
Linux_getMemoryPercent('default');
Linux_getCPUPercent('default');
Linux_getDiskPercent('default','/');
Linux_getDiskPercent('default','/home');
Linux_getInterfacePercent('default','eth0','rx',1000);
Linux_getInterfacePercent('default','eth0','tx',1000);
sendEmailToGroup('gmail','sysadmins','ALERT WARNING ON HOST', 'HOST '+host.getName()+' has a WARNING alert');
The exact content that is being injected before the execution of any script, can be seen here.
More examples can be seen in the basic example configuration here.
For displaying messages in the program's console, the standard "print" function is available:
print('A MESSAGE THAT GOES TO THE CONSOLE');
Furthermore, a script can execute any JavaScript functions.