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/lib/check_mk_agent/plugins/plg_tst.py:


*#!/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

<<<“plg_tst”>>>
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):
  print(ret_code)

register.check_plugin(
    name = "plg_tst",
    service_name = "Plugin Test",
    check_ruleset_name="plg_tst",
    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
Peter

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

discourse-preformatted-text

2 Likes

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

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.