Merge pull request #26 from salt-formulas/add-continuous-queries

FEATURE, add continuous query support
diff --git a/README.rst b/README.rst
index 769bb2d..75ffe55 100644
--- a/README.rst
+++ b/README.rst
@@ -264,6 +264,20 @@
             database: mydb1
             privilege: all
 
+
+Create an continuous queries:
+
+.. code-block:: yaml
+
+    influxdb:
+      client:
+        database:
+          mydb1:
+            continuos_query:
+              cq_avg_bus_passengers: >-
+                SELECT mean("passengers") INTO "transportation"."three_weeks"."average_passengers" FROM "bus_data" GROUP BY time(1h)
+
+
 InfluxDB relay with HTTP outputs:
 
 .. code-block:: yaml
diff --git a/influxdb/client.sls b/influxdb/client.sls
index f312531..f698a64 100644
--- a/influxdb/client.sls
+++ b/influxdb/client.sls
@@ -80,4 +80,18 @@
   {%- endif %}
 {%- endfor %}
 
+
+{# CONTINUOUS QUERIES #}
+{%- for db_name, db in client.get('database', {}).iteritems() %}
+  {%- set db_name = db.get('name', db_name) %}
+  {%- for cq_name, cq in db.get('continuous_query', {}).iteritems() %}
+    {%- set query_continuous_query = 'CONTINUOUS QUERY {} ON {} BEGIN {} END'.format(cq_name, db_name, cq ) %}
+influxdb_continuous_query_{{db_name}}_{{ cq_name }}:
+  cmd.run:
+    - name: {{ curl_command }} -s -S -POST "{{ auth_url }}" --data-urlencode "q=CREATE {{ query_continuous_query }}"|grep -v "already exists" || {{ curl_command }} -s -S -POST "{{ auth_url }}" --data-urlencode "q=ALTER {{ query_continuous_query }}"
+    - onlyif: {{ curl_command }} -s -S -POST "{{ auth_url }}" --data-urlencode "q=SHOW DATABASES" | grep {{ db_name }}
+
+  {%- endfor %}
+{%- endfor %}
+
 {%- endif %}
diff --git a/tests/pillar/client.sls b/tests/pillar/client.sls
index 5d1f0d2..6a38619 100644
--- a/tests/pillar/client.sls
+++ b/tests/pillar/client.sls
@@ -25,6 +25,11 @@
         - name: rp_db2
           duration: 365d
           replication: 1
+        continuous_query:
+          cq_avg_passenger: >-
+            SELECT mean("passengers") INTO "transportation"."rp_db1"."average_passengers" FROM "_data" GROUP BY time(1h)
+          cq_basic_br: ->
+            SELECT mean(*) INTO "downsampled_transportation"."autogen".:MEASUREMENT FROM /.*/ GROUP BY time(30m),*
       mydb2:
         enabled: true
         name: mydb2
diff --git a/tests/pillar/repo_influxdata.sls b/tests/pillar/repo_influxdata.sls
index 9599f02..012a7ae 100644
--- a/tests/pillar/repo_influxdata.sls
+++ b/tests/pillar/repo_influxdata.sls
@@ -3,6 +3,6 @@
     enabled: true
     repo:
       linux_influxdata:
-        source: "deb https://repos.influxdata.com/ubuntu {{ grains.get('oscodename') }} stable"
+        source: "deb http://repos-backend.influxdata.com/ubuntu {{ grains.get('oscodename') }} stable"
         architectures: amd64
-        key_url: "https://repos.influxdata.com/influxdb.key"
+        key_url: "http://repos-backend.influxdata.com/influxdb.key"