def test_fileinfo_min_max_age_levels():
    check = Check("prism_containers")

    item = u"prism-item"
    parsed = check.run_parse([
        [u'name', u'usage', u'capacity'],
        [u'prism-item', u'5', u'10'],
    ])

    output_expected = [
        BasicCheckResult(
            0,
            "Total: 10.00 B",
        ),
        BasicCheckResult(
            1,
            "Used: 5.00 B (warn/crit at 4.00 B/6.00 B)",
            [
                PerfValue('fs_used', 5, 4, 6, None, None),
            ],
        ),
    ]

    # percent levels
    output_perc_levels = check.run_check(item, {"levels": (40.0, 60.0)},
                                         parsed)
    assertCheckResultsEqual(
        CheckResult(output_perc_levels),
        CheckResult(output_expected),
    )

    # absolute levels
    output_abs_levels = check.run_check(item, {"levels": (4, 6)}, parsed)
    assertCheckResultsEqual(
        CheckResult(output_abs_levels),
        CheckResult(output_expected),
    )
def test_winperf_if_teaming_performance_data(check_manager, monkeypatch):
    check = check_manager.get_check("winperf_if")
    monkeypatch.setitem(check.context, "host_extra_conf", lambda _, __: [{}])
    monkeypatch.setitem(check.context, "_prepare_if_group_patterns_from_conf",
                        lambda: {})

    params_single = {'state': ['1'], 'speed': 10000000000}
    params_teamed = {
        'aggregate': {
            'item_type': 'index',
            'group_patterns': {
                'non-existent-testhost': {
                    'items': [],
                    'iftype': '6'
                }
            }
        },
        'state': ['1'],
        'speed': 20000000000
    }

    # Initalize counters
    monkeypatch.setattr('time.time', lambda: 0)
    parsed = winperf_if_teaming_parsed(time=0, out_octets=0)
    CheckResult(check.run_check(u'3', params_single, parsed))
    CheckResult(check.run_check(u'8', params_single, parsed))
    CheckResult(check.run_check(u'DAG-NET', params_teamed, parsed))

    # winperf_if should use the timestamp of the parsed data. To check
    # that it does not use time.time by accident we set it to 20s instead
    # of 10s. If winperf_if would now use time.time the Out value would only
    # be 512 MB/s instead of 1 GB/s.
    monkeypatch.setattr('time.time', lambda: 20)
    parsed = winperf_if_teaming_parsed(time=10,
                                       out_octets=1024 * 1024 * 1024 * 10)
    result_3 = CheckResult(check.run_check(u'3', params_single, parsed))
    result_8 = CheckResult(check.run_check(u'8', params_single, parsed))
    result_dag_net = CheckResult(
        check.run_check(u'DAG-NET', params_teamed, parsed))

    assert result_3 == CheckResult([
        BasicCheckResult(
            0,
            u'[SLOT 6 Port 1 DAG] (Connected) MAC: A0:36:9F:B0:A3:60, 10.00 Gbit/s, In: 0.00 B/s (0.0%), Out: 1.00 GB/s (85.9%)',
            [
                PerfValue('in', 0.0, None, None, 0, 1250000000.0),
                PerfValue('inucast', 0.0, None, None, None, None),
                PerfValue('innucast', 0.0, None, None, None, None),
                PerfValue('indisc', 0.0, None, None, None, None),
                PerfValue('inerr', 0.0, None, None, None, None),
                PerfValue('out', 1073741824.0, None, None, 0, 1250000000.0),
                PerfValue('outucast', 0.0, None, None, None, None),
                PerfValue('outnucast', 0.0, None, None, None, None),
                PerfValue('outdisc', 0.0, None, None, None, None),
                PerfValue('outerr', 0.0, None, None, None, None),
                PerfValue('outqlen', 0, None, None, None, None),
            ])
    ])
    assert result_8 == CheckResult([
        BasicCheckResult(
            0,
            u'[SLOT 4 Port 2 DAG] (Connected) MAC: A0:36:9F:B0:B3:66, 10.00 Gbit/s, In: 0.00 B/s (0.0%), Out: 1.00 GB/s (85.9%)',
            [
                PerfValue('in', 0.0, None, None, 0, 1250000000.0),
                PerfValue('inucast', 0.0, None, None, None, None),
                PerfValue('innucast', 0.0, None, None, None, None),
                PerfValue('indisc', 0.0, None, None, None, None),
                PerfValue('inerr', 0.0, None, None, None, None),
                PerfValue('out', 1073741824.0, None, None, 0, 1250000000.0),
                PerfValue('outucast', 0.0, None, None, None, None),
                PerfValue('outnucast', 0.0, None, None, None, None),
                PerfValue('outdisc', 0.0, None, None, None, None),
                PerfValue('outerr', 0.0, None, None, None, None),
                PerfValue('outqlen', 0, None, None, None, None),
            ])
    ])
    assert result_dag_net == CheckResult([
        BasicCheckResult(
            0,
            'Teaming Status (up), Members: [8 (Connected), 3 (Connected)] 20.00 Gbit/s, In: 0.00 B/s (0.0%), Out: 2.00 GB/s (85.9%)',
            [
                PerfValue('in', 0.0, None, None, 0, 2500000000.0),
                PerfValue('inucast', 0.0, None, None, None, None),
                PerfValue('innucast', 0.0, None, None, None, None),
                PerfValue('indisc', 0.0, None, None, None, None),
                PerfValue('inerr', 0.0, None, None, None, None),
                PerfValue('out', 2147483648.0, None, None, 0, 2500000000.0),
                PerfValue('outucast', 0.0, None, None, None, None),
                PerfValue('outnucast', 0.0, None, None, None, None),
                PerfValue('outdisc', 0.0, None, None, None, None),
                PerfValue('outerr', 0.0, None, None, None, None),
                PerfValue('outqlen', 0, None, None, None, None),
            ])
    ])
