Ejemplo n.º 1
0
def monitoring_se_post():
    logger.info('POST monitoring-data({0}). -start-'.format(const.TYPE_MON_SE))
    try:
        # get request body.(xml message.)
        param_list = request.body
        param_string = ""
        for row in param_list:
            param_string += row
        if not param_string:
            logger.warn('no message.')
            return HTTPResponse(
                "POST monitoring-data({0}) error.(request body is empty.)".
                format(const.TYPE_MON_SE),
                status=400)
        logger.debug(param_string)

        # lock -start-
        with util.semaphore_md:
            # open topology database connection.
            tpldb_setup()

            # upload all monitoring-data to DB.
            mon_data_dict = db_upld.cleate_monitoring_data_dict(param_string)
            if not mon_data_dict:
                logger.warn('parse monitoring-data xml error.')
                return HTTPResponse(
                    "POST monitoring-data({0}) error.(parse monitoring-data xml error.)"
                    .format(const.TYPE_MON_SE),
                    status=400)
            val_dict_list = db_upld.cleate_upload_data_list(mon_data_dict)
        # lock -end-
        db_upld.upload_monitoring_data_all(val_dict_list)

        # forwarding master-monitoring-server
        if mon_data_dict[const.XML_ATTR_FWD] == True:
            logger.debug(
                'forward monitoring-data.(post_uri={0})'.format(POST_URI))
            res_flg, res = post_md(POST_URI, param_string, 'no')
            if res_flg is False:
                logger.error('forward monitoring-data error.')
            if res:
                logger.debug("HTTP Response({0}):{1}".format(
                    res.status_code, res.text))

    except Exception:
        logger.exception('POST monitoring-data({0}) error.'.format(
            const.TYPE_MON_SE))
        return HTTPResponse("POST monitoring-data({0}) error.".format(
            const.TYPE_MON_SE),
                            status=500)

    finally:
        # close topology database connection.
        tpldb_close()
    logger.info('POST monitoring-data({0}). -end-'.format(const.TYPE_MON_SE))

    return
Ejemplo n.º 2
0
def monitoring_se_post():
    logger.info('POST monitoring-data({0}). -start-'.format(const.TYPE_MON_SE))
    try:
        # get request body.(xml message.)
        param_list=request.body
        param_string=""
        for row in param_list:
            param_string += row
        if not param_string:
            logger.warn('no message.')
            return HTTPResponse("POST monitoring-data({0}) error.(request body is empty.)"
                                .format(const.TYPE_MON_SE), status=400)
        logger.debug(param_string)
    
        # lock -start-
        with util.semaphore_md:
            # open topology database connection.
            tpldb_setup()
    
            # upload all monitoring-data to DB.
            mon_data_dict = db_upld.cleate_monitoring_data_dict(param_string)
            if not mon_data_dict:
                logger.warn('parse monitoring-data xml error.')
                return HTTPResponse("POST monitoring-data({0}) error.(parse monitoring-data xml error.)"
                                    .format(const.TYPE_MON_SE), status=400)
            val_dict_list = db_upld.cleate_upload_data_list(mon_data_dict)
        # lock -end-
        db_upld.upload_monitoring_data_all(val_dict_list)

        # forwarding master-monitoring-server
        if mon_data_dict[const.XML_ATTR_FWD] == True:
            logger.debug('forward monitoring-data.(post_uri={0})'.format(POST_URI))
            res_flg,res = post_md(POST_URI,param_string,'no')
            if res_flg is False:
                logger.error('forward monitoring-data error.')
            if res:
                logger.debug("HTTP Response({0}):{1}".format(res.status_code,res.text))
                
    except Exception:
        logger.exception('POST monitoring-data({0}) error.'.format(const.TYPE_MON_SE))
        return HTTPResponse("POST monitoring-data({0}) error."
                            .format(const.TYPE_MON_SE), status=500)

    finally:
        # close topology database connection.
        tpldb_close()
    logger.info('POST monitoring-data({0}). -end-'.format(const.TYPE_MON_SE))

    return
