From: <vv...@us...> - 2011-06-20 15:25:58
|
Revision: 2616 http://ganglia.svn.sourceforge.net/ganglia/?rev=2616&view=rev Author: vvuksan Date: 2011-06-20 15:25:52 +0000 (Mon, 20 Jun 2011) Log Message: ----------- Add the conditional for add action Modified Paths: -------------- branches/monitor-web-2.0/api/events_api.php Modified: branches/monitor-web-2.0/api/events_api.php =================================================================== --- branches/monitor-web-2.0/api/events_api.php 2011-06-20 13:55:51 UTC (rev 2615) +++ branches/monitor-web-2.0/api/events_api.php 2011-06-20 15:25:52 UTC (rev 2616) @@ -9,8 +9,8 @@ // host_regex => Host regular expression ie. web or web-0[2,4,5] //////////////////////////////////////////////////////////////////////////////////// // Make timestamp, description and host_regex have been supplied before proceeding -if ( ! isset($_GET['start_time']) || ! isset($_GET['summary']) || ! isset($_GET['host_regex']) ) { - print "Error: You need to supply start_time, description and host_regex at a minimum"; +if ( ! isset($_GET['start_time']) || ! isset($_GET['summary']) || ! isset($_GET['host_regex']) || !isset($_GET['action']) ) { + print "Error: You need to supply start_time, summary, host_regex and action at a minimum"; exit(1); } @@ -22,22 +22,36 @@ $events_array = json_decode($events_json, TRUE); -$start_time = $_GET['start_time'] == "now" ? time() : strtotime($_GET['start_time']); -$grid = isset($_GET['grid']) ? $_GET['grid'] : "*"; -$cluster = isset($_GET['cluster']) ? $_GET['cluster'] : "*"; -$description = isset($_GET['description']) ? $_GET['description'] : ""; +switch ( $_GET['action'] ) { + + case "add": + // If the time is now just insert the current time stamp. Otherwise use strtotime + // to convert + $start_time = $_GET['start_time'] == "now" ? time() : strtotime($_GET['start_time']); -$events_array[] = array( "start_time" => $start_time, "summary" => $_GET['summary'], - "grid" => $grid, "cluster" => $cluster, "host_regex" => $_GET['host_regex']); + $grid = isset($_GET['grid']) ? $_GET['grid'] : "*"; + $cluster = isset($_GET['cluster']) ? $_GET['cluster'] : "*"; + $description = isset($_GET['description']) ? $_GET['description'] : ""; -$json = json_encode($events_array); + $events_array[] = array( "start_time" => $start_time, "summary" => $_GET['summary'], + "grid" => $grid, "cluster" => $cluster, "host_regex" => $_GET['host_regex']); -if ( file_put_contents($conf['overlay_events_file'], $json) === FALSE ) { - print "Error: Can't write to file " . $conf['overlay_events_file'] . ". Perhaps permissions are wrong."; -} else { - print "Events file has been updated successfully."; -} + $json = json_encode($events_array); + if ( file_put_contents($conf['overlay_events_file'], $json) === FALSE ) { + print "Error: Can't write to file " . $conf['overlay_events_file'] . ". Perhaps permissions are wrong."; + } else { + print "Events file has been updated successfully."; + } + + break; + + default: + + print "No valid action specified"; + break; + +} // end of switch ( $_GET['action'] ) { ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |