Exemple #1
0
    def test_reach(self):
        check = CheckNTPMon()

        for i in [0, 0.01, 1, 25, 49, 49.99, 50]:
            self.assertEqual(check.reachability(i), 2, 'Low reachability non-critical')
        for i in [50.01, 50.1, 74.99, 75]:
            self.assertEqual(check.reachability(i), 1, 'Moderate reachability non-warning')
        for i in [75.01, 76, 99, 100]:
            self.assertEqual(check.reachability(i), 0, 'High reachability non-OK')
        # check that invalid percentage causes exception
        for i in [-100, -1, 100.01, 101, 1000]:
            self.assertRaises(ValueError, check.reachability, (i))
Exemple #2
0
    def test_NTPPeer4(self):
        # check the parsing done by NTPPeers
        ntp = NTPPeers(testdata[4].split("\n"))
        self.assertEqual(ntp.ntpdata.get('syncpeer'), None)
        self.assertEqual(ntp.ntpdata.get('offsetsyncpeer'), None)
        self.assertEqual(ntp.ntpdata['survivors'], 2)
        self.assertEqual(ntp.ntpdata.get('averageoffsetsurvivors'), 2.7969999999999997)
        self.assertEqual(ntp.ntpdata['discards'], 2)
        self.assertEqual(ntp.ntpdata['averageoffsetdiscards'], 14.9545)
        self.assertEqual(ntp.ntpdata['peers'], 4)
        self.assertEqual(ntp.ntpdata['averageoffset'], 8.87575)
        self.assertEqual(ntp.ntpdata['reachability'], 62.5)

        # run checks on the data
        check = CheckNTPMon()
        self.assertEqual(check.offset(ntp.ntpdata['averageoffsetdiscards']), 1, 'Discards offset non-warning')
        self.assertEqual(check.offset(ntp.ntpdata['averageoffset']), 0, 'Offset non-OK')
        self.assertEqual(check.peers(ntp.ntpdata['peers']), 0, 'Peers non-OK')
        self.assertEqual(check.reachability(ntp.ntpdata['reachability']), 1, 'Reachability non-warning')

        # run overall health checks
        self.assertEqual(ntp.check_sync(), 1, 'Missing sync peer non-warning')
        self.assertEqual(ntp.check_offset(), 0, 'Normal offset non-OK')
        self.assertEqual(ntp.check_peers(), 0, 'OK peer count non-OK')
        self.assertEqual(ntp.check_reachability(), 1, 'Low reachability non-critical')
Exemple #3
0
    def test_NTPPeer3(self):
        # check the parsing done by NTPPeers
        ntp = NTPPeers(testdata[3].split("\n"))
        self.assertEqual(ntp.ntpdata.get('syncpeer'), None)
        self.assertEqual(ntp.ntpdata.get('offsetsyncpeer'), None)
        self.assertEqual(ntp.ntpdata['survivors'], 0)
        self.assertEqual(ntp.ntpdata.get('averageoffsetsurvivors'), None)
        self.assertEqual(ntp.ntpdata['discards'], 1)
        self.assertEqual(ntp.ntpdata['averageoffsetdiscards'], 0.913)
        self.assertEqual(ntp.ntpdata['peers'], 1)
        self.assertEqual(ntp.ntpdata['averageoffset'], 0.913)
        self.assertEqual(ntp.ntpdata['reachability'], 37.5)

        # run checks on the data
        check = CheckNTPMon()
        self.assertEqual(check.offset(ntp.ntpdata['averageoffsetdiscards']), 0, 'Low offset non-OK')
        self.assertEqual(check.offset(ntp.ntpdata['averageoffset']), 0, 'Low offset non-OK')
        self.assertEqual(check.peers(ntp.ntpdata['peers']), 2, 'Low peers non-critical')
        self.assertEqual(check.reachability(ntp.ntpdata['reachability']), 2,
                         'Low reachability non-critical')

        # run overall health checks
        self.assertEqual(ntp.check_sync(), 2, 'Missing sync peer not detected')
        self.assertEqual(ntp.check_offset(), 1, 'Missing sync peer/survivor offset non-warning')
        self.assertEqual(ntp.check_peers(), 2, 'Low peers non-critical')
        self.assertEqual(ntp.check_reachability(), 2, 'Low reachability non-critical')