Ejemplo n.º 3
0
def monitoring_tn_post():
    logger.info('POST monitoring-data({0}). -start-'.format(const.TYPE_MON_TN))
    try:
        # get request body.(xml message.)
        param_list = request.body
        param_string = ""
        for row in param_list:
            param_string += row
        if not param_string:
            logger.warn('no message.')
            return HTTPResponse(
                "POST monitoring-data({0}) error.(request body is empty.)".
                format(const.TYPE_MON_TN),
                status=400)
        logger.debug(param_string)

        # upload all monitoring-data to DB.
        mon_data_dict = db_upld.upload_monitoring_data_all(param_string)
        if not mon_data_dict:
            logger.warn('parse monitoring-data xml error.')
            return HTTPResponse(
                "POST monitoring-data({0}) error.(parse monitoring-data xml error.)"
                .format(const.TYPE_MON_TN),
                status=400)

        # forwarding master-monitoring-server
        if mon_data_dict[const.XML_ATTR_FWD] == True:
            logger.debug(
                'forward monitoring-data.(post_uri={0})'.format(POST_URI))
            res_flg, res = post_md(POST_URI, param_string, 'no')
            if res_flg is False:
                logger.error('forward monitoring-data error.')
            if res:
                logger.debug("HTTP Response({0}):{1}".format(
                    res.status_code, res.text))

    except Exception:
        logger.exception('POST monitoring-data({0}) error.'.format(
            const.TYPE_MON_TN))
        return HTTPResponse("POST monitoring-data({0}) error.".format(
            const.TYPE_MON_TN),
                            status=500)

    logger.info('POST monitoring-data({0}). -end-'.format(const.TYPE_MON_TN))

    return
Ejemplo n.º 4
0
def monitoring_cp_post():
    logger.info('POST monitoring-data({0}). -start-'.format(const.TYPE_MON_CP))
    try:
        # get request body.(xml message.)
        param_list=request.body
        param_string=""
        for row in param_list:
            param_string += row
        if not param_string:
            logger.warn('no message.')
            return HTTPResponse("POST monitoring-data({0}) error.(request body is empty.)"
                                .format(const.TYPE_MON_CP), status=400)
        logger.debug(param_string)

        # upload all monitoring-data to DB.
        mon_data_dict = db_upld.upload_monitoring_data_all(param_string)
        if not mon_data_dict:
            logger.warn('parse monitoring-data xml error.')
            return HTTPResponse("POST monitoring-data({0}) error.(parse monitoring-data xml error.)"
                                .format(const.TYPE_MON_CP), status=400)
        
        # forwarding master-monitoring-server
        if mon_data_dict[const.XML_ATTR_FWD] == True:
            logger.debug('forward monitoring-data.(post_uri={0})'.format(POST_URI))
            res_flg,res = post_md(POST_URI,param_string,'no')
            if res_flg is False:
                logger.error('forward monitoring-data error.')
            if res:
                logger.debug("HTTP Response({0}):{1}".format(res.status_code,res.text))
                
    except Exception:
        logger.exception('POST monitoring-data({0}) error.'.format(const.TYPE_MON_CP))
        return HTTPResponse("POST monitoring-data({0}) error."
                            .format(const.TYPE_MON_CP), status=500)

    logger.info('POST monitoring-data({0}). -end-'.format(const.TYPE_MON_CP))

    return
Ejemplo n.º 5
0
    def main(self):
        # get now time.(UTC:0)
        # for monitoring timesamp(etime)
        now_time = calendar.timegm(datetime.utcnow().timetuple())
        try:
            print(COL_NAME + ' -start-')
            logger.info(COL_NAME + ' -start-')

            # open topology database connection.
            tpldb_setup()

            # get monitoring-data from SequelService.
            tblsaffix_list = self.__get_tblsaffix(self.before_time,now_time)
            if not tblsaffix_list:
                logger.debug('tblsaffix_list is no data.')
                return

            # get all of the switch-I/F(port) from DB.
            if_list = get_all_sw_if()
            all_md_list = []
            for interface in if_list:
                if interface.node.network.type == const.TYPE_NW_SLICE:
                    logger.debug('(skip)slice interface is not target.')
                    continue
                # get monitoring-data from SequelService.
                node_name = interface.node.node_name
                port = interface.port
                md_dict = self.__get_monitoring_data(node_name,port,self.before_time,now_time,tblsaffix_list)
                if not md_dict:
                    logger.debug('monitoring-data is no data.(node={0},port={1})'.format(node_name,port))
                    continue
                logger.debug(md_dict)

                # aggregate the monitoring-data.
                if config.aggregate_flg == 1:
                    logger.debug('aggregate the monitoring-data.')
                    md_dict = self.__aggregate(md_dict,now_time)
                    logger.debug(md_dict)

                md_dict['type'] = interface.node.type
                md_dict['network_name'] = interface.node.network_name
                ### md_dict={type:switch,network_name:xxx,node_name:xxx,
                ###             port:xxx,val_list:list(val_dict[param_name:value])}
                all_md_list.append(md_dict)

            if not all_md_list:
                logger.debug('monitoring-data is no data.(all interface)')
                return
            # parse monitoring-data-list to monitoring-data-xml.
            md_xml = create_monitoring_data_xml(logger,all_md_list)
            if not md_xml:
                logger.debug('monitoring-data-xml is null.')
                return
            logger.debug(md_xml)

            # upload all monitoring-data to DB.
            logger.debug('upload monitoring-data to DB.')
            mon_data_dict = db_upld.cleate_monitoring_data_dict(md_xml)
            if not mon_data_dict:
                logger.debug('upload monitoring-data is null.')
                return
            val_dict_list = db_upld.cleate_upload_data_list(mon_data_dict)
            db_upld.upload_monitoring_data_all(val_dict_list)
    
            # post the monitoring-data to the master-monitoring-server.
            logger.debug('post the monitoring-data to the master-monitoring-server.')
            res_flg,res = post_md(POST_URI,md_xml,'yes')
            if res_flg is False:
                logger.error('post monitoring-data error.(post_uri={0})'.format(POST_URI))
            if res:
                logger.debug("HTTP Response({0}):{1}".format(res.status_code,res.text))

        except Exception:
            logger.exception(COL_NAME)
            print(COL_NAME + ' -exception-')
    
        finally:
            self.before_time = now_time
            # close topology database connection.
            tpldb_close()
            logger.info(COL_NAME + ' -end-')
            print(COL_NAME + ' -end-')
    
        return
