Save the following powershell script in "C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML"
# Get variables from PRTG
#param (
# [parameter(Mandatory=$true,Position=0)]
# [string]$object
# )
# Import module
#if (-not (Get-module prtgshell)) {
# Import-Module prtgshell
# }
# Get the Citrix Desktop Delivery Controller
$citrixddc = "SRV.lab.local"
$MyPassword = Get-Content C:\script\CloudCred-prtg.txt | ConvertTo-SecureString
$MyCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "lab\administrator",$MyPassword
# Create a connection to the remote computer
$session = New-PSSession -ComputerName $citrixddc -credential $mycredential
# Run the commands on the remote computer
Invoke-command -Session $session -scriptblock {
asnp Citrix*
$result = Get-BrokerMachine -MaxRecordCount 10000
$ConnectionLog = Get-BrokerConnectionLog |where {$_.BrokeringTime -gt ((Get-Date).AddMinutes(-30))}
}
# Count the variable $result and print it to the variable
$connState = Invoke-Command -Session $session -ScriptBlock {$ConnectionLog}
$State = Invoke-Command -Session $session -ScriptBlock {$result}
# Start writing output to PRTG.
$XML = "<PRTG>"
# Get the total number of desktops to calculate the percentage.
$TotalDesktops = $state.count
# TotalDesktops
#Desktops Connected
$connected = ($state | Where-Object {$_.SessionState -eq "Active"} | Measure-Object -Property sessionstate).count
$disconnected = ($state | Where-Object {$_.SessionState -eq "Disconnected"} | Measure-Object -Property sessionstate).count
$Unregistered = ($state | Where-Object {$_.SummaryState -eq "Unregistered"} | Measure-Object -Property summarystate).count
$Fault = ($state | Where-Object {$_.FaultState -ne "None"} | Measure-Object -Property faultstate).count
$DesktopsInMaintenance = ($state | Where-Object {$_.InMaintenanceMode -eq "True" -and $_.PowerState -eq "On"} | Measure-Object -Property InMaintenanceMode).Count
$ConnectionOK = ($connState | Where-Object {$_.ConnectionFailureReason -eq "None"} | Measure-Object -Property ConnectionFailureReason).count
$SessionPreparation = ($connState | Where-Object {$_.ConnectionFailureReason -eq "SessionPreparation"} | Measure-Object -Property ConnectionFailureReason).count
$RegistrationTimeout = ($connState | Where-Object {$_.ConnectionFailureReason -eq "RegistrationTimeout"} | Measure-Object -Property ConnectionFailureReason).count
$ConnectionTimeout = ($connState | Where-Object {$_.ConnectionFailureReason -eq "ConnectionTimeout"} | Measure-Object -Property ConnectionFailureReason).count
$Licensing = ($connState | Where-Object {$_.ConnectionFailureReason -eq "Licensing"} | Measure-Object -Property ConnectionFailureReason).count
$Ticketing = ($connState | Where-Object {$_.ConnectionFailureReason -eq "Ticketing"} | Measure-Object -Property ConnectionFailureReason).count
$Other = ($connState | Where-Object {$_.ConnectionFailureReason -eq "Other"} | Measure-Object -Property ConnectionFailureReason).count
$XML += "<result><channel>Desktops Total</channel><value>$TotalDesktops</value><CustomUnit>#</CustomUnit></result>"
$XML += "<result><channel>Desktops Connected - Active</channel><value>$connected</value><CustomUnit>#</CustomUnit></result>"
$XML += "<result><channel>Desktops Disconnected - Active</channel><value>$disconnected</value><CustomUnit>#</CustomUnit></result>"
$XML += "<result><channel>Desktops Unregistered - Active</channel><value>$Unregistered</value><CustomUnit>#</CustomUnit></result>"
$XML += "<result><channel>Desktops In Maintenance mode</channel><value>$DesktopsInMaintenance</value><CustomUnit>#</CustomUnit></result>"
$XML += "<result><channel>Connection OK (last 30min)</channel><value>$ConnectionOK</value><CustomUnit>#</CustomUnit></result>"
$XML += "<result><channel>Desktops Fault</channel><value>$Fault</value><CustomUnit>#</CustomUnit><LimitMaxError>0</LimitMaxError><LimitMode>1</LimitMode></result>"
$XML += "<result><channel>Connection Failure to prepare session on (last 30min)</channel><value>$SessionPreparation</value><CustomUnit>#</CustomUnit><LimitMaxError>1</LimitMaxError><LimitMode>1</LimitMode></result>"
$XML += "<result><channel>Connection Registration timeout on (last 30min)</channel><value>$RegistrationTimeout</value><CustomUnit>#</CustomUnit><LimitMaxError>1</LimitMaxError><LimitMode>1</LimitMode></result>"
$XML += "<result><channel>Connection timeout on (last 30min)</channel><value>$ConnectionTimeout</value><CustomUnit>#</CustomUnit><LimitMaxError>1</LimitMaxError><LimitMode>1</LimitMode></result>"
$XML += "<result><channel>Connection Licensing issue on (last 30min)</channel><value>$Licensing</value><CustomUnit>#</CustomUnit><LimitMaxError>1</LimitMaxError><LimitMode>1</LimitMode></result>"
$XML += "<result><channel>Connection Failure during ticketing on (last 30min)</channel><value>$Ticketing</value><CustomUnit>#</CustomUnit><LimitMaxError>1</LimitMaxError><LimitMode>1</LimitMode></result>"
$XML += "<result><channel>Connection Failure to prepare session on (last 30min)</channel><value>$Other</value><CustomUnit>#</CustomUnit><LimitMaxError>1</LimitMaxError><LimitMode>1</LimitMode></result>"
# Disconnect the session
Remove-PSSession $session
#Finish writing to PRTG
$XML += "</PRTG>"
Function WriteXmlToScreen ([xml]$XML) #just to make it clean XML code...
{
$StringWriter = New-Object System.IO.StringWriter;
$XmlWriter = New-Object System.Xml.XmlTextWriter $StringWriter;
$XmlWriter.Formatting = "indented";
$XML.WriteTo($XmlWriter);
$XmlWriter.Flush();
$StringWriter.Flush();
Write-Output $StringWriter.ToString();
}
WriteXmlToScreen "$XML"
#write-host $XML
Create a custom exexml sensor and select the previous scritpt.
Questo articolo ti è stato utile?
Fantastico!
Grazie per il tuo feedback
Siamo spiacenti di non poterti essere di aiuto
Grazie per il tuo feedback
Feedback inviato
Apprezziamo il tuo sforzo e cercheremo di correggere l’articolo