@jambonz/time-series 0.1.12 → 0.2.1

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 CHANGED
@@ -11,9 +11,12 @@ const AlertType = {
11
11
  TTS_FAILURE: 'tts-failure',
12
12
  STT_FAILURE: 'stt-failure',
13
13
  CARRIER_NOT_PROVISIONED: 'no-carrier',
14
- CALL_LIMIT: 'call-limit',
15
- DEVICE_LIMIT: 'device-limit',
16
- API_LIMIT: 'api-limit',
14
+ ACCOUNT_CALL_LIMIT: 'account-call-limit',
15
+ ACCOUNT_DEVICE_LIMIT: 'account-device-limit',
16
+ ACCOUNT_API_LIMIT: 'account-api-limit',
17
+ SP_CALL_LIMIT: 'service-provider-call-limit',
18
+ SP_DEVICE_LIMIT: 'service-provider-device-limit',
19
+ SP_API_LIMIT: 'service-provider-api-limit',
17
20
  ACCOUNT_INACTIVE: 'account is inactive or suspended'
18
21
  };
19
22
 
@@ -33,6 +36,7 @@ const schemas = {
33
36
  trace_id: Influx.FieldType.STRING
34
37
  },
35
38
  tags: [
39
+ 'service_provider_sid',
36
40
  'account_sid',
37
41
  'host',
38
42
  'trunk',
@@ -47,6 +51,7 @@ const schemas = {
47
51
  detail: Influx.FieldType.STRING,
48
52
  },
49
53
  tags: [
54
+ 'service_provider_sid',
50
55
  'account_sid',
51
56
  'alert_type'
52
57
  ]
@@ -57,8 +62,18 @@ const schemas = {
57
62
  calls_in_progress: Influx.FieldType.INTEGER,
58
63
  },
59
64
  tags: [
65
+ 'service_provider_sid',
60
66
  'account_sid'
61
67
  ]
68
+ },
69
+ sp_call_counts: {
70
+ measurement: 'sp_call_counts',
71
+ fields: {
72
+ calls_in_progress: Influx.FieldType.INTEGER,
73
+ },
74
+ tags: [
75
+ 'service_provider_sid'
76
+ ]
62
77
  }
63
78
  };
64
79
 
@@ -80,6 +95,31 @@ const writeData = async(client) => {
80
95
  }
81
96
  };
82
97
 
