From 1c8e96562a002aab2e17349c7711eb8e799c34c1 Mon Sep 17 00:00:00 2001
From: Dan <22e889d8@opayq.com>
Date: Thu, 23 Feb 2017 16:14:09 +0000
Subject: [PATCH] Added measurement in template config sanity check - resolves
 #25

---
 influxgraph/templates.py                     | 7 ++++++-
 tests/test_influxdb_templates_integration.py | 4 ++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/influxgraph/templates.py b/influxgraph/templates.py
index c0b18b9..29eb560 100644
--- a/influxgraph/templates.py
+++ b/influxgraph/templates.py
@@ -20,6 +20,7 @@
 from collections import deque
 from heapq import heappush, heappop
 
+
 logger = logging.getLogger('influxgraph')
 
 
@@ -135,7 +136,11 @@ def _template_sanity_check(template):
             field = tag
     if measurement_wildcard and field_wildcard:
         raise InvalidTemplateError(
-            "Either 'field*' or 'measurement*' can be used in each template, not both - %s",
+            "Either 'field*' or 'measurement*' can be used in each template, "
+            "not both - %s", template)
+    if not measurement_wildcard and 'measurement' not in template.values():
+        raise InvalidTemplateError(
+            "At least one of 'measurement' or 'measurement*' is required - %s",
             template)
 
 def apply_template(metric_path_parts, template, default_tags, separator='.'):
diff --git a/tests/test_influxdb_templates_integration.py b/tests/test_influxdb_templates_integration.py
index a5b2b15..6452a70 100644
--- a/tests/test_influxdb_templates_integration.py
+++ b/tests/test_influxdb_templates_integration.py
@@ -949,6 +949,10 @@ def test_bad_templates(self):
         self.assertRaises(InvalidTemplateError, influxgraph.InfluxDBFinder, self.config)
         self.config['influxdb']['templates'] = ['host.field.field']
         self.assertRaises(InvalidTemplateError, influxgraph.InfluxDBFinder, self.config)
+        self.config['influxdb']['templates'] = ['host.field']
+        self.assertRaises(InvalidTemplateError, influxgraph.InfluxDBFinder, self.config)
+        self.config['influxdb']['templates'] = ['host.measurements.field']
+        self.assertRaises(InvalidTemplateError, influxgraph.InfluxDBFinder, self.config)
 
     def test_template_nofilter_extra_tags(self):
         self.config['influxdb']['templates'] = ['host.measurement* env=int,region=the_west']