REST API 基本フィルター

最終更新日: 09 年 2023 月 XNUMX 日

LogicMonitor REST API を使用して API 呼び出しを行うと、結果が多すぎる場合があります。 検索をより具体的にするために、API フィルターを使用できます。 パターンを使用できますフィルターを作成します。

このサポート記事では、REST API を使用しました /alert/alerts と/device/devices フィルターの使用方法を説明する例として。 次の演算子でサポートされている値でエンドポイントをフィルタリングできます。

演算子説明
:等しい
!:等しくない
>越える
<以下
>:以上
<:以下
~含む
!~含まれていません

管理者の役割を持つユーザーは、非管理者の役割を持つユーザーよりも多くの結果を受け取ります。 管理者の役割を持つユーザーは、より多くの権限を持ち、ほとんどのデバイスにアクセスできます。 一方、管理者以外の役割を持つユーザーは、アクセスできるデバイスに基づいて結果を取得します。

一般的な例

このセクションでは、任意の REST API エンドポイントについて次の例を参照できます。

注: これらは単なるサンプルであり、ビジネス要件に合わせて変更する必要があります。

  • 色が赤のリソースをフィルタ
filter=color:"red"
  • 名前が * のリソースをフィルター処理するaaa そしてステータスは active
filter=name:"*aaa",status:"active"
  • ステータスが active or suspend
filter=status:"active"|"suspend"
  • 連絡先オブジェクトの名前が であるリソースをフィルター処理します hoo
filter=contact.name:"hoo"
  • プロパティ配列に次の名前の要素が少なくとも XNUMX つあるリソースをフィルター処理します。 location
filter=properties.name:"location"
  • ステータスが suspend または名前は aaa or bbb or ccc
filter=name:"aaa"|"bbb"|"ccc"||status:"suspend"
  • キーワードを含むすべてのリソースを検索します
filter=_all~"keyword"

フィルター /alert/alerts APIエンドポイント

フィルタを使用する場合は、次の点を考慮する必要があります。 

  • パラメーターに基づいてエンドポイントをフィルタリングすると、複数回 API をヒットしても、アラート数に変更 (アラートの新規追加または削除) がない限り、結果は一貫します。
    Sort リクエスト属性を指定すると、結果は alert プロパティに従ってソートされます。 たとえば、アラートが startEpoch アラート プロパティに基づいて並べ替えられている場合、結果はアラートの startEpoch に従って並べ替えられます。 一部のアラートの startEpoch が等しい場合、結果はアラート ID プロパティの昇順に基づいてソートされます。 したがって、結果は常に一貫しています。
  • GET アラート リスト API のエンドポイントをフィルタリングできます (/alert/alerts)。 GET アラート リスト API の応答は、要求パラメーター (フィルター) を使用してフィルター処理できます。
  • AND 演算子のみを使用して、アラート プロパティとその値をフィルター処理できます。 たとえば、フィルター= 、 、…条件がどこにあるか
  • フィルタリングできます /alert/alerts 一度に複数のプロパティを持つエンドポイント。 例えば、
    リクエストURL
{{url}}/alert/alerts?offset=0&size=300&sort=startEpoch&filter=startEpoch>:1653295431,startEpoch<:1658146793,severity:"4"|"3",cleared:"*",resourceTemplateName:"Host status",monitorObjectName~"pod-kube"

ここでは、XNUMX つのフィルターがアラート プロパティに適用されます。 startEpoch, severity, cleared, resourceTemplateName, monitorObjectName.

  • startEpoch is 1653295431 <= startEpoch <= 1658146793
  • severity どちらでもかまいません 3 or 4
  • cleared 値は true または false です
  • resourceTemplateName 等しい Host status
  • monitorObjectName 含まれています pod-kube

応答本文では、このクエリはフィルターに従って結果を一覧表示します。

