/****************************************************************************** * * * Function: proxy_add_history * * * * Purpose: add new value to history * * * * Parameters: item - item data * * value - new value of the item * * now - new value of the item * * * * Author: Alexei Vladishev * * * * Comments: * * * ******************************************************************************/ static void proxy_add_history(DB_ITEM *item, AGENT_RESULT *value, int now) { if (value->type & AR_UINT64) zabbix_log(LOG_LEVEL_DEBUG, "In proxy_add_history(itemid:" ZBX_FS_UI64 ",key:\"%s\",value_type:%d,UINT64:"ZBX_FS_UI64")", item->itemid, item->key, item->value_type, value->ui64); if (value->type & AR_STRING) zabbix_log(LOG_LEVEL_DEBUG, "In proxy_add_history(itemid:" ZBX_FS_UI64 ",key:\"%s\",value_type:%d,STRING:%s)", item->itemid, item->key, item->value_type, value->str); if (value->type & AR_DOUBLE) zabbix_log(LOG_LEVEL_DEBUG, "In proxy_add_history(itemid:" ZBX_FS_UI64 ",key:\"%s\",value_type:%d,DOUBLE:"ZBX_FS_DBL")", item->itemid, item->key, item->value_type, value->dbl); if (value->type & AR_TEXT) zabbix_log(LOG_LEVEL_DEBUG, "In proxy_add_history(itemid: "ZBX_FS_UI64 ",key:\"%s\",value_type:%d,TEXT:[%s])", item->itemid, item->key, item->value_type, value->text); switch (item->value_type) { case ITEM_VALUE_TYPE_FLOAT: if (GET_DBL_RESULT(value)) DBproxy_add_history(item->itemid, value->dbl, now); break; case ITEM_VALUE_TYPE_STR: if (GET_STR_RESULT(value)) DBproxy_add_history_str(item->itemid, value->str, now); break; case ITEM_VALUE_TYPE_LOG: if (GET_STR_RESULT(value)) DBproxy_add_history_log(item->itemid, value->str, now, item->timestamp, item->eventlog_source, item->eventlog_severity, item->lastlogsize); break; case ITEM_VALUE_TYPE_UINT64: if (GET_UI64_RESULT(value)) DBproxy_add_history_uint(item->itemid, value->ui64, now); break; case ITEM_VALUE_TYPE_TEXT: if (GET_TEXT_RESULT(value)) DBproxy_add_history_text(item->itemid, value->str, now); break; default: zabbix_log(LOG_LEVEL_ERR, "Unknown value type [%d] for itemid [" ZBX_FS_UI64 "]", item->value_type, item->itemid); } zabbix_log( LOG_LEVEL_DEBUG, "End of proxy_add_history"); }
int check_vcenter_hv_memory_size_ballooned(AGENT_REQUEST *request, const char *username, const char *password, AGENT_RESULT *result) { int ret; ret = get_vcenter_stat(request, username, password, ZBX_OPT_MEM_BALLOONED, NULL, result); if (SYSINFO_RET_OK == ret && NULL != GET_UI64_RESULT(result)) result->ui64 = result->ui64 * ZBX_MEBIBYTE; return ret; }
int check_vcenter_vm_memory_size_shared(AGENT_REQUEST *request, const char *username, const char *password, AGENT_RESULT *result) { int ret; ret = get_vcenter_vmstat(request, username, password, ZBX_XPATH_LN2("quickStats", "sharedMemory"), result); if (SYSINFO_RET_OK == ret && NULL != GET_UI64_RESULT(result)) result->ui64 = result->ui64 * ZBX_MEBIBYTE; return ret; }
int check_vcenter_vm_cpu_usage(AGENT_REQUEST *request, const char *username, const char *password, AGENT_RESULT *result) { int ret; ret = get_vcenter_vmstat(request, username, password, ZBX_XPATH_LN2("quickStats", "overallCpuUsage"), result); if (SYSINFO_RET_OK == ret && NULL != GET_UI64_RESULT(result)) result->ui64 = result->ui64 * 1000000; return ret; }
int check_vcenter_hv_memory_used(AGENT_REQUEST *request, const char *username, const char *password, AGENT_RESULT *result) { int ret; ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_XPATH_LN2("quickStats", "overallMemoryUsage"), result); if (SYSINFO_RET_OK == ret && NULL != GET_UI64_RESULT(result)) result->ui64 = result->ui64 * ZBX_MEBIBYTE; return ret; }
int check_vcenter_hv_hw_cpu_freq(AGENT_REQUEST *request, const char *username, const char *password, AGENT_RESULT *result) { int ret; ret = get_vcenter_stat(request, username, password, ZBX_OPT_XPATH, ZBX_XPATH_LN2("hardware", "cpuMhz"), result); if (SYSINFO_RET_OK == ret && NULL != GET_UI64_RESULT(result)) result->ui64 = result->ui64 * 1000000; return ret; }
int EXECUTE_INT(const char *command, AGENT_RESULT *result) { if (SYSINFO_RET_OK != EXECUTE_STR(command, result)) return SYSINFO_RET_FAIL; if (NULL == GET_UI64_RESULT(result)) { zabbix_log(LOG_LEVEL_WARNING, "Remote command [%s] result is not unsigned integer", command); return SYSINFO_RET_FAIL; } UNSET_RESULT_EXCLUDING(result, AR_UINT64); return SYSINFO_RET_OK; }
/****************************************************************************** * * * Function: discover_service * * * * Purpose: check if service is avaiable and update database * * * * Parameters: service typ,e ip address, port number * * * * Return value: * * * * Author: Alexei Vladishev * * * * Comments: * * * ******************************************************************************/ static int discover_service(DB_DCHECK *check, char *ip, int port) { int ret = SUCCEED; char key[MAX_STRING_LEN]; AGENT_RESULT value; DB_ITEM item; struct sigaction phan; assert(check); assert(ip); zabbix_log(LOG_LEVEL_DEBUG, "In discover_service(ip:%s, port:%d, type:%d)", ip, port, check->type); init_result(&value); switch(check->type) { case SVC_SSH: zbx_snprintf(key,sizeof(key),"net.tcp.service[ssh,%s,%d]", ip, port); break; case SVC_LDAP: zbx_snprintf(key,sizeof(key),"net.tcp.service[ldap,%s,%d]", ip, port); break; case SVC_SMTP: zbx_snprintf(key,sizeof(key),"net.tcp.service[smtp,%s,%d]", ip, port); break; case SVC_FTP: zbx_snprintf(key,sizeof(key),"net.tcp.service[ftp,%s,%d]", ip, port); break; case SVC_HTTP: zbx_snprintf(key,sizeof(key),"net.tcp.service[http,%s,%d]", ip, port); break; case SVC_POP: zbx_snprintf(key,sizeof(key),"net.tcp.service[pop,%s,%d]", ip, port); break; case SVC_NNTP: zbx_snprintf(key,sizeof(key),"net.tcp.service[nntp,%s,%d]", ip, port); break; case SVC_IMAP: zbx_snprintf(key,sizeof(key),"net.tcp.service[imap,%s,%d]", ip, port); break; case SVC_TCP: zbx_snprintf(key,sizeof(key),"net.tcp.service[tcp,%s,%d]", ip, port); break; case SVC_AGENT: case SVC_SNMPv1: case SVC_SNMPv2c: break; default: ret = FAIL; break; } if(ret == SUCCEED) { phan.sa_handler = &child_signal_handler; sigemptyset(&phan.sa_mask); phan.sa_flags = 0; sigaction(SIGALRM, &phan, NULL); alarm(10); switch(check->type) { /* Agent and SNMP checks */ case SVC_AGENT: case SVC_SNMPv1: case SVC_SNMPv2c: memset(&item,0,sizeof(DB_ITEM)); strscpy(item.key,check->key_); item.host_name = ip; item.host_ip = ip; item.host_dns = ip; item.useip = 1; item.port = port; item.value_type = ITEM_VALUE_TYPE_STR; if(check->type == SVC_SNMPv1) { item.type = ITEM_TYPE_SNMPv1; } else { item.type = ITEM_TYPE_SNMPv2c; } item.snmp_oid = check->key_; item.snmp_community = check->snmp_community; item.snmp_port = port; if(check->type==SVC_AGENT) { if(SUCCEED == get_value_agent(&item, &value)) { if(GET_STR_RESULT(&value)) { strscpy(check->value, value.str); } else ret = FAIL; } else { ret = FAIL; } } else #ifdef HAVE_SNMP { if(SUCCEED == get_value_snmp(&item, &value)) { if(GET_STR_RESULT(&value)) { strscpy(check->value, value.str); } else ret = FAIL; } else { ret = FAIL; } } #else { ret = FAIL; } #endif break; /* Simple checks */ default: if(process(key, 0, &value) == SUCCEED) { if(GET_UI64_RESULT(&value)) { if(value.ui64 == 0) ret = FAIL; } else ret = FAIL; } else ret = FAIL; break; } alarm(0); } free_result(&value); zabbix_log(LOG_LEVEL_DEBUG, "End discover_service()"); return ret; }
void zbx_mock_test_entry(void **state) { AGENT_REQUEST request; AGENT_RESULT param_result; zbx_mock_error_t error; const char *init_param; zbx_mock_handle_t param_handle; const char *expected_param_value_string, *expected_return_string; zbx_uint64_t expected_param_value = 0; int expected_result = FAIL, actual_result = FAIL; ZBX_UNUSED(state); if (ZBX_MOCK_SUCCESS != (error = zbx_mock_out_parameter("return", ¶m_handle)) || ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle,&expected_return_string))) { fail_msg("Cannot get expected 'return' parameter from test case data: %s", zbx_mock_error_string(error)); } else { if (0 == strcmp("SYSINFO_RET_OK", expected_return_string)) expected_result = SYSINFO_RET_OK; else if (0 == strcmp("SYSINFO_RET_FAIL", expected_return_string)) expected_result = SYSINFO_RET_FAIL; else fail_msg("Get unexpected 'return' parameter from test case data: %s", expected_return_string); } if (ZBX_MOCK_SUCCESS != (error = zbx_mock_in_parameter("param", ¶m_handle)) || ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle, &init_param))) { fail_msg("Cannot get input 'param' from test case data: %s", zbx_mock_error_string(error)); } if (ZBX_MOCK_SUCCESS != (error = zbx_mock_out_parameter("result", ¶m_handle)) || ZBX_MOCK_SUCCESS != (error = zbx_mock_string(param_handle, &expected_param_value_string))) { fail_msg("Cannot get expected 'result' parameters from test case data: %s", zbx_mock_error_string(error)); } else { if (FAIL == is_uint64(expected_param_value_string, &expected_param_value) && SYSINFO_RET_OK == expected_result) { fail_msg("Cannot get expected numeric parameter from test case data: %s", expected_param_value_string); } } init_request(&request); init_result(¶m_result); if (SUCCEED != parse_item_key(init_param, &request)) fail_msg("Cannot parse item key: %s", init_param); if (expected_result != (actual_result = NET_IF_IN(&request,¶m_result))) { fail_msg("Got %s instead of %s as a result.", zbx_sysinfo_ret_string(actual_result), zbx_sysinfo_ret_string(expected_result)); } if (SYSINFO_RET_OK == expected_result) { if (NULL == GET_UI64_RESULT(¶m_result) || expected_param_value != *GET_UI64_RESULT(¶m_result)) { if (NULL != GET_UI64_RESULT(¶m_result)) { fail_msg("Got '" ZBX_FS_UI64 "' instead of '%s' as a value.", *GET_UI64_RESULT(¶m_result), expected_param_value_string); } else fail_msg("Got 'NULL' instead of '%s' as a value.", expected_param_value_string); } } else /* SYSINFO_RET_FAIL == expected_result */ { if (NULL == GET_MSG_RESULT(¶m_result) || 0 != strcmp(expected_param_value_string, *GET_MSG_RESULT(¶m_result))) { fail_msg("Got '%s' instead of '%s' as a value.", (NULL != GET_MSG_RESULT(¶m_result) ? *GET_MSG_RESULT(¶m_result) : "NULL"), expected_param_value_string); } } free_request(&request); free_result(¶m_result); }
/****************************************************************************** * * * Function: discover_service * * * * Purpose: check if service is available and update database * * * * Parameters: service type, ip address, port number * * * * Author: Alexei Vladishev * * * ******************************************************************************/ static int discover_service(DB_DCHECK *dcheck, char *ip, int port, char *value) { const char *__function_name = "discover_service"; int ret = SUCCEED; char key[MAX_STRING_LEN], error[ITEM_ERROR_LEN_MAX]; const char *service = NULL; AGENT_RESULT result; DC_ITEM item; ZBX_FPING_HOST host; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); init_result(&result); *value = '\0'; switch (dcheck->type) { case SVC_SSH: service = "ssh"; break; case SVC_LDAP: service = "ldap"; break; case SVC_SMTP: service = "smtp"; break; case SVC_FTP: service = "ftp"; break; case SVC_HTTP: service = "http"; break; case SVC_POP: service = "pop"; break; case SVC_NNTP: service = "nntp"; break; case SVC_IMAP: service = "imap"; break; case SVC_TCP: service = "tcp"; break; case SVC_HTTPS: service = "https"; break; case SVC_TELNET: service = "telnet"; break; case SVC_AGENT: case SVC_SNMPv1: case SVC_SNMPv2c: case SVC_SNMPv3: case SVC_ICMPPING: break; default: ret = FAIL; break; } if (SUCCEED == ret) { alarm(CONFIG_TIMEOUT); switch (dcheck->type) { /* simple checks */ case SVC_SSH: case SVC_LDAP: case SVC_SMTP: case SVC_FTP: case SVC_HTTP: case SVC_POP: case SVC_NNTP: case SVC_IMAP: case SVC_TCP: case SVC_HTTPS: case SVC_TELNET: zbx_snprintf(key, sizeof(key), "net.tcp.service[%s,%s,%d]", service, ip, port); if (SUCCEED != process(key, 0, &result) || NULL == GET_UI64_RESULT(&result) || 0 == result.ui64) { ret = FAIL; } break; /* agent and SNMP checks */ case SVC_AGENT: case SVC_SNMPv1: case SVC_SNMPv2c: case SVC_SNMPv3: memset(&item, 0, sizeof(DC_ITEM)); strscpy(item.key_orig, dcheck->key_); item.key = item.key_orig; item.interface.useip = 1; item.interface.addr = ip; item.interface.port = port; item.value_type = ITEM_VALUE_TYPE_STR; switch (dcheck->type) { case SVC_SNMPv1: item.type = ITEM_TYPE_SNMPv1; break; case SVC_SNMPv2c: item.type = ITEM_TYPE_SNMPv2c; break; case SVC_SNMPv3: item.type = ITEM_TYPE_SNMPv3; break; default: item.type = ITEM_TYPE_ZABBIX; break; } if (SVC_AGENT == dcheck->type) { if (SUCCEED == get_value_agent(&item, &result) && NULL != GET_STR_RESULT(&result)) zbx_strlcpy(value, result.str, DSERVICE_VALUE_LEN_MAX); else ret = FAIL; } else #ifdef HAVE_SNMP { item.snmp_community = strdup(dcheck->snmp_community); item.snmp_oid = strdup(dcheck->key_); substitute_simple_macros(NULL, NULL, NULL, NULL, NULL, NULL, &item.snmp_community, MACRO_TYPE_ITEM_FIELD, NULL, 0); substitute_key_macros(&item.snmp_oid, NULL, NULL, NULL, MACRO_TYPE_SNMP_OID, NULL, 0); if (ITEM_TYPE_SNMPv3 == item.type) { item.snmpv3_securityname = strdup(dcheck->snmpv3_securityname); item.snmpv3_securitylevel = dcheck->snmpv3_securitylevel; item.snmpv3_authpassphrase = strdup(dcheck->snmpv3_authpassphrase); item.snmpv3_privpassphrase = strdup(dcheck->snmpv3_privpassphrase); substitute_simple_macros(NULL, NULL, NULL, NULL, NULL, NULL, &item.snmpv3_securityname, MACRO_TYPE_ITEM_FIELD, NULL, 0); substitute_simple_macros(NULL, NULL, NULL, NULL, NULL, NULL, &item.snmpv3_authpassphrase, MACRO_TYPE_ITEM_FIELD, NULL, 0); substitute_simple_macros(NULL, NULL, NULL, NULL, NULL, NULL, &item.snmpv3_privpassphrase, MACRO_TYPE_ITEM_FIELD, NULL, 0); } if (SUCCEED == get_value_snmp(&item, &result) && NULL != GET_STR_RESULT(&result)) zbx_strlcpy(value, result.str, DSERVICE_VALUE_LEN_MAX); else ret = FAIL; zbx_free(item.snmp_community); zbx_free(item.snmp_oid); if (ITEM_TYPE_SNMPv3 == item.type) { zbx_free(item.snmpv3_securityname); zbx_free(item.snmpv3_authpassphrase); zbx_free(item.snmpv3_privpassphrase); } } #else ret = FAIL; #endif /* HAVE_SNMP */ if (FAIL == ret && ISSET_MSG(&result)) { zabbix_log(LOG_LEVEL_DEBUG, "discovery: item [%s] error: %s", item.key, result.msg); } break; case SVC_ICMPPING: memset(&host, 0, sizeof(host)); host.addr = strdup(ip); if (SUCCEED != do_ping(&host, 1, 3, 0, 0, 0, error, sizeof(error)) || 0 == host.rcv) ret = FAIL; zbx_free(host.addr); break; default: break; } alarm(0); } free_result(&result); zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
/****************************************************************************** * * * Function: update_item * * * * Purpose: update item info after new value is received * * * * Parameters: item - item data * * value - new value of the item * * now - current timestamp * * * * Author: Alexei Vladishev, Eugene Grigorjev * * * * Comments: * * * ******************************************************************************/ static void update_item(DB_ITEM *item, AGENT_RESULT *value, time_t now) { char *value_esc; zbx_uint64_t value_uint64; double value_double; zabbix_log(LOG_LEVEL_DEBUG, "In update_item()"); item->nextcheck = calculate_item_nextcheck(item->itemid, item->type, item->delay, item->delay_flex, now); switch (item->value_type) { case ITEM_VALUE_TYPE_FLOAT: if (NULL == GET_DBL_RESULT(value)) break; switch (item->delta) { /* Should we store delta or original value? */ case ITEM_STORE_AS_IS: value_double = DBmultiply_value_float(item, value->dbl); DBexecute("update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=NULL," "lastvalue='" ZBX_FS_DBL "',lastclock=%d where itemid=" ZBX_FS_UI64, item->nextcheck, value_double, (int)now, item->itemid); SET_DBL_RESULT(value, value_double); break; case ITEM_STORE_SPEED_PER_SECOND: /* Delta as speed of change */ if (0 == item->prevorgvalue_null && item->prevorgvalue_dbl <= value->dbl) { /* In order to continue normal processing, we assume difference 1 second Otherwise function update_functions and update_triggers won't work correctly*/ if (now != item->lastclock) value_double = (value->dbl - item->prevorgvalue_dbl) / (now - item->lastclock); else value_double = value->dbl - item->prevorgvalue_dbl; value_double = DBmultiply_value_float(item, value_double); DBexecute("update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue='" ZBX_FS_DBL "'," "lastvalue='" ZBX_FS_DBL "',lastclock=%d where itemid=" ZBX_FS_UI64, item->nextcheck, value->dbl, value_double, (int)now, item->itemid); SET_DBL_RESULT(value, value_double); } else { DBexecute("update items set nextcheck=%d,prevorgvalue='" ZBX_FS_DBL "',lastclock=%d where itemid=" ZBX_FS_UI64, item->nextcheck, value->dbl, (int)now, item->itemid); } break; case ITEM_STORE_SIMPLE_CHANGE: /* Real delta: simple difference between values */ if (0 == item->prevorgvalue_null && item->prevorgvalue_dbl <= value->dbl) { value_double = DBmultiply_value_float(item, value->dbl - item->prevorgvalue_dbl); DBexecute("update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue='" ZBX_FS_DBL "'," "lastvalue='" ZBX_FS_DBL "',lastclock=%d where itemid=" ZBX_FS_UI64, item->nextcheck, value->dbl, value_double, (int)now, item->itemid); SET_DBL_RESULT(value, value_double); } else { DBexecute("update items set nextcheck=%d,prevorgvalue='" ZBX_FS_DBL "',lastclock=%d where itemid=" ZBX_FS_UI64, item->nextcheck, value->dbl, (int)now, item->itemid); } break; } break; case ITEM_VALUE_TYPE_UINT64: if (NULL == GET_UI64_RESULT(value)) break; switch (item->delta) { /* Should we store delta or original value? */ case ITEM_STORE_AS_IS: value_uint64 = DBmultiply_value_uint64(item, value->ui64); DBexecute("update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=NULL," "lastvalue='" ZBX_FS_UI64 "',lastclock=%d where itemid=" ZBX_FS_UI64, item->nextcheck, value_uint64, (int)now, item->itemid); SET_UI64_RESULT(value, value_uint64); break; case ITEM_STORE_SPEED_PER_SECOND: /* Delta as speed of change */ if (0 == item->prevorgvalue_null && item->prevorgvalue_uint64 <= value->ui64) { if (now != item->lastclock) value_uint64 = (zbx_uint64_t)(value->ui64 - item->prevorgvalue_uint64) / (now - item->lastclock); else value_uint64 = value->ui64 - item->prevorgvalue_uint64; value_uint64 = DBmultiply_value_uint64(item, value_uint64); DBexecute("update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue='" ZBX_FS_UI64 "'," "lastvalue='" ZBX_FS_UI64 "',lastclock=%d where itemid=" ZBX_FS_UI64, item->nextcheck, value->ui64, value_uint64, (int)now, item->itemid); SET_UI64_RESULT(value, value_uint64); } else { DBexecute("update items set nextcheck=%d,prevorgvalue='" ZBX_FS_UI64 "',lastclock=%d where itemid=" ZBX_FS_UI64, item->nextcheck, value->ui64, (int)now, item->itemid); } break; case ITEM_STORE_SIMPLE_CHANGE: /* Real delta: simple difference between values */ if (0 == item->prevorgvalue_null && item->prevorgvalue_uint64 <= value->ui64) { value_uint64 = DBmultiply_value_uint64(item, value->ui64 - item->prevorgvalue_uint64); DBexecute("update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue='" ZBX_FS_UI64 "'," "lastvalue='" ZBX_FS_UI64 "',lastclock=%d where itemid=" ZBX_FS_UI64, item->nextcheck, value->ui64, value_uint64, (int)now, item->itemid); SET_UI64_RESULT(value, value_uint64); } else { DBexecute("update items set nextcheck=%d,prevorgvalue='" ZBX_FS_UI64 "',lastclock=%d where itemid=" ZBX_FS_UI64, item->nextcheck, value->ui64, (int)now, item->itemid); } break; } break; case ITEM_VALUE_TYPE_STR: case ITEM_VALUE_TYPE_TEXT: if (NULL == GET_STR_RESULT(value)) break; value_esc = DBdyn_escape_string_len(value->str, ITEM_LASTVALUE_LEN); DBexecute("update items set nextcheck=%d,prevvalue=lastvalue,lastvalue='%s',lastclock=%d" " where itemid=" ZBX_FS_UI64, item->nextcheck, value_esc, (int)now, item->itemid); zbx_free(value_esc); break; case ITEM_VALUE_TYPE_LOG: if (NULL == GET_STR_RESULT(value)) break; value_esc = DBdyn_escape_string_len(value->str, ITEM_LASTVALUE_LEN); DBexecute("update items set nextcheck=%d,prevvalue=lastvalue,lastvalue='%s',lastclock=%d,lastlogsize=%d" " where itemid=" ZBX_FS_UI64, item->nextcheck, value_esc, (int)now, item->lastlogsize, item->itemid); zbx_free(value_esc); break; } item->prevvalue_str = item->lastvalue_str; item->prevvalue_dbl = item->lastvalue_dbl; item->prevvalue_uint64 = item->lastvalue_uint64; item->prevvalue_null = item->lastvalue_null; item->lastvalue_uint64 = value->ui64; item->lastvalue_dbl = value->dbl; item->lastvalue_str = value->str; item->lastvalue_null = 0; /* Required for nodata() */ item->lastclock = now; /* Update item status if required */ if (item->status == ITEM_STATUS_NOTSUPPORTED) { zabbix_log( LOG_LEVEL_WARNING, "Parameter [%s] became supported by agent on host [%s]", item->key, item->host_name); zabbix_syslog("Parameter [%s] became supported by agent on host [%s]", item->key, item->host_name); item->status = ITEM_STATUS_ACTIVE; DBexecute("update items set status=%d,error='' where itemid=" ZBX_FS_UI64, item->status, item->itemid); } zabbix_log(LOG_LEVEL_DEBUG, "End of update_item()"); }
/****************************************************************************** * * * Function: add_history * * * * Purpose: add new value to history * * * * Parameters: item - item data * * value - new value of the item * * now - new value of the item * * * * Author: Alexei Vladishev * * * * Comments: * * * ******************************************************************************/ static int add_history(DB_ITEM *item, AGENT_RESULT *value, int now) { int ret = FAIL; zbx_uint64_t value_uint64; double value_double; zabbix_log(LOG_LEVEL_DEBUG, "In add_history(key:%s,value_type:%X,type:%X)", item->key, item->value_type, value->type); if (value->type & AR_UINT64) zabbix_log(LOG_LEVEL_DEBUG, "In add_history(itemid:"ZBX_FS_UI64",UINT64:"ZBX_FS_UI64")", item->itemid, value->ui64); if (value->type & AR_STRING) zabbix_log(LOG_LEVEL_DEBUG, "In add_history(itemid:"ZBX_FS_UI64",STRING:%s)", item->itemid, value->str); if (value->type & AR_DOUBLE) zabbix_log(LOG_LEVEL_DEBUG, "In add_history(itemid:"ZBX_FS_UI64",DOUBLE:"ZBX_FS_DBL")", item->itemid, value->dbl); if (value->type & AR_TEXT) zabbix_log(LOG_LEVEL_DEBUG, "In add_history(itemid:"ZBX_FS_UI64",TEXT:[%s])", item->itemid, value->text); switch (item->value_type) { case ITEM_VALUE_TYPE_FLOAT: if (NULL == GET_DBL_RESULT(value)) break; switch (item->delta) { /* Should we store delta or original value? */ case ITEM_STORE_AS_IS: if (item->history > 0) DBadd_history(item->itemid, DBmultiply_value_float(item, value->dbl), now); ret = SUCCEED; break; case ITEM_STORE_SPEED_PER_SECOND: /* Delta as speed of change */ if (0 == item->prevorgvalue_null && item->prevorgvalue_dbl <= value->dbl && item->lastclock < now) { if (item->history > 0) { value_double = (value->dbl - item->prevorgvalue_dbl) / (now - item->lastclock); DBadd_history(item->itemid, DBmultiply_value_float(item, value_double), now); } ret = SUCCEED; } break; case ITEM_STORE_SIMPLE_CHANGE: /* Real delta: simple difference between values */ if (0 == item->prevorgvalue_null && item->prevorgvalue_dbl <= value->dbl) { if (item->history > 0) DBadd_history(item->itemid, DBmultiply_value_float(item, value->dbl - item->prevorgvalue_dbl), now); ret = SUCCEED; } break; default: zabbix_log(LOG_LEVEL_ERR, "Value not stored for itemid [" ZBX_FS_UI64 "]. Unknown delta [%d]", item->itemid, item->delta); zabbix_syslog("Value not stored for itemid [" ZBX_FS_UI64 "]. Unknown delta [%d]", item->itemid, item->delta); } break; case ITEM_VALUE_TYPE_UINT64: if (NULL == GET_UI64_RESULT(value)) break; switch (item->delta) { /* Should we store delta or original value? */ case ITEM_STORE_AS_IS: if (item->history > 0) DBadd_history_uint(item->itemid, DBmultiply_value_uint64(item, value->ui64), now); ret = SUCCEED; break; case ITEM_STORE_SPEED_PER_SECOND: /* Delta as speed of change */ if (0 == item->prevorgvalue_null && item->prevorgvalue_uint64 <= value->ui64 && item->lastclock < now) { if (item->history > 0) { value_uint64 = (zbx_uint64_t)(value->ui64 - item->prevorgvalue_uint64) / (now - item->lastclock); DBadd_history_uint(item->itemid, DBmultiply_value_uint64(item, value_uint64), now); } ret = SUCCEED; } break; case ITEM_STORE_SIMPLE_CHANGE: /* Real delta: simple difference between values */ if (0 == item->prevorgvalue_null && item->prevorgvalue_uint64 <= value->ui64) { if (item->history > 0) DBadd_history_uint(item->itemid, DBmultiply_value_uint64(item, value->ui64 - item->prevorgvalue_uint64), now); ret = SUCCEED; } break; default: zabbix_log(LOG_LEVEL_ERR, "Value not stored for itemid [" ZBX_FS_UI64 "]. Unknown delta [%d]", item->itemid, item->delta); zabbix_syslog("Value not stored for itemid [" ZBX_FS_UI64 "]. Unknown delta [%d]", item->itemid, item->delta); } break; case ITEM_VALUE_TYPE_STR: if (NULL == GET_STR_RESULT(value)) break; if (item->history > 0) DBadd_history_str(item->itemid, value->str, now); ret = SUCCEED; break; case ITEM_VALUE_TYPE_LOG: if (NULL == GET_STR_RESULT(value)) break; if (item->history > 0) DBadd_history_log(item->itemid, value->str, now, item->timestamp, item->eventlog_source, item->eventlog_severity, item->lastlogsize); ret = SUCCEED; break; case ITEM_VALUE_TYPE_TEXT: if (NULL == GET_TEXT_RESULT(value)) break; if (item->history > 0) DBadd_history_text(item->itemid,value->text,now); ret = SUCCEED; break; default: zabbix_log(LOG_LEVEL_ERR, "Unknown value type [%d] for itemid [" ZBX_FS_UI64 "]", item->value_type, item->itemid); zabbix_syslog("Unknown value type [%d] for itemid [" ZBX_FS_UI64 "]", item->value_type, item->itemid); } zabbix_log(LOG_LEVEL_DEBUG, "End of add_history():%s", zbx_result_string(ret)); return ret; }