Ejemplo n.º 6
0
    def main(self):
        # get now time.(UTC:0)
        now_time = calendar.timegm(datetime.utcnow().timetuple())
        try:
            print(COL_NAME + ' -start-')
            logger.info(COL_NAME + ' -start-')
            
            # open topology database connection.
            tpldb_setup()

            # open zabbix connection.
            self.__zabbix_login()
        
            node_list =list()
            # get all of the VM from DB.
            vm_list = get_all_vm()
            if vm_list:
                node_list.extend(vm_list)

            # get all of the Server from DB.
            srv_list = get_all_srv()
            if srv_list:
                node_list.extend(srv_list)

            all_md_list = []
            for node in node_list:
                # get monitoring-data from Zabbix.
                node_name = node.node_name
                node_type = node.type
                md_dict = self.__get_monitoring_data(node_name,node_type,now_time)
                if not md_dict:
                    logger.debug('monitoring-data is no data.(node={0},type={1})'.format(node_name,node_type))
                    continue
                md_dict['network_name'] = node.network_name
                md_dict['network_type'] = node.network.type
                ### md_dict={nw_name:xxx,nw_type,node_name:xxx,node_type:server|vm,
                ###             val_list:list(val_dict[param_name:value])}
                logger.debug(md_dict)
                all_md_list.append(md_dict)
 
            if not all_md_list:
                logger.debug('monitoring-data is no data.(all node)')
                return

            # parse monitoring-data-list to monitoring-data-xml.
            md_xml = create_monitoring_data_xml(logger,all_md_list)
            if not md_xml:
                logger.debug('monitoring-data-xml is null.')
                return
            logger.debug(md_xml)

            # upload monitoring-data to DB.
            logger.debug('upload monitoring-data to DB.')
            if not db_upld.upload_monitoring_data_all(md_xml):
                logger.debug('upload monitoring-data is null.')
                return
    
            # post the monitoring-data to the master-monitoring-server.
            logger.debug('post the monitoring-data to the master-monitoring-server.')
            res_flg,res = post_md(POST_URI,md_xml,'yes')
            if res_flg is False:
                logger.error('post monitoring-data error.(post_uri={0})'.format(POST_URI))
            if res:
                logger.debug("HTTP Response({0}):{1}".format(res.status_code,res.text))

        except Exception:
            logger.exception(COL_NAME)
            print(COL_NAME + ' -exception-')
    
        finally:
            # close topology database connection.
            tpldb_close()

            # close zabbix connection.
            self.__zabbix_logout()

            logger.info(COL_NAME + ' -end-')
            print(COL_NAME + ' -end-')
    
        return
