Skip to content

Commit

Permalink
feat(model): add model objects for alarms, events, and more
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Reed committed Jun 2, 2017
1 parent 259c16a commit b8e76a3
Show file tree
Hide file tree
Showing 8 changed files with 274 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ import {OnmsVersion} from './api/OnmsVersion';
import {ServerMetadata} from './api/ServerMetadata';
import {ServerType} from './api/Constants';

import {OnmsAlarm} from './model/OnmsAlarm';
import {OnmsAlarmType} from './model/OnmsAlarmType';
import {OnmsEvent} from './model/OnmsEvent';
import {OnmsParm} from './model/OnmsParm';
import {OnmsServiceType} from './model/OnmsServiceType';
import {OnmsSeverity} from './model/OnmsSeverity';
import {OnmsTroubleTicketState} from './model/OnmsTroubleTicketState';

import {AxiosHTTP} from './rest/AxiosHTTP';
import {SuperAgentHTTP} from './rest/SuperAgentHTTP';

import {Client} from './Client';

/** @hidden */
const API = Object.freeze({
OnmsAuthConfig,
OnmsError,
Expand All @@ -23,9 +32,22 @@ const API = Object.freeze({
ServerType,
});

/** @hidden */
const Model = Object.freeze({
OnmsAlarm,
OnmsAlarmType,
OnmsEvent,
OnmsParm,
OnmsServiceType,
OnmsSeverity,
OnmsTroubleTicketState,
});

/** @hidden */
const Rest = Object.freeze({
AxiosHTTP,
SuperAgentHTTP,
});

export {API, Rest, Client};
/** @hidden */
export {API, Model, Rest, Client};
73 changes: 73 additions & 0 deletions src/model/OnmsAlarm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import {Moment} from 'moment';

import {OnmsAlarmType, ALARM_TYPES} from './OnmsAlarmType';
import {OnmsEvent} from './OnmsEvent';
import {OnmsParm} from './OnmsParm';
import {OnmsSeverity, SEVERITIES} from './OnmsSeverity';
import {OnmsTroubleTicketState, TROUBLE_TICKET_STATES} from './OnmsTroubleTicketState';

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

/** the number of times this alarm has triggered */
public count: number;

/** the user that acknowledged this alarm */
public ackUser: string;

/** the time this alarm was acknowledged */
public ackTime: Moment;

/** the UEI of the event associated with this alarm */
public uei: string;

/** the alarm's severity */
public severity: OnmsSeverity;

/** the alarm's type */
public type: OnmsAlarmType;

/** the alarm's description */
public description: string;

/** the first time an event has triggered this alarm */
public firstEventTime: Moment;

/** the most recent event that triggered this alarm */
public lastEvent: OnmsEvent;

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

/** the alarm's reduction key */
public reductionKey: string;

/** the trouble ticket ID associated with this alarm */
public troubleTicket: string;

/** the state of the trouble ticket associated with this alarm */
public troubleTicketState: OnmsTroubleTicketState;

/** the node's ID associated with this alarm */
public nodeId: number;

/** the node's label associated with this alarm */
public nodeLabel: string;

/** the parms emitted with this alarm's event */
public parms: OnmsParm[];

/** the most recent time the event has triggered this alarm */
public get lastEventTime() {
if (this.lastEvent && this.lastEvent.time) {
return this.lastEvent.time;
}
return undefined;
}

}
15 changes: 15 additions & 0 deletions src/model/OnmsAlarmType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {OnmsEnum} from '../internal/OnmsEnum';

/**
* Represents an OpenNMS alarm type.
* @module OnmsAlarmType
*/ /** */
export class OnmsAlarmType extends OnmsEnum {
}

/** @hidden */
export const ALARM_TYPES = Object.freeze({
1: new OnmsAlarmType(1, 'possible resolution'),
2: new OnmsAlarmType(2, 'resolution event'),
3: new OnmsAlarmType(3, 'no possible resolution'),
});
58 changes: 58 additions & 0 deletions src/model/OnmsEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {Moment} from 'moment';
import {Address4, Address6} from 'ip-address';
import {OnmsParm} from './OnmsParm';
import {OnmsServiceType} from './OnmsServiceType';
import {OnmsSeverity} from './OnmsSeverity';

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

/** the UEI of this event */
public uei: string;

/** the node's ID associated with this event */
public nodeId: number;

/** the node's label associated with this event */
public nodeLabel: string;

/** the interface associated with this event */
public ipAddress: Address4 | Address6;

/** the severity of this event */
public severity: OnmsSeverity;

/** when the event was created */
public createTime: Moment;

/** when the event was received by OpenNMS */
public time: Moment;

/** which subsystem the event came from */
public source: string;

/** the description of is event */
public description: string;

/** the log message of the event */
public logMessage: string;

/** the service associated with the event */
public service: OnmsServiceType;

/** the parms emitted with this alarm's event */
public parms: OnmsParm[];

/** the service name associated with the event */
public get serviceName() {
if (this.service && this.service.name) {
return this.service.name;
}
return undefined;
}
}
48 changes: 48 additions & 0 deletions src/model/OnmsParm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {Util} from '../internal/Util';

