Chef Recipe Nrpe Nagios

Embed Size (px)

DESCRIPTION

A chef recipe

Citation preview

## Cookbook Name:: nrpe# Recipe:: default## Copyright 2014, FLEXBET-SYSTEMS# version '0.10.0'# All rights reserved - Do Not Redistribute#******************************************************************************# # Recipe prerequisite-nrpe#execute "apt-get update" do command "apt-get update"end%w{build-essential apt-file openssl libssl-dev xinetd}.each do |pkg| package pkg do action :install endendcookbook_file "nagios-plugins-1.5.tar.gz" do path "/tmp/nagios-plugins-1.5.tar.gz"endexecute "tar -xzf /tmp/nagios-plugins-1.5.tar.gz" do cwd '/tmp' command "tar -xzf /tmp/nagios-plugins-1.5.tar.gz" action :runendcookbook_file "nrpe-2.14.tar.gz" do path "/tmp/nrpe-2.14.tar.gz"endexecute "tar2" do cwd '/tmp' command "tar -xzf /tmp/nrpe-2.14.tar.gz" action :runendexecute "useradd-nagios" do cwd '/tmp' command "/usr/sbin/useradd nagios -p nagios" action :runend#*******************************************************************************# Recipe configuration-nagios-plugins#execute "configuration" do cwd '/tmp/nagios-plugins-1.5' command "./configure" action :runendexecute "make" do cwd '/tmp/nagios-plugins-1.5' command "make" action :runendexecute "make-install" do cwd '/tmp/nagios-plugins-1.5' command "make install" action :runend#*********************************************************************************# Recipe configuration-nrpe#execute "configure" do cwd '/tmp/nrpe-2.14' command "./configure --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/x86_64-linux-gnu" action :runendexecute "make-all" do cwd '/tmp/nrpe-2.14' command "make all" action :runendexecute "make-install-plugin" do cwd '/tmp/nrpe-2.14' command "make install-plugin" action :runendexecute "make-install-daemon" do cwd '/tmp/nrpe-2.14' command "make install-daemon" action :runendexecute "make-install-daemon-config" do cwd '/tmp/nrpe-2.14' command "make install-daemon-config" action :runendexecute "make-install-xinetd" do cwd '/tmp/nrpe-2.14' command "make install-xinetd" action :runend#*********************************************************************************# Recipe flex-nrpe##***Modifier le fichier /etc/xinetd/nrpe***cookbook_file "nrpe" do path "/etc/xinetd.d/nrpe" owner "root" group "root" mode "0755" action :createend#***Modifier le fichier /etc/services***ruby_block "edit nrpe services" do block do file = Chef::Util::FileEdit.new("/etc/services") file.insert_line_if_no_match("nrpe", "nrpe 5666/tcp #NRPE") file.write_file endend#***Stop & Start le service xinetd***service 'xinetd' do action [ :stop, :start, :enable ]end#***Modifier le fichier /etc/hosts.allow***ruby_block "edit_hosts_allow" do block do file = Chef::Util::FileEdit.new("/etc/hosts.allow") file.insert_line_if_no_match("nrpe.d", "nrpe.d :10.12.2.40 :allow") file.insert_line_if_no_match("nagiosd", "nagiosd : 10.12.2.40 : allow") file.write_file endend#***Modifier IpTables et enregistrer les modifications***execute "change iptables" do cwd '/tmp' command "iptables -I INPUT -p tcp -m tcp --dport 5666 -j ACCEPT " action :runendexecute "save iptables" do command "iptables-save" action :runend#***Netstat le lien NRPE avec le serveur Nagios ***execute "netstat nrpe" do command "netstat -at | grep nrpe" action :runend