Hi all,

I'd like to share the results of the research I've done on how to monitor Lync online users, Lync Inbound Calls and Lync Outbound Calls.

On the internet I've found a Powershell script, which I have modified to monitor the inbound and outbound calls.

Here are the scripts. To use the script in PRTG you have to do the following:

  1. Copy powershell.exe on the probe from c:\windows\system32\windowspowershell\* to the EXE/XML directory in c:\program files (x86)\PRTG Network Monitor\Custom Sensors
  2. Copy the script as a .ps1 file in c:\batch on the probe
  3. Create an EXE/ADVANCED script in PRTG
  4. Select powershell.exe
  5. Enter parameters: -noprofile -executionpolicy bypass -file c:\batch\prtg-lyncuser.ps1 (or your script)
  6. Set security context to Use Windows credentials of parent device

Script to monitor Lync Online Users:

# prtg-lyncuser.ps1
#
# Loading current sip client connections as performance counter
#

param (
	[string]$server= "YOUR LYNC FE SERVER, YOUR SECOND LYNC FE SERVER(OPTIONAL), YOUR THIRD LYNC FE SERVER(OPTIONAL)"  # specify Servers
)

write-host "Start PRTG Sensor" 
write-host "Server:" $Server 

$serverlist = $server.split(",")
write-host "Serverlist count:" $Serverlist.count 

$result="<prtg>`r`n"


foreach ($server in $serverlist){
	write-host "Server: " $server
	$value = (Get-Counter "\LS:SIP - Peers(Clients)\SIP - Connections Active" -ComputerName $server -ErrorAction silentlycontinue)
	if ($error) {
		# Skip Counters
		write-host "Server: $server Unable to read $counter"
		$error.clear()
	}
	else  {
		$result+="  <result>`r`n"
		$result+="    <channel>SIPClients("+$server+")</channel>`r`n"
		$result+="    <value>"+$value.CounterSamples[0].CookedValue+"</value>`r`n"
		$result+="    <unit>Count</unit>`r`n"
		$result+="    <mode>Absolute</mode>`r`n"
		$result+="  </result>`r`n"
	}
}

$result+="<text>LyncUsers:"+$arg+"</text>`r`n"
$result+="</prtg>"

write-host "End: ExitCode "$error.count

Write-host "Sending Result to output pipeline"
$result

if ($error) {
	#write-host "Found Errors"
	EXIT 1
}

Script to monitor Inbound calls:

# prtg-lynccallsin.ps1
#
# Loading current sip client connections as performance counter
#

param (
	[string]$server= "YOUR LYNC FE SERVER, YOUR SECOND LYNC FE SERVER(OPTIONAL), YOUR THIRD LYNC FE SERVER(OPTIONAL)"  # specify Servers
)

write-host "Start PRTG Sensor" 
write-host "Server:" $Server 

$serverlist = $server.split(",")
write-host "Serverlist count:" $Serverlist.count 

$result="<prtg>`r`n"


foreach ($server in $serverlist){
	write-host "Server: " $server
	$value = (Get-Counter -ComputerName $server -Counter "\LS:MediationServer - Inbound Calls(_Total)\- Current" -ErrorAction silentlycontinue)
	if ($error) {
		# Skip Counters
		write-host "Server: $server Unable to read $counter"
		$error.clear()
	}
	else  {
		$result+="  <result>`r`n"
		$result+="    <channel>Inbound Calls("+$server+")</channel>`r`n"
		$result+="    <value>"+$value.CounterSamples[0].CookedValue+"</value>`r`n"
		$result+="    <unit>Count</unit>`r`n"
		$result+="    <mode>Absolute</mode>`r`n"
		$result+="  </result>`r`n"
	}
}

$result+="<text>Calls:"+$arg+"</text>`r`n"
$result+="</prtg>"

write-host "End: ExitCode "$error.count

Write-host "Sending Result to output pipeline"
$result

