Own plugin (with parameter and return values for a python script) not work

Hi everyone,

i hope i can found help for my problem: ;D

I have written a simple python script (expect a parameter) and the script give back a return value.

*#!/usr/bin/env python3*
*import sys, os*

*def main():*

*  print('<<<"plg_tst">>>')*

*  #---------------------------------------*
*  # check count of input parameter/s:*
*  #  - if missing then show error and exit*
*  #---------------------------------------*
*  if len(sys.argv) < 2:*
*    print('Missing parameter')*
*    sys.exit(2)*

*  # --------------------------*
*  # the input variables:*
*  #*
*  #*
*  # --------------------------*
*  script_name =  os.path.basename(sys.argv[0])*
*  plg_tst_parm = sys.argv[1]*

*  print('Execute ' + script_name + ' with parameter ' + plg_tst_parm)*

*  ret_code = 'fail'*
*  return ret_code*

*#   MAIN *
*if __name__ == "__main__":*

*  main()*

But the command “check_mk_agent” run on the error for missing parameter.
userle@srv001:/root# check_mk_agent

Missing parameter

First question. How can i take over a parameter to my script?

I have create the plugin script /omd/sites/dev_1/local/lib/check_mk/base/plugins/agent_based/plg_tst.py:

from .agent_based_api.v1 import 
import pprint

def discover_plg_test():
    yield Service()

def check_plg_test(ret_code):

    name = "plg_tst",
    service_name = "Plugin Test",
    discovery_function = discover_plg_test,
    check_function = check_plg_test(ret_code),

But the command
OMD[dev_1]:~$ cmk -L|grep plg

give this error:
Error in agent based plugin plg_tst: name ‘ret_code’ is not defined

My question: How can i use the return value from my script in the check_mk plugin.

Thanks for your help.

Best regards

Please format your script code as “preformatted text” to prevent the forum software from mangling the indentation etc. – thanks!



Hi Martin,

many thanks for your note.

Agent plugins are not called with any parameters. They are called by the check_mk_agent and whatever they print to stdout is transmitted to the checkmk server as part of the agent output.

I suggest reading this: Writing your own check plug-ins and especially the section about agent based plugins: Writing your own check plug-ins

1 Like