ZNCでSlackのログ取り
概要
無料版Slackだと、過去ログを10000メッセージしか保存しないので、
ZNCを使って無料でSlackの過去ログを保存した話。
Searchable message archives, up to 10k of your team’s most recent messages
ZNCとはなにか
- IRC Bouncer
- IRCサーバやSlackなどに常時接続してログを取得できるソフトウェア
- ZNC経由でIRCクライアントを接続すれば、IRCクライアントが起動してなかった時間のログもとっておいてくれる
- IRCサーバとSSL接続が可能で、Channelが増えたら自動で検出する
zncのインストール
# yum install znc
epelリポジトリが必要
zncのユーザが作られる
# grep znc /etc/passwd znc:x:495:495:Account for ZNC to run as:/var/lib/znc:/sbin/nologin
znc --makeconf で初期設定
- 対話型のシェルが走り,~/.znc/configs/znc.confに設定ファイルが作成される
- rootでは起動できないので、zncユーザで実行する
# id uid=0(root) gid=0(root) 所属グループ=0(root) # znc --makeconf [ .. ] Checking for list of available modules... [ >> ] ok [ ** ] You are running ZNC as root! Don't do that! There are not many valid [ ** ] reasons for this and it can, in theory, cause great damage! → rootでは起動できない
zncユーザで実行する
Installation - Fedora/CentOS/Red Hat Enterprise Linux
- Username :IRCのユーザとパスワード
# cd /var/lib/znc # sudo -u znc znc --makeconf ※/var/lib/znc/.znc/ ができる [ .. ] Checking for list of available modules... [ >> ] ok [ ** ] Building new config [ ** ] [ ** ] First let's start with some global settings... [ ** ] [ ?? ] What port would you like ZNC to listen on? (1025 to 65535): 56667 [ ?? ] Would you like ZNC to listen using SSL? (yes/no) [no]: yes [ ?? ] Would you like ZNC to listen using both IPv4 and IPv6? (yes/no) [yes]: [ .. ] Verifying the listener... [ >> ] ok [ ** ] Unable to locate pem file: [/home/znc_user/.znc/znc.pem], creating it [ .. ] Writing Pem file [/home/znc_user/.znc/znc.pem]... [ >> ] ok [ ** ] [ ** ] -- Global Modules -- [ ** ] [ ** ] +-----------+----------------------------------------------------------+ [ ** ] | Name | Description | [ ** ] +-----------+----------------------------------------------------------+ [ ** ] | partyline | Internal channels and queries for users connected to znc | [ ** ] | webadmin | Web based administration module | [ ** ] +-----------+----------------------------------------------------------+ [ ** ] And 10 other (uncommon) modules. You can enable those later. [ ** ] [ ?? ] Load global module <partyline>? (yes/no) [no]: [ ?? ] Load global module <webadmin>? (yes/no) [no]: yes [ ** ] [ ** ] Now we need to set up a user... [ ** ] [ ?? ] Username (AlphaNumeric): [ ?? ] Enter Password: [ ?? ] Confirm Password: [ ?? ] Would you like this user to be an admin? (yes/no) [yes]: [ ?? ] Nick [znc_user]: [ ?? ] Alt Nick [znc_user_]: [ ?? ] Ident [znc_user]: [ ?? ] Real Name [Got ZNC?]: [ ?? ] Bind Host (optional): [ ?? ] Number of lines to buffer per channel [50]: [ ?? ] Would you like to clear channel buffers after replay? (yes/no) [yes]: [ ?? ] Default channel modes [+stn]: [ ** ] [ ** ] -- User Modules -- [ ** ] [ ** ] +--------------+------------------------------------------------------------------------------------------+ [ ** ] | Name | Description | [ ** ] +--------------+------------------------------------------------------------------------------------------+ [ ** ] | chansaver | Keep config up-to-date when user joins/parts | [ ** ] | controlpanel | Dynamic configuration through IRC. Allows editing only yourself if you're not ZNC admin. | [ ** ] | perform | Keeps a list of commands to be executed when ZNC connects to IRC. | [ ** ] | webadmin | Web based administration module | [ ** ] +--------------+------------------------------------------------------------------------------------------+ [ ** ] And 21 other (uncommon) modules. You can enable those later. [ ** ] [ ?? ] Load module <chansaver>? (yes/no) [no]: [ ?? ] Load module <controlpanel>? (yes/no) [no]: [ ?? ] Load module <perform>? (yes/no) [no]: [ ?? ] Load module <webadmin>? (yes/no) [no]: [ ** ] [ ?? ] Would you like to set up a network? (yes/no) [no]: no [ ** ] [ ?? ] Would you like to set up another user? (yes/no) [no]: no [ .. ] Writing config [/home/znc_user/.znc/configs/znc.conf]... [ >> ] ok [ ** ] [ ** ]To connect to this ZNC you need to connect to it as your IRC server [ ** ]using the port that you supplied. You have to supply your login info [ ** ]as the IRC server password like this: user/network:pass. [ ** ] [ ** ]Try something like this in your IRC client... [ ** ]/server <znc_server_ip> +56667 znc_user:<pass> [ ** ]And this in your browser... [ ** ]https://<znc_server_ip>:56667/ [ ** ] [ ?? ] Launch ZNC now? (yes/no) [yes]: no
znc.confの編集
Slackへの接続設定
Slackへの接続方法は以下を確認しておく
https://xxxxxx.slack.com/account/gateways
Host: xxxxxxxx.irc.slack.com User: user_name Pass: xxxxxxxxxxxxxxxxxxxx
znc.confに以下を追記
<Network {team-name}> LoadModule = simple_away Server = xxxxxxxx.irc.slack.com +6667 xxxxxxxxxxxxxxxxxxxx </Network>
znc起動
$ /usr/bin/znc →これでバックグラウンドで起動する
停止
# pkill znc
Webadmin画面
https://{IPaddress}:{56667}
ログ取得設定
- デフォルトだとログは出力されないので、設定が必要
- デフォルトだと1日ごとにローテートされる
- 取れるのはオープンなチャンネルのみ
- Priveteなチャンネル、個人間のやりとりはログには残らない
- チャンネルが追加されると自動的にログも吐いてくれる
Webadmin > Your Settings > logsにチェックを入れる
$ cd ~/.znc/users/xxxxx/networks/xxxx/moddata/log/ # ll 合計 36 -rw-r--r-- 1 znc znc 2056 2月 3 18:02 2016 #channel01_20160203.log -rw-r--r-- 1 znc znc 3835 2月 3 18:03 2016 #channel02_20160203.log
起動と停止
- ユーザのプロセスのため、rootで停止はできるが起動はできない
- rootで起動するなら ”sudo -u [ユーザ名] /usr/bin/znc”とかやっとけばいいと思う
# id uid=0(root) gid=0(root) 所属グループ=0(root) # service znc stop znc を停止中: [ OK ] # ps -ef | grep znc root 27322 27246 0 10:16 pts/0 00:00:00 grep znc # /etc/init.d/znc start znc を起動中: [失敗] →失敗する ## 起動するには、ユーザにsuしてzncコマンド # su -znc $ znc [ .. ] Checking for list of available modules... [ >> ] ok [ .. ] Opening config [/home/fujino/.znc/configs/znc.conf]... [ >> ] ok [ .. ] Loading global module [partyline]... $ ps -ef | grep znc znc 27467 1 0 10:18 ? 00:00:00 znc znc 27471 27404 0 10:19 pts/0 00:00:00 grep znc
自動起動設定
やり方
デーモンとして動かす
Running ZNC as a system daemon起動時にコマンドを実行するようにする
→ Restartはkillとzncで
How can I restart ZNC automatically (in case of a machine reboot, crash, etc.)?
# /etc/rc.d/rc.local に以下を追記 su -l znc -s /bin/bash -c '/usr/bin/znc'
ZNCのモジュール
- ZNCの拡張機能
- Webadmin画面か設定ファイルでモジュールを追加と削除が可能
その他いろいろ
試してはないけど、おもしろそうなもの
参考
仕事中にこっそりSlackする
Node.jsで書かれたIRC bouncer、homura を作りました
IRC Bouncers(IRC Proxy)あれこれ
BNC (software) - Wikipedia, the free encyclopedia