-
Notifications
You must be signed in to change notification settings - Fork 8
/
FlowDAO.ts
698 lines (659 loc) · 32.7 KB
/
FlowDAO.ts
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
import {OnmsError} from '../api/OnmsError';
import {OnmsFlowSeries} from '../model/OnmsFlowSeries';
import {OnmsFlowSeriesColumn} from '../model/OnmsFlowSeriesColumn';
import {OnmsFlowExporterSummary} from '../model/OnmsFlowExporterSummary';
import {OnmsFlowSnmpInterface} from '../model/OnmsFlowSnmpInterface';
import {OnmsFlowExporter} from '../model/OnmsFlowExporter';
import {OnmsFlowTable} from '../model/OnmsFlowTable';
import {OnmsHTTPOptions, OnmsHTTPOptionsBuilder} from '../api/OnmsHTTPOptions';
import {BaseDAO} from './BaseDAO';
/** @hidden */
// tslint:disable-next-line
const moment = require('moment');
/**
* DAO for accessing flow (Netflow/IPFIX/sFlow) data.
* @category DAO
*/
export class FlowDAO extends BaseDAO {
/**
* Get a summary of the nodes that have exported flows.
* @param limit - maximum number of exporters to return (those with the most flows will be returned
* if the results are truncated)
* @param start - the start of the timespan to query (defaults to 4 hours ago)
* @param end - the end of the timespan to query (defaults to now)
*/
public async getExporters(limit: number, start?: number, end?: number): Promise<OnmsFlowExporterSummary[]> {
const url = this.pathToFlowsEndpoint() + '/exporters';
const builder = this.getOptions()
.addParameter('limit', limit)
.addParameter('start', start)
.addParameter('end', end);
const result = await this.http.get(url, builder.build());
if (result && result.data) {
if (!Array.isArray(result.data)) {
throw new OnmsError('Expected an array of flow exporter summaries but got "' +
(typeof result) + '" instead.');
}
return result.data.map((exporter) => {
return this.toFlowExporterSummary(exporter);
});
}
throw new OnmsError('Unexpected response from GET ' + url + ': no result data found.');
}
/**
* Get detailed information about a specific node.
* @param criteria - the node ID or foreignSource:foreignId tuple
* @param limit - maximum number of interfaces to return (those with the most flows will be returned
* if the results are truncated)
* @param start - the start of the timespan to query (defaults to 4 hours ago)
* @param end - the end of the timespan to query (defaults to now)
*/
public async getExporter(criteria: string, limit: number, start?: number, end?: number): Promise<OnmsFlowExporter> {
const builder = this.getOptions()
.addParameter('limit', limit)
.addParameter('start', start)
.addParameter('end', end);
const result = await this.http.get(this.pathToFlowsEndpoint() + '/exporters/' + criteria, builder.build());
return this.toFlowExporter(result.data);
}
/**
* Get used Dscp values for a specific interface
* @param exporterNodeCriteria - the node ID or foreignSource:foreignId tuple
* @param ifIndex - the SNMP interface
* @param start - the start of the timespan to query (defaults to 4 hours ago)
* @param end - the end of the timespan to query (defaults to now)
*/
public async getDscpValues(exporterNodeCriteria?: string, ifIndex?: number, start?: number, end?: number): Promise<number[]> {
this.checkForToSSupport();
const builder = this.getOptions()
.addParameter('start', start)
.addParameter('end', end)
.addParameter('exporterNode', exporterNodeCriteria)
.addParameter('ifIndex', ifIndex);
const result = await this.http.get(this.pathToFlowsEndpoint() + '/dscp/enumerate', builder.build());
return result.data;
}
/**
* Summarize the the dscp values based on parameters.
* @param start - the start of the timespan to query (defaults to 4 hours ago)
* @param end - the end of the timespan to query (defaults to now)
* @param includeOther - include an additional "other" result that
* represents everything that does not match the given applications
* @param exporterNodeCriteria - the node ID or foreignSource:foreignId tuple
* @param ifIndex - filter for flows that came through this SNMP interface
* @param dscp - filter for flows with this Dscp value
*/
public async getSummaryForDscps(start?: number, end?: number,
exporterNodeCriteria?: string,
ifIndex?: number, dscp?: string[]): Promise<OnmsFlowTable> {
this.checkForEnhancedFlows();
const builder = this.getOptions()
.addParameter('start', start)
.addParameter('end', end)
.addParameter('exporterNode', exporterNodeCriteria)
.addParameter('ifIndex', ifIndex)
.addParameter('dscp', dscp)
const result = await this.http.get(this.pathToFlowsEndpoint() + '/dscp', builder.build());
return this.tableFromData(result.data);
}
/**
* Get time series data for DSCP based on parameters.
* @param start - the start of the timespan to query (defaults to 4 hours ago)
* @param end - the end of the timespan to query (defaults to now)
* @param step - the requested time interval between rows
* @param includeOther - include an additional "other" result that
* represents everything that does not match the given applications
* @param exporterNodeCriteria - the node ID or foreignSource:foreignId tuple
* @param ifIndex - filter for flows that came through this SNMP interface
* @param dscp - filter for flows with this Dscp value
*/
public async getSeriesForDscps(start?: number, end?: number,
step?: number,
exporterNodeCriteria?: string,
ifIndex?: number, dscp?: string[]): Promise<OnmsFlowSeries> {
this.checkForEnhancedFlows();
const builder = this.getOptions()
.addParameter('start', start)
.addParameter('end', end)
.addParameter('step', step)
.addParameter('exporterNode', exporterNodeCriteria)
.addParameter('ifIndex', ifIndex)
.addParameter('dscp', dscp)
const result = await this.http.get(this.pathToFlowsEndpoint() + '/dscp/series', builder.build());
return this.seriesFromData(result.data);
}
/**
* Enumerate the applications matching the given prefix and filters.
* @param prefix - the prefix to match
* @param start - the start of the timespan to query (defaults to 4 hours ago)
* @param end - the end of the timespan to query (defaults to now)
* @param exporterNodeCriteria - the node ID or foreignSource:foreignId tuple
* @param ifIndex - filter for flows that came through this SNMP interface
* @param dscp - filter for flows with this Dscp value
*/
public async getApplications(prefix?: string, start?: number, end?: number,
exporterNodeCriteria?: string,
ifIndex?: number, dscp?: string[]): Promise<string[]> {
const builder = this.getOptions()
.addParameter('start', start)
.addParameter('end', end)
.addParameter('exporterNode', exporterNodeCriteria)
.addParameter('ifIndex', ifIndex)
.addParameter('dscp', dscp)
.addParameter('prefix', prefix);
const result = await this.http.get(this.pathToFlowsEndpoint() + '/applications/enumerate', builder.build());
return result.data;
}
/**
* Summarize the top N applications/protocols based on parameters.
* @param N - how many applications to return
* @param start - the start of the timespan to query (defaults to 4 hours ago)
* @param end - the end of the timespan to query (defaults to now)
* @param includeOther - include an additional "other" result that
* represents everything that does not match the top N
* @param exporterNodeCriteria - the node ID or foreignSource:foreignId tuple
* @param ifIndex - filter for flows that came through this SNMP interface
* @param dscp - filter for flows with this Dscp value
*/
public async getSummaryForTopNApplications(N?: number, start?: number, end?: number,
includeOther?: boolean,
exporterNodeCriteria?: string,
ifIndex?: number, dscp?: string[]): Promise<OnmsFlowTable> {
const builder = this.getOptions().addParameter('N', N)
.addParameter('start', start)
.addParameter('end', end)
.addParameter('exporterNode', exporterNodeCriteria)
.addParameter('ifIndex', ifIndex)
.addParameter('dscp', dscp)
.addParameter('includeOther', includeOther);
const result = await this.http.get(this.pathToFlowsEndpoint() + '/applications', builder.build());
return this.tableFromData(result.data);
}
/**
* Summarize the given applications/protocols based on parameters.
* @param applications - the applications to include
* @param start - the start of the timespan to query (defaults to 4 hours ago)
* @param end - the end of the timespan to query (defaults to now)
* @param includeOther - include an additional "other" result that
* represents everything that does not match the given applications
* @param exporterNodeCriteria - the node ID or foreignSource:foreignId tuple
* @param ifIndex - filter for flows that came through this SNMP interface
* @param dscp - filter for flows with this Dscp value
*/
public async getSummaryForApplications(applications?: string[], start?: number, end?: number,
includeOther?: boolean,
exporterNodeCriteria?: string,
ifIndex?: number, dscp?: string[]): Promise<OnmsFlowTable> {
this.checkForEnhancedFlows();
const builder = this.getOptions()
.addParameter('start', start)
.addParameter('end', end)
.addParameter('exporterNode', exporterNodeCriteria)
.addParameter('ifIndex', ifIndex)
.addParameter('dscp', dscp)
.addParameter('includeOther', includeOther);
if (applications) {
applications.forEach((application) => {
builder.addParameter('application', application);
});
}
const result = await this.http.get(this.pathToFlowsEndpoint() + '/applications', builder.build());
return this.tableFromData(result.data);
}
/**
* Get time series data for the top N applications/protocols based on parameters.
* @param N - how many applications' series to return
* @param start - the start of the timespan to query (defaults to 4 hours ago)
* @param end - the end of the timespan to query (defaults to now)
* @param step - the requested time interval between rows
* @param includeOther - include an additional "other" result that
* represents everything that does not match the top N
* @param exporterNodeCriteria - the node ID or foreignSource:foreignId tuple
* @param ifIndex - filter for flows that came through this SNMP interface
* @param dscp - filter for flows with this Dscp value
*/
public async getSeriesForTopNApplications(N?: number, start?: number, end?: number,
step?: number, includeOther?: boolean,
exporterNodeCriteria?: string,
ifIndex?: number, dscp?: string[]): Promise<OnmsFlowSeries> {
const builder = this.getOptions()
.addParameter('N', N)
.addParameter('start', start)
.addParameter('end', end)
.addParameter('step', step)
.addParameter('exporterNode', exporterNodeCriteria)
.addParameter('ifIndex', ifIndex)
.addParameter('dscp', dscp)
.addParameter('includeOther', includeOther);
const result = await this.http.get(this.pathToFlowsEndpoint() + '/applications/series', builder.build());
return this.seriesFromData(result.data);
}
/**
* Get time series data for the top N applications/protocols based on parameters.
* @param applications - the applications to include
* @param start - the start of the timespan to query (defaults to 4 hours ago)
* @param end - the end of the timespan to query (defaults to now)
* @param step - the requested time interval between rows
* @param includeOther - include an additional "other" result that
* represents everything that does not match the given applications
* @param exporterNodeCriteria - the node ID or foreignSource:foreignId tuple
* @param ifIndex - filter for flows that came through this SNMP interface
* @param dscp - filter for flows with this Dscp value
*/
public async getSeriesForApplications(applications?: string[], start?: number, end?: number,
step?: number, includeOther?: boolean,
exporterNodeCriteria?: string,
ifIndex?: number, dscp?: string[]): Promise<OnmsFlowSeries> {
this.checkForEnhancedFlows();
const builder = this.getOptions()
.addParameter('start', start)
.addParameter('end', end)
.addParameter('step', step)
.addParameter('exporterNode', exporterNodeCriteria)
.addParameter('ifIndex', ifIndex)
.addParameter('dscp', dscp)
.addParameter('includeOther', includeOther);
if (applications) {
applications.forEach((application) => {
builder.addParameter('application', application);
});
}
const result = await this.http.get(this.pathToFlowsEndpoint() + '/applications/series', builder.build());
return this.seriesFromData(result.data);
}
/**
* Summarize the top N conversations based on parameters.
* @param NOptions - how many conversations to return or an object that includes all of the parameters to be set on
* the API call
* @param start - the start of the timespan to query (defaults to 4 hours ago)
* @param end - the end of the timespan to query (defaults to now)
* @param exporterNodeCriteria - the node ID or foreignSource:foreignId tuple
* @param ifIndex - filter for flows that came through this SNMP interface
* @param dscp - filter for flows with this Dscp value
*/
public async getSummaryForTopNConversations(NOptions?: number | ITopNOptions, start?: number, end?: number,
exporterNodeCriteria?: string,
ifIndex?: number, dscp?: string[]): Promise<OnmsFlowTable> {
const builder = this.getOptions();
if (typeof NOptions === 'number') {
builder.addParameter('N', NOptions)
.addParameter('start', start)
.addParameter('end', end)
.addParameter('exporterNode', exporterNodeCriteria)
.addParameter('ifIndex', ifIndex)
.addParameter('dscp', dscp);
} else if (NOptions) {
for (const key of Object.keys(NOptions)) {
builder.addParameter(key, (NOptions as any)[key]);
}
}
const result = await this.http.get(this.pathToFlowsEndpoint() + '/conversations', builder.build());
return this.tableFromData(result.data);
}
/**
* Summarize the given conversations based on parameters.
* @param conversations - how many conversations to return
* @param start - the start of the timespan to query (defaults to 4 hours ago)
* @param end - the end of the timespan to query (defaults to now)
* @param includeOther - include an additional "other" result that
* represents everything that does not match the given conversations
* @param exporterNodeCriteria - the node ID or foreignSource:foreignId tuple
* @param ifIndex - filter for flows that came through this SNMP interface
* @param dscp - filter for flows with this Dscp value
*/
public async getSummaryForConversations(conversations?: string[], start?: number, end?: number,
includeOther?: boolean, exporterNodeCriteria?: string,
ifIndex?: number, dscp?: string[]): Promise<OnmsFlowTable> {
this.checkForEnhancedFlows();
const builder = this.getOptions()
.addParameter('start', start)
.addParameter('end', end)
.addParameter('exporterNode', exporterNodeCriteria)
.addParameter('ifIndex', ifIndex)
.addParameter('dscp', dscp)
.addParameter('includeOther', includeOther);
if (conversations) {
conversations.forEach((conversation) => {
builder.addParameter('conversation', conversation);
});
}
const result = await this.http.get(this.pathToFlowsEndpoint() + '/conversations', builder.build());
return this.tableFromData(result.data);
}
/**
* Get time series data for the top N conversations based on parameters.
* @param NOptions - how many conversations to return or an object that includes all of the parameters to be set on
* the API call
* @param start - the start of the timespan to query (defaults to 4 hours ago)
* @param end - the end of the timespan to query (defaults to now)
* @param step - the requested time interval between rows
* @param exporterNodeCriteria - the node ID or foreignSource:foreignId tuple
* @param ifIndex - filter for flows that came through this SNMP interface
* @param dscp - filter for flows with this Dscp value
*/
public async getSeriesForTopNConversations(NOptions?: number | ITopNOptions, start?: number, end?: number,
step?: number, exporterNodeCriteria?: string,
ifIndex?: number, dscp?: string[]): Promise<OnmsFlowSeries> {
const builder = this.getOptions();
if (typeof NOptions === 'number') {
builder.addParameter('N', NOptions)
.addParameter('start', start)
.addParameter('end', end)
.addParameter('step', step)
.addParameter('exporterNode', exporterNodeCriteria)
.addParameter('ifIndex', ifIndex)
.addParameter('dscp', dscp);
} else if (NOptions) {
for (const key of Object.keys(NOptions)) {
builder.addParameter(key, (NOptions as any)[key]);
}
}
const result = await this.http.get(this.pathToFlowsEndpoint() + '/conversations/series', builder.build());
return this.seriesFromData(result.data);
}
/**
* Get time series data for the given conversations based on parameters.
* @param conversations - how many conversations' series to return
* @param start - the start of the timespan to query (defaults to 4 hours ago)
* @param end - the end of the timespan to query (defaults to now)
* @param step - the requested time interval between rows
* @param includeOther - include an additional "other" result that
* represents everything that does not match the given conversations
* @param exporterNodeCriteria - the node ID or foreignSource:foreignId tuple
* @param ifIndex - filter for flows that came through this SNMP interface
* @param dscp - filter for flows with this Dscp value
*/
public async getSeriesForConversations(conversations?: string[], start?: number, end?: number,
step?: number, includeOther?: boolean, exporterNodeCriteria?: string,
ifIndex?: number, dscp?: string[], ecn?: string[]): Promise<OnmsFlowSeries> {
this.checkForEnhancedFlows();
const builder = this.getOptions()
.addParameter('start', start)
.addParameter('end', end)
.addParameter('step', step)
.addParameter('exporterNode', exporterNodeCriteria)
.addParameter('ifIndex', ifIndex)
.addParameter('dscp', dscp)
.addParameter('includeOther', includeOther);
if (conversations) {
conversations.forEach((conversation) => {
builder.addParameter('conversation', conversation);
});
}
const result = await this.http.get(this.pathToFlowsEndpoint() + '/conversations/series', builder.build());
return this.seriesFromData(result.data);
}
/**
* Enumerate all the hosts matching the given pattern and filters.
* @param pattern - the regex pattern to match
* @param start - the start of the timespan to query (defaults to 4 hours ago)
* @param end - the end of the timespan to query (defaults to now)
* @param exporterNodeCriteria - the node ID or foreignSource:foreignId tuple
* @param ifIndex - filter for flows that came through this SNMP interface
* @param dscp - filter for flows with this Dscp value
*/
public async getHosts(pattern?: string, start?: number, end?: number,
exporterNodeCriteria?: string,
ifIndex?: number, dscp?: string[]): Promise<string[]> {
const builder = this.getOptions()
.addParameter('start', start)
.addParameter('end', end)
.addParameter('exporterNode', exporterNodeCriteria)
.addParameter('ifIndex', ifIndex)
.addParameter('dscp', dscp)
.addParameter('pattern', pattern);
const result = await this.http.get(this.pathToFlowsEndpoint() + '/hosts/enumerate', builder.build());
return result.data;
}
/**
* Summarize the given hosts based on parameters.
* @param hosts - the hosts to include
* @param start - the start of the timespan to query (defaults to 4 hours ago)
* @param end - the end of the timespan to query (defaults to now)
* @param includeOther - include an additional "other" result that
* represents everything that does not match the given hosts
* @param exporterNodeCriteria - the node ID or foreignSource:foreignId tuple
* @param ifIndex - filter for flows that came through this SNMP interface
* @param dscp - filter for flows with this Dscp value
*/
public async getSummaryForHosts(hosts?: string[], start?: number, end?: number,
includeOther?: boolean,
exporterNodeCriteria?: string,
ifIndex?: number, dscp?: string[]): Promise<OnmsFlowTable> {
this.checkForEnhancedFlows();
const builder = this.getOptions()
.addParameter('start', start)
.addParameter('end', end)
.addParameter('exporterNode', exporterNodeCriteria)
.addParameter('ifIndex', ifIndex)
.addParameter('dscp', dscp)
.addParameter('includeOther', includeOther);
if (hosts) {
hosts.forEach((host) => {
builder.addParameter('host', host);
});
}
const result = await this.http.get(this.pathToFlowsEndpoint() + '/hosts', builder.build());
return this.tableFromData(result.data);
}
/**
* Summarize the top N hosts based on parameters.
* @param N - how many conversations to return
* @param start - the start of the timespan to query (defaults to 4 hours ago)
* @param end - the end of the timespan to query (defaults to now)
* @param includeOther - include an additional "other" result that
* represents everything that does not match the top N
* @param exporterNodeCriteria - the node ID or foreignSource:foreignId tuple
* @param ifIndex - filter for flows that came through this SNMP interface
* @param dscp - filter for flows with this Dscp value
*/
public async getSummaryForTopNHosts(N?: number, start?: number, end?: number,
includeOther?: boolean, exporterNodeCriteria?: string,
ifIndex?: number, dscp?: string[]): Promise<OnmsFlowTable> {
this.checkForEnhancedFlows();
const builder = this.getOptions()
.addParameter('N', N)
.addParameter('start', start)
.addParameter('end', end)
.addParameter('exporterNode', exporterNodeCriteria)
.addParameter('ifIndex', ifIndex)
.addParameter('dscp', dscp)
.addParameter('includeOther', includeOther);
const result = await this.http.get(this.pathToFlowsEndpoint() + '/hosts', builder.build());
return this.tableFromData(result.data);
}
/**
* Get time series data for the top N hosts based on parameters.
* @param N - how many applications' series to return
* @param start - the start of the timespan to query (defaults to 4 hours ago)
* @param end - the end of the timespan to query (defaults to now)
* @param step - the requested time interval between rows
* @param includeOther - include an additional "other" result that
* represents everything that does not match the top N
* @param exporterNodeCriteria - the node ID or foreignSource:foreignId tuple
* @param ifIndex - filter for flows that came through this SNMP interface
* @param dscp - filter for flows with this Dscp value
*/
public async getSeriesForTopNHosts(N?: number, start?: number, end?: number,
step?: number, includeOther?: boolean,
exporterNodeCriteria?: string,
ifIndex?: number, dscp?: string[]): Promise<OnmsFlowSeries> {
this.checkForEnhancedFlows();
const builder = this.getOptions()
.addParameter('N', N)
.addParameter('start', start)
.addParameter('end', end)
.addParameter('step', step)
.addParameter('exporterNode', exporterNodeCriteria)
.addParameter('ifIndex', ifIndex)
.addParameter('dscp', dscp)
.addParameter('includeOther', includeOther);
const result = await this.http.get(this.pathToFlowsEndpoint() + '/hosts/series', builder.build());
return this.seriesFromData(result.data);
}
/**
* Get time series data for the given hosts based on parameters.
* @param hosts - the hosts to include
* @param start - the start of the timespan to query (defaults to 4 hours ago)
* @param end - the end of the timespan to query (defaults to now)
* @param step - the requested time interval between rows
* @param includeOther - include an additional "other" result that
* represents everything that does not match the given hosts
* @param exporterNodeCriteria - the node ID or foreignSource:foreignId tuple
* @param ifIndex - filter for flows that came through this SNMP interface
* @param dscp - filter for flows with this Dscp value
*/
public async getSeriesForHosts(hosts?: string[], start?: number, end?: number,
step?: number, includeOther?: boolean,
exporterNodeCriteria?: string,
ifIndex?: number, dscp?: string[]): Promise<OnmsFlowSeries> {
this.checkForEnhancedFlows();
const builder = this.getOptions()
.addParameter('start', start)
.addParameter('end', end)
.addParameter('step', step)
.addParameter('exporterNode', exporterNodeCriteria)
.addParameter('ifIndex', ifIndex)
.addParameter('dscp', dscp)
.addParameter('includeOther', includeOther);
if (hosts) {
hosts.forEach((host) => {
builder.addParameter('host', host);
});
}
const result = await this.http.get(this.pathToFlowsEndpoint() + '/hosts/series', builder.build());
return this.seriesFromData(result.data);
}
/**
* Convert flow ReST exporter summary JSON data to an [[OnmsFlowExporterSummary]] object.
* @hidden
*/
public toFlowExporterSummary(data: any) {
const summary = new OnmsFlowExporterSummary();
summary.id = data.id;
summary.foreignId = data.foreignId;
summary.foreignSource = data.foreignSource;
summary.label = data.label;
return summary;
}
/**
* Convert flow ReST exporter JSON data to an [[OnmsFlowExporter]] object.
* @hidden
*/
public toFlowExporter(data: any) {
const exporter = new OnmsFlowExporter();
exporter.id = data.id;
exporter.foreignId = data.foreignId;
exporter.foreignSource = data.foreignSource;
exporter.label = data.label;
exporter.interfaces = [];
if (data.interface) {
exporter.interfaces = data.interface.map((iff: any) => {
return this.toInterface(iff);
});
}
return exporter;
}
/**
* Convert flow ReST interface JSON data to an [[OnmsFlowSnmpInterface]] object.
* @hidden
*/
public toInterface(data: any) {
const iff = new OnmsFlowSnmpInterface();
iff.index = data.index;
iff.name = data.name;
iff.description = data.descr;
iff.resourceId = data['resource-id'];
return iff;
}
/**
* Create a series object from a JSON object.
* @hidden
*/
public tableFromData(data: any) {
const table = new OnmsFlowTable();
table.start = this.toDate(data.start);
table.end = this.toDate(data.end);
table.headers = data.headers;
table.rows = data.rows;
return table;
}
/**
* Create a series object from a JSON object.
* @hidden
*/
public seriesFromData(data: any) {
const series = new OnmsFlowSeries();
series.start = this.toDate(data.start);
series.end = this.toDate(data.end);
series.columns = data.labels;
series.timestamps = data.timestamps;
series.values = data.values;
let columns = data.columns;
if (!Array.isArray(columns)) {
columns = [columns];
}
series.columns = [];
for (let column of columns) {
column = new OnmsFlowSeriesColumn(
column.label,
column.ingress,
);
series.columns.push(column);
}
return series;
}
/**
* Create an [[OnmsHTTPOptions]] object for DAO calls.
*/
protected getOptions(): OnmsHTTPOptionsBuilder {
return OnmsHTTPOptions.newBuilder().setHeader('Accept', 'application/json');
}
/**
* Get the path to the flows endpoint for the appropriate API version.
* @hidden
*/
private pathToFlowsEndpoint() {
return 'rest/flows';
}
/**
* Check if this version of OpenNMS supports enhanced flow API and if not throw an error.
*/
private checkForEnhancedFlows() {
if (!this.server
|| !this.server.metadata
|| !this.server.metadata.capabilities().enhancedFlows) {
throw new OnmsError('Enhanced flow API is not supported by this version of OpenNMS.');
}
}
/**
* Check if this version of OpenNMS supports ToS filtering API and if not throw an error.
*/
private checkForToSSupport() {
if (!this.server
|| !this.server.metadata
|| !this.server.metadata.capabilities().tos) {
throw new OnmsError('ToS filtering API is not supported by this version of OpenNMS.');
}
}
}
/**
* Preferred object for providing options to TopN queries.
* @category DAO
*/
export interface ITopNOptions {
/** how many series to return */
N: number;
/** the start of the timespan to query */
start?: number;
/** the end of the timespan to query */
end?: number;
/** the requested time interval between rows */
step?: number;
/** include an additional "other" result for non-matches */
includeOther?: boolean;
/** the node ID or foreignSource:foreignId tuple */
exporterNodeCriteria?: string;
/** filter based on SNMP interface */
ifIndex?: number;
}