Raspberry Pi, Nagios and Nginx monitoring for

Warning : This article has been automatically translated by Bing Translate

After a series of articles on monitoring tools (Monitorix, Zabbix, RASP-control, RPi-Monitor), a new article on a known tool : Nagios.

hpsplash5b

If you are using apache, You can go through the repository with the command

apt - get install nagios3

But if you do not want to have a web server relatively heavy, and as I am a fan of Nginx, then you will need to follow these instructions :

  1. Update the system
     apt-get update && apt-get upgrade -y
  2. Install Nginx with PHP support as explained here.
  3. Install the tools for the installation of Nagios
    apt-get install libperl-dev libpng12-dev libgd2-xpm-dev build-essential php5-gd libgd2-xpm
  4. Download Nagios
    wget http://prdownloads.sourceforge.NET/SourceForge/Nagios/Nagios-4.0.2.tar.gz tar zxvf nagios - 4.0.2.tar.gz cd nagios - 4.0.2
  5. The installation will be in need of a user and a group Nagios
    adduser - system - no-create-home-disabled-login - group nagios usermod-a g nagios www - data

    It adds the Group Nagios secondary group to the user www - data

  6. It must also be a user and group for the launch of the commands
    Groupadd nagcmd usermod g nagcmd nagios usermod-a g nagcmd www - data

    It adds the Group nagcmd secondary group to the user www - data

  7. You can start the configuration
    ./configure--prefix/opt/nagios/nagios \
    --sysconfdir = / etc/nagios \
    --with-nagios-user=nagios \
    --with-nagios-group=nagios \
    --with-command-user=nagios \
    --with-command-group=nagcmd
  8. Start the compilation
    make all
  9. Installer les différents éléments, puis les fichiers de démarrage, de ligne de commande et de configuration
    make install make install-init && make install-commandmode && make install-config cp functions/etc/nagios.

    I copy the file functions required for the startup script in /etc/nagios. Moreover you must modify /etc/init.d/nagios replacing

    . /etc/rc.d/init.d/functions

    by

    . /etc/nagios/functions
  10. Install the configuration examples
    make install-config
  11. The use of Nginx requires to go through a python script to manage the passwords. The Google friend gave me multiple results but the only convincing :
    CD wget http://Trac.edgewall.org/export/10791/trunk/contrib/htpasswd.py

    The result :
    1__ssh_et_Nagios_on_nginx___Ubuntu_12_04___idevit_nlSo for our installation : user nagiosadmin (It is used in the default files), his password password (change of course !)

    Python htpasswd.py-c-b /etc/nagios/htpasswd.users admin password
  12. If you have a special email address, It is in the file /etc/Nagios/objects/contacts.cfg what it will take to change it.
  13. For your default logs that is defined in the file /etc/Nagios/Nagios.cfg. The value is /opt/Nagios/Nagios/var/Nagios.log. Practice problems.
  14. To verify that your configuration is correct :
    /opt/nagios/nagios/bin/nagios v /etc/nagios/nagios.cfg
  15. Installer FCGI
    apt-get install spawn-fcgi fcgiwrap
  16. Configurer nginx avec le fichier suivant :
    server {
    	listen   8080;
    	server_name nagios;
    
    	access_log /var/log/nginx/nagios.access.log;
    	error_log /var/log/nginx/nagios.error.log info;
    
    	root / opt/nagios/nagios/share;
    	index index.php index.html;
    
            auth_basic "Nagios restricted access";
            auth_basic_user_file /etc/nagios/htpasswd.users;
    
    	location / stylesheets {
    		alias / opt/nagios/nagios/share/stylesheets;
    	}
    
    	location / nagios/js {
                    alias / opt/nagios/nagios/share/js;
    	}
    
    	location/nagios/stylesheets {
                    alias / opt/nagios/nagios/share/stylesheets;
            }
    
    	rewrite ^ / nagios/images /.(.*)$ /images / $1 break;
    
            rental ~ .cgi$ {
                    root/opt/nagios/nagios/sbin;
    
    		rewrite ^ / cgi-bin/nagios3 /.(.*)$ /$1;
    		rewrite ^ / nagios/cgi-bin /.(.*)$ /$1;
    
     		include/etc/nginx/fastcgi_params;
    
    		fastcgi_param AUTH_USER $remote_user;
                    fastcgi_param REMOTE_USER $remote_user;
                    fastcgi_param SCRIPT_FILENAME/opt/nagios/nagios/sbin$ fastcgi_script_name;
    
    		fastcgi_pass unix:/var/run/fcgiwrap.Socket;
            }
    
    	location ~ .php$ {
                    include/etc/nginx/fastcgi_params;
                    fastcgi_pass unix:/var/run/PHP5-fpm.sock;
            }
    }
  17. Enable configuration
    ln-s/etc/nginx/sites-available/nagios/etc/nginx/sites-enabled/nagios
  18. Restart Nginx
    service nginx restart

Here you are with your Nagios online ! Appointment with your browser to the port of your configuration. You will need to enter the login nagiosadmin and password you used during the installation :

Nagios_Core

Bonne surveillance 🙂

Like this article ? Bear with me on patreon!

You may also like...