[HOW TO] Send presence status from Asterisk 13 to kamailio presence module

Hi there, we need to do next thing - integrate Asterisk certified/13.8-cert4 with kamailio 4.4 presence module.
What we need - to have actual state of all Asterisk’s extensions in database for easy access from external applications\services.

What we have - Asterisk certified/13.8-cert4 with PJSIP 2.3 and realtime config in PostgreSQL. And Kamailio server 4.4.5 with own MySQL db.

In Asterisk pjsip.conf :
[kamailio-devicestate]
type=outbound-publish
server_uri=sip:10.10.10.10
event=asterisk-devicestate

Here SIP message that actually send Asterisk towards kamailio:

PUBLISH sip:10.10.10.10 SIP/2.0
Via: SIP/2.0/UDP 10.10.10.9:5137;rport;branch=z9hG4bKPjc56540d7-14ab-49d6-863a-ee630104e353
From: <sip:10.10.10.9>;tag=0342b7ec-f764-4dd4-9ac0-17ea58c69446
To: <sip:10.10.10.10>
Call-ID: 4817e8f5-b071-42d7-af08-f1b861bf4d77
CSeq: 6924 PUBLISH
Event: asterisk-devicestate
Expires: 3600
Max-Forwards: 70
User-Agent: Asterisk PBX certified/13.8-cert4
Content-Type: application/json
Content-Length:   100

{"type":"devicestate","device":"PJSIP/101","state":"INVALID","cachable":1,"eid":"00:11:22:33:44:55"}

and Kamailio responds with 489 error:

SIP/2.0 489 Bad Event
Via: SIP/2.0/UDP 10.10.1.66:5137;rport=5137;branch=z9hG4bKPjc56540d7-14ab-49d6-863a-ee630104e353;   received=10.10.10.9
From: <sip:10.10.10.10>;tag=0342b7ec-f764-4dd4-9ac0-17ea58c69446
To: <sip:10.10.1.63>;tag=a6a1c5f60faecf035a1ae5b6e96e979a-ddd4
Call-ID: 4817e8f5-b071-42d7-af08-f1b861bf4d77
CSeq: 6924 PUBLISH
Allow-Events: xcap-diff, presence.winfo, presence
Server: kamailio (4.4.5 (x86_64/linux))
Content-Length: 0

Changing @body property at asterisk side - do nothing.
Checked

  • application/dialog-info+xml
  • application/pidf+xml
  • application/xpidf+xml
  • application/cpim-pidf+xml

Have you followed the wiki[1] and used the example configs as a base?

[1] https://wiki.asterisk.org/wiki/display/AST/Publishing+Extension+State

Of course, at early beginning

The example config didn’t work at all. The only one working conf is in first message.

All required modules

  • res_pjsip.so: Core of PJSIP code in Asterisk.
    
  • res_pjsip_pubsub.so: The code that implements SUBSCRIBE/NOTIFY logic, on which individual event handlers are built.
  • res_pjsip_exten_state.so: Handles the “presence” and “dialog” events.
  • res_pjsip_pidf_body_generator.so: This module generates application/pidf+xml message bodies. Required for most subscriptions to the “presence” event.
  • res_pjsip_xpidf_body_generator.so: This module generates application/xpidf+xml message bodies. Required for some subscriptions to the “presence” event.
  • res_pjsip_dialog_info_body_generator.so: Required for subscriptions to the “dialog” event. This module generates application/dialog-info message bodies.

are loaded.

Main issue from my point of view- Asterisk sends PUBLISH message in only one format application/json and I can/t change this :confused:

Define “didn’t work at all”. Was anything output at startup? Did the configuration load? The exact configuration on the wiki is what I used against Kamailio when doing testing. Did you turn on auto hints? Did you specify any context/extension filtering?

ok, checked again

actual config in pjsip.conf:

