nagios core | nagios plugins | nagios ssh
tested on debian12
that libgd-dev sometimes conflicts so let’s install it first
apt install libgd-dev libjpeg-dev libpng-dev # libpnglite-dev
we are trying NOT to install apache (got NGINX already)
#apt install apache2 php php-gd php-imap php-curl libapache2-mod-php # php-mcrypt apt install libxml-libxml-perl libnet-snmp-perl libperl-dev libnumber-format-perl libconfig-inifiles-perl libdatetime-perl libnet-dns-perl
groupadd -g 517 nagios useradd -u 517 -g nagios --system -s /sbin/nologin -d /var/nagios nagios groupadd -g 518 nagios-cmd useradd -u 518 -g nagios-cmd --system -s /sbin/nologin -d /var/nagios nagios-cmd
there is a setgid in da place, we need either the same group, or enable that
usermod -aG nagios-cmd nagios
no need to change ownerships, let install-config handle it more precisely
mkdir /etc/nagios/ mkdir /var/nagios/
ver=4.4.13 wget https://github.com/NagiosEnterprises/nagioscore/archive/refs/tags/nagios-$ver.tar.gz tar xzf nagios-$ver.tar.gz cd nagioscore-nagios-$ver/ # otherwise goes to /usr/local/nagios/ ./configure --prefix=/usr/local \ --sysconfdir=/etc/nagios --localstatedir=/var/nagios \ --with-gd-lib --with-gd-inc \ --with-nagios-user=nagios --with-nagios-group=nagios \ --with-command-user=nagios-cmd --with-command-group=nagios-cmd \ --without-httpd-conf \ --with-mail=/usr/sbin/sendmail #--with-httpd-conf=/etc/apache2/sites-enabled \ # CHECK THERE WAS NO LARGE WARNING ABOUT GD echo $MAKEFLAGS make all make install make install-init make install-commandmode make install-config
check
/usr/local/nagios/bin/nagios -v
cd /etc/nagios/ cp -pi contacts.cfg contacts.cfg.dist vi contacts.cfg email YOUR@EMAIL mv -i nagios.cfg nagios.cfg.dist grep -vE '^#|^$' nagios.cfg.dist > nagios.cfg.clean grep -vE '^#|^$' nagios.cfg.dist > nagios.cfg vi nagios.cfg #cfg_file=/etc/nagios/objects/localhost.cfg cfg_dir=/etc/nagios/servers use_syslog=0 retained_host_attribute_mask=24 retained_service_attribute_mask=24 enable_flap_detection=0 use_regexp_matching=1 admin_email=YOUR@EMAIL admin_pager=YOUR@EMAIL mv -i cgi.cfg cgi.cfg.dist grep -vE '^#|^$' cgi.cfg.dist > cgi.cfg.clean grep -vE '^#|^$' cgi.cfg.dist > cgi.cfg vi cgi.cfg url_html_path=/ show_context_help=1
and put some custom configurations in there
mkdir servers/
use mailx instead of sendmail
vi commands-local.cfg define command { command_name notify-host-by-email command_line ... | mailx -s "$HOSTNAME$ is $HOSTSTATE$" $CONTACTEMAIL$ } define command { command_name notify-service-by-email command_line ... | mailx -s "$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$" $CONTACTEMAIL$ }
tweak a few remote checks
vi commands-remote.cfg define command { command_name check_ssh_2222 command_line $USER1$/check_ssh -p 2222 $ARG1$ $HOSTADDRESS$ }
enable remote checks through ssh
vi commands-ssh.cfg define command { command_name check_ssh_load command_line $USER1$/check_by_ssh -H $HOSTADDRESS$ -C "/usr/libexec/nagios/check_load -w $ARG1$ -c $ARG2$" } define command { command_name check_ssh_sensors command_line $USER1$/check_by_ssh -H $HOSTADDRESS$ -C "/usr/libexec/nagios/check_sensors" } define command { command_name check_ssh_temp command_line $USER1$/check_by_ssh -H $HOSTADDRESS$ -C "/usr/local/libexec/check_temp.ksh" }
define your hosts and host groups
vi hostgroups.cfg vi hosts.cfg
move local services up there (based on localhost.cfg)
vi services-local.cfg Root Partition Current Users Total Processes Current Load Swap Usage
move remote services up there (based on localhost.cfg)
vi services-remote.cfg PING SSH HTTP
enable remote ssh service checks
define service { use local-service hostgroup_name pmr service_description Current Load check_command check_ssh_load!5.0,4.0,3.0!10.0,6.0,4.0 } define service { use local-service hostgroup_name pmr service_description check_sensors check_command check_ssh_sensors notifications_enabled 1 } define service { use local-service hostgroup_name pmr service_description check_temp.ksh check_command check_ssh_temp notifications_enabled 1 }
check
/usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg
see nginx core nginx
tail -F /var/log/syslog systemctl status nagios systemctl restart nagios pgrep -a nagios systemctl enable nagios
systemctl reload nagios
Unable to write to check_result_path ('/var/nagios/spool/checkresults') - Permission denied Failed to init socket '/var/nagios/rw/nagios.qh'. bind() failed: Permission denied
==> nagios and nagios-cmd users belong to the same group and those folders are setgid
"PHP message: PHP Warning: Undefined array key "REMOTE_USER"
==> add that fastcgi_param
https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/quickstart.html
https://support.nagios.com/kb/article/nagios-core-installing-nagios-core-from-source-96.html#Debian
https://www.howtoforge.com/tutorial/how-to-install-nagios-on-ubuntu-2004/
https://linuxhint.com/install_nagios_ubuntu/
https://linuxize.com/post/how-to-install-nagios-on-ubuntu-20-04/ ==> htdigest
https://www.centlinux.com/2021/04/install-nagios-core-on-ubuntu-lts.html
https://kifarunix.com/install-and-setup-nagios-core-on-ubuntu-20-04/
https://www.scaleway.com/en/docs/tutorials/configure-nagios-monitoring/
https://computingforgeeks.com/install-php-mcrypt-extension-on-ubuntu/
https://askubuntu.com/questions/1031921/php-mcrypt-package-missing-in-ubuntu-server-18-04-lts
https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/config.html
https://geekpeek.net/nagios-configuration/
https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/configmain.html
https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/objecttricks.html
https://www.tothenew.com/blog/tips-for-configuring-nagios-wildcards-and-cfg-dir/
https://serverfault.com/questions/720144/wildcards-in-nagios-hostgroup-name-exclusions
Regular expression to exclude host in hostgroup members https://support.nagios.com/forum/viewtopic.php?t=58218
https://community.unix.com/t/using-mailx-to-send-emails-on-nagios-core/383284
https://stackoverflow.com/questions/25005177/sending-email-notifications-from-nagios-postfix
https://serverfault.com/questions/73004/defining-the-email-address-which-nagios-sends-emails-from
https://stackoverflow.com/questions/29642924/postfix-sendmail4825-fatal-usage-sendmail-options
https://askubuntu.com/questions/184251/why-cant-the-nagios-user-send-mails-using-sendmail
https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/flapping.html
https://support.nagios.com/kb/article.php?id=378