mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2025-12-06 17:22:49 +01:00
update all nodes motd with nodes that need restarted from patch updates - https://github.com/Security-Onion-Solutions/securityonion-saltstack/issues/112
This commit is contained in:
25
salt/_modules/needs_restarting.py
Normal file
25
salt/_modules/needs_restarting.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
from os import path
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
def check():
|
||||||
|
|
||||||
|
os = __grains__['os']
|
||||||
|
cmd = 'needs-restarting -r > /dev/null 2>&1'
|
||||||
|
|
||||||
|
if os == 'Ubuntu':
|
||||||
|
if path.exists('/var/run/reboot-required'):
|
||||||
|
retval = 'True'
|
||||||
|
else:
|
||||||
|
retval = 'False'
|
||||||
|
|
||||||
|
elif os == 'CentOS':
|
||||||
|
try:
|
||||||
|
needs_restarting = subprocess.check_call(cmd.split(), shell=True)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
retval = 'True'
|
||||||
|
retval = 'False'
|
||||||
|
|
||||||
|
else:
|
||||||
|
retval = 'Unsupported OS: %s' % os
|
||||||
|
|
||||||
|
return retval
|
||||||
23
salt/motd/files/package_update_reboot_required.jinja
Normal file
23
salt/motd/files/package_update_reboot_required.jinja
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{% set needs_restarting_check = salt['mine.get']('*', 'needs_restarting.check', tgt_type='glob') -%}
|
||||||
|
|
||||||
|
{%- if needs_restarting_check %}
|
||||||
|
{%- set minions_need_restarted = [] %}
|
||||||
|
|
||||||
|
{%- for minion, need_restarted in needs_restarting_check | dictsort() %}
|
||||||
|
{%- if need_restarted == 'True' %}
|
||||||
|
{% do minions_need_restarted.append(minion) %}
|
||||||
|
{%- endif %}
|
||||||
|
{%- endfor -%}
|
||||||
|
|
||||||
|
{%- if minions_need_restarted | length > 0 %}
|
||||||
|
*****************************************************************************************
|
||||||
|
* The following nodes in your Security Onion grid need restarted due to package updates *
|
||||||
|
*****************************************************************************************
|
||||||
|
|
||||||
|
{% for minion in minions_need_restarted -%}
|
||||||
|
{{ minion }}
|
||||||
|
{% endfor -%}
|
||||||
|
|
||||||
|
{%- endif -%}
|
||||||
|
|
||||||
|
{%- endif -%}
|
||||||
5
salt/motd/init.sls
Normal file
5
salt/motd/init.sls
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package_update_reboot_required_motd:
|
||||||
|
file.append:
|
||||||
|
- name: /etc/motd
|
||||||
|
- source: salt://motd/files/package_update_reboot_required.jinja
|
||||||
|
- template: jinja
|
||||||
@@ -1,4 +1,14 @@
|
|||||||
|
{% if grains.os == "CentOS" %}
|
||||||
|
include:
|
||||||
|
- yum.packages
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
patch_os:
|
patch_os:
|
||||||
pkg.uptodate:
|
pkg.uptodate:
|
||||||
- name: patch_os
|
- name: patch_os
|
||||||
- refresh: True
|
- refresh: True
|
||||||
|
|
||||||
|
needs_restarting:
|
||||||
|
module.run:
|
||||||
|
- mine.send:
|
||||||
|
- func: needs_restarting.check
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
base:
|
base:
|
||||||
'*':
|
'*':
|
||||||
- patch.os.schedule
|
- patch.os.schedule
|
||||||
|
- motd
|
||||||
|
|
||||||
'G@role:so-sensor':
|
'G@role:so-sensor':
|
||||||
- ca
|
- ca
|
||||||
|
|||||||
3
salt/yum/packages.sls
Normal file
3
salt/yum/packages.sls
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
install_yum_utils:
|
||||||
|
pkg.installed:
|
||||||
|
- name: yum-utils
|
||||||
Reference in New Issue
Block a user