This is a simple and effective application designed to monitor server uptime. It leverages webhooks and serverless functions to send real-time notifications to maintainers whenever the server experiences downtime. The application uses Cronitor for monitoring and Twilio for sending notifications. The serverless functions are hosted on Netlify.
Follow these steps to set up and run the application locally:
Installation
-
Clone this repository to your local machine:
git@github.com:PivotForge/server-monitor.git
-
Install the necessary dependencies:
npm install
This project uses the following dependencies:
twilio
: For sending SMS notifications.dotenv
: For managing environment variables.
Local Development
-
Start the local development server using the following command:
netlify dev
This command initializes the server on port
8080
. Once running, navigate to the following endpoint to confirm it's working:http://localhost:8080/.netlify/functions/webhook-handler
Yous should be able to see a screen with this message:
{ "message": "Listening" }
-
Expose your local server using Ngrok:
ngrok http http://localhost:8080
Ngrok will generate a temporary public URL
(e.g., https://example.ngrok.io)
. Copy this URL for use in the next steps.
Configuring Cronitor
- Log in to Cronitor and configure a monitoring job.
- Set the webhook URL for alerts to your Ngrok public URL
(e.g., https://example.ngrok.io/.netlify/functions/webhook-handler)
. - Save the configuration. Cronitor will now send server downtime alerts to your webhook.
Testing the Webhooks
- Use Cronitor to trigger a test alert.
- Monitor the logs from
netlify dev
to confirm the webhook was received. - Verify that notification was sent successfully.
Deployment
To deploy the serverless function to Netlify:
- Commit your changes and push to the repository linked to your Netlify project.
- Deploy the updated project via the Netlify dashboard or CLI:
netlify deploy
Netlify will assign a unique URL to your deployed function. Update your Cronitor webhook URL to point to the deployed endpoint.
Resources