-
-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathrun
More file actions
executable file
·72 lines (59 loc) · 2.21 KB
/
run
File metadata and controls
executable file
·72 lines (59 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
# -*- coding: utf-8; py-indent-offset: 4 -*-
#
# Author: Linuxfabrik GmbH, Zurich, Switzerland
# Contact: info (at) linuxfabrik (dot) ch
# https://www.linuxfabrik.ch/
# License: The Unlicense, see LICENSE file.
# https://github.com/Linuxfabrik/monitoring-plugins/blob/main/CONTRIBUTING.md
import sys
sys.path.insert(0, '..')
import unittest
import lib.lftest
from lib.globals import STATE_CRIT, STATE_OK, STATE_WARN
# Fixture files in stdout/ are named after the scenario (the shape of the
# data), not after the expected plugin state. The expected state lives in
# the testcase `id` and depends on the combination of fixture content and
# plugin parameters. The same fixture can therefore drive multiple
# testcases that vary --warning/--critical (or any other parameter) to
# reach different states. See CONTRIBUTING.md for the full convention.
#
# The humidity-42-percent fixture contains the raw reading from the
# Linux hwmon humidity sensor. The skeleton parses the first integer
# from stdout as its value. The four testcases below reuse that one
# fixture and only differ in thresholds and switches.
TESTS = [
{
'id': 'ok-below-warn',
'test': 'stdout/humidity-42-percent,,0',
'params': '--token=dummy --warning 80 --critical 90',
'assert-retc': STATE_OK,
'assert-in': ['42%'],
},
{
'id': 'warn-above-warn',
'test': 'stdout/humidity-42-percent,,0',
'params': '--token=dummy --warning 40 --critical 90',
'assert-retc': STATE_WARN,
'assert-regex': r'42%.*\[WARNING\]',
},
{
'id': 'crit-above-crit',
'test': 'stdout/humidity-42-percent,,0',
'params': '--token=dummy --warning 30 --critical 40',
'assert-retc': STATE_CRIT,
'assert-regex': r'42%.*\[CRITICAL\]',
},
{
'id': 'ok-always-ok-masks-crit',
'test': 'stdout/humidity-42-percent,,0',
'params': '--token=dummy --warning 30 --critical 40 --always-ok',
'assert-retc': STATE_OK,
'assert-regex': r'42%.*\[CRITICAL\]',
},
]
class TestCheck(unittest.TestCase):
check = '../example'
lib.lftest.attach_tests(TestCheck, TESTS)
if __name__ == '__main__':
unittest.main()