Files
templates-default/Azure_Cost_Management_by_HTTP.yaml

1157 lines
47 KiB
YAML

zabbix_export:
version: '7.0'
template_groups:
- uuid: c2c162144c2d4c5491c8801193af4945
name: Templates/Cloud
templates:
- uuid: c0263df8d8c14d30b24afcf45a6a354f
template: 'Azure Cost Management by HTTP'
name: 'Azure Cost Management by HTTP'
description: |
This template is designed to monitor Microsoft Cost Management 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/<subscription_id>`
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}.
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: f50c96da86654a25b937756cc7f7010e
name: 'Get daily costs'
type: SCRIPT
key: azure.get.daily.costs
delay: 0s;h/5m/30
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 AzureCost = {
params: {},
token: null,
setParams: function (params) {
['app_id', 'password', 'tenant_id', 'subscription_id'].forEach(function (field) {
if (typeof params !== 'object' || typeof params[field] === 'undefined' || params[field] === '') {
throw 'Required param is not set: ' + field + '.';
}
});
AzureCost.params = params;
AzureCost.tls = new CTlsConfig(params.tls_verify);
},
login: function () {
var response,
login = new HttpRequest(AzureCost.tls.options);
if (typeof AzureCost.params.proxy !== 'undefined' && AzureCost.params.proxy !== '') {
login.setProxy(AzureCost.params.proxy);
}
login.addHeader('Content-Type: application/x-www-form-urlencoded');
response = login.post(
'https://login.microsoftonline.com/' + encodeURIComponent(AzureCost.params.tenant_id) + '/oauth2/token',
'grant_type=client_credentials&resource=' + encodeURIComponent('https://management.azure.com/') + '&client_id=' + encodeURIComponent(AzureCost.params.app_id) + '&client_secret=' + encodeURIComponent(AzureCost.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.';
}
AzureCost.token = response['access_token'];
},
request: function (url, body) {
if (typeof body === 'undefined' || body === null) {
body = '';
}
var response,
headers,
regex = /-retry-after":"(\d+)"/,
ratelimit,
request = new HttpRequest(AzureCost.tls.options);
if (typeof AzureCost.params.proxy !== 'undefined' && AzureCost.params.proxy !== '') {
request.setProxy(AzureCost.params.proxy);
}
if (!AzureCost.token) {
throw 'Request does not contain access token.';
}
request.addHeader('Accept: application/json');
request.addHeader('Content-Type: application/json');
request.addHeader('Authorization: Bearer ' + AzureCost.token);
Zabbix.log(4, '[ AzureCost ] request url: ' + url);
response = request.post(url, body);
headers = JSON.stringify(request.getHeaders());
if (headers.match(regex) !== null && request.getStatus() === 429) {
ratelimit = headers.match(regex)[1];
Zabbix.log(4, '[ AzureCost ] Microsoft Cost Management have rate limit requests per 1 minute, retrying after ' + ratelimit + ' seconds');
Zabbix.sleep(ratelimit * 1010);
response = request.post(url, body);
}
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;
},
getCost: function () {
var metricData = {},
today = new Date(),
start_date = new Date(today);
start_date.setDate(today.getDate() - 1);
bodyRawCost = {
type: 'Usage',
'timeframe': 'Custom',
'timePeriod': {
'from': start_date,
'to': start_date
},
dataset: {
granularity: 'Daily',
aggregation: {
totalCost: {
name: 'PreTaxCost',
function: 'Sum'
}
},
grouping: [
{
type: 'Dimension',
name: 'Meter',
},
{
type: 'Dimension',
name: 'MeterSubcategory',
},
{
type: 'Dimension',
name: 'ResourceGroup',
},
{
type: 'Dimension',
name: 'ServiceName',
},
{
type: 'Dimension',
name: 'ResourceLocation',
}
]
}
};
metricData = AzureCost.request('https://management.azure.com/subscriptions/' + AzureCost.params.subscription_id + '/providers/Microsoft.CostManagement/query?api-version=2023-11-01', JSON.stringify(bodyRawCost));
var columns = AzureCost.getField(metricData, 'properties.columns');
return transformedData = {
data: AzureCost.getField(metricData, 'properties.rows').map(function (row) {
rowData = {};
columns.forEach(function (column, i) {
columnName = columns[i].name;
columnType = columns[i].type;
cellValue = row[i];
rowData[columnName] = column.type === "Number" ? cellValue.toString() : cellValue;
});
rowData.UsageDate = rowData.UsageDate.replace(/(\d{4})(\d{2})(\d{2})/, "$1-$2-$3");
return rowData;
})
};
}
};
try {
AzureCost.setParams(JSON.parse(value));
AzureCost.login();
return JSON.stringify(AzureCost.getCost());
}
catch (error) {
error += (String(error).endsWith('.')) ? '' : '.';
Zabbix.log(3, '[ AzureCost ] 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: subscription_id
value: '{$AZURE.SUBSCRIPTION.ID}'
- name: tenant_id
value: '{$AZURE.TENANT.ID}'
- name: tls_verify
value: '{$HTTP.TLS.VERIFY:"Azure Cost Management"}'
tags:
- tag: component
value: raw
- uuid: dc9824169b414303a75c5d98421bd6f8
name: 'Azure Cost: Get daily costs errors'
type: DEPENDENT
key: azure.get.daily.costs.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.get.daily.costs
tags:
- tag: component
value: raw
triggers:
- uuid: 503b3d5d008e4ad7b11384a3bd0c991c
expression: 'length(last(/Azure Cost Management by HTTP/azure.get.daily.costs.errors))>0'
name: 'Azure Cost: There are errors in requests to API'
event_name: 'Azure Cost: Error in daily costs requests to API'
opdata: '{ITEM.LASTVALUE1}'
priority: AVERAGE
description: 'Zabbix has received errors in response to API requests.'
tags:
- tag: scope
value: availability
- uuid: bbf6a0b136464d76a535ca016dcb8ae1
name: 'Get monthly costs'
type: SCRIPT
key: azure.get.monthly.costs
delay: 0s;h/12
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 AzureCost = {
params: {},
token: null,
setParams: function (params) {
['app_id', 'password', 'tenant_id', 'subscription_id', 'month'].forEach(function (field) {
if (typeof params !== 'object' || typeof params[field] === 'undefined' || params[field] === '') {
throw 'Required param is not set: ' + field + '.';
}
});
AzureCost.params = params;
AzureCost.tls = new CTlsConfig(params.tls_verify);
today = new Date();
AzureCost.params.end_date = today.toISOString();
month = today.getMonth();
today.setMonth(month - params.month);
AzureCost.params.start_time = new Date(today.getFullYear(), today.getMonth()).toISOString();
},
login: function () {
var response,
login = new HttpRequest(AzureCost.tls.options);
if (typeof AzureCost.params.proxy !== 'undefined' && AzureCost.params.proxy !== '') {
login.setProxy(AzureCost.params.proxy);
}
login.addHeader('Content-Type: application/x-www-form-urlencoded');
response = login.post(
'https://login.microsoftonline.com/' + encodeURIComponent(AzureCost.params.tenant_id) + '/oauth2/token',
'grant_type=client_credentials&resource=' + encodeURIComponent('https://management.azure.com/') + '&client_id=' + encodeURIComponent(AzureCost.params.app_id) + '&client_secret=' + encodeURIComponent(AzureCost.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.';
}
AzureCost.token = response['access_token'];
},
request: function (url, body) {
if (typeof body === 'undefined' || body === null) {
body = '';
}
var response,
headers,
regex = /-retry-after":"(\d+)"/,
ratelimit,
request = new HttpRequest(AzureCost.tls.options);
if (typeof AzureCost.params.proxy !== 'undefined' && AzureCost.params.proxy !== '') {
request.setProxy(AzureCost.params.proxy);
}
if (!AzureCost.token) {
throw 'Request does not contain access token.';
}
request.addHeader('Accept: application/json');
request.addHeader('Content-Type: application/json');
request.addHeader('Authorization: Bearer ' + AzureCost.token);
Zabbix.log(4, '[ AzureCost ] request url: ' + url);
response = request.post(url, body);
headers = JSON.stringify(request.getHeaders());
if (headers.match(regex) !== null && request.getStatus() === 429) {
ratelimit = headers.match(regex)[1];
Zabbix.log(4, '[ AzureCost ] Microsoft Cost Management have rate limit requests per 1 minute, retrying after ' + ratelimit + ' seconds');
Zabbix.sleep(ratelimit * 1010);
response = request.post(url, body);
}
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;
},
getCost: function (grouping) {
var metricData = {},
bodyRawCost = {
type: 'Usage',
timeframe: 'Custom',
timePeriod: {
from: AzureCost.params.start_time,
to: AzureCost.params.end_date
},
dataset: {
aggregation: {
totalCost: {
name: 'PreTaxCost',
function: 'Sum'
}
},
grouping: [
{
type: 'Dimension',
name: 'BillingMonth'
},
{
type: 'Dimension',
name: grouping
},
]
}
};
metricData = AzureCost.request('https://management.azure.com/subscriptions/' + AzureCost.params.subscription_id + '/providers/Microsoft.CostManagement/query?api-version=2023-11-01', JSON.stringify(bodyRawCost));
var columns = AzureCost.getField(metricData, 'properties.columns');
return transformedData = {
data: AzureCost.getField(metricData, 'properties.rows').map(function (row) {
rowData = {};
columns.forEach(function (column, i) {
columnName = columns[i].name;
cellValue = row[i];
rowData[columnName] = column.type === "Number" ? cellValue.toString() : cellValue;
});
rowData.BillingMonth = rowData.BillingMonth.slice(0, 7);
return rowData;
})
};
}
};
try {
AzureCost.setParams(JSON.parse(value));
AzureCost.login();
serviceCost = AzureCost.getCost('ServiceName');
resourceGroupCost = AzureCost.getCost('ResourceGroup');
resourceLocationCost = AzureCost.getCost('ResourceLocation');
monthCost = AzureCost.getCost('SubscriptionId');
return JSON.stringify({ resourceGroupCost, resourceLocationCost, serviceCost, monthCost });
}
catch (error) {
error += (String(error).endsWith('.')) ? '' : '.';
Zabbix.log(3, '[ AzureCost ] 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: month
value: '{$AZURE.BILLING.MONTH}'
- name: password
value: '{$AZURE.PASSWORD}'
- name: proxy
value: '{$AZURE.PROXY}'
- name: subscription_id
value: '{$AZURE.SUBSCRIPTION.ID}'
- name: tenant_id
value: '{$AZURE.TENANT.ID}'
- name: tls_verify
value: '{$HTTP.TLS.VERIFY:"Azure Cost Management"}'
tags:
- tag: component
value: raw
- uuid: 30dae868261844f39c811cdba93628eb
name: 'Azure Cost: Get monthly costs errors'
type: DEPENDENT
key: azure.get.monthly.costs.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.get.monthly.costs
tags:
- tag: component
value: raw
triggers:
- uuid: 2ea11e17fd734dee80219e22a8073e01
expression: 'length(last(/Azure Cost Management by HTTP/azure.get.monthly.costs.errors))>0'
name: 'Azure Cost: There are errors in requests to API'
event_name: 'Azure Cost: Error in monthly costs requests to API'
opdata: '{ITEM.LASTVALUE1}'
priority: AVERAGE
description: 'Zabbix has received errors in response to API requests.'
tags:
- tag: scope
value: availability
discovery_rules:
- uuid: 1220188c7a1c4df8b75e9021c4515149
name: 'Azure daily costs by services discovery'
type: DEPENDENT
key: azure.daily.services.costs.discovery
delay: '0'
filter:
evaltype: AND
conditions:
- macro: '{#AZURE.RESOURCE.GROUP}'
value: '{$AZURE.LLD.FILTER.RESOURCE.GROUP.MATCHES}'
formulaid: A
- macro: '{#AZURE.RESOURCE.GROUP}'
value: '{$AZURE.LLD.FILTER.RESOURCE.GROUP.NOT_MATCHES}'
operator: NOT_MATCHES_REGEX
formulaid: B
- macro: '{#AZURE.RESOURCE.LOCATION}'
value: '{$AZURE.LLD.FILTER.RESOURCE.LOCATION.MATCHES}'
formulaid: C
- macro: '{#AZURE.RESOURCE.LOCATION}'
value: '{$AZURE.LLD.FILTER.RESOURCE.LOCATION.NOT_MATCHES}'
operator: NOT_MATCHES_REGEX
formulaid: D
- macro: '{#AZURE.SERVICE.NAME}'
value: '{$AZURE.LLD.FILTER.SERVICE.MATCHES}'
formulaid: E
- macro: '{#AZURE.SERVICE.NAME}'
value: '{$AZURE.LLD.FILTER.SERVICE.NOT_MATCHES}'
operator: NOT_MATCHES_REGEX
formulaid: F
description: 'Discovery of daily costs by services.'
item_prototypes:
- uuid: 848ccd4cec2c4902990aa25f90f502a8
name: 'Service ["{#AZURE.SERVICE.NAME}"]: Meter ["{#AZURE.BILLING.METER}"]: Subcategory ["{#AZURE.BILLING.METER.SUBCATEGORY}"] daily cost'
type: DEPENDENT
key: 'azure.daily.cost["{#AZURE.SERVICE.NAME}", "{#AZURE.BILLING.METER}", "{#AZURE.BILLING.METER.SUBCATEGORY}","{#AZURE.RESOURCE.GROUP}"]'
delay: '0'
value_type: FLOAT
units: '!{#AZURE.BILLING.UNIT}'
description: 'The daily cost by service {#AZURE.SERVICE.NAME}, meter {#AZURE.BILLING.METER}, subcategory {#AZURE.BILLING.METER.SUBCATEGORY}.'
preprocessing:
- type: JSONPATH
parameters:
- '$.data.[?(@.ServiceName == "{#AZURE.SERVICE.NAME}" && @.Meter == "{#AZURE.BILLING.METER}" && @.MeterSubcategory == "{#AZURE.BILLING.METER.SUBCATEGORY}")].PreTaxCost.first()'
error_handler: DISCARD_VALUE
master_item:
key: azure.get.daily.costs
tags:
- tag: component
value: cost
- tag: location
value: '{#AZURE.RESOURCE.LOCATION}'
- tag: meter
value: '{#AZURE.BILLING.METER}'
- tag: resource-group
value: '{#AZURE.RESOURCE.GROUP}'
- tag: service
value: '{#AZURE.SERVICE.NAME}'
graph_prototypes:
- uuid: 2a1e03e65b1c40cba783493871e245d5
name: 'Daily Cost: "{#AZURE.SERVICE.NAME}","{#AZURE.BILLING.METER}","{#AZURE.BILLING.METER.SUBCATEGORY}","{#AZURE.RESOURCE.GROUP}"'
graph_items:
- drawtype: GRADIENT_LINE
color: 2E7D32
item:
host: 'Azure Cost Management by HTTP'
key: 'azure.daily.cost["{#AZURE.SERVICE.NAME}", "{#AZURE.BILLING.METER}", "{#AZURE.BILLING.METER.SUBCATEGORY}","{#AZURE.RESOURCE.GROUP}"]'
master_item:
key: azure.get.daily.costs
lld_macro_paths:
- lld_macro: '{#AZURE.BILLING.METER.SUBCATEGORY}'
path: $.MeterSubcategory
- lld_macro: '{#AZURE.BILLING.METER}'
path: $.Meter
- lld_macro: '{#AZURE.BILLING.UNIT}'
path: $.Currency
- lld_macro: '{#AZURE.RESOURCE.GROUP}'
path: $.ResourceGroup
- lld_macro: '{#AZURE.RESOURCE.LOCATION}'
path: $.ResourceLocation
- lld_macro: '{#AZURE.SERVICE.NAME}'
path: $.ServiceName
preprocessing:
- type: JSONPATH
parameters:
- $.data
error_handler: DISCARD_VALUE
- uuid: 9c65b60a8e1840dd81367aefe6b0de18
name: 'Azure monthly costs discovery'
type: DEPENDENT
key: azure.monthly.costs.discovery
delay: '0'
description: 'Discovery of monthly costs.'
item_prototypes:
- uuid: f91a60d2c1124eb6b297539b0a115c66
name: 'Month ["{#AZURE.BILLING.MONTH}"] cost'
type: DEPENDENT
key: 'azure.monthly.cost["{#AZURE.BILLING.MONTH}"]'
delay: '0'
value_type: FLOAT
units: '!{#AZURE.BILLING.UNIT}'
description: 'The monthly cost.'
preprocessing:
- type: JSONPATH
parameters:
- '$.monthCost.data.[?(@.BillingMonth == "{#AZURE.BILLING.MONTH}")].PreTaxCost.sum()'
error_handler: DISCARD_VALUE
master_item:
key: azure.get.monthly.costs
tags:
- tag: component
value: cost
- tag: month
value: '{#AZURE.BILLING.MONTH}'
graph_prototypes:
- uuid: 347342d3d0cc478bab33036872570cdb
name: 'Azure Cost: Month ["{#AZURE.BILLING.MONTH}"] cost'
graph_items:
- drawtype: GRADIENT_LINE
color: 2E7D32
item:
host: 'Azure Cost Management by HTTP'
key: 'azure.monthly.cost["{#AZURE.BILLING.MONTH}"]'
master_item:
key: azure.get.monthly.costs
lld_macro_paths:
- lld_macro: '{#AZURE.BILLING.MONTH}'
path: $.BillingMonth
- lld_macro: '{#AZURE.BILLING.UNIT}'
path: $.Currency
preprocessing:
- type: JSONPATH
parameters:
- $.monthCost.data
error_handler: DISCARD_VALUE
- uuid: e9a4bf192feb4472aedd40ba2371d286
name: 'Azure monthly costs by location discovery'
type: DEPENDENT
key: azure.monthly.location.costs.discovery
delay: '0'
filter:
evaltype: AND
conditions:
- macro: '{#AZURE.RESOURCE.LOCATION}'
value: '{$AZURE.LLD.FILTER.RESOURCE.LOCATION.MATCHES}'
formulaid: A
- macro: '{#AZURE.RESOURCE.LOCATION}'
value: '{$AZURE.LLD.FILTER.RESOURCE.LOCATION.NOT_MATCHES}'
operator: NOT_MATCHES_REGEX
formulaid: B
description: 'Discovery of monthly costs by location.'
item_prototypes:
- uuid: 7fb097f81a8445acaa6b17bdc4daaaa6
name: 'Location: ["{#AZURE.RESOURCE.LOCATION}"]: Month ["{#AZURE.BILLING.MONTH}"] cost'
type: DEPENDENT
key: 'azure.monthly.location.cost["{#AZURE.RESOURCE.LOCATION}", "{#AZURE.BILLING.MONTH}"]'
delay: '0'
value_type: FLOAT
units: '!{#AZURE.BILLING.UNIT}'
description: 'The monthly cost by location {#AZURE.RESOURCE.LOCATION}.'
preprocessing:
- type: JSONPATH
parameters:
- '$.resourceLocationCost.data.[?(@.BillingMonth == "{#AZURE.BILLING.MONTH}")]'
error_handler: DISCARD_VALUE
- type: JSONPATH
parameters:
- '$.[?(@.ResourceLocation == "{#AZURE.RESOURCE.LOCATION}")].PreTaxCost.sum()'
error_handler: DISCARD_VALUE
master_item:
key: azure.get.monthly.costs
tags:
- tag: component
value: cost
- tag: location
value: '{#AZURE.RESOURCE.LOCATION}'
- tag: month
value: '{#AZURE.BILLING.MONTH}'
graph_prototypes:
- uuid: e3df27afabb147d3ae07e1a2fa36e89a
name: 'Azure Cost: ["{#AZURE.RESOURCE.LOCATION}"]: Month ["{#AZURE.BILLING.MONTH}"] cost'
graph_items:
- drawtype: GRADIENT_LINE
color: 2E7D32
item:
host: 'Azure Cost Management by HTTP'
key: 'azure.monthly.location.cost["{#AZURE.RESOURCE.LOCATION}", "{#AZURE.BILLING.MONTH}"]'
master_item:
key: azure.get.monthly.costs
lld_macro_paths:
- lld_macro: '{#AZURE.BILLING.MONTH}'
path: $.BillingMonth
- lld_macro: '{#AZURE.BILLING.UNIT}'
path: $.Currency
- lld_macro: '{#AZURE.RESOURCE.LOCATION}'
path: $.ResourceLocation
preprocessing:
- type: JSONPATH
parameters:
- $.resourceLocationCost.data
error_handler: DISCARD_VALUE
- uuid: 4dfa3b60721e463d97f2f820106f816d
name: 'Azure monthly costs by resource group discovery'
type: DEPENDENT
key: azure.monthly.resource.group.costs.discovery
delay: '0'
filter:
evaltype: AND
conditions:
- macro: '{#AZURE.RESOURCE.GROUP}'
value: '{$AZURE.LLD.FILTER.RESOURCE.GROUP.MATCHES}'
formulaid: A
- macro: '{#AZURE.RESOURCE.GROUP}'
value: '{$AZURE.LLD.FILTER.RESOURCE.GROUP.NOT_MATCHES}'
operator: NOT_MATCHES_REGEX
formulaid: B
description: 'Discovery of monthly costs by resource group.'
item_prototypes:
- uuid: 9a5ed573ac374c08abf81f2b7296f260
name: 'Resource group: ["{#AZURE.RESOURCE.GROUP}"]: Month ["{#AZURE.BILLING.MONTH}"] cost'
type: DEPENDENT
key: 'azure.monthly.resource.group.cost["{#AZURE.RESOURCE.GROUP}", "{#AZURE.BILLING.MONTH}"]'
delay: '0'
value_type: FLOAT
units: '!{#AZURE.BILLING.UNIT}'
description: 'The monthly cost by resource group {#AZURE.RESOURCE.GROUP}.'
preprocessing:
- type: JSONPATH
parameters:
- '$.resourceGroupCost.data.[?(@.BillingMonth == "{#AZURE.BILLING.MONTH}")]'
error_handler: DISCARD_VALUE
- type: JSONPATH
parameters:
- '$.[?(@.ResourceGroup == "{#AZURE.RESOURCE.GROUP}")].PreTaxCost.sum()'
error_handler: DISCARD_VALUE
master_item:
key: azure.get.monthly.costs
tags:
- tag: component
value: cost
- tag: month
value: '{#AZURE.BILLING.MONTH}'
- tag: resource-group
value: '{#AZURE.RESOURCE.GROUP}'
graph_prototypes:
- uuid: fab17244d2c648e089c57c99615af537
name: 'Azure Cost: ["{#AZURE.RESOURCE.GROUP}"]: Month ["{#AZURE.BILLING.MONTH}"] cost'
graph_items:
- drawtype: GRADIENT_LINE
color: 2E7D32
item:
host: 'Azure Cost Management by HTTP'
key: 'azure.monthly.resource.group.cost["{#AZURE.RESOURCE.GROUP}", "{#AZURE.BILLING.MONTH}"]'
master_item:
key: azure.get.monthly.costs
lld_macro_paths:
- lld_macro: '{#AZURE.BILLING.MONTH}'
path: $.BillingMonth
- lld_macro: '{#AZURE.BILLING.UNIT}'
path: $.Currency
- lld_macro: '{#AZURE.RESOURCE.GROUP}'
path: $.ResourceGroup
preprocessing:
- type: JSONPATH
parameters:
- $.resourceGroupCost.data
error_handler: DISCARD_VALUE
- uuid: b9b024a7e42540f0b8387af77367b15c
name: 'Azure monthly costs by services discovery'
type: DEPENDENT
key: azure.monthly.services.costs.discovery
delay: '0'
filter:
evaltype: AND
conditions:
- macro: '{#AZURE.SERVICE.NAME}'
value: '{$AZURE.LLD.FILTER.SERVICE.MATCHES}'
formulaid: A
- macro: '{#AZURE.SERVICE.NAME}'
value: '{$AZURE.LLD.FILTER.SERVICE.NOT_MATCHES}'
operator: NOT_MATCHES_REGEX
formulaid: B
description: 'Discovery of monthly costs by services.'
item_prototypes:
- uuid: dbad6436c70e41268e3b59c2a7f0e2a2
name: 'Service ["{#AZURE.SERVICE.NAME}"]: Month ["{#AZURE.BILLING.MONTH}"] cost'
type: DEPENDENT
key: 'azure.monthly.service.cost["{#AZURE.SERVICE.NAME}", "{#AZURE.BILLING.MONTH}"]'
delay: '0'
value_type: FLOAT
units: '!{#AZURE.BILLING.UNIT}'
description: 'The monthly cost by service {#AZURE.SERVICE.NAME}.'
preprocessing:
- type: JSONPATH
parameters:
- '$.serviceCost.data.[?(@.BillingMonth == "{#AZURE.BILLING.MONTH}")]'
error_handler: DISCARD_VALUE
- type: JSONPATH
parameters:
- '$.[?(@.ServiceName == "{#AZURE.SERVICE.NAME}")].PreTaxCost.sum()'
error_handler: DISCARD_VALUE
master_item:
key: azure.get.monthly.costs
tags:
- tag: component
value: cost
- tag: month
value: '{#AZURE.BILLING.MONTH}'
- tag: service
value: '{#AZURE.SERVICE.NAME}'
graph_prototypes:
- uuid: 31f1e30f99ed426d81b48411cc7ffd7f
name: 'Azure Cost: ["{#AZURE.SERVICE.NAME}"]: Month ["{#AZURE.BILLING.MONTH}"] cost'
graph_items:
- drawtype: GRADIENT_LINE
color: 2E7D32
item:
host: 'Azure Cost Management by HTTP'
key: 'azure.monthly.service.cost["{#AZURE.SERVICE.NAME}", "{#AZURE.BILLING.MONTH}"]'
master_item:
key: azure.get.monthly.costs
lld_macro_paths:
- lld_macro: '{#AZURE.BILLING.MONTH}'
path: $.BillingMonth
- lld_macro: '{#AZURE.BILLING.UNIT}'
path: $.Currency
- lld_macro: '{#AZURE.SERVICE.NAME}'
path: $.ServiceName
preprocessing:
- type: JSONPATH
parameters:
- $.serviceCost.data
error_handler: DISCARD_VALUE
tags:
- tag: class
value: software
- tag: target
value: azure
- tag: target
value: cost
macros:
- macro: '{$AZURE.APP.ID}'
description: 'The App ID of Microsoft Azure.'
- macro: '{$AZURE.BILLING.MONTH}'
value: '11'
description: 'Months to get historical data from Azure Cost Management API, no more than 11 (plus current month). The time period for pulling the data cannot exceed 1 year.'
- macro: '{$AZURE.DATA.TIMEOUT}'
value: 60s
description: 'API response timeout.'
- macro: '{$AZURE.LLD.FILTER.RESOURCE.GROUP.MATCHES}'
value: '.*'
description: 'Filter of discoverable resource groups by name.'
- macro: '{$AZURE.LLD.FILTER.RESOURCE.GROUP.NOT_MATCHES}'
value: CHANGE_IF_NEEDED
description: 'Filter to exclude discovered resource groups by name.'
- macro: '{$AZURE.LLD.FILTER.RESOURCE.LOCATION.MATCHES}'
value: '.*'
description: 'Filter of discoverable locations by name.'
- macro: '{$AZURE.LLD.FILTER.RESOURCE.LOCATION.NOT_MATCHES}'
value: CHANGE_IF_NEEDED
description: 'Filter to exclude discovered locations by name.'
- macro: '{$AZURE.LLD.FILTER.SERVICE.MATCHES}'
value: '.*'
description: 'Filter of discoverable services by name.'
- macro: '{$AZURE.LLD.FILTER.SERVICE.NOT_MATCHES}'
value: CHANGE_IF_NEEDED
description: 'Filter to exclude discovered services by name.'
- 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.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 Cost Management", e.g. {$HTTP.TLS.VERIFY:"Azure Cost Management"}.'
dashboards:
- uuid: a1c2ce224f07483b865ce48090338dc4
name: 'Overview Azure Costs'
pages:
- name: 'Monthly costs'
widgets:
- type: itemnavigator
name: Month
width: '20'
height: '6'
fields:
- type: INTEGER
name: group_by.0.attribute
value: '3'
- type: STRING
name: group_by.0.tag_name
value: month
- type: STRING
name: items.0
value: 'Month ["*"] cost'
- type: STRING
name: reference
value: JZQAJ
- type: itemnavigator
name: Service
'y': '6'
width: '20'
height: '6'
fields:
- type: INTEGER
name: group_by.0.attribute
value: '3'
- type: STRING
name: group_by.0.tag_name
value: service
- type: INTEGER
name: group_by.1.attribute
value: '3'
- type: STRING
name: group_by.1.tag_name
value: month
- type: STRING
name: items.0
value: 'Service ["*"]: Month ["*"] cost'
- type: STRING
name: reference
value: AJICL
- type: INTEGER
name: show_lines
value: '200'
- type: piechart
name: 'Month costs'
x: '20'
width: '32'
height: '12'
hide_header: 'YES'
fields:
- type: INTEGER
name: draw_type
value: '1'
- type: STRING
name: ds.0.color.0
value: 4CAF50
- type: INTEGER
name: ds.0.dataset_type
value: '0'
- type: STRING
name: ds.0.itemids.0._reference
value: JZQAJ._itemid
- type: INTEGER
name: ds.0.type.0
value: '0'
- type: STRING
name: ds.1.color.0
value: 1565C0
- type: INTEGER
name: ds.1.dataset_type
value: '0'
- type: STRING
name: ds.1.itemids.0._reference
value: AJICL._itemid
- type: INTEGER
name: ds.1.type.0
value: '0'
- type: STRING
name: ds.2.color.0
value: '795548'
- type: INTEGER
name: ds.2.dataset_type
value: '0'
- type: STRING
name: ds.2.itemids.0._reference
value: PEIIF._itemid
- type: INTEGER
name: ds.2.type.0
value: '0'
- type: STRING
name: ds.3.color.0
value: E65100
- type: INTEGER
name: ds.3.dataset_type
value: '0'
- type: STRING
name: ds.3.itemids.0._reference
value: JRCGU._itemid
- type: INTEGER
name: ds.3.type.0
value: '0'
- type: INTEGER
name: legend_lines
value: '4'
- type: INTEGER
name: legend_value
value: '1'
- type: INTEGER
name: space
value: '2'
- type: INTEGER
name: stroke
value: '2'
- type: itemnavigator
name: Location
x: '52'
width: '20'
height: '6'
fields:
- type: INTEGER
name: group_by.0.attribute
value: '3'
- type: STRING
name: group_by.0.tag_name
value: location
- type: INTEGER
name: group_by.1.attribute
value: '3'
- type: STRING
name: group_by.1.tag_name
value: month
- type: STRING
name: items.0
value: 'Location: ["*"]: Month ["*"] cost'
- type: STRING
name: reference
value: PEIIF
- type: INTEGER
name: show_lines
value: '200'
- type: itemnavigator
name: 'Resource group'
x: '52'
'y': '6'
width: '20'
height: '6'
fields:
- type: INTEGER
name: group_by.0.attribute
value: '3'
- type: STRING
name: group_by.0.tag_name
value: resource-group
- type: INTEGER
name: group_by.1.attribute
value: '3'
- type: STRING
name: group_by.1.tag_name
value: month
- type: STRING
name: items.0
value: 'Resource group: ["*"]: Month ["*"] cost'
- type: STRING
name: reference
value: JRCGU
- type: INTEGER
name: show_lines
value: '200'
- name: 'Daily costs by service'
widgets:
- type: itemnavigator
name: Service
width: '25'
height: '7'
fields:
- type: INTEGER
name: group_by.0.attribute
value: '3'
- type: STRING
name: group_by.0.tag_name
value: service
- type: INTEGER
name: group_by.1.attribute
value: '3'
- type: STRING
name: group_by.1.tag_name
value: resource-group
- type: STRING
name: items.0
value: 'Service ["*"]: Meter ["*"]: Subcategory ["*"] daily cost'
- type: STRING
name: reference
value: TOVAT
- type: svggraph
name: 'Daily cost'
x: '25'
width: '47'
height: '7'
hide_header: 'YES'
fields:
- type: STRING
name: ds.0.color.0
value: 6A1B9A
- type: INTEGER
name: ds.0.dataset_type
value: '0'
- type: STRING
name: ds.0.itemids.0._reference
value: TOVAT._itemid
- type: INTEGER
name: ds.0.transparency
value: '4'
- type: INTEGER
name: ds.0.width
value: '2'
- type: STRING
name: reference
value: AMNYP
- type: INTEGER
name: righty
value: '0'