diff --git a/salt/_modules/needs_restarting.py b/salt/_modules/needs_restarting.py new file mode 100644 index 000000000..51f80670a --- /dev/null +++ b/salt/_modules/needs_restarting.py @@ -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 diff --git a/salt/motd/files/package_update_reboot_required.jinja b/salt/motd/files/package_update_reboot_required.jinja new file mode 100644 index 000000000..3a1fd1e9e --- /dev/null +++ b/salt/motd/files/package_update_reboot_required.jinja @@ -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 -%} diff --git a/salt/motd/init.sls b/salt/motd/init.sls new file mode 100644 index 000000000..a314ddb80 --- /dev/null +++ b/salt/motd/init.sls @@ -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 diff --git a/salt/patch/os/init.sls b/salt/patch/os/init.sls index d3ae6a1ff..97183199b 100644 --- a/salt/patch/os/init.sls +++ b/salt/patch/os/init.sls @@ -1,4 +1,14 @@ +{% if grains.os == "CentOS" %} +include: + - yum.packages +{% endif %} + patch_os: pkg.uptodate: - name: patch_os - refresh: True + +needs_restarting: + module.run: + - mine.send: + - func: needs_restarting.check diff --git a/salt/top.sls b/salt/top.sls index f742a66cf..711cf564c 100644 --- a/salt/top.sls +++ b/salt/top.sls @@ -7,6 +7,7 @@ base: '*': - patch.os.schedule + - motd 'G@role:so-sensor': - ca diff --git a/salt/yum/packages.sls b/salt/yum/packages.sls new file mode 100644 index 000000000..4c773d0e9 --- /dev/null +++ b/salt/yum/packages.sls @@ -0,0 +1,3 @@ +install_yum_utils: + pkg.installed: + - name: yum-utils