mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2025-12-06 01:02:46 +01:00
handle mine.p not being present. only check if mine_ip exists, dont compare to alived ip
This commit is contained in:
@@ -9,6 +9,10 @@ log = logging.getLogger(__name__)
|
||||
local = salt.client.LocalClient()
|
||||
|
||||
def start(interval=60):
|
||||
def mine_delete(minion, func):
|
||||
log.warning('checkmine engine: deleting mine function %s for %s' % (func, minion))
|
||||
local.cmd(minion, 'mine.delete', [func])
|
||||
|
||||
def mine_flush(minion):
|
||||
log.warning('checkmine engine: flushing mine cache for %s' % minion)
|
||||
local.cmd(minion, 'mine.flush')
|
||||
@@ -21,36 +25,35 @@ def start(interval=60):
|
||||
cachedir = __opts__['cachedir']
|
||||
while True:
|
||||
log.debug('checkmine engine: checking which minions are alive')
|
||||
manage_alived = __salt__['saltutil.runner']('manage.alived', show_ip=True)
|
||||
manage_alived = __salt__['saltutil.runner']('manage.alived', show_ip=False)
|
||||
log.debug('checkmine engine: alive minions: %s' % ' , '.join(manage_alived))
|
||||
|
||||
for minion in manage_alived:
|
||||
mine_path = os.path.join(cachedir, 'minions', minion, 'mine.p')
|
||||
# it is possible that a minion is alive, but there isn't a mine.p file
|
||||
# it is possible that a minion is alive, but hasn't created a mine file yet
|
||||
try:
|
||||
mine_size = os.path.getsize(mine_path)
|
||||
log.debug('checkmine engine: minion: %s mine_size: %i' % (minion, mine_size))
|
||||
# For some reason the mine file can be corrupt and only be 1 byte in size
|
||||
if mine_size == 1:
|
||||
log.error('checkmine engine: found %s to be 1 byte' % mine_path)
|
||||
mine_flush(minion)
|
||||
mine_update(minion)
|
||||
continue
|
||||
except FileNotFoundError:
|
||||
log.warning('checkmine engine: minion: %s %s does not exist' % (minion, mine_path))
|
||||
mine_flush(minion)
|
||||
mine_update(minion)
|
||||
continue
|
||||
|
||||
# For some reason the mine file can be corrupt and only be 1 byte in size
|
||||
if mine_size == 1:
|
||||
log.error('checkmine engine: found %s to be 1 byte' % mine_path)
|
||||
mine_flush(minion)
|
||||
mine_update(minion)
|
||||
# Update the mine if the ip in the mine doesn't match returned from manage.alived
|
||||
else:
|
||||
network_ip_addrs = __salt__['saltutil.runner']('mine.get', tgt=minion, fun='network.ip_addrs')
|
||||
network_ip_addrs = __salt__['saltutil.runner']('mine.get', tgt=minion, fun='network.ip_addrs')
|
||||
try:
|
||||
mine_ip = network_ip_addrs[minion][0]
|
||||
log.debug('checkmine engine: minion: %s mine_ip: %s' % (minion, mine_ip))
|
||||
manage_alived_ip = manage_alived[minion]
|
||||
log.debug('checkmine engine: minion: %s managed_alived_ip: %s' % (minion, manage_alived_ip))
|
||||
if mine_ip != manage_alived_ip:
|
||||
log.error('checkmine engine: found minion %s has manage_alived_ip %s but a mine_ip of %s' % (minion, manage_alived_ip, mine_ip))
|
||||
mine_flush(minion)
|
||||
mine_update(minion)
|
||||
log.debug('checkmine engine: found minion %s has mine_ip: %s' % (minion, mine_ip))
|
||||
except IndexError:
|
||||
log.error('checkmine engine: found minion %s does\'t have a mine_ip' % (minion))
|
||||
mine_delete(minion, 'network.ip_addrs')
|
||||
mine_update(minion)
|
||||
|
||||
sleep(interval)
|
||||
|
||||
Reference in New Issue
Block a user