public static function update($report_)
 {
     Logger::debug('main', "Abstract_ReportSession::update");
     $SQL = SQL::getInstance();
     $report = Abstract_ReportSession::load($report_->getID());
     if (!is_object($report)) {
         Logger::debug('main', "Abstract_ReportSession::updateSession failed to load report " . $report_->getID());
         return false;
     }
     $ret = $SQL->DoQuery('UPDATE @1 SET @2=%3,@4=%5,@6=%7 WHERE @8 = %9 LIMIT 1', $SQL->prefix . 'sessions_history', 'stop_why', $report_->stop_why, 'user', $report_->user, 'server', $report_->server, 'id', $report_->getID());
     return $ret;
 }
Ejemplo n.º 2
0
 public function run()
 {
     switch ($this->ev->status) {
         /* session created */
         case Session::SESSION_STATUS_CREATED:
             $token = $this->ev->id;
             if (!Abstract_ReportSession::exists($token)) {
                 if (!Abstract_Session::exists($token)) {
                     Logger::error('main', "SessionStatusChangedReport::run failed session '{$token}' does not exist");
                     return false;
                 }
                 $session = Abstract_Session::load($token);
                 $sessitem = new SessionReportItem($session->id, $session->user_login, $session->server, $session->start_time);
                 $ret = Abstract_ReportSession::create($sessitem);
                 if (!$ret) {
                     Logger::error('main', "SessionStatusChangedReport::run failed to save SessionReportItem({$token})");
                     return false;
                 }
             }
             return true;
             break;
             /* session ended */
         /* session ended */
         case Session::SESSION_STATUS_WAIT_DESTROY:
         case Session::SESSION_STATUS_DESTROYED:
             $token = $this->ev->id;
             if (!Abstract_Session::exists($token)) {
                 Logger::error('main', "SessionStatusChangedReport::run failed session '{$token}' does not exist");
                 return false;
             }
             $session = Abstract_Session::load($token);
             $sessitem = Abstract_ReportSession::load($token);
             if (!is_object($sessitem)) {
                 Logger::error('main', "SessionStatusChangedReport::run failed to load SessionReportItem({$token})");
                 return false;
             }
             $sessitem->end($session);
             Abstract_ReportSession::update_on_session_end($sessitem);
             return true;
             break;
         default:
             return true;
             break;
     }
 }
 public static function update_on_session_end($report_)
 {
     Logger::debug('main', "Abstract_ReportSession::update_on_session_end");
     $sql = SQL::getInstance();
     $report = Abstract_ReportSession::load($report_->getID());
     if (!is_object($report)) {
         Logger::debug('main', "Abstract_ReportSession::update_on_session_end failed to load report " . $report_->getID());
         return false;
     }
     $ret = $sql->DoQuery('UPDATE #1 SET @2=NOW(), @3=%4 WHERE @5=%6 LIMIT 1', self::table, 'stop_stamp', 'data', $report_->getData(), 'id', $report_->getID());
     return $ret;
 }
Ejemplo n.º 4
0
 public function orderDeletion($request_servers_ = true, $reason_ = NULL)
 {
     Logger::debug('main', 'Starting Session::orderDeletion for \'' . $this->id . '\'');
     $total = count($this->servers[Server::SERVER_ROLE_APS]);
     $destroyed = 0;
     if (!is_null($reason_)) {
         $report_session = Abstract_ReportSession::load($this->id);
         if (is_object($report_session)) {
             $report_session->setStopWhy($reason_);
             Abstract_ReportSession::update($report_session);
         }
     }
     if ($request_servers_) {
         foreach ($this->servers[Server::SERVER_ROLE_APS] as $server_id => $data) {
             $session_server = Abstract_Server::load($server_id);
             if (!$session_server) {
                 Logger::error('main', 'Session::orderDeletion Unable to load server \'' . $server_id . '\'');
                 return false;
             }
             if (is_array($session_server->roles)) {
                 if (array_key_exists(Server::SERVER_ROLE_APS, $session_server->roles)) {
                     $buf = $session_server->orderSessionDeletion($this->id);
                     if (!$buf) {
                         Logger::warning('main', 'Session::orderDeletion Session \'' . $this->id . '\' already destroyed on server \'' . $session_server->fqdn . '\'');
                         $this->setServerStatus($session_server->id, Session::SESSION_STATUS_DESTROYED);
                         $destroyed++;
                     } else {
                         $this->setServerStatus($session_server->id, Session::SESSION_STATUS_DESTROYING);
                     }
                 }
             }
         }
     } else {
         $destroyed = $total;
     }
     if ($destroyed == $total) {
         $this->setStatus(Session::SESSION_STATUS_DESTROYED, $reason_);
     } else {
         $this->setStatus(Session::SESSION_STATUS_DESTROYING, $reason_);
     }
     if (array_key_exists(Server::SERVER_ROLE_WEBAPPS, $this->servers)) {
         foreach ($this->servers[Server::SERVER_ROLE_WEBAPPS] as $server_id => $data) {
             $session_server = Abstract_Server::load($server_id);
             if (!$session_server) {
                 Logger::error('main', 'Session::orderDeletion Unable to load server \'' . $server_id . '\'');
                 return false;
             }
             if (is_array($session_server->roles)) {
                 if (array_key_exists(Server::SERVER_ROLE_WEBAPPS, $session_server->roles)) {
                     $buf = $session_server->orderSessionDeletion($this->id, 'webapps');
                     if (!$buf) {
                         Logger::warning('main', 'Session::orderDeletion Session \'' . $this->id . '\' already destroyed on server \'' . $session_server->fqdn . '\'');
                         $this->setServerStatus($session_server->id, Session::SESSION_STATUS_DESTROYED, NULL, Server::SERVER_ROLE_WEBAPPS);
                         $destroyed++;
                     } else {
                         $this->setServerStatus($session_server->id, Session::SESSION_STATUS_DESTROYING, NULL, Server::SERVER_ROLE_WEBAPPS);
                     }
                 }
             }
         }
     }
     return true;
 }
