Adding hosts and services to Nagios - Linux/BSD hosts

From Apoyar Wiki
Revision as of 08:57, 5 December 2022 by 152.57.149.69 (talk)
Jump to navigation Jump to search

Adding Unix/Linux host to Nagios



1. Connect to Nagios server (nagios.apoyar with neal username and apoyar.key)

  1. cd /usr/local/etc/nagios/objects/machines
  1. vi apoyar.cfg (depending on whether we are adding host for Apoyar or other customers)


2. We did for apoyar unix server hostname (test-Linux)


3. Copy the configuration format for linux server added before and e.dit the hostname and address for new host.


4. Add the host name in member list to recognize Nagios probe for checks


Save file (:wq!) and exit vi editor


Go to below path


• cd /usr/local/etc/nagios/objects


• vi services.cfg


5. Add the new hostname to the services, which we need for new server in Nagios, for those services, which we need to monitor.


6. Go to that particular service configuration and enter new server name manually


Save file (:wq!) and exit vi editor

Run below command on nagios server and check syntax errors with below command

/usr/local/bin/nagios -v /usr/local/etc/nagios/nagios.cfg


Note:

 Host machine should ping from Nagios server to confirm that servers are communicating each other.

 One more thing that it can be SSH to test-Linux server from Nagios server without password.


7. Connect from test-Linux server from Nagios server using Nagios user account with password.


8. If user account is existing in test-Linux server it will access else it will not (due to Nagios user account doesn’t exist)


9. Once configuration changes done on Nagios server, connect machine which you are adding to Nagios (test-Linux) server.


10. Need to create user name with home folder for user


  1. adduser nagios

Set password for nagios to access from Nagios server

  1. passwd nagios
  1. cd /home/nagios
  1. mkdir .ssh
  1. mkdir bin


11. After that need to change owner of those folder which is created by root.

  1. chown nagios:nagios .ssh/ -R
  1. chown nagios:nagios bin –R


12. Copy public key (authorized_keys) file from any existing working server to access server password authentication less.


13. Once key file copied into test-Linux server.


14. Need to install nagios packages on host machine


  1. dpkg –l | grep nagios # to check which packages to be installed

Monitoring-plugins

Nagios-plugins

Using below commands

  1. apt-get install nagios-plugins
  1. apt-get install monitoring-plugins


15.

So just will create soft links from actual installed folder to newly created bin folder on Nagios folder path.
  1. ln –s /usr/lib/nagios/plugins/check_load /home/nagios/bin/
  1. ln –s /usr/lib/nagios/plugins/check_users /home/nagios/bin/
  1. ln –s /usr/lib/nagios/plugins/check_uptime /home/nagios/bin/
  1. ln –s /usr/lib/nagios/plugins/check_disk /home/nagios/bin/
  1. ln –s /usr/lib/nagios/plugins/check_swap /home/nagios/bin/
  1. ln –s /usr/lib/nagios/plugins/check_procs /home/nagios/bin/


16. After that we need to copy some files from nagios server plugins folder path to hosted server into bin folder.

Connect nagios server

  1. su – nagios
  1. cd plugins
  1. scp check_debian_packages check_mem.pl check_uptime.sh test-Linux:/home/nagios/bin

Once all these done change Nagios user account password on test-Linux server which we don’t use future as well it is more secure with password generator.


17. It will start checking service checks. If you want to add more services for monitoring like, Nginx, php, disk io status.


18. Copy check files from nagios server to test-Linux server bin path like above.


  1. scp check_nginx_status.pl check_phpfpm_status.pl check_diskio.pl test-Linux:/home/nagios/bin


19. Once copied into test-Linux sevrer

Execute those files

  1. cd /home/nagios/bin
  1. ./check_nginx_status.pl # .pl extension means perl programing language
  1. ./check_phpfpm_status.pl
  1. ./check_diskio.pl # might be it will throw errors which is not installed supporting packages.

Error will be Array/unique.pm missing

  1. apt-cache search perl number::format # to find pm extension packages list search using the above command format.
  1. apr-cache search perl array::unique

It will list package names and install it that.

Similar way finds the missing packages and install it until there are no errors reported.

  1. apt-get install libarray-unique-perl
  1. ./check_diskio.pl # without any error message it has to execute.


20. If Host server is using multi cores we have to copy check_cpu.py file from nagios to test-linux server

  1. cd /home/nagios/bin/
  1. . /check_cpu.py # py extension means python packages


If the errors are reporting due to missing python packages install it.

  1. apt-get install python-psutil

Then it will be ok to monitor multiple cores which we did for Bleckmann MySQL which is having 32 cores.