おはよう仲間
リモートシステムを扱うすべての人と同様に、私はそれらの多くのマシンとサービスを監視する必要がありました。 いくつかのプログラムの説明とマニュアルをスクロールして、彼はNagiosに立ち寄った。 それに関する多くの記事と例と非常に豊富なセットアップがあなたが必要とするものであることが判明しました。 それで、clickatell.comを使用して、Bashで書かれた自己記述プラグインとSMSアラートシステムの実装と構成のいくつかのポイントを共有することにしました。
clickatell.comを選ぶ理由 はい、組織で既に使用されているだけですが、このアクションにも使用することにしました。
nagiosの設定方法には多くの記事がありますが、これに焦点を当てることはせず、私が学んだこととその仕組みの説明にまっすぐ進みます。
メッセージ送信サービス
clickatell.com自体のAPIを見ると、そこにすべてがどのように実装されているかが非常に明確になり、理解しました。
bashコードを送信するSMS
#!/ bin / bash
text1 = $ 1
nombertel = 2ドル
wget --post-data "api_id = 111111&user = User1&password = pass1" api.clickatell.com/http/auth --quiet -O-> / tmp / sms_tmp_id
session_id = $(cut -f2 -d "" / tmp / sms_tmp_id)
wget --post-data "session_id = $ session_id&to = $ nombertel&text = $ text1 " api.clickatell.com/http/sendmsg --quiet -O-rm / tmp / sms_tmp_id
出口0
text1 = $ 1
nombertel = 2ドル
wget --post-data "api_id = 111111&user = User1&password = pass1" api.clickatell.com/http/auth --quiet -O-> / tmp / sms_tmp_id
session_id = $(cut -f2 -d "" / tmp / sms_tmp_id)
wget --post-data "session_id = $ session_id&to = $ nombertel&text = $ text1 " api.clickatell.com/http/sendmsg --quiet -O-rm / tmp / sms_tmp_id
出口0
最初のwget --post-dataは、セッションIDを生成するためにデータを送信します。これは、api_idで構成されます。これは、SMSを送信するときに使用されるサービスID、userはログインユーザー名clickatell.com、passwordはパスワードです。 Clickatell.comにはsession_idのAPiチェックがありますが、単純に新しいものを生成するという単純な方法で行っています。 残念ながら、clickatell.com APIは、サイトに登録した後にのみ表示できます。
2番目のwget --post-dataでは、指定された番号にすでにテキストを送信しています。 session_idは、メッセージの送信先の電話番号とメッセージのテキストテキストに対するセッション識別子です。 検証により、すべてが機能することが示されましたが、もちろんありますが、これは最大70文字のメッセージ長です。 したがって、メーリングリストサービスとは異なり、最も重要なもののみを送信します。
nagiosからのメッセージの送信を担当するサービス自体は次のとおりです(一方は他方のサービスのホストを担当します)
nagios sms-host、sms-services
定義コマンド{
command_name sms-host
command_line /usr/bin/sms_get_number.sh "** $ NOTIFICATIONTYPE $ホストアラート:$ HOSTNAME $は$ HOSTSTATE $ **" $ CONTACTADDRESS1 $
}
定義コマンド{
command_name sms-services
command_line /usr/bin/sms_get_number.sh "$ SERVICEDESC $ホスト:$ HOSTALIAS $ $ SERVICEOUTPUT $" $ CONTACTADDRESS1 $
}
command_name sms-host
command_line /usr/bin/sms_get_number.sh "** $ NOTIFICATIONTYPE $ホストアラート:$ HOSTNAME $は$ HOSTSTATE $ **" $ CONTACTADDRESS1 $
}
定義コマンド{
command_name sms-services
command_line /usr/bin/sms_get_number.sh "$ SERVICEDESC $ホスト:$ HOSTALIAS $ $ SERVICEOUTPUT $" $ CONTACTADDRESS1 $
}
そして、これは通知を受信するユーザー設定です
nagios contact_name SMS
連絡先の定義{
contact_name mobile
エイリアスモバイル
service_notification_period noworktime
host_notification_period noworktime
service_notification_options w、u、c
host_notification_options d
service_notification_commands sms-services#上記のサービス名
host_notification_commands sms-host#上記のサービス名
address1 +79111111111
}
contact_name mobile
エイリアスモバイル
service_notification_period noworktime
host_notification_period noworktime
service_notification_options w、u、c
host_notification_options d
service_notification_commands sms-services#上記のサービス名
host_notification_commands sms-host#上記のサービス名
address1 +79111111111
}
この設定では、noworktimeと呼ばれる期間中にサービスとホストの落下に関する通知を受け取ります。
はい。noworktimeconfigに興味がある人は、非稼働時間と休みになります。そのため、営業日にはすべてがメールに送られるため、電話がメッセージを再びブロックすることはありません。
ナギオス期間
期間を定義する{
timeperiod_ noworktime
エイリアスなし作業領域SPB
日曜日00:00-24:00
月曜日00:00-05:30,14:30-24:00
火曜日00:00-05:30.14:30-24-24
水曜日00:00-05:30,14:30-24:00
木曜日00:00-05:30.14:30-24:00
金曜日00:00-05:30.14:30-24-24
土曜日00:00-24:00
}
#サーバー上の時間は、この数値から数時間ずらされます。
timeperiod_ noworktime
エイリアスなし作業領域SPB
日曜日00:00-24:00
月曜日00:00-05:30,14:30-24:00
火曜日00:00-05:30.14:30-24-24
水曜日00:00-05:30,14:30-24:00
木曜日00:00-05:30.14:30-24:00
金曜日00:00-05:30.14:30-24-24
土曜日00:00-24:00
}
#サーバー上の時間は、この数値から数時間ずらされます。
そして、はい、私はほとんど忘れていました。 また、特定のリソースからエラーを送信するスクリプトをパブリックディスプレイにスローしたかったのです。
Webサイトエラー監視サービス
このようなサービスは、サイトの崩壊に伴う状況に迅速に対応するために必要でした。 nagiosにはWebサーバー診断サービスがありますが、サーバー全体を診断し、エラーコードを返さないため、私には適していません。 また、1つのサーバーには多くのリソースが存在する可能性があるため、独自のリソースを作成します。
一般的に、これはWebリソース診断スクリプト自体です/usr/bin/check_http_error.sh
特定のサイトの構成(IPアドレスだけで可能)
スクリプトチェックhttp
#!/ bin / bash
site1 = 1ドル
exitservice = 3
WGET = `wget $ site1 -O / tmp / check_site_error 2> / tmp / error_service.tmp`
[$? -ne 0]
それから
outmes = `grep -o“ ERROR。*” / tmp / error_service.tmp`
echo "$ outmes $ site1"
exitservice = 2
他に
outmes = "OK $ site1"
エコー$ outmes
exitservice = 0
fi
rm /tmp/error_service.tmp
rm / tmp / check_site_error
exit $ exitservice
#!/ bin / bash
site1 = 1ドル
exitservice = 3
WGET = `wget $ site1 -O / tmp / check_site_error 2> / tmp / error_service.tmp`
[$? -ne 0]
それから
outmes = `grep -o“ ERROR。*” / tmp / error_service.tmp`
echo "$ outmes $ site1"
exitservice = 2
他に
outmes = "OK $ site1"
エコー$ outmes
exitservice = 0
fi
rm /tmp/error_service.tmp
rm / tmp / check_site_error
exit $ exitservice
そして、これはスクリプト/usr/bin/check_http_error.shを使用したnagios設定です
nagiosチェックhttp
定義コマンド{
command_name check_site
command_line /usr/bin/check_http_error.sh $ ARG1 $
}
command_name check_site
command_line /usr/bin/check_http_error.sh $ ARG1 $
}
はい、ここにサービス自体の説明があります。
残念ながら、各サービスはその特異性のため個別に説明する必要があり、localhostに入力します。
ナギオスサービス
サービスの定義{
名前check_site
基本サービスを使用する
service_description check_site
check_command check_site!http://mai.ru
host_name localhost
}
名前check_site
基本サービスを使用する
service_description check_site
check_command check_site!http://mai.ru
host_name localhost
}
まあ、一般に、それですべてです。サイトに問題がある場合は、エラーコードとそのリソースを受け取ります。 DDoS攻撃と侵入を判断するのにタイムリーに役立ちます。
もちろん、興味があれば、snmpを使用して空き容量をパーセンテージで決定するnagiosのサービスに関する記事を公開することもできます。
私はすべてを持っています、あなたの注意をありがとう。