Created
November 13, 2013 08:29
-
-
Save gomasaba/7445611 to your computer and use it in GitHub Desktop.
fabricでnrpeをインストールのメモ
fab client_update -H ipアドレス --port=ポート -u ユーザー -i 鍵
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import os | |
from fabric.api import * | |
from fabric.contrib.files import * | |
######################################## | |
# クライアントにnrpeをインストール | |
######################################## | |
def client_setup(): | |
with settings( | |
hide('warnings', 'running'), | |
warn_only=True | |
): | |
if run("rpm -qa | grep openssl").return_code != 0: | |
if confirm("install openssl openssl-devel?", default=False) == True: | |
sudo("yum -y install openssl openssl-devel", pty=True) | |
# nagiosグループ追加 | |
if run("cat /etc/group | grep nagios").return_code != 0: | |
sudo("groupadd nagios") | |
# nagiosユーザー追加 | |
if run("cat /etc/passwd | grep nagios").return_code != 0: | |
sudo("useradd -d /usr/local/nagios -g nagios -m nagios") | |
sudo("chmod 755 /usr/local/nagios") | |
# nrpeコマンド追加 | |
if not exists("/usr/local/nagios/bin/nrpe",True): | |
if not exists("nrpe-2.13.tar.gz"): | |
put('./src/nrpe-2.13.tar.gz', './nrpe-2.13.tar.gz') | |
run('tar -zxvf nrpe-2.13.tar.gz') | |
with cd('nrpe-2.13'): | |
run('pwd') | |
run('./configure') | |
run('make') | |
sudo('make install') | |
# 設定ファイルのコピー | |
if not exists("/usr/local/nagios/etc",True): | |
sudo('mkdir /usr/local/nagios/etc') | |
sudo('cp -a sample-config/nrpe.cfg /usr/local/nagios/etc/') | |
sudo('chown nagios.nagios /usr/local/nagios/etc/nrpe.cfg') | |
sudo('cp init-script /etc/init.d/nrpe') | |
sudo('chmod 755 /etc/init.d/nrpe') | |
# サービスの登録と確認 | |
sudo('chkconfig --add nrpe') | |
sudo('chkconfig --list nrpe') | |
# 許可するホストIPの設定 | |
sudo('sed -i -e "s/allowed_hosts=127.0.0.1/allowed_hosts=127.0.0.1,202.133.113.138,49.212.200.107/g" /usr/local/nagios/etc/nrpe.cfg') | |
# プラグインの追加 | |
if not exists("nagios-plugins-1.5.tar.gz"): | |
put('./src/nagios-plugins-1.5.tar.gz', './nagios-plugins-1.5.tar.gz') | |
run('tar -zxvf nagios-plugins-1.5.tar.gz') | |
with cd('nagios-plugins-1.5'): | |
run('pwd') | |
run('./configure') | |
run('make') | |
sudo('make install') | |
# 起動 | |
if not exists('/var/run/nrpe.pid',True): | |
sudo('/etc/init.d/nrpe start') | |
# サービス登録 | |
if run("cat /etc/services | grep nrpe").return_code != 0: | |
append('/etc/services','nrpe 5666/tcp',True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment