MikroTik Scripts: Device overheating notification

Notification when the device temperature rises above the threshold. Sends notification to email or Telegram message.

The script sends the temperature of the MikroTik device and the CPU load. If the temperature of the device has exceeded the threshold value, and the processor load of the device is minimal, there may be a problem in the external environment (for example, the failure of an air conditioner in a server room).

Sample email about MikroTik device overheating. Get device temperature and CPU load
Sample email about MikroTik device overheating

Functions used:

MikroTik script is suitable for devices equipped with a temperature sensor. Tested on Mikrotik RB3011UiAS-RM, RouterOS 6.46.4 (stable).

The safe value of the CPU temperature will be different for each model of MikroTik devices, set the value of the script trigger temperature (MaxCPUTemp) depending on the model of your device (see the specification).

Article in other languages:
?? – MikroTik Scripts: Notificación de sobrecalentamiento del dispositivo
?? – MikroTik Скрипты: Уведомление о перегреве устройства
?? – Scripts MikroTik: Notification de surchauffe de l’appareil
?? – MikroTik-Scripts: Benachrichtigung über Überhitzung des Geräts
?? – MikroTik-scripts: Melding over oververhitting van het apparaat

Create script

The MaxCPUTemp parameter is the device temperature threshold after which a notification will be sent.

For the script to work, checking the device temperature requires permissions: read, write, test, policy.

[System] -> [Scripts] -> [+] -> [Name: DeviceOverheatingScript] -> [Policy: read, write, test, policy]

Script code:

# Name: DeviceOverheatingNotification v1
# Description: Notification when the device temperature rises above the threshold. Sends notification to email or Telegram message.
# Author: Yun Sergey, MHelp.pro 2020
# License: GPL-3.0 License
# Description, purpose and questions: https://mhelp.pro/mikrotik-scripts-device-overheating-notification/
# More scripts Mikrotik: https://mhelp.pro/tag/mikrotik-scripts/
# Verified: RouterBOARD 3011UiAS, RouterOS 6.47.8 (stable)

:local MaxCPUTemp 65;
:local CurrentTemp [/system health get temperature];
:local CurrentCPULoad [/system resource get cpu-load];
:local DeviceName [/system identity get name ];
:local Time [/system clock get time];
:local Date [/system clock get date];

#:log info "Script DeviceOverheatingNotification - start.";

:if ($CurrentTemp > $MaxCPUTemp) do={

    #:log info "Script DeviceOverheatingNotification - Temperature threshold exceeded! Send Telegram message.";

    # START Send Telegram Message
    :local MessageText "\F0\9F\94\B4 <b>CRITICAL: $DeviceName Device Overheating!</b> %0D%0A Device Temperature: $CurrentTemp %C2%B0 C  %0D%0A CPU Load: $CurrentCPULoad %";
    :local SendTelegramMessage [:parse [/system script  get MyTGBotSendMessage source]];
    $SendTelegramMessage MessageText=$MessageText;
    # END Send Telegram Message

    #:log info "Script DeviceOverheatingNotification - Temperature threshold exceeded! Send Email.";

    # START Send Email
    :local SendTo "notify@mhelp.pro";
    :local Subject "\F0\9F\94\B4 CRITICAL: $DeviceName [$Date $Time]";
    :local MessageText "Device Temperature: $CurrentTemp °C, CPU Load: $CurrentCPULoad %";
    :local FileName "";
    :local SendEmail [:parse [/system script get SendEmailFunction source]];
    $SendEmail SendTo=$SendTo TextMail=$MessageText Subject=$Subject FileName=$FileName;
    # END Send Email
}

#:log info "Script DeviceOverheatingNotification - end.";
MikroTik script device overheating notification

Add script to Scheduler

To run the script to check the temperature of the MikroTik device, permissions are required: read, write, test, policy.

[System] -> [Schedule] -> [+] -> [Name:CheckDeviceOverheating] —>  [Interval: 00:01:00] -> [Policy: read, write, policy, test]

Or enter in a terminal:

/system scheduler add name=CheckDeviceOverheating policy=read,write,policy,test on-event="/system script run DeviceOverheatingScript" interval=1m comment="Checking device overheating"
Add script to check device overheating to the schedule

Now you can increase control over your device by monitoring an important parameter – device temperature!


? How to create a script to check the overheating of a MikroTik device and send a notification to an email or Telegram message has been discussed in this article. I hope now you can get notification about MikroTik device overheating and CPU load on time. However, if you run into any problems while configuring the script, feel free to write in the comments. I will try to help.

11 thoughts on “MikroTik Scripts: Device overheating notification”

    • My hardware Model: Metal G-52SHPacn.

      : local CurrentTemp [ /system health get [ find name=temperature ] value ]; # By example : 31
      : log warning “$CurrentTemp °C “; # ==> 31 °C

      Same structure the Voltage
      : local CurrentVoltage [ /system health get [ find name=voltage ] value ]; # By example : 23.8
      : log warning “$CurrentVoltage VDC “; # ==> 23.8 VDC

      Greetings

      Bernard

      Reply
  1. Replace the original line :
    :local CurrentTemp [/system health get temperature];
    by the following hereafter:
    : local CurrentTemp [ /system health get [find name=temperature] value ];

    BERNARD

    Reply
  2. Próbowałem :local CurrentTemp [/system health get [find where name=”cpu-temperature”] value=value]; ale nie działa :/

    Reply
  3. Welcome back
    You could do a script update ?

    System temperature [/system health get temperature]
    Cpu temperature [/system health get cpu-temperature]

    In my case, the processor temperature is given.
    Can I count on help and script improvement?
    Best regards, Tomek from Poland

    Reply
  4. Hello

    This scrypt doesn’t work for me.
    My device is RB5009 with ver 7.1.1
    I corrected one parameter:: local CurrentTemp [/ system health get temperature]; na: local CurrentTemp [/ system health get cpu-temperature];

    but unfortunately it still doesn’t work. The ParseLogLoginFailure and ParseLogAccountEvents scripts work fine.

    Reply

Leave a Comment