lordmilko / PrtgAPI

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

add-sensor of type snmpcustomtable fails #122

Closed terrassen closed 4 years ago

terrassen commented 4 years ago

Hello lordmilko I upgraded to prtgapi 0.9.10 and I am now facing the error message "Add-sensor : Invalid URI: The Uri string is too long."

The new-sensorparamers command is able to detect all 63 interfaces

$SensorParams = Get-Device -id $DeviceId | New-SensorParameters -RawType snmpcustomtable -QueryParameters @{'tableoid_' = '1.3.6.1.4.1.2011.6.139.13.3.3'}

$SensorParams.Targets.snmptable__check.count
63

so that means: Bug 119/121 is fixed.

$SensorParams.snmptable__check    = $SensorParams.targets.snmptable__check
$SensorParams.columns__check      = $SensorParams.targets.columns__check
$SensorParams.channel1name        = 'State'
$SensorParams.channel1column      = '1.3.6.1.4.1.2011.6.139.13.3.3.1.6'
$SensorParams.identcolumn         = '1.3.6.1.4.1.2011.6.139.13.3.3.1.4'
$SensorParams.Name                = '[rowidentifier]'
$SensorParams.channel1unit        = 'ValueLookup'
$SensorParams.channel1valuelookup = 'oid.huawei-wlan-ap-mib.hwwlanap.hwwlanaprunstate'
$SensorParams.channel1unit        = 'ValueLookup'

$SensorParams | Add-Sensor
Add-Sensor : Invalid URI: The Uri string is too long.
At line:1 char:17
+ $SensorParams | Add-Sensor
+                 ~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Sensor], UriFormatException
    + FullyQualifiedErrorId : System.UriFormatException,PrtgAPI.PowerShell.Cmdlets.AddSensor

uri_too_long.txt

What is the output of Get-PrtgClient -Diagnostic?

PS C:\install\prtg> get-prtgclient -Diagnostic

PSVersion      : 5.1.14393.3053
PSEdition      : Desktop
OS             : Microsoft Windows Server 2016 Standard
PrtgAPIVersion : 0.9.10
Culture        : de-CH
CLRVersion     : .NET Framework 4.8 (528049)
PrtgVersion    : 19.4.53.1912
PrtgLanguage   : english.lng

Attaching the verbose output as a textfile.

lordmilko commented 4 years ago

Hi @terrassen,

This is a known issue currently being tracked by #80. PRTG internally uses POST + cookies for most requests, so it can execute queries as long as it likes. PrtgAPI uses GET authentication in most places, which does not work when combined with POST. As such, you can sometimes run into issues when executing queries that construct massive URLs (as is the case here)

The workaround for this is simply to split your request up into multiple sub-requests. In your case, instead of adding all 63 in one request, do half or maybe a third in each request

$SensorParams = Get-Device -id $DeviceId | New-SensorParameters -RawType snmpcustomtable -QueryParameters @{'tableoid_' = '1.3.6.1.4.1.2011.6.139.13.3.3'}

$bigList = $SensorParams.Targets

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

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

foreach($group in $groups)
{
    $SensorParams.Targets = $group.Group
    $SensorParams | Add-Sensor
}

Please let me know how you go. As this issue is a duplicate, I will close this issue

terrassen commented 4 years ago

Thanks lordmilko

I am able to create the sensor now by creating groups with a maximum of 5 targets per group. Thanks and regards Guido

[cid:itp_oria_4bd656f6-d1dd-4962-93a0-bdf17e4690bc.jpg] Guido Weber Senior Systems Engineer

ITpoint Systems AG | Riedstrasse 1 | CH-6343 Rotkreuz D: +41 41 798 80 34 | M: +41 79 208 64 53 guido.weber@itpoint.ch

www.itpoint.chhttp://www.itpoint.ch | www.oria.chhttp://www.oria.ch | LinkedInhttps://www.linkedin.com/company/itpoint-systems-ag/ | Xinghttps://www.xing.com/companies/itpointsystemsag | Twitterhttps://twitter.com/ITpointAG | Facebookhttps://www.facebook.com/ITpointSystemsAG

Trusted IT for Business

Von: lordmilko notifications@github.com Gesendet: Donnerstag, 5. Dezember 2019 12:41 An: lordmilko/PrtgAPI PrtgAPI@noreply.github.com Cc: Guido Weber guido.weber@itpoint.ch; Mention mention@noreply.github.com Betreff: Re: [lordmilko/PrtgAPI] add-sensor of type snmpcustomtable fails (#122)

Hi @terrassenhttps://github.com/terrassen,

This is a known issue currently being tracked by #80https://github.com/lordmilko/PrtgAPI/issues/80. PRTG internally uses POST + cookies for most requests, so it can execute queries as long as it likes. PrtgAPI uses GET authentication in most places, which does not work when combined with POST. As such, you can sometimes run into issues when executing queries that construct massive URLs (as is the case here)

The workaround for this is simply to split your request up into multiple sub-requests. In your case, instead of adding all 63 in one request, do half or maybe a third in each request

$SensorParams = Get-Device -id $DeviceId | New-SensorParameters -RawType snmpcustomtable -QueryParameters @{'tableoid_' = '1.3.6.1.4.1.2011.6.139.13.3.3'}

$bigList = $SensorParams.Targets

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

$groupSize = 20

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

foreach($group in $groups)

{

$SensorParams.Targets = $group.Group

$SensorParams | Add-Sensor

}

Please let me know how you do. As this issue is a duplicate, I will close this issue

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/lordmilko/PrtgAPI/issues/122?email_source=notifications&email_token=AEWINCBEEJDC6J2WMEMQ6J3QXDSDJA5CNFSM4JVYEYBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGAN5CY#issuecomment-562093707, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEWINCFRF6GMJYOFWNY7MIDQXDSDJANCNFSM4JVYEYBA.