sdMonkey - 2013-02-24

I'm lazy and didn't want to monitor the monitor... Obviously you can't set the server to send a message when it is down, so I did the next best thing (IMHO); the server sends an alert, 'x' times a day, to notify that it is still alive (has a pulse/sends a pulse).

Here are the edits I had to make. I tried to emulate the orig script...


SMUpdaterStatus.class.php @ line 195

            # make sure a pulse check is needed
            if( (sm_get_conf('pulse') == true) && ($this->server['label'] == 'Pulse') && (sm_check_pulse() == true) ) {
               // change status if criteria is met
               $notify = true;
            } @ line 235

 * Check if last 'pulse' check was recent
 * @global object $db
 * @return boolean
function sm_check_pulse() {
    global $db;
      # set the pulse vars
    $last_pulse = sm_get_conf('last_pulse');
      $check_pulse_around = sm_get_conf('check_pulse_around');
      $pulses = explode(",",$check_pulse_around);
      $currentHr = date('G');
      # for each of the pulses, check if notification
      for($i=0,($pCount=count($pulses)-1); $i<=$pCount; $i++){
         # if the current time is greater than the last captured pulse and 
         # time of day is equal to setting, allow notification 
         if( (time() > $last_pulse) && ($currentHr == $pulses[$i]) ){
            # as long as this is not the last pulse of the day, update pulse to next hour
               # create pulse time for the next hour
               $pulseStamp = mktime($currentHr+1, 0, 0, date('m'), date('d'), date('Y'));
               # update "last_pulse"
               $last_pulse = $pulseStamp;
               $db->save(SM_DB_PREFIX . 'config', array('value' => $pulseStamp), array('key' => 'last_pulse'));
            # if this is the last pulse, update the database with the new stamp
               # create pulse time for the next day
               $pulseStamp = mktime(0, 0, 0, date('m'), date('d')+1, date('Y'));
               # update "last_pulse"
               $db->save(SM_DB_PREFIX . 'config', array('value' => $pulseStamp), array('key' => 'last_pulse'));
            # send pulse notification
            return true;
      # if you went through the pulses and didn't qualify, don't send notification
    return false;

config.tpl.html @ line 99

<tr class="odd">
    <td><input type="checkbox" name="pulse[]" {pulse_checked} /></td>
<tr class="odd">
    <td><input type="text" name="check_pulse_around" value="{check_pulse_around}" maxlength="255" /></td>


added to populateFields function array

'pulse_checked' => ($config['pulse'] == '1') ? 'checked="checked"' : '',
'check_pulse_around' => $config['check_pulse_around'],

added to executeSave function array

'pulse' => (isset($_POST['pulse'])) ? '1' : '0',
'check_pulse_around' => $_POST['check_pulse_around'],

added to createHTMLLabels functions array

'label_pulse' => sm_get_lang('config', 'pulse'),
'label_check_pulse_around' => sm_get_lang('config', 'check_pulse_around'),

added to install.php

added to servers array

('', 80, 'Pulse', 'service', 'on', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'yes', 'yes', 'yes'), 

added to config array

(null, 'pulse', '0'),
(null, 'last_pulse', '0'),
(null, 'check_pulse_around', '6')

added to en.lang.php

added to config array

'pulse' => 'Send a daily \'pulse\' notification?',
'check_pulse_around' => 'Hour of day to check \'pulse\'<br/><div class="small">(Hrs = 0-23) ie. 6,12,18</div>',

added to de.lang.php

added to config array

'pulse' => 'Lassen täglichen  \'puls\' nachricht?',
'check_pulse_around' => 'Stunde des Tages zu &uuml;berpr&uuml;fen \'puls\'<br/><div class="small">(Hrs = 0-23) ie. 6,12,18</div>',

added to fr.lang.php

added to config array

'pulse' => 'Permettre &agrave; quotidien  \'pouls\' notification?',
'check_pulse_around' => 'Heure de la journ&eacute;e pour v&eacute;rifier \'pouls\'<br/><div class="small">(Hrs = 0-23) ie. 6,12,18</div>',

added to nl.lang.php

added to config array

'pulse' => 'Stuur een dagelijkse  \'pols\' melding?',
'check_pulse_around' => 'Uur van de dag te controleren \'pols\'<br/><div class="small">(Hrs = 0-23) ie. 6,12,18</div>',