<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import logging <EOL> import psutil <EOL> log = logging . getLogger ( __name__ ) <EOL> __virtualname__ = '<STR_LIT>' <EOL> __attrs = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> def _to_list ( obj ) : <EOL> '''<STR_LIT>''' <EOL> ret = { } <EOL> for attr in __attrs : <EOL> ret [ attr ] = obj . __dict__ [ attr ] <EOL> return ret <EOL> def __virtual__ ( ) : <EOL> return __virtualname__ <EOL> def validate ( config ) : <EOL> '''<STR_LIT>''' <EOL> VALID_ITEMS = [ <EOL> '<STR_LIT:type>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> if not isinstance ( config , dict ) : <EOL> return False , ( '<STR_LIT>' ) <EOL> else : <EOL> for item in config : <EOL> if not isinstance ( config [ item ] , dict ) : <EOL> return False , ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> else : <EOL> if not any ( j in VALID_ITEMS for j in config [ item ] ) : <EOL> return False , ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return True , '<STR_LIT>' <EOL> def beacon ( config ) : <EOL> '''<STR_LIT>''' <EOL> ret = [ ] <EOL> _stats = psutil . net_io_counters ( pernic = True ) <EOL> for interface in config : <EOL> if interface in _stats : <EOL> _if_stats = _stats [ interface ] <EOL> _diff = False <EOL> for attr in __attrs : <EOL> if attr in config [ interface ] : <EOL> if '<STR_LIT:type>' in config [ interface ] and config [ interface ] [ '<STR_LIT:type>' ] == '<STR_LIT>' : <EOL> if _if_stats . __dict__ [ attr ] == int ( config [ interface ] [ attr ] ) : <EOL> _diff = True <EOL> elif '<STR_LIT:type>' in config [ interface ] and config [ interface ] [ '<STR_LIT:type>' ] == '<STR_LIT>' : <EOL> if _if_stats . __dict__ [ attr ] > int ( config [ interface ] [ attr ] ) : <EOL> _diff = True <EOL> else : <EOL> if _if_stats . __dict__ [ attr ] == int ( config [ interface ] [ attr ] ) : <EOL> _diff = True <EOL> if _diff : <EOL> ret . append ( { '<STR_LIT>' : interface , <EOL> '<STR_LIT>' : _to_list ( _if_stats ) } ) <EOL> return ret </s>
