Exemplo n.º 1
0
class MozillaNagiosStatusTest(unittest.TestCase):
    tc = None

    def setUp(self):
        self.event = Mock()
        self.event.source = 'rtucker'
        self.event.target = '#sysadmins'
        self.connection = Mock()
        self.tc = MozillaIRCPager(self.connection, [])

    def test_get_page_plugin(self):
        plugins = self.tc.return_plugins()
        self.assertEqual('^page\\s+([A-Za-z][_A-Za-z0-9]+?)\\s+(.+)\\s*$',
                         plugins[0]['regex'])

    def test_correct_page(self):
        message_content = "this is a test message"
        page_message = 'page %s %s' % (self.event.source, message_content)
        plugins = self.tc.return_plugins()
        m = re.search(plugins[0]['regex'], page_message)
        target, message = self.tc.page(self.event, page_message, m)
        self.assertEqual(self.event.target, target)
        self.assertEqual(
            message, '%s: %s has been paged with the message "%s(%s)"' %
            (self.event.source, self.event.source, message_content,
             self.event.source))
    def page_with_alert_number(self, event, message, options):
        try:
            dict_object = self.ackable_list[int(options.group(1)) - self.list_offset]
            recipient = options.group(2)
            if dict_object['service'] is not None:
                message = "%s:%s is %s - %s (%s)" % (dict_object['host'],dict_object['service'], dict_object['message'], dict_object['state'], event.source)
            else:
                message = "%s is %s - %s (%s)" % (dict_object['host'], dict_object['state'], dict_object['message'], event.source)

            m = MozillaIRCPager(self.connection)
            m.page(event, message, options)
            m = None
        except NoneType:
            return event.target, "%s: Sorry, but no alert exists at this index" % (event.source) 
        except Exception, e:
            return event.target, "Exception: %s" % (e) 
            return event.target, "%s: %s could not be paged" % (event.source, recipient) 
class MozillaNagiosStatusTest(unittest.TestCase):
    tc = None

    def setUp(self):
        self.event = Mock()
        self.event.source = 'rtucker'
        self.event.target = '#sysadmins'
        self.connection = Mock()
        self.tc = MozillaIRCPager(self.connection)

    def test_get_page_plugin(self):
        plugins = self.tc.return_plugins()
        self.assertEqual('^page\\s+([A-Za-z][_A-Za-z0-9]+?)\\s+(.+)\\s*$',plugins[0]['regex']) 

    def test_correct_page(self):
        page_message = 'page %s this is a test message' % (self.event.source)
        plugins = self.tc.return_plugins()
        m = re.search(plugins[0]['regex'], page_message)
        target, message = self.tc.page(self.event, page_message, m)
        self.assertEqual(self.event.target, target)
        self.assertEqual(message, '%s: %s has been paged' % (self.event.source, self.event.source) )
 def setUp(self):
     self.event = Mock()
     self.event.source = 'rtucker'
     self.event.target = '#sysadmins'
     self.connection = Mock()
     self.tc = MozillaIRCPager(self.connection, [])
Exemplo n.º 5
0
 def setUp(self):
     self.event = Mock()
     self.event.source = 'rtucker'
     self.event.target = '#sysadmins'
     self.connection = Mock()
     self.tc = MozillaIRCPager(self.connection, [])