Below is the file 'phonehome.py' from this revision. You can also download the file.

#!/usr/bin/python

#
# the phonehome client
#
# python program with plugins that run various tests
# also sends information about the machine to server
# client<->server communication happens over SOAP
#

import sys
import os
import config
import traceback
import ZSI
from ZSI.client import Binding

if __name__ == '__main__':
    # load each of the plugins
    results = []
    sys.path.insert(0, config.plugin_path)

    # run each plugin
    for plugin_name in config.plugins:
	def run_plugin():
	    mod = __import__(plugin_name, globals(), locals(), [''])
	    return mod.run()

	# each plugin should return a list of results
	# if there are no results it should return the empty list, []
	# the format of results is (urgency, description)
	try:
	    result = run_plugin()
	except:
	    result = [ ("traceback", traceback.format_exc()) ]

	result = [(plugin_name,) + t for t in result]
	results += result

    # send the results of our plugins back to the server
    b = Binding(url=config.soap_address, auth=(ZSI.AUTH.httpbasic, 'phonehome', 'goats'))
    b.plugin_results(results)
    sys.exit(0)

    # we also want to send over information about this machine
    def cpuinfo():
	rv = []
	if not os.access('/proc/cpuinfo', os.R_OK):
	    return rv
	for line in open('/proc/cpuinfo'):
	    fields = [t.strip() for t in line.split(':', 1)]
	    if len(fields) != 2: continue
	    key, value = fields
	    if key == 'cpu MHz':
		rv.append(value)
	return rv
    cpus = cpuinfo()
    b.cpu_info(cpus)

    def memoryinfo():
	if not os.access('/proc/meminfo', os.R_OK):
	    return None
	return open('/proc/meminfo').readline().split(':', 1)[1].strip()
    mem = memoryinfo()
    b.memory_info(mem)