Best way to get extension status?


#1

Hi,

What is the best way to have the current status of an extension? We are using Asterisk realtime database and would like to be able to know whether a user is currently registered, unregistered, in a call, etc. (via CLI or AMI.)

I have read about adding hints to extension file but I’m not sure if this is the best way and how I could add such hints to the realtime database.

Any help or advice would be appreciated.

Thanks


#2

Do you mean an extension or a device? For a device, use DEVICE_STATE.

Hints associate an extension with a device and its device state, for the purposes of presence signalling. They are not particularly useful if you want to read the state from a program. For that use the device and its device state, directly.


#3

Thank you.

I tried the DeviceStateList command using AMI. However it is showing State: NOT_INUSE even though the device has a call in progress. How do I know if a device has a call in progress, if it is registered or not…? The only states returned by DeviceStateList are INUSE and UNAVAILABLE.

Thanks


#4

For chan_sip, you need to enable callcounter (call-limit in older versions), in sip.conf, before the in use state will be monitored. Other technology drivers may differ.

;callcounter = yes              ; Enable call counters on devices. This can be set per
                                ; device too.

#5

Thank you so much!

So please correct me if I’m wrong:

NOT_INUSE means registered but idle or no call in progress.
INUSE means call in progress
UNAVAILABLE means unregistered

Correct? And are there any other possible states which may be read using other functions??

Thanks a lot!


#6

Another question please:

Is it possible to retrieve the status of a particular device (INUSE, NOT_INUSE, UNAVAILABLE) instead of having to download and process the list of all devices – which could be expensive depending on list size…?

Thanks


#7
enum ast_device_state {
	AST_DEVICE_UNKNOWN,      /*!< Device is valid but channel didn't know state */
	AST_DEVICE_NOT_INUSE,    /*!< Device is not used */
	AST_DEVICE_INUSE,        /*!< Device is in use */
	AST_DEVICE_BUSY,         /*!< Device is busy */
	AST_DEVICE_INVALID,      /*!< Device is invalid */
	AST_DEVICE_UNAVAILABLE,  /*!< Device is unavailable */
	AST_DEVICE_RINGING,      /*!< Device is ringing */
	AST_DEVICE_RINGINUSE,    /*!< Device is ringing *and* in use */
	AST_DEVICE_ONHOLD,       /*!< Device is on hold */

Since the demise of call-limit, I’m not sure that you can still get BUSY from VoIP devices.

To read an individual value, use the DEVICE_STATE function. The AMI get variable action also works with functions.


#8

Hi david551

Getting the state of a device using the AMI getvar action would be great. However, it is not clear to me what the ‘channel’ argument of getvar should be. I guess the ‘variable’ argument of getvar should be DEVICE_STATE in this case? I am new to Asterisk. Could you give me an example please?

Thank you for your help!


#9

Try it without a channel. If that doesn’t work, you will need to originate a dummy channel for that purpose.


#10

It works! Thanks a lot :slight_smile: