I am working into powershell scripts to monitor sessions of active users in view, this powershell script use by nagios to send alerst via email and sms.
right now the missing part is the performance graph although there is data but not displayed as graph.
here is the script
# Define Critical & Warning levels to alert back to Nagios.
$Critical = 10
$Warning = 8
###############################################################################################
# Set variables to 0
$Count = 0
# Set Nagios State
$returnStateOK = 0
$returnStateWarning = 1
$returnStateCritical = 2
# Add VMware View PowerShell Snapin.
add-PSSnapin "VMware.View.Broker"
# Collect Desktop Information
ForEach ($Result in Get-RemoteSession -pool_id DS7 | Select state)
{
if ($Result.state -eq "CONNECTED")
{
$Count = $Count + 1
}
elseif ($Result.state -eq "Error")
{
$Count = $Count + 1
}
elseif ($Result.state -eq "Agent unreachable")
{
$Count = $Count + 1
}
}
### PerformanceData Output
$NagiosPerfData = "|Active sessions=" + $Count + ";8;10;0"
$NagiosPerfData = $NagiosPerfData -replace " ", ""
if ($Count -ge $Critical)
{
###CRITICAL STATE
Write-Host "Activesessions="$Count" "$NagiosPerfData
((Get-RemoteSession -pool_id DS7)|Where-Object{$_.state -eq "CONNECTED"}) | select username, duraTion #starTime
exit $returnStateCritical
}
elseif ($Count -ge $Warning)
{
###WARNING STATE
Write-Host "Activesessions="$Count" "$NagiosPerfData
((Get-RemoteSession -pool_id DS7)|Where-Object{$_.state -eq "CONNECTED"}) | select username, duraTion #starTime
exit $returnStateWarning
}
else
{
###OK STATE
Write-Host "Activesessions="$Count" "$NagiosPerfData
((Get-RemoteSession -pool_id DS7)|Where-Object{$_.state -eq "CONNECTED"}) | select username, duraTion #starTime
}
exit $returnStateOk