コード例 #1
0
ファイル: events.php プロジェクト: afbjorklund/ganglia-web
                $end_time = time();
            } else {
                if (is_numeric($_REQUEST['end_time'])) {
                    $end_time = $_REQUEST['end_time'];
                } else {
                    $end_time = strtotime($_REQUEST['end_time']);
                }
            }
            $event['end_time'] = $end_time;
        }
        $message = ganglia_events_add($event);
        break;
    case "edit":
        $message = ganglia_event_modify($_REQUEST);
        break;
    case "remove":
    case "delete":
        if (!isset($_REQUEST['event_id'])) {
            api_return_error("No event_id has been supplied.");
        }
        $message = ganglia_event_delete($_REQUEST['event_id']);
        break;
    case "list":
        $message = ganglia_events_get();
        break;
    default:
        api_return_error("No valid action specified");
        break;
}
// end of switch ( $_REQUEST['action'] ) {
print json_encode($message);
コード例 #2
0
ファイル: events.php プロジェクト: afbjorklund/ganglia-web
    print "<th>Cluster</th>";
    print "<th>Host Regex</th>";
    print "</tr>";
    print "</thead>";
    include_once $conf['gweb_root'] . "/functions.php";
    include_once $conf['gweb_root'] . "/lib/common_api.php";
    function start_time_cmp($ev1, $ev2)
    {
        $start1 = $ev1['start_time'];
        $start2 = $ev2['start_time'];
        if ($start1 == $start2) {
            return 0;
        }
        return $start1 < $start2 ? 1 : -1;
    }
    $events_array = ganglia_events_get();
    if (count($events_array) > 0) {
        print "<tbody>";
        usort($events_array, 'start_time_cmp');
        foreach ($events_array as $id => $event) {
            $description = isset($event['description']) ? $event['description'] : "";
            $end_time = isset($event['end_time']) ? date("Y/m/d H:i", $event['end_time']) : "";
            print "<tr><td>" . date("Y/m/d H:i", $event['start_time']) . "</td>" . "<td>" . $end_time . "</td>" . "<td>" . $event['summary'] . "</td>" . "<td>" . $description . "</td>" . "<td>" . $event['grid'] . "</td>" . "<td>" . $event['cluster'] . "</td>" . "<td>" . $event['host_regex'] . "</td>" . "</tr>";
        }
        print "</tbody>";
    }
    print "</table>";
}
?>

