Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #require --version 4.0
- <#
- ___ ___ _____ ___
- | _ \ _ \_ _/ __|
- | _/ / | || (_ |
- |_| |_|_\ |_| \___|
- #>
- [string]$prtg_server = "enter-your-server-address";
- [string]$prtg_protoc = "http-or-https";
- [int]$prtg_port = 80;
- [string]$prtg_user = "your-prtg-user";
- [string]$prtg_pass = "your-prtg-users-passhash";
- [string]$max_downtime= 59
- [string]$find_msg = "Timeout. No packets received";
- [string]$find_status = 5;
- [string]$pause_message = "There was a connection problem and the port might have been occupied. Pausing until port is free again."
- <# this will test if the prtg server could be accessed. the sensor will be down otherwise #>
- function This-CheckPrtgAccess(){
- $options = @($prtg_protoc, $prtg_server, $prtg_port,$prtg_user,$prtg_pass);
- $prtg_uri = [string]::Format("{0}://{1}:{2}/home?username={3}&passhash={4}",$options);
- $Session = (Invoke-Webrequest -Uri $prtg_uri -UseBasicParsing -SessionVariable PRTG);
- if($Session.StatusCode -ne 200){
- write-host "0:Authentication against PRTG failed."; This-Quit 2
- }
- }
- <# this will pause the sensor for 1 minute #>
- function This-PauseSensor([int]$sensor_id, [string]$message, [int]$duration){
- $options = @($prtg_protoc, $prtg_server, $prtg_port, $sensor_id, $message, $duration, $prtg_user, $prtg_pass);
- [string]$prtg_uri = [string]::Format("{0}://{1}:{2}/api/pauseobjectfor.htm?id={3}&pausemsg={4}&duration={5}&username={6}&passhash={7}", $options);
- $Result = (Invoke-Webrequest -Uri $prtg_uri -UseBasicParsing -SessionVariable $PRTG);
- }
- <# this will find all QoS sensors that are down, have a certain message and are down for longer than x seconds #>
- function This-FindTroubledQoSSensors([string]$current_message = $find_msg, [int]$current_state = $find_status){
- $options = @($prtg_protoc, $prtg_server, $prtg_port, $current_state, $current_message, $prtg_user, $prtg_pass);
- [string]$prtg_uri = [string]::Format("{0}://{1}:{2}/api/table.json?content=sensors&output=json&columns=objid,name,sensor,message,downtimesince,type&filter_status={3}&filter_message=@sub({4})&filter_sensor=@sub(QoS)&username={5}&passhash={6}", $options);
- $troubled_sensors = ((Invoke-Webrequest -Uri $prtg_uri -UseBasicParsing -SessionVariable $PRTG) | ConvertFrom-Json)
- #write-host $prtg_uri;
- return $troubled_sensors.Sensors;
- }
- function This-CheckSensors(){
- $sensors = This-FindTroubledQoSSensors;
- foreach($sensor in $sensors){
- if($sensor.downtimesince_raw -gt $max_downtime){
- This-PauseSensor -sensor_id $sensor.objid -message $pause_message -duration 5
- }
- }
- Write-Host "0:QoS Health check running...";
- }
- function This-Quit([int]$exitCode){
- if(!($verbose)){ exit $exitCode }
- }
- This-CheckPrtgAccess;
- This-CheckSensors;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement