Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNMP Library Support for New-SensorParameters discovery #69

Closed
JustinGrote opened this issue Apr 4, 2019 · 14 comments
Closed

SNMP Library Support for New-SensorParameters discovery #69

JustinGrote opened this issue Apr 4, 2019 · 14 comments
Labels
enhancement Items that are on the todo list for incorporating into PrtgAPI in a future release

Comments

@JustinGrote
Copy link

With the current PRTG version, Fiddler shows that a special syntax is required to get the dynamic parameters of SNMP Libraries.

https://myserver/controls/addsensor2.htm?id=8322&sensortype=snmplibrary_nolist&preselection_snmplibrary_nolist=ads.Talari.oidlib

(Note the preselection_snmplibrary_nolist)
Currently I don't see a way to specify the preselection parameter in the current PRTGAPI

Here's a simple proof of concept using httpClient in Powershell (couldn't get Invoke-Restmethod to work due to the additional unremovable headres it adds) for getting the raw HTML containing the table values.

$deviceId = 8322
$baseaddress = 'https://myprtgserver'
$sensorType = 'snmplibrary_nolist'
$snmpLibraryName = 'ads.Talari.oidlib'
$username = 'myusername'
$passhash = '1133mypasshash445566'



#Couldn't get this to work with Invoke-Restmethod on PS5.1, dropping down to HTTPClient
$httpclient = [net.http.httpclient]::new()
$httpclient.baseaddress = $baseaddress
$requestUri = "controls/addsensor2.htm?id=$deviceID&sensortype=$sensorType&preselection_snmplibrary_nolist=$snmpLibraryName&username=$username&passhash=$passhash"
$addSensorResult = $httpclient.GetStringAsync($requestUri).Result

if ($addsensorResult -match 'name="tempid" value="(\d+)"') {
    $tmpid = $matches[1]
} else {
    throw "There was a problem with addsensor2 step"
}

do {
    sleep 0.5
    $targetUrl = ($httpclient.GetStringAsync("api/getaddsensorprogress.htm?id=$deviceID&tmpid=$tmpid").Result | ConvertFrom-Json).targeturl
} while (-not $targetUrl)

#Here's the HTML with the table to parse for the possible values to select
$httpclient.GetStringAsync($targetUrl).result

Example Table Entry

        <tr class=" notconnected  even">
            <td class="checkboxholder"><input type="checkbox" class="hidden validateme checkbox data-table"
                    data-rule-requiredtablecheckbox="true" class="checkbox validateme  notconnectedAll"
                    name="interfacenumber__check" id="interfacenumber_-20"
                    value="1.3.6.1.4.1.34086.2.2.16.2.1.4.2|TALARI-MIB|Wan Link  13: CAN-COMCAST1|State|#|0|0|State|2|1|0|1|The current operational state of the conduit.|0|0|0|0|oid.talari-mib.tnstatswanlink.tnstatswanlinkstate|1.3.6.1.4.1.34086.2.2.16.2.1.4|tnStatsWANLinkState|1.3.6.1.4.1.34086.2.2.16.2.1||ASN_INTEGER|0|ASN_INTEGER||TALARI-MIB|tn statswanlink: #[1.3.6.1.4.1.34086.2.2.16.2.1.1]|tn statswanlink state|||||||||||||||||||||||||||||||||||"><label
                    for="interfacenumber_-20"><i class="icon-dark prtg-checkbox"></i></label></td>
            <td title="">TALARI-MIB</td>
            <td title="">Wan Link 13: CAN-COMCAST1</td>
            <td title="">State</td>
        </tr>

Implementation Proposal

Lots of different ways this could be done, @lordmilko I invite feedback if you've done any existing work on this and have any plans, otherwise I will write a Powershell function that will parse the table with HTMLAgilityPack, and produce a SensorParameters that can be passed to add-sensor and make it available as a Gist or something. The list of OIDLIB files is in /api/sensortypes.json so I would make it query that for an autocompleter.

@lordmilko lordmilko added the enhancement Items that are on the todo list for incorporating into PrtgAPI in a future release label Apr 4, 2019
@lordmilko
Copy link
Owner

lordmilko commented Apr 4, 2019

Hi @JustinGrote,

