Use the following POST API to return all the query templates related to devices.POST /api/v2/querytemplates/device
Response:
{
"success": true,
"responseObject": [
{
"type": "*",
"profile": "*",
"specificType": "*",
"templateName": "query-ping-availability",
"queryTemplate": "{\"query\": {\"bool\": {\"filter\": [{\"term\": {\"deviceId\": {\"value\": \"{{deviceId}}\"}}}, {\"range\": {\"@timestamp\": {\"gte\": \"{{timestamp_gte}}\", \"lte\": \"{{timestamp_lte}}\"}}}]}}, \"aggs\": {\"{{statusInterval}}\": {\"date_histogram\": {\"field\": \"@timestamp\", \"interval\": \"{{statusInterval}}\"}, \"aggs\": {\"status\": {\"bucket_script\": {\"buckets_path\": {\"tot\": \"_count\", \"success\": \"count_success\"}, \"script\": \"def threshold = 0.5; if (params.success / params.tot > threshold) {return 1} else {return 0}\"}}, \"count_success\": {\"sum\": {\"script\": \"return doc['up'].value == true ? 1 : 0\"}}}}}, \"size\": 0}",
"indices": [
"heartbeat-*"
]
},
{
"type": "*",
"profile": "*",
"specificType": "*",
"templateName": "query-snmp-availability",
"queryTemplate": "{\"query\": {\"bool\": {\"filter\": [{\"term\": {\"deviceId\": {\"value\": \"{{deviceId}}\"}}}, {\"range\": {\"@timestamp\": {\"gte\": \"{{timestamp_gte}}\", \"lte\": \"{{timestamp_lte}}\"}}}]}}, \"aggs\": {\"{{statusInterval}}\": {\"date_histogram\": {\"field\": \"@timestamp\", \"interval\": \"{{statusInterval}}\"}, \"aggs\": {\"status\": {\"bucket_script\": {\"buckets_path\": {\"fail\": \"count_fail\", \"tot\": \"_count\"}, \"script\": \"def threshold = 0.5; if ((params.tot - params.fail) / params.tot > threshold) {return 1} else {return 0}\"}}, \"count_fail\": {\"value_count\": {\"field\": \"Failed\"}}}}}, \"size\": 0}",
"indices": [
"snmpbeat-*"
]
},
{
"type": "CPE",
"profile": "sdwan",
"specificType": "MERAKI",
"templateName": "meraki-device-status",
"queryTemplate": "{\"sort\": [{\"@timestamp\": {\"order\": \"desc\"}}], \"query\": {\"bool\": {\"filter\": [{\"term\": {\"deviceId\": {\"value\": \"{{deviceId}}\"}}}, {\"range\": {\"@timestamp\": {\"gte\": \"{{timestamp_gte}}\", \"lte\": \"{{timestamp_lte}}\"}}}, {\"bool\": {\"must\": [{\"exists\": {\"field\": \"DeviceHealth\"}}]}}]}}, \"aggs\": {\"{{statusInterval}}\": {\"date_histogram\": {\"field\": \"@timestamp\", \"interval\": \"{{statusInterval}}\"}, \"aggs\": {\"status\": {\"bucket_script\": {\"buckets_path\": {\"total\": \"_count\", \"deviceHealthSum\": \"deviceHealthSum\"}, \"gap_policy\": \"insert_zeros\", \"script\": \"(params.deviceHealthSum / params.total >= 0.5) ? 1 : 0\"}}, \"deviceHealthSum\": {\"sum\": {\"script\": \"return doc['DeviceHealth.status'].value == 'offline' ? 0 : doc['DeviceHealth.status'].value == 'online' ? 1 : 'undefined'\"}}}}}, \"size\": 1}",
"indices": [
"merakibeat-*"
]
}
],
"command": "Get all device health query templates",
"parms": {},
"httpStatus": "OK",
"message": "Get all device health query templates",
"errors": [],
"throwable": null
}
POST api/v2/querytemplates/device
Response:
{
"type": "CPE",
"profile": "sdwan",
"specificType": "MERAKI",
"templateName": "meraki-device-status",
"queryTemplate": "{\"sort\": [{\"@timestamp\": {\"order\": \"desc\"}}], \"query\": {\"bool\": {\"filter\": [{\"term\": {\"deviceId\": {\"value\": \"{{deviceId}}\"}}}, {\"range\": {\"@timestamp\": {\"gte\": \"{{timestamp_gte}}\", \"lte\": \"{{timestamp_lte}}\"}}}, {\"bool\": {\"must\": [{\"exists\": {\"field\": \"DeviceHealth\"}}]}}]}}, \"aggs\": {\"{{statusInterval}}\": {\"date_histogram\": {\"field\": \"@timestamp\", \"interval\": \"{{statusInterval}}\"}, \"aggs\": {\"status\": {\"bucket_script\": {\"buckets_path\": {\"total\": \"_count\", \"deviceHealthSum\": \"deviceHealthSum\"}, \"gap_policy\": \"insert_zeros\", \"script\": \"(params.deviceHealthSum / params.total >= 0.5) ? 1 : 0\"}}, \"deviceHealthSum\": {\"sum\": {\"script\": \"return doc['DeviceHealth.status'].value == 'offline' ? 0 : doc['DeviceHealth.status'].value == 'online' ? 1 : 'undefined'\"}}}}}, \"size\": 1}",
"indices": [
"merakibeat-*"
]
}