apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  name: vm-not-running-alert
spec:
  groups:
  - name: kubevirt-alerts
    rules:
    - alert: VMNotRunningFor10Minutes
      expr: |
        max_over_time(
          kubevirt_vm_info{
            status!="Running",
            exported_namespace=~".+",
            name=~".+"
          }[10m]
        ) == 1
      labels:
        severity: critical
        namespace: "{{ $labels.exported_namespace }}"
      annotations:
        summary: "VM '{{ $labels.name }}' in namespace '{{ $labels.exported_namespace }}' is not Running for more than 10 minutes"
        description: >
          The VM '{{ $labels.name }}' in namespace '{{ $labels.exported_namespace }}' has been in a non-Running state
          for more than 10 minutes. Please investigate the issue.
    - alert: VMINotRunningFor10Minutes
      expr: |
        max_over_time(
          kubevirt_vmi_info{
            phase!="running",
            exported_namespace=~".+",
            name=~".+"
          }[10m]
        ) == 1
      labels:
        severity: critical
        namespace: "{{ $labels.exported_namespace }}"
      annotations:
        summary: "VMI '{{ $labels.name }}' in namespace '{{ $labels.exported_namespace }}' is not Running for more than 10 minutes"
        description: >
          The VM '{{ $labels.name }}' in namespace '{{ $labels.exported_namespace }}' has been in a non-Running state
          for more than 10 minutes. Please investigate the issue.
