Files
templates-default/YugabyteDB_by_HTTP.yaml

258 lines
11 KiB
YAML

zabbix_export:
version: '7.0'
template_groups:
- uuid: 748ad4d098d447d492bb935c907f652f
name: Templates/Databases
host_groups:
- uuid: 748ad4d098d447d492bb935c907f652f
name: Databases
templates:
- uuid: bc056b1724e748bba50928f8cc605f8e
template: 'YugabyteDB by HTTP'
name: 'YugabyteDB by HTTP'
description: |
This template is designed for the deployment of YugabyteDB monitoring by Zabbix via HTTP and doesn't require any external scripts.
To set up the template:
1. Set your account ID as a value of the {$YUGABYTEDB.ACCOUNT.ID} macro. The account ID is the unique identifier for your customer account in YugabyteDB Managed. You can access the account ID from your profile in the YugabyteDB Managed user interface. To get your account ID, log in to YugabyteDB Managed and click the user profile icon.
See YugabyteDB documentation for instructions:
https://yugabyte.stoplight.io/docs/managed-apis/tvsjh28t5ivmw-getting-started#account-id
2. Set your project ID as a value of the {$YUGABYTEDB.PROJECT.ID} macro. The project ID is the unique identifier for a YugabyteDB Managed project. You can access the project ID from your profile in the YugabyteDB Managed user interface (along with the account ID).
See YugabyteDB documentation for instructions:
https://yugabyte.stoplight.io/docs/managed-apis/tvsjh28t5ivmw-getting-started#project-id
3. Generate the API access token and specify it as a value of the {$YUGABYTEDB.ACCESS.TOKEN} macro.
See YugabyteDB documentation for instructions:
https://docs.yugabyte.com/preview/yugabyte-cloud/managed-automation/managed-apikeys/#create-an-api-key
NOTE: If needed, you can specify a HTTP proxy for the template to use by changing the value of the {$YUGABYTEDB.PROXY} user macro.
IMPORTANT! The value of the {$YUGABYTEDB.ACCESS.TOKEN} macro is stored as plain (not secret) text by default.
Generated by official Zabbix template tool "Templator"
vendor:
name: Zabbix
version: 7.0-3
groups:
- name: Templates/Databases
items:
- uuid: 25196b29de6c45c18485f2aefe306818
name: 'Get cluster'
type: SCRIPT
key: yugabytedb.clusters.get
delay: 1h
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 YugabyteDB = {
params: {},
clusters: [],
error_msg: '',
setParams: function (params) {
['account_id', 'project_id', 'token'].forEach(function (field) {
if (typeof params !== 'object' || typeof params[field] === 'undefined' || params[field] === '') {
throw 'Required param is not set: ' + field + '.';
}
});
YugabyteDB.params = params;
YugabyteDB.tls = new CTlsConfig(params.tls_verify);
},
request: function (url, data) {
if (typeof data === 'undefined' || data === null) {
data = '';
}
var response, request = new HttpRequest(YugabyteDB.tls.options);
if (typeof YugabyteDB.params.proxy !== 'undefined' && YugabyteDB.params.proxy !== '') {
request.setProxy(YugabyteDB.params.proxy);
}
if (YugabyteDB.params.token) {
request.addHeader('Accept: application/json');
request.addHeader('Authorization: Bearer ' + YugabyteDB.params.token);
}
Zabbix.log(4, '[ YugabyteDB ] Sending request: ' + url);
response = request.get(url);
Zabbix.log(4, '[ YugabyteDB ] Received response with status code ' + request.getStatus() + ': ' + response);
if (request.getStatus() !== 200 || response === null) {
throw 'Request failed with status code ' + request.getStatus() + ': ' + response;
}
try {
return JSON.parse(response);
}
catch (error) {
throw 'Failed to parse response received from API:' + error;
}
}
};
try {
YugabyteDB.setParams(JSON.parse(value));
clusters = YugabyteDB.request(
'https://cloud.yugabyte.com/api/public/v1/accounts/' + YugabyteDB.params.account_id + '/projects/' + YugabyteDB.params.project_id + '/clusters'
)
YugabyteDB.clusters = clusters.data;
}
catch (error) {
Zabbix.log(3, '[ YugabyteDB ] ERROR: ' + error);
YugabyteDB.error_msg = 'Failed to get data from API:' + error;
}
return JSON.stringify({'clusters': YugabyteDB.clusters, 'error': YugabyteDB.error_msg});
description: 'Get raw data about clusters.'
timeout: 10s
parameters:
- name: account_id
value: '{$YUGABYTEDB.ACCOUNT.ID}'
- name: project_id
value: '{$YUGABYTEDB.PROJECT.ID}'
- name: proxy
value: '{$YUGABYTEDB.PROXY}'
- name: tls_verify
value: '{$HTTP.TLS.VERIFY:"YugabyteDB"}'
- name: token
value: '{$YUGABYTEDB.ACCESS.TOKEN}'
tags:
- tag: component
value: raw
- uuid: f5a43644d4d341658b8818077e24ccb3
name: 'Get clusters item error'
type: DEPENDENT
key: yugabytedb.clusters.get.errors
delay: '0'
value_type: TEXT
trends: '0'
description: 'Item for gathering all the cluster item errors.'
preprocessing:
- type: JSONPATH
parameters:
- $.error
error_handler: DISCARD_VALUE
- type: DISCARD_UNCHANGED_HEARTBEAT
parameters:
- 12h
master_item:
key: yugabytedb.clusters.get
tags:
- tag: component
value: error
triggers:
- uuid: add4067f699f401887d259ee35b4d654
expression: 'length(last(/YugabyteDB by HTTP/yugabytedb.clusters.get.errors)) > 0'
name: 'YugabyteDB: Failed to fetch data'
priority: WARNING
description: 'Failed to fetch data about cluster.'
tags:
- tag: scope
value: availability
discovery_rules:
- uuid: b882ad93a75046b09794c7f229482006
name: 'Cluster discovery'
type: DEPENDENT
key: yugabytedb.cluster.discovery
delay: '0'
description: 'Discovery of the available clusters.'
host_prototypes:
- uuid: 1a7ec22ad5ad41e0bcb04c01c2c45e4e
host: '{#CLUSTER.ID}'
name: 'YugabyteDB Cluster [{#CLUSTER.NAME}]'
group_links:
- group:
name: Databases
templates:
- name: 'YugabyteDB Cluster by HTTP'
macros:
- macro: '{$YUGABYTEDB.CLUSTER.ID}'
value: '{#CLUSTER.ID}'
description: 'ID of cluster.'
- macro: '{$YUGABYTEDB.CLUSTER.NAME}'
value: '{#CLUSTER.NAME}'
description: 'Name of cluster.'
tags:
- tag: cluster
value: '{#CLUSTER.NAME}'
master_item:
key: yugabytedb.clusters.get
lld_macro_paths:
- lld_macro: '{#CLUSTER.ID}'
path: $.cluster_id
- lld_macro: '{#CLUSTER.NAME}'
path: $.cluster_name
preprocessing:
- type: JAVASCRIPT
parameters:
- |
var result = [];
var clusters = JSON.parse(value);
for (var cluster in clusters['clusters']) {
result.push({
"cluster_id": clusters['clusters'][cluster]['info']['id'],
"cluster_name": clusters['clusters'][cluster]['spec']['name']
});
};
return JSON.stringify(result);
- type: DISCARD_UNCHANGED_HEARTBEAT
parameters:
- 1d
tags:
- tag: class
value: database
- tag: target
value: yugabytedb
macros:
- 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 "YugabyteDB", e.g. {$HTTP.TLS.VERIFY:"YugabyteDB"}.'
- macro: '{$YUGABYTEDB.ACCESS.TOKEN}'
value: '<Put your access token here>'
description: 'Access token for the YugabyteDB API.'
- macro: '{$YUGABYTEDB.ACCOUNT.ID}'
value: '<Put your account ID here>'
description: 'YugabyteDB account ID.'
- macro: '{$YUGABYTEDB.PROJECT.ID}'
value: '<Put your project ID here>'
description: 'YugabyteDB project ID.'
- macro: '{$YUGABYTEDB.PROXY}'
description: 'Sets the HTTP proxy value. If this macro is empty, then no proxy is used.'