diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 717f6c75dc..a6e9279f6a 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,8 @@ +2014-04-02 Sergio Martin + + * include/functions_api.php: Added new API function to validate + alerts from PagerDuty notification service + 2014-04-02 Miguel de Dios * operation/search_results.php, operation/search_users.getdata.php: diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 6aa4be870d..d0af658796 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -6643,4 +6643,46 @@ function api_set_enable_disable_agent ($id, $thrash2, $other, $thrash3) { } } +function api_set_pagerduty_webhook($type, $matchup_path, $tresh2, $return_type) { + global $config; + + $pagerduty_data = json_decode(file_get_contents('php://input'), true); + + foreach($pagerduty_data['messages'] as $pm) { + $incident = $pm['data']['incident']; + $incident_type = $pm['type']; + // incident.acknowledge + // incident.resolve + // incident.trigger + + switch($type) { + case 'alert': + // Get all the alerts that the user can see + $id_groups = array_keys(users_get_groups($config["id_user"], 'AR', false)); + $alerts = get_group_alerts($id_groups); + + // When an alert is resolved, the Pandoras alert will be validated + if ($incident_type != 'incident.resolve') { + break; + } + + $alert_id = 0; + foreach($alerts as $al) { + $key = file_get_contents($matchup_path . '/.pandora_pagerduty_id_' . $al['id']); + if ($key == $incident['incident_key']) { + $alert_id = $al['id']; + break; + } + } + + if ($alert_id != 0) { + alerts_validate_alert_agent_module($alert_id); + } + break; + case 'event': + break; + } + } +} + ?>