Showing posts with label nagios core. Show all posts
Showing posts with label nagios core. Show all posts

Wednesday, October 21, 2020

Install PNP4Nagios for adding a graph to Nagios




Nagios offers monitoring and alerting services for your business infrastructures like servers, switches, applications and services. Adding a graph to Nagios is necessary for effective monitoring especially to predict possible attacks on your servers. PNP4Nagios is a plugin for Nagios for creating graphs.

Click here to learn how to install Nagios Core.

Step 1: Install all required package

yum install rrdtool perl-Time-HiRes rrdtool-perl php-gd -y

Step 2: Download the source and extract 

cd /tmp

wget https://sourceforge.net/projects/pnp4nagios/files/latest/download/pnp4nagios-0.6.26.tar.gz

tar zxfv pnp4nagios-0.6.26.tar.gz

Step 3: Compile and Install 

cd pnp4nagios-0.6.26

./configure

make all

make fullinstall

Step 4: Setup the NPCD

Change config to run npcd only on level 3 and 5. Change also the install.php filename.

chkconfig --add npcd && chkconfig --level 35 npcd on 

service httpd reload

Check the URL http: // server / pnp4nagios / to make sure pnp4nagios has been installed. If all green and pass then proceed.

Backup install.php

mv /usr/local/pnp4nagios/share/install.php /usr/local/pnp4nagios/share/install.php-ori

Step 5: Edit nagios.cfg, and add this at the bottom of the file 

vi /usr/local/nagios/etc/nagios.cfg

[Esc]+ GA – to edit the bottom of the file

# Bulk / NPCD mode 

process_performance_data=1 

service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata 

service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECH$ 

service_perfdata_file_mode=a 

service_perfdata_file_processing_interval=15 

service_perfdata_file_processing_command=process-service-perfdata-file


host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata 

host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$ host_perfdata_file_mode=a 

host_perfdata_file_processing_interval=15 

host_perfdata_file_processing_command=process-host-perfdata-file

[Esc] :wq

Step 6: Edit commands.cfg

vi /usr/local/nagios/etc/objects/commands.cfg

[Esc]+ GA

define command{ 

command_name process-service-perfdata-file 

command_line /bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$ 

}


define command{ 

command_name process-host-perfdata-file 

command_line /bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$ 

}

Step 7: Edit templates.cfg and add host-pnp & srv-pnp

vi /usr/local/nagios/etc/objects/templates.cfg

define host { 

name host-pnp 

action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_ 

register 0 

}

define service { 

name srv-pnp 

action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$ 

register 0 

}

Put the host-pnp on every host like this:

define host{

        use                     linux-server,host-pnp

        host_name               localhost

        alias                   localhost

        address                 127.0.0.1

        }

Put the srv-pnp on every service like this:

define service{

        use                             local-service,srv-pnp         

        host_name                       localhost

        service_description             PING

        check_command check_ping!100.0,20%!500.0,60%

}

Step 8: Copy the status-header and restart services

Copy this file in the /usr/local/nagios/share/ssi/ for mouseover graph

cp contrib/ssi/status-header.ssi /usr/local/nagios/share/ssi/

Then restart npcd,httpd and nagios

service npcd restart

service httpd restart

service nagios restart 


 

Saturday, October 17, 2020

Configure Email Alert for Nagios

Nagios is an open-source software that can help you monitor your infrastructure 24/7. It has a function that will notify you whenever there's a problem on your servers, switches, applications or services. By sending an email with the information you need to fix the problem.

Click here if you want to know how to install Nagios.

Step 1: Configure contacts.cfg

Edit the contacts.cfg, if the other variables already set just add the others not included.

vi /usr/local/nagios/etc/objects/contacts.cfg

define contact {

Contact_name nagiosadmin

Use generic-contact

Alias Admin

Email admin@localhost.com ←- change to     desired email address

service_notification_period 24x7

host_notification_period 24x7

service_notification_options w,u,c,r,s,f

host_notification_options d,u,r,f,s

service_notification_commands notify-service-by-email

host_notification_commands notify-host-by-email

}

[Esc] :wq

Verify if there's no error.

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

 Step 2: Install dependencies

Install postfix & mailx

yum install –y postfix mailx

alternatives --set mta /usr/sbin/postfix

If above command not work and you get the output as “/usr/sbin/postfix has not been configured as an alternative for mta“. Use below command. 

alternatives --set mta /usr/sbin/sendmail.postfix

Configure Postfix uncomment and edit

 vi /etc/postfix/main.cf

relayhost = [smtp.gmail.com]:587

smtp_use_tls=yes

smtp_sasl_auth_enable = yes

smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

smtp_sasl_security_options = noanonymous

smtp_sasl_mechanism_filter = plain

smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt

[Esc] :wq

Step 3: Get a unique pass

 Get the unique pass from google

Step 1: Sign in first to the google account you will use.

Step 2: Go to the google account, click your profile and click Google Account

Step 3: Go to Security tab

Step 4: In the “Signing in to Google” make sure the 2 step verification is On if not just click it and wait for the text message of google to turn on the 2 step verification.

Step 5: After you set the 2-step verification click on the app password and request for it

Step 6: Select mail then select the device to receive the unique app pass from google

Step 4: Configure sasl_passwd

vi /etc/postfix/sasl_passwd

[smtp.gmail.com]:587    <your_email_address@gmail.com>:<unique_app_pass_from_google>

[Esc] :wq

postmap /etc/postfix/sasl_passwd

 Step 5: Configure master.cf

vi /etc/postfix/master.cf

Change:

smtp      inet  n       -       n       -       -       smtpd

Into:

587      inet  n       -       n       -       -       smtpd

[Esc] :wq

Step 6: Install mail fonts and start postfix

Install this for the mail font

yum -y install cyrus-sasl cyrus-sasl-plain

service postfix restart

chkconfig postfix on

Step 7: Test to send mail

Test if the mail is sending then check the mail logs.

echo "Test mail from postfix" | mail -s "Test Postfix" <your_email_address>@gmail.com

tail /var/log/maillog

Configure sound alert for Nagios Core

In this tutorial you will learn about adding sound alert to Nagios Core. Nagios is a monitoring system that can help you to predict problems on your servers, switches, applications and services.

Step 1: Install dependencies

Install required packages.

yum install alsa alsa-base alsa-utils -y

Step 2: Configure commands.cfg

Edit the commands.cfg then add the command for sound alert script.

vi /usr/local/nagios/etc/objects/commands.cfg

define command {  

command_name    play_siren  

command_line    /bin/bash /usr/local/nagios/

          etc/objects/play_siren.sh  

}

[Esc] :wq – to save it then quit

Step 3: Create a script for the sound alert

Put the .wav file into /usr/local/nagios/share/media

vi /usr/local/nagios/etc/objects/play_siren.sh

# !/bin/bash

/usr/bin/aplay -q /usr/local/share/nagios/share/

         media/siren.wav

[Esc] :wq

Set the ownership of the file to nagios.

chown nagios.nagios /usr/local/nagios/etc

           /objects/play_siren.sh

cd /usr/local/nagios/etc/objects 

chmod a+x play_siren.sh

Step 4: Configure contacts.cfg

Edit the contacts.cfg and add play_siren as notification commands under the nagiosadmin.

vi contacts.cfg

service_notification_options w,u,c,r,s,f

host_notification_options d,u,r,f,s

service_notification_commands play_siren

host_notification_commands play_siren

[Esc] :wq

Add the contact group for each services and into

the host in localhost.cfg.

vi localhost.cfg

contact_groups admins

Last uncomment and edit in cgi.cfg and change the .wav file to desired file to use.

vi /usr/local/nagios/etc/cgi.cfg

host_unreachable_sound=alert.wav

host_down_sound=alert.wav

service_critical_sound=alert.wav

service_warning_sound=alert.wav

service_unknown_sound=alert.wav

[Esc] :wq

Restart apache and nagios.

service httpd restart

service nagios restart

 

 

Thursday, October 15, 2020

Install Nagios on Centos 6.4

Nagios, now known as Nagios Core, is a free and open-source computer-software application that monitors systems, networks and infrastructure. Nagios offers monitoring and alerting services for servers, switches, applications and services. 

Step 1: Install Required Dependencies

Install Apache, PHP and some libraries like gcc, glibc, glibc-common and GD libraries and its development libraries before installing Nagios.

yum install -y httpd httpd-tools php gcc glibc glibc-common gd gd-devel make net-snmp wget

Step 2: Create Nagios User and Group

Create user named nagios and group named nagcmd.

useradd nagios

groupadd nagcmd

Next, add both the nagios user and the apache user to the nagcmd group.

usermod -G nagcmd nagios

usermod -G nagcmd apache

Step 3: Download Nagios Core 3.5.0 and Nagios Plugin 2.2.1

cd /tmp

wget https://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.5.0/nagios-3.5.0.tar.gz

wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz

Step 4: Extract Nagios Core and its Plugins

tar zxf nagios-3.5.0.tar.gz

tar zxf nagios-plugins-2.2.1.tar.gz

ls –l (check the extracted folder)

Step 5: Install and Configure Web Interface for Nagios

cd nagios/

./configure --with-command-group=nagcmd

make all

make install

make install-init

make install-commandmode

make install-config

make install-webconf

Set the password for the nagiosadmin.

htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Restart Apache to make the new settings take effect.

service httpd restart

Step 6: Compile and Install Nagios Plugin

cd /tmp

cd nagios-plugins-2.2.1/

./configure --with-nagios-user=nagios --with-nagios-group=nagios

make

make install

Step 7: Verify Nagios Configuration Files 

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

 It should be look like this.



















Step 8: Add Nagios Services to System Startup

chkconfig --add nagios

chkconfig --level 35 nagios on

chkconfig --add httpd

chkconfig --level 35 httpd on

service nagios start

Open a web browser then access the Nagios http://Your-server-IP-address/nagios.

username: nagiosadmin

password: “Your-password” 

Congratulations you have installed Nagios Core.