Skip to content

Commit

Permalink
Merge pull request #37 from OpenNMS/mbrooks/drift2
Browse files Browse the repository at this point in the history
feat(drift2): HZN-1559,HZN-1570,HZN-1571
  • Loading branch information
mattixtech authored Jun 7, 2019
2 parents a731c60 + 9b684cf commit bfe6d6b
Show file tree
Hide file tree
Showing 9 changed files with 1,210 additions and 16 deletions.
18 changes: 16 additions & 2 deletions src/api/OnmsHTTPOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class OnmsHTTPOptions {
public headers = {} as IHash<string>;

/** HTTP parameters to be passed on the URL. */
public parameters = {} as IHash<string>;
public parameters = {} as IHash<string | string[]>;

/** HTTP data to be passed when POSTing */
public data: any;
Expand Down Expand Up @@ -75,7 +75,21 @@ export class OnmsHTTPOptions {
*/
public withParameter(key: string, value?: any): OnmsHTTPOptions {
if (value !== undefined) {
this.parameters[key] = '' + value;
// Since parameters can be repeated an arbitrary number of times we will store them in an array in the map
// as soon as the occurrence of a given key is > 1
if (this.parameters[key]) {
const currentValue = this.parameters[key];
if (Array.isArray(currentValue)) {
currentValue.push('' + value);
} else {
const newArrayValue = [];
newArrayValue.push(currentValue);
newArrayValue.push(value);
this.parameters[key] = newArrayValue;
}
} else {
this.parameters[key] = '' + value;
}
}
return this;
}
Expand Down
13 changes: 12 additions & 1 deletion src/api/ServerMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,21 @@ export class ServerMetadata {
}
}

/** Returs a convenient data structure with all capabilities listed. */
/** Does this version support the drift 2.0 flows enhancements? */
public enhancedFlows() {
if (this.type && this.type === ServerTypes.MERIDIAN) {
return this.version.ge('2019.0.0');
} else {
return this.version.ge('25.0.0');
}
}

/** Returns a convenient data structure with all capabilities listed. */
public capabilities() {
return {
ackAlarms: this.ackAlarms(),
apiVersion: this.apiVersion(),
enhancedFlows: this.enhancedFlows(),
flows: this.flows(),
graphs: this.graphs(),
outageSummaries: this.outageSummaries(),
Expand All @@ -121,6 +131,7 @@ export class ServerMetadata {
+ ',apiVersion=' + this.apiVersion()
+ ',type=' + this.type.toString()
+ ',ackAlarms=' + this.ackAlarms()
+ ',enhancedFlows=' + this.enhancedFlows()
+ ',flows=' + this.flows()
+ ',graphs=' + this.graphs()
+ ',outageSummaries=' + this.outageSummaries()
Expand Down
358 changes: 345 additions & 13 deletions src/dao/FlowDAO.ts

Large diffs are not rendered by default.

122 changes: 122 additions & 0 deletions test/dao/FlowDAO25.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import {MockHTTP25} from '../rest/MockHTTP25';

declare const await, describe, beforeEach, it, xit, expect, jest, require;

import {Client} from '../../src/Client';

import {OnmsAuthConfig} from '../../src/api/OnmsAuthConfig';
import {OnmsServer} from '../../src/api/OnmsServer';

import {OnmsFlowExporter} from '../../src/model/OnmsFlowExporter';
import {OnmsFlowExporterSummary} from '../../src/model/OnmsFlowExporterSummary';
import {OnmsFlowTable} from '../../src/model/OnmsFlowTable';

import {FlowDAO} from '../../src/dao/FlowDAO';

/** @hidden */
// tslint:disable-next-line
const moment = require('moment');

const SERVER_NAME='Demo';
const SERVER_URL='http://demo.opennms.org/opennms/';
const SERVER_USER='demo';
const SERVER_PASSWORD='demo';

let opennms : Client, server, auth, mockHTTP, dao : FlowDAO;

describe('FlowDAO25', () => {
beforeEach((done) => {
auth = new OnmsAuthConfig(SERVER_USER, SERVER_PASSWORD);
server = new OnmsServer(SERVER_NAME, SERVER_URL, auth);
mockHTTP = new MockHTTP25(server);
opennms = new Client(mockHTTP);
dao = new FlowDAO(mockHTTP);
Client.getMetadata(server, mockHTTP).then((metadata) => {
server.metadata = metadata;
done();
});
});
it('FlowDao.getApplications()', () => {
return dao.getApplications().then((applications) => {
expect(['http', 'https', 'test']).toEqual(expect.arrayContaining(applications));
});
});
it('FlowDao.getSummaryForApplications()', () => {
return dao.getSummaryForApplications().then((summary) => {
expect(summary).toBeInstanceOf(OnmsFlowTable);
expect(summary.start).toBeInstanceOf(moment);
expect(summary.end).toBeInstanceOf(moment);
expect(summary.headers).toContain('Application');
});
});
it('FlowDao.getSeriesForApplications()', () => {
return dao.getSeriesForApplications().then((series) => {
expect(series.start).toBeInstanceOf(moment);
expect(series.end).toBeInstanceOf(moment);
expect(series.columns.length).toEqual(10);
expect(series.timestamps.length).toEqual(49);
expect(series.values.length).toEqual(10);
expect(series.values[0].length).toEqual(49);
});
});
it('FlowDao.getSummaryForConversations()', () => {
return dao.getSummaryForConversations().then((summary) => {
expect(summary).toBeInstanceOf(OnmsFlowTable);
expect(summary.start).toBeInstanceOf(moment);
expect(summary.end).toBeInstanceOf(moment);
expect(summary.headers).toContain('Location');
expect(summary.rows.length).toEqual(10);
});
});
it('FlowDao.getSeriesForConversations()', () => {
return dao.getSeriesForConversations().then((series) => {
expect(series.start).toBeInstanceOf(moment);
expect(series.end).toBeInstanceOf(moment);
expect(series.columns.length).toEqual(10);
expect(series.timestamps.length).toEqual(2);
expect(series.values.length).toEqual(10);
expect(series.values[0].length).toEqual(2);
});
});
it('FlowDao.getHosts()', () => {
return dao.getHosts().then((hosts) => {
expect(['10.1.1.1', '192.168.0.1', 'myhost']).toEqual(expect.arrayContaining(hosts));
});
});
it('FlowDao.getSummaryForTopNHosts()', () => {
return dao.getSummaryForTopNHosts().then((summary) => {
expect(summary).toBeInstanceOf(OnmsFlowTable);
expect(summary.start).toBeInstanceOf(moment);
expect(summary.end).toBeInstanceOf(moment);
expect(summary.headers).toContain('host');
});
});
it('FlowDao.getSummaryForHosts()', () => {
return dao.getSummaryForHosts().then((summary) => {
expect(summary).toBeInstanceOf(OnmsFlowTable);
expect(summary.start).toBeInstanceOf(moment);
expect(summary.end).toBeInstanceOf(moment);
expect(summary.headers).toContain('host');
});
});
it('FlowDao.getSeriesForTopNHosts()', () => {
return dao.getSeriesForTopNHosts().then((series) => {
expect(series.start).toBeInstanceOf(moment);
expect(series.end).toBeInstanceOf(moment);
expect(series.columns.length).toEqual(10);
expect(series.timestamps.length).toEqual(49);
expect(series.values.length).toEqual(10);
expect(series.values[0].length).toEqual(49);
});
});
it('FlowDao.getSeriesForHosts()', () => {
return dao.getSeriesForHosts().then((series) => {
expect(series.start).toBeInstanceOf(moment);
expect(series.end).toBeInstanceOf(moment);
expect(series.columns.length).toEqual(10);
expect(series.timestamps.length).toEqual(49);
expect(series.values.length).toEqual(10);
expect(series.values[0].length).toEqual(49);
});
});
});
5 changes: 5 additions & 0 deletions test/rest/25.0.0/get/rest/flows/applications/enumerate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
"http",
"https",
"test"
]
10 changes: 10 additions & 0 deletions test/rest/25.0.0/get/rest/flows/hosts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"end": 1520374562644,
"headers": [
"host",
"Bytes In",
"Bytes Out"
],
"rows": [],
"start": 1520360162644
}
5 changes: 5 additions & 0 deletions test/rest/25.0.0/get/rest/flows/hosts/enumerate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
"10.1.1.1",
"192.168.0.1",
"myhost"
]
Loading

0 comments on commit bfe6d6b

Please sign in to comment.