grafana / grafana-operator

An operator for Grafana that installs and manages Grafana instances, Dashboards and Datasources through Kubernetes/OpenShift CRs
https://grafana.github.io/grafana-operator/
Apache License 2.0
903 stars 394 forks source link

Auto-enable app plugins via operator. #1392

Open guilhermeferreyra opened 9 months ago

guilhermeferreyra commented 9 months ago

I installed the Zabbix Plugin via the Dashboard Yaml file, but the plugin requires manual interaction to be enabled. It would be beneficial to automate the installation process by auto-enabling the plugin.

Here is the YAML that I used to install the plugin.

apiVersion: grafana.integreatly.org/v1beta1
kind: GrafanaDashboard
metadata:
  name: grafanadashboard-sample
  namespace: grafana
spec:
  resyncPeriod: 30s
  instanceSelector:
    matchLabels:
      dashboards: "grafana"
  plugins:
    - name: alexanderzobnin-zabbix-app
      version: 4.4.5
  json: >
    {
      "id": null,
      "title": "Simple Dashboard",
      "tags": [],
      "style": "dark",
      "timezone": "browser",
      "editable": true,
      "hideControls": false,
      "graphTooltip": 1,
      "panels": [],
      "time": {
        "from": "now-6h",
        "to": "now"
      },
      "timepicker": {
        "time_options": [],
        "refresh_intervals": []
      }...

300584617-2c81c57b-e742-4b7a-ad3a-99c2cf980fce

Tualua commented 9 months ago

I use this ansible task. Works perfectly with plugin 4.4.5 and Grafana 10.1.6

---
- name: Add datasources
  hosts: master
  gather_facts: no
  become: yes
  tasks:
    - name: Add Zabbix datasource
      kubernetes.core.k8s:
        state: present
        definition:
          apiVersion: grafana.integreatly.org/v1beta1
          kind: GrafanaDatasource
          metadata:
            name: "{{ deployment_name }}-datasource-zabbix"
            namespace: "{{ namespace }}"
          spec:
            valuesFrom:
            - targetPath: "jsonData.username"
              valueFrom:
                secretKeyRef:
                  name: "{{ deployment_name }}-zabbix-account"
                  key: "GF_SECURITY_ZABBIX_USER"
            - targetPath: "secureJsonData.password"
              valueFrom:
                secretKeyRef:
                  name: "{{ deployment_name }}-zabbix-account"
                  key: "GF_SECURITY_ZABBIX_PASSWORD"
            instanceSelector:
              matchLabels:
                dashboards: "{{ deployment_name }}"
            plugins:
                - name: alexanderzobnin-zabbix-app
                  version: "{{ zabbix_plugin_version }}"
            datasource:
              uid: "DSZABBIX"
              name: my-zabbix
              type: "alexanderzobnin-zabbix-datasource"
              access: server
              url: https://my.zabbix.tld/api_jsonrpc.php
              isDefault: true
              jsonData:
                "authType": "userLogin"
                "dbConnectionDatasourceId": 1
                "dbConnectionEnable": true
                "disableDataAlignment": false
                "trends": true
                "trendsFrom": ""
                "trendsRange": ""
                "username": ${GF_SECURITY_ZABBIX_USER}
              secureJsonData:
                "password": ${GF_SECURITY_ZABBIX_PASSWORD}
              editable: true

I also use Postgresql connection deployed with provisioning

"dbConnectionDatasourceId": 1
"dbConnectionEnable": true

Just disable this if you don't need it

hubeadmin commented 9 months ago

@theSuess Will look into this, however, there should be a flag to do this automatically. Pending his investigation

theSuess commented 9 months ago

Alright, the difference is between app and datasource plugins. App plugins currently need to be enabled manually or using a provisioning file. This is something we should be able to implement by either using an init container or config map which will provide a plugin provisioning file like this:

apiVersion: 1

apps:
  - type: alexanderzobnin-zabbix-app
    disabled: false
pb82 commented 8 months ago

@theSuess does this apply to all App plugins or only some of them?