Hi, I have written a skeleton for python script for centreon. The problem is that the script works fine until I import the pyrfc library, which is the key for this script.
Without this library centreon returns me a green OK message which is fine.
Once the library is there, it returns No output returned from plugin. If I run the script through the OS under the user centreon-engine it works fine even with the library. I have the latest version of pyrfc and it works fine because I use it in other scripts, it just doesn't work in the centreon UI. My command is : /usr/bin/env python3 /usr/lib/nagios/plugins/SCRIPTS/test.py (working fine from OS)
What I've tried so far:
set chmod 777 on the script
change the owner to centreon-engine
run the script on the OS under the user centreon-engine - works
reinstall pyrfc library
checked Python versions
My Code:
#!python
__author__ = 'xxxx'
__version__ = 0.1import os
import time
import pyrfc # If I comment remove this line, it works.
from optparse import OptionParser, OptionGroup
import logging as log
import argparse
import subprocess
os.environ."NWRFCSDK_INCLUDE"] = "/usr/local/sap/nwrfcsdk/include"
os.environ."NWRFCSDK_LIBS"] = "/usr/local/sap/nwrfcsdk/lib"
os.environ."SAPNWRFC_HOME"] = "/usr/local/sap/nwrfcsdk"# Initialize parser
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--destination", help="Define RFC destination.")# Read arguments from command line
args = parser.parse_args()
def main():
""" Main plugin logic """with open('/usr/lib/nagios/plugins/SCRIPTS/output_rfc.txt') as f:
lines = f.readlines()
integer = int("".join(str(x) for x in lines))
if integer == 0:
gtfo(0, "OK - destination {} reached.".format(args.destination))
elif integer == 2:
gtfo(2, "CRITICAL - destination {} does not exist.".format(args.destination))
elif integer == 3:
gtfo(1, "WARNING - {} is illegal destination type 'G'.".format(args.destination))
else:
gtfo(2, "CRITICAL - destination {} unreachable.".format(args.destination))
def gtfo(exitcode, message=''):
""" Exit gracefully with exitcode and (optional) message """if message:
print(message)
exit(exitcode)
if __name__ == '__main__':
main()
Thanks in advance for the help.