Ejemplo n.º 7
0
    def main(self):
        # get now time.(UTC:0)
        # for monitoring timesamp(etime)
        now_time = calendar.timegm(datetime.utcnow().timetuple())
        try:
            print(COL_NAME + ' -start-')
            logger.info(COL_NAME + ' -start-')

            # open topology database connection.
            tpldb_setup()
           
            # get monitoring-data from SequelService.
            tblsaffix_list = self.__get_tblsaffix(self.before_time,now_time)
            if not tblsaffix_list:
                logger.debug('tblsaffix_list is no data.')
                return

            # get all of the stitching-entity-I/F(port) from DB.
            if_list = get_all_se_if()
            all_md_list = []
            for interface in if_list:
                if interface.node.network.type == const.TYPE_NW_SLICE:
                    logger.debug('(skip)slice interface is not target.')
                    continue
                # get monitoring-data from SequelService.
                node_name = interface.node.node_name
                port = interface.port
                md_dict = self.__get_monitoring_data(node_name,port,self.before_time,now_time,tblsaffix_list)
                if not md_dict:
                    logger.debug('monitoring-data is no data.(node={0},port={1})'.format(node_name,port))
                    continue
                logger.debug(md_dict)

                # aggregate the monitoring-data.
                if config.aggregate_flg == 1:
                    logger.debug('aggregate the monitoring-data.')
                    md_dict = self.__aggregate(md_dict,now_time)
                    logger.debug(md_dict)

                md_dict['type'] = interface.node.type
                md_dict['network_name'] = interface.node.network_name
                ### md_dict={type:se,network_name:xxx,node_name:xxx,
                ###             port:xxx,val_list:list(val_dict[param_name:value])}
                all_md_list.append(md_dict)

            if not all_md_list:
                logger.debug('monitoring-data is no data.(all interface)')
                return
            # parse monitoring-data-list to monitoring-data-xml.
            md_xml = create_monitoring_data_xml(logger,all_md_list)
            if not md_xml:
                logger.debug('monitoring-data-xml is null.')
                return
            logger.debug(md_xml)

            # upload all monitoring-data to DB.
            logger.debug('upload monitoring-data to DB.')
            mon_data_dict = db_upld.cleate_monitoring_data_dict(md_xml)
            if not mon_data_dict:
                logger.debug('upload monitoring-data is null.')
                return
            val_dict_list = db_upld.cleate_upload_data_list(mon_data_dict)
            db_upld.upload_monitoring_data_all(val_dict_list)
    
            # post the monitoring-data to the master-monitoring-server.
            logger.debug('post the monitoring-data to the master-monitoring-server.')
            res_flg,res = post_md(POST_URI,md_xml,'yes')
            if res_flg is False:
                logger.error('post monitoring-data error.(post_uri={0})'.format(POST_URI))
            if res:
                logger.debug("HTTP Response({0}):{1}".format(res.status_code,res.text))

        except Exception:
            logger.exception(COL_NAME)
            print(COL_NAME + ' -exception-')
    
        finally:
            self.before_time = now_time
            # close topology database connection.
            tpldb_close()
            logger.info(COL_NAME + ' -end-')
            print(COL_NAME + ' -end-')
    
        return
Ejemplo n.º 8
0
Archivo: tn.py Proyecto: HalasNet/felix
    def main(self):
        # get now time.(UTC:0)
        now_time = calendar.timegm(datetime.utcnow().timetuple())
        try:
            print(COL_NAME + ' -start-')
            logger.info(COL_NAME + ' -start-')
           
            # open topology database connection.
            tpldb_setup()

            # get all of the monitoring-data from NSI.
            all_nsi_md = self.__get_nsi_monitoring_data()

            # get all of the TN-link from DB.
            link_list = get_all_tn_link()

            all_md_list = []
            for link in link_list:
                # get monitoring-data from NSI.
                link_name = link.link_name
                md_dict = self.__get_monitoring_data(all_nsi_md,link_name,now_time)
                if not md_dict:
                    logger.debug('monitoring-data is no data.(link={0})'.format(link_name))
                    continue
                md_dict['network_type'] = link.network.type
                md_dict['network_name'] = link.network_name
                md_dict['link_type'] = link.type
                ### md_dict={network_type:slice,network_name:xxx,
                ###             link_type:tn,link_name:xxx,val_list:list(val_dict[param_name:value])}
                logger.debug(md_dict)
                all_md_list.append(md_dict)
 
            if not all_md_list:
                logger.debug('monitoring-data is no data.(all TN-link)')
                return

            # parse monitoring-data-list to monitoring-data-xml.
            md_xml = create_monitoring_data_xml(logger,all_md_list)
            if not md_xml:
                logger.debug('monitoring-data-xml is null.')
                return
            logger.debug(md_xml)

            # upload monitoring-data to DB.
            logger.debug('upload monitoring-data to DB.')
            if not db_upld.upload_monitoring_data_all(md_xml):
                logger.debug('upload monitoring-data is null.')
                return
    
            # post the monitoring-data to the master-monitoring-server.
            logger.debug('post the monitoring-data to the master-monitoring-server.')
            res_flg,res = post_md(POST_URI,md_xml,'yes')
            if res_flg is False:
                logger.error('post monitoring-data error.(post_uri={0})'.format(POST_URI))
            if res:
                logger.debug("HTTP Response({0}):{1}".format(res.status_code,res.text))

        except Exception:
            logger.exception(COL_NAME)
            print(COL_NAME + ' -exception-')
    
        finally:
            # close topology database connection.
            tpldb_close()
            logger.info(COL_NAME + ' -end-')
            print(COL_NAME + ' -end-')
    
        return