Exemplo n.º 1
0
    def setUp(self):
        sys.argv = sys.argv[:1]
        args = [
            '-H',
            'monitoring-dc.app.corp',
        ]
        sys.argv.extend(args)

        self.plugin = NagiosPlugin()
        self.delete_file(self.plugin.picklefile)
Exemplo n.º 2
0
    def setUp(self):
        sys.argv = sys.argv[:1]
        args = [
            '-H', 'monitoring-dc.app.corp',
        ]
        sys.argv.extend(args)

        self.plugin = NagiosPlugin()
        self.delete_file(self.plugin.picklefile)
Exemplo n.º 3
0
#!/usr/bin/env python
import logging
from monitoring.nagios.plugin import NagiosPlugin

logger = logging.getLogger('plugin')
myvar = 'hey'

plugin = NagiosPlugin(version='0.1',description='logging test')
logger.debug('show this message debug mode only')
logger.debug('\"myvar\":{0}'.format(myvar))
logger.debug('end ...')
Exemplo n.º 4
0
class TestBasePluginPickle(unittest.TestCase):
    """
    Test pickling data.
    """
    def setUp(self):
        sys.argv = sys.argv[:1]
        args = [
            '-H',
            'monitoring-dc.app.corp',
        ]
        sys.argv.extend(args)

        self.plugin = NagiosPlugin()
        self.delete_file(self.plugin.picklefile)

    def delete_file(self, filename):
        try:
            os.remove(filename)
        except OSError:
            pass

    def tearDown(self):
        self.delete_file(self.plugin.picklefile)

    def test_pickle_file_not_found(self):
        """Test case when pickle file cannot be found."""
        self.assertRaises(IOError, self.plugin.load_data)

    def test_pickle_save(self):
        """Test saving to pickle file."""
        l = [1, 2, 3, 4, 5]
        self.plugin.save_data(l)

    def test_pickle_load(self):
        """Test loading of pickled data."""
        l = [1, 2, 3, 4, 5]
        self.plugin.save_data(l)

        l = self.plugin.load_data()
        self.assertIn(4, l)

    def test_pickle_limit_record(self):
        """Test limiting number of records in pickle file."""
        l = []
        for i in range(0, 30):
            l.append(i)
        self.plugin.save_data(l, 10)
        l = self.plugin.load_data()
        self.assertEqual(10, len(l))

    def test_pickle_limit_continue(self):
        """Test continuation after loading next pickle data on next run."""
        l = []
        for i in range(0, 30):
            l.append(i)
        self.plugin.save_data(l, 10)
        l = self.plugin.load_data()
        self.assertEqual(20, l[0])
Exemplo n.º 5
0
class TestBasePluginPickle(unittest.TestCase):
    """
    Test pickling data.
    """

    def setUp(self):
        sys.argv = sys.argv[:1]
        args = [
            '-H', 'monitoring-dc.app.corp',
        ]
        sys.argv.extend(args)

        self.plugin = NagiosPlugin()
        self.delete_file(self.plugin.picklefile)

    def delete_file(self, filename):
        try:
            os.remove(filename)
        except OSError:
            pass

    def tearDown(self):
        self.delete_file(self.plugin.picklefile)

    def test_pickle_file_not_found(self):
        """Test case when pickle file cannot be found."""
        self.assertRaises(IOError, self.plugin.load_data)

    def test_pickle_save(self):
        """Test saving to pickle file."""
        l = [1, 2, 3, 4, 5]
        self.plugin.save_data(l)

    def test_pickle_load(self):
        """Test loading of pickled data."""
        l = [1, 2, 3, 4, 5]
        self.plugin.save_data(l)

        l = self.plugin.load_data()
        self.assertIn(4, l)

    def test_pickle_limit_record(self):
        """Test limiting number of records in pickle file."""
        l = []
        for i in range(0, 30):
            l.append(i)
        self.plugin.save_data(l, 10)
        l = self.plugin.load_data()
        self.assertEqual(10, len(l))

    def test_pickle_limit_continue(self):
        """Test continuation after loading next pickle data on next run."""
        l = []
        for i in range(0, 30):
            l.append(i)
        self.plugin.save_data(l, 10)
        l = self.plugin.load_data()
        self.assertEqual(20, l[0])