PRTG网络监视器的PowerShell脚本

时间:2020-08-06 08:20:58

标签: powershell networking scripting monitoring prtg

我目前正在使用PRTG,以监视来自Juniper EX4300交换机的接口属性。

为此,我想将“ ifDescr”作为字符串,将“ ifAlias”作为字符串,将“ ifAdminStatus”作为整数,将“ ifOperStatus”作为整数,将“ IfInErrors”作为整数,将“ IfOutErrors”作为整数。我想使用前两个字符串值,就像它们没有任何警报一样。当值大于1时,应通过查找文件转换并触发“ ifOperStatus”和“ IfInErrors”。当最后两个值大于0时,它们将由传感器限制器触发。所有这些值在整个时间内都必须是最新的,并且每个操作都应在一个传感器中列出并完成操作界面,以保持对重要值的结构化和清晰的了解。

在研究过程中,我发现这并不像我想的那么容易。我需要的唯一解决方案似乎是基于PowerShell的脚本传感器。 如果还有其他方法,请告诉我。

我没有编程PowerShell脚本的经验。因此,我很乐意提供一些帮助,尤其是将两个SNMP表传感器中的值输入到我的PowerShell脚本中。

最诚挚的问候,

SAM_N

1 个答案:

答案 0 :(得分:0)

第一部分与SNMP和查找有关-以下内容应帮助您在PRTG中实现这一目标:SNMP Custom String Lookup Sensor

第二部分-要组合来自一个(两个或多个)不同传感器的两个值,您应该使用PRTG Sensor Factory Sensor-如果需要,您甚至可以对这些值进行一些计算。无需编程

示例

假设您有一个传感器从SNMP中提取一个值-该传感器的ID为100,并且您的值存储在通道0中

ID为101的第二个传感器将不同的SNMP值拉至通道0

使用PRTG传感器工厂传感器,您可以创建新的(第三个)传感器,其通道定义如下:

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

这意味着它将两个传感器的值添加到新创建的名为“ SUM_OF_VALUES”的通道中。你可以


您始终可以使用PowerShell从SNMP中提取数据,但是PRTG提供了无需编程即可实现的工具。如果您仍然想在PowerShell中执行此操作,请询问新问题并提供详细信息,我将在PowerShell脚本方面为您提供进一步的帮助

让我知道这是否有帮助

编辑

这个简单的脚本应该可以帮助您开始使用传感器-它会收集$ ifaceNumbers数组中列出的接口的描述和错误数量。 该脚本可以放在PRTG探针的EXE目录中(而不是EXEXML,因为它不会生成XML作为输出)。

更改接口编号(从1和12更改为您的编号),更改社区字符串和IP,并尝试首先在Powershell IDE / Powershell中手动运行它

玩得开心

### 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)" 
相关问题