Nagios can be configured to send out alerts on the state of the host or host service being monitored via email. This guide will, therefore, take you through how to Configure Nagios Email Notification using Gmail.
The current state of a service or host being monitored is determined by the status of the service or host which can be OK, WARNING, UP, DOWN, etc. and the type of state the service or host which can hard or soft.
Before you can proceed, install Nagios and add hosts to be monitored.
Configure Nagios
Email Notification Using Gmail
Install Required
Mail Packages
In this guide, we are going to use Postfix as an outMail Transfer Agent (MTA). Also, by default, Nagios Mail notification is sent using the mail command. Hence, run the command below to install the required packages.
Yum install postfix cyrus-sasl-plain mailx -y
Configure Postfix
to Use Gmail Relay
Enable STARTTLS encryption by changing the
line smtp_tls_security_level = may to smtp_tls_security_level
= encrypt.
sed -i 's/smtp_tls_security_level = may/smtp_tls_security_level =
encrypt/' /etc/postfix/main.cf
If the smtp_tls_security_level option
is not set, just insert it;
Define the path to CA certificates. The public root
certificates are usually found under /etc/pki/tls/certs/ca-bundle.crt on RHEL derivatives and /etc/ssl/certs/ca-certificates.crt on Debian/Ubuntu systems.
You should be able to receive the mail on your inbox. You can also check the mail logs. The log filename may be different for your case.
tail -f /var/log/maillog
Jan 19 15:01:44 dev-server postfix/smtp[5109]: C7E8C3B5AD: to=userid@gmail.com,relay=smtp.gmail.com[74.125.200.109]:587, delay=18, delays=0.04/0.02/16/2.1,dsn=2.0.0, status=sent (250 2.0.0 OK 1571511704 h8sm11800598pfo.64 - gsmtp) Jan 19 15:01:44 dev-server postfix/qmgr[4574]: C7E8C3B5AD: removed
Create Nagios
Contact Object Definition
The first step in configuring is to create a Nagioscontacts group that defines who should be notified on the state of a monitored service or host.
Nagios comes with a default contact group, contacts.cfg, located on the default objects definition
configurations directory, /usr/local/nagios/etc/objects.
You can modify the default contacts definition configuration file or create your own.
If there is no syntax error, restart Nagios
service.
systemctl restart nagios
Testing Nagios Mail
Alerts Notification
To test if mail notification works, first change the IP address of one of the hosts to an IP that is unreachable such that it looks like the host is down.
Reschedule the next check for the host state. This will automatically send out an email alert on host DOWN.
If you encounter the error below when rescheduling
checks,
Error: Could not open command file ‘/usr/local/nagios/var/rw/nagios.cmd’
for update!
This is due to SELinux. To fix, run journactl -xe. It should show some SELinux commands to execute to fix this. The commands below is what i run myself.
WordPress is a free and open source blogging platform or content management system based on PHP and MySQL. Currently WordPress is the most popular CMS all over the world, and has 20000 plus plugins to extend its functionality.You can easily create a simple website, blog or complex portals and enterprise websites using WordPress.
WordPress provides lots of features. Some of them are listed below:
WordPress is available in more than 70 languages. So you can build a website in a language as your choice.
You can easily manage your content, schedule, look and publication using WordPress, and also secure your posts and content with a password.
WordPress comes with thousands of themes for you to create a beautiful website. You can also upload your own theme with the click of a button.
With the importers feature you can easily import your blog from another website to WordPress.
WordPress provides search engine optimization out of the box, and also provides many SEO plugins.
In this tutorial, we will discuss how to install and configure WordPress on a CentOS 7 server.
Requirements
A server running CentOS 7.
A non-root user with sudo privilege setup on your server.
Getting Started
Update your system with the latest package versions by running the following command:
sudo yum update -y
Once your system is up-to-date, you can proceed to the next step.
Installing LAMP
Before installing WordPress itself, you will need to install the LAMP stack and other required packages on your server.
You can install all the necessary packages with the following command:
By default MariaDB is not secured, so you will need to secure it first. You can do this by running mysql_secure_installation script:
sudo mysql_secure_installation
Answer all the questions as shown below:
Set root password? [Y/n] n Remove anonymous users? [Y/n] y Disallow root login remotely? [Y/n] y Remove test database and access to it? [Y/n] y Reload privilege tables now? [Y/n] y
Once you have finished, login to MariaDB console with the following command:
mysql -u root -p
Enter your MariaDB root password and hit Enter. After login, create a database for WordPress:
MariaDB [(none)]>CREATE DATABASE wordpress; MariaDB [(none)]>GRANT ALL PRIVILEGES on wordpress.* to 'user'@'localhost' identified by 'password'; MariaDB [(none)]>FLUSH PRIVILEGES; MariaDB [(none)]>exit
Installing and Configuring WordPress
You can download the latest version of the WordPress source from the official website. You can get the latest version of WordPress by running the following command:
wget http://wordpress.org/latest.tar.gz
Once download is finished, extract the downloaded file with the following command:
tar -xzvf latest.tar.gz
Next, move the extracted files to the Apache web root directory:
Next, open your web browser and type the URL http://your-server-ip. You should see the following page:
Select language as per your need and click on Continue button, you should see the following page:
Fill out all the required site information and click on Install WordPress button. You should see the WordPress default dashboard as below:
Once installation is completed, you can login WordPress by typing the URL http://your-server-ip/wp-login.php? on your web browser. You should see the WordPress login page as below:
Next, provide username and the password which you have created earlier and click on Log In button, you should see the following page:
Summary
Congratulations! You have successfully installed WordPress on CentOS 7. I hope you have now enough knowledge to host your own WordPress blog easily. Feel free to comment below if you have any questions.
These are deprecated and will be removed in future versions, might as well change them now:
sed -i 's/normal_check_interval/check_interval/g' /usr/local/nagios/etc/objects/templates.cfg sed -i 's/normal_check_interval/check_interval/g' /usr/local/nagios/etc/objects/printer.cfg sed -i 's/normal_check_interval/check_interval/g' /usr/local/nagios/etc/objects/switch.cfg sed -i 's/retry_check_interval/retry_interval/g' /usr/local/nagios/etc/objects/templates.cfg sed -i 's/retry_check_interval/retry_interval/g' /usr/local/nagios/etc/objects/printer.cfg sed -i 's/retry_check_interval/retry_interval/g' /usr/local/nagios/etc/objects/switch.cfg sed -i 's/^command_check_interval/#command_check_intervald/g' /usr/local/nagios/etc/nagios.cfg
We use Nagiosgraph, therefore we need this to continue processing data (the config file which we restored from the backup does contain the line already, therefore it’s mainly for future references).
sed -i 's/process_performance_data=0/process_performance_data=1/g' /usr/local/nagios/etc/nagios.cfg
Nagios Core 4.4.2 Copyright (c) 2009-present Nagios Core Development Team and Community Contributors Copyright (c) 1999-2009 Ethan Galstad Last Modified: 2017-08-24 License: GPL
Things look okay – No serious problems were detected during the pre-flight check
If there are any configuration mismatches between the old and the new Nagios versions that affect your set up, then change them accordingly.
In this tutorial, we will cover the installation of Nagios 4, a very popular open source monitoring system, on CentOS 7 or RHEL 7. We will cover some basic configuration, so you will be able to monitor host resources via the web interface. We will also utilize the Nagios Remote Plugin Executor (NRPE), that will be installed as an agent on remote hosts, to monitor their local resources.
Nagios is useful for keeping an inventory of your servers, and making sure your critical services are up and running. Using a monitoring system, like Nagios, is an essential tool for any production server environment.
Prerequisites
To follow this tutorial, you must have superuser privileges on the CentOS 7 server that will run Nagios. Ideally, you will be using a non-root user with superuser privileges.
This tutorial assumes that your server has private networking enabled. If it doesn’t, just replace all the references to private IP addresses with public IP addresses.
Now that we have the prerequisites sorted out, let’s move on to getting Nagios 4 installed.
Install Nagios 4.4.5
This section will cover how to install Nagios 4 on your monitoring server. You only need to complete this section once.
Install Build Dependencies
Because we are building Nagios Core from source, we must install a few development libraries that will allow us to complete the build.
We must create a user and group that will run the Nagios process. Create a “nagios” user and “nagcmd” group, then add the user to the group with these commands:
Download the source code for the latest stable release of Nagios Core. Go to the Nagios downloads page, and click the Skip to download link below the form. Copy the link address for the latest stable release so you can download it to your Nagios server.
At the time of this writing, the latest stable release is Nagios 4.4.5. Download it to your home directory with curl:
mkdir ./nagios cd ./nagios wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.5.tar.gz
Extract the Nagios archive with this command:
tar zxf nagios-4.4.5.tar.gz
Then change to the extracted directory:
cd nagios-4.4.5/
Before building Nagios, we must configure it with this command:
./configure --with-command-group=nagcmd
Now compile Nagios with this command:
make all
Now we can run these make commands to install Nagios, init scripts, and sample configuration files:
sudo make install sudo make install-commandmode sudo make install-init sudo make install-config sudo make install-webconf
In order to issue external commands via the web interface to Nagios, we must add the web server user, apache, to the nagcmd group:
sudo usermod -G nagcmd apache
Install Nagios Plugins
Find the latest release of Nagios Plugins here: Nagios Plugins Download. Copy the link address for the latest version, and copy the link address so you can download it to your Nagios server.
At the time of this writing, the latest version is Nagios Plugins 2.3.1. Download it to your home directory with curl:
cd ../ wget https://nagios-plugins.org/download/nagios-plugins-2.3.1.tar.gz
Extract Nagios Plugins archive with this command:
tar xvf nagios-plugins-*.tar.gz
Then change to the extracted directory:
cd nagios-plugins-*
Before building Nagios Plugins, we must configure it. Use this command:
Enter a password at the prompt. Remember this login, as you will need it to access the Nagios web interface.
Note: If you create a user that is not named “nagiosadmin”, you will need to edit /usr/local/nagios/etc/cgi.cfg and change all the “nagiosadmin” references to the user you created.
Nagios is ready to be started. Let’s do that, and restart Apache:
To enable Nagios & Apache to start on server boot, run this command:
systemctl enable nagios systemctl enable httpd
Optional: Restrict Access by IP Address
If you want to restrict the IP addresses that can access the Nagios web interface, you will want to edit the Apache configuration file:
sudo vi /etc/httpd/conf.d/nagios.conf
Find and comment the following two lines by adding # symbols in front of them:
Order allow,deny Allow from all
Then uncomment the following lines, by deleting the # symbols, and add the IP addresses or ranges (space delimited) that you want to allow to in the Allow from line:
# Order deny,allow # Deny from all # Allow from 127.0.0.1
As these lines will appear twice in the configuration file, so you will need to perform these steps once more.
Save and exit.
Now start Nagios and restart Apache to put the change into effect:
Open your favorite web browser, and go to your Nagios server (substitute the IP address or hostname for the highlighted part):
http://nagios_server_public_ip/nagios
Because we configured Apache to use htpasswd, you must enter the login credentials that you created earlier. We used “nagiosadmin” as the username:
After authenticating, you will be see the default Nagios home page. Click on the Hosts link, in the left navigation bar, to see which hosts Nagios is monitoring:
As you can see, Nagios is monitoring only “localhost”, or itself.
Let’s monitor another host with Nagios!
Monitor a CentOS 7 Host with NRPE
In this section, we’ll show you how to add a new host to Nagios, so it will be monitored. Repeat this section for each CentOS or RHEL server you wish to monitor.
On a server that you want to monitor, install the EPEL repository:
sudo yum install epel-release
Now install Nagios Plugins and NRPE:
Now, let’s update the NRPE configuration file. Open it in your favorite editor (we’re using vi):
Find the allowed_hosts directive, and add the private IP address of your Nagios server to the comma-delimited list (substitute it in place of the highlighted example):
allowed_hosts=127.0.0.1,10.132.224.168
Save and exit. This configures NRPE to accept requests from your Nagios server, via its private IP address.
Once you are done installing and configuring NRPE on the hosts that you want to monitor, you will have to add these hosts to your Nagios server configuration before it will start monitoring them.
Add Host to Nagios Configuration
On your Nagios server, create a new configuration file for each of the remote hosts that you want to monitor in /usr/local/nagios/etc/servers/. Replace the highlighted word, “yourhost”, with the name of your host:
sudo vi /usr/local/nagios/etc/servers/yourhost.cfg
Add in the following host definition, replacing the host_name value with your remote hostname (“web-1” in the example), the alias value with a description of the host, and the address value with the private IP address of the remote host:
define host {
use linux-server
host_name yourhost
alias My first Apache server
address 10.132.234.52
max_check_attempts 5
check_period 24x7
notification_interval 30
notification_period 24x7
}
With the configuration file above, Nagios will only monitor if the host is up or down. If this is sufficient for you, save and exit then restart Nagios. If you want to monitor particular services, read on.
Add any of these service blocks for services you want to monitor. Note that the value of check_command determines what will be monitored, including status threshold values. Here are some examples that you can add to your host’s configuration file:
Ping:
define service {
use generic-service
host_name yourhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
SSH (notifications_enabled set to 0 disables notifications for a service):
define service {
use generic-service
host_name yourhost
service_description SSH
check_command check_ssh
notifications_enabled 0
}
If you’re not sure what use generic-service means, it is simply inheriting the values of a service template called “generic-service” that is defined by default.
Now save and quit. Reload your Nagios configuration to put any changes into effect:
sudo systemctl reload nagios.service
Once you are done configuring Nagios to monitor all of your remote hosts, you should be set. Be sure to access your Nagios web interface, and check out the Services page to see all of your monitored hosts and services:
Conclusion
Now that you monitoring your hosts and some of their services, you might want to spend some time to figure out which services are critical to you, so you can start monitoring those. You may also want to set up notifications so, for example, you receive an email when your disk utilization reaches a warning or critical threshold or your main website is down, so you can resolve the situation promptly or before a problem even occurs.
By default MariaDB is not secured, so you will need to secure it first. You can do this by running mysql_secure_installation script:
sudo mysql_secure_installation
Answer all the questions as shown below:
Set root password? [Y/n] n Remove anonymous users? [Y/n] y Disallow root login remotely? [Y/n] y Remove test database and access to it? [Y/n] y Reload privilege tables now? [Y/n] y
Your Centos host is now ready for your application and is configured as a LAMP server