Skip to content

Script to monitor for 0 digitalRecorders available

hayden-t edited this page Mar 7, 2022 · 6 revisions

Currently this script is written for trunk recorder inn docker. And will email you if it runs out of digitalRecorders, ie too many simultaneous calls at once to record.

An example command you could use if not running tr in docker: journalctl --no-pager -u trunk-recorder.service --since "62 minutes ago"

#!/usr/bin/python3
# python script to check trunk recorder docker logs for error messages indicating it has run out of digitalRecorders
# could be modified to check native install with out docker
# set cron job to run this eg ever hour: 
# 0 * * * * /usr/bin/python3 /root/radio/checkForNoRecorders.py

import subprocess
import os

timeSpan = '62m'#get logs back this far, set to how often cron called (maybe plus 1-2 minute)
containerName = 'trunk_recorder'
logCommand = 'docker logs --since '+timeSpan+' '+containerName
alertCommand = 'swaks --to [email protected] --from "[email protected]" --header "Subject: Trunk Recorder Error: 0 Recorders" --body "Trunk Recorder ran out of recorders" --server smtp.server.com:587 --auth LOGIN --auth-user "[email protected]" --auth-password "SMTPPASSWORD" -tls'

proc = subprocess.check_output(logCommand ,stderr=subprocess.STDOUT,shell=True)

noRecorders = 0

for line in proc.decode().splitlines():
	#print(line)
	if 'but only 0 recorders available' in line:#how often listed
		noRecorders+=1
		
print("noRecorders = "+str(noRecorders))

if(noRecorders > 0):
	os.system(alertCommand)