Package: microengine-utils
microengine-utilsUtility package forPolySwarm EnginesSupports Python 3.6 and greater.InstallationFrom PyPI:pip install microengine-utilsFrom source:python3 setup.py install

OR

pip3 install .If you get an error about a missing package namedwheel, that means your version of pip or setuptools is too old.
You need pip >= 19.0 and setuptools >= 40.8.0.
To update pip, runpip install -U pip.
To update setuptools, runpip install -U setuptoolsUsageHere is an example for how to use thedatadogmetrics utility in an Engine.importasgiref.syncasasgiref_syncimportloggingimportosimportplatformimportpolyswarm_myenginefrompolyswarmartifact.schema.verdictimportVerdictfrompolyswarmclient.abstractscannerimportAbstractScanner,ScanResultfrommicroengine_utils.constantsimportSCAN_VERDICT,SCAN_FAIL,SCAN_TIMEfrommicroengine_utils.datadogimportconfigure_metricslogger=logging.getLogger(__name__)DATADOG_API_KEY='my_api_key'DATADOG_APP_KEY='my_app_key'# Configure Datadog metric keys for use in the applicationENGINE_NAME='myengine'SCANNER_TYPE='file'OS_TYPE='windows'# Set the environment name, "local" is used for testingPOLY_WORK=os.getenv('POLY_WORK','local')# Set the hostname, "local" is used for testingSOURCE=os.getenv("HOSTNAME","localhost")classScanner(AbstractScanner):def__init__(self):self.datadog_api_key=os.getenv('DATADOG_API_KEY',None)self.datadog_app_key=os.getenv('DATADOG_APP_KEY',None)self.metrics_collector=configure_metrics(self.datadog_api_key,self.datadog_app_key,ENGINE_NAME,OS_TYPE,POLY_WORK,SOURCE)asyncdefscan(self,guid,artifact_type,content,metadata,chain):version=awaitScanner._get_my_engine_version()metadata=Verdict().set_malware_family('')\.set_scanner(operating_system=platform.system(),architecture=platform.machine(),vendor_version=version,version=polyswarm_myengine.__version__)artifact_name=awaitasgiref_sync.sync_to_async(self._create_temp_file)(content)withself.metrics_collector.timer(SCAN_TIME):try:exit_code,scan_output=awaitScanner._run_system_cmd(Scanner._get_full_command(artifact_name))logger.info("myengine scan result:%s",scan_output)finally:awaitasgiref_sync.sync_to_async(os.unlink)(artifact_name)ifexit_code!=0:self.metrics_collector.increment(SCAN_FAIL)returnScanResult(metadata=metadata.json())infected_bool,malware_family=Scanner._process_output(scan_output)metadata.set_malware_family(malware_family)confidence=0.8ifinfected_bool:self.metrics_collector.increment(SCAN_VERDICT,tags=['verdict:malicious',f'malware_family:{metadata.malware_family}','type:file'])else:self.metrics_collector.increment(SCAN_VERDICT,tags=['verdict:benign','type:file'])returnScanResult(bit=True,verdict=infected_bool,confidence=confidence,metadata=metadata.json())Here is an example for using themalwarerepoclientutility in Engine unit testsimportasyncioimportpytestimportsysfrommicroengine_utils.malwarerepoclientimportDummyMalwareRepoClientfrompolyswarm_myengineimportScannerfrompolyswarmartifactimportArtifactType@pytest.yield_fixture()defevent_loop():loop=asyncio.get_event_loop()ifsys.platform=='win32':loop=asyncio.ProactorEventLoop()yieldlooploop.close()@pytest.mark.asyncioasyncdeftest_scan_random_malicious_and_not():scanner=Scanner()fortin[True,False]:mal_md,mal_content=DummyMalwareRepoClient().get_random_file(malicious_filter=t)result=awaitscanner.scan("nocare",ArtifactType.FILE,mal_content,None,"home")assertresult.verdict==tTestinggit clone https://github.com/polyswarm/microengine-utils.git
cd microengine-utils
pip3 install -r requirements.txt
pip3 install .
pytest -s -vQuestions? Problems?File a ticket or email us atinfo@polyswarm.io.