{
"total": -301,
"items": [
{
"resourceId": 12596234,
"anomaly": false,
"instanceName": "HostStatus",
"monitorObjectId": 775798,
"endEpoch": 1653295561,
"rule": "",
"threshold": "> 300 300 300",
"type": "dataSourceAlert",
"startEpoch": 1653295431,
"enableAnomalyAlertGeneration": "",
"internalId": "LMD50170983",
"ackComment": "",
"monitorObjectName": "kube-proxy-mj7w2-pod-kube-system-dashboard-test",
"dataPointName": "idleInterval",
"instanceId": 284641854,
"dataPointId": 99721,
"suppressDesc": null,
"nextRecipient": 0,
"suppressor": null,
"id": "DS101384979",
"ruleId": 0,
"alertValue": "395.0",
"adAlert": false,
"ackedBy": "",
"severity": 4,
"sdted": false,
"ackedEpoch": 0,
"chain": "",
"SDT": null,
"subChainId": 0,
"enableAnomalyAlertSuppression": "",
"receivedList": "",
"monitorObjectType": "device",
"acked": false,
"resourceTemplateType": "DS",
"clearValue": "44.0",
"instanceDescription": "",
"dependencyRoutingState": null,
"monitorObjectGroups": [],
"dependencyRole": null,
"chainId": 0,
"resourceTemplateId": 143475810,
"cleared": true,
"adAlertDesc": "",
"resourceTemplateName": "Host Status"
},
{
"resourceId": 12596120,
"anomaly": false,
"instanceName": "HostStatus",
"monitorObjectId": 775797,
"endEpoch": 1653295561,
"rule": "",
"threshold": "> 300 300 300",
"type": "dataSourceAlert",
"startEpoch": 1653295431,
"enableAnomalyAlertGeneration": "",
"internalId": "LMD50170864",
"ackComment": "",
"monitorObjectName": "coredns-78fcd69978-snnq2-pod-kube-system-dashboard-test",
"dataPointName": "idleInterval",
"instanceId": 284641831,
"dataPointId": 99721,
"suppressDesc": null,
"nextRecipient": 0,
"suppressor": null,
"id": "DS101384981",
"ruleId": 0,
"alertValue": "396.0",
"adAlert": false,
"ackedBy": "",
"severity": 4,
"sdted": false,
"ackedEpoch": 0,
"chain": "",
"SDT": null,
"subChainId": 0,
"enableAnomalyAlertSuppression": "",
"receivedList": "",
"monitorObjectType": "device",
"acked": false,
"resourceTemplateType": "DS",
"clearValue": "4.0",
"instanceDescription": "",
"dependencyRoutingState": null,
"monitorObjectGroups": [],
"dependencyRole": null,
"chainId": 0,
"resourceTemplateId": 143475810,
"cleared": true,
"adAlertDesc": "",
"resourceTemplateName": "Host Status"
}
],
"searchId": "",
"isMin": false
}

例: /alert/alerts filter

  • エポック範囲 1653295431 <= の間に生成されたアラートをフィルター処理します startEpoch <= 1663756550
{{url}}/alert/alerts?filter=startEpoch>:1653295431,startEpoch<:1663756550
  • でアラートをフィルタリングする severity = 3 または 4。重大度 3 はエラーを示し、重大度 4 は重大なアラートを示します。
{{url}}/alert/alerts?filter=severity:"4"|"3"
  • 以下を含むすべてのアラートを表示します cleared & uncleared アラート
{{url}}/alert/alerts?filter=cleared:"*"
  • フィルタ cleared アラート
{{url}}/alert/alerts?filter=cleared:true
  • でアラートをフィルタリングする resourceTemplateNameHost status
{{url}}/alert/alerts?filter=resourceTemplateName:"Host status"
  • でアラートをフィルタリングする monitorObjectName 含む pod-kube
{{url}}/alert/alerts?filter=monitorObjectName~"pod-kube"
  • 5 つのアラート プロパティを使用してアラートをフィルター処理する – startEpochseverityclearedresourceTemplateNamemonitorObjectName. 結果は startEpoch (昇順) に基づいて並べ替えられます。 オフセットが 0 で、指定されたサイズが 300 であるため、フィルター処理されたすべてのアラートのうち、最初の 300 個のアラートが取得されます。
{{url}}/alert/alerts?offset=0&size=300&sort=startEpoch&filter=startEpoch>:1653295431,startEpoch<:1658146793,severity:"4"|"3",cleared:"*",resourceTemplateName:"Host status",monitorObjectName~"pod-kube"
  • 次のタイプのアラートをフィルタ dataSourceAlert そして認められる
{{url}}/alert/alerts?filter=acked:true,type:"dataSourceAlert"
  • エスカレーション チェーンが Secondary およびアラート ルール名に含まれる Critical
{{url}}/alert/alerts?filter=chain:"Secondary",rule~"Critical"
  • アラートのフィルタ instanceName is HostStatus
{{url}}/alert/alerts?filter=instanceName:"HostStatus"
  • アラートのフィルタ dataPointName is Latency
{{url}}/alert/alerts?filter=dataPointName:"Latency"
  • SDT にあるアラートをフィルター処理する
{{url}}/alert/alerts?filter=sdted:true
  • 次のアラートをフィルタ cleared そして、しています endEpoch <= 1658820186
{{url}}/alert/alerts?filter=cleared:true,endEpoch<:1658820186
  • 次のアラートをフィルタ cleared そして、しています endEpoch > 1658820186
{{url}}/alert/alerts?filter=cleared:true,endEpoch>1658820186
  • 次のアラートをフィルタ cleared そして、しています endEpoch <=1658820186 および endEpoch> = 1658820079
{{url}}/alert/alerts?filter=cleared:true,endEpoch<:1658820186,endEpoch>:1658820079

