Ejemplo n.º 1
0
    def monitor_schains(self, opts):
        skale = spawn_skale_lib(self.skale)
        schains = skale.schains_data.get_schains_for_node(self.node_id)
        schains_on_node = sum(map(lambda schain: schain['active'], schains))
        schains_holes = len(schains) - schains_on_node
        logger.info(
            arguments_list_string(
                {
                    'Node ID': self.node_id,
                    'sChains on node': schains_on_node,
                    'Empty sChain structs': schains_holes
                }, 'Monitoring sChains'))
        threads = []
        for schain in schains:
            if not schain['active']:
                continue
            schain_thread = CustomThread(f'sChain monitor: {schain["name"]}',
                                         self.monitor_schain,
                                         opts=schain,
                                         once=True)
            schain_thread.start()
            threads.append(schain_thread)

        for thread in threads:
            thread.join()
Ejemplo n.º 2
0
    def monitor_schain(self, schain):
        skale = spawn_skale_lib(self.skale)
        name = schain['name']
        owner = schain['owner']
        checks = SChainChecks(name, self.node_id, log=True).get_all()

        if not SChainRecord.added(name):
            schain_record, _ = SChainRecord.add(name)
        else:
            schain_record = SChainRecord.get_by_name(name)

        if not checks['data_dir']:
            init_schain_dir(name)
        if not checks['dkg']:
            try:
                schain_record.dkg_started()
                run_dkg(skale, schain['name'], self.node_config.id,
                        self.node_config.sgx_key_name)
            except DkgError as err:
                logger.info(f'sChain {name} Dkg procedure failed with {err}')
                schain_record.dkg_failed()
                remove_config_dir(schain['name'])
                exit(1)
            schain_record.dkg_done()
        if not checks['config']:
            self.init_schain_config(skale, name, owner)
        if not checks['volume']:
            init_data_volume(schain)
        if not checks['firewall_rules']:
            self.add_firewall_rules(name)
        if not checks['container']:
            self.monitor_schain_container(schain)
        sleep(CONTAINERS_DELAY)
        if not checks['ima_container']:
            self.monitor_ima_container(schain)
Ejemplo n.º 3
0
    def monitor_job(self) -> None:
        """
        Periodic job for monitoring nodes
        """
        self.logger.info('New monitor job started...')
        skale = spawn_skale_lib(self.skale)
        try:
            self.nodes = self.skale.monitors_data.get_checked_array(self.id)
        except Exception as err:
            self.logger.exception(
                f'Failed to get list of monitored nodes. Error: {err}')
            self.logger.info('Monitoring nodes from previous job list')

        self.validate_nodes(skale, self.nodes)

        self.logger.info('Monitor job finished...')
Ejemplo n.º 4
0
 def __init__(self, skale, node_config):
     self.skale = skale
     self.skale_events = spawn_skale_lib(skale)
     self.node_config = node_config
     CustomThread('Wait for node ID', self.wait_for_node_id,
                  once=True).start()