[test-esc]
type=outbound-publish
server_uri=sip:10.10.10.10
from_uri=sip:10.10.10.9
event=dialog
multi_user=yes
@body=application/dialog-info+xml
;@context=^users

[test-esc2]
type=outbound-publish
server_uri=sip:10.10.10.10
from_uri=sip:10.10.10.9
event=dialog
multi_user=yes
@body=application/pidf+xml
;@context=^users

[test-esc3]
type=outbound-publish
server_uri=sip:10.10.10.10
from_uri=sip:10.10.10.9
event=dialog
multi_user=yes
@body=application/xpidf+xml
;@context=^users

[test-esc4]
type=outbound-publish
server_uri=sip:10.10.10.10
from_uri=sip:10.10.10.9
event=dialog
multi_user=yes
@body=application/cpim-pidf+xml

;@context=^users

Got errors in Asterisk console:

ERROR[1066]: config_options.c:715 aco_process_var: Could not find option suitable for category 'test-esc' named 'multi_user' at line 150 of
ERROR[1066]: res_sorcery_config.c:318 sorcery_config_internal_load: Could not create an object of type 'outbound-publish' with id 'test-esc' from configuration file 

DEBUG[1066]: config.c:3564 ast_parse_arg: extract int from [5] in [-2147483648, 2147483647] gives [5](0)
DEBUG[1066]: config.c:3564 ast_parse_arg: extract int from [3600] in [-2147483648, 2147483647] gives [3600](0)
ERROR[1066]: config_options.c:715 aco_process_var: Could not find option suitable for category 'test-esc2' named 'multi_user' at line 159 of
ERROR[1066]: res_sorcery_config.c:318 sorcery_config_internal_load: Could not create an object of type 'outbound-publish' with id 'test-esc2' from configuration file

DEBUG[1066]: config.c:3564 ast_parse_arg: extract int from [5] in [-2147483648, 2147483647] gives [5](0)
DEBUG[1066]: config.c:3564 ast_parse_arg: extract int from [3600] in [-2147483648, 2147483647] gives [3600](0)
ERROR[1066]: config_options.c:715 aco_process_var: Could not find option suitable for category 'test-esc3' named 'multi_user' at line 168 of
ERROR[1066]: res_sorcery_config.c:318 sorcery_config_internal_load: Could not create an object of type 'outbound-publish' with id 'test-esc3' from configuration file

DEBUG[1066]: config.c:3564 ast_parse_arg: extract int from [5] in [-2147483648, 2147483647] gives [5](0)
DEBUG[1066]: config.c:3564 ast_parse_arg: extract int from [3600] in [-2147483648, 2147483647] gives [3600](0)
ERROR[1066]: config_options.c:715 aco_process_var: Could not find option suitable for category 'test-esc4' named 'multi_user' at line 177 of
ERROR[1066]: res_sorcery_config.c:318 sorcery_config_internal_load: Could not create an object of type 'outbound-publish' with id 'test-esc4' from configuration file

Auto hints is on in extensions.conf -both in [globals] and [from-internal] contexts.

Ah, you’re using 13. This functionality is only available as of 14. That’s why it is not working.

hmm, what about https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Configuration_res_pjsip_outbound_publish#Asterisk13Configuration_res_pjsip_outbound_publish-outbound-publish_transport ?

Asterisk 13 allows the exchange of device state and MWI information between Asterisk instances using an Asterisk specific JSON payload that you saw previously. It doesn’t allow using the standard body types such as application/xpidf+xml.

ok, thanks for clarify
will try Asterisk 14

hi, i just want a clarify with this: i connect phones to asterisk directly and phones show status BLF correclty but when i setup kamailio presence module does not work property! why?

@jcolp said that Asterisk 13 allows the exchange of device state and MWI information between Asterisk instances using an Asterisk specific JSON payload BUT that means i cannot do if i have kamailio integrated in realtime with asterisk 13? why then if i setup phones directly with asterisk the BLF works?