On the Asterisk server, ensure xinetd is installed

yum -y install xinetd service xinetd start

Create an Observium agent for xinetd

nano /etc/xinetd.d/observium\_agent

Add this to the file

service app-asterisk
{
type = UNLISTED
port = 36602
socket_type = stream
protocol = tcp
wait = no
user = root
server = /usr/bin/observium_agent/asterisk

# Don't be too verbose. Don't log every check. This might be
# commented out for debugging. If this option is commented out
# the default options will be used for this service.
log_on_success =

disable = no
}

Create the executable that xinetd will call when Observium connects

mkdir /usr/bin/observium\_agent
nano /usr/bin/observium\_agent/asterisk

Add this to the file

#!/bin/bash

####### Asterisk Telephony Server
if [ -a /usr/sbin/asterisk ] then
echo '<<<app-asterisk>>>'
ACTIVECHAN=$(asterisk -rx 'core show channels' | grep 'active channels' | cut -d' ' -f1)
ACTIVECALL=$(asterisk -rx 'core show channels' | grep 'active call' | cut -d' ' -f1)
IAXCHANNELS=$(asterisk -rx 'iax2 show channels' | grep active | cut -d' ' -f1)
SIPCHANNELS=$(asterisk -rx 'sip show channels' | grep active | cut -d' ' -f1)
SIPTOTALPEERS=$(asterisk -rx 'sip show peers' | grep 'sip peers' | cut -d' ' -f1)
SIPONLINE=$(asterisk -rx 'sip show peers' | grep -o '[0-9]* online' | head -1 | cut -d' ' -f1)
IAXTOTALPEERS=$(asterisk -rx 'iax2 show peers' | grep 'iax2 peers' | cut -d' ' -f1)
IAXONLINE=$(asterisk -rx 'iax2 show peers' | grep -o '[0-9]* online' | head -1 | cut -d' ' -f1)

echo "activechan:$ACTIVECHAN"
echo "activecall:$ACTIVECALL"
echo "iaxchannels:$IAXCHANNELS"
echo "sipchannels:$SIPCHANNELS"
echo "sippeers:$SIPTOTALPEERS"
echo "sippeersonline:$SIPONLINE"
echo "iaxpeers:$IAXTOTALPEERS"
echo "iaxpeersonline:$IAXONLINE"

fi

Set the script as executable and restart xinetd

chmod +x /usr/bin/observium\_agent/asterisk
service xinetd restart

In Observium, go to the server and select Settings > Properties Enable Modules > unix-agent Set Agent Port to 36602 in Agent

Poll the device, and the Asterisk App will appear in the 'Apps' section of the device

Previous Post Next Post