ウェブサイトを取得する

最終更新日: 14 年 2021 月 XNUMX 日

LogicMonitorのRESTAPIを使用して、LogicMonitorWebサイトに関する情報をプログラムで取得できます。 あなたはどちらかをすることができます ウェブサイトのリストを取得する またはあなたがすることができます 特定のウェブサイトの詳細を取得する.

スクリプト化されたWebチェックはRESTAPIのv1を介して返されませんので、 v2を使用して、これらのリソースを取得および管理します.

ウェブサイトのリストを取得する

Webサイトのリストを返します

HTTPメソッド:GET

URI:/ service / services

リクエストパラメータ: デフォルトでは、50のサービスのリストが返されます。 リクエストに並べ替え、フィルター、フィールド、サイズ、オフセットのパラメーターを含めて、応答に含まれるデータとそのフォーマット方法を制御できます。 クエリパラメータはリソースパスの一部とは見なされないため、LMv1認証署名の計算に含めるべきではないことに注意してください。

プロパティ 構文 説明 URIの例
sort sort = {+または-} property 昇順(+)または降順(-)のいずれかで指定されたプロパティで応答を並べ替えます / service / services?sort = -id
filter filter = property {operator} value 指定された演算子と値に従って応答をフィルタリングします。 *を使用して複数の文字に一致させることができることに注意してください。「。」を使用できます。 オブジェクト内の値(カスタムプロパティなど)をフィルタリングする文字。複数のフィルターはコンマで区切ることができます。

演算子は次のとおりです。

  • 以上: >:
  • 以下: <:
  • 大なり記号: >
  • 未満: <
  • 等しくない: !:
  • 等しい: :
  • 以下の構成です: ~
  • 含まれていません: !~
/ service / services?filter = name:QAservice
フィールド fields = {コンマで区切られたプロパティのリスト} 応答をフィルタリングして、各オブジェクトの次のフィールドのみを含めます / service / services?fields = name、id
サイズ size = integer 表示する結果の数。 最大は1000です。 / service / services?size = 5
オフセット offset = integer 表示された結果を相殺する結果の数 / service / services?offset = 2

特定のWebサイトに関する情報を取得する

特定のWebサイトの詳細を返します

HTTPメソッド:GET

URI:/ service / services / {id}

リクエストパラメータ: 応答に表示されるプロパティを制御するフィルターパラメーターを含めることができます。

プロパティ 構文 説明 URIの例
フィールド fields = {コンマで区切られたプロパティのリスト} 応答をフィルタリングして、各オブジェクトの次のフィールドのみを含めます / service / services / {id}?fields = name、id

次の例は、PythonのWebサイト(サービス)リソースへのGETリクエストを示しています。

  • 例1:すべてのWebサイトを取得します。各Webサイトのすべてのフィールドが返されます
  • 例2:すべてのWebサイトを取得します。Webサイトごとに限られた数のフィールドが返されます
  • 例3:XNUMXつのWebサイトを取得し、そのWebサイトのすべてのフィールドが返される
  • 例4:Webサイトに対して限られた数のフィールドが返されるXNUMXつのWebサイトを取得します

例1:すべてのWebサイトを取得する

次のPython3スクリプトは、api.logicmonitor.comポータル内のすべてのサービスのリストを返します。

#!/ bin / envpythonインポートリクエストimportjson import hashlib import base64 import time import hmac #Account Info AccessId = 'J62te62B8u7WnCR846h6' AccessKey = '{[H ^ LX = ^ Zg ^ 32yp-x(-2Bq22vZ〜 ^ u-k3 )8!9 [7U ^ 'Company =' api '#Request Info:Get Services httpVerb =' GET'resourcePath = '/ service / services'#Construct URL url = 'https://' + Company + '。logicmonitor。 com / santaba / rest '+ resourcePath#現在の時刻をミリ秒単位で取得epoch = str(int(time.time()* 1000))#リクエストの詳細を連結するrequestVars = httpVerb + epoch + resourcePath#署名を作成するhmac1 = hmac.new(AccessKey .encode()、msg = requestVars.encode()、digestmod = hashlib.sha256).hexdigest()signature = base64.b64encode(hmac1.encode())#ヘッダーを構築するauth = 'LMv1' + AccessId + ':' + Signature.decode()+ ':' +エポックヘッダー= {'Content-Type': 'application / json'、 'Authorization':auth}#リクエストレスポンスを作成= requests.get(url、headers = headers)#ステータスを出力および応答の本文print( 'Response Status:'、response.status_code)print( 'Re スポンジボディ: '、response.content)

