1

I'm trying to write a local python check which sends an XML request to a WSDL service and get the response as XML. The script works fine on the server (Ubuntu 18.04.2 LTS Server) and prints the results I want. But check_mk (installed on another server) doesn't read this output completely.

The server which I would like to run the script runs Python 2.7.15rc1 on Ubuntu 18.04.2 LTS but check_mk server runs Python 2.7.5 on CentOS Linux 7 (Core). Also, I've noticed that the same script works on check_mk server different than I expect. I should change the try-except block to make the script work on Check_MK server.

#!/usr/bin/python

import requests, base64, re

xml_file = 'request.xml'

hdr = {'Content-Type' : 'text/xml',
    'Authorization' : 'Basic somestring')
    }

with open(xml_file) as xml:
  req = requests.post('http://192.168.39.17:8080/GatewayWebservicesBean?wsdl', data=xml, headers=hdr)
  scode = req.status_code

try:
  resp = re.search(r'<message>(.*?)</message>', req.content).group(1)
except AttributeError:
  print '2 gw_check c=1;0;1;0 Cannot Access to Gateway! Status Code: %s' %scode       #Check_MK doesn't read this output
else:
  if resp == 'Access':
    print '0 eagw_check c=0;0;1;0 OK - Gateway works well'
  else:
    print '2 eagw_check c=1;0;1;0 Please check internal system! Respond from internal system: %s' %resp
ilkerkaran
  • 4,214
  • 3
  • 27
  • 42
garavel
  • 13
  • 5

2 Answers2

0

Are you trying to write a local check or a check_mk plugin? those are two completely different things. Where do you store this file?

Ultimo
  • 113
  • 6
  • Actually, I am trying to write a local check. As I understood from the tutorial, writing a python script which prints smth. like "2 eagw_check c=1;0;1;0 Please check internal system! Respond from internal system:" as stdout is enough to run local check. And I placed this check under the path /usr/lib/check_mk_agent/local – garavel Jun 19 '19 at 14:07
0

I had a similar issue with my python script that was added as local check in the /usr/lib/check_mk_agent/local/ directory. This local script was successfully executed in one server but failed in another. The check_mk_agent when invoked manually in the server, executed the script successfully. But when invoked by the check_mk the output wasn't being sent to service discovery. So I wrapped the python script inside a bash script and redirected the error to be printed as output liked this, output=$(python /usr/lib/check_mk_agent/local/yuge.py 2>&1).

Turns out that the dateutil library used in my python script couldn't be imported by the check_mk. The library was installed using pip manager and couldn't be imported during run-time.

So I had to install the library using the apt-get instead of pip post which the local check script was executed successfully and the output was sent to the service discovery. Checked the other working server and found out that the dateutil library was already installed using apt-get.

https://github.com/chaoss/grimoirelab-perceval/issues/27

Yugendran
  • 172
  • 2
  • 9
  • Now it passes the output to the check_mk server, but it doesn't give the same output as in the local one. That is, when I run check_mk_agent on the host which the script is placed, the output is fine but when I telnet from check_mk server to the host, it gives the error output. I think this is because of the version difference in python. Anyway, (I hope) I approach to the solution one step further. Thank you! – garavel Aug 19 '19 at 15:07