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