PRTG - Sensor multiples servicios de Windows

Como ya explicamos anteriormente como crear un sensor mediante "EXE\Script Advanced", ahora vamos a crear para ver multiples servicios de windows en nuestro caso todos los servicios de Citrix.

Para que los sensores solo tengan dos valores “running” o “Stopped”, se configura un “Value Lookup” pre-generado por PRTG, en otro post explicaremos como generar LookUps personalizdos. https://www.paessler.com/manuals/prtg/define_lookups

<# ==============================================================================================
 
 Creado para PRTG
 
 NAME: Citrix_Service_sensors_xml.ps1
 ORGANIZATION: MORDOR.WORLD
 AUTHOR: GrumpyGon, Bujarron 
 DATE  : 23/10/2019
 VERSION: 01.00.01
 
 COMMENT: Script Captura datos de Citrix mediante Odata v3, salida en XML
 
 ============================================================================================== #>
Param (
	[string]$ComputerName,
	[string]$DomainName,
	[string]$UserAccount,
	[string]$Password
)
#region ===CREDENTIAL CITRIX DIRECTOR
$UserWithDomain = $DomainName + '\' + $UserAccount
$pwd = ConvertTo-SecureString $Password -AsPlainText -Force
$cred = New-Object Management.Automation.PSCredential ($UserWithDomain, $pwd)
#endregion
#region ===VALIDATION
if (!($ComputerName))
{
	return @"
<prtg>
  <error>1</error>
  <text>Required parameter not specified: please provide target hostname (or %host)</text>
</prtg>
"@
}
#endregion
#region ===FUNCIONES
function Print
{
	param
	(
		$Servicio
	)
	If ($Servicio.State -eq "Running")
	{
		$val = 1
	}	else	{
		$val = 0
	}
	$output += @"
    <result>
        <channel>Servicio: $($servicio.name)</channel>
        <value>$($val)</value>
		<Unit>Custom</Unit>
		<ValueLookup>prtg.standardlookups.wmi.service.staterunningok</ValueLookup>
		<ShowChart>0</ShowChart>
    </result>

"@
	return $output
}
#endregion
#region ===Servicios
$Servicios = Get-WmiObject -Class win32_service -computer $ComputerName -Namespace "root\cimv2" -Credential $cred| where name -like "Citrix*"
#endregion
#region ===XML
<# ======================================XML HEAD============================================== #>
$output = @"
<?xml version=`"1.0`" encoding=`"UTF-8`" ?>
<prtg>

"@
<# ======================================XML BODY============================================== #>
foreach ($servicio in $Servicios)
{
	$output += Print $servicio
}
<# ====================================XML FOOT============================================== #>
$output += @"
    <text>OK</text>
</prtg>
"@
#endregion
<# ====================================XML OUTPUT============================================== #>
$output

El ejemplo de los datos enviados al PRTG seran los siguientes

<prtg>
    <result>
        <channel>Servicio: CitrixADIdentityService</channel>
        <value>1</value>
		<Unit>Custom</Unit>
		<ValueLookup>prtg.standardlookups.wmi.service.staterunningok</ValueLookup>
		<ShowChart>0</ShowChart>
    </result>
    <result>
        <channel>Servicio: CitrixAnalytics</channel>
        <value>1</value>
		<Unit>Custom</Unit>
		<ValueLookup>prtg.standardlookups.wmi.service.staterunningok</ValueLookup>
		<ShowChart>0</ShowChart>
    </result>
    <result>
        <channel>Servicio: CitrixAppLibrary</channel>
        <value>1</value>
		<Unit>Custom</Unit>
		<ValueLookup>prtg.standardlookups.wmi.service.staterunningok</ValueLookup>
		<ShowChart>0</ShowChart>
    </result>
    <text>OK</text>
</prtg>
Pantalla PRTG

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *