static zbx_ipmi_host_t *init_ipmi_host(const char *ip, int port, int authtype, int privilege, const char *username, const char *password) { const char *__function_name = "init_ipmi_host"; zbx_ipmi_host_t *h; int ret; ipmi_open_option_t options[4]; struct timeval tv; char *addrs[1], *ports[1]; zabbix_log(LOG_LEVEL_DEBUG, "In %s() host:'[%s]:%d'", __function_name, ip, port); h = get_ipmi_host(ip, port, authtype, privilege, username, password); if (NULL != h) { if (1 == h->domain_up) { zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%p", __function_name, h); return h; } } else h = allocate_ipmi_host(ip, port, authtype, privilege, username, password); h->ret = SUCCEED; h->done = 0; addrs[0] = strdup(h->ip); ports[0] = zbx_dsprintf(NULL, "%d", h->port); if (0 != (ret = ipmi_ip_setup_con(addrs, ports, 1, h->authtype == -1 ? (unsigned int)IPMI_AUTHTYPE_DEFAULT : (unsigned int)h->authtype, (unsigned int)h->privilege, h->username, strlen(h->username), h->password, strlen(h->password), os_hnd, NULL, &h->con))) { h->err = zbx_dsprintf(h->err, "Cannot connect to IPMI host [%s]:%d." " ipmi_ip_setup_con() returned error 0x%x", h->ip, h->port, ret); h->ret = NETWORK_ERROR; goto out; } if (0 != (ret = h->con->start_con(h->con))) { h->err = zbx_dsprintf(h->err, "Cannot connect to IPMI host [%s]:%d." " start_con() returned error 0x%x", h->ip, h->port, ret); h->ret = NETWORK_ERROR; goto out; } options[0].option = IPMI_OPEN_OPTION_ALL; options[0].ival = 0; options[1].option = IPMI_OPEN_OPTION_SDRS; /* scan SDRs */ options[1].ival = 1; options[2].option = IPMI_OPEN_OPTION_IPMB_SCAN; /* scan IPMB bus to find out as much as possible */ options[2].ival = 1; options[3].option = IPMI_OPEN_OPTION_LOCAL_ONLY; /* scan only local resources */ options[3].ival = 1; if (0 != (ret = ipmi_open_domain("", &h->con, 1, setup_done, h, domain_up, h, options, ARRSIZE(options), NULL))) { h->err = zbx_dsprintf(h->err, "Cannot connect to IPMI host [%s]:%d. ipmi_open_domain() failed: %s", h->ip, h->port, zbx_strerror(ret)); h->ret = NETWORK_ERROR; goto out; } tv.tv_sec = 10; tv.tv_usec = 0; while (0 == h->done) os_hnd->perform_one_op(os_hnd, &tv); out: zbx_free(addrs[0]); zbx_free(ports[0]); zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%p", __function_name, h); return h; }
static zbx_ipmi_host_t *init_ipmi_host(const char *ip, int port, int authtype, int privilege, const char *username, const char *password) { zbx_ipmi_host_t *h; int ret; ipmi_open_option_t options[2]; struct timeval tv; char *addrs[1], *ports[1]; zabbix_log(LOG_LEVEL_DEBUG, "In init_ipmi_host([%s]:%d)", ip, port); h = get_ipmi_host(ip, port, authtype, privilege, username, password); if (NULL != h) { h->ret = SUCCEED; h->done = 0; if (1 == h->domain_up) return h; } else h = allocate_ipmi_host(ip, port, authtype, privilege, username, password); addrs[0] = strdup(h->ip); ports[0] = zbx_dsprintf(NULL, "%d", h->port); if (0 != (ret = ipmi_ip_setup_con(addrs, ports, 1, h->authtype == -1 ? (unsigned int)(~0) : (unsigned int)h->authtype, (unsigned int)h->privilege, h->username, (unsigned int)strlen(h->username), h->password, (unsigned int)strlen(h->password), os_hnd, NULL, &h->con))) { h->err = zbx_dsprintf(h->err, "Cannot connect to IPMI host [%s]:%d." " ipmi_ip_setup_con() returned error 0x%x", h->ip, h->port, ret); h->ret = NETWORK_ERROR; goto out; } if (0 != (ret = h->con->start_con(h->con))) { h->err = zbx_dsprintf(h->err, "Cannot connect to IPMI host [%s]:%d." " start_con() returned error 0x%x", h->ip, h->port, ret); h->ret = NETWORK_ERROR; goto out; } options[0].option = IPMI_OPEN_OPTION_ALL; options[0].ival = 0; options[1].option = IPMI_OPEN_OPTION_SDRS; options[1].ival = 1; if (0 != (ret = ipmi_open_domain("", &h->con, 1, setup_done, h, domain_up, h, options, 2, NULL))) { h->err = zbx_dsprintf(h->err, "Cannot connect to IPMI host [%s]:%d." "ipmi_open_domain() returned error 0x%x %s", h->ip, h->port, ret, strerror(ret)); h->ret = NETWORK_ERROR; goto out; } tv.tv_sec = 10; tv.tv_usec = 0; while (0 == h->done) os_hnd->perform_one_op(os_hnd, &tv); out: zbx_free(addrs[0]); zbx_free(ports[0]); return h; }