forked from cuttlefish-uk/alertd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecks.js
71 lines (65 loc) · 2.49 KB
/
checks.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
exports.http = function(res, on_error) {
var statusCode = this.config.statusCode === undefined ? 200 : this.config.statusCode;
if (res.statusCode !== statusCode) {
return on_error('critical', this.name + " response: " + res.statusCode + ' (expected ' + statusCode + ')');
}
if (this.config.bodyMatch !== undefined) {
if (!res.body.match(this.config.bodyMatch)) {
return on_error('critical', this.name + " body doesn't match " + this.config.bodyMatch);
}
}
if (this.config.duration !== undefined && res.duration / 1000 >= this.config.duration) {
return on_error('warning', this.name + " took " + (res.duration / 1000) + "s (warning at " + this.config.duration + "s)");
}
on_error('ok', this.name + ' ok');
};
exports.http_200 = function(res, on_error) {
if (res.statusCode === 200) {
on_error('ok', this.name + " response: " + res.statusCode);
}
else {
on_error('critical', this.name + " response: " + res.statusCode);
}
};
exports.value_over = function(res, on_error) {
if (typeof this.config.critical !== undefined) {
if (res > this.config.critical) {
return on_error('critical', this.name + ' is ' + res + ' (has exceeded ' + this.config.critical + ')');
}
}
if (typeof this.config.warning !== undefined) {
if (res > this.config.warning) {
return on_error('warning', this.name + ' is ' + res + ' (has exceeded ' + this.config.warning + ')');
}
}
on_error('ok', this.name + ' ok');
};
exports.value_gt = exports.value_over;
exports.value_under = function(res, on_error) {
if (typeof this.config.critical !== undefined) {
if (res < this.config.critical) {
return on_error('critical', this.name + ' is ' + res + ' (has fallen below ' + this.config.critical + ')');
}
}
if (typeof this.config.warning !== undefined) {
if (res < this.config.warning) {
return on_error('warning', this.name + ' is ' + res + ' (has fallen below ' + this.config.warning + ')');
}
}
on_error('ok', this.name + ' ok');
};
exports.value_lt = exports.value_under;
exports.value_equal = function(res, on_error) {
if (typeof this.config.critical !== undefined) {
if (res == this.config.critical) {
return on_error('critical', this.name + ' is ' + this.config.critical);
}
}
if (typeof this.config.warning !== undefined) {
if (res == this.config.warning) {
return on_error('warning', this.name + ' is ' + this.config.warning);
}
}
on_error('ok', this.name + ' ok');
};
exports.value_eq = exports.value_equal;