zabbix_export:
  version: '7.0'
  template_groups:
    - uuid: a571c0d144b14fd4a87a9d9b2aa9fcd6
      name: Templates/Applications
  templates:
    - uuid: 2ce384bafd524db5b910d7f55bca1fbb
      template: 'Veeam Backup Enterprise Manager by HTTP'
      name: 'Veeam Backup Enterprise Manager by HTTP'
      description: |
        This template is designed to monitor Veeam Backup Enterprise Manager.
        
        NOTE: The REST API may not be available for some editions, see (https://www.veeam.com/licensing-pricing.html) for more details.
        
        Setup:
          1. Create a user to monitor the service, or use an existing read-only account.
             Similarly to the user authentication in the Veeam Backup Enterprise Manager Web UI, 
             the client authentication in the REST API dictates which operations a client is allowed to perform when working with the REST API.
             That is, if the client is authenticated using an account that does not have enough permissions to perform some actions, it will not be able to execute them.
             You can also obtain the collected jobs if you are logged in under an account having only `Portal Administrator` role.
          See (https://helpcenter.veeam.com/docs/backup/em_rest/http_authentication.html?ver=110) for more details.
          2. Link the template to a host.
          3. Configure the following macros: {$VEEAM.MANAGER.API.URL}, {$VEEAM.MANAGER.USER}, {$VEEAM.MANAGER.PASSWORD}.
        
        You can discuss this template or leave feedback on our forum https://www.zabbix.com/forum/zabbix-suggestions-and-feedback/
        
        Generated by official Zabbix template tool "Templator"
      vendor:
        name: Zabbix
        version: 7.0-0
      groups:
        - name: Templates/Applications
      items:
        - uuid: a1b612cd8e274a27a834dbdb69fe7d08
          name: 'Failed Job Runs'
          type: DEPENDENT
          key: veeam.manager.failed.jobs
          description: 'Informs about the failed job runs.'
          preprocessing:
            - type: JSONPATH
              parameters:
                - $.JobStatistics.FailedJobRuns
              error_handler: DISCARD_VALUE
            - type: DISCARD_UNCHANGED_HEARTBEAT
              parameters:
                - 1h
          master_item:
            key: veeam.manager.get.metrics
          tags:
            - tag: component
              value: reports
          triggers:
            - uuid: 4885d43f36b541219be87b5e5ea19088
              expression: 'last(/Veeam Backup Enterprise Manager by HTTP/veeam.manager.failed.jobs)>{$VEEAM.MANAGER.JOB.MAX.FAIL}'
              name: 'Failed job runs is too high'
              event_name: 'Failed job runs is too high (over {$VEEAM.MANAGER.JOB.MAX.FAIL})'
              priority: AVERAGE
              manual_close: 'YES'
              tags:
                - tag: scope
                  value: availability
        - uuid: e698c05dae9f4d2f8323ce718e9ed83b
          name: 'Get errors'
          type: DEPENDENT
          key: veeam.manager.get.errors
          value_type: TEXT
          description: 'The errors from API requests.'
          preprocessing:
            - type: JSONPATH
              parameters:
                - $.error
              error_handler: CUSTOM_VALUE
            - type: DISCARD_UNCHANGED_HEARTBEAT
              parameters:
                - 1h
          master_item:
            key: veeam.manager.get.metrics
          tags:
            - tag: component
              value: status
          triggers:
            - uuid: 83316e2168414042aeb9d98857534baa
              expression: 'length(last(/Veeam Backup Enterprise Manager by HTTP/veeam.manager.get.errors))>0'
              name: 'There are errors in requests to API'
              opdata: '{ITEM.LASTVALUE1}'
              priority: AVERAGE
              description: 'Zabbix has received errors in response to API requests.'
              tags:
                - tag: scope
                  value: availability
        - uuid: 525a61ff4fb747efab6ac58d1ac8b7c4
          name: 'Get metrics'
          type: SCRIPT
          key: veeam.manager.get.metrics
          delay: 5m
          history: '0'
          value_type: TEXT
          params: |
            var Veeam = {
            	params: {},
            
            	setParams: function (params) {
            		['api_endpoint', 'user', 'password'].forEach(function (field) {
            			if (typeof params !== 'object' || typeof params[field] === 'undefined' || params[field] === '') {
            				throw 'Required param is not set: ' + field + '.';
            			}
            		});
            
            		Veeam.params = params;
            		if (typeof Veeam.params.api_endpoint === 'string' && !Veeam.params.api_endpoint.endsWith('/')) {
            			Veeam.params.api_endpoint += '/';
            		}
            	},
            
            	request: function (url) {
            		var response, request = new HttpRequest();
            		if (typeof Veeam.params.http_proxy !== 'undefined' && Veeam.params.http_proxy !== '') {
            			request.setProxy(Veeam.params.http_proxy);
            		}
            		request.addHeader('Accept: application/json');
            		request.addHeader('Authorization: Basic ' + btoa(Veeam.params.user + ':' + Veeam.params.password));
            		request.post(Veeam.params.api_endpoint + 'api/sessionMngr');
            		response = request.get(url);
            		if (request.getStatus() !== 200 || response === null) {
            			throw 'Request failed with status code ' + request.getStatus() + ': ' + response;
            		}
            		try {
            			return JSON.parse(response);
            		}
            		catch (error) {
            			throw 'Failed to parse response received from API.';
            		}
            	},
            
            	getMetricsData: function() {
            		var data = {};
            		endpoints = {
            			'backupFiles': 'api/backupFiles',
            		};
            		reports_summary = Veeam.request(Veeam.params.api_endpoint + 'api/reports/summary')
            		if (typeof reports_summary !== 'object' || reports_summary.hasOwnProperty('Links') === false)
            			throw 'Failed response parse. Check debug log for more information.';
            		reports_summary.Links.forEach(function (field)  {
            				data[field.Name] = Veeam.request(field.Href)
            			})
            		Object.keys(endpoints).forEach(function (key) {
            			data[key] = Veeam.request(Veeam.params.api_endpoint + endpoints[key]);
            			if (typeof data[key] !== 'object' || data[key].hasOwnProperty('Refs') === false)
            				throw 'Failed response parse. Check debug log for more information.';
            			data[key].Refs.forEach(function (field) {
            				data[field.Name] = Veeam.request(field.Href)
            			})		
            		})
            		return data;
            	}
            
            };
            try {
            	Veeam.setParams(JSON.parse(value));
            	return JSON.stringify(Veeam.getMetricsData());
            }
            catch (error) {
            	error += (String(error).endsWith('.')) ? '' : '.';
            	Zabbix.log(3, '[ VEEAM MANAGER ] ERROR: ' + error);
            	return JSON.stringify({'error': error});
            }
          description: 'The result of API requests is expressed in the JSON.'
          timeout: '{$VEEAM.MANAGER.DATA.TIMEOUT}'
          parameters:
            - name: api_endpoint
              value: '{$VEEAM.MANAGER.API.URL}'
            - name: http_proxy
              value: '{$VEEAM.MANAGER.HTTP.PROXY}'
            - name: password
              value: '{$VEEAM.MANAGER.PASSWORD}'
            - name: user
              value: '{$VEEAM.MANAGER.USER}'
          tags:
            - tag: component
              value: raw
        - uuid: a0a1e67c99c64bd1a801c87eeda3977b
          name: 'Running Jobs'
          type: DEPENDENT
          key: veeam.manager.running.jobs
          description: 'Informs about the running jobs.'
          preprocessing:
            - type: JSONPATH
              parameters:
                - $.JobStatistics.RunningJobs
              error_handler: DISCARD_VALUE
            - type: DISCARD_UNCHANGED_HEARTBEAT
              parameters:
                - 1h
          master_item:
            key: veeam.manager.get.metrics
          tags:
            - tag: component
              value: reports
        - uuid: d7510e46c6094e09979ea7dad2828cef
          name: 'Scheduled Backup Jobs'
          type: DEPENDENT
          key: veeam.manager.scheduled.backup.jobs
          description: 'Informs about the scheduled backup jobs.'
          preprocessing:
            - type: JSONPATH
              parameters:
                - $.JobStatistics.ScheduledBackupJobs
              error_handler: DISCARD_VALUE
            - type: DISCARD_UNCHANGED_HEARTBEAT
              parameters:
                - 1h
          master_item:
            key: veeam.manager.get.metrics
          tags:
            - tag: component
              value: reports
        - uuid: de9f62198b5b42cdb25460315f4af949
          name: 'Scheduled Jobs'
          type: DEPENDENT
          key: veeam.manager.scheduled.jobs
          description: 'Informs about the scheduled jobs.'
          preprocessing:
            - type: JSONPATH
              parameters:
                - $.JobStatistics.ScheduledJobs
              error_handler: DISCARD_VALUE
            - type: DISCARD_UNCHANGED_HEARTBEAT
              parameters:
                - 1h
          master_item:
            key: veeam.manager.get.metrics
          tags:
            - tag: component
              value: reports
        - uuid: 599a25d753ce4f5d8542d08569f2a136
          name: 'Scheduled Replica Jobs'
          type: DEPENDENT
          key: veeam.manager.scheduled.replica.jobs
          description: 'Informs about the scheduled replica jobs.'
          preprocessing:
            - type: JSONPATH
              parameters:
                - $.JobStatistics.ScheduledReplicaJobs
              error_handler: DISCARD_VALUE
            - type: DISCARD_UNCHANGED_HEARTBEAT
              parameters:
                - 1h
          master_item:
            key: veeam.manager.get.metrics
          tags:
            - tag: component
              value: reports
        - uuid: 7d96ebb849c94d5b89656bdfa6398a1d
          name: 'Total Job Runs'
          type: DEPENDENT
          key: veeam.manager.scheduled.total.jobs
          description: 'Informs about the total job runs.'
          preprocessing:
            - type: JSONPATH
              parameters:
                - $.JobStatistics.TotalJobRuns
              error_handler: DISCARD_VALUE
            - type: DISCARD_UNCHANGED_HEARTBEAT
              parameters:
                - 1h
          master_item:
            key: veeam.manager.get.metrics
          tags:
            - tag: component
              value: reports
        - uuid: b39d33c9d5c544a2996736dbdccfcaff
          name: 'Warnings Job Runs'
          type: DEPENDENT
          key: veeam.manager.warning.jobs
          description: 'Informs about the warning job runs.'
          preprocessing:
            - type: JSONPATH
              parameters:
                - $.JobStatistics.WarningsJobRuns
              error_handler: DISCARD_VALUE
            - type: DISCARD_UNCHANGED_HEARTBEAT
              parameters:
                - 1h
          master_item:
            key: veeam.manager.get.metrics
          tags:
            - tag: component
              value: reports
          triggers:
            - uuid: f65998e99bb24e02a2810b632a4a3f4e
              expression: 'last(/Veeam Backup Enterprise Manager by HTTP/veeam.manager.warning.jobs)>{$VEEAM.MANAGER.JOB.MAX.WARN}'
              name: 'Warning job runs is too high'
              event_name: 'Warning job runs is too high (over {$VEEAM.MANAGER.JOB.MAX.WARN})'
              priority: WARNING
              manual_close: 'YES'
              tags:
                - tag: scope
                  value: availability
      discovery_rules:
        - uuid: d07b06fbd84d493bb38d61ac0824e794
          name: 'Backup Files discovery'
          type: DEPENDENT
          key: veeam.backup.files.discovery
          filter:
            evaltype: AND
            conditions:
              - macro: '{#NAME}'
                value: '{$BACKUP.NAME.MATCHES}'
              - macro: '{#NAME}'
                value: '{$BACKUP.NAME.NOT_MATCHES}'
                operator: NOT_MATCHES_REGEX
              - macro: '{#TYPE}'
                value: '{$BACKUP.TYPE.MATCHES}'
              - macro: '{#TYPE}'
                value: '{$BACKUP.TYPE.NOT_MATCHES}'
                operator: NOT_MATCHES_REGEX
          description: 'Discovery of all backup files created on, or imported to the backup servers that are connected to Veeam Backup Enterprise Manager.'
          item_prototypes:
            - uuid: d3f87401602c48d3a837504ed08902db
              name: 'Compression ratio [{#NAME}]'
              type: DEPENDENT
              key: 'veeam.backup.compress.ratio[{#NAME}]'
              description: 'Gets the data compression ratio with the name `[{#NAME}]`.'
              preprocessing:
                - type: JSONPATH
                  parameters:
                    - '$.[''{#NAME}''].BackupFile.CompressRatio'
                  error_handler: DISCARD_VALUE
              master_item:
                key: veeam.manager.get.metrics
              tags:
                - tag: backup
                  value: '{#NAME}'
                - tag: component
                  value: backups
            - uuid: 0c5be137b40949c4946a09c57ccc7796
              name: 'Data Size [{#NAME}]'
              type: DEPENDENT
              key: 'veeam.backup.data.size[{#NAME}]'
              value_type: FLOAT
              units: B
              description: 'Gets the data size with the name `[{#NAME}]`.'
              preprocessing:
                - type: JSONPATH
                  parameters:
                    - '$.[''{#NAME}''].BackupFile.DataSize'
                  error_handler: DISCARD_VALUE
              master_item:
                key: veeam.manager.get.metrics
              tags:
                - tag: backup
                  value: '{#NAME}'
                - tag: component
                  value: backups
            - uuid: 62d0b0341bac40f9a63f0fbf3639e0d0
              name: 'Deduplication Ratio [{#NAME}]'
              type: DEPENDENT
              key: 'veeam.backup.deduplication.ratio[{#NAME}]'
              description: 'Gets the data deduplication ratio with the name `[{#NAME}]`.'
              preprocessing:
                - type: JSONPATH
                  parameters:
                    - '$.[''{#NAME}''].BackupFile.DeduplicationRatio'
                  error_handler: DISCARD_VALUE
              master_item:
                key: veeam.manager.get.metrics
              tags:
                - tag: backup
                  value: '{#NAME}'
                - tag: component
                  value: backups
            - uuid: 098cc39afb88483f93a98c96fc1450d1
              name: 'Backup Size [{#NAME}]'
              type: DEPENDENT
              key: 'veeam.backup.file.size[{#NAME}]'
              value_type: FLOAT
              units: B
              description: 'Gets the backup size with the name `[{#NAME}]`.'
              preprocessing:
                - type: JSONPATH
                  parameters:
                    - '$.[''{#NAME}''].BackupFile.BackupSize'
                  error_handler: DISCARD_VALUE
              master_item:
                key: veeam.manager.get.metrics
              tags:
                - tag: backup
                  value: '{#NAME}'
                - tag: component
                  value: backups
          master_item:
            key: veeam.manager.get.metrics
          lld_macro_paths:
            - lld_macro: '{#NAME}'
              path: $.Name
            - lld_macro: '{#TYPE}'
              path: $.Type
            - lld_macro: '{#UID}'
              path: $.UID
            - lld_macro: '{#URL}'
              path: $.Href
          preprocessing:
            - type: JSONPATH
              parameters:
                - $.backupFiles.Refs
            - type: DISCARD_UNCHANGED_HEARTBEAT
              parameters:
                - 6h
      tags:
        - tag: class
          value: software
        - tag: target
          value: veeam
      macros:
        - macro: '{$BACKUP.NAME.MATCHES}'
          value: '.*'
          description: 'This macro is used in backup discovery rule.'
        - macro: '{$BACKUP.NAME.NOT_MATCHES}'
          value: CHANGE_IF_NEEDED
          description: 'This macro is used in backup discovery rule.'
        - macro: '{$BACKUP.TYPE.MATCHES}'
          value: '.*'
          description: 'This macro is used in backup discovery rule.'
        - macro: '{$BACKUP.TYPE.NOT_MATCHES}'
          value: CHANGE_IF_NEEDED
          description: 'This macro is used in backup discovery rule.'
        - macro: '{$VEEAM.MANAGER.API.URL}'
          value: 'https://localhost:9398'
          description: 'Veeam Backup Enterprise Manager API endpoint is a URL in the format: `<scheme>://<host>:<port>`.'
        - macro: '{$VEEAM.MANAGER.DATA.TIMEOUT}'
          value: '10'
          description: 'A response timeout for API.'
        - macro: '{$VEEAM.MANAGER.HTTP.PROXY}'
          description: 'Sets the HTTP proxy to `http_proxy` value. If this parameter is empty, then no proxy is used.'
        - macro: '{$VEEAM.MANAGER.JOB.MAX.FAIL}'
          value: '5'
          description: 'The maximum score of failed jobs (for a trigger expression).'
        - macro: '{$VEEAM.MANAGER.JOB.MAX.WARN}'
          value: '10'
          description: 'The maximum score of warning jobs (for a trigger expression).'
        - macro: '{$VEEAM.MANAGER.PASSWORD}'
          type: SECRET_TEXT
          description: 'The `password` of the Veeam Backup Enterprise Manager account.'
        - macro: '{$VEEAM.MANAGER.USER}'
          type: SECRET_TEXT
          description: 'The `user name` of the Veeam Backup Enterprise Manager account .'
