-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
109 lines (94 loc) · 2.35 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
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
'use strict';
const constants = require('haraka-constants');
const syslog = require('modern-syslog');
exports.register = function () {
const plugin = this;
let options = 0;
plugin.load_syslog_ini();
const name = plugin.cfg.general.name || 'haraka';
let facility = plugin.cfg.general.facility || 'MAIL';
['pid','odelay','cons','ndelay','nowait'].forEach(opt => {
if (!plugin.cfg.general[opt]) return;
options |= syslog[`LOG_${ opt.toUpperCase()}` ];
})
if (facility !== facility.toUpperCase()) facility = facility.toUpperCase();
switch (facility) {
case 'MAIL':
case 'KERN':
case 'USER':
case 'DAEMON':
case 'AUTH':
case 'SYSLOG':
case 'LPR':
case 'NEWS':
case 'UUCP':
case 'LOCAL0':
case 'LOCAL1':
case 'LOCAL2':
case 'LOCAL3':
case 'LOCAL4':
case 'LOCAL5':
case 'LOCAL6':
case 'LOCAL7':
syslog.init(name, options, syslog[ `LOG_${ facility}` ]);
break;
default:
syslog.init(name, options, syslog.LOG_MAIL);
}
plugin.register_hook('log', 'syslog');
};
exports.load_syslog_ini = function () {
const plugin = this;
plugin.cfg = plugin.config.get('syslog.ini', {
booleans: [
'+general.pid',
'+general.odelay',
'-general.cons',
'-general.ndelay',
'-general.nowait',
'-general.always_ok',
],
},
function () {
plugin.load_syslog_ini();
})
if (!plugin.cfg.general) plugin.cfg.general = {};
}
exports.syslog = function (next, logger, log) {
const plugin = this;
switch (log.level.toUpperCase()) {
case 'INFO':
syslog.log(syslog.LOG_INFO, log.data);
break;
case 'NOTICE':
syslog.log(syslog.LOG_NOTICE, log.data);
break;
case 'WARN':
syslog.log(syslog.LOG_WARNING, log.data);
break;
case 'ERROR':
syslog.log(syslog.LOG_ERR, log.data);
break;
case 'CRIT':
syslog.log(syslog.LOG_CRIT, log.data);
break;
case 'ALERT':
syslog.log(syslog.LOG_ALERT, log.data);
break;
case 'EMERG':
syslog.log(syslog.LOG_EMERG, log.data);
break;
case 'DATA':
case 'PROTOCOL':
case 'DEBUG':
syslog.log(syslog.LOG_DEBUG, log.data);
break;
default:
syslog.log(syslog.LOG_DEBUG, log.data);
}
if (plugin.cfg.general.always_ok) {
next(constants.OK);
return;
}
next();
};