os-init/debian-11/apps/nagios-pnp4/nagios-pnp4.sh
2023-11-19 23:04:42 +01:00

110 lines
5.6 KiB
Bash

#!/bin/bash
apt -y install rrdtool librrds-perl php-gd php-xml gcc make
cd
wget -O pnp4nagios.tar.gz https://github.com/lingej/pnp4nagios/archive/refs/tags/0.6.26.tar.gz
tar xzf pnp4nagios.tar.gz
cd pnp4nagios-0.*
./configure
make all
make install
make install-webconf
make install-config
make install-init
cd
cat > /etc/apache2/sites-available/pnp4nagios.conf << EOF
Alias /pnp4nagios "/usr/local/pnp4nagios/share"
<Directory "/usr/local/pnp4nagios/share">
AllowOverride None
Order allow,deny
Allow from all
AuthDigestDomain "Nagios4"
AuthDigestProvider file
AuthUserFile "/etc/nagios4/htdigest.users"
AuthGroupFile "/etc/group"
AuthName "Nagios4"
AuthType Digest
Require valid-user
<IfModule mod_rewrite.c>
RewriteEngine On
Options symLinksIfOwnerMatch
RewriteBase /pnp4nagios/
RewriteRule "^(?:application|modules|system)/" - [F]
RewriteCond "%{REQUEST_FILENAME}" !-f
RewriteCond "%{REQUEST_FILENAME}" !-d
RewriteRule "^.*$" "index.php/\$0" [PT]
</IfModule>
</Directory>
EOF
systemctl daemon-reload
systemctl enable npcd
systemctl start npcd
systemctl reload apache2
a2ensite pnp4nagios.conf
systemctl restart apache2
sed -i 's/process_performance_data=0/process_performance_data=1/g' /etc/nagios4/nagios.cfg
sed -i 's/#host_perfdata_file=/host_perfdata_file=/g' /etc/nagios4/nagios.cfg
sed -i 's/^host_perfdata_file=.*/host_perfdata_file=\/usr\/local\/pnp4nagios\/var\/service-perfdata/g' /etc/nagios4/nagios.cfg
sed -i 's/^#host_perfdata_file_template=.*/host_perfdata_file_template=DATATYPE::HOSTPERFDATA\\tTIMET::$TIMET$\\tHOSTNAME::$HOSTNAME$\\tHOSTPERFDATA::$HOSTPERFDATA$\\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\\tHOSTSTATE::$HOSTSTATE$\\tHOSTSTATETYPE::$HOSTSTATETYPE$/g' /etc/nagios4/nagios.cfg
sed -i 's/#host_perfdata_file_mode=/host_perfdata_file_mode=/g' /etc/nagios4/nagios.cfg
sed -i 's/^#host_perfdata_file_processing_interval=.*/host_perfdata_file_processing_interval=15/g' /etc/nagios4/nagios.cfg
sed -i 's/^#host_perfdata_file_processing_command=.*/host_perfdata_file_processing_command=process-host-perfdata-file-bulk-npcd/g' /etc/nagios4/nagios.cfg
sed -i 's/#service_perfdata_file=/service_perfdata_file=/g' /etc/nagios4/nagios.cfg
sed -i 's/^service_perfdata_file=.*/service_perfdata_file=\/usr\/local\/pnp4nagios\/var\/service-perfdata/g' /etc/nagios4/nagios.cfg
sed -i 's/^#service_perfdata_file_template=.*/service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\\tTIMET::$TIMET$\\tHOSTNAME::$HOSTNAME$\\tSERVICEDESC::$SERVICEDESC$\\tSERVICEPERFDATA::$SERVICEPERFDATA$\\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\\tHOSTSTATE::$HOSTSTATE$\\tHOSTSTATETYPE::$HOSTSTATETYPE$\\tSERVICESTATE::$SERVICESTATE$\\tSERVICESTATETYPE::$SERVICESTATETYPE$/g' /etc/nagios4/nagios.cfg
sed -i 's/#service_perfdata_file_mode=/service_perfdata_file_mode=/g' /etc/nagios4/nagios.cfg
sed -i 's/^#service_perfdata_file_processing_interval=.*/service_perfdata_file_processing_interval=15/g' /etc/nagios4/nagios.cfg
sed -i 's/^#service_perfdata_file_processing_command=.*/service_perfdata_file_processing_command=process-service-perfdata-file-bulk-npcd/g' /etc/nagios4/nagios.cfg
echo '' >> /etc/nagios4/objects/commands.cfg
echo 'define command {' >> /etc/nagios4/objects/commands.cfg
echo ' command_name process-host-perfdata-file-bulk-npcd' >> /etc/nagios4/objects/commands.cfg
echo ' command_line /bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$' >> /etc/nagios4/objects/commands.cfg
echo ' }' >> /etc/nagios4/objects/commands.cfg
echo '' >> /etc/nagios4/objects/commands.cfg
echo 'define command {' >> /etc/nagios4/objects/commands.cfg
echo ' command_name process-service-perfdata-file-bulk-npcd' >> /etc/nagios4/objects/commands.cfg
echo ' command_line /bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$' >> /etc/nagios4/objects/commands.cfg
echo ' }' >> /etc/nagios4/objects/commands.cfg
echo '' >> /etc/nagios4/objects/commands.cfg
rm -f /usr/local/pnp4nagios/share/install.php
echo '' >> /etc/nagios4/objects/templates.cfg
echo 'define host {' >> /etc/nagios4/objects/templates.cfg
echo ' name host-pnp' >> /etc/nagios4/objects/templates.cfg
echo ' action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_' >> /etc/nagios4/objects/templates.cfg
echo ' register 0' >> /etc/nagios4/objects/templates.cfg
echo '}' >> /etc/nagios4/objects/templates.cfg
echo '' >> /etc/nagios4/objects/templates.cfg
echo 'define service {' >> /etc/nagios4/objects/templates.cfg
echo ' name service-pnp' >> /etc/nagios4/objects/templates.cfg
echo ' action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' >> /etc/nagios4/objects/templates.cfg
echo ' register 0' >> /etc/nagios4/objects/templates.cfg
echo '}' >> /etc/nagios4/objects/templates.cfg
echo '' >> /etc/nagios4/objects/templates.cfg
sed -i '/name.*generic-host/a\ use host-pnp' /etc/nagios4/objects/templates.cfg
sed -i '/name.*generic-service/a\ use service-pnp' /etc/nagios4/objects/templates.cfg
# Patch 1
wget https://patch-diff.githubusercontent.com/raw/lingej/pnp4nagios/pull/168.diff
wget https://patch-diff.githubusercontent.com/raw/lingej/pnp4nagios/pull/169.diff
patch /usr/local/pnp4nagios/lib/kohana/system/libraries/Input.php 168.diff
patch /usr/local/pnp4nagios/lib/kohana/system/libraries/Input.php 169.diff
rm 168.diff
rm 169.diff
# Patch 2
sed -i 's/if(sizeof($pages) > 0 ){/if(is_array($pages)\&\&sizeof($pages) > 0){/' /usr/local/pnp4nagios/share/application/models/data.php
systemctl restart apache2
systemctl restart nagios4