lordmilko / PrtgAPI

C#/PowerShell interface for PRTG Network Monitor
MIT License
301 stars 37 forks source link

Unable to create a 'snmpcustomtable' sensor using PowerShell #121

Closed terrassen closed 4 years ago

terrassen commented 4 years ago

I have no problem to manually create 'snmpcustomtable' sensors. However, using PowerShell, I get the error message:

Add-Sensor : Failed to add sensor for sensor type 'snmpcustomtable': type was not valid or you do not have sufficient permissions on the specified object.

Steps to reproduce

$SensorParams = @{'sensortype'            = 'snmpcustomtable' }
                $SensorParams += @{'name_'                = '[rowidentifier]'}
                $SensorParams += @{'tags_'                = 'wac-sensor snmpcustomsensor snmpcustomtable'}
                $SensorParams += @{'nametemplate_'        = ''}
                $SensorParams += @{'priority_'            = 3 }
                $SensorParams += @{'tableoid_'            = '1.3.6.1.4.1.2011.6.139.13.3.3'}
                $SensorParams += @{'snmptable_'           = '1'}
                $SensorParams += @{'identcolumn_'         = '1.3.6.1.4.1.2011.6.139.13.3.3.1.4|1.3.6.1.4.1.2011.6.139.13.3.3.1.4|'}
                $SensorParams += @{'channel1name_'        = 'State'}
                $SensorParams += @{'channel1column_'      = '1.3.6.1.4.1.2011.6.139.13.3.3.1.6|1.3.6.1.4.1.2011.6.139.13.3.3.1.6|'}
                $SensorParams += @{'channel1snmptype_'    = 'abs'}
                $SensorParams += @{'channel1customunit_'  = ''}
                $SensorParams += @{'channel1unit_'        = 'ValueLookup'}
                $SensorParams += @{'channel1valuelookup_' = 'oid.huawei-wlan-ap-mib.hwwlanap.hwwlanaprunstate|oid.huawei-wlan-ap-mib.hwwlanap.hwwlanaprunstate'}
                $SensorParams += @{'snmptable__check'     = '4.159.202.114.155.0|2102355553W0G7000212|AP7110DN-AGN|HGKWAP01040|hgk_hotspot|8|V200R008C10SPC800|Ver.C|P1025|533|H5TQ1G63BFR_H9C|CH|10.1.2.174|255.255.255.0|10.1.2.1|256|32|18738761|0.0.0.0|18738450|AP7110DN-AGN:V200R008C10SPC800|AP7110DN-AGN:Ver.C|Huawei Technologies Co., Ltd.|Huawei Access Point Software|Huawei Technologies Co., Ltd.|000|:::::::|:::::::|:::::::|:::::::|:::::::|15|12|1|666'}
                $SensorParams += @{'columns_'             = 1 }
                $SensorParams += @{'ident'                = '' }
                $SensorParams += @{'columns__check'       = '1.3.6.1.4.1.2011.6.139.13.3.3.1.2|1.3.6.1.4.1.2011.6.139.13.3.3.1.2|'}

$SensorObject = New-SensorParameters $SensorParams
Get-Device -Id 56061 | Add-Sensor $SensorObject

Add-Sensor : Failed to add sensor for sensor type 'snmpcustomtable': type was not valid or you do not have sufficient permissions on the specified object.
At line:1 char:24
+ Get-Device -Id 56061 | Add-Sensor $SensorObject
+                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Sensor], PrtgRequestException
    + FullyQualifiedErrorId : PrtgAPI.PrtgRequestException,PrtgAPI.PowerShell.Cmdlets.AddSensor

Additional context Please note that I have admin rights. I am able to create any other type of sensors using powershell. I do have the impression that the PRTGAPI has a problem with the sensortype "snmpcustomtable". If I use a wrong written sensortype like "snmcustomtabbllee" I get exact the same error message.

Any help is welcome.

lordmilko commented 4 years ago

