#NEWLINE# def beacon( config ) : #NEWLINE# #INDENT# '\n    Watch for changes on network settings\n\n    By default, the beacon will emit when there is a value change on one of the\n    settings on watch. The config also support the onvalue parameter for each\n    setting, which instruct the beacon to only emit if the setting changed to the\n    value defined.\n\n    Example Config\n\n    .. code-block:: yaml\n\n        beacons:\n          eth0:\n            ipaddr:\n            promiscuity:\n              onvalue: 1\n          eth1:\n            linkmode:\n\n    The config above will check for value changes on eth0 ipaddr and eth1 linkmode. It will also\n    emit if the promiscuity value changes to 1.\n\n    Beacon items can use the * wildcard to make a definition apply to several interfaces. For\n    example an eth* would apply to all ethernet interfaces.\n\n    Setting the argument coalesce = True will combine all the beacon results on a single event.\n    The example below shows how to trigger coalesced results:\n\n    .. code-block:: yaml\n\n        beacons:\n          coalesce: True\n          eth0:\n            ipaddr:\n            promiscuity:\n\n    ' #NEWLINE# ret = [ ] #NEWLINE# interfaces = [ ] #NEWLINE# expanded_config = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# global LAST_STATS #NEWLINE# coalesce = False #NEWLINE# _stats = _copy_interfaces_info ( IP . by_name ) #NEWLINE# if ( not LAST_STATS ) : #NEWLINE# #INDENT# LAST_STATS = _stats #NEWLINE# #UNINDENT# if ( ( 'coalesce' in config ) and config [ 'coalesce' ] ) : #NEWLINE# #INDENT# coalesce = True #NEWLINE# changes = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# for item in config : #NEWLINE# #INDENT# if ( item == 'coalesce' ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( item in _stats ) : #NEWLINE# #INDENT# interfaces . append ( item ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# interface_regexp = item . replace ( '*' , '[0-9]+' ) #NEWLINE# for interface in _stats : #NEWLINE# #INDENT# match = re . search ( interface_regexp , interface ) #NEWLINE# if match : #NEWLINE# #INDENT# interfaces . append ( match . group ( ) ) #NEWLINE# expanded_config [ match . group ( ) ] = config [ item ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if expanded_config : #NEWLINE# #INDENT# config . update ( expanded_config ) #NEWLINE# #UNINDENT# for interface in interfaces : #NEWLINE# #INDENT# _send_event = False #NEWLINE# _diff_stats = ( _stats [ interface ] - LAST_STATS [ interface ] ) #NEWLINE# _ret_diff = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if _diff_stats : #NEWLINE# #INDENT# _diff_stats_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# LAST_STATS [ interface ] = _stats [ interface ] #NEWLINE# for item in _diff_stats : #NEWLINE# #INDENT# _diff_stats_dict . update ( item ) #NEWLINE# #UNINDENT# for attr in config [ interface ] : #NEWLINE# #INDENT# if ( attr in _diff_stats_dict ) : #NEWLINE# #INDENT# config_value = None #NEWLINE# if ( config [ interface ] [ attr ] and ( 'onvalue' in config [ interface ] [ attr ] ) ) : #NEWLINE# #INDENT# config_value = config [ interface ] [ attr ] [ 'onvalue' ] #NEWLINE# #UNINDENT# new_value = ast . literal_eval ( _diff_stats_dict [ attr ] ) #NEWLINE# if ( ( not config_value ) or ( config_value == match ) ) : #NEWLINE# #INDENT# _send_event = True #NEWLINE# _ret_diff [ attr ] = new_value #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if _send_event : #NEWLINE# #INDENT# if coalesce : #NEWLINE# #INDENT# changes [ interface ] = _ret_diff #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret . append ( { #NEWLINE# #INDENT# 'tag' : interface , #NEWLINE# 'interface' : interface , #NEWLINE# 'change' : _ret_diff , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( coalesce and changes ) : #NEWLINE# #INDENT# grains_info = salt . loader . grains ( __opts__ , True ) #NEWLINE# __grains__ . update ( grains_info ) #NEWLINE# ret . append ( { #NEWLINE# #INDENT# 'tag' : 'result' , #NEWLINE# 'changes' : changes , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# return ret