#!/bin/bash
mkdir /rpms && cd /rpms &&
echo "
 module nagios-socket 1.0;
 require {
 type nagios_t;
 type nagios_log_t;
 class sock_file { write create unlink };
 class unix_stream_socket connectto;
 }
 allow nagios_t nagios_log_t:sock_file { write create unlink };
 allow nagios_t self:unix_stream_socket connectto;"
>> /tmp/nagios-socket.te &&
yum install policycoreutils-python -y &&
cd /tmp;checkmodule -M -m -o nagios-socket.mod nagios-socket.te &&
semodule_package -o nagios-socket.pp -m nagios-socket.mod &&
semodule -i nagios-socket.pp &&
install -d -m 755 -o nagios -g nagios /usr/local/nagios/var/rw &&
install -d -m 744 -o nagios -g nagios /usr/local/nagios/var/spool/checkresults &&
systemctl restart nagios && systemctl status nagios &&
echo " #!/bin/bash
 install -d -m 744 -o nagios -g nagios /usr/local/nagios/var/spool/checkresults
 install -d -m 744 -o nagios -g nagios /usr/local/nagios/var/rw &&
 systemctl restart nagios && systemctl status nagios
" >> /etc/nagiosfixer.sh &&
echo "
/etc/nagiosfixer.sh
" >> /etc/rc.d/rc.local &&
chmod +x /etc/nagiosfixer.sh
echo "Script executed OK"
