Skip to content

Commit

Permalink
Merge pull request #1071 from OpenNMS/jira/NMS-16939-add-nodeparentid
Browse files Browse the repository at this point in the history
NMS-16939: Add parentNodeId to OnmsNode
  • Loading branch information
synqotik authored Jan 3, 2025
2 parents d83c28c + 23c839d commit c65c55d
Show file tree
Hide file tree
Showing 9 changed files with 1,500 additions and 11,410 deletions.
12,531 changes: 1,128 additions & 11,403 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"cache-loader": "^4.1.0",
"chai": "^5.0.0",
"child_process": "^1.0.2",
"eslint": "^8.49.0",
"eslint": "^8.57.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-tsdoc": "^0.4.0",
Expand Down Expand Up @@ -93,9 +93,9 @@
"lodash": "^4.17.20",
"moment": "^2.29.1",
"object-hash": "^3.0.0",
"picocolors": "^1.0.0",
"qs": "^6.10.3",
"table": "^6.8.0",
"picocolors": "^1.1.1",
"qs": "^6.13.1",
"table": "^6.9.0",
"version_compare": "^0.0.3",
"x2js": "^3.4.2"
},
Expand Down
4 changes: 4 additions & 0 deletions src/model/OnmsNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export class OnmsNode implements IHasUrlValue {
/** the time the node was created */
public createTime?: Moment;

/** the ID of the parent node, if any */
public nodeParentId?: number;

/** the parent of this node */
public parent?: OnmsNode;

Expand Down Expand Up @@ -117,6 +120,7 @@ export class OnmsNode implements IHasUrlValue {
node.location = data.location;
node.foreignSource = data.foreignSource || undefined;
node.foreignId = data.foreignId || undefined;
node.nodeParentId = data.nodeParentID || undefined;
node.sysContact = data.sysContact;
node.sysDescription = data.sysDescription;
node.sysLocation = data.sysLocation;
Expand Down
49 changes: 46 additions & 3 deletions test/dao/NodeDAO.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {NodeDAO} from '../../src/dao/NodeDAO';

import {MockHTTP19} from '../rest/MockHTTP19';
import {MockHTTP21} from '../rest/MockHTTP21';
import {MockHTTP33} from '../rest/MockHTTP33';

/** @hidden */
// tslint:disable-next-line
Expand All @@ -43,9 +44,11 @@ describe('NodeDAO with v1 API', () => {
done();
});
});

