A Telegram Bot which provides notifications about your server.
- Node.js application to provide server notifications
- Telegram Bot framework for the Chat UI and architecture. Almost no work required
- Telegram Bot API(node-telegram-bot-api) for communicating with user. Simple and effective.
- Used node-cron to make periodic requests more simple and manageable
- Integrated with Twilio for messaging service when the app is down
- Used ngrok for a secure and certified server to run this on during testing and development
- Integrated with Firebase for a realtime DB with minimal setup and simple JSON Structure makes it convenient to use in Node.js
- Deployed on Heroku which is quite easy to use and manageable with git
- Monitor your server periodically
- Get instant notifications if your server is down.
- Get CPU and memory usage
- Get top processes
- Check System Timing stats
- Limited Shell executions
- Signup on Telegram and get @Server23TestBot Telegram Bot (No sane name was available)
- Signup for Twilio and replace the credentials in
config.json
with your own. This allows you to get SMS notifications when your server is down - Enter any of the commands listed in commands section below
- Enjoy
- NPM
- Node.js : LTS version 6.10.2
- ngrok : Provides a secure and certified server to run this on during development
- Heroku : For easy deployment (you may use other services)
- Twilio : For SMS service
- Firebase : For realtime DB
- Telegram : For the bot framework
- Change the
config.json
file based on your requirements and API keys and such
{
"port": 4041,
"bodyLimit": "100kb",
"corsHeaders": ["Link"],
"botToken": "<telegram-bot-token>",
"devUrl": "<secure-ngrok-url>",
"prodUrl": "<production-url>",
"twilioAccountId": "<twilio-account-id>",
"twilioKey": "<twilio-key>",
"twilioNum": "<twilio-given-number>",
"clientNum": "<your-personal-twilio-registered-number>"
}
-
Next, you will need to create a Firebase account if you don't have one already. Create a new project and generate your SDK. Check the Firebase docs for a step by step guide.
-
At the end of it, you should have downloaded an SDK file. Copy the contents of that file into
firebase-admin-sdk
file in thesrc
directory. This links your project to the Firebase realtime DB. -
Signup on Telegram and ask @BotFather to give you a new Telegram Bot along with it API key, which you enter into
config.json
. Check this Telegram Guide. -
Signup on Twilio and create a programmable SMS service. It's free of cost! After you generate the Twilio number, add it to
config.json
along with the number where you would like to receive SMSs from the bot. -
To install all the node modules locally, run
npm install
. -
To start the server locally, you can start up ngrok on the same port as in the
config.json
file (4041 by default) using the commandngrok http <port-number>
. -
Now, run
npm run dev
to start the server. Test out the Bot by sending it one of the commands listed below.
Command | Description |
---|---|
/startmonitor <url> |
starts monitoring the url checking for uptime. Sends periodic notifications on Telegram. Report is sent every minute(can be changed by modifying the cron task). Sends SMS if down and stops monitoring. Use /stop if you want the monitoring to stop. |
/stop |
stops monitoring the url |
/status <url> |
a single report of the server is given rather than continuous monitoring |
/memstats |
reports the cpu and memory usage of the server |
/processes |
reports the top 5 memory consuming processes on your server(currently returns any 5 processes (unordered) in production) |
/timestats |
does a timed test and reports the total system and total user time in that interval |
/exec <cmd> |
executes the <cmd> command on the server. Currently, only for non-interactive commands |
- The data sent to the user is in JSON, needs to be formatted for a decent UX
- Currently works only for single user. Need to setup a db architecture that allows multiple users to be notified simultaneously
- Better memory and process stats with more control and information
- Execute interactive commands
- Allow user to modify the report and server monitoring frequency (currently a report is sent every minute to telegram)
- Add NLP capabilities to improve overall UX
- Move this code to an independent server so that any server can setup an endpoint to get stats for their server