AMI Action: CoreShowChannels

Use a little “Action: CoreShowChannels” to monitor the status of calls being on Asterisk
But I find it very complex
There is a command “AGI or AMI” most appropriate and simple to see who talks to whom and related channels?

Hi,

What do you use to monitor the calls? would you prefer to use SSH or a web application?

Thank you,

Daniel Friedman
Trixton LTD.

Mobile: +41.79.868.7050
Email: [email protected]

Using scripts in ambi generated by php

Example:

    $fp = fsockopen("localhost", 5038, $errno, $errstr, 30);
    $out = "Action: Login\r\n";
    $out .= "Events: off\r\n";
    $out .= "UserName: a****f\r\n";
    $out .= "Secret: ma***9\r\n\r\n";
    fwrite($fp, $out);

    $in = "Action: CoreShowChannels\r\n\r\n";
    $in .= "Action: Logoff\r\n\r\n";
    fwrite($fp, $in);

Euh, I hope that this is not your real password…

Have a nice day!

Nic

Test server…

The point is that I have problems to monitor incoming calls
I always enter with the same channel

Example:
Action: CoreShowChannels
Response: Success
EventList: start
Message: Channels will follow
Event: CoreShowChannel
Channel: SIP / 01840_in-0,000,009th
ChannelState: 6
ChannelStateDesc: Up
CallerIDNum: 34
6
CallerIDName: 34
***6
ConnectedLineNum:
ConnectedLineName:
Language: en
accountcode:
Context: IVR-1
Exten: s
Priority: 11
Uniqueid: 1445007838.8012
Linkedin: 1445007838.8012
Application: BackGround
Application Date: custom / Msg_GG
Duration: 0:00:11
BridgeId:
Event: CoreShowChannelsComplete
EventList: Complete
ListItems: 1

Hi,

If it is not supposed to be an event driven application (Realtime) why not to use a simple web service to get the data from the Bash console?
I have written a simple web service that will fetch you all the channels, single channel and even hangup a channel.

Are you interested? if yes, I can share a little example of how I am doing it, and from there you can develop it on your own.

Thank you,

Daniel Friedman

of course

I will give him a look willingly

Eureka

I understand why not complendevo well trunks incoming …
Now I do the most comprehensive monitoring by obtaining everything you need!
just behave well

  1. take a look with “Action: CoreShowChannels”

  2. see the details with

  • Action: Status
  • Channel: SIP / 0182 ********* - 000000041

Aperitif is clear

Hi,

Here is a small piece of an API that I have wrote to get the channels from an Asterisk server. It will get you all the channels with the first and seventh fields (name and Application Data). It is faster because I am using the Bash console output to get the data rather the AMI that is opening another socket. On the newer versions of Asterisk (12 and up) you will be able to use the ARI to get the channels list as well.

The usage is:

http://localhost/channel_actions.php/?action=all

And here is the piece of PHP code:

<?php
$ext_action = isset($_REQUEST["action"])?$_REQUEST["action"]:'';

  if ($ext_action == "all") {
  #Get channels list from the Asterisk server
  $exten = shell_exec("asterisk -rx'core show channels concise' | cut -d '!' -f1,7,12");

  header("Content-type: text/xml");
  echo "<?xml version='1.0' encoding='UTF-8'?>\n";
  echo "<msg>\n";
  echo "<message>\n";
  #Renders each line of the channels
  $output = explode("\n" , $exten);
  array_filter($output);
  if (count($output) > 1) {
    foreach ($output as $line) {
      if (!empty($line)) {
      $line = rtrim($line);
      $sub_line = explode("!" , $line);
      array_filter($sub_line);
      echo "<channel>\n";
      $i=0;
      foreach ($sub_line as $key) {
        if ($i == 0 && !empty($key)) {
          echo "<name id='".$i."'>".htmlspecialchars($key)."</name>\n";
        }
        if ($i == 1 && !empty($key)) {
          echo "<data id='".$i."'>".htmlspecialchars($key)."</data>\n";
        }
        if ($i == 2 && !empty($key)) {
          echo "<duration id='".$i."'>".htmlspecialchars($key)."</duration>\n";
        }
        $i++;
      }
    echo "</channel>\n";
    }
    }
  } else {
    echo "<channel>no concurrent calls</channel>";
  }

  echo "</message>\n";
  echo "<status>1</status>\n";
  echo "</msg>";
  
  } else {
    header("Content-type: text/xml");
    echo "<?xml version='1.0' encoding='UTF-8'?>\n";
    echo "<msg>\n<message>extension is not set</message>\n<status>-1</status>\n</msg>";
    exit;
  }

?>

You will be able to adapt it to your needs if you will have to get other data from the channels list.

Thank you,

Daniel Friedman
Trixton LTD.

Mobile: +41.79.868.7050
Mobile: +972.50.6655579

Email: [email protected]

The ability to switch to “asterisk -rx” Interestingly I saw that much can be done
For now I’m using AMI, for now I find it a bit long-winded but especially powerful version FreePBX 13
However I tried to run "asterisk -rx’core show channels concise ‘| cut -d’! '-f1,7 "
But no answer … Maybe my version …

Hi,

Yes, of course you can use the AMI, I just wanted to show you that there is a simpler and faster way to get data from the pbx. When you are working with the AMI, you have to filter a lot just to get the response for your request. As for the command that you have failed to execute (a typo in your command), I think that you should run it like that:

asterisk -rx'core show channels concise' | cut -d '!' -f1,7

if you still fail to execute it you can connect directly to the Asterisk console (asterisk -r) and type:

core show help core show channels

to see all of the options of the command and its usage.

Thank you,

Daniel Friedman
Trixton LTD.

Mobile: +41.79.868.7050
Mobile: +972.50.6655579

Email: [email protected]

now go
Interesting and certainly more immediate

Hi,

I have update the piece of code to add the duration of the channel.

Thank you,

Daniel Friedman
Trixton LTD.

Mobile: +41.79.868.7050
Mobile: +972.50.6655579

Email: [email protected]