コード例 #1
0
 public function __construct()
 {
     $systems_already_reported = array();
     pts_client::fork(array('pts_phoromatic_event_server', 'ob_cache_run'), null);
     $is_first_run = true;
     while (true) {
         $hour = date('G');
         $minute = date('i');
         phoromatic_server::prepare_database();
         if ($is_first_run || $minute == 0) {
             if ($is_first_run || $hour == 8) {
                 pts_client::fork(array('pts_phoromatic_event_server', 'ob_cache_run'), null);
             }
             // Check for basic hung systems
             $stmt = phoromatic_server::$db->prepare('SELECT LastCommunication, CurrentTask, EstimatedTimeForTask, SystemID, AccountID, LastIP FROM phoromatic_systems WHERE State > 0 ORDER BY LastCommunication DESC');
             $result = $stmt ? $stmt->execute() : false;
             while ($result && ($row = $result->fetchArray())) {
                 $last_comm = strtotime($row['LastCommunication']);
                 if ($last_comm > time() - 3600) {
                     continue;
                 }
                 // if last comm time is less than an hour, still might be busy testing
                 if ($last_comm < time() - 3600 * 3 && !$is_first_run) {
                     continue;
                 }
                 // it's already been reported enough for now...
                 if (stripos($row['CurrentTask'], 'shutdown') !== false || stripos($row['CurrentTask'], 'shutting down') !== false) {
                     continue;
                 }
                 // if the system shutdown, no reason to report it
                 if (phoromatic_server::estimated_time_remaining_diff($row['EstimatedTimeForTask'], $row['LastCommunication']) > 0) {
                     continue;
                 }
                 // system task time didn't run out yet
                 // UPDATE SYSTEM STATUS TO "UNKNOWN"
                 $stmt_unknown = phoromatic_server::$db->prepare('UPDATE phoromatic_systems SET CurrentTask = :unknown_state WHERE AccountID = :account_id AND SystemID = :system_id');
                 $stmt_unknown->bindValue(':account_id', $row['AccountID']);
                 $stmt_unknown->bindValue(':system_id', $row['SystemID']);
                 $stmt_unknown->bindValue(':unknown_state', 'Unknown');
                 $stmt_unknown->execute();
                 $stmt_email = phoromatic_server::$db->prepare('SELECT UserName, Email FROM phoromatic_users WHERE UserID IN (SELECT UserID FROM phoromatic_user_settings WHERE AccountID = :account_id AND NotifyOnHungSystems = 1) AND AccountID = :account_id');
                 $stmt_email->bindValue(':account_id', $row['AccountID']);
                 $result_email = $stmt_email->execute();
                 while ($row_email = $result_email->fetchArray()) {
                     if (empty($row_email['Email'])) {
                         continue;
                     }
                     phoromatic_server::send_email($row_email['Email'], 'Phoromatic System Potential Hang: ' . phoromatic_server::system_id_to_name($row['SystemID'], $row['AccountID']), phoromatic_server::account_id_to_group_admin_email($row['AccountID']), '<p><strong>' . $row_email['UserName'] . ':</strong></p><p>One of the systems associated with your Phoromatic account has not been communicating with the Phoromatic Server in more than sixty minutes. Below is the system information details:</p><p><strong>System:</strong> ' . phoromatic_server::system_id_to_name($row['SystemID'], $row['AccountID']) . '<br /><strong>Last Communication:</strong> ' . phoromatic_server::user_friendly_timedate($row['LastCommunication']) . '<br /><strong>Last Task:</strong> ' . $row['CurrentTask'] . '<br /><strong>Local IP:</strong> ' . $row['LastIP'] . '</p>');
                 }
             }
         }
         if ($is_first_run || $minute % 2 == 0) {
             // Check for systems to wake
             $stmt = phoromatic_server::$db->prepare('SELECT LastCommunication, CurrentTask, SystemID, AccountID, NetworkMAC, LastIP, MaintenanceMode FROM phoromatic_systems WHERE State > 0 AND NetworkMAC NOT LIKE \'\' AND NetworkWakeOnLAN LIKE \'%g%\' ORDER BY LastCommunication DESC');
             $result = $stmt ? $stmt->execute() : false;
             while ($result && ($row = $result->fetchArray())) {
                 if (!isset($phoromatic_account_settings[$row['AccountID']])) {
                     $stmt1 = phoromatic_server::$db->prepare('SELECT NetworkPowerUpWhenNeeded, PowerOnSystemDaily FROM phoromatic_account_settings WHERE AccountID = :account_id');
                     $stmt1->bindValue(':account_id', $row['AccountID']);
                     $result1 = $stmt1->execute();
                     $phoromatic_account_settings[$row['AccountID']] = $result1->fetchArray(SQLITE3_ASSOC);
                 }
                 $last_comm = strtotime($row['LastCommunication']);
                 if ($last_comm < time() - 360 && $row['MaintenanceMode'] == 1) {
                     self::send_wol_wakeup($row['NetworkMAC'], $row['LastIP']);
                     continue;
                 }
                 if ($minute % 20 == 0 && $last_comm < time() - 3600 * 18 && $phoromatic_account_settings[$row['AccountID']]['PowerOnSystemDaily'] == 1) {
                     // Daily power on test if system hasn't communicated / powered on in a day
                     // XXX right now the "daily" power on test is 18 hours. change or make user value in future?
                     // Just doing this check every 20 minutes as not too vital
                     self::send_wol_wakeup($row['NetworkMAC'], $row['LastIP']);
                     continue;
                 }
                 if ($last_comm < time() - 600 || stripos($row['CurrentTask'], 'Shutdown') !== false) {
                     // System hasn't communicated in a number of minutes so it might be powered off
                     if (phoromatic_server::system_has_outstanding_jobs($row['AccountID'], $row['SystemID']) !== false) {
                         // Make sure account has network WoL enabled
                         if ($phoromatic_account_settings[$row['AccountID']]['NetworkPowerUpWhenNeeded'] == 1) {
                             self::send_wol_wakeup($row['NetworkMAC'], $row['LastIP']);
                         }
                     }
                 }
             }
         }
         if ($minute % 8 == 0 && $hour > 1) {
             // See if system appears down
             $stmt = phoromatic_server::$db->prepare('SELECT LastCommunication, CurrentTask, SystemID, AccountID, LastIP FROM phoromatic_systems WHERE State > 0 ORDER BY LastCommunication DESC');
             $result = $stmt ? $stmt->execute() : false;
             while ($result && ($row = $result->fetchArray())) {
                 $sys_hash = sha1($row['AccountID'] . $row['SystemID']);
                 // Avoid sending duplicate messages over time
                 if (isset($systems_already_reported[$sys_hash]) && $systems_already_reported[$sys_hash] > time() - 3600 * 24) {
                     continue;
                 }
                 if (phoromatic_server::system_check_if_down($row['AccountID'], $row['SystemID'], $row['LastCommunication'], $row['CurrentTask'])) {
                     if (strtotime($row['LastCommunication']) < time() - 86400 * 7) {
                         // If system hasn't been online in a week, likely has bigger worries...
                         continue;
                     }
                     $stmt_email = phoromatic_server::$db->prepare('SELECT UserName, Email FROM phoromatic_users WHERE UserID IN (SELECT UserID FROM phoromatic_user_settings WHERE AccountID = :account_id AND NotifyOnHungSystems = 1) AND AccountID = :account_id');
                     $stmt_email->bindValue(':account_id', $row['AccountID']);
                     $result_email = $stmt_email->execute();
                     while ($row_email = $result_email->fetchArray()) {
                         if (empty($row_email['Email'])) {
                             continue;
                         }
                         phoromatic_server::send_email($row_email['Email'], 'Phoromatic System Potential Problem: ' . phoromatic_server::system_id_to_name($row['SystemID'], $row['AccountID']), phoromatic_server::account_id_to_group_admin_email($row['AccountID']), '<p><strong>' . $row_email['UserName'] . ':</strong></p><p>One of the systems associated with your Phoromatic account has not been communicating with the Phoromatic Server and is part of a current active test schedule. Below is the system information details:</p><p><strong>System:</strong> ' . phoromatic_server::system_id_to_name($row['SystemID'], $row['AccountID']) . '<br /><strong>Last Communication:</strong> ' . phoromatic_server::user_friendly_timedate($row['LastCommunication']) . '<br /><strong>Last Task:</strong> ' . $row['CurrentTask'] . '<br /><strong>Local IP:</strong> ' . $row['LastIP'] . '</p>');
                     }
                     $systems_already_reported[$sys_hash] = time();
                 }
             }
         }
         phoromatic_server::close_database();
         sleep(60 - date('s') + 1);
         $is_first_run = false;
     }
 }