/ のフィルターdevice/devices APIエンドポイント

次のフィルターを使用して、API 呼び出しを絞り込むことができます。

  • ID が 44 のデバイスをフィルタ
{{url}}/device/devices?filter=id:44
  • 文字列で終わる名前のデバイスをフィルタリングする service, devicetype is 6
{{url}}/device/devices?filter=name:"*service",deviceType:6
  • でデバイスをフィルタリングする hostGroupIds 24517 or 31
{{url}}/device/devices?filter=hostGroupIds:"24517" | "31"
  • でデバイスをフィルタリングする inheritedProperties プロパティ名の XNUMX つが snmp.community 資産価値に関係なく。
{{url}}/device/devices?filter=inheritedProperties.name:"snmp.community"
  • 次のデバイスをフィルタ displayName 文字列が含まれています Member またはデバイス id11. 結果には、XNUMX つまたは両方のフィルターに一致するデバイスが表示されます。
{{url}}/device/devices?filter=displayName~"*Member" || id>11
  • 次のデバイスをフィルタ displayName 文字列が含まれています Member AND デバイス id > 11. 結果には、両方のフィルターに一致するデバイスのみが表示されます。
{{url}}/device/devices?filter=displayName~"*Member", id>11
  • キーワードを含むすべてのデバイスを検索します new device
{{url}}/device/devices?filter=_all~"new device"

演算子の例

含むおよび含まない (~ および !~) 演算子

次のクエリを実行します。

{{url}}/device/devices?fields=autoProperties,name,id&filter=autoProperties.name:"predef.externalResourceID",autoProperties.value~"service"

応答本文で、このクエリは、デバイスの ID、名前、および autoProperties を一覧表示します。 autoProperties.namepredef.externalResourceID または任意の autoProperties.value 部分文字列 = service.

注: また、特殊文字または数字のみを含む autoProperty 値もリストします。

