Merge "Add alerts on disk full"
diff --git a/.kitchen.vagrant.yml b/.kitchen.vagrant.yml
new file mode 100644
index 0000000..fb9981e
--- /dev/null
+++ b/.kitchen.vagrant.yml
@@ -0,0 +1,36 @@
+---
+driver:
+ name: vagrant
+ vm_hostname: linux.ci.local
+ use_sudo: false
+ customize:
+ memory: 1024
+
+
+provisioner:
+ name: salt_solo
+ salt_install: bootstrap
+ salt_bootstrap_url: https://bootstrap.saltstack.com
+ salt_version: latest
+ require_chef: false
+ log_level: error
+ formula: linux
+ grains:
+ noservices: true
+ state_top:
+ base:
+ "*":
+ - linux
+ pillars:
+ top.sls:
+ base:
+ "*":
+ - linux
+
+platforms:
+- name: ubuntu-16.04
+- name: ubuntu-14.04
+- name: centos-7.3
+- name: centos-6.8
+
+# vim: ft=yaml sw=2 ts=2 sts=2 tw=125
diff --git a/README.rst b/README.rst
index 6f81c5d..620f582 100644
--- a/README.rst
+++ b/README.rst
@@ -687,6 +687,18 @@
Possible status is dead (disable service by default), running (enable service by default), enabled, disabled.
+Linux with atop service:
+
+.. code-block:: yaml
+
+ linux:
+ system:
+ atop:
+ enabled: true
+ interval: 20
+ logpath: "/var/log/atop"
+ outfile: "/var/log/atop/daily.log"
+
RHEL / CentOS
^^^^^^^^^^^^^
@@ -984,6 +996,36 @@
reject:
- 192.33.137.211
+Linux network systemd settings:
+
+.. code-block:: yaml
+
+ linux:
+ network:
+ ...
+ systemd:
+ link:
+ 10-iface-dmz:
+ Match:
+ MACAddress: c8:5b:67:fa:1a:af
+ OriginalName: eth0
+ Link:
+ Name: dmz0
+ netdev:
+ 20-bridge-dmz:
+ match:
+ name: dmz0
+ network:
+ mescription: bridge
+ bridge: br-dmz0
+ network:
+ # works with lowercase, keys are by default capitalized
+ 40-dhcp:
+ match:
+ name: '*'
+ network:
+ DHCP: yes
+
Configure global environment variables
diff --git a/_modules/linux_hosts.py b/_modules/linux_hosts.py
index 08741ec..78853bd 100644
--- a/_modules/linux_hosts.py
+++ b/_modules/linux_hosts.py
@@ -24,4 +24,4 @@
if iterable is None or isinstance(iterable, Undefined):
return iterable
# Do effective custom sorting of iterable here
- return sorted(iterable, cmp=fqdn_sort_fn)
+ return sorted(set(iterable), cmp=fqdn_sort_fn)
diff --git a/linux/files/atop.conf b/linux/files/atop.conf
new file mode 100644
index 0000000..4474da7
--- /dev/null
+++ b/linux/files/atop.conf
@@ -0,0 +1,5 @@
+{%- from "linux/map.jinja" import system with context -%}
+# This file /etc/default/atop is managed by Salt linux formula
+INTERVAL={{ system.atop.interval }}
+LOGPATH={{ system.atop.logpath }}
+OUTFILE={{ system.atop.outfile }}
diff --git a/linux/files/atop.systemd b/linux/files/atop.systemd
new file mode 100644
index 0000000..be57dbb
--- /dev/null
+++ b/linux/files/atop.systemd
@@ -0,0 +1,16 @@
+{%- from "linux/map.jinja" import system with context -%}
+[Unit]
+Description=atop - advanced interactive monitor
+After=syslog.target
+ConditionPathExists={{ config_file }}
+Documentation=man:atop(1)
+Documentation=https://atoptool.nl
+
+[Service]
+EnvironmentFile=-{{ config_file }}
+ExecStart=/usr/bin/atop -a -w ${LOGPATH}/daily.log ${INTERVAL}
+Restart=always
+RestartSec=10
+
+[Install]
+WantedBy=multi-user.target
diff --git a/linux/files/systemd-network.conf b/linux/files/systemd-network.conf
new file mode 100644
index 0000000..6a21b4f
--- /dev/null
+++ b/linux/files/systemd-network.conf
@@ -0,0 +1,8 @@
+{%- from "linux/map.jinja" import system with context -%}
+{%- for section, options in settings.iteritems() %}
+
+[{{ section[0].upper() + section[1:] }}]
+{%- for option, value in options.iteritems() %}
+{{ option[0].upper() + option[1:] }}={{ value }}
+{%- endfor %}
+{%- endfor %}
diff --git a/linux/map.jinja b/linux/map.jinja
index 5827614..d6ffc4f 100644
--- a/linux/map.jinja
+++ b/linux/map.jinja
@@ -18,6 +18,13 @@
},
'selinux': 'permissive',
'ca_certs_dir': '/usr/local/share/ca-certificates',
+ 'atop': {
+ 'enabled': false,
+ 'interval': '20',
+ 'autostart': true,
+ 'logpath': '/var/log/atop',
+ 'outfile': '/var/log/atop/daily.log'
+ },
},
'Debian': {
'pkgs': ['python-apt', 'apt-transport-https', 'libmnl0'],
@@ -38,6 +45,13 @@
},
'selinux': 'permissive',
'ca_certs_dir': '/usr/local/share/ca-certificates',
+ 'atop': {
+ 'enabled': false,
+ 'interval': '20',
+ 'autostart': true,
+ 'logpath': '/var/log/atop',
+ 'outfile': '/var/log/atop/daily.log'
+ },
},
'RedHat': {
'pkgs': ['policycoreutils', 'policycoreutils-python', 'telnet', 'wget'],
@@ -58,6 +72,13 @@
},
'selinux': 'permissive',
'ca_certs_dir': '/usr/local/share/ca-certificates',
+ 'atop': {
+ 'enabled': false,
+ 'interval': '20',
+ 'autostart': true,
+ 'logpath': '/var/log/atop',
+ 'outfile': '/var/log/atop/daily.log'
+ },
},
}, grain='os_family', merge=salt['pillar.get']('linux:system')) %}
@@ -101,6 +122,7 @@
'ovs_pkgs': ['openvswitch-switch'],
'hostname_file': '/etc/hostname',
'network_manager': False,
+ 'systemd': {},
'interface': {},
'interface_params': interface_params,
'bridge': 'none',
@@ -117,6 +139,7 @@
'ovs_pkgs': ['openvswitch-switch', 'bridge-utils'],
'dpdk_pkgs': ['dpdk', 'dpdk-dev', 'dpdk-dkms', 'dpdk-igb-uio-dkms', 'dpdk-rte-kni-dkms'],
'network_manager': False,
+ 'systemd': {},
'interface': {},
'interface_params': interface_params,
'bridge': 'none',
@@ -132,6 +155,7 @@
'ovs_pkgs': ['openvswitch-switch', 'bridge-utils'],
'hostname_file': '/etc/sysconfig/network',
'network_manager': False,
+ 'systemd': {},
'interface': {},
'interface_params': interface_params,
'bridge': 'none',
diff --git a/linux/meta/logrotate.yml b/linux/meta/logrotate.yml
new file mode 100644
index 0000000..cd980f7
--- /dev/null
+++ b/linux/meta/logrotate.yml
@@ -0,0 +1,20 @@
+{%- from "linux/map.jinja" import system with context -%}
+
+{%- if system.atop.enabled %}
+job:
+ atop:
+ - files:
+ - {{ system.atop.logpath }}/atop*
+ - {{ system.atop.logpath }}/{{ system.atop.outfile }}
+ options:
+ - olddir {{ system.atop.logpath }}/old
+ - compress
+ - delaycompress
+ - missingok
+ - notifempty
+ - rotate: 10
+ - daily
+ - minsize: 20M
+ - maxsize: 500M
+ - postrotate: "if ! service atop status > /dev/null; then service atop restart > /dev/null; fi"
+{%- endif %}
diff --git a/linux/meta/telegraf.yml b/linux/meta/telegraf.yml
index 2ff4386..693638b 100644
--- a/linux/meta/telegraf.yml
+++ b/linux/meta/telegraf.yml
@@ -5,6 +5,7 @@
totalcpu: true
disk:
ignore_fs:
+ - aufs
- rootfs
- sysfs
- proc
diff --git a/linux/network/init.sls b/linux/network/init.sls
index 21069d3..56b05a5 100644
--- a/linux/network/init.sls
+++ b/linux/network/init.sls
@@ -13,6 +13,9 @@
{%- if network.dhclient is defined %}
- linux.network.dhclient
{%- endif %}
+{%- if network.systemd|length > 0 %}
+- linux.network.systemd
+{%- endif %}
{%- if network.interface|length > 0 %}
- linux.network.interface
{%- endif %}
diff --git a/linux/network/systemd.sls b/linux/network/systemd.sls
new file mode 100644
index 0000000..a8e1f24
--- /dev/null
+++ b/linux/network/systemd.sls
@@ -0,0 +1,43 @@
+{%- from "linux/map.jinja" import network with context %}
+{%- if network.enabled and grains.get('init', None) == 'systemd' %}
+
+{%- if network.systemd is mapping %}
+{%- for config_type, configs in network.systemd.iteritems() %}
+
+{%- if config_type == 'link' %}
+/etc/udev/rules.d/80-net-setup-link.rules:
+ file.managed:
+ - makedirs: True
+ - content: ""
+{%- endif %}
+
+{%- for config_name, config in configs.iteritems() %}
+linux_network_systemd_networkd_{{ config_type }}_config_{{ config_name }}:
+ file.managed:
+ - name: /etc/systemd/network/{{ config_name }}.{{ config_type }}
+ - source: salt://linux/files/systemd-network.conf
+ - template: jinja
+ - makedirs: True
+ - defaults:
+ settings: {{ config }}
+ - watch_in:
+ - module: linux_network_systemd_reload
+ - module: linux_network_systemd_networkd
+{%- endfor %}
+{%- endfor %}
+
+linux_network_systemd_reload:
+ module.wait:
+ - name: service.systemctl_reload
+
+linux_network_systemd_networkd:
+ service.running:
+ - name: systemd-networkd
+ - init_delay: 10
+ - enable: True
+ - reload: True
+ - watch:
+ - module: linux_network_systemd_reload
+
+{%- endif %}
+{%- endif %}
diff --git a/linux/system/atop.sls b/linux/system/atop.sls
new file mode 100644
index 0000000..e31db8a
--- /dev/null
+++ b/linux/system/atop.sls
@@ -0,0 +1,76 @@
+{%- from "linux/map.jinja" import system with context %}
+
+{%- if system.atop.enabled %}
+
+atop_packages:
+ pkg.installed:
+ - name: atop
+
+atop_defaults:
+ file.managed:
+ - name: /etc/default/atop
+ - source: salt://linux/files/atop.conf
+ - template: jinja
+ - user: root
+ - group: root
+ - mode: 644
+
+atop_logpath:
+ file.directory:
+ - name: {{ system.atop.logpath }}
+ - user: root
+ - group: root
+ - mode: 750
+ - makedirs: true
+
+{%- if grains.get('init', None) == 'systemd' %}
+atop_systemd_file:
+ file.managed:
+ - name: /etc/systemd/system/atop.service
+ - source: salt://linux/files/atop.service
+ - user: root
+ - mode: 644
+ - defaults:
+ service_name: atop
+ config_file: /etc/default/atop
+ autostart: {{ system.atop.autostart }}
+ - template: jinja
+ - require_in:
+ - service: atop_service
+{%- endif %}
+
+atop_service:
+ service.running:
+ - name: atop
+ - enable: {{ system.atop.autostart }}
+ - watch:
+ - file: atop_defaults
+ {%- if grains.get('noservices') %}
+ - onlyif: /bin/false
+ {%- endif %}
+
+{%- else %}
+
+atop_service_stop:
+ service.dead:
+ - name: atop
+ - enable: false
+ - require_in:
+ - pkg: atop_pkg_purge
+ {%- if grains.get('noservices') %}
+ - onlyif: /bin/false
+ {%- endif %}
+
+atop_defaults_purge:
+ file.absent:
+ - names:
+ - /etc/default/atop
+ - /etc/systemd/system/atop.service
+ - require:
+ - pkg: atop_pkg_purge
+
+atop_pkg_purge:
+ pkg.purged:
+ - name: atop
+
+{%- endif %}
diff --git a/linux/system/init.sls b/linux/system/init.sls
index 0ba87aa..2f379f4 100644
--- a/linux/system/init.sls
+++ b/linux/system/init.sls
@@ -63,6 +63,9 @@
{%- if system.apparmor is defined %}
- linux.system.apparmor
{%- endif %}
+{%- if pillar.linux.system.atop is defined %}
+- linux.system.atop
+{%- endif %}
{%- if system.console is defined %}
- linux.system.console
{%- endif %}
diff --git a/tests/pillar/network.sls b/tests/pillar/network.sls
index 009228f..840fd84 100644
--- a/tests/pillar/network.sls
+++ b/tests/pillar/network.sls
@@ -88,3 +88,30 @@
# initial_interval: 12
# reject:
# - 10.0.4.0/24
+ systemd:
+ link:
+ 10-iface-dmz:
+ match:
+ type: eth
+ # MACAddress: c8:5b:7f:a5:1a:da
+ # OriginalName: eth0
+ link:
+ name: dmz0
+ netdev:
+ 20-bridge:
+ NetDev:
+ Name: br0
+ Kind: bridge
+ 20-bridge-dmz:
+ # test all lowercase
+ match:
+ name: dmz0
+ network:
+ description: bridge
+ bridge: br-dmz0
+ network:
+ 40-dhcp:
+ Match:
+ Name: '*'
+ Network:
+ DHCP: yes
diff --git a/tests/pillar/system.sls b/tests/pillar/system.sls
index f39fdde..411323c 100644
--- a/tests/pillar/system.sls
+++ b/tests/pillar/system.sls
@@ -346,3 +346,8 @@
192.168.0.1:
mac: "ff:ff:ff:ff:ff:ff"
interface: bond0
+ atop:
+ enabled: true
+ interval: 20
+ logpath: "/var/mylog/atop"
+ outfile: "/var/mylog/atop/daily.log"