Added MQTT Monitor type #875

Open
tarun7singh wants to merge 7 commits from tarun7singh/master into master
tarun7singh commented 3 years ago (Migrated from github.com)
Owner

Description

Added MQTT monitor type for monitoring mqtt message and alert if a message is different from preset success message.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

Checklist

  • My code follows the style guidelines of this project
  • I ran ESLint and other linters for modified files
  • I have performed a self-review of my own code and test it
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • My code needed automated testing. I have added them (this is optional task)

Screenshots (if any)

Screen Shot 2021-11-03 at 9 45 24 PM Screen Shot 2021-11-03 at 9 45 34 PM Screen Shot 2021-11-03 at 9 45 41 PM
# Description Added MQTT monitor type for monitoring mqtt message and alert if a message is different from preset success message. ## Type of change Please delete options that are not relevant. - New feature (non-breaking change which adds functionality) ## Checklist - [x] My code follows the style guidelines of this project - [x] I ran ESLint and other linters for modified files - [x] I have performed a self-review of my own code and test it - [x] I have commented my code, particularly in hard-to-understand areas - [x] My changes generate no new warnings - [ ] My code needed automated testing. I have added them (this is optional task) ## Screenshots (if any) <img width="1440" alt="Screen Shot 2021-11-03 at 9 45 24 PM" src="https://user-images.githubusercontent.com/12068093/140244569-effbc218-532e-4272-a95d-6910af7acd21.png"> <img width="1440" alt="Screen Shot 2021-11-03 at 9 45 34 PM" src="https://user-images.githubusercontent.com/12068093/140244573-750fac71-83d2-4400-8575-7c77c4b00c88.png"> <img width="1440" alt="Screen Shot 2021-11-03 at 9 45 41 PM" src="https://user-images.githubusercontent.com/12068093/140244577-858e97fc-67d7-4b33-ab79-f7dc3def4e8d.png">
Saibamen (Migrated from github.com) reviewed 3 years ago
Saibamen (Migrated from github.com) commented 3 years ago
Owner
                } else if (this.type === "mqtt") {
```suggestion } else if (this.type === "mqtt") { ```
Saibamen (Migrated from github.com) commented 3 years ago
Owner
const mqtt = require("mqtt");
```suggestion const mqtt = require("mqtt"); ```
Saibamen (Migrated from github.com) commented 3 years ago
Owner
            });
```suggestion }); ```
Saibamen (Migrated from github.com) commented 3 years ago
Owner

Maybe change url key to serverUrl?

Maybe change `url` key to `serverUrl`?
Saibamen (Migrated from github.com) commented 3 years ago
Owner
                            <!-- MQTT -->
```suggestion <!-- MQTT --> ```
chakflying commented 3 years ago (Migrated from github.com)
Owner

Is there a way to set the ping value as well?

Is there a way to set the ping value as well?
tarun7singh commented 3 years ago (Migrated from github.com)
Poster
Owner

Is there a way to set the ping value as well?

@chakflying
I tried adding that but as pings are sent from the server-side itself and we're just listening from them. Ping time was varying a lot even without any changes.

Is there a way to set the ping value as well? > @chakflying I tried adding that but as pings are sent from the server-side itself and we're just listening from them. Ping time was varying a lot even without any changes.
louislam commented 3 years ago (Migrated from github.com)
Owner

@srgvg MQTT Monitor type is here. Thank you all.

@srgvg MQTT Monitor type is here. Thank you all.
srgvg commented 3 years ago (Migrated from github.com)
Owner

There's a merge commit from upstream master in this PR. I couldn't rebase it properly on upstream master without merge conflicts. @tarun7singh I recommend you work on a differntly named feature branch, not on your local master branch. Or at least, don't pull upstream changes with a merge, but rebase your work on top of it.

There's a merge commit from upstream master in this PR. I couldn't rebase it properly on upstream master without merge conflicts. @tarun7singh I recommend you work on a differntly named feature branch, not on your local master branch. Or at least, don't pull upstream changes with a merge, but rebase your work on top of it.
srgvg commented 3 years ago (Migrated from github.com)
Owner

My mqtt servers are authenticated. Does this PR allow authentication?

I tried building the container from @tarun7singh master branch, but that fails, not sure why?

serge@minos ~/src/tmp/uptime-kuma    tarun7singh-master tarun7singh:master (1490155)  via  v16.10.0
🕙14:30:52  ➞  docker build -t localhost/uptime-kuma:tarun7singh docker/
Sending build context to Docker daemon  8.192kB
Step 1/28 : FROM louislam/uptime-kuma:base-debian AS build
 ---> bfe4b5708d38
