def get(self, resource=None, name=None, group=None):
        """
        compose GET URI to MarkLogic Management REST API
        :param resource:
        :param name:
        :param group:
        :return:
        """
        path = "/manage/v2"
        if resource:
            path += "/" + resource
        if name:
            path += "/" + name
        path += "?view=status&format=json"
        if group:
            path += "&group-id=" + group

        # retrieve Management REST API status
        try:
            return HTTPUtil.http_get(scheme=self.scheme,
                                     host=self.host,
                                     port=self.port,
                                     path=path,
                                     user=self.user,
                                     passwd=self.passwd,
                                     realm="public",
                                     auth=self.auth,
                                     verify=self.verify)
        except Exception as exception:
            LOG.error("Problem accessing MarkLogic Management API")
            LOG.error(exception)
Beispiel #2
0
 def testRestPost(self):
     response = HTTPUtil.http_post(
         scheme="https",
         url="https://platform-api.newrelic.com/platform/v1/metrics",
         headers={
             'Accept': 'application/json',
             'Content-Type': 'application/json',
             'X-License-Key': 'e8cf9b3d7aaca22a8632c7e01a14f8e722519b8a'
         },
         payload={
             "agent": {
                 "host": host,
                 "pid": 1234,
                 "version": "1.0.0"
             },
             "components": [{
                 "name": "marklogic_unittest",
                 "guid": "com.marklogic",
                 "duration": 60,
                 "metrics": {
                     "Component/MarkLogic[UnitTest]": 50
                 }
             }]
         })
     assert response
Beispiel #3
0
 def testRest2(self):
     response = HTTPUtil.http_get(scheme="http",
                                  host=host,
                                  port=8002,
                                  path="/manage/v2?view=status",
                                  user="******",
                                  passwd="admin",
                                  realm="public",
                                  auth="DIGEST")
     assert response
 def testRest2(self):
     response = HTTPUtil.http_get(scheme="http",
                                  host=host,
                                  port=8002,
                                  path="/manage/v2?view=status",
                                  user="******",
                                  passwd="admin",
                                  realm="public",
                                  auth="DIGEST")
     assert response
Beispiel #5
0
    def update_newrelic(self,
                        host=None,
                        version=None,
                        pid=None,
                        name=None,
                        guid=None,
                        duration=None,
                        metrics=None,
                        key=None,
                        http_proxy=None,
                        https_proxy=None):
        log.debug('update newrelic')

        # construct newrelic agent
        agent = {
            'host': host or self.host,
            'pid': pid or self.pid,
            'version': version or self.version
        }

        # construct newrelic components
        components = []
        component = {
            'name': name,
            'guid': guid,
            'duration': duration,
            'metrics': metrics
        }
        components.append(component)

        # composite payload for sending to newrelic
        data = {'agent': agent, 'components': components}
        log.debug("payload:")
        log.debug(json.dumps(data))

        # send to the NewRelic API, supplying correct headers and using proxy (if defined).
        try:
            return HTTPUtil.http_post(
                scheme="https",
                url="https://platform-api.newrelic.com/platform/v1/metrics",
                headers={
                    'Accept': 'application/json',
                    'Content-Type': 'application/json',
                    'X-License-Key': key
                },
                payload=data,
                http_proxy=http_proxy,
                https_proxy=https_proxy)
        except Exception as e:
            log.error("Problem accessing NewRelic Plugin API")
            log.error(e)
            pass
 def testRestPost(self):
     response = HTTPUtil.http_post(scheme="https",
                                   url="https://platform-api.newrelic.com/platform/v1/metrics",
                                   headers={'Accept': 'application/json',
                                            'Content-Type': 'application/json',
                                            'X-License-Key': 'e8cf9b3d7aaca22a8632c7e01a14f8e722519b8a'},
                                   payload={
                                       "agent": {
                                           "host": host,
                                           "pid": 1234,
                                           "version": "1.0.0"
                                       },
                                       "components": [{
                                           "name": "marklogic_unittest",
                                           "guid": "com.marklogic",
                                           "duration": 60,
                                           "metrics": {
                                               "Component/MarkLogic[UnitTest]": 50
                                           }
                                       }]
                                   })
     assert response
 def testRest3(self):
     response = HTTPUtil.http_get(url="http://www.google.com", headers={'Accept': 'text/html'}, format="html")
     log.debug(response)
     assert response
