Skip to content

Instantly share code, notes, and snippets.

@hospitableit
Last active November 11, 2018 04:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hospitableit/0937e36a314872622e073dc84f449510 to your computer and use it in GitHub Desktop.
Save hospitableit/0937e36a314872622e073dc84f449510 to your computer and use it in GitHub Desktop.
try
{
$CUCMAPIUser = "CUCM Application User UserName"
$CUCMAPIUserEncryptedPassword = "Encrypted Password"
$CUCMServerURI = "Enter the IP or FQDN and port number (Usually 8443) of your CUCM server. e.g. cucmserver01.mylab.com:8443"
#Decrypt the password for use in the script
$SecurePassword = $CUCMAPIUserEncryptedPassword | ConvertTo-SecureString
$Marshal = [System.Runtime.InteropServices.Marshal]
$Bstr = $Marshal::SecureStringToBSTR($SecurePassword)
$Password = $Marshal::PtrToStringAuto($Bstr)
$Marshal::ZeroFreeBSTR($Bstr)
#Prepare the decrypted password for use in the PSCredential Object
$CUCMAPIPassword = ConvertTo-SecureString $Password -AsPlainText -Force
#Create a PSCredential Object for use with the New-WebServiceProxy commandlet
$CUCMAPICredential = New-Object System.Management.Automation.PSCredential($CUCMAPIUser,$CUCMAPIPassword)
# Disable SSL certificate checking so we can connect to servers using a cert signed by a private CA and enable TLS1.2
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
#Query the SOAP APIs WSDL to obtain a list of available methods
$CUCMWebService = New-WebServiceProxy -Uri "https://$CUCMServerURI/controlcenterservice2/services/ControlCenterServices?wsdl" -Namespace CUCMWebProxyService -Credential $CUCMAPICredential
#Use the method soapGetServiceStatus to obtain an array of Services on the Call Manager and there current status
$ServiceStatus = $CUCMWebService.soapGetServiceStatus("")
#Sort the list alphabetically by name
$ServiceStatusList = $ServiceStatus.ServiceInfoList | Sort-Object ServiceName
#Get the number of records returned for use in the loop and initialise a few variables
$ServiceStatusListTotal = $ServiceStatusList.Count
$ErrorMessage = "OK"
$ErrorStatus = "0"
#If reason code is "-1" then service is started - Good
#If reason code is "-1068" then service is stopped not activated - Dont Care
#If reason code is anything else then we have a problem - Throw Error and grab ServiceName for output in the error message to PRTG
For ($ServiceStatusListCount=0; $ServiceStatusListCount -lt $ServiceStatusListTotal; $ServiceStatusListCount++){
If ($ServiceStatusList.ReasonCode[$ServiceStatusListCount] -eq "-1"){
$Test = "OK"
}
ElseIf ($ServiceStatusList.ReasonCode[$ServiceStatusListCount] -eq "-1068"){
$Test = "Deactivated"
}
Else {
$ErrorStatus = "1"
If ($ErrorMessage -eq "OK") {
$ErrorMessage = "Services Down - " + $ServiceStatusList.ServiceName[$ServiceStatusListCount]
}
Else {
$ErrorMessage = $ErrorMessage + " " + "and" + " " + $ServiceStatusList.ServiceName[$ServiceStatusListCount]
}
}
}
If ($ErrorStatus -eq "1") {
Write-Host "<prtg>"
Write-host "<error>1</error>"
Write-Host "<text>$ErrorMessage</text>"
Write-Host "</prtg>"
}
Else {
Write-Host "<prtg>"
Write-Host "<result>"
Write-Host "<channel>Call Manager Services</channel>"
Write-Host "<value>0</value>"
Write-Host "</result>"
Write-Host "<Text>$ErrorMessage</Text>"
Write-Host "</prtg>"
}
}
#If try code block fails then throw an error to PRTG
catch
{
Write-Host "<prtg>"
Write-host "<error>1</error>"
Write-Host "<text>Sensor Error</text>"
Write-Host "</prtg>"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment