zabbix_export:
  version: '5.4'
  date: '2022-01-18T15:05:07Z'
  groups:
    -
      uuid: a571c0d144b14fd4a87a9d9b2aa9fcd6
      name: Templates/Applications
  templates:
    -
      uuid: e64befe2d45249b7b7a1284eb29a2823
      template: 'Systemd by Zabbix agent 2 active'
      name: 'Systemd by Zabbix agent 2 active'
      description: |
        Get systemd units metrics from plugin for the zabbix-agent2.
          1. Setup and configure zabbix-agent2 compiled with the Systemd monitoring plugin.
          2. Set filters with macros if you want to override default filter parameters.
        
        You can discuss this template or leave feedback on our forum https://www.zabbix.com/forum/zabbix-suggestions-and-feedback/
        
        Template tooling version used: 0.40
      groups:
        -
          name: Templates/Applications
      discovery_rules:
        -
          uuid: 4a221f4fe9de454c940ea2c61b630a92
          name: 'Service units discovery'
          key: 'systemd.unit.discovery[service]'
          delay: 30m
          filter:
            evaltype: AND
            conditions:
              -
                macro: '{#UNIT.ACTIVESTATE}'
                value: '{$SYSTEMD.ACTIVESTATE.SERVICE.MATCHES}'
                formulaid: A
              -
                macro: '{#UNIT.ACTIVESTATE}'
                value: '{$SYSTEMD.ACTIVESTATE.SERVICE.NOT_MATCHES}'
                operator: NOT_MATCHES_REGEX
                formulaid: B
              -
                macro: '{#UNIT.UNITFILESTATE}'
                value: '{$SYSTEMD.UNITFILESTATE.SERVICE.MATCHES}'
                formulaid: E
              -
                macro: '{#UNIT.UNITFILESTATE}'
                value: '{$SYSTEMD.UNITFILESTATE.SERVICE.NOT_MATCHES}'
                operator: NOT_MATCHES_REGEX
                formulaid: F
              -
                macro: '{#UNIT.NAME}'
                value: '{$SYSTEMD.NAME.SERVICE.NOT_MATCHES}'
                operator: NOT_MATCHES_REGEX
                formulaid: C
              -
                macro: '{#UNIT.NAME}'
                value: '{$SYSTEMD.NAME.SERVICE.MATCHES}'
                formulaid: D
          description: 'Discover systemd service units and their details.'
          item_prototypes:
            -
              uuid: 137752b64531404b8a093ae2d30b27fc
              name: '{#UNIT.NAME}: Active state'
              type: DEPENDENT
              key: 'systemd.service.active_state["{#UNIT.NAME}"]'
              delay: '0'
              history: 7d
              description: 'State value that reflects whether the unit is currently active or not. The following states are currently defined: "active", "reloading", "inactive", "failed", "activating", and "deactivating".'
              valuemap:
                name: 'Unit Active State'
              preprocessing:
                -
                  type: JSONPATH
                  parameters:
                    - $.ActiveState.state
                -
                  type: DISCARD_UNCHANGED_HEARTBEAT
                  parameters:
                    - 30m
              master_item:
                key: 'systemd.unit.get["{#UNIT.NAME}"]'
              tags:
                -
                  tag: Application
                  value: 'Systemd service: {#UNIT.NAME}'
            -
              uuid: a1dc6d3db9fa473b932a80bb98601f3f
              name: '{#UNIT.NAME}: Load state'
              type: DEPENDENT
              key: 'systemd.service.load_state["{#UNIT.NAME}"]'
              delay: '0'
              history: 7d
              description: 'State value that reflects whether the configuration file of this unit has been loaded. The following states are currently defined: "loaded", "error", and "masked".'
              valuemap:
                name: 'Unit Load State'
              preprocessing:
                -
                  type: JSONPATH
                  parameters:
                    - $.LoadState.state
                -
                  type: DISCARD_UNCHANGED_HEARTBEAT
                  parameters:
                    - 30m
              master_item:
                key: 'systemd.unit.get["{#UNIT.NAME}"]'
              tags:
                -
                  tag: Application
                  value: 'Systemd service: {#UNIT.NAME}'
            -
              uuid: eaf818907d5c43ceb88f279a75bc0103
              name: '{#UNIT.NAME}: Unit file state'
              type: DEPENDENT
              key: 'systemd.service.unitfile_state["{#UNIT.NAME}"]'
              delay: '0'
              history: 7d
              description: 'Encodes the install state of the unit file of FragmentPath. It currently knows the following states: "enabled", "enabled-runtime", "linked", "linked-runtime", "masked", "masked-runtime", "static", "disabled", and "invalid".'
              valuemap:
                name: 'Unit File State'
              preprocessing:
                -
                  type: JSONPATH
                  parameters:
                    - $.UnitFileState.state
                -
                  type: DISCARD_UNCHANGED_HEARTBEAT
                  parameters:
                    - 30m
              master_item:
                key: 'systemd.unit.get["{#UNIT.NAME}"]'
              tags:
                -
                  tag: Application
                  value: 'Systemd service: {#UNIT.NAME}'
            -
              uuid: 5adfaee42969493cae9b2d3b500e2ba1
              name: '{#UNIT.NAME}: Active time'
              type: DEPENDENT
              key: 'systemd.service.uptime["{#UNIT.NAME}"]'
              delay: '0'
              history: 7d
              value_type: FLOAT
              units: s
              description: 'Number of seconds since unit entered the active state.'
              preprocessing:
                -
                  type: JAVASCRIPT
                  parameters:
                    - |
                      data = JSON.parse(value)
                        if (data.ActiveEnterTimestamp > data.ActiveExitTimestamp) {
                            return Math.floor(Date.now()/1000)-Number(data.ActiveEnterTimestamp)/1000000;
                          }
                        return null;
              master_item:
                key: 'systemd.unit.get["{#UNIT.NAME}"]'
              tags:
                -
                  tag: Application
                  value: 'Systemd service: {#UNIT.NAME}'
              trigger_prototypes:
                -
                  uuid: af47a41a1605475ca7168e91e4a15c78
                  expression: 'last(/Systemd by Zabbix agent 2 active/systemd.service.uptime["{#UNIT.NAME}"])<10m'
                  name: '{#UNIT.NAME}: has been restarted (uptime < 10m)'
                  priority: INFO
                  description: 'Uptime is less than 10 minutes'
            -
              uuid: 7bed79135b224faea64a628247e86c15
              name: '{#UNIT.NAME}: Get unit info'
              type: ZABBIX_ACTIVE
              key: 'systemd.unit.get["{#UNIT.NAME}"]'
              history: '0'
              trends: '0'
              value_type: TEXT
              description: |
                Returns all properties of a systemd service unit.
                 Unit description: {#UNIT.DESCRIPTION}.
              tags:
                -
                  tag: Application
                  value: 'Zabbix raw items'
            -
              uuid: af3c08f69cfc43888079cfe9cd9ba6de
              name: '{#UNIT.NAME}: Type of Service'
              type: ZABBIX_ACTIVE
              key: 'systemd.unit.info["{#UNIT.NAME}",Type,Service]'
              history: 7d
              trends: '0'
              value_type: CHAR
              tags:
                -
                  tag: Application
                  value: 'Systemd service: {#UNIT.NAME}'
          trigger_prototypes:
            -
              uuid: 927e4788de4e477d9cb2fff2fe06b200
              expression: 'last(/Systemd by Zabbix agent 2 active/systemd.service.active_state["{#UNIT.NAME}"])<>1 and last(/Systemd by Zabbix agent 2 active/systemd.unit.info["{#UNIT.NAME}",Type,Service])<>"oneshot" and last(/Systemd by Zabbix agent 2 active/systemd.service.unitfile_state["{#UNIT.NAME}"])="enabled"'
              name: '{#UNIT.NAME}: Service is not running'
              priority: AVERAGE
            -
              uuid: da387535fabf402e9d223abd159d5dc6
              expression: 'last(/Systemd by Zabbix agent 2 active/systemd.service.active_state["{#UNIT.NAME}"])<>1 and last(/Systemd by Zabbix agent 2 active/systemd.unit.info["{#UNIT.NAME}",Type,Service])<>"oneshot" and last(/Systemd by Zabbix agent 2 active/systemd.service.unitfile_state["{#UNIT.NAME}"])="disabled"'
              name: '{#UNIT.NAME}: Service is running but not enabled'
              priority: WARNING
        -
          uuid: 0c4e8adc01514dfbafc49a958bd934b3
          name: 'Socket units discovery'
          key: 'systemd.unit.discovery[socket]'
          delay: 30m
          filter:
            evaltype: AND
            conditions:
              -
                macro: '{#UNIT.ACTIVESTATE}'
                value: '{$SYSTEMD.ACTIVESTATE.SOCKET.MATCHES}'
                formulaid: A
              -
                macro: '{#UNIT.ACTIVESTATE}'
                value: '{$SYSTEMD.ACTIVESTATE.SOCKET.NOT_MATCHES}'
                operator: NOT_MATCHES_REGEX
                formulaid: B
              -
                macro: '{#UNIT.UNITFILESTATE}'
                value: '{$SYSTEMD.UNITFILESTATE.SOCKET.MATCHES}'
                formulaid: E
              -
                macro: '{#UNIT.UNITFILESTATE}'
                value: '{$SYSTEMD.UNITFILESTATE.SOCKET.NOT_MATCHES}'
                operator: NOT_MATCHES_REGEX
                formulaid: F
              -
                macro: '{#UNIT.NAME}'
                value: '{$SYSTEMD.NAME.SOCKET.NOT_MATCHES}'
                operator: NOT_MATCHES_REGEX
                formulaid: C
              -
                macro: '{#UNIT.NAME}'
                value: '{$SYSTEMD.NAME.SOCKET.MATCHES}'
                formulaid: D
          description: 'Discover systemd socket units and their details.'
          item_prototypes:
            -
              uuid: 42c94ee0320442a0842736eee0aefb27
              name: '{#UNIT.NAME}: Connections accepted per sec'
              type: DEPENDENT
              key: 'systemd.socket.conn_accepted.rate["{#UNIT.NAME}"]'
              delay: '0'
              history: 7d
              description: 'The number of accepted socket connections (NAccepted) per second.'
              preprocessing:
                -
                  type: JSONPATH
                  parameters:
                    - $.NAccepted
                -
                  type: CHANGE_PER_SECOND
                  parameters:
                    - ''
              master_item:
                key: 'systemd.unit.get["{#UNIT.NAME}",Socket]'
              tags:
                -
                  tag: Application
                  value: 'Systemd socket: {#UNIT.NAME}'
            -
              uuid: 973d36b4bbe445b9aff6c20d414a9520
              name: '{#UNIT.NAME}: Connections connected'
              type: DEPENDENT
              key: 'systemd.socket.conn_count["{#UNIT.NAME}"]'
              delay: '0'
              history: 7d
              description: 'The current number of socket connections (NConnections).'
              preprocessing:
                -
                  type: JSONPATH
                  parameters:
                    - $.NConnections
              master_item:
                key: 'systemd.unit.get["{#UNIT.NAME}",Socket]'
              tags:
                -
                  tag: Application
                  value: 'Systemd socket: {#UNIT.NAME}'
            -
              uuid: f0685af8b5784e8b9018fbf44f3f4b26
              name: '{#UNIT.NAME}: Get unit info'
              type: ZABBIX_ACTIVE
              key: 'systemd.unit.get["{#UNIT.NAME}",Socket]'
              history: '0'
              trends: '0'
              value_type: TEXT
              description: |
                Returns all properties of a systemd socket unit.
                 Unit description: {#UNIT.DESCRIPTION}.
              tags:
                -
                  tag: Application
                  value: 'Zabbix raw items'
      macros:
        -
          macro: '{$SYSTEMD.ACTIVESTATE.SERVICE.MATCHES}'
          value: active
          description: 'Filter of systemd service units by active state'
        -
          macro: '{$SYSTEMD.ACTIVESTATE.SERVICE.NOT_MATCHES}'
          value: CHANGE_IF_NEEDED
          description: 'Filter of systemd service units by active state'
        -
          macro: '{$SYSTEMD.ACTIVESTATE.SOCKET.MATCHES}'
          value: active
          description: 'Filter of systemd socket units by active state'
        -
          macro: '{$SYSTEMD.ACTIVESTATE.SOCKET.NOT_MATCHES}'
          value: CHANGE_IF_NEEDED
          description: 'Filter of systemd socket units by active state'
        -
          macro: '{$SYSTEMD.NAME.SERVICE.MATCHES}'
          value: '.*'
          description: 'Filter of systemd service units by name'
        -
          macro: '{$SYSTEMD.NAME.SERVICE.NOT_MATCHES}'
          value: CHANGE_IF_NEEDED
          description: 'Filter of systemd service units by name'
        -
          macro: '{$SYSTEMD.NAME.SOCKET.MATCHES}'
          value: '.*'
          description: 'Filter of systemd socket units by name'
        -
          macro: '{$SYSTEMD.NAME.SOCKET.NOT_MATCHES}'
          value: CHANGE_IF_NEEDED
          description: 'Filter of systemd socket units by name'
        -
          macro: '{$SYSTEMD.UNITFILESTATE.SERVICE.MATCHES}'
          value: enabled
          description: 'Filter of systemd service units by unit file state'
        -
          macro: '{$SYSTEMD.UNITFILESTATE.SERVICE.NOT_MATCHES}'
          value: CHANGE_IF_NEEDED
          description: 'Filter of systemd service units by unit file state'
        -
          macro: '{$SYSTEMD.UNITFILESTATE.SOCKET.MATCHES}'
          value: enabled
          description: 'Filter of systemd socket units by unit file state'
        -
          macro: '{$SYSTEMD.UNITFILESTATE.SOCKET.NOT_MATCHES}'
          value: CHANGE_IF_NEEDED
          description: 'Filter of systemd socket units by unit file state'
      valuemaps:
        -
          uuid: 2893472ab98f4e4383075ed5946d8b93
          name: 'Unit Active State'
          mappings:
            -
              value: '0'
              newvalue: unknown
            -
              value: '1'
              newvalue: active
            -
              value: '2'
              newvalue: reloading
            -
              value: '3'
              newvalue: inactive
            -
              value: '4'
              newvalue: failed
            -
              value: '5'
              newvalue: activating
            -
              value: '6'
              newvalue: deactivating
        -
          uuid: 8f92a75876414cfda2bcac2d3184a520
          name: 'Unit File State'
          mappings:
            -
              value: '0'
              newvalue: unknown
            -
              value: '1'
              newvalue: enabled
            -
              value: '2'
              newvalue: enabled-runtime
            -
              value: '3'
              newvalue: linked
            -
              value: '4'
              newvalue: linked-runtime
            -
              value: '5'
              newvalue: masked
            -
              value: '6'
              newvalue: masked-runtime
            -
              value: '7'
              newvalue: static
            -
              value: '8'
              newvalue: disabled
            -
              value: '9'
              newvalue: invalid
        -
          uuid: e68d91de6b6849a7be6d09d0eec97633
          name: 'Unit Load State'
          mappings:
            -
              value: '0'
              newvalue: unknown
            -
              value: '1'
              newvalue: loaded
            -
              value: '2'
              newvalue: error
            -
              value: '3'
              newvalue: masked
