Setting up Nagios Core

nagios core | nagios plugins | nagios ssh

tested on debian12

Requirements

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

Sysprep

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

Install

no need to change ownerships, let install-config handle it more precisely

mkdir /etc/nagios/
mkdir /var/nagios/

grab the latest Core release

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

Setup

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

Web setup

see nginx core nginx

Ready to go

tail -F /var/log/syslog

systemctl status nagios
systemctl restart nagios
pgrep -a nagios

systemctl enable nagios

Operations

systemctl reload nagios

Troubleshooting

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

Resources

install

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://exchange.nagios.org/directory/Documentation/Nagios-Core-Documentation/Nagios-core-installation-guide-for-RED-HAT-and-CentOS-Systems/details

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/

install troubles

https://computingforgeeks.com/install-php-mcrypt-extension-on-ubuntu/

https://askubuntu.com/questions/1031921/php-mcrypt-package-missing-in-ubuntu-server-18-04-lts

syntax

https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/config.html

https://geekpeek.net/nagios-configuration/

setup

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

email settings

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://access.redhat.com/documentation/en-us/red_hat_gluster_storage/3/html/console_administration_guide/configuring_nagios_to_send_mail_notifications

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

flapping

https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/flapping.html

https://support.nagios.com/kb/article.php?id=378

moar

https://subscription.packtpub.com/book/application_development/9781783288649/12/ch12lvl1sec77/introducing-nagios-event-radio-dispatcher


HOME | GUIDES | LECTURES | LAB | SMTP HEALTH | HTML5 | CONTACT
Copyright © 2024 Pierre-Philipp Braun