Setting up Nagios Core

nagios core install | nagios core | nagios plugins | nagios ssh

tested on debian12

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

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