Installation Guide Of Nagios
Pre-Requisite:
Before Installing, Connect VM of Ubuntu(Remote) with your local
system because Nagios can be downloaded in Ubuntu Only:
1. Use Putty (Enter Your VM Server Credentials) where nagios
can be setup:
IP Address: 99.99.99.206
2. Now Putty Contains Ubuntu Remote server
(99.99.99.206):
Login as :
PWD: In2IT#$tst
Username: catsuser
Note:
1. Enable IT-Corp Network.
2. Enable Liquid VPN
1. List of OS for nagios core
1. Red Hat Enterprise Linux (RHEL)
2. CentOS
3. Oracle Linux
4. Ubuntu
5. SUSE SLES | openSUSE Leap
6. Debian
7. Raspbian
8. Fedora
9. Arch Linux
10. Gentoo
11. FreeBSD
12. Solaris
13. Apple OS X
2. For Ubuntu (20.x)
2nd Command will install appache2 and php
sudo apt-get update
sudo apt-get install -y autoconf gcc libc6 make wget unzip apache2 php
libapache2-mod-php8.1 libgd-dev
sudo apt-get install openssl libssl-dev
3. Downloading the Source
- cd /tmp
- wget -O nagioscore.tar.gz
- https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.5.6.tar.gz
- tar xzf nagioscore.tar.gz
4. Compile
- cd /tmp/nagioscore-nagios-4.5.6/
- sudo ./configure --with-httpd-conf=/etc/apache2/sites-enabled
- sudo make all
5. Create User and Group
sudo make install-groups-users
sudo usermod -a -G nagios www-data
6. Install Binaries
sudo make install
7. Install Daemon
sudo make install-daemoninit
8. Install Command Mode
sudo make install-commandmode
9. Install Configuration Files
sudo make install-config
10. Install Apache Config Files
sudo make install-webconf
sudo a2enmod rewrite
sudo a2enmod cgi
11. Configure Firewall
sudo ufw allow Apache
sudo ufw reload
12.Create nagiosadmin User Account
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Note: nagiosadmin: username
Nagiosadmin: pwd
13. Start Service
sudo systemctl start nagios.service
14. Install Plugins to remove errors in Nagios Web Interface
sudo apt-get install -y autoconf gcc libc6 libmcrypt-dev make libssl-dev
wget bc gawk dc build-essential snmp libnet-snmp-perl gettext
cd /tmp
wget --no-check-certificate -O nagios-plugins.tar.gz
https://github.com/nagios-plugins/nagios-plugins/archive/release-2.4.12.tar.gz
tar zxf nagios-plugins.tar.gz
15. Compile and install
cd /tmp/nagios-plugins-release-2.4.6/
sudo ./tools/setup
sudo ./configure
sudo make
sudo make install
16. Restart again and the error will gone
17. Common commands
sudo systemctl start nagios.service
sudo systemctl stop nagios.service
sudo systemctl restart nagios.service
sudo systemctl status nagios.service
Windows Monitoring: Nagios Core
Note:
The agent acts as a proxy between Nagios server and and private attributes
or services of windows.
NsClient++ is only for windows.
NCPA is for cross platform agent(Nagios Cross-Platform Agent)
Private Services and attributes of windows machine
Memory usage
CPU load
Disk usage
Service states
Running processes
Installing NS Client ++
1. https://sourceforge.net/projects/nscplus/
2. Write Host of Nagios: 99.99.99.206
3. Enable Check_nt and Check_nrpe
4. Enable ‘1’ in nsclient.ini if there is any ‘0’. Also Check allowed-
host to be 99.99.99.206 or your nagios host server ip address:
CheckDisk = 1
CheckEventLog = 1
NSClientServer = 1
CheckExternalScripts = 1
CheckHelpers = 1
CheckNSCP = 1
CheckSystem = 1
Setup Internal Files on Nagios Server
1.Windows.cfg
Cd/usr/local/nagios/etc/objects/ File Path
Sudo nano windows.cfg
Define Host and services of OS you want to monitor.
-Check hostname in windows and write in host_name as shown
-Check Ip address of your network(Wireless LAN Adapter Wifi) and write in
address.
Note: IpV4 Address changes as we change the network.
Host:
Services:
These are some kind of services like uptime, CPU load etc.
These will reflect on nagios web interface once setup in this file.
Write your Host name here too.
2.Commands.cfg
cd/usr/local/nagios/etc/objects/ File Path
Sudo nano commands.cfg
Write your ticket_ creation command over here. Nagios will take up from
here.
Write command_name and command_line
Note: Whenever there is change in service state (like critical to ok or to
warning and vice versa) the itop_ticket_create command will call the
command line and it will execute the script using Event Handlers(Will be
discussed later)
It has 5 arguments and correspondingly it will be passed as argument in
createTicket-nagios.php file.
Note: No argument must be left blank otherwise it will return
SoapClient error
$sHost=$argv[1]; # $HOSTNAME$ In2-DHRUVGUPTA
$sService=$argv[2]; #$SERVICEDESC$ C:\ Drive Space
$sServiceStatus=$argv[3]; # $SERVICESTATE$ CRITICAL
$sServiceStateType=$argv[4]; # $SERVICESTATETYPE$ HARD
$sServiceMessage=$argv[5]; # $LONGSERVICEOUTPUT$ Any long
description
Note: Complete Process flow will be explained at last with the help of Block
Diagram.
Don’t Worry 😊
3.Event Handlers
There are two types of event handlers: a) event handler b)
global_host_event_handler
I had implemented global_host_event_handler
File Path:
cd /usr/local/nagios/etc
sudo nano nagios.cfg
Write the command name which we had mentioned in commands.cfg file
(create_itop_ticket) as a value in global_host_event_handler.
Note: You can also implement event handler but for that you have to
mention in
Each host or service you want to invoke.
event_handler create-iTop-ticket
event_handler_enabled 1
Integrating ITOP with Nagios
Referernce:
https://www.itophub.io/wiki/page?id=2_5_0:advancedtopics:nagios
1. Download the createTicket-nagios.php zip file
http://www.combodo.com/documentation/createTicket-nagios.zip
2. Copy this script itopsoaptypes.class.inc.php in your project
directory.
webservices\itopsoaptypes.class.inc.php
3. Copy both script from 1st and 2nd step in ubuntu directory:
/usr/local/nagios/sbin
This is something sbin looks like:
It has both files createTicket-nagios.php and
itopsoaptypes.class.inc.php
Note:
You might not have enough permissions to write the script in sbin.
So first paste those scripts in root directory of ubuntu and then move to
sbin.
mv filename destination_directory/
4. In commands.cfg as discussed earlier
In here the :
<php path> is that path where your ubuntu php is located
i.e /usr/bin/php
<yourDirectory> is that directory of ubuntu in which you had paste
both files
createTicket-nagios.php and itopsoaptypes.class.inc.php
5. Enable soap extension from php.ini file
Cd /etc/php/8.1/apache2/
Sudo nano php.ini
Search
; extension = soap and remove semicolon.
Cd /etc/php/8.1/apache2/conf.d
Make sure it contains 20-soap.ini or 40-soap.ini
6. Create itop-nagios-integration extension.
In datamodel write the given path of nagios url where $this->name$ is
the host name you enter on itop UI.
http://99.99.99.206/nagios/cgi-bin/status.cgi?host=$this->name$
7. Main.php
Write down OnDisplayRelations() function which actually make a
new tab in Server page(Get new CI menu).
Refer to the itop-nagios-integration
Note:
Make sure to add ‘Server’ in php script in place of ‘Device’ .
8. ITOP Web Interface
Here all the host will be listed if you enter the correct host name which
is from windows.cfg file
Finalizing
1. Sudo systemctl start nagios
2. Sudo systemctl start apache2
3. The services will gradually come from critical to ok
Note:
The php script will be called with the help of Global Event Handler
but ticket will not create as ‘OK’ state will not pass.
4. Try to down any service like http(Apache) of windows and shut it
down and then restart nagios, after 30 seconds nagios will come
from ok to critical and ‘if’ condition in php script will allow the
critical state and hence Incident ticket will be created.
5. The command below will check log file every 30 seconds and you
can see something like this:
tail -f /usr/local/nagios/var/nagios.log
To check the events every time nagios refreshes
If services go from Critical to Ok
Here You can see Global service Event Handler is called for uptime having
‘OK’ status.
Create_itop_ticket is called but ticket is not created.
If services go from ‘ok’ to ‘crititcal’/’warning’/’down’ (Ticket
Creation)
You can see clearly I had down the apache and here it is showing ‘Critical’ to
http service
And hence ticket Incident is created.
Checked in database of uat_test in ticket_incident table
Thank you