Powershell/NRPE/Check_iis8_app_pool_state.ps1
2023-07-04 12:59:44 +02:00

70 lines
1.5 KiB
PowerShell

<#
Ester Niclos Ferreras
OK UP
WARNING
CRITICAL Stopped
UNKNOWN not found
#>
#
# Shell arguments
#
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$ApplicationPool
)
$bReturnOK = $TRUE
$bReturnCritical = $FALSE
$bReturnWarning = $FALSE
$returnStateOK = 0
$returnStateWarning = 1
$returnStateCritical = 2
$returnStateUnknown = 3
$DataTexte = ""
$strCritical = ""
$strWarning = ""
[System.Reflection.Assembly]::LoadFrom( "C:\windows\system32\inetsrv\Microsoft.Web.Administration.dll" ) > $null
$servermanager = [Microsoft.Web.Administration.ServerManager]::OpenRemote("localhost")
$apppools = $servermanager.ApplicationPools["$ApplicationPool"]
$iis = Get-ItemProperty HKLM:\SOFTWARE\Microsoft\InetStp\ | select setupstring
# Nagios output
$resultstring='IISPOOL UNKNOWN ' + $ApplicationPool + ' ' + $status +' ; ' + $iis.SETUPSTRING + ' '
$exit_code = $UNKNOWN
If ($apppools -ne $null) {
$status = $apppools.state
If ($status -eq 'Started') {
$str = 'OK '+ $ApplicationPool + ' ' + $status +' ; ' + $iis.SETUPSTRING + ' '
}
Else {
$strCritica = 'CRITICAL '+ $ApplicationPool + ' ' + $status +' ; ' + $iis.SETUPSTRING + ' '
$bReturnCritical = $TRUE
}
}
If ($bReturnCritical) {
write-output $strCritica "|" $DataTexte
exit $returnStateCritical
}
Elseif ($bReturnWarning) {
write-output $strWarning "|" $DataTexte
exit $returnStateWarning
}
Else {
write-output $str "|" $DataTexte
exit $returnStateOK
}