- Node.js v12 or higher
This package is available in the Node Package Repository and can be easily installed with npm or yarn.
$ npm i @slimio/alert
# or
$ yarn add @slimio/alert
A simple addon that will throw an alarm every second...
import Addon from "@slimio/addon";
import alert from "@slimio/alert";
import metrics from "@slimio/metrics";
const test = new Addon("test");
const { Entity } = metrics(test);
const { Alarm } = alert(test);
const ALARM_INTERVAL = 1_000;
const MY_ENTITY = new Entity("MyEntity", {
description: "Hello world!"
});
test.registerInterval(() => {
new Alarm("hello world!", {
correlateKey: "test_alarm",
entity: MY_ENTITY
});
}, ALARM_INTERVAL);
export default test;
The alert package return a function described by the following interface:
declare function Alert(addon: Addon): {
Alarm: typeof Alarm;
};
Each instance of Alarm are unique to the local Addon.
This section describe the methods and properties of Alarm Object.
constructor(message: string, options: Alert.ConstructorOptions)
Create a new Alarm Object.
new Alarm("hello world alarm", {
correlateKey: "test_alarm"
});
Available options are described the following interface:
interface ConstructorOptions {
severity?: SlimIO.AlarmSeverity;
entity?: Metrics.Entity | string | number;
correlateKey: string;
}
toJSON(): SlimIO.RawAlarm
Return a raw alarm. Refer to @slimio/tsd
for more information.
declare class Alarm extends events {
public cid: SlimIO.CID;
public severity: number;
public entity: Metrics.Entity | number;
public message: string;
public correlateKey: string;
static DefaultSeverity: number;
static Severity: SlimIO.AlarmSeverity;
}
Severity is defined in @slimio/tsd
as follow:
enum AlarmSeverity {
Critical,
Major,
Minor
}
The default severity is defined as 1 for Major.
Name | Refactoring | Security Risk | Usage |
---|---|---|---|
@slimio/is | Minor | Low | Type checker |
@slimio/safe-emitter | Medium | Safe emitter | |
@slimio/timemap | Low | Time map | |
@slimio/utils | Minor | High | Bunch of useful functions |
MIT