1
1
zabbix_export :
2
- version : " 6.2"
3
- date : " 2023-02-02T10:51:24Z "
2
+ version : ' 6.2'
3
+ date : ' 2023-02-24T12:26:54Z '
4
4
template_groups :
5
5
- uuid : a571c0d144b14fd4a87a9d9b2aa9fcd6
6
6
name : Templates/Applications
7
7
templates :
8
8
- uuid : 98a83193b39340adaf9c5b8f5de945bc
9
- template : " CPM Backup"
10
- name : " CPM Backup"
9
+ template : ' T_App_CPM Backup'
10
+ name : ' T_App_CPM Backup'
11
11
description : |
12
12
This template will add items to monitor the CPM backup tool via its API.
13
-
13
+
14
+ Monitoring has been tested on N2WS CPM Bacup 4.1.1a
15
+
14
16
MACROS:
15
17
* This template adds 2 macros to the hosts: {$API_KEY} and {$CPM_URL}}
16
18
!Make sure you update the Macros' values in the associated hosts!
17
-
19
+
18
20
REQUIREMENTS
19
21
* Zabbix server must have network connectivity to the CPM backup server
20
22
* Zabbix server must have HTTP/S access to the CPM backup server
21
23
groups :
22
24
- name : Templates/Applications
23
25
items :
24
26
- uuid : d551af8f9cbf4a37a8e1a5c6a00db24e
25
- name : " Number of errors in CPM"
27
+ name : ' Number of errors in CPM'
26
28
type : SCRIPT
27
29
key : cpm.errors
28
30
delay : 1h
29
- trends : " 0 "
31
+ trends : ' 0 '
30
32
value_type : TEXT
31
33
params : |
32
34
try {
@@ -35,65 +37,139 @@ zabbix_export:
35
37
api_key = params.api_key;
36
38
cpm_url = params.endpoint;
37
39
var type = params.count_type;
38
-
40
+
39
41
// Set the data as the api_key
40
42
var data = 'api_key=' + api_key;
41
43
var alerts = 0;
42
-
44
+
43
45
// Create a new HttpRequest
44
46
req = new HttpRequest();
45
-
47
+
46
48
// Add the header
47
49
req.addHeader('Accept: application/json; version=1.0');
48
-
50
+
49
51
// Request the access token
50
52
auth_response = req.post(cpm_url + '/api/token/obtain/api_key/', data);
51
-
53
+
52
54
// Parses the response to get the access token
53
55
json_obj = JSON.parse(auth_response);
54
56
access_token = json_obj['access'];
55
-
57
+
56
58
// Add the access token to the headers
57
59
req.addHeader('Authorization: Bearer ' + access_token);
58
-
60
+
59
61
// Retrieve the alerts from CPM Backup api
60
62
response = req.get(cpm_url + '/api/alerts/');
61
-
63
+ //return response.length;
64
+
62
65
// Parse response as JSON and retrieve the list of alerts
63
66
alerts_list = JSON.parse(response);
64
-
67
+
65
68
// Check if the list contains any alerts
66
69
if (alerts_list.length > 0) {
67
70
// If the list contains alerts, iterate through the list
68
71
for (i = 0; i < alerts_list.length; i++) {
69
72
// Check if the alert contains "error" or "warning"
70
- if (alerts_list[i].toLowerCase().includes(type.toLowerCase())) {
71
- // Adds 1 to the alerts counter
72
- alerts++;
73
+ if (alerts_list[i].severity. toLowerCase().includes(type.toLowerCase())) {
74
+ // Adds 1 to the alerts counter
75
+ alerts++;
73
76
}
74
- }
77
+ }
75
78
}
76
79
} catch (error) {
77
- Zabbix.log(4 , 'Failed accessing CPM Backup API: ' + error);
80
+ Zabbix.log(1 , 'Failed accessing CPM Backup API: ' + error);
78
81
alerts = -1;
82
+ // return error;
79
83
}
80
-
84
+
81
85
// Return number of alerts
82
86
return alerts;
83
87
timeout : 5s
84
88
parameters :
85
89
- name : api_key
86
- value : " {$API_KEY}"
90
+ value : ' {$API_KEY}'
87
91
- name : endpoint
88
- value : " {$CPM_URL}"
92
+ value : ' {$CPM_URL}'
89
93
- name : count_type
90
- value : error
94
+ value : E
95
+ - uuid : 0191ed4b836041a383aa87fe84fcbe16
96
+ name : ' Number of information in CPM'
97
+ type : SCRIPT
98
+ key : cpm.info
99
+ delay : 1h
100
+ trends : ' 0'
101
+ value_type : CHAR
102
+ params : |
103
+ try {
104
+ // Retrieve parameters defined in the Zabbix item
105
+ var params = JSON.parse(value);
106
+ api_key = params.api_key;
107
+ cpm_url = params.endpoint;
108
+ var type = params.count_type;
109
+
110
+ // Set the data as the api_key
111
+ var data = 'api_key=' + api_key;
112
+ var alerts = 0;
113
+
114
+ // Create a new HttpRequest
115
+ req = new HttpRequest();
116
+
117
+ // Add the header
118
+ req.addHeader('Accept: application/json; version=1.0');
119
+
120
+ // Request the access token
121
+ auth_response = req.post(cpm_url + '/api/token/obtain/api_key/', data);
122
+
123
+ // Parses the response to get the access token
124
+ json_obj = JSON.parse(auth_response);
125
+ access_token = json_obj['access'];
126
+
127
+ // Add the access token to the headers
128
+ req.addHeader('Authorization: Bearer ' + access_token);
129
+
130
+ // Retrieve the alerts from CPM Backup API
131
+ response = req.get(cpm_url + '/api/alerts/');
132
+ //return response.length;
133
+
134
+ // Parse response as JSON and retrieve the list of alerts
135
+ alerts_list = JSON.parse(response);
136
+
137
+ // Check if the list contains any alerts
138
+ if (alerts_list.length > 0) {
139
+ // If the list contains alerts iterate through the list
140
+ for (i = 0; i < alerts_list.length; i++) {
141
+ // Check if the alert contains an "error" or "warning"
142
+ if (alerts_list[i].severity.toLowerCase().includes(type.toLowerCase())) {
143
+ // Adds 1 to the alerts counter
144
+ alerts++;
145
+ }
146
+ }
147
+ }
148
+ } catch (error) {
149
+ Zabbix.log(1, 'Failed accessing CPM Backup API: ' + error);
150
+ alerts = -1;
151
+ // return error;
152
+ }
153
+
154
+ // Return the number of alerts
155
+ return alerts;
156
+ description : |
157
+ Obtain the number of "Information" notifications from CPM Backup API.
158
+
159
+ Make sure you set the {$API_KEY} and {$CPM_URL} macros accordingly.
160
+ parameters :
161
+ - name : api_key
162
+ value : ' {$API_KEY}'
163
+ - name : count_type
164
+ value : I
165
+ - name : endpoint
166
+ value : ' {$CPM_URL}'
91
167
- uuid : 460d3a3e19fc4390a479f68c7c537d68
92
- name : " Number of warnings in CPM"
168
+ name : ' Number of warnings in CPM'
93
169
type : SCRIPT
94
170
key : cpm.warning
95
171
delay : 1h
96
- trends : " 0 "
172
+ trends : ' 0 '
97
173
value_type : TEXT
98
174
params : |
99
175
try {
@@ -102,62 +178,64 @@ zabbix_export:
102
178
api_key = params.api_key;
103
179
cpm_url = params.endpoint;
104
180
var type = params.count_type;
105
-
181
+
106
182
// Set the data as the api_key
107
183
var data = 'api_key=' + api_key;
108
184
var alerts = 0;
109
-
185
+
110
186
// Create a new HttpRequest
111
187
req = new HttpRequest();
112
-
188
+
113
189
// Add the header
114
190
req.addHeader('Accept: application/json; version=1.0');
115
-
191
+
116
192
// Request the access token
117
193
auth_response = req.post(cpm_url + '/api/token/obtain/api_key/', data);
118
-
194
+
119
195
// Parses the response to get the access token
120
196
json_obj = JSON.parse(auth_response);
121
197
access_token = json_obj['access'];
122
-
198
+
123
199
// Add the access token to the headers
124
200
req.addHeader('Authorization: Bearer ' + access_token);
125
-
201
+
126
202
// Retrieve the alerts from CPM Backup api
127
203
response = req.get(cpm_url + '/api/alerts/');
128
-
204
+ //return response.length;
205
+
129
206
// Parse response as JSON and retrieve the list of alerts
130
207
alerts_list = JSON.parse(response);
131
-
208
+
132
209
// Check if the list contains any alerts
133
210
if (alerts_list.length > 0) {
134
- // If the list contains alerts, iterates through the list
211
+ // If the list contains alerts, iterate through the list
135
212
for (i = 0; i < alerts_list.length; i++) {
136
213
// Check if the alert contains "error" or "warning"
137
- if (alerts_list[i].toLowerCase().includes(type.toLowerCase())) {
138
- // Adds 1 to the alerts counter
139
- alerts++;
214
+ if (alerts_list[i].severity. toLowerCase().includes(type.toLowerCase())) {
215
+ // Adds 1 to the alerts counter
216
+ alerts++;
140
217
}
141
- }
218
+ }
142
219
}
143
220
} catch (error) {
144
- Zabbix.log(4 , 'Failed accessing CPM Backup API: ' + error);
221
+ Zabbix.log(1 , 'Failed accessing CPM Backup API: ' + error);
145
222
alerts = -1;
223
+ // return error;
146
224
}
147
-
225
+
148
226
// Return number of alerts
149
227
return alerts;
150
228
timeout : 5s
151
229
parameters :
152
230
- name : api_key
153
- value : " {$API_KEY}"
231
+ value : ' {$API_KEY}'
154
232
- name : count_type
155
- value : warning
233
+ value : W
156
234
- name : endpoint
157
- value : " {$CPM_URL}"
235
+ value : ' {$CPM_URL}'
158
236
macros :
159
- - macro : " {$API_KEY}"
237
+ - macro : ' {$API_KEY}'
160
238
type : SECRET_TEXT
161
- description : " The CPM Backup API key. Refer to CPM documentation on how to obtain the API key,"
162
- - macro : " {$CPM_URL}"
163
- description : " The CPM Backup endpoint URL (e.g., https://cpmbackup .mydomain.com)"
239
+ description : ' The CPM Backup API key. Refer to CPM documentation on how to obtain the API key,'
240
+ - macro : ' {$CPM_URL}'
241
+ description : ' The CPM Backup endpoint URL (e.g., https://backup .mydomain.com)'
0 commit comments