def do_compliance_state(compliance_name=''): uri = '/compliance/state' try: (code, r) = get_opsbro_local(uri) except get_request_errors() as exp: logger.error(exp) return try: compliances = jsoner.loads(r) except ValueError as exp: # bad json logger.error('Bad return from the server %s' % exp) return print_h1('Compliances') packs = {} for (cname, compliance) in compliances.items(): if compliance_name and compliance['name'] != compliance_name: continue pack_name = compliance['pack_name'] if pack_name not in packs: packs[pack_name] = {} packs[pack_name][cname] = compliance pnames = list(packs.keys()) # python3 pnames.sort() for pname in pnames: pack_entries = packs[pname] cprint('* Pack %s' % pname, color='blue') cnames = list(pack_entries.keys()) # python3 cnames.sort() for cname in cnames: cprint(' - %s' % pname, color='blue', end='') compliance = pack_entries[cname] __print_compliance_entry(compliance)
def do_tutorials_list(): from opsbro.tutorial import tutorialmgr tutorials = tutorialmgr.tutorials print_h1('Tutorials') if len(tutorials) == 0: cprint('No tutorials', color='grey') sys.exit(0) packs = {} for tutorial in tutorials: tutorial_name = tutorial.name pack_name = tutorial.pack_name if pack_name not in packs: packs[pack_name] = {} packs[pack_name][tutorial_name] = tutorial pnames = list(packs.keys()) pnames.sort() for pname in pnames: pack_entries = packs[pname] tnames = list(pack_entries.keys()) tnames.sort() for tname in tnames: tutorial = pack_entries[tname] duration = ceil(tutorial.get_duration()) level = tutorial.pack_level __print_pack_breadcumb(pname, level, end='', topic_picto='small') cprint(' %-20s ' % tname, color='magenta', end='') cprint(' (Duration: %ds) ' % duration, end='') cprint(tutorial.title, color='grey')
def do_dashboards_list(): from opsbro.dashboardmanager import get_dashboarder dashboarder = get_dashboarder() print_h1('Dashboards') dashboards = dashboarder.dashboards if len(dashboards) == 0: cprint('No dashboards', color='grey') sys.exit(0) packs = {} for (dname, dashboard) in dashboards.items(): pack_name = dashboard['pack_name'] if pack_name not in packs: packs[pack_name] = {} packs[pack_name][dname] = dashboard pnames = list(packs.keys()) pnames.sort() for pname in pnames: pack_entries = packs[pname] cprint('* Pack %s' % pname, color='blue') dnames = list(pack_entries.keys()) dnames.sort() for dname in dnames: dashboard = pack_entries[dname] level = dashboard['pack_level'] __print_pack_breadcumb(pname, level, end='', topic_picto='small') cprint('%-20s ' % dname, color='magenta', end='') cprint(dashboard['title'], color='grey')
def do_collectors_history(): try: history_entries = get_opsbro_json('/agent/collectors/history') except get_request_errors() as exp: logger.error(exp) return print_h1('History') for history_entry in history_entries: epoch_date = history_entry['date'] entries = history_entry['entries'] print_h2( ' Date: %s ' % time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(epoch_date))) for entry in entries: name = entry['name'] cprint(' * ', end='') cprint('%s ' % (name.ljust(20)), color='magenta', end='') old_state = entry['old_state'] c = COLLECTORS_STATE_COLORS.get(old_state, 'cyan') cprint('%s' % old_state.ljust(10), color=c, end='') cprint(' %s ' % CHARACTERS.arrow_left, color='grey', end='') state = entry['state'] c = COLLECTORS_STATE_COLORS.get(state, 'cyan') cprint('%s' % state.ljust(10), color=c) # Now print output the line under log = entry['log'] if log: cprint(' ' * 4 + '| ' + log, color='grey')
def do_detect_history(): uri = '/agent/detectors/history' try: (code, r) = get_opsbro_local(uri) except get_request_errors() as exp: logger.error(exp) return try: histories = jsoner.loads(r) except ValueError as exp: # bad json logger.error('Bad return from the server %s' % exp) return print_h1('Detected groups history for this node') for history in histories: epoch = history['date'] # We want only group type events entries = [entry for entry in history['entries'] if entry['type'] in ('group-add', 'group-remove')] if not entries: continue print_h2(' Date: %s ' % time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(epoch))) for entry in entries: _type = entry['type'] op = {'group-add': '+', 'group-remove': '-'}.get(_type, '?') color = {'group-add': 'green', 'group-remove': 'red'}.get(_type, 'grey') cprint(' %s %s' % (op, entry['group']), color=color)
def do_collectors_state(): print_h1('Collectors') try: collectors = get_opsbro_json('/collectors') except get_request_errors() as exp: logger.error(exp) return cnames = list(collectors.keys()) cnames.sort() for cname in cnames: d = collectors[cname] __print_collector_state(d)
def do_members_history(): # The information is available only if the agent is started wait_for_agent_started(visual_wait=True) try: history_entries = get_opsbro_json('/agent/members/history') except get_request_errors() as exp: logger.error('Cannot join opsbro agent to show member history: %s' % exp) sys.exit(1) print_h1('History') for history_entry in history_entries: epoch_date = history_entry['date'] # We want only group type events entries = [ entry for entry in history_entry['entries'] if entry['type'] == 'node-state-change' ] if not entries: continue print_h2( ' Date: %s ' % time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(epoch_date))) for entry in entries: name = entry['name'] if entry.get('display_name', ''): name = '[ ' + entry.get('display_name') + ' ]' old_state = entry['old_state'] new_state = entry['state'] old_color = NODE_STATE_COLORS.get(old_state, 'cyan') old_state_prefix = NODE_STATE_PREFIXS.get( old_state, CHARACTERS.double_exclamation) new_color = NODE_STATE_COLORS.get(new_state, 'cyan') new_state_prefix = NODE_STATE_PREFIXS.get( new_state, CHARACTERS.double_exclamation) cprint('%s ' % name.ljust(20), color='magenta', end='') cprint(('%s %s' % (old_state_prefix, old_state)).ljust(9), color=old_color, end='') # 7 for the maximum state string + 2 for prefix cprint(' %s ' % CHARACTERS.arrow_left, color='grey', end='') cprint(('%s %s' % (new_state_prefix, new_state)).ljust(9), color=new_color ) # 7 for the maximum state string + 2 for prefix
def do_zone_list(): print_h1('Known zones') try: zones = get_opsbro_json('/agent/zones') except get_request_errors() as exp: logger.error(exp) return # We are building the zone tree, so link real object in other zone for zone in zones.values(): sub_zones = {} for sub_zone_name in zone.get('sub-zones', []): sub_zone = zones.get(sub_zone_name, None) sub_zones[sub_zone_name] = sub_zone zone['sub-zones'] = sub_zones # Set if the zone is top/lower if not our own zone for zone in zones.values(): zone['type'] = _ZONE_TYPES.OTHER # And finally delete the zone that are not in top level to_del = set() for (zname, zone) in zones.items(): for sub_zname in zone['sub-zones']: to_del.add(sub_zname) for zname in to_del: del zones[zname] for zone in zones.values(): _flag_top_lower_zone(zone) # Now print it zone_names = zones.keys() zone_names.sort() for zname in zone_names: zone = zones[zname] _print_zone(zname, zone, 0) cprint('') print_h1('Zones types legend') for zone_type in _ALL_ZONE_TYPES: label = _ZONE_TYPE_LABEL[zone_type] color = _ZONE_TYPE_COLORS[zone_type] description = _ZONE_TYPE_DESCRIPTION[zone_type] cprint(' - ', end='') cprint('%-15s' % label, color=color, end='') cprint(' : %s' % description)
def do_agent_parameters_show(): logger.setLevel('ERROR') # We should already have load the configuration, so just dump it # now we read them, set it in our object parameters_from_local_configuration = configmgr.get_parameters_for_cluster_from_configuration( ) # print "Local parameters", parameters_from_local_configuration print_h1('Local agent parameters') key_names = list(parameters_from_local_configuration.keys()) key_names.sort() for k in key_names: v = parameters_from_local_configuration[k] cprint(' * ', end='') cprint('%-15s' % k, color='magenta', end='') cprint(' %s ' % CHARACTERS.arrow_left, end='') cprint('%s\n' % v, color='green', end='')
def do_compliance_history(): uri = '/compliance/history' try: (code, r) = get_opsbro_local(uri) except get_request_errors() as exp: logger.error(exp) return try: histories = jsoner.loads(r) except ValueError as exp: # bad json logger.error('Bad return from the server %s' % exp) return print_h1('Compliance history') for history in histories: epoch = history['date'] entries = history['entries'] print_h2(' Date: %s ' % time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(epoch))) entries_by_compliances = {} for entry in entries: compliance_name = entry['compliance_name'] pack_name = entry['pack_name'] mode = entry['mode'] if compliance_name not in entries_by_compliances: entries_by_compliances[compliance_name] = { 'pack_name': pack_name, 'mode': mode, 'entries': [] } entries_by_compliances[compliance_name]['entries'].append(entry) for (compliance_name, d) in entries_by_compliances.items(): pack_name = d['pack_name'] mode = d['mode'] entries = d['entries'] cprint(' - %s' % pack_name, color='blue', end='') cprint(' > compliance > ', color='grey', end='') cprint('[%s] ' % (compliance_name.ljust(30)), color='magenta', end='') cprint('[mode:%10s] ' % mode, color='magenta') for entry in entries: # rule_name = entry['name'] # cprint('[%s] ' % (rule_name.ljust(30)), color='magenta', end='') __print_rule_entry(entry) cprint("\n")
def do_zone_list(): print_h1('Known zones') try: zones = get_opsbro_json('/agent/zones') except get_request_errors() as exp: logger.error(exp) return for (zname, zone) in zones.items(): cprint(' * ', end='') cprint(zname, color='magenta') sub_zones = zone.get('sub-zones', []) if not sub_zones: continue cprint(' Sub zones:') for sub_zname in sub_zones: cprint(' - ', end='') cprint(sub_zname, color='cyan')
def do_sponsor(): from opsbro.authors import NINJA from opsbro.cli_display import print_h1 print_h1('Our sponsor') cprint(NINJA) cprint( 'Shinken Solutions Team is working on a great monitoring solution: ', end='') cprint('Shinken Enterprise', color='magenta', end='') cprint(' (http://shinken-solutions.com).') cprint('Have a look if you need a powerful monitoring with:') cprint(' - unlimited scalability') cprint(' - high availability') cprint(' - advanced configuration with multi-role communication inside') cprint(' - powerful dashboards (/.__.)/ \(.__.\)') cprint('')
def do_history(): uri = '/monitoring/history/checks' try: (code, r) = get_opsbro_local(uri) except get_request_errors() as exp: logger.error(exp) return try: history_entries = jsoner.loads(r) except ValueError as exp: # bad json logger.error('Bad return from the server %s' % exp) return print_h1('History') for history_entry in history_entries: epoch_date = history_entry['date'] entries = history_entry['entries'] print_h2(' Date: %s ' % time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(epoch_date))) for entry in entries: pname = entry['pack_name'] check_display_name = entry['display_name'] cprint(' - %s' % pname, color='blue', end='') cprint(' > checks > ', color='grey', end='') cprint('%s ' % (check_display_name.ljust(30)), color='magenta', end='') old_state = entry['old_state_id'] c = STATE_ID_COLORS.get(old_state, 'cyan') old_state = STATE_ID_STRINGS.get(old_state, 'UNKNOWN') cprint('%s' % old_state.ljust(10), color=c, end='') cprint(' %s ' % CHARACTERS.arrow_left, color='grey', end='') state = entry['state_id'] c = STATE_ID_COLORS.get(state, 'cyan') state = STATE_ID_STRINGS.get(state, 'UNKNOWN') cprint('%s' % state.ljust(10), color=c) # Now print output the line under output = entry['output'] output_lines = output.strip().splitlines() for line in output_lines: cprint(' ' * 4 + '| ' + line, color='grey')
def do_packs_list(): from opsbro.packer import packer packs = packer.get_packs() all_pack_names = set() for (level, packs_in_level) in packs.items(): for (pname, _) in packs_in_level.items(): all_pack_names.add(pname) print_h2('Legend (topics)') for topic_id in VERY_ALL_TOPICS: color_id = topiker.get_color_id_by_topic_id(topic_id) label = TOPICS_LABELS[topic_id] s = u'%s %s %s' % (CHARACTERS.topic_small_picto, CHARACTERS.arrow_left, label) color_s = lolcat.get_line(s, color_id, spread=None) cprint(color_s) print_h1('Packs') pnames = list(all_pack_names) pnames.sort() for pname in pnames: present_before = False keywords = [] # useless but make lint code check happy for level in ('core', 'global', 'zone', 'local'): if pname in packs[level]: (pack, _) = packs[level][pname] if present_before: cprint('(overloaded by %s) ' % CHARACTERS.arrow_left, color='green', end='') __print_pack_breadcumb(pname, level, end='', topic_picto='small') keywords = pack['keywords'] present_before = True cprint('[keywords: %s]' % (','.join(keywords)), color='magenta')
def do_generators_state(show_diff=False): uri = '/generators/state' try: (code, r) = get_opsbro_local(uri) except get_request_errors() as exp: logger.error(exp) return try: generators = jsoner.loads(r) except ValueError as exp: # bad json logger.error('Bad return from the server %s' % exp) return print_h1('Generators') packs = {} for (cname, generator) in generators.items(): pack_name = generator['pack_name'] if pack_name not in packs: packs[pack_name] = {} packs[pack_name][cname] = generator pnames = list(packs.keys()) pnames.sort() for pname in pnames: pack_entries = packs[pname] cprint('* Pack %s' % pname, color='blue') cnames = list(pack_entries.keys()) cnames.sort() for cname in cnames: cprint(' - %s' % pname, color='blue', end='') generator = pack_entries[cname] __print_generator_entry(generator, show_diff=show_diff) if not show_diff: cprint('') cprint( ' | Note: you can see the modification diff with the --show-diff parameter', color='grey')
def do_zone_key_generate(zone, erase=False): from opsbro.defaultpaths import DEFAULT_CFG_DIR from opsbro.configurationmanager import ZONE_KEYS_DIRECTORY_NAME from opsbro.encrypter import GOSSIP_KEY_FILE_FORMAT print_h1('Generate a new key for the zone %s' % zone) key_path = os.path.join(DEFAULT_CFG_DIR, ZONE_KEYS_DIRECTORY_NAME, GOSSIP_KEY_FILE_FORMAT % zone) if os.path.exists(key_path) and not erase: cprint('ERROR: the key %s is already existing', color='red') cprint( ' %s Note: You can use the --erase parameter to erase over an existing key' % (CHARACTERS.corner_bottom_left), color='grey') sys.exit(2) k = uuid.uuid1().hex[:16] b64_k = base64.b64encode(k) cprint('Encryption key for the zone ', end='') cprint(zone, color='magenta', end='') cprint(' :', end='') cprint(b64_k, color='green') _save_key(b64_k, zone, key_path)
def do_generators_history(): uri = '/generators/history' try: (code, r) = get_opsbro_local(uri) except get_request_errors() as exp: logger.error(exp) return try: histories = jsoner.loads(r) except ValueError as exp: # bad json logger.error('Bad return from the server %s' % exp) return print_h1('Generators history') for history in histories: epoch = history['date'] entries = history['entries'] print_h2(' Date: %s ' % time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(epoch))) for entry in entries: cprint(' - %s' % entry['pack_name'], color='blue', end='') __print_generator_entry(entry, show_diff=True) cprint("\n")
def do_members(detail=False): # The information is available only if the agent is started wait_for_agent_started(visual_wait=True) try: members = get_opsbro_json('/agent/members').values() except get_request_errors() as exp: logger.error('Cannot join opsbro agent to list members: %s' % exp) sys.exit(1) members = my_sort(members, cmp_f=__sorted_members) pprint = libstore.get_pprint() logger.debug('Raw members: %s' % (pprint.pformat(members))) # If there is a display_name, use it max_name_size = max([ max(len(m['name']), len(m.get('display_name', '')) + 4) for m in members ]) max_addr_size = max( [len(m['addr']) + len(str(m['port'])) + 1 for m in members]) zones = set() for m in members: mzone = m.get('zone', '') if mzone == '': mzone = NO_ZONE_DEFAULT m['zone'] = mzone # be sure to fix broken zones zones.add(mzone) zones = list(zones) zones.sort() for z in zones: z_display = z if not z: z_display = NO_ZONE_DEFAULT z_display = z_display.ljust(15) title_s = '%s: %s' % (sprintf('Zone', color='yellow', end=''), sprintf(z_display, color='blue', end='')) print_h1(title_s, raw_title=True) for m in members: zone = m.get('zone', NO_ZONE_DEFAULT) if zone != z: continue name = m['name'] if m.get('display_name', ''): name = '[ ' + m.get('display_name') + ' ]' groups = m.get('groups', []) groups.sort() port = m['port'] addr = m['addr'] state = m['state'] is_proxy = m.get('is_proxy', False) if not detail: cprint(' - %s > ' % zone, color='blue', end='') cprint('%s ' % name.ljust(max_name_size), color='magenta', end='') else: cprint(' %s %s ' % (m['uuid'], name.ljust(max_name_size)), end='') c = NODE_STATE_COLORS.get(state, 'cyan') state_prefix = NODE_STATE_PREFIXS.get( state, CHARACTERS.double_exclamation) cprint(('%s %s' % (state_prefix, state)).ljust(9), color=c, end='') # 7 for the maximum state string + 2 for prefix s = ' %s:%s ' % (addr, port) s = s.ljust(max_addr_size + 2) # +2 for the spaces cprint(s, end='') if is_proxy: cprint('proxy ', end='') else: cprint(' ', end='') if detail: cprint('%5d' % m['incarnation'], end='') cprint(' %s ' % ','.join(groups))
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)
def do_state(name=''): uri = '/monitoring/state/%s' % name if not name: uri = '/monitoring/state' try: (code, r) = get_opsbro_local(uri) except get_request_errors() as exp: logger.error(exp) return try: d = jsoner.loads(r) except ValueError as exp: # bad json logger.error('Bad return from the server %s' % exp) return services = d['services'] print_h1('Services') if len(services) == 0: cprint('No services', color='grey') else: for (sname, service) in services.items(): state = service['state_id'] cprint('\t%s ' % sname.ljust(20), end='') c = {0: 'green', 2: 'red', 1: 'yellow', 3: 'cyan'}.get(state, 'cyan') state = {0: 'OK', 2: 'CRITICAL', 1: 'WARNING', 3: 'UNKNOWN'}.get(state, 'UNKNOWN') cprint('%s - ' % state.ljust(8), color=c, end='') output = service['check']['output'] cprint(output.strip(), color='grey') checks = d['checks'] if len(checks) == 0: cprint('No checks', color='grey') return # nothing to do more print_h1('Checks') packs = {} for (cname, check) in checks.items(): pack_name = check['pack_name'] if pack_name not in packs: packs[pack_name] = {} packs[pack_name][cname] = check pnames = list(packs.keys()) pnames.sort() for pname in pnames: pack_entries = packs[pname] cprint('* Pack %s' % pname, color='blue') cnames = list(pack_entries.keys()) cnames.sort() for cname in cnames: check = pack_entries[cname] check_display_name = check['display_name'] cprint(' - %s' % pname, color='blue', end='') cprint(' > checks > ', color='grey', end='') cprint('%s ' % (check_display_name.ljust(30)), color='magenta', end='') state = check['state_id'] c = STATE_ID_COLORS.get(state, 'cyan') state = STATE_ID_STRINGS.get(state, 'UNKNOWN') cprint('%s' % state.ljust(10), color=c) # Now print output the line under output = check['output'] output_lines = output.strip().splitlines() for line in output_lines: cprint(' ' * 4 + '| ' + line, color='grey')
def do_packs_show(): logger.setLevel('ERROR') # We should already have load the configuration, so just dump it # now we read them, set it in our object from opsbro.packer import packer packs = {'core': {}, 'global': {}, 'zone': {}, 'local': {}} for level in packer.packs: for pname in packer.packs[level]: packs[level][pname] = { 'checks': {}, 'module': None, 'collectors': {}, 'generators': {} } from opsbro.monitoring import monitoringmgr checks = monitoringmgr.checks for cname, check in checks.items(): pack_name = check['pack_name'] pack_level = check['pack_level'] packs[pack_level][pack_name]['checks'][cname] = check from opsbro.modulemanager import modulemanager modules = modulemanager.modules for module in modules: pack_name = module.pack_name pack_level = module.pack_level packs[pack_level][pack_name]['module'] = module from opsbro.collectormanager import collectormgr collectors = collectormgr.collectors for colname, collector in collectors.items(): pack_name = collector['inst'].pack_name pack_level = collector['inst'].pack_level packs[pack_level][pack_name]['collectors'][colname] = collector from opsbro.generatormgr import generatormgr generators = generatormgr.generators for gname, generator in generators.items(): pack_name = generator.pack_name pack_level = generator.pack_level packs[pack_level][pack_name]['generators'][gname] = generator for level in ('core', 'global', 'zone', 'local'): s1 = sprintf('Packs at level ', color='yellow', end='') s2 = sprintf(level, color='blue', end='') print_h1(s1 + s2, raw_title=True) pack_names = list(packs[level].keys()) pack_names.sort() if len(pack_names) == 0: cprint(' No packs are available at the level %s' % level, color='grey') continue for pack_name in pack_names: pack_entry = packs[level][pack_name] pack_breadcumb_s = __get_pack_breadcumb(pack_name, level) cprint(pack_breadcumb_s) main_topic, secondary_topics = packer.get_pack_main_and_secondary_topics( pack_name) main_topic_color = topiker.get_color_id_by_topic_string(main_topic) if main_topic != 'generic': __print_line_header(main_topic_color) cprint(u' * Main topic: ', color='grey', end='') s = lolcat.get_line(main_topic, main_topic_color, spread=None) cprint(s) if secondary_topics: _numeral = 's' if len(secondary_topics) > 1 else '' s = u' * Secondary topic%s: %s' % (_numeral, ', '.join(secondary_topics)) __print_line_header(main_topic_color) cprint(s, color='grey') #### Now loop over objects # * checks # * module # * collectors # * handlers # * generators no_such_objects = [] checks = pack_entry['checks'] if len(checks) == 0: no_such_objects.append('checks') else: __print_line_header(main_topic_color) print_element_breadcumb(pack_name, pack_level, 'checks') cprint(' (%d)' % len(checks), color='magenta') for cname, check in checks.items(): __print_line_header(main_topic_color) cprint(' - ', end='') cprint('checks > %-15s' % cname.split(os.sep)[-1], color='cyan', end='') cprint(' if_group=%s' % (check['if_group'])) # Module module = pack_entry['module'] if module is None: no_such_objects.append('module') else: __print_line_header(main_topic_color) print_element_breadcumb(pack_name, pack_level, 'module') # cprint(' : configuration=', end='') cprint('') offset = 0 __print_element_parameters(module, pack_name, pack_level, main_topic_color, 'parameters', offset) # collectors collectors = pack_entry['collectors'] if len(collectors) == 0: no_such_objects.append('collectors') else: __print_line_header(main_topic_color) print_element_breadcumb(pack_name, pack_level, 'collectors') cprint(' (%d)' % len(collectors), color='magenta') for colname, collector_d in collectors.items(): __print_line_header(main_topic_color) collector = collector_d['inst'] cprint(' - ', end='') cprint('collectors > %-15s' % colname, end='', color='cyan') cprint('') offset = 1 __print_element_parameters(collector, pack_name, pack_level, main_topic_color, 'parameters', offset) # generators generators = pack_entry['generators'] if len(generators) == 0: no_such_objects.append('generators') else: __print_line_header(main_topic_color) print_element_breadcumb(pack_name, pack_level, 'generators') cprint(' (%d)' % len(generators), color='magenta') for gname, generator in generators.items(): __print_line_header(main_topic_color) cprint(' - ', end='') cprint('generators > %-15s' % gname.split(os.sep)[-1], color='cyan', end='') cprint(' generate_if=%s' % generator.generate_if) # Display what the pack do not manage (for info) if no_such_objects: __print_line_header(main_topic_color) cprint(' * The pack do not provide objects: %s' % ','.join(no_such_objects), color='grey') cprint('')
# By default logger should not print anything core_logger.setLevel('ERROR') # By maybe we are in verbose more? if '-v' in sys.argv or os.environ.get('DEBUG_INSTALL', '0') == '1': core_logger.setLevel('DEBUG') core_logger.debug('SCRIPT: install/update script was call with arguments: %s' % orig_sys_argv) what = 'Installing' if not is_update else 'Updating' title = sprintf('%s' % what, color='magenta', end='') + sprintf( ' OpsBro to version ', end='') + sprintf( '%s' % VERSION, color='magenta', end='') if allow_black_magic: print_h1(title, raw_title=False) ################################## Start to print to the user if allow_black_magic: # If we have a real tty, we can print the delicious banner with lot of BRO if is_tty(): cprint(BANNER) else: # ok you are poor, just got some ascii art then cprint(TXT_BANNER) # Also print a Bro quote quote, from_film = get_quote() cprint(' >> %s (%s)\n' % (quote, from_film), color='grey') if allow_black_magic: if is_update: cprint(' Previous OpsBro lib detected on this system:')