Page 1 of 2
How to call Python script within Nagios check
Posted: Thu Aug 08, 2019 7:59 am
by jankogaga
Hi,
I would like to call Python script within Nagios check.
Python script has the arguments. E.g.:
/usr/local/nagios/libexec/check_ssl.py -H google.com -c E+,E,E-,F+,F,F-,T,M,C+,C-,C,D+,D,D- -d 15
and it works when I run in command line for nagios user.
What I have tried and it didn't work for me:
in commands.cfg:
Code: Select all
define command{
command_name check_ssl
command_line /usr/local/nagios/libexec/check_ssl.py -H $ARG1$ -c $ARG2$ -d $ARG3$
}
monitor.cfg:
Code: Select all
define service{
use local-service ; Name of service template to use
host_name xxx
service_description SSLLABS Web service
check_command check_ssl!google.com!E+,E,E-,F+,F,F-,T,M,C+,C-,C,D+,D,D-!15
notifications_enabled 1
}
Thanks,
Dragan
Re: How to call Python script within Nagios check
Posted: Thu Aug 08, 2019 9:46 am
by mbellerue
The only thing I'm seeing right away is the service definition is missing some information.
https://assets.nagios.com/downloads/nag ... ml#service
Re: How to call Python script within Nagios check
Posted: Mon Aug 26, 2019 5:50 am
by jankogaga
Hi,
Thank you for your reply.
We run Nagios Core 4.4.3.
In the same .cfg file for the host we have already working service definition like this:
Code: Select all
define service{
use local-service ; Name of service template to use
host_name xxx
service_description Swap Usage
check_command check_local_swap!20!10
}
Thanks,
Dragan
Re: How to call Python script within Nagios check
Posted: Mon Aug 26, 2019 9:28 am
by mbellerue
What does the Service page look like in Nagios? Does it show an error, or just give an Unknown status?
What if you altered your command to call Python specifically?
Code: Select all
command_line /usr/bin/env python2 /usr/local/nagios/libexec/check_ssl.py -H $ARG1$ -c $ARG2$ -d $ARG3$
Or
/usr/bin/env python3 if it's a Python 3 script, of course.
Re: How to call Python script within Nagios check
Posted: Tue Aug 27, 2019 6:09 am
by jankogaga
I have got the following message in Nagios WebGUI:
Code: Select all
(Return code of 127 is out of bounds. Check if plugin exists)
When running a python script from the command line as nagios user, I have got:
Code: Select all
bash-4.2$ /usr/bin/env python3 /usr/local/nagios/libexec/check_ssl.py -H google.com -c E+,E,E-,F+,F,F-,T,M,C+,C-,C,D+,D,D- -d 15
SSLLABS grade for google.com is A, ssl certificate expires in 55 days
Re: How to call Python script within Nagios check
Posted: Tue Aug 27, 2019 10:20 am
by mbellerue
Can you check
/etc/group and make sure that the Apache user is in the Nagios group?
e.g.
Also what is the output of the following command?
Code: Select all
ls -l /usr/local/nagios/libexec/check_ssl*
Re: How to call Python script within Nagios check
Posted: Tue Aug 27, 2019 11:52 am
by jankogaga
/etc/group has the following records:
Code: Select all
nagios:x:992:nrpe
nagcmd:x:1000:nagios,apache
Please note that a bunch of services already work with that configuration.
The output of ls -l /usr/local/nagios/libexec/check_ssl* is
Code: Select all
-rwxr-xr-x 1 nagios nagios 8549 Aug 7 13:46 /usr/local/nagios/libexec/check_ssl.py
Thanks,
Dragan
Re: How to call Python script within Nagios check
Posted: Tue Aug 27, 2019 12:37 pm
by mbellerue
The permissions do look good. Let's check the shebang on the script itself.
Code: Select all
head -2 /usr/local/nagios/libexec/check_ssl.py
Also, what command are you using when you switch over to the nagios user to run the check commands?
Re: How to call Python script within Nagios check
Posted: Tue Aug 27, 2019 12:44 pm
by jankogaga
Here you are:
head -2 /usr/local/nagios/libexec/check_ssl.py
Code: Select all
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
for switching to nagios user:
Re: How to call Python script within Nagios check
Posted: Tue Aug 27, 2019 1:15 pm
by mbellerue
Try it with a dash.
That should drop your user's environment, and give you just the nagios user's environment. Then try to run the check command.