smp_time module
TIPCommon.smp_time.change_timezone
TIPCommon.smp_time.change_timezone(dtime: datetime, current_tz: str, new_tz: str)→ datetime
Changes the time zone of a datetime.datetime object.
Parameters
| Parameters | |
|---|---|
dtime |
datetime.datetimeThe datetime object whose time zone is changed. |
current_tz |
strThe current time zone. |
new_tz |
strThe time zone to change to. |
Returns
A new datetime object with a new time zone.
Return type
datetime.datetime
Raises
ValueError – When one of the time zones is not valid.
TIPCommon.smp_time.convert_string_to_timestamp
TIPCommon.smp_time.convert_string_to_timestamp(datetime_string: str)→ int
Converts a datetime string to a timestamp.
Parameters
| Parameters | |
|---|---|
datetime_string |
strA datetime string. |
Returns
The timestamp.
Return type
int
TIPCommon.smp_time.datetime_to_rfc3339
TIPCommon.smp_time.datetime_to_rfc3339(datetime_obj: datetime)→ str
Converts a datetime object to RFC 3999 representation.
Parameters
| Parameters | |
|---|---|
datetime_obj |
datetime.datetimeThe datetime object to convert. |
Returns
The RFC 3339 representation of the datetime.
Return type
str
TIPCommon.smp_time.get_last_success_time
TIPCommon.smp_time.get_last_success_time(siemplify, offset_with_metric, time_format=2, print_value=True, microtime=False)
Gets the last success time or datetime.
| Parameters | |
|---|---|
siemplify |
objAn instance of the SDK
|
offset_with_metric |
dictThe metric and value. |
time_format |
intThe format of the output time. |
print_value |
Optional
Indicates whether to print
the value or not. |
microtime |
Optional
Indicates whether to return
Unix time including microtime. |
Returns
The last success time.
Return type
Time
TIPCommon.smp_time.get_timestamps
TIPCommon.smp_time.get_timestamps(range_string: str, start_time_string: str, end_time_string: str, error_message: str = None, time_in_milliseconds: bool = False)→ tuple[int, int]
Gets start and end time timestamps.
Parameters
| Parameters | |
|---|---|
range_string |
strThe time range string. |
start_time_string |
strThe start time. |
end_time_string |
strThe end time. |
error_message |
strAn error message for raised exception. Defaults to |
time_in_milliseconds |
boolDefine whether to return start time and end time in milliseconds. Defaults to |
Returns
The start time and end time timestamps.
Return type
tuple
TIPCommon.smp_time.get_timestamps_from_range
TIPCommon.smp_time.get_timestamps_from_range(range_string: str, include_timezone: bool = False)→ tuple[datetime, datetime]
Gets start time and end time timestamps from a range.
Parameters
| Parameters | |
|---|---|
range_string |
strThe time range string. |
include_timezone |
bool, optionalDefine whether to include time zone information in timestamps. Defaults to |
Returns
The start time and end time timestamps.
Return type
tuple
TIPCommon.smp_time.is_approaching_action_timeout
TIPCommon.smp_time.is_approaching_action_timeout(action_execution_deadline_in_unix, timeout_threshold_in_sec=10)
Checks if the action script is approaching its dedicated script deadline.
Each action script has a specific deadline dedicated to it. This function checks
if the current time is less than the deadline by at least
timeout_threshold_in_sec seconds. The default is 10 seconds, meaning that if
the action is 10 or less seconds from its script deadline (at the time of the
check) the function returns True. If the deadline is exceeded, the function
returns False.
| Parameters | |
|---|---|
action_execution_deadline_in_unix |
intThe deadline for action execution. |
timeout_threshold_in_sec |
intThe timeout threshold in seconds. |
Returns
True if timeout is approaching or False in any other case.
TIPCommon.smp_time.is_approaching_timeout
TIPCommon.smp_time.is_approaching_timeout(connector_starting_time, python_process_timeout, timeout_threshold=0.9)
Checks if a timeout is approaching.
| Parameters | |
|---|---|
connector_starting_time |
intThe time the connector started. |
python_process_timeout |
intThe maximum amount of time the connector is allowed to run. |
timeout_threshold |
floatThe threshold at which the connector is considered
to be approaching a timeout. |
Returns
True if the connector is approaching a timeout or False in any other case.
TIPCommon.smp_time.save_timestamp
TIPCommon.smp_time.save_timestamp(siemplify, alerts, timestamp_key='timestamp', incrementation_value=0, log_timestamp=True, convert_timestamp_to_micro_time=False, convert_a_string_timestamp_to_unix=False)
Saves the last timestamp for given alerts.
| Parameters | |
|---|---|
siemplify |
objAn instance of the SDK
|
alerts |
dictThe list of alerts to find the last timestamp. |
timestamp_key |
Optional
The key for getting timestamp
from alert. |
incrementation_value |
Optional
The value to increment the
last timestamp in milliseconds. |
log_timestamp |
Optional
Indicates whether to log the
timestamp or not.
|
convert_timestamp_to_micro_time |
Optional
Indicates whether to convert
the timestamp to microtime. |
convert_a_string_timestamp_to_unix |
Optional
Indicates whether to convert
a string timestamp to Unix. |
Returns
A boolean indicating whether the timestamp is updated.
TIPCommon.smp_time.siemplify_fetch_timestamp
TIPCommon.smp_time.siemplify_fetch_timestamp(siemplify, datetime_format=False, timezone=False)
Fetches the timestamp from Siemplify.
| Parameters | |
|---|---|
siemplify |
objAn instance of the SDK
|
datetime_format |
Optional
Indicates whether to return the timestamp in a |
timezone |
Optional
Indicates whether to return the timestamp in a UTC time zone.
|
Returns
The timestamp.
TIPCommon.smp_time.siemplify_save_timestamp
TIPCommon.smp_time.siemplify_save_timestamp(siemplify, datetime_format=False, timezone=False, new_timestamp=1696256382032)
Saves the timestamp to Siemplify.
| Parameters | |
|---|---|
siemplify |
obj
An instance of the SDK |
datetime_format |
Optional
Indicates whether to save the timestamp in a |
timezone |
Optional
Indicates whether to save the timestamp in a UTC time zone.
|
new_timestamp |
Optional
The new timestamp to save. |
Returns
None.
TIPCommon.smp_time.validate_timestamp
TIPCommon.smp_time.validate_timestamp(last_run_timestamp, offset_in_hours, offset_is_in_days=False)
Validates the timestamp in a time range.
| Parameters | |
|---|---|
last_run_timestamp |
datetimeThe last run timestamp. |
offset_in_hours |
intThe time limit in hours. |
offset_is_in_days |
Optional
Indicates whether the offset is in days.
|
Raises
ValueError - When the timestamp is not valid.
Returns
The validated timestamp.
Return type
datetime
Need more help? Get answers from Community members and Google SecOps professionals.