Skip to content

Tutorial SensorClientExecuter lm sensors

sqall01 edited this page Jun 4, 2022 · 11 revisions

Tutorial - AlertR Sensor Client Executer - lm-sensors

This tutorial describes how to integrate sensors that can be read by the Linux tool "lm-sensors" into your AlertR system. 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.

Table of Contents

Description

The following gives you a short example on how to configure the AlertR Sensor Client Executer with the lm-sensors.py script. However, the lm-sensors.py offers more options than explained here (like triggering a sensor alert when a threshold is reached). Please use the "--help" argument to see the full list of options.

Installation

The lm-sensors.py script allows you to read sensor data like CPU temperature on Linux with the help of "lm-sensors". For the script to work correctly, lm-sensors has to be installed and configured. On Debian/Ubuntu you can install it with the following commands:

root@towel:/home/sqall# apt-get install lm-sensors

After that, lm-sensors has to be configured by executing the command "sensors-detect". For a complete configuration guide please see other tutorials like this one.

Setup

The lm-sensors.py script is located in the "scripts_example/lm-sensors/" directory of your installation. To see all available sensors we use the following command:

sqall@towel:~/sensorClientExecuter/scripts_example/lm-sensors$ python3 lm-sensors.py -p

Device: acpitz-virtual-0
Adapter: Virtual device
Sensors:
    Sensor: temp1
        temp1_crit - 128.0
        temp1_input - 43.0

-----------------------

Device: coretemp-isa-0000
Adapter: ISA adapter
Sensors:
    Sensor: Core 3
        temp5_crit - 100.0
        temp5_input - 50.0
        temp5_crit_alarm - 0.0
        temp5_max - 100.0
    Sensor: Core 2
        temp4_input - 42.0
        temp4_max - 100.0
        temp4_crit - 100.0
        temp4_crit_alarm - 0.0
    Sensor: Core 0
        temp2_crit - 100.0
        temp2_max - 100.0
        temp2_input - 43.0
        temp2_crit_alarm - 0.0
    Sensor: Physical id 0
        temp1_crit_alarm - 0.0
        temp1_max - 100.0
        temp1_crit - 100.0
        temp1_input - 49.0
    Sensor: Core 1
        temp3_crit_alarm - 0.0
        temp3_max - 100.0
        temp3_crit - 100.0
        temp3_input - 45.0

-----------------------

Device: thinkpad-isa-0000
Adapter: ISA adapter
Sensors:
    Sensor: fan1
        fan1_input - 2262.0

-----------------------

In this example we want the temperature of the whole CPU. In order to get it, we need the device (-d option) "coretemp-isa-0000", the actual sensor (-s option) "Physical id 0" and the key (-k option) "temp1_input".

To see if everything works correctly, we can manually execute the command with the given options:

sqall@towel:~/sensorClientExecuter/scripts_example/lm-sensors$ python3 lm-sensors.py -d coretemp-isa-0000 -s "Physical id 0" -k temp1_input

{"message": "statechange", "payload": {"dataType": 2, "state": 0, "data": {"value": 48.0, "unit": "°C"}}}

Note the whitespaces in the sensor name "Physical id 0". Because of them, we have to put quotes around the argument in the command line.

Configuration

The corresponding sensor configuration for the AlertR Sensor Client Executer looks like the following:

[...]

<sensors>

    <sensor>

        <general
            id="0"
            description="lm-sensors CPU"
            alertDelay="0"
            triggerAlert="True"
            triggerAlertNormal="True" />

        <alertLevel>0</alertLevel>

        <executer
            execute="/usr/bin/python3"
            timeout="5"
            intervalToCheck="10"
            parseOutput="True"
            dataType="2">

            <argument>/home/sqall/sensorClientExecuter/scripts_example/lm-sensors/lm-sensors.py</argument>
            <argument>-d</argument>
            <argument>coretemp-isa-0000</argument>
            <argument>-s</argument>
            <argument>Physical id 0</argument>
            <argument>-k</argument>
            <argument>temp1_input</argument>

        </executer>

    </sensor>

</sensors>

[...]

Note the missing quotes for the sensor name "Physical id 0". Arguments given in the configuration file do not need quotes if they have whitespaces or other special characters.

This sensor configuration is set to parse the output given by the command. The data given back by the lm-sensors.py script is always of type float. Therefore, we set the dataType to 2 (2 = float). As command we execute the interpreter /usr/bin/python3 with the lm-sensors.py script and its parameter as arguments.

Troubleshooting

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.

Clone this wiki locally