所有网络接口的盐矿 [英] salt mine for all network interfaces

查看:59
本文介绍了所有网络接口的盐矿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过 salt 使用 interface 插件配置 collectd.conf.collectd.conf 需要一个网络接口列表来监控,例如:

I'm having difficulty configuring collectd.conf using the interface plugin through salt. The collectd.conf expects a list of network interfaces to monitor like:

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

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

I've worked out that I need to use a salt mine to pull the grains into the master - which is achieved through a pillar sls like the following:

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>

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

However, it doesn't appear to work for me :(

推荐答案

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

If you're looking for interfaces on the local host (which I gather you are since you're filtering on grains['id']) then you don't need mine for this. You can get the interface names on the local host from grains:

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

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

If you want a list of the local machine's addresses instead of interface names, you can loop over grains['ipv4'] instead. No .keys(); that grain is a simple list.

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

If you need interface information for other hosts, then you use mine. Note that network.interfaces returns a nested dictionary, which may be why it's not working for you -- you are looping over it as if it were a list, which (at least when I tested it just now) produces an unreadable mess.

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

To get interface names from other servers, you would actually use something more like:

{%- 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.

这正是您所要求的,但似乎并不是您真正想要做的.

This is sort of what you asked but doesn't seem like what you're actually trying to do.

这篇关于所有网络接口的盐矿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