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; }
/** * Copyright (C) 2008-2013 Ulteo SAS * http://www.ulteo.com * Author Julien LANGLOIS <*****@*****.**> 2008-2013 * Author Laurent CLOUET <*****@*****.**> 2008-2011 * Author Jeremy DESVAGES <*****@*****.**> 2008-2011 * Author Vincent ROULLIER <*****@*****.**> 2013 * Author David LECHEVALIER <*****@*****.**> 2012 * Author David PHAM-VAN <*****@*****.**> 2013 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; version 2 * of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ function init_db($prefs_) { // prefs must be valid Logger::debug('main', 'init_db'); $modules_enable = $prefs_->get('general', 'module_enable'); foreach ($modules_enable as $module_name) { if (!is_null($prefs_->get($module_name, 'enable'))) { $enable = $prefs_->get($module_name, 'enable'); if (is_string($enable)) { $mod_name = $module_name . '_' . $enable; $ret_eval = call_user_func(array($mod_name, 'init'), $prefs_); if ($ret_eval !== true) { Logger::error('main', 'init_db init module \'' . $mod_name . '\' failed'); return false; } } elseif (is_array($enable)) { foreach ($enable as $sub_module) { $mod_name = $module_name . '_' . $sub_module; $ret_eval = call_user_func(array($mod_name, 'init'), $prefs_); if ($ret_eval !== true) { Logger::error('main', 'init_db init module \'' . $mod_name . '\' failed'); return false; } } } } } Logger::debug('main', 'init_db modules inited'); // Init of Abstract Abstract_Server::init($prefs_); Abstract_ServersGroup::init($prefs_); Abstract_Session::init($prefs_); Abstract_Token::init($prefs_); Abstract_News::init($prefs_); Abstract_Script::init($prefs_); Abstract_Liaison::init($prefs_); if (class_exists("PremiumManager")) { PremiumManager::initdb($prefs_); } Abstract_Task::init($prefs_); Abstract_ReportServer::init($prefs_); Abstract_ReportSession::init($prefs_); Abstract_User_Preferences::init($prefs_); Abstract_UserGroup_Preferences::init($prefs_); Abstract_UserGroup_Rule::init($prefs_); Abstract_VDI::init($prefs_); Abstract_Network_Folder::init($prefs_); Abstract_AdminAction::init($prefs_); return true; }
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; }
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; }
public function session_report_remove($id_) { $this->check_authorized('manageReporting'); if (!Abstract_ReportSession::exists($id_)) { Logger::error('api', sprintf('Unknown archived session "%s"', $id_)); return false; } $ret = Abstract_ReportSession::delete($id_); if ($ret !== true) { Logger::error('api', sprintf('Unable to delete archived session "%s"', $id_)); return false; } $this->log_action('session_report_remove', array('id' => $id_)); return true; }
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; }