Exemple #4
0
    def test_NTPPeer2(self):
        # check the parsing done by NTPPeers
        ntp = NTPPeers(testdata[2].split("\n"))
        self.assertEqual(ntp.ntpdata['syncpeer'], '91.189.94.4')
        self.assertEqual(ntp.ntpdata['offsetsyncpeer'], 194.54)
        self.assertEqual(ntp.ntpdata['survivors'], 1)
        self.assertEqual(ntp.ntpdata['averageoffsetsurvivors'], 194.54)
        self.assertEqual(ntp.ntpdata['discards'], 0)
        self.assertEqual(ntp.ntpdata.get('averageoffsetdiscards'), None)
        self.assertEqual(ntp.ntpdata['peers'], 1)
        self.assertEqual(ntp.ntpdata['averageoffset'], 194.54)
        self.assertEqual(ntp.ntpdata['reachability'], 100)

        # run checks on the data
        check = CheckNTPMon()
        self.assertEqual(check.sync(ntp.ntpdata['syncpeer']), 0, 'Sync peer not detected')
        self.assertEqual(check.offset(ntp.ntpdata['offsetsyncpeer']), 2, 'High offset non-critical')
        self.assertEqual(check.offset(ntp.ntpdata['averageoffsetsurvivors']), 2, 'High offset non-critical')
        self.assertEqual(ntp.ntpdata.get('averageoffsetdiscards'), None)
        self.assertEqual(check.offset(ntp.ntpdata['averageoffset']), 2, 'High offset non-critical')
        self.assertEqual(check.peers(ntp.ntpdata['peers']), 2, 'Low peers non-critical')
        self.assertEqual(check.reachability(ntp.ntpdata['reachability']), 0,
                         'High reachability non-OK')

        # run overall health checks
        self.assertEqual(ntp.check_sync(), 0, 'Sync peer not detected')
        self.assertEqual(ntp.check_offset(), 2, 'High offset non-critical')
        self.assertEqual(ntp.check_peers(), 2, 'Low peers non-critical')
        self.assertEqual(ntp.check_reachability(), 0, 'High reachability non-OK')
Exemple #5
0
    def test_NTPPeer1(self):
        # check the parsing done by NTPPeers
        ntp = NTPPeers(testdata[1].split("\n"))
        self.assertEqual(ntp.ntpdata['syncpeer'], '202.60.94.11')
        self.assertEqual(ntp.ntpdata['offsetsyncpeer'], 0.259)
        self.assertEqual(ntp.ntpdata['survivors'], 3)
        self.assertEqual(ntp.ntpdata['averageoffsetsurvivors'], 0.21133333333333335)
        self.assertEqual(ntp.ntpdata['discards'], 3)
        self.assertEqual(ntp.ntpdata['averageoffsetdiscards'], 1.024)
        self.assertEqual(ntp.ntpdata['peers'], 6)
        self.assertEqual(ntp.ntpdata['averageoffset'], 0.6176666666666667)
        self.assertEqual(ntp.ntpdata['reachability'], 100)

        # run checks on the data
        check = CheckNTPMon()
        self.assertEqual(check.sync(ntp.ntpdata['syncpeer']), 0, 'Sync peer not detected')
        self.assertEqual(check.offset(ntp.ntpdata['offsetsyncpeer']), 0, 'Low offset non-OK')
        self.assertEqual(check.offset(ntp.ntpdata['averageoffsetsurvivors']), 0, 'Low offset non-OK')
        self.assertEqual(check.offset(ntp.ntpdata['averageoffsetdiscards']), 0, 'Low offset non-OK')
        self.assertEqual(check.offset(ntp.ntpdata['averageoffset']), 0, 'Low offset non-OK')
        self.assertEqual(check.peers(ntp.ntpdata['peers']), 0, 'High peers non-OK')
        self.assertEqual(check.reachability(ntp.ntpdata['reachability']), 0,
                         'High reachability non-OK')

        # run overall health checks
        self.assertEqual(ntp.check_sync(), 0, 'Sync peer not detected')
        self.assertEqual(ntp.check_offset(), 0, 'Low offset non-OK')
        self.assertEqual(ntp.check_peers(), 0, 'High peers non-OK')
        self.assertEqual(ntp.check_reachability(), 0, 'High reachability non-OK')