/**
* Represents an OpenNMS event or alarm parameter.
* @module OnmsParm
*/ /** */
export class OnmsParm {
/** the name of the parm */
public name: string;

/** the raw parm value from the server (as a string) */
public valueString: string;

/** the parm type */
public type: string;

/** the value coerced to a native type (if possible) */
public get value() {
switch (this.type) {
// numeric types
case 'Counter32':
case 'Counter64':
case 'Gauge32':
case 'Gauge64':
case 'Int32':
case 'Int64':
case 'TimeTicks':
return parseInt(this.type, 10);

// other types
case 'Null': return null;
case 'IpAddress': return Util.toIPAddress(this.valueString);

// everything else is a string
case 'ObjectIdentifier':
case 'OctetString':
case 'Opaque':
case 'string':
default: return this.valueString;
}
}

constructor(name: string, type: string, value: string) {
this.name = name;
this.type = type;
this.valueString = value;
}
}
11 changes: 11 additions & 0 deletions src/model/OnmsServiceType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Represents an OpenNMS service.
* @module OnmsServiceType
*/ /** */
export class OnmsServiceType {
/** the service ID */
public id: number;

/** the service name */
public name: string;
}
19 changes: 19 additions & 0 deletions src/model/OnmsSeverity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {OnmsEnum} from '../internal/OnmsEnum';
/**
* Represents an OpenNMS severity.
* @module OnmsSeverity
*/ /** */
export class OnmsSeverity extends OnmsEnum {
}

/* tslint:disable:object-literal-sort-keys */
/** @hidden */
export const SEVERITIES = Object.freeze({
INDETERMINATE: new OnmsSeverity(1, 'INDETERMINATE'),
CLEARED: new OnmsSeverity(2, 'CLEARED'),
NORMAL: new OnmsSeverity(3, 'NORMAL'),
WARNING: new OnmsSeverity(4, 'WARNING'),
MINOR: new OnmsSeverity(5, 'MINOR'),
MAJOR: new OnmsSeverity(6, 'MAJOR'),
CRITICAL: new OnmsSeverity(7, 'CRITICAL'),
});
27 changes: 27 additions & 0 deletions src/model/OnmsTroubleTicketState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {OnmsEnum} from '../internal/OnmsEnum';

/**
* Represents an OpenNMS trouble ticket state.
* @module OnmsTroubleTicketState
*/ /** */
export class OnmsTroubleTicketState extends OnmsEnum {
}

/* tslint:disable:object-literal-sort-keys */
/** @hidden */
export const TROUBLE_TICKET_STATES = Object.freeze({
OPEN: new OnmsTroubleTicketState(0, 'OPEN'),
CREATE_PENDING: new OnmsTroubleTicketState(1, 'CREATE_PENDING'),
CREATE_FAILED: new OnmsTroubleTicketState(2, 'CREATE_FAILED'),
UPDATE_PENDING: new OnmsTroubleTicketState(3, 'UPDATE_PENDING'),
UPDATE_FAILED: new OnmsTroubleTicketState(4, 'UPDATE_FAILED'),
CLOSED: new OnmsTroubleTicketState(5, 'CLOSED'),
CLOSE_PENDING: new OnmsTroubleTicketState(6, 'CLOSE_PENDING'),
CLOSE_FAILED: new OnmsTroubleTicketState(7, 'CLOSE_FAILED'),
RESOLVED: new OnmsTroubleTicketState(8, 'RESOLVED'),
RESOLVE_PENDING: new OnmsTroubleTicketState(9, 'RESOLVE_PENDING'),
RESOLVE_FAILED: new OnmsTroubleTicketState(10, 'RESOLVE_FAILED'),
CANCELLED: new OnmsTroubleTicketState(11, 'CANCELLED'),
CANCEL_PENDING: new OnmsTroubleTicketState(12, 'CANCEL_PENDING'),
CANCEL_FAILED: new OnmsTroubleTicketState(13, 'CANCEL_FAILED'),
});

0 comments on commit b8e76a3

Please sign in to comment.