示例#1
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;
}
示例#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;
    }
    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;
}