254 lines
10 KiB
YAML
254 lines
10 KiB
YAML
zabbix_export:
|
|
version: '7.0'
|
|
template_groups:
|
|
- uuid: c2c162144c2d4c5491c8801193af4945
|
|
name: Templates/Cloud
|
|
host_groups:
|
|
- uuid: 137f19e6e2dc4219b33553b812627bc2
|
|
name: 'Virtual machines'
|
|
templates:
|
|
- uuid: 4e3fb27f028e4c35b8c9fc43b11c07d7
|
|
template: 'OpenStack by HTTP'
|
|
name: 'OpenStack by HTTP'
|
|
description: |
|
|
Requests OpenStack API access token and discovers available OpenStack services using OpenStack Identity API by HTTP using script item and creates host prototypes for them.
|
|
|
|
Template uses OpenStack application credentials for authorization.
|
|
|
|
Zabbix currently supports OpenStack Nova service.
|
|
|
|
Read the template documentation prior to using this template.
|
|
|
|
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-2
|
|
groups:
|
|
- name: Templates/Cloud
|
|
items:
|
|
- uuid: 0518d08edbf2480abf15f4ef0e7a251a
|
|
name: 'Get access token and service catalog'
|
|
type: SCRIPT
|
|
key: openstack.identity.auth
|
|
delay: '{$OPENSTACK.AUTH.INTERVAL}'
|
|
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;
|
|
};
|
|
}
|
|
|
|
|
|
|
|
const request_path = '/v3/auth/tokens';
|
|
|
|
function getHeader(headers, name, index) {
|
|
if (!headers || typeof headers !== 'object') {
|
|
return null;
|
|
}
|
|
|
|
var target = name.toLowerCase();
|
|
for (var key in headers) {
|
|
if (key.toLowerCase() === target) {
|
|
var value = headers[key];
|
|
if (typeof index !== 'undefined') {
|
|
return (typeof value[index] !== 'undefined') ? value[index] : null;
|
|
}
|
|
|
|
return value;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
function checkParams(params) {
|
|
['api_url', 'app_cred_id', 'app_cred_secret'].forEach(function (field) {
|
|
if (typeof params !== 'object' || typeof params[field] === 'undefined' || params[field] === '') {
|
|
throw 'Required param is not set: ' + field + '.';
|
|
}
|
|
});
|
|
return params;
|
|
}
|
|
|
|
function getHttpData(url, params, app_cred_id, app_cred_secret) {
|
|
const request = new HttpRequest(tls.options);
|
|
|
|
request.addHeader('Content-Type: application/json');
|
|
|
|
const request_body = {
|
|
"auth": {
|
|
"identity": {
|
|
"methods": [
|
|
"application_credential"
|
|
],
|
|
"application_credential": {
|
|
"id": app_cred_id,
|
|
"secret": app_cred_secret
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
if (params['http_proxy']) {
|
|
request.setProxy(params['http_proxy'])
|
|
Zabbix.log(4, '[ Openstack Nova API ] Using http proxy: ' + params['http_proxy']);
|
|
}
|
|
|
|
const response = request.post(url, JSON.stringify(request_body));
|
|
Zabbix.log(4, '[ Openstack Identity API ] [ ' + url + ' ] Received response with status code ' + request.getStatus() + ': ' + response);
|
|
|
|
if (request.getStatus() !== 201) {
|
|
if (typeof (response.error && response.error.message) !== 'undefined') {
|
|
throw response.error.message;
|
|
} else {
|
|
throw 'Failed to receive data: invalid response status code. Check debug log for more information.';
|
|
}
|
|
}
|
|
|
|
return {'request': request, 'response': response};
|
|
}
|
|
|
|
function parseHttpData(http_data) {
|
|
const headers = http_data['request'].getHeaders(true);
|
|
const token = getHeader(headers, 'x-subject-token', 0);
|
|
|
|
if (!token) {
|
|
throw 'X-Subject-Token header not found.';
|
|
}
|
|
|
|
const supported_services = ['nova'];
|
|
|
|
var ret = [];
|
|
const data = JSON.parse(http_data['response']);
|
|
if (data['token']['catalog']) {
|
|
const service_catalog = data['token']['catalog'];
|
|
} else {
|
|
throw 'Cannot find service catalog in HTTP response.'
|
|
}
|
|
|
|
service_catalog.forEach(function (service) {
|
|
if (supported_services.indexOf(service.name) > -1) {
|
|
service.endpoints.forEach(function (endpoint) {
|
|
if (endpoint.interface === 'public') {
|
|
ret.push({
|
|
'service_name': service.name[0].toUpperCase() + service.name.slice(1),
|
|
'service_url': endpoint.url,
|
|
'token': token
|
|
});
|
|
}
|
|
})
|
|
}
|
|
});
|
|
|
|
return JSON.stringify(ret);
|
|
}
|
|
|
|
const params = checkParams(JSON.parse(value)),
|
|
url = params.api_url,
|
|
auth_cred_id = params.app_cred_id,
|
|
auth_cred_secret = params.app_cred_secret;
|
|
|
|
const tls = new CTlsConfig(params.tls_verify);
|
|
tls.checkURL(url);
|
|
|
|
const httpData = getHttpData(url + request_path, params, auth_cred_id, auth_cred_secret);
|
|
return parseHttpData(httpData);
|
|
description: 'Authorizes user on the OpenStack Identity service and gets the service catalog.'
|
|
timeout: 10s
|
|
parameters:
|
|
- name: api_url
|
|
value: '{$OPENSTACK.KEYSTONE.API.ENDPOINT}'
|
|
- name: app_cred_id
|
|
value: '{$OPENSTACK.APP.CRED.ID}'
|
|
- name: app_cred_secret
|
|
value: '{$OPENSTACK.APP.CRED.SECRET}'
|
|
- name: http_proxy
|
|
value: '{$OPENSTACK.HTTP.PROXY}'
|
|
- name: tls_verify
|
|
value: '{$HTTP.TLS.VERIFY:"OpenStack"}'
|
|
tags:
|
|
- tag: component
|
|
value: raw
|
|
discovery_rules:
|
|
- uuid: f827e364d7bd4013b02504a58fdc2d39
|
|
name: 'OpenStack: Nova discovery'
|
|
type: DEPENDENT
|
|
key: openstack.services.nova.discovery
|
|
delay: '0'
|
|
filter:
|
|
conditions:
|
|
- macro: '{#SERVICE_NAME}'
|
|
value: ^Nova$
|
|
formulaid: A
|
|
description: 'Discovers OpenStack services from the monitoring user''s services catalog.'
|
|
host_prototypes:
|
|
- uuid: 580d769292ec48379c5b84cd5c72533b
|
|
host: 'OpenStack {#SERVICE_NAME}'
|
|
name: 'OpenStack {#SERVICE_NAME}'
|
|
group_links:
|
|
- group:
|
|
name: 'Virtual machines'
|
|
templates:
|
|
- name: 'OpenStack Nova by HTTP'
|
|
macros:
|
|
- macro: '{$OPENSTACK.NOVA.SERVICE.URL}'
|
|
value: '{#SERVICE_URL}'
|
|
description: 'OpenStack Nova service path.'
|
|
- macro: '{$OPENSTACK.TOKEN}'
|
|
value: '{#TOKEN}'
|
|
description: 'OpenStack authorization token.'
|
|
master_item:
|
|
key: openstack.identity.auth
|
|
lld_macro_paths:
|
|
- lld_macro: '{#SERVICE_NAME}'
|
|
path: $.service_name
|
|
- lld_macro: '{#SERVICE_URL}'
|
|
path: $.service_url
|
|
- lld_macro: '{#TOKEN}'
|
|
path: $.token
|
|
tags:
|
|
- tag: class
|
|
value: cloud
|
|
- tag: target
|
|
value: openstack
|
|
macros:
|
|
- macro: '{$HTTP.TLS.VERIFY}'
|
|
value: full
|
|
description: 'TLS certificate verification for the script item: "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 "OpenStack Nova", e.g. {$HTTP.TLS.VERIFY:"OpenStack"}.'
|
|
- macro: '{$OPENSTACK.APP.CRED.ID}'
|
|
description: 'Application credential ID for monitoring user access.'
|
|
- macro: '{$OPENSTACK.APP.CRED.SECRET}'
|
|
type: SECRET_TEXT
|
|
description: 'Application credential password for monitoring user access.'
|
|
- macro: '{$OPENSTACK.AUTH.INTERVAL}'
|
|
value: 50m
|
|
description: 'API token regeneration interval, in minutes. By default, OpenStack API tokens expire after 60m.'
|
|
- macro: '{$OPENSTACK.HTTP.PROXY}'
|
|
description: 'Sets the HTTP proxy for the authorization item. Host prototypes will also use this value for HTTP proxy. If this parameter is empty, then no proxy is used.'
|
|
- macro: '{$OPENSTACK.KEYSTONE.API.ENDPOINT}'
|
|
description: 'API endpoint for Identity Service, e.g., https://local.openstack:5000.'
|