2012-01-20 :-(
_ [munin]動的IPアドレスの監視サーバから外部のサーバを監視する
@nullpopopo がやってたこれ (っ´∀`)っ ゃー » [munin] 動的IPアドレスの監視サーバから外部のサーバを監視する
自宅( 動的IPアドレス ) で munin server を動作させ、外部の munin node ( 固定IPアドレス ) を監視する。方針としては @nullpopopo と同じで、自宅から munin node に接続したタイミングで接続元 IP アドレスを取得し、その IP アドレスを munin-node.conf に書きこむ。
munin node の munin-node.conf に # ALLOW MUNIN SERVER という目印を書いておき、その次の行に書いてある allow を更新することにする。 munin-node.conf はこんな:
# # Example config-file for munin-node # log_level 4 log_file /var/log/munin/munin-node.log port 4949 pid_file /var/run/munin/munin-node.pid background 1 setseid 1 # Which port to bind to; host * user root group wheel setsid yes # Regexps for files to ignore ignore_file ~$ ignore_file \.bak$ ignore_file %$ ignore_file \.dpkg-(tmp|new|old|dist)$ ignore_file \.rpm(save|new)$ # Set this if the client doesn't report the correct hostname when # telnetting to localhost, port 4949 # #host_name mogu.area51.gr.jp # A list of addresses that are allowed to connect. This must be a # regular expression, due to brain damage in Net::Server, which # doesn't understand CIDR-style network notation. You may repeat # the allow line as many times as you'd like allow ^127\.0\.0\.1$ allow ^192\.168\.0\..* # ALLOW MUNIN SERVER <==== 目印 allow ^127\.0\.0\.1$ <==== ここを更新する
munin-node の /usr/pkg/etc/munin/munin-node.conf を更新するだけの簡単なコードを書くことにしてみた。SSH_CLIENT は非推奨と言われてますがー [ 20111226#p04 ]
#!/usr/pkg/bin/ruby # -*- coding: utf-8 -*- def main(argv) :ST_ALLOW :ST_ADDRESS :ST_END conf = "/usr/pkg/etc/munin/munin-node.conf" svr = ENV['SSH_CLIENT'].split(' ')[0] st = :ST_ALLOW allow = "^#{svr.gsub('.', '\\.')}$" text = "" File.open(conf).each { |line| case st when :ST_ALLOW if line =~ /ALLOW MUNIN SERVER/ st = :ST_ADDRESS end when :ST_ADDRESS line.gsub!(/^allow.*/, "allow #{allow}") st = :ST_END end text << line } File.open(conf, "w").write(text) end main(ARGV
自宅から実行
% ssh -t homuhomu.example.jp "sudo -E ~/work/munin/update-munin-server_address.rb"
[ツッコミを入れる]