Skip to content

Instantly share code, notes, and snippets.

@cleytonferrari
Last active September 8, 2022 16:15
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 cleytonferrari/eb4beb4cd72a91b41052b52615a9c22d to your computer and use it in GitHub Desktop.
Save cleytonferrari/eb4beb4cd72a91b41052b52615a9c22d to your computer and use it in GitHub Desktop.
Monitorando conexão remota - RDP no Zabbix, utilizando o zabbix agent

Monitoramento de RDP no Zabbix

Passo 1

Execute no terminal do PowerShell, no modo administrador, o seguinte comando: (Para saber mais https://www.powershellgallery.com/packages/PSTerminalServices/1.0)

Install-Module -Name PSTerminalServices

Passo 2

Salve o arquivo rdp.terminal.server.ps1 na pasta de instalação do zabbix C:\Program Files\Zabbix Agent

Passo 3

Crie um parametro de usuário no Zabbix, adicionando a seguinte linha de código, ao arquivo C:\Program Files\Zabbix Agent\zabbix_agentd.conf

### Option: UserParameter
UserParameter=pmap.rdp.terminal[*],powershell.exe -noprofile -executionpolicy bypass -File "C:\Program Files\Zabbix Agent\rdp.terminal.server.ps1" $1

Pronto!

Agora basta criar o item no zabbix, utilizando algumas das chaves abaixo disponivel:

pmap.rdp.terminal[ATIVODADOS]
pmap.rdp.terminal[ATIVO]
pmap.rdp.terminal[ATIVONUM]
pmap.rdp.terminal[INATIVO]
pmap.rdp.terminal[INATIVONUM]
pmap.rdp.terminal[DEVICE]
pmap.rdp.terminal[IP]

Lembre-se de reiniciar o Agente do Zabbix

Para saber mais https://github.com/suportecavalcante/zabbix.templates/tree/master/windows/zabbix.rdp.terminalserver

# Desenvolvido por Diego Cavalcante - 10/02/2017
# Monitoramento Windows RDP - Terminal Server
Param(
[string]$select
)
# Nome dos Usuarios Ativos
if ( $select -eq 'ATIVODADOS' )
{
Import-Module PSTerminalServices
Get-TSSession -State Active -ComputerName localhost | foreach {"IP: "+($_.IPAddress).IPAddressToString + ", Usuario: "+ $_.UserName+", Dispositivo: "+ $_.ClientName}
}
# Nome dos Usuarios Ativos
if ( $select -eq 'ATIVO' )
{
Import-Module PSTerminalServices
Get-TSSession -State Active -ComputerName localhost | foreach {$_.UserName}
}
# Total de Usuarios Ativos
if ( $select -eq 'ATIVONUM' )
{
Import-Module PSTerminalServices
Get-TSSession -State Active -ComputerName localhost | foreach {$_.UserName} | Measure-Object -Line | select-object Lines | select-object -ExpandProperty Lines
}
# Nome dos Usuarios Inativos
if ( $select -eq 'INATIVO' )
{
Import-Module PSTerminalServices
Get-TSSession -State Disconnected -ComputerName localhost | where { $_.SessionID -ne 0 } | foreach {$_.UserName}
}
# Total de Usuarios Inativos
if ( $select -eq 'INATIVONUM' )
{
Import-Module PSTerminalServices
Get-TSSession -State Disconnected -ComputerName localhost | where { $_.SessionID -ne 0 } | foreach {$_.UserName} | Measure-Object -Line | select-object Lines | select-object -ExpandProperty Lines
}
# Nome do Dispositivo Remoto
if ( $select -eq 'DEVICE' )
{
Import-Module PSTerminalServices
Get-TSSession -State Active -ComputerName localhost | foreach {$_.ClientName}
}
# IP do Dispositivo Remoto
if ( $select -eq 'IP' )
{
Import-Module PSTerminalServices
Get-TSSession -State Active -ComputerName localhost | foreach {(($_.IPAddress).IPAddressToString)}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment