Skip to content

Commit

Permalink
[chores] Some requested changes
Browse files Browse the repository at this point in the history
- Swap time with datetime in local_time
- Remove unused warning
- Use a single call for collecting load information
  • Loading branch information
purhan committed Jun 18, 2021
1 parent 8cd7089 commit 0b12396
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
12 changes: 5 additions & 7 deletions netengine/backends/snmp/airos.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import binascii
import logging
import time
from datetime import datetime

from .base import SNMP
Expand Down Expand Up @@ -379,9 +378,7 @@ def local_time(self):
returns the local time of the host device as a timestamp
"""
epoch = str(self.get('1.3.6.1.4.1.41112.1.4.8.1.0')[3][0][1])
timestamp = int(
time.mktime(datetime.strptime(epoch, '%Y-%m-%d %H:%M:%S').timetuple())
)
timestamp = int(datetime.strptime(epoch, '%Y-%m-%d %H:%M:%S').timestamp())
return timestamp

@property
Expand Down Expand Up @@ -422,9 +419,10 @@ def load(self):
Returns an array with load average values respectively in the last
minute, in the last 5 minutes and in the last 15 minutes
"""
one = int(self.get_value('1.3.6.1.4.1.10002.1.1.1.4.2.1.3.1'))
five = int(self.get_value('1.3.6.1.4.1.10002.1.1.1.4.2.1.3.2'))
fifteen = int(self.get_value('1.3.6.1.4.1.10002.1.1.1.4.2.1.3.3'))
array = (self.next('1.3.6.1.4.1.10002.1.1.1.4.2.1.3.'))[3]
one = int(array[0][0][1])
five = int(array[1][0][1])
fifteen = int(array[2][0][1])
return [one, five, fifteen]

@property
Expand Down
1 change: 0 additions & 1 deletion netengine/backends/snmp/openwrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ def local_time(self):
tzinfo=pytz.utc,
).timestamp()
)
logger.warning('Invalid timestring was supplied')

@property
def RAM_total(self):
Expand Down

0 comments on commit 0b12396

Please sign in to comment.