参考
準備
- nagiosの状態変更をIRCに通知(nagircbot) - Qiitaを参考にIRCサーバを立てておく。
sudo gem install cinch
ircbot.rb
#!/usr/bin/ruby
require 'cinch'
bot = Cinch::Bot.new do
configure do |c|
c.server = "localhost"
c.port = "8888"
c.nick = "cinch"
c.channels = ["#chat", "#todo"]
c.password = "xahH7eo2"
end
on :message, /@cinch / do |m|
command = m.message.match(/@cinch (\w.*)/)[1]
require "open3"
out, err, status = Open3.capture3(command)
m.reply out
end
end
bot.start
起動
./ircbot.rb
使い方
- cinchが居るIRCチャンネル上から以下命令で、任意のコマンドの標準出力が1行ずつ投稿される。
- ホワイトリスト形式にすれば安心して使えるかも。
@cinch コマンド
@cinch ps -ef | grep http[d] | wc -l
@cinch w