测试check mk checks的pytest插件

pytest-check-mk的Python项目详细描述


Build Status

用于py.test测试的插件 Check_MK支票。

用法

以下示例包含用于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授权的。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
字符串中的java日期到日期转换中的日期   swt在Java方法中使用标志的最佳实践   日期如何读取从Youtube API Kotlin/Java返回的视频的持续时间   java无法将任何内容写入文件   java为什么将字符串转换为double可能会丢失精度?   java添加到已设置/填充的数组   java 安卓可扩展列表视图从firebase检索数据   java MsAccess SQL异常参数太少   ConcurrentHashMap中的java lock()方法   SpringBoot如何在Java(SpringBoot2)和GCP数据存储中创建种子数据   java如何在会话中设置对象并在所有控制器中使用它?   eclipse如何在java中转换XML格式的表数据   java写入Google持久磁盘   java循环数组循环,检测   java ThreeTenBackport实现与JSR310的backport?   java如何动态填充注释   数组中的java新运算符