Detect Agent on call or on hold or Unreacheable

Hi,

I’m trying to detect if caller/agent is weather on call or on hold run-time. I managed to insert CDR in MYSQL and get results from there but issue is it only inserts data when agent hangs up the call.

Also is there a way to generate an email whenever an extension changes status from “reachable” to “unreachable” or “unknown”?

Use Asterisk Newstate AMI event
https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+ManagerEvent_Newstate

Thank you but I’m not sure how to use AMI Events to get the required info.

For extensions, is it possible an email is generated whenever extension changes its status?

Only if you write the AMI code to do that.

Let’s say we use PHP, you can write your own script using or use an existing library to catch the desired event, then mail function you send the email with the data

Note you cant determine the unreachable status using Newstate event,

I Can get unreachable status using the script and running it after every few seconds and display it using HTML or PHP

ip_online=/usr/sbin/asterisk -rx ‘sip show peers’ | grep UNREACHEABLE | wc -l`

If I don’t use AMI Events and read asterisk CLI, I can get the required details from it.
Please guide me how I can relate channels/caller ID to sip extensions?

When I dial a call I get

– Executing [s@macro-callrecout:1] Set(“SIP/200-00027f75”, “chan=SIP/200-00027f75”) in new stack

00027f75 is probably caller ID but if I press hold

-- Started music on hold, class 'default', on SIP/voxbeam-00027f76

Caller ID changes

How can I know which caller is on hold?

I already told you use the AMI events, but you refuse to do it and keep trying trivial stuff on the command line. At least the positve thing about this is that it will help you to learn

You can use the hold and unhold events to track it down

Samples ouput :

Event: Hold
Privilege: call,all
Channel: SIP/101-0000000c
ChannelState: 6
ChannelStateDesc: Up
CallerIDNum: 101
CallerIDName:
ConnectedLineNum:
ConnectedLineName:
Language: en
AccountCode:
Context: home
Exten: 103
Priority: 3
Uniqueid: 1514613827.12
Linkedid: 1514613827.12
MusicClass: default

That is not caller ID. That’s part of a channel ID but not the full ID.

Try using Dumpchan() You should see all the variables set on the channel including caller ID if that’s what you are looking for.

https://wiki.asterisk.org/wiki/display/AST/Asterisk+15+Application_DumpChan