cavisson-pythonagent 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cavisson_pythonagent-0.0.1.dist-info/METADATA +32 -0
- cavisson_pythonagent-0.0.1.dist-info/RECORD +180 -0
- cavisson_pythonagent-0.0.1.dist-info/WHEEL +5 -0
- cavisson_pythonagent-0.0.1.dist-info/licenses/LICENSE +19 -0
- cavisson_pythonagent-0.0.1.dist-info/top_level.txt +1 -0
- pythonagent/__init__.py +22 -0
- pythonagent/agent/__init__.py +219 -0
- pythonagent/agent/internal/__init__.py +1 -0
- pythonagent/agent/internal/agent.py +1651 -0
- pythonagent/agent/internal/framesinfo.py +152 -0
- pythonagent/agent/internal/heap_dump.py +39 -0
- pythonagent/agent/internal/intercept_module.py +70 -0
- pythonagent/agent/internal/logs.py +122 -0
- pythonagent/agent/internal/metadata/__init__.py +0 -0
- pythonagent/agent/internal/metadata/agent_meta_data.py +276 -0
- pythonagent/agent/internal/proc_compat.py +75 -0
- pythonagent/agent/internal/profile.py +47 -0
- pythonagent/agent/internal/provider.py +83 -0
- pythonagent/agent/internal/thread_dump.py +85 -0
- pythonagent/agent/internal/udp.py +245 -0
- pythonagent/agent/internal/udp_message.py +800 -0
- pythonagent/agent/probes/Instrumentation/__init__.py +340 -0
- pythonagent/agent/probes/Instrumentation/find.py +243 -0
- pythonagent/agent/probes/Instrumentation/module_version_resolver.py +155 -0
- pythonagent/agent/probes/Instrumentation/new_parser.py +64 -0
- pythonagent/agent/probes/Instrumentation/parser.py +129 -0
- pythonagent/agent/probes/__init__.py +219 -0
- pythonagent/agent/probes/base.py +303 -0
- pythonagent/agent/probes/cache/__init__.py +51 -0
- pythonagent/agent/probes/cache/redis.py +119 -0
- pythonagent/agent/probes/cache/redis_asyncio.py +83 -0
- pythonagent/agent/probes/coroutines/__init__.py +1 -0
- pythonagent/agent/probes/coroutines/asyncio.py +63 -0
- pythonagent/agent/probes/elasticdb/__init__.py +7 -0
- pythonagent/agent/probes/elasticdb/aelastic.py +54 -0
- pythonagent/agent/probes/frameworks/__init__.py +27 -0
- pythonagent/agent/probes/frameworks/agentprofiler.py +105 -0
- pythonagent/agent/probes/frameworks/aiohttp_web.py +155 -0
- pythonagent/agent/probes/frameworks/aisess.py +151 -0
- pythonagent/agent/probes/frameworks/asgi.py +340 -0
- pythonagent/agent/probes/frameworks/bottle.py +27 -0
- pythonagent/agent/probes/frameworks/cherry.py +25 -0
- pythonagent/agent/probes/frameworks/django.py +128 -0
- pythonagent/agent/probes/frameworks/falcon.py +21 -0
- pythonagent/agent/probes/frameworks/fastapi.py +35 -0
- pythonagent/agent/probes/frameworks/flask.py +30 -0
- pythonagent/agent/probes/frameworks/pyramid.py +56 -0
- pythonagent/agent/probes/frameworks/test.py +108 -0
- pythonagent/agent/probes/frameworks/tornado_async_web.py +117 -0
- pythonagent/agent/probes/frameworks/tornado_web.py +133 -0
- pythonagent/agent/probes/frameworks/wsgi.py +353 -0
- pythonagent/agent/probes/grpc/__init__.py +76 -0
- pythonagent/agent/probes/grpc/client_interceptor.py +132 -0
- pythonagent/agent/probes/grpc/server_interceptor.py +129 -0
- pythonagent/agent/probes/havoc/__init__.py +0 -0
- pythonagent/agent/probes/havoc/custom_memory_stress.py +186 -0
- pythonagent/agent/probes/havoc/custom_thread_stress.py +187 -0
- pythonagent/agent/probes/havoc/havoc_constants.py +218 -0
- pythonagent/agent/probes/havoc/havoc_manager.py +981 -0
- pythonagent/agent/probes/http/__init__.py +49 -0
- pythonagent/agent/probes/http/aiohttp_client.py +59 -0
- pythonagent/agent/probes/http/boto.py +12 -0
- pythonagent/agent/probes/http/httplib.py +110 -0
- pythonagent/agent/probes/http/httpx_client.py +116 -0
- pythonagent/agent/probes/http/requests.py +15 -0
- pythonagent/agent/probes/http/tornado_httpclient.py +85 -0
- pythonagent/agent/probes/http/urllib3.py +16 -0
- pythonagent/agent/probes/langchain/__init__.py +21 -0
- pythonagent/agent/probes/langchain/base_tool.py +95 -0
- pythonagent/agent/probes/langchain/langchain_community.py +136 -0
- pythonagent/agent/probes/langchain/langchain_core.py +32 -0
- pythonagent/agent/probes/langchain/langchain_openai.py +110 -0
- pythonagent/agent/probes/logging/__init__.py +106 -0
- pythonagent/agent/probes/message_brokers/__init__.py +4 -0
- pythonagent/agent/probes/message_brokers/pika.py +126 -0
- pythonagent/agent/probes/mongodb/__init__.py +6 -0
- pythonagent/agent/probes/mongodb/pymongo.py +286 -0
- pythonagent/agent/probes/openai/__init__.py +3 -0
- pythonagent/agent/probes/openai/openai.py +797 -0
- pythonagent/agent/probes/span.py +101 -0
- pythonagent/agent/probes/sql/__init__.py +13 -0
- pythonagent/agent/probes/sql/botocores3.py +51 -0
- pythonagent/agent/probes/sql/dbapi.py +285 -0
- pythonagent/agent/probes/sql/dynamodb.py +90 -0
- pythonagent/agent/probes/sql/mysql_connector.py +24 -0
- pythonagent/agent/probes/sql/mysql_connector_cext.py +24 -0
- pythonagent/agent/probes/sql/mysqldb.py +43 -0
- pythonagent/agent/probes/sql/psycopg2.py +174 -0
- pythonagent/agent/probes/sql/pymysql.py +25 -0
- pythonagent/bootstrap/__init__.py +0 -0
- pythonagent/bootstrap/cav_gunicorn.py +26 -0
- pythonagent/bootstrap/cavagent_lambda_wrapper.py +291 -0
- pythonagent/bootstrap/run.py +47 -0
- pythonagent/bootstrap/sitecustomize.py +287 -0
- pythonagent/cavisson/netdiagnostics/CavAgent/instrumentationprofile.json +26 -0
- pythonagent/cavisson/netdiagnostics/CavAgent/interceptor_points.txt +29 -0
- pythonagent/cavisson/netdiagnostics/python/CavAgent/instrumentationprofile.json +42 -0
- pythonagent/cavisson/netdiagnostics/python/CavAgent/interceptor_points.txt +29 -0
- pythonagent/cavisson/netdiagnostics/python/config/ndsettings.conf +6 -0
- pythonagent/config.py +279 -0
- pythonagent/find.py +72 -0
- pythonagent/find_mod_cls_name.py +54 -0
- pythonagent/lang.py +131 -0
- pythonagent/lib.py +91 -0
- pythonagent/main/__init__.py +0 -0
- pythonagent/main/pytrace/__init__.py +79 -0
- pythonagent/main/pytrace/commands/__init__.py +0 -0
- pythonagent/main/pytrace/commands/auto_discovery.py +25 -0
- pythonagent/main/pytrace/commands/run.py +401 -0
- pythonagent/main/pytrace/pytrace.py +133 -0
- pythonagent/main/wsgi.py +6 -0
- pythonagent/main.py +27 -0
- pythonagent/run.py +46 -0
- pythonagent/sqins.py +8 -0
- pythonagent/test.py +73 -0
- pythonagent/utils.py +168 -0
- pythonagent/vendor/__init__.py +0 -0
- pythonagent/vendor/pympler/__init__.py +1 -0
- pythonagent/vendor/pympler/asizeof.py +2810 -0
- pythonagent/vendor/pympler/charts.py +62 -0
- pythonagent/vendor/pympler/classtracker.py +590 -0
- pythonagent/vendor/pympler/classtracker_stats.py +780 -0
- pythonagent/vendor/pympler/garbagegraph.py +80 -0
- pythonagent/vendor/pympler/mprofile.py +97 -0
- pythonagent/vendor/pympler/muppy.py +275 -0
- pythonagent/vendor/pympler/panels.py +115 -0
- pythonagent/vendor/pympler/process.py +238 -0
- pythonagent/vendor/pympler/py.typed +0 -0
- pythonagent/vendor/pympler/refbrowser.py +451 -0
- pythonagent/vendor/pympler/refgraph.py +350 -0
- pythonagent/vendor/pympler/summary.py +321 -0
- pythonagent/vendor/pympler/tracker.py +267 -0
- pythonagent/vendor/pympler/util/__init__.py +0 -0
- pythonagent/vendor/pympler/util/bottle.py +3809 -0
- pythonagent/vendor/pympler/util/compat.py +23 -0
- pythonagent/vendor/pympler/util/stringutils.py +77 -0
- pythonagent/vendor/pympler/web.py +346 -0
- pythonagent/vendor/werkzeug/__init__.py +20 -0
- pythonagent/vendor/werkzeug/_compat.py +228 -0
- pythonagent/vendor/werkzeug/_internal.py +473 -0
- pythonagent/vendor/werkzeug/_reloader.py +341 -0
- pythonagent/vendor/werkzeug/datastructures.py +3120 -0
- pythonagent/vendor/werkzeug/debug/__init__.py +498 -0
- pythonagent/vendor/werkzeug/debug/console.py +218 -0
- pythonagent/vendor/werkzeug/debug/repr.py +297 -0
- pythonagent/vendor/werkzeug/debug/tbtools.py +628 -0
- pythonagent/vendor/werkzeug/exceptions.py +829 -0
- pythonagent/vendor/werkzeug/filesystem.py +64 -0
- pythonagent/vendor/werkzeug/formparser.py +584 -0
- pythonagent/vendor/werkzeug/http.py +1307 -0
- pythonagent/vendor/werkzeug/local.py +420 -0
- pythonagent/vendor/werkzeug/middleware/__init__.py +25 -0
- pythonagent/vendor/werkzeug/middleware/dispatcher.py +66 -0
- pythonagent/vendor/werkzeug/middleware/http_proxy.py +219 -0
- pythonagent/vendor/werkzeug/middleware/lint.py +408 -0
- pythonagent/vendor/werkzeug/middleware/profiler.py +132 -0
- pythonagent/vendor/werkzeug/middleware/proxy_fix.py +169 -0
- pythonagent/vendor/werkzeug/middleware/shared_data.py +293 -0
- pythonagent/vendor/werkzeug/posixemulation.py +117 -0
- pythonagent/vendor/werkzeug/routing.py +2210 -0
- pythonagent/vendor/werkzeug/security.py +249 -0
- pythonagent/vendor/werkzeug/serving.py +1117 -0
- pythonagent/vendor/werkzeug/test.py +1123 -0
- pythonagent/vendor/werkzeug/testapp.py +241 -0
- pythonagent/vendor/werkzeug/urls.py +1138 -0
- pythonagent/vendor/werkzeug/useragents.py +202 -0
- pythonagent/vendor/werkzeug/utils.py +778 -0
- pythonagent/vendor/werkzeug/wrappers/__init__.py +36 -0
- pythonagent/vendor/werkzeug/wrappers/accept.py +50 -0
- pythonagent/vendor/werkzeug/wrappers/auth.py +33 -0
- pythonagent/vendor/werkzeug/wrappers/base_request.py +673 -0
- pythonagent/vendor/werkzeug/wrappers/base_response.py +700 -0
- pythonagent/vendor/werkzeug/wrappers/common_descriptors.py +341 -0
- pythonagent/vendor/werkzeug/wrappers/cors.py +100 -0
- pythonagent/vendor/werkzeug/wrappers/etag.py +304 -0
- pythonagent/vendor/werkzeug/wrappers/json.py +145 -0
- pythonagent/vendor/werkzeug/wrappers/request.py +49 -0
- pythonagent/vendor/werkzeug/wrappers/response.py +84 -0
- pythonagent/vendor/werkzeug/wrappers/user_agent.py +14 -0
- pythonagent/vendor/werkzeug/wsgi.py +1000 -0
|
@@ -0,0 +1,800 @@
|
|
|
1
|
+
import struct
|
|
2
|
+
import binascii
|
|
3
|
+
import os
|
|
4
|
+
import threading
|
|
5
|
+
import time
|
|
6
|
+
|
|
7
|
+
import logging
|
|
8
|
+
logger = logging.getLogger('pythonagent.agent')
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Header(object):
|
|
12
|
+
|
|
13
|
+
def __init__(self, context, apiReqId, awsReqId, funcName, agent_obj):
|
|
14
|
+
self.apiReqId = apiReqId
|
|
15
|
+
self.awsReqId = awsReqId
|
|
16
|
+
self.funcName = funcName
|
|
17
|
+
if agent_obj.cav_env == "AWS_LAMBDA":
|
|
18
|
+
self.tags = "tierName={};ndAppServerHost={};appName={}".format(context.tier_name, context.server_name, funcName)
|
|
19
|
+
else:
|
|
20
|
+
self.tags = "tierName={};ndAppServerHost={};appName={}".format(agent_obj.tier_name, agent_obj.server_name, agent_obj.instance_name)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
self.agentType = 0 # Python
|
|
24
|
+
self.messageType = None
|
|
25
|
+
|
|
26
|
+
self.apiReqLen = None
|
|
27
|
+
self.awsReqLen = None
|
|
28
|
+
self.funcNameLen = None
|
|
29
|
+
self.tagslength = None
|
|
30
|
+
self.whLen = None
|
|
31
|
+
self.fp_id = 0
|
|
32
|
+
if agent_obj.app_id:
|
|
33
|
+
self.app_id = agent_obj.app_id
|
|
34
|
+
else:
|
|
35
|
+
self.app_id = -1
|
|
36
|
+
self.protocol_type = 0
|
|
37
|
+
|
|
38
|
+
def encode(self, msg_type="default"):
|
|
39
|
+
|
|
40
|
+
# 3 Defaults added in arguments for testing wsgi start fp for havoc inbound delay
|
|
41
|
+
|
|
42
|
+
if self.apiReqId is None:
|
|
43
|
+
self.apiReqId = "default_apiReqId"
|
|
44
|
+
if self.awsReqId is None:
|
|
45
|
+
self.awsReqId = "default_awsReqId"
|
|
46
|
+
if self.funcName is None:
|
|
47
|
+
self.funcName = "default_funcName"
|
|
48
|
+
|
|
49
|
+
# Message Type
|
|
50
|
+
|
|
51
|
+
if msg_type == "default":
|
|
52
|
+
self.messageType = 0
|
|
53
|
+
elif msg_type == "havoc":
|
|
54
|
+
self.messageType = 1
|
|
55
|
+
elif msg_type == "init":
|
|
56
|
+
self.messageType = 2
|
|
57
|
+
elif msg_type == "heartbeat":
|
|
58
|
+
self.messageType = 3
|
|
59
|
+
elif msg_type == "agent_initialize":
|
|
60
|
+
self.messageType = 8
|
|
61
|
+
else:
|
|
62
|
+
raise Exception("Invalid msg_type in wrap header")
|
|
63
|
+
|
|
64
|
+
self.apiReqLen = len(self.apiReqId)
|
|
65
|
+
self.awsReqLen = len(self.awsReqId)
|
|
66
|
+
self.funcNameLen = len(self.funcName)
|
|
67
|
+
self.tagslength = len(self.tags)
|
|
68
|
+
|
|
69
|
+
self.whLen = (1 # ^ (1c)
|
|
70
|
+
+ 4 # whLen(int)
|
|
71
|
+
+ 4 # apiReqLen(int)
|
|
72
|
+
+ 4 # awsReqLen(int)
|
|
73
|
+
+ 4 # funcNameLen(int)
|
|
74
|
+
+ 4 # tagslength(int)
|
|
75
|
+
+ 2 # agentType(short)
|
|
76
|
+
+ 2 # messageType(short)
|
|
77
|
+
+ 8 # fpId(long long)
|
|
78
|
+
+ 4 # appId(int)
|
|
79
|
+
+ 4 # protocolType(enum)
|
|
80
|
+
+ self.apiReqLen # variable
|
|
81
|
+
+ self.awsReqLen # variable
|
|
82
|
+
+ self.funcNameLen # variable
|
|
83
|
+
+ self.tagslength) # variable
|
|
84
|
+
|
|
85
|
+
header_struct = struct.Struct('=ciiiiihhqii{}s{}s{}s{}s'.format(self.apiReqLen, self.awsReqLen,
|
|
86
|
+
self.funcNameLen, self.tagslength))
|
|
87
|
+
|
|
88
|
+
header_values = (bytes('^', "utf-8"),
|
|
89
|
+
self.whLen,
|
|
90
|
+
self.apiReqLen,
|
|
91
|
+
self.awsReqLen,
|
|
92
|
+
self.funcNameLen,
|
|
93
|
+
self.tagslength,
|
|
94
|
+
self.agentType,
|
|
95
|
+
self.messageType,
|
|
96
|
+
self.fp_id,
|
|
97
|
+
self.app_id,
|
|
98
|
+
self.protocol_type,
|
|
99
|
+
self.apiReqId.encode('utf-8'),
|
|
100
|
+
self.awsReqId.encode('utf-8'),
|
|
101
|
+
self.funcName.encode('utf-8'),
|
|
102
|
+
self.tags.encode('utf-8'))
|
|
103
|
+
|
|
104
|
+
header_packet = header_struct.pack(*header_values)
|
|
105
|
+
|
|
106
|
+
return header_packet
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class StartTransactionMessage(object):
|
|
110
|
+
|
|
111
|
+
def __init__(self, url, flow_path_instance):
|
|
112
|
+
self.fp_header = "dummy_fp_header"
|
|
113
|
+
self.url = url
|
|
114
|
+
self.btHeaderValue = "dummy_btHeaderValue"
|
|
115
|
+
self.ndCookieSet = ""
|
|
116
|
+
self.nvCookieSet = ""
|
|
117
|
+
self.correlationHeader = "dummy_correlationHeader"
|
|
118
|
+
self.flow_path_instance = flow_path_instance
|
|
119
|
+
self.qTimeMS = 0 # DUMMY
|
|
120
|
+
self.startTimeFP = 0 # DUMMY
|
|
121
|
+
|
|
122
|
+
def encode(self):
|
|
123
|
+
|
|
124
|
+
self.len_fp_header = len(self.fp_header)
|
|
125
|
+
self.len_url = len(self.url)
|
|
126
|
+
self.len_btHeaderValue = len(self.btHeaderValue)
|
|
127
|
+
self.len_ndCookieSet = len(self.ndCookieSet)
|
|
128
|
+
self.len_nvCookieSet = len(self.nvCookieSet)
|
|
129
|
+
self.len_correlationHeader = len(self.correlationHeader)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
self.header_len = (4 # header_len(int)
|
|
133
|
+
+ 4 # total_len(int)
|
|
134
|
+
+ 4) # msg_type(int)
|
|
135
|
+
|
|
136
|
+
self.total_len = (1 # ^ (1c)
|
|
137
|
+
+ 4 # header_len(int)
|
|
138
|
+
+ 4 # total_len(int)
|
|
139
|
+
+ 4 # msg_type(int)
|
|
140
|
+
+ 1 # | (1c)
|
|
141
|
+
+ 4 # len_fp_header(int)
|
|
142
|
+
+ 4 # len_url(int)
|
|
143
|
+
+ 4 # len_btHeaderValue(int)
|
|
144
|
+
+ 4 # len_ndCookieSet(int)
|
|
145
|
+
+ 4 # len_nvCookieSet(int)
|
|
146
|
+
+ 4 # len_correlationHeader(int)
|
|
147
|
+
+ 8 # flow_path_instance(long long)
|
|
148
|
+
+ 8 # qTimeMS(long)
|
|
149
|
+
+ 8 # startTimeFP(long long)
|
|
150
|
+
+ self.len_fp_header # variable
|
|
151
|
+
+ self.len_url # variable
|
|
152
|
+
+ self.len_btHeaderValue # variable
|
|
153
|
+
+ self.len_ndCookieSet # variable
|
|
154
|
+
+ self.len_nvCookieSet # variable
|
|
155
|
+
+ self.len_correlationHeader # variable
|
|
156
|
+
+ 1) # \n (1c)
|
|
157
|
+
|
|
158
|
+
self.msg_type = 2 # START TRANSACTION
|
|
159
|
+
|
|
160
|
+
format_str = "=ciiiciiiiiiqqq{}s{}s{}s{}s{}s{}sc".format(self.len_fp_header, self.len_url,
|
|
161
|
+
self.len_btHeaderValue, self.len_ndCookieSet,
|
|
162
|
+
self.len_nvCookieSet, self.len_correlationHeader)
|
|
163
|
+
|
|
164
|
+
start_transaction_message_struct = struct.Struct(format_str)
|
|
165
|
+
|
|
166
|
+
start_transaction_message_values = (bytes('^', "utf-8"),
|
|
167
|
+
self.header_len,
|
|
168
|
+
self.total_len,
|
|
169
|
+
self.msg_type,
|
|
170
|
+
bytes('|', "utf-8"),
|
|
171
|
+
self.len_fp_header,
|
|
172
|
+
self.len_url,
|
|
173
|
+
self.len_btHeaderValue,
|
|
174
|
+
self.len_ndCookieSet,
|
|
175
|
+
self.len_nvCookieSet,
|
|
176
|
+
self.len_correlationHeader,
|
|
177
|
+
self.flow_path_instance,
|
|
178
|
+
self.qTimeMS,
|
|
179
|
+
self.startTimeFP,
|
|
180
|
+
self.fp_header.encode('utf-8'),
|
|
181
|
+
self.url.encode('utf-8'),
|
|
182
|
+
self.btHeaderValue.encode('utf-8'),
|
|
183
|
+
self.ndCookieSet.encode('utf-8'),
|
|
184
|
+
self.nvCookieSet.encode('utf-8'),
|
|
185
|
+
self.correlationHeader.encode('utf-8'),
|
|
186
|
+
bytes('\n', "utf-8"))
|
|
187
|
+
|
|
188
|
+
start_transaction_message_packet = start_transaction_message_struct.pack(*start_transaction_message_values)
|
|
189
|
+
|
|
190
|
+
return start_transaction_message_packet
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
class MethodEntryMessage(object):
|
|
194
|
+
|
|
195
|
+
def __init__(self, methodName, query_string, url_parameter, query_parameter, flow_path_instance):
|
|
196
|
+
self.methodName = methodName
|
|
197
|
+
self.query_string = query_string
|
|
198
|
+
self.urlParameter = url_parameter
|
|
199
|
+
self.query_parameter = query_parameter
|
|
200
|
+
|
|
201
|
+
self.mid = 0 # DUMMY
|
|
202
|
+
self.flow_path_instance = flow_path_instance
|
|
203
|
+
self.threadId = 0 # DUMMY
|
|
204
|
+
self.startTime = 0 # DUMMY
|
|
205
|
+
|
|
206
|
+
def encode(self):
|
|
207
|
+
|
|
208
|
+
self.len_methodName = len(self.methodName)
|
|
209
|
+
self.len_query_string = len(self.query_string)
|
|
210
|
+
self.len_urlParameter = len(self.urlParameter)
|
|
211
|
+
self.len_query_parameter = len(self.query_parameter)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
self.header_len = (4 # header_len(int)
|
|
215
|
+
+ 4 # total_len(int)
|
|
216
|
+
+ 4) # msg_type(int)
|
|
217
|
+
|
|
218
|
+
self.total_len = (1 # ^ (1c)
|
|
219
|
+
+ 4 # header_len(int)
|
|
220
|
+
+ 4 # total_len(int)
|
|
221
|
+
+ 4 # msg_type(int)
|
|
222
|
+
+ 1 # | (1c)
|
|
223
|
+
+ 4 # mid(int)
|
|
224
|
+
+ 8 # flow_path_instance(long long)
|
|
225
|
+
+ 8 # threadId(long)
|
|
226
|
+
+ 8 # startTime(long long)
|
|
227
|
+
+ 4 # len_methodName(int)
|
|
228
|
+
+ 4 # len_query_string(int)
|
|
229
|
+
+ 4 # len_urlParameter(int)
|
|
230
|
+
+ 4 # len_query_parameter
|
|
231
|
+
+ self.len_methodName # variable
|
|
232
|
+
+ self.len_query_string # variable
|
|
233
|
+
+ self.len_urlParameter # variable
|
|
234
|
+
+ self.len_query_parameter # variable
|
|
235
|
+
+ 1) # \n (1c)
|
|
236
|
+
|
|
237
|
+
self.msg_type = 0 # METHOD ENTRY
|
|
238
|
+
|
|
239
|
+
format_str = "=ciiiciqqqiiii{}s{}s{}s{}sc".format(self.len_methodName, self.len_query_string, self.len_urlParameter, self.len_query_parameter)
|
|
240
|
+
|
|
241
|
+
method_entry_message_struct = struct.Struct(format_str)
|
|
242
|
+
|
|
243
|
+
method_entry_message_values = (bytes('^', "utf-8"),
|
|
244
|
+
self.header_len,
|
|
245
|
+
self.total_len,
|
|
246
|
+
self.msg_type,
|
|
247
|
+
bytes('|', "utf-8"),
|
|
248
|
+
self.mid,
|
|
249
|
+
self.flow_path_instance,
|
|
250
|
+
self.threadId,
|
|
251
|
+
self.startTime,
|
|
252
|
+
self.len_methodName,
|
|
253
|
+
self.len_query_string,
|
|
254
|
+
self.len_urlParameter,
|
|
255
|
+
self.len_query_parameter,
|
|
256
|
+
self.methodName.encode('utf-8'),
|
|
257
|
+
self.query_string.encode('utf-8'),
|
|
258
|
+
self.urlParameter.encode('utf-8'),
|
|
259
|
+
self.query_parameter.encode('utf-8'),
|
|
260
|
+
bytes('\n', "utf-8"))
|
|
261
|
+
|
|
262
|
+
method_entry_message_packet = method_entry_message_struct.pack(*method_entry_message_values)
|
|
263
|
+
|
|
264
|
+
return method_entry_message_packet
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
class MethodExitMessage(object):
|
|
268
|
+
|
|
269
|
+
def __init__(self, methodName, backend_header, status, duration, flow_path_instance):
|
|
270
|
+
|
|
271
|
+
self.methodName = methodName
|
|
272
|
+
self.backend_header = backend_header
|
|
273
|
+
self.requestNotificationPhase = ""
|
|
274
|
+
self.statusCode = status
|
|
275
|
+
self.duration = duration
|
|
276
|
+
self.mid = 0 # DUMMY
|
|
277
|
+
self.eventType = 0 # DUMMY
|
|
278
|
+
self.isCallout = 1 # DUMMY 1
|
|
279
|
+
self.threadId = 0 # DUMMY threading.get_ident()
|
|
280
|
+
self.flow_path_instance = flow_path_instance
|
|
281
|
+
self.cpuTime = 0 # DUMMY
|
|
282
|
+
|
|
283
|
+
self.len_methodName = None
|
|
284
|
+
self.len_backend_header = None
|
|
285
|
+
self.len_requestNotificationPhase = None
|
|
286
|
+
|
|
287
|
+
self.tierCallOutSeqNum = 1 # DUMMY
|
|
288
|
+
self.endTime = 0 # DUMMY
|
|
289
|
+
|
|
290
|
+
self.header_len = None
|
|
291
|
+
self.total_len = None
|
|
292
|
+
|
|
293
|
+
self.msg_type = 1 # METHOD EXIT
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def encode(self):
|
|
297
|
+
self.len_methodName = len(self.methodName)
|
|
298
|
+
self.len_backend_header = len(self.backend_header)
|
|
299
|
+
self.len_requestNotificationPhase = 0
|
|
300
|
+
|
|
301
|
+
self.header_len = (4 # header_len(int)
|
|
302
|
+
+ 4 # total_len(int)
|
|
303
|
+
+ 4) # msg_type(int)
|
|
304
|
+
|
|
305
|
+
#self.total_len = 3 + 12 + 80 + self.len_methodName + self.len_backend_header + self.len_requestNotificationPhase
|
|
306
|
+
|
|
307
|
+
self.total_len = (1 # ^ (1c)
|
|
308
|
+
+ 4 # header_len(int)
|
|
309
|
+
+ 4 # total_len(int)
|
|
310
|
+
+ 4 # msg_type(int)
|
|
311
|
+
+ 1 # | (1c)
|
|
312
|
+
+ 4 # status_code(int)
|
|
313
|
+
+ 4 # mid(int)
|
|
314
|
+
+ 4 # eventType(int)
|
|
315
|
+
+ 4 # isCallout(int)
|
|
316
|
+
+ 8 # threadId(long)
|
|
317
|
+
+ 8 # duration(long)
|
|
318
|
+
+ 8 # flow_path_instance(long long)
|
|
319
|
+
+ 8 # cpuTime(long long)
|
|
320
|
+
+ 4 # len_methodName(int)
|
|
321
|
+
+ 4 # len_backend_header(int)
|
|
322
|
+
+ 4 # len_requestNotificationPhase(int)
|
|
323
|
+
+ 8 # tierCallOutSeqNum(long long)
|
|
324
|
+
+ 8 # endTime(long long)
|
|
325
|
+
+ self.len_methodName # variable
|
|
326
|
+
+ self.len_backend_header # variable
|
|
327
|
+
+ self.len_requestNotificationPhase # variable
|
|
328
|
+
+ 1) # \n (1c)
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
format_str = "=ciiiciiiiqqqqiiiqq{}s{}s{}sc".format(self.len_methodName, self.len_backend_header, self.len_requestNotificationPhase)
|
|
332
|
+
|
|
333
|
+
method_exit_message_struct = struct.Struct(format_str)
|
|
334
|
+
|
|
335
|
+
method_exit_message_values = (bytes('^', "utf-8"),
|
|
336
|
+
self.header_len,
|
|
337
|
+
self.total_len,
|
|
338
|
+
self.msg_type,
|
|
339
|
+
bytes('|', "utf-8"),
|
|
340
|
+
self.statusCode,
|
|
341
|
+
self.mid,
|
|
342
|
+
self.eventType,
|
|
343
|
+
self.isCallout,
|
|
344
|
+
self.threadId,
|
|
345
|
+
self.duration,
|
|
346
|
+
self.flow_path_instance,
|
|
347
|
+
self.cpuTime,
|
|
348
|
+
self.len_methodName,
|
|
349
|
+
self.len_backend_header,
|
|
350
|
+
self.len_requestNotificationPhase,
|
|
351
|
+
self.tierCallOutSeqNum,
|
|
352
|
+
self.endTime,
|
|
353
|
+
self.methodName.encode('utf-8'),
|
|
354
|
+
self.backend_header.encode('utf-8'),
|
|
355
|
+
self.requestNotificationPhase.encode('utf-8'),
|
|
356
|
+
bytes('\n', "utf-8"))
|
|
357
|
+
|
|
358
|
+
method_exit_message_packet = method_exit_message_struct.pack(*method_exit_message_values)
|
|
359
|
+
logger.debug("status {} duration {}".format(self.statusCode, self.duration))
|
|
360
|
+
|
|
361
|
+
return method_exit_message_packet
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
class EndTransactionMessage(object):
|
|
365
|
+
|
|
366
|
+
def __init__(self, status_code, flow_path_instance, trace_request):
|
|
367
|
+
|
|
368
|
+
self.status_code = status_code
|
|
369
|
+
self.flow_path_instance = flow_path_instance
|
|
370
|
+
self.endTime = 0 # DUMMY
|
|
371
|
+
self.cpuTime = 0 # DUMMY
|
|
372
|
+
self.header_len = None
|
|
373
|
+
self.total_len = None
|
|
374
|
+
self.msg_type = 3 # END TRANSACTION
|
|
375
|
+
self.trace_request = trace_request
|
|
376
|
+
|
|
377
|
+
def encode(self):
|
|
378
|
+
|
|
379
|
+
self.header_len = (4 # header_len(int)
|
|
380
|
+
+ 4 # total_len(int)
|
|
381
|
+
+ 4) # msg_type(int)
|
|
382
|
+
|
|
383
|
+
#self.total_len = 3 + 12 + 32
|
|
384
|
+
|
|
385
|
+
self.total_len = (1 # ^ (1c)
|
|
386
|
+
+ 4 # header_len(int)
|
|
387
|
+
+ 4 # total_len(int)
|
|
388
|
+
+ 4 # msg_type(int)
|
|
389
|
+
+ 1 # | (1c)
|
|
390
|
+
+ 4 # status_code(int)
|
|
391
|
+
+ 8 # flow_path_instance(long long)
|
|
392
|
+
+ 8 # endTime(long long)
|
|
393
|
+
+ 8 # cpuTime(long long)
|
|
394
|
+
+ 4 # trace_request(int)
|
|
395
|
+
+ 1) # \n (1c)
|
|
396
|
+
|
|
397
|
+
end_transaction_message_struct = struct.Struct("=ciiiciqqqic")
|
|
398
|
+
|
|
399
|
+
end_transaction_message_values = (bytes('^', "utf-8"),
|
|
400
|
+
self.header_len,
|
|
401
|
+
self.total_len,
|
|
402
|
+
self.msg_type,
|
|
403
|
+
bytes('|', "utf-8"),
|
|
404
|
+
self.status_code,
|
|
405
|
+
self.flow_path_instance,
|
|
406
|
+
self.endTime,
|
|
407
|
+
self.cpuTime,
|
|
408
|
+
self.trace_request,
|
|
409
|
+
bytes('\n', "utf-8"))
|
|
410
|
+
|
|
411
|
+
end_transaction_message_packet = end_transaction_message_struct.pack(*end_transaction_message_values)
|
|
412
|
+
|
|
413
|
+
return end_transaction_message_packet
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
class TransactionEncodeHttpMessage(object):
|
|
417
|
+
|
|
418
|
+
def __init__(self, bt, rbuffer, rtype, statuscode, flow_path_instance, otl_trace_id="", otl_parent_id="", otl_trace_state=""):
|
|
419
|
+
|
|
420
|
+
# bt = 140544547110928
|
|
421
|
+
# http_host = "www.google.com"
|
|
422
|
+
# url = "/"
|
|
423
|
+
self.buffer = rbuffer
|
|
424
|
+
self.type = rtype
|
|
425
|
+
self.statuscode = statuscode
|
|
426
|
+
self.flow_path_instance = flow_path_instance
|
|
427
|
+
self.otl_trace_id = otl_trace_id
|
|
428
|
+
self.otl_parent_id = otl_parent_id
|
|
429
|
+
self.otl_trace_state = otl_trace_state
|
|
430
|
+
self.otl_version = 1
|
|
431
|
+
self.otl_trace_flag = 0
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
def encode(self):
|
|
435
|
+
self.len_buffer = len(self.buffer)
|
|
436
|
+
self.len_type = len(self.type)
|
|
437
|
+
self.len_otl_trace_id = len(self.otl_trace_id)
|
|
438
|
+
self.len_otl_parent_id = len(self.otl_parent_id)
|
|
439
|
+
self.len_otl_trace_state = len(self.otl_trace_state)
|
|
440
|
+
|
|
441
|
+
self.header_len = (4 # header_len(int)
|
|
442
|
+
+ 4 # total_len(int)
|
|
443
|
+
+ 4) # msg_type(int)
|
|
444
|
+
|
|
445
|
+
self.total_len = (1 # ^ (1c)
|
|
446
|
+
+ 4 # header_len(int)
|
|
447
|
+
+ 4 # total_len(int)
|
|
448
|
+
+ 4 # msg_type(int)
|
|
449
|
+
+ 1 # | (1c)
|
|
450
|
+
+ 4 # status_code(int)
|
|
451
|
+
+ 4 # buffer_len(int)
|
|
452
|
+
+ 4 # type_len(int)
|
|
453
|
+
+ 4 # otl_version(int)
|
|
454
|
+
+ 4 # otl_trace_flag(int)
|
|
455
|
+
+ 4 # len_otl_trace_id(int)
|
|
456
|
+
+ 4 # len_otl_parent_id(int)
|
|
457
|
+
+ 4 # len_otl_trace_state(int)
|
|
458
|
+
+ 8 # flow_path_instance(long long)
|
|
459
|
+
+ self.len_buffer # variable
|
|
460
|
+
+ self.len_type # variable
|
|
461
|
+
+ self.len_otl_trace_id # variable
|
|
462
|
+
+ self.len_otl_parent_id # variable
|
|
463
|
+
+ self.len_otl_trace_state # variable
|
|
464
|
+
+ 1) # \n (1c)
|
|
465
|
+
|
|
466
|
+
self.msg_type = 6
|
|
467
|
+
|
|
468
|
+
format_str = "=ciiiciiiiiiiiq{}s{}s{}s{}s{}sc".format(self.len_buffer,
|
|
469
|
+
self.len_type,
|
|
470
|
+
self.len_otl_trace_id,
|
|
471
|
+
self.len_otl_parent_id,
|
|
472
|
+
self.len_otl_trace_state)
|
|
473
|
+
|
|
474
|
+
transaction_encode_http_message_struct = struct.Struct(format_str)
|
|
475
|
+
|
|
476
|
+
transaction_encode_http_message_values = (bytes('^', "utf-8"),
|
|
477
|
+
self.header_len,
|
|
478
|
+
self.total_len,
|
|
479
|
+
self.msg_type,
|
|
480
|
+
bytes('|', "utf-8"),
|
|
481
|
+
self.statuscode,
|
|
482
|
+
self.len_buffer,
|
|
483
|
+
self.len_type,
|
|
484
|
+
self.otl_version,
|
|
485
|
+
self.otl_trace_flag,
|
|
486
|
+
self.len_otl_trace_id,
|
|
487
|
+
self.len_otl_parent_id,
|
|
488
|
+
self.len_otl_trace_state,
|
|
489
|
+
self.flow_path_instance,
|
|
490
|
+
self.buffer.encode('utf-8'),
|
|
491
|
+
self.type.encode('utf-8'),
|
|
492
|
+
self.otl_trace_id.encode('utf-8'),
|
|
493
|
+
self.otl_parent_id.encode('utf-8'),
|
|
494
|
+
self.otl_trace_state.encode('utf-8'),
|
|
495
|
+
bytes('\n', "utf-8"))
|
|
496
|
+
|
|
497
|
+
transaction_encode_http_message_packet = transaction_encode_http_message_struct.pack(*transaction_encode_http_message_values)
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
return transaction_encode_http_message_packet
|
|
501
|
+
|
|
502
|
+
class ExceptionEncodeMessage(object):
|
|
503
|
+
|
|
504
|
+
def __init__(self,
|
|
505
|
+
line_number,
|
|
506
|
+
exception_class_name,
|
|
507
|
+
exception_throwing_class_name,
|
|
508
|
+
exception_throwing_method_name,
|
|
509
|
+
exception_message,
|
|
510
|
+
exception_cause,
|
|
511
|
+
exception_stack_trace,
|
|
512
|
+
flow_path_instance,
|
|
513
|
+
start_time):
|
|
514
|
+
|
|
515
|
+
self.line_number = line_number
|
|
516
|
+
self.exception_class_name = exception_class_name
|
|
517
|
+
self.exception_throwing_class_name = exception_throwing_class_name
|
|
518
|
+
self.exception_throwing_method_name = exception_throwing_method_name
|
|
519
|
+
self.exception_message = exception_message
|
|
520
|
+
self.exception_cause = exception_cause
|
|
521
|
+
self.exception_stack_trace = exception_stack_trace
|
|
522
|
+
self.flow_path_instance = flow_path_instance
|
|
523
|
+
self.start_time = start_time
|
|
524
|
+
|
|
525
|
+
def encode(self):
|
|
526
|
+
self.len_of_exception_class_name = len(self.exception_class_name)
|
|
527
|
+
self.len_of_exception_throwing_class_name = len(self.exception_throwing_class_name)
|
|
528
|
+
self.len_of_exception_throwing_method_name = len(self.exception_throwing_method_name)
|
|
529
|
+
self.len_of_exception_message = len(self.exception_message)
|
|
530
|
+
self.len_of_exception_cause = len(self.exception_cause)
|
|
531
|
+
self.len_of_exception_stack_trace = len(self.exception_stack_trace)
|
|
532
|
+
|
|
533
|
+
self.header_len = (4 # header_len(int)
|
|
534
|
+
+ 4 # total_len(int)
|
|
535
|
+
+ 4) # msg_type(int)
|
|
536
|
+
|
|
537
|
+
self.total_len = (1 # ^ (1c)
|
|
538
|
+
+ 4 # header_len(int)
|
|
539
|
+
+ 4 # total_len(int)
|
|
540
|
+
+ 4 # msg_type(int)
|
|
541
|
+
+ 1 # | (1c)
|
|
542
|
+
+ 4 # int lineNumber
|
|
543
|
+
+ 4 # int lenofExceptionClassName
|
|
544
|
+
+ 4 # int lenofExceptionThrowingClassName
|
|
545
|
+
+ 4 # int lenofExceptionThrowingMethodName
|
|
546
|
+
+ 4 # int lenofExceptionMessage
|
|
547
|
+
+ 4 # int lenofExceptionCause
|
|
548
|
+
+ 4 # int lenofExceptionStackTrace
|
|
549
|
+
+ 8 # long long flowpathInstance;
|
|
550
|
+
+ 8 # long long startTime
|
|
551
|
+
+ self.len_of_exception_class_name # char* ExceptionClassName
|
|
552
|
+
+ self.len_of_exception_throwing_class_name # char* ExceptionThrowingClassName;
|
|
553
|
+
+ self.len_of_exception_throwing_method_name # char* ExceptionThrowingMethodName;
|
|
554
|
+
+ self.len_of_exception_message # char* ExceptionMessage;
|
|
555
|
+
+ self.len_of_exception_cause # char* ExceptionCause;
|
|
556
|
+
+ self.len_of_exception_stack_trace # char* ExceptionStackTrace;
|
|
557
|
+
+ 1) # \n (1c)
|
|
558
|
+
|
|
559
|
+
self.msg_type = 5
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
format_str = "=ciiiciiiiiiiqq{}s{}s{}s{}s{}s{}sc".format(self.len_of_exception_class_name,
|
|
563
|
+
self.len_of_exception_throwing_class_name,
|
|
564
|
+
self.len_of_exception_throwing_method_name,
|
|
565
|
+
self.len_of_exception_message,
|
|
566
|
+
self.len_of_exception_cause,
|
|
567
|
+
self.len_of_exception_stack_trace)
|
|
568
|
+
|
|
569
|
+
exception_encode_message_struct = struct.Struct(format_str)
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
exception_encode_message_values = (bytes('^', "utf-8"),
|
|
573
|
+
self.header_len,
|
|
574
|
+
self.total_len,
|
|
575
|
+
self.msg_type,
|
|
576
|
+
bytes('|', "utf-8"),
|
|
577
|
+
self.line_number,
|
|
578
|
+
self.len_of_exception_class_name,
|
|
579
|
+
self.len_of_exception_throwing_class_name,
|
|
580
|
+
self.len_of_exception_throwing_method_name,
|
|
581
|
+
self.len_of_exception_message,
|
|
582
|
+
self.len_of_exception_cause,
|
|
583
|
+
self.len_of_exception_stack_trace,
|
|
584
|
+
self.flow_path_instance,
|
|
585
|
+
self.start_time,
|
|
586
|
+
self.exception_class_name.encode('utf-8'),
|
|
587
|
+
self.exception_throwing_class_name.encode('utf-8'),
|
|
588
|
+
self.exception_throwing_method_name.encode('utf-8'),
|
|
589
|
+
self.exception_message.encode('utf-8'),
|
|
590
|
+
self.exception_cause.encode('utf-8'),
|
|
591
|
+
self.exception_stack_trace.encode('utf-8'),
|
|
592
|
+
bytes('\n', "utf-8"))
|
|
593
|
+
|
|
594
|
+
exception_encode_message_packet = exception_encode_message_struct.pack(*exception_encode_message_values)
|
|
595
|
+
|
|
596
|
+
return exception_encode_message_packet
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
class HavocMessage(object):
|
|
600
|
+
|
|
601
|
+
def __init__(self, havoc_header):
|
|
602
|
+
self.havoc_header = havoc_header
|
|
603
|
+
self.len_havoc_header = None
|
|
604
|
+
|
|
605
|
+
def encode(self):
|
|
606
|
+
|
|
607
|
+
self.len_havoc_header = len(self.havoc_header)
|
|
608
|
+
|
|
609
|
+
format_str = "=c{}s".format(self.len_havoc_header)
|
|
610
|
+
|
|
611
|
+
havoc_message_struct = struct.Struct(format_str)
|
|
612
|
+
|
|
613
|
+
havoc_message_values = (bytes('^', "utf-8"),
|
|
614
|
+
self.havoc_header.encode('utf-8'))
|
|
615
|
+
|
|
616
|
+
havoc_message_packet = havoc_message_struct.pack(*havoc_message_values)
|
|
617
|
+
|
|
618
|
+
return havoc_message_packet
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
def create_start_transaction_message(context, bt_name, correlation_header, agent_obj):
|
|
622
|
+
header = Header(context, context.api_request_id, context.aws_request_id, context.function_name, agent_obj)
|
|
623
|
+
header_packet = header.encode()
|
|
624
|
+
|
|
625
|
+
start_transaction_message = StartTransactionMessage(bt_name, context.flow_path_id)
|
|
626
|
+
start_transaction_message_packet = start_transaction_message.encode()
|
|
627
|
+
|
|
628
|
+
full_packet = header_packet + start_transaction_message_packet
|
|
629
|
+
|
|
630
|
+
return full_packet
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
def create_method_entry_message(context, bt, method, query_string, url_parameter, query_parameter, agent_obj):
|
|
634
|
+
|
|
635
|
+
header = Header(context, context.api_request_id, context.aws_request_id, context.function_name, agent_obj)
|
|
636
|
+
header_packet = header.encode()
|
|
637
|
+
|
|
638
|
+
method_entry_message = MethodEntryMessage(method, query_string, url_parameter, query_parameter, context.flow_path_id)
|
|
639
|
+
method_entry_message_packet = method_entry_message.encode()
|
|
640
|
+
|
|
641
|
+
full_packet = header_packet + method_entry_message_packet
|
|
642
|
+
|
|
643
|
+
return full_packet
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
def create_method_exit_message(context, bt, method, backend_header, status, duration, agent_obj):
|
|
647
|
+
header = Header(context, context.api_request_id, context.aws_request_id, context.function_name, agent_obj)
|
|
648
|
+
header_packet = header.encode()
|
|
649
|
+
|
|
650
|
+
method_exit_message = MethodExitMessage(method, backend_header, status, duration, context.flow_path_id)
|
|
651
|
+
method_exit_message_packet = method_exit_message.encode()
|
|
652
|
+
|
|
653
|
+
full_packet = header_packet + method_exit_message_packet
|
|
654
|
+
|
|
655
|
+
return full_packet
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
def create_end_transaction_message(context, bt, statuscode, agent_obj):
|
|
659
|
+
header = Header(context, context.api_request_id, context.aws_request_id, context.function_name, agent_obj)
|
|
660
|
+
header_packet = header.encode()
|
|
661
|
+
if context.havoc_applied:
|
|
662
|
+
trace_request = 4
|
|
663
|
+
else:
|
|
664
|
+
trace_request = 0
|
|
665
|
+
|
|
666
|
+
end_transaction_message = EndTransactionMessage(statuscode, context.flow_path_id, trace_request)
|
|
667
|
+
end_transaction_message_packet = end_transaction_message.encode()
|
|
668
|
+
|
|
669
|
+
full_packet = header_packet + end_transaction_message_packet
|
|
670
|
+
|
|
671
|
+
return full_packet
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
def create_havoc_message(context, havoc_header, agent_obj):
|
|
675
|
+
|
|
676
|
+
header = Header(context, context.api_request_id, context.aws_request_id, context.function_name, agent_obj)
|
|
677
|
+
msg_type = "havoc"
|
|
678
|
+
header_packet = header.encode(msg_type)
|
|
679
|
+
|
|
680
|
+
havoc_message = HavocMessage(havoc_header)
|
|
681
|
+
havoc_message_packet = havoc_message.encode()
|
|
682
|
+
|
|
683
|
+
full_packet = header_packet + havoc_message_packet
|
|
684
|
+
|
|
685
|
+
return full_packet
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
def create_transaction_encode_http_message(context, bt, rbuffer, rtype, statuscode, agent_obj):
|
|
689
|
+
|
|
690
|
+
header = Header(context, context.api_request_id, context.aws_request_id, context.function_name, agent_obj)
|
|
691
|
+
header_packet = header.encode()
|
|
692
|
+
transaction_encode_http_message = TransactionEncodeHttpMessage(bt, rbuffer, rtype, statuscode, context.flow_path_id)
|
|
693
|
+
transaction_encode_http_message_packet = transaction_encode_http_message.encode()
|
|
694
|
+
|
|
695
|
+
full_packet = header_packet + transaction_encode_http_message_packet
|
|
696
|
+
|
|
697
|
+
return full_packet
|
|
698
|
+
|
|
699
|
+
def create_exception_encode_message(context, line_number, exception_class_name,
|
|
700
|
+
exception_throwing_class_name, exception_throwing_method_name,
|
|
701
|
+
exception_message, exception_cause, exception_stack_trace, start_time, agent_obj):
|
|
702
|
+
|
|
703
|
+
header = Header(context, context.api_request_id, context.aws_request_id, context.function_name, agent_obj)
|
|
704
|
+
header_packet = header.encode()
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
exception_encode_message = ExceptionEncodeMessage(line_number,
|
|
708
|
+
exception_class_name,
|
|
709
|
+
exception_throwing_class_name,
|
|
710
|
+
exception_throwing_method_name,
|
|
711
|
+
exception_message,
|
|
712
|
+
exception_cause,
|
|
713
|
+
exception_stack_trace,
|
|
714
|
+
context.flow_path_id,
|
|
715
|
+
start_time)
|
|
716
|
+
|
|
717
|
+
exception_encode_message_packet = exception_encode_message.encode()
|
|
718
|
+
|
|
719
|
+
full_packet = header_packet + exception_encode_message_packet
|
|
720
|
+
|
|
721
|
+
return full_packet
|
|
722
|
+
|
|
723
|
+
class InitMessage(object):
|
|
724
|
+
|
|
725
|
+
def __init__(self):
|
|
726
|
+
self.buffer = "dummy_buffer"
|
|
727
|
+
|
|
728
|
+
def encode(self):
|
|
729
|
+
init_message_struct = struct.Struct("=c")
|
|
730
|
+
init_message_values = (bytes('^', "utf-8"),)
|
|
731
|
+
init_message_packet = init_message_struct.pack(*init_message_values)
|
|
732
|
+
return init_message_packet
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
def create_init_message(context, agent_obj):
|
|
736
|
+
header = Header(context, context.api_request_id, context.aws_request_id, context.function_name, agent_obj)
|
|
737
|
+
logger.debug('function name inside wrap header {}'.format(context.function_name))
|
|
738
|
+
msg_type = "init"
|
|
739
|
+
header_packet = header.encode(msg_type)
|
|
740
|
+
|
|
741
|
+
init_message = InitMessage()
|
|
742
|
+
init_message_encode_packet = init_message.encode()
|
|
743
|
+
|
|
744
|
+
full_packet = header_packet + init_message_encode_packet
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
return full_packet
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
class AgentInitializeMessage(object):
|
|
751
|
+
|
|
752
|
+
def __init__(self):
|
|
753
|
+
pass
|
|
754
|
+
|
|
755
|
+
def encode(self):
|
|
756
|
+
agent_initialize_message_struct = struct.Struct("=c")
|
|
757
|
+
agent_initialize_message_values = (bytes('\n', "utf-8"),)
|
|
758
|
+
agent_initialize_message_packet = agent_initialize_message_struct.pack(*agent_initialize_message_values)
|
|
759
|
+
return agent_initialize_message_packet
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
def create_agent_initialize_message(context, agent_obj):
|
|
763
|
+
header = Header(context, context.api_request_id, context.aws_request_id, context.function_name, agent_obj)
|
|
764
|
+
logger.debug('function name inside wrap header {}'.format(context.function_name))
|
|
765
|
+
msg_type = "agent_initialize"
|
|
766
|
+
header_packet = header.encode(msg_type)
|
|
767
|
+
|
|
768
|
+
agent_initialize_message = AgentInitializeMessage()
|
|
769
|
+
agent_initialize_message_encode_packet = agent_initialize_message.encode()
|
|
770
|
+
|
|
771
|
+
full_packet = header_packet + agent_initialize_message_encode_packet
|
|
772
|
+
|
|
773
|
+
return full_packet
|
|
774
|
+
|
|
775
|
+
|
|
776
|
+
class HeartbeatMessage(object):
|
|
777
|
+
|
|
778
|
+
def __init__(self):
|
|
779
|
+
self.buffer = "dummy_buffer"
|
|
780
|
+
|
|
781
|
+
def encode(self):
|
|
782
|
+
|
|
783
|
+
heartbeat_message_struct = struct.Struct("=c")
|
|
784
|
+
heartbeat_message_values = (bytes('^', "utf-8"),)
|
|
785
|
+
heartbeat_message_packet = heartbeat_message_struct.pack(*heartbeat_message_values)
|
|
786
|
+
return heartbeat_message_packet
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
def create_heartbeat_message(context, agent_obj):
|
|
790
|
+
header = Header(context, context.api_request_id, context.aws_request_id, context.function_name, agent_obj)
|
|
791
|
+
logger.debug('function name inside wrap header {}'.format(context.function_name))
|
|
792
|
+
msg_type = "heartbeat"
|
|
793
|
+
header_packet = header.encode(msg_type)
|
|
794
|
+
|
|
795
|
+
heartbeat_message = HeartbeatMessage()
|
|
796
|
+
heartbeat_message_encode_packet = heartbeat_message.encode()
|
|
797
|
+
|
|
798
|
+
full_packet = header_packet + heartbeat_message_encode_packet
|
|
799
|
+
|
|
800
|
+
return full_packet
|