Exemple #3
0
         ('/AB', {}), ('/ABC', {})
     ], [('/AB', {}, BasicCheckResult(0, "Mount seems OK", None)),
         ('/ABC', {}, BasicCheckResult(0, "Mount seems OK", None))]),
 (  # Mountpoint with spaces and permission denied
     [[u'/var/dba', u'export', u'Permission',
       u'denied'], [u'/var/dbaexport', u'ok'] + size2.info], [
           ('/var/dbaexport', {}), ('/var/dba export', {})
       ], [('/var/dba export', {}, BasicCheckResult(2, 'Permission denied', None)),
           ('/var/dbaexport', {}, BasicCheckResult(0, size2.text, None))]),
 (  # with perfdata
     [[u'/PERFshare', u'ok'] + size1.info], [('/PERFshare', {})], [
         ('/PERFshare', {
             'has_perfdata': True
         },
          BasicCheckResult(0, size1.text, [
              PerfValue('fs_used', size1.used, 0.8 * size1.total, 0.9 * size1.total, 0,
                        size1.total),
              PerfValue('fs_size', size1.total),
          ]))
     ]),
 (  # state == 'hanging'
     [[u'/test', u'hanging', u'hanging', u'0', u'0', u'0', u'0']
     ], [('/test hanging', {})], [('/test hanging', {
         'has_perfdata': True
     }, BasicCheckResult(2, "Server not responding", None))]),
 (  # unknown state
     [[u'/test', u'unknown', u'unknown', u'1', u'1', u'1', u'1']], [('/test unknown', {})], [
         ('/test unknown', {}, BasicCheckResult(2, "Unknown state: unknown", None))
     ]),
 (  # zero block size
     [[u'/test', u'perfdata', u'ok', u'0', u'460182', u'460182', u'0']],
     [('/test perfdata', {})],
def test_fileinfo_min_max_age_levels():
    # This test has the following purpose:
    # For each file attr (size or age) the levels 'min*', 'max*' are evaluated.
    # 'min*' is evaluated first and if 'max*' returns state '0' (eg. not set)
    # the service state is also '0'.

    check = Check("fileinfo")
    item = u'c:\\filetest\\check_mk.txt'
    parsed = check.run_parse([
        [u'8'],
        [u'c:\\filetest\\check_mk.txt', u'7', u'5'],
    ])

    size_result = BasicCheckResult(
        0,
        "Size: 7 B",
        [
            PerfValue('size', 7, None, None, None, None),
        ],
    )

    # minage matches
    output_minage = check.run_check(item, {
        'minage': (5, 1),
    }, parsed)

    # In 1.6.0 warn, crit of minage was added, but now we use the
    # generic check_levels function.
    assertCheckResultsEqual(
        CheckResult(output_minage),
        CheckResult([
            size_result,
            BasicCheckResult(
                1,
                "Age: 3.00 s (warn/crit below 5.00 s/1.00 s)",
                [
                    PerfValue('age', 3, None, None, None, None),
                ],
            ),
        ]))

    # maxage matches
    output_maxage = check.run_check(item, {
        'maxage': (1, 2),
    }, parsed)

    assertCheckResultsEqual(
        CheckResult(output_maxage),
        CheckResult([
            size_result,
            BasicCheckResult(
                2,
                "Age: 3.00 s (warn/crit at 1.00 s/2.00 s)",
                [
                    PerfValue('age', 3, 1, 2, None, None),
                ],
            ),
        ]))

    # both match
    # This should never happen (misconfiguration), but test the order
    # of min* vs. max* and perfdata (always take the upper levels)
    # In 1.6.0 levels text of minage was added, but now we use the
    # generic check_levels function.
    output_both = check.run_check(item, {
        'minage': (5, 1),
        'maxage': (1, 2),
    }, parsed)

    assertCheckResultsEqual(
        CheckResult(output_both),
        CheckResult([
            size_result,
            BasicCheckResult(
                2,
                "Age: 3.00 s (warn/crit at 1.00 s/2.00 s)",
                [
                    PerfValue('age', 3, 1, 2, None, None),
                ],
            ),
        ]))
 (  # Mountpoint with spaces and permission denied
     [[u'/var/dba', u'export', u'Permission', u'denied'],
      [u'/var/dbaexport', u'ok'] + size2.info], [
          ('/var/dbaexport', {}), ('/var/dba export', {})
      ], [('/var/dba export', {},
           BasicCheckResult(2, 'Permission denied', None)),
          ('/var/dbaexport', {}, BasicCheckResult(0, size2.text, None))
          ]),
 (  # with perfdata
     [[u'/PERFshare', u'ok'] + size1.info], [('/PERFshare', {})],
     [('/PERFshare',
       {
           'has_perfdata': True
       },
       BasicCheckResult(0, size1.text, [
           PerfValue('fs_used', size1.used, 0.8 * size1.total,
                     0.9 * size1.total, 0, size1.total),
           PerfValue('fs_size', size1.total),
           PerfValue('fs_growth', 0),
           PerfValue('fs_trend', 0, None, None, 0, 15534.459259259258),
       ]))]),
 (  # state == 'hanging'
     [[u'/test', u'hanging', u'hanging', u'0', u'0', u'0', u'0']
      ], [('/test hanging', {})], [('/test hanging', {
          'has_perfdata': True
      }, BasicCheckResult(2, "Server not responding", None))]),
 (  # unknown state
     [[u'/test', u'unknown', u'unknown', u'1', u'1', u'1', u'1']], [
         ('/test unknown', {})
     ], [('/test unknown', {},
          BasicCheckResult(2, "Unknown state: unknown", None))]),
 (  # zero block size
          u'170803720', u'32768'
      ]], [('/var/dbaexport', {}), ('/var/dba export', {})], [
          ('/var/dba export', {},
           BasicCheckResult(2, 'Permission denied', None)),
          ('/var/dbaexport', {},
           BasicCheckResult(0, '15.2% used (931.48 GB of 6.00 TB)',
                            None))
      ]),
 (  # with perfdata
     [[u'/PERFshare', u'ok', u'491520', u'460182', u'460182', u'65536']
      ], [('/PERFshare', {})], [
          ('/PERFshare', {
              'has_perfdata': True
          },
           BasicCheckResult(0, "6.4% used (1.91 GB of 30.00 GB)", [
               PerfValue('fs_size', 491520 * 65536),
               PerfValue('fs_used', 491520 * 65536 - 460182 * 65536)
           ]))
      ]),
 (  # state == 'hanging'
     [[u'/test', u'hanging', u'hanging', u'0', u'0', u'0', u'0']
      ], [('/test hanging', {})], [('/test hanging', {
          'has_perfdata': True
      }, BasicCheckResult(2, "Server not responding", None))]),
 (  # unknown state
     [[u'/test', u'unknown', u'unknown', u'1', u'1', u'1', u'1']], [
         ('/test unknown', {})
     ], [('/test unknown', {}, BasicCheckResult(2, "Unknown state",
                                                None))]),
 (  # zero block size
     [[u'/test', u'perfdata', u'ok', u'0', u'460182', u'460182', u'0']],