Beispiel #8
0
 def test_get_request_url_combo(self):
     self.assertEqual("http://marklogic.com", HTTPUtil.get_request_url(url="http://marklogic.com", scheme="https", host="test.com", port=123, path="/test"))
 def testRest1(self):
     response = HTTPUtil.http_get("http", host, 8002, "/manage/v2?view=status", "admin", "admin", "public",
                                  "DIGEST")
     assert response
Beispiel #10
0
 def testRest3(self):
     response = HTTPUtil.http_get(url="http://www.google.com",
                                  headers={'Accept': 'text/html'},
                                  format="html")
     log.debug(response)
     assert response
Beispiel #11
0
 def test_get_auth_digest(self):
     auth = HTTPUtil.get_auth(auth="DIGEST", user="******", passwd="digest-password")
     self.assertTrue(isinstance(auth, HTTPDigestAuth))
     self.assertEqual(auth.username, "digest-admin")
     self.assertEqual(auth.password, "digest-password")
Beispiel #12
0
 def test_get_auth_none(self):
     self.assertIsNone(HTTPUtil.get_auth())
Beispiel #13
0
 def test_http_get_status(self):
     response = HTTPUtil.http_get(SCHEME, HOST, PORT, "/manage/v2?view=status&format=json", USER, PASS, "public", AUTH)
     self.assertTrue(isinstance(response, dict))
     self.assertIsNotNone(response["local-cluster-status"])
Beispiel #14
0
 def test_get_proxies_none(self):
     self.assertIsNone(HTTPUtil.get_proxies())
Beispiel #15
0
 def test_get_proxies_https_only(self):
     proxy = HTTPUtil.get_proxies(https_proxy="foo")
     self.assertIsNone(proxy.get("http", None))
     self.assertEqual(proxy.get("https"), "foo")
Beispiel #16
0
 def test_get_proxies(self):
     proxy = HTTPUtil.get_proxies(http_proxy="foo", https_proxy="bar")
     self.assertEqual(proxy.get("http"), "foo")
     self.assertEqual(proxy.get("https"), "bar")
Beispiel #17
0
 def testRest1(self):
     response = HTTPUtil.http_get("http", host, 8002,
                                  "/manage/v2?view=status", "admin",
                                  "admin", "public", "DIGEST")
     assert response
Beispiel #18
0
 def test_get_request_url_components(self):
     self.assertEqual("https://test.com:123/test", HTTPUtil.get_request_url(scheme="https", host="test.com", port=123, path="/test"))
Beispiel #19
0
 def test_http_get_status_params(self):
     response = HTTPUtil.http_get(scheme=SCHEME, host=HOST, port=PORT, path="/manage/v2?view=status&format=json", user=USER, passwd=PASS, realm="public", auth=AUTH)
     self.assertTrue(isinstance(response, dict))
     self.assertIsNotNone(response["local-cluster-status"])
Beispiel #20
0
 def test_get_auth_basic(self):
     auth = HTTPUtil.get_auth(auth="BASIC", user="******", passwd="basic-password")
     self.assertTrue(isinstance(auth, HTTPBasicAuth))
     self.assertEqual(auth.username, "basic-admin")
     self.assertEqual(auth.password, "basic-password")
Beispiel #21
0
 def test_http_get(self):
     response = HTTPUtil.http_get(url="http://www.google.com", headers={'Accept': 'text/html'}, format="html")
     # response will be HTML, not JSON
     self.assertFalse(isinstance(response, dict))
Beispiel #22
0
 def test_get_request_url(self):
     self.assertEqual("http://marklogic.com", HTTPUtil.get_request_url("http://marklogic.com"))