Merge pull request #113 from jm890/pillar_interface_selection

Use Pillar to choose which interfaces to monitor.
diff --git a/_modules/linux_netlink.py b/_modules/linux_netlink.py
index 9e6df55..52d8a1d 100644
--- a/_modules/linux_netlink.py
+++ b/_modules/linux_netlink.py
@@ -2,16 +2,15 @@
 
 import re
 
-_alphanum_re = re.compile(r'^[a-z0-9]+$')
-_lo_re = re.compile(r'^lo$')
 
-
-def _filter(interface):
-    return _alphanum_re.match(interface) and not _lo_re.match(interface)
-
-
-def ls():
+def ls(regex):
     """
     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 771da0f..a27906c 100644
--- a/linux/map.jinja
+++ b/linux/map.jinja
@@ -200,24 +200,29 @@
 {% set monitoring = salt['grains.filter_by']({
     'default': {
         'zombie': {
-              'warn': 3,
-              'crit': 7,
+            'warn': 3,
+            'crit': 7,
         },
         'procs': {
-              'warn': 5000,
-              'crit': 10000,
+            'warn': 5000,
+            'crit': 10000,
         },
         'load': {
-              'warn': '6,4,2',
-              'crit': '12,8,4',
+            'warn': '6,4,2',
+            'crit': '12,8,4',
         },
         'swap': {
-              'warn': '50%',
-              'crit': '20%',
+            'warn': '50%',
+            'crit': '20%',
         },
         'disk': {
-              'warn': '15%',
-              'crit': '5%',
+            'warn': '15%',
+            'crit': '5%',
+        },
+        'netlink': {
+            'interfaces': [],
+            'interface_regex': '^[a-z0-9]+$',
+            'ignore_selected': False,
         },
         'cpu_idle_percentage': {
               'warn': 10.0,
diff --git a/linux/meta/collectd.yml b/linux/meta/collectd.yml
index d38f1ae..521e895 100644
--- a/linux/meta/collectd.yml
+++ b/linux/meta/collectd.yml
@@ -1,11 +1,17 @@
+{%- from "linux/map.jinja" import monitoring with context %}
 local_plugin:
   linux_network_netlink:
     plugin: netlink
     template: linux/files/collectd_netlink.conf
-    ignore_selected: false
-    {%- if 'linux_netlink.ls' in salt.keys() %}
+    ignore_selected: {{ monitoring.netlink.ignore_selected }}
+    {%- if monitoring.netlink.interfaces is list and monitoring.netlink.interfaces|length > 0 %}
+    {%- set interfaces = monitoring.netlink.interfaces %}
+    {%- else %}
+    {%- set interfaces = salt['linux_netlink.ls'](monitoring.netlink.interface_regex) %}
+    {%- endif %} 
+    {%- if interfaces %}
     interfaces:
-    {%- for interface_name in salt['linux_netlink.ls']() %}
+    {%- for interface_name in interfaces|sort %}
     - {{ interface_name }}
     {%- endfor %}
     {%- endif %}