forked from vvuksan/ganglia-misc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request vvuksan#100 from jbuchbinder/master
Implement driver segmentation for events
- Loading branch information
Showing
6 changed files
with
92 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
$conf['ganglia_dir'] = dirname(dirname(dirname(__FILE__))); | ||
|
||
include_once $conf['ganglia_dir'] . "/eval_conf.php"; | ||
include_once $conf['ganglia_dir'] . "/lib/common_api.php"; | ||
|
||
function ganglia_events_add( $event ) { | ||
$events_array = ganglia_events_get(); | ||
$events_array[] = $event; | ||
$json = json_encode($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", "event_id" => $event_id); | ||
} | ||
return $message; | ||
} // end method ganglia_events_add | ||
|
||
function ganglia_events_get() { | ||
global $conf; | ||
$events_json = file_get_contents($conf['overlay_events_file']); | ||
$events_array = json_decode($events_json, TRUE); | ||
return $events_array; | ||
} // end method ganglia_events_get | ||
|
||
function ganglia_event_modify( $event ) { | ||
global $conf; | ||
$event_found = 0; | ||
$events_array = ganglia_events_get(); | ||
$new_events_array = array(); | ||
|
||
if (isset($event['id'])) { | ||
api_return_error( "Event ID not found" ); | ||
} // isset event_id | ||
|
||
foreach ( $events_array AS $k => $e ) { | ||
if ( $e['event_id'] == $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 . " removed successfully" ); | ||
} | ||
} // end if event_found | ||
|
||
return $message; | ||
} // end method ganglia_event_modify | ||
|
||
?> |