トップ «前の日記(2012-01-19) 最新 次の日記(2012-01-21)» 編集

ヨタの日々

2001|08|09|10|11|12|
2002|01|02|03|04|05|06|07|08|09|10|11|12|
2003|01|02|03|04|05|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|12|
2024|01|02|03|04|

2012-01-20 :-(

_ 午前

0520 起床

0830 出勤

0900 テスト準備

_ 午後

1300 テスト準備

1700 退勤

_

1900 munin

2030 飯

_ [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"