Skip to content

Commit

Permalink
feat(alarms): expose the sticky and journal memos
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse White committed Jul 12, 2017
1 parent a352ea8 commit adbcb3a
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/dao/AlarmDAO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {OnmsParm} from '../model/OnmsParm';
import {OnmsServiceType} from '../model/OnmsServiceType';
import {Severities} from '../model/OnmsSeverity';
import {TroubleTicketStates} from '../model/OnmsTroubleTicketState';
import {OnmsMemo} from '../model/OnmsMemo';

import {log, catDao} from '../api/Log';
import {Category} from 'typescript-logging';
Expand Down Expand Up @@ -104,6 +105,9 @@ export class AlarmDAO extends AbstractDAO<number, OnmsAlarm> {
}
}

alarm.sticky = this.toMemo(data.stickyMemo);
alarm.journal = this.toMemo(data.reductionKeyMemo);

return alarm;
}

Expand Down Expand Up @@ -150,4 +154,20 @@ export class AlarmDAO extends AbstractDAO<number, OnmsAlarm> {
private pathToAlarmsEndpoint() {
return this.getApiVersion() === 2 ? 'api/v2/alarms' : 'rest/alarms';
}

/** generate a memo from the given dictionary */
private toMemo(data: any): OnmsMemo {
if (!data) {
return null;
}

const memo = new OnmsMemo();
memo.id = data.id;
memo.author = data.author;
memo.body = data.body;
memo.created = this.toDate(data.created);
memo.updated = this.toDate(data.updated);
return memo;
}

}
7 changes: 7 additions & 0 deletions src/model/OnmsAlarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {OnmsParm} from './OnmsParm';
import {OnmsServiceType} from './OnmsServiceType';
import {OnmsSeverity} from './OnmsSeverity';
import {OnmsTroubleTicketState} from './OnmsTroubleTicketState';
import {OnmsMemo} from './OnmsMemo';

/**
* Represents an OpenNMS alarm.
Expand Down Expand Up @@ -75,6 +76,12 @@ export class OnmsAlarm {
/** the parameters emitted with this alarm's event */
public parameters: OnmsParm[];

/** sticky memo - a note associated with this specific alarm instance */
public sticky: OnmsMemo;

/** journal memo - a note associated with the reduction key for this alarm */
public journal: OnmsMemo;

/** the most recent time the event has triggered this alarm */
public get lastEventTime() {
if (this.lastEvent && this.lastEvent.time) {
Expand Down
22 changes: 22 additions & 0 deletions src/model/OnmsMemo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {Moment} from 'moment';

/**
* Represents an OpenNMS memo.
* @module OnmsMemo
*/ /** */
export class OnmsMemo {
/** the memo ID */
public id: number;

/** the content of the memo */
public body: string;

/** the user who last updated (or created) the memo */
public author: string;

/** when the memo was last updated */
public updated: Moment;

/** when the memo was created */
public created: Moment;
}
7 changes: 7 additions & 0 deletions test/dao/AlarmDAO.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,11 @@ describe('AlarmDAO with v2 API', () => {
expect(alarms.length).toEqual(0);
});
});
it('should make the journal and sticky notes available - AlarmDAO.get(82416)', () => {
return dao.get(82416).then((alarm) => {
expect(alarm.id).toEqual(82416);
expect(alarm.sticky.body).toEqual('sticky');
expect(alarm.journal.body).toEqual('journal');
});
});
});
79 changes: 79 additions & 0 deletions test/rest/21.0.0/get/api/v2/alarms/82416.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"id": 82416,
"description": "A problem has been triggered.",
"ifIndex": null,
"uei": "uei.opennms.org/alarms/trigger",
"serviceType": null,
"x733AlarmType": null,
"x733ProbableCause": 0,
"reductionKey": "uei.opennms.org/alarms/trigger:f5:0.0.0.0:HTTPS_POOL",
"ackId": 1,
"stickyMemo": {
"id": 1,
"created": 1499786686515,
"body": "sticky",
"author": "admin",
"updated": 1499786686515
},
"reductionKeyMemo": {
"reductionKey": "uei.opennms.org/alarms/trigger:f5:0.0.0.0:HTTPS_POOL",
"id": 2,
"created": 1499786689405,
"body": "journal",
"author": "admin",
"updated": 1499786689405
},
"firstEventTime": 1499716228000,
"suppressedUntil": 1499716228000,
"suppressedTime": 1499716228000,
"lastEvent": {
"id": 34,
"ifIndex": null,
"serviceType": null,
"host": "noise",
"uei": "uei.opennms.org/alarms/trigger",
"time": 1499786650000,
"source": "perl_send_event",
"createTime": 1499786650999,
"description": "A problem has been triggered.",
"logMessage": "A problem has been triggered on f5/0.0.0.0/HTTPS_POOL.",
"log": "Y",
"display": "Y",
"severity": "CRITICAL",
"parameters": [{
"name": "service",
"value": "HTTPS_POOL",
"type": "string"
}, {
"name": "ip",
"value": "0.0.0.0",
"type": "string"
}, {
"name": "node",
"value": "f5",
"type": "string"
}]
},
"lastEventTime": 1499786650000,
"managedObjectInstance": null,
"managedObjectType": null,
"ossPrimaryKey": null,
"qosAlarmState": null,
"type": 1,
"count": 2,
"severity": "CRITICAL",
"logMessage": "A problem has been triggered on f5/0.0.0.0/HTTPS_POOL.",
"parameters": [{
"name": "service",
"value": "HTTPS_POOL",
"type": "string"
}, {
"name": "ip",
"value": "0.0.0.0",
"type": "string"
}, {
"name": "node",
"value": "f5",
"type": "string"
}]
}
5 changes: 5 additions & 0 deletions test/rest/MockHTTP21.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export class MockHTTP21 extends AbstractHTTP {
result.type = 'application/json';
return Promise.resolve(result);
}
case 'api/v2/alarms/82416': {
const result = OnmsResult.ok(require('./21.0.0/get/api/v2/alarms/82416.json'));
result.type = 'application/json';
return Promise.resolve(result);
}
case 'api/v2/alarms?limit=1000&_s=alarm.id%3D%3D6806': {
const result = OnmsResult.ok(require('./21.0.0/get/api/v2/alarms/id.eq.6806.json'));
result.type = 'application/json';
Expand Down

0 comments on commit adbcb3a

Please sign in to comment.