function update_host($hostid, $host, $port, $status, $useip, $dns, $ip, $proxy_hostid, $templates, $useipmi, $ipmi_ip, $ipmi_port, $ipmi_authtype, $ipmi_privilege, $ipmi_username, $ipmi_password, $newgroup, $groups) { $old_templates = get_templates_by_hostid($hostid); $unlinked_templates = array_diff($old_templates, $templates); foreach ($unlinked_templates as $id => $name) { unlink_template($hostid, $id); } $new_templates = array_diff($templates, $old_templates); $result = (bool) db_save_host($host, $port, $status, $useip, $dns, $ip, $proxy_hostid, $new_templates, $useipmi, $ipmi_ip, $ipmi_port, $ipmi_authtype, $ipmi_privilege, $ipmi_username, $ipmi_password, $hostid); if (!$result) { return $result; } update_host_groups($hostid, $groups); add_group_to_host($hostid, $newgroup); if (count($new_templates) > 0) { sync_host_with_templates($hostid, array_keys($new_templates)); } return $result; }
function update_host($hostid, $host, $port, $status, $useip, $dns, $ip, $proxy_hostid, $templates, $useipmi, $ipmi_ip, $ipmi_port, $ipmi_authtype, $ipmi_privilege, $ipmi_username, $ipmi_password, $newgroup, $groups) { if (zbx_empty($newgroup) && count($groups) == 0) { info('Host "' . $host . '" must be linked to at least one host group'); return false; } if (is_null($templates)) { $new_templates = array(); } else { $old_templates = get_templates_by_hostid($hostid); $new_templates = array_diff($templates, $old_templates); $unlinked_templates = array_diff($old_templates, $templates); foreach ($unlinked_templates as $id => $name) { unlink_template($hostid, $id); } } $result = (bool) db_save_host($host, $port, $status, $useip, $dns, $ip, $proxy_hostid, $new_templates, $useipmi, $ipmi_ip, $ipmi_port, $ipmi_authtype, $ipmi_privilege, $ipmi_username, $ipmi_password, $hostid); if (!$result) { return $result; } if (!is_null($groups)) { update_host_groups($hostid, $groups); } add_group_to_host($hostid, $newgroup); if (count($new_templates) > 0) { sync_host_with_templates($hostid, array_keys($new_templates)); } return $result; }