====== iax2.sh ====== ^ Author | [[ etmsys@rit.edu | Eric Meddaugh ]] | ^ Compatibility | Xymon 4.2 | ^ Requirements | Perl | ^ Download | None | ^ Last Update | 2008-09-11 | ===== Description ===== Monitor IAX2 on an Asterisk server. Needs access to UDP port 4569. ===== Installation ===== === Client configuration === None. === Server configuration === Add following to the hobbitlaunch.cfg file [iax2] ENVFILE /home/hobbit/server/etc/hobbitserver.cfg NEEDS hobbitd CMD $BBHOME/ext/iax2.sh LOGFILE $BBSERVERLOGS/iax2.log INTERVAL 1m Add the "iax2" tag in bb-hosts. ===== Source ===== ==== Monitor Code ==== iax2.sh -- Place in ext directory, this is the main script hobbit calls. #!/bin/sh # COLUMN=iax2 TIMEOUT=10 $BBHOME/bin/bbhostgrep --no-down ${COLUMN} | while read L do set $L IP="$1" HOSTNAME="$2" COLOR=green # linux use "/usr/bin/time -p" instead of ptime /bin/ptime $BBHOME/ext/iax2ping.pl $IP >$BBTMP/${COLUMN}.out 2>&1 SECONDS=`egrep "^real" $BBTMP/${COLUMN}.out | awk '{printf $2}'` OK=`/bin/egrep -c "Response from" $BBTMP/${COLUMN}.out` BAD=`/bin/egrep -c "Error" $BBTMP/${COLUMN}.out` if [ ${OK} -eq 0 -a ${BAD} -ge 1 ] ; then COLOR=red MSG="IAX2 query failed `cat $BBTMP/${COLUMN}.out | egrep -vi user` Seconds: ${SECONDS} " elif [ ${OK} -ge 1 -a ${BAD} -ge 1 ] ; then COLOR=yellow MSG="IAX2 query weird `cat $BBTMP/${COLUMN}.out | egrep -vi user` Seconds: ${SECONDS} " else COLOR=green MSG="IAX2 query succeeded `cat $BBTMP/${COLUMN}.out | egrep -vi user` Seconds: ${SECONDS} " fi $BB $BBDISP "status $HOSTNAME.$COLUMN $COLOR `date` $MSG" done exit 0 \\ iax2ping.pl -- Place in ext folder #!/usr/bin/perl -w #udp ping tool use IO::Socket; $target = shift; #"192.168.0.255"; $target_port = 4569; socket(PING, PF_INET, SOCK_DGRAM, getprotobyname("udp")); # Build Packet ... # Names from ethereal filter of registration packet $src_call = "8000"; #8000 most siginificant bit is IAX packet type full ... required for a poke etc... $dst_call = "0000"; $timestamp = "00000000"; $outbound_seq = "00"; $inbound_seq = "00"; $type = "06"; #IAX_Control $iax_type = "1e"; #POKE $msg = pack "H24", $src_call . $dst_call . $timestamp . $outbound_seq . $inbound_seq . $type . $iax_type; # Send UDP packet $ipaddr = inet_aton($target); $sendto = sockaddr_in($target_port,$ipaddr); send(PING, $msg, 0, $sendto) == length($msg) or die "cannot send to $target : $target_port : $!\n"; # Listen for responses... listen for TIMEOUT seconds and report all responders (works for broadcast pings) $MAXLEN = 1024; $TIMEOUT = 15; eval { local $SIG{ALRM} = sub { die "alarm time out"; }; alarm $TIMEOUT; $total = 3; $count = 0; while ($count < $total) { $recvfrom = recv(PING, $msg, $MAXLEN, 0) or die "recv: $!"; ($port, $ipaddr) = sockaddr_in($recvfrom); $respaddr = inet_ntoa($ipaddr); print "Response from $respaddr : $port\n"; $count++; } $type = "06"; #IAX_Control $iax_type = "04"; #ACK $msg = pack "H24", $src_call . $dst_call . $timestamp . $outbound_seq . $inbound_seq . $type . $iax_type; send(PING, $msg, 0, $sendto) == length($msg) or die "cannot send to $target : $target_port : $!\n"; }; if ($@) { print "Error Timeout waiting for packet from: $target\r\n"; $type = "06"; #IAX_Control $iax_type = "04"; #ACK $msg = pack "H24", $src_call . $dst_call . $timestamp . $outbound_seq . $inbound_seq . $type . $iax_type; send(PING, $msg, 0, $sendto) == length($msg) or die "cannot send to $target : $target_port : $!\n"; } ===== Known Bugs and Issues ===== ===== To Do ===== ===== Credits ===== ===== Changelog ===== * **2008-09-11** * Initial release