77
88import binascii
99import logging
10- from datetime import timedelta
10+ import time
11+ from datetime import datetime , timedelta
1112
1213from .base import SNMP
1314
@@ -98,15 +99,6 @@ def uptime(self):
9899 """
99100 return int (self .get_value ('1.3.6.1.2.1.1.3.0' )) // 100
100101
101- @property
102- def uptime_tuple (self ):
103- """
104- returns (days, hours, minutes)
105- """
106- td = timedelta (seconds = self .uptime )
107-
108- return td .days , td .seconds // 3600 , (td .seconds // 60 ) % 60
109-
110102 @property
111103 def interfaces_number (self ):
112104 """
@@ -381,6 +373,17 @@ def wireless_links(self):
381373 final .append (result )
382374 return final
383375
376+ @property
377+ def local_time (self ):
378+ """
379+ returns the local time of the host device as a timestamp
380+ """
381+ epoch = str (self .get ('1.3.6.1.4.1.41112.1.4.8.1.0' )[3 ][0 ][1 ])
382+ timestamp = int (
383+ time .mktime (datetime .strptime (epoch , '%Y-%m-%d %H:%M:%S' ).timetuple ())
384+ )
385+ return timestamp
386+
384387 @property
385388 def RAM_total (self ):
386389 """
@@ -397,14 +400,74 @@ def RAM_free(self):
397400 free = self .get_value ('1.3.6.1.4.1.10002.1.1.1.1.2.0' )
398401 return int (free )
399402
403+ @property
404+ def RAM_buffered (self ):
405+ """
406+ Returns the buffered RAM of the device
407+ """
408+ buffered = self .get_value ('1.3.6.1.4.1.10002.1.1.1.1.3.0' )
409+ return int (buffered )
410+
411+ @property
412+ def RAM_cached (self ):
413+ """
414+ Returns the cached RAM of the device
415+ """
416+ cached = self .get_value ('1.3.6.1.4.1.10002.1.1.1.1.4.0' )
417+ return int (cached )
418+
419+ @property
420+ def load (self ):
421+ """
422+ Returns an array with load average values respectively in the last
423+ minute, in the last 5 minutes and in the last 15 minutes
424+ """
425+ one = int (self .get_value ('1.3.6.1.4.1.10002.1.1.1.4.2.1.3.1' ))
426+ five = int (self .get_value ('1.3.6.1.4.1.10002.1.1.1.4.2.1.3.2' ))
427+ fifteen = int (self .get_value ('1.3.6.1.4.1.10002.1.1.1.4.2.1.3.3' ))
428+ return [one , five , fifteen ]
429+
430+ @property
431+ def SWAP_total (self ):
432+ """
433+ Returns the total SWAP of the device
434+ """
435+ total = self .get_value ('1.3.6.1.4.1.10002.1.1.1.2.1.0' )
436+ return int (total )
437+
438+ @property
439+ def SWAP_free (self ):
440+ """
441+ Returns the free SWAP of the device
442+ """
443+ free = self .get_value ('1.3.6.1.4.1.10002.1.1.1.2.2.0' )
444+ return int (free )
445+
446+ @property
447+ def resources_to_dict (self ):
448+ """
449+ returns an ordered dict with hardware resources information
450+ """
451+ result = self ._dict (
452+ {
453+ 'load' : self .load ,
454+ 'memory' : {
455+ 'total' : self .RAM_total ,
456+ 'buffered' : self .RAM_buffered ,
457+ 'free' : self .RAM_free ,
458+ 'cached' : self .RAM_cached ,
459+ },
460+ 'swap' : {'total' : self .SWAP_total , 'free' : self .SWAP_free },
461+ }
462+ )
463+ return result
464+
400465 def to_dict (self ):
401466 return self ._dict (
402467 {
403468 'type' : 'DeviceMonitoring' ,
404- 'general' : {'uptime' : self .uptime },
405- 'resources' : {
406- 'memory' : {'total' : self .RAM_total , 'free' : self .RAM_free },
407- },
469+ 'general' : {'uptime' : self .uptime , 'local_time' : self .local_time },
470+ 'resources' : self .resources_to_dict ,
408471 'interfaces' : self .interfaces_to_dict ,
409472 }
410473 )
0 commit comments