int main(int argc, char *argv[]) { int rv; int curr_arg = 1; ipmi_args_t *args; ipmi_con_t *con; progname = argv[0]; /* OS handler allocated first. */ os_hnd = ipmi_posix_setup_os_handler(); if (!os_hnd) { printf("ipmi_smi_setup_con: Unable to allocate os handler\n"); exit(1); } /* Use the default log handler. */ /* Initialize the OpenIPMI library. */ ipmi_init(os_hnd); rv = ipmi_parse_args2(&curr_arg, argc, argv, &args); if (rv) { fprintf(stderr, "Error parsing command arguments, argument %d: %s\n", curr_arg, strerror(rv)); usage(); exit(1); } rv = ipmi_args_setup_con(args, os_hnd, NULL, &con); if (rv) { fprintf(stderr, "ipmi_ip_setup_con: %s", strerror(rv)); exit(1); } rv = ipmi_open_domain("", &con, 1, setup_done, NULL, NULL, NULL, NULL, 0, NULL); if (rv) { fprintf(stderr, "ipmi_init_domain: %s\n", strerror(rv)); exit(1); } /* This is the main loop of the event-driven program. Try <CTRL-C> to exit the program */ /* Let the selector code run the select loop. */ os_hnd->operation_loop(os_hnd); /* Technically, we can't get here, but this is an example. */ os_hnd->free_os_handler(os_hnd); return 0; }
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; }
int main(int argc, char *argv[]) { int rv; int curr_arg = 1; const char *arg; int full_screen = 1; ipmi_domain_id_t domain_id; int i; #ifdef HAVE_UCDSNMP int init_snmp = 0; #endif ipmi_args_t *con_parms[2]; ipmi_con_t *con[2]; int last_con = 0; selector_t *selector; while ((curr_arg < argc) && (argv[curr_arg][0] == '-')) { arg = argv[curr_arg]; curr_arg++; if (strcmp(arg, "--") == 0) { break; } else if (strcmp(arg, "-c") == 0) { full_screen = 0; } else if (strcmp(arg, "-dlock") == 0) { DEBUG_LOCKS_ENABLE(); } else if (strcmp(arg, "-dmem") == 0) { DEBUG_MALLOC_ENABLE(); } else if (strcmp(arg, "-drawmsg") == 0) { DEBUG_RAWMSG_ENABLE(); } else if (strcmp(arg, "-dmsg") == 0) { DEBUG_MSG_ENABLE(); #ifdef HAVE_UCDSNMP } else if (strcmp(arg, "-snmp") == 0) { init_snmp = 1; #endif } else { fprintf(stderr, "Unknown option: %s\n", arg); return 1; } } rv = ipmi_ui_init(&selector, full_screen); #ifdef HAVE_UCDSNMP if (init_snmp) { if (snmp_init(selector) < 0) goto out; } #endif next_con: rv = ipmi_parse_args(&curr_arg, argc, argv, &con_parms[last_con]); if (rv) { fprintf(stderr, "Error parsing command arguments, argument %d: %s\n", curr_arg, strerror(rv)); exit(1); } last_con++; if (curr_arg < argc) { if (last_con == 2) { fprintf(stderr, "Too many connections\n"); rv = EINVAL; goto out; } goto next_con; } for (i=0; i<last_con; i++) { rv = ipmi_args_setup_con(con_parms[i], &ipmi_ui_cb_handlers, selector, &con[i]); if (rv) { fprintf(stderr, "ipmi_ip_setup_con: %s", strerror(rv)); exit(1); } } for (i=0; i<last_con; i++) ipmi_free_args(con_parms[i]); rv = ipmi_open_domain("first", con, last_con, ipmi_ui_setup_done, NULL, NULL, NULL, NULL, 0, &domain_id); if (rv) { fprintf(stderr, "ipmi_init_domain: %s\n", strerror(rv)); goto out; } sel_select_loop(selector, NULL, 0, NULL); out: ipmi_ui_shutdown(); if (rv) return 1; return 0; }
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; }