Monitor python service on remote linux host

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Ravikimt
Posts: 77
Joined: Tue Apr 03, 2018 12:02 pm

Monitor python service on remote linux host

Post by Ravikimt »

I need suggestion or help on this one python script is running ("runserver.py") on my remote linux host.
Basically, It means if "runserver.py" script is running mean python3 is running on my remote host and I can access my web application.
If my python script doestn't run I can't access my web application. Can someone help me how I can monitor this on Ngios Core 4.3.4.?

Thanks in advance.
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Monitor python service on remote linux host

Post by mcapra »

Here's some official documentation with simple sample checks you can configure in Nagios Core:
https://support.nagios.com/kb/category.php?id=186

The Process Checks and Service Checks sections might be useful for your situation. They offer examples using several different agents/plugins. I would suggest using NCPA if you don't currently have a monitoring agent configured on the remote Linux host.
Former Nagios employee
https://www.mcapra.com/
Ravikimt
Posts: 77
Joined: Tue Apr 03, 2018 12:02 pm

Re: Monitor python service on remote linux host

Post by Ravikimt »

I have Linux remote host and I have Installed NRPE plugin on that is it also fine right.?

I will go through the document and let you know If I find any difficulty.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Monitor python service on remote linux host

Post by scottwilkerson »

Ravikimt wrote:I have Linux remote host and I have Installed NRPE plugin on that is it also fine right.?
Yes
Ravikimt wrote:I will go through the document and let you know If I find any difficulty.
Sounds good!
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Ravikimt
Posts: 77
Joined: Tue Apr 03, 2018 12:02 pm

Re: Monitor python service on remote linux host

Post by Ravikimt »

I have create my own script to check whether the particular process is running or not for that I have followed below mentioned steps.
The script is working fine on my local Nagios server. I have done this in my local machine for testing purpose.

1-Created my own script [check_runsever] under this directory /usr/local/nagios/libexec/.

2- Added these lines in my command.cfg file.

# 'check_runserver' command definition
define command{
command_name check_runserver
command_line $USER1$/check_runserver
}

3- Added these lines in localhost.cfg

#Define a service to check Runserver on the local machine.
define service{
use local-service
host_name localhost
service_description Runserver
check_command check_runserver
notifications_enabled 0
}

It's working fine in my local Nagios server because this process in running on my local Nagios machine.But I have to monitor the service for remote host.

My doubt is if my script check_runserver is configured on my Nagios production machine. How it will get the correct status of the process which is running on remote host.? OR should I have to do some configuration in remote host as well as.?

Mean I have to do some changes in nrpe.cfg file so that my Nagios server can get the details from Remote host.? .
Last edited by Ravikimt on Mon Jun 04, 2018 10:52 am, edited 2 times in total.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Monitor python service on remote linux host

Post by scottwilkerson »

Do you have the NRPE agent on the remote host installed?

If so can you run any of the commands from the Nagios server and get results?

Did you add your script to the remote host and configure the nrpe.cfg on the remote host to add the new command?

If all of the above are correct, what command are you running and what error are you receiving when you run the command from the CLI on the Nagios server?
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Ravikimt
Posts: 77
Joined: Tue Apr 03, 2018 12:02 pm

Re: Monitor python service on remote linux host

Post by Ravikimt »

@scottwilkerson, NRPE agent is installed on remote host.

I am monitoring mysql service which is running on remote host and I am getting correct status also.

Q1-Did you add your script to the remote host and configure the nrpe.cfg on the remote host to add the new command?
Ans- No, I didn't add my script to the remote host where I have to add this script in /usr/local/nagios/libexec/ directory.?
How I can configure the nrpe.cfg on the remote host can you just give some example.? so that I can understand easily.

here is my script [check_runserver]

Code: Select all

 #!/bin/bash

#Mentioned valid service name
service=runserver.py

#Checking for service pid value
process=`ps -ef | grep -v grep | grep -i $service | wc -l`

case $process in
[2]*)

echo "OK -$service is running" 
exit 0
;;

[0]*)

echo "CRITICAL -$service is not running"
exit 2
;;

[1]*)

echo "WARNING -$service please check the service"
exit 1
;;

esac

this script runserver.py is running on the remote host basically In this script we are calling some API to start the web application.

