Below is the file 'client/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
#

from getopt import getopt
import sys
import os
import config
import traceback
urgency = { 'info' : 0, 'notice' : 1, 'warning' : 2, 'alert' : 3, 'critical' : 4 }

if __name__ == '__main__':
    opts, args = getopt(sys.argv[1:], 'n')
    skip_network = False
    for opt, value in opts:
        if opt == '-n':
            skip_network = True

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

    binding = None
    if not skip_network:
        import ZSI
        from ZSI.client import Binding

        # SOAP connection to send information back
        soap_password = open(os.path.join(config.install_path, 'etc', 'client.pass')).readline().strip()
        b = Binding(url=config.soap_address, host=config.soap_host, auth=(ZSI.AUTH.httpbasic, 'phonehome', soap_password), tracefile=open('trace.txt', 'w'))

    # 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:
            exc_info = sys.exc_info()
	    exception = '\n'.join(traceback.format_exception(exc_info[0], exc_info[1], exc_info[2]))
	    sys.stderr.write("Exception in plugin %s\n" % plugin_name + exception)
	    result = [ (urgency['alert'], exception) ]
	result = [(plugin_name,) + t for t in result]
	results += result

    if skip_network:
	print >>sys.stderr, "Transmission to network server skipped.\nResults follow:\n"
	from pprint import pprint
	pprint(results, sys.stderr)
    else:
        b.plugin_results(results)

    sys.exit(0)

    # not for now.. perhaps do this as a plugin instead
    #
    # unreachable..


    # 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)