MSPL: How to monitor calls that are allowed/blocked by CallerIDBlock

While reviewing a comment on Missed call notification when the call is blocked by CallerIDBlock MSPL Script we realize that the calls blocked by the CallerIDBlock are hard to track.

An easy way to get an event for each blocked call is to use the Log function:

MSPL built-in functions > Log
https://msdn.microsoft.com/en-us/library/office/dn439170.aspx

The CallerIDBlock previous version (1.1) sends the log to the debug log, to view this log we need the APILogger.exe. For more details please check:

Deploying and Troubleshooting Lync Server 2010 MSPL Applications
https://blogs.technet.microsoft.com/nexthop/2012/03/14/deploying-and-troubleshooting-lync-server-2010-mspl-applications/

However, the MSPL Log function has the ability to send it to the Event Viewer.

Since we may not want to have the Event Viewer full of events, we added a new .config file:

CallerIDBlock.config

The file can be changed on-the-fly like the BlockedTelephoneNumbers.txt. This means that we don’t need to reload the script if we want to change the log setting.

For reference, the following code was change from:

To:

Here is an example if we configure the log setting to rejected:

We can also set it to both, then the CallerIDBlock will also log the allowed calls:

Note: We only recommend to the setting both for troubleshooting purposes.

The CallerIDBlock v1.2 can be downloaded from TechNet Gallery:

MSPL: Blocking Calls on Lync Server/Skype for Business 2015 Based on CallerID
https://gallery.technet.microsoft.com/MSPL-Blocking-Calls-on-e6d52de9

CallerIDBlock: Version 1.1 release notes

It’s been a while since we looked at the Blocking Calls on Lync Server and Skype for Business Based on Caller ID.

Since then, we had an update related to the script Missed call notification when the call is blocked by CallerIDBlock MSPL Script, but the MSPL Script remained the same (created by VoIPNorm’s UC Blog – Blocking Calls in Lync Based on Caller ID), with some minor changes to work on Lync Server 2013 and Skype for Business Server 2015.

The first thing we noticed was that the script was using the full path for the BlockedTelephoneNumbers.txt file. While this will work, we could improve it by changing it from:

path=”\\<Lync Share Path>\CallerIDBlock\BlockedTelephoneNumbers.txt

To:

path=”.\BlockedTelephoneNumbers.txt”

Now we don’t need to worry to update the path in the script when we deploy it, but we need to make sure that both files are in the same folder.

Another change was that previously we were processing all the SIP Requests, but to block a call we only need to process the INVITE. So we changed the following line from:

<lc:requestFilter methodNames=”ALL” strictRoute=”true”/>

To:

<lc:requestFilter methodNames=”INVITE” strictRoute=”true”/>

We can also remove the following line, since all SIP Requests handled by CallerIDBlock script will be INVITE:

