nagios と slack を Amazon Linux から連携しようとしたら エラー で半日程度かかった件

slackにはnagios integrationがあるから楽勝と思ってたんですが、今日半日かかったのでメモ。

  • PCから対象チームのSlack Web UIにログインし、左上チーム名をクリックしたメニューから[App & Integrations]を選択します。この辺りのワーディングが結構時間とともに変わるので最初場所がわからんかった。
  • Find new apps ... のinput formからnagiosで検索します。
  • 左の[Add configuration]をクリックします。あとは、基本[Setup Instructions]の通りなのですが。。。
  • Amazon Linuxにはaptなんてないのでyumで必要なperlライブラリをインストールします。こう。

yum info perl-libwww-perl perl-Crypt-SSLeay

  • Download the plugin and move it into place:(Slackのまんまです)

wget https://raw.github.com/tinyspeck/services-examples/master/nagios.pl
cp nagios.pl /usr/local/bin/slack_nagios.pl
chmod 755 /usr/local/bin/slack_nagios.pl

  • Edit the slack_nagios.pl, find the $opt_domain and $opt_token variables, and set them to:(Slackのではちゃんとあなたの環境のが書かれているのでコピペして貼ればよいです)

my $opt_domain = "hogehugapiyobaaaaan.slack.com"; # Your team's domain
my $opt_token = "SQUIGGLEWHATEVERTHINGS"; # The token from your Nagios services page

  • ここでinstructionsにはないのですが試し打ちしてみます。#channelnameはご自身のチャンネル名にあわせてください(なければ作ってください。たぶんprivateで)

/usr/local/bin/slack_nagios.pl -field slack_channel=#channelname -field HOSTALIAS="HOSTNAME" -field SERVICEDESC="SERVICEDESC" -field SERVICESTATE="SERVICESTATE" -field SERVICEOUTPUT="SERVICEOUTPUT" -field NOTIFICATIONTYPE="NOTIFICATIONTYPE"

  • だがしかしエラーが。こんなの。

501 Protocol scheme 'https' is not supported (LWP::Protocol::https not installed ...

yum install perl-Net-SSLeay
yum install perl-Crypt-SSLeay
yum install perl-IO-Socket-SSL

  • が、ダメ。なので同じページにあるcpanminusでLWP::Protocol::httpsをインストールしようとするも、cpanmがそもそもありませんでした。
  • cpanmのインストール。このページのとおりこう。

curl -L http://cpanmin.us | perl - --sudo App::cpanminus

  • が、エラー。こんなん。

Can't locate ExtUtils/Manifest.pm

  • perl-ExtUtils-Manifest をインストール。

このページを参考にこう。

sudo yum install perl-ExtUtils-Manifest

  • やっとLWP::Protocol::httpsをインストール

sudo cpanm LWP::Protocol::https

  • slack_nagios.plを試し打ち。

これでOkayならあとはnagiosの設定。というかinstructionsまんま。etc/objects/contacts.cfgに配信したいユーザー定義と配信コマンド名、そのコマンド名の定義をetc/objects/commands.cfgに記載して終了。

define contact {
contact_name slack
alias Slack
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,r
service_notification_commands notify-service-by-slack
host_notification_commands notify-host-by-slack
}
...
define contactgroup {
contactgroup_name admins
alias Nagios Administrators
members root,slack
} # 既存グループにメンバー追加

define command {
command_name notify-service-by-slack
command_line /usr/local/bin/slack_nagios.pl -field slack_channel=#channelname -field HOSTALIAS="$HOSTNAME$" -field SERVICEDESC="$SERVICEDESC$" -field SERVICESTATE="$SERVICESTATE$" -field SERVICEOUTPUT="$SERVICEOUTPUT$" -field NOTIFICATIONTYPE="$NOTIFICATIONTYPE$"
}

define command {
command_name notify-host-by-slack
command_line /usr/local/bin/slack_nagios.pl -field slack_channel=#channelname -field HOSTALIAS="$HOSTNAME$" -field HOSTSTATE="$HOSTSTATE$" -field HOSTOUTPUT="$HOSTOUTPUT$" -field NOTIFICATIONTYPE="$NOTIFICATIONTYPE$"
}

  • nagiosのconfigchekアンドrestart

service nagios checkconfig
service nagios restart

  • あとはnagiosのコンパネからテスト用(配信対象)のサービスに入り、[今すぐ通知する]からテストすればOkay。

メモを書くのすら長かった。。。