Пример #1
0
    def test(self, get_config):
        mock_configuration = PropertyMock()
        mock_configuration.livestatus_socket = './livestatus_socket'
        get_config.return_value = mock_configuration
        socket_response = '[["host_name","notifications_enabled"],["devica01", 1], ["tuvdbs05",1], ["tuvdbs06",1]]'

        with LiveServer() as liveserver:
            with LiveSocket('./livestatus_socket',
                            socket_response) as livesocket:
                api_call_result = urlopen('{0}query?q=GET%20hosts'.format(
                    liveserver.url))
                actual_result = json.loads(
                    api_call_result.read().decode('utf-8'))
                expected_result = json.loads(expected_api_call_response)
                diff = [
                    element for element in actual_result
                    if element not in expected_result
                ]
                diff.extend([
                    element for element in expected_result
                    if element not in actual_result
                ])
                self.assertEqual(
                    diff, [],
                    'Found difference between expected and actual result : %s'
                    % diff)
                written_to_socket = livesocket.incoming.get()
                self.assertTrue('GET hosts' in written_to_socket
                                and 'OutputFormat: json' in written_to_socket)
 def test(self, get_config):
     mock_configuration = PropertyMock()
     mock_configuration.livestatus_socket = './livestatus_socket'
     get_config.return_value = mock_configuration
     with LiveServer() as liveserver:
         with LiveSocket('./livestatus_socket', '{}') as livesocket:
             result = urlopen('{0}cmd?q=DISABLE_HOST_NOTIFICATIONS;devica01'.format(liveserver.url))
             self.assertEqual(result.read(), b'OK\n')
             written_to_socket = livesocket.incoming.get()
             self.assertTrue('DISABLE_HOST_NOTIFICATIONS;devica01' in written_to_socket)
 def test(self, get_config):
     mock_configuration = PropertyMock()
     mock_configuration.livestatus_socket = './livestatus_socket'
     get_config.return_value = mock_configuration
     with LiveServer() as liveserver:
         socket_response = '[["host_name","notifications_enabled"],["devica01", 1], ["tuvdbs05",1], ["tuvdbs06",1]]'
         with LiveSocket('./livestatus_socket', socket_response) as livesocket:
             api_call_result = urlopen('{0}query?q=GET%20hosts&key=host_name'.format(liveserver.url))
             actual_api_response = json.loads(api_call_result.read().decode('utf-8'))
             self.assertEqual(expected_api_call_response, actual_api_response)
             written_to_socket = livesocket.incoming.get()
             self.assertTrue('GET hosts' in written_to_socket and 'OutputFormat: json' in written_to_socket)
Пример #4
0
 def test(self, get_config):
     mock_configuration = PropertyMock()
     mock_configuration.livestatus_socket = './livestatus_socket'
     get_config.return_value = mock_configuration
     with LiveServer() as liveserver:
         socket_response = '[["host_name","notifications_enabled"],["devica01", 1], ["tuvdbs05",1], ["tuvdbs06",1]]'
         with LiveSocket('./livestatus_socket', socket_response) as livesocket:
             api_call_result = urlopen('{0}query?q=GET%20hosts&key=host_name'.format(liveserver.url))
             actual_api_response = json.loads(api_call_result.read().decode('utf-8'))
             self.assertEquals(expected_api_call_response, actual_api_response)
             written_to_socket = livesocket.incoming.get()
             self.assertTrue('GET hosts' in written_to_socket and 'OutputFormat: json' in written_to_socket)
 def test(self, get_config):
     mock_configuration = PropertyMock()
     mock_configuration.livestatus_socket = './livestatus_socket'
     get_config.return_value = mock_configuration
     with LiveServer() as liveserver:
         with LiveSocket('./livestatus_socket', '{}') as livesocket:
             result = urlopen(
                 '{0}cmd?q=DISABLE_HOST_NOTIFICATIONS;devica01'.format(
                     liveserver.url))
             self.assertEqual(result.read(), b'OK\n')
             written_to_socket = livesocket.incoming.get()
             self.assertTrue(
                 'DISABLE_HOST_NOTIFICATIONS;devica01' in written_to_socket)
 def test(self, get_config):
     mock_configuration = PropertyMock()
     mock_configuration.livestatus_socket = "./livestatus_socket"
     get_config.return_value = mock_configuration
     with LiveServer() as liveserver:
         socket_response = '[["host_name","notifications_enabled"],["devica01", 1], ["tuvdbs05",1], ["tuvdbs06",1]]'
         with LiveSocket("./livestatus_socket", socket_response) as livesocket:
             api_call_result = urlopen("{0}query?q=GET%20hosts".format(liveserver.url))
             actual_result = json.loads(api_call_result.read().decode("utf-8"))
             expected_result = json.loads(expected_api_call_response)
             diff = [element for element in actual_result if element not in expected_result]
             diff.extend([element for element in expected_result if element not in actual_result])
             self.assertEqual(diff, [], "Found difference between expected and actual result : %s" % diff)
             written_to_socket = livesocket.incoming.get()
             self.assertTrue("GET hosts" in written_to_socket and "OutputFormat: json" in written_to_socket)
    def test(self, get_config):
        mock_configuration = PropertyMock()
        mock_configuration.livestatus_socket = './livestatus_socket'
        get_config.return_value = mock_configuration
        with LiveServer() as liveserver:
            with LiveSocket('./livestatus_socket', '{}') as livesocket:

                url = '{0}cmd'.format(liveserver.url)
                parameters = {'q': 'DISABLE_HOST_NOTIFICATIONS;devica01',
                              }
                data = urlencode(parameters)
                binary_data = data.encode('utf-8')
                request = Request(url, binary_data)
                response = urlopen(request)
                self.assertEquals(response.read(), b'OK\n')
                written_to_socket = livesocket.incoming.get()
                self.assertTrue('DISABLE_HOST_NOTIFICATIONS;devica01' in written_to_socket)