forked from Yelp/elastalert
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Logitech/feat-tz-enhancement
TimeZone Enhancement Module
- Loading branch information
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from datetime import datetime | ||
from pytz import timezone | ||
|
||
from elastalert.enhancements import BaseEnhancement | ||
from elastalert.util import ts_to_dt, pretty_ts, elastalert_logger | ||
|
||
""" | ||
This Class will convert the incoming Timezone object of UTC offset to Taiwan/India Standard Timezone | ||
""" | ||
class ConvertTzInfo(BaseEnhancement): | ||
# The enhancement is run against every match | ||
# The match is passed to the process function where it can be modified in any way | ||
# ElastAlert will do this for each enhancement linked to a rule | ||
def process(self, match): | ||
|
||
elastalert_logger.info("Received UTC Time %s" % (match['@timestamp'])) | ||
utc_ts = match['@timestamp'] | ||
if not isinstance(utc_ts, datetime): | ||
utc_ts = ts_to_dt(utc_ts) | ||
|
||
taipei_tz = timezone('Asia/Taipei') | ||
india_tz = timezone('Asia/Kolkata') | ||
|
||
ist_tz = utc_ts.astimezone(india_tz) | ||
tst_tz = utc_ts.astimezone(taipei_tz) | ||
|
||
ist_tz_str = pretty_ts(ist_tz, False) | ||
tst_tz_str = pretty_ts(tst_tz, False) | ||
|
||
tz_str = ist_tz_str + " Or " + tst_tz_str | ||
|
||
match['@timestamp'] = tz_str |