Hi @Jay_Clifford ,
I tried following the article you sent but that did not help.
This is what my starlark script looks like:
load("time.star", "time")
load("logging.star", "log")
def apply(metric):
for k, v in metric.fields.items():
# log.debug("This is k: {}".format(k))
if k == "last-established":
epochDate = metric.fields["last-established"]
newDate = time.parse_time(str(epochDate), format="2006-01-02T15:04:05.999999999", location="UTC")
metric.fields["test-data"] = newDate
return [metric]
I get the following error message:
2021-10-22T15:39:42Z E! [processors.starlark] Error in parse_time: parsing time "1632299576746236416" as "2006-01-02T15:04:05.999999999": cannot parse "299576746236416" as "-"
2021-10-22T15:39:42Z E! [processors.starlark] Error in plugin: parsing time "1632299576746236416" as "2006-01-02T15:04:05.999999999": cannot parse "299576746236416" as "-"
So after tinkering with Starlark and my data set for a few hours, I was able to figure out how to convert epoch time to regular time. Here is my working solution:
[[processors.starlark]]
namepass = ["bgp"]
source = '''
load("time.star", "time")
load("logging.star", "log")
def apply(metric):
for k, v in metric.fields.items():
# log.debug("This is k: {}".format(k))
if k == "neighbors/neighbor/state/last_established":
new_date = time.from_timestamp(int(v / 1e9))
metric.fields.pop(k)
metric.fields["last-established"] = str(new_date)
# log.debug("This is last-established: {}".format(metric.fields.get("last-established")))
return [metric]
'''