Allow the use of a custom URL for accessing the PagerDuty API and correct API schema violation (#14010)

* Allow the use of a custom URL for accessing PagerDuty

* styleci

* PagerDuty custom details must be an Object, not string

* styleci
This commit is contained in:
Nash Kaminski
2022-06-04 13:54:35 -05:00
committed by GitHub
parent 6039293a7c
commit 24e1c96790

View File

@@ -53,12 +53,13 @@ class Pagerduty extends Transport
*/
public function contactPagerduty($obj, $config)
{
$custom_details = ['message' => strip_tags($obj['msg']) ?: 'Test'];
$data = [
'routing_key' => $config['service_key'],
'event_action' => $obj['event_type'],
'dedup_key' => (string) $obj['alert_id'],
'payload' => [
'custom_details' => strip_tags($obj['msg']) ?: 'Test',
'custom_details' => $custom_details,
'group' => (string) \DeviceCache::get($obj['device_id'])->groups->pluck('name'),
'source' => $obj['hostname'],
'severity' => $obj['severity'],
@@ -69,11 +70,11 @@ class Pagerduty extends Transport
// EU service region
if ($config['region'] == 'EU') {
$url = 'https://events.eu.pagerduty.com/v2/enqueue';
}
} elseif ($config['region'] == 'US') {
// US service region
else {
$url = 'https://events.pagerduty.com/v2/enqueue';
} else {
$url = $config['custom-url'];
}
$client = new Client();
@@ -106,6 +107,7 @@ class Pagerduty extends Transport
'options' => [
'EU' => 'EU',
'US' => 'US',
'Custom URL' => 'CUSTOM',
],
],
[
@@ -113,9 +115,16 @@ class Pagerduty extends Transport
'type' => 'text',
'name' => 'service_key',
],
[
'title' => 'Custom API URL',
'type' => 'text',
'name' => 'custom-url',
'descr' => 'Custom PagerDuty API URL',
],
],
'validation' => [
'region' => 'in:EU,US',
'region' => 'in:EU,US,CUSTOM',
'custom-url' => 'url',
],
];
}