mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
commit
1e299ede4f
4 changed files with 31 additions and 23 deletions
|
@ -35,8 +35,22 @@ to a beacon.
|
|||
.. code-block:: yaml
|
||||
|
||||
beacons:
|
||||
inotify:
|
||||
/etc/httpd/conf.d: {}
|
||||
/opt: {}
|
||||
interval: 5
|
||||
load:
|
||||
- interval: 5
|
||||
- 1m:
|
||||
- 0.0
|
||||
- 2.0
|
||||
- 5m:
|
||||
- 0.0
|
||||
- 1.5
|
||||
- 15m:
|
||||
- 0.1
|
||||
- 1.0
|
||||
- interval: 10
|
||||
|
||||
|
||||
Writing Beacon Plugins
|
||||
======================
|
||||
|
|
|
@ -29,8 +29,8 @@ class Beacon(object):
|
|||
code_block:: yaml
|
||||
beacons:
|
||||
inotify:
|
||||
- /etc/fstab
|
||||
- /var/cache/foo/*
|
||||
/etc/fstab: {}
|
||||
/var/cache/foo: {}
|
||||
'''
|
||||
ret = []
|
||||
b_config = copy.deepcopy(config)
|
||||
|
@ -38,9 +38,18 @@ class Beacon(object):
|
|||
log.trace('Beacon processing: {0}'.format(mod))
|
||||
fun_str = '{0}.beacon'.format(mod)
|
||||
if fun_str in self.beacons:
|
||||
interval = [arg for arg in config[mod] if 'interval' in arg]
|
||||
if isinstance(config[mod], list):
|
||||
interval = None
|
||||
interval_config = [arg for arg in config[mod] if 'interval' in arg]
|
||||
if interval_config:
|
||||
interval = interval_config[0]['interval']
|
||||
elif isinstance(config[mod], dict):
|
||||
interval = config[mod].get('interval', False)
|
||||
if interval:
|
||||
b_config[mod].remove(interval[0])
|
||||
if isinstance(b_config[mod], list):
|
||||
b_config[mod].remove(interval_config[0])
|
||||
elif isinstance(b_config[mod], dict):
|
||||
b_config[mod].pop('interval')
|
||||
if not self._process_interval(mod, interval):
|
||||
log.trace('Skipping beacon {0}. Interval not reached.'.format(mod))
|
||||
continue
|
||||
|
@ -65,7 +74,7 @@ class Beacon(object):
|
|||
log.trace('Processing interval in map')
|
||||
counter = self.interval_map[mod]
|
||||
log.trace('Interval counter: {0}'.format(counter))
|
||||
if counter * loop_interval >= interval[0]['interval']:
|
||||
if counter * loop_interval >= interval:
|
||||
self.interval_map[mod] = 1
|
||||
return True
|
||||
else:
|
||||
|
|
|
@ -132,7 +132,7 @@ def beacon(config):
|
|||
if isinstance(mask, list):
|
||||
r_mask = 0
|
||||
for sub in mask:
|
||||
r_mask |= _get_mask(mask)
|
||||
r_mask |= _get_mask(sub)
|
||||
elif isinstance(mask, salt.ext.six.binary_type):
|
||||
r_mask = _get_mask(mask)
|
||||
else:
|
||||
|
|
|
@ -39,34 +39,20 @@ def beacon(config):
|
|||
account_sid: "<account sid>"
|
||||
auth_token: "<auth token>"
|
||||
twilio_number: "+15555555555"
|
||||
poll_interval: 10
|
||||
interval: 10
|
||||
|
||||
poll_interval defaults to 10 seconds
|
||||
'''
|
||||
log.trace('twilio_txt_msg beacon starting')
|
||||
ret = []
|
||||
if not all([config['account_sid'], config['auth_token'], config['twilio_number']]):
|
||||
return ret
|
||||
output = {}
|
||||
poll_interval = config.get('poll_interval')
|
||||
if not poll_interval:
|
||||
# Let's default to polling every 10 secons
|
||||
poll_interval = 10
|
||||
now = datetime.now()
|
||||
if 'twilio_txt_msg' in __context__:
|
||||
timedelta = now - __context__['twilio_txt_msg']
|
||||
if timedelta.seconds < poll_interval:
|
||||
log.trace('Twilio beacon poll interval not met.')
|
||||
log.trace('Twilio polling in {0}'.format(poll_interval - timedelta.seconds))
|
||||
return ret
|
||||
|
||||
output['texts'] = []
|
||||
client = TwilioRestClient(config['account_sid'], config['auth_token'])
|
||||
messages = client.messages.list(to=config['twilio_number'])
|
||||
log.trace('Num messages: {0}'.format(len(messages)))
|
||||
if len(messages) < 1:
|
||||
log.trace('Twilio beacon has no texts')
|
||||
__context__['twilio_txt_msg'] = now
|
||||
return ret
|
||||
|
||||
for message in messages:
|
||||
|
@ -84,6 +70,5 @@ def beacon(config):
|
|||
item['images'].append(str(pic.uri))
|
||||
output['texts'].append(item)
|
||||
message.delete()
|
||||
__context__['twilio_txt_msg'] = now
|
||||
ret.append(output)
|
||||
return ret
|
||||
|
|
Loading…
Add table
Reference in a new issue