workflow:
  id: fluxcd-example
  name: "FluxCD Resource Monitor"
  description: "Example workflow that retrieves Flux CD resources and creates alerts for failed deployments"
  triggers:
    - type: interval
      value: 1800  # 30 minutes in seconds
  steps:
    - name: get-fluxcd-resources
      provider:
        type: fluxcd
        config: "{{ providers.fluxcd }}"
        with:
          kubeconfig: "{{ env.KUBECONFIG }}"
          namespace: "flux-system"
      vars:
        fluxcd_resources: "{{ steps.get-fluxcd-resources.results }}"

    - name: check-for-failed-deployments
      provider:
        type: console
        with:
          message: |
            Found {{ vars.fluxcd_resources.kustomizations | length }} Kustomizations and {{ vars.fluxcd_resources.helm_releases | length }} HelmReleases

    - name: create-alerts-for-failed-kustomizations
      foreach: "{{ vars.fluxcd_resources.kustomizations }}"
      if: "{{ item.status.conditions[0].status == 'False' }}"
      provider:
        type: keep
        with:
          alert_name: "FluxCD Kustomization {{ item.metadata.name }} failed"
          alert_description: "Kustomization {{ item.metadata.name }} in namespace {{ item.metadata.namespace }} failed with message: {{ item.status.conditions[0].message }}"
          alert_severity: "critical"
          alert_fingerprint: "fluxcd-kustomization-{{ item.metadata.name }}-{{ item.metadata.namespace }}"
          alert_source: "fluxcd"
          alert_labels:
            namespace: "{{ item.metadata.namespace }}"
            name: "{{ item.metadata.name }}"
            type: "kustomization"

    - name: create-alerts-for-failed-helmreleases
      foreach: "{{ vars.fluxcd_resources.helm_releases }}"
      if: "{{ item.status.conditions[0].status == 'False' }}"
      provider:
        type: keep
        with:
          alert_name: "FluxCD HelmRelease {{ item.metadata.name }} failed"
          alert_description: "HelmRelease {{ item.metadata.name }} in namespace {{ item.metadata.namespace }} failed with message: {{ item.status.conditions[0].message }}"
          alert_severity: "critical"
          alert_fingerprint: "fluxcd-helmrelease-{{ item.metadata.name }}-{{ item.metadata.namespace }}"
          alert_source: "fluxcd"
          alert_labels:
            namespace: "{{ item.metadata.namespace }}"
            name: "{{ item.metadata.name }}"
            type: "helmrelease"
