2016-04-10 8 views
1

私は現在、次のコード残りのAPIを使用してAzureイベントハブメトリックを取得しますか?

def get_metrics(subscription, eventhub, cert, specific_partition=None): 
    apiversion = '2014-01' 
    namespace = eventhub['namespace'] 
    eventhubname = eventhub['name'] 
    url = "https://management.core.windows.net/{}/services/ServiceBus/Namespaces/{}/eventhubs/{}/Metrics/requests.total/Rollups/P1D/Values/?$filter=timestamp%20gt%20datetime'2016-04-09T00:00:00.0000000Z'&api-version={}".format(
     subscription, namespace, eventhubname, apiversion) 
    request = requests.Request('GET', url, headers=DEFAULT_HEADERS).prepare() 
    session = requests.Session() 
    if cert is None or not os.path.isfile(cert): 
     raise ValueError('You must give certificate file') 
    session.cert = cert 
    result = session.send(request) 
    return result 
を試し https://msdn.microsoft.com/en-us/library/azure/dn163589.aspxhttps://msdn.microsoft.com/en-us/library/azure/mt652158.aspx を読んだ後、私は実際にURLを呼び出し、応答 を得ることができますPythonコードを持っている 、残りのAPIを使用して、イベントのハブメトリックを引くしようとしています

私の問題は、コードでURLを使用するときに、私は

<Error xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Code>InternalError</Code><Message>The server encountered an internal error. Please retry the request.</Message></Error> 

を得る上で、私は出力にすべての可能なロールアップし、すべての可能な指標をAPIを取得することができ、URLであるが、actuaを取得しようとしたときl値は失敗します。

URLに何か間違いがありますか、それとも、紺碧/紺碧の文書化のバグですか?

+0

「DEFAULT_HEADERS」は何ですか?ちょうどコンテンツタイプと認可? –

+0

コンテンツタイプとx-msバージョン、私はセッションの証明書を使用します – Srgrn

答えて

2

通常、この問題が発生すると、Rest Apisのために結合したエンドポイントに問題があることを意味します。そのため、エンドポイントを解析するときにサービスが例外を送出します。

私の成功したテストと比較して、私が見つけた興味深い点は、フィルタのパラメータtimestampによって生成された問題が、最初の文字をTimestampとして大文字にする必要があることです。次のエンドポイントは私の側で正常に動作します。それがあなたに役立つことを願っています。

url = "https://management.core.windows.net/{}/services/ServiceBus/Namespaces/{}/eventhubs/{}/Metrics/requests.total/Rollups/P1D/Values/?$filter=Timestamp%20gt%20datetime'2016-04-09T00:00:00.0000000Z'&api-version={}".format(
     subscription, namespace, eventhubname, '2012-03-01') 
+0

ありがとう、紺碧のサイトの文書も更新できますか? – Srgrn