Esempio n. 1
0
    def create_map(self, font_path_fn: str, icon_path: str):
        self.obj_nodes = {section: None for section in self.cfg_dict if 'node-' in section}
        self.obj_links = {section: None for section in self.cfg_dict if 'link-' in section}
        palette = self.cfg_dict['palette']
        fontsize = int(self.cfg_dict['map']['fontsize'])

        for node in self.obj_nodes.keys():
            x = int(self.cfg_dict[node]['x'])
            y = int(self.cfg_dict[node]['y'])

            if self.cfg_dict[node].get('label'):
                label = self.cfg_dict[node]['label']
            else:
                label = None

            if self.cfg_dict[node].get('icon'):
                icon = self.cfg_dict[node]['icon']
            else:
                icon = None

            self.obj_nodes[node] = (Node(font_path_fn, icon_path, x=x, y=y, label=label, icon=icon, fontsize=fontsize))

        for link in self.obj_links.keys():
            node1 = self.obj_nodes[self.cfg_dict[link]['node1']]
            node2 = self.obj_nodes[self.cfg_dict[link]['node2']]

            if self.cfg_dict[link].get('bandwidth'):
                bandwidth = self.cfg_dict[link]['bandwidth']
            else:
                bandwidth = self.cfg_dict['link']['bandwidth']

            if self.cfg_dict[link].get('width'):
                width = self.cfg_dict[link]['width']
            else:
                width = self.cfg_dict['link']['width']

            hostname = self.cfg_dict[link]['hostname']
            item_in = self.cfg_dict[link]['itemin']
            item_out = self.cfg_dict[link]['itemout']
            self.obj_links[link] = (Link(font_path_fn, node1, node2, bandwidth=bandwidth, width=width,
                                         palette=palette, fontsize=fontsize))
            data_in, data_out = self.zbx.get_item_data2(hostname, item_in, item_out)
            self.obj_links[link].data(in_bps=data_in, out_bps=data_out)

        if int(self.cfg_dict['table']['show']):
            table = Table(font_path_fn, x=int(self.cfg_dict['table']['x']), y=int(self.cfg_dict['table']['y']),
                          palette=palette)
        else:
            table = None

        map_width = int(self.cfg_dict['map']['width'])
        map_height = int(self.cfg_dict['map']['height'])
        if self.cfg_dict['map']['bgcolor']:
            map_bgcolor = self.cfg_dict['map']['bgcolor']
        else:
            map_bgcolor = None
        map_obj = Map(self.obj_links.values(), self.obj_nodes.values(), table=table, len_x=map_width,
                      len_y=map_height, bgcolor=map_bgcolor)
        return map_obj
    def create_map(self, font_path_fn, icon_path):
        palette = [self.cfg_dict['palette'][key] for key in sorted(self.cfg_dict['palette'])]
        fontsize = int(self.cfg_dict['map']['fontsize'])

        for node in self.obj_nodes.keys():
            x = int(self.cfg_dict[node]['x'])
            y = int(self.cfg_dict[node]['y'])
            label = self.cfg_dict[node]['label']
            icon = self.cfg_dict[node]['icon']
            self.obj_nodes[node] = (Node(font_path_fn, icon_path, x=x, y=y, label=label, icon=icon, fontsize=fontsize))

        for link in self.obj_links.keys():
            node1 = self.obj_nodes[self.cfg_dict[link]['node1']]
            node2 = self.obj_nodes[self.cfg_dict[link]['node2']]
            bandwidth = int(self.cfg_dict[link]['bandwidth'])
            width = int(self.cfg_dict[link]['width'])
            hostname = self.cfg_dict[link]['hostname']
            item_in = self.cfg_dict[link]['itemin']
            item_out = self.cfg_dict[link]['itemout']
            self.obj_links[link] = (Link(font_path_fn, node1, node2, bandwidth=bandwidth, width=width,
                                         palette=palette, fontsize=fontsize))
            data_in, data_out = self.zbx.get_item_data2(hostname, item_in, item_out)
            self.obj_links[link].data(in_bps=data_in, out_bps=data_out)

        if int(self.cfg_dict['table']['show']):
            table = Table(font_path_fn, x=int(self.cfg_dict['table']['x']), y=int(self.cfg_dict['table']['y']),
                          palette=palette)
        else:
            table = None

        map_width = int(self.cfg_dict['map']['width'])
        map_height = int(self.cfg_dict['map']['height'])
        if self.cfg_dict['map']['bgcolor']:
            map_bgcolor = self.cfg_dict['map']['bgcolor']
        else:
            map_bgcolor = None
        map_obj = Map(self.obj_links.values(), self.obj_nodes.values(), table=table, len_x=map_width,
                      len_y=map_height, bgcolor=map_bgcolor)
        return map_obj
    def setUp(self):
        self.hash = '43228a6d34e15561dcb179a9e4388489e4634093348a57f34801a12fd548f203'
        self.root_path = str(os.path.dirname(os.path.abspath(__file__))).replace('tests', '')
        self.font_path = self.root_path + 'fonts'
        self.font_path_fn = self.root_path + 'fonts/DejaVuSansMono.ttf'
        self.icon_path = self.root_path + 'icons'
        self.cfg_path = self.root_path + 'mapcfgs'
        self.img_path = self.root_path + 'mapimgs'

        a = Node(self.font_path_fn, self.icon_path, x=300, y=30, label='host-A', icon='Router96.png')
        b = Node(self.font_path_fn, self.icon_path, x=750, y=30, label='host-B', icon='Router96.png')
        c = Node(self.font_path_fn, self.icon_path, x=30, y=750, label='host C', icon='Router96.png')
        d = Node(self.font_path_fn, self.icon_path, x=750, y=750, label='HOST-D', icon='Router96.png')
        e = Node(self.font_path_fn, self.icon_path, x=400, y=400, label='host-E', icon='Router96.png')

        link_a = Link(self.font_path_fn, a, e, bandwidth=1000, width=10)
        link_a.data(in_bps=0, out_bps=123345123)
        link_b = Link(self.font_path_fn, b, e, bandwidth=100, width=15)
        link_b.data(in_bps=54123456, out_bps=114987654)
        link_c = Link(self.font_path_fn, c, e, bandwidth=10000)
        link_c.data(in_bps=841123456, out_bps=5147987654)
        link_d = Link(self.font_path_fn, d, e, bandwidth=100, width=15)
        link_d.data(in_bps=73456852, out_bps=987654)
        link_e = Link(self.font_path_fn, a, b, bandwidth=100, width=15)
        link_e.data(in_bps=73456852, out_bps=987654)

        table = Table(self.font_path_fn, x=700, y=350, dt=False)
        self.new_map = Map([link_a, link_b, link_c, link_d, link_e], [a, b, c, d, e], table=table, len_x=800, len_y=800)
