skip to Main Content

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

2

Answers


  1. 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?

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search