The pfSense Store

Author Topic: Temperature Alert Script  (Read 2165 times)

0 Members and 1 Guest are viewing this topic.

Offline JMac87

  • Newbie
  • *
  • Posts: 18
  • Karma: +2/-0
    • View Profile
Temperature Alert Script
« on: July 26, 2016, 01:47:14 pm »
I wrote a simple shell script to send an email alert when the average CPU temperature reaches a set threshold. It uses the php mail feature within PfSense since there is no "mail" command available.

I'm using our firewall as a sort of temperature monitor for our server room, which frequently has HVAC issues. Instead of buying some sort of temperature monitor, I figured I'd just use the average temperature of the CPU and send an alert when it hits a certain temperature that is known to exist when our HVAC system is off/broken.

I'm sure you guys could integrate this into the GUI for others to easily use, since pfSense has no such built-in function.

https://gist.github.com/JMac87/1303f78c56a54165447568318eeca3b3

Notes:
You must set up a notification email in System > Advanced > Notifications.

I had to edit /etc/inc/notices.inc to include:
Code: [Select]
require_once("functions.inc");
You can cron this script to run every X minutes or whatever interval you'd like to check.

Offline lpallard

  • Full Member
  • ***
  • Posts: 274
  • Karma: +3/-0
    • View Profile
Re: Temperature Alert Script
« Reply #1 on: August 14, 2016, 05:10:59 pm »
Im amazed that pfsense is still not capable of sending a email notification when system or CPU temp goes above a set value.  All the pieces are there, its just to connect them together.

  • Email notification is there
  • CPU temp measurement is there
  • System temp measurement is there

Whats the show stopper to integrate a GUI page to enter a treshold and set a checkbox to "Notify if above this value?"

What about smart temps for HDDs??

Freenas does this seamlessly AFAIK.  If I had any coding skills I'd attempt something on a VM but things as they are, I know nothing about coding.  ???

Hardware monitoring and notification (temps, RAM and HDD status) are definitely something I'd be interested into.

Offline guardian

  • Full Member
  • ***
  • Posts: 247
  • Karma: +8/-0
    • View Profile
Re: Temperature Alert Script
« Reply #2 on: August 16, 2016, 04:14:06 pm »
Agreed... seems like an easy add, and could save someone's hardware from frying if a fan died.

Offline jimp

  • Administrator
  • Hero Member
  • *****
  • Posts: 21378
  • Karma: +1431/-26
    • View Profile
Re: Temperature Alert Script
« Reply #3 on: August 23, 2016, 09:48:05 am »
The stopper is primarily that we don't have a periodic polling script for monitoring those conditions. They are only displayed in the GUI when the dashboard is loaded. It's not difficult to add, but it would also need a GUI to control its settings (e.g. alert thresholds). Also support for temp sensors varies from system to system and hardware quirks with temp sensors make them not 100% reliable, so it may be something we'd have to restrict to hardware we can assure it will work for (e.g. systems we sell).
Need help fast? Commercial Support!

Co-Author of pfSense: The Definitive Guide. - Check the Doc Wiki for FAQs.

Do not PM for help!

Offline dcol

  • Full Member
  • ***
  • Posts: 193
  • Karma: +7/-5
    • View Profile
Re: Temperature Alert Script
« Reply #4 on: October 02, 2017, 06:38:35 pm »
Worked like a charm.
Now I need a script for CPU usage so if the CPU is pinned by suricata, I will be notified. It has happened to me on many occasions.

Offline kpa

  • Hero Member
  • *****
  • Posts: 1186
  • Karma: +132/-6
    • View Profile
Re: Temperature Alert Script
« Reply #5 on: October 03, 2017, 08:21:38 am »
Jimp is right, this type of monitoring needs a lot of manual configuration because on many systems the readings are nonsensical unless adjusted properly using information from the manufacturer. For example some of the AMD CPUs give you negative values and you're supposed to know the reference temperature used to calculate the real temperature as reference+reported. On such systems the only out of the box reliable CPU temperature is the one show in BIOS setup.

Such reporting system would work out of the box only on a small number of systems where the calibration values are known.