Skip to content

Instantly share code, notes, and snippets.

@kura1420
Created May 30, 2025 02:06
Show Gist options
  • Select an option

  • Save kura1420/f0f73ca1ad554d7b8db3a04bf72911e7 to your computer and use it in GitHub Desktop.

Select an option

Save kura1420/f0f73ca1ad554d7b8db3a04bf72911e7 to your computer and use it in GitHub Desktop.
Monitoring Asterisk
#!/bin/bash
IP_SERVER="192.168.1.1"
TELEGRAM_BOT_TOKEN="123:abc"
TELEGRAM_CHAT_ID="-100"
TELEGRAM_TOPIC_ID="1419"
DOWN_PEERS=$(/usr/sbin/asterisk -rx "sip show peers" | grep -E "UNREACHABLE|UNKNOWN")
if [[ -n "$DOWN_PEERS" ]]; then
MESSAGE="[${IP_SERVER}] SIP Peer DOWN:\n\n"
while IFS= read -r line; do
NAME=$(echo "$line" | awk '{print $1}')
IP=$(echo "$line" | awk '{print $2}')
STATUS=$(echo "$line" | awk '{print $NF}')
MESSAGE+="- ${NAME} (${IP}) - ${STATUS}\n"
done <<< "$DOWN_PEERS"
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
-d chat_id="${TELEGRAM_CHAT_ID}" \
-d message_thread_id="${TELEGRAM_TOPIC_ID}" \
--data-urlencode "text=$(echo -e "$MESSAGE")"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment