From 76e98472f45317c47af95331fd6b74c02f3dda18 Mon Sep 17 00:00:00 2001
From: Doug Szumski <doug@stackhpc.com>
Date: Thu, 6 Jun 2019 13:52:24 +0100
Subject: [PATCH] Supporting monitoring time synchronisation with Monasca

This plugin is useful for monitoring host clock synchronisation with
an NTP reference. If the delta becomes too large, the metrics from
this plugin can be used to trigger an alarm.

Change-Id: Id1fe6d7c823f8404c19c81ccdeb8b311bcb46e47
---
 ansible/roles/monasca/defaults/main.yml                      | 2 ++
 .../templates/monasca-agent-collector/plugins/ntp.yaml       | 5 +++++
 2 files changed, 7 insertions(+)
 create mode 100644 ansible/roles/monasca/templates/monasca-agent-collector/plugins/ntp.yaml

diff --git a/ansible/roles/monasca/defaults/main.yml b/ansible/roles/monasca/defaults/main.yml
index c690c36600..1f10f2a89f 100644
--- a/ansible/roles/monasca/defaults/main.yml
+++ b/ansible/roles/monasca/defaults/main.yml
@@ -186,6 +186,8 @@ monasca_zookeeper_servers: "{% for host in groups['zookeeper'] %}{{ hostvars[hos
 monasca_memcached_servers: "{% for host in groups['memcached'] %}{{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address'] }}:{{ memcached_port }}{% if not loop.last %},{% endif %}{% endfor %}"
 monasca_elasticsearch_servers: "{% for host in groups['elasticsearch'] %}'{{ internal_protocol }}://{{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address'] }}:{{ elasticsearch_port }}'{% if not loop.last %},{% endif %}{% endfor %}"
 monasca_storm_nimbus_servers: "{% for host in groups['storm-nimbus'] %}'{{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address'] }}'{% if not loop.last %},{% endif %}{% endfor %}"
+# NOTE(dszumski): Only one NTP server is currently supported by the Monasca Agent plugin
+monasca_ntp_server: "{{ external_ntp_servers | first }}"
 
 # Kafka topics used by Monasca services
 monasca_metrics_topic: "metrics"
diff --git a/ansible/roles/monasca/templates/monasca-agent-collector/plugins/ntp.yaml b/ansible/roles/monasca/templates/monasca-agent-collector/plugins/ntp.yaml
new file mode 100644
index 0000000000..15f5f43cee
--- /dev/null
+++ b/ansible/roles/monasca/templates/monasca-agent-collector/plugins/ntp.yaml
@@ -0,0 +1,5 @@
+---
+init_config: null
+instances:
+  - built_by: Ntp
+    host: "{{ monasca_ntp_server }}"