Ejemplo n.º 1
0
function check_circle_host_link($hostid, $templates)
{
    if (count($templates) == 0) {
        return false;
    }
    if (isset($templates[$hostid])) {
        return true;
    }
    foreach ($templates as $id => $name) {
        if (check_circle_host_link($hostid, get_templates_by_hostid($id))) {
            return true;
        }
    }
    return false;
}
Ejemplo n.º 2
0
function db_save_host($host, $port, $status, $useip, $dns, $ip, $proxy_hostid, $templates, $useipmi, $ipmi_ip, $ipmi_port, $ipmi_authtype, $ipmi_privilege, $ipmi_username, $ipmi_password, $hostid = null)
{
    if (!eregi('^' . ZBX_EREG_HOST_FORMAT . '$', $host)) {
        error("Incorrect characters used for Hostname");
        return false;
    }
    if (!empty($dns) && !eregi('^' . ZBX_EREG_DNS_FORMAT . '$', $dns)) {
        error("Incorrect characters used for DNS");
        return false;
    }
    if (DBfetch(DBselect('SELECT h.host ' . ' FROM hosts h ' . ' WHERE h.host=' . zbx_dbstr($host) . ' AND ' . DBin_node('h.hostid', get_current_nodeid(false)) . ' AND status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ',' . HOST_STATUS_TEMPLATE . ')' . (isset($hostid) ? ' AND h.hostid<>' . $hostid : '')))) {
        error("Host '{$host}' already exists");
        return false;
    }
    if (is_null($hostid)) {
        $hostid = get_dbid('hosts', 'hostid');
        $result = DBexecute('INSERT INTO hosts ' . ' (hostid,proxy_hostid,host,port,status,useip,dns,ip,disable_until,available,useipmi,ipmi_port,ipmi_authtype,ipmi_privilege,ipmi_username,ipmi_password,ipmi_ip) ' . ' VALUES (' . $hostid . ',' . $proxy_hostid . ',' . zbx_dbstr($host) . ',' . $port . ',' . $status . ',' . $useip . ',' . zbx_dbstr($dns) . ',' . zbx_dbstr($ip) . ',0,' . HOST_AVAILABLE_UNKNOWN . ',' . ($useipmi == 'yes' ? 1 : 0) . ',' . $ipmi_port . ',' . $ipmi_authtype . ',' . $ipmi_privilege . ',' . zbx_dbstr($ipmi_username) . ',' . zbx_dbstr($ipmi_password) . ',' . zbx_dbstr($ipmi_ip) . ')');
        if ($result) {
            add_audit_ext(AUDIT_ACTION_ADD, AUDIT_RESOURCE_HOST, $hostid, $host, 'hosts', NULL, NULL);
        }
    } else {
        if (check_circle_host_link($hostid, $templates)) {
            error("Circle link can't be created");
            return false;
        }
        $host_old = get_host_by_hostid($hostid);
        $result = DBexecute('UPDATE hosts SET proxy_hostid=' . $proxy_hostid . ',host=' . zbx_dbstr($host) . ',port=' . $port . ',useip=' . $useip . ',dns=' . zbx_dbstr($dns) . ',ip=' . zbx_dbstr($ip) . ',useipmi=' . ($useipmi == 'yes' ? 1 : 0) . ',ipmi_port=' . $ipmi_port . ',ipmi_authtype=' . $ipmi_authtype . ',ipmi_privilege=' . $ipmi_privilege . ',ipmi_username='******',ipmi_password='******',ipmi_ip=' . zbx_dbstr($ipmi_ip) . ' WHERE hostid=' . $hostid);
        if ($result) {
            $host_new = get_host_by_hostid($hostid);
            add_audit_ext(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_HOST, $hostid, $host_old['host'], 'hosts', $host_old, $host_new);
        }
        update_host_status($hostid, $status);
    }
    foreach ($templates as $id => $name) {
        $hosttemplateid = get_dbid('hosts_templates', 'hosttemplateid');
        if (!($result = DBexecute('INSERT INTO hosts_templates VALUES (' . $hosttemplateid . ',' . $hostid . ',' . $id . ')'))) {
            break;
        }
    }
    if ($result) {
        $result = $hostid;
    }
    return $result;
}