[Check_mk (english)] Getting my basic MRPE check working

Hi

I have a fairly basic local check written in python and while it prints the correct output (I believe) Check_Mk is not picking up the output correctly. I have
done a re-inventory several times, restarted Check_MK and made sure the script is executable and other checks.

Check_MK CEE 1.2.8p26 shows this output when I run:

#> cmk -d VSSOLUTIONS | grep –C1 mrpe

<<>>

(check_pdn.py) PDN_STATUS 127

But when I run the check with check_mk_agent on the host I get:

<<>>

(check_pdn.py) PDN_STATUS 0 0 PDN_STATUS - OK - Normal Parameters

Running the script manually I get:

0 PDN_STATUS - OK - Normal Parameters

Just trying to figure out where the discrepancy is.

Only 1 line in /etc/check_mk/mrpe.cfg:

PDN_STATUS /root/scripts/python/nagios-checks/check_pdn.py

Any help appreciated,

Rgds

Paraic

···

Full Script:

#!/opt/rh/rh-python34/root/usr/bin/python3.4

‘’’

this file is the backend for a Check_Mk script to check the PDN_Status.txt file

‘’’

import os

from datetime import datetime

Set the time to report the current hour

timenow=datetime.now().strftime(’%H’)

set the date to today’s date

datestr=datetime.now().strftime(’%d/%m/%Y’)

Initialise the two strings we will use

newlist = []

list1=[]

This is the file that CT Solutions use to check the status of the lines

PDN_FILE="/mnt/koteleq4u/PDN_Status.txt"

read the file into a lines string

with open(PDN_FILE) as file1:

lines = file1.readlines()

Split into columns and check Col 4 to see if it registers 0 which means it’s available and not in error state

then append the available lines into the string newlist

for line in lines[1:] :

columns = line.split()

if columns[4] == ‘0’:

newlist.append(columns[:])

iterate thru the newlist and pick the ones that are on today’s date and select the column with the time and then select the digits and add the strings to

make the hour

for item in newlist :

if item[2] == datestr :

str1=item[3][0]

str2=item[3][1]

str3=str1+str2

list1.append(str3)

check the difference in hours between now and the latest hour represented in the status file

timehour=int(max(list1))

if the time in the file is greater than two hours old, output a ‘2’ which is a CRIT for Nagios, otherwise a ‘0’ which is an OK, alonmg with some other info

for the check

if timehour > int(timenow) - 2 :

print(“0”,“PDN_STATUS”,"-",“OK - Normal Parameters”)

else:

print(“2”,“PDN_Status”,"-", “CRIT - No Dialup in the last 2 hours!”)

You have written a Local Check, not a Nagios plugin.
MRPE uses classical Nagios plugins.
There is a difference in output format and exit code handling.

Local checks belong into the local subdirectory of the Check_MK agent
installation.

http://mathias-kettner.com/cms_localchecks.html

https://mathias-kettner.com/cms_agent_linux.html#mrpe

Regards

···

On 29.01.2018 18:20, Paraic O'Ceallaigh wrote:

if timehour > int(timenow) - 2 :

print\(&quot;0&quot;,&quot;PDN\_STATUS&quot;,&quot;\-&quot;,&quot;OK \- Normal Parameters&quot;\)

else:

print\(&quot;2&quot;,&quot;PDN\_Status&quot;,&quot;\-&quot;, &quot;CRIT \- No Dialup in the last 2 hours\!&quot;\)

--
Robert Sander
Heinlein Support GmbH
Schwedter Str. 8/9b, 10119 Berlin

Tel: 030 / 405051-43
Fax: 030 / 405051-19

Zwangsangaben lt. §35a GmbHG:
HRB 93818 B / Amtsgericht Berlin-Charlottenburg,
Geschäftsführer: Peer Heinlein -- Sitz: Berlin

Hi Robert
Thanks for the direction.
I copied the script into /usr/lib/check_mk_agent/local which corresponds to the local folder in the check_mk agent output and then did an inventory of the host but no output in the <<<local>>> section when I run the cmk -d HOST from the Check_Mk server.
I do see the output when I run the check_mk_agent locally on the host.

So to troubleshoot I created the standard test script in my host's local folder:
#!/bin/sh
echo "0 myservice - OK: This is my custom output"

and this worked when I checked for local scripts.
Is there something missing in my python script to make it valid as a local check?

Rgds
Paraic

···

