This project is a web monitoring system that uses discord.js
to monitor the uptime status of websites and send alerts to a specified Discord channel if a website goes offline. It also provides a real-time alert system via WebSocket and an API endpoint to view the current status of the monitoring system.
Note: this app works the best with my web-monitor app to recieve notifications and view the services.
- Monitor the uptime status of a list of websites.
- Sends real-time alerts to a Discord channel if a website goes offline.
- Provides an API endpoint to view the current status of the monitoring system.
- WebSocket server to broadcast real-time alerts to connected clients.
- Slash command
/status
in Discord to retrieve the latest website status.
-
Clone the repository:
git clone https://github.com/tijnndev/web-monitor
-
Install dependencies:
npm install
-
Configure the bot:
- Create a file named
config.js
in the root directory. - Add the following configuration:
module.exports = { discord: { token: 'YOUR_BOT_TOKEN', channelID: 'YOUR_CHANNEL_ID', clientId: 'YOUR_CLIENT_ID', guildId: 'YOUR_GUILD_ID' }, websites: [ { name: 'Example Website', url: 'https://example.com' }, { name: 'Example2 Website', url: 'https://example2.com' } ] };
- Create a file named
-
Start the bot:
node index.js
- The bot automatically checks the status of websites periodically (default is daily at midnight using
node-cron
). - If a website goes offline, the bot sends an alert to the specified Discord channel and notifies connected WebSocket clients.
- /status: Use this command in Discord to view the current status of all monitored websites.
- The bot responds with an embed showing the status of each website.
- The API runs on http://localhost:3000/status. This endpoint shows the status of all monitored websites and whether they are online or offline.
- A WebSocket server runs on port
8082
to broadcast real-time alerts. Any connected clients will receive updates when websites go online or offline.
- index.js: Main bot logic that handles WebSocket connections and Express API.
- config.js: Configuration file for Discord credentials and monitored websites.
- websiteMonitor.js: Defines the functions that returns the status of the websites.
- tokenManager.js: Defines the functions to manage the FCM Tokens.
- firebase.js: Manages the connection with Firebase.
- discord.js: Manages the connection with discord.
- discord.js - For building the Discord bot and interacting with Discord APIs.
- axios - For making HTTP requests to check the status of websites.
- node-cron - For scheduling periodic tasks such as checking website statuses.
- express - For setting up the web API to retrieve the status of monitored websites.
- ws - For managing real-time WebSocket connections.
config.js
module.exports = {
discord: {
token: 'YOUR_BOT_TOKEN',
channelID: 'YOUR_CHANNEL_ID',
clientId: 'YOUR_CLIENT_ID',
guildId: 'YOUR_GUILD_ID'
},
websites: [
{ name: 'Example Website', url: 'https://example.com' },
{ name: 'Example2 Website', url: 'https://example2.com' }
]
};
When a user types /status
, the bot will respond with an embed like:
Embed Example: Website Status Check:
https://example.com
: ONLINEhttps://example2.com
: OFFLINE
To access the status of the monitored websites, you can use the following API endpoint:
GET /status
- Response example:
{ "status": "Monitoring active", "websites": [ { "name": "Example 1", "url": "https://example.com" }, { "name": "Example 2", "url": "https://example2.com" } ] }
Clients can connect to the WebSocket server running on ws://localhost:8082
. Once connected, they will receive real-time updates about website status changes.
Example WebSocket Message:
{
"url": "https://example2.com",
"status": "ONLINE"
}
- The bot uses
node-cron
to schedule website checks. - Alerts are sent to a specified Discord channel when a website goes offline.
- The WebSocket server broadcasts real-time alerts to clients.
- The bot sends updates to a Discord channel if any monitored website goes offline.
- A
/status
slash command provides real-time website status via Discord embeds.
- An Express-based API exposes the current status of monitored websites at
/status
.
- A WebSocket server broadcasts website status changes to connected clients on port
8082
.
- Fork the repository.
- Create a new branch:
git checkout -b feature/YourFeature
. - Commit your changes:
git commit -m 'Add some feature'
. - Push to the branch:
git push origin feature/YourFeature
. - Open a pull request.