powershellnetwork-programmingscriptingmonitoringprtg

PowerShell script for PRTG Network Monitor


I am currently working with PRTG, to monitor the interface properties from a Juniper EX4300 switch.

For that, I want to get the "ifDescr" as string, the "ifAlias" as string, the "ifAdminStatus" as integer, the "ifOperStatus" as integer, the "IfInErrors" as integer and the "IfOutErrors" as integer. I want to use the first two string values just the way they are without any alert. The "ifOperStatus" and "IfInErrors" should be converted and triggered, when the value is higher than 1, through a lookup file. The last two values will be triggered with the sensor limiter, when they are above 0. All these values, that have to be up-to-date for the whole time, and the operations should be listed and done in only one sensor for each interface, to keep the view on the important values structured and clear.

During a research I found out that this is not as easy as I thought. The only solution for my needs seems to be a PowerShell based script sensor. Should there be another way, please let me know.

I have no experience in programming PowerShell scripts. So I would be very happy about some help, especially to get the values from the two SNMP table sensors into my PowerShell script.

Best regards,

SAM_N


Solution

  • First part was related to SNMP and lookups - following should help you to achieve that in PRTG: SNMP Custom String Lookup Sensor

    Second part - to combine two values from one (two or more) different sensor(s) you should use PRTG Sensor Factory Sensor - you can do even some calculations on those values if you need to. No programming needed

    Example

    Lets say you have one sensor pulling one value from SNMP - that sensor has ID 100 and your value is being stored into channel 0

    Second sensor with ID 101 is pulling different SNMP value to channel 0

    With PRTG Sensor Factory Sensor you creat new (third) sensor which will have in its Channel definition following:

    #1:SUM_OF_VALUES
    Channel(100,0) + Channel(101,0) 
    

    This means it will add values from both sensors into your newly created channel named "SUM_OF_VALUES". You can


    You can always use PowerShell to pull data from SNMP but PRTG has tools for you to achieve it without programming. If you still want to do it in PowerShell please ask new question with details and I can further help you with PowerShell script

    Let me know if this helps

    EDIT

    This simple script should help you to begin with your sensor - it will collect description and number of errors for listed interfaces in $ifaceNumbers array. This script can be put to EXE directory of PRTG probe (not EXEXML since this doesnt generate XML as output).

    Change interface numbers (from 1 and 12 to your numbers) and change community string and IP and try to run it first manually in Powershell IDE/Powershell

    Have fun

    ### source: https://www.cisco.com/c/en/us/support/docs/ip/simple-network-management-protocol-snmp/26007-faq-snmpcounter.html
    #
    # ifInNUcastPkts (.1.3.6.1.2.1.2.2.1.12)    These are counts of inbound broadcast and multicast packets.
    # ifInDiscards (.1.3.6.1.2.1.2.2.1.13)  These are counted as no buffers as reflected in the show interfaces command.
    # ifInErrors (.1.3.6.1.2.1.2.2.1.14)    These are counts of all input errors as reflected in the show interfaces command.
    # ifInUnknownProtos (.1.3.6.1.2.1.2.2.1.15)     These are counted as unclassified errors.
    # ifOutOctets (.1.3.6.1.2.1.2.2.1.16)   These are counts of the number of bytes output by the interface as shown in the show interfaces command.
    # ifOutUcastPkts (.1.3.6.1.2.1.2.2.1.17)    These are counts of outbound broadcast and multicast packets.
    # ifOutDiscards (.1.3.6.1.2.1.2.2.1.19)     These are counted as output drops as shown in the show interfaces command.
    # ifOutErrors (.1.3.6.1.2.1.2.2.1.20)   These are counted as output errors as shown in the show interfaces command.
    # ifOutQLen (.1.3.6.1.2.1.2.2.1.21)     This is the number of packets allowed to be on the output queue as shown in the show interfaces command.
    #
    # desctiption .1.3.6.1.2.1.2.2.1.2
    ### 
    
    $OIDDescripiton = ".1.3.6.1.2.1.2.2.1.2"
    $OIDErrors = ".1.3.6.1.2.1.2.2.1.20"
    $ifaceNumbers = @(1,12)
    $state=0 # OK state
    $cntErrors=0
    $msg = "All interfaces are ok - no errors found"
    
    function getSNMPValue ($oid)
    {
        $snmp = New-Object -ComObject olePrn.OleSNMP
        $snmp.open('192.168.1.1','secretCommunityString',2,1000)
        return $snmp.get($oid)
    }
    foreach ($ifaceNum in $ifaceNumbers)
    {
        $oid = ("{0}.{1}" -f $OIDDescripiton, $ifaceNum )
        $descr = getSNMPValue -oid $oid
        $oid = ("{0}.{1}" -f $OIDErrors, $ifaceNum )
        $errors = getSNMPValue -oid $oid
    
        if ([int]$errors -gt 0) { 
            $state=1; # ERROR state
            $cntErrors +=1; 
            $msg="$($descr) has $($errors) errors" 
        } 
    }
    
    # writing output to PRTG probe
    echo "$($state):$($cntErrors) $($msg)"