Item: url.statuscode[{#DESCRIPTION}] Trigger: {Template App IIS - Site Checks:url.statuscode[{#DESCRIPTION}].last()}<>{#RESPONSE}
Last active
December 16, 2016 14:40
-
-
Save Sam-Martin/08d8572164a1b8ee7ba43a13804773e5 to your computer and use it in GitHub Desktop.
Zabbix Website Checks Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[Parameter(Position=0)] | |
$Description, | |
[Parameter(Position=1)] | |
$ConfigFile = "C:\zabbix\scripts\production.iis.checks.json" | |
) | |
$Config = Get-Content $ConfigFile | Out-String | ConvertFrom-Json | |
$Check = $config.data | ?{$_."{#DESCRIPTION}" -eq $Description} | |
if($Check.count){ | |
Write-Error $("There are {0} matching entries for this description in {1}" -f $Check.count, $ConfigFile) | |
break; | |
} | |
# Identify HTTP/HTTPS | |
$Scheme = "HTTP" | |
if($Check."{#SCHEME}"){ | |
$Scheme = $Check."{#SCHEME}" | |
} | |
# Force check of this website on the local server, irrespective of the DNS resolution | |
if($Check.'{#CHECK_LOCALHOST}'){ | |
$hostname = "localhost"; | |
}else{ | |
$hostname = $Check.'{#HOST}' | |
} | |
# Prep HTTP request | |
$URL = "{0}://{1}{2}" -f $Scheme, $hostname ,$check.'{#PATH}' | |
$request = [System.Net.WebRequest]::Create($URL) | |
# Force check of this website on the local server, irrespective of the DNS resolution | |
if($Check.'{#CHECK_LOCALHOST}'){ | |
Write-Verbose $("Using Host header: {0}" -f $Check.'{#HOST}') | |
$request.Host = $Check.'{#HOST}' | |
} | |
# Bypass Proxy | |
$request.Proxy = New-Object System.Net.WebProxy | |
# Ignore SSL errors | |
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} | |
# Don't follow redirects | |
$request.AllowAutoRedirect = $false | |
if($Check."{#USER}"){ | |
Write-Verbose "Using Basic Auth" | |
$BasicAuth = "{0}:{1}" -f $Check."{#USER}",$Check."{#PASS}" | |
$Bytes = [System.Text.Encoding]::Unicode.GetBytes($BasicAuth) | |
$BasicAuthEncoded =[Convert]::ToBase64String($Bytes) | |
$request.Headers["Authorization"] = $BasicAuthEncoded | |
} | |
Write-Verbose "Fetching $URL" | |
try { | |
$res = $request.GetResponse() | |
} catch [System.Net.WebException] { | |
$res = $_.Exception.Response | |
Write-Verbose $_.Exception.Message -ErrorAction SilentlyContinue | |
} | |
$StatusCode = [int]$res.StatusCode | |
if($StatusCode){ | |
if($StatusCode -eq $Check."{#RESPONSE}"){ | |
Write-Verbose "The check is returning as expected!" | |
} | |
$StatusCode | |
}else{ | |
"0" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"data": [ | |
{ | |
"{#HOST}": "www.example.com", | |
"{#PATH}": "/", | |
"{#USER}": "username", | |
"{#PASS}": "P@ssW0rd!", | |
"{#DESCRIPTION}": "Checking Example.com logs in!", | |
"{#RESPONSE}": "200", | |
"{#CHECK_LOCALHOST}": true | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UserParameter=generic.discoverfile[*], powershell -NoProfile -Command "&{try{cat C:\zabbix\scripts\$1 -erroraction stop}catch{'{"""data""":[]}'}}" | |
UserParameter=url.statuscode[*],powershell -NoProfile -ExecutionPolicy Bypass -File "C:\zabbix\scripts\get_iis_site_status_code.ps1" "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment