What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Is there a way to monitor the notifications of PRTG (active/paused/deleted)?

Votes:

0

Hey there,

Sometimes important notifications (Setup | Account Settings | Notifications) get paused or deleted, which is why we no longer receive any notifications.
Is there a way to monitor certain notifications for their status, for example via a sensor?

Best regards!

custom custom-sensor important notifications powershell prtg script

Created on Feb 7, 2018 9:44:21 AM by  Dariusz Gorka [Paessler Support]

Last change on Apr 8, 2024 9:21:44 AM by  Yasodhara Das [Paessler Support]



1 Reply

Accepted Answer

Votes:

1

This article applies to PRTG Network Monitor 17 or later

Monitor the Status of a Notification within PRTG (Active/Paused/Deleted)

If you want to monitor the status of a notification added to PRTG (Setup | Account Settings | Notifications), then use the following PowerShell (.ps1) script. This script basically

  • Queries the settings of a certain notification
  • Checks via RegEx if the Status is set to Active or Paused
  • Searches for the notification ID and displays a corresponding error message if the ID cannot be found (for example, if the notification was deleted)

Requirements

  • A locally (within PRTG) created user with access to the notifications
  • Set the Execution Policy of PowerShell to at least RemoteSigned.

Important Notice

Please use the script at your own risk! Additionally, note that we officially cannot support this script so any Support-Case regarding this ticket will most likely be disregarded.


How to Use the Script

  • Save the script as a .ps1 file in the \Custom Sensors\EXEXML\ subdirectory of the PRTG program directory on the probe machine from where you want to check the access point.
#    ____  ____  ____________
#   / __ \/ __ \/_  __/ ____/
#  / /_/ / /_/ / / / / / __  
# / ____/ _, _/ / / / /_/ /  
#/_/   /_/ |_| /_/  \____/                         
#    NETWORK MONITOR
#-------------------
#(c) 2018 Dariusz Gorka, Paessler AG
#
# This script checks if a certain notification within PRTG is paused,active or deleted.
#

# Parameter "-username" - Username from within PRTG (User that can access Notification-Settings)
# Parameter "-passhash" - The Passhash of the User ("Show Passhash" in the User Settings Page)
# Parameter "-prtghost" - The URL for PRTG !!! Please without an ending "/" !!!
# Parameter "-notifid" - The ID of the notification - displayed in the URL of the Notification
# copy paste for the Parameters field in PRTG:
# -username "MyUser" -passhash "12345678910" -prtghost "http(s)://PRTGServer" -notifid "300"
#

param(
    [string] $username = "prtgadmin",
    [string] $passhash = "1278894095",
    [string] $prtghost = "http://server",
    [String] $notifid = "4085"
)

# Check URL
$prtgserverlength = $prtghost.Length - 1
$prtgserverlastch = $prtghost.Substring($prtgserverlength)
if ($prtgserverlastch -eq "/"){
$prtghost = $prtghost.Substring(0,$prtghost.Length - 1)
} 

# Check connectivity
$conerror = 0
try{
        $conurl = [String]::Format("{0}/api/status.json?username={1}&passhash={2}",$prtghost,$username,$passhash)
        Invoke-WebRequest -Uri $conurl -UseBasicParsing | Out-Null
    } catch {
        $conerror = 1
}


if ($conerror -eq 0) {

    # Check if Notification is there
    $notification_site_url = ([String]::Format("{0}/controls/editnotification.htm?id={1}&username={2}&passhash={3}",$prtghost,$notifid,$username,$passhash))
    $notification_site = Invoke-WebRequest -uri $notification_site_url -UseBasicParsing

    $notif_id_found = $notification_site -match '<div\s+class="errormsg">'

    if (!$notif_id_found) {

    $notif_result = $notification_site -match 'name="active_"\s+value="1"\s+checked\s+id="active1"'

    if ($notif_result) {
        $notification_site -match '(name="name_"\s+id="name_"\s+autocomplete="off"\s+value=")(.*)("\s+><\/div>)' | Out-Null
        $notification_name = $Matches[2]
        
        Write-Host @"
        <PRTG>
            <result>
                <channel>Notification</channel>
                <value>1</value>
                <showChart>1</showChart>
                <showTable>1</showTable>
                <Float>1</Float>
                <unit>CustomUnit</unit>
                <customunit>Active</customunit>
                <mode>Absolute</mode>
                <LimitMode>1</LimitMode>
                <LimitMinError>1</LimitMinError>
            </result>
            <text>
                The Notification '$($notification_name)' is active!
            </text>
        </PRTG>
"@

    } else {
        $notification_site -match '(name="name_"\s+id="name_"\s+autocomplete="off"\s+value=")(.*)("\s+><\/div>)' | Out-Null
        $notification_name = $Matches[2]

        Write-Host @"
        <PRTG>
            <result>
                <channel>Notification</channel>
                <value>0</value>
                <showChart>1</showChart>
                <showTable>1</showTable>
                <Float>1</Float>
                <unit>CustomUnit</unit>
                <customunit>Active</customunit>
                <mode>Absolute</mode>
                <LimitMode>1</LimitMode>
                <LimitMinError>1</LimitMinError>
            </result>
            <text>
                The Notification '$($notification_name)' is paused!
            </text>
        </PRTG>
"@
    }
} else {
    # Notification not found

    Write-Host @"
    <PRTG>
        <error>1</error>
        <text>
            The Notification-ID '$($notifid)' was not found! Maybe it is deleted?
        </text>
    </PRTG>
"@
}
} else {
    # Connection Error

    Write-Host @"
    <PRTG>
        <error>1</error>
        <text>
            Something went wrong with the connection! Please check the parameters!
        </text>
    </PRTG>
"@
}
  • Add an EXE/Script Advanced sensor.
  • In the sensor settings, select the above script from the dropdown list and provide the following under Parameters:

-username "<USER>" -passhash "<PASSHASH>" -prtghost "<PRTGServer>" -notifid "<ID>"

  • Adjust the <USER>, <PASSHASH>, <PRTGServer> and <ID> parameters like in the examples below, depending on your scenario:
    • <USER>: prtg-api
    • <PASSHASH>: 12345678910 (You can find the passhash under Setup | Account Settings | My Account, section User Account)
    • <PRTGServer>: http://myprtg.com
    • <ID>: 300
  • Click Continue to save your settings.

Check Notification Status

You can now monitor the status of a notification in PRTG.

Created on Feb 7, 2018 9:50:20 AM by  Dariusz Gorka [Paessler Support]

Last change on Apr 8, 2024 9:21:17 AM by  Yasodhara Das [Paessler Support]




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.