50%

🚀

6

IP PBX Asterisk SIP , (peers). , .


Asterisk


Asterisk Pro

, . bash . , 3 , , B C. Asterisk A. , , 2 : , , , . , . :

[root@asteriskpbx]# touch /home/admin/log_mail.txt
[root@asteriskpbx]# touch /home/admin/message.txt

, :

#!/bin/sh
LOGSIZE=`ls -l /home/admin/log_mail.txt |  awk '{ print $5 }'` //    
problempeers=`/usr/sbin/asterisk -rx 'sip show peers' | grep UNKNOWN` //  'sip show peers'   Asterisk,  ,    grep UNKNOWN  ,    ,    UNKNOWN
GWB=`ping -c4 11.22.33.44 | grep 'received' | awk -F',' '{ print $2}' | awk '{ print $1}'`  //  ICMP,  IP        .   ,   ,      4.   ,    0.
GWC=`ping -c4 44.33.22.11 | grep 'received' | awk -F',' '{ print $2}' | awk '{ print $1}'` //      C
ResultB="" // 
ResultC="" // 
FILENAME=/home/admin/message.txt //     - 
LOGFILE=/home/admin/log_mail.txt
DATE="`date +%d.%m.%Y" "%H:%M:%S`" //       .. ::
echo "$problempeers" > /home/admin/message.txt //   problempeers   .          .
FILESIZE=$(stat -c%s "$FILENAME") //    message.txt.     - ,      (   UNKNOWN),   ,   .

, ( ) email . :

if [ $GWB -eq 0 ]; then //      B    0,     
ResultB ="  B  !" //  .      
else
ResultB ="" //      ,    
fi
if [ $GW -eq 0 ]; then //          0,     
Result="    !" // .   ,   C 
else
Result ="" //  ,    
fi
if [ $FILESIZE -ne 1 ]; then //    message.txt  ,    
if [ $GWB -eq 0 ] || [ $GWC -eq 0 ]; then //       ,      

   echo "$problempeers"| mailx -s "  SIP  |  $ResultB $ResultC!" -r "info@merionet.ru" youremail@some.ru </home/admin/message.txt && //   ,  ,       , ,  -    ,  .        .
   echo "FAIL :: $DATE :: Some problems with phones" >> "$LOGFILE" //   ,     ,        (        )
else
echo "$problempeers"| mailx -s "  SIP  |  !" -r "info@merionet.ru" youremail@some.ru <	/home/admin/message.txt && //    ,     ,      . 
echo "FAIL :: $DATE :: Some problems with phones" >> "$LOGFILE" //      .
fi
else
echo "OK :: $DATE :: all phones are OK" >> "$LOGFILE" //   ,               .
fi
if [ $LOGSIZE -ge 150000 ]; then //         150 ,     (   ,   .)
   cat /dev/null > /home/admin/log_mail.txt
fi
cat /dev/null > /home/admin/message.txt //      message.txt,   

, , , :

     Asterisk

, . , , :

:
#!/bin/bash
ALLTRUNKSMINIMUM="`/usr/sbin/asterisk -rx "sip show registry"`" //    SIP
ALLTRUNKS=`echo "$ALLTRUNKSMINIMUM" |grep "SIP registrations" |awk '{print $1}'` //    
REGTRUNKS=`/usr/sbin/asterisk -rx "sip show registry" |grep Registered |wc -l` //    
DATE="`date +%d.%m.%Y" "%H:%M:%S`" //  ,  
LOGFILE=/home/admin/log_mail.txt //   ,    ,       
if [ "$REGTRUNKS" -lt "$ALLTRUNKS" ]; then //        
sleep 5 // 5 
echo `/usr/sbin/asterisk -rx "sip reload"` \\   SIP,   .        ,  , , ,  .
sleep 5 //  5 
VAR=`/usr/sbin/asterisk -rx "sip show registry"` //  SIP ,   SIP .       ,    VAR     .   ,   email       .   .
echo "$VAR"| mailx -s " " -r "info@merionet.ru" youremail@some.ru //      ,   SIP    
else
echo "OK :: $DATE :: all trunks are OK" >> "$LOGFILE" //   ,   ,       .
fi

, Asterisk, . .sh, , , Notepad ++. 2 , 10 . , , , Linux :

[root@asteriskpbx]# dos2unix peer.sh //    
[root@asteriskpbx]# dos2unix trunk.sh //    
[root@asteriskpbx]# chmod 777 peer.sh //    
[root@asteriskpbx]# chmod 777 trunk.sh
[root@asteriskpbx]# crontab -e

cron, :

*/10 * * * * /bin/bash /home/peer.sh >/dev/null //    10 
*/2 * * * * /bin/bash /home/trunk.sh >/dev/null //    2 

. , Asterisk


>