Ejemplo n.º 1
0
    def test3_checkArgsMatchRules(self):
        """
        Given 2 invalid arguments 'integer1' and 'integer2',
        Should return 'False'
        """
        integer1Value = 12.34
        integer2Value = 'a'
        integerRule = '(\d+)'

        myUtility = Utility.Utility()
        myDebug = Debug.Debug()

        myCommandLine = CommandLine.CommandLine(description='Blah blah blah.',
                                                objDebug=myDebug,
                                                objUtility=myUtility)

        myCommandLine._argDict['integer1'] = {
            'value': integer1Value,
            'rule': integerRule,
        }
        myCommandLine._argDict['integer2'] = {
            'value': integer2Value,
            'rule': integerRule,
        }

        self.assertEqual(myCommandLine.checkArgsMatchRules(), False)
Ejemplo n.º 2
0
    def test3_checkOrArgGroups(self):
        """
        Given no argument while expecting 2 'orArg' arguments in a single group,
        Should return 'False' and an error message
        """
        myUtility = Utility.Utility()
        myDebug = Debug.Debug()

        myCommandLine = CommandLine.CommandLine(description='Blah blah blah.',
                                                objDebug=myDebug,
                                                objUtility=myUtility)

        myCommandLine._argDict['arg1'] = {
            'value': None,
            'orArgGroup': 'group1'
        }

        myCommandLine._argDict['arg2'] = {
            'value': None,
            'orArgGroup': 'group1'
        }

        orArgsAreOk, message = myCommandLine.checkOrArgGroups()
        self.assertFalse(orArgsAreOk)
        self.assertNotEqual(message, '')
Ejemplo n.º 3
0
    def test6_computeExitStatus(self):
        """
        Given 3 values : metric < crit < warn
	should return 'CRITICAL'
        """
        myDebug = Debug.Debug()
        myPlugin = NagiosPlugin.NagiosPlugin(name='bla', objDebug=myDebug)
        self.assertEqual(myPlugin.computeExitStatus(1, 3, 2), 'CRITICAL')
Ejemplo n.º 4
0
    def test5_computeExitStatus(self):
        """
        Given 3 values : crit < metric < warn
	should return 'WARNING'
        """
        myDebug = Debug.Debug()
        myPlugin = NagiosPlugin.NagiosPlugin(name='bla', objDebug=myDebug)
        self.assertEqual(myPlugin.computeExitStatus(2, 3, 1), 'WARNING')
Ejemplo n.º 5
0
    def test4_computeExitStatus(self):
        """
        Given 3 values : crit < warn < metric
	should return 'OK'
        """
        myDebug = Debug.Debug()
        myPlugin = NagiosPlugin.NagiosPlugin(name='bla', objDebug=myDebug)
        self.assertEqual(myPlugin.computeExitStatus(3, 2, 1), 'OK')
Ejemplo n.º 6
0
    def test3_computeExitStatus(self):
        """
        Given a CPU load > crit threshold
	should return the 'CRITICAL' Nagios plugin exit status
        """
        self._objUtility = Utility.Utility()
        self._objDebug = Debug.Debug()
        myPlugin = CheckLocalCpu.CheckLocalCpu(
            name='CHECK LOCAL CPU',
            objDebug=self._objDebug,
        )

        myPlugin.cpuUsagePercent = critical + 1

        exitStatus = myPlugin.computeExitStatus(warningThreshold=warning,
                                                criticalThreshold=critical)
        self.assertEqual(exitStatus, 'CRITICAL')
Ejemplo n.º 7
0
#                   Installing "psutil" this way requires the (Debian) packages :
#                       python-pip
#                       python-dev
#
# KNOWN BUGS AND LIMITATIONS :
#               1.
#
########################################## ##########################################################

from modules import CommandLine
from modules import CheckLocalCpu
from modules import Debug
from modules import Utility

myUtility = Utility.Utility()
myDebug = Debug.Debug()

myCommandLine = CommandLine.CommandLine(
    description='Check the local CPU usage.',
    objDebug=myDebug,
    objUtility=myUtility)

myPlugin = CheckLocalCpu.CheckLocalCpu(
    name='CHECK LOCAL CPU',
    objDebug=myDebug,
)

myCommandLine.declareArgument({
    'shortOption': 'w',
    'longOption': 'warning',
    'required': True,
Ejemplo n.º 8
0
def main():
    text = file('../mixins/__init__.py').read()
    re_import = re.compile('^#import (.*)$', re.M)
    result = re_import.findall(text)
    if result:
        fp = file('../mixins/Import.py', 'wb')
        fp.write("""\
#   Programmer: limodou
#   E-mail:     [email protected]
#
#   Copyleft 2006 limodou
#
#   Distributed under the terms of the GPL (GNU Public License)
#
#   UliPad is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program 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 General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#   $Id$

import os
import pickle
from modules import Globals
from modules import Mixin

pfile = os.path.join(Globals.workpath, 'mixins.pickls')
Mixin.__mixinset__ = pickle.load(file(pfile, 'rb'))
Mixin.ENABLE = False
""")

        def _(s):
            return s

        sys.path.insert(0, os.path.abspath('../mixins'))
        sys.path.insert(0, os.path.abspath('..'))
        import __builtin__
        __builtin__.__dict__['tr'] = _

        for f in result:
            #            print 'dealing ... ', f
            mod = __import__(f)

        from modules import Mixin
        Mixin.MUST_FUNC = True
        from modules import Debug
        Debug.debug = Debug.Debug('../debug.txt')

        processMixin(Mixin.__mixinset__)
        pfile = '../mixins.pickls'
        pickle.dump(Mixin.__mixinset__, file(pfile, 'wb'))
        Mixin.printMixin()
        print "Successful!"
Ejemplo n.º 9
0
ini = common.get_config_file_obj()
debugflag = ini.default.get('debug', False)

#add pythonpath settings
if ini.default.has_key('pythonpath'):
    pythonpath = ini.default.pythonpath
    if isinstance(pythonpath, list):
        sys.path = pythonpath + sys.path
    elif isinstance(pythonpath, (str, unicode)):
        sys.path.insert(0, pythonpath)
    else:
        print 'The pythonpath should be a string list or a string.'

common.print_time('begin...', DEBUG)

Debug.debug = Debug.Debug(os.path.join(workpath, 'debug.txt'), debugflag)
Debug.error = Debug.Debug(os.path.join(workpath, 'error.txt'), True)


#hook global exception
def myexcepthook(type, value, tb):
    Debug.error.traceback((type, value, tb))


sys.excepthook = myexcepthook

#install i18n package
i18n = i18n.I18n('./lang', keyfunc='tr')
#ini = dict4ini.DictIni(os.path.join(workpath, 'config.ini'))
if ini.language.get('default', None) is not None:
    i18n.install(ini.language.default)