forked from EmmaXin/log_agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
46 lines (39 loc) · 1.19 KB
/
Copy pathclient.js
File metadata and controls
46 lines (39 loc) · 1.19 KB
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
'use strict';
var program = require('commander');
var syslog = require("syslog-client");
program
.version('0.0.1')
.option('--address <n>', 'IP address', '127.0.0.1')
.option('--port <n>', 'port number', 514)
.option('--tag <n>', 'tag', 'snmp')
.option('--message <n>', 'message', 'VLAN 1 link-down notification')
.option('--facility <n>', 'facility number', 16)
.option('--severity <n>', 'level (emerg | alert | crit | err | warning | notice | info | debug)',
/^([0-7]|emerg|alert|crit|err|warning|notice|info|debug)$/i, 'info')
.parse(process.argv);
var client = syslog.createClient(program.host, {port: program.port});
var severity = {
'0': 0,
'1': 1,
'2': 2,
'3': 3,
'4': 4,
'5': 5,
'6': 6,
'7': 7,
'emerg': 0,
'alert': 1,
'crit': 2,
'err': 3,
'warning': 4,
'notice': 5,
'info': 6,
'debug': 7
};
// Message:
// <190>Sep 22 9:51:41 192.168.137.55/24 snmp: VLAN 1 link-down notification.
// <190>Sep 22 9:51:49 192.168.137.55/24 snmp: Unit 1, Port 3 link-up notification.
client.log(program.tag + ': ' + program.message, {
facility: program.facility,
severity: severity[program.severity]
});