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

Set a threshold trigger notification based on the number of alarms related to a group

Votes:

0

Hi, I have a problem with notification/alert settings. l have a group that contains different groups/devices. I need to send a notification when number of alarms is bigger than (for example) 10. I don't care about single device down, I need to be notified when a number of sensor greater than "x" is down.

Is it possible with PRTG? Thanks Paolo

alert group notification prtg

Created on Dec 27, 2021 2:40:51 PM



Best Answer

Accepted Answer

Votes:

1

Hello Paolo,

You can use the following template to execute the API call and return the value in PRTG. However, please note that we don't provide support for it.

param(
    [string] $hostname = "", # PRTG IP/DNS
    [string] $username = "", # PRTG Account
    [string] $passhash = "", # Account passhash
    [string] $groupid = "" # Group ID for the API call
)

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::TLS12
 
 
function Skip-SSLCertificates{
    $Provider = New-Object Microsoft.CSharp.CSharpCodeProvider
    $Compiler = $Provider.CreateCompiler()
    $Params = New-Object System.CodeDom.Compiler.CompilerParameters
    $Params.GenerateExecutable = $false
    $Params.GenerateInMemory = $true
    $Params.IncludeDebugInformation = $false
    $Params.ReferencedAssemblies.Add("System.DLL") > $null
    $TASource=@'
        namespace Local.ToolkitExtensions.Net.CertificatePolicy
        {
            public class TrustAll : System.Net.ICertificatePolicy
            {
                public bool CheckValidationResult(System.Net.ServicePoint sp,System.Security.Cryptography.X509Certificates.X509Certificate cert, System.Net.WebRequest req, int problem)
                {
                    return true;
                }
            }
        }
'@ 
    $TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)
    $TAAssembly=$TAResults.CompiledAssembly
    ## We create an instance of TrustAll and attach it to the ServicePointManager
    $TrustAll = $TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")
    [System.Net.ServicePointManager]::CertificatePolicy = $TrustAll
}
 
function Invoke-Request {
	Param(
		$baseurl = $script:hostname,
		$user = $script:username,
		$passh = $script:passhash,
		$groupid = $script:groupid
	)

	$url = "https://$baseurl/api/table.json?content=sensors&output=json&columns=objid,sensor,status&id=$groupid&username=$user&passhash=$passh"
	Invoke-RestMethod $url -Method Get
}
 
try {
	
    Skip-SSLCertificates

    # Get number of sensors with Down state
    $count = ((Invoke-Request).sensors | where {$_.status_raw -eq "5"}).count
    
    Write-Output "$($count):Message"
    Exit 0

} catch {
    Write-Output "0:$($_.exception.message) At line : $($_.InvocationInfo.ScriptLineNumber)"
    Exit 1
}

Regards.

Created on Jan 10, 2022 6:53:14 AM by  Florian Lesage [Paessler Support]



3 Replies

Votes:

1

Hello Paolo,

Thank you for your message.

Regarding what you would like to achieve, you need to use a custom script with the EXE/Script sensor which will get the number of down sensors from that group. Then, you can configure the threshold trigger to this sensor.

To get that information, you can use the following API call to get a list of the sensors which belong to that group and then count the ones in down state:

https://PRTGServer/api/table.json?content=sensors&output=json&columns=objid,sensor,status&id=GROUPID&username=PRTGUser&passhash=Passhash

Note that the script must return the data in a specific format depending on the custom sensor used, which is described here: https://www.paessler.com/manuals/prtg/custom_sensors

If you have questions, do not hesitate.

Regards.

Created on Dec 28, 2021 7:13:46 AM by  Florian Lesage [Paessler Support]

Last change on Dec 28, 2021 7:14:24 AM by  Florian Lesage [Paessler Support]



Votes:

0

Thanks @Florian, I found the API call, is there some EXE/Script sensor already tested (where I can use my string) without write it down by myself?
thanks

Regards

Created on Jan 7, 2022 4:09:20 PM



Accepted Answer

Votes:

1

Hello Paolo,

You can use the following template to execute the API call and return the value in PRTG. However, please note that we don't provide support for it.

param(
    [string] $hostname = "", # PRTG IP/DNS
    [string] $username = "", # PRTG Account
    [string] $passhash = "", # Account passhash
    [string] $groupid = "" # Group ID for the API call
)

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::TLS12
 
 
function Skip-SSLCertificates{
    $Provider = New-Object Microsoft.CSharp.CSharpCodeProvider
    $Compiler = $Provider.CreateCompiler()
    $Params = New-Object System.CodeDom.Compiler.CompilerParameters
    $Params.GenerateExecutable = $false
    $Params.GenerateInMemory = $true
    $Params.IncludeDebugInformation = $false
    $Params.ReferencedAssemblies.Add("System.DLL") > $null
    $TASource=@'
        namespace Local.ToolkitExtensions.Net.CertificatePolicy
        {
            public class TrustAll : System.Net.ICertificatePolicy
            {
                public bool CheckValidationResult(System.Net.ServicePoint sp,System.Security.Cryptography.X509Certificates.X509Certificate cert, System.Net.WebRequest req, int problem)
                {
                    return true;
                }
            }
        }
'@ 
    $TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)
    $TAAssembly=$TAResults.CompiledAssembly
    ## We create an instance of TrustAll and attach it to the ServicePointManager
    $TrustAll = $TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")
    [System.Net.ServicePointManager]::CertificatePolicy = $TrustAll
}
 
function Invoke-Request {
	Param(
		$baseurl = $script:hostname,
		$user = $script:username,
		$passh = $script:passhash,
		$groupid = $script:groupid
	)

	$url = "https://$baseurl/api/table.json?content=sensors&output=json&columns=objid,sensor,status&id=$groupid&username=$user&passhash=$passh"
	Invoke-RestMethod $url -Method Get
}
 
try {
	
    Skip-SSLCertificates

    # Get number of sensors with Down state
    $count = ((Invoke-Request).sensors | where {$_.status_raw -eq "5"}).count
    
    Write-Output "$($count):Message"
    Exit 0

} catch {
    Write-Output "0:$($_.exception.message) At line : $($_.InvocationInfo.ScriptLineNumber)"
    Exit 1
}

Regards.

Created on Jan 10, 2022 6:53:14 AM by  Florian Lesage [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.