description: >
  The generic Grafana Service

metadata:
  name: Generic Grafana Dashboard
  icon: https://www.cybus.io/wp-content/uploads/2017/10/for-whom3.svg
  provider: cybus
  homepage: https://www.cybus.io
  version: 1.2.1

definitions:
  SID: !ref Cybus::ServiceId
  CYBUS_MQTT_ROOT: 'services'

resources:

  #----------------------------------------------------------------------------
  # VOLUMES
  #----------------------------------------------------------------------------

  grafanaVolume:
    type: Cybus::Volume

  influxdbVolume:
    type: Cybus::Volume

  #----------------------------------------------------------------------------
  # FRONTENDS
  #----------------------------------------------------------------------------

  # Grafana
  grafanaURL:
    type: Cybus::IngressRoute
    properties:
      container: !ref genericGrafana
      type: http
      slug: grafana
      target:
        path: '/'
        port: 3000

  dashboard:
    type: Cybus::Link
    properties:
      name: Dashboard
      ingressRoute: !ref grafanaURL
      href: ''

  #----------------------------------------------------------------------------
  # Cybus Timeseris & Dashboard service containers
  #----------------------------------------------------------------------------

  influxdbPush:
      type: Cybus::Container
      properties:
        image: registry.cybus.io/cybus-services/influxdb-push:0.0.3
        environment:
          MQTT_HOST: !ref Cybus::MqttHost
          MQTT_USER: !ref Cybus::MqttUser
          MQTT_PORT: !ref Cybus::MqttPort
          MQTT_PASS: !ref Cybus::MqttPassword
          MQTT_ROOT_TOPIC: !sub "services/#"
          INFLUX_HOST: !ref influxdb
          INFLUX_PORT: 8086
          INFLUX_DB: generic
          HTTP_ROOT: /

  influxdb:
    type: Cybus::Container
    properties:
      image: registry.cybus.io/cybus-services/influxdb:1.7.7-alpine
      ports:
        - 8086:8086/tcp
      volumes:
        - !sub "${influxdbVolume}:/var/lib/influxdb"
      environment:
        INFLUXDB_DB: generic

  genericGrafana:
    type: Cybus::Container
    properties:
      image: registry.cybus.io/cybus-services/generic-grafana:1.2.1
      volumes:
        - !sub "${grafanaVolume}:/var/lib/grafana"
      environment:
        GF_SERVER_ROOT_URL: !sub "/services/${SID}/grafana"
        GF_AUTH_ANONYMOUS_ENABLED: true
        INFLUX_DB: generic
        INFLUX_HOST: !ref influxdb
        INFLUX_PORT: 8086
