# Best way to get extension status?

**URL:** <https://community.asterisk.org/t/best-way-to-get-extension-status/71355>\
**Category:** Asterisk SIP\
**Created:** [July 15, 2017, 9:37am UTC](https://community.asterisk.org/t/best-way-to-get-extension-status/71355 "2017-07-15T09:37:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![tlp.research.dpt](https://avatars.discourse-cdn.com/v4/letter/t/97f17d/32.png) [@tlp.research.dpt](https://community.asterisk.org/u/tlp.research.dpt)\
**Post date:** [July 15, 2017, 9:37am UTC](https://community.asterisk.org/t/best-way-to-get-extension-status/71355/1 "2017-07-15T09:37:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [July 15, 2017, 10:05am UTC](https://community.asterisk.org/t/best-way-to-get-extension-status/71355/2 "2017-07-15T10:05:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tlp.research.dpt](https://avatars.discourse-cdn.com/v4/letter/t/97f17d/32.png) [@tlp.research.dpt](https://community.asterisk.org/u/tlp.research.dpt)\
**Post date:** [July 15, 2017, 11:36am UTC](https://community.asterisk.org/t/best-way-to-get-extension-status/71355/3 "2017-07-15T11:36:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [July 15, 2017, 11:43am UTC](https://community.asterisk.org/t/best-way-to-get-extension-status/71355/4 "2017-07-15T11:43:31Z")

</div>

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.

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

```

---

<div class="post-metadata">

**Author:** ![tlp.research.dpt](https://avatars.discourse-cdn.com/v4/letter/t/97f17d/32.png) [@tlp.research.dpt](https://community.asterisk.org/u/tlp.research.dpt)\
**Post date:** [July 15, 2017, 12:04pm UTC](https://community.asterisk.org/t/best-way-to-get-extension-status/71355/5 "2017-07-15T12:04:04Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![tlp.research.dpt](https://avatars.discourse-cdn.com/v4/letter/t/97f17d/32.png) [@tlp.research.dpt](https://community.asterisk.org/u/tlp.research.dpt)\
**Post date:** [July 15, 2017, 12:48pm UTC](https://community.asterisk.org/t/best-way-to-get-extension-status/71355/6 "2017-07-15T12:48:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [July 15, 2017, 1:16pm UTC](https://community.asterisk.org/t/best-way-to-get-extension-status/71355/7 "2017-07-15T13:16:14Z")

</div>

```auto
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.

---

<div class="post-metadata">

**Author:** ![tlp.research.dpt](https://avatars.discourse-cdn.com/v4/letter/t/97f17d/32.png) [@tlp.research.dpt](https://community.asterisk.org/u/tlp.research.dpt)\
**Post date:** [July 15, 2017, 1:45pm UTC](https://community.asterisk.org/t/best-way-to-get-extension-status/71355/8 "2017-07-15T13:45:44Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [July 15, 2017, 2:52pm UTC](https://community.asterisk.org/t/best-way-to-get-extension-status/71355/9 "2017-07-15T14:52:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tlp.research.dpt](https://avatars.discourse-cdn.com/v4/letter/t/97f17d/32.png) [@tlp.research.dpt](https://community.asterisk.org/u/tlp.research.dpt)\
**Post date:** [July 17, 2017, 6:08am UTC](https://community.asterisk.org/t/best-way-to-get-extension-status/71355/10 "2017-07-17T06:08:58Z")

</div>

It works! Thanks a lot 🙂
