Ejemplo n.º 1
0
class HostStatusDaemon(Daemon):
    """
    XMLRPC server for returning host status on request.  This wraps 
    the various classes in readers.py into an XMLRPC server.

    @todo Include interface ipv4 and ipv6 addresses 
    @todo Move memory from 'storage' to another location
    @todo Add daemon logging
    """
    def __init__(self,
                 pidfile,
                 logfile,
                 testmode=False,
                 snmpHost='localhost',
                 snmpPort=161,
                 snmpAgentName='ooici',
                 snmpCommunityName='ooicinet',
                 rpcHost='localhost',
                 rpcPort=9010):
        """
        Creates the RPC server
        """
        Daemon.__init__(self, pidfile, logfile)
        self.hostreader = HostReader(snmpHost, snmpPort, snmpAgentName,
                                     snmpCommunityName)
        self.rpcPort = rpcPort
        self.rpcHost = rpcHost
        logging.debug('host_status_daemon intialized')

    def run(self):
        """
        Puts the server in motion.  Blocks forever.
        """
        server = SimpleXMLRPCServer((self.rpcHost, self.rpcPort),
                                    allow_none=True)
        server.register_function(self.getStatus)
        server.register_function(self.getStatusString)
        server.register_introspection_functions()
        server.serve_forever()

    def getStatus(self, system):
        """
        Gets the status of this host (RPC registered function)
        """
        report = self.hostreader.get(system)
        return encoders.encodeJSONToXMLRPC(report)

    def getStatusString(self, system):
        """
        Gets the status of this host (RPC registered function)
        """
        report = self.hostreader.get(system)
        report = self.hostreader.pformat(report)
        return report
class HostStatusDaemon(Daemon):
    """
    XMLRPC server for returning host status on request.  This wraps 
    the various classes in readers.py into an XMLRPC server.

    @todo Include interface ipv4 and ipv6 addresses 
    @todo Move memory from 'storage' to another location
    @todo Add daemon logging
    """

    def __init__(
                 self, 
                 pidfile,
                 logfile,
                 testmode = False, 
                 snmpHost          = 'localhost', 
                 snmpPort          = 161,
                 snmpAgentName     = 'ooici',
                 snmpCommunityName = 'ooicinet',
                 rpcHost           = 'localhost',
                 rpcPort           = 9010  ):
        """
        Creates the RPC server
        """
        Daemon.__init__(self, pidfile, logfile)
        self.hostreader = HostReader(
                                 snmpHost, 
                                 snmpPort, 
                                 snmpAgentName, 
                                 snmpCommunityName
                                 )
        self.rpcPort = rpcPort
        self.rpcHost = rpcHost
        logging.debug('host_status_daemon intialized')


    def run(self):
        """
        Puts the server in motion.  Blocks forever.
        """
        server = SimpleXMLRPCServer((self.rpcHost, self.rpcPort), allow_none=True)
        server.register_function(self.getStatus)
        server.register_function(self.getStatusString)
        server.register_introspection_functions()
        server.serve_forever()


    def getStatus(self,system):
        """
        Gets the status of this host (RPC registered function)
        """
        report = self.hostreader.get(system)
        return encoders.encodeJSONToXMLRPC(report)


    def getStatusString(self,system):
        """
        Gets the status of this host (RPC registered function)
        """
        report = self.hostreader.get(system)
        report = self.hostreader.pformat(report)
        return report