template.update
Описание
object template.update(объект/массив templates)
Этот метод позволяет обновлять существующие шаблоны.
Этот метод доступен только пользователям с типом доступа Администратор и Супер-администратор. Разрешения на вызов метода можно отозвать в настройках ролей пользователя. Дополнительную информацию см. в разделе Роли пользователей.
Параметры
(объект/массив) Свойства шаблонов, которые будут обновлены.
Свойство templateid должно быть указано по каждому шаблону, все
остальные свойства опциональны. Будут обновлены только переданные
свойства, все остальные останутся неизменными.
В дополнение к стандартным свойствам шаблона, этот метод принимает следующие параметры.
| Параметр | Тип | Описание |
|---|---|---|
| groups | объект/массив | Группы узлов сети, которые заменят текущие группы узлов сети в которые входят шаблоны. У групп узлов сети должно быть задано свойство groupid. |
| hosts | объект/массив | Узлы сети и шаблоны, которые заменят текущие присоединенные узлы сети и шаблоны. Как у узлов сети, так и у шаблонов, чтобы указать ID, необходимо использовать свойство hostid. |
| macros | объект/массив | Пользовательские макросы, которые заменят текущие макросы у заданных шаблонов. |
| templates | объект/массив | Шаблоны, которые заменят текущие присоединенные шаблоны. Шаблоны, которые не указаны, будут только отсоединены. У шаблонов должно быть задано свойство templateid. |
| templates_clear | объект/массив | Шаблоны, которые необходимо отсоединить и очистить от заданных шаблонов. У шаблонов должно быть задано свойство templateid. |
Возвращаемые значения
(объект) Возвращает объект, который содержит ID обновленных шаблонов,
указанных в свойстве templateids.
Примеры
Changing the standard template properties
Change the technical name of the template to "Linux by Zabbix agent Custom", the visible name to "My template", and update the template description.
Request:
{
"jsonrpc": "2.0",
"method": "template.update",
"params": {
"templateid": "10086",
"host": "Linux by Zabbix agent Custom",
"name": "My template",
"description": "This is a custom Linux template."
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Response:
{
"jsonrpc": "2.0",
"result": {
"templateids": [
"10086"
]
},
"id": 1
}
Updating template groups
Replace all template groups for the given template with a different one.
Request:
{
"jsonrpc": "2.0",
"method": "template.update",
"params": {
"templateid": "10086",
"groups": [
{
"groupid": "24"
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Response:
{
"jsonrpc": "2.0",
"result": {
"templateids": [
"10086"
]
},
"id": 1
}
Updating template tags
Replace all template tags with a different one.
Request:
{
"jsonrpc": "2.0",
"method": "template.update",
"params": {
"templateid": "10086",
"tags": [
{
"tag": "Host name",
"value": "{HOST.NAME}"
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Response:
{
"jsonrpc": "2.0",
"result": {
"templateids": [
"10086"
]
},
"id": 1
}
Updating template macros
Replace all template macros with a different one.
Request:
{
"jsonrpc": "2.0",
"method": "template.update",
"params": {
"templateid": "10086",
"macros": [
{
"macro": "{$MY_MACRO}",
"value": "new_value"
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Response:
{
"jsonrpc": "2.0",
"result": {
"templateids": [
"10086"
]
},
"id": 1
}
Updating template linked templates
Unlink (without clearing) all templates from the given template and link a different one to it.
Request:
{
"jsonrpc": "2.0",
"method": "template.update",
"params": {
"templateid": "10086",
"templates": [
{
"templateid": "10087"
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Response:
{
"jsonrpc": "2.0",
"result": {
"templateids": [
"10086"
]
},
"id": 1
}
Clearing template linked templates
Unlink and clear the given template from a specific linked template.
Request:
{
"jsonrpc": "2.0",
"method": "template.update",
"params": {
"templateid": "10086",
"templates_clear": [
{
"templateid": "10087"
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Response:
{
"jsonrpc": "2.0",
"result": {
"templateids": [
"10086"
]
},
"id": 1
}
Источник
CTemplate::update() в ui/include/classes/api/services/CTemplate.php.