Permalink
Browse files

feat(alarms): expose the sticky and journal memos

  • Loading branch information...
j-white committed Jul 11, 2017
1 parent a352ea8 commit adbcb3af7e5c205193686202edde3ba1dd7ba515
View
@@ -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';
@@ -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;
}
@@ -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;
}
}
View
@@ -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.
@@ -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) {
View
@@ -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;
}
@@ -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');
});
});
});
@@ -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"
}]
}
View
@@ -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';

0 comments on commit adbcb3a

Please sign in to comment.