As noted on the wiki, PrtgAPI does not currently support retrieving sensor targets or dynamic sensor parameters for sensors that you require you to enter some information before PRTG will load the sensor creation page. SNMP Library sensors fall into this category, and as such can only be created by creating a set of custom parameters.

I have had a thought about this previously and believe this external interface for this feature can be implemented by allowing the user to specify a list or dictionary or something to GetSensorTargets / GetDynamicSensorParameters. In the PowerShell interface this would presumably be achieved via parameter accepting a hashtable or something. These query parameters would then be passed to BeginAddSensorQueryParameters, where they would be added as a set CustomParameter objects

While implementing the external user interface is fairly straight forward to do, what is not clear is how to implement a system to tell you what query parameters should be specified when you fail to enter them properly. Is that even possible? What is the page that is opened to select a SNMP Library when you go to to add the sensor? How does PRTG know that page needs to be opened? What requests are made? These questions will require a bit of investigating to determine the best way to implement the feature.

My current priority is getting .NET Core/.NET Standard support shipped, I will add this issue to the roadmap to hopefully tackle after .NET Core support is implemented

Regards,
lordmilko

@JustinGrote
Copy link
Author

JustinGrote commented Apr 4, 2019 via email

@JustinGrote
Copy link
Author

JustinGrote commented Apr 5, 2019

Here's the rough proof of concept, requires my PowerHTML module (on the gallery) as well
https://gist.github.com/JustinGrote/d39ce1c1f398aa53354fdbc0b46b3049

Examples on my system (some custom sensors visible)

~> Get-PRTGSNMPLibraryOIDLibs
ads.Adtran.oidlib
ads.BGP.Peers.oidlib
ads.EIGRP.Peers.oidlib
ads.MIB2.basicinfo.oidlib
ads.Talari.oidlib
APC UPS.oidlib
APCSensorstationlib.oidlib
Basic Linux Library (UCD-SNMP-MIB).oidlib
cisco-interfaces.oidlib
cisco-queue.oidlib
Dell Storage Management.oidlib
Dell Systems Management Instrumentation.oidlib
HP Laserjet Status.oidlib
Linux SNMP (AX BGP DisMan EtherLike Host).oidlib
Linux SNMP (Framework Proxy Noti v2).oidlib
Linux SNMP (IP Net SNMP Noti OSPF RMON SMUX).oidlib
Linux SNMP (Source TCP UCD UDP).oidlib
Paessler Common OID Library.oidlib
SNMP Informant Std.oidlib

