Skip to content

andrelcmadeira/OpnSense-MultiWan-Telegram

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 

Repository files navigation

OpnSense-MultiWan-Telegram

  • Script for OPNsense: monitors multi-WAN gateway status and sends notifications via Telegram (or email with Monit service)

Donation | Doações

(En)      Support our project via Pix or PayPal.
(Pt-Br) Apoie nosso projeto via Pix ou PayPal:

Screenshot

Screenshot

Overview (En)

This project provides two scripts for monitoring the status of gateways in OPNsense and sending alerts to Telegram.

The gateway_multiwan script monitors the offline, packet loss, online, or unknown status of all gateways found in opnSense. If any of them change, it sends an alert using the sendTelegram.sh file to a group, via a Telegram bot. If the SMTP alert is configured, it will also be sent to your email. For it to work, the script needs to be added to your opnSense and set up to be executed and triggered by events through the already included package called Monit.

Requirements

  • OPNsense Firewall
  • SSH terminal
  • Download the two files from this GitHub repository (stable version) to your machine with OPNsense
  • Telegram Account

Quick Installation Guide

  1. Enable SSH on OpnSense
  2. Download Files
  3. Set Permissions
  4. Configure Telegram
  5. Edit sendTelegram.sh
  6. Enable Monit Service
  7. Enable Script
  8. Test

Detailed Installation Guide

  1. Enable SSH on OpnSense and download the files
    1.1 Enable SSH on OpnSense: System > Settings > Administration
    1.2 Access OpnSense via SSH from terminal: ssh [email protected]. Replace root with your username and 192.168.1.1 with your OpnSense IP address.
    1.3 Navigate to the Monit service folder: cd /usr/local/opnsense/scripts/OPNsense/Monit
    1.4 Use fetch to download "gateway_multiwan" and "sendTelegram.sh' from GitHub:
    fetch https://github.com/macielmeireles/opnsense_gateways_status/blob/main/versions/stable/0.6/gateway_multiwan && fetch https://github.com/macielmeireles/opnsense_gateways_status/blob/main/versions/stable/0.6/sendTelegram.sh

  2. Set Permissions:
    2.1 Set +x permission on the files:
    chmod +x gateway_multiwan sendTelegram.sh

  3. Telegram Configuration:
    3.1 Create a Telegram group.
    3.2 Create a bot with "BotFather".
    3.3 Note down the bot token.
    3.4 Add the bot and yourself to the group.
    3.5 Get the group ID from the URL.

  4. Configure sendTelegram.sh:
    4.1 Open sendTelegram.sh in a text editor.
    4.2 Update TOKEN and CHAT_ID with your bot token and group ID.

  5. Enable Monit Service:
    5.1 In OPNsense, go to Services > Monit > Services and click on Enable Monit.
    5.2 Set your preferred polling interval.

  6. Enable Script:
    6.1 OPNsense, go to Services > Monit > Services and duplicate the pre-existing service called gateway_alert.
    6.2 In the Duplicate Item dialog box, enter a name for the new service, such as "gateway_multiwan".
    6.3 In the Path field, enter the path to the shell script, such as /usr/local/opnsense/scripts/OPNsense/Monit/gateway_multiwan.
    6.4 In Tests field, uncheck "NonZeroStatus" and check "ChangedStatus".
    6.5 Click Save and Apply.

Testing the Script
To test the script, manually disable a WAN link in OPNsense. You should receive a Telegram alert.

For more details on how to get your bot token in Telegram[^1^][2] or how to get your chat ID in Telegram, you can refer to these links.

(1) How to Generate a Token for Telegram Bot API | https://medium.com/geekculture/generate-telegram-token-for-bot-api-d26faf9bf064
(2) How to Find a Chat ID in Telegram | https://www.alphr.com/find-chat-id-telegram/

(pt-br) Script de Monitoramento Multiwan Gateway no OPNsense e alerta via Telegram

Visão Geral

Este projeto fornece dois arquivos para monitorar o status dos gateways no OPNsense e enviar alertas para o Telegram.

O script gateway_multiwan monitora os status offline, perda de pacote, online ou desconhecido de todos os gateways encontrados no opnSense. Se algum deles mudar, ele envia um alerta usando o arquivo sendTelegram.sh para um grupo, via um bot do Telegram. Caso o alerta SMTP esteja configurado, também será enviado para seu e-mail. Para funcionar, o script precisa ser adicionado em seu opnSense e para ser executado e acionado por eventos através do pacote já incluído chamado Monit.

Requisitos

  • Firewall OPNsense
  • Conta do Telegram
  • Acesso ao Shell
  • Baixe os dois arquivos deste repositório do GitHub (versão stable) para sua máquina com OPNsense

Guia de Instalação Rápida

  1. Baixar Arquivos
  2. Definir Permissões
  3. Configurar Telegram
  4. Editar sendTelegram.sh
  5. Habilitar Serviço Monit
  6. Habilitar Script

Guia Detalhado de Instalação

  1. Ative o SSH no OpnSense e baixe os arquivos
    1.1 Ative o SSH no OpnSense: Sistema > Configurações > Administração
    1.2 Acesse o OpnSense via SSH a partir do terminal, exemplo: ssh [email protected]
    1.3 Navegue até a pasta do serviço Monit: cd /usr/local/opnsense/scripts/OPNsense/Monit
    1.4 Use fetch para baixar "gateway_multiwan" e "sendTelegram.sh' do GitHub:
    fetch https://github.com/macielmeireles/opnsense_gateways_status/blob/main/versions/stable/0.6/gateway_multiwan && fetch https://github.com/macielmeireles/opnsense_gateways_status/blob/main/versions/stable/0.6/sendTelegram.sh

  2. Defina as Permissões

    2.1 Defina a permissão +x nos arquivos:
    chmod +x gateway_multiwan sendTelegram.sh

  3. Configuração do Telegram
    3.1 Crie um grupo no Telegram.
    3.2 Crie um bot com o "BotFather".
    3.3 Anote o token do bot.
    3.4 Adicione o bot e você mesmo ao grupo.
    3.5 Obtenha o ID do grupo a partir da URL.

  4. Configure o sendTelegram.sh
    4.1 Abra o sendTelegram.sh em um editor de texto.
    4.2 Atualize TOKEN e CHAT_ID com o token do seu bot e o ID do grupo.

  5. Ative o Serviço Monit
    5.1 No OPNsense, vá para Serviços > Monit > Serviços e clique em Ativar Monit.
    5.2 Defina o intervalo de pesquisa de sua preferência.

  6. Ative o Script
    6.1 No OPNsense, vá para Serviços > Monit > Serviços e duplique o serviço pré-existente chamado gateway_alert.
    6.2 Na caixa de diálogo Duplicar Item, insira um nome para o novo serviço, como "gateway_multiwan".
    6.3 No campo Caminho, insira o caminho para o script shell, como /usr/local/opnsense/scripts/OPNsense/Monit/gateway_multiwan.
    6.4 No campo Testes, desmarque "NonZeroStatus" e marque "ChangedStatus".
    6.5 Clique em Salvar e Aplicar.

Testando o Script
Para testar o script, desative manualmente um link WAN no OPnSense.
Você deve receber um alerta no Telegram.

About

OpnSense | MultiWan Status Script with Telegram Notification

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 95.4%
  • Shell 4.6%