zabbix_export:
  version: '6.0'
  date: '2022-12-01T12:35:38Z'
  templates:
    -
      uuid: d92d19ac1c964fa683f8b9dfe2d00920
      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.41
      groups:
        -
          name: Templates/Applications
      discovery_rules:
        -
          uuid: 92b878cd6a814a158bca19a0c1939fdb
          name: 'Service units discovery'
          type: ZABBIX_ACTIVE
          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: 663231a68dea4013830fbbbf74dbe1e9
              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: component
                  value: service
            -
              uuid: d313c2e87cb846349bfd51ba8c151381
              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: component
                  value: service
            -
              uuid: 546b9696cc7b485e9c99179c322e5ac3
              name: '{#UNIT.NAME}: Service type'
              type: DEPENDENT
              key: 'systemd.service.type["{#UNIT.NAME}"]'
              delay: '0'
              history: 7d
              trends: '0'
              value_type: TEXT
              description: 'The service types.'
              valuemap:
                name: 'Unit Active State'
              preprocessing:
                -
                  type: JSONPATH
                  parameters:
                    - $.Type
                -
                  type: DISCARD_UNCHANGED_HEARTBEAT
                  parameters:
                    - 30m
              master_item:
                key: 'systemd.unit.get["{#UNIT.NAME}",Service]'
              tags:
                -
                  tag: component
                  value: service
            -
              uuid: 8cfd0a6c9410476eb27a322b2d401ba9
              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: component
                  value: service
            -
              uuid: 7caeb1a0760f49cf8334fd701b03e6c4
              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: component
                  value: service
              trigger_prototypes:
                -
                  uuid: 3a240fadc7fc4a82840bde86e7dbf02a
                  expression: 'last(/Systemd by Zabbix agent 2 active/systemd.service.uptime["{#UNIT.NAME}"])<10m'
                  name: '{#UNIT.NAME}: has been restarted'
                  event_name: '{#UNIT.NAME}: has been restarted (uptime < 10m)'
                  priority: INFO
                  description: 'Uptime is less than 10 minutes.'
                  manual_close: 'YES'
                  tags:
                    -
                      tag: scope
                      value: notice
            -
              uuid: ced57ba82dc84dacbb6d22862c6d89df
              name: '{#UNIT.NAME}: Get service info'
              type: ZABBIX_ACTIVE
              key: 'systemd.unit.get["{#UNIT.NAME}",Service]'
              history: '0'
              trends: '0'
              value_type: TEXT
              description: |
                Returns all service properties of a systemd service unit.
                 Unit description: {#UNIT.DESCRIPTION}.
              tags:
                -
                  tag: component
                  value: raw
                -
                  tag: component
                  value: service
            -
              uuid: 6136fc4c769d43b19e1db446977f9845
              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: component
                  value: raw
                -
                  tag: component
                  value: unit
          trigger_prototypes:
            -
              uuid: 8354ace53761436f92807f4370e32d33
              expression: 'last(/Systemd by Zabbix agent 2 active/systemd.service.active_state["{#UNIT.NAME}"])<>1 and last(/Systemd by Zabbix agent 2 active/systemd.service.type["{#UNIT.NAME}"])<>"oneshot" and last(/Systemd by Zabbix agent 2 active/systemd.service.type["{#UNIT.NAME}"])<>"dbus" and last(/Systemd by Zabbix agent 2 active/systemd.service.unitfile_state["{#UNIT.NAME}"])=1'
              name: '{#UNIT.NAME}: Service is not running'
              priority: WARNING
              tags:
                -
                  tag: scope
                  value: availability
            -
              uuid: b27577edf12047ebb0939220f1415578
              expression: 'last(/Systemd by Zabbix agent 2 active/systemd.service.active_state["{#UNIT.NAME}"])=1 and last(/Systemd by Zabbix agent 2 active/systemd.service.type["{#UNIT.NAME}"])<>"oneshot" and last(/Systemd by Zabbix agent 2 active/systemd.service.unitfile_state["{#UNIT.NAME}"])=8'
              name: '{#UNIT.NAME}: Service is running but not enabled'
              priority: INFO
              tags:
                -
                  tag: scope
                  value: availability
        -
          uuid: 11363f5bcd9f42fe96ffc9c23482152f
          name: 'Socket units discovery'
          type: ZABBIX_ACTIVE
          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: 7afa4138a8bd4e7fac23be75e0e7630b
              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: component
                  value: socket
            -
              uuid: 90eb5edb617249c1aa95112cea8e9661
              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: component
                  value: socket
            -
              uuid: 67feabc1c6db4de08c456a31538ec1c2
              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: component
                  value: raw
                -
                  tag: component
                  value: socket
      tags:
        -
          tag: class
          value: software
        -
          tag: target
          value: systemd
      macros:
        -
          macro: '{$SYSTEMD.ACTIVESTATE.SERVICE.MATCHES}'
          value: '.*'
          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: '.*'
          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: ^systemd-readahead.+|NetworkManager-dispatcher.+
          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: '.*'
          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: '.*'
          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: c2aceba76da04f76b7b62e127922f938
          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: 7129117305d04ff8bff96c9789c10de6
          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: 7565c23ca5d64e26866cba687c25d52c
          name: 'Unit Load State'
          mappings:
            -
              value: '0'
              newvalue: unknown
            -
              value: '1'
              newvalue: loaded
            -
              value: '2'
              newvalue: error
            -
              value: '3'
              newvalue: masked
