2
我没有得到使用python脚本在munin.conf中添加节点的确切解决方案。我尝试使用ConfigParser,但由于munin.conf是一个无段文件,因此无法使用该模块。 Anyoune可以向我建议可能的解决方案吗?如何在使用Python脚本的munin中添加节点以监视?
我没有得到使用python脚本在munin.conf中添加节点的确切解决方案。我尝试使用ConfigParser,但由于munin.conf是一个无段文件,因此无法使用该模块。 Anyoune可以向我建议可能的解决方案吗?如何在使用Python脚本的munin中添加节点以监视?
用python脚本在munin中添加主机或节点可以通过使用python的config parser模块来完成。下面是它的解决方案: -
def addhost(self, host):
cfile = '/etc/munin/munin.conf'
hostname = host['host_name']
address = host['address']
# use_node_name = host['use_node_name']
with open(cfile, "r+") as f:
s = f.read()
f.seek(0)
f.write("[default]\n" + s)
config.readfp(f)
# config.add_section(hostname)
# config.set(hostname, 'address '+ address)
# config.set(hostname, 'use_node_name yes')
#config.write(fout)
with open(cfile,"w") as fout:
print config.sections()
#config.readfp(fout)
config.add_section(hostname)
config.set(hostname, 'address ' + address)
config.set(hostname, 'use_node_name yes')
config.write(fout)
for line in fileinput.input(cfile, inplace=1):
line = line.strip()
if not '[default]' in line:
print line
在这里,对于使用配置解析器,我们需要在munin.conf中做一些更改。首先你需要在上面写入一个默认的文件,然后写下你想写的数据,第三个删除该部分。通过这种方式,您可以通过python在munin中添加一个节点进行监控。
你能否给我提供这个功能的输出...... –