if ($error) {
	#write-host "Found Errors"
	EXIT 1
}

Script to monitor outbound calls:

# prtg-lyncuser.ps1
#
# Loading current sip client connections as performance counter
#

param (
	[string]$server= "YOUR LYNC FE SERVER, YOUR SECOND LYNC FE SERVER(OPTIONAL), YOUR THIRD LYNC FE SERVER(OPTIONAL)"  # specify Servers
)

write-host "Start PRTG Sensor" 
write-host "Server:" $Server 

$serverlist = $server.split(",")
write-host "Serverlist count:" $Serverlist.count 

$result="<prtg>`r`n"


foreach ($server in $serverlist){
	write-host "Server: " $server
	$value = (Get-Counter -ComputerName $server -Counter "\LS:MediationServer - Outbound Calls(_Total)\- Current" -ErrorAction silentlycontinue)
	if ($error) {
		# Skip Counters
		write-host "Server: $server Unable to read $counter"
		$error.clear()
	}
	else  {
		$result+="  <result>`r`n"
		$result+="    <channel>Outbound Calls("+$server+")</channel>`r`n"
		$result+="    <value>"+$value.CounterSamples[0].CookedValue+"</value>`r`n"
		$result+="    <unit>Count</unit>`r`n"
		$result+="    <mode>Absolute</mode>`r`n"
		$result+="  </result>`r`n"
	}
}

$result+="<text>Calls:"+$arg+"</text>`r`n"
$result+="</prtg>"

write-host "End: ExitCode "$error.count

Write-host "Sending Result to output pipeline"
$result

if ($error) {
	#write-host "Found Errors"
	EXIT 1
}

It's working seamlessly on our systems in PRTG.


Article Comments

Thanks for sharing the script! :) Looks like a lot of work went into it. Just note that you don't need to copy the PowerShell.exe into the EXE XML directory.

Simply put the scripts into the C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML directory and it will be available as a script in the EXEXML setup. The NoProfile parameter is already built into the PowerShell call, you just need to execute

Set-ExecutionPolicy Unrestricted

...on the PRTG Server in a elevated 32 Bit PowerShell to make it work :)


Feb, 2015 - Permalink

Thanks Herman, very useful! Just a small warning: the inbound/outbound call scripts are missing the parameter '-ComputerName $server' on the line that starts with: $value = (Get-Counter -Counter...


Mar, 2015 - Permalink

Thanks for the hint, Gunter! I fixed the lines in the original post :)


Mar, 2015 - Permalink

Just wanted to say awesome job on these! Any more visibility I can get into Lync the happier I'll be!


Apr, 2015 - Permalink

Hello, I have an error when i want use this sensor. It tells me:

"XML: The returned xml does not match the expected schema. (code: PE233) -- JSON: The returned json does not match the expected structure (No mapping for the Unicode character exists in the target multi-byte code page). (code: PE231)"

In fact i am not sure that my settings are ok.

In sensor Settings i have:

EXE/Script: powershell.exe

Parameters: -noprofile -executionpolicy bypass -file C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\Le_script_lync.ps1

My path is correct but i am bad with powershell so i do not know where my mistake is.

Could you help me please?

PS: My server is a lync 2013


May, 2015 - Permalink

Stagiaire2,

Make sure you put these scripts on the probe, and not the main PRTG server.


May, 2015 - Permalink

Can you try to exchange the following line in all scripts:

$result="<prtg>`r`n"

with this one:

$result='<?xml version="1.0" encoding="UTF-8" ?>`r`n<prtg>`r`n'

...does it work then? What's the output when you execute it manually?


May, 2015 - Permalink

Hello,

If i execute my script manually i have the message :

"PS C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML> C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\Le_script_lync.ps1 Start PRTG Sensor

Server: 10.1.0.56,10.1.0.39

Serverlist count: 2

Server: 10.1.0.56

Server: 10.1.0.56 Unable to read

