-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Paolo Trivisonno edited this page Apr 23, 2025
·
2 revisions
- ✅ LibreNMS installato e funzionante
- ✅ PHP 8.0+ con estensione
curl - ✅ Accesso al terminale (Linux/Unix)
- ✅ Comandi disponibili:
ping,traceroute,nmap,nslookup - ✅ Un bot Telegram creato tramite @BotFather
- Apri @BotFather
- Esegui
/newbot - Dai un nome e uno username (es.
NMS_AlertBot) - Copia il token che ti viene restituito
Per recuperare chat_id e (se necessario) message_thread_id:
- Invia un messaggio al tuo bot (in chat privata o in un gruppo dove l'hai aggiunto)
- Poi visita questo URL nel browser (sostituendo
<TOKEN>con quello reale):
https://api.telegram.org/bot<TOKEN>/getUpdates
Cerca nel JSON restituito:
-
"chat": { "id": ... }→ è ilchat_id -
"message_thread_id": ...→ se usi thread nei gruppi
git clone https://github.com/paolo-trivi/telegram-librenms-bot.git
cd telegram-librenms-botApri il file config.php e modifica le seguenti righe:
$botToken = 'INSERISCI_TOKEN_BOT';
$librenmsUrl = 'http://nms.example.net'; // https://nms.example.com:port
$librenmsToken = 'INSERISCI_TOKEN_API_LIBRENMS';
$allowedChatIds = [12345678, -100987654321]; // ID della tua chat o gruppo
$allowedThreads = [null, 24]; // Opzionale: ID thread nel gruppo📌 Per ottenere il token API in LibreNMS:
→ Impostazioni utente → API Settings → Generate API Token
Lancia lo script con:
php bot.phpPer tenerlo attivo anche dopo il logout, puoi usare screen:
screen -S telegrambot
php bot.php
# Ctrl+A / D per staccare la sessioneOppure crea un servizio systemd.
Apri la chat (privata o gruppo) dove è presente il bot e prova:
/help
/list
/ack 1234 alert preso in carico
/ping 8.8.8.8
Per problemi o suggerimenti:
- Apri una issue su GitHub