Пример #1
0
def test():
    config = CParser()
    config.read('./etc/observant/observant.cfg')

    pid = os.fork()
    if pid != 0:
        os.waitpid(pid, 0)
    else:
        dump = './.test.out'
        sockPath = './.test.sock'
        server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        server.setblocking(0)
        with open(dump, 'w') as fd:
            fd.write("test")
            server.bind(sockPath)
            server.listen(1)
            transport = daemon.transportFromConfig(config)
            lock = str(config.get('daemon', 'lock'))
            sock = str(config.get('daemon', 'sock'))
            key = str(config.get('daemon', 'key'))
            client = StatsCore.attachOrCreateStatsDaemon(key, transport, pid=lock, sock=sock)
            client.postWatchPid('test', os.getpid())
            time.sleep(4)
            client.postLogMessageForKey('test', 'some random logmessage')
            time.sleep(4)
            client.postLogMessageForKey('test', 'some random logmessage')
            client.close()
            time.sleep(4)
        os.remove(dump)
        server.close()
        os.unlink(sockPath)
Пример #2
0
    def _start_observing(self):
        # ``StatsCore`` is the original observant daemon. It seems to have been
        # replaced more recently by ``vigilant.daemon.Daemon``
        # TODO: update for vigilant Daemon

        # Get vigilant to read its own config
        config = CParser()
        config.read(os.path.join(etc_location, 'vigilant.cfg'))

        # Extract the information we need from the config object
        lock = str(config.get('daemon', 'lock'))
        sock = str(config.get('daemon', 'sock'))
        transport_type = str(config.get('transport', 'type'))
        host = str(config.get('transport', 'host'))
        port = int(config.get('transport', 'port'))
        transport_means = UDPStatsTransport if transport_type == 'udp' else TCPStatsTransport
        transport = transport_means(host=host, port=port)

        # Start the daemon
        self.client = StatsCore.attachOrCreateStatsDaemon(transport, pid=lock, sock=sock)

        # Tell the daemon who we are
        self.client.postWatchPid('go-smart-launcher', os.getpid())

        # Give it a second to avoid confusion by posting before registered
        # TODO: tidy this up!
        time.sleep(1)
Пример #3
0
def setup_monitoring(config):
    try:
        name = "observant-dashboard-%s" % str(config.get("dashboard", "port"))
        client = StatsCore.attchToStatsDaemon()
        client.postWatchPid(name, os.getpid())
        client.close()
    except:
        logging.error("Unable to setup monitoring: [%s]" % str(sys.exc_info()))
Пример #4
0
def isDaemonRunning(config):
    try:
        lock = str(config.get('daemon', 'lock'))
        sock = str(config.get('daemon', 'sock'))
        client = StatsCore.attchToStatsDaemon(pid=lock, sock=sock)
        print(client.postDaemonStatusMessage())
        client.close()
        return True
    except:
        return str(sys.exc_info()[1])
Пример #5
0
    def __init__(self,
                 server_id,
                 database,
                 publish_cb,
                 ignore_development=False,
                 use_observant=use_observant,
                 simdata_path='/tmp'):
        # This forwards exceptions to the client
        self.traceback_app = True

        self.server_id = server_id
        self.current = {}
        self.publish = publish_cb
        # Flag that tells the server to ignore anything with a parameter
        # `DEVELOPMENT` true
        self._ignore_development = ignore_development
        self._simdata_path = simdata_path

        # If we are using vigilant, do the relevant set-up
        if use_observant:
            config = CParser()
            config.read(os.path.join(gssa.config.etc_location, 'vigilant.cfg'))

            lock = str(config.get('daemon', 'lock'))
            sock = str(config.get('daemon', 'sock'))
            transport_type = str(config.get('transport', 'type'))
            host = str(config.get('transport', 'host'))
            port = int(config.get('transport', 'port'))
            transport_means = UDPStatsTransport if transport_type == 'udp' else TCPStatsTransport
            transport = transport_means(host=host, port=port)

            self.client = StatsCore.attachOrCreateStatsDaemon(transport,
                                                              pid=lock,
                                                              sock=sock)
            self.client.postWatchPid('go-smart-simulation-server', os.getpid())

        # Create a directory to hold information specific to this server ID
        if not os.path.exists(server_id):
            logger.debug("Creating server ID directory")
            os.mkdir(server_id)

        logger.debug("Changing to server ID directory")

        # Use this as the working directory
        os.chdir(server_id)

        logger.debug("Storing identity (%s)" % server_id)

        self._write_identity(server_id)

        logger.debug("Requesting DB setup")

        # Flag this up to be done, but don't wait for it
        _threadsafe_call(self.setDatabase, database())
Пример #6
0
    def __init__(self, server_id, database, publish_cb, ignore_development=False, use_observant=use_observant, simdata_path='/tmp'):
        # This forwards exceptions to the client
        self.traceback_app = True

        self.server_id = server_id
        self.current = {}
        self.publish = publish_cb
        # Flag that tells the server to ignore anything with a parameter
        # `DEVELOPMENT` true
        self._ignore_development = ignore_development
        self._simdata_path = simdata_path

        # If we are using vigilant, do the relevant set-up
        if use_observant:
            config = CParser()
            config.read(os.path.join(gssa.config.etc_location, 'vigilant.cfg'))

            lock = str(config.get('daemon', 'lock'))
            sock = str(config.get('daemon', 'sock'))
            transport_type = str(config.get('transport', 'type'))
            host = str(config.get('transport', 'host'))
            port = int(config.get('transport', 'port'))
            transport_means = UDPStatsTransport if transport_type == 'udp' else TCPStatsTransport
            transport = transport_means(host=host, port=port)

            self.client = StatsCore.attachOrCreateStatsDaemon(transport, pid=lock, sock=sock)
            self.client.postWatchPid('go-smart-simulation-server', os.getpid())

        # Create a directory to hold information specific to this server ID
        if not os.path.exists(server_id):
            logger.debug("Creating server ID directory")
            os.mkdir(server_id)

        logger.debug("Changing to server ID directory")

        # Use this as the working directory
        os.chdir(server_id)

        logger.debug("Storing identity (%s)" % server_id)

        self._write_identity(server_id)

        logger.debug("Requesting DB setup")

        # Flag this up to be done, but don't wait for it
        _threadsafe_call(self.setDatabase, database())
Пример #7
0
def startDaemon(config):
    lock = str(config.get('daemon', 'lock'))
    sock = str(config.get('daemon', 'sock'))
    transport = transportFromConfig(config)
    client = StatsCore.attachOrCreateStatsDaemon(transport, pid=lock, sock=sock)
    client.close()
Пример #8
0
def killDaemon(config):
    lock = str(config.get('daemon', 'lock'))
    sock = str(config.get('daemon', 'sock'))
    client = StatsCore.attchToStatsDaemon(pid=lock, sock=sock)
    client.postStopDaemon()
    client.close()