Welcome to mirror list, hosted at ThFree Co, Russian Federation.

media_pagerduty.yaml « pagerduty « media « templates - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c0ad9edbdb78c80019d3dbc732fb91ad86443a43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
zabbix_export:
  version: '5.4'
  date: '2020-10-16T09:33:50Z'
  media_types:
    -
      name: PagerDuty
      type: WEBHOOK
      parameters:
        -
          name: alert_message
          value: '{ALERT.MESSAGE}'
        -
          name: eventack
          value: '{EVENT.ACK.STATUS}'
        -
          name: eventdate
          value: '{EVENT.DATE}'
        -
          name: eventid
          value: '{EVENT.ID}'
        -
          name: eventname
          value: '{ALERT.SUBJECT}'
        -
          name: eventtags
          value: '{EVENT.TAGS}'
        -
          name: eventtime
          value: '{EVENT.TIME}'
        -
          name: eventupdate
          value: '{EVENT.UPDATE.STATUS}'
        -
          name: eventvalue
          value: '{EVENT.VALUE}'
        -
          name: event_source
          value: '{EVENT.SOURCE}'
        -
          name: hostip
          value: '{HOST.IP}'
        -
          name: hostname
          value: '{HOST.NAME}'
        -
          name: severity
          value: '{EVENT.NSEVERITY}'
        -
          name: token
          value: '<put your key>'
        -
          name: triggerdesc
          value: '{TRIGGER.DESCRIPTION}'
        -
          name: triggerid
          value: '{TRIGGER.ID}'
        -
          name: triggeropdata
          value: '{EVENT.OPDATA}'
        -
          name: url
          value: '{$ZABBIX.URL}'
      script: |
        try {
        
            var params = JSON.parse(value),
                req = new HttpRequest(),
                fields = {},
                resp = '';
        
            // Correspondence between the PagerDuty and Zabbix severity level
            var severityMapping = [
                'info',    // Not classified
                'info',    // Information
                'warning', // Warning
                'warning', // Average
                'error',   // High
                'critical' // Disaster
            ];
        
            if (!severityMapping[params.severity]) {
                params.severity = '0';
            }
        
            if (typeof params.HTTPProxy === 'string' && params.HTTPProxy.trim() !== '') {
                req.setProxy(params.HTTPProxy);
            }
        
            if (isNaN(parseInt(params.eventid)) || params.eventid < 1) {
                throw 'incorrect value for variable "eventid". The value must be a positive number.';
            }
            if (params.eventname.length < 1) {
                throw 'incorrect value for variable "eventname". The value must be a non-empty string.';
            }
            if (isNaN(parseInt(params.severity)) || (params.severity < 0 && params.severity > 5)) {
                throw 'incorrect value for variable "severity". The value must be a number 0..5.';
            }
        
            if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
                throw 'Incorrect "event_source" parameter given: "' + params.event_source + '".\nMust be 0-3.';
            }
            // Check {EVENT.VALUE} for trigger-based and internal events.
            if (params.eventvalue !== '0' && params.eventvalue !== '1'
                && (params.event_source === '0' || params.event_source === '3')) {
                throw 'Incorrect "eventvalue" parameter given: "' + params.eventvalue + '".\nMust be 0 or 1.';
            }
        
            if (params.event_source === '0') {
                if (params.hostname.length < 1) {
                    throw 'incorrect value for variable "hostname". The value must be a non-empty string.';
                }
                if (isNaN(parseInt(params.triggerid)) || params.triggerid < 1) {
                    throw 'incorrect value for variable "triggerid". The value must be a positive number.';
                }
                if (params.eventack != 'Yes' && params.eventack != 'No') {
                    throw 'incorrect value for variable "eventack". The value must be Yes or No.';
                }
                if (isNaN(parseInt(params.eventupdate)) || (params.eventupdate < 0 || params.eventupdate > 1)) {
                    throw 'incorrect value for variable "eventupdate". The value must be 0 or 1.';
                }
            }
        
        
        
            req.addHeader('Content-Type: application/json');
        
            fields.routing_key = params.token;
            fields.dedup_key = params.eventid;
        
            if (((params.eventvalue == 1) && (params.eventupdate == 0)) || params.event_source !== '0') {
                fields.event_action = 'trigger';
                fields.payload = {
                    summary: params.eventname,
                    source: (params.event_source === '1') ? 'Discovery' : params.hostname + ' : ' + params.hostip,
                    severity: severityMapping[params.severity],
                };
                
                if (params.event_source === '0') {
                    fields.payload.custom_details = {
                        'Event date': params.eventdate,
                        'Event time': params.eventtime,
                        'Trigger description': params.triggerdesc,
                        'Trigger opdata': params.triggeropdata,
                        'Event tags': params.eventtags,
                        'Event host': params.hostname,
                        'Event host ip': params.hostip
                    };
                    fields.links = [{
                        href: params.url + '/tr_events.php?triggerid=' + params.triggerid + '&eventid=' + params.eventid,
                        text: 'Event link'
                    }];
                }
                else {
                    fields.payload.custom_details = {
                        'Alert message': params.alert_message
                    };
                }
        
                fields.client = 'Zabbix';
                fields.client_url = params.url;
            }
            else if ((params.eventvalue == 1) && (params.eventupdate == 1) && (params.eventack == 'Yes'))
                fields.event_action = 'acknowledge';
            else if (params.eventvalue == 0)
                fields.event_action = 'resolve';
            else
                throw 'incorrect values. Update message without ack will not be sent.';
        
            Zabbix.log(4, '[PagerDuty Webhook] Sending request:' + JSON.stringify(fields));
            resp = req.post('https://events.pagerduty.com/v2/enqueue',
                JSON.stringify(fields)
            );
            Zabbix.log(4, '[PagerDuty Webhook] Receiving response:' + resp);
        
            try {
                resp = JSON.parse(resp);
            }
            catch (error) {
                throw 'incorrect response. PagerDuty returned a non-JSON object.';
            }
        
            if (req.getStatus() != 202) {
                if (typeof resp === 'object' && typeof resp.errors === 'object' && typeof resp.errors[0] === 'string') {
                    throw resp.errors[0];
                }
                else {
                    throw 'Unknown error.';
                }
            }
        
            if (resp.status != 'success') {
                throw 'Unknown error.';
            }
        
            return 'OK';
        }
        catch (error) {
            Zabbix.log(3, '[PagerDuty Webhook] Notification failed : ' + error);
            throw 'PagerDuty notification failed : ' + error;
        }
      description: |
        Please refer to https://v2.developer.pagerduty.com/docs/send-an-event-events-api-v2 and https://www.zabbix.com/documentation/6.0/manual/config/notifications/media/webhook#example_scripts.
          
        Set global macro {$ZABBIX.URL} with your Zabbix server URL.
        Add a dedicated user with the media type "PagerDuty" and place the integration key in the "token" parameter to integrate into the service.
      message_templates:
        -
          event_source: TRIGGERS
          operation_mode: PROBLEM
          subject: 'Problem: {EVENT.NAME}'
          message: |
            Problem started at {EVENT.TIME} on {EVENT.DATE}
            Problem name: {EVENT.NAME}
            Host: {HOST.NAME}
            Severity: {EVENT.SEVERITY}
            Operational data: {EVENT.OPDATA}
            Original problem ID: {EVENT.ID}
            {TRIGGER.URL}
        -
          event_source: TRIGGERS
          operation_mode: RECOVERY
          subject: 'Resolved in {EVENT.DURATION}: {EVENT.NAME}'
          message: |
            Problem has been resolved at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}
            Problem name: {EVENT.NAME}
            Problem duration: {EVENT.DURATION}
            Host: {HOST.NAME}
            Severity: {EVENT.SEVERITY}
            Original problem ID: {EVENT.ID}
            {TRIGGER.URL}
        -
          event_source: TRIGGERS
          operation_mode: UPDATE
          subject: 'Updated problem in {EVENT.AGE}: {EVENT.NAME}'
          message: |
            {USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.
            {EVENT.UPDATE.MESSAGE}
            
            Current problem status is {EVENT.STATUS}, age is {EVENT.AGE}, acknowledged: {EVENT.ACK.STATUS}.
        -
          event_source: DISCOVERY
          operation_mode: PROBLEM
          subject: 'Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}'
          message: |
            Discovery rule: {DISCOVERY.RULE.NAME}
            
            Device IP: {DISCOVERY.DEVICE.IPADDRESS}
            Device DNS: {DISCOVERY.DEVICE.DNS}
            Device status: {DISCOVERY.DEVICE.STATUS}
            Device uptime: {DISCOVERY.DEVICE.UPTIME}
            
            Device service name: {DISCOVERY.SERVICE.NAME}
            Device service port: {DISCOVERY.SERVICE.PORT}
            Device service status: {DISCOVERY.SERVICE.STATUS}
            Device service uptime: {DISCOVERY.SERVICE.UPTIME}
        -
          event_source: AUTOREGISTRATION
          operation_mode: PROBLEM
          subject: 'Autoregistration: {HOST.HOST}'
          message: |
            Host name: {HOST.HOST}
            Host IP: {HOST.IP}
            Agent port: {HOST.PORT}