def test_bin_value(self): eo = NagErrors() ev = NagEval(eo) ev.evalEnum('OKVal', okValues=['OKVal']) self.assertEqual(len(eo.critical), 0) self.assertEqual(len(eo.warning), 0) self.assertEqual(len(eo.unknown), 0) self.assertEqual(eo.getExitCode(), 0) ev.evalEnum('WarningVal', warningValues=['WarningVal']) self.assertEqual(len(eo.critical), 0) self.assertEqual(len(eo.warning), 1) self.assertEqual(len(eo.unknown), 0) self.assertEqual(eo.getExitCode(), 1) ev.evalEnum('CriticalVal', criticalValues=['CriticalVal']) self.assertEqual(len(eo.critical), 1) self.assertEqual(len(eo.warning), 1) self.assertEqual(len(eo.unknown), 0) self.assertEqual(eo.getExitCode(), 2) ev.evalEnum('UnknownVal', unknownValues=['UnknownVal']) self.assertEqual(len(eo.critical), 1) self.assertEqual(len(eo.warning), 1) self.assertEqual(len(eo.unknown), 1) self.assertEqual(eo.getExitCode(), 3) eo = NagErrors() ev = NagEval(eo) ev.evalEnum('OKVal', okValues=['OKVal'], warningValues=['WarningVal'], criticalValues=['CriticalVal'], unknownValues=['UnknownVal']) self.assertEqual(len(eo.critical), 0) self.assertEqual(len(eo.warning), 0) self.assertEqual(len(eo.unknown), 0) self.assertEqual(eo.getExitCode(), 0) ev.evalEnum('WarningVal', okValues=['OKVal'], warningValues=['WarningVal'], criticalValues=['CriticalVal'], unknownValues=['UnknownVal']) self.assertEqual(len(eo.critical), 0) self.assertEqual(len(eo.warning), 1) self.assertEqual(len(eo.unknown), 0) self.assertEqual(eo.getExitCode(), 1) ev.evalEnum('CriticalVal', okValues=['OKVal'], warningValues=['WarningVal'], criticalValues=['CriticalVal'], unknownValues=['UnknownVal']) self.assertEqual(len(eo.critical), 1) self.assertEqual(len(eo.warning), 1) self.assertEqual(len(eo.unknown), 0) self.assertEqual(eo.getExitCode(), 2) ev.evalEnum('UnknownVal', okValues=['OKVal'], warningValues=['WarningVal'], criticalValues=['CriticalVal'], unknownValues=['UnknownVal']) self.assertEqual(len(eo.critical), 1) self.assertEqual(len(eo.warning), 1) self.assertEqual(len(eo.unknown), 1) self.assertEqual(eo.getExitCode(), 3)
def test_unknownValues(self): eo = NagErrors() ev = NagEval(eo) ev.evalListEnum(['junkVal'], unknownValueStatus="OK") self.assertEqual(len(eo.critical), 0) self.assertEqual(len(eo.warning), 0) self.assertEqual(len(eo.unknown), 0) self.assertEqual(eo.getExitCode(), 0) ev.evalListEnum(['junkVal'], unknownValueStatus="WARNING") self.assertEqual(len(eo.critical), 0) self.assertEqual(len(eo.warning), 1) self.assertEqual(len(eo.unknown), 0) self.assertEqual(eo.getExitCode(), 1) ev.evalListEnum(['junkVal'], unknownValueStatus="CRITICAL") self.assertEqual(len(eo.critical), 1) self.assertEqual(len(eo.warning), 1) self.assertEqual(len(eo.unknown), 0) self.assertEqual(eo.getExitCode(), 2) ev.evalListEnum(['junkVal']) self.assertEqual(len(eo.critical), 1) self.assertEqual(len(eo.warning), 1) self.assertEqual(len(eo.unknown), 1) self.assertEqual(eo.getExitCode(), 3)
def test_addCritical(self): eo = NagErrors() eo.addCritical('Critical Error') self.assertEqual(len(eo.critical), 1) self.assertEqual(len(eo.warning), 0) self.assertEqual(len(eo.unknown), 0) self.assertEqual(eo.getExitCode(), 2)
def test_default(self): eo = NagErrors() ev = NagEval(eo) ev.evalEnum('Junk', defaultStatus='OK') self.assertEqual(len(eo.critical), 0) self.assertEqual(len(eo.warning), 0) self.assertEqual(len(eo.unknown), 0) self.assertEqual(eo.getExitCode(), 0) ev.evalEnum('Junk', defaultStatus='WARNING') self.assertEqual(len(eo.critical), 0) self.assertEqual(len(eo.warning), 1) self.assertEqual(len(eo.unknown), 0) self.assertEqual(eo.getExitCode(), 1) ev.evalEnum('Junk', defaultStatus='CRITICAL') self.assertEqual(len(eo.critical), 1) self.assertEqual(len(eo.warning), 1) self.assertEqual(len(eo.unknown), 0) self.assertEqual(eo.getExitCode(), 2) ev.evalEnum('Junk', defaultStatus='UNKNOWN') self.assertEqual(len(eo.critical), 1) self.assertEqual(len(eo.warning), 1) self.assertEqual(len(eo.unknown), 1) self.assertEqual(eo.getExitCode(), 3)
def test_bin_valuelist(self): eo = NagErrors() ev = NagEval(eo) ev.evalListNumberDesc([5, 200, 52, 4000], warningBelow=2000, criticalBelow=100) self.assertEqual(len(eo.critical), 2) self.assertEqual(len(eo.warning), 1) self.assertEqual(len(eo.unknown), 0) self.assertEqual(eo.getExitCode(), 2)
def test_string(self): eo = NagErrors() ev = NagEval(eo) ev.evalListEnum('WarningVal', warningValues=['WarningVal']) self.assertEqual(len(eo.critical), 0) self.assertEqual(len(eo.warning), 1) self.assertEqual(len(eo.unknown), 0) self.assertEqual(eo.warning[0], "value is WarningVal") self.assertEqual(eo.getExitCode(), 1)
def test_string(self): eo = NagErrors() ev = NagEval(eo) ev.evalListNumberAsc(50, warningAbove=25, criticalAbove=100) self.assertEqual(len(eo.critical), 0) self.assertEqual(len(eo.warning), 1) self.assertEqual(len(eo.unknown), 0) self.assertEqual(eo.warning[0], "50 is > 25") self.assertEqual(eo.getExitCode(), 1)
def test_string(self): eo = NagErrors() ev = NagEval(eo) ev.evalListNumberDesc(55, warningBelow=100, criticalBelow=50) self.assertEqual(len(eo.critical), 0) self.assertEqual(len(eo.warning), 1) self.assertEqual(len(eo.unknown), 0) self.assertEqual(eo.warning[0], "55 is < 100") self.assertEqual(eo.getExitCode(), 1)
def test_emptyList(self): eo = NagErrors() ev = NagEval(eo) ev.evalListNumberDesc([], emptyStatus="OK") self.assertEqual(len(eo.critical), 0) self.assertEqual(len(eo.warning), 0) self.assertEqual(len(eo.unknown), 0) self.assertEqual(eo.getExitCode(), 0) ev.evalListNumberDesc([], emptyStatus="WARNING") self.assertEqual(eo.warning[0], "list is Empty") self.assertEqual(eo.getExitCode(), 1)
def test_prefixText(self): eo = NagErrors() ev = NagEval(eo) ev.evalListNumberDesc([45], warningBelow=50, postfixText=" Units") self.assertEqual(eo.warning[0], "45 is < 50 Units")
def test_numberUnits(self): eo = NagErrors() ev = NagEval(eo) ev.evalListNumberDesc([45], warningBelow=50, numberUnits="sec") self.assertEqual(eo.warning[0], "45sec is < 50sec")
def test_swappedTresholds(self): eo = NagErrors() ev = NagEval(eo) ev.evalListNumberDesc([21], warningBelow=50, criticalBelow=40) self.assertEqual(eo.getExitCode(), 2)
def test_negative_high(self): eo = NagErrors() ev = NagEval(eo) ev.evalListNumberDesc([-3], warningBelow=-5, criticalBelow=-10) self.assertEqual(eo.getExitCode(), 0)
def test_high(self): eo = NagErrors() ev = NagEval(eo) ev.evalListNumberDesc([55], warningBelow=50, criticalBelow=40) self.assertEqual(eo.getExitCode(), 0)
def test_high(self): eo = NagErrors() ev = NagEval(eo) ev.evalListNumberAsc([55], warningAbove=40, criticalAbove=50) self.assertEqual(eo.getExitCode(), 2)
def test_mid(self): eo = NagErrors() ev = NagEval(eo) ev.evalNumberDesc(45, warningBelow=50, criticalBelow=40) self.assertEqual(eo.getExitCode(), 1)
def test_formatStatus(self): eo = NagErrors() self.assertEqual(eo.formatStatus('WARNING', ['String1']), "WARNING String1\r\n") self.assertEqual(eo.formatStatus('WARNING', ['String1', 'String2']), "WARNING:\r\n String1\r\n String2\r\n")
def test_prefixText(self): eo = NagErrors() ev = NagEval(eo) ev.evalEnum('Warning', warningValues=['Warning'], prefixText="Test ") self.assertEqual(eo.warning[0], "Test value is Warning")
def test_numberUnits(self): eo = NagErrors() ev = NagEval(eo) ev.evalListNumberAsc([45], warningAbove=40, numberUnits="sec") self.assertEqual(eo.warning[0], "45sec is > 40sec")
def test_swappedTresholds(self): eo = NagErrors() ev = NagEval(eo) ev.evalListNumberAsc([51], warningAbove=50, criticalAbove=40) self.assertEqual(eo.getExitCode(), 2)
def test_negative_high(self): eo = NagErrors() ev = NagEval(eo) ev.evalListNumberAsc([-3], warningAbove=-10, criticalAbove=-5) self.assertEqual(eo.getExitCode(), 2)
def test_negative_mid(self): eo = NagErrors() ev = NagEval(eo) ev.evalNumberAsc(-8, warningAbove=-10, criticalAbove=-5) self.assertEqual(eo.getExitCode(), 1)
def test_mid(self): eo = NagErrors() ev = NagEval(eo) ev.evalNumberAsc(45, warningAbove=40, criticalAbove=50) self.assertEqual(eo.getExitCode(), 1)
def test_negative_mid(self): eo = NagErrors() ev = NagEval(eo) ev.evalNumberDesc(-8, warningBelow=-5, criticalBelow=-10) self.assertEqual(eo.getExitCode(), 1)
def test_prefixText(self): eo = NagErrors() ev = NagEval(eo) ev.evalNumberDesc(45, warningBelow=50, prefixText="Test ") self.assertEqual(eo.warning[0], "Test 45 is < 50")
def test_prefixText(self): eo = NagErrors() ev = NagEval(eo) ev.evalListNumberAsc([45], warningAbove=40, postfixText=" Units") self.assertEqual(eo.warning[0], "45 is > 40 Units")
def test_prefixText(self): eo = NagErrors() ev = NagEval(eo) ev.evalNumberAsc(45, warningAbove=40, prefixText="Test ") self.assertEqual(eo.warning[0], "Test 45 is > 40")
def test_postfixText(self): eo = NagErrors() ev = NagEval(eo) ev.evalEnum('Warning', warningValues=['Warning'], postfixText=" String") self.assertEqual(eo.warning[0], "value is Warning String")
def test_okStatus(self): eo = NagErrors() self.assertEqual(len(eo.critical), 0) self.assertEqual(len(eo.warning), 0) self.assertEqual(len(eo.unknown), 0) self.assertEqual(eo.getExitCode(), 0)