-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
filter_app_sonuslog.js
122 lines (108 loc) · 3.97 KB
/
filter_app_sonuslog.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
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
Custom, Unoptimized Sonus Log to SIP/HEP3 Parser w/ reassembly of rows
(C) 2020 QXIP BV
*/
var base_filter = require('@pastash/pastash').base_filter,
util = require('util'),
logger = require('@pastash/pastash').logger;
var moment = require('moment');
function FilterAppSonusLog() {
base_filter.BaseFilter.call(this);
this.mergeConfig({
name: 'AppSonusLog',
optional_params: ['correlation_hdr','type'],
default_values: {
'correlation_hdr': false,
'type': 0
},
start_hook: this.start,
});
}
util.inherits(FilterAppSonusLog, base_filter.BaseFilter);
FilterAppSonusLog.prototype.start = function(callback) {
logger.info('Initialized App Sonus SysLog to SIP/HEP parser');
this.postProcess = function(){
if(!last||!ipcache) return;
var rcinfo = {
type: 'HEP',
version: 3,
payload_type: 1,
ip_family: 2,
protocol: 17,
proto_type: 1,
correlation_id: ipcache.callId || '',
srcIp: ipcache.srcIp,
srcPort: ipcache.srcPort,
dstIp: ipcache.dstIp,
dstPort: ipcache.dstPort,
time_sec: ipcache.ts || new Date().getTime(),
time_usec: ipcache.usec || 000
};
// EXTRACT CORRELATION HEADER, IF ANY
/*
if (this.correlation_hdr) {
var xcid = sip.match(this.correlation_hdr+":\s?(.*)\\r");
if (xcid && xcid[1]) rcinfo.correlation_id = xcid[1].trim();
}
*/
if (last.indexOf('2.0/TCP') !== -1 || last.indexOf('2.0/TLS') !== -1){
rcinfo.protocol = 6;
}
if (last && rcinfo) {
var data = { payload: last, rcinfo: rcinfo };
this.emit('output', data);
last = '';
ipcache = {};
}
}
callback();
};
var last = '';
var ipcache = {};
FilterAppSonusLog.prototype.process = function(data) {
var line = data.message;
if (line.indexOf('sent msg for CallId') !== -1) {
var regex = /<147> [0-9] (.*)(?:usec| USEC)(.*?)sent msg for CallId:(.*) to IP\/port:(.*)\/(.*), Local IP\/port:(.*)\/(.*), SMM:(.*)RAW PDU:#012(.*)(<147>)?/g;
if (this.type == 1) regex = /.*<147> [0-9] (\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d?\.\d+?[+-]\d\d:\d\d|Z) (.*)msg for CallId:(.*) to IP\/port:(.*)\/(.*), Local IP\/port:(.*)\/(.*), SMM:(.*)#012.*RAW PDU:#012(.*)(<147>)?/g;
var ip = regex.exec(line);
if (!ip) { logger.error(line); return; }
ipcache = {};
ipcache.srcIp = ip[6];
ipcache.srcPort = ip[7];
ipcache.dstIp = ip[4];
ipcache.dstPort = ip[5];
ipcache.callId = ip[3];
ipcache.group = ip[8];
ipcache.ts = parseInt(new Date(ip[1].trim()).getTime()/1000);
ipcache.usec = parseInt(ip[1].split('.')[1])
last = ip[9];
last = last.replace(/#015#012/g, '\r\n');
last = last.replace(/#012/g, '\r\n');
last += '\r\n';
logger.info('out',ipcache);
this.postProcess();
} else if (line.indexOf('received msg for CallId') !== -1) {
var regex = /<147> [0-9] (.*)(?:usec| USEC)(.*?)received msg for CallId:(.*) from IP\/port:(.*)\/(.*), Local IP\/port:(.*)\/(.*), SMM:(.*)RAW PDU:#012(.*)(<147>)?/g;
if (this.type == 1) regex = /.*<147> [0-9] (\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d?\.\d+?[+-]\d\d:\d\d|Z) (.*)msg for CallId:(.*) from IP\/port:(.*)\/(.*), Local IP\/port:(.*)\/(.*), SMM:(.*)#012.*RAW PDU:#012(.*)(<147>)?/g;
var ip = regex.exec(line);
if (!ip) { logger.error(line); return; }
logger.log('receive',ipcache);
ipcache.srcIp = ip[4];
ipcache.srcPort = ip[5];
ipcache.dstIp = ip[6];
ipcache.dstPort = ip[7];
ipcache.callId = ip[3];
ipcache.group = ip[8];
ipcache.ts = parseInt(new Date(ip[1].trim()).getTime()/1000);
ipcache.usec = parseInt(ip[1].split('.')[1])
last = ip[9];
last = last.replace(/#015#012/g, '\r\n');
last = last.replace(/#012/g, '\r\n');
last += '\r\n';
logger.info('out',ipcache);
this.postProcess();
}
};
exports.create = function() {
return new FilterAppSonusLog();
};