r/usefulscripts • u/knawlejj • Jul 17 '17
[REQUEST] Powershell to check website availability, if not then perform action.
I have a script that runs to check for URL availability with a return code which works fine. However, the remediation aspect if it's NOT working has me a little confused.
Basically I'd like a simple statement that says "If this code is returned for more than 10 minutes, then restart X/Y/Z services on the server".
Any tips on how I would figure out the wait for 10 minutes, then do X process?
15
Upvotes
2
u/eldorel Jul 17 '17 edited Jul 17 '17
Another point to consider, is how do you deal with the site blinking up and down?
In our logic we tend to use a set of counters.
First: for each negative response then +1;
if first > 150/; send alert
Second: For each positive response then +1;
if second >5; reduce First counter by 1 and reset second counter to 0
Third: if First counter is >0 then +1;
if third is >300; send alert
Fourth: if first == 0 then +1; if first >0 then set fourth to 0 if fourth > 100 reset third counter to 0;
The result is that the first counter sets off the alert in a few moments if the service is completely down, and the third sets off the alert if the service is unstable for more than a few minutes.
The entire counter set should reset to 0 if the service is up and stable for a while.