if(sipRequest.Method == “INVITE”){

To obtain the updated version please go to:

MSPL: Blocking Calls on Lync Server/Skype for Business 2015 Based on CallerID
https://gallery.technet.microsoft.com/MSPL-Blocking-Calls-on-e6d52de9

Missed call notification when the call is blocked by CallerIDBlock MSPL Script

After deploying the CallerIDBlock script, some users mentioned that they received a Missed Call Notification in their mailbox.

During our troubleshooting process, we found out that this was happening because the priority of the CallerIDBlock was low:

Get-CsServerApplication | ft -AutoSize
https://technet.microsoft.com/en-us/library/gg425948.aspx

In this example, the CallerIDBlock has priority 12, while DefaultRouting has 8. The Missed Call Notification is generated by the DefaultRouting, which means that if we want to disable the Missed Call Notification for the blocked number, we need to change CallerIDBlock priority to 8. By doing so, it will run before the DefaultRouting:

Set-CsServerApplication -Identity Service:Registrar:festd2013.gears.lab/CallerIDBlock -Priority 8

We can check if the priority was changed by running again:

Get-CsServerApplication | ft -AutoSize

Since an error event is logged when the priority is changed, we need to restart the services on all Front Ends:

Log Name: Lync Server
Source: LS Inbound Routing
Date: 31/03/2016 13:14:03
Event ID: 45038
Task Category: (1037)
Level: Error
Keywords: Classic
User: N/A
Computer: FESTD2013.gears.lab
Description:
Failed to start Call Notification Queuing Engine.

Failed to start Call Notification Queuing Engine. Exception Message: Object reference not set to an instance of an object..
Cause: Unexpected failure.
Resolution:
Try to re-start the service. If problem persists, contact product support.

After the services restart, everything will go back to normal and we won’t get any Missed Call Notification for blocked numbers.

Blocking Calls on Lync Server and Skype for Business Based on Caller ID

Update 2016/04/01 – To avoid Missed call notifications check Missed call notification when the call is blocked by CallerIDBlock MSPL Script

Last week a customer asked how we can block calls in Lync Server. After some searching, I found the following post:

VoIPNorm’s UC Blog – Blocking Calls in Lync Based on Caller ID

Unfortunately, the comments refer that the script worked only on Lync Server 2010, but not on Lync Server 2013.

With the help of both the above blog script and the MSPL scripting reference, the script was rewritten to support Lync Server 2013 and Skype for Business Server 2015. The script is available in the TechNet Gallery for download:

MSPL: Blocking Calls on Lync Server/Skype for Business 2015 Based on CallerID
https://gallery.technet.microsoft.com/MSPL-Blocking-Calls-on-e6d52de9

In the script, we only need to replace <Lync Share Path> to the proper setting. On a Standard Pool this can be a local path, but on Enterprise Pool it makes more sense to use Lync Share. The reason for this is because all Front Ends must reach both the script and blocked number list files when we enable the script.

Create a new folder in Lync Server Share. In this new folder put the script file (CallerIDBlock.am) and the block list file (BlockedTelephoneNumbers.txt).

calleridblock01

Insert one line per blocked number in the BlockedTelephoneNumbers.txt file. The number must be exactly what the PSTN Gateway is sending to Lync Server. In this case, our gateway doesn’t send the “+”:

Phone,Action
01234567890,block
01234567891,block
01234567892,block

The next step is to add the script as a Lync Server Application. This can be done by entering the following cmdlet in Lync PowerShell:

New-CsServerApplication -Identity “Service:Registrar:<Lync/SfB Front End Pool>/CallerIDBlock” -Uri https://uclobby.com/2014/07/31/CallerIDBlock -Critical $false -ScriptName “\\<Lync/SfB Share Path>\CallerIDBlock\CallerIDBlock.am”

 calleridblock02

Now we need to Enable the new application. We could do it while we add it to Lync/SfB Server, but I prefer to enable it after.

Set-CsServerApplication -Identity “Service:Registrar:<Lync/SfB Front End Pool>/CallerIDBlock” -Enabled $true

Or in Lync Control Panel->Topology->ServerApplication:

 calleridblock03

Shortly afterwards Lync Server Event Viewer can be checked for the following message:

calleridblock04
Note: Check all Front Ends for this message.

When installing the Lync Server 2013 SDK, we can use AppLogger (located in “C:\Program Files\Microsoft Lync Server 2013\SDK\Bin”) to debug MSPL Scripts.

If the number isn’t present in the BlockedTelephoneNumbers.txt file, the message should look like this:

CallerIDBlock processing request:
From – 01234567890;phone-context=uk.*****.co.uk
To – +449876543210
Allowed by CallerIDBlock

After adding the line 01234567890,block to the BlockedTelephoneNumbers.txt file, the call is rejected and the message changes:

CallerIDBlock processing request:
From – 01234567890;phone-context=uk.*****.co.uk
To – +449876543210
Rejected by CallerIDBlock

If the phone-context is received, the script will only use the number before “;”.