forked from cuttlefish-uk/alertd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotify.js
47 lines (41 loc) · 1.15 KB
/
notify.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
var email = require('emailjs')
, url = require('url')
, util = require('util')
, Prowl
try {
Prowl = require('node-prowl/lib')
}
catch(e) {}
exports.console = function(contact, value, level, error) {
util.log(level + ': ' + error);
};
exports.email = function(contact, value, level, error) {
var to = contact.email;
if (util.isArray(to)) {
to = to.join(', ');
}
var server = email.server.connect({
"host": "localhost"
});
server.send({
"text": error + "\n\n" + (new Date),
"subject": level + ': ' + this.name,
"from": "servers@cuttlefish.com",
"to": to
}, function(err, message) { console.log(err || (new Date) + ' ' + level + ' sent to ' + to); });
};
exports.prowl = function(contact, value, level, error) {
if (!Prowl) {
console.log("node-prowl module not available");
return;
}
var key = contact.api_key;
var prowl = new Prowl(key);
prowl.push(level + ': ' + this.name, this.app_config.application_name||'alertd', {
priority: (level === 'critical' ? 2 : 0),
url: this.config.url ? this.config.url : null,
description: error
}, function(err, res) {
if (err) console.log(err);
});
};