Exemplo n.º 1
0
    }
    $ret = array('id' => $node->getAttribute('id'), 'server' => $_SERVER['REMOTE_ADDR'], 'status' => $node->getAttribute('status'), 'reason' => NULL, 'role' => NULL);
    if ($node->hasAttribute('reason')) {
        $ret['reason'] = $node->getAttribute('reason');
    }
    if ($node->hasAttribute('role')) {
        $ret['role'] = $node->getAttribute('role');
    }
    return $ret;
}
$ret = parse_session_status_XML(@file_get_contents('php://input'));
if (!$ret) {
    Logger::error('main', '(webservices/session/status) Server does not send a valid XML (error_code: 1)');
    webservices_return_error(1, 'Server does not send a valid XML');
}
$server = webservices_load_server($_SERVER['REMOTE_ADDR']);
if (is_null($server)) {
    Logger::error('main', '(webservices/session/status) Server does not exist (error_code: 2)');
    webservices_return_error(2, 'Server does not exist');
}
$session = Abstract_Session::load($ret['id']);
if (!$session) {
    Logger::error('main', '(webservices/session/status) Session does not exist (error_code: 2)');
    webservices_return_error(2, 'Session does not exist');
}
$session->setServerStatus($server->id, $ret['status'], $ret['reason'], $ret['role']);
header('Content-Type: text/xml; charset=utf-8');
$dom = new DomDocument('1.0', 'utf-8');
$node = $dom->createElement('session');
$node->setAttribute('id', $session->id);
$node->setAttribute('status', $session->status);
Exemplo n.º 2
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;
    }
    $server = webservices_load_server($_SERVER['REMOTE_ADDR']);
    if (!$server) {
        Logger::error('main', '(webservices/server/monitoring) Server does not exist (error_code: 2)');
        webservices_return_error(2, 'Server does not exist');
    }
    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');
                    }
                }
                $sri = ServerReportItem::create_from_server_report($ret['server'], $xml_);
                if ($sri !== null) {
                    Abstract_ReportServer::save($sri);
                }
                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;
}