Skip to content

Commit

Permalink
added Gotify integration
Browse files Browse the repository at this point in the history
  • Loading branch information
petersem committed May 21, 2024
1 parent 81cceac commit 2886efc
Show file tree
Hide file tree
Showing 6 changed files with 591 additions and 23 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Monitors Docker (MONitors dOCKER) containers and alerts on 'state' change.
- Telegram
- Pushbullet
- Pushover
- Discord (via webhooks)
- Discord
- Ntfy
- Slack

- Gotify

## Future Considerations
- Additional messaging platform support
Expand All @@ -33,11 +33,11 @@ services:
# DOCKER_HOST: tcp://docker-socket-proxy:2375
# Optional label to preface messages. Handy if you are running multiple versions of Monocker
SERVER_LABEL: 'Your server name'
# Optional avatar image URL to add to messages. Handy if you are running Monocker on different machines
# - supported by discord & ntfy (mobile app) & slack
SERVER_AVATAR: ''
# Optional avatar image URL to add to messages. Handy if you are running Monocker on different machines (discord, ntfy, and slack)
SERVER_AVATAR: 'https://content.invisioncic.com/u329766/monthly_2024_05/monocker.png.ba5ffdb390b627097d2a53645cf87350.png'
# Specify the messaging platform and details, or leave blank if only wanting container logs (pick one only)
MESSAGE_PLATFORM: 'telegram@your_bot_id@your_chat_id'
# MESSAGE_PLATFORM: 'gotify@app_token'
# MESSAGE_PLATFORM: 'pushbullet@your_api_key@your_device_id'
# MESSAGE_PLATFORM: 'pushover@your_user_key@your_app_api_token'
# MESSAGE_PLATFORM: 'discord@webhook_url'
Expand All @@ -54,12 +54,10 @@ services:
PERIOD: 30
# [Optional] - Supress startup messages from being sent. Default is false
DISABLE_STARTUP_MSG: 'false'
## ADVANCED NTFY SETTINGS
#CUSTOM_NTFY_SERVER: 'https://custom.ntfy.com' # use your own NTFY server
#NTFY_USER: 'user' # use a username and password to login (on ntfy.sh or your own server. Option if you have your own server open)
#NTFY_PASS: 'password'
# [optional] - adds SHA ID for all container references. 'true' or 'false' (default)
SHA: 'false'
volumes:
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ services:
# MESSAGE_PLATFORM: 'pushbullet@your_api_key@your_device_id'
# MESSAGE_PLATFORM: 'pushover@your_user_key@your_app_api_token'
MESSAGE_PLATFORM: 'discord@webhook_url'
# MESSAGE_PLATFORM: 'gotify@app_token'
# MESSAGE_PLATFORM: 'ntfy@topic_title'
# MESSAGE_PLATFORM: 'slack@bot_user_oauth_token@your_chat_id'
# MESSAGE_PLATFORM: ''
Expand Down
39 changes: 27 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import Pushover from 'node-pushover';
import { Webhook } from 'discord-webhook-node';
import { NtfyClient } from 'ntfy';
import { WebClient } from '@slack/web-api';
import { gotify } from 'gotify';

process.on('warning', (warning) => {
console.log(warning.stack);
});
Expand Down Expand Up @@ -50,6 +52,7 @@ let runClock;
console.log("-------------------------------------------------------");
console.log(" Monocker - MONitor dOCKER container states");
console.log(" Developed by Matt Petersen - Brisbane Australia");
console.log(" Donate: https://www.paypal.com/paypalme/thanksmp")
console.log(" ");
console.log(" Version: " + pjson.version);
console.log("-------------------------------------------------------");
Expand Down Expand Up @@ -80,6 +83,16 @@ async function sendPushbullet(title, message) {
});
}

async function sendGotify(title, message) {
await gotify({
server: msgDetails[1],
app: msgDetails[2],
title: title,
message: message,
priority: 5
});
}

async function sendPushover(title, message) {
var push = new Pushover({
token: msgDetails[2],
Expand Down Expand Up @@ -174,6 +187,9 @@ async function send(message) {
case "slack":
sendSlack(title, message);
break;
case "gotify":
sendGotify(title, message);
break;
case "default":
// do nothing
break;
Expand Down Expand Up @@ -234,15 +250,14 @@ async function list() {
}
if (ONLY_OFFLINE_STATES == 'true') {
if (offlineStates.includes(c.State) || offlineStates.includes(c.State + " " + hcStatus)) {
console.log(" - " + output);
console.log(" - " + output);
//send(output);
messages += output + "\r\n";
}
}
else {
console.log(" - " + output);
//send(output);
console.log('*****' + output);
messages += output + "\r\n";
}
}
Expand All @@ -257,16 +272,16 @@ async function list() {
console.log(" - Currently monitoring " + newConArray.length + " (running) containers");
if(DISABLE_STARTUP_MSG.toLowerCase()!='true'){
//send("Currently monitoring " + newConArray.length + " (running) containers");
messages =`Monitoring started
-- Version: ` + pjson.version + `
-- Messaging platform: ` + MESSAGE_PLATFORM.split("@")[0] +`
-- Polling period: ` + PERIOD + ` seconds` +`
-- Only offline state monitoring: ` + ONLY_OFFLINE_STATES +`
-- Only include labelled containers: ` + LABEL_ENABLE +`
-- Do not monitor 'Exited': ` + EXCLUDE_EXITED +`
-- Disable Startup Messages: ` + DISABLE_STARTUP_MSG +`
-- Display SHA ID: ` + SHA +`
`;
messages ="Monitoring started" + `
- Version: ` + pjson.version + `
- Messaging platform: ` + MESSAGE_PLATFORM.split("@")[0] +`
- Polling period: ` + PERIOD + ` seconds` +`
- Only offline state monitoring: ` + ONLY_OFFLINE_STATES +`
- Only include labelled containers: ` + LABEL_ENABLE +`
- Do not monitor 'Exited': ` + EXCLUDE_EXITED +`
- Disable Startup Messages: ` + DISABLE_STARTUP_MSG +`
- Display SHA ID: ` + SHA +`
`;
messages += "Currently monitoring " + newConArray.length + " (running) containers" + "\r\n";
}
isFirstRun=false;
Expand Down
Loading

0 comments on commit 2886efc

Please sign in to comment.