예제 #1
0
파일: module.py 프로젝트: naparuba/opsbro
 def launch(self):
     threader.create_and_launch(self.launch_database_thread,
                                name='Database thread',
                                essential=True,
                                part='imrane')
     threader.create_and_launch(self.launch_collector_thread,
                                name='Collector thread',
                                essential=True,
                                part='imrane')
예제 #2
0
파일: module.py 프로젝트: naparuba/opsbro
 def launch(self):
     threader.create_and_launch(self.launch_statsd_udp_listener,
                                name='UDP port:%d listening' %
                                self.statsd_port,
                                essential=True,
                                part='statsd')
     threader.create_and_launch(self.launch_compute_stats_thread,
                                name='Stats computing',
                                essential=True,
                                part='statsd')
예제 #3
0
    def SvcDoRun(self):
        try:
            LOG('SvcDoRun')
            import servicemanager
            servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, servicemanager.PYS_SERVICE_STARTED, (self._svc_name_, ''))
            servicemanager.LogInfoMsg("OpsBro Start")

            # Set as english
            locale.setlocale(locale.LC_ALL, 'English_Australia.1252')
            
            # under service, stdout and stderr are not available
            # TODO: enable debug mode?
            self.destroy_stdout_stderr()
            LOG('BEFORE CLI')
            # simulate CLI startup with config parsing
            from opsbro.log import cprint, logger, is_tty
            from opsbro.cli import CLICommander, save_current_binary
            from opsbro.yamlmgr import yamler
            
            with open('c:\\opsbro\\etc\\agent.yml', 'r') as f:
                buf = f.read()
                CONFIG = yamler.loads(buf)

            LOG('CONF LOADED')
            
            # Load config
            CLI = CLICommander(CONFIG, None)

            LOG('CLI LOADED')
            l = Launcher(cfg_dir='c:\\opsbro\\etc')
            LOG('LAUNCHER created')
            l.do_daemon_init_and_start(is_daemon=False)
            LOG('LAUNCHER init')
            # Start the stopper threads
            threader.create_and_launch(self.__check_for_hWaitStop, (), name='Windows service stopper', essential=True, part='agent')
            LOG('LAUNCHER call main')
            # Here only the last son reach this
            l.main()
            # called when we're being shut down
        except Exception:
            err = traceback.format_exc()
            LOG('CRASH: %s' % err)
            logger_crash.error(err)
            raise
예제 #4
0
파일: module.py 프로젝트: naparuba/opsbro
 def launch(self):
     if not self.websocket['enabled']:
         self.logger.log('Websocket object defined in the configuration is disabled, skipping websocket launch')
         return
     
     threader.create_and_launch(self.do_launch, name='Websocket port:%d listening' % self.websocket.get('port'), essential=True, part='websocket')
예제 #5
0
파일: module.py 프로젝트: naparuba/opsbro
 def launch(self):
     self.shinken_thread = threader.create_and_launch(
         self.main_thread,
         name='Export nodes/checks and states to Shinken',
         essential=True,
         part='shinken')
예제 #6
0
파일: cli.py 프로젝트: naparuba/opsbro
def do_detect_nodes(auto_join, timeout=5):
    # The information is available only if the agent is started
    wait_for_agent_started(visual_wait=True)

    print_h1('UDP broadcast LAN detection')
    print(
        "Trying to detect other nodes on the network thanks to a UDP broadcast. Will last %ds."
        % timeout)
    cprint(' * The detection scan will be ', end='')
    cprint('%ds' % timeout, color='magenta', end='')
    cprint(' long.')
    threader.create_and_launch(__print_detection_spinner, (timeout, ),
                               'spinner',
                               essential=False)

    # Send UDP broadcast packets from the daemon
    try:
        network_nodes = get_opsbro_json('/agent/detect?timeout=%d' % timeout,
                                        timeout=timeout + 10)
    except get_request_errors() as exp:
        logger.error('Cannot join opsbro agent to detect network nodes: %s' %
                     exp)
        sys.exit(1)
    cprint(" * Detection is DONE")
    print_h1('Detection result')
    if len(network_nodes) == 0:
        cprint(' ERROR: ', color='red', end='')
        cprint("cannot detect (broadcast UDP) other nodes")
        sys.exit(1)
    cprint("Other network nodes detected on this network:")
    cprint(
        '  Name                                 Zone        Address:port          Proxy    Groups'
    )
    for node in network_nodes:
        cprint('  %-35s  %-10s  %s:%d  %5s     %s' %
               (node['name'], node['zone'], node['addr'], node['port'],
                node['is_proxy'], ','.join(node['groups'])))
    if not auto_join:
        cprint('NOTICE: ', color='blue', end='')
        cprint(
            "Auto join (--auto-join) is not enabled, so don't try to join theses nodes"
        )
        return

    # try to join theses nodes so :)
    # NOTE: sort by uuid so we are always joining the same nodes
    # and so we don't have split network if possible (common node)
    all_proxys = sorted([node for node in network_nodes if node['is_proxy']],
                        key=lambda n: n['uuid'])
    not_proxys = sorted(
        [node for node in network_nodes if not node['is_proxy']],
        key=lambda n: n['uuid'])
    if all_proxys:
        node = all_proxys.pop()
        cprint("A proxy node is detected, using it: %s (%s:%d)" %
               (node['name'], node['addr'], node['port']))
        to_connect = '%s:%d' % (node['addr'], node['port'])
    else:
        node = not_proxys.pop()
        cprint("No proxy node detected. Using a standard one: %s (%s:%d)" %
               (node['name'], node['addr'], node['port']))
        to_connect = '%s:%d' % (node['addr'], node['port'])
    do_join(to_connect)
예제 #7
0
 def launch(self):
     threader.create_and_launch(self.do_launch,
                                name='UDP port:%d listening' % self.port,
                                essential=True,
                                part='dns')
예제 #8
0
 def launch(self):
     threader.create_and_launch(self.launch_graphite_udp_listener, name='UDP port:%d listening' % self.graphite_port, essential=True, part='graphite')
     threader.create_and_launch(self.launch_graphite_tcp_listener, name='TCP port:%d listening' % self.graphite_port, essential=True, part='graphite')
     threader.create_and_launch(self.graphite_reaper, name='Metric reader', essential=True, part='graphite')
예제 #9
0
 def _before_start_callback(self):
     threader.create_and_launch(self.__check_for_hWaitStop, (),
                                name='Windows service stopper',
                                essential=True,
                                part='agent')
예제 #10
0
 def launch(self):
     threader.create_and_launch(self.launch_main,
                                name='Synology',
                                essential=True,
                                part='synology')
예제 #11
0
 def launch(self):
     threader.create_and_launch(
         self.do_launch,
         name='Grafana module data sources synchronizer',
         essential=True,
         part='grafana')