@@ -242,6 +242,43 @@ def add_comment(self, **kwargs):
242242
243243 return res .text
244244
245+ def run_query (self , ** kwargs ):
246+
247+ # Get a client credential access token
248+ auth = self .authenticate (
249+ kwargs ["tenant_id" ], kwargs ["client_id" ], kwargs ["client_secret" ]
250+ )
251+ if not auth ["success" ]:
252+ return {"error" : auth ["message" ]}
253+
254+ query_url = f"{ self .azure_url } /subscriptions/{ kwargs ['subscription_id' ]} /resourceGroups/{ kwargs ['resource_group_name' ]} /providers/Microsoft.OperationalInsights/workspaces/{ kwargs ['workspace_name' ]} /savedSearches"
255+
256+ #providers/Microsoft.SecurityInsights/incidents/{kwargs['incident_id']}/comments"
257+
258+ #PUT https://management.azure.com/subscriptions/{subscriptionId} _
259+ #/resourcegroups/{resourceGroupName} _
260+ #/providers/Microsoft.OperationalInsights/workspaces/{workspaceName} _
261+ #/savedSearches/{savedSearchId}?api-version=2020-03-01-preview
262+
263+
264+ params = {"api-version" : "2020-01-01" }
265+
266+ comment_id = str (uuid .uuid4 ())
267+ comment_data = {
268+ "properties" : {
269+ "Category" : kwargs ["query_category" ],
270+ "DisplayName" : kwargs ["query_name" ],
271+ "Query" : {kwargs ['query' ]},
272+ }
273+ }
274+
275+
276+ res = self .s .put (f"{ comment_url } /{ comment_id } " , json = comment_data , params = params )
277+ if res .status_code != 200 :
278+ raise ConnectionError (res .text )
279+
280+ return res .text
281+
245282
246283if __name__ == "__main__" :
247284 AzureSentinel .run ()
0 commit comments