This script checks the availability of a website on the internet. It runs every 2 minutes via the server's cron. In case no response (after a set number of requests) site sends messages to Slack and/or Telegram.
-
Copy the script file
check_sites.shand the filesites.txtto the server. -
Set permissions to run the script:
chmod +x check_sites.sh -
Edit the
/etc/sites_monitor.conffile by adding the websites to be monitored. There must be an empty line at the end of the file! -
Set up the server cron, for example, by running
crontab -e. In the opened editor, add the following line (to run every 2 minutes):*/2 * * * * /path/to/check_sites.sh
-
Register a webhook (something like TRXXXXXXX/XXXXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX) in Slack and add it to line 40 of the check_sites.sh script.
-
In line 35 of the check_sites.sh script, enter the channel in which you will go messages.
-
Create a bot in Telegram and get an access token:
- Find @BotFather on Telegram and send the command /newbot.
- Follow the instructions to create a bot and receive a token.
-
Find out your chat ID:
- Find @userinfobot on Telegram and send the /start command.
- Write down the value User ID.
-
Enter the data from points 7 and 8 in lines 8 and 10 in check_sites.sh
-
Comment out lines 43-45 of the check_sites.sh file if you don’t need Telegram
-
Comment out line 40 of the check_sites.sh file if you don’t need Slack
Скрипт проверяет доступность сайта в сети интернет. Запускается каждые 2 минуты по крону сервера. В случае отсутствия ответа (после установленного количества запросов) сайта шлет сообщения в Слак и/или Телеграм
-
Скопировать файл скрипта check_sites.sh и файл sites.txt на сервер.
-
Установите права на запуск скрипта:
chmod +x check_sites.sh -
Отредактировать файл
/etc/sites_monitor.confдобавив в него сайты для мониторинга В конце файла должна быть пустая строка! -
Настроить крон сервера, например,
crontab -e. В открывшемся редакторе добавить строку (для запуска каждые 2 минуты):*/2 * * * * /path/to/check_sites.sh
-
Зарегистрируйте веб-хук (что-то типа TRXXXXXXX/XXXXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX) в Слаке и добавьте в строку 40 скрипта check_sites.sh
-
В строку 35 скрипта check_sites.sh впишите канал, в который будут идти сообщения.
-
Создайте бота в Telegram и получите токен доступа:
- Найдите @BotFather в Telegram и отправьте команду /newbot.
- Следуйте инструкциям для создания бота и получите токен.
-
Узнайте свой идентификатор чата:
- Найдите @userinfobot в Telegram и отправьте команду /start.
- Запишите значение User ID.
-
Впишите данные из пунктов 7 и 8 в строки 8 и 10 в check_sites.sh
-
Закомментируйте строки 43-45 файла check_sites.sh если не нужен Телеграм
-
Закомментируйте строку 40 файла check_sites.sh если не нужен Слак