Skip to content

Commit

Permalink
fix: add fields to monitored services
Browse files Browse the repository at this point in the history
  • Loading branch information
synqotik committed Oct 6, 2023
1 parent 340ba5b commit ad3d90d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/model/OnmsMonitoredService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { IpInterfaceDAO } from './../dao/IpInterfaceDAO';
import {Moment} from 'moment';

import {IHasUrlValue} from '../api/IHasUrlValue';
Expand Down Expand Up @@ -35,6 +36,14 @@ export class OnmsMonitoredService implements IHasUrlValue {
/** the current status */
public status?: OnmsServiceStatusType;

public ipInterfaceId?: number;

public ipAddress?: string;

public nodeId?: number;

public nodeLabel?: string;

/** @inheritdoc */
public get urlValue() {
return this.type ? this.type.name : 'null';
Expand All @@ -59,6 +68,22 @@ export class OnmsMonitoredService implements IHasUrlValue {
service.status = OnmsServiceStatusType.forId(data.status);
}

if (data.ipInterfaceId) {
service.ipInterfaceId = data.ipInterfaceId;
}

if (data.ipAddress) {
service.ipAddress = data.ipAddress;
}

if (data.nodeId) {
service.nodeId = data.nodeId;
}

if (data.nodeLabel) {
service.nodeLabel = data.nodeLabel;
}

return service;
}
}
30 changes: 29 additions & 1 deletion test/dao/MonitoredServiceDAO.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('MonitoredServiceDAO with v2 API', () => {
});
});

it('MonitoredServiceDAO.get(4)', () => {
it('MonitoredServiceDAO.get(4), does not have all fields', () => {
return dao.get(4).then((service: OnmsMonitoredService) => {
expect(service.id).toEqual(4);

Expand All @@ -53,6 +53,34 @@ describe('MonitoredServiceDAO with v2 API', () => {
expect(service.status?.label).toEqual('MANAGED');

expect(service.urlValue).toEqual('DeviceConfig-default');

expect(service.ipInterfaceId).toEqual(1);
expect(service.ipAddress).not.toBeDefined();
expect(service.nodeId).not.toBeDefined();
});
});

it('MonitoredServiceDAO.get(99), has all fields', () => {
return dao.get(99).then((service: OnmsMonitoredService) => {
expect(service.id).toEqual(99);

// Spot check some of the known properties
expect(service.down).toBeTruthy();
expect(service.lastGood?.valueOf()).toEqual(1651862554301);
expect(service.lastFail?.valueOf()).toEqual(1663000042923);

expect(service.type?.id).toEqual(1);
expect(service.type?.name).toEqual('DeviceConfig-default');

expect(service.status?.id).toEqual('A');
expect(service.status?.label).toEqual('MANAGED');

expect(service.urlValue).toEqual('DeviceConfig-default');

expect(service.ipInterfaceId).toEqual(101);
expect(service.ipAddress).toEqual('192.168.1.119');
expect(service.nodeId).toEqual(142);
expect(service.nodeLabel).toEqual('node119');
});
});

Expand Down
19 changes: 19 additions & 0 deletions test/rest/32.0.0/get/api/v2/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": 1651862554301,
"lastFail": 1663000042923,
"statusLong": "Managed",
"ipInterfaceId": 101,
"ipAddress": "192.168.1.119",
"nodeId": 142,
"nodeLabel": "node119",
"serviceType": {
"id": 1,
"name": "DeviceConfig-default"
},
"id": 99
}
3 changes: 3 additions & 0 deletions test/rest/MockHTTP32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export class MockHTTP32 extends AbstractMockHTTP {
case 'api/v2/ifservices/4': {
return this.okJsonFile('./32.0.0/get/api/v2/4.json');
}
case 'api/v2/ifservices/99': {
return this.okJsonFile('./32.0.0/get/api/v2/99.json');
}
}
}
}

0 comments on commit ad3d90d

Please sign in to comment.