############################################################### # # Scriptname: PRTGCustomCitrixADMConfigDrift.ps1 # # Autor: Urs Heeb # Date: 26.09.2022 # # Version: 2022.10.01 / 31.10.22 / Urs Heeb # Create script # # Description: Script does following: # Connects to a Citrix ADM # Gets the information of existing config drifts # # Requirements: # PRTG variables are needed while configuration # FQDN of the ADM %windowsdomain %windowsuser %windowspassword # PRTG service user needs read permission on Citrix ADM # PRTGCustomCitrixADM.psm1 module is needed in the same # PRTG custom sensor folder as this script # ############################################################### ### # Get parameter from PRTG param ( [string]$server, [string]$domain, [string]$username, [string]$password ) # For troubleshooting <# $server="adm.domain.pit" $username="username" $password="password" $CustomSensors="\\domain.pit\development\PRTG Custom sensors" #> # Import ADM PS module $CustomSensors="C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\" Import-Module $CustomSensors\PRTGCustomCitrixADM.psm1 # Create the ADM session $ADMHost = "https://"+$server $ADMSession = Connect-ADM -ADMHost $ADMHost -CredUser $username -CredPW $password # Prepare the output variables $DiffEvents = $null $DiffEvents2 = $null # Get the config status from the ADM $DiffEvents = Invoke-ADMNitro -ADMSession $ADMSession -OperationMethod GET -ResourceType ns_conf # Create the variable only with the active events content $DiffEvents2 = $DiffEvents | Select-Object ns_conf # For troubleshooting # $DiffEvents2.ns_conf | FT hostname, diff_status -AutoSize # Prepare the PRTG output $returnState=$null $returnState=@() $returnStateOK = 0 $returnStateWarning = 1 $returnStateCritical = 2 $RetCritical = $null $AlertString = "ALERT - some ADCs needs attention!" $AlertLevel = "0.9" $Events = $null $Events = @() ForEach ($Event in $DiffEvents2.ns_conf){ If ($Event.diff_status -eq "Diff Exists"){ # Filter out 'entityup' messages from critical state $RetState = $returnStateCritical $Events += [PSCustomObject]@{Severity=$Event.hostname;SourceIP=$Event.ns_ip_address;SourceHost=$Event.hostname;State=[Int64]$RetState} $RetCritical = $RetCritical + 1 } } # For troubleshooting #$Events | FT -AutoSize # Determine return string depends on the several states If ($Events.State -contains 2) { $RetString = $AlertString } ElseIf ($Events.State -contains 1) { $RetString = $WarningString } Else { $RetString = "OK" } # For troubleshooting #$RetString # Start preparing XML output $retXml = "`n" $retXml += " `n" $retXml += " Config drifts`n" $retXml += " $RetCritical`n" $retXml += " Count`n" $retXml += " 1`n" $retXml += " $AlertLevel`n" $retXml += " $AlertString`n" $retXml += " `n" $retXml += " `n" $retXml += " `n" $retXml += " $RetString`n" $retXml += "`n" ### # Return info to PRTG write-host $retXml