{"id":1101,"date":"2017-10-08T00:46:30","date_gmt":"2017-10-07T19:46:30","guid":{"rendered":"http:\/\/alexeyka.zantsev.com\/?p=1101"},"modified":"2017-10-08T00:56:29","modified_gmt":"2017-10-07T19:56:29","slug":"asterisk-count-active-calls-on-certain-peers","status":"publish","type":"post","link":"https:\/\/alexeyka.zantsev.com\/?p=1101","title":{"rendered":"Asterisk: count active calls on certain peers"},"content":{"rendered":"<p>Let&#8217;s imagine that you have a number of peers &#8211; both internal users and trunks with VoIP providers.<br \/>\nAnd you need to count active calls on trunks only. Or even on trunks with some concrete provider, but not the total &#8216;core show calls&#8217;. As an example, you may need to pass that integer to Zabbix.<\/p>\n<pre>\r\nroot@pbx:~# asterisk -C \/etc\/asterisk\/asterisk.conf -rx 'sip show inuse' \r\nSetting max files open to 1000\r\n* Peer name               In use          Limit           \r\n104                       0\/0\/0           10              \r\n107                       0\/0\/0           10              \r\n100                       0\/0\/0           10                            \r\nvoip-isp-london1          1\/0\/0           6      \r\nvoip-isp-london2          2\/1\/0           6      \r\nroot@pbx:~# \r\n<\/pre>\n<p>In fact, all magic is done with grep and especially awk tool. Firstly, you need to grep &#8216;voip-isp&#8217;, then extract the second column (is done with <em>awk &#8216;{print $2}&#8217;<\/em> ) and then extract the first digit from three ones (e.g. 2 from 2\/1\/0).<br \/>\nAt this point, you&#8217;ll get a list of integers, one per line, corresponding to number of active calls on each grepped trunk.<br \/>\nNow it&#8217;s time to summarize them, and the best way to do it is also awk! (is done with <em>awk -F\\\/ &#8216;{sum += $1} END {print sum}&#8217;<\/em> )<\/p>\n<pre>\r\nroot@pbx:~# asterisk -C \/etc\/asterisk\/asterisk.conf -rx 'sip show inuse' | grep voip | awk '{print $2}' | awk -F\\\/ '{sum += $1} END {print sum}'\r\n3\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s imagine that you have a number of peers &#8211; both internal users and trunks with VoIP providers. And you need to count active calls on trunks only. Or even on trunks with some concrete provider, but not the total &#8216;core show calls&#8217;. As an example, you may need to pass that integer to Zabbix. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[43,163,237],"class_list":["post-1101","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-asterisk","tag-awk","tag-zabbix"],"_links":{"self":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts\/1101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1101"}],"version-history":[{"count":5,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts\/1101\/revisions"}],"predecessor-version":[{"id":1108,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts\/1101\/revisions\/1108"}],"wp:attachment":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}