Ejemplo n.º 1
0
    def process(self, device, results, log):
        """
        Must return one of :
            - None, changes nothing. Good in error cases.
            - A RelationshipMap, for the device to component information
            - An ObjectMap, for the device device information
            - A list of RelationshipMaps and ObjectMaps, both
        """
        log.debug('SBA process results: {}'.format(results))

        self.result_data = {}
        for success, result in results:
            if success:
                if result:
                    content = json.loads(result[1])
                else:
                    content = {}
                self.result_data[result[0]] = content
        sba_data = self.result_data.get('sba', '')

        app_maps = []
        rm = []
        for app in sba_data:
            om_app = ObjectMap()
            app_label = app.get('name', '')
            app_name = app_label.lower().replace(' ', '_')
            app_id = app.get('id', '')
            om_app.id = self.prepId('app_{}_{}'.format(app_name, app_id))
            om_app.applicationComponentID = om_app.id
            om_app.applicationName = app_label
            om_app.applicationNameID = self.prepId('{}_{}'.format(
                app_name, app_id))
            om_app.componentName = ''
            # TODO: try to get rid of this, but info required for collectors
            om_app.applicationID = app_id
            mgmtURL = app.get('managementUrl', '')
            om_app.mgmtURL = mgmtURL
            om_app.healthURL = app.get('healthUrl', '')
            om_app.serviceURL = app.get('serviceUrl', '')
            r = re.match(r'^(.*:)//([A-Za-z0-9\-\.]+)(:[0-9]+)?(.*)$', mgmtURL)
            server = r.group(2)
            om_app.hostingServer = server
            om_app.title = '{} on {} ({})'.format(app_label, server, app_id)

            app_maps.append(om_app)
            # comp_app = 'springBootApplications/{}'.format(om_app.id)

        rm.append(
            RelationshipMap(
                relname='springBootApplications',
                modname='ZenPacks.fednot.Delivery.SpringBootApplication',
                compname='',
                objmaps=app_maps))

        return rm
Ejemplo n.º 2
0
    def process(self, device, results, log):
        """
        Must return one of :
            - None, changes nothing. Good in error cases.
            - A RelationshipMap, for the device to component information
            - An ObjectMap, for the device device information
            - A list of RelationshipMaps and ObjectMaps, both
        """
        # log.debug('SBA process results: {}'.format(results))

        result_data = {}
        for success, result in results:
            if success:
                if result:
                    content = json.loads(result[1])
                else:
                    content = {}
                result_data[result[0]] = content

        # sba_data = result_data.get('sba', '')
        log.debug('AAA result_data: {}'.format(result_data))

        sba_maps = []
        rm = []
        rm_sba = []
        rm_app = []
        rm_comp = []
        rm_jvm = []
        for context, sba_data in result_data.iteritems():
            # Modeling of SBA instances
            om_sba = ObjectMap()
            sba_label = 'Spring Boot Admin ({})'.format(context)
            om_sba.id = self.prepId('sba_{}'.format(context))
            om_sba.title = sba_label
            om_sba.context = context
            if 'endpoints' in sba_data[0]:
                om_sba.sbaVersion = '2'
            else:
                om_sba.sbaVersion = '1'
            sba_maps.append(om_sba)
            component_sba = 'springBootAdmins/{}'.format(om_sba.id)
            app_maps = []
            for app in sba_data:
                # Modeling of Applications
                if 'registration' not in app:
                    # Spring Boot Admin v1
                    app_info = app
                else:
                    # Spring Boot Admin v2
                    app_info = app.get('registration', '')
                om_app = ObjectMap()
                app_label = app_info.get('name', '')
                app_name = app_label.lower().replace(' ', '_')
                app_id = app.get('id', '')
                om_app.id = self.prepId('app_{}_{}'.format(app_name, app_id))
                om_app.applicationComponentID = om_app.id                   # to be inherited
                om_app.applicationName = app_label
                om_app.applicationNameID = self.prepId('{}_{}'.format(app_name, app_id))
                om_app.applicationID = app_id
                mgmtURL = app_info.get('managementUrl', '')
                om_app.mgmtURL = mgmtURL
                om_app.healthURL = app_info.get('healthUrl', '')
                om_app.serviceURL = app_info.get('serviceUrl', '')
                r = re.match(r'^(.*:)//([A-Za-z0-9\-\.]+)(:[0-9]+)?(.*)$', mgmtURL)
                server = r.group(2)
                om_app.hostingServer = server
                om_app.title = '{} on {} ({})'.format(app_label, server, app_id)
                app_maps.append(om_app)

                applicationNameID = '{}_{}'.format(app_label.lower().replace(' ', '_'), app_id)
                component_app = '{}/springBootApplications/{}'.format(component_sba, om_app.id)

                # Modeling of Application Components
                app_status = app.get('statusInfo', '')
                app_details = app_status.get('details', '')
                comp_maps = []
                for comp_name in app_details:
                    if comp_name == 'status':
                        continue
                    om_comp = ObjectMap()
                    om_comp.id = self.prepId('comp_{}_{}'.format(applicationNameID, comp_name))
                    om_comp.title = '{} ({} on {})'.format(comp_name, app_label, server)
                    om_comp.componentName = comp_name
                    comp_maps.append(om_comp)

                rm_comp.append(RelationshipMap(relname='springBootComponents',
                                               modname='ZenPacks.fednot.SpringBootAdmin.SpringBootComponent',
                                               compname=component_app,
                                               objmaps=comp_maps))

                # Modeling of Application JVM
                om_jvm = ObjectMap()
                om_jvm.id = self.prepId('jvm_{}'.format(applicationNameID))
                om_jvm.title = 'JVM ({} on {})'.format(app_label, server)
                if om_sba.sbaVersion == '1':
                    rm_jvm.append(RelationshipMap(relname='springBootJVMs',
                                                  modname='ZenPacks.fednot.SpringBootAdmin.SpringBootJVM',
                                                  compname=component_app,
                                                  objmaps=[om_jvm]))
                elif om_sba.sbaVersion == '2':
                    rm_jvm.append(RelationshipMap(relname='springBootJVM2s',
                                                  modname='ZenPacks.fednot.SpringBootAdmin.SpringBootJVM2',
                                                  compname=component_app,
                                                  objmaps=[om_jvm]))


            rm_app.append(RelationshipMap(relname='springBootApplications',
                                          modname='ZenPacks.fednot.SpringBootAdmin.SpringBootApplication',
                                          compname=component_sba,
                                          objmaps=app_maps))
        rm_sba.append(RelationshipMap(relname='springBootAdmins',
                                      modname='ZenPacks.fednot.SpringBootAdmin.SpringBootAdmin',
                                      compname='',
                                      objmaps=sba_maps))

        rm.extend(rm_sba)
        rm.extend(rm_app)
        rm.extend(rm_comp)
        rm.extend(rm_jvm)

        return rm