mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Adding a validate function to each beacon that will be used by the beacons.add function to ensure configuration is correct.
This commit is contained in:
parent
d2eac55240
commit
7ea207db42
@ -49,6 +49,16 @@ def _get_loc():
|
||||
return __context__[LOC_KEY]
|
||||
|
||||
|
||||
def validate(config):
|
||||
'''
|
||||
Validate the beacon configuration
|
||||
'''
|
||||
# Configuration for load beacon should be a list of dicts
|
||||
if not isinstance(config, dict):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
# TODO: add support for only firing events for specific users and login times
|
||||
def beacon(config):
|
||||
'''
|
||||
|
@ -26,6 +26,17 @@ def __virtual__():
|
||||
return __virtualname__
|
||||
|
||||
|
||||
def validate(config):
|
||||
'''
|
||||
Validate the beacon configuration
|
||||
'''
|
||||
# Configuration for diskusage beacon should be a list of dicts
|
||||
if not isinstance(config, dict):
|
||||
log.info('Configuration for diskusage beacon must be a dictionary.')
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def beacon(config):
|
||||
'''
|
||||
Monitor the disk usage of the minion
|
||||
@ -37,7 +48,7 @@ def beacon(config):
|
||||
code_block:: yaml
|
||||
|
||||
beacons:
|
||||
- diskusage:
|
||||
diskusage:
|
||||
- /: 63%
|
||||
- /mnt/nfs: 50%
|
||||
|
||||
|
@ -25,6 +25,9 @@ except ImportError:
|
||||
|
||||
__virtualname__ = 'inotify'
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def __virtual__():
|
||||
if HAS_PYINOTIFY:
|
||||
@ -58,6 +61,72 @@ def _get_notifier():
|
||||
return __context__['inotify.notifier']
|
||||
|
||||
|
||||
def validate(config):
|
||||
'''
|
||||
Validate the beacon configuration
|
||||
'''
|
||||
|
||||
VALID_MASK = [
|
||||
'access',
|
||||
'attrib',
|
||||
'close_nowrite',
|
||||
'close_write',
|
||||
'create',
|
||||
'delete',
|
||||
'delete_self',
|
||||
'excl_unlink',
|
||||
'ignored',
|
||||
'modify',
|
||||
'moved_from',
|
||||
'moved_to',
|
||||
'move_self',
|
||||
'oneshot',
|
||||
'onlydir',
|
||||
'open',
|
||||
'unmount'
|
||||
]
|
||||
|
||||
# Configuration for diskusage beacon should be a list of dicts
|
||||
if not isinstance(config, dict):
|
||||
log.info('Configuration for inotify beacon must be a dictionary.')
|
||||
return False
|
||||
else:
|
||||
for config_item in config:
|
||||
if not isinstance(config[config_item], dict):
|
||||
log.info('Configuration for inotify beacon must '
|
||||
'be a dictionary of dictionaries.')
|
||||
return False
|
||||
else:
|
||||
if not any(j in ['mask', 'recurse', 'auto_add'] for j in config[config_item]):
|
||||
log.info('Configuration for inotify beacon must '
|
||||
'contain mask, recurse or auto_add items.')
|
||||
return False
|
||||
|
||||
if 'auto_add' in config[config_item]:
|
||||
if not isinstance(config[config_item]['auto_add'], bool):
|
||||
log.info('Configuration for inotify beacon '
|
||||
'auto_add must be boolean.')
|
||||
return False
|
||||
|
||||
if 'recurse' in config[config_item]:
|
||||
if not isinstance(config[config_item]['recurse'], bool):
|
||||
log.info('Configuration for inotify beacon '
|
||||
'recurse must be boolean.')
|
||||
return False
|
||||
|
||||
if 'mask' in config[config_item]:
|
||||
if not isinstance(config[config_item]['mask'], list):
|
||||
log.info('Configuration for inotify beacon '
|
||||
'mask must be list.')
|
||||
return False
|
||||
for mask in config[config_item]['mask']:
|
||||
if mask not in VALID_MASK:
|
||||
log.info('Configuration for inotify beacon '
|
||||
'invalid mask option.'.format(mask))
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def beacon(config):
|
||||
'''
|
||||
Watch the configured files
|
||||
|
@ -18,6 +18,9 @@ try:
|
||||
except ImportError:
|
||||
HAS_SYSTEMD = False
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
__virtualname__ = 'journald'
|
||||
|
||||
|
||||
@ -40,6 +43,22 @@ def _get_journal():
|
||||
return __context__['systemd.journald']
|
||||
|
||||
|
||||
def validate(config):
|
||||
'''
|
||||
Validate the beacon configuration
|
||||
'''
|
||||
# Configuration for journald beacon should be a list of dicts
|
||||
if not isinstance(config, dict):
|
||||
return False
|
||||
else:
|
||||
for item in config:
|
||||
if not isinstance(config[item], dict):
|
||||
log.info('Configuration for journald beacon must '
|
||||
'be a dictionary of dictionaries.')
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def beacon(config):
|
||||
'''
|
||||
The journald beacon allows for the systemd jornal to be parsed and linked
|
||||
|
@ -36,25 +36,25 @@ def validate(config):
|
||||
log.info('Configuration for load beacon must be a list.')
|
||||
return False
|
||||
else:
|
||||
for l in config:
|
||||
if not isinstance(l, dict):
|
||||
for config_item in config:
|
||||
if not isinstance(config_item, dict):
|
||||
log.info('Configuration for load beacon must '
|
||||
'be a list of dictionarys.')
|
||||
'be a list of dictionaries.')
|
||||
return False
|
||||
else:
|
||||
if not any(j in ['1m', '5m', '15m'] for j in l.keys()):
|
||||
if not any(j in ['1m', '5m', '15m'] for j in config_item.keys()):
|
||||
log.info('Configuration for load beacon must '
|
||||
'contain 1m, 5m and 15m items.')
|
||||
return False
|
||||
|
||||
for item in l:
|
||||
if not isinstance(l[item], list):
|
||||
for item in config_item:
|
||||
if not isinstance(config_item[item], list):
|
||||
log.info('Configuration for load beacon: '
|
||||
'1m, 5m and 15m items must be '
|
||||
'a list of two items.')
|
||||
return False
|
||||
else:
|
||||
if len(l[item]) != 2:
|
||||
if len(config_item[item]) != 2:
|
||||
log.info('Configuration for load beacon: '
|
||||
'1m, 5m and 15m items must be '
|
||||
'a list of two items.')
|
||||
|
@ -35,6 +35,35 @@ def __virtual__():
|
||||
return __virtualname__
|
||||
|
||||
|
||||
def validate(config):
|
||||
'''
|
||||
Validate the beacon configuration
|
||||
'''
|
||||
|
||||
VALID_ITEMS = [
|
||||
'type', 'bytes_sent', 'bytes_recv', 'packets_sent',
|
||||
'packets_recv', 'errin', 'errout', 'dropin',
|
||||
'dropout'
|
||||
]
|
||||
|
||||
# Configuration for load beacon should be a list of dicts
|
||||
if not isinstance(config, dict):
|
||||
log.info('Configuration for load beacon must be a dictionary.')
|
||||
return False
|
||||
else:
|
||||
for item in config:
|
||||
if not isinstance(config[item], dict):
|
||||
log.info('Configuration for load beacon must '
|
||||
'be a dictionary of dictionaries.')
|
||||
return False
|
||||
else:
|
||||
if not any(j in VALID_ITEMS for j in config[item]):
|
||||
log.info('Invalid configuration item in '
|
||||
'Beacon configuration.')
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def beacon(config):
|
||||
'''
|
||||
Emit the network statistics of this host.
|
||||
|
@ -12,6 +12,17 @@ import psutil
|
||||
log = logging.getLogger(__name__) # pylint: disable=invalid-name
|
||||
|
||||
|
||||
def validate(config):
|
||||
'''
|
||||
Validate the beacon configuration
|
||||
'''
|
||||
# Configuration for ps beacon should be a list of dicts
|
||||
if not isinstance(config, dict):
|
||||
log.info('Configuration for ps beacon must be a dictionary.')
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def beacon(config):
|
||||
'''
|
||||
Scan for processes and fire events
|
||||
|
@ -11,6 +11,17 @@ import logging
|
||||
log = logging.getLogger(__name__) # pylint: disable=invalid-name
|
||||
|
||||
|
||||
def validate(config):
|
||||
'''
|
||||
Validate the beacon configuration
|
||||
'''
|
||||
# Configuration for service beacon should be a list of dicts
|
||||
if not isinstance(config, dict):
|
||||
log.info('Configuration for service beacon must be a dictionary.')
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def beacon(config):
|
||||
'''
|
||||
Scan for the configured services and fire events
|
||||
|
@ -14,6 +14,9 @@ from salt.ext.six.moves import range # pylint: disable=import-error,redefined-b
|
||||
|
||||
__virtualname__ = 'sh'
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
@ -38,6 +41,17 @@ def _get_shells():
|
||||
return __context__['sh.shells']
|
||||
|
||||
|
||||
def validate(config):
|
||||
'''
|
||||
Validate the beacon configuration
|
||||
'''
|
||||
# Configuration for sh beacon should be a list of dicts
|
||||
if not isinstance(config, dict):
|
||||
log.info('Configuration for sh beacon must be a dictionary.')
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def beacon(config):
|
||||
'''
|
||||
Scan the shell execve routines. This beacon will convert all login shells
|
||||
|
@ -27,6 +27,17 @@ def __virtual__():
|
||||
return False
|
||||
|
||||
|
||||
def validate(config):
|
||||
'''
|
||||
Validate the beacon configuration
|
||||
'''
|
||||
# Configuration for twilio_txt_msg beacon should be a list of dicts
|
||||
if not isinstance(config, dict):
|
||||
log.info('Configuration for twilio_txt_msg beacon must be a dictionary.')
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def beacon(config):
|
||||
'''
|
||||
Emit a dict name "texts" whose value is a list
|
||||
|
@ -30,10 +30,13 @@ FIELDS = [
|
||||
'session',
|
||||
'time',
|
||||
'addr'
|
||||
]
|
||||
]
|
||||
SIZE = struct.calcsize(FMT)
|
||||
LOC_KEY = 'wtmp.loc'
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def __virtual__():
|
||||
if os.path.isfile(WTMP):
|
||||
@ -49,6 +52,17 @@ def _get_loc():
|
||||
return __context__[LOC_KEY]
|
||||
|
||||
|
||||
def validate(config):
|
||||
'''
|
||||
Validate the beacon configuration
|
||||
'''
|
||||
# Configuration for wtmp beacon should be a list of dicts
|
||||
if not isinstance(config, dict):
|
||||
log.info('Configuration for wtmp beacon must be a dictionary.')
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
# TODO: add support for only firing events for specific users and login times
|
||||
def beacon(config):
|
||||
'''
|
||||
|
Loading…
Reference in New Issue
Block a user