Build precise queries to find exactly what you need
Press ESC to close
I do not know what the correct way is here to publish/suggest patches. I implemented pjsip for this plugin:
— check_asterisk_peers 2025-04-10 08:45:57.319369355 +0200 +++ check_asterisk_peers_pjsip 2025-04-10 09:11:59.703011415 +0200 @@ -3,6 +3,8 @@ # Check asterisk peers plugin for Nagios. # Written by Chad Phillips ([email protected]) # Last Modified: 2009-05-02 +# modified by Paul Neuwirth ([email protected]) to include pjsip +# 2025-04-10
ASTERISK=/usr/sbin/asterisk
@@ -13,7 +15,7 @@
print_usage() { echo ” -Usage: check_asterisk_peers [–type | -t ] [–peers | -p ] [–registrations | -r ] [–verify-peers] [–verify-registrations] [–config-file ] +Usage: check_asterisk_peers [–type | -t ] [–peers | -p ] [–registrations | -r ] [–verify-peers] [–verify-registrations] [–config-file ] Usage: check_asterisk_peers –help | -h
Description: @@ -62,6 +64,7 @@ Default value is based on the –type setting:
sip: /etc/asterisk/sip.conf + pjsip: /etc/asterisk/pjsip.conf iax: /etc/asterisk/iax.conf
–help | -h Print this help and exit. @@ -227,12 +230,14 @@ done
# Make sure we have a valid peer type. -if [ “$peer_type” != “” ] && [ “$peer_type” != “sip” ] && [ “$peer_type” != “iax” ]; then – echo “Peer type must be one of: sip, iax.” +if [ “$peer_type” != “” ] && [ “$peer_type” != “sip” ] && [ “$peer_type” != “pjsip” ] && [ “$peer_type” != “iax” ]; then + echo “Peer type must be one of: sip, iax, pjsip.” exit $STATE_UNKNOWN # Convert iax type into internal iax2 type for the Asterisk executable. elif [ “$peer_type” = “iax” ]; then peer_type=iax2 +elif [ “$peer_type” = “pjsip” ]; then + peer_type=pjsip # Default type is SIP. else peer_type=sip @@ -247,6 +252,8 @@ if [ “$conf_file” = “” ]; then if [ “$peer_type” = “iax2” ]; then conf_file=/etc/asterisk/iax.conf + elif [ “$peer_type” = “pjsip” ]; then + conf_file=/etc/asterisk/pjsip.conf else conf_file=/etc/asterisk/sip.conf fi @@ -258,10 +265,15 @@ if [ “$registrations” ]; then for r in $registrations do – REGISTRATION_FORMAT_CORRECT=`echo “$r” | grep “.+@.+”` – if [ ! “$REGISTRATION_FORMAT_CORRECT” ]; then – echo “Registration $r is not in the valid username@uri format.” – exit $STATE_UNKNOWN + if [ “$peer_type” != “pjsip” ]; then + REGISTRATION_FORMAT_CORRECT=`echo “$r” | grep “.+@.+”` + if [ ! “$REGISTRATION_FORMAT_CORRECT” ]; then + echo “Registration $r is not in the valid username@uri format.” + exit $STATE_UNKNOWN + fi + else + #no limitations for pjsip registrations, afaik + REGISTRATION_FORMAT_CORRECT=1 fi done fi @@ -277,31 +289,55 @@ for p in $peers do if [ “$verify_peers” ]; then – peer_verified=`echo “$all_config” | grep “^[${p}]$”` + peer_verified=`echo “$all_config” | grep “^[${p}].*$”` else peer_verified=1 fi if [ “$peer_verified” ]; then # Fetch the data from asterisk. – command_output=`$ASTERISK -rx “$peer_type show peer $p” 2>&1` – check_asterisk_result $? “$command_output” – status=`echo “$command_output” | grep “^[[:space:]]*Status[[:space:]]*:” | awk ‘{print $3;}’` – if [ “$status” = “OK” ]; then – if [ “$test_ok” ]; then – test_ok=”${test_ok}, $p” + if [ “$peer_type” = “pjsip” ]; then + command_output=`$ASTERISK -rx “$peer_type show endpoint $p” 2>&1` + check_asterisk_result $? “$command_output” + status=`echo “$command_output” | grep “^sEndpoint:s*$p.*” | awk -F’ +’ ‘{print $3;}’` + if [ “$status” = “Not in use” ] || [ “$status” = “In use” ]; then + if [ “$test_ok” ]; then + test_ok=”${test_ok}, $p” + else + test_ok=”$p” + fi else – test_ok=”$p” + if [ “$status” ]; then + status_error=”$status” + else + status_error=”Not found” + fi + if [ “$test_errors” ]; then + test_errors=”${test_errors}, ${p}: $status_error” + else + test_errors=”${p}: $status_error” + fi fi else – if [ “$status” ]; then – status_error=”$status” – else – status_error=”Not found” – fi – if [ “$test_errors” ]; then – test_errors=”${test_errors}, ${p}: $status_error” + command_output=`$ASTERISK -rx “$peer_type show peer $p” 2>&1` + check_asterisk_result $? “$command_output” + status=`echo “$command_output” | grep “^[[:space:]]*Status[[:space:]]*:” | awk ‘{print $3;}’` + if [ “$status” = “OK” ]; then + if [ “$test_ok” ]; then + test_ok=”${test_ok}, $p” + else + test_ok=”$p” + fi else – test_errors=”${p}: $status_error” + if [ “$status” ]; then + status_error=”$status” + else + status_error=”Not found” + fi + if [ “$test_errors” ]; then + test_errors=”${test_errors}, ${p}: $status_error” + else + test_errors=”${p}: $status_error” + fi fi fi else @@ -314,8 +350,8 @@ done fi
-# Check registrations. -if [ “$registrations” ]; then +# Check registrations. not pjsip +if [ “$peer_type” != “pjsip” ] && [ “$registrations” ]; then # Fetch the data from asterisk. command_output=`$ASTERISK -rx “$peer_type show registry” 2>&1` check_asterisk_result $? “$command_output” @@ -364,6 +400,50 @@ done fi
+# Check registrations. pjsip +if [ “$peer_type” = “pjsip” ] && [ “$registrations” ]; then + # Fetch the data from asterisk. + command_output=`$ASTERISK -rx “$peer_type show registrations” 2>&1` + check_asterisk_result $? “$command_output” + for r in $registrations + do + if [ “$verify_registrations” ]; then + # best what can be done without getting too deep into config file (type=registration might be part of a template…) + registration_verified=`echo “$all_config” | grep “^[${r}].*$”` + else + registration_verified=1 + fi + if [ “$registration_verified” ]; then + # This regex isn’t perfect, but it does the trick ok. + status=`echo “$command_output” | grep “^s$r/.*” | awk -F’ +’ ‘{ print $3;}’` + if [ “$status” = “Registered” ]; then + if [ “$test_ok” ]; then + test_ok=”${test_ok}, $r” + else + test_ok=”$r” + fi + else + if [ “$status” ]; then + status_error=”$status” + else + status_error=”Not found” + fi + if [ “$test_errors” ]; then + test_errors=”${test_errors}, ${r}: $status_error” + else + test_errors=”${r}: $status_error” + fi + fi + else + if [ “$test_ok” ]; then + test_ok=”${test_ok}, $r (not active)” + else + test_ok=”$r (not active)” + fi + fi + done +fi + if [ “$test_errors” ]; then output=”$output ERROR: $test_errors” set_exit_status $STATE_CRITICAL @@ -379,4 +459,4 @@ fi
echo “$output” -exit $exitstatus No newline at end of file +exit $exitstatus
We’ve completely redesigned the world’s largest repository of Nagios plugins and monitoring tools. Join thousands of users sharing monitoring solutions for servers, applications, and everything in between.
Due to our redesign, all existing accounts require a password reset to access your account again.
Ready to explore 6,100+ projects and contribute to the community?
Reset Password Create Account
Happy Monitoring!