Skip to content

Commit 5cefa29

Browse files
committed
monofon-health: update to support pjsip
1 parent 03a4158 commit 5cefa29

File tree

1 file changed

+57
-18
lines changed

1 file changed

+57
-18
lines changed

scripts/monofon/monofon-health.sh

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -246,25 +246,55 @@ function check_concurrent_calls() {
246246

247247
function check_trunks() {
248248
echo_status "Checking the statuses of the Trunks"
249-
trunk_list=$(asterisk -rx "sip show peers" | grep -E '^[a-zA-Z]' | sed '1d')
249+
250+
# Check if PJSIP is being used by trying to run a PJSIP command
251+
if asterisk -rx "module show like pjsip" 2>/dev/null | grep -q "res_pjsip.so"; then
252+
# PJSIP mode - use pjsip show contacts for a cleaner output
253+
trunk_list=$(asterisk -rx "pjsip show contacts" | grep -E '^[[:space:]]*Contact:' | grep -v "Objects found" | sed '1d' | sed 's/^[[:space:]]*Contact:[[:space:]]*//')
250254

251-
OLDIFS=$IFS
252-
IFS=$'\n'
253-
for trunk in $trunk_list; do
254-
trunk_status=$(echo "$trunk" | awk '{print $6}')
255-
trunk_name=$(echo "$trunk" | awk '{print $1}')
256-
if containsElement "$trunk_name" "${IGNORED_TRUNKS[@]}"; then
257-
continue
258-
fi
259-
if [ "$trunk_status" != "OK" ]; then
260-
print_colour "$trunk_name" "${trunk_status}" "error"
261-
alarm_check_down "$trunk_name" "Trunk $trunk_name is ${trunk_status} at $IDENTIFIER" "trunk"
262-
else
263-
alarm_check_up "$trunk_name" "Trunk $trunk_name is ${trunk_status} again at $IDENTIFIER" "trunk"
264-
print_colour "$trunk_name" "OK"
265-
fi
266-
done
267-
IFS=$OLDIFS
255+
OLDIFS=$IFS
256+
IFS=$'\n'
257+
for trunk in $trunk_list; do
258+
# Extract trunk name and status from contact line
259+
trunk_name=$(echo "$trunk" | awk '{print $1}' | cut -d'/' -f1)
260+
trunk_status=$(echo "$trunk" | awk '{print $3}')
261+
262+
if containsElement "$trunk_name" "${IGNORED_TRUNKS[@]}"; then
263+
continue
264+
fi
265+
266+
# The status in pjsip show contacts is "Avail" instead of "OK"
267+
if [ "$trunk_status" != "Avail" ] && [ "$trunk_status" != "Available" ]; then
268+
print_colour "$trunk_name" "${trunk_status}" "error"
269+
alarm_check_down "$trunk_name" "Trunk $trunk_name is ${trunk_status} at $IDENTIFIER" "trunk"
270+
else
271+
alarm_check_up "$trunk_name" "Trunk $trunk_name is OK again at $IDENTIFIER" "trunk"
272+
print_colour "$trunk_name" "OK"
273+
fi
274+
done
275+
IFS=$OLDIFS
276+
else
277+
# Original SIP mode
278+
trunk_list=$(asterisk -rx "sip show peers" | grep -E '^[a-zA-Z]' | sed '1d')
279+
280+
OLDIFS=$IFS
281+
IFS=$'\n'
282+
for trunk in $trunk_list; do
283+
trunk_status=$(echo "$trunk" | awk '{print $6}')
284+
trunk_name=$(echo "$trunk" | awk '{print $1}')
285+
if containsElement "$trunk_name" "${IGNORED_TRUNKS[@]}"; then
286+
continue
287+
fi
288+
if [ "$trunk_status" != "OK" ]; then
289+
print_colour "$trunk_name" "${trunk_status}" "error"
290+
alarm_check_down "$trunk_name" "Trunk $trunk_name is ${trunk_status} at $IDENTIFIER" "trunk"
291+
else
292+
alarm_check_up "$trunk_name" "Trunk $trunk_name is ${trunk_status} again at $IDENTIFIER" "trunk"
293+
print_colour "$trunk_name" "OK"
294+
fi
295+
done
296+
IFS=$OLDIFS
297+
fi
268298
}
269299

270300
function asterisk_error_check() {
@@ -381,6 +411,7 @@ function check_data_file() {
381411
function main() {
382412
create_pid
383413
is_old=0
414+
384415
# Checks if systemctl is present, if not it uses service instead
385416
if [ -z "$(command -v systemctl)" ]; then
386417
is_old=1
@@ -390,7 +421,15 @@ function main() {
390421
if [ "$out" == "mysql: unrecognized service" ]; then
391422
SERVICES[4]="mysqld"
392423
fi
424+
else
425+
# Check web server service name (httpd vs apache2)
426+
if systemctl list-unit-files | grep -q "apache2.service"; then
427+
SERVICES[3]="apache2"
428+
elif systemctl list-unit-files | grep -q "httpd.service"; then
429+
SERVICES[3]="httpd"
430+
fi
393431
fi
432+
394433
echo "Monofon-health.sh started health check at $(date)"
395434
printf '\n'
396435
echo_status "Checking the statuses of the Services"

0 commit comments

Comments
 (0)