////////////////////////////////////// // This configuration file can be used asis only with ASUS P2B Mother board (which I have on my computer) // For other motherboard, you have to find the sensor names you want to monitor // you can do it using sentinelle -l // and change the following variables accordingly // ///////////////////////////////////// ///////////////////////////// // monitored sensors (FAN speed and CPU temperatures // // // the temperature of the MOtherBoard #define t_MOB = sensor("w83781d-isa-0290" "temp1"); // the temperature of the CPU #define t_CPU = sensor("w83781d-isa-0290" "temp2"); // the temperature of the CHAssis #define t_CHA = sensor("w83781d-isa-0290" "temp3"); // the fan speed of the CHASsis fan #define f_CHA = sensor("w83781d-isa-0290" "fan1"); // the fan speed of the CPU fan #define f_CPU = sensor("w83781d-isa-0290" "fan2"); // the fan speed of the POWer block fan #define f_POW = sensor("w83781d-isa-0290" "fan3"); ////////////////////////////// // we have two states : normal and alert // NORMAL state is when all FAN turn over the minimum speed // ALERT state is when at least one fan seems broken // in each state if the temperature exceed a given limit the // computer is lead to shutdown. // follows the parameters you can tune to your need : // // // the minimum speed under which the FAN is considered not working properly #const FCHA_MIN = -1; #const FCPU_MIN = 3000; #const FPOW_MIN = -1; // inactive the monitoring of this fan (mine is broken) // // temperature over which the computer is shutdown in normal state #const CPU_TEMP_NORMAL = 55; #const MOB_TEMP_NORMAL = 50; #const CHA_TEMP_NORMAL = 45; // // temperature over which the computer is shutdown in alert state #const CPU_TEMP_ALERTE = 50; #const MOB_TEMP_ALERTE = 45; #const CHA_TEMP_ALERTE = 40; ///////////// // when in alerte state, we are not going back as soon as the fan speed get higher the // minimum, but after a certain time of good condition this delay can be tuned here // this is a number of second // #const DELTA_TIME_RESUME = 3600; /////////////////////// // Just to use the possibility to change some sensors, this is not really useful here. // for fan speed, there is a scale sensor that may be useful to change the way the speed // is count. This is what we do for CHASSIS and POWER fans // #define fan1_div = sensor("w83781d-isa-0290" "fan1_div"); #define fan3_div = sensor("w83781d-isa-0290" "fan3_div"); // // here is the action that change theses variables #action debut = { set fan1_div = 6; /* set fan3_div = 6; */ }; // // we have to do it once on sentinelled startup : //#init { debut; }; // NOTE : if you don't need or find any similar value, it is safe to comment this whole block ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// ////// NOTHING SHOULD BE CHANGE UNDER THIS UNLESS YOU KNOW WHAT YOU DO ////////// ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// #const NORMAL = 1; #const ALERTE = 2; #const RECOVERY = 3; // when condition are good but an alert condition occured recently #define automate = state(NORMAL); ///////////////////////////// // we need some variable to monitor the last values of all sensors // to be able to report minimum and maximum values // // the m1_t_* variables are the values retrieved the last cycle // the m2_t_* variables are the values retrieved two cycles back // the get initialized with the actual values #define m1_t_CPU = state(t_CPU); #define m2_t_CPU = state(t_CPU); #define m1_t_MOB = state(t_MOB); #define m2_t_MOB = state(t_MOB); #define m1_t_CHA = state(t_CHA); #define m2_t_CHA = state(t_CHA); ////////////////////// // theses variables contain the current min and max values of each sensors // #define min_CPU = state(t_CPU+1); #define max_CPU = state(t_CPU-1); #define min_MOB = state(t_MOB+1); #define max_MOB = state(t_MOB-1); #define min_CHA = state(t_CHA+1); #define max_CHA = state(t_CHA-1); //////////// // this action updates the m1_t_* and m2_t_* variables (shift one cycle) // #action mise_a_jour = { set m2_t_CPU = m1_t_CPU; set m1_t_CPU = t_CPU; set m2_t_MOB = m1_t_MOB; set m1_t_MOB = t_MOB; set m2_t_CHA = m1_t_CHA; set m1_t_CHA = t_CHA; }; ////////// // action executed when a new min or max has been reached // #action report_CPU_max = syslog local1 notice "CPU temp is at maximum = $m1_t_CPU"; #action report_MOB_max = syslog local1 notice "MotherBoard temp is at maximum = $m1_t_MOB"; #action report_CHA_max = syslog local1 notice "Chassis temp is at maximum = $m1_t_CHA"; #action report_CPU_min = syslog local1 notice "CPU temp is at minimum = $m1_t_CPU"; #action report_MOB_min = syslog local1 notice "MotherBoard temp is at minimum = $m1_t_MOB"; #action report_CHA_min = syslog local1 notice "Chassis temp is at minimum = $m1_t_CHA"; ////////// // the following action check if the curent temperatures are min or max // in NORMAL state, only extrema that overcome the actual extrema value are reported // in ALERT state, any change in the max or min value is reported even if it is not an extremum // because we will not wait that the extremum is reach to report that you CPU is burning ! ;-) // NOTE : // - an maximum occured when the last cycle (m1_t_*) value is greater than the current // value and the two cycle back value // - a minumum occured when the last cycle (m1_t_*) value is lower than the current value // and the two cycle back (m2_t_*) value #action test_CPU = { if(m1_t_CPU >= m2_t_CPU && m1_t_CPU > t_CPU || automate == ALERTE) if(m1_t_CPU > max_CPU) { set max_CPU = m1_t_CPU; report_CPU_max; }; if(m1_t_CPU <= m2_t_CPU && m1_t_CPU < t_CPU || automate == ALERTE) if(m1_t_CPU < min_CPU) { set min_CPU = m1_t_CPU; report_CPU_min; }; }; #action test_MOB = { if(m1_t_MOB >= m2_t_MOB && m1_t_MOB > t_MOB || automate == ALERTE) if(m1_t_MOB > max_MOB) { set max_MOB = m1_t_MOB; report_MOB_max; }; if(m1_t_MOB <= m2_t_MOB && m1_t_MOB < t_MOB || automate == ALERTE) if(m1_t_MOB < min_MOB) { set min_MOB = m1_t_MOB; report_MOB_min; }; }; #action test_CHA = { if(m1_t_CHA >= m2_t_CHA && m1_t_CHA > t_CHA || automate == ALERTE) if(m1_t_CHA > max_CHA) { set max_CHA = m1_t_CHA; report_CHA_max; }; if(m1_t_CHA <= m2_t_CHA && m1_t_CHA < t_CHA || automate == ALERTE) if(m1_t_CHA < min_CHA) { set min_CHA = m1_t_CHA; report_CHA_min; }; }; //////////////////////////////////////////////////////////////// /////////// Main core of the monitoring part /////////////////// //////////////////////////////////////////////////////////////// #action start_log = syslog local1 notice "variables have been reset"; #init { start_log; }; #loop { test_CPU; test_MOB; test_CHA; mise_a_jour; }; //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// // This part concerns the AUTOMATE - which defines two states : NORMAL & ALERT // // //////////////// // constants need to define what state we are in (for shutdown) // #const YES = 3; #const NO = 4; // // to know if a shutdown has been issued if it is necessary to cancel it when // normal condition are back #define shutdown = state(NO); // time of the last alert condition #define time = system(VAR_SYSTEM_TIME); #define last_event = state(time-2*DELTA_TIME_RESUME); ///////////////////////////////// // action to swap to ALERT state // // #action go_alerte = if(automate != ALERTE) { if(automate != RECOVERY) { // alert all logged user shell "echo 'ALERT condition, a FAN has some problem, if temperature gets too high, a shutdown will be issued !' | /usr/bin/wall"; // alert administrator by email shell "(echo 'sentinelled alert on ' $HOSTNAME ' :' ; echo 'fan_CPU = $f_CPU; fan_CHA = $f_CHA; fan_POW = $f_POW' ; echo 'temp_CPU = $t_CPU; temp_CHA = $t_CHA; temp_MOB = $t_MOB') | /bin/mail -s 'sentinelled ALERTE on '$HOSTNAME root" ; }; // log event using syslog syslog local1 warning "sensor ALERTE condition"; // change the state set automate = ALERTE; }; /////////////////////////////////// // action to swap back to NORMAL state // // #action go_normal = if(automate != NORMAL) { // change state set automate = NORMAL; // inform logged users shell "echo 'we are back in NORMAL condition for fan and temperature sensors' | /usr/bin/wall"; // log condition using syslog syslog local1 warning "sensor NORMAL condition"; }; /////////////////////////////////// // action to swap back to RECOVERY state // // #action go_recovery = if(automate != RECOVERY) { // change state set automate = RECOVERY; // log condition using syslog syslog local1 warning "sensor RECOVERY condition"; }; ////////////////////////////////////// // action to stop a running shutdown // // #action stop_shutdown = if(shutdown == YES) { // cancel a running shutdown shell "/usr/bin/sudo /sbin/shutdown -c"; shell "echo 'temperature or fan speed is better, the shutdown has been canceled' | /usr/bin/wall"; syslog local1 warning "shutdown has been canceled"; set shutdown = NO; }; /////////////////////////// // action that will determin the state to stay or go to // based on the fan speed and date of the last alert event // // #action fan_check = if(f_CPU < FCPU_MIN || f_CHA < FCHA_MIN || f_POW < FPOW_MIN) { // this is an alert condition // record the date of this event set last_event = time; // call the action to go to ALERT mode go_alerte; } else { stop_shutdown; if(time > DELTA_TIME_RESUME+last_event) go_normal // OK we go back (or stay) in normal mode else go_recovery; }; ////////////////// // what to do when a temperature has reached the limit // in ALERT or in NORMAL state // #action stop_alerte = if(shutdown == NO) { set shutdown = YES; // if sentinelled is run as root, you can avoid using 'sudo' syslog local1 warning "shutting down the computer in one minute"; shell "/usr/bin/sudo /sbin/shutdown -h +1 'TEMPERATURE TOO HIGH , BROKEN FAN'&"; }; #action stop_normal = if(shutdown == NO) { set shutdown = YES; syslog local1 warning "shutting down the computer in one minute"; shell "/usr/bin/sudo /sbin/shutdown -h +1 'TEMPERATURE TOO HIGH, BUT FAN OK'&"; set last_event = time; }; //////////////////////// // action that check if the temperature is not too high // one for each state (temperature limit are not the same in ALERT and NORMAL state) // #action mate_normal = if(t_CPU > CPU_TEMP_NORMAL || t_MOB > MOB_TEMP_NORMAL || t_CHA > MOB_TEMP_NORMAL) stop_normal else stop_shutdown; #action mate_alerte = if(t_CPU > CPU_TEMP_ALERTE || t_MOB > MOB_TEMP_ALERTE || t_CHA > MOB_TEMP_ALERTE) stop_alerte; //////////////////////////////////////////////////////////////// /////////// Main core of the automate part ///////////////////// //////////////////////////////////////////////////////////////// #action automate = { fan_check ; if(automate != ALERTE) mate_normal else mate_alerte; }; #loop { automate; }; //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// //////////////////////////////////////// // some extra feature, concerning monitoring: // this resets the min and max once a day // if you want to use it, remove or comment the /* and */ // // /* // <--- remove or comment this line to use this feature #define day = system(VAR_SYSTEM_DAY); #define last_day = state(day); #define tmp_day = state(day); #action do_reset = { set max_CPU = t_CPU-1; set min_CPU = t_CPU+1; set max_CHA = t_CHA-1; set min_CHA = t_CHA+1; set max_MOB = t_MOB-1; set min_MOB = t_MOB+1; syslog local1 notice "--- min & max temperature have been reset ---"; set last_day = tmp_day; }; #action reset_min_max = { set tmp_day = day; if(tmp_day != last_day) do_reset; }; #loop { reset_min_max; } ; #init { do_reset; }; */ // <--- remove or comment this line to use this feature