Hi Guys,
Is it possible to save the event ingested time in a connector? If yes, how can I save it? I tried using
siemplify.fetch_timestamp()
but did not work.
Hi
@Farukh_Shaik
you need to use save_timestamp and not fetch
@Yuli_Dubrovski
well I want to save and also fetch how can I achieve that?
These are 2 separate functions. you need to do save_timestamp for save and then fetch_timestamp for fetch.
Hi
@Yuli_Dubrovski
do you have any documentation of sorts on how to use this save_timestamp like what format does it get saved and what does it return if we fetch the time stamp because I'm getting an integer like this "1657028732071" if I'm saving and fetching it again but I don't know what is this number referring to
@Farukh_Shaik
it's unix timestamp. We don't have internal documentation but I think this might help-
https://www.geeksforgeeks.org/how-to-convert-datetime-to-unix-timestamp-in-python/#:~:text=Unix%20timestamp%20to%2[…]p()%20function%20ignores%20them
(or here you can manually convert unix time to date time
https://www.epochconverter.com/
)
@Farukh_Shaik
and you can take a look on our Misp connector (just to see how we implemented the convert there) I think it's a good example!
Hi
@Yuli_Dubrovski
,
I just have one more doubt so I'm using the
siemplify.save_timestamp() and siemplify.fetch_timestamp()
and I'm getting the result I wanted.
I wrote a loop to fetch and save timestamp but the whenever that loop is starting the fetch time is going back to "1970-01-01 00:00:00+00:00" even after saving it.
Any Idea why is this occurring? I have attached the loop I wrote:
def datetime_params(siemplify):
current_time = datetime.now()
try:
fetch_time = siemplify.fetch_timestamp(datetime_format=True, timezone=False)
print("+++++++++++++++++")
print(fetch_time)
if not fetch_time:
from_datetime = current_time
str_from_date = from_datetime.strftime("%Y-%m-%d %H-%M-%S")
str_from_date = datetime.strptime(str_from_date, "%Y-%m-%d %H-%M-%S")
from_time = str_from_date - timedelta(days=90)
to_time = current_time
str_to_date = to_time.strftime("%Y-%m-%d %H-%M-%S")
to_time = datetime.datetime.strptime(str_to_date, "%Y-%m-%d %H-%M-%S")
siemplify.save_timestamp(datetime_format=True, timezone=False, new_timestamp=unix_now())
else:
str_fetch_time = fetch_time.strftime("%Y-%m-%d %H-%M-%S")
str_fetch_time = datetime.strptime(str_fetch_time, "%Y-%m-%d %H-%M-%S")
from_time = str_fetch_time
to_time = current_time
str_to_date = to_time.strftime("%Y-%m-%d %H-%M-%S")
to_time = datetime.strptime(str_to_date, "%Y-%m-%d %H-%M-%S")
siemplify.save_timestamp(datetime_format=True, timezone=False, new_timestamp=unix_now())
except Exception as err:
siemplify.LOGGER.error(err)
siemplify.LOGGER.error(traceback.format_exc())
return from_time, to_time
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.