|
2 | 2 | from datetime import datetime |
3 | 3 | from collections import defaultdict |
4 | 4 | from json import loads |
5 | | -from dateparser import parse |
6 | 5 | import numpy as np |
7 | 6 |
|
8 | 7 | from suzieq.poller.worker.services.service import Service |
9 | 8 | from suzieq.shared.utils import (get_timestamp_from_junos_time, |
10 | | - expand_ios_ifname, expand_nxos_ifname) |
11 | | -from suzieq.shared.utils import convert_macaddr_format_to_colon |
| 9 | + expand_ios_ifname, expand_nxos_ifname, |
| 10 | + convert_macaddr_format_to_colon, |
| 11 | + parse_relative_timestamp) |
12 | 12 | from suzieq.shared.utils import MISSING_SPEED, NO_SPEED, MISSING_SPEED_IF_TYPES |
13 | 13 |
|
14 | 14 |
|
@@ -151,11 +151,9 @@ def _clean_eos_data(self, processed_data, _): |
151 | 151 | adm_state = entry.get('adminState', 'down') |
152 | 152 | if adm_state == 'notconnect': |
153 | 153 | entry['reason'] = 'notconnect' |
154 | | - entry['adminState'] = 'down' |
155 | 154 | entry['state'] = 'notConnected' |
156 | 155 | elif adm_state == 'errdisabled': |
157 | 156 | entry['reason'] = 'errdisabled' |
158 | | - entry['adminState'] = 'down' |
159 | 157 | entry['state'] = 'errDisabled' |
160 | 158 | elif adm_state == 'connected': |
161 | 159 | entry['adminState'] = 'up' |
@@ -590,14 +588,10 @@ def fix_nxos_speed(entry): |
590 | 588 | if any(x in lastChange for x in 'dwmy'): |
591 | 589 | lastChange = f'{lastChange} hours ago' |
592 | 590 |
|
593 | | - lastChange = parse( |
594 | | - lastChange, |
595 | | - settings={'RELATIVE_BASE': datetime.fromtimestamp( |
596 | | - (raw_data[0]['timestamp'])/1000), |
597 | | - 'TIMEZONE': 'UTC'}) |
| 591 | + lastChange = parse_relative_timestamp( |
| 592 | + lastChange, raw_data[0]['timestamp'], ms=True) |
598 | 593 | if lastChange: |
599 | | - old_entry['statusChangeTimestamp'] = int( |
600 | | - lastChange.timestamp() * 1000) |
| 594 | + old_entry['statusChangeTimestamp'] = lastChange |
601 | 595 | else: |
602 | 596 | old_entry['statusChangeTimestamp'] = 0 |
603 | 597 | old_entry['description'] = entry.get('description', '') |
@@ -895,14 +889,12 @@ def _clean_iosxr_data(self, processed_data, raw_data): |
895 | 889 | entry['interfaceMac'] = convert_macaddr_format_to_colon( |
896 | 890 | entry.get('interfaceMac', '0000.0000.0000')) |
897 | 891 |
|
898 | | - lastChange = parse( |
| 892 | + lastChange = parse_relative_timestamp( |
899 | 893 | entry.get('statusChangeTimestamp', ''), |
900 | | - settings={'RELATIVE_BASE': |
901 | | - datetime.fromtimestamp( |
902 | | - (raw_data[0]['timestamp'])/1000), }) |
| 894 | + raw_data[0]['timestamp'], ms=True) |
| 895 | + |
903 | 896 | if lastChange: |
904 | | - entry['statusChangeTimestamp'] = int(lastChange.timestamp() |
905 | | - * 1000) |
| 897 | + entry['statusChangeTimestamp'] = lastChange |
906 | 898 | if 'ipAddressList' not in entry: |
907 | 899 | entry['ipAddressList'] = [] |
908 | 900 | entry['ip6AddressList'] = [] |
|
0 commit comments