Overview
A new feature called Tenant ID (or multi-tenant identifier) was recently added to Asterisk. It doesn’t do anything on its own, but can be used for many different purposes. If you want call traffic that goes through a certain dialplan extension to have a specific Tenant ID, you can do so. If you want all channels created via a specific PJSIP endpoint to have the same Tenant ID, you can do that as well. The power of Tenant ID is in its flexibility and being able to do what you want with it.
How to Set Tenant ID
Tenant ID can be set in a few different ways. The first option is to set it in dialplan using the Set function:
exten => example,1,Set(CHANNEL(tenantid)=My Tenant ID)
It can be read similarly:
exten => example2,1,NoOp(${CHANNEL(tenantid)})
This is useful for changing Tenant ID on the fly, but does have some fallbacks. That’s why the second option is the preferred method. In pjsip.conf, you can specify the Tenant ID on an endpoint using the tenantid option. Any channel created using this endpoint will have Tenant ID set before important events such as Newchannel, which can be very useful.
[my_endpoint]
type=endpoint
tenantid=My Tenant ID
You can also set Tenant ID via set_var (like channel variables), but this has the same fallback as using the dialplan. Newchannel events will not have Tenant ID set because of how channels are created and the order in which things happen.
set_var=CHANNEL(tenantid)=My Tenant ID
It’s important to note that the latter options are specific to chan_pjsip, but Tenant ID itself is available to all channel types.
Events
If Tenant ID is present on a channel, it will show up in channel-related events for things like AMI, ARI, CDR, and CEL. For example, let’s say you set tenantid in pjsip.conf for endpoint 1234 to My Tenant ID. When this endpoint is used to make a call, you’d get something like this:
Event: Newchannel
Privilege: call,all
Channel: PJSIP/1234-00000000
ChannelState: 4
ChannelStateDesc: Ring
CallerIDNum: 1234
CallerIDName: 1234
ConnectedLineNum: <unknown>
ConnectedLineName: <unknown>
Language: en
AccountCode:
Context: default
Exten: 111
Priority: 1
Uniqueid: 1725547169.0
Linkedid: 1725547169.0
Tenantid: My Tenant ID
If Tenant ID had not been set, it would not show up in the event at all:
Event: Newchannel
Privilege: call,all
Channel: PJSIP/1234-00000000
ChannelState: 4
ChannelStateDesc: Ring
CallerIDNum: 1234
CallerIDName: 1234
ConnectedLineNum: <unknown>
ConnectedLineName: <unknown>
Language: en
AccountCode:
Context: default
Exten: 111
Priority: 1
Uniqueid: 1725547169.0
Linkedid: 1725547169.0
With CDR, tenantid is a read-only variable that can be accessed with the CDR function:
CDR(tenantid)
If you’re using CDR and wish to use Tenant ID to track channels for things like billing, then it’s highly recommended to use chan_pjsip and the tenantid option. The same applies to CEL.
Final Thoughts
There are several things you can do with Tenant ID from a system administrator perspective. For example, you could put your customers into different groups that are tracked by a Tenant ID. You can easily identify which group they belong to from there. Another option is assigning a Tenant ID based on the type of phone that is registering to an endpoint. Data can then be collected based on that for performance monitoring. There are several possibilities, and we’d love to hear what you plan to use Tenant ID for!
If you want to take a look at the commit in Asterisk, you can find it here: https://github.com/asterisk/asterisk/commit/fb0e46e464b54b79818841f6cf9d82bea0d5a794
The testsuite link for the tests: https://github.com/asterisk/testsuite/commit/3220993aa8df248926a98f5912a1bd5ec1ca14bc