0

我很难collectd.conf通过. 期望监控的网络接口列表如下:interfacesaltcollectd.conf

<Plugin interface>
  Interface "em1"
  Interface "em2"
</Plugin>

我已经确定我需要使用 asalt mine将谷物拉入主控器 - 这是通过如下所示的支柱 sls 实现的:

mine_functions:
  network.interfaces: []

在我的collectd.conf我有:

<Plugin interface>
{% for host, info in salt['mine.get']('*','network.interfaces').items() %}
 {% if host == grains['id'] %}
  {% for interface in info %}
  Interface "{{ interface }}"
  {% endfor %}
 {% endif %}
{% endif %}
{% endfor %}
</Plugin>

但是,它似乎对我不起作用:(

4

1 回答 1

0

如果您正在本地主机上寻找接口(我认为您是因为您正在过滤 grains['id']),那么您不需要我的接口。您可以从 grains 获取本地主机上的接口名称:

{%- for iface in grains['ip_interfaces'].keys() %}
Interface "{{ iface }}"
{%- endfor %}

如果您想要本地机器的地址列表而不是接口名称,则可以循环遍历 grains['ipv4'] 。没有.keys();那粒谷物是一个简单的清单。

如果您需要其他主机的接口信息,那么您使用我的。请注意,network.interfaces 返回一个嵌套字典,这可能就是它对您不起作用的原因——您正在循环它,就好像它是一个列表一样,这(至少在我刚刚测试它时)会产生难以理解的混乱。

要从其他服务器获取接口名称,您实际上会使用类似的东西:

{%- for minion, ifaces in salt['mine.get']('*', 'network.interfaces').items() %}
{{ minion }}:
{%-   for iface in ifaces.keys() %}
  - {{ iface }}
{%-   endfor %}
{%- endfor %}

哪个应该输出:

minion1:
  - eth0
  - eth1
  - lo
minion2:
  - eth0
  - eth1
  - lo
...and so on.

这有点像你问的,但看起来不像你真正想要做的。

于 2015-06-19T13:44:57.487 回答