Advertisement
Guest User

Untitled

a guest
Mar 12th, 2023
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.68 KB | None | 0 0
  1. #!/bin/bash
  2. set -e
  3. # Authors: Rodrigo Cuadra
  4. # with Collaboration of Jose Miguel Rivera
  5. # Date: 3-Jun-2022
  6. # Support: [email protected]
  7. #
  8. # Modifications: João Pedrosa - 03-2023
  9. #
  10. echo -e "\n"
  11. echo -e "\e[39m"
  12. echo -e "************************************************************"
  13. echo -e "* Welcome to the VitalPBX 3-4 stress test *"
  14. echo -e "* All options are mandatory *"
  15. echo -e "************************************************************"
  16. echo -e "* Warning-Warning-Warning-Warning *"
  17. echo -e "* Due to limitations in the audio used *"
  18. echo -e "* the test can not be longer than 6 minutes *"
  19. echo -e "************************************************************"
  20. filename="config.txt"
  21. if [ -f $filename ]; then
  22. echo -e "config file"
  23. n=1
  24. while read line; do
  25. case $n in
  26. 1)
  27. ip_local=$line
  28. ;;
  29. 2)
  30. ip_remote=$line
  31. ;;
  32. 3)
  33. ssh_remote_port=$line
  34. ;;
  35. 4)
  36. interface_name=$line
  37. ;;
  38. 5)
  39. protocol=$line
  40. ;;
  41. 6)
  42. codec=$line
  43. ;;
  44. 7)
  45. recording=$line
  46. ;;
  47. 8)
  48. maxcpuload=$line
  49. ;;
  50. 9)
  51. call_step=$line
  52. ;;
  53. 10)
  54. call_step_seconds=$line
  55. ;;
  56. esac
  57. n=$((n+1))
  58. done < $filename
  59. echo -e "IP Local....................................... > $ip_local"
  60. echo -e "IP Remote...................................... > $ip_remote"
  61. echo -e "SSH Remote Port (Default is 22)................ > $ssh_remote_port"
  62. echo -e "Network Interface name (ej: eth0).............. > $interface_name"
  63. echo -e "Protocol (1.-SIP)...................... > $protocol"
  64. echo -e "Codec (1. G.711A, 2.- G.711U, 3.- G729)............... > $codec"
  65. echo -e "Recording Calls (yes,no)....................... > $recording"
  66. echo -e "Max CPU Load (Recommended 90%)................. > $maxcpuload"
  67. echo -e "Calls Step (Recommended 5-20).................. > $call_step"
  68. echo -e "Seconds between each step (Recommended 5-30)... > $call_step_seconds"
  69. fi
  70.  
  71. while [[ $ip_local == '' ]]
  72. do
  73. read -p "IP Local....................................... > " ip_local
  74. done
  75.  
  76. while [[ $ip_remote == '' ]]
  77. do
  78. read -p "IP Remote...................................... > " ip_remote
  79. done
  80.  
  81. while [[ $ssh_remote_port == '' ]]
  82. do
  83. read -p "SSH Remote Port (Default is 22)................ > " ssh_remote_port
  84. done
  85.  
  86. while [[ $interface_name == '' ]]
  87. do
  88. read -p "Network Interface name (ej: eth0).............. > " interface_name
  89. done
  90.  
  91. while [[ $protocol == '' ]]
  92. do
  93. read -p "Protocol (1.-SIP)...................... > " protocol
  94. done
  95.  
  96. while [[ $codec == '' ]]
  97. do
  98. read -p "Codec (1. G.711A, 2.- G.711U, 3.- G729)............... > " codec
  99. done
  100.  
  101. while [[ $recording == '' ]]
  102. do
  103. read -p "Recording Calls (yes,no)....................... > " recording
  104. done
  105.  
  106. while [[ $maxcpuload == '' ]]
  107. do
  108. read -p "Max CPU Load (Recommended 90%)................. > " maxcpuload
  109. done
  110.  
  111. while [[ $call_step == '' ]]
  112. do
  113. read -p "Calls Step (Recommended 5-20).................. > " call_step
  114. done
  115.  
  116. while [[ $call_step_seconds == '' ]]
  117. do
  118. read -p "Seconds between each step (Recommended 5-30)... > " call_step_seconds
  119. done
  120.  
  121. echo -e "************************************************************"
  122. echo -e "* Check Information *"
  123. echo -e "* Make sure that both server have communication *"
  124. echo -e "************************************************************"
  125. while [[ $veryfy_info != yes && $veryfy_info != no ]]
  126. do
  127. read -p "Are you sure to continue with this settings? (yes,no) > " veryfy_info
  128. done
  129.  
  130. if [ "$veryfy_info" = yes ] ;then
  131. echo -e "************************************************************"
  132. echo -e "* Starting to run the scripts *"
  133. echo -e "************************************************************"
  134. else
  135. while [[ $ip_local == '' ]]
  136. do
  137. read -p "IP Local....................................... > " ip_local
  138. done
  139.  
  140. while [[ $ip_remote == '' ]]
  141. do
  142. read -p "IP Remote...................................... > " ip_remote
  143. done
  144.  
  145. while [[ $ssh_remote_port == '' ]]
  146. do
  147. read -p "SSH Remote Port (Default is 22)................. > " ssh_remote_port
  148. done
  149.  
  150. while [[ $interface_name == '' ]]
  151. do
  152. read -p "Network Interface name (ej: eth0).............. > " interface_name
  153. done
  154.  
  155. while [[ $protocol == '' ]]
  156. do
  157. read -p "Protocol (1.-SIP....................... > " protocol
  158. done
  159.  
  160. while [[ $codec == '' ]]
  161. do
  162. read -p "Codec (1. G.711A, 2.- G.711U, 3.- G729)................ > " codec
  163. done
  164.  
  165. while [[ $recording == '' ]]
  166. do
  167. read -p "Recording Calls (yes,no)....................... > " recording
  168. done
  169.  
  170. while [[ $maxcpuload == '' ]]
  171. do
  172. read -p "Max CPU Load (Recommended 90%)................. > " maxcpuload
  173. done
  174.  
  175. while [[ $call_step == '' ]]
  176. do
  177. read -p "Calls Step (Recommended 5-20).................. > " call_step
  178. done
  179.  
  180. while [[ $call_step_seconds == '' ]]
  181. do
  182. read -p "Seconds between each step (Recommended 5-30)... > " call_step_seconds
  183. done
  184. fi
  185.  
  186. echo -e "$ip_local" > config.txt
  187. echo -e "$ip_remote" >> config.txt
  188. echo -e "$ssh_remote_port" >> config.txt
  189. echo -e "$interface_name" >> config.txt
  190. echo -e "$protocol" >> config.txt
  191. echo -e "$codec" >> config.txt
  192. echo -e "$recording" >> config.txt
  193. echo -e "$maxcpuload" >> config.txt
  194. echo -e "$call_step" >> config.txt
  195. echo -e "$call_step_seconds" >> config.txt
  196. echo -e "************************************************************"
  197. echo -e "* Copy Authorization key to remote server *"
  198. echo -e "************************************************************"
  199. sshKeyFile=/root/.ssh/id_rsa
  200. if [ ! -f $sshKeyFile ]; then
  201. ssh-keygen -f /root/.ssh/id_rsa -t rsa -N '' >/dev/null
  202. fi
  203. ssh-copy-id -p $ssh_remote_port root@$ip_remote
  204. echo -e "*** Done ***"
  205.  
  206. echo -e "************************************************************"
  207. echo -e "* Creating Asterisk config files *"
  208. echo -e "************************************************************"
  209. echo -e "[call-test-ext]" > /etc/asterisk/vitalpbx/extensions__60-call-test.conf
  210. echo -e "exten => _200,1,NoOp(Outgoing Call)" >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf
  211. if [ "$cdrs" != yes ] ;then
  212. echo -e " same => n,NoCDR()" >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf
  213. fi
  214. if [ "$recording" = yes ] ;then
  215. echo -e " same => n,MixMonitor(/tmp/$"{UNIQUEID}".wav,ab)" >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf
  216. fi
  217. if [ "$protocol" = 1 ] ;then
  218. echo -e " same => n,Dial(SIP/call-test-trk/100,30,rtT)" >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf
  219. fi
  220. echo -e " same => n,Hangup()" >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf
  221.  
  222. if [ "$protocol" = 1 ] ;then
  223. protocol_name=SIP
  224. rm -rf /etc/asterisk/vitalpbx/iax__60-call-test.conf
  225. echo -e "[call-test-trk]" > /etc/asterisk/vitalpbx/sip__60-call-test.conf
  226. echo -e "context=call-test-ext" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
  227. echo -e "description=Call_Test" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
  228. echo -e "host=$ip_remote" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
  229. echo -e "port=5062" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
  230. echo -e "type=friend" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
  231. echo -e "transport=udp" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
  232. echo -e "qualify=yes" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
  233. echo -e "outbound_registration=yes" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
  234. echo -e "auth_rejection_permanent=yes" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
  235. echo -e "max_retries=10" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
  236. echo -e "expiration=3600" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
  237. echo -e "retry_interval=60" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
  238. echo -e "forbidden_retry_interval=10" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
  239. codec_name=NONE
  240. if [ "$codec" = 1 ] ;then
  241. codec_name=alaw
  242. echo -e "allow=!all,alaw" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
  243. fi
  244. if [ "$codec" = 2 ] ;then
  245. codec_name=ulaw
  246. echo -e "allow=!all,ulaw" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
  247. fi
  248. if [ "$codec" = 3 ] ;then
  249. codec_name=g729
  250. echo -e "allow=!all,g729" >> /etc/asterisk/vitalpbx/sip__60-call-test.conf
  251. fi
  252. fi
  253.  
  254.  
  255. ssh -p $ssh_remote_port root@$ip_remote "echo -e '[call-test-ext]' > /etc/asterisk/vitalpbx/extensions__60-call-test.conf"
  256. ssh -p $ssh_remote_port root@$ip_remote "echo -e 'exten => _100,1,Answer()' >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf"
  257. ssh -p $ssh_remote_port root@$ip_remote "echo -e ' same => n,NoCDR()' >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf"
  258. ssh -p $ssh_remote_port root@$ip_remote "echo -e ' same => n(begin),Wait(1)' >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf"
  259. ssh -p $ssh_remote_port root@$ip_remote "echo -e ' same => n,Playback(demo-instruct&silence/10)' >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf"
  260. ssh -p $ssh_remote_port root@$ip_remote "echo -e ' same => n,Goto(begin)' >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf"
  261. ssh -p $ssh_remote_port root@$ip_remote "echo -e ' same => n,Hangup()' >> /etc/asterisk/vitalpbx/extensions__60-call-test.conf"
  262.  
  263. if [ "$protocol" = 1 ] ;then
  264. ssh -p $ssh_remote_port root@$ip_remote "rm -rf /etc/asterisk/vitalpbx/iax__60-call-test.conf"
  265. ssh -p $ssh_remote_port root@$ip_remote " echo -e '[call-test-trk]' > /etc/asterisk/vitalpbx/sip__60-call-test.conf"
  266. ssh -p $ssh_remote_port root@$ip_remote " echo -e 'context=call-test-ext' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
  267. ssh -p $ssh_remote_port root@$ip_remote " echo -e 'description=Call_Test' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
  268. ssh -p $ssh_remote_port root@$ip_remote " echo -e 'host=$ip_local' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
  269. ssh -p $ssh_remote_port root@$ip_remote " echo -e 'port=5062' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
  270. ssh -p $ssh_remote_port root@$ip_remote " echo -e 'type=friend' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
  271. ssh -p $ssh_remote_port root@$ip_remote " echo -e 'transport=udp' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
  272. ssh -p $ssh_remote_port root@$ip_remote " echo -e 'qualify=yes' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
  273. ssh -p $ssh_remote_port root@$ip_remote " echo -e 'outbound_registration=yes' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
  274. ssh -p $ssh_remote_port root@$ip_remote " echo -e 'auth_rejection_permanent=yes' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
  275. ssh -p $ssh_remote_port root@$ip_remote " echo -e 'max_retries=10' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
  276. ssh -p $ssh_remote_port root@$ip_remote " echo -e 'expiration=3600' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
  277. ssh -p $ssh_remote_port root@$ip_remote " echo -e 'retry_interval=60' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
  278. ssh -p $ssh_remote_port root@$ip_remote " echo -e 'forbidden_retry_interval=10' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
  279. if [ "$codec" = 1 ] ;then
  280. #ssh -p $ssh_remote_port root@$ip_remote " echo -e 'allow=!all,alaw' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
  281. ssh -p $ssh_remote_port root@$ip_remote " echo -e 'allow=alaw' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
  282. fi
  283. if [ "$codec" = 2 ] ;then
  284. #ssh -p $ssh_remote_port root@$ip_remote " echo -e 'allow=!all,ulaw' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
  285. ssh -p $ssh_remote_port root@$ip_remote " echo -e 'allow=ulaw' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
  286. fi
  287. if [ "$codec" = 3 ] ;then
  288. ssh -p $ssh_remote_port root@$ip_remote " echo -e 'allow=!all,g729' >> /etc/asterisk/vitalpbx/sip__60-call-test.conf"
  289. fi
  290. fi
  291.  
  292. asterisk -rx"core restart now"
  293. ssh -p $ssh_remote_port root@$ip_remote "asterisk -rx'core restart now'"
  294. #ssh -p $ssh_remote_port root@$ip_remote "asterisk -rvvvvv' restart now'"
  295.  
  296. echo -e "*** Done ***"
  297. echo -e " *************************************************************************************"
  298. echo -e " * Restarting Asterisk in both Server *"
  299. echo -e " *************************************************************************************"
  300. sleep 10
  301. numcores=`nproc --all`
  302. exitcalls=false
  303. i=0
  304. step=0
  305. clear
  306. echo -e " *************************************************************************************"
  307.  
  308. echo -e " * Codec escolhido: "$codec", Actual Test State (Protocol: "$protocol_name", Codec: "$codec_name", Recording: "$recording") *"
  309.  
  310. echo -e " *************************************************************************************"
  311. echo -e " -------------------------------------------------------------------------------------"
  312. printf "%2s %7s %10s %16s %10s %10s %12s %12s\n" "|" " Step |" "Calls |" "Asterisk Calls |" "CPU Load |" "Memory |" "BW TX kb/s |" "BW RX kb/s |"
  313. R1=`cat /sys/class/net/"$interface_name"/statistics/rx_bytes`
  314. T1=`cat /sys/class/net/"$interface_name"/statistics/tx_bytes`
  315. date1=$(date +"%s")
  316. sleep 1
  317. echo -e "calls, active calls, cpu load (%), memory (%), bwtx (kb/s), bwrx(kb/s), interval(seg)" > data_ulaw.csv
  318. while [ $exitcalls = 'false' ]
  319. do
  320. R2=`cat /sys/class/net/"$interface_name"/statistics/rx_bytes`
  321. T2=`cat /sys/class/net/"$interface_name"/statistics/tx_bytes`
  322. date2=$(date +"%s")
  323. diff=$(($date2-$date1))
  324. seconds="$(($diff % 60))"
  325. T2=`expr $T2 + 128`
  326. R2=`expr $R2 + 128`
  327. TBPS=`expr $T2 - $T1`
  328. RBPS=`expr $R2 - $R1`
  329. TKBPS=`expr $TBPS / 128`
  330. RKBPS=`expr $RBPS / 128`
  331. bwtx="$((TKBPS/seconds))"
  332. bwrx="$((RKBPS/seconds))"
  333. activecalls=`asterisk -rx "core show calls" | grep "active" | cut -d' ' -f1`
  334. cpu=`top -n 1 | awk 'FNR > 7 {s+=$10} END {print s}'`
  335. cpuint=${cpu%.*}
  336. cpu="$((cpuint/numcores))"
  337. memory=`free | awk '/Mem/{printf("%.2f%"), $3/$2*100} /buffers\/cache/{printf(", buffers: %.2f%"), $4/($3+$4)*100}'`
  338. if [ "$cpu" -le 34 ] ;then
  339. echo -e "\e[92m -------------------------------------------------------------------------------------"
  340. fi
  341. if [ "$cpu" -ge 35 ] && [ "$cpu" -lt 65 ] ;then
  342. echo -e "\e[93m -------------------------------------------------------------------------------------"
  343. fi
  344. if [ "$cpu" -ge 65 ] ;then
  345. echo -e "\e[91m -------------------------------------------------------------------------------------"
  346. fi
  347. printf "%2s %7s %10s %16s %10s %10s %12s %12s\n" "|" " "$step" |" ""$i" |" ""$activecalls" |" ""$cpu"% |" ""$memory" |" ""$bwtx" |" ""$bwrx" |"
  348. echo -e "$i, $activecalls, $cpu, $memory, $bwtx, $bwrx, $seconds" >> data_ulaw.csv
  349. exitstep=false
  350. x=1
  351. while [ $exitstep = 'false' ]
  352. do
  353. let x=x+1
  354. if [ "$call_step" -lt $x ] ;then
  355. exitstep=true
  356. fi
  357. asterisk -rx"channel originate Local/200@call-test-ext application Playback demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct&demo-instruct"
  358. done
  359. let step=step+1
  360. let i=i+"$call_step"
  361. if [ "$cpu" -gt "$maxcpuload" ] ;then
  362. exitcalls=true
  363. fi
  364. R1=`cat /sys/class/net/"$interface_name"/statistics/rx_bytes`
  365. T1=`cat /sys/class/net/"$interface_name"/statistics/tx_bytes`
  366. date1=$(date +"%s")
  367. sleep "$call_step_seconds"
  368. done
  369. echo -e "\e[39m -------------------------------------------------------------------------------------"
  370. echo -e " *************************************************************************************"
  371. echo -e " * Restarting Asterisk *"
  372. echo -e " *************************************************************************************"
  373. asterisk -rx"core restart now"
  374. rm -rf /tmp/*.wav
  375. echo -e " *************************************************************************************"
  376. echo -e " * Test Complete *"
  377. echo -e " * Result in data_ulaw.csv file *"
  378. echo -e " *************************************************************************************"
  379. echo -e "\e[39m"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement