mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-29 20:21:35 +03:00
Implement Threasholds classes
This commit is contained in:
parent
822a0735dd
commit
a2f97d56d3
@ -548,7 +548,7 @@ class GlancesPlugin(object):
|
||||
# Manage action
|
||||
self.manage_action(stat_name, ret.lower(), header, action_key)
|
||||
|
||||
# Default is ok
|
||||
# Default is 'OK'
|
||||
return ret + log_str
|
||||
|
||||
def manage_action(self,
|
||||
|
75
glances/thresholds.py
Normal file
75
glances/thresholds.py
Normal file
@ -0,0 +1,75 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# This file is part of Glances.
|
||||
#
|
||||
# Copyright (C) 2017 Nicolargo <nicolas@nicolargo.com>
|
||||
#
|
||||
# Glances is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Glances is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
Thresholds classes: OK, CAREFUL, WARNING, CRITICAL
|
||||
"""
|
||||
|
||||
|
||||
class _GlancesThreshold(object):
|
||||
|
||||
"""Father class for all other Thresholds"""
|
||||
|
||||
def description(self):
|
||||
return self._threshold['description']
|
||||
|
||||
def value(self):
|
||||
return self._threshold['value']
|
||||
|
||||
def __repr__(self):
|
||||
return self._threshold
|
||||
|
||||
def __str__(self):
|
||||
return self.description()
|
||||
|
||||
def __cmp__(self, other):
|
||||
"""Override the default comparaison behavior"""
|
||||
return self.value().__cmp__(other.value())
|
||||
|
||||
|
||||
class GlancesThresholdOk(_GlancesThreshold):
|
||||
|
||||
"""Ok Threshold class"""
|
||||
|
||||
_threshold = {'description': 'OK',
|
||||
'value': 0}
|
||||
|
||||
|
||||
class GlancesThresholdCareful(_GlancesThreshold):
|
||||
|
||||
"""Careful Threshold class"""
|
||||
|
||||
_threshold = {'description': 'CAREFUL',
|
||||
'value': 1}
|
||||
|
||||
|
||||
class GlancesThresholdWarning(_GlancesThreshold):
|
||||
|
||||
"""Warning Threshold class"""
|
||||
|
||||
_threshold = {'description': 'WARNING',
|
||||
'value': 2}
|
||||
|
||||
|
||||
class GlancesThresholdCritical(_GlancesThreshold):
|
||||
|
||||
"""Warning Threshold class"""
|
||||
|
||||
_threshold = {'description': 'CRITICAL',
|
||||
'value': 3}
|
18
unitest.py
18
unitest.py
@ -28,6 +28,10 @@ from glances.stats import GlancesStats
|
||||
from glances import __version__
|
||||
from glances.globals import WINDOWS, LINUX
|
||||
from glances.outputs.glances_bars import Bar
|
||||
from glances.thresholds import GlancesThresholdOk
|
||||
from glances.thresholds import GlancesThresholdCareful
|
||||
from glances.thresholds import GlancesThresholdWarning
|
||||
from glances.thresholds import GlancesThresholdCritical
|
||||
|
||||
# Global variables
|
||||
# =================
|
||||
@ -205,6 +209,20 @@ class TestGlances(unittest.TestCase):
|
||||
self.assertTrue(type(stats_grab) is list, msg='GPU stats is not a list')
|
||||
print('INFO: GPU stats: %s' % stats_grab)
|
||||
|
||||
def test_094_thresholds(self):
|
||||
"""Test thresholds classes"""
|
||||
print('INFO: [TEST_094] Mandatories methods')
|
||||
ok = GlancesThresholdOk()
|
||||
careful = GlancesThresholdCareful()
|
||||
warning = GlancesThresholdWarning()
|
||||
critical = GlancesThresholdCritical()
|
||||
self.assertTrue(ok < careful)
|
||||
self.assertTrue(careful < warning)
|
||||
self.assertTrue(warning < critical)
|
||||
self.assertFalse(ok > careful)
|
||||
self.assertTrue(ok == ok)
|
||||
self.assertTrue(str(ok) == 'OK')
|
||||
|
||||
def test_095_methods(self):
|
||||
"""Test mandatories methods"""
|
||||
print('INFO: [TEST_095] Mandatories methods')
|
||||
|
Loading…
Reference in New Issue
Block a user