-
Notifications
You must be signed in to change notification settings - Fork 46
/
pushbullet.js
81 lines (76 loc) · 3.05 KB
/
pushbullet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//将这个文件替换 ./uptime-kuma/server/notification-providers/pushbullet.js
//并更改16行域名,企业微信通知部署教程:https://pighog.vercel.app/p/c99d.html
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
var qs = require('qs');
const { DOWN, UP } = require("../../src/util");
class Pushbullet extends NotificationProvider {
name = "pushbullet";
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
let okMsg = "Sent Successfully.";
try {
let pushbulletUrl = "你的站点域名!示例:https://xxxx.repl.co";
let config = {
headers: {
"Content-Type": "application/json"
}
};
if (heartbeatJSON == null) {
let testdata = {
"type": "note",
"title": "Uptime Kuma Alert",
"body": "Testing Successful.",
}
// 提交 构造from表单
var access_token_data = qs.stringify(testdata);
var _config = {
method: 'post',
url: pushbulletUrl,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data : access_token_data
};
await axios(_config)
} else if (heartbeatJSON["status"] == DOWN) {
let downdata = {
"type": "note",
"title": "UptimeKuma Alert: " + monitorJSON["name"],
"body": "[🔴 Down] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
}
// 提交 构造from表单
var access_token_data = qs.stringify(downdata);
var _config = {
method: 'post',
url: pushbulletUrl,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data : access_token_data
};
await axios(_config)
} else if (heartbeatJSON["status"] == UP) {
let updata = {
"type": "note",
"title": "UptimeKuma Alert: " + monitorJSON["name"],
"body": "[✅ Up] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
}
// 提交 构造from表单
var access_token_data = qs.stringify(updata);
var _config = {
method: 'post',
url: pushbulletUrl,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data : access_token_data
};
await axios(_config)
}
return okMsg;
} catch (error) {
this.throwGeneralAxiosError(error)
}
}
}
module.exports = Pushbullet;