forked from Viber/build-a-bot-with-zero-coding
-
Notifications
You must be signed in to change notification settings - Fork 1
/
media_viber.xml
170 lines (170 loc) · 6.72 KB
/
media_viber.xml
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
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>5.0</version>
<date>2021-07-09T11:36:08Z</date>
<media_types>
<media_type>
<name>Viber webhook</name>
<type>WEBHOOK</type>
<parameters>
<parameter>
<name>Message</name>
<value>{ALERT.MESSAGE}</value>
</parameter>
<parameter>
<name>Subject</name>
<value>{ALERT.SUBJECT}</value>
</parameter>
<parameter>
<name>To</name>
<value>{ALERT.SENDTO}</value>
</parameter>
<parameter>
<name>Token</name>
<value>your-auth-token</value>
</parameter>
</parameters>
<attempts>10</attempts>
<script>var Viber = {
token: null,
to: null,
message: null,
proxy: null,
sendMessage: function() {
var params = {
auth_token: Viber.token,
receiver: Viber.to,
'sender.name': 'alerter',
type: 'text',
text: Viber.message,
},
data,
response,
request = new CurlHttpRequest(),
url = 'https://chatapi.viber.com/pa/send_message';
if (Viber.proxy) {
request.SetProxy(Viber.proxy);
}
request.AddHeader('Content-Type: application/json');
data = JSON.stringify(params);
// Remove replace() function if you want to see the exposed token in the log file.
Zabbix.Log(4, '[Viber Webhook] URL: ' + url.replace(Viber.token, '<TOKEN>'));
Zabbix.Log(4, '[Viber Webhook] params: ' + data);
response = request.Post(url, data);
Zabbix.Log(4, '[Viber Webhook] HTTP code: ' + request.Status());
try {
response = JSON.parse(response);
}
catch (error) {
response = null;
}
if (request.Status() !== 200 || response.status !== 0 || response.status_message !== 'ok') {
if (typeof response.status_message === 'string') {
throw response.status_message;
}
else {
throw 'Unknown error. Check debug log for more information.'
}
}
}
}
try {
var params = JSON.parse(value);
if (typeof params.Token === 'undefined') {
throw 'Incorrect value is given for parameter "Token": parameter is missing';
}
Viber.token = params.Token;
if (params.HTTPProxy) {
Viber.proxy = params.HTTPProxy;
}
Viber.to = params.To;
Viber.message = params.Subject + '\n' + params.Message;
Viber.sendMessage();
return 'OK';
}
catch (error) {
Zabbix.Log(4, '[Viber Webhook] notification failed: ' + error);
throw 'Sending failed: ' + error + '.';
}</script>
<timeout>10s</timeout>
<description>See https://github.com/who0ps/build-a-bot-with-zero-coding/blob/master/README-ZBX.md for instructions.
Special thanks to https://github.com/vladislav805</description>
<message_templates>
<message_template>
<event_source>TRIGGERS</event_source>
<operation_mode>PROBLEM</operation_mode>
<subject>`{HOST.NAME}` {EVENT.NAME}</subject>
<message>❌Problem started at {EVENT.TIME} on {EVENT.DATE}
Operational data: {EVENT.OPDATA}</message>
</message_template>
<message_template>
<event_source>TRIGGERS</event_source>
<operation_mode>RECOVERY</operation_mode>
<subject>`{HOST.NAME}` {EVENT.RECOVERY.NAME} - resolved in {EVENT.DURATION}</subject>
<message>✅Problem started at {EVENT.TIME} on {EVENT.DATE} and resolved at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}
Operational data: {EVENT.OPDATA}</message>
</message_template>
<message_template>
<event_source>TRIGGERS</event_source>
<operation_mode>UPDATE</operation_mode>
<subject>`{HOST.NAME}` {EVENT.NAME}</subject>
<message>☑️{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.
_{EVENT.UPDATE.MESSAGE}_
Current problem status is {EVENT.STATUS}, acknowledged: {EVENT.ACK.STATUS}.</message>
</message_template>
<message_template>
<event_source>DISCOVERY</event_source>
<operation_mode>PROBLEM</operation_mode>
<subject>Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}</subject>
<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}</message>
</message_template>
<message_template>
<event_source>AUTOREGISTRATION</event_source>
<operation_mode>PROBLEM</operation_mode>
<subject>Autoregistration: {HOST.HOST}</subject>
<message>Host name: {HOST.HOST}
Host IP: {HOST.IP}
Agent port: {HOST.PORT}</message>
</message_template>
<message_template>
<event_source>INTERNAL</event_source>
<operation_mode>PROBLEM</operation_mode>
<subject>State: {ITEM.STATE}</subject>
<message>Host: {HOST.NAME}
Item: {ITEM.NAME}
</message>
</message_template>
<message_template>
<event_source>INTERNAL</event_source>
<operation_mode>RECOVERY</operation_mode>
<subject>State: {ITEM.STATE}</subject>
<message>Host: {HOST.NAME}
Item: {ITEM.NAME}</message>
</message_template>
</message_templates>
</media_type>
</media_types>
</zabbix_export>