From 96cdd35dfb0ee937e806523cc24e0f7d26ac7f92 Mon Sep 17 00:00:00 2001
From: MJB <mjb@it-innovation.soton.ac.uk>
Date: Fri, 8 Jun 2018 13:33:32 +0100
Subject: [PATCH] added systemctl test and dependency on new plugin

---
 scripts/clmc-agent/install.sh                      | 13 +++++++------
 src/test/clmctest/inputs/test_telegraf_agents.py   |  3 ++-
 .../clmctest/services/nginx/telegraf_nginx.conf    | 14 +++++++++++++-
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/scripts/clmc-agent/install.sh b/scripts/clmc-agent/install.sh
index d82b944..cf5e4eb 100755
--- a/scripts/clmc-agent/install.sh
+++ b/scripts/clmc-agent/install.sh
@@ -32,7 +32,7 @@ apt-get install wget -y
 
 echo "Installing Telegraf agent"
 
-TELEGRAF_VERSION=1.7.0~5618bb0-0
+TELEGRAF_VERSION=1.8.0~2736fa0-0
 TELEGRAF_CHECKSUM=dc24932fa1aef9392582880c077dd2493b9f2c66babd7733a0654540bbb5003b
 
 # Install telegraf
@@ -48,10 +48,11 @@ source ${REPO_ROOT}/reporc
 wget --user ${REPO_USER} --password ${REPO_PASS} https://flame-nexus.it-innovation.soton.ac.uk/repository/flame-general/it-innovation/telegraf/${TELEGRAF_VERSION}/telegraf-${TELEGRAF_VERSION}.deb -O telegraf-${TELEGRAF_VERSION}.deb
 
 
-#sha256sum telegraf_${TELEGRAF_VERSION}_amd64.deb | grep $TELEGRAF_CHECKSUM > /dev/null
-#if [ $? == 1 ]; then
-#	echo "Telegraf download failed checksum"
-#	exit 1
-#fi
 dpkg -i telegraf-${TELEGRAF_VERSION}.deb
 
+# add telegraf to run as root for systemctl input plugin
+# this should not be required as the "systemctl status" command is available to no priviledged users
+# issued raised 
+sed -i s/User=telegraf/User=root/g /lib/systemd/system/telegraf.service
+systemctl daemon-reload
+systemctl restart telegraf.service
\ No newline at end of file
diff --git a/src/test/clmctest/inputs/test_telegraf_agents.py b/src/test/clmctest/inputs/test_telegraf_agents.py
index 2358d93..88238ea 100644
--- a/src/test/clmctest/inputs/test_telegraf_agents.py
+++ b/src/test/clmctest/inputs/test_telegraf_agents.py
@@ -63,8 +63,9 @@ def test_ping(telegraf_agent_config):
     ('net', 'SELECT mean("bytes_sent") AS "mean" FROM "CLMCMetrics"."autogen"."net"', 0),
     ('disk', 'SELECT mean("free") AS "mean" FROM "CLMCMetrics"."autogen"."disk"', 0),
     ('mem', 'SELECT mean("free") AS "mean" FROM "CLMCMetrics"."autogen"."mem"', 0),
+    ('service_config_state', 'SELECT mean("loaded.active.running_count") AS "mean" FROM "CLMCMetrics"."autogen"."service_config_state" WHERE "resource"=\'nginx.service\'', 0),
     # Report MINIO's HTTP request response time (as a rolling difference of the sum total)
-    ('minio_http_requests_duration_seconds', 'SELECT difference(max("sum")) AS "mean" FROM "CLMCMetrics"."autogen"."minio_http_requests_duration_seconds" WHERE time > now() - 1h GROUP BY time(10s)',0),              
+    ('minio_http_requests_duration_seconds', 'SELECT difference(max("sum")) AS "mean" FROM "CLMCMetrics"."autogen"."minio_http_requests_duration_seconds" WHERE time > now() - 1h GROUP BY time(10s)',0),      
     # Report the average change in difference of MINIO's HTTP response time (the inner query determines a rolling difference between sampling periods [respTimeDiff])
     ('minio_http_requests_duration_seconds', 'SELECT mean("respTimeDiff") AS "mean" FROM (SELECT difference(max("sum")) AS "respTimeDiff" FROM "CLMCMetrics"."autogen"."minio_http_requests_duration_seconds" WHERE time > now() - 1h GROUP BY time(10s))',0)              
     ])
diff --git a/src/test/clmctest/services/nginx/telegraf_nginx.conf b/src/test/clmctest/services/nginx/telegraf_nginx.conf
index 6bc3b87..cce0734 100644
--- a/src/test/clmctest/services/nginx/telegraf_nginx.conf
+++ b/src/test/clmctest/services/nginx/telegraf_nginx.conf
@@ -30,4 +30,16 @@
 # # Influx HTTP write listener
 [[inputs.http_listener]]
   ## Address and port to host HTTP listener on
-  service_address = ":8186"
\ No newline at end of file
+  service_address = ":8186"
+
+[[inputs.systemctl]]
+	services = [
+	  "nginx.service",
+	]
+	## Sample rate for sampling state of service.
+	## Must be greter that the collection_interval/2 
+	sample_rate = 2
+	
+	## Logging level for this plugin according to logrus log levels
+	## "debug", "info", "warning", "error", "fatal", "panic"
+	log_level = "debug"
\ No newline at end of file
-- 
GitLab