Merge "Subtracted utc offset from update_timestamp"
This commit is contained in:
commit
ab4080e34c
@ -38,13 +38,11 @@ class NagiosTransformer(AlarmTransformerBase):
|
|||||||
|
|
||||||
def _create_vertex(self, entity_event):
|
def _create_vertex(self, entity_event):
|
||||||
|
|
||||||
update_timestamp = datetime_utils.change_time_str_format(
|
update_timestamp = datetime_utils.change_to_utc_time_and_format(
|
||||||
entity_event[NagiosProperties.LAST_CHECK],
|
entity_event[NagiosProperties.LAST_CHECK],
|
||||||
'%Y-%m-%d %H:%M:%S',
|
'%Y-%m-%d %H:%M:%S',
|
||||||
tbase.TIMESTAMP_FORMAT)
|
tbase.TIMESTAMP_FORMAT)
|
||||||
|
|
||||||
sample_timestamp = entity_event[DSProps.SAMPLE_DATE]
|
sample_timestamp = entity_event[DSProps.SAMPLE_DATE]
|
||||||
|
|
||||||
update_timestamp = self._format_update_timestamp(update_timestamp,
|
update_timestamp = self._format_update_timestamp(update_timestamp,
|
||||||
sample_timestamp)
|
sample_timestamp)
|
||||||
|
|
||||||
|
@ -30,10 +30,11 @@ from vitrage.datasources.nagios.properties import NagiosTestStatus
|
|||||||
from vitrage.datasources.nagios.transformer import NagiosTransformer
|
from vitrage.datasources.nagios.transformer import NagiosTransformer
|
||||||
from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE
|
from vitrage.datasources.nova.host import NOVA_HOST_DATASOURCE
|
||||||
from vitrage.datasources.nova.host.transformer import HostTransformer
|
from vitrage.datasources.nova.host.transformer import HostTransformer
|
||||||
|
from vitrage.datasources import transformer_base as tbase
|
||||||
from vitrage.datasources.transformer_base import TransformerBase
|
from vitrage.datasources.transformer_base import TransformerBase
|
||||||
from vitrage.tests import base
|
from vitrage.tests import base
|
||||||
from vitrage.tests.mocks import mock_driver as mock_sync
|
from vitrage.tests.mocks import mock_driver as mock_sync
|
||||||
|
from vitrage.utils import datetime as datetime_utils
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -119,7 +120,11 @@ class NagiosTransformerTest(base.BaseTest):
|
|||||||
self.assertEqual(EntityCategory.ALARM, vertex[VProps.CATEGORY])
|
self.assertEqual(EntityCategory.ALARM, vertex[VProps.CATEGORY])
|
||||||
self.assertEqual(event[DSProps.ENTITY_TYPE], vertex[VProps.TYPE])
|
self.assertEqual(event[DSProps.ENTITY_TYPE], vertex[VProps.TYPE])
|
||||||
self.assertEqual(event[NagiosProperties.SERVICE], vertex[VProps.NAME])
|
self.assertEqual(event[NagiosProperties.SERVICE], vertex[VProps.NAME])
|
||||||
|
self.assertEqual(datetime_utils.change_to_utc_time_and_format(
|
||||||
|
event[NagiosProperties.LAST_CHECK],
|
||||||
|
'%Y-%m-%d %H:%M:%S',
|
||||||
|
tbase.TIMESTAMP_FORMAT),
|
||||||
|
vertex[VProps.UPDATE_TIMESTAMP])
|
||||||
event_type = event.get(DSProps.EVENT_TYPE, None)
|
event_type = event.get(DSProps.EVENT_TYPE, None)
|
||||||
if event_type is not None:
|
if event_type is not None:
|
||||||
self.assertEqual(vertex[VProps.STATE],
|
self.assertEqual(vertex[VProps.STATE],
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from datetime import timedelta
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
|
|
||||||
|
|
||||||
@ -31,6 +32,13 @@ def change_time_str_format(timestamp_str, old_format, new_format):
|
|||||||
return utc.strftime(new_format)
|
return utc.strftime(new_format)
|
||||||
|
|
||||||
|
|
||||||
|
def change_to_utc_time_and_format(timestamp_str, old_format, new_format):
|
||||||
|
timestamp = datetime.strptime(timestamp_str, old_format)
|
||||||
|
timestamp = timestamp - timedelta(seconds=(
|
||||||
|
datetime.now() - datetime.utcnow()).total_seconds())
|
||||||
|
return timestamp.strftime(new_format)
|
||||||
|
|
||||||
|
|
||||||
def format_unix_timestamp(timestamp, date_format=TIMESTAMP_FORMAT):
|
def format_unix_timestamp(timestamp, date_format=TIMESTAMP_FORMAT):
|
||||||
return datetime.fromtimestamp(float(timestamp)) \
|
return datetime.fromtimestamp(float(timestamp)) \
|
||||||
.strftime(date_format)
|
.strftime(date_format)
|
||||||
|
Loading…
Reference in New Issue
Block a user