Example #1
0
 /**
  * Update Host's HostGroups with new HostGroups (rewrite) 
  *
  * {@source}
  * @access public
  * @static
  * @since 1.8
  * @version 1
  *
  * @static
  * @param string $hostid
  * @param array $groupids
  * @return boolean
  */
 public static function updateGroupsToHost($data)
 {
     $hostid = $data['hostid'];
     $groupids = $data['groupids'];
     $result = update_host_groups($hostid, $groupids);
     if ($result) {
         return true;
     } else {
         self::$error = array('error' => ZBX_API_ERROR_INTERNAL, 'data' => 'Internal zabbix error');
         return false;
     }
 }
Example #2
0
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;
}
Example #3
0
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;
}