测试check mk checks的pytest插件
pytest-check-mk的Python项目详细描述
用法
以下示例包含用于foobar检查的测试套件 包含在check-mk安装中(请参见 share/doc/check_mk/skeleton_check)。检查文件需要命名 在其代理部分之后,即foobar。
目录布局
├── agents │ └── plugins │ └── foobar_linux ├── checks │ └── foobar └── test └── test_foobar.py
测试试剂
agents目录中的所有可执行文件都可以使用 agents设备:
def test_agent_plugin(agent): assert agents['plugins/foobar_linux'].run() == '<<<foobar>>>\nFOO BAR\n'
也可以将命令行参数传递给代理 插件:
def test_fritzbox_agent(agents): assert '<<<fritz>>>' in agents['special/agent_fritzbox'].run('--timeout', '20', 'fritz.box')
测试检查
在单个测试文件中,可以测试一个检查文件。的名称 check file是用test_for模块级变量设置的。
from pytest_check_mk import OK, WARNING, CRITICAL, UNKNOWN test_for = 'foobar' sample_plugin_output = ''' <<<foobar>>> FOO BAR ''' def test_inventory(checks): assert checks['foobar'].inventory(sample_plugin_output) == [] def test_check(checks): item = None params = None assert checks['foobar'].check(item, params, sample_plugin_output) == (UNKNOWN, 'UNKNOWN - Check not implemented') def test_settings(checks): assert checks['foobar'].service_description == 'FOOBAR' assert not checks['foobar'].has_perfdata
使用代理数据进行测试检查
有一种“确保一切工作在一起”的论断。它 使用给定的代理输出调用inventory和check函数 检查返回值是否与预期格式匹配。
from pytest_check_mk.assertions import assert_inventory_and_check_works_with_check_output test_for = 'foobar' def test_check_with_agent_output(agent, checks): output = agents['plugins/foobar_linux'].run() assert_inventory_and_check_works_with_check_output(checks['foobar'], output)
许可证
此软件是根据GPLV2授权的。