'''Alerts=============Methods described in this section relate to the alerts API.These methods can be accessed at ``TenableIE.alerts``... rst-class:: hide-signature.. autoclass:: AlertsAPI :members:'''fromtypingimportList,Dictfromtenable.ie.alert.schemaimportAlertSchema,AlertParamsSchemafromtenable.ie.base.iteratorimportADIteratorfromtenable.base.endpointimportAPIEndpointclassAlertIterator(ADIterator):''' The alert iterator provides a scalable way to work through alert list result sets of any size. The iterator will walk through each page of data, returning one record at a time. If it reaches the end of a page of records, then it will request the next page of information and then continue to return records from the next page (and the next, and the next) until the counter reaches the total number of records that the API has reported. '''
[docs]deflist_by_profile(self,profile_id:str,**kwargs)->AlertIterator:''' Retrieve all alert instances Args: profile_id (str): The profile instance identifier. archived (optional, bool): is alert archived? read (optional, bool): is alert read? page (optional, int): The page number user wants to retrieve. per_page (optional, int): The number of records per page user wants to retrieve. max_items (optional, int): The maximum number of records to return before stopping iteration. max_pages (optional, int): The maximum number of pages to request before throwing stopping iteration. Returns: :obj:`AlertIterator`: An iterator that handles the page management of the requested records. Examples: >>> for alert in tie.alerts.list_by_profile( ... profile_id='1', ... archived=False, ... read=False, ... page=1, ... per_page=20, ... max_pages=10, ... max_items=200 ... ): ... pprint(alert) '''schema=AlertParamsSchema()params=schema.dump(self._schema.load(kwargs))returnAlertIterator(api=self._api,_path=f'profiles/{profile_id}/alerts',num_pages=params.get('page'),_per_page=params.get('perPage'),_query=params,_schema=schema,max_pages=params.pop('maxPages',None),max_items=params.pop('maxItems',None))
[docs]defdetails(self,alert_id:str)->Dict:''' Retrieves the details of a specific alert. Args: alert_id (str): The alert instance identifier. Returns: dict: the alert object. Examples: >>> tie.alerts.details( ... alert_id='1' ... ) '''returnself._schema.load(self._get(f"{alert_id}"))