Skip to content

Commit

Permalink
Merge pull request #30 from OpenNMS/smith/oce-rest
Browse files Browse the repository at this point in the history
feat(api): OCE-REST extend Alarm and summary
  • Loading branch information
j-white committed Sep 6, 2018
2 parents 8affcd8 + abd86d1 commit 93af6a0
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/dao/AlarmDAO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ export class AlarmDAO extends AbstractDAO<number, OnmsAlarm> {

alarm.detailsPage = this.getDetailsPage(alarm);

alarm.affectedNodeCount = data.affectedNodeCount;

return alarm;
}

Expand Down
4 changes: 4 additions & 0 deletions src/model/OnmsAlarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ export class OnmsAlarm implements IHasUrlValue {
/** operator instructions */
public operatorInstructions: string;

/** If this alarm is a Situation, the number of Nodes affected by its RelatedAlarms, a value of 1 otherwise */
public affectedNodeCount: number;

/** the most recent time the event has triggered this alarm */
public get lastEventTime() {
if (this.lastEvent && this.lastEvent.time) {
Expand All @@ -110,4 +113,5 @@ export class OnmsAlarm implements IHasUrlValue {
public get urlValue() {
return String(this.id);
}

}
6 changes: 6 additions & 0 deletions src/model/OnmsAlarmSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export class OnmsAlarmSummary implements IHasUrlValue {
/** the alarm's description */
public description: string;

/** the alarm's log message */
public logMessage: string;

/** the label of this alarm as defined in the alarm configuration */
public label: string;

public get urlValue() {
return String(this.id);
}
Expand Down
24 changes: 24 additions & 0 deletions test/dao/AlarmDAO.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,27 @@ describe('AlarmDAO with AlarmSummaryDTO', () => {
});
});
});

describe('Extended Situation tests', () => {
beforeEach((done) => {
auth = new OnmsAuthConfig(SERVER_USER, SERVER_PASSWORD);
server = new OnmsServer(SERVER_NAME, SERVER_URL, auth);
mockHTTP = new MockHTTP23(server);
opennms = new Client(mockHTTP);
dao = new AlarmDAO(mockHTTP);
Client.getMetadata(server, mockHTTP).then((metadata) => {
server.metadata = metadata;
done();
});
});
it('AlarmDAO.get(situations)', () => {
const filter = new Filter();
filter.withOrRestriction(new Restriction('isSituation', Comparators.EQ, 'true'));
return dao.find(filter).then((alarms) => {
expect(alarms.length).toEqual(1);
expect(alarms[0].id).toEqual(243);
expect(alarms[0].relatedAlarms.length).toEqual(3);
expect(alarms[0].affectedNodeCount).toEqual(1);
});
});
});
157 changes: 157 additions & 0 deletions test/rest/23.0.0/get/api/v2/alarms/243.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
{
"totalCount": 1,
"count": 1,
"offset": 0,
"alarm": [
{
"id": 243,
"uei": "uei.opennms.org/alarms/trigger",
"location": "Default",
"nodeId": 1,
"nodeLabel": "locally",
"reductionKey": "uei.opennms.org/alarms/trigger:localhost:0.0.0.0:FEEDBACK_F",
"type": 1,
"count": 1,
"severity": "CRITICAL",
"firstEventTime": 1536070358000,
"description": "A problem has been triggered.",
"logMessage": "A problem has been triggered on localhost/0.0.0.0/FEEDBACK_F.",
"suppressedUntil": 1536070358000,
"suppressedTime": 1536070358000,
"lastEvent": {
"id": 18766,
"uei": "uei.opennms.org/alarms/trigger",
"label": "Alarm: Generic Trigger",
"time": 1536070358000,
"host": "LAPTOP-CPLHKS5S.localdomain",
"source": "perl_send_event",
"parameters": [
{
"name": "cat1",
"value": "ENVIRONMENTAL",
"type": "string"
},
{
"name": "cat2",
"value": "HUMIDITY",
"type": "string"
},
{
"name": "hexcode",
"value": "0xfff06131",
"type": "string"
},
{
"name": "ip",
"value": "0.0.0.0",
"type": "string"
},
{
"name": "node",
"value": "localhost",
"type": "string"
},
{
"name": "related-reductionKey",
"value": "uei.opennms.org/alarms/trigger:localhost:0.0.0.0:FEEDBACK_A",
"type": "string"
},
{
"name": "service",
"value": "FEEDBACK_F",
"type": "string"
},
{
"name": "type",
"value": "ENV",
"type": "string"
}
],
"createTime": 1536070358205,
"description": "A problem has been triggered.",
"logMessage": "A problem has been triggered on localhost/0.0.0.0/FEEDBACK_F.",
"severity": "CRITICAL",
"log": "Y",
"display": "Y",
"nodeId": 1,
"nodeLabel": "locally",
"location": "Default"
},
"parameters": [
{
"name": "cat1",
"value": "ENVIRONMENTAL",
"type": "string"
},
{
"name": "cat2",
"value": "HUMIDITY",
"type": "string"
},
{
"name": "hexcode",
"value": "0xfff06131",
"type": "string"
},
{
"name": "ip",
"value": "0.0.0.0",
"type": "string"
},
{
"name": "node",
"value": "localhost",
"type": "string"
},
{
"name": "related-reductionKey",
"value": "uei.opennms.org/alarms/trigger:localhost:0.0.0.0:FEEDBACK_A",
"type": "string"
},
{
"name": "service",
"value": "FEEDBACK_F",
"type": "string"
},
{
"name": "type",
"value": "ENV",
"type": "string"
}
],
"lastEventTime": 1536070358000,
"x733ProbableCause": 0,
"ifIndex": null,
"relatedAlarms": [
{
"id": 240,
"type": 2,
"severity": "CRITICAL",
"reductionKey": "uei.opennms.org/alarms/trigger:localhost:0.0.0.0:FEEDBACK_A",
"description": "A problem has been triggered.",
"label": "Alarm: Generic Trigger",
"logMessage": "A problem has been triggered on localhost/0.0.0.0/FEEDBACK_A."
},
{
"id": 241,
"type": 2,
"severity": "CRITICAL",
"reductionKey": "uei.opennms.org/alarms/trigger:localhost:0.0.0.0:FEEDBACK_B",
"description": "A problem has been triggered.",
"label": "Alarm: Generic Trigger",
"logMessage": "A problem has been triggered on localhost/0.0.0.0/FEEDBACK_B."
},
{
"id": 242,
"type": 2,
"severity": "CRITICAL",
"reductionKey": "uei.opennms.org/alarms/trigger:localhost:0.0.0.0:FEEDBACK_C",
"description": "A problem has been triggered.",
"label": "Alarm: Generic Trigger",
"logMessage": "A problem has been triggered on localhost/0.0.0.0/FEEDBACK_C."
}
],
"affectedNodeCount": 1
}
]
}
5 changes: 5 additions & 0 deletions test/rest/MockHTTP23.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export class MockHTTP23 extends AbstractHTTP {
result.type = 'application/json';
return Promise.resolve(result);
}
case 'api/v2/alarms?limit=1000&_s=isSituation%3D%3Dtrue': {
const result = OnmsResult.ok(require('./23.0.0/get/api/v2/alarms/243.json'));
result.type = 'application/json';
return Promise.resolve(result);
}
}

throw new Error('Not yet implemented: GET ' + urlObj.toString());
Expand Down

0 comments on commit 93af6a0

Please sign in to comment.