zabbix_export: version: '7.0' template_groups: - uuid: c2c162144c2d4c5491c8801193af4945 name: Templates/Cloud templates: - uuid: 29325098807848aa928b4192ad5e020f template: 'Azure Cosmos DB for MongoDB by HTTP' name: 'Azure Cosmos DB for MongoDB by HTTP' description: | This template is designed to monitor Microsoft Azure Cosmos DB for MongoDB by HTTP. It works without any external scripts and uses the script item. Setup: 1. Create an Azure service principal via the Azure command-line interface (Azure CLI) for your subscription. `az ad sp create-for-rbac --name zabbix --role reader --scope /subscriptions/` See https://docs.microsoft.com/en-us/cli/azure/create-an-azure-service-principal-azure-cli for more details. 2. Link the template to a host. 3. Configure the macros: {$AZURE.APP.ID}, {$AZURE.PASSWORD}, {$AZURE.TENANT.ID}, {$AZURE.SUBSCRIPTION.ID}, and {$AZURE.RESOURCE.ID}. You can discuss this template or leave feedback on our forum https://www.zabbix.com/forum/zabbix-suggestions-and-feedback/. Generated by official Zabbix template tool "Templator" vendor: name: Zabbix version: 7.0-3 groups: - name: Templates/Cloud items: - uuid: 9e247bdb17f44630b9440b59d5ef251b name: 'Autoscale max throughput' type: DEPENDENT key: azure.cosmosdb.autoscale.max.throughput delay: '0' description: 'The autoscale max throughput.' preprocessing: - type: JSONPATH parameters: - $.requests.AutoscaleMaxThroughput.maximum error_handler: DISCARD_VALUE master_item: key: azure.cosmosdb.data.get tags: - tag: component value: storage - uuid: 35a7d2c96990407f937e07fd160266a9 name: 'Get errors' type: DEPENDENT key: azure.cosmosdb.data.errors delay: '0' value_type: TEXT trends: '0' description: 'A list of errors from API requests.' preprocessing: - type: JSONPATH parameters: - $.error error_handler: CUSTOM_VALUE - type: DISCARD_UNCHANGED_HEARTBEAT parameters: - 1h master_item: key: azure.cosmosdb.data.get tags: - tag: component value: raw triggers: - uuid: dfd484aa8a4e4b759e4e34c5318c7176 expression: 'length(last(/Azure Cosmos DB for MongoDB by HTTP/azure.cosmosdb.data.errors))>0' name: 'Azure Cosmos DB: There are errors in requests to API' opdata: '{ITEM.LASTVALUE1}' priority: AVERAGE description: 'Zabbix has received errors in response to API requests.' tags: - tag: scope value: availability - uuid: 647faea1597c4da6a3cd78694be8e77e name: 'Get data' type: SCRIPT key: azure.cosmosdb.data.get history: '0' value_type: TEXT trends: '0' params: | const CTlsConfig = function (raw_value) { raw_value = String(raw_value).trim().toLowerCase(); if (['none', 'peer', 'full'].indexOf(raw_value) === -1) { raw_value = 'full'; } this.options = { SSLVerifyPeer: (raw_value === 'peer' || raw_value === 'full'), SSLVerifyHost: (raw_value === 'full') }; this.enabled = (raw_value !== 'none'); this.checkURL = function (url) { if (this.enabled && !/^https:\/\//i.test(url)) { throw 'TLS certificate verification is enabled by {$' + 'HTTP.TLS.VERIFY}, but the URL uses plain HTTP: ' + url + '. Use an "https://" URL, or set {$' + 'HTTP.TLS.VERIFY} to `none` to disable verification.'; } return url; }; } var AzureCosmosDB = { params: {}, token: null, setParams: function (params) { ['app_id', 'password', 'tenant_id', 'subscription_id', 'resource_id'].forEach(function (field) { if (typeof params !== 'object' || typeof params[field] === 'undefined' || params[field] === '') { throw 'Required param is not set: ' + field + '.'; } }); AzureCosmosDB.params = params; AzureCosmosDB.tls = new CTlsConfig(params.tls_verify); }, login: function () { var response, login = new HttpRequest(AzureCosmosDB.tls.options); if (typeof AzureCosmosDB.params.proxy !== 'undefined' && AzureCosmosDB.params.proxy !== '') { login.setProxy(AzureCosmosDB.params.proxy); } login.addHeader('Content-Type: application/x-www-form-urlencoded'); response = login.post( 'https://login.microsoftonline.com/' + encodeURIComponent(AzureCosmosDB.params.tenant_id) + '/oauth2/token', 'grant_type=client_credentials&resource=' + encodeURIComponent('https://management.azure.com/') + '&client_id=' + encodeURIComponent(AzureCosmosDB.params.app_id) + '&client_secret=' + encodeURIComponent(AzureCosmosDB.params.password) ); if (login.getStatus() !== 200) { throw 'Login failed with status code ' + login.getStatus() + ': ' + response; } try { response = JSON.parse(response); } catch (error) { throw 'Failed to parse login session response.'; } if (!response.hasOwnProperty('access_token')) { throw 'Authentication response does not contain access token.'; } AzureCosmosDB.token = response['access_token']; }, request: function (url) { var response, request = new HttpRequest(AzureCosmosDB.tls.options); if (typeof AzureCosmosDB.params.proxy !== 'undefined' && AzureCosmosDB.params.proxy !== '') { request.setProxy(AzureCosmosDB.params.proxy); } if (!AzureCosmosDB.token) { throw 'Request does not contain access token.'; } request.addHeader('Accept: application/json'); request.addHeader('Authorization: Bearer ' + AzureCosmosDB.token); Zabbix.log(4, '[ AzureCosmosDB ] request url: ' + url); response = request.get(url); if (request.getStatus() !== 200) { throw 'Request failed with status code ' + request.getStatus() + ': ' + response; } try { return JSON.parse(response); } catch (error) { throw 'Failed to parse response received from API.'; } }, getField: function (data, path) { var steps = path.split('.'); for (var i = 0; i < steps.length; i++) { var step = steps[i]; if (typeof data !== 'object' || typeof data[step] === 'undefined') { throw 'Required field was not found: ' + path; } data = data[step]; } return data; }, getMetricsData: function () { var data = {}; start_date = new Date((new Date().getTime()) - 600000).toISOString().replace(/\.\d+/, ''); end_date = new Date(new Date().getTime()).toISOString().replace(/\.\d+/, ''); endpoints = { 'availability': '/providers/Microsoft.Insights/metrics?metricnames=ServiceAvailability&api-version=2021-05-01&interval=PT1H×pan=' + encodeURIComponent(start_date) + '/' + encodeURIComponent(end_date), 'requests': '/providers/Microsoft.Insights/metrics?metricnames=DataUsage,IndexUsage,DocumentQuota,AvailableStorage,DocumentCount,NormalizedRUConsumption,PhysicalPartitionThroughputInfo,PhysicalPartitionSizeInfo,AutoscaleMaxThroughput,ProvisionedThroughput,TotalRequests,TotalRequestUnits,MetadataRequests,MongoRequests,MongoRequestCharge,ServerSideLatency,ServerSideLatencyGateway,ServerSideLatencyDirect,ReplicationLatency&api-version=2021-05-01×pan=' + encodeURIComponent(start_date) + '/' + encodeURIComponent(end_date), }; Object.keys(endpoints).forEach(function (field) { data[field] = {}; try { metrics = AzureCosmosDB.request('https://management.azure.com' + AzureCosmosDB.params.resource_id + endpoints[field]); if (!metrics.hasOwnProperty('value')) { throw 'Failed getting required field. Check debug log for more information.'; } for (k in metrics.value) { key = AzureCosmosDB.getField(metrics.value[k], 'name.value') if (metrics.value[k].timeseries.length === 0) { metrics.value[k].timeseries.push({ 'data': ['nodata'] }) } data[field][key] = AzureCosmosDB.getField(metrics.value[k], 'timeseries.0.data.0'); } } catch (error) { data.error = error.toString(); } }); return data } }; try { AzureCosmosDB.setParams(JSON.parse(value)); AzureCosmosDB.login(); return JSON.stringify(AzureCosmosDB.getMetricsData()); } catch (error) { error += (String(error).endsWith('.')) ? '' : '.'; Zabbix.log(3, '[ AzureCosmosDB ] ERROR: ' + error); return JSON.stringify({ 'error': error }); } description: 'The result of API requests is expressed in the JSON.' timeout: '{$AZURE.DATA.TIMEOUT}' parameters: - name: app_id value: '{$AZURE.APP.ID}' - name: password value: '{$AZURE.PASSWORD}' - name: proxy value: '{$AZURE.PROXY}' - name: resource_id value: '{$AZURE.RESOURCE.ID}' - name: subscription_id value: '{$AZURE.SUBSCRIPTION.ID}' - name: tenant_id value: '{$AZURE.TENANT.ID}' - name: tls_verify value: '{$HTTP.TLS.VERIFY:"Azure Cosmos DB for MongoDB"}' tags: - tag: component value: raw - uuid: 947a2eb530754a609fa81c59e29fe7b7 name: 'Data usage' type: DEPENDENT key: azure.cosmosdb.data.usage delay: '0' units: B description: 'The total data usage.' preprocessing: - type: JSONPATH parameters: - $.requests.DataUsage.total error_handler: DISCARD_VALUE master_item: key: azure.cosmosdb.data.get tags: - tag: component value: storage - uuid: 0bf3da9168144016b663c9b8e76447fa name: 'Document count' type: DEPENDENT key: azure.cosmosdb.document.count delay: '0' description: 'The total document count.' preprocessing: - type: JSONPATH parameters: - $.requests.DocumentCount.total error_handler: DISCARD_VALUE master_item: key: azure.cosmosdb.data.get tags: - tag: component value: storage - uuid: 7fa0f59f8cfa4d9e83086b203e4f71ea name: 'Document quota' type: DEPENDENT key: azure.cosmosdb.document.quota delay: '0' units: B description: 'The total storage quota.' preprocessing: - type: JSONPATH parameters: - $.requests.DocumentQuota.total error_handler: DISCARD_VALUE master_item: key: azure.cosmosdb.data.get tags: - tag: component value: storage - uuid: b09f9445d960415185457b89b6a73452 name: 'Index usage' type: DEPENDENT key: azure.cosmosdb.index.usage delay: '0' units: B description: 'The total index usage.' preprocessing: - type: JSONPATH parameters: - $.requests.IndexUsage.total error_handler: DISCARD_VALUE master_item: key: azure.cosmosdb.data.get tags: - tag: component value: storage - uuid: cd35f04b180542cda50dc5d4e979e54e name: 'Metadata requests' type: DEPENDENT key: azure.cosmosdb.metadata.requests delay: '0' description: | The count of metadata requests. Cosmos DB maintains system metadata collection for each account, which allows you to enumerate collections, databases, etc., and their configurations, free of charge. preprocessing: - type: JSONPATH parameters: - $.requests.MetadataRequests.count error_handler: DISCARD_VALUE master_item: key: azure.cosmosdb.data.get tags: - tag: component value: storage - uuid: e42cf83e456a490295a84cfe9eb288ef name: 'Mongo requests' type: DEPENDENT key: azure.cosmosdb.mongo.requests delay: '0' description: 'The number of Mongo requests made.' preprocessing: - type: JSONPATH parameters: - $.requests.MongoRequests.count error_handler: DISCARD_VALUE master_item: key: azure.cosmosdb.data.get tags: - tag: component value: storage - uuid: 8fd4068986af444799ae64c6bc8f16a6 name: 'Mongo request charge' type: DEPENDENT key: azure.cosmosdb.mongo.requests.charge delay: '0' description: 'The Mongo request units consumed.' preprocessing: - type: JSONPATH parameters: - $.requests.MongoRequestCharge.total error_handler: DISCARD_VALUE master_item: key: azure.cosmosdb.data.get tags: - tag: component value: storage - uuid: fda6b39ce6ef4b8c8418b2e123ecdd17 name: 'Normalized RU consumption' type: DEPENDENT key: azure.cosmosdb.normalized.ru.consumption delay: '0' units: '%' description: 'The max RU consumption percentage per minute.' preprocessing: - type: JSONPATH parameters: - $.requests.NormalizedRUConsumption.maximum error_handler: DISCARD_VALUE master_item: key: azure.cosmosdb.data.get tags: - tag: component value: storage - uuid: be6800214a0443e899c40f8a4b6c3f21 name: 'Physical partition size' type: DEPENDENT key: azure.cosmosdb.physical.partition.size delay: '0' units: B description: 'The physical partition size in bytes.' preprocessing: - type: JSONPATH parameters: - $.requests.PhysicalPartitionSizeInfo.maximum error_handler: DISCARD_VALUE master_item: key: azure.cosmosdb.data.get tags: - tag: component value: storage - uuid: e30d5eadde15427484e7a0d1cb38e9e3 name: 'Physical partition throughput' type: DEPENDENT key: azure.cosmosdb.physical.partition.throughput delay: '0' description: 'The physical partition throughput.' preprocessing: - type: JSONPATH parameters: - $.requests.PhysicalPartitionThroughputInfo.maximum error_handler: DISCARD_VALUE master_item: key: azure.cosmosdb.data.get tags: - tag: component value: storage - uuid: 49311bbfb2584a46b42ed1a7d8fcfd94 name: 'Provisioned throughput' type: DEPENDENT key: azure.cosmosdb.provisioned.throughput delay: '0' description: 'The provisioned throughput.' preprocessing: - type: JSONPATH parameters: - $.requests.ProvisionedThroughput.maximum error_handler: DISCARD_VALUE master_item: key: azure.cosmosdb.data.get tags: - tag: component value: storage - uuid: 6d7175e27d10406191c883dc2e5949e4 name: 'Replication latency, P99' type: DEPENDENT key: azure.cosmosdb.replication.latency delay: '0' value_type: FLOAT units: s description: 'The P99 replication latency across source and target regions for geo-enabled account.' preprocessing: - type: JSONPATH parameters: - $.requests.ReplicationLatency.average error_handler: DISCARD_VALUE - type: MULTIPLIER parameters: - '0.001' master_item: key: azure.cosmosdb.data.get tags: - tag: component value: network - uuid: d9b5af0c71874114b48464ce20f8cf3d name: 'Server side latency' type: DEPENDENT key: azure.cosmosdb.server.side.latency delay: '0' value_type: FLOAT units: s description: 'The server side latency.' preprocessing: - type: JSONPATH parameters: - $.requests.ServerSideLatency.average error_handler: DISCARD_VALUE - type: MULTIPLIER parameters: - '0.001' master_item: key: azure.cosmosdb.data.get tags: - tag: component value: network - uuid: 7587d3750d1643f085db5931670dc2f3 name: 'Server side latency, direct' type: DEPENDENT key: azure.cosmosdb.server.side.latency.direct delay: '0' value_type: FLOAT units: s description: 'The server side latency in direct connection mode.' preprocessing: - type: JSONPATH parameters: - $.requests.ServerSideLatencyDirect.average error_handler: DISCARD_VALUE - type: MULTIPLIER parameters: - '0.001' master_item: key: azure.cosmosdb.data.get tags: - tag: component value: network - uuid: 0aefdc3101fe4bcba4743d6e32671554 name: 'Server side latency, gateway' type: DEPENDENT key: azure.cosmosdb.server.side.latency.gateway delay: '0' value_type: FLOAT units: s description: 'The server side latency in gateway connection mode.' preprocessing: - type: JSONPATH parameters: - $.requests.ServerSideLatencyGateway.average error_handler: DISCARD_VALUE - type: MULTIPLIER parameters: - '0.001' master_item: key: azure.cosmosdb.data.get tags: - tag: component value: network - uuid: 42bd03c1753b4f19bc9793b03834cd3d name: 'Service availability' type: DEPENDENT key: azure.cosmosdb.service.availability delay: '0' value_type: FLOAT units: '%' description: 'The account requests availability at one hour granularity.' preprocessing: - type: JSONPATH parameters: - $.availability.ServiceAvailability.average error_handler: DISCARD_VALUE master_item: key: azure.cosmosdb.data.get tags: - tag: component value: health triggers: - uuid: c7649cd317f04a3d8fec0eebe3df6766 expression: '(min(/Azure Cosmos DB for MongoDB by HTTP/azure.cosmosdb.service.availability,#3))<{$AZURE.DB.COSMOS.MONGO.AVAILABILITY}' name: 'Azure Cosmos DB: Cosmos DB for MongoDB account: Availability is low' opdata: '{ITEM.LASTVALUE1}' priority: WARNING tags: - tag: scope value: availability - uuid: f4d4d2def5e945ab9048ada4813b7f04 name: 'Total request units' type: DEPENDENT key: azure.cosmosdb.total.request.units delay: '0' value_type: FLOAT description: 'The request units consumed per minute.' preprocessing: - type: JSONPATH parameters: - $.requests.TotalRequestUnits.total error_handler: DISCARD_VALUE master_item: key: azure.cosmosdb.data.get tags: - tag: component value: storage - uuid: 3dd2cd4edb7746edb9d917c83b280ca3 name: 'Total requests' type: DEPENDENT key: azure.cosmosdb.total.requests delay: '0' description: 'Number of requests per minute.' preprocessing: - type: JSONPATH parameters: - $.requests.TotalRequests.count error_handler: DISCARD_VALUE master_item: key: azure.cosmosdb.data.get tags: - tag: component value: storage tags: - tag: class value: software - tag: target value: azure - tag: target value: cosmosdb - tag: target value: mongodb macros: - macro: '{$AZURE.APP.ID}' description: 'The App ID of Microsoft Azure.' - macro: '{$AZURE.DATA.TIMEOUT}' value: 15s description: 'API response timeout.' - macro: '{$AZURE.DB.COSMOS.MONGO.AVAILABILITY}' value: '70' description: 'The warning threshold of the Cosmos DB for MongoDB service availability.' - macro: '{$AZURE.PASSWORD}' type: SECRET_TEXT description: 'Microsoft Azure password.' - macro: '{$AZURE.PROXY}' description: 'Sets the HTTP proxy value. If this macro is empty, then no proxy is used.' - macro: '{$AZURE.RESOURCE.ID}' description: 'Microsoft Azure Cosmos DB ID.' - macro: '{$AZURE.SUBSCRIPTION.ID}' description: 'Microsoft Azure subscription ID.' - macro: '{$AZURE.TENANT.ID}' description: 'Microsoft Azure tenant ID.' - macro: '{$HTTP.TLS.VERIFY}' value: full description: 'TLS certificate verification for script items: "none" - disabled, "peer" - verify the certificate chain and expiration, "full" - full verification. Any other value enables full verification. To override the setting for this template only, define the macro with the context "Azure Cosmos DB for MongoDB", e.g. {$HTTP.TLS.VERIFY:"Azure Cosmos DB for MongoDB"}.' dashboards: - uuid: 323fb91b388a44bfbd4b7d634f6e6b6c name: 'Overview Azure Cosmos DB for MongoDB' pages: - widgets: - type: item name: 'Service Availability' width: '18' height: '4' fields: - type: INTEGER name: decimal_places value: '0' - type: STRING name: down_color value: FF0000 - type: ITEM name: itemid.0 value: host: 'Azure Cosmos DB for MongoDB by HTTP' key: azure.cosmosdb.service.availability - type: INTEGER name: show.0 value: '2' - type: INTEGER name: show.1 value: '4' - type: STRING name: units value: '%' - type: STRING name: units_color value: 66BB6A - type: STRING name: up_color value: 4CAF50 - type: STRING name: value_color value: 66BB6A - type: graph 'y': '4' width: '72' height: '5' fields: - type: GRAPH name: graphid.0 value: host: 'Azure Cosmos DB for MongoDB by HTTP' name: 'Azure MongoDB: Usage' - type: STRING name: reference value: AAAAC - type: graph 'y': '9' width: '72' height: '5' fields: - type: GRAPH name: graphid.0 value: host: 'Azure Cosmos DB for MongoDB by HTTP' name: 'Azure MongoDB: Requests' - type: STRING name: reference value: AAAAB - type: graph 'y': '14' width: '72' height: '5' fields: - type: GRAPH name: graphid.0 value: host: 'Azure Cosmos DB for MongoDB by HTTP' name: 'Azure MongoDB: Latency' - type: STRING name: reference value: AAAAA - type: item name: 'Provisioned Throughput' x: '18' width: '18' height: '4' fields: - type: ITEM name: itemid.0 value: host: 'Azure Cosmos DB for MongoDB by HTTP' key: azure.cosmosdb.provisioned.throughput - type: INTEGER name: show.0 value: '2' - type: item name: 'Normalized RU Consumption' x: '36' width: '18' height: '4' fields: - type: ITEM name: itemid.0 value: host: 'Azure Cosmos DB for MongoDB by HTTP' key: azure.cosmosdb.normalized.ru.consumption - type: INTEGER name: show.0 value: '4' - type: INTEGER name: show.1 value: '2' - type: item name: 'Document Count' x: '54' width: '18' height: '4' fields: - type: ITEM name: itemid.0 value: host: 'Azure Cosmos DB for MongoDB by HTTP' key: azure.cosmosdb.document.count - type: INTEGER name: show.0 value: '2' graphs: - uuid: 89256a1eba8c49d2b7469a68ff050ac5 name: 'Azure MongoDB: Latency' graph_items: - color: 199C0D item: host: 'Azure Cosmos DB for MongoDB by HTTP' key: azure.cosmosdb.server.side.latency.gateway - sortorder: '1' color: F63100 item: host: 'Azure Cosmos DB for MongoDB by HTTP' key: azure.cosmosdb.server.side.latency - sortorder: '2' color: 00611C item: host: 'Azure Cosmos DB for MongoDB by HTTP' key: azure.cosmosdb.server.side.latency.direct - sortorder: '3' color: F7941D item: host: 'Azure Cosmos DB for MongoDB by HTTP' key: azure.cosmosdb.replication.latency - uuid: a1225fc27d334c5bbb5043e3d468bf02 name: 'Azure MongoDB: Requests' graph_items: - color: 199C0D item: host: 'Azure Cosmos DB for MongoDB by HTTP' key: azure.cosmosdb.total.requests - sortorder: '1' color: F63100 item: host: 'Azure Cosmos DB for MongoDB by HTTP' key: azure.cosmosdb.total.request.units - sortorder: '2' color: 00611C item: host: 'Azure Cosmos DB for MongoDB by HTTP' key: azure.cosmosdb.metadata.requests - sortorder: '3' color: F7941D item: host: 'Azure Cosmos DB for MongoDB by HTTP' key: azure.cosmosdb.mongo.requests - sortorder: '4' color: FC6EA3 item: host: 'Azure Cosmos DB for MongoDB by HTTP' key: azure.cosmosdb.mongo.requests.charge - uuid: 07168aaf3abb42f6b61746cc6e2d2910 name: 'Azure MongoDB: Usage' graph_items: - color: 199C0D item: host: 'Azure Cosmos DB for MongoDB by HTTP' key: azure.cosmosdb.data.usage - sortorder: '1' color: F63100 item: host: 'Azure Cosmos DB for MongoDB by HTTP' key: azure.cosmosdb.index.usage - sortorder: '2' color: 00611C item: host: 'Azure Cosmos DB for MongoDB by HTTP' key: azure.cosmosdb.document.quota