@jambonz/time-series 0.2.10 → 0.2.12
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/index.js +45 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -17,7 +17,8 @@ const AlertType = {
|
|
|
17
17
|
SP_CALL_LIMIT: 'service-provider-call-limit',
|
|
18
18
|
SP_DEVICE_LIMIT: 'service-provider-device-limit',
|
|
19
19
|
SP_API_LIMIT: 'service-provider-api-limit',
|
|
20
|
-
ACCOUNT_INACTIVE: 'account is inactive or suspended'
|
|
20
|
+
ACCOUNT_INACTIVE: 'account is inactive or suspended',
|
|
21
|
+
PLAY_FILENOTFOUND: 'play-url-notfound'
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
const schemas = {
|
|
@@ -89,6 +90,17 @@ const schemas = {
|
|
|
89
90
|
'account_sid',
|
|
90
91
|
'application_sid'
|
|
91
92
|
]
|
|
93
|
+
},
|
|
94
|
+
system_alerts: {
|
|
95
|
+
measurement: 'system_alerts',
|
|
96
|
+
fields: {
|
|
97
|
+
detail: Influx.FieldType.STRING,
|
|
98
|
+
host: Influx.FieldType.STRING
|
|
99
|
+
},
|
|
100
|
+
tags: [
|
|
101
|
+
'system_component',
|
|
102
|
+
'state'
|
|
103
|
+
]
|
|
92
104
|
}
|
|
93
105
|
};
|
|
94
106
|
|
|
@@ -495,6 +507,25 @@ const writeCdrs = async(client, cdrs) => {
|
|
|
495
507
|
return;
|
|
496
508
|
};
|
|
497
509
|
|
|
510
|
+
const writeSystemAlerts = async(client, systemAlerts) => {
|
|
511
|
+
if (!client.locals.initialized) await initDatabase(client, 'system_alerts');
|
|
512
|
+
systemAlerts = (Array.isArray(systemAlerts) ? systemAlerts : [systemAlerts])
|
|
513
|
+
.map((systemAlert) => {
|
|
514
|
+
const {system_component, state, fields} = systemAlert;
|
|
515
|
+
return {
|
|
516
|
+
measurement: 'system_alerts',
|
|
517
|
+
timestamp: new Date(),
|
|
518
|
+
fields,
|
|
519
|
+
tags: {
|
|
520
|
+
system_component,
|
|
521
|
+
state
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
});
|
|
525
|
+
client.locals.data = [...client.locals.data, ...systemAlerts];
|
|
526
|
+
await writeData(client);
|
|
527
|
+
return;
|
|
528
|
+
};
|
|
498
529
|
const queryCdrsSP = async(client, opts) => {
|
|
499
530
|
if (!client.locals.initialized) await initDatabase(client, 'cdrs');
|
|
500
531
|
const response = {
|
|
@@ -639,6 +670,9 @@ const writeAlerts = async(client, alerts) => {
|
|
|
639
670
|
// eslint-disable-next-line max-len
|
|
640
671
|
message = `you have exceeded your service provider api limit of ${count}; please consider upgrading your plan`;
|
|
641
672
|
break;
|
|
673
|
+
case AlertType.PLAY_FILENOTFOUND:
|
|
674
|
+
message = `The file at ${url} was not found`;
|
|
675
|
+
break;
|
|
642
676
|
default:
|
|
643
677
|
break;
|
|
644
678
|
}
|
|
@@ -741,6 +775,7 @@ module.exports = (logger, opts) => {
|
|
|
741
775
|
const callCountSPClient = new Influx.InfluxDB({database: 'sp_call_counts', schemas: schemas.sp_call_counts, ...opts});
|
|
742
776
|
// eslint-disable-next-line max-len
|
|
743
777
|
const callCountAppClient = new Influx.InfluxDB({database: 'app_call_counts', schemas: schemas.app_call_counts, ...opts});
|
|
778
|
+
const systemAlertClient = new Influx.InfluxDB({database: 'system_alerts', schemas: schemas.system_alerts, ...opts});
|
|
744
779
|
|
|
745
780
|
cdrClient.locals = {
|
|
746
781
|
db: 'cdrs',
|
|
@@ -782,6 +817,14 @@ module.exports = (logger, opts) => {
|
|
|
782
817
|
commitInterval: opts.commitInterval || 10,
|
|
783
818
|
data: []
|
|
784
819
|
};
|
|
820
|
+
systemAlertClient.locals = {
|
|
821
|
+
db: 'system_alerts',
|
|
822
|
+
initialized: false,
|
|
823
|
+
writing: false,
|
|
824
|
+
commitSize: opts.commitSize || 1,
|
|
825
|
+
commitInterval: opts.commitInterval || 10,
|
|
826
|
+
data: []
|
|
827
|
+
};
|
|
785
828
|
|
|
786
829
|
if (opts.commitSize > 1 && opts.commitInterval && opts.commitInterval > 2) {
|
|
787
830
|
setInterval(writeData.bind(null, callCountClient), opts.commitInterval * 1000);
|
|
@@ -804,6 +847,7 @@ module.exports = (logger, opts) => {
|
|
|
804
847
|
writeAlerts: writeAlerts.bind(null, alertClient),
|
|
805
848
|
queryAlerts: queryAlerts.bind(null, alertClient),
|
|
806
849
|
queryAlertsSP: queryAlertsSP.bind(null, alertClient),
|
|
850
|
+
writeSystemAlerts: writeSystemAlerts.bind(null, systemAlertClient),
|
|
807
851
|
AlertType: { ...AlertType }
|
|
808
852
|
};
|
|
809
853
|
};
|