コード例 #2
0
$environmental_variables = array('aid' => 'ACCOUNT_ID', 'sid' => 'SYSTEM_ID', 'bid' => 'BENCHMARK_TICKET_ID', 'gsid' => 'GSID', 'a' => 'ACTIVITY', 'r' => 'REQUEST', 'pts' => 'CLIENT_VERSION', 'pts_core' => 'CLIENT_CORE_VERSION', 'h' => 'CLIENT_HARDWARE', 's' => 'CLIENT_SOFTWARE', 'i' => 'ID', 'o' => 'OTHER', 'nm' => 'NETWORK_CLIENT_MAC', 'nw' => 'NETWORK_CLIENT_WOL', 'n' => 'HOSTNAME', 'ti' => 'TEST_IDENTIFIER', 'ts' => 'TRIGGER_STRING', 'time' => 'ESTIMATED_TIME', 'pc' => 'PERCENT_COMPLETE', 'c' => 'COMPOSITE_XML', 'ob' => 'OPENBENCHMARKING_ID', 'sched' => 'SCHEDULE_ID', 'lip' => 'LOCAL_IP', 'j' => 'JSON', 'composite_xml' => 'COMPOSITE_XML', 'composite_xml_gz' => 'COMPOSITE_XML_GZ', 'composite_xml_hash' => 'COMPOSITE_XML_HASH', 'system_logs_zip' => 'SYSTEM_LOGS_ZIP', 'system_logs_hash' => 'SYSTEM_LOGS_HASH', 'msi' => 'PTS_MACHINE_SELF_ID', 'err' => 'ERROR_MSG', 'et' => 'ELAPSED_TIME');
foreach ($environmental_variables as $get_var => $to_var) {
    if (isset($_REQUEST[$get_var]) && !empty($_REQUEST[$get_var])) {
        ${$to_var} = $_REQUEST[$get_var];
    } else {
        ${$to_var} = null;
    }
}
if ($CLIENT_CORE_VERSION < 5312) {
    // Due to major PTS 5.4 development changes, client version bump will be necessary
    $json['phoromatic']['error'] = 'You must update your Phoronix Test Suite clients for compatibility with this Phoromatic server.';
    echo json_encode($json);
    exit;
}
// DATABASE SETUP
phoromatic_server::prepare_database();
if ($ACCOUNT_ID == null && $PTS_MACHINE_SELF_ID != null) {
    // Try to find the account
    $stmt = phoromatic_server::$db->prepare('SELECT AccountID FROM phoromatic_systems WHERE MachineSelfID = :machine_self_id');
    $stmt->bindValue(':machine_self_id', $PTS_MACHINE_SELF_ID);
    $result = $stmt->execute();
    if (!empty($result)) {
        $result = $result->fetchArray();
        if ($result['AccountID'] != null) {
            $json['phoromatic']['account_id'] = $result['AccountID'];
            echo json_encode($json);
            exit;
        }
    }
    // Try to find the account if there is an IP/MAC claim
    if (!empty($_SERVER['REMOTE_ADDR']) && !empty($NETWORK_CLIENT_MAC)) {
コード例 #3
0
 public static function generate_export_result_schedule_dump($r)
 {
     phoromatic_server::prepare_database();
     if (isset($r[0]) && !empty($r[0])) {
         phoromatic_server::generate_result_export_dump($r[0]);
     }
 }