Step 2/28 : WORKDIR /app
 ---> Using cache
 ---> 388407a9a805
Step 3/28 : ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1
 ---> Using cache
 ---> 0aaaf81523ef
Step 4/28 : COPY . .
 ---> Using cache
 ---> 094bb8b20b90
Step 5/28 : RUN npm ci --production &&     chmod +x /app/extra/entrypoint.sh
 ---> Running in e3111503ce6c
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /app/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-11-07T13_31_03_192Z-debug.log
The command '/bin/sh -c npm ci --production &&     chmod +x /app/extra/entrypoint.sh' returned a non-zero code: 254
My mqtt servers are authenticated. Does this PR allow authentication? I tried building the container from @tarun7singh master branch, but that fails, not sure why? ``` serge@minos ~/src/tmp/uptime-kuma  tarun7singh-master tarun7singh:master (1490155) via  v16.10.0 🕙14:30:52 ➞ docker build -t localhost/uptime-kuma:tarun7singh docker/ Sending build context to Docker daemon 8.192kB Step 1/28 : FROM louislam/uptime-kuma:base-debian AS build ---> bfe4b5708d38 Step 2/28 : WORKDIR /app ---> Using cache ---> 388407a9a805 Step 3/28 : ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1 ---> Using cache ---> 0aaaf81523ef Step 4/28 : COPY . . ---> Using cache ---> 094bb8b20b90 Step 5/28 : RUN npm ci --production && chmod +x /app/extra/entrypoint.sh ---> Running in e3111503ce6c npm ERR! code ENOENT npm ERR! syscall open npm ERR! path /app/package.json npm ERR! errno -2 npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json' npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2021-11-07T13_31_03_192Z-debug.log The command '/bin/sh -c npm ci --production && chmod +x /app/extra/entrypoint.sh' returned a non-zero code: 254 ```
louislam commented 3 years ago (Migrated from github.com)
Owner

@srgvg

The path need to be the project root.

Build cmd should be like this:

docker build -f docker/dockerfile -t uptime-kuma-mqtt-nightly .
@srgvg The path need to be the project root. Build cmd should be like this: ``` docker build -f docker/dockerfile -t uptime-kuma-mqtt-nightly . ```
srgvg commented 3 years ago (Migrated from github.com)
Owner

Thx @louislam
now fails diferently:

...
 ---> 202c057b84fc
Step 25/28 : ARG DIST=dist.tar.gz
 ---> Running in 547d2f42cd61
Removing intermediate container 547d2f42cd61
 ---> 57c3bf9e7c27
Step 26/28 : RUN chmod +x /app/extra/upload-github-release-asset.sh
 ---> Running in 4deae6b34faa
Removing intermediate container 4deae6b34faa
 ---> ea725e251620
Step 27/28 : RUN cd /app && tar -zcvf $DIST dist
 ---> Running in 5bba2c37f219
tar: dist: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
The command '/bin/sh -c cd /app && tar -zcvf $DIST dist' returned a non-zero code: 2

serge@minos ~/src/tmp/uptime-kuma   tarun7singh-master tarun7singh:master (1490155)  via  v16.10.0 took 2m5s187ms
🕙16:07:47 🔴2 USAGE ➞  docker build -f docker/dockerfile -t uptime-kuma-mqtt-nightly .
Thx @louislam now fails diferently: ``` ... ---> 202c057b84fc Step 25/28 : ARG DIST=dist.tar.gz ---> Running in 547d2f42cd61 Removing intermediate container 547d2f42cd61 ---> 57c3bf9e7c27 Step 26/28 : RUN chmod +x /app/extra/upload-github-release-asset.sh ---> Running in 4deae6b34faa Removing intermediate container 4deae6b34faa ---> ea725e251620 Step 27/28 : RUN cd /app && tar -zcvf $DIST dist ---> Running in 5bba2c37f219 tar: dist: Cannot stat: No such file or directory tar: Exiting with failure status due to previous errors The command '/bin/sh -c cd /app && tar -zcvf $DIST dist' returned a non-zero code: 2 serge@minos ~/src/tmp/uptime-kuma  tarun7singh-master tarun7singh:master (1490155) via  v16.10.0 took 2m5s187ms 🕙16:07:47 🔴2 USAGE ➞ docker build -f docker/dockerfile -t uptime-kuma-mqtt-nightly . ```
louislam commented 3 years ago (Migrated from github.com)
Owner

Ops, target is missing

--target release

# or 

-- target nightly

Ops, target is missing ``` --target release # or -- target nightly ```
srgvg commented 3 years ago (Migrated from github.com)
Owner

