Package Exports
- @slimio/alert
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@slimio/alert) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Alert
Requirements
- Node.js v10 or higher
Getting Started
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/alertUsage example
A simple addon that will throw an alarm every second...
// Require Dependencies
const Addon = require("@slimio/addon");
const alert = require("@slimio/alert");
const metrics = require("@slimio/metrics");
// Declare addons
const test = new Addon("test");
const { Entity } = metrics(test);
const { Alarm } = alert(test);
let intervalId;
const MyEntity = new Entity("MyEntity", {
description: "Hello world!"
});
test.on("awake", () => {
intervalId = setInterval(() => {
new Alarm("hello world!", {
correlateKey: "test_alarm",
entity: MyEntity
});
}, 1000);
test.ready();
});
test.on("close", () => {
clearInterval(intervalId);
});
module.exports = test;API
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.
Alarm
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.
Properties
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.
License
MIT