如何在Perl中监视远程Linux机器并检索已安装的软件? [英] How to monitor remote Linux machines and retrieve installed software in Perl?
问题描述
我有几个Perl脚本,它们使我可以通过WMI监视远程Windows机械.现在,我可以检查CPU使用率,内存使用率,磁盘使用率和已安装的软件.但是,如果我想在远程Linux机器上做同样的事情怎么办?当然没有WMI,所以我想我会使用类似的东西.我读过另一个旧的 StackOverflow问题,Linux通过/proc 和/sys ,但是我可以从远程计算机查询它们吗?我该如何在Perl中完全做到这一点?有专门的模块吗?
I have a couple of Perl scripts that allow me to monitor remote Windows machinses through WMI. Right now I can check CPU usage, Memory usage, Disk usage and Installed Software. But what if I want to do the same job on a remote Linux machine? Ofcourse there's no WMI so I guess I shall use something similar. I have read on another old StackOverflow question that Linux exposes informations through /proc and /sys but can I query them from a remote computer? And how can I do that exactly in Perl? Is there a dedicated module?
为澄清起见,脚本必须是无代理的.
Just to clarify, the script MUST be agent-free.
推荐答案
检查以下内容:
http://www.net-snmp.org/docs/mibs/host.html
http://www.oidview.com/mibs/0/RFC1213-MIB.html
这将为您提供内存/磁盘使用量:
This will give you memory / disk usage :
snmptable -v1 -c public localhost hrStorageTable
snmptable -v1 -c public localhost .1.3.6.1.2.1.25.2.3
这将为您提供处理器利用率:
This will give you processor utilisation :
snmptable -v1 -c public localhost hrProcessorTable
snmptable -v1 -c public localhost .1.3.6.1.2.1.25.3.3
接口状态:
snmptable -v1 -c public localhost ifTable
snmptable -v1 -c public localhost .1.3.6.1.2.1.2.2
如果您使用基于rpm的linux,这将为您提供已安装的软件:
If you use rpm-based linux, this will give you installed software :
snmptable -v1 -c public localhost hrSWInstalledTable
snmptable -v1 -c public localhost .1.3.6.1.2.1.25.6.3
您可以使它适用于Linux的.deb风格:
You can make this work for .deb flavours of linux :
Sample output of `snmptable -v1 -c public localhost hrProcessorTable`
hrProcessorFrwID hrProcessorLoad
SNMPv2-SMI::zeroDotZero 54
SNMPv2-SMI::zeroDotZero 22
您要查询的框上,公众是否对.1.3.6.1.2.1.25具有读权限?
On the box you are querying, does public have read access to .1.3.6.1.2.1.25 ?
您可能需要在/etc/snmp/snmpd.conf中添加类似的内容
You may need to add something like this to your /etc/snmp/snmpd.conf
com2sec monitor default monitor
group monitorGroup v1 monitor
group monitorGroup v2c monitor
view hardware included .1.3.6.1.2.1.25
view hardware included .1.3.6.1.2.1.2
access monitorGroup "" any noauth exact hardware none none
重新启动snmpd
然后在上面的命令中指定 -c监视器
,而不是 -c public
Then specify -c monitor
in the commands above instead of -c public
这篇关于如何在Perl中监视远程Linux机器并检索已安装的软件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!