hmm, once the container started with docker run --restart=always -p 3001:3001 -v uptime-kuma:/app/data --name uptime-kuma -e NODE_ENV=development uptime-kuma-mqtt-nightly , I don't get anything in browser, only

➞  curl -iv localhost:3001/dashboard
*   Trying 127.0.0.1:3001...
* Connected to localhost (127.0.0.1) port 3001 (#0)
> GET /dashboard HTTP/1.1
> Host: localhost:3001
> User-Agent: curl/7.74.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< X-Frame-Options: SAMEORIGIN
X-Frame-Options: SAMEORIGIN
< Content-Type: text/html; charset=utf-8
Content-Type: text/html; charset=utf-8
< Content-Length: 0
Content-Length: 0
< ETag: W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"
ETag: W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"
< Date: Sun, 07 Nov 2021 17:05:10 GMT
Date: Sun, 07 Nov 2021 17:05:10 GMT
< Connection: keep-alive
Connection: keep-alive
< Keep-Alive: timeout=5
Keep-Alive: timeout=5

<
* Connection #0 to host localhost left intact
hmm, once the container started with `docker run --restart=always -p 3001:3001 -v uptime-kuma:/app/data --name uptime-kuma -e NODE_ENV=development uptime-kuma-mqtt-nightly` , I don't get anything in browser, only ``` ➞ curl -iv localhost:3001/dashboard * Trying 127.0.0.1:3001... * Connected to localhost (127.0.0.1) port 3001 (#0) > GET /dashboard HTTP/1.1 > Host: localhost:3001 > User-Agent: curl/7.74.0 > Accept: */* > * Mark bundle as not supporting multiuse < HTTP/1.1 200 OK HTTP/1.1 200 OK < X-Frame-Options: SAMEORIGIN X-Frame-Options: SAMEORIGIN < Content-Type: text/html; charset=utf-8 Content-Type: text/html; charset=utf-8 < Content-Length: 0 Content-Length: 0 < ETag: W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk" ETag: W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk" < Date: Sun, 07 Nov 2021 17:05:10 GMT Date: Sun, 07 Nov 2021 17:05:10 GMT < Connection: keep-alive Connection: keep-alive < Keep-Alive: timeout=5 Keep-Alive: timeout=5 < * Connection #0 to host localhost left intact ```
tarun7singh commented 3 years ago (Migrated from github.com)
Poster
Owner

My mqtt servers are authenticated. Does this PR allow authentication?

@srgvg No this only allows for unauthenticated mqtt servers for now, I'm planning to add this.
@louislam Currently, the main issue I'm facing and need help with is that I'm setting up a listener for MQTT messages on each heartbeat which is not ideal, is there any way to set it up once on monitor start and then update the heartbeat/data based on messages received?

> My mqtt servers are authenticated. Does this PR allow authentication? @srgvg No this only allows for unauthenticated mqtt servers for now, I'm planning to add this. @louislam Currently, the main issue I'm facing and need help with is that I'm setting up a listener for MQTT messages on each heartbeat which is not ideal, is there any way to set it up once on monitor start and then update the heartbeat/data based on messages received?
srgvg commented 3 years ago (Migrated from github.com)
Owner

No this only allows for unauthenticated mqtt servers for now

That will block me from testing this I'm afraid.

> No this only allows for unauthenticated mqtt servers for now That will block me from testing this I'm afraid.
louislam commented 3 years ago (Migrated from github.com)
Owner

hmm, once the container started with docker run --restart=always -p 3001:3001 -v uptime-kuma:/app/data --name uptime-kuma -e NODE_ENV=development uptime-kuma-mqtt-nightly , I don't get anything in browser, only

➞  curl -iv localhost:3001/dashboard
*   Trying 127.0.0.1:3001...
* Connected to localhost (127.0.0.1) port 3001 (#0)
> GET /dashboard HTTP/1.1
> Host: localhost:3001
> User-Agent: curl/7.74.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< X-Frame-Options: SAMEORIGIN
X-Frame-Options: SAMEORIGIN
< Content-Type: text/html; charset=utf-8
Content-Type: text/html; charset=utf-8
< Content-Length: 0
Content-Length: 0
< ETag: W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"
ETag: W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"
< Date: Sun, 07 Nov 2021 17:05:10 GMT
Date: Sun, 07 Nov 2021 17:05:10 GMT
< Connection: keep-alive
Connection: keep-alive
< Keep-Alive: timeout=5
Keep-Alive: timeout=5

<
* Connection #0 to host localhost left intact

I forgot that I changed the workflow recently.

You have to build the frontend first by npm run build then build the docker image.

If you don't have local development environment, I think you can go to the container shell and build inside the container:

npm ci
npm run build
> hmm, once the container started with `docker run --restart=always -p 3001:3001 -v uptime-kuma:/app/data --name uptime-kuma -e NODE_ENV=development uptime-kuma-mqtt-nightly` , I don't get anything in browser, only > > ``` > ➞ curl -iv localhost:3001/dashboard > * Trying 127.0.0.1:3001... > * Connected to localhost (127.0.0.1) port 3001 (#0) > > GET /dashboard HTTP/1.1 > > Host: localhost:3001 > > User-Agent: curl/7.74.0 > > Accept: */* > > > * Mark bundle as not supporting multiuse > < HTTP/1.1 200 OK > HTTP/1.1 200 OK > < X-Frame-Options: SAMEORIGIN > X-Frame-Options: SAMEORIGIN > < Content-Type: text/html; charset=utf-8 > Content-Type: text/html; charset=utf-8 > < Content-Length: 0 > Content-Length: 0 > < ETag: W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk" > ETag: W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk" > < Date: Sun, 07 Nov 2021 17:05:10 GMT > Date: Sun, 07 Nov 2021 17:05:10 GMT > < Connection: keep-alive > Connection: keep-alive > < Keep-Alive: timeout=5 > Keep-Alive: timeout=5 > > < > * Connection #0 to host localhost left intact > ``` I forgot that I changed the workflow recently. You have to build the frontend first by `npm run build` then build the docker image. If you don't have local development environment, I think you can go to the container shell and build inside the container: ``` npm ci npm run build ```
chakflying commented 3 years ago (Migrated from github.com)
Owner

@tarun7singh I agree that having to connect every time is a bit inefficient. I guess changing it to have a persistent connection will make it work like the push monitor type, but it would be a pretty big change.

@tarun7singh I agree that having to connect every time is a bit inefficient. I guess changing it to have a persistent connection will make it work like the push monitor type, but it would be a pretty big change.
louislam (Migrated from github.com) reviewed 3 years ago
louislam (Migrated from github.com) commented 3 years ago
Owner

Prefix mqtt_ for better meaning.

Prefix `mqtt_` for better meaning.
louislam (Migrated from github.com) commented 3 years ago
Owner

Prefix mqtt_ for better meaning.

Prefix `mqtt_` for better meaning.
louislam commented 3 years ago (Migrated from github.com)
Owner

Currently, the main issue I'm facing and need help with is that I'm setting up a listener for MQTT messages on each heartbeat which is not ideal, is there any way to set it up once on monitor start and then update the heartbeat/data based on messages received?

Although it is not the best method, I still prefer your current implementation, because it is straightforward and and it is not likely to be buggy.

While with a persistent connection, as @chakflying said, it is a big change. You may have to implement a connection pool to handle all expected and unexpected network things. Usually lead to be unstable. Also Uptime Kuma itself no such similar monitor type for reference, it is a completely new monitor type. I guess it would be hard.

> Currently, the main issue I'm facing and need help with is that I'm setting up a listener for MQTT messages on each heartbeat which is not ideal, is there any way to set it up once on monitor start and then update the heartbeat/data based on messages received? Although it is not the best method, I still prefer your current implementation, because it is straightforward and and it is not likely to be buggy. While with a persistent connection, as @chakflying said, it is a big change. You may have to implement a connection pool to handle all expected and unexpected network things. Usually lead to be unstable. Also Uptime Kuma itself no such similar monitor type for reference, it is a completely new monitor type. I guess it would be hard.
tarun7singh (Migrated from github.com) reviewed 3 years ago
tarun7singh (Migrated from github.com) commented 3 years ago
Poster
Owner

Done

Done
tarun7singh (Migrated from github.com) reviewed 3 years ago
tarun7singh (Migrated from github.com) commented 3 years ago
Poster
Owner

done

done
tarun7singh commented 3 years ago (Migrated from github.com)
Poster
Owner

@louislam
Yes, it could be added as a long-term tasks to support these types of monitors.
@srgvg
You can test it by using https://test.mosquitto.org
I tested by pushing a periodic green message to this and sending a red message to trigger a down status.
Also I'll take care to not use master branch.

@louislam Yes, it could be added as a long-term tasks to support these types of monitors. @srgvg You can test it by using https://test.mosquitto.org I tested by pushing a periodic green message to this and sending a red message to trigger a down status. Also I'll take care to not use master branch.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
Sign in to join this conversation.
Loading…
There is no content yet.