lordmilko / PrtgAPI

C#/PowerShell interface for PRTG Network Monitor
MIT License
305 stars 38 forks source link

Trying add sensors are getting following error #244

Closed marcelo-0511 closed 3 years ago

marcelo-0511 commented 3 years ago

Describe the bug

When I am trying add sensors i am getting following errors:

WARNING: 'Add-Sensor' timed out: The underlying connection was closed: The connection was closed unexpectedly. Retries remaining: 1
Add-Sensor : The underlying connection was closed: The connection was closed unexpectedly.
At C:\Users\adm.msantos\Desktop\01-Adicionar_SDWAN_FortiOS6.4.ps1:102 char:22
+ Get-Device -Id $ID | Add-Sensor $sdwan_state ; Start-Sleep -Seconds 1 ...
+                      ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Sensor], WebException
    + FullyQualifiedErrorId : System.Net.WebException,PrtgAPI.PowerShell.Cmdlets.AddSensor

image

image

Steps to reproduce

When I tried to add sensor.

What is the output of 'Get-PrtgClient -Diagnostic'?

Version    : 18.1.38.11958
RetryCount : 1
RetryDelay : 3
LogLevel   : Trace, Request

PSVersion      : 5.1.17763.1971
PSEdition      : Desktop
OS             : Microsoft Windows Server 2019 Standard
PrtgAPIVersion : 0.9.16
Culture        : en-US
CLRVersion     : .NET Framework 4.7.2 (461814)
PrtgVersion    : 18.1.38.11958
PrtgLanguage   : brazilian.lng

Additional context

No response

lordmilko commented 3 years ago

Hi @marcelo-0511,

The implication here is there's something wrong with your sensor parameters.

Can you do

$sdwan_state

and provide the output?

Furthermore, if you add the -Verbose parameter to your invocation of Add-Sensor, are you able to provide the output? Please be sure to redact any sensitive information

marcelo-0511 commented 3 years ago

There is below the output:

image

lordmilko commented 3 years ago

Hi @marcelo-0511,

Can you also provide the -Verbose log output as mentioned above?

In additon, what happens if you simply target a single specific interface? (change -Target * to something more specific)

Are you able to add snmplibrary sensors for other OIDLIBs?

marcelo-0511 commented 3 years ago

Yes, there are print screens below: sdwan_01 sdwan_02 sdwan_03

Yes, I am able to add sensors.

I will try to do with a especific interface.

marcelo-0511 commented 3 years ago

I have an important thing to say, this script worked before in this device and now it worked to another device, the difference between the devices are the quantity os sensors(more in device that is not working yet).

lordmilko commented 3 years ago

Hi @marcelo-0511,

Based on this information this appears to be a duplicate of #80; as such, in order to work around this for now you will need to split this into several API calls, with each API call only specifying a few interfaces.

You can easily do this by "chunking" the interfaces you'd like to add up into several smaller groups (the following code has not been tested but should more or less work)

$device = Get-Device -Id $id

# Get your parameters as normal
$params = $device | New-SensorParameters -rt snmplibrary -qt sdwan_state.oidlib -DynamicType

# Now chunk the interface targets up into groups of 4
# Taken from https://stackoverflow.com/questions/13888253/powershell-break-a-long-array-into-a-array-of-array-with-length-of-n-in-one-line

$counter = [pscustomobject] @{ Value = 0 }
$groupSize = 4

$groups = $params.Targets.interface__check | Group-Object -Property { [math]::Floor($counter.Value++ / $groupSize) }

# Now add the sensors to your device, 4 interfaces at a time

foreach($group in $groups)
{
    $params.interface__check = $group.Group

    $device | Add-Sensor $params
}

Regards, lordmilko