98
+ /* for Service Provider */
99
+ const createCallCountsQuerySP = ({page, page_size, days, start, end}) => {
100
+ let sql = 'SELECT * from sp_call_counts WHERE service_provider_sid = $service_provider_sid ';
101
+ if (days) sql += 'AND time > $timestamp ';
102
+ else {
103
+ if (start) sql += 'AND time >= $start ';
104
+ if (end) sql += 'AND time <= $end ';
105
+ }
106
+ sql += ' ORDER BY time DESC';
107
+ if (page_size) sql += ' LIMIT $page_size';
108
+ if (page) sql += ' OFFSET $offset';
109
+ return sql;
110
+ };
111
+
112
+ const createCallCountsCountQuerySP = ({days, start, end}) => {
113
+ let sql = 'SELECT COUNT(calls_in_progress) from sp_call_counts WHERE service_provider_sid = $service_provider_sid ';
114
+ if (days) sql += 'AND time > $timestamp ';
115
+ else {
116
+ if (start) sql += 'AND time >= $start ';
117
+ if (end) sql += 'AND time <= $end ';
118
+ }
119
+ return sql;
120
+ };
121
+
122
+ /* for Account */
83
123
  const createCallCountsQuery = ({page, page_size, days, start, end}) => {
84
124
  let sql = 'SELECT * from call_counts WHERE account_sid = $account_sid ';
85
125
  if (days) sql += 'AND time > $timestamp ';
@@ -103,6 +143,36 @@ const createCallCountsCountQuery = ({days, start, end}) => {
103
143
  return sql;
104
144
  };
105
145
 
146
+ /* for Service Provider */
147
+ const createCdrQuerySP = ({page, page_size, trunk, direction, answered, days, start, end}) => {
148
+ let sql = 'SELECT * from cdrs WHERE service_provider_sid = $service_provider_sid ';
149
+ if (trunk) sql += 'AND trunk = $trunk ';
150
+ if (direction) sql += 'AND direction = $direction ';
151
+ if (['true', 'false'].includes(answered)) sql += 'AND answered = $answered ';
152
+ if (days) sql += 'AND time > $timestamp ';
153
+ else {
154
+ if (start) sql += 'AND time >= $start ';
155
+ if (end) sql += 'AND time <= $end ';
156
+ }
157
+ sql += ' ORDER BY time DESC';
158
+ if (page_size) sql += ' LIMIT $page_size';
159
+ if (page) sql += ' OFFSET $offset';
160
+ return sql;
161
+ };
162
+ const createCdrCountQuerySP = ({trunk, direction, answered, days, start, end}) => {
163
+ let sql = 'SELECT COUNT(sip_callid) from cdrs WHERE service_provider_sid = $service_provider_sid ';
164
+ if (trunk) sql += 'AND trunk = $trunk ';
165
+ if (direction) sql += 'AND direction = $direction ';
166
+ if (['true', 'false'].includes(answered)) sql += 'AND answered = $answered ';
167
+ if (days) sql += 'AND time > $timestamp ';
168
+ else {
169
+ if (start) sql += 'AND time >= $start ';
170
+ if (end) sql += 'AND time <= $end ';
171
+ }
172
+ return sql;
173
+ };
174
+
175
+ /* for Account */
106
176
  const createCdrQuery = ({page, page_size, trunk, direction, answered, days, start, end}) => {
107
177
  let sql = 'SELECT * from cdrs WHERE account_sid = $account_sid ';
108
178
  if (trunk) sql += 'AND trunk = $trunk ';
@@ -131,6 +201,36 @@ const createCdrCountQuery = ({trunk, direction, answered, days, start, end}) =>
131
201
  return sql;
132
202
  };
133
203
 
204
+ /* for Service Provider */
205
+ const createAlertsQuerySP = ({target_sid, alert_type, page, page_size, days, start, end}) => {
206
+ // eslint-disable-next-line max-len
207
+ let sql = 'SELECT service_provider_sid, message, detail FROM alerts WHERE service_provider_sid = $service_provider_sid ';
208
+ if (target_sid) sql += 'AND target_sid = $target_sid ';
209
+ if (alert_type) sql += 'AND alert_type = $alert_type ';
210
+ if (days) sql += 'AND time > $timestamp ';
211
+ else {
212
+ if (start) sql += 'AND time >= $start ';
213
+ if (end) sql += 'AND time <= $end ';
214
+ }
215
+ sql += ' ORDER BY time DESC';
216
+ if (page_size) sql += ' LIMIT $page_size';
217
+ if (page) sql += ' OFFSET $offset';
218
+ return sql;
219
+ };
220
+
221
+ const createAlertsCountQuerySP = ({target_sid, alert_type, days, start, end}) => {
222
+ let sql = 'SELECT COUNT(message) FROM alerts WHERE service_provider_sid = $service_provider_sid ';
223
+ if (target_sid) sql += 'AND target_sid = $target_sid ';
224
+ if (alert_type) sql += 'AND alert_type = $alert_type ';
225
+ if (days) sql += 'AND time > $timestamp ';
226
+ else {
227
+ if (start) sql += 'AND time >= $start ';
228
+ if (end) sql += 'AND time <= $end ';
229
+ }
230
+ return sql;
231
+ };
232
+
233
+ /* for Account */
134
234
  const createAlertsQuery = ({target_sid, alert_type, page, page_size, days, start, end}) => {
135
235
  let sql = 'SELECT * FROM alerts WHERE account_sid = $account_sid ';
136
236
  if (target_sid) sql += 'AND target_sid = $target_sid ';
@@ -168,11 +268,12 @@ const initDatabase = async(client, dbName) => {
168
268
 
169
269
  const writeCallCount = async(client, count) => {
170
270
  if (!client.locals.initialized) await initDatabase(client, 'call_counts');
171
- const {account_sid, ...fields} = count;
271
+ const {service_provider_sid, account_sid, ...fields} = count;
172
272
  const data = {
173
273
  measurement: 'call_counts',
174
274
  fields,
175
275
  tags: {
276
+ service_provider_sid,
176
277
  account_sid
177
278
  }
178
279
  };
@@ -183,6 +284,58 @@ const writeCallCount = async(client, count) => {
183
284
  return;
184
285
  };
185
286
 
287
+ const writeCallCountSP = async(client, count) => {
288
+ if (!client.locals.initialized) await initDatabase(client, 'sp_call_counts');
289
+ const {service_provider_sid, ...fields} = count;
290
+ const data = {
291
+ measurement: 'sp_call_counts',
292
+ fields,
293
+ tags: {
294
+ service_provider_sid
295
+ }
296
+ };
297
+ client.locals.data = [...client.locals.data, ...[data]];
298
+ if (client.locals.data.length >= client.locals.commitSize) {
299
+ await writeData(client);
300
+ }
301
+ return;
302
+ };
303
+
304
+ const queryCallCountsSP = async(client, opts) => {
305
+ if (!client.locals.initialized) await initDatabase(client, 'sp_call_counts');
306
+ const response = {
307
+ total: 0,
308
+ page_size: opts.page_size,
309
+ page: opts.page,
310
+ data: []
311
+ };
312
+ const params = generateBindParameters(opts);
313
+ const sqlTotal = createCallCountsCountQuerySP(opts);
314
+ const obj = await client.queryRaw(sqlTotal, { placeholders: params});
315
+ //console.log(`sqlTotal: ${sqlTotal}, results: ${JSON.stringify(obj)}`);
316
+ if (!obj.results || !obj.results[0].series) return response;
317
+ response.total = obj.results[0].series[0].values[0][1];
318
+
319
+ const sql = createCallCountsQuerySP(opts);
320
+ const res = await client.queryRaw(sql, { placeholders: params});
321
+ //console.log(`sql: ${sqlTotal}, results: ${JSON.stringify(res)}`);
322
+ if (res.results[0].series && res.results[0].series.length) {
323
+ const {columns, values} = res.results[0].series[0];
324
+ const data = values.map((v) => {
325
+ const obj = {};
326
+ v.forEach((val, idx) => {
327
+ v.forEach((val, idx) => {
328
+ const key = columns[idx];
329
+ obj[key] = val;
330
+ });
331
+ });
332
+ return obj;
333
+ });
334
+ response.data = data;
335
+ }
336
+ return response;
337
+ };
338
+
186
339
  const queryCallCounts = async(client, opts) => {
187
340
  if (!client.locals.initialized) await initDatabase(client, 'call_counts');
188
341
  const response = {
@@ -222,7 +375,7 @@ const writeCdrs = async(client, cdrs) => {
222
375
  if (!client.locals.initialized) await initDatabase(client, 'cdrs');
223
376
  cdrs = (Array.isArray(cdrs) ? cdrs : [cdrs])
224
377
  .map((cdr) => {
225
- const {direction, host, trunk, account_sid, answered, attempted_at, ...fields} = cdr;
378
+ const {direction, host, trunk, service_provider_sid, account_sid, answered, attempted_at, ...fields} = cdr;
226
379
  return {
227
380
  measurement: 'cdrs',
228
381
  timestamp: new Date(attempted_at),
@@ -231,6 +384,7 @@ const writeCdrs = async(client, cdrs) => {
231
384
  direction,
232
385
  host,
233
386
  trunk,
387
+ service_provider_sid,
234
388
  account_sid,
235
389
  answered
236
390
  }
@@ -244,6 +398,41 @@ const writeCdrs = async(client, cdrs) => {
244
398
  return;
245
399
  };
246
400
 
401
+ const queryCdrsSP = async(client, opts) => {
402
+ if (!client.locals.initialized) await initDatabase(client, 'cdrs');
403
+ const response = {
404
+ total: 0,
405
+ page_size: opts.page_size,
406
+ page: opts.page,
407
+ data: []
408
+ };
409
+ const params = generateBindParameters(opts);
410
+ const sqlTotal = createCdrCountQuerySP(opts);
411
+ const obj = await client.queryRaw(sqlTotal, { placeholders: params});
412
+ //console.log(`sql: ${sqlTotal}, results: ${JSON.stringify(obj)}`);
413
+ if (!obj.results || !obj.results[0].series) return response;
414
+ response.total = obj.results[0].series[0].values[0][1];
415
+
416
+ const sql = createCdrQuerySP(opts);
417
+ const res = await client.queryRaw(sql, { placeholders: params});
418
+ if (res.results[0].series && res.results[0].series.length) {
419
+ const {columns, values} = res.results[0].series[0];
420
+ const data = values.map((v) => {
421
+ const obj = {};
422
+ v.forEach((val, idx) => {
423
+ const key = 'time' === columns[idx] ? 'attempted_at' : columns[idx];
424
+ let retvalue = val;
425
+ if (['answered_at', 'terminated_at'].includes(key)) retvalue = new Date(val);
426
+ if (key === 'answered') retvalue = 'true' === val ? true : false;
427
+ obj[key] = retvalue;
428
+ });
429
+ return obj;
430
+ });
431
+ response.data = data;
432
+ }
433
+ return response;
434
+ };
435
+
247
436
  const queryCdrs = async(client, opts) => {
248
437
  if (!client.locals.initialized) await initDatabase(client, 'cdrs');
249
438
  const response = {
@@ -283,7 +472,18 @@ const writeAlerts = async(client, alerts) => {
283
472
  if (!client.locals.initialized) await initDatabase(client, 'alerts');
284
473
  alerts = (Array.isArray(alerts) ? alerts : [alerts])
285
474
  .map((alert) => {
286
- const {alert_type, account_sid, target_sid, url, status, vendor, count, detail, timestamp} = alert;
475
+ const {
476
+ alert_type,
477
+ service_provider_sid,
478
+ account_sid,
479
+ target_sid,
480
+ url,
481
+ status,
482
+ vendor,
483
+ count,
484
+ detail,
485
+ timestamp
486
+ } = alert;
287
487
  let message = alert.message;
288
488
  if (!message) {
289
489
  switch (alert_type) {
@@ -317,15 +517,29 @@ const writeAlerts = async(client, alerts) => {
317
517
  case AlertType.CARRIER_NOT_PROVISIONED:
318
518
  message = 'outbound call failure: no carriers have been provisioned';
319
519
  break;
320
- case AlertType.CALL_LIMIT:
321
- message = `you have exceeded your provisioned call limit of ${count}; please consider upgrading your plan`;
520
+ case AlertType.ACCOUNT_CALL_LIMIT:
521
+ message = `you have exceeded your account call limit of ${count}; please consider upgrading your plan`;
522
+ break;
523
+ case AlertType.ACCOUNT_DEVICE_LIMIT:
524
+ message =
525
+ // eslint-disable-next-line max-len
526
+ `you have exceeded your account limit of ${count} registered devices; please consider upgrading your plan`;
527
+ break;
528
+ case AlertType.ACCOUNT_API_LIMIT:
529
+ message = `you have exceeded your account api limit of ${count}; please consider upgrading your plan`;
530
+ break;
531
+ case AlertType.SP_CALL_LIMIT:
532
+ // eslint-disable-next-line max-len
533
+ message = `you have exceeded your service provider call limit of ${count}; please consider upgrading your plan`;
322
534
  break;
323
- case AlertType.DEVICE_LIMIT:
535
+ case AlertType.SP_DEVICE_LIMIT:
324
536
  message =
325
- `you have exceeded your device registration limit of ${count}; please consider upgrading your plan`;
537
+ // eslint-disable-next-line max-len
538
+ `you have exceeded your service provider limit of ${count} registered devices; please consider upgrading your plan`;
326
539
  break;
327
- case AlertType.API_LIMIT:
328
- message = `you have exceeded your api limit of ${count}; please consider upgrading your plan`;
540
+ case AlertType.SP_API_LIMIT:
541
+ // eslint-disable-next-line max-len
542
+ message = `you have exceeded your service provider api limit of ${count}; please consider upgrading your plan`;
329
543
  break;
330
544
  default:
331
545
  break;
@@ -333,7 +547,7 @@ const writeAlerts = async(client, alerts) => {
333
547
  }
334
548
  let fields = { message };
335
549
  if (target_sid) fields = Object.assign(fields, {target_sid});
336
- const obj = {measurement: 'alerts', fields: fields, tags: { alert_type, account_sid }};
550
+ const obj = {measurement: 'alerts', fields: fields, tags: { alert_type, service_provider_sid, account_sid }};
337
551
  if (timestamp) obj.timestamp = timestamp;
338
552
  if (detail) obj.fields.detail = detail;
339
553
  return obj;
@@ -354,6 +568,38 @@ const generateBindParameters = (opts) => {
354
568
  return params;
355
569
  };
356
570
 
571
+ const queryAlertsSP = async(client, opts) => {
572
+ if (!client.locals.initialized) await initDatabase(client, 'alerts');
573
+ const response = {
574
+ total: 0,
575
+ page_size: opts.page_size,
576
+ page: opts.page,
577
+ data: []
578
+ };
579
+ const params = generateBindParameters(opts);
580
+ const sqlTotal = createAlertsCountQuerySP(opts);
581
+ const obj = await client.queryRaw(sqlTotal, { placeholders: params});
582
+ //console.log(`query total alerts: ${sqlTotal}: ${JSON.stringify(obj)}`);
583
+ if (!obj.results || !obj.results[0].series) return response;
584
+ response.total = obj.results[0].series[0].values[0][1];
585
+
586
+ const sql = createAlertsQuerySP(opts);
587
+ const res = await client.queryRaw(sql, { placeholders: params});
588
+ if (res.results[0].series && res.results[0].series.length) {
589
+ const {columns, values} = res.results[0].series[0];
590
+ const data = values.map((v) => {
591
+ const obj = {};
592
+ v.forEach((val, idx) => {
593
+ const key = columns[idx];
594
+ obj[key] = val;
595
+ });
596
+ return obj;
597
+ });
598
+ response.data = data;
599
+ }
600
+ return response;
601
+ };
602
+
357
603
  const queryAlerts = async(client, opts) => {
358
604
  if (!client.locals.initialized) await initDatabase(client, 'alerts');
359
605
  const response = {
@@ -393,6 +639,7 @@ module.exports = (logger, opts) => {
393
639
  const cdrClient = new Influx.InfluxDB({database: 'cdrs', schemas: schemas.cdr, ...opts});
394
640
  const alertClient = new Influx.InfluxDB({database: 'alerts', schemas: schemas.alerts, ...opts});
395
641
  const callCountClient = new Influx.InfluxDB({database: 'call_counts', schemas: schemas.call_counts, ...opts});
642
+ const callCountSPClient = new Influx.InfluxDB({database: 'sp_call_counts', schemas: schemas.sp_call_counts, ...opts});
396
643
 
397
644
  cdrClient.locals = {
398
645
  db: 'cdrs',
@@ -410,6 +657,14 @@ module.exports = (logger, opts) => {
410
657
  commitInterval: opts.commitInterval || 10,
411
658
  data: []
412
659
  };
660
+ callCountSPClient.locals = {
661
+ db: 'sp_call_counts',
662
+ initialized: false,
663
+ writing: false,
664
+ commitSize: opts.commitSize || 1,
665
+ commitInterval: opts.commitInterval || 10,
666
+ data: []
667
+ };
413
668
  callCountClient.locals = {
414
669
  db: 'call_counts',
415
670
  initialized: false,
@@ -427,11 +682,15 @@ module.exports = (logger, opts) => {
427
682
 
428
683
  return {
429
684
  writeCallCount: writeCallCount.bind(null, callCountClient),
685
+ writeCallCountSP: writeCallCountSP.bind(null, callCountSPClient),
430
686
  queryCallCounts: queryCallCounts.bind(null, callCountClient),
687
+ queryCallCountsSP: queryCallCountsSP.bind(null, callCountSPClient),
431
688
  writeCdrs: writeCdrs.bind(null, cdrClient),
689
+ queryCdrsSP: queryCdrsSP.bind(null, cdrClient),
432
690
  queryCdrs: queryCdrs.bind(null, cdrClient),
433
691
  writeAlerts: writeAlerts.bind(null, alertClient),
434
692
  queryAlerts: queryAlerts.bind(null, alertClient),
693
+ queryAlertsSP: queryAlertsSP.bind(null, alertClient),
435
694
  AlertType: { ...AlertType }
436
695
  };
437
696
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jambonz/time-series",
3
- "version": "0.1.12",
3
+ "version": "0.2.1",
4
4
  "description": "write and query data to time series daetabase",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -4,11 +4,15 @@ const consoleLogger = {error: console.error, info: console.log, debug: console.l
4
4
 
5
5
  const {
6
6
  writeCallCount,
7
+ writeCallCountSP,
7
8
  queryCallCounts,
9
+ queryCallCountsSP,
8
10
  writeCdrs,
9
11
  queryCdrs,
12
+ queryCdrsSP,
10
13
  writeAlerts,
11
14
  queryAlerts,
15
+ queryAlertsSP,
12
16
  AlertType
13
17
  } = require('..')(consoleLogger, '127.0.0.1', {commitSize: 1});
14
18
 
@@ -27,6 +31,7 @@ test('write timeseries data', async(t) => {
27
31
  host: '10.10.100.1',
28
32
  remote_host: '10.10.100.8',
29
33
  trunk: 'device',
34
+ service_provider_sid: 'zzzzz',
30
35
  account_sid: 'xxxx',
31
36
  call_sid: 'foo'
32
37
  },
@@ -44,6 +49,7 @@ test('write timeseries data', async(t) => {
44
49
  host: '10.10.100.1',
45
50
  remote_host: '10.10.100.8',
46
51
  trunk: 'twilio',
52
+ service_provider_sid: 'zzzzz',
47
53
  account_sid: 'yyyy',
48
54
  call_sid: 'bar'
49
55
  }]);
@@ -51,72 +57,102 @@ test('write timeseries data', async(t) => {
51
57
 
52
58
  result = await queryCdrs({account_sid: 'xxxx', page: 1, page_size:25});
53
59
  //npm tesconsole.log(JSON.stringify(result));
54
- t.ok(result.data.length === 1, 'queried cdrs')
60
+ t.ok(result.data.length === 1, 'queried cdrs by account sid')
55
61
 
56
62
  result = await queryCdrs({account_sid: 'yyyy', trunk: 'twilio', page: 1, page_size:25});
57
63
  t.ok(result.data.length === 1, 'queried cdrs by trunk')
58
64
 
65
+ result = await queryCdrsSP({service_provider_sid: 'zzzzz', page: 1, page_size:25});
66
+ t.ok(result.data.length === 2, 'queried cdrs by service provider sid')
67
+
59
68
  result = await writeAlerts([
60
69
  {
61
70
  alert_type: AlertType.WEBHOOK_STATUS_FAILURE,
71
+ service_provider_sid: 'zzzzz',
62
72
  account_sid: 'yyyy',
63
73
  url: 'http://foo.bar',
64
74
  status: 404
65
75
  },
66
76
  {
67
77
  alert_type: AlertType.WEBHOOK_CONNECTION_FAILURE,
78
+ service_provider_sid: 'zzzzz',
68
79
  account_sid: 'yyyy',
69
80
  url: 'http://foo.bar'
70
81
  },
71
82
  {
72
83
  alert_type: AlertType.WEBHOOK_AUTH_FAILURE,
84
+ service_provider_sid: 'zzzzz',
73
85
  account_sid: 'yyyy',
74
86
  url: 'http://foo.bar'
75
87
  },
76
88
  {
77
89
  alert_type: AlertType.INVALID_APP_PAYLOAD,
90
+ service_provider_sid: 'zzzzz',
78
91
  account_sid: 'yyyy',
79
92
  target_sid: 'zzzz',
80
93
  message: 'invalid app payload'
81
94
  },
82
95
  {
83
96
  alert_type: AlertType.TTS_NOT_PROVISIONED,
97
+ service_provider_sid: 'zzzzz',
84
98
  account_sid: 'yyyy',
85
99
  vendor: 'google'
86
100
  },
87
101
  {
88
102
  alert_type: AlertType.STT_NOT_PROVISIONED,
103
+ service_provider_sid: 'zzzzz',
89
104
  account_sid: 'yyyy',
90
105
  vendor: 'google'
91
106
  },
92
107
  {
93
108
  alert_type: AlertType.TTS_FAILURE,
109
+ service_provider_sid: 'zzzzz',
94
110
  account_sid: 'yyyy',
95
111
  vendor: 'google'
96
112
  },
97
113
  {
98
114
  alert_type: AlertType.STT_FAILURE,
115
+ service_provider_sid: 'zzzzz',
99
116
  account_sid: 'yyyy',
100
117
  vendor: 'google'
101
118
  },
102
119
  {
103
120
  alert_type: AlertType.CARRIER_NOT_PROVISIONED,
121
+ service_provider_sid: 'zzzzz',
104
122
  account_sid: 'yyyy',
105
123
  },
106
124
  {
107
- alert_type: AlertType.CALL_LIMIT,
125
+ alert_type: AlertType.SP_CALL_LIMIT,
126
+ service_provider_sid: 'zzzzz',
127
+ count: 50,
128
+ },
129
+ {
130
+ alert_type: AlertType.ACCOUNT_CALL_LIMIT,
131
+ service_provider_sid: 'zzzzz',
108
132
  account_sid: 'yyyy',
109
133
  count: 50,
110
134
  },
111
135
  {
112
- alert_type: AlertType.DEVICE_LIMIT,
136
+ alert_type: AlertType.SP_DEVICE_LIMIT,
137
+ service_provider_sid: 'zzzzz',
138
+ count: 500,
139
+ },
140
+ {
141
+ alert_type: AlertType.ACCOUNT_DEVICE_LIMIT,
142
+ service_provider_sid: 'zzzzz',
113
143
  account_sid: 'yyyy',
114
144
  count: 250,
115
145
  },
116
146
  {
117
- alert_type: AlertType.API_LIMIT,
147
+ alert_type: AlertType.ACCOUNT_API_LIMIT,
148
+ service_provider_sid: 'zzzzz',
118
149
  account_sid: 'yyyy',
119
150
  count: 120,
151
+ },
152
+ {
153
+ alert_type: AlertType.SP_API_LIMIT,
154
+ service_provider_sid: 'zzzzz',
155
+ count: 300,
120
156
  }
121
157
  ]);
122
158
  t.pass('wrote alerts');
@@ -137,20 +173,41 @@ test('write timeseries data', async(t) => {
137
173
  t.ok(result.data.length === 1, 'queried alerts by target_sid');
138
174
  t.ok(result.data[0].target_sid === 'zzzz')
139
175
 
176
+ result = await queryAlertsSP({service_provider_sid: 'zzzzz', page: 1, page_size: 25, days: 7});
177
+ //console.log(result);
178
+ t.ok(result.data.length === 15, 'queried alerts by service_provider_sid');
179
+
140
180
  result = await writeCallCount(
141
181
  {
142
182
  calls_in_progress: 49,
183
+ service_provider_sid: 'zzzzz',
143
184
  account_sid: 'yyyy'
144
185
  });
145
186
  result = await writeCallCount(
146
187
  {
147
188
  calls_in_progress: 50,
189
+ service_provider_sid: 'zzzzz',
148
190
  account_sid: 'yyyy'
149
191
  });
150
- t.pass('wrote call counts');
192
+ t.pass('wrote call counts for account');
151
193
 
152
- result = await queryCallCounts({account_sid: 'yyyy', page: 1, page_size: 25, days: 7});
194
+ result = await writeCallCountSP(
195
+ {
196
+ calls_in_progress: 500,
197
+ service_provider_sid: 'zzzzz'
198
+ });
199
+ result = await writeCallCountSP(
200
+ {
201
+ calls_in_progress: 501,
202
+ service_provider_sid: 'zzzzz'
203
+ });
204
+ t.pass('wrote call counts for service provider');
205
+
206
+ result = await queryCallCountsSP({service_provider_sid: 'zzzzz', page: 1, page_size: 25, days: 7});
153
207
  //console.log(JSON.stringify(result));
154
- t.ok(result.data.length === 2, 'queried call counts');
208
+ t.ok(result.data.length === 2, 'queried call counts by service provider sid');
155
209
 
210
+ result = await queryCallCounts({account_sid: 'yyyy', page: 1, page_size: 25, days: 7});
211
+ //console.log(JSON.stringify(result));
212
+ t.ok(result.data.length === 2, 'queried call counts by account_sid');
156
213
  });