{
"total":4865,
"items":[
{
"id":44,
"name":"Instance",
"autoProperties":[
{
"name":"predef.externalResourceID",
"value":"service_44"
},
{
"name":"predef.externalResourceType",
"value":"Service"
}
]
},
{
"id":63,
"name":"gcp",
"autoProperties":[
{
"name":"predef.externalResourceID",
"value":"service_63"
},
{
"name":"predef.externalResourceType",
"value":"Service"
}
]
},
{
"id":65,
"name":"cloudAndNormal",
"autoProperties":[
{
"name":"predef.externalResourceID",
"value":"service_memberdevice_65"
},
{
"name":"predef.externalResourceType",
"value":"ServiceMember"
}
]
 
{
"id": 2378,
"name": "1.1.1.3",
"autoProperties": [
{
"name": "predef.externalResourceID",
"value": "service_2378"
},
{
"name": "predef.externalResourceType",
"value": "Service"
},
{
"name": "auto.host",
"value": "1.1.1.3"
}
]
},
 
 
}

等しい、含む、より大きい、より小さい (:、~、>、<) 演算子

次のクエリを実行します。

{{url}}/device/devices?filter=id<5000,displayName~"service",hostGroupIds:"1",createdOn>1559000000

応答本文で、このクエリは ID が 5000 未満のすべてのデバイスを一覧表示します AND displayName 「を含む」service" ストリング、 hostGroupIds =「1」、および createdOn 時間 > 1559000000

{
"total": 1,
"items": [
{
"id": 4389,
"name": "czservice",
"displayName": "czservice",
"deviceType": 6,
"relatedDeviceId": -1,
"currentCollectorId": -4,
"preferredCollectorId": -4,
"autoBalancedCollectorGroupId": 0,
"preferredCollectorGroupId": 1,
"preferredCollectorGroupName": "@default",
"description": "",
"createdOn": 1559236150,
"updatedOn": 1632927244,
"disableAlerting": false,
"autoPropsAssignedOn": 0,
"autoPropsUpdatedOn": 0,
"scanConfigId": 0,
"link": "",
"enableNetflow": false,
"netflowCollectorId": 0,
"netflowCollectorGroupId": 0,
"netflowCollectorGroupName": null,
"isPreferredLogCollectorConfigured": false,
"currentLogCollectorId": 0,
"logCollectorId": 0,
"logCollectorDescription": null,
"logCollectorGroupId": 0,
"logCollectorGroupName": null,
"lastDataTime": 0,
"lastRawdataTime": 0,
"hostGroupIds": "1",
"sdtStatus": "none-none-none",
"userPermission": "write",
"rolePrivileges": [],
"hostStatus": "normal",
"alertStatus": "none",
"alertStatusPriority": 100000,
"awsState": 1,
"azureState": 1,
"gcpState": 1,
"alertDisableStatus": "none-none-none",
"alertingDisabledOn": null,
"collectorDescription": "Service Data Aggregator",
"netflowCollectorDescription": null,
"customProperties": [
{
"name": "predef.bizservice.evalMembersInterval",
"value": "30"
},
{
"name": "predef.bizservice.members",
"value": "{\"device\":[{\"deviceGroupFullPath\":\"Devices by Type*\",\"deviceDisplayName\":\"127.0.0.34_PhysicalDatastore\",\"deviceProperties\":[]}],\"instance\":[]}"
},
{
"name": "system.categories",
"value": ""
}
],
"resourceIds": null,
"upTimeInSeconds": 0,
"deletedTimeInMs": 0,
"toDeleteTimeInMs": 0,
"hasDisabledSubResource": false,
"ancestorHasDisabledLogicModule": false,
"systemProperties": [
{
"name": "system.enablenetflow",
"value": "false"
},
{
"name": "system.collectorplatform",
"value": "n/a"
},
{
"name": "system.collectorid",
"value": "-4"
},
{
"name": "system.deviceId",
"value": "4389"
},
{
"name": "system.prefcollectordesc",
"value": "Service Data Aggregator"
},
{
"name": "system.collectordesc",
"value": "Service Data Aggregator"
},
{
"name": "system.deviceGroupId",
"value": "1"
},
{
"name": "system.resourceCreatedOn",
"value": "1559236150"
},
{
"name": "system.devicetype",
"value": "6"
},
{
"name": "system.collectorversion",
"value": "0"
},
{
"name": "system.prefcollectorid",
"value": "-4"
},
{
"name": "system.displayname",
"value": "czservice"
},
{
"name": "system.hostname",
"value": "czservice"
}
],
"autoProperties": [
{
"name": "predef.externalResourceID",
"value": "service_4389"
},
{
"name": "predef.externalResourceType",
"value": "Service"
}
],
"inheritedProperties": [
{
"name": "test.pass",
"value": "********"
},
{
"name": "esx.user",
"value": "n n "
},
{
"name": "snmp.community",
"value": "********"
},
{
"name": "esx.pass",
"value": "********"
},
{
"name": "ssh.pass",
"value": "********"
}
],
"syntheticsCollectorIds": null
}
],
"searchId": null,
"isMin": false
}
記事上で