Beispiel #1
0
def __get_pack_breadcumb(pack_name, pack_level, end='', topic_picto='large'):
    pack_topics = packer.get_pack_all_topics(pack_name)
    pack_main_topic = 'generic'
    if len(pack_topics) != 0:
        pack_main_topic = pack_topics[0]
    topic_color = topiker.get_color_id_by_topic_string(pack_main_topic)
    if topic_picto == 'large':
        picto = u'%s%s ' % (CHARACTERS.corner_top_left, CHARACTERS.hbar * 2)
    else:
        picto = u'%s ' % CHARACTERS.topic_small_picto
    res = lolcat.get_line(picto, topic_color, spread=None) \
          + sprintf('%-6s' % pack_level, color='blue', end='') \
          + sprintf(' > ', end='') \
          + sprintf('%-15s' % pack_name, color='yellow', end='') \
          + end
    
    return res
Beispiel #2
0
    def display(self, title):
        terminal_height, terminal_width = get_terminal_size()

        # Clear the terminal
        cprint('\033c')

        tbox = TBox(1, 0, terminal_width, terminal_height -
                    2)  # -1 for title, -1 for the ending line

        # Show the title at the first line
        self._jump_to(0, 0)

        # Put OpsBro title on all dashboards
        cprint(u' %s' % TITLE_COLOR, end='')

        # Put the title in the middle of the first line
        title = u'ʃ %s ʅ' % title
        l_title = len(title)
        title = lolcat.get_line(title, 1, spread=1)
        self._jump_to(0, int((terminal_width / 2) - (l_title / 2)))
        cprint(title, end='')

        time_format = time.strftime("%H:%M")
        self._jump_to(0, terminal_width - len(time_format) - 1)
        cprint(time_format, color='white', end='')

        # Now display the other box
        self._display(tbox, None)

        self._jump_to(terminal_height - 1, 0)
        cprint(' http://opsbro.io (by Shinken Solutions team)',
               color='grey',
               end='')

        quote, from_film = get_quote()
        full_quote = '>> %s  (%s)' % (quote, from_film)
        l_full_quote = len(full_quote)
        self._jump_to(terminal_height - 1, terminal_width - l_full_quote)
        cprint(full_quote, color='grey', end='')

        # park cursor in a safe place and reset color
        self._jump_to(terminal_height, -1)
        sys.stdout.flush()
Beispiel #3
0
def colorize(s, color):
    """**colorize(s, color)** -> return the string s with the color (ainsi)

 * s: (string) string to colorize
 * color: (int between 1 -> 64) ainsi color

<code>
    Example:
        colorize('my string', 55)
    Returns:
        \x1b[55Dmy string\x1b[0m
</code>
    """
    if not isinstance(s, basestring):
        try:
            s = unicode(s)
        except:
            return ''
    return lolcat.get_line(s, color, spread=None)
Beispiel #4
0
    def _display(self, tbox, parent):
        self._refresh_value()
        self.title = self.title_orig + (': %d %s' % (self.value, self.unit))

        tbox = self._draw_borders_and_title(tbox)

        box_height = tbox.h
        box_width = tbox.w

        for line_idx in range(box_height):
            # get a degraded color, wil be the same for all the line
            pct = 1.0 * line_idx / box_height
            line_color = colorpalette.get_color_from_percent_between_0_1(pct)
            bar = ''
            for col_idx in range(box_width):
                dp_index = (col_idx - box_width) * 2
                try:
                    value_1 = self.datapoints[dp_index]
                    value_2 = self.datapoints[dp_index + 1]
                except IndexError:
                    # no data (yet)
                    # and no color too, useful for quick debug by hightlight shell :)
                    bar += ' '
                    continue
                # TODO: manage more than % here, with min/max
                v1_ratio = value_1 / 100.0
                v2_ratio = value_2 / 100.0
                y_v1 = (1 - v1_ratio) * box_height
                y_v2 = (1 - v2_ratio) * box_height
                index1 = self._get_braille_idx_from_pos(y_v1, line_idx)
                index2 = self._get_braille_idx_from_pos(y_v2, line_idx)

                char = self._generate_braille(index1, index2)

                color_char = lolcat.get_line(char, line_color, spread=None)
                bar += color_char

            self._jump_to(tbox.x + line_idx, tbox.y)
            cprint(bar, end='')
Beispiel #5
0
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')
Beispiel #6
0
def __print_topic_header(TOPIC_ID):
    topic_color = TOPICS_COLORS[TOPIC_ID]
    picto = u'%s%s %s' % (CHARACTERS.corner_top_left, CHARACTERS.hbar * 19,
                          TOPICS_LABELS[TOPIC_ID])
    cprint(lolcat.get_line(picto, topic_color, spread=None))
Beispiel #7
0
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('')
Beispiel #8
0
def __print_line_header(main_topic_color):
    cprint(lolcat.get_line(CHARACTERS.vbar, main_topic_color, spread=None),
           end='')
Beispiel #9
0
    u'┏ service discovery', u'┗ automatic detection', u'┏ monitoring',
    u'┗ metrology', u'┏ configuraton automation', u'┗ system compliance'
]
ordered = []
for t in what:
    color = 0
    for (i, w) in elements.iteritems():
        if t == w:
            color = i
    ordered.append((t, color))

for (i, c) in enumerate(TEST_CHARS):
    cprint(u'%d : %s' % (i, c))

base_text = 'A'
for i in xrange(0, 512):
    # if i not in elements:
    #    continue
    text = elements.get(i, '%d : %s' % (i, base_text))
    lol_txt = lolcat.get_line(text, i, spread=None)
    cprint(lol_txt)

print "'''''''''''''''''''''\n\n"
for (text, color) in ordered:
    lol_txt = lolcat.get_line(text, color, spread=None)
    cprint(lol_txt)

for i in range(00, 700):
    print "\033[74m %d " % i,
    cprint('%s' % unichr(i), color='red')