forked from p15670423/monkey
Island: Send analytics on island startup instead of object creation
This change makes the logic more evident, because sending the analytics is not done during the initialization of an object
This commit is contained in:
parent
bec7bef1b3
commit
c61737abc0
|
@ -5,8 +5,11 @@ import sys
|
|||
from pathlib import Path
|
||||
|
||||
import gevent.hub
|
||||
import requests
|
||||
from gevent.pywsgi import WSGIServer
|
||||
|
||||
from monkey_island.cc import Version
|
||||
from monkey_island.cc.deployment import Deployment
|
||||
from monkey_island.cc.server_utils.consts import ISLAND_PORT
|
||||
from monkey_island.cc.setup.config_setup import get_server_config
|
||||
|
||||
|
@ -150,6 +153,7 @@ def _start_island_server(
|
|||
error_log=logger,
|
||||
)
|
||||
_log_init_info()
|
||||
_send_analytics(container)
|
||||
http_server.serve_forever()
|
||||
|
||||
|
||||
|
@ -173,3 +177,25 @@ def _log_web_interface_access_urls():
|
|||
"To access the web interface, navigate to one of the the following URLs using your "
|
||||
f"browser: {web_interface_urls}"
|
||||
)
|
||||
|
||||
|
||||
ANALYTICS_URL = (
|
||||
"https://m15mjynko3.execute-api.us-east-1.amazonaws.com/default?version={"
|
||||
"version}&deployment={deployment}"
|
||||
)
|
||||
|
||||
|
||||
def _send_analytics(di_container):
|
||||
version = di_container.resolve(Version)
|
||||
deployment = di_container.resolve(Deployment)
|
||||
url = ANALYTICS_URL.format(deployment=deployment.value, version=version.version_number)
|
||||
try:
|
||||
response = requests.get(url).json()
|
||||
logger.info(
|
||||
f"Version number and deployment type was sent to analytics server."
|
||||
f" The response is: {response}"
|
||||
)
|
||||
except requests.exceptions.ConnectionError as err:
|
||||
logger.info(
|
||||
f"Failed to send deployment type and version " f"number to the analytics server: {err}"
|
||||
)
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
import logging
|
||||
|
||||
import requests
|
||||
|
||||
from monkey_island.cc import Version
|
||||
from monkey_island.cc.deployment import Deployment
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
ANALYTICS_URL = (
|
||||
"https://m15mjynko3.execute-api.us-east-1.amazonaws.com/default?version={"
|
||||
"version}&deployment={deployment}"
|
||||
)
|
||||
|
||||
|
||||
class Analytics:
|
||||
def __init__(self, version: Version, deployment: Deployment):
|
||||
self.version = version.version_number
|
||||
self.deployment = deployment.value
|
||||
self._send_analytics()
|
||||
|
||||
def _send_analytics(self):
|
||||
url = ANALYTICS_URL.format(deployment=self.deployment, version=self.version)
|
||||
response = requests.get(url).json()
|
||||
logger.info(
|
||||
f"Version number and deployment type was sent to analytics server."
|
||||
f" The response is: {response}"
|
||||
)
|
|
@ -53,7 +53,6 @@ from monkey_island.cc.services.utils.network_utils import get_ip_addresses
|
|||
from monkey_island.cc.setup.mongo.mongo_setup import MONGO_URL
|
||||
|
||||
from . import AuthenticationService
|
||||
from .analytics import Analytics
|
||||
from .reporting.report import ReportService
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -74,7 +73,6 @@ def initialize_services(data_dir: Path) -> DIContainer:
|
|||
ILockableEncryptor, RepositoryEncryptor(data_dir / REPOSITORY_KEY_FILE_NAME)
|
||||
)
|
||||
container.register_instance(Version, container.resolve(Version))
|
||||
container.register_instance(Analytics, container.resolve(Analytics))
|
||||
container.register(Publisher, Publisher)
|
||||
container.register_instance(IEventQueue, container.resolve(PyPubSubEventQueue))
|
||||
|
||||
|
|
Loading…
Reference in New Issue