Hi @terrassen,

I copied and pasted this and was successfully able to create an snmpcustomtable sensor.

Is there any reason you are manually constructing the sensor parameters instead of using DynamicSensorParameters? DynamicSensorParameters are not only easier to use, but also guarantee that all required fields are present and have their correct values

$params = Get-Device -Id 56061 | New-SensorParameters -RawType snmpcustomtable

# Fill out all the required parameter properties

$params | Add-Sensor

Are you able to advise how you go if you try and do this with dynamic parameters instead? (note: you might need to specify the tableoid as a sensor query target

lordmilko commented 4 years ago

I was successfully able to create several snmpcustomtable sensors on a Cisco router by performing the following

# Get the parameters
$params = Get-Device -id 9530 | New-SensorParameters -RawType snmpcustomtable -qp @{tableoid_="1.3.6.1.2.1.2.2"}

# Select all the options. Once you know it works you can select specific ones
$params.snmptable__check = $params.targets.snmptable__check

# Mandatory fields (channel1column will be different in your scenario)
$params.channel1name = "test"
$params.channel1column = $params.targets.channel1column|where name -eq ifType

# Create the sensor
$params | Add-Sensor
terrassen commented 4 years ago

Hello lordmilko Thanks for your quick reply, but still the same problem. Do I need to be at a certain version of PRTGAPI ?

$SensorParams = Get-Device -id 56061 | New-SensorParameters -RawType snmpcustomtable New-SensorParameters : Failed to resolve sensor targets for sensor type 'snmpcustomtable': type was not valid or you do not have sufficient permissions on the specified object. At line:1 char:40

lordmilko commented 4 years ago

You need to be running at least PrtgAPI 0.9.7 to be able to access the -QueryParameters/-qp parameter

Download the latest version by following these instructions, run the included PrtgAPI.cmd file and see how you go. This will prevent overwriting the currently system wide version of PrtgAPI while allowing us to test the newer version

terrassen commented 4 years ago

Upgrading to version 0.9.9 solved my problem, I was on 0.9.6. Thanks One last question: Running $SensorParams = Get-Device -id 56061 | New-SensorParameters -RawType snmpcustomtable -QueryParameters @{'tableoid_' = '1.3.6.1.4.1.2011.6.139.13.3.3'}

and then

$SensorParams.targets.snmptable__check shows me only 3 interfaces, while creating the sensor in the GUI brings me a list of 76 interfaces. What am I doing wrong ?

lordmilko commented 4 years ago

Hi @terrassen,

Can you please type the following commands

cls
Set-PrtgClient -LogLevel Response
$SensorParams = Get-Device -id 56061 | New-SensorParameters -RawType snmpcustomtable -QueryParameters @{'tableoid_' = '1.3.6.1.4.1.2011.6.139.13.3.3'} -Verbose

This will cause PrtgAPI to emit the HTML responses it gets back from PRTG that it uses to extract the list of snmptable__check items

Once this completes, click the PowerShell icon up the top left of your PowerShell window, select Edit -> Select All, and then hit Enter on your keyboard to copy everything to the clipboard.

Finally, open up Notepad or something, paste the text in and search for the text snmptable__check. We want to see how many interfaces are listed in the response. Keep hitting F3 whenever you find a match to cycle through all the search results. You should keep getting results that look like the following

utErrors</th></tr></thead>
<tr class=" notconnected  even"><td class="checkboxholder"><input type="checkbox"  data-rule-required="true"
class="checkbox  notconnectedAll" name="snmptable__check" id="snmptable_-0"

For me, the final result I had had id=snmptable_-18, which corresponds with the total number of sensor targets PrtgAPI showed me

terrassen commented 4 years ago

Hello lordmilko

Thanks for your reply. I am learning with every answer from you.

The PRTG GUI shows me a total of 63 sensor targets (showing here twenty out of them):

[cid:image001.jpg@01D5A5D2.16F68EB0]

The html response shows 63 "snmptable_check" entries, 'snmptable-0' throu 'snmptable_-62'. So here we have a match. However, the $SensorParams.targets value has only three out of the 63 targets:

PS C:\Windows\system32> $SensorParams.targets

Key                  Value
---                  -----
snmptable__check     {2102351KDXW0K1000018, 2102351KDXW0K1000019, 2102351KDXW0K1000215}
columns__check       {, 1.3.6.1.4.1.2011.6.139.13.3.3.1.2, 1.3.6.1.4.1.2011.6.139.13.3.3.1.3, 1.3.6.1.4.1.2011.6.139.13.3.3.1.4...}
identcolumn          {table_index, 1.3.6.1.4.1.2011.6.139.13.3.3.1.2, 1.3.6.1.4.1.2011.6.139.13.3.3.1.3, 1.3.6.1.4.1.2011.6.139.13.3.3.1.4...}
channel1column       {, 1.3.6.1.4.1.2011.6.139.13.3.3.1.3, 1.3.6.1.4.1.2011.6.139.13.3.3.1.4, 1.3.6.1.4.1.2011.6.139.13.3.3.1.5...}
channel1valuelookup  {None, custom_prtg.standardlookups.synology.diskstatus, get-gpo_applocker_citrix_all_ts_status, itp.exchange.contentindexstate...}
channel2column       {, 1.3.6.1.4.1.2011.6.139.13.3.3.1.3, 1.3.6.1.4.1.2011.6.139.13.3.3.1.4, 1.3.6.1.4.1.2011.6.139.13.3.3.1.5...}
channel2valuelookup  {None, custom_prtg.standardlookups.synology.diskstatus, get-gpo_applocker_citrix_all_ts_status, itp.exchange.contentindexstate...}
channel3column       {, 1.3.6.1.4.1.2011.6.139.13.3.3.1.3, 1.3.6.1.4.1.2011.6.139.13.3.3.1.4, 1.3.6.1.4.1.2011.6.139.13.3.3.1.5...}
channel3valuelookup  {None, custom_prtg.standardlookups.synology.diskstatus, get-gpo_applocker_citrix_all_ts_status, itp.exchange.contentindexstate...}
channel4column       {, 1.3.6.1.4.1.2011.6.139.13.3.3.1.3, 1.3.6.1.4.1.2011.6.139.13.3.3.1.4, 1.3.6.1.4.1.2011.6.139.13.3.3.1.5...}
channel4valuelookup  {None, custom_prtg.standardlookups.synology.diskstatus, get-gpo_applocker_citrix_all_ts_status, itp.exchange.contentindexstate...}
channel5column       {, 1.3.6.1.4.1.2011.6.139.13.3.3.1.3, 1.3.6.1.4.1.2011.6.139.13.3.3.1.4, 1.3.6.1.4.1.2011.6.139.13.3.3.1.5...}
channel5valuelookup  {None, custom_prtg.standardlookups.synology.diskstatus, get-gpo_applocker_citrix_all_ts_status, itp.exchange.contentindexstate...}
channel6column       {, 1.3.6.1.4.1.2011.6.139.13.3.3.1.3, 1.3.6.1.4.1.2011.6.139.13.3.3.1.4, 1.3.6.1.4.1.2011.6.139.13.3.3.1.5...}
channel6valuelookup  {None, custom_prtg.standardlookups.synology.diskstatus, get-gpo_applocker_citrix_all_ts_status, itp.exchange.contentindexstate...}
channel7column       {, 1.3.6.1.4.1.2011.6.139.13.3.3.1.3, 1.3.6.1.4.1.2011.6.139.13.3.3.1.4, 1.3.6.1.4.1.2011.6.139.13.3.3.1.5...}
channel7valuelookup  {None, custom_prtg.standardlookups.synology.diskstatus, get-gpo_applocker_citrix_all_ts_status, itp.exchange.contentindexstate...}
channel8column       {, 1.3.6.1.4.1.2011.6.139.13.3.3.1.3, 1.3.6.1.4.1.2011.6.139.13.3.3.1.4, 1.3.6.1.4.1.2011.6.139.13.3.3.1.5...}
channel8valuelookup  {None, custom_prtg.standardlookups.synology.diskstatus, get-gpo_applocker_citrix_all_ts_status, itp.exchange.contentindexstate...}
channel9column       {, 1.3.6.1.4.1.2011.6.139.13.3.3.1.3, 1.3.6.1.4.1.2011.6.139.13.3.3.1.4, 1.3.6.1.4.1.2011.6.139.13.3.3.1.5...}
channel9valuelookup  {None, custom_prtg.standardlookups.synology.diskstatus, get-gpo_applocker_citrix_all_ts_status, itp.exchange.contentindexstate...}
channel10column      {, 1.3.6.1.4.1.2011.6.139.13.3.3.1.3, 1.3.6.1.4.1.2011.6.139.13.3.3.1.4, 1.3.6.1.4.1.2011.6.139.13.3.3.1.5...}
channel10valuelookup {None, custom_prtg.standardlookups.synology.diskstatus, get-gpo_applocker_citrix_all_ts_status, itp.exchange.contentindexstate...}

I have attached the complete html response.

-- REMOVED --

lordmilko commented 4 years ago

Hi @terrassen,

It's possible GitHub limited the text of your reply, as I can see this is not the full response. I have now removed that text from your reply, as that is creating a lot of junk that needs to be scrolled past when navigating this issue. Can you please copy the response into a text file and reply to this issue with it as an attachment?

terrassen commented 4 years ago

Hello lordmilko

The PRTG GUI shows me a total of 63 sensor targets. The html response shows 63 "snmptable_check" entries, 'snmptable-0' throu 'snmptable_-62'. So here we have a match. However, the $SensorParams.targets value has only three out of the 63 targets:

PS C:\Windows\system32> $SensorParams.targets.snmptable__check

Value                Properties                                                             Name                
-----                ----------                                                             ----                
40.65.198.154.38.160 {40.65.198.154.38.160, 2102351KDXW0K1000018, AP7152DN, HGKWAP01059...} 2102351KDXW0K1000018
40.65.198.154.38.192 {40.65.198.154.38.192, 2102351KDXW0K1000019, AP7152DN, HGKWAP01052...} 2102351KDXW0K1000019
40.65.198.154.63.64  {40.65.198.154.63.64, 2102351KDXW0K1000215, AP7152DN, HGKWAP01058...}  2102351KDXW0K1000215

Attached full htmlresponse: htmlresponse.txt

lordmilko commented 4 years ago

Thanks @terrassen,

Based on this information, I am feeling fairly confident that this is in fact a bug that I have already solved for the next release of PrtgAPI. The issue is that PrtgAPI's current HTML parsing logic does not anticipate that <input/> tag values will go over several lines. If you look at the HTML response, you'll see that almost every single snmptable__check value spans several lines, except the three listed above

<!-- Working -->
<input type="checkbox" class="hidden validateme checkbox data-table"  data-rule-requiredtablecheckbox="true" class="checkbox validateme  notconnectedAll" name="snmptable__check" id="snmptable_-25" value="40.65.198.154.63.64|2102351KDXW0K1000215|AP7152DN|HGKWAP01058|hgk_hotspot|1||||-1|||255.255.255.255|255.255.255.255|255.255.255.255|-1|-1|0|255.255.255.255|0|||||||:::::::|:::::::|:::::::|:::::::|:::::::|0|0|1||2|0|00:00:00:00:00:00|0|0|0|0|0|0|0|0|0|0|||||0|0|0|0|0|0|0|0|0|0|1|0|0|58|4294967295|ÿÿÿÿÿÿ||-1|||0|0|4|4||">
<!-- Not Working -->
<input type="checkbox" class="hidden validateme checkbox data-table"  data-rule-requiredtablecheckbox="true" class="checkbox validateme  notconnectedAll" name="snmptable__check" id="snmptable_-24" value="40.65.198.154.59.192|2102351KDXW0K1000187|AP7152DN|HGKWAP01057|hgk_hotspot|8|V200R008C10SPC800|Ver.B|NXP1043|1200|MT47H64M16HR|CH|10.1.2.135|255.255.255.0|10.1.2.1|512|128|12770859|0.0.0.0|12770776|AP7152DN:V200R008C10SPC800|AP7152DN:Ver.B|Huawei Technologies Co., Ltd.|Huawei Access Point Software|Huawei Technologies Co., Ltd.|001|:::::::|:::::::|:::::::|:::::::|:::::::|4|4|1|/$[ArchivesInfo Version]
/$ArchivesInfoVersion=3.0

[Board Properties]
BoardType=AP7152DN
BarCode=2102351KDXW0K1000187
Item=02351KDX
Description=Assembling Components,AP7152DN,AP7152DN,AP7152DN Mainframe(11ac Wave2,Indoor,4X4 Dual-Band,IoT Expansion,External Antenna)
Manufactured=2019-01-10
VendorName=Huawei
IssueNumber=00
CLEICode=
BOM=
Model=AP7152DN
/$ElabelVersion=4.0
|2|1800|(AÆš;À|23|2|0|45|1|0|1|0|17|0|||||2|0|2|36|27090925911|4781330180|73483738498|8633067811|453969978|48795772|1|73483738498|8633067811|57|4294967295|ÿÿÿÿÿÿ||0|||14003139|18828641|2|3||">

The next version of PrtgAPI likely won't be released for at least a few more weeks, however if you absolutely need this resolved right now you can download the PrtgAPI source code, apply the patch and then recompile it yourself. In theory this should be really easy

  1. Open a command prompt and run git clone https://github.com/lordmilko/PrtgAPI
  2. Open the PrtgAPI folder that was downloaded double click the build.cmd file. This will open a PrtgAPI Build Environment PowerShell
  3. Run Invoke-PrtgBuild inside the PrtgAPI Build Environment to confirm you can build PrtgAPI. Any required dependencies should be automatically downloaded
  4. Extract the attached HtmlParser.cs file and replace the existing copy under the src/PrtgAPI/Request folder
  5. Run Invoke-PrtgBuild -Configuration Release inside the PrtgAPI Build Environment

If all goes well, you will have a working copy of PrtgAPI under the PrtgAPI\src\PrtgAPI.PowerShell\bin\Release\net452\PrtgAPI folder. To test it right away, open the PrtgAPI.cmd file inside this folder and see whether you get all 63 sensor targets now

Regards, lordmilko

HtmlParser.zip

terrassen commented 4 years ago

Hello lordmilko Thanks a lot for your information. I can wait a few weeks. Regards

lordmilko commented 4 years ago

Duplicate of #119

lordmilko commented 4 years ago

Hi @terrassen,

Please be advised PrtgAPI 0.9.10 has been released, which includes a fix for this issue. To update to the latest version of PrtgAPI run the command

Update-Module PrtgAPI

and then close and reopen PowerShell.

Regards, lordmilko

terrassen commented 4 years ago

Hello lordmilko

Thanks for your quick a very helpfull support. 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 05:34 An: lordmilko/PrtgAPI PrtgAPI@noreply.github.com Cc: Guido Weber guido.weber@itpoint.ch; Mention mention@noreply.github.com Betreff: Re: [lordmilko/PrtgAPI] Unable to create a 'snmpcustomtable' sensor using PowerShell (#121)

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

Please be advised PrtgAPI 0.9.10 has been released, which includes a fix for this issue. To update to the latest version of PrtgAPI run the command

Update-Module PrtgAPI

and then close and reopen PowerShell.

Regards, lordmilko

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