コード例 #1
0
 private function _handleCronSensorsPost($event)
 {
     $logger = DevblocksPlatform::getConsoleLog();
     $translate = DevblocksPlatform::getTranslationService();
     $sensors = DAO_Sensor::getAll();
     // Check that all external sensors aren't over their M.I.A. time
     if (is_array($sensors)) {
         foreach ($sensors as $sensor) {
             /* @var $sensor Model_Sensor */
             // Only external sensors
             if ('sensor.external' != $sensor->extension_id) {
                 continue;
             }
             // Skip if the sensor hasn't run once yet
             if (0 == $sensor->updated_date) {
                 continue;
             }
             $mia_secs = intval($sensor->params->mia_secs);
             $elapsed = time() - $sensor->updated_date;
             if ($mia_secs && $elapsed > $mia_secs) {
                 $fields = array(DAO_Sensor::STATUS => 2, DAO_Sensor::FAIL_COUNT => intval($sensor->fail_count) + 1, DAO_Sensor::METRIC => $translate->_('sensor.status.mia'), DAO_Sensor::OUTPUT => $translate->_('sensor.status.mia'));
                 DAO_Sensor::update($sensor->id, $fields);
                 $logger->info($sensor->name . " is M.I.A. for {$elapsed} seconds.");
             }
         }
     }
 }
コード例 #2
0
ファイル: cron.classes.php プロジェクト: jstanden/portsensor
 function run()
 {
     $logger = DevblocksPlatform::getConsoleLog();
     $logger->info("[Alerts] Starting...");
     $alerts = DAO_Alert::getAll();
     $check_sensors = DAO_Sensor::getAll();
     $workers = DAO_Worker::getAll();
     if (is_array($alerts)) {
         foreach ($alerts as $alert) {
             /* @var $alert Model_Alert */
             if (!isset($workers[$alert->worker_id])) {
                 continue;
             }
             $logger->info(sprintf("[Alerts] Checking '%s' for %s...", $alert->name, $workers[$alert->worker_id]->getName()));
             $hit_sensors = $alert->getMatches($check_sensors);
             if (is_array($hit_sensors)) {
                 $alert->run($hit_sensors);
             }
         }
     }
     $logger->info("[Alerts] Finished!");
 }