@@ -270,6 +270,7 @@ class Alert:
270270
271271 def __init__ (self ,
272272 alert_id : Optional [str ] = None ,
273+ environment : Optional [str ] = None ,
273274 alert_stream : Optional [BinaryIO ] = None ,
274275 api : IntezerApiClient = None ):
275276 """
@@ -278,6 +279,7 @@ def __init__(self,
278279 instance with the given alert id.
279280
280281 :param alert_id: The alert id.
282+ :param environment: The environment of the alert.
281283 :param api: The API connection to Intezer.
282284 """
283285 if alert_stream and alert_id :
@@ -294,6 +296,7 @@ def __init__(self,
294296 else :
295297 self .alert_id : str = alert_id
296298
299+ self .environment = environment
297300 self ._intezer_api_client = api
298301 self ._api = IntezerApi (api or get_global_api ())
299302 self ._report : Optional [Dict ] = None
@@ -320,12 +323,14 @@ def check_status(self) -> AlertStatusCode:
320323
321324 """
322325 try :
323- alert , status = self ._api .get_alert_by_alert_id (alert_id = self .alert_id )
326+ alert , status = self ._api .get_alert_by_alert_id (alert_id = self .alert_id , environment = self . environment )
324327 except requests .HTTPError :
325328 self .status = AlertStatusCode .NOT_FOUND
326329 raise errors .AlertNotFoundError (self .alert_id )
327330
328331 self ._report = alert
332+ if not self .environment :
333+ self .environment = alert ['environment' ]
329334
330335 if status in (AlertStatusCode .IN_PROGRESS .value , AlertStatusCode .QUEUED .value ):
331336 self .status = AlertStatusCode .IN_PROGRESS
@@ -359,6 +364,7 @@ def result(self) -> dict:
359364 @classmethod
360365 def from_id (cls ,
361366 alert_id : str ,
367+ environment : Optional [str ] = None ,
362368 api : IntezerApiClient = None ,
363369 fetch_scans : bool = False ,
364370 wait : bool = False ,
@@ -367,6 +373,7 @@ def from_id(cls,
367373 Create a new Alert instance, and fetch the alert data from the Intezer Analyze API.
368374
369375 :param alert_id: The alert id.
376+ :param environment: The environment of the alert.
370377 :param api: The API connection to Intezer.
371378 :param fetch_scans: Whether to fetch the scans for the alert - this could take some time.
372379 :param wait: Wait for the alert to finish processing before returning.
@@ -375,7 +382,7 @@ def from_id(cls,
375382 :raises intezer_sdk.errors.AlertInProgressError: If the alert is still being processed.
376383 :return: The Alert instance, with the updated alert data.
377384 """
378- new_alert = cls (alert_id = alert_id , api = api )
385+ new_alert = cls (alert_id = alert_id , environment = environment , api = api )
379386 status = new_alert .check_status ()
380387 if status == AlertStatusCode .IN_PROGRESS and not wait :
381388 raise errors .AlertInProgressError (alert_id )
@@ -488,7 +495,7 @@ def send_phishing_email(cls,
488495 send_alert_params = {key : value for key , value in send_alert_params .items () if value is not None }
489496 alert_id = _api .send_binary_alert (** send_alert_params )
490497
491- alert = cls (alert_id = alert_id , api = api )
498+ alert = cls (alert_id = alert_id , environment = environment , api = api )
492499 if wait :
493500 alert .wait_for_completion (timeout = timeout )
494501 return alert
@@ -550,17 +557,20 @@ def _fetch_scan(scan_: dict,
550557 _fetch_scan (scan , 'url_analysis' , UrlAnalysis )
551558
552559 def get_raw_data (self ,
553- environment : str ,
560+ environment : Optional [ str ] = None ,
554561 raw_data_type : str = 'raw_alert' ) -> dict :
555562 """
556563 Get raw alert data.
557564
558- :param environment: The environment to get raw data from.
565+ :param environment: The environment to get raw data from. If not provided, the environment will be taken from the alert.
559566 :param raw_data_type: The type of raw data to retrieve. Defaults to 'raw_alert'.
560567 :return: The raw alert data.
561568 """
569+ if not environment and not self .environment :
570+ raise ValueError ('Environment is required to get raw data.' )
571+
562572 return self ._api .get_raw_alert_data (
563573 alert_id = self .alert_id ,
564- environment = environment ,
574+ environment = environment or self . environment ,
565575 raw_data_type = raw_data_type
566576 )
0 commit comments