See www.zabbix.com for the official Zabbix site.

Docs/specs/ZBX-8800

From Zabbix.org
Jump to: navigation, search

Action operation order

ZBX-8800

Status: Initial draft, do not comment

Owner: Gunārs Pujāts

Summary

Action operations are sorted by type as defined in include/defines.inc.php. This ordering is not only visual - it is also the order in which they are inserted into the database. Due to this you cannot, for example, add a discovered host and execute a remote command on it, because at that point, the host doesn't exist.

Also it is possible to create conflicting operations, e.g., "Enable host" and "Disable host", or "Remove host" and "Enable host".

To solve this, each operation should have "sortorder" value, and frontend should validate operations and throw an error when operations have conflicts.

Specification

Operations order

Operations must be saved in DB and displayed in order as those were created. Operations can be reordered using drag&drop functionality in action operations form. For greater clarity rename operation "Add host" to "Create host".

Validation

If action has operations:

  • "Enable host" and "Disable host",
  • "Remove host" and any other operation except "Send message" and "Remote command",

then throw error, e.g.,:

'Conflicting operations "Remove host" and "Enable host".'

if ($operation1['operationtype'] == OPERATION_TYPE_HOST_REMOVE && $operation2['operationtype'] == OPERATION_TYPE_HOST_ENABLE) {
	self::exception(
		ZBX_API_ERROR_PARAMETERS,
		_s(
			'Conflicting operations "%1$s" and "%2$s".',
			_('Remove host'),
			_('Enable host')
		)
	);
}


If action has operations "Add to host group" and "Remove from host group", then check if those have different groups specified, otherwise throw error:

"Conflicting operations "Add to host group" and "Remove from host group" with the same host group name."

if ($operation1['operationtype'] == OPERATION_TYPE_GROUP_ADD
		&& $operation2['operationtype'] == OPERATION_TYPE_GROUP_REMOVE
		&& array_intersect($operation1['groupids'], $operation2['groupids'])) {
	self::exception(
		ZBX_API_ERROR_PARAMETERS,
		_s(
			'Conflicting operations "%1$s" and "%2$s" with the same host group name.',
			_('Add to host group'),
			_('Remove from host group')
		)
	);
}


If action has operations "Link to template" and "Unlink from template", then check if those have no common templates specified, otherwise throw error:

"Conflicting operations "Link to template" and "Unlink from template" with the same template name."

if ($operation1['operationtype'] == OPERATION_TYPE_TEMPLATE_ADD
		&& $operation2['operationtype'] == OPERATION_TYPE_TEMPLATE_REMOVE
		&& array_intersect($operation1['templateids'], $operation2['templateids'])) {
	self::exception(
		ZBX_API_ERROR_PARAMETERS,
		_s(
			'Conflicting operations "%1$s" and "%2$s" with the same template name.',
			_('Add to host group'),
			_('Remove from host group')
		)
	);
}


Validation rules
1 2 3 4 5 6 7 8 9 10 11
1 Send message
2 Remote command
3 Create host X
4 Remove host X X X X X X X X
5 Add to host group X C1
6 Remove from host group X C1
7 Link to template X C2
8 Unlink from template X C2
9 Enable host X X
10 Disable host X X
11 Set host inventory mode X
  • X – throw an error: 'Conflicting operations "..." and "...".'
  • C1 – check if both operations have no common groups.
  • C2 – check if both operations have no common templates.

Translation strings

Added new translation strings

  • Conflicting operations \"%1$s\" and \"%2$s\".
  • Conflicting operations \"%1$s\" and \"%2$s\" with the same template name.
  • Conflicting operations \"%1$s\" and \"%2$s\" with the same host group name.


Removed translation strings

  • Add host

Database changes

A new field must be added to table operations:

FIELD		|sortorder	|t_integer	|'0'	|NOT NULL	|0