# Microsoft Skype for Business - Edge Server Services Check # # Info: # This NSCP (former known as NSClient++) plugin will check the services on an Skype for business edge server and will report # if that service isnīt any longer running. # # This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # Revision History: # Version 1.0: 2015-03-28 Bastian W. [Bastian@gmx-ist-cool.de] # * initial version # Version 2.0: 2015-03-31 Bastian W. [Bastian@gmx-ist-cool.de] # * completely rewritten due to some issues to detect the services # Version 2.1: 2016-08-12 Bastian W. [Bastian@gmx-ist-cool.de] # * Configured for an Skype for Business Edge Server # # FAQ: # How To solve "cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details." # See: http://technet.microsoft.com/en-us/library/ee176949.aspx [a possible solution would be 'Set-ExecutionPolicy RemoteSigned'] # # Installation: # # 1.) # Create a folder on C:\ called "NagiosMonitoring" if it didnīt exist, and put this script into that folder. # # Note: If you use another Foldername, you need to change this script completly! # # 2.) # Now start a Powershell and run the following comands (to test if the script is working for you) # "C:" # "cd NagiosMonitoring" # ".\NagiosMonitoring_SfB_EdgeServicesCheck.ps1" # # 3.) # Add this script to the NSClient++ configuration (file: NSC.ini) # # [External Scripts] # SfBEdgeServicesCheck=cmd /c echo C:\NagiosMonitoring\NagiosMonitoring_SfB_EdgeServicesCheck.ps1 | PowerShell.exe -Command - # # On the check_nrpe command include the -t 30, since it takes some time to load the Exchange cmdlet's. # # 4.) # uncommend CheckExternalScripts.dll in the NSClient++ configuration (file: NSC.ini) # # 5.) # You need to edit the config below # # Configuration: # ==================== # Create a subset of the previous array for services you want to monitor # Syntax: $ServicesToCheckArray = "Service1","Service2","Service3"; $ServicesToCheckArray="RTCSRV","RTCMRAUTH","RTCMEDIARELAY","RTCCLSAGT","REPLICA","RTCDATAPROXY"; # # 6.) # restart the NSClient++ Service # ========================================================================================================================= # # ------------- Do not change anything behind that line ! ---------------------------- # # # Buildinfo # # initialize vars/reset vars to zero $intNagiosStatus = "0" $strNagiosDescription = "" $bfound = 0 $bDebugScript = 0 $strServiceToCheck = "" #Create an array of all services running $GetService = get-service -ComputerName $env:computername $FoundServices = New-Object System.Collections.ArrayList #Loop true all services on Host foreach ($Service in $GetService) { foreach ($strServiceToCheck in $ServicesToCheckArray) { # loop true all services we need to check if ($bDebugScript -eq 1){ Write-Host " Debug:: Working on Check for Service:"$strServiceToCheck -foregroundcolor magenta} if ($Service.Name -eq $strServiceToCheck) { if ($bDebugScript -eq 1){ Write-Host " Debug:: Current Service"$Service.Name"matched to be checked service"$strServiceToCheck -foregroundcolor magenta} $bfound = 1 # We found our service if ($bDebugScript -eq 1){ Write-Host " Debug:: Found value "$bfound -foregroundcolor magenta} if ($Service.Status -eq "StopPending") { #check if a service is hung if ($bDebugScript -eq 1){ Write-Host " Debug:: Current Service "$Service.Name"is StopPending" -foregroundcolor magenta} #automatically restart the service. #$servicePID = (gwmi win32_Service | where { $_.Name -eq $strServiceToCheck}).ProcessID #Stop-Process $ServicePID #Start-Service -InputObject (get-Service -ComputerName $env:computername -Name $strServiceToCheck) if ($strNagiosDescription -eq "") { # $strNagiosDescription = $strServiceToCheck + " (pending)" $strNagiosDescription = $strNagiosDescription + ", " + $Service.DisplayName + " (pending)" } else { #$strNagiosDescription = $strNagiosDescription + ", " + $strServiceToCheck + " (pending)" $strNagiosDescription = $strNagiosDescription + ", " + $Service.DisplayName + " (pending)" } if ($intNagiosStatus -ne "2") { # Don't lower the status level if we already have a critical state, otherwiese set it to critical $intNagiosStatus = "2" } } elseif ($Service.Status -eq "Stopped") { # check if a service is stopped if ($bDebugScript -eq 1){ Write-Host " Debug:: Current Service "$Service.Name"is Stopped" -foregroundcolor magenta} #automatically restart the service. #Start-Service -InputObject (get-Service -ComputerName $env:computername -Name $strServiceToCheck) if ($strNagiosDescription -eq "") { #$strNagiosDescription = $strServiceToCheck + " (stopped)" $strNagiosDescription = $Service.DisplayName + " (stopped)" } else { #$strNagiosDescription = $strNagiosDescription + ", " + $strServiceToCheck + " (stopped)" $strNagiosDescription = $strNagiosDescription + ", " + $Service.DisplayName + " (stopped)" } if ($intNagiosStatus -ne "2") { # Don't lower the status level if we already have a critical state, otherwiese set it to warning $intNagiosStatus = "1" } } [void] $FoundServices.Add("$strServiceToCheck") $strServiceToCheck = "" } } } foreach ($EntryFromServiceArray in $ServicesToCheckArray) { if($FoundServices -contains "$EntryFromServiceArray") { # nothing to do } else { # we couldnīt found $strServiceToCheck # we need to build here our list with missing services # seamed the service we should control here is missing if ($strNagiosDescription -eq "") { $strNagiosDescription = $strServiceToCheck + " (not found)" } else { $strNagiosDescription = $strNagiosDescription + ", " + $strServiceToCheck + " (not found)" } # Set the status to critical $intNagiosStatus = "2" if ($intNagiosStatus -ne "2") { # Don't lower the status level if we already have a critical state, otherwiese set it to critical $intNagiosStatus = "2" } } } # Output, when should we push out a notification to nagios? if ($intNagiosStatus -eq "2") { Write-Host "CRITICAL:" $strNagiosDescription } elseif ($intNagiosStatus -eq "1") { Write-Host "WARNING:" $strNagiosDescription } else { Write-Host "Service OK: All services are up and running" } exit $intNagiosStatus