Currently It's not updating the correct status on Nagios web UI. It's giving me runserver.py service is not running as CRITICAL .Because on my Nagios server I don,t have any runserver.py script that's why I am getting this error.

It's not getting the correct status from remote host. But I have verified runserver.py is running on remote host
Last edited by tmcdonald on Mon Jun 04, 2018 10:38 am, edited 1 time in total.
Reason: Please use [code][/code] tags around code
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Monitor python service on remote linux host

Post by scottwilkerson »

Ravikimt wrote:No, I didn't add my script to the remote host where I have to add this script in /usr/local/nagios/libexec/ directory.?
Yes I would save it as /usr/local/nagios/libexec/check_runserver then mark it executable

Code: Select all

chmod +x /usr/local/nagios/libexec/check_runserver
Then add the following to your nrpe.cfg

Code: Select all

command[check_runserver]=/usr/local/nagios/libexec/check_runserver
Now, restart nrpe on the remote machine

then setup the command for the service to runch check_nrpe passing

Code: Select all

-c check_runserver
and you should be all set
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Ravikimt
Posts: 77
Joined: Tue Apr 03, 2018 12:02 pm

Re: Monitor python service on remote linux host

Post by Ravikimt »

@scottwilkerson I copied my script check_runserver under /usr/local/nagios/libexec directory and made it executable as well.

And added command in nrpe.cfg file

# The following examples use hardcoded command arguments...
# This is by far the most secure method of using NRPE

Code: Select all

command [check_runserver]=/usr/local/nagios/libexec/check_runserver
After that restarted nrpe service o remote host

Code: Select all

sudo service nrpe restart
I have added this command in my command.cfg file on my Nagios server.

#'check_runserver' command definition

Code: Select all

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

Added these lines in linux_server.cfg

Code: Select all

define service{
        use                        local-service         ; Name of service template to use
        host_name                  Sales-Demo
        service_description        Python
        check_command              check_nrpe!check_runserver
        contact_groups             Nagios
        notification_options       w,u,c,r
        notification_interval      10
        notification_period        24x7
        }


After that restarted nagios service on Nagios server. Now I am getting Unknown error NRPE: Command 'check_runserver' not defined
I have gone through the both the servers logs [ Ngaios server and as well as remote host].


Remote host log /usr/local/nagios/var/nrpe.log getting this error.

[1528194540] CONN_CHECK_PEER: checking if host is allowed: 10.10.102.25 port 28840
[1528194540] Connection from 10.10.102.25 port 28840
[1528194540] is_an_allowed_host (AF_INET): is host >10.10.102.25< an allowed host >10.10.102.25<
[1528194540] is_an_allowed_host (AF_INET): is host >10.10.102.25< an allowed host >10.10.102.25<
[1528194540] is_an_allowed_host (AF_INET): host is in allowed host list!
[1528194540] Host address is in allowed_hosts
[1528194541] Host 10.10.102.25 is asking for command 'check_runserver' to be run...
[1528194541] NRPE: Command 'check_runserver' not defined
[1528194541] Return Code: 3, Output: NRPE: Command 'check_runserver' not defined
[1528194541] Connection from 10.10.102.25 closed


Nagios sever logs /usr/local/nagios/var/nagios.log

[1528193232] EXTERNAL COMMAND: SCHEDULE_FORCED_SVC_CHECK;Sales-Demo;Python;1528193230
[1528193412] EXTERNAL COMMAND: SCHEDULE_FORCED_SVC_CHECK;Sales-Demo;Python;1528193411
[1528193879] EXTERNAL COMMAND: SCHEDULE_FORCED_SVC_CHECK;Sales-Demo;Python;1528193878
[1528194540] EXTERNAL COMMAND: SCHEDULE_FORCED_SVC_CHECK;Sales-Demo;Python;1528194538


Please help me here, I want to get rid of this problem.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Monitor python service on remote linux host

Post by scottwilkerson »

in the mrpe config change this

Code: Select all

command [check_runserver]=/usr/local/nagios/libexec/check_runserver
to this

Code: Select all

command[check_runserver]=/usr/local/nagios/libexec/check_runserver
then restart nrpe

I think that is it, an extra space
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked