zabbix_export: version: '7.0' template_groups: - uuid: a571c0d144b14fd4a87a9d9b2aa9fcd6 name: Templates/Applications host_groups: - uuid: a571c0d144b14fd4a87a9d9b2aa9fcd6 name: Applications templates: - uuid: f74adf26d9ab44ada318002d31fd2881 template: 'HashiCorp Nomad by HTTP' name: 'HashiCorp Nomad by HTTP' description: | Discover HashiCorp Nomad servers and clients automatically. Don't forget to change macro {$NOMAD.ENDPOINT.API.URL}, {$NOMAD.TOKEN} values. 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/Applications items: - uuid: 50bf00cc5c9f41c887add07d0bba3cc1 name: 'Client nodes API response' type: DEPENDENT key: nomad.client.nodes.api.response delay: '0' value_type: TEXT trends: '0' description: 'Client nodes API response message.' preprocessing: - type: JAVASCRIPT parameters: - | try { var response = Object.keys(JSON.parse(value).header).filter(function (f) { return f.match(/HTTP\/[\d.]+\s+\d{3}/); }); return response.pop(); } catch (error) { return "HTTP/1.1 408 Request timeout"; } - type: DISCARD_UNCHANGED_HEARTBEAT parameters: - 1h master_item: key: nomad.client.nodes.get tags: - tag: component value: status triggers: - uuid: f2e1cbbf808946ca902c1f378747e936 expression: 'find(/HashiCorp Nomad by HTTP/nomad.client.nodes.api.response,,"like","{$NOMAD.API.RESPONSE.SUCCESS}")=0' name: 'HashiCorp Nomad: Client nodes API connection has failed' event_name: 'HashiCorp Nomad: Client nodes API connection has failed. HTTP response code: {{ITEM.VALUE}.regsub("HTTP\/[\d.]+\s+(\d{3})", \1")}. Response message: {{ITEM.VALUE}.regsub("HTTP\/[\d.]+\s+\d{3}\s+(.*)", \1")}' priority: AVERAGE description: | Client nodes API connection has failed. Ensure that Nomad API URL and the necessary permissions have been defined correctly, check the service state and network connectivity between Nomad and Zabbix. manual_close: 'YES' tags: - tag: scope value: availability - uuid: 99d8cd0768094bef93995e4baa475186 name: 'Nomad clients get' type: HTTP_AGENT key: nomad.client.nodes.get delay: 1h history: '0' value_type: TEXT trends: '0' description: 'Nomad clients data in raw format.' preprocessing: - type: CHECK_NOT_SUPPORTED parameters: - '-1' error_handler: CUSTOM_VALUE error_handler_params: '{"header":{"HTTP/1.1 408 Request timeout":""}}' timeout: '{$NOMAD.DATA.TIMEOUT}' url: '{$NOMAD.ENDPOINT.API.URL}/v1/nodes' query_fields: - name: os value: 'true' status_codes: '' http_proxy: '{$NOMAD.HTTP.PROXY}' headers: - name: X-Nomad-Token value: '{$NOMAD.TOKEN}' retrieve_mode: BOTH output_format: JSON tags: - tag: component value: raw - uuid: 7a46e18358e641cc941b306de6eb5dc4 name: 'Nomad clients count' type: DEPENDENT key: nomad.clients.count delay: '0' description: 'Nomad clients count.' preprocessing: - type: JSONPATH parameters: - '$.body[?(@.Name)].length()' master_item: key: nomad.client.nodes.get tags: - tag: component value: environment - uuid: e848e135a5574931accf114fcafb89d7 name: Region type: DEPENDENT key: nomad.region delay: '0' value_type: CHAR trends: '0' description: 'Current cluster region.' preprocessing: - type: JSONPATH parameters: - $..region.first() master_item: key: nomad.server.nodes.get tags: - tag: component value: environment - uuid: 53a0c689f27547ccbcb0a57c736a5027 name: 'Server-related APIs response' type: DEPENDENT key: nomad.server.api.response delay: '0' value_type: TEXT trends: '0' description: 'Server-related (`operator/raft/configuration`, `agent/members`) APIs error response message.' preprocessing: - type: JSONPATH parameters: - $.error error_handler: CUSTOM_VALUE error_handler_params: 'HTTP/1.1 200 OK' - type: DISCARD_UNCHANGED_HEARTBEAT parameters: - 1h master_item: key: nomad.server.nodes.get triggers: - uuid: 1560c32cb7de4fc8a58cf537c7958205 expression: 'find(/HashiCorp Nomad by HTTP/nomad.server.api.response,,"like","{$NOMAD.API.RESPONSE.SUCCESS}")=0' name: 'HashiCorp Nomad: Server-related API connection has failed' event_name: 'HashiCorp Nomad: Server-related API connection has failed. HTTP response code: {{ITEM.VALUE}.regsub("HTTP\/[\d.]+\s+(\d{3})", \1")}. Response message: {{ITEM.VALUE}.regsub("HTTP\/[\d.]+\s+\d{3}\s+(.*)", \1")}' priority: AVERAGE description: | Server-related API connection has failed. Ensure that Nomad API URL and the necessary permissions have been defined correctly, check the service state and network connectivity between Nomad and Zabbix. manual_close: 'YES' tags: - tag: scope value: availability - uuid: 254354aa21764751bf7e1961e37de7ae name: 'Nomad servers get' type: SCRIPT key: nomad.server.nodes.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 Nomad = { setParams: function (params) { ['api_endpoint'].forEach(function (field) { if (typeof params !== 'object' || typeof params[field] === 'undefined' || params[field] === '') { throw 'Required param is not set: "' + field + '".'; } }); Nomad.params = params; if (typeof Nomad.params.api_endpoint === 'string' && !Nomad.params.api_endpoint.endsWith('/')) { Nomad.params.api_endpoint += '/'; } Nomad.tls = new CTlsConfig(params.tls_verify); Nomad.tls.checkURL(Nomad.params.api_endpoint); }, request: function (query) { var response, request = new HttpRequest(Nomad.tls.options), url = Nomad.params.api_endpoint + query; request.addHeader('Content-Type: application/json'); request.addHeader('X-Nomad-Token: ' + Nomad.params.token); if (Nomad.params.http_proxy) { request.setProxy(Nomad.params.http_proxy) Zabbix.log(4, '[ Nomad ] Using http proxy: ' + Nomad.params.http_proxy); } Zabbix.log(4, '[ Nomad ] Sending request: ' + url); response = request.get(url); Zabbix.log(4, '[ Nomad ] Received response with status code ' + request.getStatus() + ': ' + response); if (response !== null) { try { response = JSON.parse(response); } catch (error) { throw 'Failed to parse response received from Nomad agent API.'; } } return { status: request.getStatus(), response: response }; }, 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; }, getIds: function () { var result = this.request('v1/operator/raft/configuration'); if (typeof result.response !== 'object' || result.status != 200) { throw 'Cannot get servers list from Nomad agent API.'; } return this.getField(result, 'response.Servers') .map(function (srv) { return srv['ID']; }); }, getServers: function () { var ids = this.getIds(); result = Nomad.request('v1/agent/members'); if (typeof result.response !== 'object' || result.status != 200) { throw 'Cannot get servers list from Nomad agent API.'; } return this.getField(result,'response.Members').filter(function (s) { return ids.indexOf(s.Tags.id) >= 0; }); }, }; try { Nomad.setParams(JSON.parse(value)); var servers = Nomad.getServers(); return JSON.stringify(servers); } catch (error) { error += ((String(error).endsWith('.')) ? '' : '.'); Zabbix.log(3, '[ Nomad ] ERROR: ' + error); return JSON.stringify({ error: error + ' Check debug log for more information.' }); } description: 'Nomad servers data in raw format.' timeout: '{$NOMAD.DATA.TIMEOUT}' parameters: - name: api_endpoint value: '{$NOMAD.ENDPOINT.API.URL}' - name: http_proxy value: '{$NOMAD.HTTP.PROXY}' - name: tls_verify value: '{$HTTP.TLS.VERIFY:"HashiCorp Nomad"}' - name: token value: '{$NOMAD.TOKEN}' tags: - tag: component value: raw - uuid: 904e226008324cb8aa11f716e0420b51 name: 'Nomad servers count' type: DEPENDENT key: nomad.servers.count delay: '0' description: 'Nomad servers count.' preprocessing: - type: JSONPATH parameters: - '$[?(@.Name)].length()' master_item: key: nomad.server.nodes.get tags: - tag: component value: environment discovery_rules: - uuid: 0ba167e5638344ab842224df5b8909e1 name: 'Clients discovery' type: DEPENDENT key: nomad.clients.discovery delay: '0' filter: evaltype: AND conditions: - macro: '{#CLIENT.DC}' value: '{$NOMAD.CLIENT.DC.MATCHES}' formulaid: A - macro: '{#CLIENT.DC}' value: '{$NOMAD.CLIENT.DC.NOT_MATCHES}' operator: NOT_MATCHES_REGEX formulaid: B - macro: '{#CLIENT.NAME}' value: '{$NOMAD.CLIENT.NAME.MATCHES}' formulaid: C - macro: '{#CLIENT.NAME}' value: '{$NOMAD.CLIENT.NAME.NOT_MATCHES}' operator: NOT_MATCHES_REGEX formulaid: D - macro: '{#CLIENT.SCHEDULE.ELIGIBILITY}' value: '{$NOMAD.CLIENT.SCHEDULE.ELIGIBILITY.MATCHES}' formulaid: E - macro: '{#CLIENT.SCHEDULE.ELIGIBILITY}' value: '{$NOMAD.CLIENT.SCHEDULE.ELIGIBILITY.NOT_MATCHES}' operator: NOT_MATCHES_REGEX formulaid: F description: 'Client nodes discovery.' host_prototypes: - uuid: 8284dcf3055749d3b27720526c665e34 host: '{#CLIENT.ID}' name: '{#CLIENT.NAME}-client' group_links: - group: name: Applications templates: - name: 'HashiCorp Nomad Client by HTTP' tags: - tag: class value: '{#CLIENT.CLASS}' - tag: dc value: '{#CLIENT.DC}' - tag: drained value: '{#CLIENT.DRAIN.STATE}' - tag: os value: '{#CLIENT.OS}' - tag: scheduling value: '{#CLIENT.SCHEDULE.ELIGIBILITY}' - tag: service value: nomad-client - tag: version value: '{#CLIENT.VERSION}' custom_interfaces: 'YES' interfaces: - ip: '{#CLIENT.IP}' master_item: key: nomad.client.nodes.get lld_macro_paths: - lld_macro: '{#CLIENT.CLASS}' path: $.NodeClass - lld_macro: '{#CLIENT.DC}' path: $.Datacenter - lld_macro: '{#CLIENT.DRAIN.STATE}' path: $.Drain - lld_macro: '{#CLIENT.ID}' path: $.ID - lld_macro: '{#CLIENT.IP}' path: $.Address - lld_macro: '{#CLIENT.NAME}' path: $.Name - lld_macro: '{#CLIENT.OS}' path: '$.Attributes[''os.name'']' - lld_macro: '{#CLIENT.SCHEDULE.ELIGIBILITY}' path: $.SchedulingEligibility - lld_macro: '{#CLIENT.VERSION}' path: $.Version preprocessing: - type: JSONPATH parameters: - $.body error_handler: DISCARD_VALUE - type: DISCARD_UNCHANGED_HEARTBEAT parameters: - 1h - uuid: 202ee1d0060d48b09a48fe2039d3b081 name: 'Servers discovery' type: DEPENDENT key: nomad.servers.discovery delay: '0' filter: evaltype: AND conditions: - macro: '{#SERVER.DC}' value: '{$NOMAD.SERVER.DC.MATCHES}' formulaid: A - macro: '{#SERVER.DC}' value: '{$NOMAD.SERVER.DC.NOT_MATCHES}' operator: NOT_MATCHES_REGEX formulaid: B - macro: '{#SERVER.NAME}' value: '{$NOMAD.SERVER.NAME.MATCHES}' formulaid: C - macro: '{#SERVER.NAME}' value: '{$NOMAD.SERVER.NAME.NOT_MATCHES}' operator: NOT_MATCHES_REGEX formulaid: D description: 'Server nodes discovery.' host_prototypes: - uuid: addb1ce7995f44089a13128052171445 host: '{#SERVER.ID}' name: '{#SERVER.NAME}' group_links: - group: name: Applications templates: - name: 'HashiCorp Nomad Server by HTTP' tags: - tag: dc value: '{#SERVER.DC}' - tag: region value: '{#SERVER.REGION}' - tag: role value: '{#SERVER.ROLE}' - tag: service value: nomad-server - tag: version value: '{#SERVER.VERSION}' custom_interfaces: 'YES' interfaces: - ip: '{#SERVER.IP}' master_item: key: nomad.server.nodes.get lld_macro_paths: - lld_macro: '{#SERVER.DC}' path: $.Tags.dc - lld_macro: '{#SERVER.ID}' path: $.Tags.id - lld_macro: '{#SERVER.IP}' path: $.Addr - lld_macro: '{#SERVER.NAME}' path: $.Name - lld_macro: '{#SERVER.REGION}' path: $.Tags.region - lld_macro: '{#SERVER.ROLE}' path: $.Tags.role - lld_macro: '{#SERVER.VERSION}' path: $.Tags.build preprocessing: - type: CHECK_JSON_ERROR parameters: - $.error error_handler: DISCARD_VALUE - type: DISCARD_UNCHANGED_HEARTBEAT parameters: - 1h tags: - tag: class value: software - tag: target value: nomad 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 "HashiCorp Nomad", e.g. {$HTTP.TLS.VERIFY:"HashiCorp Nomad"}.' - macro: '{$NOMAD.API.RESPONSE.SUCCESS}' value: '200' description: 'HTTP API successful response code. Availability triggers threshold. Change, if needed.' - macro: '{$NOMAD.CLIENT.DC.MATCHES}' value: '.*' description: 'The filter to include HashiCorp Nomad clients by datacenter belonging.' - macro: '{$NOMAD.CLIENT.DC.NOT_MATCHES}' value: CHANGE_IF_NEEDED description: 'The filter to exclude HashiCorp Nomad clients by datacenter belonging.' - macro: '{$NOMAD.CLIENT.NAME.MATCHES}' value: '.*' description: 'The filter to include HashiCorp Nomad clients by name.' - macro: '{$NOMAD.CLIENT.NAME.NOT_MATCHES}' value: CHANGE_IF_NEEDED description: 'The filter to exclude HashiCorp Nomad clients by name.' - macro: '{$NOMAD.CLIENT.SCHEDULE.ELIGIBILITY.MATCHES}' value: '.*' description: 'The filter to include HashiCorp Nomad clients by scheduling eligibility.' - macro: '{$NOMAD.CLIENT.SCHEDULE.ELIGIBILITY.NOT_MATCHES}' value: CHANGE_IF_NEEDED description: 'The filter to exclude HashiCorp Nomad clients by scheduling eligibility.' - macro: '{$NOMAD.DATA.TIMEOUT}' value: 15s description: 'Response timeout for an API.' - macro: '{$NOMAD.ENDPOINT.API.URL}' value: 'http://localhost:4646' description: 'API endpoint URL for one of the Nomad cluster members.' - macro: '{$NOMAD.HTTP.PROXY}' description: 'Sets the HTTP proxy for script and HTTP agent items. If this parameter is empty, then no proxy is used.' - macro: '{$NOMAD.SERVER.DC.MATCHES}' value: '.*' description: 'The filter to include HashiCorp Nomad servers by datacenter belonging.' - macro: '{$NOMAD.SERVER.DC.NOT_MATCHES}' value: CHANGE_IF_NEEDED description: 'The filter to exclude HashiCorp Nomad servers by datacenter belonging.' - macro: '{$NOMAD.SERVER.NAME.MATCHES}' value: '.*' description: 'The filter to include HashiCorp Nomad servers by name.' - macro: '{$NOMAD.SERVER.NAME.NOT_MATCHES}' value: CHANGE_IF_NEEDED description: 'The filter to exclude HashiCorp Nomad servers by name.' - macro: '{$NOMAD.TOKEN}' value: '' description: 'Nomad authentication token.' dashboards: - uuid: 0b1cb124081f4cf1af2e35245aeb415f name: 'Region resources' pages: - name: 'Region resources' widgets: - type: item name: Region width: '24' height: '5' fields: - type: INTEGER name: decimal_places value: '0' - type: ITEM name: itemid.0 value: host: 'HashiCorp Nomad by HTTP' key: nomad.region - type: INTEGER name: show.0 value: '2' - type: INTEGER name: show.1 value: '4' - type: item name: Servers x: '24' width: '24' height: '5' fields: - type: INTEGER name: decimal_places value: '0' - type: ITEM name: itemid.0 value: host: 'HashiCorp Nomad by HTTP' key: nomad.servers.count - type: INTEGER name: show.0 value: '2' - type: INTEGER name: show.1 value: '4' - type: item name: Clients x: '48' width: '24' height: '5' fields: - type: INTEGER name: decimal_places value: '0' - type: ITEM name: itemid.0 value: host: 'HashiCorp Nomad by HTTP' key: nomad.clients.count - type: INTEGER name: show.0 value: '2' - type: INTEGER name: show.1 value: '4'