Devstate and hints get out of sync

Recently I set up two Asterisk (20.8.1) servers to exchange device and mailbox state. However, I noticed that devstate and hints quickly (but not immediately) became out of sync:

$ rasterisk -x "devstate change Custom:test123 NOT_INUSE"
Changing test123 to NOT_INUSE
$ rasterisk -x "core show hints" | grep test123
8014@endpoints : Custom:test123        State:InUse           Presence:not_set         Watchers  0
$ rasterisk -x "devstate list" | grep test123
--- Name: 'Custom:test123'  State: 'NOT_INUSE'

Setting device_state_filter=^PJSIP/ on the asterisk-publication at both ends worked. However, although pjsip reload was all that was necessary to filter processing of the device states, fixing the hints required a restart of Asterisk.

According to Exchanging Device and Mailbox State Using PJSIP,

As previously mentioned state events can be filtered by the device or mailbox they relate to using a regular expression. This is configured on ‘publish’ types using ‘@device_state_filter’ and ‘@mailbox_state_filter

I wasn’t able to get this to work. This is the syntax I used:

[instance1-devicestate]
type=outbound-publish
server_uri=sip:instance2@192.168.1.101
event=asterisk-devicestate
transport=transport-tlsv1_2
@device_state_filter=^PJSIP/

However, when I tried that, Asterisk still sent PUBLISH to the opposite server when I changed devstate.

Questions:

  1. Has anyone else noticed devstate and hints out of sync? Is this a bug or am I doing it wrong?

  2. How can I prevent Asterisk from publishing the device state events that don’t match a filter?

Thanks :slightly_smiling_face:

I think we’d need to see the complete configuration (inbound-publication, outbound-publish and asterisk-publication objects) for both sides to know.

@device_state_filter and @mailbox_state_filter are regular expressions so @device_state_filter=^PJSIP/ says “match everything that begins with PJSIP/”. What did you intend to do?

@device_state_filter and @mailbox_state_filter are regular expressions so @device_state_filter=^PJSIP/ says “match everything that begins with PJSIP/”. What did you intend to do?

Goal: Only publish device state changes for endpoints beginning with PJSIP/.

Will post the complete configuration shortly.

Here is the complete configuration. Any suggestions would be appreciated.

Both servers:

[pbxendpoint](!)
type=endpoint
context=pbxinternal
disallow=all
allow=g722,ulaw
direct_media=yes
identify_by=ip
send_rpid=yes
trust_id_inbound=yes
trust_id_outbound=yes
inband_progress=yes
send_connected_line=no
transport=transport-tlsv1_2
dtls_ca_file=/etc/asterisk/keys/asterisk.ca.pem

instance1:

[instance2](pbxendpoint)
aors=instance2
[instance2]
type=aor
contact=sip:192.168.1.102
[instance2]
type=identify
endpoint=instance2
match=192.168.1.102

[instance2-devicestate]
type=outbound-publish
server_uri=sip:instance1@192.168.1.102
event=asterisk-devicestate
transport=transport-tlsv1_2
@device_state_filter=^PJSIP/ ; This seems to do nothing.  Goal: only publish for devices beginning with PJSIP/

[instance2-mwi]
type=outbound-publish
server_uri=sip:instance1@192.168.1.102
event=asterisk-mwi
transport=transport-tlsv1_2

[instance2]
type=inbound-publication
event_asterisk-devicestate=instance2
event_asterisk-mwi=instance2
endpoint=instance2 ; Optional name of an endpoint that is only allowed to publish to this resource.

[instance2]
type=asterisk-publication
devicestate_publish=instance2-devicestate ; publish item that can be used to publish a req
mailboxstate_publish=instance2-mwi ; publish item that can be used to publish a req
device_state=yes ; permit incoming device state events
device_state_filter=^PJSIP/ ; Without this, devstate and hints get out of sync.
mailbox_state=yes ; permit incoming MWI events

instance2:

[instance1](pbxendpoint)
aors=instance1
[instance1]
type=aor
contact=sip:192.168.1.101
[instance1]
type=identify
endpoint=instance1
match=192.168.1.101

[instance1-devicestate]
type=outbound-publish
server_uri=sip:instance2@192.168.1.101
event=asterisk-devicestate
transport=transport-tlsv1_2
@device_state_filter=^PJSIP/ ; This seems to do nothing.  Goal: only publish for devices beginning with PJSIP/

[instance1-mwi]
type=outbound-publish
server_uri=sip:instance2@192.168.1.101
event=asterisk-mwi
transport=transport-tlsv1_2

[instance1]
type=inbound-publication
event_asterisk-devicestate=instance1 ; if you don't set the event_asterisk options; Asterisk responds with 404 Not Found.
event_asterisk-mwi=instance1
@device_state_filter=^PJSIP/
endpoint=instance1 ; Optional name of an endpoint that is only allowed to publish to this resource.

[instance1]
type=asterisk-publication
devicestate_publish=instance1-devicestate ; publish item that can be used to publish a req
mailboxstate_publish=instance1-mwi ; publish item that can be used to publish a req
device_state=yes ; permit incoming device state events
device_state_filter=^PJSIP/ ; Without this, devstate and hints get out of sync.
mailbox_state=yes ; permit incoming MWI events

First, @device_state_filter doesn’t work on inbound-publication objects, device_state_filter (without the leading @) on the asterisk-publication object is what filters incoming events.

So, on the outbound-publish, you’re saying that @device_state_filter=^PJSIP/ is allowing more than PJSIP resources to be published?

OK so collect more info…
Make sure that logger.conf is configured to send at least “debug” and “verbose” messages to a file and that dateformat includes the milliseconds. I.E. dateformat=%F %T.%3q %z
Run the following commands on both instances…

CLI> core set debug 3 res_pjsip_pubsub.so
CLI> core set debug 3 res_pjsip_publish_asterisk.so
CLI> core set debug 3 res_pjsip_publish_outbound.so

On instance 1 only:

CLI> pjsip set logger host 192.168.1.102

Now do what you can to reproduce the issue and let’s see what the logs can tell us.

Oh, you can place CLI commands in the “startup_commands” section of cli.conf so you don’t have to type them every time you restart asterisk…

[startup_commands]
core set debug 3 res_pjsip_pubsub.so = yes
core set debug 3 res_pjsip_publish_asterisk.so = yes
core set debug 3 res_pjsip_publish_outbound.so = yes
pjsip set logger host 192.168.1.102 = yes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.