it('NodeDAO.get(43, [recurse=false])', () => {
return dao.get(43).then((node) => {
expect(node.id).toEqual(43);
expect(node.nodeParentId).toBeUndefined();
expect(node.categories.length).toEqual(2);
expect(node.categories[0]).toBeInstanceOf(OnmsCategory);
expect(node.foreignSource).toBeUndefined();
Expand All @@ -54,9 +57,11 @@ describe('NodeDAO with v1 API', () => {
expect(node.type).toBeInstanceOf(OnmsNodeType);
});
});

it('NodeDAO.get(43, recurse=true)', () => {
return dao.get(43, true).then((node) => {
expect(node.id).toEqual(43);
expect(node.nodeParentId).toBeUndefined();
expect(node.categories.length).toEqual(2);
expect(node.categories[0]).toBeInstanceOf(OnmsCategory);
expect(node.foreignSource).toBeUndefined();
Expand All @@ -73,23 +78,26 @@ describe('NodeDAO with v1 API', () => {
expect(snmp.ifOperStatus).toEqual(SnmpStatusTypes['1']);
expect(snmp.ifName).toEqual('br0');
expect(snmp.physAddr).toBeDefined();
expect(snmp.physAddr.toString()).toEqual('40:8D:5C:55:55:A2');
expect(snmp.physAddr?.toString()).toEqual('40:8D:5C:55:55:A2');

expect(node.ipInterfaces.length).toEqual(2);
const ip = node.ipInterfaces[0];
expect(ip.hostname).toEqual('butters.internal.opennms.com');
expect(ip.services.length).toEqual(5);

expect(ip.snmpInterface.toJSON()).toEqual(snmp.toJSON());
expect(ip.snmpInterface?.toJSON()).toEqual(snmp.toJSON());
});
});

it('NodeDAO.find(id=43)', () => {
const filter = new Filter();
filter.withOrRestriction(new Restriction('id', Comparators.EQ, 43));

return dao.find(filter).then((nodes) => {
expect(nodes.length).toEqual(1);
});
});

it('NodeDAO.properties() should reject', () => {
return expect(dao.searchProperties()).rejects.toBeDefined();
});
Expand All @@ -109,9 +117,11 @@ describe('NodeDAO with v2 API', () => {
done();
});
});

it('NodeDAO.get(81, [recurse=false])', () => {
return dao.get(81).then((node) => {
expect(node.id).toEqual(81);
expect(node.nodeParentId).toBeUndefined();
expect(node.categories.length).toEqual(1);
expect(node.categories[0]).toBeInstanceOf(OnmsCategory);
expect(node.foreignSource).toEqual('test');
Expand All @@ -120,9 +130,11 @@ describe('NodeDAO with v2 API', () => {
expect(node.type).toBeInstanceOf(OnmsNodeType);
});
});

it('NodeDAO.get(81, recurse=true)', () => {
return dao.get(81, true).then((node) => {
expect(node.id).toEqual(81);
expect(node.nodeParentId).toBeUndefined();
expect(node.categories.length).toEqual(1);
expect(node.categories[0]).toBeInstanceOf(OnmsCategory);
expect(node.foreignSource).toEqual('test');
Expand All @@ -145,9 +157,10 @@ describe('NodeDAO with v2 API', () => {
expect(ip.services.length).toEqual(3);

expect(ip.snmpInterface).toBeDefined();
expect(ip.snmpInterface.id).toEqual(2018);
expect(ip.snmpInterface?.id).toEqual(2018);
});
});

/* find is currently broken in v2
it('NodeDAO.find(id=81)', () => {
const filter = new Filter();
Expand All @@ -161,3 +174,33 @@ describe('NodeDAO with v2 API', () => {
return expect(dao.searchProperties()).rejects.toBeDefined();
});
});

describe('NodeDAO with v2 API, OpenNMS v33', () => {
beforeEach((done) => {
auth = new OnmsAuthConfig(SERVER_USER, SERVER_PASSWORD);
const builder = OnmsServer.newBuilder(SERVER_URL).setName(SERVER_NAME).setAuth(auth);
server = builder.build();
mockHTTP = new MockHTTP33(server);
opennms = new Client(mockHTTP);
dao = new NodeDAO(mockHTTP);
Client.getMetadata(server, mockHTTP).then((metadata) => {
server = builder.setMetadata(metadata).build();
mockHTTP.server = server;
done();
});
});

it('NodeDAO.get(81, [recurse=false])', () => {
return dao.get(81).then((node) => {
expect(node.id).toEqual(81);
expect(node.nodeParentId).toEqual(181);
expect(node.categories.length).toEqual(1);
expect(node.categories[0]).toBeInstanceOf(OnmsCategory);
expect(node.foreignSource).toEqual('test');
expect(node.createTime).toBeInstanceOf(moment);
expect(node.type).toBeDefined();
expect(node.type).toBeInstanceOf(OnmsNodeType);
});
});
});

16 changes: 16 additions & 0 deletions test/rest/33.0.0/get/api/v2/nodes/4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"down": true,
"notify": null,
"status": "A",
"source": null,
"qualifier": null,
"lastGood": 1681862554301,
"lastFail": 1693000042923,
"statusLong": "Managed",
"ipInterfaceId": 1,
"serviceType": {
"id": 1,
"name": "DeviceConfig-default"
},
"id": 4
}
92 changes: 92 additions & 0 deletions test/rest/33.0.0/get/api/v2/nodes/81.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"assetRecord": {
"additionalhardware": null,
"admin": null,
"assetNumber": null,
"autoenable": null,
"building": "test",
"category": "Unspecified",
"circuitId": null,
"comment": null,
"connection": null,
"cpu": null,
"dateInstalled": null,
"department": null,
"description": null,
"displayCategory": null,
"division": null,
"enable": null,
"floor": null,
"hdd1": null,
"hdd2": null,
"hdd3": null,
"hdd4": null,
"hdd5": null,
"hdd6": null,
"id": 1960,
"inputpower": null,
"lastModifiedBy": "",
"lastModifiedDate": 1699799013442,
"latitude": 35.68642,
"lease": null,
"leaseExpires": null,
"longitude": -78.727554,
"maintContractExpiration": null,
"maintContractNumber": null,
"maintcontract": null,
"managedObjectInstance": null,
"managedObjectType": null,
"manufacturer": null,
"modelNumber": null,
"notifyCategory": null,
"numpowersupplies": null,
"operatingSystem": null,
"password": null,
"pollerCategory": null,
"port": null,
"rack": null,
"rackunitheight": null,
"ram": null,
"region": null,
"room": null,
"serialNumber": null,
"slot": null,
"snmpcommunity": null,
"storagectrl": null,
"supportPhone": null,
"thresholdCategory": null,
"username": null,
"vendor": null,
"vendorAssetNumber": null,
"vendorFax": null,
"vendorPhone": null,
"vmwareManagedEntityType": null,
"vmwareManagedObjectId": null,
"vmwareManagementServer": null,
"vmwareState": null,
"vmwareTopologyInfo": null
},
"categories": [
{
"authorizedGroups": [],
"id": 7,
"name": "Monitor_SNMP"
}
],
"createTime": 1699799013442,
"foreignId": "sin.local",
"foreignSource": "test",
"id": 81,
"nodeParentID": 181,
"label": "Sin.local",
"labelSource": "U",
"lastCapsdPoll": 1701532685099,
"location": "Default",
"sysContact": "Administrator <[email protected]>",
"sysDescription": "Darwin With-Teeth.local 24.1.0 Darwin Kernel Version 24.1.0: Mon Nov 4 14:16:27 PDT 2024; root:xnu-3789.70.16~2/RELEASE_M1_PRO M1_PRO",
"sysLocation": "Right here, right now.",
"sysName": "With-Teeth.local",
"sysObjectId": ".1.3.6.1.4.1.8072.3.2.255",
"type": "A"
}

19 changes: 19 additions & 0 deletions test/rest/33.0.0/get/api/v2/nodes/99.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"down": true,
"notify": null,
"status": "A",
"source": null,
"qualifier": null,
"lastGood": 1681862554301,
"lastFail": 1693000042923,
"statusLong": "Managed",
"ipInterfaceId": 101,
"ipAddress": "192.168.1.119",
"nodeId": 142,
"nodeLabel": "node119",
"serviceType": {
"id": 1,
"name": "DeviceConfig-default"
},
"id": 99
}
Loading

0 comments on commit c65c55d

Please sign in to comment.