Nagios for system monitoring

since most of the users needed a system monitoring so putting forth a nagios setup for the easy monitoring of the tools.


$ sudo apt-get install -y gcc glibc glibc-common perl httpd php wget gd gd-devel
$ sudo apt-get install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils
$ systemctl start httpd 
$ systemctl enable httpd
   
# Installing the Nagios and adding a user to the Nagios
https://assets.nagios.com/downloads/nagioscore/versions.php

$ wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.8.tar.gz
   tar xzf nagioscore.tar.gz
   cd nagioscore-nagios-4.4.8/
$ ./configure
$ make all
$ make install-groups-users finishing the installation of the nagios with the defined user group. 
$ usermod -a -G nagios apache
$ make install
$ make install-daemoninit
$ htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin enabling the httpd
$ make install-commandmode		
$ make install-config			  
$ make install-webconf

# Check the configuration file 

cd /etc/apache2
apachectl configtest

# Installing the Nagios plugins:         

$ wget --no-check-certificate -O nagios-plugins.tar.gz https://github.com/nagios-plugins/nagios-plugins/releases/download/release-2.4.1/nagios-plugins-2.4.1.tar.gz 
$ tar zxf nagios-plugins.tar.gz
$ cd nagios-plugins-release-2.2.1/
$ ./tools/setup
$ ./configure
$ make
$ make install

# If you are downloading it from CPAN: https://metacpan.org/dist/Nagios-Monitoring-Plugin

$ perl -MCPAN -e shell
$ cpan install module
$ perl -MCPAN -e 'install Nagios::Monitoring::Plugin'
Nagios::Monitoring::Plugin	A family of perl modules to streamline writing Nagios plugins
Nagios::Monitoring::Plugin::Config	read nagios plugin .ini style config files
Nagios::Monitoring::Plugin::ExitResult	Helper class for returning both output and return codes when testing.
Nagios::Monitoring::Plugin::Functions	functions to simplify the creation of Nagios plugins
Nagios::Monitoring::Plugin::Getopt	OO perl module providing standardised argument processing for Nagios plugins
Nagios::Monitoring::Plugin::Performance	class for handling Nagios::Monitoring::Plugin performance data.
Nagios::Monitoring::Plugin::Range	class for handling Nagios::Monitoring::Plugin range data.
Nagios::Monitoring::Plugin::Threshold	class for handling Nagios::Monitoring::Plugin thresholds.

# Restarting the system and the nagios service

$ systemctl restart httpd.service
$ systemctl start nagios.service
$ start nagios service
$ nagios service status 

# Two ways to start firewall, either in the system enabled or the cloud enabled. 

$ firewall-cmd --permanent --zone=public --add-port=80/tcp
$ firewall-cmd --reload
or 

# google cloud enabled 

$gcloud compute --project=projectname firewall-rules create firewall-8080 --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:8080 --source-ranges=0.0.0.0/0

# Check the Nagios on http://localhost/nagios or http://externalip/nagios

alles super,
Gaurav

1 Like

It works also with nginx system. Not everyone is using an apache server so it could be also helpful trick for people using nginx.
You need to create the file:

sudo nano /etc/nginx/sites-available/nagios```
And then add following code:

server {
server_name nagios.your-domain.com;
root /usr/local/nagios/share;
listen 80;
index index.php index.html index.htm;
access_log /var/log/nginx/nagios.access.log;
error_log /var/log/nginx/nagios.error.log;
auth_basic “Nagios Access”;
auth_basic_user_file /usr/local/nagios/etc/htpasswd.users;

add_header X-Frame-Options "ALLOW";
location ~ \.php$ {
    try_files       $uri = 404;
    fastcgi_index   index.php;
    fastcgi_pass    unix:/run/php/php7.4-fpm.sock;
    include         fastcgi.conf;
}
location ~ \.cgi$ {
    root            /usr/local/nagios/sbin;
    rewrite         ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
    fastcgi_param   AUTH_USER $remote_user;
    fastcgi_param   REMOTE_USER $remote_user;
    include         fastcgi.conf;
    fastcgi_pass    unix:/run/fcgiwrap.socket;
}

location /nagios {
    alias /usr/local/nagios/share;
}

}

After that you do following command to make effective:

sudo ln -s /etc/nginx/sites-available/nagios /etc/nginx/sites-enabled/nagios
sudo systemctl reload nginx

1 Like