コード例 #3
0
ファイル: Driver_Json.php プロジェクト: pombredanne/ganglia
function ganglia_event_modify($event)
{
    global $conf;
    $event_found = 0;
    $events_array = ganglia_events_get();
    $new_events_array = array();
    if (!isset($event['event_id'])) {
        api_return_error("Event ID not found");
    }
    // isset event_id
    foreach ($events_array as $k => $e) {
        if ($e['event_id'] == $event['event_id']) {
            $event_found = 1;
            if (isset($event['start_time'])) {
                if ($event['start_time'] == "now") {
                    $e['start_time'] = time();
                } else {
                    if (is_numeric($event['start_time'])) {
                        $e['start_time'] = $event['start_time'];
                    } else {
                        $e['start_time'] = strtotime($event['start_time']);
                    }
                }
            }
            // end isset start_time
            foreach (array('cluster', 'description', 'summary', 'grid', 'host_regex') as $k) {
                if (isset($event[$k])) {
                    $e[$k] = $event[$k];
                }
            }
            // end foreach
            if (isset($event['end_time'])) {
                $e['end_time'] = $event['end_time'] == "now" ? time() : strtotime($event['end_time']);
            }
            // end isset end_time
        }
        // if event_id
        // Add either original or modified event back in
        $new_events_array[] = $e;
    }
    // foreach events array
    if ($event_found == 1) {
        $json = json_encode($new_events_array);
        if (file_put_contents($conf['overlay_events_file'], $json) === FALSE) {
            api_return_error("Can't write to file " . $conf['overlay_events_file'] . ". Perhaps permissions are wrong.");
        } else {
            $message = array("status" => "ok", "message" => "Event ID " . $event_id . " modified successfully");
        }
    }
    // end if event_found
    return $message;
}
コード例 #4
0
ファイル: graph.php プロジェクト: sasharatkovic/cldemo
function rrdgraph_cmd_add_overlay_events($command, $graph_start, $graph_end, $conf_overlay_events_color_map_file, $conf_overlay_events_shade_alpha, $conf_overlay_events_tick_alpha, $conf_overlay_events_line_type, $conf_graph_colors, $nagios_events)
{
    $debug = FALSE;
    // In order not to pollute the command line with all the possible VRULEs
    // we need to find the time range for the graph
    $graph_end_timestamp = get_timestamp($graph_end);
    $graph_start_timestamp = get_timestamp($graph_start);
    if ($graph_start_timestamp == NULL || $graph_end_timestamp == NULL) {
        error_log("process_over_events: " . "Start/end timestamp(s) are NULL");
        return $command;
    }
    // Get array of events for time range
    $events_array = ganglia_events_get($graph_start_timestamp, $graph_end_timestamp);
    if (empty($events_array)) {
        return $command;
    }
    $event_color_json = file_get_contents($conf_overlay_events_color_map_file);
    if ($debug) {
        error_log("{$event_color_json}");
    }
    $event_color_array = json_decode($event_color_json, TRUE);
    $initial_event_color_count = count($event_color_array);
    $event_color_map = array();
    foreach ($event_color_array as $event_color_entry) {
        $event_color_map[$event_color_entry['summary']] = $event_color_entry['color'];
        if ($debug) {
            error_log("Adding event color to map: " . $event_color_entry['summary'] . ' ' . $event_color_entry['color']);
        }
    }
    // Combine the nagios_events array, if it exists
    if (count($nagios_events) > 0) {
        // World's dumbest array merge:
        foreach ($nagios_events as $ne) {
            $events_array[] = $ne;
        }
    }
    foreach ($events_array as $key => $row) {
        $start_time[$key] = $row['start_time'];
    }
    // Sort events in reverse chronological order
    array_multisort($start_time, SORT_DESC, $events_array);
    // Default to dashed line unless events_line_type is set to solid
    if ($conf_overlay_events_line_type == "solid") {
        $overlay_events_line_type = "";
    } else {
        $overlay_events_line_type = ":dashes";
    }
    // Preserve original rrdtool command. That's the one we'll run regex checks
    // against
    $original_command = $command;
    // Loop through all the events
    $color_count = sizeof($conf_graph_colors);
    $counter = 0;
    $legend_items = array();
    foreach ($events_array as $id => $event) {
        $evt_start = $event['start_time'];
        // Make sure it's a number
        if (!is_numeric($evt_start)) {
            continue;
        }
        unset($evt_end);
        if (array_key_exists('end_time', $event) && is_numeric($event['end_time'])) {
            $evt_end = $event['end_time'];
        }
        // If event start is less than start bail out of the loop since
        // there is nothing more to do since events are sorted in reverse
        // chronological order and these events are not gonna show up in
        // the graph
        $in_graph = $evt_start >= $graph_start_timestamp && $evt_start <= $graph_end_timestamp || isset($evt_end) && $evt_end >= $graph_start_timestamp && $evt_start <= $graph_end_timestamp;
        if (!$in_graph) {
            if ($debug) {
                error_log("process_overlay_events: " . "Event [{$evt_start}] does not overlap with graph " . "[{$graph_start_timestamp}, {$graph_end_timestamp}]");
            }
            continue;
        }
        // Compute the part of the event to be displayed
        $evt_start_in_graph_range = TRUE;
        if ($evt_start < $graph_start_timestamp) {
            $evt_start = $graph_start_timestamp;
            $evt_start_in_graph_range = FALSE;
        }
        $evt_end_in_graph_range = TRUE;
        if (isset($evt_end)) {
            if ($evt_end > $graph_end_timestamp) {
                $evt_end = $graph_end_timestamp;
                $evt_end_in_graph_range = FALSE;
            }
        } else {
            $evt_end_in_graph_range = FALSE;
        }
        if (preg_match("/" . $event["host_regex"] . "/", $original_command)) {
            if ($evt_start >= $graph_start_timestamp) {
                // Do we have the end timestamp.
                if (!isset($graph_end_timestamp) || $evt_start < $graph_end_timestamp) {
                    // This is a potential vector since this gets added to the
                    // command line_width TODO: Look over sanitize
                    $summary = isset($event['summary']) ? sanitize($event['summary']) : "";
                    // We need to keep track of summaries so that if we have identical
                    // summaries e.g. Deploy we can use the same color
                    if (array_key_exists($summary, $event_color_map)) {
                        $color = $event_color_map[$summary];
                        if ($debug) {
                            error_log("process_overlay_events: " . "Found existing color: {$summary} {$color}");
                        }
                        // Reset summary to empty string if it is already present in
                        // the legend
                        if (array_key_exists($summary, $legend_items)) {
                            $summary = "";
                        } else {
                            $legend_items[$summary] = TRUE;
                        }
                    } else {
                        // Haven't seen this summary before. Assign it a color
                        $color_index = count($event_color_map) % $color_count;
                        $color = $conf_graph_colors[$color_index];
                        $event_color_map[$summary] = $color;
                        $event_color_array[] = array('summary' => $summary, 'color' => $color);
                        if ($debug) {
                            error_log("process_overlay_events: " . "Adding new event color: {$summary} {$color}");
                        }
                    }
                    if (isset($evt_end)) {
                        // Attempt to draw a shaded area between start and end points.
                        // Force solid line for ranges
                        $overlay_events_line_type = "";
                        $start_vrule = '';
                        if ($evt_start_in_graph_range) {
                            $start_vrule = " VRULE:" . $evt_start . "#{$color}" . $conf_overlay_events_tick_alpha . ":\"" . $summary . "\"" . $overlay_events_line_type;
                        }
                        $end_vrule = '';
                        if ($evt_end_in_graph_range) {
                            $end_vrule = " VRULE:" . $evt_end . "#{$color}" . $conf_overlay_events_tick_alpha . ':""' . $overlay_events_line_type;
                        }
                        // We need a dummpy DEF statement, because RRDtool is too stupid
                        // to plot graphs without a DEF statement.
                        // We can't count on a static name, so we have to "find" one.
                        if (preg_match("/DEF:['\"]?(\\w+)['\"]?=/", $command, $matches)) {
                            // stupid rrdtool limitation.
                            $area_cdef = " CDEF:area_{$counter}={$matches['1']},POP," . "TIME,{$evt_start},GT,1,UNKN,IF,TIME,{$evt_end},LT,1,UNKN,IF,+";
                            $area_shade = $color . $conf_overlay_events_shade_alpha;
                            $area = " TICK:area_{$counter}#{$area_shade}:1";
                            if (!$evt_start_in_graph_range) {
                                $area .= ':"' . $summary . '"';
                            }
                            $command .= "{$area_cdef} {$area} {$start_vrule} {$end_vrule}";
                        } else {
                            error_log("No DEF statements found in \$command?!");
                        }
                    } else {
                        $command .= " VRULE:" . $evt_start . "#" . $color . ":\"" . $summary . "\"" . $overlay_events_line_type;
                    }
                    $counter++;
                } else {
                    if ($debug) {
                        error_log("process_overlay_events: " . "Event start [{$evt_start}] >= graph end " . "[{$graph_end_timestamp}]");
                    }
                }
            } else {
                if ($debug) {
                    error_log("process_overlay_events: " . "Event start [{$evt_start}] < graph start " . "[{$graph_start_timestamp}]");
                }
            }
        } else {
            // error_log("Doesn't match host_regex");
        }
    }
    // end of foreach ( $events_array ...
    unset($events_array);
    if (count($event_color_array) > $initial_event_color_count) {
        $event_color_json = json_encode($event_color_array);
        file_put_contents($conf_overlay_events_color_map_file, $event_color_json);
    }
    return $command;
}
コード例 #5
0
ファイル: graph.php プロジェクト: rosarion/ganglia-web
     if (is_numeric($rrdtool_graph['end'])) {
         $end = $rrdtool_graph['end'];
     }
 }
 if (preg_match("/\\-([0-9]*)(s)/", $rrdtool_graph['start'], $out)) {
     $start = time() - $out[1];
 } else {
     if (is_numeric($rrdtool_graph['start'])) {
         $start = $rrdtool_graph['start'];
     } else {
         // If it's not
         $start = time() - 157680000;
     }
 }
 // Get array of events for time range
 $events_array = ganglia_events_get($start, $end);
 if (!empty($events_array)) {
     $event_color_json = file_get_contents($conf['overlay_events_color_map_file']);
     if ($debug) {
         error_log("{$event_color_json}");
     }
     $event_color_array = json_decode($event_color_json, TRUE);
     $initial_event_color_count = count($event_color_array);
     $event_color_map = array();
     foreach ($event_color_array as $event_color_entry) {
         $event_color_map[$event_color_entry['summary']] = $event_color_entry['color'];
         if ($debug) {
             error_log("Adding event color to map: " . $event_color_entry['summary'] . ' ' . $event_color_entry['color']);
         }
     }
     $color_count = sizeof($conf['graph_colors']);
コード例 #6
0
<?php

include_once "./functions.php";
$event_array = ganglia_events_get(intval($_GET['start']), intval($_GET['end']));
header("Content-type: application/json");
print json_encode($event_array);
exit(0);