Server: 10.1.0.39

Server: 10.1.0.39 Unable to read

End: ExitCode 0 Sending Result to output pipeline <?xml version="1.0" encoding="UTF-8" ?>`r`n<prtg>`r`n<text>LyncUsers:</text> </prtg>".

I tried to put " $result='<?xml version="1.0" encoding="UTF-8" ?>`r`n<prtg>`r`n' " but it is not the problem.

Should i fix something in my lync-server?


May, 2015 - Permalink

Did you modify the server variable inside the script? If not, you need to pass a parameter containing the FQDN of your lync server. For example:

.\Le_script_lync.ps1 lync.live.local

Is that the case?


May, 2015 - Permalink

Thank you for your scripts. They helped me to monitor Skype for business. I made them a bit simpler. Inbound connections; $server = $args $connections = (Get-Counter -ComputerName $server -Counter "\LS:MediationServer - Inbound Calls(_Total)\- Current").CounterSamples.CookedValue write-host $connections":OK"

Outbound connections; $server = $args $connections = (Get-Counter -ComputerName $server -Counter "\LS:MediationServer - Outbound Calls(_Total)\- Current").CounterSamples.CookedValue write-host $connections":OK"

Number of clients; $server = $args $connections = (Get-Counter "\LS:SIP - Peers(Clients)\SIP - Connections Active" -ComputerName $server).CounterSamples.Cookedvalue write-host $connections":OK"

When creating this sensors use ’Custom sensors’ ‘EXE/script’ and in the sensor settings define ‘Parameters’ to ‘%host’ – that is what is read in the script sin $args

You need to have credentials on the target server from PRTG, we add the PRTG-server to trusteed computers via GPU so we can run Powershell scripts on our target servers.


Nov, 2015 - Permalink

Thanks for your input! It will come in handy for people who want to integrate this :)


Nov, 2015 - Permalink

Anyone who can show an output from the sensor? I'm about to try adding it.


May, 2016 - Permalink

What stops you from doing so :) There are not many options, either the script works or it will error out. If it's working, you'll see an XML output.


May, 2016 - Permalink

Hi guys, i just added the Script´s, the Output is green / ok, but values are 0. Any idea?


Oct, 2016 - Permalink

What actual script are we talking about? There are three of them :) Did you install them correctly?


Oct, 2016 - Permalink

the command param () is not necessary as this is not part of a function. I wonder if nobody gets an error calling the script.


Jan, 2017 - Permalink

It sure is used? The $servers variable gets split into the $serverList array using $servers.split(',')? ;)


Jan, 2017 - Permalink

Just incase this is of use to anyone else, you will recieve issues on this if you run the server list against the skype servers themselves when using a mediation server they will not have the required perfmon entries for

"\LS:MediationServer - Inbound Calls(_Total)\- Current"
"\LS:MediationServer - Outbound Calls(_Total)\- Current"

And will return errors relating to a null array. Aim them at mediation servers if you use them.

Cheers

sam


Mar, 2018 - Permalink

Is the same solution fit for Skype For Business 2015?


Jan, 2019 - Permalink

I tend to say no, as the counters most likely differ. One thing I found regarding PRTG and S4B was this. Perhaps it will get you started?


PRTG Scheduler | PRTGapi | Feature Requests | WMI Issues | SNMP Issues

Kind regards,
Stephan Linke, Tech Support Team


Jan, 2019 - Permalink

hi , is there any chance I could monitor the failed logon to lync users with any scripts?


Mar, 2019 - Permalink

I can't find anything regarding that to be logged anywhere :( Perhaps someone else has an idea. Note that Lync is already replaced by Skype For Business, which is already being replaced by Microsoft Teams. So it might be time to migrate :)


PRTGapi | Feature Requests | WMI Issues | SNMP Issues

Kind regards,
Stephan Linke, Tech Support Team


Mar, 2019 - Permalink