出力:

{
  "status" : 200,
  "errmsg" : "OK",
  "data" : {
    "total" : 5,
    "items" : [ {
      "type" : "webservice",
      "id" : 58,
      "name" : "Form-based auth",
      "description" : "",
      "serviceFolderId" : 1,
      "stopMonitoring" : false,
      "stopMonitoringByFolder" : false,
      "disableAlerting" : false,
      "individualSmAlertEnable" : false,
      "individualAlertLevel" : "warn",
      "overallAlertLevel" : "warn",
      "alertStatus" : "none",
      "sdtStatus" : "none-none-none",
      "alertDisableStatus" : "none-none-none",
      "pollingInterval" : 10,
      "transition" : 1,
      "testLocation" : "{\"smgIds\":[3],\"all\":false}",
      "globalSmAlertCond" : 0,
      "useDefaultLocationSetting" : false,
      "useDefaultAlertSetting" : false,
      "userPermission" : "write",
      "checkpoints" : [ {
        "id" : 292,
        "geoInfo" : "Overall",
        "smgId" : 0
      }, {
        "id" : 294,
        "geoInfo" : "US - San Francisco",
        "smgId" : 3
      } ],
      "serviceProperties" : [ ],
      "steps" : [ {
        "HTTPHeaders" : "",
        "statusCode" : "",
        "followRedirection" : true,
        "matchType" : "plain",
        "keyword" : "",
        "HTTPBody" : "",
        "HTTPMethod" : "GET",
        "postDataEditType" : "raw",
        "label" : "",
        "url" : "test.logicmonitor.com/santaba/",
        "fullpageLoad" : false,
        "requireAuth" : false,
        "auth" : null,
        "invertMatch" : false,
        "timeout" : 30,
        "HTTPVersion" : "1.1",
        "schema" : "https",
        "description" : "",
        "path" : "",
        "enable" : true,
        "name" : "__step0",
        "domain" : "test.logicmonitor.com"
      }, {
        "HTTPHeaders" : "Content-Type:application/x-www-form-urlencoded",
        "statusCode" : "",
        "followRedirection" : true,
        "matchType" : "plain",
        "keyword" : "",
        "HTTPBody" : "c=test&u=testp=test",
        "HTTPMethod" : "POST",
        "postDataEditType" : "raw",
        "label" : "",
        "url" : "test.logicmonitor.com/santaba/",
        "fullpageLoad" : false,
        "requireAuth" : false,
        "auth" : null,
        "invertMatch" : false,
        "timeout" : 30,
        "HTTPVersion" : "1.1",
        "schema" : "https",
        "description" : "",
        "path" : "data.status",
        "enable" : true,
        "name" : "__step1",
        "domain" : "test.logicmonitor.com"
      }, {
        "HTTPHeaders" : "",
        "statusCode" : "",
        "followRedirection" : true,
        "matchType" : "plain",
        "keyword" : "sarah",
        "HTTPBody" : "",
        "HTTPMethod" : "GET",
        "postDataEditType" : "raw",
        "label" : "",
        "url" : "test.logicmonitor.com/santaba/uiv3/device/index.jsp#layer/dg/1/info",
        "fullpageLoad" : true,
        "requireAuth" : false,
        "auth" : null,
        "invertMatch" : false,
        "timeout" : 30,
        "HTTPVersion" : "1.1",
        "schema" : "https",
        "description" : "",
        "path" : "",
        "enable" : true,
        "name" : "__step2",
        "domain" : "test.logicmonitor.com"
      } ],
      "script" : "",
      "method" : "tabledriven",
      "ignoreSSL" : false,
      "pageLoadAlertTimeInMS" : 30000
    }, {
      "type" : "webservice",
      "id" : 41,
      "name" : "Multi-Step",
      "description" : "",
      "serviceFolderId" : 11,
      "stopMonitoring" : false,
      "stopMonitoringByFolder" : false,
      "disableAlerting" : false,
      "individualSmAlertEnable" : false,
      "individualAlertLevel" : "warn",
      "overallAlertLevel" : "warn",
      "alertStatus" : "unconfirmed-warn",
      "sdtStatus" : "none-none-none",
      "alertDisableStatus" : "none-none-none",
      "pollingInterval" : 1,
      "transition" : 1,
      "testLocation" : "{\"all\":true}",
      "globalSmAlertCond" : 0,
      "useDefaultLocationSetting" : false,
      "useDefaultAlertSetting" : false,
      "userPermission" : "write",
      "checkpoints" : [ {
        "id" : 204,
        "geoInfo" : "Overall",
        "smgId" : 0
      }, {
        "id" : 208,
        "geoInfo" : "Asia - Singapore",
        "smgId" : 5
      }, {
        "id" : 207,
        "geoInfo" : "Europe - Dublin",
        "smgId" : 4
      }, {
        "id" : 205,
        "geoInfo" : "US - San Francisco",
        "smgId" : 3
      }, {
        "id" : 203,
        "geoInfo" : "US - Washington DC",
        "smgId" : 2
      } ],
      "serviceProperties" : [ ],
      "steps" : [ {
        "HTTPHeaders" : "",
        "statusCode" : "",
        "followRedirection" : false,
        "matchType" : "plain",
        "keyword" : "",
        "HTTPBody" : "",
        "HTTPMethod" : "GET",
        "postDataEditType" : "raw",
        "label" : "step 1",
        "url" : "kittens.test.logicmonitor.com/morekittens.html",
        "fullpageLoad" : true,
        "requireAuth" : false,
        "auth" : null,
        "invertMatch" : false,
        "timeout" : 30,
        "HTTPVersion" : "1.1",
        "schema" : "http",
        "description" : "",
        "path" : "",
        "enable" : true,
        "name" : "__step0",
        "domain" : "kittens.test.logicmonitor.com"
      } ],
      "script" : "",
      "method" : "tabledriven",
      "ignoreSSL" : true,
      "pageLoadAlertTimeInMS" : 30000
    }, {
      "type" : "ping",
      "id" : 60,
      "name" : "JIRA",
      "description" : "",
      "serviceFolderId" : 11,
      "stopMonitoring" : false,
      "stopMonitoringByFolder" : false,
      "disableAlerting" : false,
      "individualSmAlertEnable" : true,
      "individualAlertLevel" : "critical",
      "overallAlertLevel" : "critical",
      "alertStatus" : "unconfirmed-critical",
      "sdtStatus" : "none-none-none",
      "alertDisableStatus" : "none-none-none",
      "pollingInterval" : 5,
      "transition" : 1,
      "testLocation" : "{\"smgIds\":[1,2,3,4,5],\"all\":true}",
      "globalSmAlertCond" : 0,
      "useDefaultLocationSetting" : true,
      "useDefaultAlertSetting" : false,
      "userPermission" : "write",
      "checkpoints" : [ {
        "id" : 302,
        "geoInfo" : "Overall",
        "smgId" : 0
      }, {
        "id" : 306,
        "geoInfo" : "Asia - Singapore",
        "smgId" : 5
      }, {
        "id" : 305,
        "geoInfo" : "Europe - Dublin",
        "smgId" : 4
      }, {
        "id" : 304,
        "geoInfo" : "US - San Francisco",
        "smgId" : 3
      }, {
        "id" : 303,
        "geoInfo" : "US - Washington DC",
        "smgId" : 2
      } ],
      "serviceProperties" : [ ],
      "count" : 5,
      "host" : "asdfasdfasdfasdf",
      "percentPktsNotReceiveInTime" : 80,
      "timeoutInMSPktsNotReceive" : 500
    }, {
      "type" : "webservice",
      "id" : 49,
      "name" : "LMCertification",
      "description" : "",
      "serviceFolderId" : 12,
      "stopMonitoring" : false,
      "stopMonitoringByFolder" : false,
      "disableAlerting" : false,
      "individualSmAlertEnable" : false,
      "individualAlertLevel" : "warn",
      "overallAlertLevel" : "warn",
      "alertStatus" : "none",
      "sdtStatus" : "none-none-none",
      "alertDisableStatus" : "none-none-none",
      "pollingInterval" : 10,
      "transition" : 3,
      "testLocation" : "{\"smgIds\":[1,4],\"all\":false}",
      "globalSmAlertCond" : 0,
      "useDefaultLocationSetting" : false,
      "useDefaultAlertSetting" : false,
      "userPermission" : "write",
      "checkpoints" : [ {
        "id" : 251,
        "geoInfo" : "Overall",
        "smgId" : 0
      }, {
        "id" : 253,
        "geoInfo" : "Europe - Dublin",
        "smgId" : 4
      } ],
      "serviceProperties" : [ ],
      "steps" : [ {
        "HTTPHeaders" : "",
        "statusCode" : "",
        "followRedirection" : true,
        "matchType" : "plain",
        "keyword" : "LogicMonitor Certification",
        "HTTPBody" : "",
        "HTTPMethod" : "GET",
        "postDataEditType" : "raw",
        "label" : "",
        "url" : "logicmonitor.docebosaas.com/lms/",
        "fullpageLoad" : false,
        "requireAuth" : false,
        "auth" : null,
        "invertMatch" : false,
        "timeout" : 30,
        "HTTPVersion" : "1.1",
        "schema" : "https",
        "description" : "",
        "path" : "",
        "enable" : true,
        "name" : "__step0",
        "domain" : "logicmonitor.docebosaas.com"
      }, {
        "HTTPHeaders" : "Content-Type:application/x-www-form-urlencoded",
        "statusCode" : "",
        "followRedirection" : true,
        "matchType" : "plain",
        "keyword" : "",
        "HTTPBody" : "login_pwd=test&login_user=test",
        "HTTPMethod" : "POST",
        "postDataEditType" : "x-www-form-urlencoded",
        "label" : "",
        "url" : "logicmonitor.docebosaas.com/lms/",
        "fullpageLoad" : false,
        "requireAuth" : false,
        "auth" : null,
        "invertMatch" : false,
        "timeout" : 30,
        "HTTPVersion" : "1.1",
        "schema" : "https",
        "description" : "",
        "path" : "",
        "enable" : true,
        "name" : "__step1",
        "domain" : "logicmonitor.docebosaas.com"
      } ],
      "script" : "",
      "method" : "tabledriven",
      "ignoreSSL" : false,
      "pageLoadAlertTimeInMS" : 20000
    }, {
      "type" : "ping",
      "id" : 48,
      "name" : "LMService",
      "description" : "",
      "serviceFolderId" : 12,
      "stopMonitoring" : false,
      "stopMonitoringByFolder" : false,
      "disableAlerting" : false,
      "individualSmAlertEnable" : false,
      "individualAlertLevel" : "warn",
      "overallAlertLevel" : "warn",
      "alertStatus" : "none",
      "sdtStatus" : "none-none-none",
      "alertDisableStatus" : "none-none-none",
      "pollingInterval" : 5,
      "transition" : 1,
      "testLocation" : "{\"all\":true}",
      "globalSmAlertCond" : 0,
      "useDefaultLocationSetting" : false,
      "useDefaultAlertSetting" : false,
      "userPermission" : "write",
      "checkpoints" : [ {
        "id" : 245,
        "geoInfo" : "Overall",
        "smgId" : 0
      }, {
        "id" : 250,
        "geoInfo" : "Asia - Singapore",
        "smgId" : 5
      }, {
        "id" : 249,
        "geoInfo" : "Europe - Dublin",
        "smgId" : 4
      }, {
        "id" : 248,
        "geoInfo" : "US - San Francisco",
        "smgId" : 3
      }, {
        "id" : 247,
        "geoInfo" : "US - Washington DC",
        "smgId" : 2
      } ],
      "serviceProperties" : [ ],
      "count" : 20,
      "host" : "kittens.test.logicmonitor.com",
      "percentPktsNotReceiveInTime" : 70,
      "timeoutInMSPktsNotReceive" : 300
    } ],
    "searchId" : null
  }

例2:すべてのWebサイトを取得する

次のPython3スクリプトは、api.logicmonitor.comポータル内のすべてのWebサイトのリストを返します。ここでは、結果ごとにid、name、type、alertStatusフィールドのみが返され、結果はalertStatusに従って降順で並べ替えられます。

#!/ bin / envpythonインポートリクエストimportjson import hashlib import base64 import time import hmac #Account Info AccessId = 'J62te62B8u7WnCR846h6' AccessKey = '{[H ^ LX = ^ Zg ^ 32yp-x(-2Bq22vZ〜 ^ u-k3 )8!9 [7U ^ 'Company =' api '#Request Info:Get Services httpVerb =' GET'resourcePath = '/ service / services'queryParams ='?fields = id、name、host、alertStatus&sort = -alertStatus '# URLの構築url = 'https://' + Company + '。logicmonitor.com / santaba / rest' + resourcePath + queryParams#現在の時刻をミリ秒単位で取得epoch = str(int(time.time()* 1000))#Concatenateリクエストの詳細requestVars = httpVerb + epoch + resourcePath#Construct署名hmac1 = hmac.new(AccessKey.encode()、msg = requestVars.encode()、digestmod = hashlib.sha256).hexdigest()署名= base64.b64encode(hmac1。 encode())#Construct headers auth = 'LMv1' + AccessId + ':' + Signature.decode()+ ':' + epoch headers = {'Content-Type': 'application / json'、 'Authorization':auth }#リクエストレスポンスを作成= requests.get(url、headers = headers)#Print sta tusと応答の本文print( 'Response Status:'、response.status_code)print( 'Response Body:'、response.content)

出力:

{"status":200、 "errmsg": "OK"、 "data":{"total":5、 "items":[{"type": "webservice"、 "id":58、 "name": "フォームベース認証"、 "alertStatus": "none"}、{"type": "webservice"、 "id":41、 "name": "Multi-Step"、 "alertStatus": "unconfirmed-warn" }、{"type": "ping"、 "id":60、 "name": "JIRA"、 "alertStatus": "unconfirmed-critical"}、{"type": "webservice"、 "id":49 、 "name": "LMCertification"、 "alertStatus": "none"}、{"type": "ping"、 "id":48、 "name": "LMService"、 "alertStatus": "none"}] 、 "searchId":null}

例3:XNUMXつのWebサイトを取得する

次のPython3スクリプトは、ID2のWebサイトの詳細を返します。

#!/ bin / envpythonインポートリクエストimportjson import hashlib import base64 import time import hmac #Account Info AccessId = 'J62te62B8u7WnCR846h6' AccessKey = '{[H ^ LX = ^ Zg ^ 32yp-x(-2Bq22vZ〜 ^ u-k3 )8!9 [7U ^ 'Company =' api '#Request Info:Get Services httpVerb =' GET'resourcePath = '/ service / services / 2'#Construct URL url = 'https://' + Company + '。 logicmonitor.com/santaba/rest'+ resourcePath#現在の時刻をミリ秒単位で取得epoch = str(int(time.time()* 1000))#リクエストの詳細を連結requestVars = httpVerb + epoch + resourcePath#署名を作成hmac1 = hmac.new (AccessKey.encode()、msg = requestVars.encode()、digestmod = hashlib.sha256).hexdigest()signature = base64.b64encode(hmac1.encode())#ヘッダーを構築するauth = 'LMv1' + AccessId + ': '+ Signature.decode()+': '+エポックヘッダー= {' Content-Type ':' application / json '、' Authorization ':auth}#リクエストレスポンスを作成= requests.get(url、headers = headers)#印刷ステータスと応答の本文print( 'Response Status:'、response.status_code)print( ' 応答本文: '、response.content)

出力:

{"status":200、 "errmsg": "OK"、 "data":{"type": "ping"、 "id":2、 "name": "JIRA"、 "description": ""、 " serviceFolderId ":11、" stopMonitoring ":false、" stopMonitoringByFolder ":false、" disableAlerting ":false、" individualSmAlertEnable ":true、" personalAlertLevel ":" critical "、" overallAlertLevel ":" critical "、" alertStatus ":" unconfirmed-critical "、" sdtStatus ":" none-none-none "、" alertDisableStatus ":" none-none-none "、" pollingInterval ":5、" transition ":1、" testLocation ":" {\ "smgIds \ ":[1,2,3,4,5]、\" all \ ":true}"、 "globalSmAlertCond":0、 "useDefaultLocationSetting":true、 "useDefaultAlertSetting":false、 "userPermission": "write" 、 "チェックポイント":[{"id":302、 "geoInfo": "全体"、 "smgId":0}、{"id":306、 "geoInfo": "アジア-シンガポール"、 "smgId":5 }、{"id":305、 "geoInfo": "Europe-Dublin"、 "smgId":4}、{"id":304、 "geoInfo": "US-San Francisco"、 "smgId":3} 、{"id":303、 "geoInfo": "US-ワシントンDC"、 "smgId":2}]、 "serviceProperties" :[]、 "count":5、 "host": "test.jira.com"、 "percentPktsNotReceiveInTime":80、 "timeoutInMSPktsNotReceive":500}

例4:XNUMXつのWebサイトを取得する

次のPython3スクリプトは、ID 2のWebサイトのID、名前、およびalertStatusを返します。

#!/ bin / envpythonインポートリクエストimportjson import hashlib import base64 import time import hmac #Account Info AccessId = 'J62te62B8u7WnCR846h6' AccessKey = '{[H ^ LX = ^ Zg ^ 32yp-x(-2Bq22vZ〜 ^ u-k3 )8!9 [7U ^ 'Company =' api '#Request Info:Get Services httpVerb =' GET'resourcePath = '/ service / services / 2'queryParams ='?fields = id、name、alertStatus '#Construct URL url = 'https://' + Company + '。logicmonitor.com/ santaba / rest' + resourcePath + queryParams#現在の時刻をミリ秒単位で取得epoch = str(int(time.time()* 1000))#リクエストの詳細を連結requestVars = httpVerb + epoch + resourcePath#Construct署名hmac1 = hmac.new(AccessKey.encode()、msg = requestVars.encode()、digestmod = hashlib.sha256).hexdigest()署名= base64.b64encode(hmac1.encode() )#Construct headers auth = 'LMv1' + AccessId + ':' + Signature.decode()+ ':' + epoch headers = {'Content-Type': 'application / json'、 'Authorization':auth} #Make request response = requests.get(url、headers = headers)#ステータスとrespoの本文を出力しますnse print( 'Response Status:'、response.status_code)print( 'Response Body:'、response.content)

出力:

{"status":200、 "errmsg": "OK"、 "data":{"id":60、 "name": "JIRA"、 "alertStatus": "unconfirmed-critical"}
記事上で