6

I'd like to write a python script to perform some very simple "agentless" monitoring of remote processes running on linux servers.

It would perform the following tasks, in psuedocode:

for each remoteIPAddress in listOfIPAddresses:
    log into server@remoteIPAddress via ssh
    execute the equivalent of a 'ps -ef' command
    grep the result to make sure a particular process (by name) is still running

One way to do this is to have python call shell scripts in a subprocess and parse their output. That seems pretty inefficient. Is there a better way to do this via python libraries?

All I could find via research here and elsewhere was:

  • psutil - looks like it doesn't do remote monitoring, so I'd have to run agents on the remote machines to report stats back via RPC.
  • pymeter - I would have to write my own plugin for monitoring a specific remote service.
  • stackoverflow #4546492 - Some helpful links but the poster was looking for a different solution.

Thanks, and please go easy on me, it's my first question :-)

Community
  • 1
  • 1
tohster
  • 6,973
  • 5
  • 38
  • 55

5 Answers5

4

The Fabric library may be of interest to you.

Carl Groner
  • 4,149
  • 1
  • 19
  • 20
  • +1 to Fabric, makes such thing way more efficient to write and maintain in place of shell scripts from Python. –  Aug 11 '12 at 02:31
  • Thanks very much. Looks like I will still need to do the core of it using ssh commands but Fabric wraps this much more elegantly than I could have hoped to kluge together myself. Appreciate the prompt suggestion! – tohster Aug 11 '12 at 21:28
1

Check out paramiko. You can use it to ssh into the server and run commands. You can then parse the results and do what you'd like with them.

Mark Hildreth
  • 42,023
  • 11
  • 120
  • 109
  • Thanks for the suggestion. I think I'll start with Fabric but this is plan B and a good answer. – tohster Aug 11 '12 at 21:26
  • Looked into both Fabric and Paramiko. I am accepting this answer because it conforms most closely to the original question. – tohster Aug 14 '12 at 19:52
1

Taking cues from the answers above, I investigated Fabric and found the following presentation particularly interesting/helpful. It is an overview of three libraries -- Fabric, Cuisine, and Watchdog -- for server monitoring and administration. For posterity:

Using Fabric, Cuisine, and Watchdog for server administration in Python

tohster
  • 6,973
  • 5
  • 38
  • 55
0

It might be heavier than what you're looking for, but Zenoss supports agentless monitoring.

paramiko and Fabric, suggested in the other answers, are great options too.

Brian Cain
  • 14,403
  • 3
  • 50
  • 88
0

Why don't you use a dedicated monitoring tool like Nagios ? Nagios has agent and agent less monitoring through NRPE plugins and SSH plugins etc. Try it out.

Sss
  • 1
  • 1