首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PRTG网络监视器的PowerShell脚本

PRTG网络监视器的PowerShell脚本
EN

Stack Overflow用户
提问于 2020-08-06 08:20:58
回答 1查看 1K关注 0票数 0

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

为此,我希望将"ifDescr“作为字符串,"ifAlias”作为字符串,"ifAdminStatus“作为整数,"ifOperStatus”作为整数,"IfInErrors“作为整数,"IfOutErrors”作为整数。我想使用前两个字符串值的方式,他们没有任何警告。当值大于1时,应该通过查找文件转换和触发"ifOperStatus“和"IfInErrors”。当传感器限制器超过0时,将触发最后两个值。所有这些值,必须始终是最新的,并且操作应该在每个接口上只在一个传感器中列出和执行,以保持对重要值的结构化和清晰的视图。

在一项研究中,我发现这并不像我想的那么容易。满足我需求的唯一解决方案似乎是基于PowerShell的脚本传感器。如果有别的办法,请告诉我。

我没有编写PowerShell脚本的经验。因此,我非常乐意得到一些帮助,特别是将来自两个SNMP表传感器的值输入到我的PowerShell脚本中。

诚挚的问候,

SAM_N

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-06 08:52:30

第一部分是与SNMP和查找有关的-下面的内容将帮助您在PRTG中实现这一点:SNMP自定义字符串查找传感器

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

示例

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

带有ID 101的第二个传感器正在将不同的SNMP值拉到通道0。

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

代码语言:javascript
复制
#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中首先手动运行

玩得开心

代码语言:javascript
复制
### 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)" 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63279544

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档