Allow to change ping, status and message via event

This commit is contained in:
Ilya 2023-08-20 18:49:11 +03:00
parent d9a928f7c8
commit 47e1d5d9e0
4 changed files with 11 additions and 3 deletions

View file

@ -1,6 +1,6 @@
# UptimeKuma-api
Supports UptimeKuma versions from 1.13.1 to 1.18.0
Supports UptimeKuma versions from 1.13.1 to 1.21.0
## Installation

View file

@ -1,6 +1,6 @@
{
"name": "uptimekuma-api",
"version": "1.0.4",
"version": "1.0.5",
"description": "",
"main": "src/index.js",
"types": "src/index.d.ts",

6
src/index.d.ts vendored
View file

@ -1,12 +1,18 @@
export default class UptimeKumaApi {
constructor(baseURL: string);
/**
* Starts pushing heartbeats to the server
* @param code The monitor code
* @param interval The interval in seconds
*/
startPushing(code: string, interval?: number);
cancelPushing();
on(event: "pushSuccessful", handle: (url: string) => void);
on(event: "pushFailed", handle: (url: string, err: Error) => void);
on(event: "prePush", handle: (url: string, params: {status:"up"|"down",msg:string,ping?:number}) => void);
status(name?:string): Promise<[{
id: number,

View file

@ -12,7 +12,9 @@ module.exports = class UptimeKumaApi extends EventEmitter {
}
push(url) {
client.get(url).then(res => {
let params = {status:"up",msg:"OK",ping:undefined};
this.emit("prePush", url, params);
client.get(url,{params}).then(res => {
this.emit("pushSuccessful", url);
}).catch(err => {
this.emit("pushFailed", url, err);