1

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?

EDIT: Just to clarify, the script MUST be agent-free.

Community
  • 1
  • 1
raz3r
  • 3,071
  • 8
  • 44
  • 66

2 Answers2

3

Check these :

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

Interface Status :

snmptable -v1 -c public localhost ifTable
snmptable -v1 -c public localhost .1.3.6.1.2.1.2.2

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

You can make this work for .deb flavours of linux :

http://community.zenoss.org/blogs/zenossblog/2009/02/18/tip-of-the-month-snmp-software-inventory-for-debian-and-ubuntu-machines

Sample output of `snmptable -v1 -c public localhost hrProcessorTable`

        hrProcessorFrwID hrProcessorLoad
 SNMPv2-SMI::zeroDotZero              54
 SNMPv2-SMI::zeroDotZero              22

On the box you are querying, does public have read access to .1.3.6.1.2.1.25 ?

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

The restart snmpd

Then specify -c monitor in the commands above instead of -c public

John
  • 573
  • 2
  • 6
  • snmptable works if I launch the command with the OID (wich I don't know) if I try your command it says *Unknown Object Identifier (Sub-id not found: (top) -> hrProcessorTable)* and that happens for every parameter. – raz3r Dec 01 '11 at 15:04
  • snmptable command gives me *was that a table?* error. snmpwalk works and returns (for CPU utilization) this output: *iso.3.6.1.2.1.25.3.3.1.1.768 = OID: ccitt.0 iso.3.6.1.2.1.25.3.3.1.2.768 = INTEGER: 1* That doesn't sound like a CPU utilization at all O_o – raz3r Dec 02 '11 at 07:42
  • Updated answer with sample output and snmpd.conf – John Dec 02 '11 at 13:57
  • What if I have Debian instead of an rpm-based Linux? – raz3r Dec 09 '11 at 14:56
1

I don't think so, perhaps you can use Net::SSH to access these files, but I think it would make more sense if you install snmp agent and use Net::SNMP for the purpose.

Monitoring installed software may get trickier, will depend on the linux distribution and will probably be easiest over ssh.

EDIT: Ignore the snmp part, since you want to be agent-free.

Michael Krelin - hacker
  • 138,757
  • 24
  • 193
  • 173
  • Well I do have SSH access on almost all Linux machines but I do not have an SNMP interface. I mean I can setup SNMP but if I can retrieve those informations in an agent-free way it would be MUCH better. Regarding installed software SSH is the easiest way indeed, I can launch dpkg *--get-selections* and parse the output. – raz3r Dec 01 '11 at 10:12
  • Yes, that's what i meant as long as it's debian based. May get trickier if you have different packaging systems. ssh is an option, it's just that you poll often enough, it's probably not the most performant solution for gettint information available via snmp. – Michael Krelin - hacker Dec 01 '11 at 10:17
  • Frequency is high, I have to read those informations like every minute or less and update a Round Robin Database. I did try to gather SNMP informations in Windows but it was really hard, maybe I need to understand MIBs better. Out of curiosity how will you do that? Do I need to query a particular OID? This is the code I tested on Windows (forget about OID it's just an example): *my $oid = '1.3.6.1.....'; ($session, $error) = Net::SNMP->session(-hostname => '192.168.252.165', -community => 'test'); $result = $session->get_request(-varbindlist => [ $oid ]); $result = $result->{$oid};* – raz3r Dec 01 '11 at 10:23
  • To tell you the truth, I have used both snmp and perl about 10 years ago last time :) If I remember correctly, there were requests like get, get_bulk, etc. Pretty straightforward. – Michael Krelin - hacker Dec 01 '11 at 10:28
  • http://search.cpan.org/~dtown/Net-SNMP-v6.0.1/lib/Net/SNMP.pm has pretty sensible examples. – Michael Krelin - hacker Dec 01 '11 at 10:29
  • Exactly but I have the feeling that some informations are stored in tables and not in single labels. My question is, a single OID equals to a single value? I mean if I want to read CPU usage is the value stored on a OID like 1.3.6.x.x.x.x.x? – raz3r Dec 01 '11 at 10:31
  • I think there's an oid with count and then you access by index. I used to look at `snmpwalk` output back when I used it to get the picture of what's where and why. – Michael Krelin - hacker Dec 01 '11 at 10:34