Tab Completion works on the second parameter here.
``` powershell
~\desktop> Get-PRTGSnmpLibraryTargets (get-device Test-SDW*) ads.Talari.oidlib

OIDName                                                         TargetValue
-------                                                         -----------
TALARI-MIBConduit 458795: NORTHCHASE_DR-CANDLER-GAJitter        1.3.6.1.4.1.34086.2.2.17.2.1.12.2|TALARI-MIB|Conduit 458795: NORTHCHASE_DR-CANDLER-GA|Jitter|ms|0|0|Jitter|2|1|0|1|The current best jitter value (in...
TALARI-MIBConduit 458795: NORTHCHASE_DR-CANDLER-GABytes Dropped 1.3.6.1.4.1.34086.2.2.17.2.1.9.2|TALARI-MIB|Conduit 458795: NORTHCHASE_DR-CANDLER-GA|Bytes Dropped|Bytes|0|1|Bytes Dropped|0|1|0|1|The count of byte...
TALARI-MIBConduit 458795: NORTHCHASE_DR-CANDLER-GABytes In      1.3.6.1.4.1.34086.2.2.17.2.1.7.2|TALARI-MIB|Conduit 458795: NORTHCHASE_DR-CANDLER-GA|Bytes In|Bytes|0|1|Bytes In|0|1|0|1|The count of bytes received...
TALARI-MIBConduit 458795: NORTHCHASE_DR-CANDLER-GASent          1.3.6.1.4.1.34086.2.2.17.2.1.5.2|TALARI-MIB|Conduit 458795: NORTHCHASE_DR-CANDLER-GA|Sent|Bytes|0|1|Sent|0|1|0|1|The count of bytes sent for this Co...
TALARI-MIBConduit 458795: NORTHCHASE_DR-CANDLER-GAState         1.3.6.1.4.1.34086.2.2.17.2.1.4.2|TALARI-MIB|Conduit 458795: NORTHCHASE_DR-CANDLER-GA|State|#|0|0|State|2|1|0|1|The current operational state of the ...
TALARI-MIBConduit 458795: NORTHCHASE_DR-CANDLER-GAID            1.3.6.1.4.1.34086.2.2.17.2.1.2.2|TALARI-MIB|Conduit 458795: NORTHCHASE_DR-CANDLER-GA|ID|#|0|0|ID|2|1|0|1|The unique Talari ID for the Conduit.|0|0|0...
TALARI-MIBConduit 7: INTERNAP-COLO-CANDLER-GAJitter             1.3.6.1.4.1.34086.2.2.17.2.1.12.1|TALARI-MIB|Conduit 7: INTERNAP-COLO-CANDLER-GA|Jitter|ms|0|0|Jitter|2|1|0|1|The current best jitter value (in mill...
TALARI-MIBConduit 7: INTERNAP-COLO-CANDLER-GABytes Dropped      1.3.6.1.4.1.34086.2.2.17.2.1.9.1|TALARI-MIB|Conduit 7: INTERNAP-COLO-CANDLER-GA|Bytes Dropped|Bytes|0|1|Bytes Dropped|0|1|0|1|The count of bytes dro...
TALARI-MIBConduit 7: INTERNAP-COLO-CANDLER-GABytes In           1.3.6.1.4.1.34086.2.2.17.2.1.7.1|TALARI-MIB|Conduit 7: INTERNAP-COLO-CANDLER-GA|Bytes In|Bytes|0|1|Bytes In|0|1|0|1|The count of bytes received for ...
TALARI-MIBConduit 7: INTERNAP-COLO-CANDLER-GASent               1.3.6.1.4.1.34086.2.2.17.2.1.5.1|TALARI-MIB|Conduit 7: INTERNAP-COLO-CANDLER-GA|Sent|Bytes|0|1|Sent|0|1|0|1|The count of bytes sent for this Conduit...
TALARI-MIBConduit 7: INTERNAP-COLO-CANDLER-GAState              1.3.6.1.4.1.34086.2.2.17.2.1.4.1|TALARI-MIB|Conduit 7: INTERNAP-COLO-CANDLER-GA|State|#|0|0|State|2|1|0|1|The current operational state of the condu...
TALARI-MIBConduit 7: INTERNAP-COLO-CANDLER-GAID                 1.3.6.1.4.1.34086.2.2.17.2.1.2.1|TALARI-MIB|Conduit 7: INTERNAP-COLO-CANDLER-GA|ID|#|0|0|ID|2|1|0|1|The unique Talari ID for the Conduit.|0|0|0|0||1...
TALARI-MIBWan Link  12: CAN-CENTURYLINK1Bytes Dropped           1.3.6.1.4.1.34086.2.2.16.2.1.9.1|TALARI-MIB|Wan Link  12: CAN-CENTURYLINK1|Bytes Dropped|Bytes|0|1|Bytes Dropped|0|1|0|1|The count of bytes dropped ...
TALARI-MIBWan Link  12: CAN-CENTURYLINK1Bytes In                1.3.6.1.4.1.34086.2.2.16.2.1.7.1|TALARI-MIB|Wan Link  12: CAN-CENTURYLINK1|Bytes In|Bytes|0|1|Bytes In|0|1|0|1|The count of bytes received for this ...
TALARI-MIBWan Link  12: CAN-CENTURYLINK1Bytes Out               1.3.6.1.4.1.34086.2.2.16.2.1.5.1|TALARI-MIB|Wan Link  12: CAN-CENTURYLINK1|Bytes Out|Bytes|0|1|Bytes Out|0|1|0|1|The count of bytes sent for this WA...
TALARI-MIBWan Link  12: CAN-CENTURYLINK1State                   1.3.6.1.4.1.34086.2.2.16.2.1.4.1|TALARI-MIB|Wan Link  12: CAN-CENTURYLINK1|State|#|0|0|State|2|1|0|1|The current operational state of the conduit.|0...
TALARI-MIBWan Link  12: CAN-CENTURYLINK1ID                      1.3.6.1.4.1.34086.2.2.16.2.1.2.1|TALARI-MIB|Wan Link  12: CAN-CENTURYLINK1|ID|#|0|0|ID|2|1|0|1|The unique Talari ID for the WAN Link.|0|0|0|0||1.3.6...
TALARI-MIBWan Link  13: CAN-COMCAST1Bytes Dropped               1.3.6.1.4.1.34086.2.2.16.2.1.9.2|TALARI-MIB|Wan Link  13: CAN-COMCAST1|Bytes Dropped|Bytes|0|1|Bytes Dropped|0|1|0|1|The count of bytes dropped for ...
TALARI-MIBWan Link  13: CAN-COMCAST1Bytes In                    1.3.6.1.4.1.34086.2.2.16.2.1.7.2|TALARI-MIB|Wan Link  13: CAN-COMCAST1|Bytes In|Bytes|0|1|Bytes In|0|1|0|1|The count of bytes received for this WAN ...
TALARI-MIBWan Link  13: CAN-COMCAST1Bytes Out                   1.3.6.1.4.1.34086.2.2.16.2.1.5.2|TALARI-MIB|Wan Link  13: CAN-COMCAST1|Bytes Out|Bytes|0|1|Bytes Out|0|1|0|1|The count of bytes sent for this WAN Li...
TALARI-MIBWan Link  13: CAN-COMCAST1State                       1.3.6.1.4.1.34086.2.2.16.2.1.4.2|TALARI-MIB|Wan Link  13: CAN-COMCAST1|State|#|0|0|State|2|1|0|1|The current operational state of the conduit.|0|0|0...
TALARI-MIBWan Link  13: CAN-COMCAST1ID                          1.3.6.1.4.1.34086.2.2.16.2.1.2.2|TALARI-MIB|Wan Link  13: CAN-COMCAST1|ID|#|0|0|ID|2|1|0|1|The unique Talari ID for the WAN Link.|0|0|0|0||1.3.6.1.4...

Bringing it all together (Autodiscover Talari MIB on systems and only onboard the WAN Links, not the Conduits)

$device = (get-device -id 8322)
$targets = Get-PRTGSNMPLibraryTargets -device $device -OIDLibName 'ads.Talari.oidlib' | where oidname -match 'MIBWan'
$sensorParameters = New-SensorParameters -RawType snmplibrary -device $device
Add-PrtgSnmpLibrarySensor $targets $device $sensorParameters

Result: Only WAN Link Sensors Onboarded. Could have also manipulated the sensor parameters to change priority, etc.
image

Contributes

  • Get-PRTGSNMPLibraryTargets cmdlet that autocompletes with the list of available oidlibs on the server, and then you can use that along with a sensorparameters

  • Add-PRTGSNMPLibrarySensor cmdlet that takes the library targets and the standard snmplibrary New-Sensorparameters output and adds it. I used [httpclient] for this one because one of the parameters repeatsand invoke-restmethod doesn't support that.

Quirks Learned

  • tmpid is optional for the creation, so is the session cookie, it can be done effectively stateless
  • both the webgui and windows client use a multipart form to submit the adddsensor5.htm, but a GET query works just as well
  • you have to use name and not name_ for this creation, so I couldn't use Add-Sensor because the sensorparameters requires name_ and that causes it to fail. Maybe add a switch option for Add-Sensor for compatability?

Is there any way to get at the httpclient that the PRTGClient uses? Maybe expose it as a public property?

EDIT: Bonus Script to auto-rename the created SNMP tables to something nicer

if (-not (Get-PRTGClient)) {throw "You must be connected to a PRTG Server First"}

$snmpTableNameRegex = '^Table\((.+)\): .+}$'
$sensors = Get-Sensor -Filter (New-SearchFilter type eq snmpcustomtable) | where name -match $snmpTableNameRegex

foreach ($sensorItem in $sensors) {
    $newSensorName = $sensorItem.name -replace $snmpTableNameRegex,'$1'
    write-host -fore green "$($sensorItem.Device): Renaming $($sensorItem.Name) to $newSensorName"
    $sensorItem | Rename-Object $newSensorName
}

@lordmilko
Copy link
Owner

Thanks @JustinGrote,

I'm not sure what the rules are like in the current version of PRTG and/or for SNMP Library sensors, however generally speaking the tmpid and cookie are definitely not optional. In my experience, failure to maintain the correct state when performing sensor creation queries will result in PRTG responding that a session is no longer valid. This is definitely true of sensors that take a long time to query; if you don't identify your session, how will PRTG know what progress percentage your request is up to? The only page that is stateless is the page that actually creates the sensor, addsensor5.htm

I can see you're right - SNMP Library sensors do appear to utilize a parameter called name, not name_. I'll need to figure out an appropriate way to implement this in a way that works for both dynamic sensor parameters and raw parameters.

PrtgAPI currently supports the api/sensortypes.json endpoint through the Get-SensorType cmdlet. Currently however it only deserializes the bare minimum of properties. From a quick check I can see that calling this page is the technique PRTG uses itself, so I will need to expand the properties of the SensorTypeDescriptor type.

The fact PrtgAPI uses a HttpClient is an implementation detail. My HttpClient doesn't really do anything that yours doesn't do. The only part of PrtgAPI that even knows a HttpClient is the class the implements the IWebClient interface. If PrtgAPI's existing extension mechanisms (supporting "raw" values, etc) do not support a given feature, users can either invoke the request directly via Invoke-WebRequest, etc as a one off, or modify the PrtgAPI source code specifically for their use case.

I can see that the complexity of implementing this feature is quickly blowing up; I'm glad I made the decision to put a pin in this for now! :P

Regards,
lordmilko

@JustinGrote
Copy link
Author

JustinGrote commented Apr 5, 2019 via email

@lordmilko
Copy link
Owner

lordmilko commented Apr 28, 2019

Hi @JustinGrote,

I am currently doing some research into the implementation of this feature.

Are you able to advise whether you are aware of any other sensor types that give initial prompts in the PRTG UI prior to taking you to the normal sensor creation page?

So far, I am aware of the following types

SensorType Stage Content Mandatory
snmplibrary Before addsensor2.htm Preselection Yes
oracletablespace Before addsensor3.htm Partial query No

Depending on the types of information you can get away with not specifying during the requests leading up to the normal sensor creation page, this will determine how simple or complicated the API for this will have to be

Regards,
lordmilko

@JustinGrote
Copy link
Author

JustinGrote commented Apr 29, 2019 via email

lordmilko added a commit that referenced this issue May 6, 2019
…roperties on NewObjectParameters (#69)

-DynamicSensorParameters will automatically override the names of any properties based on properties contained in the PRTG response
lordmilko added a commit that referenced this issue May 6, 2019
…rying sensor targets and retrieving dynamic sensor parameters (#69)

-Sensor query targets can now be retrieved from GetSensorTypes / Get-SensorType
-Sensor query targets can be specified as SensorQueryTarget objects or as sensor query target parameter objects, representing a set of parameters required to retrieve the data required to create the specified sensor (such as IPMI authentication details, OAuth tokens, etc)
@lordmilko
Copy link
Owner

Hi @JustinGrote,

Please be advised that PrtgAPI 0.9.7 has now been released, which includes fixes for these issues

To update to the latest version, run

Update-Module PrtgAPI

and reopen PowerShell. Please see the release notes for a list of breaking changes that may affect you.

PrtgAPI 0.9.7 introduces the concept of sensor query targets, which unlike sensor targets, merely specify the target that a query should apply to (such as the oidlib to use for an SNMP Library, the details of a database server or the authentication details to use for a niche sensor type). For more information on sensor query targets, please see the wiki.

In your case, you should now be able to create a sensor for the oidlib ads.Talari.oidlib via the following code

$device = Get-Device -Id 8322
$params = $device | New-SensorParameters -RawType snmplibrary -qt "ads.Talari.oidlib"
$device | Add-Sensor $params

Attempting to query dynamic sensor parameters or sensor targets of a sensor type that requires some type of sensor query target will now generate an InvalidOperationException, specifying the possible values that can be specified.

SensorTypeDescriptor objects returned from Get-SensorType now include a QueryTargets property that can be used to retrieve SensorQueryTarget objects, however generally it is a lot simpler to specify a wildcard value to the new -QueryTarget parameter.

For sensor types that require multiple values be specified, you can do so using the new -QueryParameter property

$params = $device | New-SensorParameters -RawType ipmisensor -qp @{
    username = "admin"
    password = "password"
}

For sensor types that require custom parameter names be used for common parameters defined under NewSensorParameters / NewObjectParameters PrtgAPI now allows you to override these parameter names with something different. For more information, see the wiki. Note however that when retrieving DynamicSensorParameters, PrtgAPI will now automatically apply any required name overrides for you when it detects a typed dynamic parameter name is different from the name it would use by default.

Thanks for raising this issue!

Regards,
lordmilko

@JustinGrote
Copy link
Author

@lordmilko I apologize I got pulled off to another priority and didn't get to test this.

Initially the parameter discovery works great and I get all the relevant OIDs for the SNMPLibrary

$sensorparameters = new-sensorparameters -RawType snmplibrary -QueryTarget 'ads.Talari.oidlib' -device (get-device -id 8322) -verbose
$sensorparameters.targets.interfacenumber__check
Value                             Properties                                                                                                 Name
-----                             ----------                                                                                                 ----
1.3.6.1.4.1.34086.2.2.17.2.1.12.2 {1.3.6.1.4.1.34086.2.2.17.2.1.12.2, TALARI-MIB, Conduit 458795: NORTHCHASE_DR-CANDLER-GA, Jitter…}         TALARI-MIB    
1.3.6.1.4.1.34086.2.2.17.2.1.9.2  {1.3.6.1.4.1.34086.2.2.17.2.1.9.2, TALARI-MIB, Conduit 458795: NORTHCHASE_DR-CANDLER-GA, Traffic Dropped…} TALARI-MIB
1.3.6.1.4.1.34086.2.2.17.2.1.7.2  {1.3.6.1.4.1.34086.2.2.17.2.1.7.2, TALARI-MIB, Conduit 458795: NORTHCHASE_DR-CANDLER-GA, Traffic In…}      TALARI-MIB
1.3.6.1.4.1.34086.2.2.17.2.1.5.2  {1.3.6.1.4.1.34086.2.2.17.2.1.5.2, TALARI-MIB, Conduit 458795: NORTHCHASE_DR-CANDLER-GA, Traffic Out…}     TALARI-MIB
1.3.6.1.4.1.34086.2.2.17.2.1.4.2  {1.3.6.1.4.1.34086.2.2.17.2.1.4.2, TALARI-MIB, Conduit 458795: NORTHCHASE_DR-CANDLER-GA, State…}           TALARI-MIB
1.3.6.1.4.1.34086.2.2.17.2.1.2.2  {1.3.6.1.4.1.34086.2.2.17.2.1.2.2, TALARI-MIB, Conduit 458795: NORTHCHASE_DR-CANDLER-GA, ID…}              TALARI-MIB
1.3.6.1.4.1.34086.2.2.17.2.1.12.1 {1.3.6.1.4.1.34086.2.2.17.2.1.12.1, TALARI-MIB, Conduit 7: INTERNAP-COLO-CANDLER-GA, Jitter…}              TALARI-MIB    
1.3.6.1.4.1.34086.2.2.17.2.1.9.1  {1.3.6.1.4.1.34086.2.2.17.2.1.9.1, TALARI-MIB, Conduit 7: INTERNAP-COLO-CANDLER-GA, Traffic Dropped…}      TALARI-MIB    
1.3.6.1.4.1.34086.2.2.17.2.1.7.1  {1.3.6.1.4.1.34086.2.2.17.2.1.7.1, TALARI-MIB, Conduit 7: INTERNAP-COLO-CANDLER-GA, Traffic In…}           TALARI-MIB    
1.3.6.1.4.1.34086.2.2.17.2.1.5.1  {1.3.6.1.4.1.34086.2.2.17.2.1.5.1, TALARI-MIB, Conduit 7: INTERNAP-COLO-CANDLER-GA, Traffic Out…}          TALARI-MIB
1.3.6.1.4.1.34086.2.2.17.2.1.4.1  {1.3.6.1.4.1.34086.2.2.17.2.1.4.1, TALARI-MIB, Conduit 7: INTERNAP-COLO-CANDLER-GA, State…}                TALARI-MIB
1.3.6.1.4.1.34086.2.2.17.2.1.2.1  {1.3.6.1.4.1.34086.2.2.17.2.1.2.1, TALARI-MIB, Conduit 7: INTERNAP-COLO-CANDLER-GA, ID…}                   TALARI-MIB    
1.3.6.1.4.1.34086.2.2.16.2.1.9.1  {1.3.6.1.4.1.34086.2.2.16.2.1.9.1, TALARI-MIB, Wan Link  12: CAN-CENTURYLINK1, Traffic Dropped…}           TALARI-MIB    
1.3.6.1.4.1.34086.2.2.16.2.1.7.1  {1.3.6.1.4.1.34086.2.2.16.2.1.7.1, TALARI-MIB, Wan Link  12: CAN-CENTURYLINK1, Traffic In…}                TALARI-MIB    
1.3.6.1.4.1.34086.2.2.16.2.1.5.1  {1.3.6.1.4.1.34086.2.2.16.2.1.5.1, TALARI-MIB, Wan Link  12: CAN-CENTURYLINK1, Traffic Out…}               TALARI-MIB
1.3.6.1.4.1.34086.2.2.16.2.1.4.1  {1.3.6.1.4.1.34086.2.2.16.2.1.4.1, TALARI-MIB, Wan Link  12: CAN-CENTURYLINK1, State…}                     TALARI-MIB    
1.3.6.1.4.1.34086.2.2.16.2.1.2.1  {1.3.6.1.4.1.34086.2.2.16.2.1.2.1, TALARI-MIB, Wan Link  12: CAN-CENTURYLINK1, ID…}                        TALARI-MIB    
1.3.6.1.4.1.34086.2.2.16.2.1.9.2  {1.3.6.1.4.1.34086.2.2.16.2.1.9.2, TALARI-MIB, Wan Link  13: CAN-COMCAST1, Traffic Dropped…}               TALARI-MIB    
1.3.6.1.4.1.34086.2.2.16.2.1.7.2  {1.3.6.1.4.1.34086.2.2.16.2.1.7.2, TALARI-MIB, Wan Link  13: CAN-COMCAST1, Traffic In…}                    TALARI-MIB
1.3.6.1.4.1.34086.2.2.16.2.1.5.2  {1.3.6.1.4.1.34086.2.2.16.2.1.5.2, TALARI-MIB, Wan Link  13: CAN-COMCAST1, Traffic Out…}                   TALARI-MIB    
1.3.6.1.4.1.34086.2.2.16.2.1.4.2  {1.3.6.1.4.1.34086.2.2.16.2.1.4.2, TALARI-MIB, Wan Link  13: CAN-COMCAST1, State…}                         TALARI-MIB    
1.3.6.1.4.1.34086.2.2.16.2.1.2.2  {1.3.6.1.4.1.34086.2.2.16.2.1.2.2, TALARI-MIB, Wan Link  13: CAN-COMCAST1, ID…}                            TALARI-MIB

However, in attempting to create the sensor itself, it only creates the first channel of the first sensor. What is expected is to create 4 interface sensors with individual channels each (22 channels total) as my powershell above and the GUI do. I tried creating it in this fashion:
get-device -id 8322 | add-sensor -parameters $sensorparameters

Let me know if the syntax is correct or if I need to go about it otherwise. I also would assume if I filtered the targets property and only wanted to create a couple of the OIDs, that it would work as expected if I edited that property.

@lordmilko
Copy link
Owner

Hi @JustinGrote,

By default only the first sensor target is selected. Therefore you need to add -Target * to your call to New-SensorParameters (or filter the list above manually yourself before assigning it)

Regards,
lordmilko

@JustinGrote
Copy link
Author

@lordmilko
So the -Target appears to be a string filter on the name property of the GenericSensorTarget objects that are returned. The problem is that, in the case of SNMP library, they are all the same.

new-sensorparameters -rawtype snmplibrary -device $device -querytarget 'ads.talari.oidlib' -target '*' | % interfacenumber__check | select name,value

Name       Value
----       -----
TALARI-MIB 1.3.6.1.4.1.34086.2.2.17.2.1.12.2
TALARI-MIB 1.3.6.1.4.1.34086.2.2.17.2.1.9.2
TALARI-MIB 1.3.6.1.4.1.34086.2.2.17.2.1.7.2
TALARI-MIB 1.3.6.1.4.1.34086.2.2.17.2.1.5.2
TALARI-MIB 1.3.6.1.4.1.34086.2.2.17.2.1.4.2
TALARI-MIB 1.3.6.1.4.1.34086.2.2.17.2.1.2.2
TALARI-MIB 1.3.6.1.4.1.34086.2.2.17.2.1.12.1
TALARI-MIB 1.3.6.1.4.1.34086.2.2.17.2.1.9.1
TALARI-MIB 1.3.6.1.4.1.34086.2.2.17.2.1.7.1
TALARI-MIB 1.3.6.1.4.1.34086.2.2.17.2.1.5.1
TALARI-MIB 1.3.6.1.4.1.34086.2.2.17.2.1.4.1
TALARI-MIB 1.3.6.1.4.1.34086.2.2.17.2.1.2.1
TALARI-MIB 1.3.6.1.4.1.34086.2.2.16.2.1.9.1
TALARI-MIB 1.3.6.1.4.1.34086.2.2.16.2.1.7.1
TALARI-MIB 1.3.6.1.4.1.34086.2.2.16.2.1.5.1
TALARI-MIB 1.3.6.1.4.1.34086.2.2.16.2.1.4.1
TALARI-MIB 1.3.6.1.4.1.34086.2.2.16.2.1.2.1
TALARI-MIB 1.3.6.1.4.1.34086.2.2.16.2.1.9.2
TALARI-MIB 1.3.6.1.4.1.34086.2.2.16.2.1.7.2
TALARI-MIB 1.3.6.1.4.1.34086.2.2.16.2.1.5.2
TALARI-MIB 1.3.6.1.4.1.34086.2.2.16.2.1.4.2
TALARI-MIB 1.3.6.1.4.1.34086.2.2.16.2.1.2.2

So the target parameter is useless in this scenario and should allow for a richer evaluation.

I was able to get it to work by unlocking the returned object and filtering out the unwanted targets, but obviously unlocking is an "off the reservation activity"

$sp = new-sensorparameters -rawtype snmplibrary -device $device -querytarget 'ads.talari.oidlib' -target '*'
$sp.unlock()
$sp.interfacenumber__check = $sp.interfacenumber__check.where{$PSItem.properties[2] -notmatch 'Centurylink'}

@lordmilko
Copy link
Owner

As per the wiki, you can either filter by -Target or filter the targets directly yourself once the parameters have been returned

# Untested but more or less correct
$params = new-sensorparameters -rawtype snmplibrary -device $device -querytarget 'ads.talari.oidlib'
$params.interfacenumber__check = $params.Targets.interfacenumber__check | where { $_.properties[2] -notmatch 'Centurylink' }

@lordmilko
Copy link
Owner

In regards to your query (now deleted?) the DynamicSensorParameters type constructs itself by

  1. Instantiating its parameters using their default values, and then
  2. Constructing a dictionary of values that appear to be suitable as sensor targets

As a result of this, any property that does represent a sensor target will only have the first sensor target in the list. While I can think of a number of scenarios where selecting all targets by default would be useful (WMI Volumes, VMware Datastores, Exchange Databases, etc) there are other scenarios where it wouldn't be (WMI Services - you sure don't want a sensor for all 200 services on your system!)

Bottom line, for now I have decided not to go the additional step of selecting all of the targets by default, and have left it up to users to specify what they want. If you really do want to select all targets, it's not that hard to add -Target * to your call to New-SensorParamters`.

In your case however, you don't want to specify -Target * you should simply filter the targets via the Targets property of the parameters object after the object has been created

@JustinGrote
Copy link
Author

JustinGrote commented Jul 9, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Items that are on the todo list for incorporating into PrtgAPI in a future release
Projects
None yet
Development

No branches or pull requests

2 participants