PRTG provides versatile monitoring, from Server health to application API. today we will use powershell to monitor the API health.
Below are the configurations in the PRTG sensor:
- Host IP: 10.34.50.56
- URL: https:///stationery.webapi/Account/LogOn’
- Postdata: {‘username’: ‘xxxx‘,’password’:’xxxx‘,’merchantNumber’:xxxx}
- Content Type: Custom
- Custom content type: application/json
insert the Host IP after the second slash in the URL , you find the complet url: https://10.34.50.56/stationery.webapi/Account/LogOn
To find out the “Response Must Include” area, run bellow powershell command (Postdata is used in the body area):
##below ignore the ssl cert trust isue:
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
## below pass the JSON data to the url, and get the response.
invoke-webrequest -Uri 'https://10.34.50.56/stationery.webapi/Account/LogOn' -Method Post -ContentType "application/json" -Body "{'username': 'xxxx','password':'xxxx','merchantID':xxxx}"
I found some code like:
Content: {"data":{"user":{"countrycode":0, "Reload":31, "rolename":"Stationery Shop","username":xxxx,........ AllElements: .... RawContent : HTTP/1.1 200 OK Pragma: no-cache,no-cache Content-Length:1195 {"data":{"user":{"countrycode":0, "Reload":31, "rolename":"Stationery Shop","username":xxxx,........ "merchantID":"1234567890123"
now I change the password to a wrong one on purpose,which is 12345, and try to get some other response just for comparison purpose:
invoke-webrequest -Uri 'https://10.34.50.56/stationery.webapi/Account/LogOn' -Method Post -ContentType "application/json" -Body "{'username': 'xxxx','password':'12345','merchantID':xxxx}"
now the response become:
Server Error We're sorry, but an unexpected error occurred on the server. .....
So I will just pick a piece of data, such as merchantID from the first response and use it as the evidence of working API.
Response Must Include: 1234567890123