Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Biba <andrew.biba@zabbix.com>2022-02-18 16:33:26 +0300
committerAndrew Biba <andrew.biba@zabbix.com>2022-02-18 16:33:26 +0300
commite854d46334896294cce93a1a78c7e428096a83d9 (patch)
tree12b66658c61d211fd1470c2c1e9e03d026bae8ac /templates
parent57c0c6bd0dc7024ebbe1488cb3aaae04d938157f (diff)
parent88d0236d5126d8e9bebc4ff9207749c85d65b7d8 (diff)
.........T [ZBX-20443] fixed requirement of admin rights for creating issues with custom fields and added option to close tasks in Redmine webhook
* commit '88d0236d5126d8e9bebc4ff9207749c85d65b7d8': .........T [ZBX-20443] fixed requirement of admin rights for creating issues with custom fields and added option to close tasks in Redmine webhook
Diffstat (limited to 'templates')
-rw-r--r--templates/media/redmine/README.md16
-rw-r--r--templates/media/redmine/media_redmine.yaml81
2 files changed, 37 insertions, 60 deletions
diff --git a/templates/media/redmine/README.md b/templates/media/redmine/README.md
index 9e06a787a3c..d8cfe958fa0 100644
--- a/templates/media/redmine/README.md
+++ b/templates/media/redmine/README.md
@@ -2,12 +2,12 @@
# Redmine webhook
![](images/redmine_logo_v1.png?raw=true)
-This guide describes how to integrate your Zabbix 5.4 installation with Redmine using the Zabbix webhook feature. This guide will provide instructions on setting up a media type, a user and an action in Zabbix.
+This guide describes how to integrate your Zabbix 6.0 installation with Redmine using the Zabbix webhook feature. This guide will provide instructions on setting up a media type, a user and an action in Zabbix.
## Requirements
- Redmine with enabled REST API and Authentication
-- Zabbix version 5.4 or higher
+- Zabbix version 6.0 or higher
## Setting up a Redmine
@@ -39,17 +39,19 @@ You can find Project ID on *http://&lt;YOR_REDMINE_URL&gt;/projects.xml*
[![](images/thumb.05.png?raw=true)](images/05.png)
-4\. If you have **custom fields** in **Redmine** and you want them to be filled in with values from Zabbix, add parameters in the form **customfield_\<Redmine custom field ID\>**. Custom fields can only be of the **text**, **integer**, **float** or **date** types. Custom fields of **date** type must be in the format "YYYY-MM-DD".
+4\. If you want to close issues on trigger resolve, add parameter **redmine_close_status_id** with close Status ID as value. (Status with "Issue closed" tick)
-5\. If you want to prioritize issues according to **severity** values in Zabbix, you can define mapping parameters:
+5\. If you have **custom fields** in **Redmine** and you want them to be filled in with values from Zabbix, add parameters in the form **customfield_\<Redmine custom field ID\>**. Custom fields can only be of the **text**, **integer**, **float** or **date** types. Custom fields of **date** type must be in the format "YYYY-MM-DD".
+
+6\. If you want to prioritize issues according to **severity** values in Zabbix, you can define mapping parameters:
- **severity_\<name\>**: Redmine priority ID
[![](images/thumb.07.png?raw=true)](images/07.png)
-6\. Click the **Update** button to save the **Webhook** settings.
+7\. Click the **Update** button to save the **Webhook** settings.
-7\. To receive notifications in **Redmine**, you need to create a **Zabbix user** and add **Media** with the **Redmine** type.
+8\. To receive notifications in **Redmine**, you need to create a **Zabbix user** and add **Media** with the **Redmine** type.
For **Send to**: enter any text, as this value is not used, but is required.
@@ -59,4 +61,4 @@ For more information, use the [Zabbix](https://www.zabbix.com/documentation/6.0/
## Supported Versions
-Zabbix 5.4
+Zabbix 6.0
diff --git a/templates/media/redmine/media_redmine.yaml b/templates/media/redmine/media_redmine.yaml
index e1b15917143..d9410696353 100644
--- a/templates/media/redmine/media_redmine.yaml
+++ b/templates/media/redmine/media_redmine.yaml
@@ -1,6 +1,6 @@
zabbix_export:
- version: '5.4'
- date: '2020-10-16T09:33:50Z'
+ version: '6.0'
+ date: '2022-02-03T16:00:17Z'
media_types:
-
name: Redmine
@@ -70,51 +70,18 @@ zabbix_export:
addCustomFields: function (data, fields) {
if (typeof fields === 'object' && Object.keys(fields).length) {
- var schema = Redmine.getSchema();
-
- if (schema) {
- data.issue.custom_fields = [];
-
- Object.keys(fields)
- .forEach(function(field) {
- for (var idx in schema.custom_fields) {
- if (schema.custom_fields[idx].id != field) {
- continue;
- }
-
- var field_value;
-
- switch (schema.custom_fields[idx].field_format) {
- case 'string':
- field_value = fields[field];
- break;
-
- case 'int':
- field_value = parseInt(fields[field]);
- break;
-
- case 'float':
- field_value = parseFloat(fields[field]);
- break;
-
- case 'date':
- if (fields[field].match(/^\d{4}[.-]\d{2}[.-]\d{2}$/)) {
- field_value = fields[field].replace(/\./g, '-');
- }
- break;
- }
-
- if (field_value !== undefined) {
- data.issue.custom_fields.push({id: field, value: field_value});
- }
- }
- });
- }
- else {
- Zabbix.log(4, '[ Redmine Webhook ] Failed to retrieve field schema.');
- }
- }
+ data.issue.custom_fields = [];
+ Object.keys(fields)
+ .forEach(function (field) {
+ var field_value = fields[field];
+
+ if (field_value !== undefined) {
+ data.issue.custom_fields.push({ id: field, value: field_value });
+ }
+ });
+
+ }
return data;
},
@@ -219,12 +186,6 @@ zabbix_export:
return project_id;
},
- getSchema: function() {
- var result = Redmine.request('get', 'custom_fields.json');
-
- return result.response;
- },
-
createIssue: function(subject, description, priority, fields) {
var project_id = /^\d+$/.test(Redmine.params.project)
? Redmine.params.project
@@ -254,15 +215,20 @@ zabbix_export:
return result.response.issue.id;
},
- updateIssue: function(note, fields) {
+ updateIssue: function (note, fields, status) {
var data = {
issue: {
notes: note || ''
}
};
+ if (status) {
+ data.issue.status_id = status;
+ }
+
Redmine.request('put', 'issues/' + Redmine.params.issue_key + '.json', Redmine.addCustomFields(data, fields));
}
+
};
try {
@@ -318,6 +284,11 @@ zabbix_export:
throw 'Incorrect "event_update_status" parameter given: ' + params.event_update_status + '\nMust be 0 or 1.';
}
+
+ if (typeof params_redmine.close_status_id === 'string' && params_redmine.close_status_id.trim() !== '' && !parseInt(params_redmine.close_status_id, 10)) {
+ throw 'Incorrect "redmine_close_status_id" parameter given! Must be an integer.';
+ }
+
if (params.event_source !== '0' && params.event_value === '0') {
throw 'Recovery operations are supported only for trigger-based actions.';
}
@@ -363,6 +334,10 @@ zabbix_export:
result.tags.__zbx_redmine_issuelink = params.redmine_url +
(params.redmine_url.endsWith('/') ? '' : '/') + 'issues/' + issue_id;
}
+ // Close issue if parameter close_status_id is set and it is a recovery operation
+ else if (params.event_value === '0' && typeof params_redmine.close_status_id === 'string' && params_redmine.close_status_id.trim() !== '') {
+ Redmine.updateIssue(params.alert_subject + '\n' + params.alert_message, params_fields, params_redmine.close_status_id);
+ }
// Update created issue for trigger-based event.
else {
Redmine.updateIssue(params.alert_subject + '\n' + params.alert_message, params_fields);