Last active
April 24, 2021 22:57
-
-
Save stephanlinke/a145cae16c147e5cab0bed22e47bbf1b to your computer and use it in GitHub Desktop.
[CheckWebLogin] A Script Sensor for PRTG that will allow you to check websites behind a form based login #PRTG #prtgexe
This file contains 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
# ___ ___ _____ ___ | |
#| _ \ _ \_ _/ __| | |
#| _/ / | || (_ | | |
#|_| |_|_\ |_| \___| | |
# NETWORK MONITOR | |
#------------------- | |
# Description: Monitors if a login on a website with a HTML login form works properly | |
# Parameters: | |
# -URL: The URL to the login form | |
# -Username: A valid username for the page | |
# -Password: The user's password | |
# -FormId: The ID of the login form (usually 0) | |
# -UsernameID: The CSS ID of the username field | |
# -PasswordID: The CSS ID of the password field | |
# -CheckString: A string element that only occurs if the login worked | |
# ------------------ | |
# (c) 2015 Stephan Linke | Paessler AG | |
Param( | |
[string]$url = "www.acme.com", | |
[string]$logout = "www.acme.com/logout", | |
[string]$username="<login>", | |
[string]$password="<password>", | |
[int]$formId = 0, | |
[string]$usernameId = "username", | |
[string]$passwordId = "password", | |
[string]$checkString = "Abmelden" | |
) | |
$loginPage = (Invoke-WebRequest -Uri "$url" -SessionVariable PRTG) | |
Start-Sleep 1 | |
$LoginForm = $loginPage.Forms[$formId]; | |
$LoginForm.Fields[$usernameId] = $username; | |
$LoginForm.Fields[$passwordId] = $password; | |
$LoginForm.Fields['body_0_content_0_sectioned_0_SignInButton'] = "Sign In"; | |
$result = (Invoke-WebRequest -Uri ($url) -WebSession $PRTG -Method POST -Body $LoginForm.Fields) | |
if($result.Content.Contains($checkString)) | |
{ | |
Write-Host "0:Login successful - '$($Checkstring)' found."; | |
# Logout | |
Invoke-WebRequest -Uri $logout -SessionVariable PRTG | Out-Null; | |
Remove-Variable PRTG; | |
exit 0; | |
} | |
else | |
{ | |
Write-Host "0:Login failed or checkstring not found. Please check the check if the username/password combination and the checkstring is correct!"; | |
# Logout | |
Invoke-WebRequest -Uri $logout -SessionVariable PRTG | Out-Null; | |
Remove-Variable PRTG; | |
exit 1; | |
}#> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment