class msiempy.EventManager(_QueryExecuteManager): (source)
List-Like object. Interface to execute a event query.
Query events according to destination IP and hostname filters, sorted by AlertID.
from msiempy import EventManager, FieldFilter print('Simple event query sorted by AlertID') events = EventManager( time_range='CURRENT_YEAR', fields=['SrcIP', 'AlertID'], # SrcIP and AlertID are not queried by default filters=[ FieldFilter('DstIP', ['0.0.0.0/0',]), FieldFilter('HostID', ['mail'], operator='CONTAINS')], # Replace "mail" by a test hostname order=(('ASCENDING', 'AlertID')), limit=10) # Should be increased to 500 or 1000 once finish testing for better performance events.load_data() print(events) print(events.get_text(fields=['AlertID','LastTime','SrcIP', 'Rule.msg']))
FieldFilter
with dump_all_fields.py script.Set the note of some events and check if the note is well set.
from msiempy import EventManager, Event events = EventManager( time_range='CURRENT_YEAR', limit=2 ) events.load_data() for event in events : event.set_note("Test note") event.refresh(use_query=False) # Event data will be loaded with ipsGetAlertData API method assert "Test note" in genuine_event['note'], "Error, the note hasn't been added"
Event
and FieldFilter
Class Variable | POSSBILE_ROW_ORDER | "ASCENDING" or "DESCENDING" |
Method | __init__ | Create a new event query. |
Instance Variable | fields | List of query fields |
Instance Variable | limit | Maximum number of rows per query. |
Instance Variable | order | The order is a tuple (direction, field) . Default value is ("DESCENDING", "LastTime"). |
Method | clear_filters | Replace all filters by a non filtering rule. Acts like there is not filters. |
Method | load_data | Load the events data into the list. Wraps around msiempy.event.EventManager._qry_load_data . |
Instance Variable | data | Undocumented |
Method | get_possible_fields | Return the list of possible fields that you can request in a Events query. The list is loaded from the SIEM. |
Method | get_possible_filters | Return the list of possible fields that you can use as a filter in a query. The list is loaded from the SIEM. |
Class Variable | _GROUPTYPE | NO_GROUP : EventManager handles only events see GroupedEventManager for grouped queries |
Instance Variable | _parent | Undocumented |
Method | _get_order | Undocumented |
Method | _set_order | Undocumented |
Instance Variable | _order_direction | Undocumented |
Instance Variable | _order_field | Undocumented |
Instance Variable | _filters | Undocumented |
Method | _qry_load_data | No summary |
Method | _root_parent | Internal method that return the first query of the query tree. |
Inherited from _QueryExecuteManager:
Method | add_filter | Add a filter to the query. |
Static Method | get_field_nickname | Resolve SIEM events field nickname base on Event.SIEM_FIELDS_MAP_INTERNAL_NAME_TO_NICKNAME mapping. Returns the valid query field nickname if found else the initial value. |
Class Variable | _TYPE | EVENT : Flow queries are not implemented (yet) |
Method | _get_filters | Returns SIEM formatted filters for the query structured from msiempy.event.GroupFilter and/or msiempy.event.FieldFilter See msiempy.core.query.FilteredQueryList.filters . |
Method | _close_query | Close the query |
Method | _wait_for | Wait and sleep for the query. |
Method | _get_events | Internal method that will get the query events. Called by _qry_load_data . By default, numRows correspond to limit. |
Inherited from FilteredQueryList (via _QueryExecuteManager):
Instance Variable | not_completed | Boolean signals the query is not completed |
Instance Variable | filters | Query filters |
Instance Variable | start_time | Start time of the query in the right SIEM format. |
Instance Variable | end_time | End time of the query in the right SIEM format. |
Instance Variable | time_range | Query time range. Defaults to "CURRENT_DAY". |
Class Variable | DEFAULT_TIME_RANGE | Default time range : "CURRENT_DAY" |
Class Variable | POSSIBLE_TIME_RANGE | No summary |
Instance Variable | _time_range | Undocumented |
Instance Variable | _start_time | Undocumented |
Instance Variable | _end_time | Undocumented |
Method | _get_time_range | Undocumented |
Method | _set_time_range | Undocumented |
Method | _get_start_time | Undocumented |
Method | _set_start_time | Undocumented |
Method | _get_end_time | Undocumented |
Method | _set_end_time | Undocumented |
Method | _set_filters | Undocumented |
Inherited from NitroList (via _QueryExecuteManager, FilteredQueryList):
Method | __str__ | str(obj) -> return text string. |
Method | keys | List items keys. Every items should have the same set of keys. |
Method | get_text | Return a csv or table string representation of the list |
Method | text | Defaut table string, a shorcut to get_text() with no arguments. |
Method | json | JSON list of dicts representing the list. |
Method | search | Search elements in the list with a regex pattern |
Method | refresh | Execute refresh function on all items. |
Method | perform | Wrapper to execute a function on the list of elements |
Static Method | _confirm_func | Ask user inut to confirm the calling of func on elements . |
Inherited from NitroObject (via _QueryExecuteManager, FilteredQueryList, NitroList):
Class | NitroJSONEncoder | Custom JSON encoder that will use the approprtiate propertie depending of the type of NitroObject. TODO support json json dumping of QueryFilers, may be by making them inherits from NitroDict. |
Instance Variable | nitro | msiempy.core.session.NitroSession object. Interface to the SIEM. |
NO_GROUP
: EventManager handles only events see GroupedEventManager
for grouped queriesstr
)
Create a new event query.
fields
(list[str]
): Query fieldsorder
(tuple(direction, field)
): Query order direction and field. Direction can be "ASCENDING" or "DESCENDING".limit
(int): Max number of rows per query result.filters
(list[tuple(field, [values])
or FieldFilter
or GroupFilter
]): Query filterstime_range
(str
): Query time range. No need to specify "CUSTOM" if start_time and end_time are set.start_time
(str
or datetime
): Query start timeend_time
(str
or datetime
): Query end timeEventManager.get_possible_fields
Event
order
is a tuple (direction, field)
.
Default value is ("DESCENDING", "LastTime").msiempy.event.EventManager
, Query completed? bool
)msiempy.core.session.NitroError
: If any unhandled errors.TimeoutError
: If wait_timeout_sec counter gets to 0.Load the events data into the list.
Wraps around msiempy.event.EventManager._qry_load_data
.
max_query_depth
(int
): Maximum number of reccursive divisions load_data
method can apply to the query in order to load all events. Splits the query in differents time slots if the query apprears not to be completed. Only works with custom times and some time ranges.slots
(int
): number of time slots the query can be divided. Loading bar is divided according to the number of slots. Applicable if max_query_depth>0.delta
(str
): exemple : '2h', the query will be firstly divided in chuncks according to the time delta read with dateutil
. Applicable if max_query_depth>0.workers
(int
): numbre of parrallels tasks, should be equal or less than the number of slots. Applicable if max_query_depth>0.retry
(int
): number of time the query can be failed and retried. (Default value = 1)wait_timeout_sec
(int
): wait timeout in seconds. (Default value = 120)msiempy.event.EventManager