Esempio n. 1
0
 def add_interfaces(self, interface_data):
     '''
     Value interface_name (\S+)
     Value service_instance (\d+)
     '''
     index = InterfaceUfinet.get_normalize_interface_name(
         interface_data["interface_name"])
     if index != '':
         if "BDI" in index:
             self.routed_interface = index
         else:
             self.interfaces[index] = interface_data
Esempio n. 2
0
    def set_interfaces_db(self):
        self.uid_dict()
        self.verbose.warning(f'set_interfaces_db INIT')
        sql = InterfaceUfinet.sql_today_last_polled_interfaces(self.values())

        data_interfaces = self.dict_from_sql(sql=sql)

        data_segmented_by_uid = defaultdict(list)
        for row in data_interfaces:
            data_segmented_by_uid[row['net_device_uid']].append(row)

        for device in self:
            device.set_interfaces_data(
                interfaces_data=data_segmented_by_uid[device.uid])
        self.verbose.warning(f'set_interfaces_db FINISH')
Esempio n. 3
0
    def set_interfaces_db_period(self, period_start, period_end):
        self.uid_dict()
        sql = InterfaceUfinet.sql_last_period_polled_interfaces(
            devices=self.values(),
            date_start=period_start,
            date_end=period_end)
        print(sql)
        data_interfaces = self.dict_from_sql(sql=sql)
        print(data_interfaces)
        data_segmented_by_uid = defaultdict(list)
        for row in data_interfaces:
            data_segmented_by_uid[row['net_device_uid']].append(row)

        for device in self:
            device.set_interfaces_data(
                interfaces_data=data_segmented_by_uid[device.uid])
Esempio n. 4
0
    def add_vfi(self, vfi_data):
        '''
                Value Filldown bride_domain (\d+)
                Value interface_name (\S+)
                Value neighbor_ip ((\d{1,3}\.){3}\d{1,3})
                Value vfi_vc_id (\d+)

                :return:
                '''
        index = InterfaceUfinet.get_normalize_interface_name(
            vfi_data["interface_name"])
        if index != '':
            if index not in self.vfis:
                self.vfis[index] = [vfi_data]
            else:
                self.vfis[index].append(vfi_data)
Esempio n. 5
0
def data_interfaces():
    request.get_json()
    grupo_interfaces = request.json['grupo_interfaces']
    month = datetime.date.today().month
    year = datetime.date.today().year
    last_day = calendar.monthrange(year, month)[1]
    initial_date = '{year}-{month}-{day} 00:00:00'.format(year=year, month=month, day=1) \
        if request.json['initial_date'] == '' else request.json['initial_date'] + ' 00:00:00'
    end_date = '{year}-{month}-{day} 23:59:59'.format(year=year, month=month, day=last_day) \
        if request.json['end_date'] == '' else request.json['end_date'] + ' 00:00:00'

    data = InterfaceUfinet.interface_states_data_by_date(
        master=master,
        initial_date=initial_date,
        end_date=end_date,
        filter_keys=InterfaceUfinet.FILTERS_GROUP[grupo_interfaces])

    pass
Esempio n. 6
0
def json_group_interfaces():
    request.get_json()
    pprint(request.json)
    group_interfaces = request.json['group_interfaces']
    month = datetime.date.today().month
    year = datetime.date.today().year
    last_day = calendar.monthrange(year, month)[1]
    initial_date = '{year}-{month}-{day} 00:00:00'.format(year=year, month=month, day=1) \
        if request.json['initial_date'] == '' else request.json['initial_date'] + ' 00:00:00'
    end_date = '{year}-{month}-{day} 23:59:59'.format(year=year, month=month, day=last_day) \
        if request.json['end_date'] == '' else request.json['end_date'] + ' 00:00:00'

    data = InterfaceUfinet.interface_states_data_by_date_query(
        master=master,
        initial_date=initial_date,
        end_date=end_date,
        sql_filters=InterfaceUfinet.FILTERS_GROUP[group_interfaces],
        sort=InterfaceUfinet.ORDER_BY_INTERFFACE_GROUPS[group_interfaces])

    return jsonify(data)
Esempio n. 7
0
def json_interfaces_cisco():
    request.get_json()
    month = datetime.date.today().month
    year = datetime.date.today().year
    last_day = calendar.monthrange(year, month)[1]
    initial_date = '{year}-{month}-{day} 00:00:00'.format(year=year, month=month, day=1) \
        if request.json['initial_date'] == '' else request.json['initial_date'] + ' 00:00:00'
    end_date = '{year}-{month}-{day} 23:59:59'.format(year=year, month=month, day=last_day) \
        if request.json['end_date'] == '' else request.json['end_date'] + ' 00:00:00'

    cantidad_interfaces = int(request.json['cantidad_interfaces'])
    grupo_interfaces = request.json['grupo_interfaces']
    weblog.warning(
        f'InterfaceUfinet.FILTERS_GROUP[grupo_interfaces] {InterfaceUfinet.FILTERS_GROUP[grupo_interfaces]}'
    )
    data = InterfaceUfinet.interface_states_data_by_date(
        master=master,
        initial_date=initial_date,
        end_date=end_date,
        filter_keys=InterfaceUfinet.FILTERS_GROUP[grupo_interfaces])
    data_grupo = data[grupo_interfaces]
    cantidad_interfaces = cantidad_interfaces - 1 if len(
        data_grupo) >= cantidad_interfaces else len(cantidad_interfaces) - 1
    return jsonify(data_grupo[0:cantidad_interfaces])
Esempio n. 8
0
 def save_interfaces(self):
     InterfaceUfinet.save_bulk_states_devices(self)