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 da39965
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 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
2 changes: 1 addition & 1 deletion tests/test_snmp/test_airos.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def test_local_time(self):
def test_load(self):
load = self.device.load
self.assertIsInstance(load, list)
self.assertEquals(len(load), 3)
self.assertEqual(len(load), 3)
self.assertIsInstance(load[0], int)
self.assertIsInstance(load[1], int)
self.assertIsInstance(load[2], int)
Expand Down
1 change: 1 addition & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def _get_nextcmd_list(return_value):
'1.3.6.1.2.1.4.20.1.2': [[[0, 1]]],
'1.3.6.1.2.1.25.3.3.1.2': [0, 2],
'1.3.6.1.2.1.4.20.1.3': [[[0, OctetString('192.168.0.1')]]],
'1.3.6.1.4.1.10002.1.1.1.4.2.1.3': [[[0, 51]], [[0, 18]], [[0, 24]]],
}
oid = args[2]
return _get_nextcmd_list(res[oid])

0 comments on commit da39965

Please sign in to comment.