示例#1
0
function displayCheckGraphs($interval = 'day')
{
    global $tool, $form, $status_array, $status_collors;
    $my_colors = array("FF0000", "0404B4", "04B431", "B45F04", "F7FE2E", "8B008B", "4B0082", "FA8072", "4169E1", "D2B9D3", "B4CFEC", "eF6600", "77CEEB", "eFFF00", "6FFF00", "8E7BFF", "7B008B", "3B0082", "eA8072", "3169E1", "c2B9D3", "a4CFEC", "dF6600", "67CEEB", "dFFF00", "5FFF00", "7E7BFF", "6B008B", "2B0082", "dA8072", "2169E1", "b2B9D3", "94CFEC");
    if (is_numeric($_GET[checkid])) {
        $check = new Check($_GET[checkid]);
    } else {
        $form->warning("Invalid check id");
    }
    $property = new Property();
    if ($rrd_dir = $property->get_property("path_rrddir")) {
    } else {
        $form->warning($property->get_error());
        return false;
    }
    if ($rrdtool = $property->get_property("path_rrdtool")) {
    } else {
        return;
    }
    $filename = "checks/checkid_" . $check->get_check_id() . ".rrd";
    $filepath = $rrd_dir . "/" . $filename;
    // Now check if there's are graphs for this check
    // Not all checks have these
    if (!file_exists($filepath)) {
        //$form->warning( "file $filename not there");
        return false;
    }
    if ($interval == 'week') {
        $from = "-7d";
    } elseif ($interval == 'month') {
        $from = "-1m";
    } elseif ($interval == 'year') {
        $from = "-365d";
    } else {
        $from = "-24h";
    }
    $rrd = new RRD("{$filepath}", $rrdtool);
    $datasources = $rrd->get_data_sources();
    ksort($datasources, SORT_STRING);
    $exclude_ds = array();
    $color_codes = "";
    $exclude = "";
    $i = 0;
    foreach ($datasources as $ds => $value) {
        $color_code .= "&ds_colors[{$ds}]={$my_colors[$i]}";
        $i++;
        if (isset($_GET[$ds]) && $_GET[$ds] == 'no') {
            array_push($exclude_ds, $ds);
            $exclude .= "&exclude_ds[{$ds}]=yes";
        }
    }
    $rrd_url = "rrdgraph.php?file=" . urlencode($filename) . "&type=check&title=" . urlencode($check->get_name()) . "&width=400&height=122&from={$from}" . "{$exclude}" . $color_code;
    return "<img src='{$rrd_url}'>";
}