This repository has been archived by the owner on May 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (72 loc) · 3.3 KB
/
index.js
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
/**
* icinga2-burrow-plugin
* Copyright (C) 2020 e.GO Digital GmbH, Aachen, Germany
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
function checkExcludedConsumers(consumer) {
if (argv._[3] && argv._[3].length > 0) {
const excludedConsumers = argv._[3].split(',');
for (let h = 0; h < excludedConsumers.length; h++) {
const excludedConsumer = excludedConsumers[h];
if (excludedConsumer === consumer) {
return true;
}
}
return false;
} else {
return false;
}
}
var argv = require('minimist')(process.argv.slice(2));
if (argv._.length < 3) {
console.error('The script needs three mandatory parameters: 1. Burrow API Base URL e.g. http://1.2.3.4:9991/v3, 2. Warning threshold, 3. Critical threshold (Optional: 4. Excluded consumers)');
process.exit(2);
} else {
const burrowBaseUrl = argv._[0];
const axios = require('axios');
let totalLag = 0;
(async () => {
try {
const clustersResponse = await axios.get(burrowBaseUrl + '/kafka')
for (let i = 0; i < clustersResponse.data.clusters.length; i++) {
const cluster = clustersResponse.data.clusters[i];
const consumersResponse = await axios.get(burrowBaseUrl + '/kafka/' + cluster + '/consumer');
for (let j = 0; j < consumersResponse.data.consumers.length; j++) {
const consumer = consumersResponse.data.consumers[j];
const lagResponse = await axios.get(burrowBaseUrl + '/kafka/' + cluster + '/consumer/' + consumer + '/lag');
if (!checkExcludedConsumers(consumer)) {
totalLag += lagResponse.data.status.totallag;
}
}
}
const warningThreshold = argv._[1];
const errorThreshold = argv._[2];
if (totalLag >= errorThreshold) {
console.log('CRITICAL - The total lag of unread messages is currently ' + totalLag + ' and above ' + errorThreshold + '|totalLag=' + totalLag);
process.exit(2);
} else if (totalLag >= warningThreshold) {
console.log('WARNING - The total lag of unread messages is currently ' + totalLag + ' and above ' + warningThreshold + '|totalLag=' + totalLag);
process.exit(1);
} else {
console.log('OK - The total lag of unread messages is ' + totalLag + '|totalLag=' + totalLag);
process.exit(0);
}
} catch (error) {
if (error && error.response && error.response.status && error.response.status !== 404) {
console.log('CRITICAL - An error occurred: ' + error);
process.exit(2);
}
}
})();
}