Permalink
Browse files

feat(dao): add alarm setTTicketId/setTTicketState

This adds the old ReSTv1/ReSTv1 API for setting ticket ID and state
on an alarm.  It also modifies ack/unack/escalate/clear to accept
an OnmsAlarm object in addition to an alarm ID.
  • Loading branch information...
RangerRick committed Jul 24, 2017
1 parent d83abd6 commit bb429f6bfb1d7a4a26a5a864d1d97be6914cb277
Showing with 126 additions and 35 deletions.
  1. +55 −13 src/dao/AlarmDAO.ts
  2. +51 −22 test/dao/AlarmDAO.spec.ts
  3. +10 −0 test/rest/MockHTTP19.ts
  4. +10 −0 test/rest/MockHTTP21.ts
View
@@ -14,7 +14,7 @@ import {AlarmTypes} from '../model/OnmsAlarmType';
import {OnmsParm} from '../model/OnmsParm';
import {OnmsServiceType} from '../model/OnmsServiceType';
import {Severities} from '../model/OnmsSeverity';
import {TroubleTicketStates} from '../model/OnmsTroubleTicketState';
import {OnmsTroubleTicketState, TroubleTicketStates} from '../model/OnmsTroubleTicketState';
import {OnmsMemo} from '../model/OnmsMemo';
import {log, catDao} from '../api/Log';
@@ -116,6 +116,7 @@ export class AlarmDAO extends AbstractDAO<number, OnmsAlarm> {
/**
* Fetch an alarm.
*
* @version ReST v1+
* @param {number} id - the alarm's ID
* @return an {@link OnmsAlarm}
*/
@@ -129,6 +130,7 @@ export class AlarmDAO extends AbstractDAO<number, OnmsAlarm> {
/**
* Find matching alarms.
*
* @version ReST v1+
* @param {Filter} filter - the filter to use when querying
* @return an array of {@link OnmsAlarm}s
*/
@@ -159,49 +161,89 @@ export class AlarmDAO extends AbstractDAO<number, OnmsAlarm> {
/**
* Acknowledge an alarm.
*
* @param {number} id - the alarm ID
* @version ReST v1+
* @param {number|OnmsAlarm} id - the {@link OnmsAlarm} or alarm ID
* @param {string=} user - the user to ack the alarm as (only administrators have the right to do this)
*/
public async acknowledge(id: number, user?: string): Promise<void> {
public async acknowledge(alarm: number|OnmsAlarm, user?: string): Promise<void> {
const alarmId = (typeof(alarm) === 'number' ? alarm : alarm.id);
const parameters = {} as IHash<string>;
parameters.ack = 'true';
if (user !== undefined) {
parameters.ackUser = user;
}
return this.put(this.pathToAlarmsEndpoint() + '/' + id, parameters);
return this.put(this.pathToAlarmsEndpoint() + '/' + alarmId, parameters);
}
/**
* Un-acknowledge an alarm.
*
* @param {number} id - the alarm ID
* @version ReST v1+
* @param {number|OnmsAlarm} alarm - the {@link OnmsAlarm} or alarm ID
*/
public async unacknowledge(id: number): Promise<void> {
public async unacknowledge(alarm: number|OnmsAlarm): Promise<void> {
const alarmId = (typeof(alarm) === 'number' ? alarm : alarm.id);
const parameters = {} as IHash<string>;
parameters.ack = 'false';
return this.put(this.pathToAlarmsEndpoint() + '/' + id, parameters);
return this.put(this.pathToAlarmsEndpoint() + '/' + alarmId, parameters);
}
/**
* Escalate an alarm.
*
* @param {number} id - the alarm ID
* @version ReST v1+
* @param {number|OnsmAlarm} alarm - the {@link OnmsAlarm} or alarm ID
*/
public async escalate(id: number): Promise<void> {
public async escalate(alarm: number|OnmsAlarm): Promise<void> {
const alarmId = (typeof(alarm) === 'number' ? alarm : alarm.id);
const parameters = {} as IHash<string>;
parameters.escalate = 'true';
return this.put(this.pathToAlarmsEndpoint() + '/' + id, parameters);
return this.put(this.pathToAlarmsEndpoint() + '/' + alarmId, parameters);
}
/**
* Clear an alarm.
*
* @param {number} id - the alarm ID
* @version ReST v1+
* @param {number|OnmsAlarm} alarm - the {@link OnmsAlarm} or alarm ID
*/
public async clear(id: number): Promise<void> {
public async clear(alarm: number|OnmsAlarm): Promise<void> {
const alarmId = (typeof(alarm) === 'number' ? alarm : alarm.id);
const parameters = {} as IHash<string>;
parameters.clear = 'true';
return this.put(this.pathToAlarmsEndpoint() + '/' + id, parameters);
return this.put(this.pathToAlarmsEndpoint() + '/' + alarmId, parameters);
}
/**
* Associate a ticket ID with the alarm.
*
* @version ReST v1+
* @deprecated Please use the Rest v2 {@link AlarmDAO#createTicket} method
* instead to invoke an OpenNMS ticketer plugin.
* @param {number|OnmsAlarm} alarm - the {@link OnmsAlarm} or alarm ID
* @param {string} ticketId - the ticket ID
*/
public async setTTicketId(alarm: number|OnmsAlarm, ticketId: string): Promise<void> {
const alarmId = (typeof(alarm) === 'number' ? alarm : alarm.id);
const parameters = {} as IHash<string>;
parameters.ticketId = ticketId;
return this.put(this.pathToAlarmsEndpoint() + '/' + alarmId, parameters);
}
/**
* Update the state of the ticket associated with the alarm.
*
* @version ReST v1+
* @deprecated Please use the Rest v2 {@link AlarmDAO#createTicket} method
* instead to invoke an OpenNMS ticketer plugin.
* @param {number|OnmsAlarm} alarm - the {@link OnmsAlarm} or alarm ID
* @param {string} state - the ticket state
*/
public async setTTicketState(alarm: number|OnmsAlarm, state: OnmsTroubleTicketState): Promise<void> {
const alarmId = (typeof(alarm) === 'number' ? alarm : alarm.id);
const parameters = {} as IHash<string>;
parameters.ticketState = state.label;
return this.put(this.pathToAlarmsEndpoint() + '/' + alarmId, parameters);
}
/** given an optional filter, generate an {@link OnmsHTTPOptions} object for DAO calls */
View
@@ -16,6 +16,9 @@ import {Restriction} from '../../src/api/Restriction';
import {AlarmDAO} from '../../src/dao/AlarmDAO';
import {OnmsAlarm} from '../../src/model/OnmsAlarm';
import {TroubleTicketStates} from '../../src/model/OnmsTroubleTicketState';
import {MockHTTP19} from '../rest/MockHTTP19';
import {MockHTTP21} from '../rest/MockHTTP21';
@@ -50,20 +53,33 @@ describe('AlarmDAO with v1 API', () => {
expect(alarms.length).toEqual(1);
});
});
it('AlarmDAO.acknowledge(id=404725)', () => {
return dao.acknowledge(404725);
});
it('AlarmDAO.acknowledge(id=404725, user=ranger)', () => {
return dao.acknowledge(404725, 'ranger');
for (const method of ['acknowledge', 'unacknowledge', 'escalate', 'clear']) {
it('AlarmDAO.' + method + '(id=404725)', () => {
return dao[method](404725);
});
it('AlarmDAO.' + method + '(OnmsAlarm(404725))', () => {
const alarm = new OnmsAlarm();
alarm.id=404725;
return dao[method](alarm);
});
}
it('AlarmDAO.setTTicketId(alarmId=404725, ticketId=abcde)', () => {
return dao.setTTicketId(404725, 'abcde');
});
it('AlarmDAO.unacknowledge(id=404725)', () => {
return dao.unacknowledge(404725);
it('AlarmDAO.setTTicketId(alarm=OnmsAlarm(404725), ticketId=abcde)', () => {
const alarm = new OnmsAlarm();
alarm.id=404725;
return dao.setTTicketId(alarm, 'abcde');
});
it('AlarmDAO.escalate(id=404725)', () => {
return dao.escalate(404725);
it('AlarmDAO.setTTicketState(alarmId=404725, ticketState=RESOLVED)', () => {
return dao.setTTicketState(404725, TroubleTicketStates.RESOLVED);
});
it('AlarmDAO.clear(id=404725)', () => {
return dao.clear(404725);
it('AlarmDAO.setTTicketState(alarm=OnmsAlarm(404725), ticketState=RESOLVED)', () => {
const alarm = new OnmsAlarm();
alarm.id=404725;
return dao.setTTicketState(alarm, TroubleTicketStates.RESOLVED);
});
});
@@ -106,19 +122,32 @@ describe('AlarmDAO with v2 API', () => {
expect(alarm.journal.body).toEqual('journal');
});
});
it('AlarmDAO.acknowledge(id=404725)', () => {
return dao.acknowledge(404725);
});
it('AlarmDAO.acknowledge(id=404725, user=ranger)', () => {
return dao.acknowledge(404725, 'ranger');
for (const method of ['acknowledge', 'unacknowledge', 'escalate', 'clear']) {
it('AlarmDAO.' + method + '(id=404725)', () => {
return dao[method](404725);
});
it('AlarmDAO.' + method + '(OnmsAlarm(404725))', () => {
const alarm = new OnmsAlarm();
alarm.id=404725;
return dao[method](alarm);
});
}
it('AlarmDAO.setTTicketId(alarmId=404725, ticketId=abcde)', () => {
return dao.setTTicketId(404725, 'abcde');
});
it('AlarmDAO.unacknowledge(id=404725)', () => {
return dao.unacknowledge(404725);
it('AlarmDAO.setTTicketId(alarm=OnmsAlarm(404725), ticketId=abcde)', () => {
const alarm = new OnmsAlarm();
alarm.id=404725;
return dao.setTTicketId(alarm, 'abcde');
});
it('AlarmDAO.escalate(id=404725)', () => {
return dao.escalate(404725);
it('AlarmDAO.setTTicketState(alarmId=404725, ticketState=RESOLVED)', () => {
return dao.setTTicketState(404725, TroubleTicketStates.RESOLVED);
});
it('AlarmDAO.clear(id=404725)', () => {
return dao.clear(404725);
it('AlarmDAO.setTTicketState(alarm=OnmsAlarm(404725), ticketState=RESOLVED)', () => {
const alarm = new OnmsAlarm();
alarm.id=404725;
return dao.setTTicketState(alarm, TroubleTicketStates.RESOLVED);
});
});
View
@@ -102,6 +102,16 @@ export class MockHTTP19 extends AbstractHTTP {
result.type = 'text/plain';
return Promise.resolve(result);
}
case 'rest/alarms/404725?ticketId=abcde': {
const result = OnmsResult.ok('');
result.type = 'text/plain';
return Promise.resolve(result);
}
case 'rest/alarms/404725?ticketState=RESOLVED': {
const result = OnmsResult.ok('');
result.type = 'text/plain';
return Promise.resolve(result);
}
}
return Promise.reject(OnmsResult.error('Not yet implemented: PUT ' + urlObj.toString()));
View
@@ -79,6 +79,16 @@ export class MockHTTP21 extends AbstractHTTP {
result.type = 'text/plain';
return Promise.resolve(result);
}
case 'api/v2/alarms/404725?ticketId=abcde': {
const result = OnmsResult.ok('');
result.type = 'text/plain';
return Promise.resolve(result);
}
case 'api/v2/alarms/404725?ticketState=RESOLVED': {
const result = OnmsResult.ok('');
result.type = 'text/plain';
return Promise.resolve(result);
}
}
return Promise.reject(OnmsResult.error('Not yet implemented: PUT ' + urlObj.toString()));

0 comments on commit bb429f6

Please sign in to comment.