New Question
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Download >>


What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more


Top Tags

View all Tags

Maintenance mode scripts



Your Vote:




I don't know where to post it, and it's not a question, but I wanted to share this with the community: I have been looking for an automated way to pause/put into maintenance mode all our servers.
I don't want to lookup the id for every machine and create an individual file. Since I couldn't find a 'howto' on the net, I have created 2 scripts myself. 1 for Linux & 1 for windows. Am I not a developer/scripter, so the code will be ugly and there will probably be a better way to do stuff, but, here it is:

! Before you can start with either script, you'll need a DEDICATED service account with password set to never expires, make sure this account has permissions to put machines in maintenance mode. Log in with this account, go to the account properties and click "show passhash".

The scripts work as follows:
It connects to the PRTG server to download the list of machines (FQDN based!!!)+ IDs. It then compares the hostname to the name in the file. It then does a webcall to that ID.

LINUX: (bash script, so save as .sh and execute at shutdown)

# Script that can automatically pause the sensors on PRTG for xx minutes with reboot
# variables
######setup details, access related.

#auth is retrieved from the logged in user - should be a service account, because hash changes when password changes
#duration of pause
if [ ! -d "/scripts" ]; then
	mkdir /scripts
if [ ! -d  "/scripts/prtg" ]; then
	mkdir /scripts/prtg
if [ ! -d  $localdir ]; then
	mkdir $localdir
#Retrieve list of devices
wget --no-check-certificate -O ${localdir}/devices.csv ${PRTGUrl}

#Retrieve FQDN
while read LINE
done < /proc/sys/kernel/hostname
typeset -l fqdn
shopt -s nocasematch # set environment case insesitive
# Read csv into array
read -d '' -r -a lines < ${localdir}/devices.csv
for i in "${lines[@]}"
	IFS=', ' read -ra linearray <<< "$i"
	typeset -l arrayvalue
	#remove quotes from value
	newarray=$(echo $arrayvalue|sed 's/\"//g'|tee)
	#echo "$fqdn - $newarray"
	if [[ $newarray == $fqdn ]]; then
		#echo "$newarray - IN IF LOOP"
		serverID=$(echo ${linearray[0]}|sed 's/\"//g'|tee) 
		#remove quotes from value
		echo "Server ${linearray[2]} found with ID $serverID"
		echo $PauseURL
		# Put machine in pause
		wget --no-check-certificate -O ${localdir}/pausedir.html $PauseURL 

WINDOWS: (powershell - so add a .bat file next to it to launch the script, configure with GPO)

$DebugPreference = "SilentlyContinue"

######ignore invalid SSL Certs##########
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
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

######setup details, access related.
$auth = "username=SERVICEACCOUNT&passhash=1111111111"
$PRTGHost = "prtg.fqdn.dom"
$durationinminutes = "10"

$PRTGUrl = "http://$PRTGHost/api/table.xml?content=devices&output=csvtable&columns=objid,host&count=2500&$auth"
$RETRIEVECSV =Invoke-WebRequest -Uri $PRTGUrl -MaximumRedirection 0 -ErrorAction Ignore

#Invoke-WebRequest -Uri $PRTGUrl -MaximumRedirection 0 -ErrorAction Ignore

$WebClient = New-Object System.Net.WebClient

$CSVFile = Import-Csv -Path $PRTGCSV

$myIPs = @()
# Get IP for lookup
$myIPs += Get-NetIPAddress -AddressFamily IPv4 | where { $_.InterfaceAlias -notmatch 'Loopback'} |Select IPAddress
# Get FQDN for lookup
$t = "" | select ipaddress 
$t.ipaddress = (Get-WmiObject win32_computersystem).DNSHostName+"."+(Get-WmiObject win32_computersystem).Domain
$myIPs += $t
# Get hostname for lookup
$t = "" | select ipaddress 
$t.ipaddress = hostname
$myIPs += $t

ForEach ($Line in $CSVFile){
    #Write-Debug "$($Line.Host)"
    If ($myIPs -contains "$($Line.Host)"){
        $PauseDate = Get-Date -Format yyyyMMdd-HHmm
        Write-Debug "Machine: $($Line.Host) $($Line.ID)"
        $serverID = $($Line.ID)
        $PauseURL = "http://$PRTGHost/api/pauseobjectfor.htm?id=$serverID&duration=$durationinminutes&pausemsg=Automatically%20paused%20for%20server%20reboot%20(10%20minutes%20-%20$PauseDate)&$auth"
        $PauseServer = Invoke-WebRequest -Uri $PauseURL  -ErrorAction Ignore
        Write-Debug $PauseURL

Hopefully this helps you guys out :)

Have a nice day

pause prtg script

Created on Feb 8, 2019 11:03:35 AM by  bitnoise (0) 1

Last change on Feb 8, 2019 11:59:26 AM by  Dariusz Gorka [Paessler Support]

1 Reply



Your Vote:



Hi there,

I just added some formatting to your topic, in case you want to format it further, check this guide:

However thanks for the contribution! Hope it helps some other users as well.

Best regards.

Created on Feb 8, 2019 12:00:24 PM by  Dariusz Gorka [Paessler Support]

Please log in or register to enter your reply.

Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.