Пример #1
0
function renderMuninServersEditor()
{
    function printNewItemTR()
    {
        printOpFormIntro('add');
        echo '<tr>';
        echo '<td>' . getImageHREF('create', 'add a new server', TRUE, 112) . '</td>';
        echo '<td><input type=text size=48 name=base_url tabindex=101></td>';
        echo '<td>&nbsp;</td>';
        echo '<td>' . getImageHREF('create', 'add a new server', TRUE, 111) . '</td>';
        echo '</tr></form>';
    }
    echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>';
    echo '<tr><th>&nbsp;</th><th>base URL</th><th>graph(s)</th><th>&nbsp;</th></tr>';
    if (getConfigVar('ADDNEW_AT_TOP') == 'yes') {
        printNewItemTR();
    }
    foreach (getMuninServers() as $server) {
        printOpFormIntro('upd', array('id' => $server['id']));
        echo '<tr><td>';
        if ($server['num_graphs']) {
            printImageHREF('nodestroy', 'cannot delete, graphs exist');
        } else {
            echo getOpLink(array('op' => 'del', 'id' => $server['id']), '', 'destroy', 'delete this server');
        }
        echo '</td>';
        echo '<td><input type=text size=48 name=base_url value="' . htmlspecialchars($server['base_url'], ENT_QUOTES, 'UTF-8') . '"></td>';
        echo "<td class=tdright>{$server['num_graphs']}</td>";
        echo '<td>' . getImageHREF('save', 'update this server', TRUE) . '</td>';
        echo '</tr></form>';
    }
    if (getConfigVar('ADDNEW_AT_TOP') != 'yes') {
        printNewItemTR();
    }
    echo '</table>';
}
Пример #2
0
function renderObjectMuninGraphs($object_id)
{
    function printNewItem($options)
    {
        echo "<table cellspacing=\"0\" align=\"center\" width=\"50%\">";
        echo "<tr><td>&nbsp;</td><th>Server</th><th>Graph</th><th>Caption</th><td>&nbsp;</td></tr>\n";
        printOpFormIntro('add');
        echo "<tr><td>";
        printImageHREF('Attach', 'Link new graph', TRUE);
        echo '</td><td>' . getSelect($options, array('name' => 'server_id'));
        echo "</td><td><input type=text name=graph></td><td><input type=text name=caption></td><td>";
        printImageHREF('Attach', 'Link new graph', TRUE);
        echo "</td></tr></form>";
        echo "</table>";
        echo "<br/><br/>";
    }
    if (!extension_loaded('curl')) {
        showError('The PHP cURL extension is not loaded.');
        return;
    }
    try {
        list($host, $domain) = getMuninNameAndDomain($object_id);
    } catch (InvalidArgException $e) {
        showError('This object does not have the FQDN or the common name in the host.do.ma.in format.');
        return;
    }
    $servers = getMuninServers();
    $options = array();
    foreach ($servers as $server) {
        $options[$server['id']] = "{$server['id']}: {$server['base_url']}";
    }
    startPortlet('Munin Graphs');
    if (getConfigVar('ADDNEW_AT_TOP') == 'yes') {
        printNewItem($options);
    }
    echo "<table cellspacing=\"0\" cellpadding=\"10\" align=\"center\" width=\"50%\">";
    foreach (getMuninGraphsForObject($object_id) as $graph_name => $graph) {
        $munin_url = $servers[$graph['server_id']]['base_url'];
        $text = "(graph {$graph_name} on server {$graph['server_id']})";
        echo "<tr><td>";
        echo "<a href='{$munin_url}/{$domain}/{$host}.{$domain}/{$graph_name}.html' target='_blank'>";
        echo "<img src='index.php?module=image&img=muningraph&object_id={$object_id}&server_id={$graph['server_id']}&graph={$graph_name}' alt='{$text}' title='{$text}'></a></td>";
        echo "<td>";
        echo getOpLink(array('op' => 'del', 'server_id' => $graph['server_id'], 'graph' => $graph_name), '', 'Cut', 'Unlink graph', 'need-confirmation');
        echo "&nbsp; &nbsp;{$graph['caption']}";
        echo "</td></tr>";
    }
    echo '</table>';
    if (getConfigVar('ADDNEW_AT_TOP') != 'yes') {
        printNewItem($options);
    }
    finishPortlet();
}
Пример #3
0
function proxyMuninRequest($server_id, $graph)
{
    $object = spotEntity('object', $server_id);
    list($host, $domain) = preg_split("/\\./", $object['dname'], 2);
    $ret = array();
    $servers = getMuninServers();
    if (!array_key_exists($server_id, $servers)) {
        throw new InvalidRequestArgException('server_id', $server_id);
    }
    $munin_url = $servers[$server_id]['base_url'];
    $url = "{$munin_url}/{$domain}/{$object['dname']}/{$graph}-day.png";
    $session = curl_init();
    // Initial options up here so a specific type can override them
    curl_setopt($session, CURLOPT_FOLLOWLOCATION, FALSE);
    curl_setopt($session, CURLOPT_TIMEOUT, 10);
    curl_setopt($session, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($session, CURLOPT_URL, $url);
    if (isset($_SESSION['MUNINCOOKIE'][$munin_url])) {
        curl_setopt($session, CURLOPT_COOKIE, $_SESSION['MUNINCOOKIE'][$munin_url]);
    }
    // Request the image
    $ret['contents'] = curl_exec($session);
    $ret['type'] = curl_getinfo($session, CURLINFO_CONTENT_TYPE);
    $ret['size'] = curl_getinfo($session, CURLINFO_SIZE_DOWNLOAD);
    curl_close($session);
    if ($ret['type'] != NULL) {
        header("Content-Type: {$ret['type']}");
    }
    if ($ret['size'] > 0) {
        header("Content-Length: {$ret['size']}");
    }
    echo $ret['contents'];
}
Пример #4
0
function triggerMuninGraphs()
{
    if (!count(getMuninServers())) {
        return '';
    }
    if (count(getMuninGraphsForObject(getBypassValue())) or considerConfiguredConstraint(spotEntity('object', getBypassValue()), 'MUNIN_LISTSRC')) {
        return 'std';
    } else {
        return '';
    }
}