forked from p15670423/monkey
Island: Send analytics upon island startup
This commit is contained in:
parent
02e719f7b2
commit
32460bbb3e
|
@ -0,0 +1,28 @@
|
|||
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,6 +53,7 @@ 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__)
|
||||
|
@ -73,6 +74,7 @@ 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))
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ from .deployment import Deployment
|
|||
|
||||
# TODO get redirects instead of using direct links to AWS
|
||||
LATEST_VERSION_URL = "https://njf01cuupf.execute-api.us-east-1.amazonaws.com/default?deployment={}"
|
||||
|
||||
LATEST_VERSION_TIMEOUT = 7
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
Loading…
Reference in New Issue