Keep regex as default but still allow overrides.
diff --git a/_modules/linux_netlink.py b/_modules/linux_netlink.py
new file mode 100644
index 0000000..b1a3c17
--- /dev/null
+++ b/_modules/linux_netlink.py
@@ -0,0 +1,16 @@
+# -*- coding: utf-8 -*-
+
+import re
+
+
+def ls(regex=r'^[a-z0-9]+$'):
+ """
+ Provide a list of network interfaces.
+ """
+ _lo_re = re.compile(r'^lo$')
+ _alphanum_re = re.compile(regex)
+
+ def _filter(interface):
+ return _alphanum_re.match(interface) and not _lo_re.match(interface)
+
+ return filter(_filter, __salt__['grains.get']('ip_interfaces', {}).keys())
diff --git a/linux/map.jinja b/linux/map.jinja
index 0a6db54..d27c7d1 100644
--- a/linux/map.jinja
+++ b/linux/map.jinja
@@ -210,7 +210,9 @@
'crit': '5%',
},
'netlink': {
- 'interfaces': ['all'],
+ 'interface_override': False,
+ 'interfaces': [],
+ 'interface_regex': '^[a-z0-9]+$',
'ignore_selected': False,
},
},
diff --git a/linux/meta/collectd.yml b/linux/meta/collectd.yml
index 41831b3..aa153da 100644
--- a/linux/meta/collectd.yml
+++ b/linux/meta/collectd.yml
@@ -4,8 +4,14 @@
plugin: netlink
template: linux/files/collectd_netlink.conf
ignore_selected: {{ monitoring.netlink.ignore_selected }}
+ {%- if monitoring.netlink.interface_override and monitoring.netlink.interfaces is list %}
+ {%- set interfaces = monitoring.netlink.interfaces %}
+ {%- else %}
+ {%- set interfaces = salt['linux_netlink.ls'](monitoring.netlink.interface_regex) %}
+ {%- endif %}
+ {%- if interfaces %}
interfaces:
- {%- for interface_name in monitoring.netlink.interfaces|sort %}
+ {%- for interface_name in interfaces|sort %}
- {{ interface_name }}
{%- endfor %}
{%- endif %}