zabbix_export:
  version: '7.0'
  template_groups:
    - uuid: e29f7cbf75cf41cb81078cb4c10d584a
      name: Templates/Databases
  templates:
    - uuid: 69899eb3126b4c62b70351f305b69dd9
      template: 'Zabbix Partitioning Monitor'
      name: 'Zabbix Partitioning Monitor'
      description: |
        Monitor Zabbix Database Partitioning.
        Prerequisites:
        1. Install zabbix_partitioning.py on the Zabbix Server/Proxy.
        2. Configure userparameter for automatic discovery:
           UserParameter=zabbix.partitioning.discovery[*], /usr/local/bin/zabbix_partitioning.py -c $1 --discovery
           UserParameter=zabbix.partitioning.discovery[*], /usr/local/bin/zabbix_partitioning.py -c $1 --discovery
           UserParameter=zabbix.partitioning.stats[*], /usr/local/bin/zabbix_partitioning.py -c $1 --stats $2
           # Legacy check removed in favor of stats
        
        Or use Docker wrapper scripts.
      groups:
        - name: Templates/Databases
      items:
        - uuid: bc753e750cc2485f917ba1f023c87d05
          name: 'Partitioning Last Run Status'
          type: ZABBIX_ACTIVE
          key: 'log[/var/log/syslog,zabbix_partitioning]'
          history: 7d
          value_type: LOG
          trends: '0'
          triggers:
            - uuid: 25497978dbb943e49dac8f3b9db91c29
              expression: 'find(/Zabbix Partitioning Monitor/log[/var/log/syslog,zabbix_partitioning],,"like","Failed")=1'
              name: 'Partitioning Script Failed'
              priority: HIGH
              description: 'The partitioning script reported a failure.'
              tags:
                - tag: services
                  value: database
      discovery_rules:
        - uuid: 097c96467035468a80ce5c519b0297bb
          name: 'Partitioning Discovery'
          key: 'zabbix.partitioning.discovery[{$PATH.TO.CONFIG}]'
          delay: 1d
          description: 'Discover partitioned tables'
          item_prototypes:
            - uuid: 1fbff85191c244dca956be7a94bf08a3
              name: 'Partitioning Stats: {#TABLE}'
              key: 'zabbix.partitioning.stats[{$PATH.TO.CONFIG}, {#TABLE}]'
              delay: 12h
              history: '0'
              trends: '0'
              value_type: TEXT
              description: 'JSON statistics for table {#TABLE}'
              tags:
                - tag: component
                  value: partitioning
                - tag: table
                  value: '{#TABLE}'

            - uuid: a8371234567890abcdef1234567890ab
              name: 'Days remaining: {#TABLE}'
              type: DEPENDENT
              key: 'zabbix.partitioning.days_left[{#TABLE}]'
              delay: 0
              history: 7d
              description: 'Days until the last partition runs out for {#TABLE}'
              master_item:
                key: 'zabbix.partitioning.stats[{$PATH.TO.CONFIG}, {#TABLE}]'
              preprocessing:
                - type: JSONPATH
                  parameters:
                    - $.days_left
              tags:
                - tag: component
                  value: partitioning
                - tag: table
                  value: '{#TABLE}'
              trigger_prototypes:
                - uuid: da23fae76a41455c86c58267d6d9f86d
                  expression: 'last(/Zabbix Partitioning Monitor/zabbix.partitioning.days_left[{#TABLE}])<={$PARTITION.DAYS}'
                  name: 'Partitioning critical: {#TABLE} has less than {$PARTITION.DAYS} days in partition'
                  opdata: 'Days till Zabbix server will crash: {ITEM.LASTVALUE}'
                  priority: DISASTER
                  description: 'New partitions are not being created. Check the script logs.'

            - uuid: b9482345678901bcdef23456789012cd
              name: 'Partition Count: {#TABLE}'
              type: DEPENDENT
              key: 'zabbix.partitioning.count[{#TABLE}]'
              delay: 0
              history: 7d
              description: 'Total number of partitions for {#TABLE}'
              master_item:
                key: 'zabbix.partitioning.stats[{$PATH.TO.CONFIG}, {#TABLE}]'
              preprocessing:
                - type: JSONPATH
                  parameters:
                    - $.partition_count
              tags:
                - tag: component
                  value: partitioning
                - tag: table
                  value: '{#TABLE}'

            - uuid: c0593456789012cdef345678901234de
              name: 'Table Size: {#TABLE}'
              type: DEPENDENT
              key: 'zabbix.partitioning.size[{#TABLE}]'
              delay: 0
              history: 7d
              units: B
              description: 'Total size (Data+Index) of {#TABLE}'
              master_item:
                key: 'zabbix.partitioning.stats[{$PATH.TO.CONFIG}, {#TABLE}]'
              preprocessing:
                - type: JSONPATH
                  parameters:
                    - $.size_bytes
              tags:
                - tag: component
                  value: partitioning
                - tag: table
                  value: '{#TABLE}'
      macros:
        - macro: '{$PARTITION.DAYS}'
          value: '3'
        - macro: '{$PATH.TO.CONFIG}'
          value: /etc/zabbix/scripts/zabbix_partitioning.conf
