mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-09-14 23:47:00 +08:00
Compare commits
454 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
11d01ebc78 | ||
|
66cfbd02c3 | ||
|
688f23035b | ||
|
7701e2ad36 | ||
|
8e72d6f534 | ||
|
278b88a9d9 | ||
|
084cf01fcd | ||
|
25c8196641 | ||
|
baf5613dfa | ||
|
695691468c | ||
|
4891ec4527 | ||
|
e2a87eb430 | ||
|
80927332cb | ||
|
a0eb733d54 | ||
|
21d556528f | ||
|
357466cc90 | ||
|
b038d09349 | ||
|
5dd4231e56 | ||
|
c6d0c431bd | ||
|
d1b7f4c834 | ||
|
5c4180fb45 | ||
|
345e61abca | ||
|
dd1526deff | ||
|
be26bb75d9 | ||
|
99fb5836e2 | ||
|
2f5a565ce4 | ||
|
973db9d4b2 | ||
|
6bece8796e | ||
|
e7d1b4e14a | ||
|
e5c6783781 | ||
|
ac68a35d3a | ||
|
d825dbf828 | ||
|
cfb4bbc6cb | ||
|
293015ff35 | ||
|
18d8b3a8e0 | ||
|
d55794e1a5 | ||
|
3d50572dd7 | ||
|
cdb38d49eb | ||
|
80b55786a4 | ||
|
fe40d819bd | ||
|
3dbd8277f0 | ||
|
771d21c4ad | ||
|
ed6b4e5ae5 | ||
|
3b9c95a8a8 | ||
|
cdf6922bdd | ||
|
9954ba82e7 | ||
|
19873e5b9e | ||
|
13ae878ee8 | ||
|
1774bb86dc | ||
|
c583037dff | ||
|
8223121cd8 | ||
|
ff22010330 | ||
|
a9d691a6a8 | ||
|
7c529d8f83 | ||
|
4fe0891a60 | ||
|
bd5496d267 | ||
|
a0736e04b2 | ||
|
df8fcffb19 | ||
|
9da712054a | ||
|
af78da1dd9 | ||
|
9e041f219b | ||
|
8c60e902e1 | ||
|
de74efb2e6 | ||
|
9ee2780e9e | ||
|
a386f1fc9e | ||
|
35154ef9c5 | ||
|
1baa592824 | ||
|
9882fc65b1 | ||
|
3e5e7e6e32 | ||
|
0e725569e5 | ||
|
afcfb7e19c | ||
|
eaee55fc8f | ||
|
affac0a97b | ||
|
a12e7eba72 | ||
|
4f6035899d | ||
|
dd77baabe1 | ||
|
820f2eec9f | ||
|
4b913c8b4c | ||
|
d01c7c3faa | ||
|
772a946234 | ||
|
f8c9a20afd | ||
|
cea894cc6d | ||
|
79b38e0e7b | ||
|
7cc9783436 | ||
|
21405f71b5 | ||
|
b4b6e07e6b | ||
|
cf4220901b | ||
|
f3996fdef4 | ||
|
1dfe5227ad | ||
|
4ead0609af | ||
|
a8bf52b1e0 | ||
|
ede6d90497 | ||
|
4b8e86efb7 | ||
|
5f706e1921 | ||
|
722c64a4d1 | ||
|
23de52ca5a | ||
|
3d3fb357f9 | ||
|
3b9aa00126 | ||
|
29267e5c2e | ||
|
3e801323b6 | ||
|
b80fd81d24 | ||
|
9cb776405a | ||
|
de7ae3e2db | ||
|
e49ced0524 | ||
|
7e782edf44 | ||
|
43e1e3c272 | ||
|
dc4cf7087f | ||
|
65a0a2b2b5 | ||
|
2d269c3639 | ||
|
11bad53709 | ||
|
9f7782b1c1 | ||
|
9fb8f94e22 | ||
|
7a34103da6 | ||
|
8955c3816b | ||
|
7761e9a05e | ||
|
c9d6e576ab | ||
|
97d38ee1a8 | ||
|
cc94609423 | ||
|
149f8c3646 | ||
|
bdcbd6389b | ||
|
c06b929529 | ||
|
d3ecdb8456 | ||
|
4e420ee3ff | ||
|
a00561ff09 | ||
|
6af44e0780 | ||
|
596402e71f | ||
|
62bbc1cf55 | ||
|
19fc7d31e6 | ||
|
6708eed121 | ||
|
3c56a6f395 | ||
|
2b46693995 | ||
|
c61a3d360f | ||
|
392f95cdd2 | ||
|
dfc6e5ea5b | ||
|
ba4d925374 | ||
|
d37c33ad42 | ||
|
c04194191f | ||
|
de9ad0fe60 | ||
|
8884c2108b | ||
|
ac8ca36895 | ||
|
71c34694b7 | ||
|
2128ed5ce3 | ||
|
09ab6a015b | ||
|
ec858eb67a | ||
|
c4c3fc81b2 | ||
|
8aa577529f | ||
|
cdd5067b17 | ||
|
5fdb01308a | ||
|
eb1a1d0ac7 | ||
|
a1fc283b3c | ||
|
419b684433 | ||
|
8bc139d8c1 | ||
|
91dfd8dfaa | ||
|
1f405cf2a0 | ||
|
cf61077dd8 | ||
|
4396e0d4d8 | ||
|
240db1d173 | ||
|
ef06b5376d | ||
|
186d733134 | ||
|
225ba61e22 | ||
|
11b32ce553 | ||
|
3707919025 | ||
|
d10e378fb1 | ||
|
370328c3b8 | ||
|
1d8a82ae3e | ||
|
7da336e975 | ||
|
b8c12cca2a | ||
|
88fcfcc6fc | ||
|
fcb22f7d05 | ||
|
5be41990bc | ||
|
09149f50e0 | ||
|
8f60274582 | ||
|
7dadac3ebe | ||
|
28c29f755d | ||
|
b426840b5b | ||
|
4f2d39d5fc | ||
|
4012fc6964 | ||
|
d1b52bc098 | ||
|
c9a32f9dbb | ||
|
b884f82de6 | ||
|
65928a26c7 | ||
|
abe00efa7f | ||
|
0c364fc288 | ||
|
0d21529037 | ||
|
37ae8eb44a | ||
|
8897385690 | ||
|
6132a45c7c | ||
|
f68452c47a | ||
|
fea8ef8367 | ||
|
9d71e34a83 | ||
|
37031fb9a7 | ||
|
58ec53fb1d | ||
|
57190b58c6 | ||
|
6c2948d2de | ||
|
68f389868c | ||
|
af5d7cbb0b | ||
|
1fa8c0f9fe | ||
|
9a8bea5761 | ||
|
56f448bfe5 | ||
|
2b46da0f47 | ||
|
9bd76c2795 | ||
|
376d84c742 | ||
|
4b3a2ee71b | ||
|
1634df5a39 | ||
|
039fdb0730 | ||
|
20af2d9d95 | ||
|
04806ba4f3 | ||
|
3ff910a8f8 | ||
|
343a1d3344 | ||
|
f1c184c30c | ||
|
f3fe392ec4 | ||
|
f3c09f2bbd | ||
|
85eb084305 | ||
|
0735f12d19 | ||
|
8ed2b59410 | ||
|
0b8dddba24 | ||
|
2114295381 | ||
|
bc95875aa0 | ||
|
c1efe0f26d | ||
|
a0d0d5b015 | ||
|
8d05d80a5f | ||
|
36942de329 | ||
|
771ca09331 | ||
|
3cb287a40e | ||
|
9c3bb67b6b | ||
|
5200e10aab | ||
|
f1a396b0f7 | ||
|
83a59bd984 | ||
|
446b5fa9e4 | ||
|
0d1b5321ad | ||
|
1e1cc86a10 | ||
|
9825b33ef3 | ||
|
00f733d352 | ||
|
fd10897988 | ||
|
317024ed72 | ||
|
f604d96c5b | ||
|
f30f00655f | ||
|
891f09def7 | ||
|
6b5e179bb0 | ||
|
f653aba735 | ||
|
9dc02bb8e2 | ||
|
bb15fa0179 | ||
|
966066b897 | ||
|
8d24891b8e | ||
|
ba7de3fd37 | ||
|
80c8fd7372 | ||
|
a27386bb92 | ||
|
ce70b3fc62 | ||
|
06fba5b55a | ||
|
f2c294e9e5 | ||
|
332e54937e | ||
|
a1adc30a89 | ||
|
6ce882ad4a | ||
|
e392d12585 | ||
|
253214ad2b | ||
|
33de7bdb1c | ||
|
7f5d0e5490 | ||
|
1a344c1371 | ||
|
28b0f8fc00 | ||
|
0eaaa8b6fa | ||
|
5cd506e340 | ||
|
f0beccf6bf | ||
|
72c16c3aa2 | ||
|
aa8454b73f | ||
|
d23cb0b382 | ||
|
9975050872 | ||
|
f8c2909576 | ||
|
fcfe13e52d | ||
|
9f51115a19 | ||
|
4057ca6e72 | ||
|
8a3bce44ef | ||
|
dfe6f52f6a | ||
|
333a631389 | ||
|
eaa948579b | ||
|
74dd07c3ca | ||
|
f75cf3a186 | ||
|
a3e31b22bc | ||
|
078d1f96a5 | ||
|
8207f16396 | ||
|
ba82abe5f3 | ||
|
eb9c748071 | ||
|
3579520575 | ||
|
030faddd1c | ||
|
0e516a42e5 | ||
|
680dccefea | ||
|
8c9423f4de | ||
|
f433f33418 | ||
|
d4a31cf02a | ||
|
a7588adc52 | ||
|
6356b1e50a | ||
|
af6e01ee3a | ||
|
11f4cb8725 | ||
|
1bf97e701d | ||
|
4c1ac5e870 | ||
|
9e320dc5fb | ||
|
2f3f929fbd | ||
|
b776e88b26 | ||
|
49741bbef2 | ||
|
682f8e52a8 | ||
|
171aff1226 | ||
|
1f7f1f70bf | ||
|
be7d3f6142 | ||
|
7706c29564 | ||
|
9dd1b1ca0f | ||
|
21ad715e6a | ||
|
23af66f618 | ||
|
03aa685d3f | ||
|
84c1baf706 | ||
|
23808efe2a | ||
|
1db25a329f | ||
|
e314d517ad | ||
|
84d1cb73b6 | ||
|
ddd3d3bc92 | ||
|
190e85d2c8 | ||
|
d8511fa201 | ||
|
e76d29dee5 | ||
|
fb38048159 | ||
|
80f1959871 | ||
|
4ddc3b5f5e | ||
|
d173a3c663 | ||
|
45ef7b2f69 | ||
|
6b078b83bd | ||
|
22f730499f | ||
|
1be74e2720 | ||
|
32f84b5e4e | ||
|
97c7ad9cc7 | ||
|
8f449ab738 | ||
|
dbfaddafca | ||
|
511038b45a | ||
|
e8d48561fc | ||
|
aeb2feacd3 | ||
|
c01055efb3 | ||
|
17ae47d091 | ||
|
de0d1edfd4 | ||
|
0f5a243450 | ||
|
b975c24531 | ||
|
524cf7c607 | ||
|
a6acd065bb | ||
|
227cec86a8 | ||
|
ba52e1c885 | ||
|
02291730fe | ||
|
dcc065c86f | ||
|
501dc29e6d | ||
|
d2b09ef042 | ||
|
f608590526 | ||
|
a7f21bffec | ||
|
ebd42444d1 | ||
|
f0f7645c57 | ||
|
3ada6fa99b | ||
|
4fb10a4e3f | ||
|
1aac15bccc | ||
|
cbcd2a1027 | ||
|
17f038767d | ||
|
edd1c6b662 | ||
|
29be8d3ddb | ||
|
2ac1abd424 | ||
|
738a494dcb | ||
|
e575d41f7d | ||
|
8ee4b844fd | ||
|
4ae437dd61 | ||
|
6cb296b07a | ||
|
644c6a872f | ||
|
8c69c18f6d | ||
|
c1a1160767 | ||
|
a0ebd88849 | ||
|
2e9413cf33 | ||
|
278b52ec34 | ||
|
caa757a27c | ||
|
3ce117a943 | ||
|
cefe484b47 | ||
|
a700892709 | ||
|
13d721ccf8 | ||
|
6c66bff518 | ||
|
bea51d048b | ||
|
2e1a0fe4d5 | ||
|
27b0895722 | ||
|
e687698851 | ||
|
fc4312ca1a | ||
|
fbdeb30ce7 | ||
|
41bda4e1d7 | ||
|
4869e6531c | ||
|
302b9cf644 | ||
|
3c3a192943 | ||
|
b64c835cee | ||
|
5266e713e6 | ||
|
86579d245f | ||
|
b6169408be | ||
|
4f05912276 | ||
|
bf525371d9 | ||
|
89bfc3bf33 | ||
|
a2014278b8 | ||
|
70572af1af | ||
|
b31c23a43b | ||
|
f4ee5271af | ||
|
7330db3563 | ||
|
097567e5f0 | ||
|
35f300c8eb | ||
|
4c9d7ac8ca | ||
|
ca52047bf5 | ||
|
d9558833fc | ||
|
776a482a1d | ||
|
d2527d7254 | ||
|
6dfca0c163 | ||
|
df47609671 | ||
|
e63f7562f8 | ||
|
8921ed0cff | ||
|
35a56dd9e0 | ||
|
442f54de84 | ||
|
cf59832d51 | ||
|
8f259e1756 | ||
|
29b2809279 | ||
|
16f2701f61 | ||
|
3bbf269da0 | ||
|
56d716cee4 | ||
|
391692a708 | ||
|
f32fcb204f | ||
|
e8814e8479 | ||
|
193a273557 | ||
|
bb7de6aa88 | ||
|
150607cc93 | ||
|
cbbd3e20ad | ||
|
beb22f743d | ||
|
6fc34e44d9 | ||
|
7b4f90ce92 | ||
|
db6b863445 | ||
|
186ca30508 | ||
|
896e33815d | ||
|
0be8b111e2 | ||
|
cef0a0faf4 | ||
|
dfb95dfdcb | ||
|
e10ba9ed7e | ||
|
9446c2d102 | ||
|
2c581ade90 | ||
|
f286386f59 | ||
|
9286dcb6ce | ||
|
a6894d36f2 | ||
|
66573934f6 | ||
|
c444d78706 | ||
|
661fa87134 | ||
|
d48eb24046 | ||
|
aee4c22dee | ||
|
9a46b50989 | ||
|
faf3488b1e | ||
|
f3ac351d75 | ||
|
aba515e172 | ||
|
97bd306a09 | ||
|
645fd94bba | ||
|
71f00b3690 | ||
|
a21a47de93 | ||
|
f6d0f28b3a | ||
|
6de0c6a90c | ||
|
94b69935fe | ||
|
3f30feaefb | ||
|
9404efd86d |
28
.devcontainer/README.md
Normal file
28
.devcontainer/README.md
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# Codespaces
|
||||||
|
|
||||||
|
You can modifiy Uptime Kuma in your browser without setting up a local development.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
1. Click `Code` -> `Create codespace on master`
|
||||||
|
2. Wait a few minutes until you see there are two exposed ports
|
||||||
|
3. Go to the `3000` url, see if it is working
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Frontend
|
||||||
|
|
||||||
|
Since the frontend is using [Vite.js](https://vitejs.dev/), all changes in this area will be hot-reloaded.
|
||||||
|
You don't need to restart the frontend, unless you try to add a new frontend dependency.
|
||||||
|
|
||||||
|
## Backend
|
||||||
|
|
||||||
|
The backend does not automatically hot-reload.
|
||||||
|
You will need to restart the backend after changing something using these steps:
|
||||||
|
|
||||||
|
1. Click `Terminal`
|
||||||
|
2. Click `Codespaces: server-dev` in the right panel
|
||||||
|
3. Press `Ctrl + C` to stop the server
|
||||||
|
4. Press `Up` to run `npm run start-server-dev`
|
||||||
|
|
||||||
|

|
22
.devcontainer/devcontainer.json
Normal file
22
.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"image": "mcr.microsoft.com/devcontainers/javascript-node:dev-18-bookworm",
|
||||||
|
"features": {
|
||||||
|
"ghcr.io/devcontainers/features/github-cli:1": {}
|
||||||
|
},
|
||||||
|
"updateContentCommand": "npm ci",
|
||||||
|
"postCreateCommand": "",
|
||||||
|
"postAttachCommand": {
|
||||||
|
"frontend-dev": "npm run start-frontend-devcontainer",
|
||||||
|
"server-dev": "npm run start-server-dev",
|
||||||
|
"open-port": "gh codespace ports visibility 3001:public -c $CODESPACE_NAME"
|
||||||
|
},
|
||||||
|
"customizations": {
|
||||||
|
"vscode": {
|
||||||
|
"extensions": [
|
||||||
|
"streetsidesoftware.code-spell-checker",
|
||||||
|
"dbaeumer.vscode-eslint"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"forwardPorts": [3000, 3001]
|
||||||
|
}
|
10
.github/ISSUE_TEMPLATE/ask-for-help.yaml
vendored
10
.github/ISSUE_TEMPLATE/ask-for-help.yaml
vendored
@@ -26,6 +26,12 @@ body:
|
|||||||
label: "📝 Describe your problem"
|
label: "📝 Describe your problem"
|
||||||
description: "Please walk us through it step by step."
|
description: "Please walk us through it step by step."
|
||||||
placeholder: "Describe what are you asking for..."
|
placeholder: "Describe what are you asking for..."
|
||||||
|
- type: textarea
|
||||||
|
id: error-msg
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
attributes:
|
||||||
|
label: "📝 Error Message(s) or Log"
|
||||||
- type: input
|
- type: input
|
||||||
id: uptime-kuma-version
|
id: uptime-kuma-version
|
||||||
attributes:
|
attributes:
|
||||||
@@ -38,7 +44,7 @@ body:
|
|||||||
id: operating-system
|
id: operating-system
|
||||||
attributes:
|
attributes:
|
||||||
label: "💻 Operating System and Arch"
|
label: "💻 Operating System and Arch"
|
||||||
description: "Which OS is your server/device running on?"
|
description: "Which OS is your server/device running on? (For Replit, please do not report this bug)"
|
||||||
placeholder: "Ex. Ubuntu 20.04 x86"
|
placeholder: "Ex. Ubuntu 20.04 x86"
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
@@ -46,7 +52,7 @@ body:
|
|||||||
id: browser-vendor
|
id: browser-vendor
|
||||||
attributes:
|
attributes:
|
||||||
label: "🌐 Browser"
|
label: "🌐 Browser"
|
||||||
description: "Which browser are you running on?"
|
description: "Which browser are you running on? (For Replit, please do not report this bug)"
|
||||||
placeholder: "Ex. Google Chrome 95.0.4638.69"
|
placeholder: "Ex. Google Chrome 95.0.4638.69"
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
|
4
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
4
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
@@ -61,8 +61,8 @@ body:
|
|||||||
id: operating-system
|
id: operating-system
|
||||||
attributes:
|
attributes:
|
||||||
label: "💻 Operating System and Arch"
|
label: "💻 Operating System and Arch"
|
||||||
description: "Which OS is your server/device running on?"
|
description: "Which OS is your server/device running on? (For Replit, please do not report this bug)"
|
||||||
placeholder: "Ex. Ubuntu 20.04 x86"
|
placeholder: "Ex. Ubuntu 20.04 x64 "
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
- type: input
|
- type: input
|
||||||
|
1
.github/config/exclude.txt
vendored
Normal file
1
.github/config/exclude.txt
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# This is a .gitignore style file for 'GrantBirki/json-yaml-validate' Action workflow
|
34
.github/workflows/auto-test.yml
vendored
34
.github/workflows/auto-test.yml
vendored
@@ -1,4 +1,4 @@
|
|||||||
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
|
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
|
||||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
||||||
|
|
||||||
name: Auto Test
|
name: Auto Test
|
||||||
@@ -21,8 +21,8 @@ jobs:
|
|||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [macos-latest, ubuntu-latest, windows-latest]
|
os: [macos-latest, ubuntu-latest, windows-latest, ARM64]
|
||||||
node: [ 14, 16, 18, 19 ]
|
node: [ 14, 18 ]
|
||||||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -33,7 +33,7 @@ jobs:
|
|||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node }}
|
node-version: ${{ matrix.node }}
|
||||||
cache: 'npm'
|
- run: npm install npm@latest -g
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
- run: npm test
|
- run: npm test
|
||||||
@@ -41,6 +41,29 @@ jobs:
|
|||||||
HEADLESS_TEST: 1
|
HEADLESS_TEST: 1
|
||||||
JUST_FOR_TEST: ${{ secrets.JUST_FOR_TEST }}
|
JUST_FOR_TEST: ${{ secrets.JUST_FOR_TEST }}
|
||||||
|
|
||||||
|
# As a lot of dev dependencies are not supported on ARMv7, we have to test it separately and just test if `npm ci --production` works
|
||||||
|
armv7-simple-test:
|
||||||
|
needs: [ check-linters ]
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
timeout-minutes: 15
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ ARMv7 ]
|
||||||
|
node: [ 14.21.3, 18.16.1 ]
|
||||||
|
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- run: git config --global core.autocrlf false # Mainly for Windows
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Use Node.js ${{ matrix.node }}
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node }}
|
||||||
|
- run: npm install npm@latest -g
|
||||||
|
- run: npm ci --production
|
||||||
|
|
||||||
check-linters:
|
check-linters:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
@@ -52,7 +75,6 @@ jobs:
|
|||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 14
|
node-version: 14
|
||||||
cache: 'npm'
|
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm run lint
|
- run: npm run lint
|
||||||
|
|
||||||
@@ -67,7 +89,6 @@ jobs:
|
|||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 14
|
node-version: 14
|
||||||
cache: 'npm'
|
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
- run: npm run cy:test
|
- run: npm run cy:test
|
||||||
@@ -83,7 +104,6 @@ jobs:
|
|||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 14
|
node-version: 14
|
||||||
cache: 'npm'
|
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
- run: npm run cy:run:unit
|
- run: npm run cy:run:unit
|
||||||
|
26
.github/workflows/json-yaml-validate.yml
vendored
Normal file
26
.github/workflows/json-yaml-validate.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
name: json-yaml-validate
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
pull-requests: write # enable write permissions for pull request comments
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
json-yaml-validate:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: json-yaml-validate
|
||||||
|
id: json-yaml-validate
|
||||||
|
uses: GrantBirki/json-yaml-validate@v1.3.0
|
||||||
|
with:
|
||||||
|
comment: "true" # enable comment mode
|
||||||
|
exclude_file: ".github/config/exclude.txt" # gitignore style file for exclusions
|
3
.gitignore
vendored
3
.gitignore
vendored
@@ -23,3 +23,6 @@ cypress/screenshots
|
|||||||
|
|
||||||
extra/exe-builder/bin
|
extra/exe-builder/bin
|
||||||
extra/exe-builder/obj
|
extra/exe-builder/obj
|
||||||
|
|
||||||
|
.vs
|
||||||
|
.vscode
|
||||||
|
@@ -47,17 +47,17 @@ Here are some references:
|
|||||||
|
|
||||||
❌ Won't Merge
|
❌ Won't Merge
|
||||||
- A dedicated pr for translating existing languages (You can now translate on https://weblate.kuma.pet)
|
- A dedicated pr for translating existing languages (You can now translate on https://weblate.kuma.pet)
|
||||||
- Do not pass auto test
|
- Do not pass the auto test
|
||||||
- Any breaking changes
|
- Any breaking changes
|
||||||
- Duplicated pull request
|
- Duplicated pull requests
|
||||||
- Buggy
|
- Buggy
|
||||||
- UI/UX is not close to Uptime Kuma
|
- UI/UX is not close to Uptime Kuma
|
||||||
- Existing logic is completely modified or deleted for no reason
|
- Modifications or deletions of existing logic without a valid reason.
|
||||||
- A function that is completely out of scope
|
- Adding functions that is completely out of scope
|
||||||
- Convert existing code into other programming languages
|
- Converting existing code into other programming languages
|
||||||
- Unnecessary large code changes (Hard to review, causes code conflicts to other pull requests)
|
- Unnecessarily large code changes that are hard to review and cause conflicts with other PRs.
|
||||||
|
|
||||||
The above cases cannot cover all situations.
|
The above cases may not cover all possible situations.
|
||||||
|
|
||||||
I (@louislam) have the final say. If your pull request does not meet my expectations, I will reject it, no matter how much time you spend on it. Therefore, it is essential to have a discussion beforehand.
|
I (@louislam) have the final say. If your pull request does not meet my expectations, I will reject it, no matter how much time you spend on it. Therefore, it is essential to have a discussion beforehand.
|
||||||
|
|
||||||
|
25
README.md
25
README.md
@@ -23,7 +23,7 @@ It is a temporary live demo, all data will be deleted after 10 minutes. Use the
|
|||||||
|
|
||||||
## ⭐ Features
|
## ⭐ Features
|
||||||
|
|
||||||
* Monitoring uptime for HTTP(s) / TCP / HTTP(s) Keyword / Ping / DNS Record / Push / Steam Game Server / Docker Containers
|
* Monitoring uptime for HTTP(s) / TCP / HTTP(s) Keyword / HTTP(s) Json Query / Ping / DNS Record / Push / Steam Game Server / Docker Containers
|
||||||
* Fancy, Reactive, Fast UI/UX
|
* Fancy, Reactive, Fast UI/UX
|
||||||
* Notifications via Telegram, Discord, Gotify, Slack, Pushover, Email (SMTP), and [90+ notification services, click here for the full list](https://github.com/louislam/uptime-kuma/tree/master/src/components/notifications)
|
* Notifications via Telegram, Discord, Gotify, Slack, Pushover, Email (SMTP), and [90+ notification services, click here for the full list](https://github.com/louislam/uptime-kuma/tree/master/src/components/notifications)
|
||||||
* 20 second intervals
|
* 20 second intervals
|
||||||
@@ -49,8 +49,12 @@ Uptime Kuma is now running on http://localhost:3001
|
|||||||
|
|
||||||
### 💪🏻 Non-Docker
|
### 💪🏻 Non-Docker
|
||||||
|
|
||||||
Required Tools:
|
Requirements:
|
||||||
- [Node.js](https://nodejs.org/en/download/) >= 14
|
- Platform
|
||||||
|
- ✅ Major Linux distros such as Debian, Ubuntu, CentOS, Fedora and ArchLinux etc.
|
||||||
|
- ✅ Windows 10 (x64), Windows Server 2012 R2 (x64) or higher
|
||||||
|
- ❌ Replit / Heroku
|
||||||
|
- [Node.js](https://nodejs.org/en/download/) 14 / 16 / 18 / 20.4
|
||||||
- [npm](https://docs.npmjs.com/cli/) >= 7
|
- [npm](https://docs.npmjs.com/cli/) >= 7
|
||||||
- [Git](https://git-scm.com/downloads)
|
- [Git](https://git-scm.com/downloads)
|
||||||
- [pm2](https://pm2.keymetrics.io/) - For running Uptime Kuma in the background
|
- [pm2](https://pm2.keymetrics.io/) - For running Uptime Kuma in the background
|
||||||
@@ -87,6 +91,10 @@ pm2 monit
|
|||||||
pm2 save && pm2 startup
|
pm2 save && pm2 startup
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Windows Portable (x64)
|
||||||
|
|
||||||
|
https://github.com/louislam/uptime-kuma/files/11886108/uptime-kuma-win64-portable-1.0.1.zip
|
||||||
|
|
||||||
### Advanced Installation
|
### Advanced Installation
|
||||||
|
|
||||||
If you need more options or need to browse via a reverse proxy, please read:
|
If you need more options or need to browse via a reverse proxy, please read:
|
||||||
@@ -144,17 +152,18 @@ Telegram Notification Sample:
|
|||||||
|
|
||||||
If you love this project, please consider giving me a ⭐.
|
If you love this project, please consider giving me a ⭐.
|
||||||
|
|
||||||
## 🗣️ Discussion
|
## 🗣️ Discussion / Ask for Help
|
||||||
|
|
||||||
### Issues Page
|
⚠️ For any general or technical questions, please don't send me an email, as I am unable to provide support in that manner. I will not response if you asked such questions.
|
||||||
|
|
||||||
You can discuss or ask for help in [issues](https://github.com/louislam/uptime-kuma/issues).
|
I recommend using Google, GitHub Issues, or Uptime Kuma's Subreddit for finding answers to your question. If you cannot find the information you need, feel free to ask:
|
||||||
|
|
||||||
### Subreddit
|
- [GitHub Issues](https://github.com/louislam/uptime-kuma/issues)
|
||||||
|
- [Subreddit r/Uptime kuma](https://www.reddit.com/r/UptimeKuma/)
|
||||||
|
|
||||||
My Reddit account: [u/louislamlam](https://reddit.com/u/louislamlam).
|
My Reddit account: [u/louislamlam](https://reddit.com/u/louislamlam).
|
||||||
You can mention me if you ask a question on Reddit.
|
You can mention me if you ask a question on Reddit.
|
||||||
[r/Uptime kuma](https://www.reddit.com/r/UptimeKuma/)
|
|
||||||
|
|
||||||
## Contribute
|
## Contribute
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@ import vue from "@vitejs/plugin-vue";
|
|||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
import visualizer from "rollup-plugin-visualizer";
|
import visualizer from "rollup-plugin-visualizer";
|
||||||
import viteCompression from "vite-plugin-compression";
|
import viteCompression from "vite-plugin-compression";
|
||||||
|
import commonjs from "vite-plugin-commonjs";
|
||||||
|
|
||||||
const postCssScss = require("postcss-scss");
|
const postCssScss = require("postcss-scss");
|
||||||
const postcssRTLCSS = require("postcss-rtlcss");
|
const postcssRTLCSS = require("postcss-rtlcss");
|
||||||
@@ -16,8 +17,12 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
define: {
|
define: {
|
||||||
"FRONTEND_VERSION": JSON.stringify(process.env.npm_package_version),
|
"FRONTEND_VERSION": JSON.stringify(process.env.npm_package_version),
|
||||||
|
"DEVCONTAINER": JSON.stringify(process.env.DEVCONTAINER),
|
||||||
|
"GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN": JSON.stringify(process.env.GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN),
|
||||||
|
"CODESPACE_NAME": JSON.stringify(process.env.CODESPACE_NAME),
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
|
commonjs(),
|
||||||
vue(),
|
vue(),
|
||||||
legacy({
|
legacy({
|
||||||
targets: [ "since 2015" ],
|
targets: [ "since 2015" ],
|
||||||
@@ -42,6 +47,9 @@ export default defineConfig({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
|
commonjsOptions: {
|
||||||
|
include: [ /.js$/ ],
|
||||||
|
},
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
output: {
|
output: {
|
||||||
manualChunks(id, { getModuleInfo, getModuleIds }) {
|
manualChunks(id, { getModuleInfo, getModuleIds }) {
|
||||||
|
7
db/patch-add-invert-keyword.sql
Normal file
7
db/patch-add-invert-keyword.sql
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
-- You should not modify if this have pushed to Github, unless it does serious wrong with the db.
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD invert_keyword BOOLEAN default 0 not null;
|
||||||
|
|
||||||
|
COMMIT;
|
6
db/patch-add-parent-monitor.sql
Normal file
6
db/patch-add-parent-monitor.sql
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
BEGIN TRANSACTION;
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD parent INTEGER REFERENCES [monitor] ([id]) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
COMMIT
|
10
db/patch-added-json-query.sql
Normal file
10
db/patch-added-json-query.sql
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
-- You should not modify if this have pushed to Github, unless it does serious wrong with the db.
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD json_path TEXT;
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD expected_value VARCHAR(255);
|
||||||
|
|
||||||
|
COMMIT;
|
22
db/patch-added-kafka-producer.sql
Normal file
22
db/patch-added-kafka-producer.sql
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
-- You should not modify if this have pushed to Github, unless it does serious wrong with the db.
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD kafka_producer_topic VARCHAR(255);
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD kafka_producer_brokers TEXT;
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD kafka_producer_ssl INTEGER;
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD kafka_producer_allow_auto_topic_creation VARCHAR(255);
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD kafka_producer_sasl_options TEXT;
|
||||||
|
|
||||||
|
ALTER TABLE monitor
|
||||||
|
ADD kafka_producer_message TEXT;
|
||||||
|
|
||||||
|
COMMIT;
|
11
db/patch-maintenance-cron.sql
Normal file
11
db/patch-maintenance-cron.sql
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
-- You should not modify if this have pushed to Github, unless it does serious wrong with the db.
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
|
||||||
|
DROP TABLE maintenance_timeslot;
|
||||||
|
|
||||||
|
-- 999 characters. https://stackoverflow.com/questions/46134830/maximum-length-for-cron-job
|
||||||
|
ALTER TABLE maintenance ADD cron TEXT;
|
||||||
|
ALTER TABLE maintenance ADD timezone VARCHAR(255);
|
||||||
|
ALTER TABLE maintenance ADD duration INTEGER;
|
||||||
|
|
||||||
|
COMMIT;
|
@@ -4,5 +4,5 @@ WORKDIR /app
|
|||||||
|
|
||||||
# Install apprise, iputils for non-root ping, setpriv
|
# Install apprise, iputils for non-root ping, setpriv
|
||||||
RUN apk add --no-cache iputils setpriv dumb-init python3 py3-cryptography py3-pip py3-six py3-yaml py3-click py3-markdown py3-requests py3-requests-oauthlib git && \
|
RUN apk add --no-cache iputils setpriv dumb-init python3 py3-cryptography py3-pip py3-six py3-yaml py3-click py3-markdown py3-requests py3-requests-oauthlib git && \
|
||||||
pip3 --no-cache-dir install apprise==1.3.0 && \
|
pip3 --no-cache-dir install apprise==1.4.0 && \
|
||||||
rm -rf /root/.cache
|
rm -rf /root/.cache
|
||||||
|
@@ -8,21 +8,21 @@ WORKDIR /app
|
|||||||
# Install Curl
|
# Install Curl
|
||||||
# Install Apprise, add sqlite3 cli for debugging in the future, iputils-ping for ping, util-linux for setpriv
|
# Install Apprise, add sqlite3 cli for debugging in the future, iputils-ping for ping, util-linux for setpriv
|
||||||
# Stupid python3 and python3-pip actually install a lot of useless things into Debian, specify --no-install-recommends to skip them, make the base even smaller than alpine!
|
# Stupid python3 and python3-pip actually install a lot of useless things into Debian, specify --no-install-recommends to skip them, make the base even smaller than alpine!
|
||||||
RUN apt update && \
|
RUN apt-get update && \
|
||||||
apt --yes --no-install-recommends install python3 python3-pip python3-cryptography python3-six python3-yaml python3-click python3-markdown python3-requests python3-requests-oauthlib \
|
apt-get --yes --no-install-recommends install python3 python3-pip python3-cryptography python3-six python3-yaml python3-click python3-markdown python3-requests python3-requests-oauthlib \
|
||||||
sqlite3 iputils-ping util-linux dumb-init git && \
|
sqlite3 iputils-ping util-linux dumb-init git curl ca-certificates && \
|
||||||
pip3 --no-cache-dir install apprise==1.3.0 && \
|
pip3 --no-cache-dir install apprise==1.4.0 && \
|
||||||
rm -rf /var/lib/apt/lists/* && \
|
rm -rf /var/lib/apt/lists/* && \
|
||||||
apt --yes autoremove
|
apt --yes autoremove
|
||||||
|
|
||||||
# Install cloudflared
|
# Install cloudflared
|
||||||
# dpkg --add-architecture arm: cloudflared do not provide armhf, this is workaround. Read more: https://github.com/cloudflare/cloudflared/issues/583
|
RUN set -eux && \
|
||||||
COPY extra/download-cloudflared.js ./extra/download-cloudflared.js
|
mkdir -p --mode=0755 /usr/share/keyrings && \
|
||||||
RUN node ./extra/download-cloudflared.js $TARGETPLATFORM && \
|
curl --fail --show-error --silent --location --insecure https://pkg.cloudflare.com/cloudflare-main.gpg --output /usr/share/keyrings/cloudflare-main.gpg && \
|
||||||
dpkg --add-architecture arm && \
|
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared buster main' | tee /etc/apt/sources.list.d/cloudflared.list && \
|
||||||
apt update && \
|
apt-get update && \
|
||||||
apt --yes --no-install-recommends install ./cloudflared.deb && \
|
apt-get install --yes --no-install-recommends cloudflared && \
|
||||||
|
cloudflared version && \
|
||||||
rm -rf /var/lib/apt/lists/* && \
|
rm -rf /var/lib/apt/lists/* && \
|
||||||
rm -f cloudflared.deb && \
|
|
||||||
apt --yes autoremove
|
apt --yes autoremove
|
||||||
|
|
||||||
|
@@ -26,6 +26,8 @@ RUN chmod +x /app/extra/entrypoint.sh
|
|||||||
FROM louislam/uptime-kuma:base-debian AS release
|
FROM louislam/uptime-kuma:base-debian AS release
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
ENV UPTIME_KUMA_IS_CONTAINER=1
|
||||||
|
|
||||||
# Copy app files from build layer
|
# Copy app files from build layer
|
||||||
COPY --from=build /app /app
|
COPY --from=build /app /app
|
||||||
|
|
||||||
@@ -70,7 +72,6 @@ RUN git clone https://github.com/louislam/uptime-kuma.git .
|
|||||||
RUN npm ci
|
RUN npm ci
|
||||||
|
|
||||||
EXPOSE 3000 3001
|
EXPOSE 3000 3001
|
||||||
VOLUME ["/app/data"]
|
|
||||||
HEALTHCHECK --interval=60s --timeout=30s --start-period=180s --retries=5 CMD extra/healthcheck
|
HEALTHCHECK --interval=60s --timeout=30s --start-period=180s --retries=5 CMD extra/healthcheck
|
||||||
CMD ["npm", "run", "start-pr-test"]
|
CMD ["npm", "run", "start-pr-test"]
|
||||||
|
|
||||||
|
@@ -1,48 +0,0 @@
|
|||||||
//
|
|
||||||
|
|
||||||
const http = require("https"); // or 'https' for https:// URLs
|
|
||||||
const fs = require("fs");
|
|
||||||
|
|
||||||
const platform = process.argv[2];
|
|
||||||
|
|
||||||
if (!platform) {
|
|
||||||
console.error("No platform??");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
let arch = null;
|
|
||||||
|
|
||||||
if (platform === "linux/amd64") {
|
|
||||||
arch = "amd64";
|
|
||||||
} else if (platform === "linux/arm64") {
|
|
||||||
arch = "arm64";
|
|
||||||
} else if (platform === "linux/arm/v7") {
|
|
||||||
arch = "arm";
|
|
||||||
} else {
|
|
||||||
console.error("Invalid platform?? " + platform);
|
|
||||||
}
|
|
||||||
|
|
||||||
const file = fs.createWriteStream("cloudflared.deb");
|
|
||||||
get("https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-" + arch + ".deb");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Download specified file
|
|
||||||
* @param {string} url URL to request
|
|
||||||
*/
|
|
||||||
function get(url) {
|
|
||||||
http.get(url, function (res) {
|
|
||||||
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
||||||
console.log("Redirect to " + res.headers.location);
|
|
||||||
get(res.headers.location);
|
|
||||||
} else if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
||||||
res.pipe(file);
|
|
||||||
|
|
||||||
res.on("end", function () {
|
|
||||||
console.log("Downloaded");
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.error(res.statusCode);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
@@ -1,3 +1,3 @@
|
|||||||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
|
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
|
||||||
<Costura />
|
<Costura DisableCompression='true' IncludeDebugSymbols='false' />
|
||||||
</Weavers>
|
</Weavers>
|
@@ -6,9 +6,9 @@ using System.Runtime.InteropServices;
|
|||||||
// set of attributes. Change these attribute values to modify the information
|
// set of attributes. Change these attribute values to modify the information
|
||||||
// associated with an assembly.
|
// associated with an assembly.
|
||||||
[assembly: AssemblyTitle("Uptime Kuma")]
|
[assembly: AssemblyTitle("Uptime Kuma")]
|
||||||
[assembly: AssemblyDescription("")]
|
[assembly: AssemblyDescription("A portable executable for running Uptime Kuma")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("Uptime Kuma")]
|
||||||
[assembly: AssemblyProduct("Uptime Kuma")]
|
[assembly: AssemblyProduct("Uptime Kuma")]
|
||||||
[assembly: AssemblyCopyright("Copyright © 2023 Louis Lam")]
|
[assembly: AssemblyCopyright("Copyright © 2023 Louis Lam")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
@@ -20,7 +20,7 @@ using System.Runtime.InteropServices;
|
|||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
[assembly: Guid("2DB53988-1D93-4AC0-90C4-96ADEAAC5C04")]
|
[assembly: Guid("86B40AFB-61FC-433D-8C31-650B0F32EA8F")]
|
||||||
|
|
||||||
// Version information for an assembly consists of the following four values:
|
// Version information for an assembly consists of the following four values:
|
||||||
//
|
//
|
||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
[assembly: AssemblyVersion("1.0.1.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
[assembly: AssemblyFileVersion("1.0.1.0")]
|
||||||
|
9
extra/test-docker.js
Normal file
9
extra/test-docker.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// Check if docker is running
|
||||||
|
const { exec } = require("child_process");
|
||||||
|
|
||||||
|
exec("docker ps", (err, stdout, stderr) => {
|
||||||
|
if (err) {
|
||||||
|
console.error("Docker is not running. Please start docker and try again.");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
});
|
@@ -2,7 +2,7 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
||||||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
|
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
|
||||||
<link rel="icon" type="image/svg+xml" href="/icon.svg" />
|
<link rel="icon" type="image/svg+xml" href="/icon.svg" />
|
||||||
<link rel="manifest" href="/manifest.json" />
|
<link rel="manifest" href="/manifest.json" />
|
||||||
|
23697
package-lock.json
generated
23697
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
70
package.json
70
package.json
@@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "uptime-kuma",
|
"name": "uptime-kuma",
|
||||||
"version": "1.21.0",
|
"version": "1.22.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/louislam/uptime-kuma.git"
|
"url": "https://github.com/louislam/uptime-kuma.git"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "14.* || >=16.*"
|
"node": "14 || 16 || 18 || >= 20.4.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"install-legacy": "npm install",
|
"install-legacy": "npm install",
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
"lint": "npm run lint:js && npm run lint:style",
|
"lint": "npm run lint:js && npm run lint:style",
|
||||||
"dev": "concurrently -k -r \"wait-on tcp:3000 && npm run start-server-dev \" \"npm run start-frontend-dev\"",
|
"dev": "concurrently -k -r \"wait-on tcp:3000 && npm run start-server-dev \" \"npm run start-frontend-dev\"",
|
||||||
"start-frontend-dev": "cross-env NODE_ENV=development vite --host --config ./config/vite.config.js",
|
"start-frontend-dev": "cross-env NODE_ENV=development vite --host --config ./config/vite.config.js",
|
||||||
|
"start-frontend-devcontainer": "cross-env NODE_ENV=development DEVCONTAINER=1 vite --host --config ./config/vite.config.js",
|
||||||
"start": "npm run start-server",
|
"start": "npm run start-server",
|
||||||
"start-server": "node server/server.js",
|
"start-server": "node server/server.js",
|
||||||
"start-server-dev": "cross-env NODE_ENV=development node server/server.js",
|
"start-server-dev": "cross-env NODE_ENV=development node server/server.js",
|
||||||
@@ -34,12 +35,12 @@
|
|||||||
"build-docker-builder-go": "docker buildx build -f docker/builder-go.dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:builder-go . --push",
|
"build-docker-builder-go": "docker buildx build -f docker/builder-go.dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:builder-go . --push",
|
||||||
"build-docker-alpine": "node ./extra/env2arg.js docker buildx build -f docker/dockerfile-alpine --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:alpine -t louislam/uptime-kuma:1-alpine -t louislam/uptime-kuma:$VERSION-alpine --target release . --push",
|
"build-docker-alpine": "node ./extra/env2arg.js docker buildx build -f docker/dockerfile-alpine --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:alpine -t louislam/uptime-kuma:1-alpine -t louislam/uptime-kuma:$VERSION-alpine --target release . --push",
|
||||||
"build-docker-debian": "node ./extra/env2arg.js docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma -t louislam/uptime-kuma:1 -t louislam/uptime-kuma:$VERSION -t louislam/uptime-kuma:debian -t louislam/uptime-kuma:1-debian -t louislam/uptime-kuma:$VERSION-debian --target release . --push",
|
"build-docker-debian": "node ./extra/env2arg.js docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma -t louislam/uptime-kuma:1 -t louislam/uptime-kuma:$VERSION -t louislam/uptime-kuma:debian -t louislam/uptime-kuma:1-debian -t louislam/uptime-kuma:$VERSION-debian --target release . --push",
|
||||||
"build-docker-nightly": "npm run build && docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:nightly --target nightly . --push",
|
"build-docker-nightly": "node ./extra/test-docker.js && npm run build && docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:nightly --target nightly . --push",
|
||||||
"build-docker-nightly-alpine": "docker buildx build -f docker/dockerfile-alpine --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:nightly-alpine --target nightly . --push",
|
"build-docker-nightly-alpine": "docker buildx build -f docker/dockerfile-alpine --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:nightly-alpine --target nightly . --push",
|
||||||
"build-docker-nightly-amd64": "docker buildx build -f docker/dockerfile --platform linux/amd64 -t louislam/uptime-kuma:nightly-amd64 --target nightly . --push --progress plain",
|
"build-docker-nightly-amd64": "docker buildx build -f docker/dockerfile --platform linux/amd64 -t louislam/uptime-kuma:nightly-amd64 --target nightly . --push --progress plain",
|
||||||
"build-docker-pr-test": "docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64 -t louislam/uptime-kuma:pr-test --target pr-test . --push",
|
"build-docker-pr-test": "docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64 -t louislam/uptime-kuma:pr-test --target pr-test . --push",
|
||||||
"upload-artifacts": "docker buildx build -f docker/dockerfile --platform linux/amd64 -t louislam/uptime-kuma:upload-artifact --build-arg VERSION --build-arg GITHUB_TOKEN --target upload-artifact . --progress plain",
|
"upload-artifacts": "docker buildx build -f docker/dockerfile --platform linux/amd64 -t louislam/uptime-kuma:upload-artifact --build-arg VERSION --build-arg GITHUB_TOKEN --target upload-artifact . --progress plain",
|
||||||
"setup": "git checkout 1.21.0 && npm ci --production && npm run download-dist",
|
"setup": "git checkout 1.22.1 && npm ci --production && npm run download-dist",
|
||||||
"download-dist": "node extra/download-dist.js",
|
"download-dist": "node extra/download-dist.js",
|
||||||
"mark-as-nightly": "node extra/mark-as-nightly.js",
|
"mark-as-nightly": "node extra/mark-as-nightly.js",
|
||||||
"reset-password": "node extra/reset-password.js",
|
"reset-password": "node extra/reset-password.js",
|
||||||
@@ -54,8 +55,8 @@
|
|||||||
"simple-mqtt-server": "node extra/simple-mqtt-server.js",
|
"simple-mqtt-server": "node extra/simple-mqtt-server.js",
|
||||||
"update-language-files": "cd extra/update-language-files && node index.js && cross-env-shell eslint ../../src/languages/$npm_config_language.js --fix",
|
"update-language-files": "cd extra/update-language-files && node index.js && cross-env-shell eslint ../../src/languages/$npm_config_language.js --fix",
|
||||||
"ncu-patch": "npm-check-updates -u -t patch",
|
"ncu-patch": "npm-check-updates -u -t patch",
|
||||||
"release-final": "node extra/update-version.js && npm run build-docker && node ./extra/press-any-key.js && npm run upload-artifacts && node ./extra/update-wiki-version.js",
|
"release-final": "node ./extra/test-docker.js && node extra/update-version.js && npm run build-docker && node ./extra/press-any-key.js && npm run upload-artifacts && node ./extra/update-wiki-version.js",
|
||||||
"release-beta": "node extra/beta/update-version.js && npm run build && node ./extra/env2arg.js docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:$VERSION -t louislam/uptime-kuma:beta . --target release --push && node ./extra/press-any-key.js && npm run upload-artifacts",
|
"release-beta": "node ./extra/test-docker.js && node extra/beta/update-version.js && npm run build && node ./extra/env2arg.js docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:$VERSION -t louislam/uptime-kuma:beta . --target release --push && node ./extra/press-any-key.js && npm run upload-artifacts",
|
||||||
"git-remove-tag": "git tag -d",
|
"git-remove-tag": "git tag -d",
|
||||||
"build-dist-and-restart": "npm run build && npm run start-server-dev",
|
"build-dist-and-restart": "npm run build && npm run start-server-dev",
|
||||||
"start-pr-test": "node extra/checkout-pr.js && npm install && npm run dev",
|
"start-pr-test": "node extra/checkout-pr.js && npm install && npm run dev",
|
||||||
@@ -64,19 +65,18 @@
|
|||||||
"cy:run:unit": "npx cypress run --browser chrome --headless --config-file ./config/cypress.frontend.config.js",
|
"cy:run:unit": "npx cypress run --browser chrome --headless --config-file ./config/cypress.frontend.config.js",
|
||||||
"cypress-open": "concurrently -k -r \"node test/prepare-test-server.js && node server/server.js --port=3002 --data-dir=./data/test/\" \"cypress open --config-file ./config/cypress.config.js\"",
|
"cypress-open": "concurrently -k -r \"node test/prepare-test-server.js && node server/server.js --port=3002 --data-dir=./data/test/\" \"cypress open --config-file ./config/cypress.config.js\"",
|
||||||
"build-healthcheck-armv7": "cross-env GOOS=linux GOARCH=arm GOARM=7 go build -x -o ./extra/healthcheck-armv7 ./extra/healthcheck.go",
|
"build-healthcheck-armv7": "cross-env GOOS=linux GOARCH=arm GOARM=7 go build -x -o ./extra/healthcheck-armv7 ./extra/healthcheck.go",
|
||||||
"depoly-demo-server": "node extra/deploy-demo-server.js",
|
"deploy-demo-server": "node extra/deploy-demo-server.js",
|
||||||
"sort-contributors": "node extra/sort-contributors.js"
|
"sort-contributors": "node extra/sort-contributors.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@grpc/grpc-js": "~1.7.3",
|
"@grpc/grpc-js": "~1.7.3",
|
||||||
"@louislam/ping": "~0.4.4-mod.0",
|
"@louislam/ping": "~0.4.4-mod.1",
|
||||||
"@louislam/sqlite3": "15.1.2",
|
"@louislam/sqlite3": "15.1.6",
|
||||||
"args-parser": "~1.3.0",
|
"args-parser": "~1.3.0",
|
||||||
"axios": "~0.27.0",
|
"axios": "~0.27.0",
|
||||||
"axios-ntlm": "1.3.0",
|
"axios-ntlm": "1.3.0",
|
||||||
"badge-maker": "~3.3.1",
|
"badge-maker": "~3.3.1",
|
||||||
"bcryptjs": "~2.4.3",
|
"bcryptjs": "~2.4.3",
|
||||||
"bree": "~7.1.5",
|
|
||||||
"cacheable-lookup": "~6.0.4",
|
"cacheable-lookup": "~6.0.4",
|
||||||
"chardet": "~1.4.0",
|
"chardet": "~1.4.0",
|
||||||
"check-password-strength": "^2.0.5",
|
"check-password-strength": "^2.0.5",
|
||||||
@@ -85,26 +85,30 @@
|
|||||||
"command-exists": "~1.2.9",
|
"command-exists": "~1.2.9",
|
||||||
"compare-versions": "~3.6.0",
|
"compare-versions": "~3.6.0",
|
||||||
"compression": "~1.7.4",
|
"compression": "~1.7.4",
|
||||||
|
"croner": "~6.0.5",
|
||||||
"dayjs": "~1.11.5",
|
"dayjs": "~1.11.5",
|
||||||
"dotenv": "~16.0.3",
|
"dotenv": "~16.0.3",
|
||||||
"express": "~4.17.3",
|
"express": "~4.17.3",
|
||||||
"express-basic-auth": "~1.2.1",
|
"express-basic-auth": "~1.2.1",
|
||||||
"express-static-gzip": "~2.1.7",
|
"express-static-gzip": "~2.1.7",
|
||||||
"form-data": "~4.0.0",
|
"form-data": "~4.0.0",
|
||||||
"gamedig": "^4.0.5",
|
"gamedig": "~4.0.5",
|
||||||
"http-graceful-shutdown": "~3.1.7",
|
"http-graceful-shutdown": "~3.1.7",
|
||||||
"http-proxy-agent": "~5.0.0",
|
"http-proxy-agent": "~5.0.0",
|
||||||
"https-proxy-agent": "~5.0.1",
|
"https-proxy-agent": "~5.0.1",
|
||||||
"iconv-lite": "~0.6.3",
|
"iconv-lite": "~0.6.3",
|
||||||
"jsesc": "~3.0.2",
|
"jsesc": "~3.0.2",
|
||||||
|
"jsonata": "^2.0.3",
|
||||||
"jsonwebtoken": "~9.0.0",
|
"jsonwebtoken": "~9.0.0",
|
||||||
"jwt-decode": "~3.1.2",
|
"jwt-decode": "~3.1.2",
|
||||||
|
"kafkajs": "^2.2.4",
|
||||||
"limiter": "~2.1.0",
|
"limiter": "~2.1.0",
|
||||||
|
"liquidjs": "^10.7.0",
|
||||||
"mongodb": "~4.14.0",
|
"mongodb": "~4.14.0",
|
||||||
"mqtt": "~4.3.7",
|
"mqtt": "~4.3.7",
|
||||||
"mssql": "~8.1.4",
|
"mssql": "~8.1.4",
|
||||||
"mysql2": "~2.3.3",
|
"mysql2": "~2.3.3",
|
||||||
"nanoid": "^3.3.4",
|
"nanoid": "~3.3.4",
|
||||||
"node-cloudflared-tunnel": "~1.0.9",
|
"node-cloudflared-tunnel": "~1.0.9",
|
||||||
"node-radius-client": "~1.0.0",
|
"node-radius-client": "~1.0.0",
|
||||||
"nodemailer": "~6.6.5",
|
"nodemailer": "~6.6.5",
|
||||||
@@ -112,14 +116,17 @@
|
|||||||
"password-hash": "~1.2.2",
|
"password-hash": "~1.2.2",
|
||||||
"pg": "~8.8.0",
|
"pg": "~8.8.0",
|
||||||
"pg-connection-string": "~2.5.0",
|
"pg-connection-string": "~2.5.0",
|
||||||
|
"playwright-core": "~1.35.1",
|
||||||
"prom-client": "~13.2.0",
|
"prom-client": "~13.2.0",
|
||||||
"prometheus-api-metrics": "~3.2.1",
|
"prometheus-api-metrics": "~3.2.1",
|
||||||
"protobufjs": "~7.1.1",
|
"protobufjs": "~7.2.4",
|
||||||
"qs": "~6.10.4",
|
"qs": "~6.10.4",
|
||||||
"redbean-node": "~0.2.0",
|
"queue": "~7.0.0",
|
||||||
|
"redbean-node": "~0.3.0",
|
||||||
"redis": "~4.5.1",
|
"redis": "~4.5.1",
|
||||||
"socket.io": "~4.5.3",
|
"semver": "~7.5.4",
|
||||||
"socket.io-client": "~4.5.3",
|
"socket.io": "~4.6.1",
|
||||||
|
"socket.io-client": "~4.6.1",
|
||||||
"socks-proxy-agent": "6.1.1",
|
"socks-proxy-agent": "6.1.1",
|
||||||
"tar": "~6.1.11",
|
"tar": "~6.1.11",
|
||||||
"tcp-ping": "~0.1.1",
|
"tcp-ping": "~0.1.1",
|
||||||
@@ -127,7 +134,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@actions/github": "~5.0.1",
|
"@actions/github": "~5.0.1",
|
||||||
"@babel/eslint-parser": "~7.17.0",
|
"@babel/eslint-parser": "^7.22.7",
|
||||||
"@babel/preset-env": "^7.15.8",
|
"@babel/preset-env": "^7.15.8",
|
||||||
"@fortawesome/fontawesome-svg-core": "~1.2.36",
|
"@fortawesome/fontawesome-svg-core": "~1.2.36",
|
||||||
"@fortawesome/free-regular-svg-icons": "~5.15.4",
|
"@fortawesome/free-regular-svg-icons": "~5.15.4",
|
||||||
@@ -135,28 +142,29 @@
|
|||||||
"@fortawesome/vue-fontawesome": "~3.0.0-5",
|
"@fortawesome/vue-fontawesome": "~3.0.0-5",
|
||||||
"@popperjs/core": "~2.10.2",
|
"@popperjs/core": "~2.10.2",
|
||||||
"@types/bootstrap": "~5.1.9",
|
"@types/bootstrap": "~5.1.9",
|
||||||
"@vitejs/plugin-legacy": "~2.1.0",
|
"@vitejs/plugin-legacy": "~4.1.0",
|
||||||
"@vitejs/plugin-vue": "~3.1.0",
|
"@vitejs/plugin-vue": "~4.2.3",
|
||||||
"@vue/compiler-sfc": "~3.2.36",
|
"@vue/compiler-sfc": "~3.3.4",
|
||||||
"@vuepic/vue-datepicker": "~3.4.8",
|
"@vuepic/vue-datepicker": "~3.4.8",
|
||||||
"aedes": "^0.46.3",
|
"aedes": "^0.46.3",
|
||||||
"babel-plugin-rewire": "~1.2.0",
|
"babel-plugin-rewire": "~1.2.0",
|
||||||
"bootstrap": "5.1.3",
|
"bootstrap": "5.1.3",
|
||||||
"chart.js": "~3.6.2",
|
"chart.js": "~4.2.1",
|
||||||
"chartjs-adapter-dayjs": "~1.0.0",
|
"chartjs-adapter-dayjs-4": "~1.0.4",
|
||||||
"concurrently": "^7.1.0",
|
"concurrently": "^7.1.0",
|
||||||
"core-js": "~3.26.1",
|
"core-js": "~3.26.1",
|
||||||
|
"cronstrue": "~2.24.0",
|
||||||
"cross-env": "~7.0.3",
|
"cross-env": "~7.0.3",
|
||||||
"cypress": "^10.1.0",
|
"cypress": "^12.17.0",
|
||||||
"delay": "^5.0.0",
|
"delay": "^5.0.0",
|
||||||
"dns2": "~2.0.1",
|
"dns2": "~2.0.1",
|
||||||
"dompurify": "~2.4.3",
|
"dompurify": "~2.4.3",
|
||||||
"eslint": "~8.14.0",
|
"eslint": "~8.14.0",
|
||||||
"eslint-plugin-vue": "~8.7.1",
|
"eslint-plugin-vue": "~8.7.1",
|
||||||
"favico.js": "~0.3.10",
|
"favico.js": "~0.3.10",
|
||||||
"jest": "~27.2.5",
|
"jest": "~29.6.1",
|
||||||
"marked": "~4.2.5",
|
"marked": "~4.2.5",
|
||||||
"node-ssh": "~13.0.1",
|
"node-ssh": "~13.1.0",
|
||||||
"postcss-html": "~1.5.0",
|
"postcss-html": "~1.5.0",
|
||||||
"postcss-rtlcss": "~3.7.2",
|
"postcss-rtlcss": "~3.7.2",
|
||||||
"postcss-scss": "~4.0.4",
|
"postcss-scss": "~4.0.4",
|
||||||
@@ -164,16 +172,17 @@
|
|||||||
"qrcode": "~1.5.0",
|
"qrcode": "~1.5.0",
|
||||||
"rollup-plugin-visualizer": "^5.6.0",
|
"rollup-plugin-visualizer": "^5.6.0",
|
||||||
"sass": "~1.42.1",
|
"sass": "~1.42.1",
|
||||||
"stylelint": "~14.7.1",
|
"stylelint": "^15.10.1",
|
||||||
"stylelint-config-standard": "~25.0.0",
|
"stylelint-config-standard": "~25.0.0",
|
||||||
"terser": "~5.15.0",
|
"terser": "~5.15.0",
|
||||||
"timezones-list": "~3.0.1",
|
"timezones-list": "~3.0.1",
|
||||||
"typescript": "~4.4.4",
|
"typescript": "~4.4.4",
|
||||||
"v-pagination-3": "~0.1.7",
|
"v-pagination-3": "~0.1.7",
|
||||||
"vite": "~3.1.0",
|
"vite": "~4.4.1",
|
||||||
|
"vite-plugin-commonjs": "^0.8.0",
|
||||||
"vite-plugin-compression": "^0.5.1",
|
"vite-plugin-compression": "^0.5.1",
|
||||||
"vue": "next",
|
"vue": "~3.3.4",
|
||||||
"vue-chart-3": "3.0.9",
|
"vue-chartjs": "~5.2.0",
|
||||||
"vue-confirm-dialog": "~1.0.2",
|
"vue-confirm-dialog": "~1.0.2",
|
||||||
"vue-contenteditable": "~3.0.4",
|
"vue-contenteditable": "~3.0.4",
|
||||||
"vue-i18n": "~9.2.2",
|
"vue-i18n": "~9.2.2",
|
||||||
@@ -184,6 +193,7 @@
|
|||||||
"vue-router": "~4.0.14",
|
"vue-router": "~4.0.14",
|
||||||
"vue-toastification": "~2.0.0-rc.5",
|
"vue-toastification": "~2.0.0-rc.5",
|
||||||
"vuedraggable": "~4.1.0",
|
"vuedraggable": "~4.1.0",
|
||||||
"wait-on": "^6.0.1"
|
"wait-on": "^6.0.1",
|
||||||
|
"whatwg-url": "~12.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,7 @@ const basicAuth = require("express-basic-auth");
|
|||||||
const passwordHash = require("./password-hash");
|
const passwordHash = require("./password-hash");
|
||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
const { setting } = require("./util-server");
|
const { setting } = require("./util-server");
|
||||||
|
const { log } = require("../src/util");
|
||||||
const { loginRateLimiter, apiRateLimiter } = require("./rate-limiter");
|
const { loginRateLimiter, apiRateLimiter } = require("./rate-limiter");
|
||||||
const { Settings } = require("./settings");
|
const { Settings } = require("./settings");
|
||||||
const dayjs = require("dayjs");
|
const dayjs = require("dayjs");
|
||||||
@@ -81,12 +82,16 @@ function apiAuthorizer(username, password, callback) {
|
|||||||
apiRateLimiter.pass(null, 0).then((pass) => {
|
apiRateLimiter.pass(null, 0).then((pass) => {
|
||||||
if (pass) {
|
if (pass) {
|
||||||
verifyAPIKey(password).then((valid) => {
|
verifyAPIKey(password).then((valid) => {
|
||||||
|
if (!valid) {
|
||||||
|
log.warn("api-auth", "Failed API auth attempt: invalid API Key");
|
||||||
|
}
|
||||||
callback(null, valid);
|
callback(null, valid);
|
||||||
// Only allow a set number of api requests per minute
|
// Only allow a set number of api requests per minute
|
||||||
// (currently set to 60)
|
// (currently set to 60)
|
||||||
apiRateLimiter.removeTokens(1);
|
apiRateLimiter.removeTokens(1);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
log.warn("api-auth", "Failed API auth attempt: rate limit exceeded");
|
||||||
callback(null, false);
|
callback(null, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -106,10 +111,12 @@ function userAuthorizer(username, password, callback) {
|
|||||||
callback(null, user != null);
|
callback(null, user != null);
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
|
log.warn("basic-auth", "Failed basic auth attempt: invalid username/password");
|
||||||
loginRateLimiter.removeTokens(1);
|
loginRateLimiter.removeTokens(1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
log.warn("basic-auth", "Failed basic auth attempt: rate limit exceeded");
|
||||||
callback(null, false);
|
callback(null, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -1,27 +1,33 @@
|
|||||||
const { setSetting, setting } = require("./util-server");
|
const { setSetting, setting } = require("./util-server");
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const compareVersions = require("compare-versions");
|
const compareVersions = require("compare-versions");
|
||||||
|
const { log } = require("../src/util");
|
||||||
|
|
||||||
exports.version = require("../package.json").version;
|
exports.version = require("../package.json").version;
|
||||||
exports.latestVersion = null;
|
exports.latestVersion = null;
|
||||||
|
|
||||||
|
// How much time in ms to wait between update checks
|
||||||
|
const UPDATE_CHECKER_INTERVAL_MS = 1000 * 60 * 60 * 48;
|
||||||
|
const UPDATE_CHECKER_LATEST_VERSION_URL = "https://uptime.kuma.pet/version";
|
||||||
|
|
||||||
let interval;
|
let interval;
|
||||||
|
|
||||||
/** Start 48 hour check interval */
|
|
||||||
exports.startInterval = () => {
|
exports.startInterval = () => {
|
||||||
let check = async () => {
|
let check = async () => {
|
||||||
|
if (await setting("checkUpdate") === false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("update-checker", "Retrieving latest versions");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await axios.get("https://uptime.kuma.pet/version");
|
const res = await axios.get(UPDATE_CHECKER_LATEST_VERSION_URL);
|
||||||
|
|
||||||
// For debug
|
// For debug
|
||||||
if (process.env.TEST_CHECK_VERSION === "1") {
|
if (process.env.TEST_CHECK_VERSION === "1") {
|
||||||
res.data.slow = "1000.0.0";
|
res.data.slow = "1000.0.0";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (await setting("checkUpdate") === false) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let checkBeta = await setting("checkBeta");
|
let checkBeta = await setting("checkBeta");
|
||||||
|
|
||||||
if (checkBeta && res.data.beta) {
|
if (checkBeta && res.data.beta) {
|
||||||
@@ -35,12 +41,14 @@ exports.startInterval = () => {
|
|||||||
exports.latestVersion = res.data.slow;
|
exports.latestVersion = res.data.slow;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (_) { }
|
} catch (_) {
|
||||||
|
log.info("update-checker", "Failed to check for new versions");
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
check();
|
check();
|
||||||
interval = setInterval(check, 3600 * 1000 * 48);
|
interval = setInterval(check, UPDATE_CHECKER_INTERVAL_MS);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -141,12 +141,21 @@ async function sendAPIKeyList(socket) {
|
|||||||
/**
|
/**
|
||||||
* Emits the version information to the client.
|
* Emits the version information to the client.
|
||||||
* @param {Socket} socket Socket.io socket instance
|
* @param {Socket} socket Socket.io socket instance
|
||||||
|
* @param {boolean} hideVersion
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async function sendInfo(socket) {
|
async function sendInfo(socket, hideVersion = false) {
|
||||||
|
let version;
|
||||||
|
let latestVersion;
|
||||||
|
|
||||||
|
if (!hideVersion) {
|
||||||
|
version = checkVersion.version;
|
||||||
|
latestVersion = checkVersion.latestVersion;
|
||||||
|
}
|
||||||
|
|
||||||
socket.emit("info", {
|
socket.emit("info", {
|
||||||
version: checkVersion.version,
|
version,
|
||||||
latestVersion: checkVersion.latestVersion,
|
latestVersion,
|
||||||
primaryBaseURL: await setting("primaryBaseURL"),
|
primaryBaseURL: await setting("primaryBaseURL"),
|
||||||
serverTimezone: await server.getTimezone(),
|
serverTimezone: await server.getTimezone(),
|
||||||
serverTimezoneOffset: server.getTimezoneOffset(),
|
serverTimezoneOffset: server.getTimezoneOffset(),
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
const args = require("args-parser")(process.argv);
|
// Interop with browser
|
||||||
|
const args = (typeof process !== "undefined") ? require("args-parser")(process.argv) : {};
|
||||||
const demoMode = args["demo"] || false;
|
const demoMode = args["demo"] || false;
|
||||||
|
|
||||||
const badgeConstants = {
|
const badgeConstants = {
|
||||||
|
@@ -2,9 +2,7 @@ const fs = require("fs");
|
|||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
const { setSetting, setting } = require("./util-server");
|
const { setSetting, setting } = require("./util-server");
|
||||||
const { log, sleep } = require("../src/util");
|
const { log, sleep } = require("../src/util");
|
||||||
const dayjs = require("dayjs");
|
|
||||||
const knex = require("knex");
|
const knex = require("knex");
|
||||||
const { PluginsManager } = require("./plugins-manager");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database & App Data Folder
|
* Database & App Data Folder
|
||||||
@@ -23,6 +21,8 @@ class Database {
|
|||||||
*/
|
*/
|
||||||
static uploadDir;
|
static uploadDir;
|
||||||
|
|
||||||
|
static screenshotDir;
|
||||||
|
|
||||||
static path;
|
static path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,11 +30,6 @@ class Database {
|
|||||||
*/
|
*/
|
||||||
static patched = false;
|
static patched = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* For Backup only
|
|
||||||
*/
|
|
||||||
static backupPath = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add patch filename in key
|
* Add patch filename in key
|
||||||
* Values:
|
* Values:
|
||||||
@@ -74,6 +69,11 @@ class Database {
|
|||||||
"patch-add-description-monitor.sql": true,
|
"patch-add-description-monitor.sql": true,
|
||||||
"patch-api-key-table.sql": true,
|
"patch-api-key-table.sql": true,
|
||||||
"patch-monitor-tls.sql": true,
|
"patch-monitor-tls.sql": true,
|
||||||
|
"patch-maintenance-cron.sql": true,
|
||||||
|
"patch-add-parent-monitor.sql": true,
|
||||||
|
"patch-add-invert-keyword.sql": true,
|
||||||
|
"patch-added-json-query.sql": true,
|
||||||
|
"patch-added-kafka-producer.sql": true,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,12 +92,6 @@ class Database {
|
|||||||
// Data Directory (must be end with "/")
|
// Data Directory (must be end with "/")
|
||||||
Database.dataDir = process.env.DATA_DIR || args["data-dir"] || "./data/";
|
Database.dataDir = process.env.DATA_DIR || args["data-dir"] || "./data/";
|
||||||
|
|
||||||
// Plugin feature is working only if the dataDir = "./data";
|
|
||||||
if (Database.dataDir !== "./data/") {
|
|
||||||
log.warn("PLUGIN", "Warning: In order to enable plugin feature, you need to use the default data directory: ./data/");
|
|
||||||
PluginsManager.disable = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Database.path = Database.dataDir + "kuma.db";
|
Database.path = Database.dataDir + "kuma.db";
|
||||||
if (! fs.existsSync(Database.dataDir)) {
|
if (! fs.existsSync(Database.dataDir)) {
|
||||||
fs.mkdirSync(Database.dataDir, { recursive: true });
|
fs.mkdirSync(Database.dataDir, { recursive: true });
|
||||||
@@ -109,6 +103,12 @@ class Database {
|
|||||||
fs.mkdirSync(Database.uploadDir, { recursive: true });
|
fs.mkdirSync(Database.uploadDir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create screenshot dir
|
||||||
|
Database.screenshotDir = Database.dataDir + "screenshots/";
|
||||||
|
if (! fs.existsSync(Database.screenshotDir)) {
|
||||||
|
fs.mkdirSync(Database.screenshotDir, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
log.info("db", `Data Dir: ${Database.dataDir}`);
|
log.info("db", `Data Dir: ${Database.dataDir}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,12 +165,12 @@ class Database {
|
|||||||
await R.exec("PRAGMA journal_mode = WAL");
|
await R.exec("PRAGMA journal_mode = WAL");
|
||||||
}
|
}
|
||||||
await R.exec("PRAGMA cache_size = -12000");
|
await R.exec("PRAGMA cache_size = -12000");
|
||||||
await R.exec("PRAGMA auto_vacuum = FULL");
|
await R.exec("PRAGMA auto_vacuum = INCREMENTAL");
|
||||||
|
|
||||||
// This ensures that an operating system crash or power failure will not corrupt the database.
|
// This ensures that an operating system crash or power failure will not corrupt the database.
|
||||||
// FULL synchronous is very safe, but it is also slower.
|
// FULL synchronous is very safe, but it is also slower.
|
||||||
// Read more: https://sqlite.org/pragma.html#pragma_synchronous
|
// Read more: https://sqlite.org/pragma.html#pragma_synchronous
|
||||||
await R.exec("PRAGMA synchronous = FULL");
|
await R.exec("PRAGMA synchronous = NORMAL");
|
||||||
|
|
||||||
if (!noLog) {
|
if (!noLog) {
|
||||||
log.info("db", "SQLite config:");
|
log.info("db", "SQLite config:");
|
||||||
@@ -198,15 +198,7 @@ class Database {
|
|||||||
} else {
|
} else {
|
||||||
log.info("db", "Database patch is needed");
|
log.info("db", "Database patch is needed");
|
||||||
|
|
||||||
try {
|
// Try catch anything here
|
||||||
this.backup(version);
|
|
||||||
} catch (e) {
|
|
||||||
log.error("db", e);
|
|
||||||
log.error("db", "Unable to create a backup before patching the database. Please make sure you have enough space and permission.");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try catch anything here, if gone wrong, restore the backup
|
|
||||||
try {
|
try {
|
||||||
for (let i = version + 1; i <= this.latestVersion; i++) {
|
for (let i = version + 1; i <= this.latestVersion; i++) {
|
||||||
const sqlFile = `./db/patch${i}.sql`;
|
const sqlFile = `./db/patch${i}.sql`;
|
||||||
@@ -222,7 +214,6 @@ class Database {
|
|||||||
log.error("db", "Start Uptime-Kuma failed due to issue patching the database");
|
log.error("db", "Start Uptime-Kuma failed due to issue patching the database");
|
||||||
log.error("db", "Please submit a bug report if you still encounter the problem after restart: https://github.com/louislam/uptime-kuma/issues");
|
log.error("db", "Please submit a bug report if you still encounter the problem after restart: https://github.com/louislam/uptime-kuma/issues");
|
||||||
|
|
||||||
this.restore();
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -264,8 +255,6 @@ class Database {
|
|||||||
log.error("db", "Start Uptime-Kuma failed due to issue patching the database");
|
log.error("db", "Start Uptime-Kuma failed due to issue patching the database");
|
||||||
log.error("db", "Please submit the bug report if you still encounter the problem after restart: https://github.com/louislam/uptime-kuma/issues");
|
log.error("db", "Please submit the bug report if you still encounter the problem after restart: https://github.com/louislam/uptime-kuma/issues");
|
||||||
|
|
||||||
this.restore();
|
|
||||||
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,8 +356,6 @@ class Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.backup(dayjs().format("YYYYMMDDHHmmss"));
|
|
||||||
|
|
||||||
log.info("db", sqlFilename + " is patching");
|
log.info("db", sqlFilename + " is patching");
|
||||||
this.patched = true;
|
this.patched = true;
|
||||||
await this.importSQLFile("./db/" + sqlFilename);
|
await this.importSQLFile("./db/" + sqlFilename);
|
||||||
@@ -434,6 +421,9 @@ class Database {
|
|||||||
|
|
||||||
log.info("db", "Closing the database");
|
log.info("db", "Closing the database");
|
||||||
|
|
||||||
|
// Flush WAL to main database
|
||||||
|
await R.exec("PRAGMA wal_checkpoint(TRUNCATE)");
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
Database.noReject = true;
|
Database.noReject = true;
|
||||||
await R.close();
|
await R.close();
|
||||||
@@ -450,100 +440,6 @@ class Database {
|
|||||||
process.removeListener("unhandledRejection", listener);
|
process.removeListener("unhandledRejection", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* One backup one time in this process.
|
|
||||||
* Reset this.backupPath if you want to backup again
|
|
||||||
* @param {string} version Version code of backup
|
|
||||||
*/
|
|
||||||
static backup(version) {
|
|
||||||
if (! this.backupPath) {
|
|
||||||
log.info("db", "Backing up the database");
|
|
||||||
this.backupPath = this.dataDir + "kuma.db.bak" + version;
|
|
||||||
fs.copyFileSync(Database.path, this.backupPath);
|
|
||||||
|
|
||||||
const shmPath = Database.path + "-shm";
|
|
||||||
if (fs.existsSync(shmPath)) {
|
|
||||||
this.backupShmPath = shmPath + ".bak" + version;
|
|
||||||
fs.copyFileSync(shmPath, this.backupShmPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
const walPath = Database.path + "-wal";
|
|
||||||
if (fs.existsSync(walPath)) {
|
|
||||||
this.backupWalPath = walPath + ".bak" + version;
|
|
||||||
fs.copyFileSync(walPath, this.backupWalPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Double confirm if all files actually backup
|
|
||||||
if (!fs.existsSync(this.backupPath)) {
|
|
||||||
throw new Error("Backup failed! " + this.backupPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fs.existsSync(shmPath)) {
|
|
||||||
if (!fs.existsSync(this.backupShmPath)) {
|
|
||||||
throw new Error("Backup failed! " + this.backupShmPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fs.existsSync(walPath)) {
|
|
||||||
if (!fs.existsSync(this.backupWalPath)) {
|
|
||||||
throw new Error("Backup failed! " + this.backupWalPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Restore from most recent backup */
|
|
||||||
static restore() {
|
|
||||||
if (this.backupPath) {
|
|
||||||
log.error("db", "Patching the database failed!!! Restoring the backup");
|
|
||||||
|
|
||||||
const shmPath = Database.path + "-shm";
|
|
||||||
const walPath = Database.path + "-wal";
|
|
||||||
|
|
||||||
// Make sure we have a backup to restore before deleting old db
|
|
||||||
if (
|
|
||||||
!fs.existsSync(this.backupPath)
|
|
||||||
&& !fs.existsSync(shmPath)
|
|
||||||
&& !fs.existsSync(walPath)
|
|
||||||
) {
|
|
||||||
log.error("db", "Backup file not found! Leaving database in failed state.");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete patch failed db
|
|
||||||
try {
|
|
||||||
if (fs.existsSync(Database.path)) {
|
|
||||||
fs.unlinkSync(Database.path);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fs.existsSync(shmPath)) {
|
|
||||||
fs.unlinkSync(shmPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fs.existsSync(walPath)) {
|
|
||||||
fs.unlinkSync(walPath);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
log.error("db", "Restore failed; you may need to restore the backup manually");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore backup
|
|
||||||
fs.copyFileSync(this.backupPath, Database.path);
|
|
||||||
|
|
||||||
if (this.backupShmPath) {
|
|
||||||
fs.copyFileSync(this.backupShmPath, shmPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.backupWalPath) {
|
|
||||||
fs.copyFileSync(this.backupWalPath, walPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
log.info("db", "Nothing to restore");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Get the size of the database */
|
/** Get the size of the database */
|
||||||
static getSize() {
|
static getSize() {
|
||||||
log.debug("db", "Database.getSize()");
|
log.debug("db", "Database.getSize()");
|
||||||
|
@@ -1,24 +0,0 @@
|
|||||||
const childProcess = require("child_process");
|
|
||||||
|
|
||||||
class Git {
|
|
||||||
|
|
||||||
static clone(repoURL, cwd, targetDir = ".") {
|
|
||||||
let result = childProcess.spawnSync("git", [
|
|
||||||
"clone",
|
|
||||||
repoURL,
|
|
||||||
targetDir,
|
|
||||||
], {
|
|
||||||
cwd: cwd,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (result.status !== 0) {
|
|
||||||
throw new Error(result.stderr.toString("utf-8"));
|
|
||||||
} else {
|
|
||||||
return result.stdout.toString("utf-8") + result.stderr.toString("utf-8");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
Git,
|
|
||||||
};
|
|
@@ -1,41 +1,51 @@
|
|||||||
const path = require("path");
|
const { UptimeKumaServer } = require("./uptime-kuma-server");
|
||||||
const Bree = require("bree");
|
const { clearOldData } = require("./jobs/clear-old-data");
|
||||||
const { SHARE_ENV } = require("worker_threads");
|
const { incrementalVacuum } = require("./jobs/incremental-vacuum");
|
||||||
const { log } = require("../src/util");
|
const Cron = require("croner");
|
||||||
let bree;
|
|
||||||
const jobs = [
|
const jobs = [
|
||||||
{
|
{
|
||||||
name: "clear-old-data",
|
name: "clear-old-data",
|
||||||
interval: "at 03:14",
|
interval: "14 03 * * *",
|
||||||
|
jobFunc: clearOldData,
|
||||||
|
croner: null,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "incremental-vacuum",
|
||||||
|
interval: "*/5 * * * *",
|
||||||
|
jobFunc: incrementalVacuum,
|
||||||
|
croner: null,
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize background jobs
|
* Initialize background jobs
|
||||||
* @param {Object} args Arguments to pass to workers
|
* @returns {Promise<void>}
|
||||||
* @returns {Bree}
|
|
||||||
*/
|
*/
|
||||||
const initBackgroundJobs = function (args) {
|
const initBackgroundJobs = async function () {
|
||||||
bree = new Bree({
|
const timezone = await UptimeKumaServer.getInstance().getTimezone();
|
||||||
root: path.resolve("server", "jobs"),
|
|
||||||
jobs,
|
for (const job of jobs) {
|
||||||
worker: {
|
const cornerJob = new Cron(
|
||||||
env: SHARE_ENV,
|
job.interval,
|
||||||
workerData: args,
|
{
|
||||||
},
|
name: job.name,
|
||||||
workerMessageHandler: (message) => {
|
timezone,
|
||||||
log.info("jobs", message);
|
},
|
||||||
}
|
job.jobFunc,
|
||||||
});
|
);
|
||||||
|
job.croner = cornerJob;
|
||||||
|
}
|
||||||
|
|
||||||
bree.start();
|
|
||||||
return bree;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Stop all background jobs if running */
|
/** Stop all background jobs if running */
|
||||||
const stopBackgroundJobs = function () {
|
const stopBackgroundJobs = function () {
|
||||||
if (bree) {
|
for (const job of jobs) {
|
||||||
bree.stop();
|
if (job.croner) {
|
||||||
|
job.croner.stop();
|
||||||
|
job.croner = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -1,12 +1,15 @@
|
|||||||
const { log, exit, connectDb } = require("./util-worker");
|
|
||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
|
const { log } = require("../../src/util");
|
||||||
const { setSetting, setting } = require("../util-server");
|
const { setSetting, setting } = require("../util-server");
|
||||||
|
|
||||||
const DEFAULT_KEEP_PERIOD = 180;
|
const DEFAULT_KEEP_PERIOD = 180;
|
||||||
|
|
||||||
(async () => {
|
/**
|
||||||
await connectDb();
|
* Clears old data from the heartbeat table of the database.
|
||||||
|
* @return {Promise<void>} A promise that resolves when the data has been cleared.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const clearOldData = async () => {
|
||||||
let period = await setting("keepDataPeriodDays");
|
let period = await setting("keepDataPeriodDays");
|
||||||
|
|
||||||
// Set Default Period
|
// Set Default Period
|
||||||
@@ -20,26 +23,30 @@ const DEFAULT_KEEP_PERIOD = 180;
|
|||||||
try {
|
try {
|
||||||
parsedPeriod = parseInt(period);
|
parsedPeriod = parseInt(period);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
log("Failed to parse setting, resetting to default..");
|
log.warn("clearOldData", "Failed to parse setting, resetting to default..");
|
||||||
await setSetting("keepDataPeriodDays", DEFAULT_KEEP_PERIOD, "general");
|
await setSetting("keepDataPeriodDays", DEFAULT_KEEP_PERIOD, "general");
|
||||||
parsedPeriod = DEFAULT_KEEP_PERIOD;
|
parsedPeriod = DEFAULT_KEEP_PERIOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parsedPeriod < 1) {
|
if (parsedPeriod < 1) {
|
||||||
log(`Data deletion has been disabled as period is less than 1. Period is ${parsedPeriod} days.`);
|
log.info("clearOldData", `Data deletion has been disabled as period is less than 1. Period is ${parsedPeriod} days.`);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
log(`Clearing Data older than ${parsedPeriod} days...`);
|
log.debug("clearOldData", `Clearing Data older than ${parsedPeriod} days...`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await R.exec(
|
await R.exec(
|
||||||
"DELETE FROM heartbeat WHERE time < DATETIME('now', '-' || ? || ' days') ",
|
"DELETE FROM heartbeat WHERE time < DATETIME('now', '-' || ? || ' days') ",
|
||||||
[ parsedPeriod ]
|
[ parsedPeriod ]
|
||||||
);
|
);
|
||||||
} catch (e) {
|
|
||||||
log(`Failed to clear old data: ${e.message}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exit();
|
await R.exec("PRAGMA optimize;");
|
||||||
})();
|
} catch (e) {
|
||||||
|
log.error("clearOldData", `Failed to clear old data: ${e.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
clearOldData,
|
||||||
|
};
|
||||||
|
21
server/jobs/incremental-vacuum.js
Normal file
21
server/jobs/incremental-vacuum.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
const { R } = require("redbean-node");
|
||||||
|
const { log } = require("../../src/util");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run incremental_vacuum and checkpoint the WAL.
|
||||||
|
* @return {Promise<void>} A promise that resolves when the process is finished.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const incrementalVacuum = async () => {
|
||||||
|
try {
|
||||||
|
log.debug("incrementalVacuum", "Running incremental_vacuum and wal_checkpoint(PASSIVE)...");
|
||||||
|
await R.exec("PRAGMA incremental_vacuum(200)");
|
||||||
|
await R.exec("PRAGMA wal_checkpoint(PASSIVE)");
|
||||||
|
} catch (e) {
|
||||||
|
log.error("incrementalVacuum", `Failed: ${e.message}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
incrementalVacuum,
|
||||||
|
};
|
@@ -1,50 +0,0 @@
|
|||||||
const { parentPort, workerData } = require("worker_threads");
|
|
||||||
const Database = require("../database");
|
|
||||||
const path = require("path");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send message to parent process for logging
|
|
||||||
* since worker_thread does not have access to stdout, this is used
|
|
||||||
* instead of console.log()
|
|
||||||
* @param {any} any The message to log
|
|
||||||
*/
|
|
||||||
const log = function (any) {
|
|
||||||
if (parentPort) {
|
|
||||||
parentPort.postMessage(any);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exit the worker process
|
|
||||||
* @param {number} error The status code to exit
|
|
||||||
*/
|
|
||||||
const exit = function (error) {
|
|
||||||
if (error && error !== 0) {
|
|
||||||
process.exit(error);
|
|
||||||
} else {
|
|
||||||
if (parentPort) {
|
|
||||||
parentPort.postMessage("done");
|
|
||||||
} else {
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Connects to the database */
|
|
||||||
const connectDb = async function () {
|
|
||||||
const dbPath = path.join(
|
|
||||||
process.env.DATA_DIR || workerData["data-dir"] || "./data/"
|
|
||||||
);
|
|
||||||
|
|
||||||
Database.init({
|
|
||||||
"data-dir": dbPath,
|
|
||||||
});
|
|
||||||
|
|
||||||
await Database.connect();
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
log,
|
|
||||||
exit,
|
|
||||||
connectDb,
|
|
||||||
};
|
|
@@ -1,8 +1,10 @@
|
|||||||
const { BeanModel } = require("redbean-node/dist/bean-model");
|
const { BeanModel } = require("redbean-node/dist/bean-model");
|
||||||
const { parseTimeObject, parseTimeFromTimeObject, utcToLocal, localToUTC, log } = require("../../src/util");
|
const { parseTimeObject, parseTimeFromTimeObject, log } = require("../../src/util");
|
||||||
const { timeObjectToUTC, timeObjectToLocal } = require("../util-server");
|
|
||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
const dayjs = require("dayjs");
|
const dayjs = require("dayjs");
|
||||||
|
const Cron = require("croner");
|
||||||
|
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
||||||
|
const apicache = require("../modules/apicache");
|
||||||
|
|
||||||
class Maintenance extends BeanModel {
|
class Maintenance extends BeanModel {
|
||||||
|
|
||||||
@@ -15,16 +17,19 @@ class Maintenance extends BeanModel {
|
|||||||
|
|
||||||
let dateRange = [];
|
let dateRange = [];
|
||||||
if (this.start_date) {
|
if (this.start_date) {
|
||||||
dateRange.push(utcToLocal(this.start_date));
|
dateRange.push(this.start_date);
|
||||||
if (this.end_date) {
|
} else {
|
||||||
dateRange.push(utcToLocal(this.end_date));
|
dateRange.push(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.end_date) {
|
||||||
|
dateRange.push(this.end_date);
|
||||||
}
|
}
|
||||||
|
|
||||||
let timeRange = [];
|
let timeRange = [];
|
||||||
let startTime = timeObjectToLocal(parseTimeObject(this.start_time));
|
let startTime = parseTimeObject(this.start_time);
|
||||||
timeRange.push(startTime);
|
timeRange.push(startTime);
|
||||||
let endTime = timeObjectToLocal(parseTimeObject(this.end_time));
|
let endTime = parseTimeObject(this.end_time);
|
||||||
timeRange.push(endTime);
|
timeRange.push(endTime);
|
||||||
|
|
||||||
let obj = {
|
let obj = {
|
||||||
@@ -39,12 +44,44 @@ class Maintenance extends BeanModel {
|
|||||||
weekdays: (this.weekdays) ? JSON.parse(this.weekdays) : [],
|
weekdays: (this.weekdays) ? JSON.parse(this.weekdays) : [],
|
||||||
daysOfMonth: (this.days_of_month) ? JSON.parse(this.days_of_month) : [],
|
daysOfMonth: (this.days_of_month) ? JSON.parse(this.days_of_month) : [],
|
||||||
timeslotList: [],
|
timeslotList: [],
|
||||||
|
cron: this.cron,
|
||||||
|
duration: this.duration,
|
||||||
|
durationMinutes: parseInt(this.duration / 60),
|
||||||
|
timezone: await this.getTimezone(), // Only valid timezone
|
||||||
|
timezoneOption: this.timezone, // Mainly for dropdown menu, because there is a option "SAME_AS_SERVER"
|
||||||
|
timezoneOffset: await this.getTimezoneOffset(),
|
||||||
|
status: await this.getStatus(),
|
||||||
};
|
};
|
||||||
|
|
||||||
const timeslotList = await this.getTimeslotList();
|
if (this.strategy === "manual") {
|
||||||
|
// Do nothing, no timeslots
|
||||||
|
} else if (this.strategy === "single") {
|
||||||
|
obj.timeslotList.push({
|
||||||
|
startDate: this.start_date,
|
||||||
|
endDate: this.end_date,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Should be cron or recurring here
|
||||||
|
if (this.beanMeta.job) {
|
||||||
|
let runningTimeslot = this.getRunningTimeslot();
|
||||||
|
|
||||||
for (let timeslot of timeslotList) {
|
if (runningTimeslot) {
|
||||||
obj.timeslotList.push(await timeslot.toPublicJSON());
|
obj.timeslotList.push(runningTimeslot);
|
||||||
|
}
|
||||||
|
|
||||||
|
let nextRunDate = this.beanMeta.job.nextRun();
|
||||||
|
if (nextRunDate) {
|
||||||
|
let startDateDayjs = dayjs(nextRunDate);
|
||||||
|
|
||||||
|
let startDate = startDateDayjs.toISOString();
|
||||||
|
let endDate = startDateDayjs.add(this.duration, "second").toISOString();
|
||||||
|
|
||||||
|
obj.timeslotList.push({
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Array.isArray(obj.weekdays)) {
|
if (!Array.isArray(obj.weekdays)) {
|
||||||
@@ -55,54 +92,9 @@ class Maintenance extends BeanModel {
|
|||||||
obj.daysOfMonth = [];
|
obj.daysOfMonth = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maintenance Status
|
|
||||||
if (!obj.active) {
|
|
||||||
obj.status = "inactive";
|
|
||||||
} else if (obj.strategy === "manual") {
|
|
||||||
obj.status = "under-maintenance";
|
|
||||||
} else if (obj.timeslotList.length > 0) {
|
|
||||||
let currentTimestamp = dayjs().unix();
|
|
||||||
|
|
||||||
for (let timeslot of obj.timeslotList) {
|
|
||||||
if (dayjs.utc(timeslot.startDate).unix() <= currentTimestamp && dayjs.utc(timeslot.endDate).unix() >= currentTimestamp) {
|
|
||||||
log.debug("timeslot", "Timeslot ID: " + timeslot.id);
|
|
||||||
log.debug("timeslot", "currentTimestamp:" + currentTimestamp);
|
|
||||||
log.debug("timeslot", "timeslot.start_date:" + dayjs.utc(timeslot.startDate).unix());
|
|
||||||
log.debug("timeslot", "timeslot.end_date:" + dayjs.utc(timeslot.endDate).unix());
|
|
||||||
|
|
||||||
obj.status = "under-maintenance";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!obj.status) {
|
|
||||||
obj.status = "scheduled";
|
|
||||||
}
|
|
||||||
} else if (obj.timeslotList.length === 0) {
|
|
||||||
obj.status = "ended";
|
|
||||||
} else {
|
|
||||||
obj.status = "unknown";
|
|
||||||
}
|
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Only get future or current timeslots only
|
|
||||||
* @returns {Promise<[]>}
|
|
||||||
*/
|
|
||||||
async getTimeslotList() {
|
|
||||||
return R.convertToBeans("maintenance_timeslot", await R.getAll(`
|
|
||||||
SELECT maintenance_timeslot.*
|
|
||||||
FROM maintenance_timeslot, maintenance
|
|
||||||
WHERE maintenance_timeslot.maintenance_id = maintenance.id
|
|
||||||
AND maintenance.id = ?
|
|
||||||
AND ${Maintenance.getActiveAndFutureMaintenanceSQLCondition()}
|
|
||||||
`, [
|
|
||||||
this.id
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an object that ready to parse to JSON
|
* Return an object that ready to parse to JSON
|
||||||
* @param {string} timezone If not specified, the timeRange will be in UTC
|
* @param {string} timezone If not specified, the timeRange will be in UTC
|
||||||
@@ -126,7 +118,7 @@ class Maintenance extends BeanModel {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of days in month that maintenance is active for
|
* Get a list of days in month that maintenance is active for
|
||||||
* @returns {number[]} Array of active days in month
|
* @returns {number[]|string[]} Array of active days in month
|
||||||
*/
|
*/
|
||||||
getDayOfMonthList() {
|
getDayOfMonthList() {
|
||||||
return JSON.parse(this.days_of_month).sort(function (a, b) {
|
return JSON.parse(this.days_of_month).sort(function (a, b) {
|
||||||
@@ -135,26 +127,10 @@ class Maintenance extends BeanModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the start date and time for maintenance
|
* Get the duration of maintenance in seconds
|
||||||
* @returns {dayjs.Dayjs} Start date and time
|
|
||||||
*/
|
|
||||||
getStartDateTime() {
|
|
||||||
let startOfTheDay = dayjs.utc(this.start_date).format("HH:mm");
|
|
||||||
log.debug("timeslot", "startOfTheDay: " + startOfTheDay);
|
|
||||||
|
|
||||||
// Start Time
|
|
||||||
let startTimeSecond = dayjs.utc(this.start_time, "HH:mm").diff(dayjs.utc(startOfTheDay, "HH:mm"), "second");
|
|
||||||
log.debug("timeslot", "startTime: " + startTimeSecond);
|
|
||||||
|
|
||||||
// Bake StartDate + StartTime = Start DateTime
|
|
||||||
return dayjs.utc(this.start_date).add(startTimeSecond, "second");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the duraction of maintenance in seconds
|
|
||||||
* @returns {number} Duration of maintenance
|
* @returns {number} Duration of maintenance
|
||||||
*/
|
*/
|
||||||
getDuration() {
|
calcDuration() {
|
||||||
let duration = dayjs.utc(this.end_time, "HH:mm").diff(dayjs.utc(this.start_time, "HH:mm"), "second");
|
let duration = dayjs.utc(this.end_time, "HH:mm").diff(dayjs.utc(this.start_time, "HH:mm"), "second");
|
||||||
// Add 24hours if it is across day
|
// Add 24hours if it is across day
|
||||||
if (duration < 0) {
|
if (duration < 0) {
|
||||||
@@ -169,71 +145,270 @@ class Maintenance extends BeanModel {
|
|||||||
* @param {Object} obj Data to fill bean with
|
* @param {Object} obj Data to fill bean with
|
||||||
* @returns {Bean} Filled bean
|
* @returns {Bean} Filled bean
|
||||||
*/
|
*/
|
||||||
static jsonToBean(bean, obj) {
|
static async jsonToBean(bean, obj) {
|
||||||
if (obj.id) {
|
if (obj.id) {
|
||||||
bean.id = obj.id;
|
bean.id = obj.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply timezone offset to timeRange, as it cannot apply automatically.
|
|
||||||
if (obj.timeRange[0]) {
|
|
||||||
timeObjectToUTC(obj.timeRange[0]);
|
|
||||||
if (obj.timeRange[1]) {
|
|
||||||
timeObjectToUTC(obj.timeRange[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bean.title = obj.title;
|
bean.title = obj.title;
|
||||||
bean.description = obj.description;
|
bean.description = obj.description;
|
||||||
bean.strategy = obj.strategy;
|
bean.strategy = obj.strategy;
|
||||||
bean.interval_day = obj.intervalDay;
|
bean.interval_day = obj.intervalDay;
|
||||||
|
bean.timezone = obj.timezoneOption;
|
||||||
bean.active = obj.active;
|
bean.active = obj.active;
|
||||||
|
|
||||||
if (obj.dateRange[0]) {
|
if (obj.dateRange[0]) {
|
||||||
bean.start_date = localToUTC(obj.dateRange[0]);
|
bean.start_date = obj.dateRange[0];
|
||||||
|
} else {
|
||||||
|
bean.start_date = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (obj.dateRange[1]) {
|
if (obj.dateRange[1]) {
|
||||||
bean.end_date = localToUTC(obj.dateRange[1]);
|
bean.end_date = obj.dateRange[1];
|
||||||
}
|
} else {
|
||||||
|
bean.end_date = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bean.strategy === "cron") {
|
||||||
|
bean.duration = obj.durationMinutes * 60;
|
||||||
|
bean.cron = obj.cron;
|
||||||
|
this.validateCron(bean.cron);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bean.strategy.startsWith("recurring-")) {
|
||||||
bean.start_time = parseTimeFromTimeObject(obj.timeRange[0]);
|
bean.start_time = parseTimeFromTimeObject(obj.timeRange[0]);
|
||||||
bean.end_time = parseTimeFromTimeObject(obj.timeRange[1]);
|
bean.end_time = parseTimeFromTimeObject(obj.timeRange[1]);
|
||||||
|
|
||||||
bean.weekdays = JSON.stringify(obj.weekdays);
|
bean.weekdays = JSON.stringify(obj.weekdays);
|
||||||
bean.days_of_month = JSON.stringify(obj.daysOfMonth);
|
bean.days_of_month = JSON.stringify(obj.daysOfMonth);
|
||||||
|
await bean.generateCron();
|
||||||
|
this.validateCron(bean.cron);
|
||||||
|
}
|
||||||
return bean;
|
return bean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SQL conditions for active maintenance
|
* Throw error if cron is invalid
|
||||||
* @returns {string}
|
* @param cron
|
||||||
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static getActiveMaintenanceSQLCondition() {
|
static async validateCron(cron) {
|
||||||
return `
|
let job = new Cron(cron, () => {});
|
||||||
(
|
job.stop();
|
||||||
(maintenance_timeslot.start_date <= DATETIME('now')
|
|
||||||
AND maintenance_timeslot.end_date >= DATETIME('now')
|
|
||||||
AND maintenance.active = 1)
|
|
||||||
OR
|
|
||||||
(maintenance.strategy = 'manual' AND active = 1)
|
|
||||||
)
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SQL conditions for active and future maintenance
|
* Run the cron
|
||||||
* @returns {string}
|
|
||||||
*/
|
*/
|
||||||
static getActiveAndFutureMaintenanceSQLCondition() {
|
async run(throwError = false) {
|
||||||
return `
|
if (this.beanMeta.job) {
|
||||||
(
|
log.debug("maintenance", "Maintenance is already running, stop it first. id: " + this.id);
|
||||||
((maintenance_timeslot.end_date >= DATETIME('now')
|
this.stop();
|
||||||
AND maintenance.active = 1)
|
}
|
||||||
OR
|
|
||||||
(maintenance.strategy = 'manual' AND active = 1))
|
log.debug("maintenance", "Run maintenance id: " + this.id);
|
||||||
)
|
|
||||||
`;
|
// 1.21.2 migration
|
||||||
|
if (!this.cron) {
|
||||||
|
await this.generateCron();
|
||||||
|
if (!this.timezone) {
|
||||||
|
this.timezone = "UTC";
|
||||||
|
}
|
||||||
|
if (this.cron) {
|
||||||
|
await R.store(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.strategy === "manual") {
|
||||||
|
// Do nothing, because it is controlled by the user
|
||||||
|
} else if (this.strategy === "single") {
|
||||||
|
this.beanMeta.job = new Cron(this.start_date, { timezone: await this.getTimezone() }, () => {
|
||||||
|
log.info("maintenance", "Maintenance id: " + this.id + " is under maintenance now");
|
||||||
|
UptimeKumaServer.getInstance().sendMaintenanceListByUserID(this.user_id);
|
||||||
|
apicache.clear();
|
||||||
|
});
|
||||||
|
} else if (this.cron != null) {
|
||||||
|
// Here should be cron or recurring
|
||||||
|
try {
|
||||||
|
this.beanMeta.status = "scheduled";
|
||||||
|
|
||||||
|
let startEvent = (customDuration = 0) => {
|
||||||
|
log.info("maintenance", "Maintenance id: " + this.id + " is under maintenance now");
|
||||||
|
|
||||||
|
this.beanMeta.status = "under-maintenance";
|
||||||
|
clearTimeout(this.beanMeta.durationTimeout);
|
||||||
|
|
||||||
|
// Check if duration is still in the window. If not, use the duration from the current time to the end of the window
|
||||||
|
let duration;
|
||||||
|
|
||||||
|
if (customDuration > 0) {
|
||||||
|
duration = customDuration;
|
||||||
|
} else if (this.end_date) {
|
||||||
|
let d = dayjs(this.end_date).diff(dayjs(), "second");
|
||||||
|
if (d < this.duration) {
|
||||||
|
duration = d * 1000;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
duration = this.duration * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
UptimeKumaServer.getInstance().sendMaintenanceListByUserID(this.user_id);
|
||||||
|
|
||||||
|
this.beanMeta.durationTimeout = setTimeout(() => {
|
||||||
|
// End of maintenance for this timeslot
|
||||||
|
this.beanMeta.status = "scheduled";
|
||||||
|
UptimeKumaServer.getInstance().sendMaintenanceListByUserID(this.user_id);
|
||||||
|
}, duration);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create Cron
|
||||||
|
this.beanMeta.job = new Cron(this.cron, {
|
||||||
|
timezone: await this.getTimezone(),
|
||||||
|
}, startEvent);
|
||||||
|
|
||||||
|
// Continue if the maintenance is still in the window
|
||||||
|
let runningTimeslot = this.getRunningTimeslot();
|
||||||
|
let current = dayjs();
|
||||||
|
|
||||||
|
if (runningTimeslot) {
|
||||||
|
let duration = dayjs(runningTimeslot.endDate).diff(current, "second") * 1000;
|
||||||
|
log.debug("maintenance", "Maintenance id: " + this.id + " Remaining duration: " + duration + "ms");
|
||||||
|
startEvent(duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
log.error("maintenance", "Error in maintenance id: " + this.id);
|
||||||
|
log.error("maintenance", "Cron: " + this.cron);
|
||||||
|
log.error("maintenance", e);
|
||||||
|
|
||||||
|
if (throwError) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
log.error("maintenance", "Maintenance id: " + this.id + " has no cron");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getRunningTimeslot() {
|
||||||
|
let start = dayjs(this.beanMeta.job.nextRun(dayjs().add(-this.duration, "second").toDate()));
|
||||||
|
let end = start.add(this.duration, "second");
|
||||||
|
let current = dayjs();
|
||||||
|
|
||||||
|
if (current.isAfter(start) && current.isBefore(end)) {
|
||||||
|
return {
|
||||||
|
startDate: start.toISOString(),
|
||||||
|
endDate: end.toISOString(),
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
if (this.beanMeta.job) {
|
||||||
|
this.beanMeta.job.stop();
|
||||||
|
delete this.beanMeta.job;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async isUnderMaintenance() {
|
||||||
|
return (await this.getStatus()) === "under-maintenance";
|
||||||
|
}
|
||||||
|
|
||||||
|
async getTimezone() {
|
||||||
|
if (!this.timezone || this.timezone === "SAME_AS_SERVER") {
|
||||||
|
return await UptimeKumaServer.getInstance().getTimezone();
|
||||||
|
}
|
||||||
|
return this.timezone;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getTimezoneOffset() {
|
||||||
|
return dayjs.tz(dayjs(), await this.getTimezone()).format("Z");
|
||||||
|
}
|
||||||
|
|
||||||
|
async getStatus() {
|
||||||
|
if (!this.active) {
|
||||||
|
return "inactive";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.strategy === "manual") {
|
||||||
|
return "under-maintenance";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the maintenance is started
|
||||||
|
if (this.start_date && dayjs().isBefore(dayjs.tz(this.start_date, await this.getTimezone()))) {
|
||||||
|
return "scheduled";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the maintenance is ended
|
||||||
|
if (this.end_date && dayjs().isAfter(dayjs.tz(this.end_date, await this.getTimezone()))) {
|
||||||
|
return "ended";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.strategy === "single") {
|
||||||
|
return "under-maintenance";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.beanMeta.status) {
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.beanMeta.status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate Cron for recurring maintenance
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async generateCron() {
|
||||||
|
log.info("maintenance", "Generate cron for maintenance id: " + this.id);
|
||||||
|
|
||||||
|
if (this.strategy === "cron") {
|
||||||
|
// Do nothing for cron
|
||||||
|
} else if (!this.strategy.startsWith("recurring-")) {
|
||||||
|
this.cron = "";
|
||||||
|
} else if (this.strategy === "recurring-interval") {
|
||||||
|
let array = this.start_time.split(":");
|
||||||
|
let hour = parseInt(array[0]);
|
||||||
|
let minute = parseInt(array[1]);
|
||||||
|
this.cron = minute + " " + hour + " */" + this.interval_day + " * *";
|
||||||
|
this.duration = this.calcDuration();
|
||||||
|
log.debug("maintenance", "Cron: " + this.cron);
|
||||||
|
log.debug("maintenance", "Duration: " + this.duration);
|
||||||
|
} else if (this.strategy === "recurring-weekday") {
|
||||||
|
let list = this.getDayOfWeekList();
|
||||||
|
let array = this.start_time.split(":");
|
||||||
|
let hour = parseInt(array[0]);
|
||||||
|
let minute = parseInt(array[1]);
|
||||||
|
this.cron = minute + " " + hour + " * * " + list.join(",");
|
||||||
|
this.duration = this.calcDuration();
|
||||||
|
} else if (this.strategy === "recurring-day-of-month") {
|
||||||
|
let list = this.getDayOfMonthList();
|
||||||
|
let array = this.start_time.split(":");
|
||||||
|
let hour = parseInt(array[0]);
|
||||||
|
let minute = parseInt(array[1]);
|
||||||
|
|
||||||
|
let dayList = [];
|
||||||
|
|
||||||
|
for (let day of list) {
|
||||||
|
if (typeof day === "string" && day.startsWith("lastDay")) {
|
||||||
|
if (day === "lastDay1") {
|
||||||
|
dayList.push("L");
|
||||||
|
}
|
||||||
|
// Unfortunately, lastDay2-4 is not supported by cron
|
||||||
|
} else {
|
||||||
|
dayList.push(day);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove duplicate
|
||||||
|
dayList = [ ...new Set(dayList) ];
|
||||||
|
|
||||||
|
this.cron = minute + " " + hour + " " + dayList.join(",") + " * *";
|
||||||
|
this.duration = this.calcDuration();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,223 +0,0 @@
|
|||||||
const { BeanModel } = require("redbean-node/dist/bean-model");
|
|
||||||
const { R } = require("redbean-node");
|
|
||||||
const dayjs = require("dayjs");
|
|
||||||
const { log, utcToLocal, SQL_DATETIME_FORMAT_WITHOUT_SECOND, localToUTC } = require("../../src/util");
|
|
||||||
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
|
||||||
|
|
||||||
class MaintenanceTimeslot extends BeanModel {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an object that ready to parse to JSON for public
|
|
||||||
* Only show necessary data to public
|
|
||||||
* @returns {Object}
|
|
||||||
*/
|
|
||||||
async toPublicJSON() {
|
|
||||||
const serverTimezoneOffset = UptimeKumaServer.getInstance().getTimezoneOffset();
|
|
||||||
|
|
||||||
const obj = {
|
|
||||||
id: this.id,
|
|
||||||
startDate: this.start_date,
|
|
||||||
endDate: this.end_date,
|
|
||||||
startDateServerTimezone: utcToLocal(this.start_date, SQL_DATETIME_FORMAT_WITHOUT_SECOND),
|
|
||||||
endDateServerTimezone: utcToLocal(this.end_date, SQL_DATETIME_FORMAT_WITHOUT_SECOND),
|
|
||||||
serverTimezoneOffset,
|
|
||||||
};
|
|
||||||
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an object that ready to parse to JSON
|
|
||||||
* @returns {Object}
|
|
||||||
*/
|
|
||||||
async toJSON() {
|
|
||||||
return await this.toPublicJSON();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {Maintenance} maintenance
|
|
||||||
* @param {dayjs} minDate (For recurring type only) Generate a next timeslot from this date.
|
|
||||||
* @param {boolean} removeExist Remove existing timeslot before create
|
|
||||||
* @returns {Promise<MaintenanceTimeslot>}
|
|
||||||
*/
|
|
||||||
static async generateTimeslot(maintenance, minDate = null, removeExist = false) {
|
|
||||||
log.info("maintenance", "Generate Timeslot for maintenance id: " + maintenance.id);
|
|
||||||
|
|
||||||
if (removeExist) {
|
|
||||||
await R.exec("DELETE FROM maintenance_timeslot WHERE maintenance_id = ? ", [
|
|
||||||
maintenance.id
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (maintenance.strategy === "manual") {
|
|
||||||
log.debug("maintenance", "No need to generate timeslot for manual type");
|
|
||||||
|
|
||||||
} else if (maintenance.strategy === "single") {
|
|
||||||
let bean = R.dispense("maintenance_timeslot");
|
|
||||||
bean.maintenance_id = maintenance.id;
|
|
||||||
bean.start_date = maintenance.start_date;
|
|
||||||
bean.end_date = maintenance.end_date;
|
|
||||||
bean.generated_next = true;
|
|
||||||
|
|
||||||
if (!await this.isDuplicateTimeslot(bean)) {
|
|
||||||
await R.store(bean);
|
|
||||||
return bean;
|
|
||||||
} else {
|
|
||||||
log.debug("maintenance", "Duplicate timeslot, skip");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (maintenance.strategy === "recurring-interval") {
|
|
||||||
// Prevent dead loop, in case interval_day is not set
|
|
||||||
if (!maintenance.interval_day || maintenance.interval_day <= 0) {
|
|
||||||
maintenance.interval_day = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return await this.handleRecurringType(maintenance, minDate, (startDateTime) => {
|
|
||||||
return startDateTime.add(maintenance.interval_day, "day");
|
|
||||||
}, () => {
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
} else if (maintenance.strategy === "recurring-weekday") {
|
|
||||||
let dayOfWeekList = maintenance.getDayOfWeekList();
|
|
||||||
log.debug("timeslot", dayOfWeekList);
|
|
||||||
|
|
||||||
if (dayOfWeekList.length <= 0) {
|
|
||||||
log.debug("timeslot", "No weekdays selected?");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isValid = (startDateTime) => {
|
|
||||||
log.debug("timeslot", "nextDateTime: " + startDateTime);
|
|
||||||
|
|
||||||
let day = startDateTime.local().day();
|
|
||||||
log.debug("timeslot", "nextDateTime.day(): " + day);
|
|
||||||
|
|
||||||
return dayOfWeekList.includes(day);
|
|
||||||
};
|
|
||||||
|
|
||||||
return await this.handleRecurringType(maintenance, minDate, (startDateTime) => {
|
|
||||||
while (true) {
|
|
||||||
startDateTime = startDateTime.add(1, "day");
|
|
||||||
|
|
||||||
if (isValid(startDateTime)) {
|
|
||||||
return startDateTime;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, isValid);
|
|
||||||
|
|
||||||
} else if (maintenance.strategy === "recurring-day-of-month") {
|
|
||||||
let dayOfMonthList = maintenance.getDayOfMonthList();
|
|
||||||
if (dayOfMonthList.length <= 0) {
|
|
||||||
log.debug("timeslot", "No day selected?");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isValid = (startDateTime) => {
|
|
||||||
let day = parseInt(startDateTime.local().format("D"));
|
|
||||||
|
|
||||||
log.debug("timeslot", "day: " + day);
|
|
||||||
|
|
||||||
// Check 1-31
|
|
||||||
if (dayOfMonthList.includes(day)) {
|
|
||||||
return startDateTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check "lastDay1","lastDay2"...
|
|
||||||
let daysInMonth = startDateTime.daysInMonth();
|
|
||||||
let lastDayList = [];
|
|
||||||
|
|
||||||
// Small first, e.g. 28 > 29 > 30 > 31
|
|
||||||
for (let i = 4; i >= 1; i--) {
|
|
||||||
if (dayOfMonthList.includes("lastDay" + i)) {
|
|
||||||
lastDayList.push(daysInMonth - i + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.debug("timeslot", lastDayList);
|
|
||||||
return lastDayList.includes(day);
|
|
||||||
};
|
|
||||||
|
|
||||||
return await this.handleRecurringType(maintenance, minDate, (startDateTime) => {
|
|
||||||
while (true) {
|
|
||||||
startDateTime = startDateTime.add(1, "day");
|
|
||||||
if (isValid(startDateTime)) {
|
|
||||||
return startDateTime;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, isValid);
|
|
||||||
} else {
|
|
||||||
throw new Error("Unknown maintenance strategy");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async isDuplicateTimeslot(timeslot) {
|
|
||||||
let bean = await R.findOne("maintenance_timeslot", "maintenance_id = ? AND start_date = ? AND end_date = ?", [
|
|
||||||
timeslot.maintenance_id,
|
|
||||||
timeslot.start_date,
|
|
||||||
timeslot.end_date
|
|
||||||
]);
|
|
||||||
return bean !== null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a next timeslot for all recurring types
|
|
||||||
* @param maintenance
|
|
||||||
* @param minDate
|
|
||||||
* @param {function} nextDayCallback The logic how to get the next possible day
|
|
||||||
* @param {function} isValidCallback Check the day whether is matched the current strategy
|
|
||||||
* @returns {Promise<null|MaintenanceTimeslot>}
|
|
||||||
*/
|
|
||||||
static async handleRecurringType(maintenance, minDate, nextDayCallback, isValidCallback) {
|
|
||||||
let bean = R.dispense("maintenance_timeslot");
|
|
||||||
|
|
||||||
let duration = maintenance.getDuration();
|
|
||||||
let startDateTime = maintenance.getStartDateTime();
|
|
||||||
let endDateTime;
|
|
||||||
|
|
||||||
// Keep generating from the first possible date, until it is ok
|
|
||||||
while (true) {
|
|
||||||
//log.debug("timeslot", "startDateTime: " + startDateTime.format());
|
|
||||||
|
|
||||||
// Handling out of effective date range
|
|
||||||
if (startDateTime.diff(dayjs.utc(maintenance.end_date)) > 0) {
|
|
||||||
log.debug("timeslot", "Out of effective date range");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
endDateTime = startDateTime.add(duration, "second");
|
|
||||||
|
|
||||||
// If endDateTime is out of effective date range, use the end datetime from effective date range
|
|
||||||
if (endDateTime.diff(dayjs.utc(maintenance.end_date)) > 0) {
|
|
||||||
endDateTime = dayjs.utc(maintenance.end_date);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If minDate is set, the endDateTime must be bigger than it.
|
|
||||||
// And the endDateTime must be bigger current time
|
|
||||||
// Is valid under current recurring strategy
|
|
||||||
if (
|
|
||||||
(!minDate || endDateTime.diff(minDate) > 0) &&
|
|
||||||
endDateTime.diff(dayjs()) > 0 &&
|
|
||||||
isValidCallback(startDateTime)
|
|
||||||
) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
startDateTime = nextDayCallback(startDateTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
bean.maintenance_id = maintenance.id;
|
|
||||||
bean.start_date = localToUTC(startDateTime);
|
|
||||||
bean.end_date = localToUTC(endDateTime);
|
|
||||||
bean.generated_next = false;
|
|
||||||
|
|
||||||
if (!await this.isDuplicateTimeslot(bean)) {
|
|
||||||
await R.store(bean);
|
|
||||||
return bean;
|
|
||||||
} else {
|
|
||||||
log.debug("maintenance", "Duplicate timeslot, skip");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = MaintenanceTimeslot;
|
|
@@ -2,9 +2,11 @@ const https = require("https");
|
|||||||
const dayjs = require("dayjs");
|
const dayjs = require("dayjs");
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const { Prometheus } = require("../prometheus");
|
const { Prometheus } = require("../prometheus");
|
||||||
const { log, UP, DOWN, PENDING, MAINTENANCE, flipStatus, TimeLogger, MAX_INTERVAL_SECOND, MIN_INTERVAL_SECOND } = require("../../src/util");
|
const { log, UP, DOWN, PENDING, MAINTENANCE, flipStatus, TimeLogger, MAX_INTERVAL_SECOND, MIN_INTERVAL_SECOND,
|
||||||
|
SQL_DATETIME_FORMAT
|
||||||
|
} = require("../../src/util");
|
||||||
const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, mssqlQuery, postgresQuery, mysqlQuery, mqttAsync, setSetting, httpNtlm, radius, grpcQuery,
|
const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, mssqlQuery, postgresQuery, mysqlQuery, mqttAsync, setSetting, httpNtlm, radius, grpcQuery,
|
||||||
redisPingAsync, mongodbPing,
|
redisPingAsync, mongodbPing, kafkaProducerAsync
|
||||||
} = require("../util-server");
|
} = require("../util-server");
|
||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
const { BeanModel } = require("redbean-node/dist/bean-model");
|
const { BeanModel } = require("redbean-node/dist/bean-model");
|
||||||
@@ -16,9 +18,10 @@ const apicache = require("../modules/apicache");
|
|||||||
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
||||||
const { CacheableDnsHttpAgent } = require("../cacheable-dns-http-agent");
|
const { CacheableDnsHttpAgent } = require("../cacheable-dns-http-agent");
|
||||||
const { DockerHost } = require("../docker");
|
const { DockerHost } = require("../docker");
|
||||||
const Maintenance = require("./maintenance");
|
|
||||||
const { UptimeCacheList } = require("../uptime-cache-list");
|
const { UptimeCacheList } = require("../uptime-cache-list");
|
||||||
const Gamedig = require("gamedig");
|
const Gamedig = require("gamedig");
|
||||||
|
const jsonata = require("jsonata");
|
||||||
|
const jwt = require("jsonwebtoken");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* status:
|
* status:
|
||||||
@@ -69,22 +72,33 @@ class Monitor extends BeanModel {
|
|||||||
|
|
||||||
const tags = await this.getTags();
|
const tags = await this.getTags();
|
||||||
|
|
||||||
|
let screenshot = null;
|
||||||
|
|
||||||
|
if (this.type === "real-browser") {
|
||||||
|
screenshot = "/screenshots/" + jwt.sign(this.id, UptimeKumaServer.getInstance().jwtSecret) + ".png";
|
||||||
|
}
|
||||||
|
|
||||||
let data = {
|
let data = {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
description: this.description,
|
description: this.description,
|
||||||
|
pathName: await this.getPathName(),
|
||||||
|
parent: this.parent,
|
||||||
|
childrenIDs: await Monitor.getAllChildrenIDs(this.id),
|
||||||
url: this.url,
|
url: this.url,
|
||||||
method: this.method,
|
method: this.method,
|
||||||
hostname: this.hostname,
|
hostname: this.hostname,
|
||||||
port: this.port,
|
port: this.port,
|
||||||
maxretries: this.maxretries,
|
maxretries: this.maxretries,
|
||||||
weight: this.weight,
|
weight: this.weight,
|
||||||
active: this.active,
|
active: await this.isActive(),
|
||||||
|
forceInactive: !await Monitor.isParentActive(this.id),
|
||||||
type: this.type,
|
type: this.type,
|
||||||
interval: this.interval,
|
interval: this.interval,
|
||||||
retryInterval: this.retryInterval,
|
retryInterval: this.retryInterval,
|
||||||
resendInterval: this.resendInterval,
|
resendInterval: this.resendInterval,
|
||||||
keyword: this.keyword,
|
keyword: this.keyword,
|
||||||
|
invertKeyword: this.isInvertKeyword(),
|
||||||
expiryNotification: this.isEnabledExpiryNotification(),
|
expiryNotification: this.isEnabledExpiryNotification(),
|
||||||
ignoreTls: this.getIgnoreTls(),
|
ignoreTls: this.getIgnoreTls(),
|
||||||
upsideDown: this.isUpsideDown(),
|
upsideDown: this.isUpsideDown(),
|
||||||
@@ -112,7 +126,15 @@ class Monitor extends BeanModel {
|
|||||||
radiusCalledStationId: this.radiusCalledStationId,
|
radiusCalledStationId: this.radiusCalledStationId,
|
||||||
radiusCallingStationId: this.radiusCallingStationId,
|
radiusCallingStationId: this.radiusCallingStationId,
|
||||||
game: this.game,
|
game: this.game,
|
||||||
httpBodyEncoding: this.httpBodyEncoding
|
httpBodyEncoding: this.httpBodyEncoding,
|
||||||
|
jsonPath: this.jsonPath,
|
||||||
|
expectedValue: this.expectedValue,
|
||||||
|
kafkaProducerTopic: this.kafkaProducerTopic,
|
||||||
|
kafkaProducerBrokers: JSON.parse(this.kafkaProducerBrokers),
|
||||||
|
kafkaProducerSsl: this.kafkaProducerSsl === "1" && true || false,
|
||||||
|
kafkaProducerAllowAutoTopicCreation: this.kafkaProducerAllowAutoTopicCreation === "1" && true || false,
|
||||||
|
kafkaProducerMessage: this.kafkaProducerMessage,
|
||||||
|
screenshot,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (includeSensitiveData) {
|
if (includeSensitiveData) {
|
||||||
@@ -136,6 +158,7 @@ class Monitor extends BeanModel {
|
|||||||
tlsCa: this.tlsCa,
|
tlsCa: this.tlsCa,
|
||||||
tlsCert: this.tlsCert,
|
tlsCert: this.tlsCert,
|
||||||
tlsKey: this.tlsKey,
|
tlsKey: this.tlsKey,
|
||||||
|
kafkaProducerSaslOptions: JSON.parse(this.kafkaProducerSaslOptions),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,6 +166,16 @@ class Monitor extends BeanModel {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the monitor is active based on itself and its parents
|
||||||
|
* @returns {Promise<Boolean>}
|
||||||
|
*/
|
||||||
|
async isActive() {
|
||||||
|
const parentActive = await Monitor.isParentActive(this.id);
|
||||||
|
|
||||||
|
return (this.active === 1) && parentActive;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all tags applied to this monitor
|
* Get all tags applied to this monitor
|
||||||
* @returns {Promise<LooseObject<any>[]>}
|
* @returns {Promise<LooseObject<any>[]>}
|
||||||
@@ -184,6 +217,14 @@ class Monitor extends BeanModel {
|
|||||||
return Boolean(this.upsideDown);
|
return Boolean(this.upsideDown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse to boolean
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
isInvertKeyword() {
|
||||||
|
return Boolean(this.invertKeyword);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse to boolean
|
* Parse to boolean
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
@@ -258,7 +299,37 @@ class Monitor extends BeanModel {
|
|||||||
if (await Monitor.isUnderMaintenance(this.id)) {
|
if (await Monitor.isUnderMaintenance(this.id)) {
|
||||||
bean.msg = "Monitor under maintenance";
|
bean.msg = "Monitor under maintenance";
|
||||||
bean.status = MAINTENANCE;
|
bean.status = MAINTENANCE;
|
||||||
} else if (this.type === "http" || this.type === "keyword") {
|
} else if (this.type === "group") {
|
||||||
|
const children = await Monitor.getChildren(this.id);
|
||||||
|
|
||||||
|
if (children.length > 0) {
|
||||||
|
bean.status = UP;
|
||||||
|
bean.msg = "All children up and running";
|
||||||
|
for (const child of children) {
|
||||||
|
if (!child.active) {
|
||||||
|
// Ignore inactive childs
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const lastBeat = await Monitor.getPreviousHeartbeat(child.id);
|
||||||
|
|
||||||
|
// Only change state if the monitor is in worse conditions then the ones before
|
||||||
|
if (bean.status === UP && (lastBeat.status === PENDING || lastBeat.status === DOWN)) {
|
||||||
|
bean.status = lastBeat.status;
|
||||||
|
} else if (bean.status === PENDING && lastBeat.status === DOWN) {
|
||||||
|
bean.status = lastBeat.status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bean.status !== UP) {
|
||||||
|
bean.msg = "Child inaccessible";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Set status pending if group is empty
|
||||||
|
bean.status = PENDING;
|
||||||
|
bean.msg = "Group empty";
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (this.type === "http" || this.type === "keyword" || this.type === "json-query") {
|
||||||
// Do not do any queries/high loading things before the "bean.ping"
|
// Do not do any queries/high loading things before the "bean.ping"
|
||||||
let startTime = dayjs().valueOf();
|
let startTime = dayjs().valueOf();
|
||||||
|
|
||||||
@@ -364,8 +435,8 @@ class Monitor extends BeanModel {
|
|||||||
tlsInfo = await this.updateTlsInfo(tlsInfoObject);
|
tlsInfo = await this.updateTlsInfo(tlsInfoObject);
|
||||||
|
|
||||||
if (!this.getIgnoreTls() && this.isEnabledExpiryNotification()) {
|
if (!this.getIgnoreTls() && this.isEnabledExpiryNotification()) {
|
||||||
log.debug("monitor", `[${this.name}] call sendCertNotification`);
|
log.debug("monitor", `[${this.name}] call checkCertExpiryNotifications`);
|
||||||
await this.sendCertNotification(tlsInfoObject);
|
await this.checkCertExpiryNotifications(tlsInfoObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -386,7 +457,7 @@ class Monitor extends BeanModel {
|
|||||||
|
|
||||||
if (this.type === "http") {
|
if (this.type === "http") {
|
||||||
bean.status = UP;
|
bean.status = UP;
|
||||||
} else {
|
} else if (this.type === "keyword") {
|
||||||
|
|
||||||
let data = res.data;
|
let data = res.data;
|
||||||
|
|
||||||
@@ -395,17 +466,37 @@ class Monitor extends BeanModel {
|
|||||||
data = JSON.stringify(data);
|
data = JSON.stringify(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.includes(this.keyword)) {
|
let keywordFound = data.includes(this.keyword);
|
||||||
bean.msg += ", keyword is found";
|
if (keywordFound === !this.isInvertKeyword()) {
|
||||||
|
bean.msg += ", keyword " + (keywordFound ? "is" : "not") + " found";
|
||||||
bean.status = UP;
|
bean.status = UP;
|
||||||
} else {
|
} else {
|
||||||
data = data.replace(/<[^>]*>?|[\n\r]|\s+/gm, " ");
|
data = data.replace(/<[^>]*>?|[\n\r]|\s+/gm, " ").trim();
|
||||||
if (data.length > 50) {
|
if (data.length > 50) {
|
||||||
data = data.substring(0, 47) + "...";
|
data = data.substring(0, 47) + "...";
|
||||||
}
|
}
|
||||||
throw new Error(bean.msg + ", but keyword is not in [" + data + "]");
|
throw new Error(bean.msg + ", but keyword is " +
|
||||||
|
(keywordFound ? "present" : "not") + " in [" + data + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if (this.type === "json-query") {
|
||||||
|
let data = res.data;
|
||||||
|
|
||||||
|
// convert data to object
|
||||||
|
if (typeof data === "string") {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
let expression = jsonata(this.jsonPath);
|
||||||
|
|
||||||
|
let result = await expression.evaluate(data);
|
||||||
|
|
||||||
|
if (result.toString() === this.expectedValue) {
|
||||||
|
bean.msg += ", expected value is found";
|
||||||
|
bean.status = UP;
|
||||||
|
} else {
|
||||||
|
throw new Error(bean.msg + ", but value is not equal to expected value, value was: [" + result + "]");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (this.type === "port") {
|
} else if (this.type === "port") {
|
||||||
@@ -480,7 +571,7 @@ class Monitor extends BeanModel {
|
|||||||
// No need to insert successful heartbeat for push type, so end here
|
// No need to insert successful heartbeat for push type, so end here
|
||||||
retries = 0;
|
retries = 0;
|
||||||
log.debug("monitor", `[${this.name}] timeout = ${timeout}`);
|
log.debug("monitor", `[${this.name}] timeout = ${timeout}`);
|
||||||
this.heartbeatInterval = setTimeout(beat, timeout);
|
this.heartbeatInterval = setTimeout(safeBeat, timeout);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -573,9 +664,15 @@ class Monitor extends BeanModel {
|
|||||||
|
|
||||||
log.debug("monitor", `[${this.name}] Axios Request`);
|
log.debug("monitor", `[${this.name}] Axios Request`);
|
||||||
let res = await axios.request(options);
|
let res = await axios.request(options);
|
||||||
|
|
||||||
if (res.data.State.Running) {
|
if (res.data.State.Running) {
|
||||||
|
if (res.data.State.Health && res.data.State.Health.Status !== "healthy") {
|
||||||
|
bean.status = PENDING;
|
||||||
|
bean.msg = res.data.State.Health.Status;
|
||||||
|
} else {
|
||||||
bean.status = UP;
|
bean.status = UP;
|
||||||
bean.msg = res.data.State.Status;
|
bean.msg = res.data.State.Health ? res.data.State.Health.Status : res.data.State.Status;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw Error("Container State is " + res.data.State.Status);
|
throw Error("Container State is " + res.data.State.Status);
|
||||||
}
|
}
|
||||||
@@ -604,7 +701,6 @@ class Monitor extends BeanModel {
|
|||||||
grpcEnableTls: this.grpcEnableTls,
|
grpcEnableTls: this.grpcEnableTls,
|
||||||
grpcMethod: this.grpcMethod,
|
grpcMethod: this.grpcMethod,
|
||||||
grpcBody: this.grpcBody,
|
grpcBody: this.grpcBody,
|
||||||
keyword: this.keyword
|
|
||||||
};
|
};
|
||||||
const response = await grpcQuery(options);
|
const response = await grpcQuery(options);
|
||||||
bean.ping = dayjs().valueOf() - startTime;
|
bean.ping = dayjs().valueOf() - startTime;
|
||||||
@@ -617,13 +713,14 @@ class Monitor extends BeanModel {
|
|||||||
bean.status = DOWN;
|
bean.status = DOWN;
|
||||||
bean.msg = `Error in send gRPC ${response.code} ${response.errorMessage}`;
|
bean.msg = `Error in send gRPC ${response.code} ${response.errorMessage}`;
|
||||||
} else {
|
} else {
|
||||||
if (response.data.toString().includes(this.keyword)) {
|
let keywordFound = response.data.toString().includes(this.keyword);
|
||||||
|
if (keywordFound === !this.isInvertKeyword()) {
|
||||||
bean.status = UP;
|
bean.status = UP;
|
||||||
bean.msg = `${responseData}, keyword [${this.keyword}] is found`;
|
bean.msg = `${responseData}, keyword [${this.keyword}] ${keywordFound ? "is" : "not"} found`;
|
||||||
} else {
|
} else {
|
||||||
log.debug("monitor:", `GRPC response [${response.data}] + ", but keyword [${this.keyword}] is not in [" + ${response.data} + "]"`);
|
log.debug("monitor:", `GRPC response [${response.data}] + ", but keyword [${this.keyword}] is ${keywordFound ? "present" : "not"} in [" + ${response.data} + "]"`);
|
||||||
bean.status = DOWN;
|
bean.status = DOWN;
|
||||||
bean.msg = `, but keyword [${this.keyword}] is not in [" + ${responseData} + "]`;
|
bean.msg = `, but keyword [${this.keyword}] is ${keywordFound ? "present" : "not"} in [" + ${responseData} + "]`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (this.type === "postgres") {
|
} else if (this.type === "postgres") {
|
||||||
@@ -637,9 +734,7 @@ class Monitor extends BeanModel {
|
|||||||
} else if (this.type === "mysql") {
|
} else if (this.type === "mysql") {
|
||||||
let startTime = dayjs().valueOf();
|
let startTime = dayjs().valueOf();
|
||||||
|
|
||||||
await mysqlQuery(this.databaseConnectionString, this.databaseQuery);
|
bean.msg = await mysqlQuery(this.databaseConnectionString, this.databaseQuery);
|
||||||
|
|
||||||
bean.msg = "";
|
|
||||||
bean.status = UP;
|
bean.status = UP;
|
||||||
bean.ping = dayjs().valueOf() - startTime;
|
bean.ping = dayjs().valueOf() - startTime;
|
||||||
} else if (this.type === "mongodb") {
|
} else if (this.type === "mongodb") {
|
||||||
@@ -672,7 +767,8 @@ class Monitor extends BeanModel {
|
|||||||
this.radiusCalledStationId,
|
this.radiusCalledStationId,
|
||||||
this.radiusCallingStationId,
|
this.radiusCallingStationId,
|
||||||
this.radiusSecret,
|
this.radiusSecret,
|
||||||
port
|
port,
|
||||||
|
this.interval * 1000 * 0.8,
|
||||||
);
|
);
|
||||||
if (resp.code) {
|
if (resp.code) {
|
||||||
bean.msg = resp.code;
|
bean.msg = resp.code;
|
||||||
@@ -697,11 +793,29 @@ class Monitor extends BeanModel {
|
|||||||
} else if (this.type in UptimeKumaServer.monitorTypeList) {
|
} else if (this.type in UptimeKumaServer.monitorTypeList) {
|
||||||
let startTime = dayjs().valueOf();
|
let startTime = dayjs().valueOf();
|
||||||
const monitorType = UptimeKumaServer.monitorTypeList[this.type];
|
const monitorType = UptimeKumaServer.monitorTypeList[this.type];
|
||||||
await monitorType.check(this, bean);
|
await monitorType.check(this, bean, UptimeKumaServer.getInstance());
|
||||||
if (!bean.ping) {
|
if (!bean.ping) {
|
||||||
bean.ping = dayjs().valueOf() - startTime;
|
bean.ping = dayjs().valueOf() - startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if (this.type === "kafka-producer") {
|
||||||
|
let startTime = dayjs().valueOf();
|
||||||
|
|
||||||
|
bean.msg = await kafkaProducerAsync(
|
||||||
|
JSON.parse(this.kafkaProducerBrokers),
|
||||||
|
this.kafkaProducerTopic,
|
||||||
|
this.kafkaProducerMessage,
|
||||||
|
{
|
||||||
|
allowAutoTopicCreation: this.kafkaProducerAllowAutoTopicCreation,
|
||||||
|
ssl: this.kafkaProducerSsl,
|
||||||
|
clientId: `Uptime-Kuma/${version}`,
|
||||||
|
interval: this.interval,
|
||||||
|
},
|
||||||
|
JSON.parse(this.kafkaProducerSaslOptions),
|
||||||
|
);
|
||||||
|
bean.status = UP;
|
||||||
|
bean.ping = dayjs().valueOf() - startTime;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Unknown Monitor Type");
|
throw new Error("Unknown Monitor Type");
|
||||||
}
|
}
|
||||||
@@ -1179,12 +1293,18 @@ class Monitor extends BeanModel {
|
|||||||
|
|
||||||
for (let notification of notificationList) {
|
for (let notification of notificationList) {
|
||||||
try {
|
try {
|
||||||
// Prevent if the msg is undefined, notifications such as Discord cannot send out.
|
|
||||||
const heartbeatJSON = bean.toJSON();
|
const heartbeatJSON = bean.toJSON();
|
||||||
|
|
||||||
|
// Prevent if the msg is undefined, notifications such as Discord cannot send out.
|
||||||
if (!heartbeatJSON["msg"]) {
|
if (!heartbeatJSON["msg"]) {
|
||||||
heartbeatJSON["msg"] = "N/A";
|
heartbeatJSON["msg"] = "N/A";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Also provide the time in server timezone
|
||||||
|
heartbeatJSON["timezone"] = await UptimeKumaServer.getInstance().getTimezone();
|
||||||
|
heartbeatJSON["timezoneOffset"] = UptimeKumaServer.getInstance().getTimezoneOffset();
|
||||||
|
heartbeatJSON["localDateTime"] = dayjs.utc(heartbeatJSON["time"]).tz(heartbeatJSON["timezone"]).format(SQL_DATETIME_FORMAT);
|
||||||
|
|
||||||
await Notification.send(JSON.parse(notification.config), msg, await monitor.toJSON(false), heartbeatJSON);
|
await Notification.send(JSON.parse(notification.config), msg, await monitor.toJSON(false), heartbeatJSON);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.error("monitor", "Cannot send notification to " + notification.name);
|
log.error("monitor", "Cannot send notification to " + notification.name);
|
||||||
@@ -1207,13 +1327,19 @@ class Monitor extends BeanModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send notification about a certificate
|
* checks certificate chain for expiring certificates
|
||||||
* @param {Object} tlsInfoObject Information about certificate
|
* @param {Object} tlsInfoObject Information about certificate
|
||||||
*/
|
*/
|
||||||
async sendCertNotification(tlsInfoObject) {
|
async checkCertExpiryNotifications(tlsInfoObject) {
|
||||||
if (tlsInfoObject && tlsInfoObject.certInfo && tlsInfoObject.certInfo.daysRemaining) {
|
if (tlsInfoObject && tlsInfoObject.certInfo && tlsInfoObject.certInfo.daysRemaining) {
|
||||||
const notificationList = await Monitor.getNotificationList(this);
|
const notificationList = await Monitor.getNotificationList(this);
|
||||||
|
|
||||||
|
if (! notificationList.length > 0) {
|
||||||
|
// fail fast. If no notification is set, all the following checks can be skipped.
|
||||||
|
log.debug("monitor", "No notification, no need to send cert notification");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let notifyDays = await setting("tlsExpiryNotifyDays");
|
let notifyDays = await setting("tlsExpiryNotifyDays");
|
||||||
if (notifyDays == null || !Array.isArray(notifyDays)) {
|
if (notifyDays == null || !Array.isArray(notifyDays)) {
|
||||||
// Reset Default
|
// Reset Default
|
||||||
@@ -1221,10 +1347,19 @@ class Monitor extends BeanModel {
|
|||||||
notifyDays = [ 7, 14, 21 ];
|
notifyDays = [ 7, 14, 21 ];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notifyDays != null && Array.isArray(notifyDays)) {
|
if (Array.isArray(notifyDays)) {
|
||||||
for (const day of notifyDays) {
|
for (const targetDays of notifyDays) {
|
||||||
log.debug("monitor", "call sendCertNotificationByTargetDays", day);
|
let certInfo = tlsInfoObject.certInfo;
|
||||||
await this.sendCertNotificationByTargetDays(tlsInfoObject.certInfo.daysRemaining, day, notificationList);
|
while (certInfo) {
|
||||||
|
let subjectCN = certInfo.subject["CN"];
|
||||||
|
if (certInfo.daysRemaining > targetDays) {
|
||||||
|
log.debug("monitor", `No need to send cert notification for ${certInfo.certType} certificate "${subjectCN}" (${certInfo.daysRemaining} days valid) on ${targetDays} deadline.`);
|
||||||
|
} else {
|
||||||
|
log.debug("monitor", `call sendCertNotificationByTargetDays for ${targetDays} deadline on certificate ${subjectCN}.`);
|
||||||
|
await this.sendCertNotificationByTargetDays(subjectCN, certInfo.certType, certInfo.daysRemaining, targetDays, notificationList);
|
||||||
|
}
|
||||||
|
certInfo = certInfo.issuerCertificate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1233,21 +1368,16 @@ class Monitor extends BeanModel {
|
|||||||
/**
|
/**
|
||||||
* Send a certificate notification when certificate expires in less
|
* Send a certificate notification when certificate expires in less
|
||||||
* than target days
|
* than target days
|
||||||
* @param {number} daysRemaining Number of days remaining on certifcate
|
* @param {string} certCN Common Name attribute from the certificate subject
|
||||||
|
* @param {string} certType certificate type
|
||||||
|
* @param {number} daysRemaining Number of days remaining on certificate
|
||||||
* @param {number} targetDays Number of days to alert after
|
* @param {number} targetDays Number of days to alert after
|
||||||
* @param {LooseObject<any>[]} notificationList List of notification providers
|
* @param {LooseObject<any>[]} notificationList List of notification providers
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async sendCertNotificationByTargetDays(daysRemaining, targetDays, notificationList) {
|
async sendCertNotificationByTargetDays(certCN, certType, daysRemaining, targetDays, notificationList) {
|
||||||
|
|
||||||
if (daysRemaining > targetDays) {
|
let row = await R.getRow("SELECT * FROM notification_sent_history WHERE type = ? AND monitor_id = ? AND days <= ?", [
|
||||||
log.debug("monitor", `No need to send cert notification. ${daysRemaining} > ${targetDays}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (notificationList.length > 0) {
|
|
||||||
|
|
||||||
let row = await R.getRow("SELECT * FROM notification_sent_history WHERE type = ? AND monitor_id = ? AND days = ?", [
|
|
||||||
"certificate",
|
"certificate",
|
||||||
this.id,
|
this.id,
|
||||||
targetDays,
|
targetDays,
|
||||||
@@ -1265,7 +1395,7 @@ class Monitor extends BeanModel {
|
|||||||
for (let notification of notificationList) {
|
for (let notification of notificationList) {
|
||||||
try {
|
try {
|
||||||
log.debug("monitor", "Sending to " + notification.name);
|
log.debug("monitor", "Sending to " + notification.name);
|
||||||
await Notification.send(JSON.parse(notification.config), `[${this.name}][${this.url}] Certificate will expire in ${daysRemaining} days`);
|
await Notification.send(JSON.parse(notification.config), `[${this.name}][${this.url}] ${certType} certificate ${certCN} will be expired in ${daysRemaining} days`);
|
||||||
sent = true;
|
sent = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.error("monitor", "Cannot send cert notification to " + notification.name);
|
log.error("monitor", "Cannot send cert notification to " + notification.name);
|
||||||
@@ -1280,9 +1410,6 @@ class Monitor extends BeanModel {
|
|||||||
targetDays,
|
targetDays,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
log.debug("monitor", "No notification, no need to send cert notification");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1305,18 +1432,24 @@ class Monitor extends BeanModel {
|
|||||||
* @returns {Promise<boolean>}
|
* @returns {Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
static async isUnderMaintenance(monitorID) {
|
static async isUnderMaintenance(monitorID) {
|
||||||
let activeCondition = Maintenance.getActiveMaintenanceSQLCondition();
|
const maintenanceIDList = await R.getCol(`
|
||||||
const maintenance = await R.getRow(`
|
SELECT maintenance_id FROM monitor_maintenance
|
||||||
SELECT COUNT(*) AS count
|
WHERE monitor_id = ?
|
||||||
FROM monitor_maintenance mm
|
`, [ monitorID ]);
|
||||||
JOIN maintenance
|
|
||||||
ON mm.maintenance_id = maintenance.id
|
for (const maintenanceID of maintenanceIDList) {
|
||||||
AND mm.monitor_id = ?
|
const maintenance = await UptimeKumaServer.getInstance().getMaintenance(maintenanceID);
|
||||||
LEFT JOIN maintenance_timeslot
|
if (maintenance && await maintenance.isUnderMaintenance()) {
|
||||||
ON maintenance_timeslot.maintenance_id = maintenance.id
|
return true;
|
||||||
WHERE ${activeCondition}
|
}
|
||||||
LIMIT 1`, [ monitorID ]);
|
}
|
||||||
return maintenance.count !== 0;
|
|
||||||
|
const parent = await Monitor.getParent(monitorID);
|
||||||
|
if (parent != null) {
|
||||||
|
return await Monitor.isUnderMaintenance(parent.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Make sure monitor interval is between bounds */
|
/** Make sure monitor interval is between bounds */
|
||||||
@@ -1328,6 +1461,105 @@ class Monitor extends BeanModel {
|
|||||||
throw new Error(`Interval cannot be less than ${MIN_INTERVAL_SECOND} seconds`);
|
throw new Error(`Interval cannot be less than ${MIN_INTERVAL_SECOND} seconds`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets Parent of the monitor
|
||||||
|
* @param {number} monitorID ID of monitor to get
|
||||||
|
* @returns {Promise<LooseObject<any>>}
|
||||||
|
*/
|
||||||
|
static async getParent(monitorID) {
|
||||||
|
return await R.getRow(`
|
||||||
|
SELECT parent.* FROM monitor parent
|
||||||
|
LEFT JOIN monitor child
|
||||||
|
ON child.parent = parent.id
|
||||||
|
WHERE child.id = ?
|
||||||
|
`, [
|
||||||
|
monitorID,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all Children of the monitor
|
||||||
|
* @param {number} monitorID ID of monitor to get
|
||||||
|
* @returns {Promise<LooseObject<any>>}
|
||||||
|
*/
|
||||||
|
static async getChildren(monitorID) {
|
||||||
|
return await R.getAll(`
|
||||||
|
SELECT * FROM monitor
|
||||||
|
WHERE parent = ?
|
||||||
|
`, [
|
||||||
|
monitorID,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets Full Path-Name (Groups and Name)
|
||||||
|
* @returns {Promise<String>}
|
||||||
|
*/
|
||||||
|
async getPathName() {
|
||||||
|
let path = this.name;
|
||||||
|
|
||||||
|
if (this.parent === null) {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
let parent = await Monitor.getParent(this.id);
|
||||||
|
while (parent !== null) {
|
||||||
|
path = `${parent.name} / ${path}`;
|
||||||
|
parent = await Monitor.getParent(parent.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets recursive all child ids
|
||||||
|
* @param {number} monitorID ID of the monitor to get
|
||||||
|
* @returns {Promise<Array>}
|
||||||
|
*/
|
||||||
|
static async getAllChildrenIDs(monitorID) {
|
||||||
|
const childs = await Monitor.getChildren(monitorID);
|
||||||
|
|
||||||
|
if (childs === null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
let childrenIDs = [];
|
||||||
|
|
||||||
|
for (const child of childs) {
|
||||||
|
childrenIDs.push(child.id);
|
||||||
|
childrenIDs = childrenIDs.concat(await Monitor.getAllChildrenIDs(child.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return childrenIDs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unlinks all children of the the group monitor
|
||||||
|
* @param {number} groupID ID of group to remove children of
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
static async unlinkAllChildren(groupID) {
|
||||||
|
return await R.exec("UPDATE `monitor` SET parent = ? WHERE parent = ? ", [
|
||||||
|
null, groupID
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks recursive if parent (ancestors) are active
|
||||||
|
* @param {number} monitorID ID of the monitor to get
|
||||||
|
* @returns {Promise<Boolean>}
|
||||||
|
*/
|
||||||
|
static async isParentActive(monitorID) {
|
||||||
|
const parent = await Monitor.getParent(monitorID);
|
||||||
|
|
||||||
|
if (parent === null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parentActive = await Monitor.isParentActive(parent.id);
|
||||||
|
return parent.active && parentActive;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Monitor;
|
module.exports = Monitor;
|
||||||
|
@@ -3,7 +3,6 @@ const { R } = require("redbean-node");
|
|||||||
const cheerio = require("cheerio");
|
const cheerio = require("cheerio");
|
||||||
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
||||||
const jsesc = require("jsesc");
|
const jsesc = require("jsesc");
|
||||||
const Maintenance = require("./maintenance");
|
|
||||||
const googleAnalytics = require("../google-analytics");
|
const googleAnalytics = require("../google-analytics");
|
||||||
|
|
||||||
class StatusPage extends BeanModel {
|
class StatusPage extends BeanModel {
|
||||||
@@ -290,21 +289,17 @@ class StatusPage extends BeanModel {
|
|||||||
try {
|
try {
|
||||||
const publicMaintenanceList = [];
|
const publicMaintenanceList = [];
|
||||||
|
|
||||||
let activeCondition = Maintenance.getActiveMaintenanceSQLCondition();
|
let maintenanceIDList = await R.getCol(`
|
||||||
let maintenanceBeanList = R.convertToBeans("maintenance", await R.getAll(`
|
SELECT DISTINCT maintenance_id
|
||||||
SELECT DISTINCT maintenance.*
|
FROM maintenance_status_page
|
||||||
FROM maintenance
|
WHERE status_page_id = ?
|
||||||
JOIN maintenance_status_page
|
`, [ statusPageId ]);
|
||||||
ON maintenance_status_page.maintenance_id = maintenance.id
|
|
||||||
AND maintenance_status_page.status_page_id = ?
|
|
||||||
LEFT JOIN maintenance_timeslot
|
|
||||||
ON maintenance_timeslot.maintenance_id = maintenance.id
|
|
||||||
WHERE ${activeCondition}
|
|
||||||
ORDER BY maintenance.end_date
|
|
||||||
`, [ statusPageId ]));
|
|
||||||
|
|
||||||
for (const bean of maintenanceBeanList) {
|
for (const maintenanceID of maintenanceIDList) {
|
||||||
publicMaintenanceList.push(await bean.toPublicJSON());
|
let maintenance = UptimeKumaServer.getInstance().getMaintenance(maintenanceID);
|
||||||
|
if (maintenance && await maintenance.isUnderMaintenance()) {
|
||||||
|
publicMaintenanceList.push(await maintenance.toPublicJSON());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return publicMaintenanceList;
|
return publicMaintenanceList;
|
||||||
|
@@ -6,9 +6,10 @@ class MonitorType {
|
|||||||
*
|
*
|
||||||
* @param {Monitor} monitor
|
* @param {Monitor} monitor
|
||||||
* @param {Heartbeat} heartbeat
|
* @param {Heartbeat} heartbeat
|
||||||
|
* @param {UptimeKumaServer} server
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async check(monitor, heartbeat) {
|
async check(monitor, heartbeat, server) {
|
||||||
throw new Error("You need to override check()");
|
throw new Error("You need to override check()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
212
server/monitor-types/real-browser-monitor-type.js
Normal file
212
server/monitor-types/real-browser-monitor-type.js
Normal file
@@ -0,0 +1,212 @@
|
|||||||
|
const { MonitorType } = require("./monitor-type");
|
||||||
|
const { chromium } = require("playwright-core");
|
||||||
|
const { UP, log } = require("../../src/util");
|
||||||
|
const { Settings } = require("../settings");
|
||||||
|
const commandExistsSync = require("command-exists").sync;
|
||||||
|
const childProcess = require("child_process");
|
||||||
|
const path = require("path");
|
||||||
|
const Database = require("../database");
|
||||||
|
const jwt = require("jsonwebtoken");
|
||||||
|
const config = require("../config");
|
||||||
|
|
||||||
|
let browser = null;
|
||||||
|
|
||||||
|
let allowedList = [];
|
||||||
|
let lastAutoDetectChromeExecutable = null;
|
||||||
|
|
||||||
|
if (process.platform === "win32") {
|
||||||
|
allowedList.push(process.env.LOCALAPPDATA + "\\Google\\Chrome\\Application\\chrome.exe");
|
||||||
|
allowedList.push(process.env.PROGRAMFILES + "\\Google\\Chrome\\Application\\chrome.exe");
|
||||||
|
allowedList.push(process.env["ProgramFiles(x86)"] + "\\Google\\Chrome\\Application\\chrome.exe");
|
||||||
|
|
||||||
|
// Allow Chromium too
|
||||||
|
allowedList.push(process.env.LOCALAPPDATA + "\\Chromium\\Application\\chrome.exe");
|
||||||
|
allowedList.push(process.env.PROGRAMFILES + "\\Chromium\\Application\\chrome.exe");
|
||||||
|
allowedList.push(process.env["ProgramFiles(x86)"] + "\\Chromium\\Application\\chrome.exe");
|
||||||
|
|
||||||
|
// For Loop A to Z
|
||||||
|
for (let i = 65; i <= 90; i++) {
|
||||||
|
let drive = String.fromCharCode(i);
|
||||||
|
allowedList.push(drive + ":\\Program Files\\Google\\Chrome\\Application\\chrome.exe");
|
||||||
|
allowedList.push(drive + ":\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (process.platform === "linux") {
|
||||||
|
allowedList = [
|
||||||
|
"chromium",
|
||||||
|
"chromium-browser",
|
||||||
|
"google-chrome",
|
||||||
|
|
||||||
|
"/usr/bin/chromium",
|
||||||
|
"/usr/bin/chromium-browser",
|
||||||
|
"/usr/bin/google-chrome",
|
||||||
|
];
|
||||||
|
} else if (process.platform === "darwin") {
|
||||||
|
// TODO: Generated by GitHub Copilot, but not sure if it's correct
|
||||||
|
allowedList = [
|
||||||
|
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
||||||
|
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("chrome", allowedList);
|
||||||
|
|
||||||
|
async function isAllowedChromeExecutable(executablePath) {
|
||||||
|
console.log(config.args);
|
||||||
|
if (config.args["allow-all-chrome-exec"] || process.env.UPTIME_KUMA_ALLOW_ALL_CHROME_EXEC === "1") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the executablePath is in the list of allowed executables
|
||||||
|
return allowedList.includes(executablePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getBrowser() {
|
||||||
|
if (!browser) {
|
||||||
|
let executablePath = await Settings.get("chromeExecutable");
|
||||||
|
|
||||||
|
executablePath = await prepareChromeExecutable(executablePath);
|
||||||
|
|
||||||
|
browser = await chromium.launch({
|
||||||
|
//headless: false,
|
||||||
|
executablePath,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return browser;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function prepareChromeExecutable(executablePath) {
|
||||||
|
// Special code for using the playwright_chromium
|
||||||
|
if (typeof executablePath === "string" && executablePath.toLocaleLowerCase() === "#playwright_chromium") {
|
||||||
|
// Set to undefined = use playwright_chromium
|
||||||
|
executablePath = undefined;
|
||||||
|
} else if (!executablePath) {
|
||||||
|
if (process.env.UPTIME_KUMA_IS_CONTAINER) {
|
||||||
|
executablePath = "/usr/bin/chromium";
|
||||||
|
|
||||||
|
// Install chromium in container via apt install
|
||||||
|
if ( !commandExistsSync(executablePath)) {
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
log.info("Chromium", "Installing Chromium...");
|
||||||
|
let child = childProcess.exec("apt update && apt --yes --no-install-recommends install chromium fonts-indic fonts-noto fonts-noto-cjk");
|
||||||
|
|
||||||
|
// On exit
|
||||||
|
child.on("exit", (code) => {
|
||||||
|
log.info("Chromium", "apt install chromium exited with code " + code);
|
||||||
|
|
||||||
|
if (code === 0) {
|
||||||
|
log.info("Chromium", "Installed Chromium");
|
||||||
|
let version = childProcess.execSync(executablePath + " --version").toString("utf8");
|
||||||
|
log.info("Chromium", "Chromium version: " + version);
|
||||||
|
resolve();
|
||||||
|
} else if (code === 100) {
|
||||||
|
reject(new Error("Installing Chromium, please wait..."));
|
||||||
|
} else {
|
||||||
|
reject(new Error("apt install chromium failed with code " + code));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
executablePath = findChrome(allowedList);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// User specified a path
|
||||||
|
// Check if the executablePath is in the list of allowed
|
||||||
|
if (!await isAllowedChromeExecutable(executablePath)) {
|
||||||
|
throw new Error("This Chromium executable path is not allowed by default. If you are sure this is safe, please add an environment variable UPTIME_KUMA_ALLOW_ALL_CHROME_EXEC=1 to allow it.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return executablePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
function findChrome(executables) {
|
||||||
|
// Use the last working executable, so we don't have to search for it again
|
||||||
|
if (lastAutoDetectChromeExecutable) {
|
||||||
|
if (commandExistsSync(lastAutoDetectChromeExecutable)) {
|
||||||
|
return lastAutoDetectChromeExecutable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let executable of executables) {
|
||||||
|
if (commandExistsSync(executable)) {
|
||||||
|
lastAutoDetectChromeExecutable = executable;
|
||||||
|
return executable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error("Chromium not found, please specify Chromium executable path in the settings page.");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function resetChrome() {
|
||||||
|
if (browser) {
|
||||||
|
await browser.close();
|
||||||
|
browser = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if the chrome executable is valid and return the version
|
||||||
|
* @param executablePath
|
||||||
|
* @returns {Promise<string>}
|
||||||
|
*/
|
||||||
|
async function testChrome(executablePath) {
|
||||||
|
try {
|
||||||
|
executablePath = await prepareChromeExecutable(executablePath);
|
||||||
|
|
||||||
|
log.info("Chromium", "Testing Chromium executable: " + executablePath);
|
||||||
|
|
||||||
|
const browser = await chromium.launch({
|
||||||
|
executablePath,
|
||||||
|
});
|
||||||
|
const version = browser.version();
|
||||||
|
await browser.close();
|
||||||
|
return version;
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: connect remote browser? https://playwright.dev/docs/api/class-browsertype#browser-type-connect
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class RealBrowserMonitorType extends MonitorType {
|
||||||
|
|
||||||
|
name = "real-browser";
|
||||||
|
|
||||||
|
async check(monitor, heartbeat, server) {
|
||||||
|
const browser = await getBrowser();
|
||||||
|
const context = await browser.newContext();
|
||||||
|
const page = await context.newPage();
|
||||||
|
|
||||||
|
const res = await page.goto(monitor.url, {
|
||||||
|
waitUntil: "networkidle",
|
||||||
|
timeout: monitor.interval * 1000 * 0.8,
|
||||||
|
});
|
||||||
|
|
||||||
|
let filename = jwt.sign(monitor.id, server.jwtSecret) + ".png";
|
||||||
|
|
||||||
|
await page.screenshot({
|
||||||
|
path: path.join(Database.screenshotDir, filename),
|
||||||
|
});
|
||||||
|
|
||||||
|
await context.close();
|
||||||
|
|
||||||
|
if (res.status() >= 200 && res.status() < 400) {
|
||||||
|
heartbeat.status = UP;
|
||||||
|
heartbeat.msg = res.status();
|
||||||
|
|
||||||
|
const timing = res.request().timing();
|
||||||
|
heartbeat.ping = timing.responseEnd;
|
||||||
|
} else {
|
||||||
|
throw new Error(res.status() + "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
RealBrowserMonitorType,
|
||||||
|
testChrome,
|
||||||
|
resetChrome,
|
||||||
|
};
|
@@ -15,7 +15,7 @@ class DingDing extends NotificationProvider {
|
|||||||
msgtype: "markdown",
|
msgtype: "markdown",
|
||||||
markdown: {
|
markdown: {
|
||||||
title: `[${this.statusToString(heartbeatJSON["status"])}] ${monitorJSON["name"]}`,
|
title: `[${this.statusToString(heartbeatJSON["status"])}] ${monitorJSON["name"]}`,
|
||||||
text: `## [${this.statusToString(heartbeatJSON["status"])}] ${monitorJSON["name"]} \n > ${heartbeatJSON["msg"]} \n > Time(UTC):${heartbeatJSON["time"]}`,
|
text: `## [${this.statusToString(heartbeatJSON["status"])}] ${monitorJSON["name"]} \n> ${heartbeatJSON["msg"]}\n> Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (this.sendToDingDing(notification, params)) {
|
if (this.sendToDingDing(notification, params)) {
|
||||||
|
@@ -59,8 +59,8 @@ class Discord extends NotificationProvider {
|
|||||||
value: monitorJSON["type"] === "push" ? "Heartbeat" : address,
|
value: monitorJSON["type"] === "push" ? "Heartbeat" : address,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Time (UTC)",
|
name: `Time (${heartbeatJSON["timezone"]})`,
|
||||||
value: heartbeatJSON["time"],
|
value: heartbeatJSON["localDateTime"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Error",
|
name: "Error",
|
||||||
@@ -94,8 +94,8 @@ class Discord extends NotificationProvider {
|
|||||||
value: monitorJSON["type"] === "push" ? "Heartbeat" : address,
|
value: monitorJSON["type"] === "push" ? "Heartbeat" : address,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Time (UTC)",
|
name: `Time (${heartbeatJSON["timezone"]})`,
|
||||||
value: heartbeatJSON["time"],
|
value: heartbeatJSON["localDateTime"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Ping",
|
name: "Ping",
|
||||||
|
@@ -35,8 +35,7 @@ class Feishu extends NotificationProvider {
|
|||||||
text:
|
text:
|
||||||
"[Down] " +
|
"[Down] " +
|
||||||
heartbeatJSON["msg"] +
|
heartbeatJSON["msg"] +
|
||||||
"\nTime (UTC): " +
|
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`
|
||||||
heartbeatJSON["time"],
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
@@ -62,8 +61,7 @@ class Feishu extends NotificationProvider {
|
|||||||
text:
|
text:
|
||||||
"[Up] " +
|
"[Up] " +
|
||||||
heartbeatJSON["msg"] +
|
heartbeatJSON["msg"] +
|
||||||
"\nTime (UTC): " +
|
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`,
|
||||||
heartbeatJSON["time"],
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
@@ -11,7 +11,7 @@ class HomeAssistant extends NotificationProvider {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await axios.post(
|
await axios.post(
|
||||||
`${notification.homeAssistantUrl}/api/services/notify/${notificationService}`,
|
`${notification.homeAssistantUrl.trim().replace(/\/*$/, "")}/api/services/notify/${notificationService}`,
|
||||||
{
|
{
|
||||||
title: "Uptime Kuma",
|
title: "Uptime Kuma",
|
||||||
message,
|
message,
|
||||||
|
@@ -33,7 +33,10 @@ class Line extends NotificationProvider {
|
|||||||
"messages": [
|
"messages": [
|
||||||
{
|
{
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"text": "UptimeKuma Alert: [🔴 Down]\n" + "Name: " + monitorJSON["name"] + " \n" + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"]
|
"text": "UptimeKuma Alert: [🔴 Down]\n" +
|
||||||
|
"Name: " + monitorJSON["name"] + " \n" +
|
||||||
|
heartbeatJSON["msg"] +
|
||||||
|
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
@@ -44,7 +47,10 @@ class Line extends NotificationProvider {
|
|||||||
"messages": [
|
"messages": [
|
||||||
{
|
{
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"text": "UptimeKuma Alert: [✅ Up]\n" + "Name: " + monitorJSON["name"] + " \n" + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"]
|
"text": "UptimeKuma Alert: [✅ Up]\n" +
|
||||||
|
"Name: " + monitorJSON["name"] + " \n" +
|
||||||
|
heartbeatJSON["msg"] +
|
||||||
|
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
@@ -24,12 +24,18 @@ class LineNotify extends NotificationProvider {
|
|||||||
await axios.post(lineAPIUrl, qs.stringify(testMessage), config);
|
await axios.post(lineAPIUrl, qs.stringify(testMessage), config);
|
||||||
} else if (heartbeatJSON["status"] === DOWN) {
|
} else if (heartbeatJSON["status"] === DOWN) {
|
||||||
let downMessage = {
|
let downMessage = {
|
||||||
"message": "\n[🔴 Down]\n" + "Name: " + monitorJSON["name"] + " \n" + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"]
|
"message": "\n[🔴 Down]\n" +
|
||||||
|
"Name: " + monitorJSON["name"] + " \n" +
|
||||||
|
heartbeatJSON["msg"] + "\n" +
|
||||||
|
`Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`
|
||||||
};
|
};
|
||||||
await axios.post(lineAPIUrl, qs.stringify(downMessage), config);
|
await axios.post(lineAPIUrl, qs.stringify(downMessage), config);
|
||||||
} else if (heartbeatJSON["status"] === UP) {
|
} else if (heartbeatJSON["status"] === UP) {
|
||||||
let upMessage = {
|
let upMessage = {
|
||||||
"message": "\n[✅ Up]\n" + "Name: " + monitorJSON["name"] + " \n" + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"]
|
"message": "\n[✅ Up]\n" +
|
||||||
|
"Name: " + monitorJSON["name"] + " \n" +
|
||||||
|
heartbeatJSON["msg"] + "\n" +
|
||||||
|
`Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`
|
||||||
};
|
};
|
||||||
await axios.post(lineAPIUrl, qs.stringify(upMessage), config);
|
await axios.post(lineAPIUrl, qs.stringify(upMessage), config);
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,9 @@ class LunaSea extends NotificationProvider {
|
|||||||
if (heartbeatJSON["status"] === DOWN) {
|
if (heartbeatJSON["status"] === DOWN) {
|
||||||
let downdata = {
|
let downdata = {
|
||||||
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
||||||
"body": "[🔴 Down] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
|
"body": "[🔴 Down] " +
|
||||||
|
heartbeatJSON["msg"] +
|
||||||
|
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`
|
||||||
};
|
};
|
||||||
await axios.post(lunaseaurl, downdata);
|
await axios.post(lunaseaurl, downdata);
|
||||||
return okMsg;
|
return okMsg;
|
||||||
@@ -37,7 +39,9 @@ class LunaSea extends NotificationProvider {
|
|||||||
if (heartbeatJSON["status"] === UP) {
|
if (heartbeatJSON["status"] === UP) {
|
||||||
let updata = {
|
let updata = {
|
||||||
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
||||||
"body": "[✅ Up] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
|
"body": "[✅ Up] " +
|
||||||
|
heartbeatJSON["msg"] +
|
||||||
|
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`
|
||||||
};
|
};
|
||||||
await axios.post(lunaseaurl, updata);
|
await axios.post(lunaseaurl, updata);
|
||||||
return okMsg;
|
return okMsg;
|
||||||
|
@@ -10,7 +10,7 @@ class Mattermost extends NotificationProvider {
|
|||||||
let okMsg = "Sent Successfully.";
|
let okMsg = "Sent Successfully.";
|
||||||
try {
|
try {
|
||||||
const mattermostUserName = notification.mattermostusername || "Uptime Kuma";
|
const mattermostUserName = notification.mattermostusername || "Uptime Kuma";
|
||||||
// If heartbeatJSON is null, assume we're testing.
|
// If heartbeatJSON is null, assume non monitoring notification (Certificate warning) or testing.
|
||||||
if (heartbeatJSON == null) {
|
if (heartbeatJSON == null) {
|
||||||
let mattermostTestData = {
|
let mattermostTestData = {
|
||||||
username: mattermostUserName,
|
username: mattermostUserName,
|
||||||
@@ -27,86 +27,69 @@ class Mattermost extends NotificationProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const mattermostIconEmoji = notification.mattermosticonemo;
|
const mattermostIconEmoji = notification.mattermosticonemo;
|
||||||
const mattermostIconUrl = notification.mattermosticonurl;
|
let mattermostIconEmojiOnline = "";
|
||||||
|
let mattermostIconEmojiOffline = "";
|
||||||
|
|
||||||
if (heartbeatJSON["status"] === DOWN) {
|
if (mattermostIconEmoji && typeof mattermostIconEmoji === "string") {
|
||||||
let mattermostdowndata = {
|
const emojiArray = mattermostIconEmoji.split(" ");
|
||||||
username: mattermostUserName,
|
if (emojiArray.length >= 2) {
|
||||||
text: "Uptime Kuma Alert",
|
mattermostIconEmojiOnline = emojiArray[0];
|
||||||
channel: mattermostChannel,
|
mattermostIconEmojiOffline = emojiArray[1];
|
||||||
icon_emoji: mattermostIconEmoji,
|
}
|
||||||
icon_url: mattermostIconUrl,
|
}
|
||||||
attachments: [
|
const mattermostIconUrl = notification.mattermosticonurl;
|
||||||
{
|
let iconEmoji = mattermostIconEmoji;
|
||||||
fallback:
|
let statusField = {
|
||||||
"Your " +
|
|
||||||
monitorJSON["name"] +
|
|
||||||
" service went down.",
|
|
||||||
color: "#FF0000",
|
|
||||||
title:
|
|
||||||
"❌ " +
|
|
||||||
monitorJSON["name"] +
|
|
||||||
" service went down. ❌",
|
|
||||||
title_link: monitorJSON["url"],
|
|
||||||
fields: [
|
|
||||||
{
|
|
||||||
short: true,
|
|
||||||
title: "Service Name",
|
|
||||||
value: monitorJSON["name"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
short: true,
|
|
||||||
title: "Time (UTC)",
|
|
||||||
value: heartbeatJSON["time"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
short: false,
|
short: false,
|
||||||
title: "Error",
|
title: "Error",
|
||||||
value: heartbeatJSON["msg"],
|
value: heartbeatJSON.msg,
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
await axios.post(
|
let statusText = "unknown";
|
||||||
notification.mattermostWebhookUrl,
|
let color = "#000000";
|
||||||
mattermostdowndata
|
if (heartbeatJSON.status === DOWN) {
|
||||||
);
|
iconEmoji = mattermostIconEmojiOffline || mattermostIconEmoji;
|
||||||
return okMsg;
|
statusField = {
|
||||||
} else if (heartbeatJSON["status"] === UP) {
|
short: false,
|
||||||
let mattermostupdata = {
|
title: "Error",
|
||||||
username: mattermostUserName,
|
value: heartbeatJSON.msg,
|
||||||
text: "Uptime Kuma Alert",
|
};
|
||||||
|
statusText = "down.";
|
||||||
|
color = "#FF0000";
|
||||||
|
} else if (heartbeatJSON.status === UP) {
|
||||||
|
iconEmoji = mattermostIconEmojiOnline || mattermostIconEmoji;
|
||||||
|
statusField = {
|
||||||
|
short: false,
|
||||||
|
title: "Ping",
|
||||||
|
value: heartbeatJSON.ping + "ms",
|
||||||
|
};
|
||||||
|
statusText = "up!";
|
||||||
|
color = "#32CD32";
|
||||||
|
}
|
||||||
|
|
||||||
|
let mattermostdata = {
|
||||||
|
username: monitorJSON.name + " " + mattermostUserName,
|
||||||
channel: mattermostChannel,
|
channel: mattermostChannel,
|
||||||
icon_emoji: mattermostIconEmoji,
|
icon_emoji: iconEmoji,
|
||||||
icon_url: mattermostIconUrl,
|
icon_url: mattermostIconUrl,
|
||||||
attachments: [
|
attachments: [
|
||||||
{
|
{
|
||||||
fallback:
|
fallback:
|
||||||
"Your " +
|
"Your " +
|
||||||
monitorJSON["name"] +
|
monitorJSON.name +
|
||||||
" service went up!",
|
" service went " +
|
||||||
color: "#32CD32",
|
statusText,
|
||||||
|
color: color,
|
||||||
title:
|
title:
|
||||||
"✅ " +
|
monitorJSON.name +
|
||||||
monitorJSON["name"] +
|
" service went " +
|
||||||
" service went up! ✅",
|
statusText,
|
||||||
title_link: monitorJSON["url"],
|
title_link: monitorJSON.url,
|
||||||
fields: [
|
fields: [
|
||||||
|
statusField,
|
||||||
{
|
{
|
||||||
short: true,
|
short: true,
|
||||||
title: "Service Name",
|
title: `Time (${heartbeatJSON["timezone"]})`,
|
||||||
value: monitorJSON["name"],
|
value: heartbeatJSON.localDateTime,
|
||||||
},
|
|
||||||
{
|
|
||||||
short: true,
|
|
||||||
title: "Time (UTC)",
|
|
||||||
value: heartbeatJSON["time"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
short: false,
|
|
||||||
title: "Ping",
|
|
||||||
value: heartbeatJSON["ping"] + "ms",
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -114,10 +97,9 @@ class Mattermost extends NotificationProvider {
|
|||||||
};
|
};
|
||||||
await axios.post(
|
await axios.post(
|
||||||
notification.mattermostWebhookUrl,
|
notification.mattermostWebhookUrl,
|
||||||
mattermostupdata
|
mattermostdata
|
||||||
);
|
);
|
||||||
return okMsg;
|
return okMsg;
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.throwGeneralAxiosError(error);
|
this.throwGeneralAxiosError(error);
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
const NotificationProvider = require("./notification-provider");
|
const NotificationProvider = require("./notification-provider");
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
|
const { DOWN, UP } = require("../../src/util");
|
||||||
|
|
||||||
class Ntfy extends NotificationProvider {
|
class Ntfy extends NotificationProvider {
|
||||||
|
|
||||||
@@ -9,16 +10,54 @@ class Ntfy extends NotificationProvider {
|
|||||||
let okMsg = "Sent Successfully.";
|
let okMsg = "Sent Successfully.";
|
||||||
try {
|
try {
|
||||||
let headers = {};
|
let headers = {};
|
||||||
if (notification.ntfyusername) {
|
if (notification.ntfyAuthenticationMethod === "usernamePassword") {
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": "Basic " + Buffer.from(notification.ntfyusername + ":" + notification.ntfypassword).toString("base64"),
|
"Authorization": "Basic " + Buffer.from(notification.ntfyusername + ":" + notification.ntfypassword).toString("base64"),
|
||||||
};
|
};
|
||||||
|
} else if (notification.ntfyAuthenticationMethod === "accessToken") {
|
||||||
|
headers = {
|
||||||
|
"Authorization": "Bearer " + notification.ntfyaccesstoken,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// If heartbeatJSON is null, assume non monitoring notification (Certificate warning) or testing.
|
||||||
|
if (heartbeatJSON == null) {
|
||||||
|
let ntfyTestData = {
|
||||||
|
"topic": notification.ntfytopic,
|
||||||
|
"title": (monitorJSON?.name || notification.ntfytopic) + " [Uptime-Kuma]",
|
||||||
|
"message": msg,
|
||||||
|
"priority": notification.ntfyPriority,
|
||||||
|
"tags": [ "test_tube" ],
|
||||||
|
};
|
||||||
|
await axios.post(`${notification.ntfyserverurl}`, ntfyTestData, { headers: headers });
|
||||||
|
return okMsg;
|
||||||
|
}
|
||||||
|
let tags = [];
|
||||||
|
let status = "unknown";
|
||||||
|
let priority = notification.ntfyPriority || 4;
|
||||||
|
if ("status" in heartbeatJSON) {
|
||||||
|
if (heartbeatJSON.status === DOWN) {
|
||||||
|
tags = [ "red_circle" ];
|
||||||
|
status = "Down";
|
||||||
|
// if priority is not 5, increase priority for down alerts
|
||||||
|
priority = priority === 5 ? priority : priority + 1;
|
||||||
|
} else if (heartbeatJSON["status"] === UP) {
|
||||||
|
tags = [ "green_circle" ];
|
||||||
|
status = "Up";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let data = {
|
let data = {
|
||||||
"topic": notification.ntfytopic,
|
"topic": notification.ntfytopic,
|
||||||
"message": msg,
|
"message": heartbeatJSON.msg,
|
||||||
"priority": notification.ntfyPriority || 4,
|
"priority": priority,
|
||||||
"title": "Uptime-Kuma",
|
"title": monitorJSON.name + " " + status + " [Uptime-Kuma]",
|
||||||
|
"tags": tags,
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"action": "view",
|
||||||
|
"label": "Open " + monitorJSON.name,
|
||||||
|
"url": monitorJSON.url,
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
if (notification.ntfyIcon) {
|
if (notification.ntfyIcon) {
|
||||||
|
97
server/notification-providers/opsgenie.js
Normal file
97
server/notification-providers/opsgenie.js
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
const NotificationProvider = require("./notification-provider");
|
||||||
|
const axios = require("axios");
|
||||||
|
const { UP, DOWN } = require("../../src/util");
|
||||||
|
|
||||||
|
const opsgenieAlertsUrlEU = "https://api.eu.opsgenie.com/v2/alerts";
|
||||||
|
const opsgenieAlertsUrlUS = "https://api.opsgenie.com/v2/alerts";
|
||||||
|
let okMsg = "Sent Successfully.";
|
||||||
|
|
||||||
|
class Opsgenie extends NotificationProvider {
|
||||||
|
|
||||||
|
name = "Opsgenie";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
|
let opsgenieAlertsUrl;
|
||||||
|
let priority = (!notification.opsgeniePriority) ? 3 : notification.opsgeniePriority;
|
||||||
|
const textMsg = "Uptime Kuma Alert";
|
||||||
|
|
||||||
|
try {
|
||||||
|
switch (notification.opsgenieRegion) {
|
||||||
|
case "US":
|
||||||
|
opsgenieAlertsUrl = opsgenieAlertsUrlUS;
|
||||||
|
break;
|
||||||
|
case "EU":
|
||||||
|
opsgenieAlertsUrl = opsgenieAlertsUrlEU;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
opsgenieAlertsUrl = opsgenieAlertsUrlUS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (heartbeatJSON == null) {
|
||||||
|
let notificationTestAlias = "uptime-kuma-notification-test";
|
||||||
|
let data = {
|
||||||
|
"message": msg,
|
||||||
|
"alias": notificationTestAlias,
|
||||||
|
"source": "Uptime Kuma",
|
||||||
|
"priority": "P5"
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.post(notification, opsgenieAlertsUrl, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (heartbeatJSON.status === DOWN) {
|
||||||
|
let data = {
|
||||||
|
"message": monitorJSON ? textMsg + `: ${monitorJSON.name}` : textMsg,
|
||||||
|
"alias": monitorJSON.name,
|
||||||
|
"description": msg,
|
||||||
|
"source": "Uptime Kuma",
|
||||||
|
"priority": `P${priority}`
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.post(notification, opsgenieAlertsUrl, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (heartbeatJSON.status === UP) {
|
||||||
|
let opsgenieAlertsCloseUrl = `${opsgenieAlertsUrl}/${encodeURIComponent(monitorJSON.name)}/close?identifierType=alias`;
|
||||||
|
let data = {
|
||||||
|
"source": "Uptime Kuma",
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.post(notification, opsgenieAlertsCloseUrl, data);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {BeanModel} notification
|
||||||
|
* @param {string} url Request url
|
||||||
|
* @param {Object} data Request body
|
||||||
|
* @returns {Promise<string>}
|
||||||
|
*/
|
||||||
|
async post(notification, url, data) {
|
||||||
|
let config = {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": `GenieKey ${notification.opsgenieApiKey}`,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let res = await axios.post(url, data, config);
|
||||||
|
if (res.status == null) {
|
||||||
|
return "Opsgenie notification failed with invalid response!";
|
||||||
|
}
|
||||||
|
if (res.status < 200 || res.status >= 300) {
|
||||||
|
return `Opsgenie notification failed with status code ${res.status}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return okMsg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Opsgenie;
|
@@ -29,14 +29,18 @@ class Pushbullet extends NotificationProvider {
|
|||||||
let downData = {
|
let downData = {
|
||||||
"type": "note",
|
"type": "note",
|
||||||
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
||||||
"body": "[🔴 Down] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
|
"body": "[🔴 Down] " +
|
||||||
|
heartbeatJSON["msg"] +
|
||||||
|
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`,
|
||||||
};
|
};
|
||||||
await axios.post(pushbulletUrl, downData, config);
|
await axios.post(pushbulletUrl, downData, config);
|
||||||
} else if (heartbeatJSON["status"] === UP) {
|
} else if (heartbeatJSON["status"] === UP) {
|
||||||
let upData = {
|
let upData = {
|
||||||
"type": "note",
|
"type": "note",
|
||||||
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
||||||
"body": "[✅ Up] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
|
"body": "[✅ Up] " +
|
||||||
|
heartbeatJSON["msg"] +
|
||||||
|
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`,
|
||||||
};
|
};
|
||||||
await axios.post(pushbulletUrl, upData, config);
|
await axios.post(pushbulletUrl, upData, config);
|
||||||
}
|
}
|
||||||
|
@@ -24,13 +24,16 @@ class Pushover extends NotificationProvider {
|
|||||||
if (notification.pushoverdevice) {
|
if (notification.pushoverdevice) {
|
||||||
data.device = notification.pushoverdevice;
|
data.device = notification.pushoverdevice;
|
||||||
}
|
}
|
||||||
|
if (notification.pushoverttl) {
|
||||||
|
data.ttl = notification.pushoverttl;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (heartbeatJSON == null) {
|
if (heartbeatJSON == null) {
|
||||||
await axios.post(pushoverlink, data);
|
await axios.post(pushoverlink, data);
|
||||||
return okMsg;
|
return okMsg;
|
||||||
} else {
|
} else {
|
||||||
data.message += "\n<b>Time (UTC)</b>:" + heartbeatJSON["time"];
|
data.message += `\n<b>Time (${heartbeatJSON["timezone"]})</b>:${heartbeatJSON["localDateTime"]}`;
|
||||||
await axios.post(pushoverlink, data);
|
await axios.post(pushoverlink, data);
|
||||||
return okMsg;
|
return okMsg;
|
||||||
}
|
}
|
||||||
|
@@ -22,8 +22,6 @@ class RocketChat extends NotificationProvider {
|
|||||||
return okMsg;
|
return okMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
const time = heartbeatJSON["time"];
|
|
||||||
|
|
||||||
let data = {
|
let data = {
|
||||||
"text": "Uptime Kuma Alert",
|
"text": "Uptime Kuma Alert",
|
||||||
"channel": notification.rocketchannel,
|
"channel": notification.rocketchannel,
|
||||||
@@ -31,7 +29,7 @@ class RocketChat extends NotificationProvider {
|
|||||||
"icon_emoji": notification.rocketiconemo,
|
"icon_emoji": notification.rocketiconemo,
|
||||||
"attachments": [
|
"attachments": [
|
||||||
{
|
{
|
||||||
"title": "Uptime Kuma Alert *Time (UTC)*\n" + time,
|
"title": `Uptime Kuma Alert *Time (${heartbeatJSON["timezone"]})*\n${heartbeatJSON["localDateTime"]}`,
|
||||||
"text": "*Message*\n" + msg,
|
"text": "*Message*\n" + msg,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@@ -27,6 +27,11 @@ class Slack extends NotificationProvider {
|
|||||||
|
|
||||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
let okMsg = "Sent Successfully.";
|
let okMsg = "Sent Successfully.";
|
||||||
|
|
||||||
|
if (notification.slackchannelnotify) {
|
||||||
|
msg += " <!channel>";
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (heartbeatJSON == null) {
|
if (heartbeatJSON == null) {
|
||||||
let data = {
|
let data = {
|
||||||
@@ -39,7 +44,6 @@ class Slack extends NotificationProvider {
|
|||||||
return okMsg;
|
return okMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
const time = heartbeatJSON["time"];
|
|
||||||
const textMsg = "Uptime Kuma Alert";
|
const textMsg = "Uptime Kuma Alert";
|
||||||
let data = {
|
let data = {
|
||||||
"text": `${textMsg}\n${msg}`,
|
"text": `${textMsg}\n${msg}`,
|
||||||
@@ -54,7 +58,7 @@ class Slack extends NotificationProvider {
|
|||||||
"type": "header",
|
"type": "header",
|
||||||
"text": {
|
"text": {
|
||||||
"type": "plain_text",
|
"type": "plain_text",
|
||||||
"text": "Uptime Kuma Alert",
|
"text": textMsg,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -65,7 +69,7 @@ class Slack extends NotificationProvider {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "mrkdwn",
|
"type": "mrkdwn",
|
||||||
"text": "*Time (UTC)*\n" + time,
|
"text": `*Time (${heartbeatJSON["timezone"]})*\n${heartbeatJSON["localDateTime"]}`,
|
||||||
}],
|
}],
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
42
server/notification-providers/smsc.js
Normal file
42
server/notification-providers/smsc.js
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
const NotificationProvider = require("./notification-provider");
|
||||||
|
const axios = require("axios");
|
||||||
|
|
||||||
|
class SMSC extends NotificationProvider {
|
||||||
|
name = "smsc";
|
||||||
|
|
||||||
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
|
let okMsg = "Sent Successfully.";
|
||||||
|
try {
|
||||||
|
let config = {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "text/json",
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let getArray = [
|
||||||
|
"fmt=3",
|
||||||
|
"translit=" + notification.smscTranslit,
|
||||||
|
"login=" + notification.smscLogin,
|
||||||
|
"psw=" + notification.smscPassword,
|
||||||
|
"phones=" + notification.smscToNumber,
|
||||||
|
"mes=" + encodeURIComponent(msg.replace(/[^\x00-\x7F]/g, "")),
|
||||||
|
];
|
||||||
|
if (notification.smscSenderName !== "") {
|
||||||
|
getArray.push("sender=" + notification.smscSenderName);
|
||||||
|
}
|
||||||
|
|
||||||
|
let resp = await axios.get("https://smsc.kz/sys/send.php?" + getArray.join("&"), config);
|
||||||
|
if (resp.data.id === undefined) {
|
||||||
|
let error = `Something gone wrong. Api returned code ${resp.data.error_code}: ${resp.data.error}`;
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return okMsg;
|
||||||
|
} catch (error) {
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = SMSC;
|
@@ -67,7 +67,7 @@ class SMTP extends NotificationProvider {
|
|||||||
if (monitorJSON !== null) {
|
if (monitorJSON !== null) {
|
||||||
monitorName = monitorJSON["name"];
|
monitorName = monitorJSON["name"];
|
||||||
|
|
||||||
if (monitorJSON["type"] === "http" || monitorJSON["type"] === "keyword") {
|
if (monitorJSON["type"] === "http" || monitorJSON["type"] === "keyword" || monitorJSON["type"] === "json-query") {
|
||||||
monitorHostnameOrURL = monitorJSON["url"];
|
monitorHostnameOrURL = monitorJSON["url"];
|
||||||
} else {
|
} else {
|
||||||
monitorHostnameOrURL = monitorJSON["hostname"];
|
monitorHostnameOrURL = monitorJSON["hostname"];
|
||||||
@@ -91,7 +91,7 @@ class SMTP extends NotificationProvider {
|
|||||||
|
|
||||||
let bodyTextContent = msg;
|
let bodyTextContent = msg;
|
||||||
if (heartbeatJSON) {
|
if (heartbeatJSON) {
|
||||||
bodyTextContent = `${msg}\nTime (UTC): ${heartbeatJSON["time"]}`;
|
bodyTextContent = `${msg}\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// send mail with defined transport object
|
// send mail with defined transport object
|
||||||
|
@@ -25,8 +25,11 @@ class Telegram extends NotificationProvider {
|
|||||||
return okMsg;
|
return okMsg;
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
let msg = (error.response.data.description) ? error.response.data.description : "Error without description";
|
if (error.response && error.response.data && error.response.data.description) {
|
||||||
throw new Error(msg);
|
throw new Error(error.response.data.description);
|
||||||
|
} else {
|
||||||
|
throw new Error(error.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
42
server/notification-providers/twilio.js
Normal file
42
server/notification-providers/twilio.js
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
const NotificationProvider = require("./notification-provider");
|
||||||
|
const axios = require("axios");
|
||||||
|
|
||||||
|
class Twilio extends NotificationProvider {
|
||||||
|
|
||||||
|
name = "twilio";
|
||||||
|
|
||||||
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
|
|
||||||
|
let okMsg = "Sent Successfully.";
|
||||||
|
|
||||||
|
let accountSID = notification.twilioAccountSID;
|
||||||
|
let apiKey = notification.twilioApiKey ? notification.twilioApiKey : accountSID;
|
||||||
|
let authToken = notification.twilioAuthToken;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
let config = {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
|
||||||
|
"Authorization": "Basic " + Buffer.from(apiKey + ":" + authToken).toString("base64"),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let data = new URLSearchParams();
|
||||||
|
data.append("To", notification.twilioToNumber);
|
||||||
|
data.append("From", notification.twilioFromNumber);
|
||||||
|
data.append("Body", msg);
|
||||||
|
|
||||||
|
let url = "https://api.twilio.com/2010-04-01/Accounts/" + accountSID + "/Messages.json";
|
||||||
|
|
||||||
|
await axios.post(url, data, config);
|
||||||
|
|
||||||
|
return okMsg;
|
||||||
|
} catch (error) {
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Twilio;
|
@@ -1,6 +1,7 @@
|
|||||||
const NotificationProvider = require("./notification-provider");
|
const NotificationProvider = require("./notification-provider");
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const FormData = require("form-data");
|
const FormData = require("form-data");
|
||||||
|
const { Liquid } = require("liquidjs");
|
||||||
|
|
||||||
class Webhook extends NotificationProvider {
|
class Webhook extends NotificationProvider {
|
||||||
|
|
||||||
@@ -15,17 +16,27 @@ class Webhook extends NotificationProvider {
|
|||||||
monitor: monitorJSON,
|
monitor: monitorJSON,
|
||||||
msg,
|
msg,
|
||||||
};
|
};
|
||||||
let finalData;
|
|
||||||
let config = {
|
let config = {
|
||||||
headers: {}
|
headers: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (notification.webhookContentType === "form-data") {
|
if (notification.webhookContentType === "form-data") {
|
||||||
finalData = new FormData();
|
const formData = new FormData();
|
||||||
finalData.append("data", JSON.stringify(data));
|
formData.append("data", JSON.stringify(data));
|
||||||
config.headers = finalData.getHeaders();
|
config.headers = formData.getHeaders();
|
||||||
} else {
|
data = formData;
|
||||||
finalData = data;
|
} else if (notification.webhookContentType === "custom") {
|
||||||
|
// Initialize LiquidJS and parse the custom Body Template
|
||||||
|
const engine = new Liquid();
|
||||||
|
const tpl = engine.parse(notification.webhookCustomBody);
|
||||||
|
|
||||||
|
// Insert templated values into Body
|
||||||
|
data = await engine.render(tpl,
|
||||||
|
{
|
||||||
|
msg,
|
||||||
|
heartbeatJSON,
|
||||||
|
monitorJSON
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notification.webhookAdditionalHeaders) {
|
if (notification.webhookAdditionalHeaders) {
|
||||||
@@ -39,7 +50,7 @@ class Webhook extends NotificationProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await axios.post(notification.webhookURL, finalData, config);
|
await axios.post(notification.webhookURL, data, config);
|
||||||
return okMsg;
|
return okMsg;
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@@ -6,6 +6,7 @@ const AliyunSms = require("./notification-providers/aliyun-sms");
|
|||||||
const Apprise = require("./notification-providers/apprise");
|
const Apprise = require("./notification-providers/apprise");
|
||||||
const Bark = require("./notification-providers/bark");
|
const Bark = require("./notification-providers/bark");
|
||||||
const ClickSendSMS = require("./notification-providers/clicksendsms");
|
const ClickSendSMS = require("./notification-providers/clicksendsms");
|
||||||
|
const SMSC = require("./notification-providers/smsc");
|
||||||
const DingDing = require("./notification-providers/dingding");
|
const DingDing = require("./notification-providers/dingding");
|
||||||
const Discord = require("./notification-providers/discord");
|
const Discord = require("./notification-providers/discord");
|
||||||
const Feishu = require("./notification-providers/feishu");
|
const Feishu = require("./notification-providers/feishu");
|
||||||
@@ -23,6 +24,7 @@ const Mattermost = require("./notification-providers/mattermost");
|
|||||||
const Ntfy = require("./notification-providers/ntfy");
|
const Ntfy = require("./notification-providers/ntfy");
|
||||||
const Octopush = require("./notification-providers/octopush");
|
const Octopush = require("./notification-providers/octopush");
|
||||||
const OneBot = require("./notification-providers/onebot");
|
const OneBot = require("./notification-providers/onebot");
|
||||||
|
const Opsgenie = require("./notification-providers/opsgenie");
|
||||||
const PagerDuty = require("./notification-providers/pagerduty");
|
const PagerDuty = require("./notification-providers/pagerduty");
|
||||||
const PagerTree = require("./notification-providers/pagertree");
|
const PagerTree = require("./notification-providers/pagertree");
|
||||||
const PromoSMS = require("./notification-providers/promosms");
|
const PromoSMS = require("./notification-providers/promosms");
|
||||||
@@ -41,6 +43,7 @@ const Stackfield = require("./notification-providers/stackfield");
|
|||||||
const Teams = require("./notification-providers/teams");
|
const Teams = require("./notification-providers/teams");
|
||||||
const TechulusPush = require("./notification-providers/techulus-push");
|
const TechulusPush = require("./notification-providers/techulus-push");
|
||||||
const Telegram = require("./notification-providers/telegram");
|
const Telegram = require("./notification-providers/telegram");
|
||||||
|
const Twilio = require("./notification-providers/twilio");
|
||||||
const Splunk = require("./notification-providers/splunk");
|
const Splunk = require("./notification-providers/splunk");
|
||||||
const Webhook = require("./notification-providers/webhook");
|
const Webhook = require("./notification-providers/webhook");
|
||||||
const WeCom = require("./notification-providers/wecom");
|
const WeCom = require("./notification-providers/wecom");
|
||||||
@@ -66,6 +69,7 @@ class Notification {
|
|||||||
new Apprise(),
|
new Apprise(),
|
||||||
new Bark(),
|
new Bark(),
|
||||||
new ClickSendSMS(),
|
new ClickSendSMS(),
|
||||||
|
new SMSC(),
|
||||||
new DingDing(),
|
new DingDing(),
|
||||||
new Discord(),
|
new Discord(),
|
||||||
new Feishu(),
|
new Feishu(),
|
||||||
@@ -83,6 +87,7 @@ class Notification {
|
|||||||
new Ntfy(),
|
new Ntfy(),
|
||||||
new Octopush(),
|
new Octopush(),
|
||||||
new OneBot(),
|
new OneBot(),
|
||||||
|
new Opsgenie(),
|
||||||
new PagerDuty(),
|
new PagerDuty(),
|
||||||
new PagerTree(),
|
new PagerTree(),
|
||||||
new PromoSMS(),
|
new PromoSMS(),
|
||||||
@@ -103,6 +108,7 @@ class Notification {
|
|||||||
new Teams(),
|
new Teams(),
|
||||||
new TechulusPush(),
|
new TechulusPush(),
|
||||||
new Telegram(),
|
new Telegram(),
|
||||||
|
new Twilio(),
|
||||||
new Splunk(),
|
new Splunk(),
|
||||||
new Webhook(),
|
new Webhook(),
|
||||||
new WeCom(),
|
new WeCom(),
|
||||||
|
@@ -1,13 +0,0 @@
|
|||||||
class Plugin {
|
|
||||||
async load() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async unload() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
Plugin,
|
|
||||||
};
|
|
@@ -1,256 +0,0 @@
|
|||||||
const fs = require("fs");
|
|
||||||
const { log } = require("../src/util");
|
|
||||||
const path = require("path");
|
|
||||||
const axios = require("axios");
|
|
||||||
const { Git } = require("./git");
|
|
||||||
const childProcess = require("child_process");
|
|
||||||
|
|
||||||
class PluginsManager {
|
|
||||||
|
|
||||||
static disable = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Plugin List
|
|
||||||
* @type {PluginWrapper[]}
|
|
||||||
*/
|
|
||||||
pluginList = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Plugins Dir
|
|
||||||
*/
|
|
||||||
pluginsDir;
|
|
||||||
|
|
||||||
server;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {UptimeKumaServer} server
|
|
||||||
*/
|
|
||||||
constructor(server) {
|
|
||||||
this.server = server;
|
|
||||||
|
|
||||||
if (!PluginsManager.disable) {
|
|
||||||
this.pluginsDir = "./data/plugins/";
|
|
||||||
|
|
||||||
if (! fs.existsSync(this.pluginsDir)) {
|
|
||||||
fs.mkdirSync(this.pluginsDir, { recursive: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
log.debug("plugin", "Scanning plugin directory");
|
|
||||||
let list = fs.readdirSync(this.pluginsDir);
|
|
||||||
|
|
||||||
this.pluginList = [];
|
|
||||||
for (let item of list) {
|
|
||||||
this.loadPlugin(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
log.warn("PLUGIN", "Skip scanning plugin directory");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Install a Plugin
|
|
||||||
*/
|
|
||||||
async loadPlugin(name) {
|
|
||||||
log.info("plugin", "Load " + name);
|
|
||||||
let plugin = new PluginWrapper(this.server, this.pluginsDir + name);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await plugin.load();
|
|
||||||
this.pluginList.push(plugin);
|
|
||||||
} catch (e) {
|
|
||||||
log.error("plugin", "Failed to load plugin: " + this.pluginsDir + name);
|
|
||||||
log.error("plugin", "Reason: " + e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Download a Plugin
|
|
||||||
* @param {string} repoURL Git repo url
|
|
||||||
* @param {string} name Directory name, also known as plugin unique name
|
|
||||||
*/
|
|
||||||
downloadPlugin(repoURL, name) {
|
|
||||||
if (fs.existsSync(this.pluginsDir + name)) {
|
|
||||||
log.info("plugin", "Plugin folder already exists? Removing...");
|
|
||||||
fs.rmSync(this.pluginsDir + name, {
|
|
||||||
recursive: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
log.info("plugin", "Installing plugin: " + name + " " + repoURL);
|
|
||||||
let result = Git.clone(repoURL, this.pluginsDir, name);
|
|
||||||
log.info("plugin", "Install result: " + result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove a plugin
|
|
||||||
* @param {string} name
|
|
||||||
*/
|
|
||||||
async removePlugin(name) {
|
|
||||||
log.info("plugin", "Removing plugin: " + name);
|
|
||||||
for (let plugin of this.pluginList) {
|
|
||||||
if (plugin.info.name === name) {
|
|
||||||
await plugin.unload();
|
|
||||||
|
|
||||||
// Delete the plugin directory
|
|
||||||
fs.rmSync(this.pluginsDir + name, {
|
|
||||||
recursive: true
|
|
||||||
});
|
|
||||||
|
|
||||||
this.pluginList.splice(this.pluginList.indexOf(plugin), 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.warn("plugin", "Plugin not found: " + name);
|
|
||||||
throw new Error("Plugin not found: " + name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: Update a plugin
|
|
||||||
* Only available for plugins which were downloaded from the official list
|
|
||||||
* @param pluginID
|
|
||||||
*/
|
|
||||||
updatePlugin(pluginID) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the plugin list from server + local installed plugin list
|
|
||||||
* Item will be merged if the `name` is the same.
|
|
||||||
* @returns {Promise<[]>}
|
|
||||||
*/
|
|
||||||
async fetchPluginList() {
|
|
||||||
let remotePluginList;
|
|
||||||
try {
|
|
||||||
const res = await axios.get("https://uptime.kuma.pet/c/plugins.json");
|
|
||||||
remotePluginList = res.data.pluginList;
|
|
||||||
} catch (e) {
|
|
||||||
log.error("plugin", "Failed to fetch plugin list: " + e.message);
|
|
||||||
remotePluginList = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let plugin of this.pluginList) {
|
|
||||||
let find = false;
|
|
||||||
// Try to merge
|
|
||||||
for (let remotePlugin of remotePluginList) {
|
|
||||||
if (remotePlugin.name === plugin.info.name) {
|
|
||||||
find = true;
|
|
||||||
remotePlugin.installed = true;
|
|
||||||
remotePlugin.name = plugin.info.name;
|
|
||||||
remotePlugin.fullName = plugin.info.fullName;
|
|
||||||
remotePlugin.description = plugin.info.description;
|
|
||||||
remotePlugin.version = plugin.info.version;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Local plugin
|
|
||||||
if (!find) {
|
|
||||||
plugin.info.local = true;
|
|
||||||
remotePluginList.push(plugin.info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort Installed first, then sort by name
|
|
||||||
return remotePluginList.sort((a, b) => {
|
|
||||||
if (a.installed === b.installed) {
|
|
||||||
if (a.fullName < b.fullName) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (a.fullName > b.fullName) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
} else if (a.installed) {
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class PluginWrapper {
|
|
||||||
|
|
||||||
server = undefined;
|
|
||||||
pluginDir = undefined;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Must be an `new-able` class.
|
|
||||||
* @type {function}
|
|
||||||
*/
|
|
||||||
pluginClass = undefined;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @type {Plugin}
|
|
||||||
*/
|
|
||||||
object = undefined;
|
|
||||||
info = {};
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {UptimeKumaServer} server
|
|
||||||
* @param {string} pluginDir
|
|
||||||
*/
|
|
||||||
constructor(server, pluginDir) {
|
|
||||||
this.server = server;
|
|
||||||
this.pluginDir = pluginDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
async load() {
|
|
||||||
let indexFile = this.pluginDir + "/index.js";
|
|
||||||
let packageJSON = this.pluginDir + "/package.json";
|
|
||||||
|
|
||||||
log.info("plugin", "Installing dependencies");
|
|
||||||
|
|
||||||
if (fs.existsSync(indexFile)) {
|
|
||||||
// Install dependencies
|
|
||||||
let result = childProcess.spawnSync("npm", [ "install" ], {
|
|
||||||
cwd: this.pluginDir,
|
|
||||||
env: {
|
|
||||||
...process.env,
|
|
||||||
PLAYWRIGHT_BROWSERS_PATH: "../../browsers", // Special handling for read-browser-monitor
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (result.stdout) {
|
|
||||||
log.info("plugin", "Install dependencies result: " + result.stdout.toString("utf-8"));
|
|
||||||
} else {
|
|
||||||
log.warn("plugin", "Install dependencies result: no output");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.pluginClass = require(path.join(process.cwd(), indexFile));
|
|
||||||
|
|
||||||
let pluginClassType = typeof this.pluginClass;
|
|
||||||
|
|
||||||
if (pluginClassType === "function") {
|
|
||||||
this.object = new this.pluginClass(this.server);
|
|
||||||
await this.object.load();
|
|
||||||
} else {
|
|
||||||
throw new Error("Invalid plugin, it does not export a class");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fs.existsSync(packageJSON)) {
|
|
||||||
this.info = require(path.join(process.cwd(), packageJSON));
|
|
||||||
} else {
|
|
||||||
this.info.fullName = this.pluginDir;
|
|
||||||
this.info.name = "[unknown]";
|
|
||||||
this.info.version = "[unknown-version]";
|
|
||||||
}
|
|
||||||
|
|
||||||
this.info.installed = true;
|
|
||||||
log.info("plugin", `${this.info.fullName} v${this.info.version} loaded`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async unload() {
|
|
||||||
await this.object.unload();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
PluginsManager,
|
|
||||||
PluginWrapper
|
|
||||||
};
|
|
@@ -28,7 +28,7 @@ const monitorResponseTime = new PrometheusClient.Gauge({
|
|||||||
|
|
||||||
const monitorStatus = new PrometheusClient.Gauge({
|
const monitorStatus = new PrometheusClient.Gauge({
|
||||||
name: "monitor_status",
|
name: "monitor_status",
|
||||||
help: "Monitor Status (1 = UP, 0= DOWN)",
|
help: "Monitor Status (1 = UP, 0= DOWN, 2= PENDING, 3= MAINTENANCE)",
|
||||||
labelNames: commonLabels
|
labelNames: commonLabels
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -132,6 +132,9 @@ class Proxy {
|
|||||||
...httpAgentOptions,
|
...httpAgentOptions,
|
||||||
...httpsAgentOptions,
|
...httpsAgentOptions,
|
||||||
...proxyOptions,
|
...proxyOptions,
|
||||||
|
tls: {
|
||||||
|
rejectUnauthorized: httpsAgentOptions.rejectUnauthorized,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
httpAgent = agent;
|
httpAgent = agent;
|
||||||
|
@@ -10,6 +10,7 @@ const { UptimeKumaServer } = require("../uptime-kuma-server");
|
|||||||
const { UptimeCacheList } = require("../uptime-cache-list");
|
const { UptimeCacheList } = require("../uptime-cache-list");
|
||||||
const { makeBadge } = require("badge-maker");
|
const { makeBadge } = require("badge-maker");
|
||||||
const { badgeConstants } = require("../config");
|
const { badgeConstants } = require("../config");
|
||||||
|
const { Prometheus } = require("../prometheus");
|
||||||
|
|
||||||
let router = express.Router();
|
let router = express.Router();
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@ router.get("/api/push/:pushToken", async (request, response) => {
|
|||||||
|
|
||||||
let pushToken = request.params.pushToken;
|
let pushToken = request.params.pushToken;
|
||||||
let msg = request.query.msg || "OK";
|
let msg = request.query.msg || "OK";
|
||||||
let ping = request.query.ping || null;
|
let ping = parseInt(request.query.ping) || null;
|
||||||
let statusString = request.query.status || "up";
|
let statusString = request.query.status || "up";
|
||||||
let status = (statusString === "up") ? UP : DOWN;
|
let status = (statusString === "up") ? UP : DOWN;
|
||||||
|
|
||||||
@@ -89,6 +90,7 @@ router.get("/api/push/:pushToken", async (request, response) => {
|
|||||||
io.to(monitor.user_id).emit("heartbeat", bean.toJSON());
|
io.to(monitor.user_id).emit("heartbeat", bean.toJSON());
|
||||||
UptimeCacheList.clearCache(monitor.id);
|
UptimeCacheList.clearCache(monitor.id);
|
||||||
Monitor.sendStats(io, monitor.id, monitor.user_id);
|
Monitor.sendStats(io, monitor.id, monitor.user_id);
|
||||||
|
new Prometheus(monitor).update(bean, undefined);
|
||||||
|
|
||||||
response.json({
|
response.json({
|
||||||
ok: true,
|
ok: true,
|
||||||
@@ -147,7 +149,11 @@ router.get("/api/badge/:id/status", cache("5 minutes"), async (request, response
|
|||||||
const heartbeat = await Monitor.getPreviousHeartbeat(requestedMonitorId);
|
const heartbeat = await Monitor.getPreviousHeartbeat(requestedMonitorId);
|
||||||
const state = overrideValue !== undefined ? overrideValue : heartbeat.status;
|
const state = overrideValue !== undefined ? overrideValue : heartbeat.status;
|
||||||
|
|
||||||
badgeValues.label = label ?? "Status";
|
if (label === undefined) {
|
||||||
|
badgeValues.label = "Status";
|
||||||
|
} else {
|
||||||
|
badgeValues.label = label;
|
||||||
|
}
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case DOWN:
|
case DOWN:
|
||||||
badgeValues.color = downColor;
|
badgeValues.color = downColor;
|
||||||
@@ -224,7 +230,7 @@ router.get("/api/badge/:id/uptime/:duration?", cache("5 minutes"), async (reques
|
|||||||
);
|
);
|
||||||
|
|
||||||
// limit the displayed uptime percentage to four (two, when displayed as percent) decimal digits
|
// limit the displayed uptime percentage to four (two, when displayed as percent) decimal digits
|
||||||
const cleanUptime = parseFloat(uptime.toPrecision(4));
|
const cleanUptime = (uptime * 100).toPrecision(4);
|
||||||
|
|
||||||
// use a given, custom color or calculate one based on the uptime value
|
// use a given, custom color or calculate one based on the uptime value
|
||||||
badgeValues.color = color ?? percentageToColor(uptime);
|
badgeValues.color = color ?? percentageToColor(uptime);
|
||||||
@@ -235,7 +241,7 @@ router.get("/api/badge/:id/uptime/:duration?", cache("5 minutes"), async (reques
|
|||||||
labelPrefix,
|
labelPrefix,
|
||||||
label ?? `Uptime (${requestedDuration}${labelSuffix})`,
|
label ?? `Uptime (${requestedDuration}${labelSuffix})`,
|
||||||
]);
|
]);
|
||||||
badgeValues.message = filterAndJoin([ prefix, `${cleanUptime * 100}`, suffix ]);
|
badgeValues.message = filterAndJoin([ prefix, cleanUptime, suffix ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// build the SVG based on given values
|
// build the SVG based on given values
|
||||||
@@ -436,7 +442,7 @@ router.get("/api/badge/:id/cert-exp", cache("5 minutes"), async (request, respon
|
|||||||
if (!tlsInfo.valid) {
|
if (!tlsInfo.valid) {
|
||||||
// return a "Bad Cert" badge in naColor (grey), when cert is not valid
|
// return a "Bad Cert" badge in naColor (grey), when cert is not valid
|
||||||
badgeValues.message = "Bad Cert";
|
badgeValues.message = "Bad Cert";
|
||||||
badgeValues.color = badgeConstants.downColor;
|
badgeValues.color = downColor;
|
||||||
} else {
|
} else {
|
||||||
const daysRemaining = parseInt(overrideValue ?? tlsInfo.certInfo.daysRemaining);
|
const daysRemaining = parseInt(overrideValue ?? tlsInfo.certInfo.daysRemaining);
|
||||||
|
|
||||||
|
@@ -5,6 +5,8 @@ const StatusPage = require("../model/status_page");
|
|||||||
const { allowDevAllOrigin, sendHttpError } = require("../util-server");
|
const { allowDevAllOrigin, sendHttpError } = require("../util-server");
|
||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
const Monitor = require("../model/monitor");
|
const Monitor = require("../model/monitor");
|
||||||
|
const { badgeConstants } = require("../config");
|
||||||
|
const { makeBadge } = require("badge-maker");
|
||||||
|
|
||||||
let router = express.Router();
|
let router = express.Router();
|
||||||
|
|
||||||
@@ -139,4 +141,100 @@ router.get("/api/status-page/:slug/manifest.json", cache("1440 minutes"), async
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// overall status-page status badge
|
||||||
|
router.get("/api/status-page/:slug/badge", cache("5 minutes"), async (request, response) => {
|
||||||
|
allowDevAllOrigin(response);
|
||||||
|
const slug = request.params.slug;
|
||||||
|
const statusPageID = await StatusPage.slugToID(slug);
|
||||||
|
const {
|
||||||
|
label,
|
||||||
|
upColor = badgeConstants.defaultUpColor,
|
||||||
|
downColor = badgeConstants.defaultDownColor,
|
||||||
|
partialColor = "#F6BE00",
|
||||||
|
maintenanceColor = "#808080",
|
||||||
|
style = badgeConstants.defaultStyle
|
||||||
|
} = request.query;
|
||||||
|
|
||||||
|
try {
|
||||||
|
let monitorIDList = await R.getCol(`
|
||||||
|
SELECT monitor_group.monitor_id FROM monitor_group, \`group\`
|
||||||
|
WHERE monitor_group.group_id = \`group\`.id
|
||||||
|
AND public = 1
|
||||||
|
AND \`group\`.status_page_id = ?
|
||||||
|
`, [
|
||||||
|
statusPageID
|
||||||
|
]);
|
||||||
|
|
||||||
|
let hasUp = false;
|
||||||
|
let hasDown = false;
|
||||||
|
let hasMaintenance = false;
|
||||||
|
|
||||||
|
for (let monitorID of monitorIDList) {
|
||||||
|
// retrieve the latest heartbeat
|
||||||
|
let beat = await R.getAll(`
|
||||||
|
SELECT * FROM heartbeat
|
||||||
|
WHERE monitor_id = ?
|
||||||
|
ORDER BY time DESC
|
||||||
|
LIMIT 1
|
||||||
|
`, [
|
||||||
|
monitorID,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// to be sure, when corresponding monitor not found
|
||||||
|
if (beat.length === 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// handle status of beat
|
||||||
|
if (beat[0].status === 3) {
|
||||||
|
hasMaintenance = true;
|
||||||
|
} else if (beat[0].status === 2) {
|
||||||
|
// ignored
|
||||||
|
} else if (beat[0].status === 1) {
|
||||||
|
hasUp = true;
|
||||||
|
} else {
|
||||||
|
hasDown = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const badgeValues = { style };
|
||||||
|
|
||||||
|
if (!hasUp && !hasDown && !hasMaintenance) {
|
||||||
|
// return a "N/A" badge in naColor (grey), if monitor is not public / not available / non exsitant
|
||||||
|
|
||||||
|
badgeValues.message = "N/A";
|
||||||
|
badgeValues.color = badgeConstants.naColor;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (hasMaintenance) {
|
||||||
|
badgeValues.label = label ? label : "";
|
||||||
|
badgeValues.color = maintenanceColor;
|
||||||
|
badgeValues.message = "Maintenance";
|
||||||
|
} else if (hasUp && !hasDown) {
|
||||||
|
badgeValues.label = label ? label : "";
|
||||||
|
badgeValues.color = upColor;
|
||||||
|
badgeValues.message = "Up";
|
||||||
|
} else if (hasUp && hasDown) {
|
||||||
|
badgeValues.label = label ? label : "";
|
||||||
|
badgeValues.color = partialColor;
|
||||||
|
badgeValues.message = "Degraded";
|
||||||
|
} else {
|
||||||
|
badgeValues.label = label ? label : "";
|
||||||
|
badgeValues.color = downColor;
|
||||||
|
badgeValues.message = "Down";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// build the svg based on given values
|
||||||
|
const svg = makeBadge(badgeValues);
|
||||||
|
|
||||||
|
response.type("image/svg+xml");
|
||||||
|
response.send(svg);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
sendHttpError(response, error.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
@@ -15,15 +15,27 @@ dayjs.extend(require("dayjs/plugin/customParseFormat"));
|
|||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
|
|
||||||
// Check Node.js Version
|
// Check Node.js Version
|
||||||
const nodeVersion = parseInt(process.versions.node.split(".")[0]);
|
const nodeVersion = process.versions.node;
|
||||||
const requiredVersion = 14;
|
|
||||||
|
// Get the required Node.js version from package.json
|
||||||
|
const requiredNodeVersions = require("../package.json").engines.node;
|
||||||
|
const bannedNodeVersions = " < 14 || 20.0.* || 20.1.* || 20.2.* || 20.3.* ";
|
||||||
console.log(`Your Node.js version: ${nodeVersion}`);
|
console.log(`Your Node.js version: ${nodeVersion}`);
|
||||||
|
|
||||||
if (nodeVersion < requiredVersion) {
|
const semver = require("semver");
|
||||||
console.error(`Error: Your Node.js version is not supported, please upgrade to Node.js >= ${requiredVersion}.`);
|
const requiredNodeVersionsComma = requiredNodeVersions.split("||").map((version) => version.trim()).join(", ");
|
||||||
|
|
||||||
|
// Exit Uptime Kuma immediately if the Node.js version is banned
|
||||||
|
if (semver.satisfies(nodeVersion, bannedNodeVersions)) {
|
||||||
|
console.error("\x1b[31m%s\x1b[0m", `Error: Your Node.js version: ${nodeVersion} is not supported, please upgrade your Node.js to ${requiredNodeVersionsComma}.`);
|
||||||
process.exit(-1);
|
process.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Warning if the Node.js version is not in the support list, but it maybe still works
|
||||||
|
if (!semver.satisfies(nodeVersion, requiredNodeVersions)) {
|
||||||
|
console.warn("\x1b[31m%s\x1b[0m", `Warning: Your Node.js version: ${nodeVersion} is not officially supported, please upgrade your Node.js to ${requiredNodeVersionsComma}.`);
|
||||||
|
}
|
||||||
|
|
||||||
const args = require("args-parser")(process.argv);
|
const args = require("args-parser")(process.argv);
|
||||||
const { sleep, log, getRandomInt, genSecret, isDev } = require("../src/util");
|
const { sleep, log, getRandomInt, genSecret, isDev } = require("../src/util");
|
||||||
const config = require("./config");
|
const config = require("./config");
|
||||||
@@ -142,8 +154,8 @@ const { apiKeySocketHandler } = require("./socket-handlers/api-key-socket-handle
|
|||||||
const { generalSocketHandler } = require("./socket-handlers/general-socket-handler");
|
const { generalSocketHandler } = require("./socket-handlers/general-socket-handler");
|
||||||
const { Settings } = require("./settings");
|
const { Settings } = require("./settings");
|
||||||
const { CacheableDnsHttpAgent } = require("./cacheable-dns-http-agent");
|
const { CacheableDnsHttpAgent } = require("./cacheable-dns-http-agent");
|
||||||
const { pluginsHandler } = require("./socket-handlers/plugins-handler");
|
|
||||||
const apicache = require("./modules/apicache");
|
const apicache = require("./modules/apicache");
|
||||||
|
const { resetChrome } = require("./monitor-types/real-browser-monitor-type");
|
||||||
|
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
@@ -156,12 +168,6 @@ app.use(function (req, res, next) {
|
|||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* Use for decode the auth object
|
|
||||||
* @type {null}
|
|
||||||
*/
|
|
||||||
let jwtSecret = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show Setup Page
|
* Show Setup Page
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
@@ -172,7 +178,6 @@ let needSetup = false;
|
|||||||
Database.init(args);
|
Database.init(args);
|
||||||
await initDatabase(testMode);
|
await initDatabase(testMode);
|
||||||
await server.initAfterDatabaseReady();
|
await server.initAfterDatabaseReady();
|
||||||
server.loadPlugins();
|
|
||||||
server.entryPage = await Settings.get("entryPage");
|
server.entryPage = await Settings.get("entryPage");
|
||||||
await StatusPage.loadDomainMappingList();
|
await StatusPage.loadDomainMappingList();
|
||||||
|
|
||||||
@@ -210,6 +215,7 @@ let needSetup = false;
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (isDev) {
|
if (isDev) {
|
||||||
|
app.use(express.urlencoded({ extended: true }));
|
||||||
app.post("/test-webhook", async (request, response) => {
|
app.post("/test-webhook", async (request, response) => {
|
||||||
log.debug("test", request.headers);
|
log.debug("test", request.headers);
|
||||||
log.debug("test", request.body);
|
log.debug("test", request.body);
|
||||||
@@ -264,7 +270,7 @@ let needSetup = false;
|
|||||||
log.info("server", "Adding socket handler");
|
log.info("server", "Adding socket handler");
|
||||||
io.on("connection", async (socket) => {
|
io.on("connection", async (socket) => {
|
||||||
|
|
||||||
sendInfo(socket);
|
sendInfo(socket, true);
|
||||||
|
|
||||||
if (needSetup) {
|
if (needSetup) {
|
||||||
log.info("server", "Redirect to setup page");
|
log.info("server", "Redirect to setup page");
|
||||||
@@ -281,7 +287,7 @@ let needSetup = false;
|
|||||||
log.info("auth", `Login by token. IP=${clientIP}`);
|
log.info("auth", `Login by token. IP=${clientIP}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let decoded = jwt.verify(token, jwtSecret);
|
let decoded = jwt.verify(token, server.jwtSecret);
|
||||||
|
|
||||||
log.info("auth", "Username from JWT: " + decoded.username);
|
log.info("auth", "Username from JWT: " + decoded.username);
|
||||||
|
|
||||||
@@ -352,7 +358,7 @@ let needSetup = false;
|
|||||||
ok: true,
|
ok: true,
|
||||||
token: jwt.sign({
|
token: jwt.sign({
|
||||||
username: data.username,
|
username: data.username,
|
||||||
}, jwtSecret),
|
}, server.jwtSecret),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,7 +388,7 @@ let needSetup = false;
|
|||||||
ok: true,
|
ok: true,
|
||||||
token: jwt.sign({
|
token: jwt.sign({
|
||||||
username: data.username,
|
username: data.username,
|
||||||
}, jwtSecret),
|
}, server.jwtSecret),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -637,6 +643,9 @@ let needSetup = false;
|
|||||||
monitor.accepted_statuscodes_json = JSON.stringify(monitor.accepted_statuscodes);
|
monitor.accepted_statuscodes_json = JSON.stringify(monitor.accepted_statuscodes);
|
||||||
delete monitor.accepted_statuscodes;
|
delete monitor.accepted_statuscodes;
|
||||||
|
|
||||||
|
monitor.kafkaProducerBrokers = JSON.stringify(monitor.kafkaProducerBrokers);
|
||||||
|
monitor.kafkaProducerSaslOptions = JSON.stringify(monitor.kafkaProducerSaslOptions);
|
||||||
|
|
||||||
bean.import(monitor);
|
bean.import(monitor);
|
||||||
bean.user_id = socket.userID;
|
bean.user_id = socket.userID;
|
||||||
|
|
||||||
@@ -671,6 +680,7 @@ let needSetup = false;
|
|||||||
// Edit a monitor
|
// Edit a monitor
|
||||||
socket.on("editMonitor", async (monitor, callback) => {
|
socket.on("editMonitor", async (monitor, callback) => {
|
||||||
try {
|
try {
|
||||||
|
let removeGroupChildren = false;
|
||||||
checkLogin(socket);
|
checkLogin(socket);
|
||||||
|
|
||||||
let bean = await R.findOne("monitor", " id = ? ", [ monitor.id ]);
|
let bean = await R.findOne("monitor", " id = ? ", [ monitor.id ]);
|
||||||
@@ -679,8 +689,22 @@ let needSetup = false;
|
|||||||
throw new Error("Permission denied.");
|
throw new Error("Permission denied.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if Parent is Descendant (would cause endless loop)
|
||||||
|
if (monitor.parent !== null) {
|
||||||
|
const childIDs = await Monitor.getAllChildrenIDs(monitor.id);
|
||||||
|
if (childIDs.includes(monitor.parent)) {
|
||||||
|
throw new Error("Invalid Monitor Group");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove children if monitor type has changed (from group to non-group)
|
||||||
|
if (bean.type === "group" && monitor.type !== bean.type) {
|
||||||
|
removeGroupChildren = true;
|
||||||
|
}
|
||||||
|
|
||||||
bean.name = monitor.name;
|
bean.name = monitor.name;
|
||||||
bean.description = monitor.description;
|
bean.description = monitor.description;
|
||||||
|
bean.parent = monitor.parent;
|
||||||
bean.type = monitor.type;
|
bean.type = monitor.type;
|
||||||
bean.url = monitor.url;
|
bean.url = monitor.url;
|
||||||
bean.method = monitor.method;
|
bean.method = monitor.method;
|
||||||
@@ -699,6 +723,7 @@ let needSetup = false;
|
|||||||
bean.maxretries = monitor.maxretries;
|
bean.maxretries = monitor.maxretries;
|
||||||
bean.port = parseInt(monitor.port);
|
bean.port = parseInt(monitor.port);
|
||||||
bean.keyword = monitor.keyword;
|
bean.keyword = monitor.keyword;
|
||||||
|
bean.invertKeyword = monitor.invertKeyword;
|
||||||
bean.ignoreTls = monitor.ignoreTls;
|
bean.ignoreTls = monitor.ignoreTls;
|
||||||
bean.expiryNotification = monitor.expiryNotification;
|
bean.expiryNotification = monitor.expiryNotification;
|
||||||
bean.upsideDown = monitor.upsideDown;
|
bean.upsideDown = monitor.upsideDown;
|
||||||
@@ -733,14 +758,25 @@ let needSetup = false;
|
|||||||
bean.radiusCallingStationId = monitor.radiusCallingStationId;
|
bean.radiusCallingStationId = monitor.radiusCallingStationId;
|
||||||
bean.radiusSecret = monitor.radiusSecret;
|
bean.radiusSecret = monitor.radiusSecret;
|
||||||
bean.httpBodyEncoding = monitor.httpBodyEncoding;
|
bean.httpBodyEncoding = monitor.httpBodyEncoding;
|
||||||
|
bean.expectedValue = monitor.expectedValue;
|
||||||
|
bean.jsonPath = monitor.jsonPath;
|
||||||
|
bean.kafkaProducerTopic = monitor.kafkaProducerTopic;
|
||||||
|
bean.kafkaProducerBrokers = JSON.stringify(monitor.kafkaProducerBrokers);
|
||||||
|
bean.kafkaProducerAllowAutoTopicCreation = monitor.kafkaProducerAllowAutoTopicCreation;
|
||||||
|
bean.kafkaProducerSaslOptions = JSON.stringify(monitor.kafkaProducerSaslOptions);
|
||||||
|
bean.kafkaProducerMessage = monitor.kafkaProducerMessage;
|
||||||
|
|
||||||
bean.validate();
|
bean.validate();
|
||||||
|
|
||||||
await R.store(bean);
|
await R.store(bean);
|
||||||
|
|
||||||
|
if (removeGroupChildren) {
|
||||||
|
await Monitor.unlinkAllChildren(monitor.id);
|
||||||
|
}
|
||||||
|
|
||||||
await updateMonitorNotification(bean.id, monitor.notificationIDList);
|
await updateMonitorNotification(bean.id, monitor.notificationIDList);
|
||||||
|
|
||||||
if (bean.active) {
|
if (bean.isActive()) {
|
||||||
await restartMonitor(socket.userID, bean.id);
|
await restartMonitor(socket.userID, bean.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -883,6 +919,8 @@ let needSetup = false;
|
|||||||
delete server.monitorList[monitorID];
|
delete server.monitorList[monitorID];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const startTime = Date.now();
|
||||||
|
|
||||||
await R.exec("DELETE FROM monitor WHERE id = ? AND user_id = ? ", [
|
await R.exec("DELETE FROM monitor WHERE id = ? AND user_id = ? ", [
|
||||||
monitorID,
|
monitorID,
|
||||||
socket.userID,
|
socket.userID,
|
||||||
@@ -891,6 +929,10 @@ let needSetup = false;
|
|||||||
// Fix #2880
|
// Fix #2880
|
||||||
apicache.clear();
|
apicache.clear();
|
||||||
|
|
||||||
|
const endTime = Date.now();
|
||||||
|
|
||||||
|
log.info("DB", `Delete Monitor completed in : ${endTime - startTime} ms`);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
msg: "Deleted Successfully.",
|
msg: "Deleted Successfully.",
|
||||||
@@ -1134,6 +1176,8 @@ let needSetup = false;
|
|||||||
await doubleCheckPassword(socket, currentPassword);
|
await doubleCheckPassword(socket, currentPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const previousChromeExecutable = await Settings.get("chromeExecutable");
|
||||||
|
|
||||||
await setSettings("general", data);
|
await setSettings("general", data);
|
||||||
server.entryPage = data.entryPage;
|
server.entryPage = data.entryPage;
|
||||||
|
|
||||||
@@ -1144,6 +1188,12 @@ let needSetup = false;
|
|||||||
await server.setTimezone(data.serverTimezone);
|
await server.setTimezone(data.serverTimezone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If Chrome Executable is changed, need to reset the browser
|
||||||
|
if (previousChromeExecutable !== data.chromeExecutable) {
|
||||||
|
log.info("settings", "Chrome executable is changed. Resetting Chrome...");
|
||||||
|
await resetChrome();
|
||||||
|
}
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
msg: "Saved"
|
msg: "Saved"
|
||||||
@@ -1345,13 +1395,14 @@ let needSetup = false;
|
|||||||
maxretries: monitorListData[i].maxretries,
|
maxretries: monitorListData[i].maxretries,
|
||||||
port: monitorListData[i].port,
|
port: monitorListData[i].port,
|
||||||
keyword: monitorListData[i].keyword,
|
keyword: monitorListData[i].keyword,
|
||||||
|
invertKeyword: monitorListData[i].invertKeyword,
|
||||||
ignoreTls: monitorListData[i].ignoreTls,
|
ignoreTls: monitorListData[i].ignoreTls,
|
||||||
upsideDown: monitorListData[i].upsideDown,
|
upsideDown: monitorListData[i].upsideDown,
|
||||||
maxredirects: monitorListData[i].maxredirects,
|
maxredirects: monitorListData[i].maxredirects,
|
||||||
accepted_statuscodes: monitorListData[i].accepted_statuscodes,
|
accepted_statuscodes: monitorListData[i].accepted_statuscodes,
|
||||||
dns_resolve_type: monitorListData[i].dns_resolve_type,
|
dns_resolve_type: monitorListData[i].dns_resolve_type,
|
||||||
dns_resolve_server: monitorListData[i].dns_resolve_server,
|
dns_resolve_server: monitorListData[i].dns_resolve_server,
|
||||||
notificationIDList: {},
|
notificationIDList: monitorListData[i].notificationIDList,
|
||||||
proxy_id: monitorListData[i].proxy_id || null,
|
proxy_id: monitorListData[i].proxy_id || null,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1513,7 +1564,6 @@ let needSetup = false;
|
|||||||
maintenanceSocketHandler(socket);
|
maintenanceSocketHandler(socket);
|
||||||
apiKeySocketHandler(socket);
|
apiKeySocketHandler(socket);
|
||||||
generalSocketHandler(socket, server);
|
generalSocketHandler(socket, server);
|
||||||
pluginsHandler(socket, server);
|
|
||||||
|
|
||||||
log.debug("server", "added all socket handlers");
|
log.debug("server", "added all socket handlers");
|
||||||
|
|
||||||
@@ -1557,7 +1607,7 @@ let needSetup = false;
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
initBackgroundJobs(args);
|
await initBackgroundJobs();
|
||||||
|
|
||||||
// Start cloudflared at the end if configured
|
// Start cloudflared at the end if configured
|
||||||
await cloudflaredAutoStart(cloudflaredToken);
|
await cloudflaredAutoStart(cloudflaredToken);
|
||||||
@@ -1616,6 +1666,7 @@ async function afterLogin(socket, user) {
|
|||||||
socket.join(user.id);
|
socket.join(user.id);
|
||||||
|
|
||||||
let monitorList = await server.sendMonitorList(socket);
|
let monitorList = await server.sendMonitorList(socket);
|
||||||
|
sendInfo(socket);
|
||||||
server.sendMaintenanceList(socket);
|
server.sendMaintenanceList(socket);
|
||||||
sendNotificationList(socket);
|
sendNotificationList(socket);
|
||||||
sendProxyList(socket);
|
sendProxyList(socket);
|
||||||
@@ -1683,7 +1734,7 @@ async function initDatabase(testMode = false) {
|
|||||||
needSetup = true;
|
needSetup = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
jwtSecret = jwtSecretBean.value;
|
server.jwtSecret = jwtSecretBean.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -3,6 +3,7 @@ const { Settings } = require("../settings");
|
|||||||
const { sendInfo } = require("../client");
|
const { sendInfo } = require("../client");
|
||||||
const { checkLogin } = require("../util-server");
|
const { checkLogin } = require("../util-server");
|
||||||
const GameResolver = require("gamedig/lib/GameResolver");
|
const GameResolver = require("gamedig/lib/GameResolver");
|
||||||
|
const { testChrome } = require("../monitor-types/real-browser-monitor-type");
|
||||||
|
|
||||||
let gameResolver = new GameResolver();
|
let gameResolver = new GameResolver();
|
||||||
let gameList = null;
|
let gameList = null;
|
||||||
@@ -47,4 +48,18 @@ module.exports.generalSocketHandler = (socket, server) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on("testChrome", (executable, callback) => {
|
||||||
|
// Just noticed that await call could block the whole socket.io server!!! Use pure promise instead.
|
||||||
|
testChrome(executable).then((version) => {
|
||||||
|
callback({
|
||||||
|
ok: true,
|
||||||
|
msg: "Found Chromium/Chrome. Version: " + version,
|
||||||
|
});
|
||||||
|
}).catch((e) => {
|
||||||
|
callback({
|
||||||
|
ok: false,
|
||||||
|
msg: e.message,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
@@ -5,7 +5,6 @@ const apicache = require("../modules/apicache");
|
|||||||
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
||||||
const Maintenance = require("../model/maintenance");
|
const Maintenance = require("../model/maintenance");
|
||||||
const server = UptimeKumaServer.getInstance();
|
const server = UptimeKumaServer.getInstance();
|
||||||
const MaintenanceTimeslot = require("../model/maintenance_timeslot");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handlers for Maintenance
|
* Handlers for Maintenance
|
||||||
@@ -19,10 +18,12 @@ module.exports.maintenanceSocketHandler = (socket) => {
|
|||||||
|
|
||||||
log.debug("maintenance", maintenance);
|
log.debug("maintenance", maintenance);
|
||||||
|
|
||||||
let bean = Maintenance.jsonToBean(R.dispense("maintenance"), maintenance);
|
let bean = await Maintenance.jsonToBean(R.dispense("maintenance"), maintenance);
|
||||||
bean.user_id = socket.userID;
|
bean.user_id = socket.userID;
|
||||||
let maintenanceID = await R.store(bean);
|
let maintenanceID = await R.store(bean);
|
||||||
await MaintenanceTimeslot.generateTimeslot(bean);
|
|
||||||
|
server.maintenanceList[maintenanceID] = bean;
|
||||||
|
await bean.run(true);
|
||||||
|
|
||||||
await server.sendMaintenanceList(socket);
|
await server.sendMaintenanceList(socket);
|
||||||
|
|
||||||
@@ -45,17 +46,15 @@ module.exports.maintenanceSocketHandler = (socket) => {
|
|||||||
try {
|
try {
|
||||||
checkLogin(socket);
|
checkLogin(socket);
|
||||||
|
|
||||||
let bean = await R.findOne("maintenance", " id = ? ", [ maintenance.id ]);
|
let bean = server.getMaintenance(maintenance.id);
|
||||||
|
|
||||||
if (bean.user_id !== socket.userID) {
|
if (bean.user_id !== socket.userID) {
|
||||||
throw new Error("Permission denied.");
|
throw new Error("Permission denied.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Maintenance.jsonToBean(bean, maintenance);
|
await Maintenance.jsonToBean(bean, maintenance);
|
||||||
|
|
||||||
await R.store(bean);
|
await R.store(bean);
|
||||||
await MaintenanceTimeslot.generateTimeslot(bean, null, true);
|
await bean.run(true);
|
||||||
|
|
||||||
await server.sendMaintenanceList(socket);
|
await server.sendMaintenanceList(socket);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
@@ -187,7 +186,7 @@ module.exports.maintenanceSocketHandler = (socket) => {
|
|||||||
|
|
||||||
log.debug("maintenance", `Get Monitors for Maintenance: ${maintenanceID} User ID: ${socket.userID}`);
|
log.debug("maintenance", `Get Monitors for Maintenance: ${maintenanceID} User ID: ${socket.userID}`);
|
||||||
|
|
||||||
let monitors = await R.getAll("SELECT monitor.id, monitor.name FROM monitor_maintenance mm JOIN monitor ON mm.monitor_id = monitor.id WHERE mm.maintenance_id = ? ", [
|
let monitors = await R.getAll("SELECT monitor.id FROM monitor_maintenance mm JOIN monitor ON mm.monitor_id = monitor.id WHERE mm.maintenance_id = ? ", [
|
||||||
maintenanceID,
|
maintenanceID,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -236,6 +235,7 @@ module.exports.maintenanceSocketHandler = (socket) => {
|
|||||||
log.debug("maintenance", `Delete Maintenance: ${maintenanceID} User ID: ${socket.userID}`);
|
log.debug("maintenance", `Delete Maintenance: ${maintenanceID} User ID: ${socket.userID}`);
|
||||||
|
|
||||||
if (maintenanceID in server.maintenanceList) {
|
if (maintenanceID in server.maintenanceList) {
|
||||||
|
server.maintenanceList[maintenanceID].stop();
|
||||||
delete server.maintenanceList[maintenanceID];
|
delete server.maintenanceList[maintenanceID];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,9 +267,15 @@ module.exports.maintenanceSocketHandler = (socket) => {
|
|||||||
|
|
||||||
log.debug("maintenance", `Pause Maintenance: ${maintenanceID} User ID: ${socket.userID}`);
|
log.debug("maintenance", `Pause Maintenance: ${maintenanceID} User ID: ${socket.userID}`);
|
||||||
|
|
||||||
await R.exec("UPDATE maintenance SET active = 0 WHERE id = ? ", [
|
let maintenance = server.getMaintenance(maintenanceID);
|
||||||
maintenanceID,
|
|
||||||
]);
|
if (!maintenance) {
|
||||||
|
throw new Error("Maintenance not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
maintenance.active = false;
|
||||||
|
await R.store(maintenance);
|
||||||
|
maintenance.stop();
|
||||||
|
|
||||||
apicache.clear();
|
apicache.clear();
|
||||||
|
|
||||||
@@ -294,9 +300,15 @@ module.exports.maintenanceSocketHandler = (socket) => {
|
|||||||
|
|
||||||
log.debug("maintenance", `Resume Maintenance: ${maintenanceID} User ID: ${socket.userID}`);
|
log.debug("maintenance", `Resume Maintenance: ${maintenanceID} User ID: ${socket.userID}`);
|
||||||
|
|
||||||
await R.exec("UPDATE maintenance SET active = 1 WHERE id = ? ", [
|
let maintenance = server.getMaintenance(maintenanceID);
|
||||||
maintenanceID,
|
|
||||||
]);
|
if (!maintenance) {
|
||||||
|
throw new Error("Maintenance not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
maintenance.active = true;
|
||||||
|
await R.store(maintenance);
|
||||||
|
await maintenance.run();
|
||||||
|
|
||||||
apicache.clear();
|
apicache.clear();
|
||||||
|
|
||||||
|
@@ -1,69 +0,0 @@
|
|||||||
const { checkLogin } = require("../util-server");
|
|
||||||
const { PluginsManager } = require("../plugins-manager");
|
|
||||||
const { log } = require("../../src/util.js");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handlers for plugins
|
|
||||||
* @param {Socket} socket Socket.io instance
|
|
||||||
* @param {UptimeKumaServer} server
|
|
||||||
*/
|
|
||||||
module.exports.pluginsHandler = (socket, server) => {
|
|
||||||
|
|
||||||
const pluginManager = server.getPluginManager();
|
|
||||||
|
|
||||||
// Get Plugin List
|
|
||||||
socket.on("getPluginList", async (callback) => {
|
|
||||||
try {
|
|
||||||
checkLogin(socket);
|
|
||||||
|
|
||||||
log.debug("plugin", "PluginManager.disable: " + PluginsManager.disable);
|
|
||||||
|
|
||||||
if (PluginsManager.disable) {
|
|
||||||
throw new Error("Plugin Disabled: In order to enable plugin feature, you need to use the default data directory: ./data/");
|
|
||||||
}
|
|
||||||
|
|
||||||
let pluginList = await pluginManager.fetchPluginList();
|
|
||||||
callback({
|
|
||||||
ok: true,
|
|
||||||
pluginList,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
log.warn("plugin", "Error: " + error.message);
|
|
||||||
callback({
|
|
||||||
ok: false,
|
|
||||||
msg: error.message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on("installPlugin", async (repoURL, name, callback) => {
|
|
||||||
try {
|
|
||||||
checkLogin(socket);
|
|
||||||
pluginManager.downloadPlugin(repoURL, name);
|
|
||||||
await pluginManager.loadPlugin(name);
|
|
||||||
callback({
|
|
||||||
ok: true,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
callback({
|
|
||||||
ok: false,
|
|
||||||
msg: error.message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on("uninstallPlugin", async (name, callback) => {
|
|
||||||
try {
|
|
||||||
checkLogin(socket);
|
|
||||||
await pluginManager.removePlugin(name);
|
|
||||||
callback({
|
|
||||||
ok: true,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
callback({
|
|
||||||
ok: false,
|
|
||||||
msg: error.message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
@@ -276,7 +276,7 @@ module.exports.statusPageSocketHandler = (socket) => {
|
|||||||
let statusPage = R.dispense("status_page");
|
let statusPage = R.dispense("status_page");
|
||||||
statusPage.slug = slug;
|
statusPage.slug = slug;
|
||||||
statusPage.title = title;
|
statusPage.title = title;
|
||||||
statusPage.theme = "light";
|
statusPage.theme = "auto";
|
||||||
statusPage.icon = "";
|
statusPage.icon = "";
|
||||||
await R.store(statusPage);
|
await R.store(statusPage);
|
||||||
|
|
||||||
|
@@ -10,8 +10,7 @@ const util = require("util");
|
|||||||
const { CacheableDnsHttpAgent } = require("./cacheable-dns-http-agent");
|
const { CacheableDnsHttpAgent } = require("./cacheable-dns-http-agent");
|
||||||
const { Settings } = require("./settings");
|
const { Settings } = require("./settings");
|
||||||
const dayjs = require("dayjs");
|
const dayjs = require("dayjs");
|
||||||
const { PluginsManager } = require("./plugins-manager");
|
// DO NOT IMPORT HERE IF THE MODULES USED `UptimeKumaServer.getInstance()`, put at the bottom of this file instead.
|
||||||
// DO NOT IMPORT HERE IF THE MODULES USED `UptimeKumaServer.getInstance()`
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `module.exports` (alias: `server`) should be inside this class, in order to avoid circular dependency issue.
|
* `module.exports` (alias: `server`) should be inside this class, in order to avoid circular dependency issue.
|
||||||
@@ -47,14 +46,6 @@ class UptimeKumaServer {
|
|||||||
*/
|
*/
|
||||||
indexHTML = "";
|
indexHTML = "";
|
||||||
|
|
||||||
generateMaintenanceTimeslotsInterval = undefined;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Plugins Manager
|
|
||||||
* @type {PluginsManager}
|
|
||||||
*/
|
|
||||||
pluginsManager = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @type {{}}
|
* @type {{}}
|
||||||
@@ -63,6 +54,12 @@ class UptimeKumaServer {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use for decode the auth object
|
||||||
|
* @type {null}
|
||||||
|
*/
|
||||||
|
jwtSecret = null;
|
||||||
|
|
||||||
static getInstance(args) {
|
static getInstance(args) {
|
||||||
if (UptimeKumaServer.instance == null) {
|
if (UptimeKumaServer.instance == null) {
|
||||||
UptimeKumaServer.instance = new UptimeKumaServer(args);
|
UptimeKumaServer.instance = new UptimeKumaServer(args);
|
||||||
@@ -74,6 +71,7 @@ class UptimeKumaServer {
|
|||||||
// SSL
|
// SSL
|
||||||
const sslKey = args["ssl-key"] || process.env.UPTIME_KUMA_SSL_KEY || process.env.SSL_KEY || undefined;
|
const sslKey = args["ssl-key"] || process.env.UPTIME_KUMA_SSL_KEY || process.env.SSL_KEY || undefined;
|
||||||
const sslCert = args["ssl-cert"] || process.env.UPTIME_KUMA_SSL_CERT || process.env.SSL_CERT || undefined;
|
const sslCert = args["ssl-cert"] || process.env.UPTIME_KUMA_SSL_CERT || process.env.SSL_CERT || undefined;
|
||||||
|
const sslKeyPassphrase = args["ssl-key-passphrase"] || process.env.UPTIME_KUMA_SSL_KEY_PASSPHRASE || process.env.SSL_KEY_PASSPHRASE || undefined;
|
||||||
|
|
||||||
log.info("server", "Creating express and socket.io instance");
|
log.info("server", "Creating express and socket.io instance");
|
||||||
this.app = express();
|
this.app = express();
|
||||||
@@ -81,7 +79,8 @@ class UptimeKumaServer {
|
|||||||
log.info("server", "Server Type: HTTPS");
|
log.info("server", "Server Type: HTTPS");
|
||||||
this.httpServer = https.createServer({
|
this.httpServer = https.createServer({
|
||||||
key: fs.readFileSync(sslKey),
|
key: fs.readFileSync(sslKey),
|
||||||
cert: fs.readFileSync(sslCert)
|
cert: fs.readFileSync(sslCert),
|
||||||
|
passphrase: sslKeyPassphrase,
|
||||||
}, this.app);
|
}, this.app);
|
||||||
} else {
|
} else {
|
||||||
log.info("server", "Server Type: HTTP");
|
log.info("server", "Server Type: HTTP");
|
||||||
@@ -98,11 +97,17 @@ class UptimeKumaServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set Monitor Types
|
||||||
|
UptimeKumaServer.monitorTypeList["real-browser"] = new RealBrowserMonitorType();
|
||||||
|
|
||||||
this.io = new Server(this.httpServer);
|
this.io = new Server(this.httpServer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Initialise app after the database has been set up */
|
/** Initialise app after the database has been set up */
|
||||||
async initAfterDatabaseReady() {
|
async initAfterDatabaseReady() {
|
||||||
|
// Static
|
||||||
|
this.app.use("/screenshots", express.static(Database.screenshotDir));
|
||||||
|
|
||||||
await CacheableDnsHttpAgent.update();
|
await CacheableDnsHttpAgent.update();
|
||||||
|
|
||||||
process.env.TZ = await this.getTimezone();
|
process.env.TZ = await this.getTimezone();
|
||||||
@@ -110,8 +115,7 @@ class UptimeKumaServer {
|
|||||||
log.debug("DEBUG", "Timezone: " + process.env.TZ);
|
log.debug("DEBUG", "Timezone: " + process.env.TZ);
|
||||||
log.debug("DEBUG", "Current Time: " + dayjs.tz().format());
|
log.debug("DEBUG", "Current Time: " + dayjs.tz().format());
|
||||||
|
|
||||||
await this.generateMaintenanceTimeslots();
|
await this.loadMaintenanceList();
|
||||||
this.generateMaintenanceTimeslotsInterval = setInterval(this.generateMaintenanceTimeslots, 60 * 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -173,16 +177,33 @@ class UptimeKumaServer {
|
|||||||
*/
|
*/
|
||||||
async getMaintenanceJSONList(userID) {
|
async getMaintenanceJSONList(userID) {
|
||||||
let result = {};
|
let result = {};
|
||||||
|
for (let maintenanceID in this.maintenanceList) {
|
||||||
|
result[maintenanceID] = await this.maintenanceList[maintenanceID].toJSON();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load maintenance list and run
|
||||||
|
* @param userID
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async loadMaintenanceList(userID) {
|
||||||
|
let maintenanceList = await R.findAll("maintenance", " ORDER BY end_date DESC, title", [
|
||||||
|
|
||||||
let maintenanceList = await R.find("maintenance", " user_id = ? ORDER BY end_date DESC, title", [
|
|
||||||
userID,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
for (let maintenance of maintenanceList) {
|
for (let maintenance of maintenanceList) {
|
||||||
result[maintenance.id] = await maintenance.toJSON();
|
this.maintenanceList[maintenance.id] = maintenance;
|
||||||
|
maintenance.run(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
getMaintenance(maintenanceID) {
|
||||||
|
if (this.maintenanceList[maintenanceID]) {
|
||||||
|
return this.maintenanceList[maintenanceID];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -228,9 +249,9 @@ class UptimeKumaServer {
|
|||||||
|
|
||||||
return (typeof forwardedFor === "string" ? forwardedFor.split(",")[0].trim() : null)
|
return (typeof forwardedFor === "string" ? forwardedFor.split(",")[0].trim() : null)
|
||||||
|| socket.client.conn.request.headers["x-real-ip"]
|
|| socket.client.conn.request.headers["x-real-ip"]
|
||||||
|| clientIP.replace(/^.*:/, "");
|
|| clientIP.replace(/^::ffff:/, "");
|
||||||
} else {
|
} else {
|
||||||
return clientIP.replace(/^.*:/, "");
|
return clientIP.replace(/^::ffff:/, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,16 +259,46 @@ class UptimeKumaServer {
|
|||||||
* Attempt to get the current server timezone
|
* Attempt to get the current server timezone
|
||||||
* If this fails, fall back to environment variables and then make a
|
* If this fails, fall back to environment variables and then make a
|
||||||
* guess.
|
* guess.
|
||||||
* @returns {string}
|
* @returns {Promise<string>}
|
||||||
*/
|
*/
|
||||||
async getTimezone() {
|
async getTimezone() {
|
||||||
let timezone = await Settings.get("serverTimezone");
|
// From process.env.TZ
|
||||||
if (timezone) {
|
try {
|
||||||
return timezone;
|
if (process.env.TZ) {
|
||||||
} else if (process.env.TZ) {
|
this.checkTimezone(process.env.TZ);
|
||||||
return process.env.TZ;
|
return process.env.TZ;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.warn("timezone", e.message + " in process.env.TZ");
|
||||||
|
}
|
||||||
|
|
||||||
|
let timezone = await Settings.get("serverTimezone");
|
||||||
|
|
||||||
|
// From Settings
|
||||||
|
try {
|
||||||
|
log.debug("timezone", "Using timezone from settings: " + timezone);
|
||||||
|
if (timezone) {
|
||||||
|
this.checkTimezone(timezone);
|
||||||
|
return timezone;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.warn("timezone", e.message + " in settings");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Guess
|
||||||
|
try {
|
||||||
|
let guess = dayjs.tz.guess();
|
||||||
|
log.debug("timezone", "Guessing timezone: " + guess);
|
||||||
|
if (guess) {
|
||||||
|
this.checkTimezone(guess);
|
||||||
|
return guess;
|
||||||
} else {
|
} else {
|
||||||
return dayjs.tz.guess();
|
return "UTC";
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Guess failed, fall back to UTC
|
||||||
|
log.debug("timezone", "Guessed an invalid timezone. Use UTC as fallback");
|
||||||
|
return "UTC";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,85 +310,38 @@ class UptimeKumaServer {
|
|||||||
return dayjs().format("Z");
|
return dayjs().format("Z");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throw an error if the timezone is invalid
|
||||||
|
* @param timezone
|
||||||
|
*/
|
||||||
|
checkTimezone(timezone) {
|
||||||
|
try {
|
||||||
|
dayjs.utc("2013-11-18 11:55").tz(timezone).format();
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error("Invalid timezone:" + timezone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the current server timezone and environment variables
|
* Set the current server timezone and environment variables
|
||||||
* @param {string} timezone
|
* @param {string} timezone
|
||||||
*/
|
*/
|
||||||
async setTimezone(timezone) {
|
async setTimezone(timezone) {
|
||||||
|
this.checkTimezone(timezone);
|
||||||
await Settings.set("serverTimezone", timezone, "general");
|
await Settings.set("serverTimezone", timezone, "general");
|
||||||
process.env.TZ = timezone;
|
process.env.TZ = timezone;
|
||||||
dayjs.tz.setDefault(timezone);
|
dayjs.tz.setDefault(timezone);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Load the timeslots for maintenance */
|
|
||||||
async generateMaintenanceTimeslots() {
|
|
||||||
log.debug("maintenance", "Routine: Generating Maintenance Timeslots");
|
|
||||||
|
|
||||||
// Prevent #2776
|
|
||||||
// Remove duplicate maintenance_timeslot with same start_date, end_date and maintenance_id
|
|
||||||
await R.exec("DELETE FROM maintenance_timeslot WHERE id NOT IN (SELECT MIN(id) FROM maintenance_timeslot GROUP BY start_date, end_date, maintenance_id)");
|
|
||||||
|
|
||||||
let list = await R.find("maintenance_timeslot", " generated_next = 0 AND start_date <= DATETIME('now') ");
|
|
||||||
|
|
||||||
for (let maintenanceTimeslot of list) {
|
|
||||||
let maintenance = await maintenanceTimeslot.maintenance;
|
|
||||||
await MaintenanceTimeslot.generateTimeslot(maintenance, maintenanceTimeslot.end_date, false);
|
|
||||||
maintenanceTimeslot.generated_next = true;
|
|
||||||
await R.store(maintenanceTimeslot);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Stop the server */
|
/** Stop the server */
|
||||||
async stop() {
|
async stop() {
|
||||||
clearTimeout(this.generateMaintenanceTimeslotsInterval);
|
|
||||||
}
|
|
||||||
|
|
||||||
loadPlugins() {
|
|
||||||
this.pluginsManager = new PluginsManager(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @returns {PluginsManager}
|
|
||||||
*/
|
|
||||||
getPluginManager() {
|
|
||||||
return this.pluginsManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {MonitorType} monitorType
|
|
||||||
*/
|
|
||||||
addMonitorType(monitorType) {
|
|
||||||
if (monitorType instanceof MonitorType && monitorType.name) {
|
|
||||||
if (monitorType.name in UptimeKumaServer.monitorTypeList) {
|
|
||||||
log.error("", "Conflict Monitor Type name");
|
|
||||||
}
|
|
||||||
UptimeKumaServer.monitorTypeList[monitorType.name] = monitorType;
|
|
||||||
} else {
|
|
||||||
log.error("", "Invalid Monitor Type: " + monitorType.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {MonitorType} monitorType
|
|
||||||
*/
|
|
||||||
removeMonitorType(monitorType) {
|
|
||||||
if (UptimeKumaServer.monitorTypeList[monitorType.name] === monitorType) {
|
|
||||||
delete UptimeKumaServer.monitorTypeList[monitorType.name];
|
|
||||||
} else {
|
|
||||||
log.error("", "Remove MonitorType failed: " + monitorType.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
UptimeKumaServer
|
UptimeKumaServer
|
||||||
};
|
};
|
||||||
|
|
||||||
// Must be at the end
|
// Must be at the end to avoid circular dependencies
|
||||||
const MaintenanceTimeslot = require("./model/maintenance_timeslot");
|
const { RealBrowserMonitorType } = require("./monitor-types/real-browser-monitor-type");
|
||||||
const { MonitorType } = require("./monitor-types/monitor-type");
|
|
||||||
|
@@ -28,8 +28,11 @@ const {
|
|||||||
} = require("node-radius-utils");
|
} = require("node-radius-utils");
|
||||||
const dayjs = require("dayjs");
|
const dayjs = require("dayjs");
|
||||||
|
|
||||||
const isWindows = process.platform === /^win/.test(process.platform);
|
// SASLOptions used in JSDoc
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
const { Kafka, SASLOptions } = require("kafkajs");
|
||||||
|
|
||||||
|
const isWindows = process.platform === /^win/.test(process.platform);
|
||||||
/**
|
/**
|
||||||
* Init or reset JWT secret
|
* Init or reset JWT secret
|
||||||
* @returns {Promise<Bean>}
|
* @returns {Promise<Bean>}
|
||||||
@@ -196,6 +199,94 @@ exports.mqttAsync = function (hostname, topic, okMessage, options = {}) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Monitor Kafka using Producer
|
||||||
|
* @param {string} topic Topic name to produce into
|
||||||
|
* @param {string} message Message to produce
|
||||||
|
* @param {Object} [options={interval = 20, allowAutoTopicCreation = false, ssl = false, clientId = "Uptime-Kuma"}]
|
||||||
|
* Kafka client options. Contains ssl, clientId, allowAutoTopicCreation and
|
||||||
|
* interval (interval defaults to 20, allowAutoTopicCreation defaults to false, clientId defaults to "Uptime-Kuma"
|
||||||
|
* and ssl defaults to false)
|
||||||
|
* @param {string[]} brokers List of kafka brokers to connect, host and port joined by ':'
|
||||||
|
* @param {SASLOptions} [saslOptions={}] Options for kafka client Authentication (SASL) (defaults to
|
||||||
|
* {})
|
||||||
|
* @returns {Promise<string>}
|
||||||
|
*/
|
||||||
|
exports.kafkaProducerAsync = function (brokers, topic, message, options = {}, saslOptions = {}) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const { interval = 20, allowAutoTopicCreation = false, ssl = false, clientId = "Uptime-Kuma" } = options;
|
||||||
|
|
||||||
|
let connectedToKafka = false;
|
||||||
|
|
||||||
|
const timeoutID = setTimeout(() => {
|
||||||
|
log.debug("kafkaProducer", "KafkaProducer timeout triggered");
|
||||||
|
connectedToKafka = true;
|
||||||
|
reject(new Error("Timeout"));
|
||||||
|
}, interval * 1000 * 0.8);
|
||||||
|
|
||||||
|
if (saslOptions.mechanism === "None") {
|
||||||
|
saslOptions = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
let client = new Kafka({
|
||||||
|
brokers: brokers,
|
||||||
|
clientId: clientId,
|
||||||
|
sasl: saslOptions,
|
||||||
|
retry: {
|
||||||
|
retries: 0,
|
||||||
|
},
|
||||||
|
ssl: ssl,
|
||||||
|
});
|
||||||
|
|
||||||
|
let producer = client.producer({
|
||||||
|
allowAutoTopicCreation: allowAutoTopicCreation,
|
||||||
|
retry: {
|
||||||
|
retries: 0,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
producer.connect().then(
|
||||||
|
() => {
|
||||||
|
try {
|
||||||
|
producer.send({
|
||||||
|
topic: topic,
|
||||||
|
messages: [{
|
||||||
|
value: message,
|
||||||
|
}],
|
||||||
|
});
|
||||||
|
connectedToKafka = true;
|
||||||
|
clearTimeout(timeoutID);
|
||||||
|
resolve("Message sent successfully");
|
||||||
|
} catch (e) {
|
||||||
|
connectedToKafka = true;
|
||||||
|
producer.disconnect();
|
||||||
|
clearTimeout(timeoutID);
|
||||||
|
reject(new Error("Error sending message: " + e.message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
).catch(
|
||||||
|
(e) => {
|
||||||
|
connectedToKafka = true;
|
||||||
|
producer.disconnect();
|
||||||
|
clearTimeout(timeoutID);
|
||||||
|
reject(new Error("Error in producer connection: " + e.message));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
producer.on("producer.network.request_timeout", (_) => {
|
||||||
|
clearTimeout(timeoutID);
|
||||||
|
reject(new Error("producer.network.request_timeout"));
|
||||||
|
});
|
||||||
|
|
||||||
|
producer.on("producer.disconnect", (_) => {
|
||||||
|
if (!connectedToKafka) {
|
||||||
|
clearTimeout(timeoutID);
|
||||||
|
reject(new Error("producer.disconnect"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use NTLM Auth for a http request.
|
* Use NTLM Auth for a http request.
|
||||||
* @param {Object} options The http request options
|
* @param {Object} options The http request options
|
||||||
@@ -322,20 +413,32 @@ exports.postgresQuery = function (connectionString, query) {
|
|||||||
* Run a query on MySQL/MariaDB
|
* Run a query on MySQL/MariaDB
|
||||||
* @param {string} connectionString The database connection string
|
* @param {string} connectionString The database connection string
|
||||||
* @param {string} query The query to validate the database with
|
* @param {string} query The query to validate the database with
|
||||||
* @returns {Promise<(string[]|Object[]|Object)>}
|
* @returns {Promise<(string)>}
|
||||||
*/
|
*/
|
||||||
exports.mysqlQuery = function (connectionString, query) {
|
exports.mysqlQuery = function (connectionString, query) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const connection = mysql.createConnection(connectionString);
|
const connection = mysql.createConnection(connectionString);
|
||||||
connection.promise().query(query)
|
|
||||||
.then(res => {
|
connection.on("error", (err) => {
|
||||||
resolve(res);
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
reject(err);
|
reject(err);
|
||||||
})
|
});
|
||||||
.finally(() => {
|
|
||||||
|
connection.query(query, (err, res) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
if (Array.isArray(res)) {
|
||||||
|
resolve("Rows: " + res.length);
|
||||||
|
} else {
|
||||||
|
resolve("No Error, but the result is not an array. Type: " + typeof res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
connection.end();
|
||||||
|
} catch (_) {
|
||||||
connection.destroy();
|
connection.destroy();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -366,6 +469,7 @@ exports.mongodbPing = async function (connectionString) {
|
|||||||
* @param {string} callingStationId ID of calling station
|
* @param {string} callingStationId ID of calling station
|
||||||
* @param {string} secret Secret to use
|
* @param {string} secret Secret to use
|
||||||
* @param {number} [port=1812] Port to contact radius server on
|
* @param {number} [port=1812] Port to contact radius server on
|
||||||
|
* @param {number} [timeout=2500] Timeout for connection to use
|
||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
exports.radius = function (
|
exports.radius = function (
|
||||||
@@ -376,10 +480,12 @@ exports.radius = function (
|
|||||||
callingStationId,
|
callingStationId,
|
||||||
secret,
|
secret,
|
||||||
port = 1812,
|
port = 1812,
|
||||||
|
timeout = 2500,
|
||||||
) {
|
) {
|
||||||
const client = new radiusClient({
|
const client = new radiusClient({
|
||||||
host: hostname,
|
host: hostname,
|
||||||
hostPort: port,
|
hostPort: port,
|
||||||
|
timeout: timeout,
|
||||||
dictionaries: [ file ],
|
dictionaries: [ file ],
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -401,12 +507,18 @@ exports.radius = function (
|
|||||||
exports.redisPingAsync = function (dsn) {
|
exports.redisPingAsync = function (dsn) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const client = redis.createClient({
|
const client = redis.createClient({
|
||||||
url: dsn,
|
url: dsn
|
||||||
});
|
});
|
||||||
client.on("error", (err) => {
|
client.on("error", (err) => {
|
||||||
|
if (client.isOpen) {
|
||||||
|
client.disconnect();
|
||||||
|
}
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
client.connect().then(() => {
|
client.connect().then(() => {
|
||||||
|
if (!client.isOpen) {
|
||||||
|
client.emit("error", new Error("connection isn't open"));
|
||||||
|
}
|
||||||
client.ping().then((res, err) => {
|
client.ping().then((res, err) => {
|
||||||
if (client.isOpen) {
|
if (client.isOpen) {
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
@@ -416,7 +528,7 @@ exports.redisPingAsync = function (dsn) {
|
|||||||
} else {
|
} else {
|
||||||
resolve(res);
|
resolve(res);
|
||||||
}
|
}
|
||||||
});
|
}).catch(error => reject(error));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -512,12 +624,16 @@ const parseCertificateInfo = function (info) {
|
|||||||
|
|
||||||
// Move up the chain until loop is encountered
|
// Move up the chain until loop is encountered
|
||||||
if (link.issuerCertificate == null) {
|
if (link.issuerCertificate == null) {
|
||||||
|
link.certType = (i === 0) ? "self-signed" : "root CA";
|
||||||
break;
|
break;
|
||||||
} else if (link.issuerCertificate.fingerprint in existingList) {
|
} else if (link.issuerCertificate.fingerprint in existingList) {
|
||||||
|
// a root CA certificate is typically "signed by itself" (=> "self signed certificate") and thus the "issuerCertificate" is a reference to itself.
|
||||||
log.debug("cert", `[Last] ${link.issuerCertificate.fingerprint}`);
|
log.debug("cert", `[Last] ${link.issuerCertificate.fingerprint}`);
|
||||||
|
link.certType = (i === 0) ? "self-signed" : "root CA";
|
||||||
link.issuerCertificate = null;
|
link.issuerCertificate = null;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
link.certType = (i === 0) ? "server" : "intermediate CA";
|
||||||
link = link.issuerCertificate;
|
link = link.issuerCertificate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -266,6 +266,11 @@ optgroup {
|
|||||||
background-color: $dark-bg2;
|
background-color: $dark-bg2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.form-select:disabled {
|
||||||
|
color: rgba($dark-font-color, 0.7);
|
||||||
|
background-color: $dark-bg;
|
||||||
|
}
|
||||||
|
|
||||||
.form-control, .form-select {
|
.form-control, .form-select {
|
||||||
border-color: $dark-border-color;
|
border-color: $dark-border-color;
|
||||||
}
|
}
|
||||||
@@ -431,12 +436,12 @@ optgroup {
|
|||||||
.monitor-list {
|
.monitor-list {
|
||||||
&.scrollbar {
|
&.scrollbar {
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
height: calc(100% - 65px);
|
height: calc(100% - 107px);
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 770px) {
|
@media (max-width: 770px) {
|
||||||
&.scrollbar {
|
&.scrollbar {
|
||||||
height: calc(100% - 40px);
|
height: calc(100% - 97px);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -556,6 +561,31 @@ h5.settings-subheading::after {
|
|||||||
border-bottom: 1px solid $dark-border-color;
|
border-bottom: 1px solid $dark-border-color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$shadow-box-padding: 20px;
|
||||||
|
|
||||||
|
.shadow-box-with-fixed-bottom-bar {
|
||||||
|
padding-top: $shadow-box-padding;
|
||||||
|
padding-bottom: 0;
|
||||||
|
padding-right: $shadow-box-padding;
|
||||||
|
padding-left: $shadow-box-padding;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fixed-bottom-bar {
|
||||||
|
position: sticky;
|
||||||
|
bottom: 0;
|
||||||
|
margin-left: -$shadow-box-padding;
|
||||||
|
margin-right: -$shadow-box-padding;
|
||||||
|
z-index: 100;
|
||||||
|
background-color: rgba(white, 0.2);
|
||||||
|
backdrop-filter: blur(2px);
|
||||||
|
border-radius: 0 0 10px 10px;
|
||||||
|
|
||||||
|
.dark & {
|
||||||
|
background-color: rgba($dark-header-bg, 0.9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Localization
|
// Localization
|
||||||
|
|
||||||
@import "localization.scss";
|
@import "localization.scss";
|
||||||
|
@@ -1,6 +1,12 @@
|
|||||||
@import "vars.scss";
|
@import "vars.scss";
|
||||||
@import "node_modules/vue-multiselect/dist/vue-multiselect";
|
@import "node_modules/vue-multiselect/dist/vue-multiselect";
|
||||||
|
|
||||||
|
.multiselect {
|
||||||
|
.dark & {
|
||||||
|
color: $dark-font-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.multiselect__tags {
|
.multiselect__tags {
|
||||||
border-radius: 1.5rem;
|
border-radius: 1.5rem;
|
||||||
border: 1px solid #ced4da;
|
border: 1px solid #ced4da;
|
||||||
@@ -14,10 +20,12 @@
|
|||||||
|
|
||||||
.multiselect__option--highlight {
|
.multiselect__option--highlight {
|
||||||
background: $primary !important;
|
background: $primary !important;
|
||||||
|
color: $dark-font-color2 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.multiselect__option--highlight::after {
|
.multiselect__option--highlight::after {
|
||||||
background: $primary !important;
|
background: $primary !important;
|
||||||
|
color: $dark-font-color2 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.multiselect__tag {
|
.multiselect__tag {
|
||||||
@@ -61,6 +69,7 @@
|
|||||||
.multiselect__content-wrapper {
|
.multiselect__content-wrapper {
|
||||||
background-color: $dark-bg2;
|
background-color: $dark-bg2;
|
||||||
border-color: $dark-border-color;
|
border-color: $dark-border-color;
|
||||||
|
z-index: 150;
|
||||||
}
|
}
|
||||||
|
|
||||||
.multiselect--above .multiselect__content-wrapper {
|
.multiselect--above .multiselect__content-wrapper {
|
||||||
|
@@ -48,7 +48,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button
|
<button
|
||||||
id="monitor-submit-btn" class="btn btn-primary" type="submit"
|
id="monitor-submit-btn" class="btn btn-primary" type="submit"
|
||||||
@@ -60,7 +60,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div ref="keymodal" class="modal fade" tabindex="-1" data-bs-backdrop="static">
|
<div ref="keymodal" class="modal fade" tabindex="-1" data-bs-backdrop="static">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
@@ -159,6 +158,16 @@ export default {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/** Clear Form inputs */
|
||||||
|
clearForm() {
|
||||||
|
this.key = {
|
||||||
|
name: "",
|
||||||
|
expires: this.minDate,
|
||||||
|
active: 1,
|
||||||
|
};
|
||||||
|
this.noExpire = false;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
305
src/components/BadgeGeneratorDialog.vue
Normal file
305
src/components/BadgeGeneratorDialog.vue
Normal file
@@ -0,0 +1,305 @@
|
|||||||
|
<template>
|
||||||
|
<div ref="BadgeGeneratorModal" class="modal fade" tabindex="-1" data-bs-backdrop="static">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">
|
||||||
|
{{ $t("Badge Generator", [monitor.name]) }}
|
||||||
|
</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" />
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="type" class="form-label">{{ $t("Badge Type") }}</label>
|
||||||
|
<select id="type" v-model="badge.type" class="form-select">
|
||||||
|
<option value="status">status</option>
|
||||||
|
<option value="uptime">uptime</option>
|
||||||
|
<option value="ping">ping</option>
|
||||||
|
<option value="avg-response">avg-response</option>
|
||||||
|
<option value="cert-exp">cert-exp</option>
|
||||||
|
<option value="response">response</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if=" (parameters[badge.type || 'null'] || [] ).includes('duration') " class="mb-3">
|
||||||
|
<label for="duration" class="form-label">{{ $t("Badge Duration (in hours)") }}</label>
|
||||||
|
<input id="duration" v-model="badge.duration" type="number" min="0" placeholder="24" class="form-control">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if=" (parameters[badge.type || 'null'] || [] ).includes('label') " class="mb-3">
|
||||||
|
<label for="label" class="form-label">{{ $t("Badge Label") }}</label>
|
||||||
|
<input id="label" v-model="badge.label" type="text" class="form-control">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if=" (parameters[badge.type || 'null'] || [] ).includes('prefix') " class="mb-3">
|
||||||
|
<label for="prefix" class="form-label">{{ $t("Badge Prefix") }}</label>
|
||||||
|
<input id="prefix" v-model="badge.prefix" type="text" class="form-control">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if=" (parameters[badge.type || 'null'] || [] ).includes('suffix') " class="mb-3">
|
||||||
|
<label for="suffix" class="form-label">{{ $t("Badge Suffix") }}</label>
|
||||||
|
<input id="suffix" v-model="badge.suffix" type="text" placeholder="%" class="form-control">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if=" (parameters[badge.type || 'null'] || [] ).includes('labelColor') " class="mb-3">
|
||||||
|
<label for="labelColor" class="form-label">{{ $t("Badge Label Color") }}</label>
|
||||||
|
<input id="labelColor" v-model="badge.labelColor" type="text" placeholder="#555" class="form-control">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if=" (parameters[badge.type || 'null'] || [] ).includes('color') " class="mb-3">
|
||||||
|
<label for="color" class="form-label">{{ $t("Badge Color") }}</label>
|
||||||
|
<input id="color" v-model="badge.color" type="text" :placeholder="badgeConstants.defaultUpColor" class="form-control">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if=" (parameters[badge.type || 'null'] || [] ).includes('labelPrefix') " class="mb-3">
|
||||||
|
<label for="labelPrefix" class="form-label">{{ $t("Badge Label Prefix") }}</label>
|
||||||
|
<input id="labelPrefix" v-model="badge.labelPrefix" type="text" class="form-control">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if=" (parameters[badge.type || 'null'] || [] ).includes('labelSuffix') " class="mb-3">
|
||||||
|
<label for="labelSuffix" class="form-label">{{ $t("Badge Label Suffix") }}</label>
|
||||||
|
<input id="labelSuffix" v-model="badge.labelSuffix" type="text" placeholder="h" class="form-control">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if=" (parameters[badge.type || 'null'] || [] ).includes('upColor') " class="mb-3">
|
||||||
|
<label for="upColor" class="form-label">{{ $t("Badge Up Color") }}</label>
|
||||||
|
<input id="upColor" v-model="badge.upColor" type="text" class="form-control" :placeholder="badgeConstants.defaultUpColor">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if=" (parameters[badge.type || 'null'] || [] ).includes('downColor') " class="mb-3">
|
||||||
|
<label for="downColor" class="form-label">{{ $t("Badge Down Color") }}</label>
|
||||||
|
<input id="downColor" v-model="badge.downColor" type="text" class="form-control" :placeholder="badgeConstants.defaultDownColor">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if=" (parameters[badge.type || 'null'] || [] ).includes('pendingColor') " class="mb-3">
|
||||||
|
<label for="pendingColor" class="form-label">{{ $t("Badge Pending Color") }}</label>
|
||||||
|
<input id="pendingColor" v-model="badge.pendingColor" type="text" class="form-control" :placeholder="badgeConstants.defaultPendingColor">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if=" (parameters[badge.type || 'null'] || [] ).includes('maintenanceColor') " class="mb-3">
|
||||||
|
<label for="maintenanceColor" class="form-label">{{ $t("Badge Maintenance Color") }}</label>
|
||||||
|
<input id="maintenanceColor" v-model="badge.maintenanceColor" type="text" class="form-control" :placeholder="badgeConstants.defaultMaintenanceColor">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if=" (parameters[badge.type || 'null'] || [] ).includes('warnColor') " class="mb-3">
|
||||||
|
<label for="warnColor" class="form-label">{{ $t("Badge Warn Color") }}</label>
|
||||||
|
<input id="warnColor" v-model="badge.warnColor" type="text" class="form-control" :placeholder="badgeConstants.defaultMaintenanceColor">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if=" (parameters[badge.type || 'null'] || [] ).includes('warnDays') " class="mb-3">
|
||||||
|
<label for="warnDays" class="form-label">{{ $t("Badge Warn Days") }}</label>
|
||||||
|
<input id="warnDays" v-model="badge.warnDays" type="number" min="0" class="form-control" :placeholder="badgeConstants.defaultCertExpireWarnDays">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if=" (parameters[badge.type || 'null'] || [] ).includes('downDays') " class="mb-3">
|
||||||
|
<label for="downDays" class="form-label">{{ $t("Badge Down Days") }}</label>
|
||||||
|
<input id="downDays" v-model="badge.downDays" type="number" min="0" class="form-control" :placeholder="badgeConstants.defaultCertExpireDownDays">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="style" class="form-label">{{ $t("Badge Style") }}</label>
|
||||||
|
<select id="style" v-model="badge.style" class="form-select">
|
||||||
|
<option value="plastic">plastic</option>
|
||||||
|
<option value="flat">flat</option>
|
||||||
|
<option value="flat-square">flat-square</option>
|
||||||
|
<option value="for-the-badge">for-the-badge</option>
|
||||||
|
<option value="social">social</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="value" class="form-label">{{ $t("Badge value (For Testing only.)") }}</label>
|
||||||
|
<input id="value" v-model="badge.value" type="text" class="form-control">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3 pt-3 d-flex justify-content-center">
|
||||||
|
<img :src="badgeURL" :alt="$t('Badge Preview')">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="my-3">
|
||||||
|
<label for="badge-url" class="form-label">{{ $t("Badge URL") }}</label>
|
||||||
|
<CopyableInput id="badge-url" v-model="badgeURL" type="url" disabled="disabled" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="submit" class="btn btn-danger" data-bs-dismiss="modal">
|
||||||
|
{{ $t("Close") }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { Modal } from "bootstrap";
|
||||||
|
import CopyableInput from "./CopyableInput.vue";
|
||||||
|
import { default as serverConfig } from "../../server/config.js";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
CopyableInput
|
||||||
|
},
|
||||||
|
props: {},
|
||||||
|
emits: [],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
model: null,
|
||||||
|
processing: false,
|
||||||
|
monitor: {
|
||||||
|
id: null,
|
||||||
|
name: null,
|
||||||
|
},
|
||||||
|
badge: {
|
||||||
|
type: "status",
|
||||||
|
duration: null,
|
||||||
|
label: null,
|
||||||
|
prefix: null,
|
||||||
|
suffix: null,
|
||||||
|
labelColor: null,
|
||||||
|
color: null,
|
||||||
|
labelPrefix: null,
|
||||||
|
labelSuffix: null,
|
||||||
|
upColor: null,
|
||||||
|
downColor: null,
|
||||||
|
pendingColor: null,
|
||||||
|
maintenanceColor: null,
|
||||||
|
warnColor: null,
|
||||||
|
warnDays: null,
|
||||||
|
downDays: null,
|
||||||
|
style: "flat",
|
||||||
|
value: null,
|
||||||
|
},
|
||||||
|
parameters: {
|
||||||
|
status: [
|
||||||
|
"upLabel",
|
||||||
|
"downLabel",
|
||||||
|
"pendingLabel",
|
||||||
|
"maintenanceLabel",
|
||||||
|
"upColor",
|
||||||
|
"downColor",
|
||||||
|
"pendingColor",
|
||||||
|
"maintenanceColor",
|
||||||
|
],
|
||||||
|
uptime: [
|
||||||
|
"duration",
|
||||||
|
"labelPrefix",
|
||||||
|
"labelSuffix",
|
||||||
|
"prefix",
|
||||||
|
"suffix",
|
||||||
|
"color",
|
||||||
|
"labelColor",
|
||||||
|
],
|
||||||
|
ping: [
|
||||||
|
"duration",
|
||||||
|
"labelPrefix",
|
||||||
|
"labelSuffix",
|
||||||
|
"prefix",
|
||||||
|
"suffix",
|
||||||
|
"color",
|
||||||
|
"labelColor",
|
||||||
|
],
|
||||||
|
"avg-response": [
|
||||||
|
"duration",
|
||||||
|
"labelPrefix",
|
||||||
|
"labelSuffix",
|
||||||
|
"prefix",
|
||||||
|
"suffix",
|
||||||
|
"color",
|
||||||
|
"labelColor",
|
||||||
|
],
|
||||||
|
"cert-exp": [
|
||||||
|
"labelPrefix",
|
||||||
|
"labelSuffix",
|
||||||
|
"prefix",
|
||||||
|
"suffix",
|
||||||
|
"upColor",
|
||||||
|
"warnColor",
|
||||||
|
"downColor",
|
||||||
|
"warnDays",
|
||||||
|
"downDays",
|
||||||
|
"labelColor",
|
||||||
|
],
|
||||||
|
response: [
|
||||||
|
"labelPrefix",
|
||||||
|
"labelSuffix",
|
||||||
|
"prefix",
|
||||||
|
"suffix",
|
||||||
|
"color",
|
||||||
|
"labelColor",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
badgeConstants: serverConfig.badgeConstants,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
badgeURL() {
|
||||||
|
if (!this.monitor.id || !this.badge.type) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let badgeURL = this.$root.baseURL + "/api/badge/" + this.monitor.id + "/" + this.badge.type;
|
||||||
|
|
||||||
|
let parameterList = {};
|
||||||
|
|
||||||
|
for (let parameter of this.parameters[this.badge.type] || []) {
|
||||||
|
if (parameter === "duration" && this.badge.duration) {
|
||||||
|
badgeURL += "/" + this.badge.duration;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.badge[parameter]) {
|
||||||
|
parameterList[parameter] = this.badge[parameter];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let parameter of [ "label", "style", "value" ]) {
|
||||||
|
if (parameter === "style" && this.badge.style === "flat") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.badge[parameter]) {
|
||||||
|
parameterList[parameter] = this.badge[parameter];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Object.keys(parameterList).length > 0) {
|
||||||
|
return badgeURL + "?" + new URLSearchParams(parameterList);
|
||||||
|
}
|
||||||
|
|
||||||
|
return badgeURL;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
this.BadgeGeneratorModal = new Modal(this.$refs.BadgeGeneratorModal);
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
/**
|
||||||
|
* Setting monitor
|
||||||
|
* @param {number} monitorId ID of monitor
|
||||||
|
* @param {string} monitorName Name of monitor
|
||||||
|
*/
|
||||||
|
show(monitorId, monitorName) {
|
||||||
|
this.monitor = {
|
||||||
|
id: monitorId,
|
||||||
|
name: monitorName,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.BadgeGeneratorModal.show();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
@import "../assets/vars.scss";
|
||||||
|
|
||||||
|
.dark {
|
||||||
|
.modal-dialog .form-text, .modal-dialog p {
|
||||||
|
color: $dark-font-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
@@ -13,6 +13,9 @@
|
|||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
>
|
>
|
||||||
|
|
||||||
|
<!-- A hidden textarea for copying text on non-https -->
|
||||||
|
<textarea ref="hiddenTextarea" style="position: fixed; left: -999999px; top: -999999px;"></textarea>
|
||||||
|
|
||||||
<a class="btn btn-outline-primary" @click="copyToClipboard(model)">
|
<a class="btn btn-outline-primary" @click="copyToClipboard(model)">
|
||||||
<font-awesome-icon :icon="icon" />
|
<font-awesome-icon :icon="icon" />
|
||||||
</a>
|
</a>
|
||||||
@@ -111,24 +114,19 @@ export default {
|
|||||||
}, 3000);
|
}, 3000);
|
||||||
|
|
||||||
// navigator clipboard api needs a secure context (https)
|
// navigator clipboard api needs a secure context (https)
|
||||||
|
// For http, use the text area method (else part)
|
||||||
if (navigator.clipboard && window.isSecureContext) {
|
if (navigator.clipboard && window.isSecureContext) {
|
||||||
// navigator clipboard api method'
|
// navigator clipboard api method'
|
||||||
return navigator.clipboard.writeText(textToCopy);
|
return navigator.clipboard.writeText(textToCopy);
|
||||||
} else {
|
} else {
|
||||||
// text area method
|
// text area method
|
||||||
let textArea = document.createElement("textarea");
|
let textArea = this.$refs.hiddenTextarea;
|
||||||
textArea.value = textToCopy;
|
textArea.value = textToCopy;
|
||||||
// make the textarea out of viewport
|
|
||||||
textArea.style.position = "fixed";
|
|
||||||
textArea.style.left = "-999999px";
|
|
||||||
textArea.style.top = "-999999px";
|
|
||||||
document.body.appendChild(textArea);
|
|
||||||
textArea.focus();
|
textArea.focus();
|
||||||
textArea.select();
|
textArea.select();
|
||||||
return new Promise((res, rej) => {
|
return new Promise((res, rej) => {
|
||||||
// here the magic happens
|
// here the magic happens
|
||||||
document.execCommand("copy") ? res() : rej();
|
document.execCommand("copy") ? res() : rej();
|
||||||
textArea.remove();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,16 +3,23 @@
|
|||||||
<div v-if="maintenance.strategy === 'manual'" class="timeslot">
|
<div v-if="maintenance.strategy === 'manual'" class="timeslot">
|
||||||
{{ $t("Manual") }}
|
{{ $t("Manual") }}
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="maintenance.timeslotList.length > 0" class="timeslot">
|
<div v-else-if="maintenance.timeslotList.length > 0">
|
||||||
{{ maintenance.timeslotList[0].startDateServerTimezone }}
|
<div class="timeslot">
|
||||||
|
{{ startDateTime }}
|
||||||
<span class="to">-</span>
|
<span class="to">-</span>
|
||||||
{{ maintenance.timeslotList[0].endDateServerTimezone }}
|
{{ endDateTime }}
|
||||||
(UTC{{ maintenance.timeslotList[0].serverTimezoneOffset }})
|
</div>
|
||||||
|
<div class="timeslot">
|
||||||
|
UTC{{ maintenance.timezoneOffset }} <span v-if="maintenance.timezone !== 'UTC'">{{ maintenance.timezone }}</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
import { SQL_DATETIME_FORMAT_WITHOUT_SECOND } from "../util.ts";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
maintenance: {
|
maintenance: {
|
||||||
@@ -20,6 +27,14 @@ export default {
|
|||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
startDateTime() {
|
||||||
|
return dayjs(this.maintenance.timeslotList[0].startDate).tz(this.maintenance.timezone).format(SQL_DATETIME_FORMAT_WITHOUT_SECOND);
|
||||||
|
},
|
||||||
|
endDateTime() {
|
||||||
|
return dayjs(this.maintenance.timeslotList[0].endDate).tz(this.maintenance.timezone).format(SQL_DATETIME_FORMAT_WITHOUT_SECOND);
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -31,6 +46,7 @@ export default {
|
|||||||
background-color: rgba(255, 255, 255, 0.5);
|
background-color: rgba(255, 255, 255, 0.5);
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
|
margin-right: 5px;
|
||||||
|
|
||||||
.to {
|
.to {
|
||||||
margin: 0 6px;
|
margin: 0 6px;
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="shadow-box mb-3" :style="boxStyle">
|
<div class="shadow-box mb-3" :style="boxStyle">
|
||||||
<div class="list-header">
|
<div class="list-header">
|
||||||
|
<div class="header-top">
|
||||||
<div class="placeholder"></div>
|
<div class="placeholder"></div>
|
||||||
<div class="search-wrapper">
|
<div class="search-wrapper">
|
||||||
<a v-if="searchText == ''" class="search-icon">
|
<a v-if="searchText == ''" class="search-icon">
|
||||||
@@ -10,52 +11,39 @@
|
|||||||
<font-awesome-icon icon="times" />
|
<font-awesome-icon icon="times" />
|
||||||
</a>
|
</a>
|
||||||
<form>
|
<form>
|
||||||
<input v-model="searchText" class="form-control search-input" :placeholder="$t('Search...')" autocomplete="off" />
|
<input
|
||||||
|
v-model="searchText" class="form-control search-input" :placeholder="$t('Search...')"
|
||||||
|
autocomplete="off"
|
||||||
|
/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="header-filter">
|
||||||
|
<MonitorListFilter :filterState="filterState" @update-filter="updateFilter" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="monitor-list" :class="{ scrollbar: scrollbar }">
|
<div class="monitor-list" :class="{ scrollbar: scrollbar }">
|
||||||
<div v-if="Object.keys($root.monitorList).length === 0" class="text-center mt-3">
|
<div v-if="Object.keys($root.monitorList).length === 0" class="text-center mt-3">
|
||||||
{{ $t("No Monitors, please") }} <router-link to="/add">{{ $t("add one") }}</router-link>
|
{{ $t("No Monitors, please") }} <router-link to="/add">{{ $t("add one") }}</router-link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<router-link v-for="(item, index) in sortedMonitorList" :key="index" :to="monitorURL(item.id)" class="item" :class="{ 'disabled': ! item.active }" :title="item.description">
|
<MonitorListItem
|
||||||
<div class="row">
|
v-for="(item, index) in sortedMonitorList" :key="index" :monitor="item"
|
||||||
<div class="col-9 col-md-8 small-padding" :class="{ 'monitor-item': $root.userHeartbeatBar == 'bottom' || $root.userHeartbeatBar == 'none' }">
|
:isSearch="searchText !== ''"
|
||||||
<div class="info">
|
/>
|
||||||
<Uptime :monitor="item" type="24" :pill="true" />
|
|
||||||
{{ item.name }}
|
|
||||||
</div>
|
|
||||||
<div class="tags">
|
|
||||||
<Tag v-for="tag in item.tags" :key="tag" :item="tag" :size="'sm'" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div v-show="$root.userHeartbeatBar == 'normal'" :key="$root.userHeartbeatBar" class="col-3 col-md-4">
|
|
||||||
<HeartbeatBar size="small" :monitor-id="item.id" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="$root.userHeartbeatBar == 'bottom'" class="row">
|
|
||||||
<div class="col-12 bottom-style">
|
|
||||||
<HeartbeatBar size="small" :monitor-id="item.id" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</router-link>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import HeartbeatBar from "../components/HeartbeatBar.vue";
|
import MonitorListItem from "../components/MonitorListItem.vue";
|
||||||
import Tag from "../components/Tag.vue";
|
import MonitorListFilter from "./MonitorListFilter.vue";
|
||||||
import Uptime from "../components/Uptime.vue";
|
|
||||||
import { getMonitorRelativeURL } from "../util.ts";
|
import { getMonitorRelativeURL } from "../util.ts";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
Uptime,
|
MonitorListItem,
|
||||||
HeartbeatBar,
|
MonitorListFilter,
|
||||||
Tag,
|
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
/** Should the scrollbar be shown */
|
/** Should the scrollbar be shown */
|
||||||
@@ -67,6 +55,11 @@ export default {
|
|||||||
return {
|
return {
|
||||||
searchText: "",
|
searchText: "",
|
||||||
windowTop: 0,
|
windowTop: 0,
|
||||||
|
filterState: {
|
||||||
|
status: null,
|
||||||
|
active: null,
|
||||||
|
tags: null,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -91,6 +84,20 @@ export default {
|
|||||||
sortedMonitorList() {
|
sortedMonitorList() {
|
||||||
let result = Object.values(this.$root.monitorList);
|
let result = Object.values(this.$root.monitorList);
|
||||||
|
|
||||||
|
// Simple filter by search text
|
||||||
|
// finds monitor name, tag name or tag value
|
||||||
|
if (this.searchText !== "") {
|
||||||
|
const loweredSearchText = this.searchText.toLowerCase();
|
||||||
|
result = result.filter(monitor => {
|
||||||
|
return monitor.name.toLowerCase().includes(loweredSearchText)
|
||||||
|
|| monitor.tags.find(tag => tag.name.toLowerCase().includes(loweredSearchText)
|
||||||
|
|| tag.value?.toLowerCase().includes(loweredSearchText));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
result = result.filter(monitor => monitor.parent === null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter result by active state, weight and alphabetical
|
||||||
result.sort((m1, m2) => {
|
result.sort((m1, m2) => {
|
||||||
|
|
||||||
if (m1.active !== m2.active) {
|
if (m1.active !== m2.active) {
|
||||||
@@ -116,14 +123,24 @@ export default {
|
|||||||
return m1.name.localeCompare(m2.name);
|
return m1.name.localeCompare(m2.name);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Simple filter by search text
|
if (this.filterState.status != null && this.filterState.status.length > 0) {
|
||||||
// finds monitor name, tag name or tag value
|
result.map(monitor => {
|
||||||
if (this.searchText !== "") {
|
if (monitor.id in this.$root.lastHeartbeatList && this.$root.lastHeartbeatList[monitor.id]) {
|
||||||
const loweredSearchText = this.searchText.toLowerCase();
|
monitor.status = this.$root.lastHeartbeatList[monitor.id].status;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
result = result.filter(monitor => this.filterState.status.includes(monitor.status));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.filterState.active != null && this.filterState.active.length > 0) {
|
||||||
|
result = result.filter(monitor => this.filterState.active.includes(monitor.active));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.filterState.tags != null && this.filterState.tags.length > 0) {
|
||||||
result = result.filter(monitor => {
|
result = result.filter(monitor => {
|
||||||
return monitor.name.toLowerCase().includes(loweredSearchText)
|
return monitor.tags.map(tag => tag.tag_id) // convert to array of tag IDs
|
||||||
|| monitor.tags.find(tag => tag.name.toLowerCase().includes(loweredSearchText)
|
.filter(monitorTagId => this.filterState.tags.includes(monitorTagId)) // perform Array Intersaction between filter and monitor's tags
|
||||||
|| tag.value?.toLowerCase().includes(loweredSearchText));
|
.length > 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,7 +173,14 @@ export default {
|
|||||||
/** Clear the search bar */
|
/** Clear the search bar */
|
||||||
clearSearchText() {
|
clearSearchText() {
|
||||||
this.searchText = "";
|
this.searchText = "";
|
||||||
}
|
},
|
||||||
|
/**
|
||||||
|
* Update the MonitorList Filter
|
||||||
|
* @param {object} newFilter Object with new filter
|
||||||
|
*/
|
||||||
|
updateFilter(newFilter) {
|
||||||
|
this.filterState = newFilter;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@@ -181,8 +205,6 @@ export default {
|
|||||||
margin: -10px;
|
margin: -10px;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
|
|
||||||
.dark & {
|
.dark & {
|
||||||
background-color: $dark-header-bg;
|
background-color: $dark-header-bg;
|
||||||
@@ -190,6 +212,17 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.header-top {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-filter {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 770px) {
|
@media (max-width: 770px) {
|
||||||
.list-header {
|
.list-header {
|
||||||
margin: -20px;
|
margin: -20px;
|
||||||
@@ -238,5 +271,4 @@ export default {
|
|||||||
padding-left: 67px;
|
padding-left: 67px;
|
||||||
margin-top: 5px;
|
margin-top: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
284
src/components/MonitorListFilter.vue
Normal file
284
src/components/MonitorListFilter.vue
Normal file
@@ -0,0 +1,284 @@
|
|||||||
|
<template>
|
||||||
|
<div class="px-2 pt-2 d-flex">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:title="$t('Clear current filters')"
|
||||||
|
class="clear-filters-btn btn"
|
||||||
|
:class="{ 'active': numFiltersActive > 0}"
|
||||||
|
tabindex="0"
|
||||||
|
:disabled="numFiltersActive === 0"
|
||||||
|
@click="clearFilters"
|
||||||
|
>
|
||||||
|
<font-awesome-icon icon="stream" />
|
||||||
|
<span v-if="numFiltersActive > 0" class="px-1 fw-bold">{{ numFiltersActive }}</span>
|
||||||
|
<font-awesome-icon v-if="numFiltersActive > 0" icon="times" />
|
||||||
|
</button>
|
||||||
|
<MonitorListFilterDropdown
|
||||||
|
:filterActive="filterState.status?.length > 0"
|
||||||
|
>
|
||||||
|
<template #status>
|
||||||
|
<Status v-if="filterState.status?.length === 1" :status="filterState.status[0]" />
|
||||||
|
<span v-else>
|
||||||
|
{{ $t('Status') }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<template #dropdown>
|
||||||
|
<li>
|
||||||
|
<div class="dropdown-item" tabindex="0" @click.stop="toggleStatusFilter(1)">
|
||||||
|
<div class="d-flex align-items-center justify-content-between">
|
||||||
|
<Status :status="1" />
|
||||||
|
<span class="ps-3">
|
||||||
|
{{ $root.stats.up }}
|
||||||
|
<span v-if="filterState.status?.includes(1)" class="px-1 filter-active">
|
||||||
|
<font-awesome-icon icon="check" />
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<div class="dropdown-item" tabindex="0" @click.stop="toggleStatusFilter(0)">
|
||||||
|
<div class="d-flex align-items-center justify-content-between">
|
||||||
|
<Status :status="0" />
|
||||||
|
<span class="ps-3">
|
||||||
|
{{ $root.stats.down }}
|
||||||
|
<span v-if="filterState.status?.includes(0)" class="px-1 filter-active">
|
||||||
|
<font-awesome-icon icon="check" />
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<div class="dropdown-item" tabindex="0" @click.stop="toggleStatusFilter(2)">
|
||||||
|
<div class="d-flex align-items-center justify-content-between">
|
||||||
|
<Status :status="2" />
|
||||||
|
<span class="ps-3">
|
||||||
|
{{ $root.stats.pending }}
|
||||||
|
<span v-if="filterState.status?.includes(2)" class="px-1 filter-active">
|
||||||
|
<font-awesome-icon icon="check" />
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<div class="dropdown-item" tabindex="0" @click.stop="toggleStatusFilter(3)">
|
||||||
|
<div class="d-flex align-items-center justify-content-between">
|
||||||
|
<Status :status="3" />
|
||||||
|
<span class="ps-3">
|
||||||
|
{{ $root.stats.maintenance }}
|
||||||
|
<span v-if="filterState.status?.includes(3)" class="px-1 filter-active">
|
||||||
|
<font-awesome-icon icon="check" />
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</template>
|
||||||
|
</MonitorListFilterDropdown>
|
||||||
|
<MonitorListFilterDropdown :filterActive="filterState.active?.length > 0">
|
||||||
|
<template #status>
|
||||||
|
<span v-if="filterState.active?.length === 1">
|
||||||
|
<span v-if="filterState.active[0]">{{ $t("Running") }}</span>
|
||||||
|
<span v-else>{{ $t("filterActivePaused") }}</span>
|
||||||
|
</span>
|
||||||
|
<span v-else>
|
||||||
|
{{ $t("filterActive") }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<template #dropdown>
|
||||||
|
<li>
|
||||||
|
<div class="dropdown-item" tabindex="0" @click.stop="toggleActiveFilter(true)">
|
||||||
|
<div class="d-flex align-items-center justify-content-between">
|
||||||
|
<span>{{ $t("Running") }}</span>
|
||||||
|
<span class="ps-3">
|
||||||
|
{{ $root.stats.active }}
|
||||||
|
<span v-if="filterState.active?.includes(true)" class="px-1 filter-active">
|
||||||
|
<font-awesome-icon icon="check" />
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<div class="dropdown-item" tabindex="0" @click.stop="toggleActiveFilter(false)">
|
||||||
|
<div class="d-flex align-items-center justify-content-between">
|
||||||
|
<span>{{ $t("filterActivePaused") }}</span>
|
||||||
|
<span class="ps-3">
|
||||||
|
{{ $root.stats.pause }}
|
||||||
|
<span v-if="filterState.active?.includes(false)" class="px-1 filter-active">
|
||||||
|
<font-awesome-icon icon="check" />
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</template>
|
||||||
|
</MonitorListFilterDropdown>
|
||||||
|
<MonitorListFilterDropdown :filterActive="filterState.tags?.length > 0">
|
||||||
|
<template #status>
|
||||||
|
<Tag
|
||||||
|
v-if="filterState.tags?.length === 1"
|
||||||
|
:item="tagsList.find(tag => tag.id === filterState.tags[0])"
|
||||||
|
:size="'sm'"
|
||||||
|
/>
|
||||||
|
<span v-else>
|
||||||
|
{{ $t('Tags') }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<template #dropdown>
|
||||||
|
<li v-for="tag in tagsList" :key="tag.id">
|
||||||
|
<div class="dropdown-item" tabindex="0" @click.stop="toggleTagFilter(tag)">
|
||||||
|
<div class="d-flex align-items-center justify-content-between">
|
||||||
|
<span><Tag :item="tag" :size="'sm'" /></span>
|
||||||
|
<span class="ps-3">
|
||||||
|
{{ getTaggedMonitorCount(tag) }}
|
||||||
|
<span v-if="filterState.tags?.includes(tag.id)" class="px-1 filter-active">
|
||||||
|
<font-awesome-icon icon="check" />
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</template>
|
||||||
|
</MonitorListFilterDropdown>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import MonitorListFilterDropdown from "./MonitorListFilterDropdown.vue";
|
||||||
|
import Status from "./Status.vue";
|
||||||
|
import Tag from "./Tag.vue";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
MonitorListFilterDropdown,
|
||||||
|
Status,
|
||||||
|
Tag,
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
filterState: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
emits: [ "updateFilter" ],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
tagsList: [],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
numFiltersActive() {
|
||||||
|
let num = 0;
|
||||||
|
|
||||||
|
Object.values(this.filterState).forEach(item => {
|
||||||
|
if (item != null && item.length > 0) {
|
||||||
|
num += 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.getExistingTags();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
toggleStatusFilter(status) {
|
||||||
|
let newFilter = {
|
||||||
|
...this.filterState
|
||||||
|
};
|
||||||
|
|
||||||
|
if (newFilter.status == null) {
|
||||||
|
newFilter.status = [ status ];
|
||||||
|
} else {
|
||||||
|
if (newFilter.status.includes(status)) {
|
||||||
|
newFilter.status = newFilter.status.filter(item => item !== status);
|
||||||
|
} else {
|
||||||
|
newFilter.status.push(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.$emit("updateFilter", newFilter);
|
||||||
|
},
|
||||||
|
toggleActiveFilter(active) {
|
||||||
|
let newFilter = {
|
||||||
|
...this.filterState
|
||||||
|
};
|
||||||
|
|
||||||
|
if (newFilter.active == null) {
|
||||||
|
newFilter.active = [ active ];
|
||||||
|
} else {
|
||||||
|
if (newFilter.active.includes(active)) {
|
||||||
|
newFilter.active = newFilter.active.filter(item => item !== active);
|
||||||
|
} else {
|
||||||
|
newFilter.active.push(active);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.$emit("updateFilter", newFilter);
|
||||||
|
},
|
||||||
|
toggleTagFilter(tag) {
|
||||||
|
let newFilter = {
|
||||||
|
...this.filterState
|
||||||
|
};
|
||||||
|
|
||||||
|
if (newFilter.tags == null) {
|
||||||
|
newFilter.tags = [ tag.id ];
|
||||||
|
} else {
|
||||||
|
if (newFilter.tags.includes(tag.id)) {
|
||||||
|
newFilter.tags = newFilter.tags.filter(item => item !== tag.id);
|
||||||
|
} else {
|
||||||
|
newFilter.tags.push(tag.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.$emit("updateFilter", newFilter);
|
||||||
|
},
|
||||||
|
clearFilters() {
|
||||||
|
this.$emit("updateFilter", {
|
||||||
|
status: null,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getExistingTags() {
|
||||||
|
this.$root.getSocket().emit("getTags", (res) => {
|
||||||
|
if (res.ok) {
|
||||||
|
this.tagsList = res.tags;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getTaggedMonitorCount(tag) {
|
||||||
|
return Object.values(this.$root.monitorList).filter(monitor => {
|
||||||
|
return monitor.tags.find(monitorTag => monitorTag.tag_id === tag.id);
|
||||||
|
}).length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
@import "../assets/vars.scss";
|
||||||
|
|
||||||
|
.clear-filters-btn {
|
||||||
|
font-size: 0.8em;
|
||||||
|
margin-right: 5px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 2px 10px;
|
||||||
|
border-radius: 16px;
|
||||||
|
background-color: transparent;
|
||||||
|
|
||||||
|
.dark & {
|
||||||
|
color: $dark-font-color;
|
||||||
|
border: 1px solid $dark-font-color2;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
border: 1px solid $highlight;
|
||||||
|
background-color: $highlight-white;
|
||||||
|
|
||||||
|
.dark & {
|
||||||
|
background-color: $dark-font-color2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
131
src/components/MonitorListFilterDropdown.vue
Normal file
131
src/components/MonitorListFilterDropdown.vue
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
<template>
|
||||||
|
<div class="dropdown" @focusin="open = true" @focusout="handleFocusOut">
|
||||||
|
<button type="button" class="filter-dropdown-status" :class="{ 'active': filterActive }" tabindex="0">
|
||||||
|
<div class="px-1 d-flex align-items-center">
|
||||||
|
<slot name="status"></slot>
|
||||||
|
</div>
|
||||||
|
<span class="px-1">
|
||||||
|
<font-awesome-icon icon="angle-down" />
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
<ul class="filter-dropdown-menu" :class="{ 'open': open }">
|
||||||
|
<slot name="dropdown"></slot>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
filterActive: {
|
||||||
|
type: Boolean,
|
||||||
|
required: true,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
open: false
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
handleFocusOut(e) {
|
||||||
|
if (e.relatedTarget != null && this.$el.contains(e.relatedTarget)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.open = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
@import "../assets/vars.scss";
|
||||||
|
|
||||||
|
.filter-dropdown-menu {
|
||||||
|
z-index: 100;
|
||||||
|
transition: all 0.2s;
|
||||||
|
padding: 5px 0 !important;
|
||||||
|
border-radius: 16px;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
position: absolute;
|
||||||
|
inset: 0 auto auto 0;
|
||||||
|
margin: 0;
|
||||||
|
transform: translate(0, 36px);
|
||||||
|
box-shadow: 0 15px 70px rgba(0, 0, 0, 0.1);
|
||||||
|
visibility: hidden;
|
||||||
|
list-style: none;
|
||||||
|
height: 0;
|
||||||
|
opacity: 0;
|
||||||
|
background: white;
|
||||||
|
|
||||||
|
&.open {
|
||||||
|
height: unset;
|
||||||
|
visibility: inherit;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-item {
|
||||||
|
padding: 5px 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-item:focus {
|
||||||
|
background: $highlight-white;
|
||||||
|
|
||||||
|
.dark & {
|
||||||
|
background: $dark-bg2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark & {
|
||||||
|
background-color: $dark-bg;
|
||||||
|
color: $dark-font-color;
|
||||||
|
border-color: $dark-border-color;
|
||||||
|
|
||||||
|
.dropdown-item {
|
||||||
|
color: $dark-font-color;
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
color: $dark-font-color2;
|
||||||
|
background-color: $highlight !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: $dark-bg2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-dropdown-status {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 4px 10px;
|
||||||
|
margin-left: 5px;
|
||||||
|
border: 1px solid #ced4da;
|
||||||
|
border-radius: 25px;
|
||||||
|
background-color: transparent;
|
||||||
|
|
||||||
|
.dark & {
|
||||||
|
color: $dark-font-color;
|
||||||
|
border: 1px solid $dark-font-color2;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
border: 1px solid $highlight;
|
||||||
|
background-color: $highlight-white;
|
||||||
|
|
||||||
|
.dark & {
|
||||||
|
background-color: $dark-font-color2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-active {
|
||||||
|
color: $highlight;
|
||||||
|
}
|
||||||
|
</style>
|
204
src/components/MonitorListItem.vue
Normal file
204
src/components/MonitorListItem.vue
Normal file
@@ -0,0 +1,204 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<router-link :to="monitorURL(monitor.id)" class="item" :class="{ 'disabled': ! monitor.active }">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-9 col-md-8 small-padding" :class="{ 'monitor-item': $root.userHeartbeatBar == 'bottom' || $root.userHeartbeatBar == 'none' }">
|
||||||
|
<div class="info" :style="depthMargin">
|
||||||
|
<Uptime :monitor="monitor" type="24" :pill="true" />
|
||||||
|
<span v-if="hasChildren" class="collapse-padding" @click.prevent="changeCollapsed">
|
||||||
|
<font-awesome-icon icon="chevron-down" class="animated" :class="{ collapsed: isCollapsed}" />
|
||||||
|
</span>
|
||||||
|
{{ monitorName }}
|
||||||
|
</div>
|
||||||
|
<div class="tags">
|
||||||
|
<Tag v-for="tag in monitor.tags" :key="tag" :item="tag" :size="'sm'" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-show="$root.userHeartbeatBar == 'normal'" :key="$root.userHeartbeatBar" class="col-3 col-md-4">
|
||||||
|
<HeartbeatBar size="small" :monitor-id="monitor.id" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="$root.userHeartbeatBar == 'bottom'" class="row">
|
||||||
|
<div class="col-12 bottom-style">
|
||||||
|
<HeartbeatBar size="small" :monitor-id="monitor.id" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</router-link>
|
||||||
|
|
||||||
|
<transition name="slide-fade-up">
|
||||||
|
<div v-if="!isCollapsed" class="childs">
|
||||||
|
<MonitorListItem v-for="(item, index) in sortedChildMonitorList" :key="index" :monitor="item" :isSearch="isSearch" :depth="depth + 1" />
|
||||||
|
</div>
|
||||||
|
</transition>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import HeartbeatBar from "../components/HeartbeatBar.vue";
|
||||||
|
import Tag from "../components/Tag.vue";
|
||||||
|
import Uptime from "../components/Uptime.vue";
|
||||||
|
import { getMonitorRelativeURL } from "../util.ts";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "MonitorListItem",
|
||||||
|
components: {
|
||||||
|
Uptime,
|
||||||
|
HeartbeatBar,
|
||||||
|
Tag,
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
/** Monitor this represents */
|
||||||
|
monitor: {
|
||||||
|
type: Object,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
/** If the user is currently searching */
|
||||||
|
isSearch: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
/** How many ancestors are above this monitor */
|
||||||
|
depth: {
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
isCollapsed: true,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
sortedChildMonitorList() {
|
||||||
|
let result = Object.values(this.$root.monitorList);
|
||||||
|
|
||||||
|
result = result.filter(childMonitor => childMonitor.parent === this.monitor.id);
|
||||||
|
|
||||||
|
result.sort((m1, m2) => {
|
||||||
|
|
||||||
|
if (m1.active !== m2.active) {
|
||||||
|
if (m1.active === 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m2.active === 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m1.weight !== m2.weight) {
|
||||||
|
if (m1.weight > m2.weight) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m1.weight < m2.weight) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return m1.name.localeCompare(m2.name);
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
hasChildren() {
|
||||||
|
return this.sortedChildMonitorList.length > 0;
|
||||||
|
},
|
||||||
|
depthMargin() {
|
||||||
|
return {
|
||||||
|
marginLeft: `${31 * this.depth}px`,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
monitorName() {
|
||||||
|
if (this.isSearch) {
|
||||||
|
return this.monitor.pathName;
|
||||||
|
} else {
|
||||||
|
return this.monitor.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
beforeMount() {
|
||||||
|
|
||||||
|
// Always unfold if monitor is accessed directly
|
||||||
|
if (this.monitor.childrenIDs.includes(parseInt(this.$route.params.id))) {
|
||||||
|
this.isCollapsed = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set collapsed value based on local storage
|
||||||
|
let storage = window.localStorage.getItem("monitorCollapsed");
|
||||||
|
if (storage === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let storageObject = JSON.parse(storage);
|
||||||
|
if (storageObject[`monitor_${this.monitor.id}`] == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isCollapsed = storageObject[`monitor_${this.monitor.id}`];
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
/**
|
||||||
|
* Changes the collapsed value of the current monitor and saves it to local storage
|
||||||
|
*/
|
||||||
|
changeCollapsed() {
|
||||||
|
this.isCollapsed = !this.isCollapsed;
|
||||||
|
|
||||||
|
// Save collapsed value into local storage
|
||||||
|
let storage = window.localStorage.getItem("monitorCollapsed");
|
||||||
|
let storageObject = {};
|
||||||
|
if (storage !== null) {
|
||||||
|
storageObject = JSON.parse(storage);
|
||||||
|
}
|
||||||
|
storageObject[`monitor_${this.monitor.id}`] = this.isCollapsed;
|
||||||
|
|
||||||
|
window.localStorage.setItem("monitorCollapsed", JSON.stringify(storageObject));
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Get URL of monitor
|
||||||
|
* @param {number} id ID of monitor
|
||||||
|
* @returns {string} Relative URL of monitor
|
||||||
|
*/
|
||||||
|
monitorURL(id) {
|
||||||
|
return getMonitorRelativeURL(id);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
@import "../assets/vars.scss";
|
||||||
|
|
||||||
|
.small-padding {
|
||||||
|
padding-left: 5px !important;
|
||||||
|
padding-right: 5px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.collapse-padding {
|
||||||
|
padding-left: 8px !important;
|
||||||
|
padding-right: 2px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
// .monitor-item {
|
||||||
|
// width: 100%;
|
||||||
|
// }
|
||||||
|
|
||||||
|
.tags {
|
||||||
|
margin-top: 4px;
|
||||||
|
padding-left: 67px;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.collapsed {
|
||||||
|
transform: rotate(-90deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.animated {
|
||||||
|
transition: all 0.2s $easing-in;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
123
src/components/MonitorSettingDialog.vue
Normal file
123
src/components/MonitorSettingDialog.vue
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
<template>
|
||||||
|
<div ref="MonitorSettingDialog" class="modal fade" tabindex="-1">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">
|
||||||
|
{{ $t("Monitor Setting", [monitor.name]) }}
|
||||||
|
</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" />
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="my-3 form-check">
|
||||||
|
<input id="show-clickable-link" v-model="monitor.isClickAble" class="form-check-input" type="checkbox" @click="toggleLink(monitor.group_index, monitor.monitor_index)" />
|
||||||
|
<label class="form-check-label" for="show-clickable-link">
|
||||||
|
{{ $t("Show Clickable Link") }}
|
||||||
|
</label>
|
||||||
|
<div class="form-text">
|
||||||
|
{{ $t("Show Clickable Link Description") }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
class="btn btn-primary btn-add-group me-2"
|
||||||
|
@click="$refs.badgeGeneratorDialog.show(monitor.id, monitor.name)"
|
||||||
|
>
|
||||||
|
<font-awesome-icon icon="certificate" />
|
||||||
|
{{ $t("Open Badge Generator") }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="submit" class="btn btn-danger" data-bs-dismiss="modal">
|
||||||
|
{{ $t("Close") }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<BadgeGeneratorDialog ref="badgeGeneratorDialog" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { Modal } from "bootstrap";
|
||||||
|
import BadgeGeneratorDialog from "./BadgeGeneratorDialog.vue";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
BadgeGeneratorDialog
|
||||||
|
},
|
||||||
|
props: {},
|
||||||
|
emits: [],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
monitor: {
|
||||||
|
id: null,
|
||||||
|
name: null,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
computed: {},
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
this.MonitorSettingDialog = new Modal(this.$refs.MonitorSettingDialog);
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
/**
|
||||||
|
* Setting monitor
|
||||||
|
* @param {Object} group Data of monitor
|
||||||
|
* @param {Object} monitor Data of monitor
|
||||||
|
*/
|
||||||
|
show(group, monitor) {
|
||||||
|
this.monitor = {
|
||||||
|
id: monitor.element.id,
|
||||||
|
name: monitor.element.name,
|
||||||
|
monitor_index: monitor.index,
|
||||||
|
group_index: group.index,
|
||||||
|
isClickAble: this.showLink(monitor),
|
||||||
|
};
|
||||||
|
|
||||||
|
this.MonitorSettingDialog.show();
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggle the value of sendUrl
|
||||||
|
* @param {number} groupIndex Index of group monitor is member of
|
||||||
|
* @param {number} index Index of monitor within group
|
||||||
|
*/
|
||||||
|
toggleLink(groupIndex, index) {
|
||||||
|
this.$root.publicGroupList[groupIndex].monitorList[index].sendUrl = !this.$root.publicGroupList[groupIndex].monitorList[index].sendUrl;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should a link to the monitor be shown?
|
||||||
|
* Attempts to guess if a link should be shown based upon if
|
||||||
|
* sendUrl is set and if the URL is default or not.
|
||||||
|
* @param {Object} monitor Monitor to check
|
||||||
|
* @param {boolean} [ignoreSendUrl=false] Should the presence of the sendUrl
|
||||||
|
* property be ignored. This will only work in edit mode.
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
showLink(monitor, ignoreSendUrl = false) {
|
||||||
|
// We must check if there are any elements in monitorList to
|
||||||
|
// prevent undefined errors if it hasn't been loaded yet
|
||||||
|
if (this.$parent.editMode && ignoreSendUrl && Object.keys(this.$root.monitorList).length) {
|
||||||
|
return this.$root.monitorList[monitor.element.id].type === "http" || this.$root.monitorList[monitor.element.id].type === "keyword" || this.$root.monitorList[monitor.element.id].type === "json-query";
|
||||||
|
}
|
||||||
|
return monitor.element.sendUrl && monitor.element.url && monitor.element.url !== "https://" && !this.editMode;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
@import "../assets/vars.scss";
|
||||||
|
|
||||||
|
.dark {
|
||||||
|
.modal-dialog .form-text, .modal-dialog p {
|
||||||
|
color: $dark-font-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
@@ -129,7 +129,9 @@ export default {
|
|||||||
"ntfy": "Ntfy",
|
"ntfy": "Ntfy",
|
||||||
"octopush": "Octopush",
|
"octopush": "Octopush",
|
||||||
"OneBot": "OneBot",
|
"OneBot": "OneBot",
|
||||||
|
"Opsgenie": "Opsgenie",
|
||||||
"PagerDuty": "PagerDuty",
|
"PagerDuty": "PagerDuty",
|
||||||
|
"PagerTree": "PagerTree",
|
||||||
"pushbullet": "Pushbullet",
|
"pushbullet": "Pushbullet",
|
||||||
"PushByTechulus": "Push by Techulus",
|
"PushByTechulus": "Push by Techulus",
|
||||||
"pushover": "Pushover",
|
"pushover": "Pushover",
|
||||||
@@ -143,6 +145,7 @@ export default {
|
|||||||
"stackfield": "Stackfield",
|
"stackfield": "Stackfield",
|
||||||
"teams": "Microsoft Teams",
|
"teams": "Microsoft Teams",
|
||||||
"telegram": "Telegram",
|
"telegram": "Telegram",
|
||||||
|
"twilio": "Twilio",
|
||||||
"Splunk": "Splunk",
|
"Splunk": "Splunk",
|
||||||
"webhook": "Webhook",
|
"webhook": "Webhook",
|
||||||
"GoAlert": "GoAlert",
|
"GoAlert": "GoAlert",
|
||||||
@@ -161,6 +164,7 @@ export default {
|
|||||||
"SMSManager": "SmsManager (smsmanager.cz)",
|
"SMSManager": "SmsManager (smsmanager.cz)",
|
||||||
"WeCom": "WeCom (企业微信群机器人)",
|
"WeCom": "WeCom (企业微信群机器人)",
|
||||||
"ServerChan": "ServerChan (Server酱)",
|
"ServerChan": "ServerChan (Server酱)",
|
||||||
|
"smsc": "SMSC",
|
||||||
};
|
};
|
||||||
|
|
||||||
// Sort by notification name
|
// Sort by notification name
|
||||||
|
@@ -11,16 +11,16 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="chart-wrapper" :class="{ loading : loading}">
|
<div class="chart-wrapper" :class="{ loading : loading}">
|
||||||
<LineChart :chart-data="chartData" :options="chartOptions" />
|
<Line :data="chartData" :options="chartOptions" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="js">
|
<script lang="js">
|
||||||
import { BarController, BarElement, Chart, Filler, LinearScale, LineController, LineElement, PointElement, TimeScale, Tooltip } from "chart.js";
|
import { BarController, BarElement, Chart, Filler, LinearScale, LineController, LineElement, PointElement, TimeScale, Tooltip } from "chart.js";
|
||||||
import "chartjs-adapter-dayjs";
|
import "chartjs-adapter-dayjs-4";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { LineChart } from "vue-chart-3";
|
import { Line } from "vue-chartjs";
|
||||||
import { useToast } from "vue-toastification";
|
import { useToast } from "vue-toastification";
|
||||||
import { DOWN, PENDING, MAINTENANCE, log } from "../util.ts";
|
import { DOWN, PENDING, MAINTENANCE, log } from "../util.ts";
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ const toast = useToast();
|
|||||||
Chart.register(LineController, BarController, LineElement, PointElement, TimeScale, BarElement, LinearScale, Tooltip, Filler);
|
Chart.register(LineController, BarController, LineElement, PointElement, TimeScale, BarElement, LinearScale, Tooltip, Filler);
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: { LineChart },
|
components: { Line },
|
||||||
props: {
|
props: {
|
||||||
/** ID of monitor */
|
/** ID of monitor */
|
||||||
monitorId: {
|
monitorId: {
|
||||||
@@ -104,8 +104,10 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
ticks: {
|
ticks: {
|
||||||
|
sampleSize: 3,
|
||||||
maxRotation: 0,
|
maxRotation: 0,
|
||||||
autoSkipPadding: 30,
|
autoSkipPadding: 30,
|
||||||
|
padding: 3,
|
||||||
},
|
},
|
||||||
grid: {
|
grid: {
|
||||||
color: this.$root.theme === "light" ? "rgba(0,0,0,0.1)" : "rgba(255,255,255,0.1)",
|
color: this.$root.theme === "light" ? "rgba(0,0,0,0.1)" : "rgba(255,255,255,0.1)",
|
||||||
@@ -197,6 +199,7 @@ export default {
|
|||||||
borderColor: "#5CDD8B",
|
borderColor: "#5CDD8B",
|
||||||
backgroundColor: "#5CDD8B38",
|
backgroundColor: "#5CDD8B38",
|
||||||
yAxisID: "y",
|
yAxisID: "y",
|
||||||
|
label: "ping",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Bar Chart
|
// Bar Chart
|
||||||
@@ -208,6 +211,8 @@ export default {
|
|||||||
barThickness: "flex",
|
barThickness: "flex",
|
||||||
barPercentage: 1,
|
barPercentage: 1,
|
||||||
categoryPercentage: 1,
|
categoryPercentage: 1,
|
||||||
|
inflateAmount: 0.05,
|
||||||
|
label: "status",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
@@ -1,102 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div v-if="! (!plugin.installed && plugin.local)" class="plugin-item pt-4 pb-2">
|
|
||||||
<div class="info">
|
|
||||||
<h5>{{ plugin.fullName }}</h5>
|
|
||||||
<p class="description">
|
|
||||||
{{ plugin.description }}
|
|
||||||
</p>
|
|
||||||
<span class="version">{{ $t("Version") }}: {{ plugin.version }} <a v-if="plugin.repo" :href="plugin.repo" target="_blank">Repo</a></span>
|
|
||||||
</div>
|
|
||||||
<div class="buttons">
|
|
||||||
<button v-if="status === 'installing'" class="btn btn-primary" disabled>{{ $t("installing") }}</button>
|
|
||||||
<button v-else-if="status === 'uninstalling'" class="btn btn-danger" disabled>{{ $t("uninstalling") }}</button>
|
|
||||||
<button v-else-if="plugin.installed || status === 'installed'" class="btn btn-danger" @click="deleteConfirm">{{ $t("uninstall") }}</button>
|
|
||||||
<button v-else class="btn btn-primary" @click="install">{{ $t("install") }}</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Confirm ref="confirmDelete" btn-style="btn-danger" :yes-text="$t('Yes')" :no-text="$t('No')" @yes="uninstall">
|
|
||||||
{{ $t("confirmUninstallPlugin") }}
|
|
||||||
</Confirm>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import Confirm from "./Confirm.vue";
|
|
||||||
|
|
||||||
export default {
|
|
||||||
components: {
|
|
||||||
Confirm,
|
|
||||||
},
|
|
||||||
props: {
|
|
||||||
plugin: {
|
|
||||||
type: Object,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
status: "",
|
|
||||||
};
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
/**
|
|
||||||
* Show confirmation for deleting a tag
|
|
||||||
*/
|
|
||||||
deleteConfirm() {
|
|
||||||
this.$refs.confirmDelete.show();
|
|
||||||
},
|
|
||||||
|
|
||||||
install() {
|
|
||||||
this.status = "installing";
|
|
||||||
|
|
||||||
this.$root.getSocket().emit("installPlugin", this.plugin.repo, this.plugin.name, (res) => {
|
|
||||||
if (res.ok) {
|
|
||||||
this.status = "";
|
|
||||||
// eslint-disable-next-line vue/no-mutating-props
|
|
||||||
this.plugin.installed = true;
|
|
||||||
} else {
|
|
||||||
this.$root.toastRes(res);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
uninstall() {
|
|
||||||
this.status = "uninstalling";
|
|
||||||
|
|
||||||
this.$root.getSocket().emit("uninstallPlugin", this.plugin.name, (res) => {
|
|
||||||
if (res.ok) {
|
|
||||||
this.status = "";
|
|
||||||
// eslint-disable-next-line vue/no-mutating-props
|
|
||||||
this.plugin.installed = false;
|
|
||||||
} else {
|
|
||||||
this.$root.toastRes(res);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
@import "../assets/vars.scss";
|
|
||||||
|
|
||||||
.plugin-item {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-content: center;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
.info {
|
|
||||||
margin-right: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.description {
|
|
||||||
font-size: 13px;
|
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.version {
|
|
||||||
font-size: 13px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
@@ -49,16 +49,15 @@
|
|||||||
{{ monitor.element.name }}
|
{{ monitor.element.name }}
|
||||||
</a>
|
</a>
|
||||||
<p v-else class="item-name"> {{ monitor.element.name }} </p>
|
<p v-else class="item-name"> {{ monitor.element.name }} </p>
|
||||||
|
|
||||||
<span
|
<span
|
||||||
v-if="showLink(monitor, true)"
|
title="Setting"
|
||||||
title="Toggle Clickable Link"
|
|
||||||
>
|
>
|
||||||
<font-awesome-icon
|
<font-awesome-icon
|
||||||
v-if="editMode"
|
v-if="editMode"
|
||||||
:class="{'link-active': monitor.element.sendUrl, 'btn-link': true}"
|
:class="{'link-active': true, 'btn-link': true}"
|
||||||
icon="link" class="action me-3"
|
icon="cog" class="action me-3"
|
||||||
|
@click="$refs.monitorSettingDialog.show(group, monitor)"
|
||||||
@click="toggleLink(group.index, monitor.index)"
|
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -77,9 +76,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</Draggable>
|
</Draggable>
|
||||||
|
<MonitorSettingDialog ref="monitorSettingDialog" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import MonitorSettingDialog from "./MonitorSettingDialog.vue";
|
||||||
import Draggable from "vuedraggable";
|
import Draggable from "vuedraggable";
|
||||||
import HeartbeatBar from "./HeartbeatBar.vue";
|
import HeartbeatBar from "./HeartbeatBar.vue";
|
||||||
import Uptime from "./Uptime.vue";
|
import Uptime from "./Uptime.vue";
|
||||||
@@ -87,6 +88,7 @@ import Tag from "./Tag.vue";
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
MonitorSettingDialog,
|
||||||
Draggable,
|
Draggable,
|
||||||
HeartbeatBar,
|
HeartbeatBar,
|
||||||
Uptime,
|
Uptime,
|
||||||
@@ -135,15 +137,6 @@ export default {
|
|||||||
this.$root.publicGroupList[groupIndex].monitorList.splice(index, 1);
|
this.$root.publicGroupList[groupIndex].monitorList.splice(index, 1);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Toggle the value of sendUrl
|
|
||||||
* @param {number} groupIndex Index of group monitor is member of
|
|
||||||
* @param {number} index Index of monitor within group
|
|
||||||
*/
|
|
||||||
toggleLink(groupIndex, index) {
|
|
||||||
this.$root.publicGroupList[groupIndex].monitorList[index].sendUrl = !this.$root.publicGroupList[groupIndex].monitorList[index].sendUrl;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should a link to the monitor be shown?
|
* Should a link to the monitor be shown?
|
||||||
* Attempts to guess if a link should be shown based upon if
|
* Attempts to guess if a link should be shown based upon if
|
||||||
@@ -157,7 +150,7 @@ export default {
|
|||||||
// We must check if there are any elements in monitorList to
|
// We must check if there are any elements in monitorList to
|
||||||
// prevent undefined errors if it hasn't been loaded yet
|
// prevent undefined errors if it hasn't been loaded yet
|
||||||
if (this.$parent.editMode && ignoreSendUrl && Object.keys(this.$root.monitorList).length) {
|
if (this.$parent.editMode && ignoreSendUrl && Object.keys(this.$root.monitorList).length) {
|
||||||
return this.$root.monitorList[monitor.element.id].type === "http" || this.$root.monitorList[monitor.element.id].type === "keyword";
|
return this.$root.monitorList[monitor.element.id].type === "http" || this.$root.monitorList[monitor.element.id].type === "keyword" || this.$root.monitorList[monitor.element.id].type === "json-query";
|
||||||
}
|
}
|
||||||
return monitor.element.sendUrl && monitor.element.url && monitor.element.url !== "https://" && !this.editMode;
|
return monitor.element.sendUrl && monitor.element.url && monitor.element.url !== "https://" && !this.editMode;
|
||||||
},
|
},
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
'm-2': size == 'normal',
|
'm-2': size == 'normal',
|
||||||
'px-2': size == 'sm',
|
'px-2': size == 'sm',
|
||||||
'py-0': size == 'sm',
|
'py-0': size == 'sm',
|
||||||
'm-1': size == 'sm',
|
'mx-1': size == 'sm',
|
||||||
}"
|
}"
|
||||||
:style="{ backgroundColor: item.color, fontSize: size == 'sm' ? '0.7em' : '1em' }"
|
:style="{ backgroundColor: item.color, fontSize: size == 'sm' ? '0.7em' : '1em' }"
|
||||||
>
|
>
|
||||||
|
@@ -76,17 +76,30 @@
|
|||||||
</button>
|
</button>
|
||||||
</router-link>
|
</router-link>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="allMonitorList.length > 0" class="pt-3 px-3">
|
<div v-if="allMonitorList.length > 0" class="pt-3">
|
||||||
<label class="form-label">{{ $t("Add a monitor") }}:</label>
|
<label class="form-label">{{ $t("Add a monitor") }}:</label>
|
||||||
<select v-model="selectedAddMonitor" class="form-control">
|
<VueMultiselect
|
||||||
<option v-for="monitor in allMonitorList" :key="monitor.id" :value="monitor">{{ monitor.name }}</option>
|
v-model="selectedAddMonitor"
|
||||||
</select>
|
:options="allMonitorList"
|
||||||
|
:multiple="false"
|
||||||
|
:searchable="true"
|
||||||
|
:placeholder="$t('Add a monitor')"
|
||||||
|
label="name"
|
||||||
|
trackBy="name"
|
||||||
|
class="mt-1"
|
||||||
|
>
|
||||||
|
<template #option="{ option }">
|
||||||
|
<div class="d-inline-flex">
|
||||||
|
<span>{{ option.name }} <Tag v-for="monitorTag in option.tags" :key="monitorTag" :item="monitorTag" :size="'sm'" /></span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</VueMultiselect>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button v-if="tag" type="button" class="btn btn-danger" :disabled="processing" @click="deleteConfirm">
|
<button v-if="tag && tag.id !== null" type="button" class="btn btn-danger" :disabled="processing" @click="deleteConfirm">
|
||||||
{{ $t("Delete") }}
|
{{ $t("Delete") }}
|
||||||
</button>
|
</button>
|
||||||
<button type="submit" class="btn btn-primary" :disabled="processing">
|
<button type="submit" class="btn btn-primary" :disabled="processing">
|
||||||
@@ -107,6 +120,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import { Modal } from "bootstrap";
|
import { Modal } from "bootstrap";
|
||||||
import Confirm from "./Confirm.vue";
|
import Confirm from "./Confirm.vue";
|
||||||
|
import Tag from "./Tag.vue";
|
||||||
import VueMultiselect from "vue-multiselect";
|
import VueMultiselect from "vue-multiselect";
|
||||||
import { colorOptions } from "../util-frontend";
|
import { colorOptions } from "../util-frontend";
|
||||||
import { useToast } from "vue-toastification";
|
import { useToast } from "vue-toastification";
|
||||||
@@ -117,6 +131,7 @@ export default {
|
|||||||
components: {
|
components: {
|
||||||
VueMultiselect,
|
VueMultiselect,
|
||||||
Confirm,
|
Confirm,
|
||||||
|
Tag,
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
updated: {
|
updated: {
|
||||||
|
@@ -16,17 +16,29 @@
|
|||||||
<input id="ntfy-priority" v-model="$parent.notification.ntfyPriority" type="number" class="form-control" required min="1" max="5" step="1">
|
<input id="ntfy-priority" v-model="$parent.notification.ntfyPriority" type="number" class="form-control" required min="1" max="5" step="1">
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="ntfy-username" class="form-label">{{ $t("Username") }} ({{ $t("Optional") }})</label>
|
<label for="authentication-method" class="form-label">{{ $t("ntfyAuthenticationMethod") }}</label>
|
||||||
|
<select id="authentication-method" v-model="$parent.notification.ntfyAuthenticationMethod" class="form-select">
|
||||||
|
<option v-for="(name, type) in authenticationMethods" :key="type" :value="type">{{ name }}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div v-if="$parent.notification.ntfyAuthenticationMethod === 'usernamePassword'" class="mb-3">
|
||||||
|
<label for="ntfy-username" class="form-label">{{ $t("Username") }}</label>
|
||||||
<div class="input-group mb-3">
|
<div class="input-group mb-3">
|
||||||
<input id="ntfy-username" v-model="$parent.notification.ntfyusername" type="text" class="form-control">
|
<input id="ntfy-username" v-model="$parent.notification.ntfyusername" type="text" class="form-control">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div v-if="$parent.notification.ntfyAuthenticationMethod === 'usernamePassword'" class="mb-3">
|
||||||
<label for="ntfy-password" class="form-label">{{ $t("Password") }} ({{ $t("Optional") }})</label>
|
<label for="ntfy-password" class="form-label">{{ $t("Password") }}</label>
|
||||||
<div class="input-group mb-3">
|
<div class="input-group mb-3">
|
||||||
<HiddenInput id="ntfy-password" v-model="$parent.notification.ntfypassword" autocomplete="new-password"></HiddenInput>
|
<HiddenInput id="ntfy-password" v-model="$parent.notification.ntfypassword" autocomplete="new-password"></HiddenInput>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-if="$parent.notification.ntfyAuthenticationMethod === 'accessToken'" class="mb-3">
|
||||||
|
<label for="ntfy-access-token" class="form-label">{{ $t("Access Token") }}</label>
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<HiddenInput id="ntfy-access-token" v-model="$parent.notification.ntfyaccesstoken"></HiddenInput>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="ntfy-icon" class="form-label">{{ $t("IconUrl") }}</label>
|
<label for="ntfy-icon" class="form-label">{{ $t("IconUrl") }}</label>
|
||||||
<input id="ntfy-icon" v-model="$parent.notification.ntfyIcon" type="text" class="form-control">
|
<input id="ntfy-icon" v-model="$parent.notification.ntfyIcon" type="text" class="form-control">
|
||||||
@@ -40,11 +52,29 @@ export default {
|
|||||||
components: {
|
components: {
|
||||||
HiddenInput,
|
HiddenInput,
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
authenticationMethods() {
|
||||||
|
return {
|
||||||
|
none: this.$t("None"),
|
||||||
|
usernamePassword: this.$t("ntfyUsernameAndPassword"),
|
||||||
|
accessToken: this.$t("Access Token")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
if (typeof this.$parent.notification.ntfyPriority === "undefined") {
|
if (typeof this.$parent.notification.ntfyPriority === "undefined") {
|
||||||
this.$parent.notification.ntfyserverurl = "https://ntfy.sh";
|
this.$parent.notification.ntfyserverurl = "https://ntfy.sh";
|
||||||
this.$parent.notification.ntfyPriority = 5;
|
this.$parent.notification.ntfyPriority = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handling notifications that added before 1.22.0
|
||||||
|
if (typeof this.$parent.notification.ntfyAuthenticationMethod === "undefined") {
|
||||||
|
if (!this.$parent.notification.ntfyusername) {
|
||||||
|
this.$parent.notification.ntfyAuthenticationMethod = "none";
|
||||||
|
} else {
|
||||||
|
this.$parent.notification.ntfyAuthenticationMethod = "usernamePassword";
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
36
src/components/notifications/Opsgenie.vue
Normal file
36
src/components/notifications/Opsgenie.vue
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<template>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="opsgenie-region" class="form-label">{{ $t("Region") }}<span style="color: red;"><sup>*</sup></span></label>
|
||||||
|
<select id="opsgenie-region" v-model="$parent.notification.opsgenieRegion" class="form-select" required>
|
||||||
|
<option value="us">
|
||||||
|
US (Default)
|
||||||
|
</option>
|
||||||
|
<option value="eu">
|
||||||
|
EU
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="opsgenie-apikey" class="form-label">{{ $t("API Key") }}<span style="color: red;"><sup>*</sup></span></label>
|
||||||
|
<HiddenInput id="opsgenie-apikey" v-model="$parent.notification.opsgenieApiKey" required="true" autocomplete="false"></HiddenInput>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="opsgenie-priority" class="form-label">{{ $t("Priority") }}</label>
|
||||||
|
<input id="opsgenie-priority" v-model="$parent.notification.opsgeniePriority" type="number" class="form-control" min="1" max="5" step="1">
|
||||||
|
</div>
|
||||||
|
<div class="form-text">
|
||||||
|
<span style="color: red;"><sup>*</sup></span>{{ $t("Required") }}
|
||||||
|
<i18n-t tag="p" keypath="aboutWebhooks" style="margin-top: 8px;">
|
||||||
|
<a href="https://docs.opsgenie.com/docs/alert-api" target="_blank">https://docs.opsgenie.com/docs/alert-api</a>
|
||||||
|
</i18n-t>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import HiddenInput from "../HiddenInput.vue";
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
HiddenInput,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
@@ -42,6 +42,8 @@
|
|||||||
<option value="vibrate">{{ $t("pushoversounds vibrate") }}</option>
|
<option value="vibrate">{{ $t("pushoversounds vibrate") }}</option>
|
||||||
<option value="none">{{ $t("pushoversounds none") }}</option>
|
<option value="none">{{ $t("pushoversounds none") }}</option>
|
||||||
</select>
|
</select>
|
||||||
|
<label for="pushover-ttl" class="form-label">{{ $t("pushoverMessageTtl") }}</label>
|
||||||
|
<input id="pushover-ttl" v-model="$parent.notification.pushoverttl" type="number" min="0" step="1" class="form-control">
|
||||||
<div class="form-text">
|
<div class="form-text">
|
||||||
<span style="color: red;"><sup>*</sup></span>{{ $t("Required") }}
|
<span style="color: red;"><sup>*</sup></span>{{ $t("Required") }}
|
||||||
<i18n-t tag="p" keypath="More info on:" style="margin-top: 8px;">
|
<i18n-t tag="p" keypath="More info on:" style="margin-top: 8px;">
|
||||||
|
43
src/components/notifications/SMSC.vue
Normal file
43
src/components/notifications/SMSC.vue
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<template>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="smsc-login" class="form-label">{{ $t("API Username") }}</label>
|
||||||
|
<i18n-t tag="div" class="form-text" keypath="wayToGetClickSendSMSToken">
|
||||||
|
<a href="https://smsc.kz/" target="_blank">{{ $t("here") }}</a>
|
||||||
|
</i18n-t>
|
||||||
|
<input id="smsc-login" v-model="$parent.notification.smscLogin" type="text" class="form-control" required>
|
||||||
|
<label for="smsc-key" class="form-label">{{ $t("API Key") }}</label>
|
||||||
|
<HiddenInput id="smsc-key" v-model="$parent.notification.smscPassword" :required="true" autocomplete="new-password"></HiddenInput>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<div class="form-text">
|
||||||
|
{{ $t("checkPrice", ['СМСЦ']) }}
|
||||||
|
<a href="https://smsc.kz/tariffs/" target="_blank">https://smsc.kz/tariffs/</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="smsc-to-number" class="form-label">{{ $t("Recipient Number") }}</label>
|
||||||
|
<input id="smsc-to-number" v-model="$parent.notification.smscToNumber" type="text" minlength="11" class="form-control" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="smsc-sender-name" class="form-label">{{ $t("From Name/Number") }}</label>
|
||||||
|
<input id="smsc-sender-name" v-model="$parent.notification.smscSenderName" type="text" minlength="1" maxlength="15" class="form-control">
|
||||||
|
<div class="form-text">{{ $t("Leave blank to use a shared sender number.") }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="smsc-platform" class="form-label">{{ $t("smscTranslit") }}</label><span style="color: red;"><sup>*</sup></span>
|
||||||
|
<select id="smsc-platform" v-model="$parent.notification.smscTranslit" class="form-select">
|
||||||
|
<option value="0">{{ $t("Default") }}</option>
|
||||||
|
<option value="1">Translit</option>
|
||||||
|
<option value="2">MpaHc/Ium</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
import HiddenInput from "../HiddenInput.vue";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
HiddenInput,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
@@ -24,5 +24,13 @@
|
|||||||
<a href="https://www.webfx.com/tools/emoji-cheat-sheet/" target="_blank">https://www.webfx.com/tools/emoji-cheat-sheet/</a>
|
<a href="https://www.webfx.com/tools/emoji-cheat-sheet/" target="_blank">https://www.webfx.com/tools/emoji-cheat-sheet/</a>
|
||||||
</i18n-t>
|
</i18n-t>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-check form-switch">
|
||||||
|
<input id="slack-channel-notify" v-model="$parent.notification.slackchannelnotify" type="checkbox" class="form-check-input">
|
||||||
|
<label for="slack-channel-notify" class="form-label">{{ $t("Notify Channel") }}</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-text">
|
||||||
|
{{ $t("aboutNotifyChannel") }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
38
src/components/notifications/Twilio.vue
Normal file
38
src/components/notifications/Twilio.vue
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<template>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="twilio-account-sid" class="form-label">{{ $t("Account SID") }}</label>
|
||||||
|
<input id="twilio-account-sid" v-model="$parent.notification.twilioAccountSID" type="text" class="form-control" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="twilio-apikey-token" class="form-label">{{ $t("Api Key (optional)") }}</label>
|
||||||
|
<input id="twilio-apikey-token" v-model="$parent.notification.twilioApiKey" type="text" class="form-control">
|
||||||
|
<div class="form-text">
|
||||||
|
<p>
|
||||||
|
The API key is optional but recommended. You can provide either Account SID and AuthToken
|
||||||
|
from the may TwilioConsole page or Account SID and the pair of Api Key and Api Key secret
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="twilio-auth-token" class="form-label">{{ $t("Auth Token / Api Key Secret") }}</label>
|
||||||
|
<input id="twilio-auth-token" v-model="$parent.notification.twilioAuthToken" type="text" class="form-control" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="twilio-from-number" class="form-label">{{ $t("From Number") }}</label>
|
||||||
|
<input id="twilio-from-number" v-model="$parent.notification.twilioFromNumber" type="text" class="form-control" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="twilio-to-number" class="form-label">{{ $t("To Number") }}</label>
|
||||||
|
<input id="twilio-to-number" v-model="$parent.notification.twilioToNumber" type="text" class="form-control" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<i18n-t tag="p" keypath="More info on:" style="margin-top: 8px;">
|
||||||
|
<a href="https://www.twilio.com/docs/sms" target="_blank">https://www.twilio.com/docs/sms</a>
|
||||||
|
</i18n-t>
|
||||||
|
</div>
|
||||||
|
</template>
|
@@ -12,61 +12,97 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="webhook-content-type" class="form-label">{{
|
<label for="webhook-request-body" class="form-label">{{
|
||||||
$t("Content Type")
|
$t("Request Body")
|
||||||
}}</label>
|
}}</label>
|
||||||
<select
|
<select
|
||||||
id="webhook-content-type"
|
id="webhook-request-body"
|
||||||
v-model="$parent.notification.webhookContentType"
|
v-model="$parent.notification.webhookContentType"
|
||||||
class="form-select"
|
class="form-select"
|
||||||
required
|
required
|
||||||
>
|
>
|
||||||
<option value="json">application/json</option>
|
<option value="json">{{ $t("webhookBodyPresetOption", ["application/json"]) }}</option>
|
||||||
<option value="form-data">multipart/form-data</option>
|
<option value="form-data">{{ $t("webhookBodyPresetOption", ["multipart/form-data"]) }}</option>
|
||||||
|
<option value="custom">{{ $t("webhookBodyCustomOption") }}</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<div class="form-text">
|
<div class="form-text">
|
||||||
|
<div v-if="$parent.notification.webhookContentType == 'json'">
|
||||||
<p>{{ $t("webhookJsonDesc", ['"application/json"']) }}</p>
|
<p>{{ $t("webhookJsonDesc", ['"application/json"']) }}</p>
|
||||||
|
</div>
|
||||||
|
<div v-if="$parent.notification.webhookContentType == 'form-data'">
|
||||||
<i18n-t tag="p" keypath="webhookFormDataDesc">
|
<i18n-t tag="p" keypath="webhookFormDataDesc">
|
||||||
<template #multipart>"multipart/form-data"</template>
|
<template #multipart>multipart/form-data"</template>
|
||||||
<template #decodeFunction>
|
<template #decodeFunction>
|
||||||
<strong>json_decode($_POST['data'])</strong>
|
<strong>json_decode($_POST['data'])</strong>
|
||||||
</template>
|
</template>
|
||||||
</i18n-t>
|
</i18n-t>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-if="$parent.notification.webhookContentType == 'custom'">
|
||||||
|
<i18n-t tag="p" keypath="webhookCustomBodyDesc">
|
||||||
|
<template #msg>
|
||||||
|
<code>msg</code>
|
||||||
|
</template>
|
||||||
|
<template #heartbeat>
|
||||||
|
<code>heartbeatJSON</code>
|
||||||
|
</template>
|
||||||
|
<template #monitor>
|
||||||
|
<code>monitorJSON</code>
|
||||||
|
</template>
|
||||||
|
</i18n-t>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<textarea
|
||||||
|
v-if="$parent.notification.webhookContentType == 'custom'"
|
||||||
|
id="customBody"
|
||||||
|
v-model="$parent.notification.webhookCustomBody"
|
||||||
|
class="form-control"
|
||||||
|
:placeholder="customBodyPlaceholder"
|
||||||
|
></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<i18n-t
|
<div class="form-check form-switch">
|
||||||
tag="label"
|
<input v-model="showAdditionalHeadersField" class="form-check-input" type="checkbox">
|
||||||
class="form-label"
|
<label class="form-check-label">{{ $t("webhookAdditionalHeadersTitle") }}</label>
|
||||||
for="additionalHeaders"
|
</div>
|
||||||
keypath="webhookAdditionalHeadersTitle"
|
<div class="form-text">
|
||||||
>
|
<i18n-t tag="p" keypath="webhookAdditionalHeadersDesc"> </i18n-t>
|
||||||
</i18n-t>
|
</div>
|
||||||
<textarea
|
<textarea
|
||||||
|
v-if="showAdditionalHeadersField"
|
||||||
id="additionalHeaders"
|
id="additionalHeaders"
|
||||||
v-model="$parent.notification.webhookAdditionalHeaders"
|
v-model="$parent.notification.webhookAdditionalHeaders"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
:placeholder="headersPlaceholder"
|
:placeholder="headersPlaceholder"
|
||||||
></textarea>
|
></textarea>
|
||||||
<div class="form-text">
|
|
||||||
<i18n-t tag="p" keypath="webhookAdditionalHeadersDesc"> </i18n-t>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
showAdditionalHeadersField: this.$parent.notification.webhookAdditionalHeaders != null,
|
||||||
|
};
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
headersPlaceholder() {
|
headersPlaceholder() {
|
||||||
return this.$t("Example:", [
|
return this.$t("Example:", [
|
||||||
`
|
`
|
||||||
{
|
{
|
||||||
"HeaderName": "HeaderValue"
|
"Authorization": "Authorization Token"
|
||||||
}`,
|
}`,
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
|
customBodyPlaceholder() {
|
||||||
|
return `Example:
|
||||||
|
{
|
||||||
|
"Title": "Uptime Kuma Alert - {{ monitorJSON['name'] }}",
|
||||||
|
"Body": "{{ msg }}"
|
||||||
|
}`;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@@ -4,6 +4,7 @@ import AliyunSMS from "./AliyunSms.vue";
|
|||||||
import Apprise from "./Apprise.vue";
|
import Apprise from "./Apprise.vue";
|
||||||
import Bark from "./Bark.vue";
|
import Bark from "./Bark.vue";
|
||||||
import ClickSendSMS from "./ClickSendSMS.vue";
|
import ClickSendSMS from "./ClickSendSMS.vue";
|
||||||
|
import SMSC from "./SMSC.vue";
|
||||||
import DingDing from "./DingDing.vue";
|
import DingDing from "./DingDing.vue";
|
||||||
import Discord from "./Discord.vue";
|
import Discord from "./Discord.vue";
|
||||||
import Feishu from "./Feishu.vue";
|
import Feishu from "./Feishu.vue";
|
||||||
@@ -21,6 +22,7 @@ import Mattermost from "./Mattermost.vue";
|
|||||||
import Ntfy from "./Ntfy.vue";
|
import Ntfy from "./Ntfy.vue";
|
||||||
import Octopush from "./Octopush.vue";
|
import Octopush from "./Octopush.vue";
|
||||||
import OneBot from "./OneBot.vue";
|
import OneBot from "./OneBot.vue";
|
||||||
|
import Opsgenie from "./Opsgenie.vue";
|
||||||
import PagerDuty from "./PagerDuty.vue";
|
import PagerDuty from "./PagerDuty.vue";
|
||||||
import PagerTree from "./PagerTree.vue";
|
import PagerTree from "./PagerTree.vue";
|
||||||
import PromoSMS from "./PromoSMS.vue";
|
import PromoSMS from "./PromoSMS.vue";
|
||||||
@@ -41,6 +43,7 @@ import STMP from "./SMTP.vue";
|
|||||||
import Teams from "./Teams.vue";
|
import Teams from "./Teams.vue";
|
||||||
import TechulusPush from "./TechulusPush.vue";
|
import TechulusPush from "./TechulusPush.vue";
|
||||||
import Telegram from "./Telegram.vue";
|
import Telegram from "./Telegram.vue";
|
||||||
|
import Twilio from "./Twilio.vue";
|
||||||
import Webhook from "./Webhook.vue";
|
import Webhook from "./Webhook.vue";
|
||||||
import WeCom from "./WeCom.vue";
|
import WeCom from "./WeCom.vue";
|
||||||
import GoAlert from "./GoAlert.vue";
|
import GoAlert from "./GoAlert.vue";
|
||||||
@@ -59,6 +62,7 @@ const NotificationFormList = {
|
|||||||
"apprise": Apprise,
|
"apprise": Apprise,
|
||||||
"Bark": Bark,
|
"Bark": Bark,
|
||||||
"clicksendsms": ClickSendSMS,
|
"clicksendsms": ClickSendSMS,
|
||||||
|
"smsc": SMSC,
|
||||||
"DingDing": DingDing,
|
"DingDing": DingDing,
|
||||||
"discord": Discord,
|
"discord": Discord,
|
||||||
"Feishu": Feishu,
|
"Feishu": Feishu,
|
||||||
@@ -76,6 +80,7 @@ const NotificationFormList = {
|
|||||||
"ntfy": Ntfy,
|
"ntfy": Ntfy,
|
||||||
"octopush": Octopush,
|
"octopush": Octopush,
|
||||||
"OneBot": OneBot,
|
"OneBot": OneBot,
|
||||||
|
"Opsgenie": Opsgenie,
|
||||||
"PagerDuty": PagerDuty,
|
"PagerDuty": PagerDuty,
|
||||||
"PagerTree": PagerTree,
|
"PagerTree": PagerTree,
|
||||||
"promosms": PromoSMS,
|
"promosms": PromoSMS,
|
||||||
@@ -95,6 +100,7 @@ const NotificationFormList = {
|
|||||||
"stackfield": Stackfield,
|
"stackfield": Stackfield,
|
||||||
"teams": Teams,
|
"teams": Teams,
|
||||||
"telegram": Telegram,
|
"telegram": Telegram,
|
||||||
|
"twilio": Twilio,
|
||||||
"Splunk": Splunk,
|
"Splunk": Splunk,
|
||||||
"webhook": Webhook,
|
"webhook": Webhook,
|
||||||
"WeCom": WeCom,
|
"WeCom": WeCom,
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user