forked from p15670423/monkey
Added telemetry collection
This commit is contained in:
parent
5fa27c14e8
commit
7d397da245
|
@ -0,0 +1,18 @@
|
||||||
|
"""
|
||||||
|
Define a Document Schema for the Monkey document.
|
||||||
|
"""
|
||||||
|
from mongoengine import Document, StringField
|
||||||
|
|
||||||
|
|
||||||
|
class TestTelem(Document):
|
||||||
|
# SCHEMA
|
||||||
|
method = StringField(required=True)
|
||||||
|
endpoint = StringField(required=True)
|
||||||
|
content = StringField(required=True)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def try_drop_collection():
|
||||||
|
try:
|
||||||
|
TestTelem.drop_collection()
|
||||||
|
except Exception:
|
||||||
|
pass
|
|
@ -3,6 +3,7 @@ from datetime import datetime
|
||||||
|
|
||||||
import dateutil.parser
|
import dateutil.parser
|
||||||
import flask_restful
|
import flask_restful
|
||||||
|
from monkey_island.cc.resources.test.utils.telem_store import store_test_telem
|
||||||
from flask import request
|
from flask import request
|
||||||
|
|
||||||
from monkey_island.cc.consts import DEFAULT_MONKEY_TTL_EXPIRY_DURATION_IN_SECONDS
|
from monkey_island.cc.consts import DEFAULT_MONKEY_TTL_EXPIRY_DURATION_IN_SECONDS
|
||||||
|
@ -33,6 +34,7 @@ class Monkey(flask_restful.Resource):
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
# Used by monkey. can't secure.
|
# Used by monkey. can't secure.
|
||||||
|
@store_test_telem
|
||||||
def patch(self, guid):
|
def patch(self, guid):
|
||||||
monkey_json = json.loads(request.data)
|
monkey_json = json.loads(request.data)
|
||||||
update = {"$set": {'modifytime': datetime.now()}}
|
update = {"$set": {'modifytime': datetime.now()}}
|
||||||
|
@ -56,6 +58,7 @@ class Monkey(flask_restful.Resource):
|
||||||
return mongo.db.monkey.update({"_id": monkey["_id"]}, update, upsert=False)
|
return mongo.db.monkey.update({"_id": monkey["_id"]}, update, upsert=False)
|
||||||
|
|
||||||
# Used by monkey. can't secure.
|
# Used by monkey. can't secure.
|
||||||
|
@store_test_telem
|
||||||
def post(self, **kw):
|
def post(self, **kw):
|
||||||
monkey_json = json.loads(request.data)
|
monkey_json = json.loads(request.data)
|
||||||
monkey_json['creds'] = []
|
monkey_json['creds'] = []
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
from functools import wraps
|
||||||
|
|
||||||
|
from flask import request
|
||||||
|
|
||||||
|
from monkey_island.cc.models.test_telem import TestTelem
|
||||||
|
|
||||||
|
MONKEY_TELEM_COLLECTION_NAME = "monkey_telems_for_tests"
|
||||||
|
|
||||||
|
|
||||||
|
def store_test_telem(f):
|
||||||
|
@wraps(f)
|
||||||
|
def decorated_function(*args, **kwargs):
|
||||||
|
method = request.method
|
||||||
|
content = request.data.decode()
|
||||||
|
endpoint = str(request.url_rule)
|
||||||
|
TestTelem(method=method, endpoint=endpoint, content=content).save()
|
||||||
|
return f(*args, **kwargs)
|
||||||
|
|
||||||
|
return decorated_function
|
Loading…
Reference in New Issue