-
-
Notifications
You must be signed in to change notification settings - Fork 60
Tutorial Developer SensorClientExecuterOutput
This tutorial describes how to write your own scripts that can be executed by the AlertR Sensor Client Executer and its exit code is processed by AlertR. This tutorial assumes you have set up the AlertR Sensor Client Executer according to the provided AlertR Sensor Client Executer Tutorial and only describes the necessary additions.
The following gives you a short example on how to configure the AlertR Sensor Client Executer with a script that provides an exit code that is processed by AlertR. The script is written in Python, but it can be any programming language you like. I just find Python most convenient to show what has to be done.
The corresponding sensor configuration for the AlertR Sensor Client Executer looks like the following:
[...]
<sensors>
<sensor>
<general
id="0"
description="Developer Sensor"
alertDelay="0"
triggerAlert="True"
triggerAlertNormal="True" />
<alertLevel>0</alertLevel>
<executer
execute="/usr/bin/python3"
timeout="5"
intervalToCheck="10"
parseOutput="False"
dataType="0">
<argument>/home/alertr/dev_script.py</argument>
</executer>
</sensor>
</sensors>
[...]
This sensor executes the Python interpreter with the script at /home/alertr/dev_script.py
as argument every 10 seconds. The output of the script is ignored and hence no type of data is set.
The following shows the script /home/alertr/dev_script.py
. This script does not have any purpose at all. It should just demonstrate how to output data that can be processed by AlertR.
#!/usr/bin/python3
import sys
import random
# This actually does nothing. It just creates a
# random number and triggers the sensor if
# it is greater than 10.
def main():
data = random.randint(0, 20)
if data > 10:
sys.exit(1)
else:
sys.exit(0)
if __name__ == '__main__':
main()
Done. This script sets the sensor to triggered
if the random number is greater than 10. Otherwise, it sets the sensor to normal
. Depending on the state the sensor already has, a sensor alert is triggered (if the state of the sensor is already triggered
and the number is greater than 10, nothing is changed).
If you want additional examples that have actually any purpose, please take a look into the scripts_example
folder in the AlertR Sensor Client Executer installation directory. Or see other tutorials that use the AlertR Sensor Client Executer like the Tutorial for integrating lm-sensors.
If you experience problems, please check the log file first. If it is not helpful, change the log level to DEBUG and check again. If no error can be seen, please start the AlertR client manually and check if an error occurs that is not printed into the log file. This can be done by just executing the AlertR client as the user that it normally runs with.
alertr@towel:~/sensorClientExecuter$ ./alertRclient.py
If you still have problems and do not know how to solve them, you can ask on the community page on reddit or you can use the Github Issues.