@jambonz/time-series 0.2.9 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +5 -0
- package/index.js +42 -1
- package/package.json +1 -1
- package/test/unit-tests.js +3 -0
package/.github/workflows/ci.yml
CHANGED
|
@@ -12,6 +12,11 @@ jobs:
|
|
|
12
12
|
- uses: actions/setup-node@v1
|
|
13
13
|
with:
|
|
14
14
|
node-version: 12
|
|
15
|
+
- name: Install Docker Compose
|
|
16
|
+
run: |
|
|
17
|
+
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
|
18
|
+
sudo chmod +x /usr/local/bin/docker-compose
|
|
19
|
+
docker-compose --version
|
|
15
20
|
- run: npm install
|
|
16
21
|
- run: npm run jslint
|
|
17
22
|
- run: npm test
|
package/index.js
CHANGED
|
@@ -29,6 +29,7 @@ const schemas = {
|
|
|
29
29
|
from: Influx.FieldType.STRING,
|
|
30
30
|
to: Influx.FieldType.STRING,
|
|
31
31
|
sip_callid: Influx.FieldType.STRING,
|
|
32
|
+
sip_parent_callid: Influx.FieldType.STRING,
|
|
32
33
|
sip_status: Influx.FieldType.INTEGER,
|
|
33
34
|
duration: Influx.FieldType.INTEGER,
|
|
34
35
|
terminated_at: Influx.FieldType.INTEGER,
|
|
@@ -88,6 +89,17 @@ const schemas = {
|
|
|
88
89
|
'account_sid',
|
|
89
90
|
'application_sid'
|
|
90
91
|
]
|
|
92
|
+
},
|
|
93
|
+
system_alerts: {
|
|
94
|
+
measurement: 'system_alerts',
|
|
95
|
+
fields: {
|
|
96
|
+
detail: Influx.FieldType.STRING,
|
|
97
|
+
host: Influx.FieldType.STRING
|
|
98
|
+
},
|
|
99
|
+
tags: [
|
|
100
|
+
'system_component',
|
|
101
|
+
'state'
|
|
102
|
+
]
|
|
91
103
|
}
|
|
92
104
|
};
|
|
93
105
|
|
|
@@ -494,6 +506,25 @@ const writeCdrs = async(client, cdrs) => {
|
|
|
494
506
|
return;
|
|
495
507
|
};
|
|
496
508
|
|
|
509
|
+
const writeSystemAlerts = async(client, systemAlerts) => {
|
|
510
|
+
if (!client.locals.initialized) await initDatabase(client, 'system_alerts');
|
|
511
|
+
systemAlerts = (Array.isArray(systemAlerts) ? systemAlerts : [systemAlerts])
|
|
512
|
+
.map((systemAlert) => {
|
|
513
|
+
const {system_component, state, fields} = systemAlert;
|
|
514
|
+
return {
|
|
515
|
+
measurement: 'system_alerts',
|
|
516
|
+
timestamp: new Date(),
|
|
517
|
+
fields,
|
|
518
|
+
tags: {
|
|
519
|
+
system_component,
|
|
520
|
+
state
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
});
|
|
524
|
+
client.locals.data = [...client.locals.data, ...systemAlerts];
|
|
525
|
+
await writeData(client);
|
|
526
|
+
return;
|
|
527
|
+
};
|
|
497
528
|
const queryCdrsSP = async(client, opts) => {
|
|
498
529
|
if (!client.locals.initialized) await initDatabase(client, 'cdrs');
|
|
499
530
|
const response = {
|
|
@@ -734,12 +765,13 @@ module.exports = (logger, opts) => {
|
|
|
734
765
|
if (typeof opts === 'string') opts = {host: opts};
|
|
735
766
|
assert(opts.host);
|
|
736
767
|
|
|
737
|
-
const cdrClient = new Influx.InfluxDB({database: 'cdrs', schemas: schemas.
|
|
768
|
+
const cdrClient = new Influx.InfluxDB({database: 'cdrs', schemas: schemas.cdrs, ...opts});
|
|
738
769
|
const alertClient = new Influx.InfluxDB({database: 'alerts', schemas: schemas.alerts, ...opts});
|
|
739
770
|
const callCountClient = new Influx.InfluxDB({database: 'call_counts', schemas: schemas.call_counts, ...opts});
|
|
740
771
|
const callCountSPClient = new Influx.InfluxDB({database: 'sp_call_counts', schemas: schemas.sp_call_counts, ...opts});
|
|
741
772
|
// eslint-disable-next-line max-len
|
|
742
773
|
const callCountAppClient = new Influx.InfluxDB({database: 'app_call_counts', schemas: schemas.app_call_counts, ...opts});
|
|
774
|
+
const systemAlertClient = new Influx.InfluxDB({database: 'system_alerts', schemas: schemas.system_alerts, ...opts});
|
|
743
775
|
|
|
744
776
|
cdrClient.locals = {
|
|
745
777
|
db: 'cdrs',
|
|
@@ -781,6 +813,14 @@ module.exports = (logger, opts) => {
|
|
|
781
813
|
commitInterval: opts.commitInterval || 10,
|
|
782
814
|
data: []
|
|
783
815
|
};
|
|
816
|
+
systemAlertClient.locals = {
|
|
817
|
+
db: 'system_alerts',
|
|
818
|
+
initialized: false,
|
|
819
|
+
writing: false,
|
|
820
|
+
commitSize: opts.commitSize || 1,
|
|
821
|
+
commitInterval: opts.commitInterval || 10,
|
|
822
|
+
data: []
|
|
823
|
+
};
|
|
784
824
|
|
|
785
825
|
if (opts.commitSize > 1 && opts.commitInterval && opts.commitInterval > 2) {
|
|
786
826
|
setInterval(writeData.bind(null, callCountClient), opts.commitInterval * 1000);
|
|
@@ -803,6 +843,7 @@ module.exports = (logger, opts) => {
|
|
|
803
843
|
writeAlerts: writeAlerts.bind(null, alertClient),
|
|
804
844
|
queryAlerts: queryAlerts.bind(null, alertClient),
|
|
805
845
|
queryAlertsSP: queryAlertsSP.bind(null, alertClient),
|
|
846
|
+
writeSystemAlerts: writeSystemAlerts.bind(null, systemAlertClient),
|
|
806
847
|
AlertType: { ...AlertType }
|
|
807
848
|
};
|
|
808
849
|
};
|
package/package.json
CHANGED
package/test/unit-tests.js
CHANGED
|
@@ -23,6 +23,7 @@ test('write timeseries data', async(t) => {
|
|
|
23
23
|
from: 'me',
|
|
24
24
|
to: 'you',
|
|
25
25
|
sip_callid: 'foo@127.0.0.1',
|
|
26
|
+
sip_parent_callid: 'foo2@127.0.0.1',
|
|
26
27
|
answered: true,
|
|
27
28
|
duration: 22,
|
|
28
29
|
attempted_at: new Date(Date.now() - (3600 * 1000)),
|
|
@@ -41,6 +42,7 @@ test('write timeseries data', async(t) => {
|
|
|
41
42
|
from: 'me2',
|
|
42
43
|
to: 'you2',
|
|
43
44
|
sip_callid: 'foo@127.0.0.1',
|
|
45
|
+
sip_parent_callid: 'foo2@127.0.0.1',
|
|
44
46
|
answered: false,
|
|
45
47
|
duration: 20,
|
|
46
48
|
attempted_at: new Date(Date.now() - (7200 * 1000)),
|
|
@@ -61,6 +63,7 @@ test('write timeseries data', async(t) => {
|
|
|
61
63
|
result = await queryCdrs({account_sid: 'xxxx', page: 1, page_size:25});
|
|
62
64
|
//console.log(JSON.stringify(result));
|
|
63
65
|
t.ok(result.data.length === 1, 'queried cdrs by account sid');
|
|
66
|
+
t.ok(result.data[0].sip_parent_callid === 'foo2@127.0.0.1', 'sip_parent_callid successfully added');
|
|
64
67
|
|
|
65
68
|
result = await queryCdrs({account_sid: 'xxxx', filter: 'a', page: 1, page_size:25});
|
|
66
69
|
t.ok(result.data.length === 0, 'queried cdrs by from');
|