Linux Programmer | RHCE | RHCSA

Search This Blog

Monday 1 November 2021

Create custom plugin in nagios using bash script.

Nagios is an open source computer software application that monitors systems, networks, and infrastructure.

With Nagios, we can monitor host and configure alerts on the services for servers and applications. It sends alert messages to
relevant people through emails when things go wrong and then sends another alert message when things get rectified.
 
Also we can set to send SMS on mobile when things goes wrong.

In this post, make our custom plugin using bash script which is executed on every client machine using nrpe.

First, install the Nagios-plugin and NRPE on the client servers

"""
apt-get install -y nagios-plugins nagios-nrpe-server
"""

Furthermore, assume that we want to monitor the memory of the server. In order to achieve this, write a bash script memory.sh 
in the directory /usr/lib/Nagios/plugins/ as shown below

"""
#!/bin/bash
free -m | awk ‘NR==2{printf "%.2f%%\t\t", $3*100/$2 }’
[/js]
"""

Now, add the script file in the nrpe configuration file (/etc/Nagios/nrpe.cfg) on the client VPS as shown below.

"""
command[memory_bash]=/usr/lib/nagios/plugins/memory.sh -w 85 -c 90
[/js]
"""

Now on the Nagios-core server add the below command to Nagios checks in the commands.cfg file in /etc/nagios3/ directory.

"""
define command{
command_name memory_bash
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c memory_bash
}
"""

Moving further, define a service in the configuration file to monitor the host as shown below:

"""
define service {
use generic-service
host_name i-085675f30c08376a3
service_description Custom memory checker In Bash
check_command memory_bash
}
"""


Now restart the nrpe server and nagios3 service as below

"""
service nagios3 restart ( on the nagios-core)
service nagios-nrpe-server restart ( on the client server)
"""

And you are good to go!
Your Nagios UI will be able to check the results now. Hope this will helpful and you will yourself be able to create Plugin in Nagios 
using Bash Script.


No comments:

Post a Comment

SSH not working with password after upgrade ubuntu 22.04

Issue: In recent upgrade of ubuntu 22.04 we are not able to login server with SSH password. but when we try to login with key then it allow...