zabbix_export:
  version: '7.0'
  template_groups:
    - uuid: 954038916d0c4aa593b4bc7726d04fc1
      name: CF/ServerLinux/DynamicDetectAddScript
  templates:
    - uuid: a91520e3f4a24948a05ec4b70d84c066
      template: '--CF DRBD on Linux'
      name: '--CF DRBD on Linux'
      groups:
        - name: CF/ServerLinux/DynamicDetectAddScript
      items:
        - uuid: b7e42417883642dab38546a3f47ed2a0
          name: 'DRDB fail cstate number'
          type: CALCULATED
          key: fail.count.drbd.cstate
          delay: 5m
          history: 7d
          trends: '0'
          params: 'count(last_foreach(//drbd.cstate[*]),"regexp","^Fail: ")'
          description: 'Count DRDB fail cstate'
          tags:
            - tag: component
              value: drbd
            - tag: scope
              value: health
            - tag: state
              value: cstate
          triggers:
            - uuid: 33f75700e3b14033bcc45fc261c568e7
              expression: 'last(/--CF DRBD on Linux/fail.count.drbd.cstate)>={$DRBD_FAIL_NUMBER}'
              name: 'DRBD Number of FAIL cstate is >= {$DRBD_FAIL_NUMBER}'
              opdata: 'Fail cstate: {ITEM.LASTVALUE}'
              priority: HIGH
              description: 'This trigger hides each cstate problem if the count is >= {$DRBD_FAIL_NUMBER}'
              tags:
                - tag: cf-oncall
                  value: '0'
                - tag: component
                  value: drbd
                - tag: jira
                  value: '0'
        - uuid: 3de55dc5968048efbb76c26c6584093b
          name: 'DRDB fail dstate number'
          type: CALCULATED
          key: fail.count.drbd.dstate
          delay: 5m
          history: 7d
          trends: '0'
          params: 'count(last_foreach(//drbd.dstate[*]),"regexp","^Fail: ")'
          description: 'Count DRDB fail dstate'
          tags:
            - tag: component
              value: drbd
            - tag: scope
              value: health
            - tag: state
              value: cstate
          triggers:
            - uuid: 2697f6e4a53947838231f1076f76704f
              expression: 'last(/--CF DRBD on Linux/fail.count.drbd.dstate)>={$DRBD_FAIL_NUMBER}'
              name: 'DRBD Number of FAIL dstate is >= {$DRBD_FAIL_NUMBER}'
              opdata: 'Fail dstate: {ITEM.LASTVALUE}'
              priority: HIGH
              description: 'This trigger hides each dstate problem if the count is >= {$DRBD_FAIL_NUMBER}'
              tags:
                - tag: cf-oncall
                  value: '0'
                - tag: component
                  value: drbd
                - tag: jira
                  value: '0'
      discovery_rules:
        - uuid: 0179e4a054a9416c8cc5ba854750f00e
          name: 'DRBD Resources'
          type: ZABBIX_ACTIVE
          key: drbd.discovery
          delay: 1h
          lifetime: 3d
          item_prototypes:
            - uuid: cfd1679cca3848dd8e92e62ac9b07d0c
              name: 'DRBD cstate: {#RESOURCE_NAME}'
              type: ZABBIX_ACTIVE
              key: 'drbd.cstate[{#RESOURCE_NAME}]'
              delay: 5m
              history: 7d
              value_type: TEXT
              trends: '0'
              description: 'Connection State for {#RESOURCE_NAME} DRBD Volume'
              preprocessing:
                - type: JAVASCRIPT
                  parameters:
                    - |
                      var lines = value.split('\n');
                      for (var i = 0; i < lines.length; i++) {
                          if (lines[i] !== 'Connected') {
                              return 'Fail: ' + value.replace(/\n/g, '/');
                          }
                      }
                      return 'OK: ' + value.replace(/\n/g, '/');
                      
              tags:
                - tag: component
                  value: drbd
                - tag: 'drbd resource'
                  value: '{#RESOURCE_NAME}'
                - tag: state
                  value: cstate
              trigger_prototypes:
                - uuid: 6dcb3769cab044dba0ebfbc9baced1f9
                  expression: 'find(/--CF DRBD on Linux/drbd.cstate[{#RESOURCE_NAME}],,"regexp","^OK: ")=0'
                  name: 'DRBD cstate volume {#RESOURCE_NAME} problem'
                  opdata: 'state: {{ITEM.LASTVALUE}.regsub("^(OK|Fail):\s*(.*)", "\2")}'
                  priority: HIGH
                  dependencies:
                    - name: 'DRBD Number of FAIL cstate is >= {$DRBD_FAIL_NUMBER}'
                      expression: 'last(/--CF DRBD on Linux/fail.count.drbd.cstate)>={$DRBD_FAIL_NUMBER}'
                  tags:
                    - tag: cf-oncall
                      value: '0'
                    - tag: component
                      value: drbd
                    - tag: jira
                      value: '0'
            - uuid: 836d2506162c4d1da828926fc6e6d0a1
              name: 'DRBD dstate: {#RESOURCE_NAME}'
              type: ZABBIX_ACTIVE
              key: 'drbd.dstate[{#RESOURCE_NAME}]'
              delay: 5m
              history: 7d
              value_type: TEXT
              trends: '0'
              description: 'Device State for {#RESOURCE_NAME} DRBD Volume'
              preprocessing:
                - type: JAVASCRIPT
                  parameters:
                    - |
                      var parts = value.split('/');
                      var count = 0;
                      for (var i = 0; i < parts.length; i++) {
                          if (parts[i] === 'UpToDate') {
                              count++;
                          }
                      }
                      if (count >= 2) {
                          return 'OK: ' + value.replace(/\n/g, ' ');;
                      } else {
                          return 'Fail: ' + value.replace(/\n/g, ' ');
                      }
                      
              tags:
                - tag: component
                  value: drbd
                - tag: 'drbd resource'
                  value: '{#RESOURCE_NAME}'
                - tag: state
                  value: dstate
              trigger_prototypes:
                - uuid: e72614c4b2444137a67ef57dafd826b9
                  expression: 'find(/--CF DRBD on Linux/drbd.dstate[{#RESOURCE_NAME}],,"regexp","^OK: ")=0'
                  name: 'DRBD dstate volume {#RESOURCE_NAME} problem'
                  opdata: 'state: {{ITEM.LASTVALUE}.regsub("^(OK|Fail):\s*(.*)", "\2")}'
                  priority: HIGH
                  dependencies:
                    - name: 'DRBD Number of FAIL dstate is >= {$DRBD_FAIL_NUMBER}'
                      expression: 'last(/--CF DRBD on Linux/fail.count.drbd.dstate)>={$DRBD_FAIL_NUMBER}'
                  tags:
                    - tag: cf-oncall
                      value: '0'
                    - tag: component
                      value: drbd
                    - tag: jira
                      value: '0'
      tags:
        - tag: class
          value: storage
        - tag: component
          value: drbd
      macros:
        - macro: '{$DRBD_FAIL_NUMBER}'
          value: '3'
          description: 'Hide each cstate/dstate problem if count is > fail NR'