-----Original Message-----
From: checkmk-en [mailto:checkmk-en-bounces@lists.mathias-kettner.de] On Behalf Of Robert Sander
Sent: Tuesday 30 January 2018 09:59
To: checkmk-en@lists.mathias-kettner.de
Subject: Re: [Check_mk (english)] Getting my basic MRPE check working

On 29.01.2018 18:20, Paraic O'Ceallaigh wrote:

if timehour > int(timenow) - 2 :

    print("0","PDN_STATUS","-","OK - Normal Parameters")

else:

    print("2","PDN_Status","-", "CRIT - No Dialup in the last 2
hours!")

You have written a Local Check, not a Nagios plugin.
MRPE uses classical Nagios plugins.
There is a difference in output format and exit code handling.

Local checks belong into the local subdirectory of the Check_MK agent installation.

http://mathias-kettner.com/cms_localchecks.html

https://mathias-kettner.com/cms_agent_linux.html#mrpe

Regards
--
Robert Sander
Heinlein Support GmbH
Schwedter Str. 8/9b, 10119 Berlin

Tel: 030 / 405051-43
Fax: 030 / 405051-19

Zwangsangaben lt. §35a GmbHG:
HRB 93818 B / Amtsgericht Berlin-Charlottenburg,
Geschäftsführer: Peer Heinlein -- Sitz: Berlin

This email, including any attachments, is confidential. If you are not the named recipient, please contact the sender and delete all copies of this email from your computer system(s).

Mystery solved.
Turns out the Python 3.4 I was using to run the script was causing it not to be recognised as a local script. I adjusted it to the local Python 2.7 on the host and now Check_MK picks it up fine.
Strange.

Paraic

···

-----Original Message-----
From: checkmk-en [mailto:checkmk-en-bounces@lists.mathias-kettner.de] On Behalf Of Paraic O'Ceallaigh
Sent: Tuesday 30 January 2018 10:25
To: Robert Sander; checkmk-en@lists.mathias-kettner.de
Subject: Re: [Check_mk (english)] Getting my basic MRPE check working

Hi Robert
Thanks for the direction.
I copied the script into /usr/lib/check_mk_agent/local which corresponds to the local folder in the check_mk agent output and then did an inventory of the host but no output in the <<<local>>> section when I run the cmk -d HOST from the Check_Mk server.
I do see the output when I run the check_mk_agent locally on the host.

So to troubleshoot I created the standard test script in my host's local folder:
#!/bin/sh
echo "0 myservice - OK: This is my custom output"

and this worked when I checked for local scripts.
Is there something missing in my python script to make it valid as a local check?

Rgds
Paraic

-----Original Message-----
From: checkmk-en [mailto:checkmk-en-bounces@lists.mathias-kettner.de] On Behalf Of Robert Sander
Sent: Tuesday 30 January 2018 09:59
To: checkmk-en@lists.mathias-kettner.de
Subject: Re: [Check_mk (english)] Getting my basic MRPE check working

On 29.01.2018 18:20, Paraic O'Ceallaigh wrote:

if timehour > int(timenow) - 2 :

    print("0","PDN_STATUS","-","OK - Normal Parameters")

else:

    print("2","PDN_Status","-", "CRIT - No Dialup in the last 2
hours!")

You have written a Local Check, not a Nagios plugin.
MRPE uses classical Nagios plugins.
There is a difference in output format and exit code handling.

Local checks belong into the local subdirectory of the Check_MK agent installation.

http://mathias-kettner.com/cms_localchecks.html

https://mathias-kettner.com/cms_agent_linux.html#mrpe

Regards
--
Robert Sander
Heinlein Support GmbH
Schwedter Str. 8/9b, 10119 Berlin

Tel: 030 / 405051-43
Fax: 030 / 405051-19

Zwangsangaben lt. §35a GmbHG:
HRB 93818 B / Amtsgericht Berlin-Charlottenburg,
Geschäftsführer: Peer Heinlein -- Sitz: Berlin

This email, including any attachments, is confidential. If you are not the named recipient, please contact the sender and delete all copies of this email from your computer system(s).
_______________________________________________
checkmk-en mailing list
checkmk-en@lists.mathias-kettner.de
http://lists.mathias-kettner.de/mailman/listinfo/checkmk-en
This email, including any attachments, is confidential. If you are not the named recipient, please contact the sender and delete all copies of this email from your computer system(s).