Ejemplo n.º 5
0
 public function session_report_info($id_)
 {
     $this->check_authorized('viewStatus');
     $report = Abstract_ReportSession::load($id_);
     if (!$report) {
         return null;
     }
     return self::generate_sessionreport_array($report);
 }
Ejemplo n.º 6
0
function parse_monitoring_XML($xml_)
{
    if (!$xml_ || strlen($xml_) == 0) {
        return false;
    }
    $dom = new DomDocument('1.0', 'utf-8');
    $buf = @$dom->loadXML($xml_);
    if (!$buf) {
        return false;
    }
    if (!$dom->hasChildNodes()) {
        return false;
    }
    $server_node = $dom->getElementsByTagName('server')->item(0);
    if (is_null($server_node)) {
        return false;
    }
    if (!$server_node->hasAttribute('name')) {
        return false;
    }
    if (!Abstract_Server::exists($server_node->getAttribute('name'))) {
        die;
    }
    // An unknown Server should not send monitoring, so we reject it...
    $server = Abstract_Server::load($server_node->getAttribute('name'));
    if (!$server) {
        return false;
    }
    if (!$server->isAuthorized()) {
        return false;
    }
    $ret = array('server' => $server_node->getAttribute('name'));
    $cpu_node = $dom->getElementsByTagName('cpu')->item(0);
    if (is_null($cpu_node)) {
        return false;
    }
    if (!$cpu_node->hasAttribute('load')) {
        return false;
    }
    $ret['cpu_load'] = $cpu_node->getAttribute('load');
    $ram_node = $dom->getElementsByTagName('ram')->item(0);
    if (is_null($ram_node)) {
        return false;
    }
    if (!$ram_node->hasAttribute('used')) {
        return false;
    }
    $ret['ram_used'] = $ram_node->getAttribute('used');
    $role_nodes = $dom->getElementsByTagName('role');
    foreach ($role_nodes as $role_node) {
        if (!$role_node->hasAttribute('name')) {
            return false;
        }
        switch ($role_node->getAttribute('name')) {
            case 'ApplicationServer':
                $ret['sessions'] = array();
                $session_nodes = $dom->getElementsByTagName('session');
                foreach ($session_nodes as $session_node) {
                    $ret['sessions'][$session_node->getAttribute('id')] = array('id' => $session_node->getAttribute('id'), 'server' => $_SERVER['REMOTE_ADDR'], 'status' => $session_node->getAttribute('status'), 'instances' => array());
                    $childnodes = $session_node->childNodes;
                    foreach ($childnodes as $childnode) {
                        if ($childnode->nodeName != 'instance') {
                            continue;
                        }
                        $ret['sessions'][$session_node->getAttribute('id')]['instances'][$childnode->getAttribute('id')] = $childnode->getAttribute('application');
                    }
                    $token = $session_node->getAttribute('id');
                    if (Abstract_ReportSession::exists($session_node->getAttribute('id'))) {
                        $report = Abstract_ReportSession::load($session_node->getAttribute('id'));
                        if (is_object($report)) {
                            $report->update($session_node);
                        }
                    }
                }
                $sri = new ServerReportItem($ret['server'], $xml_);
                $sri->save();
                break;
            case 'FileServer':
                $size_node = $dom->getElementsByTagName('size')->item(0);
                if (is_null($size_node)) {
                    break;
                }
                $ret['disk_size'] = array('total' => NULL, 'free' => NULL);
                if ($size_node->hasAttribute('total')) {
                    $ret['disk_size']['total'] = $size_node->getAttribute('total');
                }
                if ($size_node->hasAttribute('free')) {
                    $ret['disk_size']['free'] = $size_node->getAttribute('free');
                }
                $ret['shares'] = array();
                $share_nodes = $dom->getElementsByTagName('share');
                foreach ($share_nodes as $share_node) {
                    $ret['shares'][$share_node->getAttribute('id')] = array('id' => $share_node->getAttribute('id'), 'status' => $share_node->getAttribute('status'), 'users' => array());
                    $user_nodes = $share_node->getElementsByTagName('user');
                    foreach ($user_nodes as $user_node) {
                        $ret['shares'][$share_node->getAttribute('id')]['users'][] = $user_node->getAttribute('login');
                    }
                }
                break;
        }
    }
    return $ret;
}