Esempio n. 4
0
    def setUp(self):
        self.hash = 'fd6069568a5d453a8572fbfafb517f14115bc093deee67554c468b61ac734d61'
        self.root_path = str(os.path.dirname(
            os.path.abspath(__file__))).replace('tests', '')
        self.font_path = self.root_path + 'fonts'
        self.font_path_fn = self.root_path + 'fonts/DejaVuSansMono.ttf'
        self.icon_path = self.root_path + 'icons'
        self.cfg_path = self.root_path + 'mapcfgs'
        self.img_path = self.root_path + 'mapimgs'

        a = Node(self.font_path_fn,
                 self.icon_path,
                 x=300,
                 y=30,
                 label='host-A',
                 icon='Router96.png')
        b = Node(self.font_path_fn,
                 self.icon_path,
                 x=750,
                 y=30,
                 label='host-B',
                 icon='Router96.png')
        c = Node(self.font_path_fn,
                 self.icon_path,
                 x=30,
                 y=750,
                 label='host C',
                 icon='Router96.png')
        d = Node(self.font_path_fn,
                 self.icon_path,
                 x=750,
                 y=750,
                 label='HOST-D',
                 icon='Router96.png')
        e = Node(self.font_path_fn,
                 self.icon_path,
                 x=400,
                 y=400,
                 label='host-E',
                 icon='Router96.png')

        link_a = Link(self.font_path_fn, a, e, bandwidth=1000, width=10)
        link_a.data(in_bps=0, out_bps=123345123)
        link_b = Link(self.font_path_fn, b, e, bandwidth=100, width=15)
        link_b.data(in_bps=54123456, out_bps=114987654)
        link_c = Link(self.font_path_fn, c, e, bandwidth=10000)
        link_c.data(in_bps=841123456, out_bps=5147987654)
        link_d = Link(self.font_path_fn, d, e, bandwidth=100, width=15)
        link_d.data(in_bps=73456852, out_bps=987654)
        link_e = Link(self.font_path_fn, a, b, bandwidth=100, width=15)
        link_e.data(in_bps=73456852, out_bps=987654)

        table = Table(self.font_path_fn, x=700, y=350, dt=False)
        self.new_map = Map([link_a, link_b, link_c, link_d, link_e],
                           [a, b, c, d, e],
                           table=table,
                           len_x=800,
                           len_y=800)
    def setUp(self):
        self.hash = 'fd6069568a5d453a8572fbfafb517f14115bc093deee67554c468b61ac734d61'
        self.root_path = str(os.path.dirname(os.path.abspath(__file__))).replace('tests', '')
        self.font_path = self.root_path + 'fonts'
        self.font_path_fn = self.root_path + 'fonts/DejaVuSansMono.ttf'
        self.icon_path = self.root_path + 'icons'
        self.cfg_path = self.root_path + 'mapcfgs'
        self.img_path = self.root_path + 'mapimgs'

        a = Node(self.font_path_fn, self.icon_path, x=300, y=30, label='host-A', icon='Router96.png')
        b = Node(self.font_path_fn, self.icon_path, x=750, y=30, label='host-B', icon='Router96.png')
        c = Node(self.font_path_fn, self.icon_path, x=30, y=750, label='host C', icon='Router96.png')
        d = Node(self.font_path_fn, self.icon_path, x=750, y=750, label='HOST-D', icon='Router96.png')
        e = Node(self.font_path_fn, self.icon_path, x=400, y=400, label='host-E', icon='Router96.png')

        link_a = Link(self.font_path_fn, a, e, bandwidth=1000, width=10)
        link_a.data(in_bps=0, out_bps=123345123)
        link_b = Link(self.font_path_fn, b, e, bandwidth=100, width=15)
        link_b.data(in_bps=54123456, out_bps=114987654)
        link_c = Link(self.font_path_fn, c, e, bandwidth=10000)
        link_c.data(in_bps=841123456, out_bps=5147987654)
        link_d = Link(self.font_path_fn, d, e, bandwidth=100, width=15)
        link_d.data(in_bps=73456852, out_bps=987654)
        link_e = Link(self.font_path_fn, a, b, bandwidth=100, width=15)
        link_e.data(in_bps=73456852, out_bps=987654)

        table = Table(self.font_path_fn, x=700, y=350, dt=False)
        self.new_map = Map([link_a, link_b, link_c, link_d, link_e], [a, b, c, d, e], table=table, len_x=800, len_y=800)