-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(model): add model objects for alarms, events, and more
- Loading branch information
Benjamin Reed
committed
Jun 2, 2017
1 parent
259c16a
commit b8e76a3
Showing
8 changed files
with
274 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
}); |