1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\PagerDuty; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Arr; |
6
|
|
|
|
7
|
|
|
class PagerDutyMessage |
8
|
|
|
{ |
9
|
|
|
const EVENT_TRIGGER = 'trigger'; |
10
|
|
|
const EVENT_RESOLVE = 'resolve'; |
11
|
|
|
|
12
|
|
|
protected $payload = []; |
13
|
|
|
protected $meta = []; |
14
|
|
|
|
15
|
20 |
|
public function __construct() |
16
|
|
|
{ |
17
|
20 |
|
Arr::set($this->meta, 'event_action', self::EVENT_TRIGGER); |
18
|
|
|
|
19
|
20 |
|
Arr::set($this->payload, 'source', gethostname()); |
20
|
20 |
|
Arr::set($this->payload, 'severity', 'critical'); |
21
|
20 |
|
} |
22
|
|
|
|
23
|
20 |
|
public function routingKey($value) |
24
|
|
|
{ |
25
|
20 |
|
return $this->setMeta('routing_key', $value); |
26
|
|
|
} |
27
|
|
|
|
28
|
2 |
|
public function resolve() |
29
|
|
|
{ |
30
|
2 |
|
return $this->setMeta('event_action', self::EVENT_RESOLVE); |
31
|
|
|
} |
32
|
|
|
|
33
|
4 |
|
public function dedupKey($key) |
34
|
|
|
{ |
35
|
4 |
|
return $this->setMeta('dedup_key', $key); |
36
|
|
|
} |
37
|
|
|
|
38
|
8 |
|
public function summary($value) |
39
|
|
|
{ |
40
|
8 |
|
return $this->setPayload('summary', $value); |
41
|
|
|
} |
42
|
|
|
|
43
|
18 |
|
public function source($value) |
44
|
|
|
{ |
45
|
18 |
|
return $this->setPayload('source', $value); |
46
|
|
|
} |
47
|
|
|
|
48
|
2 |
|
public function severity($value) |
49
|
|
|
{ |
50
|
2 |
|
return $this->setPayload('severity', $value); |
51
|
|
|
} |
52
|
|
|
|
53
|
2 |
|
public function timestamp($value) |
54
|
|
|
{ |
55
|
2 |
|
return $this->setPayload('timestamp', $value); |
56
|
|
|
} |
57
|
|
|
|
58
|
2 |
|
public function component($value) |
59
|
|
|
{ |
60
|
2 |
|
return $this->setPayload('component', $value); |
61
|
|
|
} |
62
|
|
|
|
63
|
2 |
|
public function group($value) |
64
|
|
|
{ |
65
|
2 |
|
return $this->setPayload('group', $value); |
66
|
|
|
} |
67
|
|
|
|
68
|
2 |
|
public function setClass($value) |
69
|
|
|
{ |
70
|
2 |
|
return $this->setPayload('class', $value); |
71
|
|
|
} |
72
|
|
|
|
73
|
2 |
|
public function addCustomDetail($key, $value) |
74
|
|
|
{ |
75
|
2 |
|
return $this->setPayload("custom_details.$key", $value); |
76
|
|
|
} |
77
|
|
|
|
78
|
20 |
|
protected function setPayload($key, $value) |
79
|
|
|
{ |
80
|
20 |
|
Arr::set($this->payload, $key, $value); |
81
|
|
|
|
82
|
20 |
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
20 |
|
protected function setMeta($key, $value) |
86
|
|
|
{ |
87
|
20 |
|
Arr::set($this->meta, $key, $value); |
88
|
|
|
|
89
|
20 |
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
20 |
|
public function toArray() |
93
|
|
|
{ |
94
|
20 |
|
return Arr::collapse([$this->meta, ['payload' => $this->payload]]); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|