这篇教程C++ zbx_free函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中zbx_free函数的典型用法代码示例。如果您正苦于以下问题:C++ zbx_free函数的具体用法?C++ zbx_free怎么用?C++ zbx_free使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了zbx_free函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: dns_query//.........这里部分代码省略......... type = T_SOA; else { for (i = 0; NULL != qt[i].name; i++) {#ifdef _WINDOWS if (0 == lstrcmpiA(qt[i].name, tmp))#else if (0 == strcasecmp(qt[i].name, tmp))#endif { type = qt[i].type; break; } } if (NULL == qt[i].name) return SYSINFO_RET_FAIL; } if (0 != get_param(param, 4, tmp, sizeof(tmp)) || '/0' == *tmp) retrans = 1; else retrans = atoi(tmp); if (0 != get_param(param, 5, tmp, sizeof(tmp)) || '/0' == *tmp) retry = 2; else retry = atoi(tmp);#ifdef _WINDOWS wzone = zbx_utf8_to_unicode(zone); res = DnsQuery(wzone, type, DNS_QUERY_STANDARD, NULL, &pQueryResults, NULL); zbx_free(wzone); if (1 == short_answer) { SET_UI64_RESULT(result, DNS_RCODE_NOERROR != res ? 0 : 1); ret = SYSINFO_RET_OK; goto clean; } if (DNS_RCODE_NOERROR != res) return SYSINFO_RET_FAIL; pDnsRecord = pQueryResults; while (NULL != pDnsRecord) { if (DnsSectionAnswer != pDnsRecord->Flags.S.Section) { pDnsRecord = pDnsRecord->pNext; continue; } if (NULL == pDnsRecord->pName) goto clean; offset += zbx_snprintf(buffer + offset, sizeof(buffer) - offset, "%-20s", zbx_unicode_to_utf8_static(pDnsRecord->pName, tmp, sizeof(tmp))); offset += zbx_snprintf(buffer + offset, sizeof(buffer) - offset, " %-8s", decode_type(pDnsRecord->wType)); switch (pDnsRecord->wType) { case T_A:
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:67,
示例2: zbx_waitpid//.........这里部分代码省略......... if (WAIT_TIMEOUT == WaitForSingleObject(pi.hProcess, timeout)) ret = TIMEOUT_ERROR; } } /* wait for child process to exit */ if (TIMEOUT_ERROR == ret) { zbx_strlcpy(error, "Timeout while executing a shell script", max_error_len); ret = FAIL; } /* terminate child process */ TerminateProcess(pi.hProcess, 0); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); CloseHandle(hRead); hRead = NULL;lbl_exit: if (NULL != hWrite) { CloseHandle(hWrite); hWrite = NULL; } if (NULL != hRead) { CloseHandle(hRead); hRead = NULL; } zbx_free(cmd); zbx_free(wcmd);#else /* not _WINDOWS */ alarm(timeout); if (-1 != (fd = zbx_popen(&pid, command))) { int rc = 0; if (NULL != buffer) { while (0 < (rc = read(fd, p, buf_size))) { p += rc; if (0 == (buf_size -= rc)) break; } *p = '/0'; } close(fd); if (-1 == rc) { if (EINTR == errno) zbx_strlcpy(error, "Timeout while executing a shell script", max_error_len); else zbx_strlcpy(error, strerror(errno), max_error_len); kill(pid, SIGTERM); zbx_waitpid(pid); ret = FAIL; } else { if (-1 == zbx_waitpid(pid)) { if (EINTR == errno) zbx_strlcpy(error, "Timeout while executing a shell script", max_error_len); else zbx_strlcpy(error, strerror(errno), max_error_len); kill(pid, SIGTERM); zbx_waitpid(pid); ret = FAIL; } } } else { zbx_strlcpy(error, strerror(errno), max_error_len); ret = FAIL; } alarm(0);#endif /* _WINDOWS */ if (FAIL == ret && NULL != buffer) zbx_free(*buffer); return ret;}
开发者ID:songyuanjie,项目名称:zabbix-stats,代码行数:101,
示例3: calculate_checksums//.........这里部分代码省略......... zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, "insert into node_cksum (nodeid,tablename,recordid,cksumtype,cksum)" " select %d,'%s',%s,%d,", nodeid, tables[t].table, tables[t].recid, NODE_CKSUM_TYPE_NEW);#ifdef HAVE_MYSQL zbx_strcpy_alloc(&sql, &sql_alloc, &sql_offset, "concat_ws(',',");#endif for (f = 0; NULL != tables[t].fields[f].name; f++) { const ZBX_FIELD *field = &tables[t].fields[f]; if (0 == (field->flags & ZBX_SYNC)) continue; if (field->flags & ZBX_NOTNULL) { switch (field->type) { case ZBX_TYPE_ID: case ZBX_TYPE_INT: case ZBX_TYPE_UINT: zbx_strcpy_alloc(&sql, &sql_alloc, &sql_offset, field->name); break; case ZBX_TYPE_FLOAT: zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, "md5(cast(%s as char))", field->name); break; default: zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, "md5(%s)", field->name); break; } } else { zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, "case when %s is null then 'NULL'", field->name); switch (field->type) { case ZBX_TYPE_ID: case ZBX_TYPE_INT: case ZBX_TYPE_UINT: zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, " else cast(%s as char) end", field->name); break; case ZBX_TYPE_FLOAT: zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, " else md5(cast(%s as char)) end", field->name); break; default: zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, " else md5(%s) end", field->name); break; } }#ifdef HAVE_MYSQL zbx_chrcpy_alloc(&sql, &sql_alloc, &sql_offset, ',');#else zbx_strcpy_alloc(&sql, &sql_alloc, &sql_offset, "||','||");#endif } /* remove last delimiter */ if (f > 0) {#ifdef HAVE_MYSQL sql_offset--; zbx_chrcpy_alloc(&sql, &sql_alloc, &sql_offset, ')');#else sql_offset -= 7;#endif } zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, " from %s", tables[t].table); if (0 != recordid) { zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, " where %s=" ZBX_FS_UI64, tables[t].recid, recordid); } else { zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, " where 1=1" DB_NODE, DBnode(tables[t].recid, nodeid)); } if (ZBX_DB_OK > DBexecute("%s", sql)) { res = FAIL; break; } } zbx_free(sql); zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(res)); return res;}
开发者ID:nabnut,项目名称:zabbix2.0-cookies,代码行数:101,
示例4: get_dmi_infostatic int get_dmi_info(char *buf, int bufsize, int flags){ int ret = SYSINFO_RET_FAIL, fd, offset = 0; unsigned char membuf[SMBIOS_ENTRY_POINT_SIZE], *smbuf = NULL, *data; size_t len, fp; void *mmp = NULL; static long pagesize = 0; static int smbios_status = SMBIOS_STATUS_UNKNOWN; static size_t smbios_len, smbios; /* length and address of SMBIOS table (if found) */ if (-1 == (fd = open(DEV_MEM, O_RDONLY))) return ret; if (SMBIOS_STATUS_UNKNOWN == smbios_status) /* look for SMBIOS table only once */ { pagesize = sysconf(_SC_PAGESIZE); /* find smbios entry point - located between 0xF0000 and 0xFFFFF (according to the specs) */ for (fp = 0xf0000; 0xfffff > fp; fp += 16) { memset(membuf, 0, sizeof(membuf)); len = fp % pagesize; /* mmp needs to be a multiple of pagesize for munmap */ if (MAP_FAILED == (mmp = mmap(0, len + SMBIOS_ENTRY_POINT_SIZE, PROT_READ, MAP_SHARED, fd, fp - len))) goto close; memcpy(membuf, mmp + len, sizeof(membuf)); munmap(mmp, len + SMBIOS_ENTRY_POINT_SIZE); if (0 == strncmp((char *)membuf, "_DMI_", 5)) /* entry point found */ { smbios_len = membuf[7] << 8 | membuf[6]; smbios = (size_t)membuf[11] << 24 | (size_t)membuf[10] << 16 | (size_t)membuf[9] << 8 | membuf[8]; smbios_status = SMBIOS_STATUS_OK; break; } } } if (SMBIOS_STATUS_OK != smbios_status) { smbios_status = SMBIOS_STATUS_ERROR; goto close; } smbuf = zbx_malloc(smbuf, smbios_len); len = smbios % pagesize; /* mmp needs to be a multiple of pagesize for munmap */ if (MAP_FAILED == (mmp = mmap(0, len + smbios_len, PROT_READ, MAP_SHARED, fd, smbios - len))) goto clean; memcpy(smbuf, mmp + len, smbios_len); munmap(mmp, len + smbios_len); data = smbuf; while (data + DMI_HEADER_SIZE <= smbuf + smbios_len) { if (1 == data[0]) /* system information */ { if (0 != (flags & DMI_GET_VENDOR)) { offset += get_dmi_string(buf + offset, bufsize - offset, data, data[4]); flags &= ~DMI_GET_VENDOR; } if (0 != (flags & DMI_GET_MODEL)) { offset += get_dmi_string(buf + offset, bufsize - offset, data, data[5]); flags &= ~DMI_GET_MODEL; } if (0 != (flags & DMI_GET_SERIAL)) { offset += get_dmi_string(buf + offset, bufsize - offset, data, data[7]); flags &= ~DMI_GET_SERIAL; } } else if (3 == data[0] && 0 != (flags & DMI_GET_TYPE)) /* chassis */ { offset += get_chassis_type(buf + offset, bufsize - offset, data[5]); flags &= ~DMI_GET_TYPE; } if (0 == flags) break; data += data[1]; /* skip the main data */ while (0 != data[0] || 0 != data[1]) /* string data ends with two nulls */ { data++; } data += 2; } if (0 < offset) ret = SYSINFO_RET_OK;clean: zbx_free(smbuf);close: close(fd);//.........这里部分代码省略.........
开发者ID:nabnut,项目名称:zabbix2.0-cookies,代码行数:101,
示例5: PROC_NUMint PROC_NUM(AGENT_REQUEST *request, AGENT_RESULT *result){ char *procname, *proccomm, *param; int zbx_proc_stat, count, i, proc_ok, stat_ok, comm_ok; int proccount = 0; size_t sz; struct passwd *usrinfo;#ifdef KERN_PROC2 int mib[6]; struct kinfo_proc2 *proc = NULL;#else int mib[4]; struct kinfo_proc *proc = NULL;#endif char **argv = NULL, *args = NULL; size_t argv_alloc = 0, args_alloc = 0; int argc; if (4 < request->nparam) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters.")); return SYSINFO_RET_FAIL; } procname = get_rparam(request, 0); param = get_rparam(request, 1); if (NULL != param && '/0' != *param) { errno = 0; if (NULL == (usrinfo = getpwnam(param))) { if (0 == errno) SET_MSG_RESULT(result, zbx_strdup(NULL, "Specified user does not exist.")); else SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain user information: %s", zbx_strerror(errno))); return SYSINFO_RET_FAIL; } } else usrinfo = NULL; param = get_rparam(request, 2); if (NULL == param || '/0' == *param || 0 == strcmp(param, "all")) zbx_proc_stat = ZBX_PROC_STAT_ALL; else if (0 == strcmp(param, "run")) zbx_proc_stat = ZBX_PROC_STAT_RUN; else if (0 == strcmp(param, "sleep")) zbx_proc_stat = ZBX_PROC_STAT_SLEEP; else if (0 == strcmp(param, "zomb")) zbx_proc_stat = ZBX_PROC_STAT_ZOMB; else { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid third parameter.")); return SYSINFO_RET_FAIL; } proccomm = get_rparam(request, 3); mib[0] = CTL_KERN; if (NULL != usrinfo) { mib[2] = KERN_PROC_UID; mib[3] = usrinfo->pw_uid; } else { mib[2] = KERN_PROC_ALL; mib[3] = 0; }#ifdef KERN_PROC2 mib[1] = KERN_PROC2; mib[4] = sizeof(struct kinfo_proc2); mib[5] = 0; sz = 0; if (0 != sysctl(mib, 6, NULL, &sz, NULL, 0)) { SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain necessary buffer size from system: %s", zbx_strerror(errno))); return SYSINFO_RET_FAIL; } proc = (struct kinfo_proc2 *)zbx_malloc(proc, sz); mib[5] = (int)(sz / sizeof(struct kinfo_proc2)); if (0 != sysctl(mib, 6, proc, &sz, NULL, 0)) { zbx_free(proc); SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain process information: %s",//.........这里部分代码省略.........
开发者ID:HupuInc,项目名称:zabbix,代码行数:101,
示例6: process_escalations//.........这里部分代码省略......... if (ESCALATION_STATUS_COMPLETED == escalation.status) { /* delete a recovery record and skip all processing */ zbx_vector_uint64_append(&escalationids, escalation.escalationid); goto next; } if (0 != last_escalation.escalationid) { esc_superseded = (escalation.actionid == last_escalation.actionid && escalation.triggerid == last_escalation.triggerid); if (1 == esc_superseded) { if (0 != last_escalation.r_eventid) { /* recover this escalation */ escalation.r_eventid = last_escalation.r_eventid; escalation.status = ESCALATION_STATUS_ACTIVE; } else if (escalation.nextcheck > now || ESCALATION_STATUS_SLEEP == escalation.status) { zbx_vector_uint64_append(&escalationids, escalation.escalationid); goto next; } } } if (ESCALATION_STATUS_ACTIVE != escalation.status || (escalation.nextcheck > now && 0 == escalation.r_eventid)) { goto next; } DBbegin(); if (escalation.nextcheck <= now) execute_escalation(&escalation); /* execute recovery */ if (ESCALATION_STATUS_COMPLETED != escalation.status && 0 != escalation.r_eventid) { escalation.status = ESCALATION_STATUS_RECOVERY; execute_escalation(&escalation); } else if (1 == esc_superseded) escalation.status = ESCALATION_STATUS_COMPLETED; sql_offset = 0; if (ESCALATION_STATUS_COMPLETED != escalation.status) { zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, "update escalations set status=%d", escalation.status); if (ESCALATION_STATUS_ACTIVE == escalation.status) { zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, ",esc_step=%d,nextcheck=%d", escalation.esc_step, escalation.nextcheck); } zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, " where escalationid=" ZBX_FS_UI64, escalation.escalationid); } else { zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, "delete from escalations where escalationid=" ZBX_FS_UI64, escalation.escalationid); } DBexecute("%s", sql); DBcommit(); }next: if (NULL != row) memcpy(&escalation, &last_escalation, sizeof(escalation)); } while (NULL != row); DBfree_result(result); zbx_free(sql); /* delete completed escalations */ if (0 != escalationids.values_num) { zbx_vector_uint64_sort(&escalationids, ZBX_DEFAULT_UINT64_COMPARE_FUNC); DBbegin(); DBexecute_multiple_query("delete from escalations where", "escalationid", &escalationids); DBcommit(); } zbx_vector_uint64_destroy(&escalationids); zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);}
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,
示例7: execute_operations//.........这里部分代码省略......... escalation->esc_step); } while (NULL != (row = DBfetch(result))) { memset(&operation, 0, sizeof(operation)); ZBX_STR2UINT64(operation.operationid, row[0]); operation.actionid = action->actionid; operation.operationtype = atoi(row[1]); operation.esc_period = atoi(row[2]); operation.evaltype = (unsigned char)atoi(row[3]); if (SUCCEED == check_operation_conditions(event, operation.operationid, operation.evaltype)) { unsigned char default_msg; char *subject, *message; zbx_uint64_t mediatypeid; zabbix_log(LOG_LEVEL_DEBUG, "Conditions match our event. Execute operation."); if (0 == esc_period || esc_period > operation.esc_period) esc_period = operation.esc_period; switch (operation.operationtype) { case OPERATION_TYPE_MESSAGE: if (SUCCEED == DBis_null(row[4])) break; default_msg = (unsigned char)atoi(row[5]); ZBX_DBROW2UINT64(mediatypeid, row[8]); if (0 == default_msg) { subject = row[6]; message = row[7]; } else { subject = action->shortdata; message = action->longdata; } add_object_msg(operation.operationid, mediatypeid, &user_msg, subject, message, event->source, event->objectid); break; case OPERATION_TYPE_COMMAND: execute_commands(event, action->actionid, operation.operationid, escalation->esc_step); break; } } else zabbix_log(LOG_LEVEL_DEBUG, "Conditions do not match our event. Do not execute operation."); operations = 1; } DBfree_result(result); while (NULL != user_msg) { p = user_msg; user_msg = user_msg->next; add_message_alert(escalation, event, action, p->userid, p->mediatypeid, p->subject, p->message); zbx_free(p->subject); zbx_free(p->message); zbx_free(p); } if (0 == action->esc_period) { escalation->status = (action->recovery_msg == 1) ? ESCALATION_STATUS_SLEEP : ESCALATION_STATUS_COMPLETED; } else { if (0 == operations) { result = DBselect("select operationid from operations where actionid=" ZBX_FS_UI64 " and esc_step_from>%d", action->actionid, escalation->esc_step); if (NULL != (row = DBfetch(result)) && SUCCEED != DBis_null(row[0])) operations = 1; DBfree_result(result); } if (1 == operations) { esc_period = (0 != esc_period) ? esc_period : action->esc_period; escalation->nextcheck = time(NULL) + esc_period; } else escalation->status = (action->recovery_msg == 1) ? ESCALATION_STATUS_SLEEP : ESCALATION_STATUS_COMPLETED; } zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);}
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,
示例8: update_checksums//.........这里部分代码省略......... while ((table->fields[f].flags & ZBX_SYNC) == 0) f++; d[0] = NULL; d[1] = NULL; if (NULL != r[0] && NULL != (d[0] = strchr(r[0], ','))) *d[0] = '/0'; if (NULL != r[1] && NULL != (d[1] = strchr(r[1], ','))) *d[1] = '/0'; if (NULL == tablename || SUCCEED == str_in_list(fields, table->fields[f].name, ',')) { ck += zbx_snprintf(ck, 64, "%s,", NULL != r[1] ? r[1] : r[0]); if (r[0] == NULL || r[1] == NULL || strcmp(r[0], r[1]) != 0) { if (synked_nodetype == ZBX_NODE_SLAVE) { s[0] = c[0]; s[1] = ' '; } else if (synked_nodetype == ZBX_NODE_MASTER) { s[0] = ' '; s[1] = c[0]; } } else { if (synked == SUCCEED) { if (synked_nodetype == ZBX_NODE_SLAVE) s[0] = c[0]; else if (synked_nodetype == ZBX_NODE_MASTER) s[1] = c[0]; } } } else ck += zbx_snprintf(ck, 64, "%s,", NULL != r[0] ? r[0] : ""); s += 2; f++; if (d[0] != NULL) { *d[0] = ','; r[0] = d[0] + 1; } else r[0] = NULL; if (d[1] != NULL) { *d[1] = ','; r[1] = d[1] + 1; } else r[1] = NULL; } while (d[0] != NULL || d[1] != NULL); *--ck = '/0'; } *s = '/0'; if (SUCCEED == DBis_null(row[2]) || SUCCEED == DBis_null(row[3]) || 0 != strcmp(row[4], sync) || 0 != strcmp(row[2], row[3])) { cksumtype = (DBis_null(row[2]) == SUCCEED) ? NODE_CKSUM_TYPE_NEW : NODE_CKSUM_TYPE_OLD; zbx_snprintf_alloc(&exsql, &exsql_alloc, &exsql_offset, 2560, "update node_cksum" " set cksumtype=%d," "cksum='%s'," "sync='%s'" " where nodeid=%d" " and cksumtype=%d" " and tablename='%s'" " and recordid=%s;/n", NODE_CKSUM_TYPE_OLD, cksum, sync, nodeid, cksumtype, row[0], row[1]); DBexecute_overflowed_sql(&exsql, &exsql_alloc, &exsql_offset); } } DBfree_result(result);#ifdef HAVE_ORACLE zbx_snprintf_alloc(&exsql, &exsql_alloc, &exsql_offset, 8, "end;/n");#endif if (exsql_offset > 16) /* In ORACLE always present begin..end; */ DBexecute("%s", exsql); zbx_free(exsql); DBcommit(); zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name); return SUCCEED;}
开发者ID:songyuanjie,项目名称:zabbix-stats,代码行数:101,
示例9: zbx_tcp_listen//.........这里部分代码省略......... if (ZBX_SOCK_ERROR == (s->sockets[s->num_socks] = socket(current_ai->ai_family, current_ai->ai_socktype | SOCK_CLOEXEC, current_ai->ai_protocol))) { zbx_set_tcp_strerror("socket() for [[%s]:%s] failed: %s", ip ? ip : "-", port, strerror_from_system(zbx_sock_last_error()));#ifdef _WINDOWS if (WSAEAFNOSUPPORT == zbx_sock_last_error())#else if (EAFNOSUPPORT == zbx_sock_last_error())#endif continue; else goto out; }#if !defined(_WINDOWS) && !SOCK_CLOEXEC fcntl(s->sockets[s->num_socks], F_SETFD, FD_CLOEXEC);#endif /* enable address reuse */ /* this is to immediately use the address even if it is in TIME_WAIT state */ /* http://www-128.ibm.com/developerworks/linux/library/l-sockpit/index.html */ on = 1; if (ZBX_TCP_ERROR == setsockopt(s->sockets[s->num_socks], SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on))) { zbx_set_tcp_strerror("setsockopt() with SO_REUSEADDR for [[%s]:%s] failed: %s", ip ? ip : "-", port, strerror_from_system(zbx_sock_last_error())); }#if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY) if (PF_INET6 == current_ai->ai_family && ZBX_TCP_ERROR == setsockopt(s->sockets[s->num_socks], IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on, sizeof(on))) { zbx_set_tcp_strerror("setsockopt() with IPV6_V6ONLY for [[%s]:%s] failed: %s", ip ? ip : "-", port, strerror_from_system(zbx_sock_last_error())); }#endif if (ZBX_TCP_ERROR == bind(s->sockets[s->num_socks], current_ai->ai_addr, current_ai->ai_addrlen)) { zbx_set_tcp_strerror("bind() for [[%s]:%s] failed: %s", ip ? ip : "-", port, strerror_from_system(zbx_sock_last_error())); zbx_sock_close(s->sockets[s->num_socks]);#ifdef _WINDOWS if (WSAEADDRINUSE == zbx_sock_last_error())#else if (EADDRINUSE == zbx_sock_last_error())#endif continue; else goto out; } if (ZBX_TCP_ERROR == listen(s->sockets[s->num_socks], SOMAXCONN)) { zbx_set_tcp_strerror("listen() for [[%s]:%s] failed: %s", ip ? ip : "-", port, strerror_from_system(zbx_sock_last_error())); zbx_sock_close(s->sockets[s->num_socks]); goto out; } s->num_socks++; } if (NULL != ai) { freeaddrinfo(ai); ai = NULL; } if (NULL == ip || NULL == delim) break; *delim = ','; ip = delim + 1; } if (0 == s->num_socks) { zbx_set_tcp_strerror("zbx_tcp_listen() fatal error: unable to serve on any address [[%s]:%hu]", listen_ip ? listen_ip : "-", listen_port); goto out; } ret = SUCCEED;out: if (NULL != ips) zbx_free(ips); if (NULL != ai) freeaddrinfo(ai); if (SUCCEED != ret) { for (i = 0; i < s->num_socks; i++) zbx_sock_close(s->sockets[i]); } return ret;}
开发者ID:abhilash07,项目名称:agent,代码行数:101,
示例10: ZBX_THREAD_ENTRYZBX_THREAD_ENTRY(active_checks_thread, args){ ZBX_THREAD_ACTIVECHK_ARGS activechk_args;#if defined(ZABBIX_DAEMON) struct sigaction phan;#endif /* ZABBIX_DAEMON */ int nextcheck = 0, nextrefresh = 0, nextsend = 0; char *p = NULL;#if defined(ZABBIX_DAEMON) phan.sa_handler = child_signal_handler; sigemptyset(&phan.sa_mask); phan.sa_flags = 0; sigaction(SIGALRM, &phan, NULL);#endif /* ZABBIX_DAEMON */ activechk_args.host = strdup(((ZBX_THREAD_ACTIVECHK_ARGS *)args)->host); activechk_args.port = ((ZBX_THREAD_ACTIVECHK_ARGS *)args)->port; assert(activechk_args.host); p = strchr(activechk_args.host,','); if(p) *p = '/0'; zabbix_log( LOG_LEVEL_INFORMATION, "zabbix_agentd active check started [%s:%u]", activechk_args.host, activechk_args.port); init_active_metrics(); while(ZBX_IS_RUNNING) { if(time(NULL) >= nextsend) { send_buffer(activechk_args.host, activechk_args.port); nextsend = (int)time(NULL) + 1; } if(time(NULL) >= nextrefresh) { zbx_setproctitle("poller [getting list of active checks]"); if(FAIL == refresh_active_checks(activechk_args.host, activechk_args.port)) { nextrefresh = (int)time(NULL) + 60; } else { nextrefresh = (int)time(NULL) + CONFIG_REFRESH_ACTIVE_CHECKS; } } if(time(NULL) >= nextcheck) { zbx_setproctitle("poller [processing active checks]"); process_active_checks(activechk_args.host, activechk_args.port); nextcheck = get_min_nextcheck(); if(FAIL == nextcheck) nextcheck = (int)time(NULL) + 60; } else { zabbix_log(LOG_LEVEL_DEBUG, "Sleeping for %d seconds", 1 ); zbx_setproctitle("poller [sleeping for %d seconds]", 1); zbx_sleep(1); } } zbx_free(activechk_args.host); free_active_metrics(); zabbix_log( LOG_LEVEL_INFORMATION, "zabbix_agentd active check stopped"); ZBX_DO_EXIT(); zbx_tread_exit(0);}
开发者ID:rennhak,项目名称:zabbix,代码行数:77,
示例11: zabbix_log//.........这里部分代码省略......... row[0], table->recid, row[1]); result2 = DBselect("%s", sql); if (NULL == (row2 = DBfetch(result2))) goto out; zbx_snprintf_alloc(&data, &data_allocated, &data_offset, 128, "/n%s%c%s%c%d", row[0], ZBX_DM_DELIMITER, row[1], ZBX_DM_DELIMITER, NODE_CONFIGLOG_OP_UPDATE); r[0] = DBis_null(row[2]) == SUCCEED ? NULL : row[2]; r[1] = row[3]; s = sync; f = 0; j = 0; do { while ((table->fields[f].flags & ZBX_SYNC) == 0) f++; d[0] = NULL; d[1] = NULL; if (NULL != r[0] && NULL != (d[0] = strchr(r[0], ','))) *d[0] = '/0'; if (NULL != r[1] && NULL != (d[1] = strchr(r[1], ','))) *d[1] = '/0'; if (r[0] == NULL || r[1] == NULL || (dest_nodetype == ZBX_NODE_SLAVE && *s != c[0]) || (dest_nodetype == ZBX_NODE_MASTER && *(s+1) != c[0]) || strcmp(r[0], r[1]) != 0) { zbx_snprintf_alloc(&data, &data_allocated, &data_offset, 128, "%c%s%c%d%c", ZBX_DM_DELIMITER, table->fields[f].name, ZBX_DM_DELIMITER, table->fields[f].type, ZBX_DM_DELIMITER); /* Fieldname, type, value */ if (SUCCEED == DBis_null(row2[j])) { zbx_snprintf_alloc(&data, &data_allocated, &data_offset, 5, "NULL"); } else if (table->fields[f].type == ZBX_TYPE_INT || table->fields[f].type == ZBX_TYPE_UINT || table->fields[f].type == ZBX_TYPE_ID || table->fields[f].type == ZBX_TYPE_FLOAT) { zbx_snprintf_alloc(&data, &data_allocated, &data_offset, 128, "%s", row2[j]); } else { if (ZBX_TYPE_BLOB == table->fields[f].type) rowlen = atoi(row2[j + 1]); else rowlen = strlen(row2[j]); zbx_binary2hex((u_char *)row2[j], rowlen, &hex, &hex_allocated); zbx_snprintf_alloc(&data, &data_allocated, &data_offset, strlen(hex) + 128, "%s", hex); } if (ZBX_TYPE_BLOB == table->fields[f].type) j += 2; else j++; } s += 2; f++; if (NULL != d[0]) { *d[0] = ','; r[0] = d[0] + 1; } else r[0] = NULL; if (NULL != d[1]) { *d[1] = ','; r[1] = d[1] + 1; } else r[1] = NULL; } while (NULL != d[0] || NULL != d[1]);out: DBfree_result(result2); } DBfree_result(result); zbx_free(hex); zbx_free(sql); zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name); return data;}
开发者ID:songyuanjie,项目名称:zabbix-stats,代码行数:101,
示例12: process_active_checksstatic void process_active_checks(char *server, unsigned short port){ register int i, s_count, p_count; char **pvalue; int now, send_err = SUCCEED, ret; unsigned long timestamp; char *source = NULL; char *value = NULL; unsigned short severity; long lastlogsize; char params[MAX_STRING_LEN]; char filename[MAX_STRING_LEN]; char pattern[MAX_STRING_LEN]; AGENT_RESULT result; zabbix_log( LOG_LEVEL_DEBUG, "In process_active_checks('%s',%u)",server, port); init_result(&result); now = (int)time(NULL); for(i=0; NULL != active_metrics[i].key && SUCCEED == send_err; i++) { if(active_metrics[i].nextcheck > now) continue; if(active_metrics[i].status != ITEM_STATUS_ACTIVE) continue; /* Special processing for log files */ if(strncmp(active_metrics[i].key,"log[",4) == 0) { do{ /* simple try realization */ if (parse_command(active_metrics[i].key, NULL, 0, params, MAX_STRING_LEN) != 2) break; if (num_param(params) > 2) break; if (get_param(params, 1, filename, sizeof(filename)) != 0) break; if (get_param(params, 2, pattern, sizeof(pattern)) != 0) *pattern = '/0'; s_count = 0; p_count = 0; lastlogsize = active_metrics[i].lastlogsize; while (SUCCEED == (ret = process_log(filename, &lastlogsize, &value))) { if (!value) /* EOF */ break; if (SUCCEED == regexp_match_ex(regexps, regexps_num, value, pattern, ZBX_CASE_SENSITIVE)) { send_err = process_value( server, port, CONFIG_HOSTNAME, active_metrics[i].key_orig, value, &lastlogsize, NULL, NULL, NULL ); s_count++; } p_count++; zbx_free(value); if (SUCCEED == send_err) active_metrics[i].lastlogsize = lastlogsize; else lastlogsize = active_metrics[i].lastlogsize; /* Do not flood ZABBIX server if file grows too fast */ if(s_count >= (MAX_LINES_PER_SECOND * active_metrics[i].refresh)) break; /* Do not flood local system if file grows too fast */ if(p_count >= (4 * MAX_LINES_PER_SECOND * active_metrics[i].refresh)) break; } if( FAIL == ret ) { active_metrics[i].status = ITEM_STATUS_NOTSUPPORTED; zabbix_log( LOG_LEVEL_WARNING, "Active check [%s] is not supported. Disabled.", active_metrics[i].key); send_err = process_value( server, port, CONFIG_HOSTNAME, active_metrics[i].key_orig, "ZBX_NOTSUPPORTED", &active_metrics[i].lastlogsize, NULL, NULL, NULL ); } }while(0); /* simple try realization *///.........这里部分代码省略.........
开发者ID:rennhak,项目名称:zabbix,代码行数:101,
示例13: process_value/****************************************************************************** * * * Function: process_value * * * * Purpose: Buffer new value or send the whole buffer to the server * * * * Parameters: host - IP or Hostname of ZABBIX server * * port - port of ZABBIX server * * hostname - name of host in ZABBIX database * * key - name of metric * * value - string version os key value * * lastlogsize - size of readed logfile * * timestamp - timestamp of readed value * * source - name of logged data source * * severity - severity of logged data sources * * * * Return value: returns SUCCEED on succesfull parsing, * * FAIL on other cases * * * * Author: Alexei Vladishev * * * * Comments: * * * ******************************************************************************/static int process_value( const char *server, unsigned short port, const char *host, const char *key, const char *value, long *lastlogsize, unsigned long *timestamp, const char *source, unsigned short *severity){ ZBX_ACTIVE_BUFFER_ELEMENT *el; int ret = SUCCEED; zabbix_log( LOG_LEVEL_DEBUG, "In process_value('%s','%s','%s')", host, key, value); send_buffer(server,port); /* Called first time, allocate memory */ if(NULL == buffer.data) { zabbix_log( LOG_LEVEL_DEBUG, "Buffer: first allocation for %d elements", CONFIG_BUFFER_SIZE); buffer.data = zbx_malloc(buffer.data, CONFIG_BUFFER_SIZE*sizeof(ZBX_ACTIVE_BUFFER_ELEMENT)); memset(buffer.data, 0, CONFIG_BUFFER_SIZE*sizeof(ZBX_ACTIVE_BUFFER_ELEMENT)); buffer.count = 0; } if(buffer.count < CONFIG_BUFFER_SIZE) { zabbix_log( LOG_LEVEL_DEBUG, "Buffer: new element %d", buffer.count); el = &buffer.data[buffer.count]; buffer.count++; } else { zabbix_log( LOG_LEVEL_DEBUG, "Buffer full: new element %d", buffer.count); if(buffer.data[0].host != NULL) zbx_free(buffer.data[0].host); if(buffer.data[0].key != NULL) zbx_free(buffer.data[0].key); if(buffer.data[0].value != NULL) zbx_free(buffer.data[0].value); if(buffer.data[0].source != NULL) zbx_free(buffer.data[0].source); memmove(&buffer.data[0],&buffer.data[1], (CONFIG_BUFFER_SIZE-1)*sizeof(ZBX_ACTIVE_BUFFER_ELEMENT)); el = &buffer.data[CONFIG_BUFFER_SIZE-1]; } memset(el, 0, sizeof(ZBX_ACTIVE_BUFFER_ELEMENT)); el->host = strdup(host); el->key = strdup(key); el->value = strdup(value); if (source) el->source = strdup(source); if (severity) el->severity = *severity; if (lastlogsize) el->lastlogsize = *lastlogsize; if (timestamp) el->timestamp = *timestamp; el->clock = (int)time(NULL);/* zabbix_log(LOG_LEVEL_DEBUG, "BUFFER"); for(i=0;i<buffer.count;i++) { zabbix_log(LOG_LEVEL_DEBUG, " Host %s Key %s Values %s", buffer.data[i].host, buffer.data[i].key, buffer.data[i].value); }*/ return ret;}
开发者ID:rennhak,项目名称:zabbix,代码行数:96,
示例14: send_buffer//.........这里部分代码省略......... zabbix_log( LOG_LEVEL_DEBUG, "In send_buffer('%s','%d')", host, port); zabbix_log( LOG_LEVEL_DEBUG, "Values in the buffer %d Max %d", buffer.count, CONFIG_BUFFER_SIZE); now = (int)time(NULL); if(buffer.count < CONFIG_BUFFER_SIZE && now-lastsent < CONFIG_BUFFER_SEND) { zabbix_log( LOG_LEVEL_DEBUG, "Will not send now. Now %d lastsent %d < %d", now, lastsent, CONFIG_BUFFER_SEND); return ret; } if(buffer.count < 1) { return ret; } zbx_json_init(&json, ZBX_JSON_STAT_BUF_LEN); zbx_json_addstring(&json, ZBX_PROTO_TAG_REQUEST, ZBX_PROTO_VALUE_AGENT_DATA, ZBX_JSON_TYPE_STRING); zbx_json_addarray(&json, ZBX_PROTO_TAG_DATA); for(i=0;i<buffer.count;i++) { zbx_json_addobject(&json, NULL); zbx_json_addstring(&json, ZBX_PROTO_TAG_HOST, buffer.data[i].host, ZBX_JSON_TYPE_STRING); zbx_json_addstring(&json, ZBX_PROTO_TAG_KEY, buffer.data[i].key, ZBX_JSON_TYPE_STRING); zbx_json_addstring(&json, ZBX_PROTO_TAG_VALUE, buffer.data[i].value, ZBX_JSON_TYPE_STRING); if (buffer.data[i].lastlogsize) zbx_json_adduint64(&json, ZBX_PROTO_TAG_LOGLASTSIZE, buffer.data[i].lastlogsize); if (buffer.data[i].timestamp) zbx_json_adduint64(&json, ZBX_PROTO_TAG_LOGTIMESTAMP, buffer.data[i].timestamp); if (buffer.data[i].source) zbx_json_addstring(&json, ZBX_PROTO_TAG_LOGSOURCE, buffer.data[i].source, ZBX_JSON_TYPE_STRING); if (buffer.data[i].severity) zbx_json_adduint64(&json, ZBX_PROTO_TAG_LOGSEVERITY, buffer.data[i].severity); zbx_json_adduint64(&json, ZBX_PROTO_TAG_CLOCK, buffer.data[i].clock); zbx_json_close(&json); } zbx_json_close(&json); zbx_json_adduint64(&json, ZBX_PROTO_TAG_CLOCK, (int)time(NULL)); if (SUCCEED == (ret = zbx_tcp_connect(&s, CONFIG_SOURCE_IP, host, port, MIN(buffer.count*CONFIG_TIMEOUT, 60)))) { zabbix_log(LOG_LEVEL_DEBUG, "JSON before sending [%s]", json.buffer); ret = zbx_tcp_send(&s, json.buffer); if( SUCCEED == ret ) { if( SUCCEED == (ret = zbx_tcp_recv(&s, &buf)) ) { zabbix_log(LOG_LEVEL_DEBUG, "JSON back [%s]", buf); if( !buf || check_response(buf) != SUCCEED ) { zabbix_log(LOG_LEVEL_DEBUG, "NOT OK"); } else { zabbix_log(LOG_LEVEL_DEBUG, "OK"); } } else zabbix_log(LOG_LEVEL_DEBUG, "Send value error: [recv] %s", zbx_tcp_strerror()); } else zabbix_log(LOG_LEVEL_DEBUG, "Send value error: [send] %s", zbx_tcp_strerror()); zbx_tcp_close(&s); } else zabbix_log(LOG_LEVEL_DEBUG, "Send value error: [connect] %s", zbx_tcp_strerror()); zbx_json_free(&json); if(SUCCEED == ret) { /* free buffer */ for(i=0;i<buffer.count;i++) { if(buffer.data[i].host != NULL) zbx_free(buffer.data[i].host); if(buffer.data[i].key != NULL) zbx_free(buffer.data[i].key); if(buffer.data[i].value != NULL) zbx_free(buffer.data[i].value); if(buffer.data[i].source != NULL) zbx_free(buffer.data[i].source); } buffer.count = 0; } if(SUCCEED == ret) lastsent = now; return ret;}
开发者ID:rennhak,项目名称:zabbix,代码行数:101,
示例15: free_event_info/****************************************************************************** * * * Function: free_event_info * * * * Purpose: clean allocated memory by function 'get_event_info' * * * * Parameters: event - [IN] event data * * * * Return value: * * * * Author: Alexander Vladishev * * * * Comments: * * * ******************************************************************************/static void free_event_info(DB_EVENT *event){ zbx_free(event->trigger.comments); zbx_free(event->trigger.url);}
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:20,
示例16: execute_escalation//.........这里部分代码省略......... " and f.triggerid=t.triggerid" " and t.triggerid=" ZBX_FS_UI64 " and i.status=%d", escalation->triggerid, ITEM_STATUS_DISABLED); if (NULL != (row = DBfetch(result))) error = zbx_dsprintf(error, "item '%s' disabled.", row[0]); DBfree_result(result); } if (NULL == error && EVENT_SOURCE_TRIGGERS == source) { /* host disabled? */ result = DBselect( "select h.host" " from hosts h,items i,functions f,triggers t" " where h.hostid=i.hostid" " and i.itemid=f.itemid" " and f.triggerid=t.triggerid" " and t.triggerid=" ZBX_FS_UI64 " and h.status=%d", escalation->triggerid, HOST_STATUS_NOT_MONITORED); if (NULL != (row = DBfetch(result))) error = zbx_dsprintf(error, "host '%s' disabled.", row[0]); DBfree_result(result); } switch (escalation->status) { case ESCALATION_STATUS_ACTIVE: result = DBselect( "select actionid,eventsource,esc_period,def_shortdata,def_longdata," "recovery_msg,status,name" " from actions" " where actionid=" ZBX_FS_UI64, escalation->actionid); break; case ESCALATION_STATUS_RECOVERY: result = DBselect( "select actionid,eventsource,esc_period,r_shortdata,r_longdata,recovery_msg," "status,name" " from actions" " where actionid=" ZBX_FS_UI64, escalation->actionid); break; default: THIS_SHOULD_NEVER_HAPPEN; return; } if (NULL != (row = DBfetch(result))) { memset(&action, 0, sizeof(action)); ZBX_STR2UINT64(action.actionid, row[0]); action.eventsource = atoi(row[1]); action.esc_period = atoi(row[2]); action.shortdata = row[3]; action.recovery_msg = atoi(row[5]); if (ACTION_STATUS_ACTIVE != atoi(row[6])) error = zbx_dsprintf(error, "action '%s' disabled.", row[7]); if (NULL != error) { action.longdata = zbx_dsprintf(action.longdata, "NOTE: Escalation cancelled: %s/n%s", error, row[4]); } else action.longdata = row[4]; switch (escalation->status) { case ESCALATION_STATUS_ACTIVE: if (SUCCEED == get_event_info(escalation->eventid, &event)) execute_operations(escalation, &event, &action); free_event_info(&event); break; case ESCALATION_STATUS_RECOVERY: if (SUCCEED == get_event_info(escalation->r_eventid, &event)) process_recovery_msg(escalation, &event, &action); free_event_info(&event); break; default: break; } if (NULL != error) zbx_free(action.longdata); } else error = zbx_dsprintf(error, "action [" ZBX_FS_UI64 "] deleted", escalation->actionid); DBfree_result(result); if (NULL != error) { escalation->status = ESCALATION_STATUS_COMPLETED; zabbix_log(LOG_LEVEL_WARNING, "escalation cancelled: %s", error); zbx_free(error); } zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);}
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,
示例17: zbx_tcp_free/****************************************************************************** * * * Function: zbx_tcp_free * * * * Purpose: close open socket * * * * Author: Alexei Vladishev * * * ******************************************************************************/void zbx_tcp_free(zbx_sock_t *s){ zbx_free(s->buf_dyn);}
开发者ID:abhilash07,项目名称:agent,代码行数:13,
示例18: add_message_alertstatic void add_message_alert(DB_ESCALATION *escalation, DB_EVENT *event, DB_ACTION *action, zbx_uint64_t userid, zbx_uint64_t mediatypeid, const char *subject, const char *message){ const char *__function_name = "add_message_alert"; DB_RESULT result; DB_ROW row; zbx_uint64_t alertid; int now, severity, medias = 0; char *subject_dyn, *message_dyn, *sendto_esc, *subject_esc, *message_esc, *error_esc; char error[MAX_STRING_LEN]; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); subject_dyn = zbx_strdup(NULL, subject); message_dyn = zbx_strdup(NULL, message); substitute_simple_macros(event, &userid, NULL, NULL, NULL, NULL, &subject_dyn, MACRO_TYPE_MESSAGE, NULL, 0); substitute_simple_macros(event, &userid, NULL, NULL, NULL, NULL, &message_dyn, MACRO_TYPE_MESSAGE, NULL, 0); now = time(NULL); subject_esc = DBdyn_escape_string_len(subject_dyn, ALERT_SUBJECT_LEN); message_esc = DBdyn_escape_string_len(message_dyn, ALERT_MESSAGE_LEN); zbx_free(subject_dyn); zbx_free(message_dyn); if (0 == mediatypeid) { result = DBselect( "select m.mediatypeid,m.sendto,m.severity,m.period,mt.status" " from media m,media_type mt" " where m.mediatypeid=mt.mediatypeid" " and m.active=%d" " and m.userid=" ZBX_FS_UI64, MEDIA_STATUS_ACTIVE, userid); } else { result = DBselect( "select m.mediatypeid,m.sendto,m.severity,m.period,mt.status" " from media m,media_type mt" " where m.mediatypeid=mt.mediatypeid" " and m.active=%d" " and m.userid=" ZBX_FS_UI64 " and m.mediatypeid=" ZBX_FS_UI64, MEDIA_STATUS_ACTIVE, userid, mediatypeid); } while (NULL != (row = DBfetch(result))) { medias = 1; ZBX_STR2UINT64(mediatypeid, row[0]); severity = atoi(row[2]); zabbix_log(LOG_LEVEL_DEBUG, "Trigger severity [%d] Media severity [%d] Period [%s]", (int)event->trigger.priority, severity, row[3]); if (((1 << event->trigger.priority) & severity) == 0) { zabbix_log(LOG_LEVEL_DEBUG, "Won't send message (severity)"); continue; } if (FAIL == check_time_period(row[3], (time_t)NULL)) { zabbix_log(LOG_LEVEL_DEBUG, "Won't send message (period)"); continue; } alertid = DBget_maxid("alerts"); sendto_esc = DBdyn_escape_string_len(row[1], ALERT_SENDTO_LEN); if (MEDIA_TYPE_STATUS_ACTIVE == atoi(row[4])) { DBexecute("insert into alerts (alertid,actionid,eventid,userid,clock" ",mediatypeid,sendto,subject,message,status,alerttype,esc_step)" " values (" ZBX_FS_UI64 "," ZBX_FS_UI64 "," ZBX_FS_UI64 "," ZBX_FS_UI64 ",%d" "," ZBX_FS_UI64 ",'%s','%s','%s',%d,%d,%d)", alertid, action->actionid, event->eventid, userid, now, mediatypeid, sendto_esc, subject_esc, message_esc, ALERT_STATUS_NOT_SENT, ALERT_TYPE_MESSAGE, escalation->esc_step); } else { error_esc = DBdyn_escape_string("Media type disabled"); DBexecute("insert into alerts (alertid,actionid,eventid,userid,clock" ",mediatypeid,sendto,subject,message,status,alerttype,esc_step,error)" " values (" ZBX_FS_UI64 "," ZBX_FS_UI64 "," ZBX_FS_UI64 "," ZBX_FS_UI64 ",%d"//.........这里部分代码省略.........
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,
示例19: zbx_tcp_recv_ext/****************************************************************************** * * * Function: zbx_tcp_recv_ext * * * * Purpose: receive data * * * * Return value: number of bytes received - success, * * FAIL - an error occurred * * * * Author: Eugene Grigorjev * * * ******************************************************************************/ssize_t zbx_tcp_recv_ext(zbx_sock_t *s, char **data, unsigned char flags, int timeout){#define ZBX_BUF_LEN (ZBX_STAT_BUF_LEN * 8) ssize_t nbytes, left, total_bytes; size_t allocated, offset, read_bytes; zbx_uint64_t expected_len; ZBX_TCP_START(); if (0 != timeout) zbx_tcp_timeout_set(s, timeout); zbx_free(s->buf_dyn); total_bytes = 0; read_bytes = 0; s->buf_type = ZBX_BUF_TYPE_STAT; *data = s->buf_stat; left = ZBX_TCP_HEADER_LEN; if (ZBX_TCP_ERROR == (nbytes = ZBX_TCP_READ(s->socket, s->buf_stat, left))) goto out; if (ZBX_TCP_HEADER_LEN == nbytes && 0 == strncmp(s->buf_stat, ZBX_TCP_HEADER, ZBX_TCP_HEADER_LEN)) { total_bytes += nbytes; left = sizeof(zbx_uint64_t); if (left != (nbytes = ZBX_TCP_READ(s->socket, (void *)&expected_len, left))) { total_bytes = FAIL; goto out; } expected_len = zbx_letoh_uint64(expected_len); if (ZBX_MAX_RECV_DATA_SIZE < expected_len) { zabbix_log(LOG_LEVEL_WARNING, "Message size " ZBX_FS_UI64 " from %s" " exceeds the maximum size " ZBX_FS_UI64 " bytes. Message ignored.", expected_len, get_ip_by_socket(s), (zbx_uint64_t)ZBX_MAX_RECV_DATA_SIZE); total_bytes = FAIL; goto cleanup; } flags |= ZBX_TCP_READ_UNTIL_CLOSE; } else { read_bytes = nbytes; expected_len = 16 * ZBX_MEBIBYTE; } s->buf_stat[read_bytes] = '/0'; if (0 != (flags & ZBX_TCP_READ_UNTIL_CLOSE)) { if (0 == nbytes) goto cleanup; } else { if (nbytes < left) goto cleanup; } left = sizeof(s->buf_stat) - read_bytes - 1; /* check for an empty socket if exactly ZBX_TCP_HEADER_LEN bytes (without a header) were sent */ if (0 == read_bytes || '/n' != s->buf_stat[read_bytes - 1]) /* requests to passive agents end with '/n' */ { /* fill static buffer */ while (read_bytes < expected_len && 0 < left && ZBX_TCP_ERROR != (nbytes = ZBX_TCP_READ(s->socket, s->buf_stat + read_bytes, left))) { read_bytes += nbytes; if (0 != (flags & ZBX_TCP_READ_UNTIL_CLOSE)) { if (0 == nbytes) break; } else { if (nbytes < left) /* should we stop reading? */ {//.........这里部分代码省略.........
开发者ID:abhilash07,项目名称:agent,代码行数:101,
示例20: SYSTEM_HW_MACADDRint SYSTEM_HW_MACADDR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result){ size_t offset; int ret = SYSINFO_RET_FAIL, s, i, show_names; char *p, regex[MAX_STRING_LEN], address[MAX_STRING_LEN], buffer[MAX_STRING_LEN]; struct ifreq *ifr; struct ifconf ifc; zbx_vector_str_t addresses; if (2 < num_param(param)) return ret; if (0 != get_param(param, 1, regex, sizeof(regex)) || 0 == strcmp(regex, "all")) *regex = '/0'; if (0 != get_param(param, 2, buffer, sizeof(buffer)) || '/0' == *buffer || 0 == strcmp(buffer, "full")) show_names = 1; /* show interface names */ else if (0 == strcmp(buffer, "short")) show_names = 0; else return ret; if (-1 == (s = socket(AF_INET, SOCK_DGRAM, 0))) return ret; /* get the interface list */ ifc.ifc_len = sizeof(buffer); ifc.ifc_buf = buffer; if (-1 == ioctl(s, SIOCGIFCONF, &ifc)) goto close; ifr = ifc.ifc_req; ret = SYSINFO_RET_OK; zbx_vector_str_create(&addresses); zbx_vector_str_reserve(&addresses, 8); /* go through the list */ for (i = ifc.ifc_len / sizeof(struct ifreq); 0 < i--; ifr++) { if ('/0' != *regex && NULL == zbx_regexp_match(ifr->ifr_name, regex, NULL)) continue; if (-1 != ioctl(s, SIOCGIFFLAGS, ifr) && /* get the interface */ 0 == (ifr->ifr_flags & IFF_LOOPBACK) && /* skip loopback interface */ -1 != ioctl(s, SIOCGIFHWADDR, ifr)) /* get the MAC address */ { offset = 0; if (1 == show_names) offset += zbx_snprintf(address + offset, sizeof(address) - offset, "[%s ", ifr->ifr_name); zbx_snprintf(address + offset, sizeof(address) - offset, "%.2hx:%.2hx:%.2hx:%.2hx:%.2hx:%.2hx", (unsigned short int)(unsigned char)ifr->ifr_hwaddr.sa_data[0], (unsigned short int)(unsigned char)ifr->ifr_hwaddr.sa_data[1], (unsigned short int)(unsigned char)ifr->ifr_hwaddr.sa_data[2], (unsigned short int)(unsigned char)ifr->ifr_hwaddr.sa_data[3], (unsigned short int)(unsigned char)ifr->ifr_hwaddr.sa_data[4], (unsigned short int)(unsigned char)ifr->ifr_hwaddr.sa_data[5]); if (0 == show_names && FAIL != zbx_vector_str_search(&addresses, address, ZBX_DEFAULT_STR_COMPARE_FUNC)) continue; zbx_vector_str_append(&addresses, zbx_strdup(NULL, address)); } } offset = 0; if (0 != addresses.values_num) { zbx_vector_str_sort(&addresses, ZBX_DEFAULT_STR_COMPARE_FUNC); for (i = 0; i < addresses.values_num; i++) { if (1 == show_names && NULL != (p = strchr(addresses.values[i], ' '))) *p = ']'; offset += zbx_snprintf(buffer + offset, sizeof(buffer) - offset, "%s, ", addresses.values[i]); zbx_free(addresses.values[i]); } offset -= 2; } buffer[offset] = '/0'; if (SYSINFO_RET_OK == ret) SET_STR_RESULT(result, zbx_strdup(NULL, buffer)); zbx_vector_str_destroy(&addresses);close: close(s); return ret;}
开发者ID:nabnut,项目名称:zabbix2.0-cookies,代码行数:95,
示例21: telnet_executeint telnet_execute(ZBX_SOCKET socket_fd, const char *command, AGENT_RESULT *result, const char *encoding){ const char *__function_name = "telnet_execute"; char buf[MAX_BUFFER_LEN]; size_t sz, offset; int rc, ret = FAIL; char *command_lf = NULL, *command_crlf = NULL; size_t i, offset_lf, offset_crlf; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); /* `command' with multiple lines may contain CR+LF from the browser; */ /* it should be converted to plain LF to remove echo later on properly */ offset_lf = strlen(command); command_lf = zbx_malloc(command_lf, offset_lf + 1); zbx_strlcpy(command_lf, command, offset_lf + 1); convert_telnet_to_unix_eol(command_lf, &offset_lf); /* telnet protocol requires that end-of-line is transferred as CR+LF */ command_crlf = zbx_malloc(command_crlf, offset_lf * 2 + 1); convert_unix_to_telnet_eol(command_lf, offset_lf, command_crlf, &offset_crlf); telnet_socket_write(socket_fd, command_crlf, offset_crlf); telnet_socket_write(socket_fd, "/r/n", 2); sz = sizeof(buf); offset = 0; while (ZBX_TCP_ERROR != (rc = telnet_read(socket_fd, buf, &sz, &offset))) { if (prompt_char == telnet_lastchar(buf, offset)) break; } convert_telnet_to_unix_eol(buf, &offset); zabbix_log(LOG_LEVEL_DEBUG, "%s() command output:'%.*s'", __function_name, offset, buf); if (ZBX_TCP_ERROR == rc) { SET_MSG_RESULT(result, zbx_dsprintf(NULL, "No prompt: %s", zbx_tcp_strerror())); goto fail; } telnet_rm_echo(buf, &offset, command_lf, offset_lf); /* multi-line commands may have returned additional prompts; */ /* this is not a perfect solution, because in case of multiple */ /* multi-line shell statements these prompts might appear in */ /* the middle of the output, but we still try to be helpful by */ /* removing additional prompts at least from the beginning */ for (i = 0; i < offset_lf; i++) { if ('/n' == command_lf[i]) if (SUCCEED != telnet_rm_echo(buf, &offset, "$ ", 2) && SUCCEED != telnet_rm_echo(buf, &offset, "# ", 2) && SUCCEED != telnet_rm_echo(buf, &offset, "> ", 2) && SUCCEED != telnet_rm_echo(buf, &offset, "% ", 2)) { break; } } telnet_rm_echo(buf, &offset, "/n", 1); telnet_rm_prompt(buf, &offset); zabbix_log(LOG_LEVEL_DEBUG, "%s() stripped command output:'%.*s'", __function_name, offset, buf); if (MAX_BUFFER_LEN == offset) offset--; buf[offset] = '/0'; SET_STR_RESULT(result, convert_to_utf8(buf, offset, encoding)); ret = SUCCEED;fail: zbx_free(command_lf); zbx_free(command_crlf); zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret;}
开发者ID:0000-bigtree,项目名称:zabbix,代码行数:80,
示例22: PROC_MEM//.........这里部分代码省略......... proccomm = get_rparam(request, 3); pagesize = getpagesize(); mib[0] = CTL_KERN; if (NULL != usrinfo) { mib[2] = KERN_PROC_UID; mib[3] = usrinfo->pw_uid; } else { mib[2] = KERN_PROC_ALL; mib[3] = 0; }#ifdef KERN_PROC2 mib[1] = KERN_PROC2; mib[4] = sizeof(struct kinfo_proc2); mib[5] = 0; sz = 0; if (0 != sysctl(mib, 6, NULL, &sz, NULL, 0)) { SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain necessary buffer size from system: %s", zbx_strerror(errno))); return SYSINFO_RET_FAIL; } proc = (struct kinfo_proc2 *)zbx_malloc(proc, sz); mib[5] = (int)(sz / sizeof(struct kinfo_proc2)); if (0 != sysctl(mib, 6, proc, &sz, NULL, 0)) { zbx_free(proc); SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain process information: %s", zbx_strerror(errno))); return SYSINFO_RET_FAIL; } count = sz / sizeof(struct kinfo_proc2);#else mib[1] = KERN_PROC; sz = 0; if (0 != sysctl(mib, 4, NULL, &sz, NULL, 0)) { SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain necessary buffer size from system: %s", zbx_strerror(errno))); return SYSINFO_RET_FAIL; } proc = (struct kinfo_proc *)zbx_malloc(proc, sz); if (0 != sysctl(mib, 4, proc, &sz, NULL, 0)) { zbx_free(proc); SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain process information: %s", zbx_strerror(errno))); return SYSINFO_RET_FAIL; } count = sz / sizeof(struct kinfo_proc);#endif for (i = 0; i < count; i++) { proc_ok = 0; comm_ok = 0;
开发者ID:HupuInc,项目名称:zabbix,代码行数:67,
示例23: zabbix_logstatic 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;}
开发者ID:HupuInc,项目名称:zabbix,代码行数:81,
示例24: housekeeping_cleanup/****************************************************************************** * * * Function: housekeeping_cleanup * * * * Purpose: remove deleted items data * * * * Return value: number of rows deleted * * * * Author: Alexei Vladishev, Dmitry Borovikov * * * * Comments: sqlite3 does not use CONFIG_MAX_HOUSEKEEPER_DELETE, deletes all * * * ******************************************************************************/static int housekeeping_cleanup(){ const char *__function_name = "housekeeping_cleanup"; DB_HOUSEKEEPER housekeeper; DB_RESULT result; DB_ROW row; int d, deleted = 0; zbx_vector_uint64_t housekeeperids; char *sql = NULL, *table_name_esc; size_t sql_alloc = 0, sql_offset = 0; zbx_hk_cleanup_table_t *table; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); /* first handle the trivial case when history and trend housekeeping is disabled */ if (ZBX_HK_OPTION_DISABLED == hk_config.history_mode && ZBX_HK_OPTION_DISABLED == hk_config.trends_mode) goto out; zbx_vector_uint64_create(&housekeeperids); zbx_strcpy_alloc(&sql, &sql_alloc, &sql_offset, "select housekeeperid,tablename,field,value" " from housekeeper" " where tablename in ("); /* assemble list of tables excluded from housekeeping procedure */ for (table = hk_cleanup_tables; NULL != table->name; table++) { if (ZBX_HK_OPTION_ENABLED != *table->poption_mode) continue; table_name_esc = DBdyn_escape_string(table->name); zbx_chrcpy_alloc(&sql, &sql_alloc, &sql_offset, '/''); zbx_strcpy_alloc(&sql, &sql_alloc, &sql_offset, table_name_esc); zbx_strcpy_alloc(&sql, &sql_alloc, &sql_offset, "',"); zbx_free(table_name_esc); } sql_offset--; /* order by tablename to effectively use DB cache */ zbx_strcpy_alloc(&sql, &sql_alloc, &sql_offset, ") order by tablename"); result = DBselect("%s", sql); while (NULL != (row = DBfetch(result))) { ZBX_STR2UINT64(housekeeper.housekeeperid, row[0]); housekeeper.tablename = row[1]; housekeeper.field = row[2]; ZBX_STR2UINT64(housekeeper.value, row[3]); if (0 == CONFIG_MAX_HOUSEKEEPER_DELETE) { d = DBexecute( "delete from %s" " where %s=" ZBX_FS_UI64, housekeeper.tablename, housekeeper.field, housekeeper.value); } else {#if defined(HAVE_IBM_DB2) || defined(HAVE_ORACLE) d = DBexecute( "delete from %s" " where %s=" ZBX_FS_UI64 " and rownum<=%d", housekeeper.tablename, housekeeper.field, housekeeper.value, CONFIG_MAX_HOUSEKEEPER_DELETE);#elif defined(HAVE_MYSQL) d = DBexecute( "delete from %s" " where %s=" ZBX_FS_UI64 " limit %d", housekeeper.tablename, housekeeper.field, housekeeper.value, CONFIG_MAX_HOUSEKEEPER_DELETE);#elif defined(HAVE_POSTGRESQL) d = DBexecute( "delete from %s" " where ctid = any(array(select ctid from %s" " where %s=" ZBX_FS_UI64 " limit %d))",//.........这里部分代码省略.........
开发者ID:0000-bigtree,项目名称:zabbix,代码行数:101,
示例25: send_list_of_active_checks_json/****************************************************************************** * * * Function: send_list_of_active_checks_json * * * * Purpose: send list of active checks to the host * * * * Parameters: sock - open socket of server-agent connection * * json - request buffer * * * * Return value: SUCCEED - list of active checks sent succesfully * * FAIL - an error occured * * * * Author: Aleksander Vladishev * * * * Comments: * * * ******************************************************************************/int send_list_of_active_checks_json(zbx_sock_t *sock, struct zbx_json_parse *jp){ char host[HOST_HOST_LEN_MAX], *name_esc, params[MAX_STRING_LEN], pattern[MAX_STRING_LEN], tmp[32]; DB_RESULT result; DB_ROW row; DB_ITEM item; struct zbx_json json; int res = FAIL; zbx_uint64_t hostid; char error[MAX_STRING_LEN]; char **regexp = NULL; int regexp_alloc = 32; int regexp_num = 0, n; char *sql = NULL; int sql_alloc = 2048; int sql_offset; zabbix_log(LOG_LEVEL_DEBUG, "In send_list_of_active_checks_json()"); if (FAIL == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_HOST, host, sizeof(host))) { zbx_snprintf(error, MAX_STRING_LEN, "%s", zbx_json_strerror()); goto out; } if (FAIL == get_hostid_by_host(host, &hostid, error)) goto out; regexp = zbx_malloc(regexp, regexp_alloc); sql = zbx_malloc(sql, sql_alloc); name_esc = DBdyn_escape_string(host); sql_offset = 0; zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, 1024, "select %s where i.hostid=h.hostid and h.status=%d and i.type=%d and h.hostid=" ZBX_FS_UI64 " and h.proxy_hostid=0", ZBX_SQL_ITEM_SELECT, HOST_STATUS_MONITORED, ITEM_TYPE_ZABBIX_ACTIVE, hostid); if (0 != CONFIG_REFRESH_UNSUPPORTED) zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, 256, " and (i.status=%d or (i.status=%d and i.nextcheck<=%d))", ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED, time(NULL)); else zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, 256, " and i.status=%d", ITEM_STATUS_ACTIVE); zbx_free(name_esc); zbx_json_init(&json, ZBX_JSON_STAT_BUF_LEN); zbx_json_addstring(&json, ZBX_PROTO_TAG_RESPONSE, ZBX_PROTO_VALUE_SUCCESS, ZBX_JSON_TYPE_STRING); zbx_json_addarray(&json, ZBX_PROTO_TAG_DATA); result = DBselect("%s", sql); while (NULL != (row = DBfetch(result))) { DBget_item_from_db(&item, row); zbx_json_addobject(&json, NULL); zbx_json_addstring(&json, ZBX_PROTO_TAG_KEY, item.key, ZBX_JSON_TYPE_STRING); if (0 != strcmp(item.key, item.key_orig)) zbx_json_addstring(&json, ZBX_PROTO_TAG_KEY_ORIG, item.key_orig, ZBX_JSON_TYPE_STRING); zbx_snprintf(tmp, sizeof(tmp), "%d", item.delay); zbx_json_addstring(&json, ZBX_PROTO_TAG_DELAY, tmp, ZBX_JSON_TYPE_STRING); zbx_snprintf(tmp, sizeof(tmp), "%d", item.lastlogsize); zbx_json_addstring(&json, ZBX_PROTO_TAG_LOGLASTSIZE, tmp, ZBX_JSON_TYPE_STRING); zbx_json_close(&json); /* Special processing for log[] and eventlog[] items */ do { /* simple try realization */ if (0 != strncmp(item.key, "log[", 4) && 0 != strncmp(item.key, "eventlog[", 9)) break; if (2 != parse_command(item.key, NULL, 0, params, MAX_STRING_LEN)) break;; if (0 != get_param(params, 2, pattern, sizeof(pattern)))//.........这里部分代码省略.........
开发者ID:rennhak,项目名称:zabbix,代码行数:101,
示例26: DMcollect_table_data//.........这里部分代码省略......... zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, " from %s where %s=%s", table->table, table->recid, row[0]); result2 = DBselect("%s", sql); if (NULL == (row2 = DBfetch(result2))) goto out; zbx_snprintf_alloc(data, data_alloc, data_offset, "/n%s%c%s%c%d", table->table, ZBX_DM_DELIMITER, row[0], ZBX_DM_DELIMITER, NODE_CONFIGLOG_OP_UPDATE); prev_cksum = DBis_null(row[1]) == SUCCEED ? NULL : row[1]; curr_cksum = row[2]; s = sync; f = 0; j = 0; do { while (0 == (table->fields[f].flags & ZBX_SYNC)) f++; d_prev_cksum = NULL; if (NULL != prev_cksum && NULL != (d_prev_cksum = strchr(prev_cksum, ','))) *d_prev_cksum = '/0'; d_curr_cksum = NULL; if (NULL != curr_cksum && NULL != (d_curr_cksum = strchr(curr_cksum, ','))) *d_curr_cksum = '/0'; if (NULL == prev_cksum || NULL == curr_cksum || ZBX_REC_UPDATED != s[dest_nodetype] || 0 != strcmp(prev_cksum, curr_cksum)) { /* fieldname, type */ zbx_snprintf_alloc(data, data_alloc, data_offset, "%c%s%c%d%c", ZBX_DM_DELIMITER, table->fields[f].name, ZBX_DM_DELIMITER, table->fields[f].type, ZBX_DM_DELIMITER); /* value */ if (SUCCEED == DBis_null(row2[j])) { zbx_strcpy_alloc(data, data_alloc, data_offset, "NULL"); } else if (ZBX_TYPE_INT == table->fields[f].type || ZBX_TYPE_UINT == table->fields[f].type || ZBX_TYPE_ID == table->fields[f].type || ZBX_TYPE_FLOAT == table->fields[f].type) { zbx_strcpy_alloc(data, data_alloc, data_offset, row2[j]); } else { if (table->fields[f].type == ZBX_TYPE_BLOB) rowlen = (size_t)atoi(row2[j + 1]); else rowlen = strlen(row2[j]); zbx_binary2hex((u_char *)row2[j], rowlen, &hex, &hex_alloc); zbx_strcpy_alloc(data, data_alloc, data_offset, hex); } if (table->fields[f].type == ZBX_TYPE_BLOB) j += 2; else j++; } /* "host_inventory" table has more than 64 fields */ /* remaining fields are processed as one */ if (126 > s - sync) s += 2; f++; if (d_prev_cksum != NULL) { *d_prev_cksum = ','; prev_cksum = d_prev_cksum + 1; } else prev_cksum = NULL; if (d_curr_cksum != NULL) { *d_curr_cksum = ','; curr_cksum = d_curr_cksum + 1; } else curr_cksum = NULL; } while (NULL != d_prev_cksum || NULL != d_curr_cksum);out: DBfree_result(result2); } DBfree_result(result); zbx_free(hex); zbx_free(sql); zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);}
开发者ID:nabnut,项目名称:zabbix2.0-cookies,代码行数:101,
示例27: send_list_of_active_checks/****************************************************************************** * * * Function: send_list_of_active_checks * * * * Purpose: send list of active checks to the host * * * * Parameters: sock - open socket of server-agent connection * * request - request buffer * * * * Return value: SUCCEED - list of active checks sent succesfully * * FAIL - an error occured * * * * Author: Alexei Vladishev * * * * Comments: format of the request: ZBX_GET_ACTIVE_CHECKS/n<host name>/n * * format of the list: key:delay:last_log_size * * * ******************************************************************************/int send_list_of_active_checks(zbx_sock_t *sock, char *request){ char *host = NULL, *p; DB_RESULT result; DB_ROW row; char *buffer = NULL; int buffer_alloc = 2048; int buffer_offset = 0; int res = FAIL; zbx_uint64_t hostid; char error[MAX_STRING_LEN]; zabbix_log(LOG_LEVEL_DEBUG, "In send_list_of_active_checks()"); if (NULL != (host = strchr(request, '/n'))) { host++; if (NULL != (p = strchr(host, '/n'))) *p = '/0'; } else { zbx_snprintf(error, MAX_STRING_LEN, "host is null"); goto out; } if (FAIL == get_hostid_by_host(host, &hostid, error)) goto out; buffer = zbx_malloc(buffer, buffer_alloc); buffer_offset = 0; zbx_snprintf_alloc(&buffer, &buffer_alloc, &buffer_offset, 1024, "select i.key_,i.delay,i.lastlogsize from items i,hosts h" " where i.hostid=h.hostid and h.status=%d and i.type=%d and h.hostid=" ZBX_FS_UI64 " and h.proxy_hostid=0", HOST_STATUS_MONITORED, ITEM_TYPE_ZABBIX_ACTIVE, hostid); if (0 != CONFIG_REFRESH_UNSUPPORTED) { zbx_snprintf_alloc(&buffer, &buffer_alloc, &buffer_offset, 256, " and (i.status=%d or (i.status=%d and i.nextcheck<=%d))", ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED, time(NULL)); } else { zbx_snprintf_alloc(&buffer, &buffer_alloc, &buffer_offset, 256, " and i.status=%d", ITEM_STATUS_ACTIVE); } result = DBselect("%s", buffer); buffer_offset = 0; while (NULL != (row = DBfetch(result))) { zbx_snprintf_alloc(&buffer, &buffer_alloc, &buffer_offset, 512, "%s:%s:%s/n", row[0], row[1], row[2]); } DBfree_result(result); zbx_snprintf_alloc(&buffer, &buffer_alloc, &buffer_offset, 512, "ZBX_EOF/n"); zabbix_log(LOG_LEVEL_DEBUG, "Sending [%s]", buffer); if (SUCCEED != zbx_tcp_send_raw(sock, buffer)) zbx_snprintf(error, MAX_STRING_LEN, "%s", zbx_tcp_strerror()); else res = SUCCEED; zbx_free(buffer);out: if (FAIL == res) zabbix_log(LOG_LEVEL_WARNING, "Send list of active checks to [%s] failed: %s", get_ip_by_socket(sock), error); return res;}
开发者ID:rennhak,项目名称:zabbix,代码行数:100,
示例28: update_checksums//.........这里部分代码省略......... s += 2; } else { r[0] = SUCCEED == DBis_null(row[2]) ? NULL : row[2]; r[1] = row[3]; f = 0; do { while ((table->fields[f].flags & ZBX_SYNC) == 0) f++; /* "host_inventory" table has more than 64 fields */ /* remaining fields are processed as one */ if (128 == s - sync) s -= 2; d[0] = NULL; d[1] = NULL; if (NULL != r[0] && NULL != (d[0] = strchr(r[0], ','))) *d[0] = '/0'; if (NULL != r[1] && NULL != (d[1] = strchr(r[1], ','))) *d[1] = '/0'; if (NULL == tablename || SUCCEED == str_in_list(fields, table->fields[f].name, ',')) { ck += zbx_snprintf(ck, 64, "%s,", NULL != r[1] ? r[1] : r[0]); if (NULL == r[0] || NULL == r[1] || 0 != strcmp(r[0], r[1])) { s[0] = s[1] = ' '; s[synked_nodetype] = c[0]; } else { if (SUCCEED == synked) s[synked_nodetype] = c[0]; } } else ck += zbx_snprintf(ck, 64, "%s,", NULL != r[0] ? r[0] : ""); s += 2; f++; if (d[0] != NULL) { *d[0] = ','; r[0] = d[0] + 1; } else r[0] = NULL; if (d[1] != NULL) { *d[1] = ','; r[1] = d[1] + 1; } else r[1] = NULL; } while (d[0] != NULL || d[1] != NULL); *--ck = '/0'; } *s = '/0'; if (SUCCEED == DBis_null(row[2]) || SUCCEED == DBis_null(row[3]) || 0 != strcmp(row[4], sync) || 0 != strcmp(row[2], row[3])) { cksumtype = (DBis_null(row[2]) == SUCCEED) ? NODE_CKSUM_TYPE_NEW : NODE_CKSUM_TYPE_OLD; zbx_snprintf_alloc(&exsql, &exsql_alloc, &exsql_offset, "update node_cksum" " set cksumtype=%d," "cksum='%s'," "sync='%s'" " where nodeid=%d" " and cksumtype=%d" " and tablename='%s'" " and recordid=%s;/n", NODE_CKSUM_TYPE_OLD, cksum, sync, nodeid, cksumtype, row[0], row[1]); DBexecute_overflowed_sql(&exsql, &exsql_alloc, &exsql_offset); } } DBfree_result(result); DBend_multiple_update(&exsql, &exsql_alloc, &exsql_offset); if (exsql_offset > 16) /* In ORACLE always present begin..end; */ DBexecute("%s", exsql); zbx_free(exsql); DBcommit(); zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name); return SUCCEED;}
开发者ID:nabnut,项目名称:zabbix2.0-cookies,代码行数:101,
示例29: zbx_db_connect/****************************************************************************** * * * Function: zbx_db_connect * * * * Purpose: connect to the database * * * * Return value: ZBX_DB_OK - succefully connected * * ZBX_DB_DOWN - database is down * * ZBX_DB_FAIL - failed to connect * * * ******************************************************************************/int zbx_db_connect(char *host, char *user, char *password, char *dbname, char *dbschema, char *dbsocket, int port){ int ret = ZBX_DB_OK;#if defined(HAVE_IBM_DB2) char *connect = NULL;#elif defined(HAVE_ORACLE) char *connect = NULL; sword err = OCI_SUCCESS;#elif defined(HAVE_POSTGRESQL) char *cport = NULL; DB_RESULT result; DB_ROW row;#endif txn_init = 1; assert(NULL != host);#if defined(HAVE_IBM_DB2) connect = zbx_strdup(connect, "PROTOCOL=TCPIP;"); if ('/0' != *host) connect = zbx_strdcatf(connect, "HOSTNAME=%s;", host); if (NULL != dbname && '/0' != *dbname) connect = zbx_strdcatf(connect, "DATABASE=%s;", dbname); if (0 != port) connect = zbx_strdcatf(connect, "PORT=%d;", port); if (NULL != user && '/0' != *user) connect = zbx_strdcatf(connect, "UID=%s;", user); if (NULL != password && '/0' != *password) connect = zbx_strdcatf(connect, "PWD=%s;", password); memset(&ibm_db2, 0, sizeof(ibm_db2)); /* allocate an environment handle */ if (SUCCEED != zbx_ibm_db2_success(SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &ibm_db2.henv))) ret = ZBX_DB_FAIL; /* set attribute to enable application to run as ODBC 3.0 application; */ /* recommended for pure IBM DB2 CLI, but not required */ if (ZBX_DB_OK == ret && SUCCEED != zbx_ibm_db2_success(SQLSetEnvAttr(ibm_db2.henv, SQL_ATTR_ODBC_VERSION, (void *)SQL_OV_ODBC3, 0))) ret = ZBX_DB_FAIL; /* allocate a database connection handle */ if (ZBX_DB_OK == ret && SUCCEED != zbx_ibm_db2_success(SQLAllocHandle(SQL_HANDLE_DBC, ibm_db2.henv, &ibm_db2.hdbc))) ret = ZBX_DB_FAIL; /* connect to the database */ if (ZBX_DB_OK == ret && SUCCEED != zbx_ibm_db2_success(SQLDriverConnect(ibm_db2.hdbc, NULL, (SQLCHAR *)connect, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT))) ret = ZBX_DB_FAIL; /* set autocommit on */ if (ZBX_DB_OK == ret && SUCCEED != zbx_ibm_db2_success(SQLSetConnectAttr(ibm_db2.hdbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_ON, SQL_NTS))) ret = ZBX_DB_DOWN; /* we do not generate vendor escape clause sequences */ if (ZBX_DB_OK == ret && SUCCEED != zbx_ibm_db2_success(SQLSetConnectAttr(ibm_db2.hdbc, SQL_ATTR_NOSCAN, (SQLPOINTER)SQL_NOSCAN_ON, SQL_NTS))) ret = ZBX_DB_DOWN; /* set current schema */ if (NULL != dbschema && '/0' != *dbschema && ZBX_DB_OK == ret) { char *dbschema_esc; dbschema_esc = DBdyn_escape_string(dbschema); DBexecute("set current schema='%s'", dbschema_esc); zbx_free(dbschema_esc); } /* output error information */ if (ZBX_DB_OK != ret) { zbx_ibm_db2_log_errors(SQL_HANDLE_ENV, ibm_db2.henv); zbx_ibm_db2_log_errors(SQL_HANDLE_DBC, ibm_db2.hdbc); zbx_db_close(); } zbx_free(connect);#elif defined(HAVE_MYSQL) conn = mysql_init(NULL); if (!mysql_real_connect(conn, host, user, password, dbname, port, dbsocket, CLIENT_MULTI_STATEMENTS)) { zabbix_errlog(ERR_Z3001, dbname, mysql_errno(conn), mysql_error(conn));//.........这里部分代码省略.........
开发者ID:hatta0713,项目名称:jobarranger,代码行数:101,
注:本文中的zbx_free函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ zbx_json_addstring函数代码示例 C++ zbx_error函数代码示例 |