예제 #1
0
    def test_livestatus_query_when_response_code_is_error(self):
        with self.assertRaises(nagios_exporter.NagiosResponseError):
            # Expect 10 bytes that are never sent.
            message = 'error message'
            fake_sock = FakeSocketIO(fixed16('400', len(message)) + message)

            session = nagios_exporter.LiveStatus(fake_sock)
            session.query('blah')
예제 #2
0
    def test_livestatus_query(self):
        json_response = json.dumps(self.services)
        fixed16_header = fixed16('200', len(json_response))
        fake_sock = FakeSocketIO(fixed16_header + json_response)

        session = nagios_exporter.LiveStatus(fake_sock)
        actual = session.query('blah')

        self.assertEqual(actual, self.services)
    def test_get_status(self):
        expected = ['nagios_thing_a 1', 'nagios_thing_b 0']
        json_response = json.dumps([['thing_a', 'thing_b'], [1, 0]])
        fixed16_header = fixed16('200', len(json_response))
        fake_sock = FakeSocketIO(fixed16_header + json_response)

        session = nagios_exporter.LiveStatus(fake_sock)
        actual = nagios_exporter.get_status(session)

        self.assertItemsEqual(actual, expected)
    def test_livestatus_query_when_recv_raises_exception(self):
        class FakeSocketIOWithError(FakeSocketIO):
            """Subclass of FakeSocketIO that raises an exception on sendall"""
            def recv(self, count):
                raise socket.error('fake socket error')

        with self.assertRaises(nagios_exporter.NagiosResponseError):
            # Expect 10 bytes that are never sent.
            fake_sock = FakeSocketIOWithError(fixed16('400', 10))

            session = nagios_exporter.LiveStatus(fake_sock)
            session.query('blah')
    def test_livestatus_query_when_sendall_raises_exception(self):
        class FakeSocketIOWithError(FakeSocketIO):
            """Subclass of FakeSocketIO that raises an exception on sendall"""
            def sendall(self, msg):
                raise socket.error('fake socket error')

        with self.assertRaises(nagios_exporter.NagiosQueryError):
            # Text is never used.
            fake_sock = FakeSocketIOWithError('')

            session = nagios_exporter.LiveStatus(fake_sock)
            session.query('blah')
예제 #6
0
    def test_get_services(self):
        expected = [
            'nagios_check_load_exec_time{hostname="localhost", service="Current Load"} 0.011084',
            'nagios_check_load_latency{hostname="localhost", service="Current Load"} 0.078',
            'nagios_check_load_state{hostname="localhost", service="Current Load"} 0',
            'nagios_check_load_flapping{hostname="localhost", service="Current Load"} 0',
            'nagios_check_load_acknowledged{hostname="localhost", service="Current Load"} 0'
        ]
        json_response = json.dumps(self.services)
        fixed16_header = fixed16('200', len(json_response))
        fake_sock = FakeSocketIO(fixed16_header + json_response)

        session = nagios_exporter.LiveStatus(fake_sock)
        actual = nagios_exporter.get_services(session, False, ())

        self.assertEqual(actual, expected)
예제 #7
0
    def test_livestatus_query_when_recv_response_is_empty(self):
        with self.assertRaises(nagios_exporter.NagiosResponseError):
            fake_sock = FakeSocketIO('')

            session = nagios_exporter.LiveStatus(fake_sock)
            session.query('blah')