no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | monitors:asterisk-sip [2009/11/23 05:31] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== sip.sh ====== | ||
+ | |||
+ | ^ Author | [[ etmsys@rit.edu | Eric Meddaugh ]] | | ||
+ | ^ Compatibility | Xymon 4.2 | | ||
+ | ^ Requirements | Perl | | ||
+ | ^ Download | None | | ||
+ | ^ Last Update | 2008-09-11 | | ||
+ | |||
+ | ===== Description ===== | ||
+ | |||
+ | Monitor SIP on an Asterisk server. Needs access to UDP port 5060. | ||
+ | |||
+ | ===== Installation ===== | ||
+ | === Client configuration === | ||
+ | |||
+ | None. | ||
+ | |||
+ | === Server configuration === | ||
+ | |||
+ | Add following to the hobbitlaunch.cfg file | ||
+ | < | ||
+ | [sip] | ||
+ | ENVFILE / | ||
+ | NEEDS hobbitd | ||
+ | CMD $BBHOME/ | ||
+ | LOGFILE $BBSERVERLOGS/ | ||
+ | INTERVAL 1m | ||
+ | </ | ||
+ | |||
+ | Add the " | ||
+ | |||
+ | ===== Source ===== | ||
+ | |||
+ | ==== Monitor Code ==== | ||
+ | sip.sh -- Place in ext directory, this is the main script hobbit calls. | ||
+ | <hidden onHidden=" | ||
+ | <code bash> | ||
+ | #!/bin/sh | ||
+ | |||
+ | COLUMN=sip | ||
+ | TIMEOUT=10 | ||
+ | |||
+ | $BBHOME/ | ||
+ | while read L | ||
+ | do | ||
+ | set $L | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | # linux use "/ | ||
+ | / | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | if [ ${OK} -eq 0 ] ; then | ||
+ | COLOR=red | ||
+ | MSG=" | ||
+ | |||
+ | `cat $BBTMP/ | ||
+ | |||
+ | Seconds: ${SECONDS} | ||
+ | " | ||
+ | else | ||
+ | COLOR=green | ||
+ | MSG=" | ||
+ | |||
+ | `cat $BBTMP/ | ||
+ | |||
+ | Seconds: ${SECONDS} | ||
+ | " | ||
+ | fi | ||
+ | |||
+ | $BB $BBDISP " | ||
+ | |||
+ | $MSG" | ||
+ | |||
+ | $RM $BBTMP/ | ||
+ | done | ||
+ | |||
+ | exit 0 | ||
+ | </ | ||
+ | </ | ||
+ | \\ | ||
+ | |||
+ | sip_ping.pl -- Place in ext folder | ||
+ | <hidden onHidden=" | ||
+ | <code perl> | ||
+ | # | ||
+ | |||
+ | use IO::Socket; | ||
+ | use POSIX ' | ||
+ | use Time::HiRes qw(gettimeofday tv_interval); | ||
+ | use Getopt:: | ||
+ | use strict; | ||
+ | |||
+ | my $USAGE = " | ||
+ | |||
+ | my $RECV_TIMEOUT = 5; # how long in seconds to wait for a response | ||
+ | |||
+ | my $sock = IO:: | ||
+ | | ||
+ | | ||
+ | or die "Could not make socket: $@"; | ||
+ | |||
+ | # options | ||
+ | my ($verbose, $host, $my_ip, $my_port, $time); | ||
+ | GetOptions(" | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | |||
+ | # figure out who to ping | ||
+ | my $host = shift(@ARGV) or die $USAGE; | ||
+ | my $dst_addr = inet_aton($host) or die "Could not find host: $host"; | ||
+ | my $dst_ip = inet_ntoa($dst_addr); | ||
+ | my $portaddr = sockaddr_in(5060, | ||
+ | |||
+ | # figure out who we are | ||
+ | $my_ip = " | ||
+ | $my_port = " | ||
+ | |||
+ | # callid is just 32 randomn hex chars | ||
+ | my $callid = ""; | ||
+ | # today' | ||
+ | my $date = strftime(' | ||
+ | |||
+ | # branch id via rfc3261 pour plus d?infos, avec | ||
+ | # utilisation de time( ) pour l?unicité | ||
+ | my $branch=" | ||
+ | |||
+ | my $packet = qq(OPTIONS sip:$dst_ip SIP/2.0 | ||
+ | Via: SIP/2.0/UDP $my_ip: | ||
+ | From: < | ||
+ | To: < | ||
+ | Contact: < | ||
+ | Call-ID: $callid\@$my_ip | ||
+ | CSeq: 102 OPTIONS | ||
+ | User-Agent: sip_ping.pl | ||
+ | Date: $date | ||
+ | Allow: ACK, CANCEL | ||
+ | Content-Length: | ||
+ | |||
+ | ); | ||
+ | |||
+ | # send the packet | ||
+ | print " | ||
+ | send($sock, $packet, 0, $portaddr) == length($packet) | ||
+ | or die " | ||
+ | my $send_time = [gettimeofday( )]; # start the stopwatch | ||
+ | my $elapsed; | ||
+ | # get the reponse | ||
+ | eval | ||
+ | { | ||
+ | local $SIG{ALRM} = sub { die "Host timeout" | ||
+ | alarm $RECV_TIMEOUT; | ||
+ | $portaddr = recv($sock, $packet, 1500, 0) or die " | ||
+ | $elapsed = tv_interval($send_time); | ||
+ | alarm 0; | ||
+ | 1; | ||
+ | } or die($@); | ||
+ | |||
+ | # affiche la sortie | ||
+ | if ($verbose) { | ||
+ | printf(" | ||
+ | } | ||
+ | elsif ($time) { | ||
+ | printf(" | ||
+ | } | ||
+ | else { | ||
+ | print(" | ||
+ | printf(" | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===== Known Bugs and Issues ===== | ||
+ | |||
+ | ===== To Do ===== | ||
+ | |||
+ | ===== Credits ===== | ||
+ | |||
+ | ===== Changelog ===== | ||
+ | |||
+ | * **2008-09-11** | ||
+ | * Initial release | ||