int WEB_PAGE_REGEXP(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char hostname[MAX_STRING_LEN]; char path[MAX_STRING_LEN]; char port_str[8]; char regexp[MAX_STRING_LEN]; char len_str[16]; char back[MAX_BUFFER_LEN]; char *buffer = NULL, *found; int len, found_len; if (num_param(param) > 5) return SYSINFO_RET_FAIL; if (0 != get_param(param, 1, hostname, sizeof(hostname))) return SYSINFO_RET_FAIL; if (0 != get_param(param, 2, path, sizeof(path))) *path = '\0'; if (0 != get_param(param, 3, port_str, sizeof(port_str)) || '\0' == *port_str) zbx_snprintf(port_str, sizeof(port_str), "%d", ZBX_DEFAULT_HTTP_PORT); else if (FAIL == is_uint(port_str)) return SYSINFO_RET_FAIL; if (0 != get_param(param, 4, regexp, sizeof(regexp))) return SYSINFO_RET_FAIL; if (0 != get_param(param, 5, len_str, sizeof(len_str)) || '\0' == *len_str) zbx_snprintf(len_str, sizeof(len_str), "%d", MAX_BUFFER_LEN - 1); else if (FAIL == is_uint(len_str)) return SYSINFO_RET_FAIL; buffer = zbx_malloc(buffer, ZBX_MAX_WEBPAGE_SIZE); if (SYSINFO_RET_OK == get_http_page(hostname, path, (unsigned short)atoi(port_str), buffer, ZBX_MAX_WEBPAGE_SIZE)) { if (NULL != (found = zbx_regexp_match(buffer, regexp, &found_len))) { len = atoi(len_str) + 1; len = MIN(len, found_len + 1); len = MIN(len, sizeof(back)); zbx_strlcpy(back, found, len); SET_STR_RESULT(result, strdup(back)); } else SET_STR_RESULT(result, strdup("EOF")); } else SET_STR_RESULT(result, strdup("EOF")); zbx_free(buffer); return SYSINFO_RET_OK; }
var_t operator() (ti_atomic_t ta) const { if (ta == TI_INT && is_uint(v_) && boost::get<unsigned int>(v_) <= INT_MAX) { return int(boost::get<unsigned int>(v_)); } if (ta == TI_DOUBLE && is_uint(v_)) { return double(boost::get<unsigned int>(v_)); } if (ta == TI_DOUBLE && is_int(v_)) { return double(boost::get<int>(v_)); } return v_; }
int WEB_PAGE_PERF(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char hostname[MAX_STRING_LEN]; char path[MAX_STRING_LEN]; char port_str[8]; double start_time; if (num_param(param) > 3) return SYSINFO_RET_FAIL; if (0 != get_param(param, 1, hostname, sizeof(hostname))) return SYSINFO_RET_FAIL; if (0 != get_param(param, 2, path, sizeof(path))) *path = '\0'; if (0 != get_param(param, 3, port_str, sizeof(port_str)) || '\0' == *port_str) zbx_snprintf(port_str, sizeof(port_str), "%d", ZBX_DEFAULT_HTTP_PORT); else if (FAIL == is_uint(port_str)) return SYSINFO_RET_FAIL; start_time = zbx_time(); if (SYSINFO_RET_OK == get_http_page(hostname, path, (unsigned short)atoi(port_str), NULL, 0)) { SET_DBL_RESULT(result, zbx_time() - start_time); } else SET_DBL_RESULT(result, 0.0); return SYSINFO_RET_OK; }
int WEB_PAGE_GET(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char hostname[MAX_STRING_LEN]; char path[MAX_STRING_LEN]; char port_str[8]; char buffer[MAX_BUFFER_LEN]; if (num_param(param) > 3) return SYSINFO_RET_FAIL; if (0 != get_param(param, 1, hostname, sizeof(hostname))) return SYSINFO_RET_FAIL; if (0 != get_param(param, 2, path, sizeof(path))) *path = '\0'; if (0 != get_param(param, 3, port_str, sizeof(port_str)) || '\0' == *port_str) zbx_snprintf(port_str, sizeof(port_str), "%d", ZBX_DEFAULT_HTTP_PORT); else if (FAIL == is_uint(port_str)) return SYSINFO_RET_FAIL; if (SYSINFO_RET_OK == get_http_page(hostname, path, (unsigned short)atoi(port_str), buffer, sizeof(buffer))) { zbx_rtrim(buffer, "\r\n"); SET_TEXT_RESULT(result, strdup(buffer)); } else SET_TEXT_RESULT(result, strdup("EOF")); return SYSINFO_RET_OK; }
int SYSTEM_CPU_UTIL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char tmp[16]; int cpu_num, state, mode; if (3 < num_param(param)) return SYSINFO_RET_FAIL; if (0 != get_param(param, 1, tmp, sizeof(tmp)) || '\0' == *tmp || 0 == strcmp(tmp, "all")) cpu_num = 0; else if (SUCCEED != is_uint(tmp) || 1 > (cpu_num = atoi(tmp) + 1)) return SYSINFO_RET_FAIL; if (0 != get_param(param, 2, tmp, sizeof(tmp)) || '\0' == *tmp || 0 == strcmp(tmp, "user")) state = ZBX_CPU_STATE_USER; else if (0 == strcmp(tmp, "iowait")) state = ZBX_CPU_STATE_IOWAIT; else if (0 == strcmp(tmp, "system")) state = ZBX_CPU_STATE_SYSTEM; else if (0 == strcmp(tmp, "idle")) state = ZBX_CPU_STATE_IDLE; else return SYSINFO_RET_FAIL; if (0 != get_param(param, 3, tmp, sizeof(tmp)) || '\0' == *tmp || 0 == strcmp(tmp, "avg1")) mode = ZBX_AVG1; else if (0 == strcmp(tmp, "avg5")) mode = ZBX_AVG5; else if (0 == strcmp(tmp, "avg15")) mode = ZBX_AVG15; else return SYSINFO_RET_FAIL; return get_cpustat(result, cpu_num, state, mode); }
/** * Get image samples per line from PDS scalar. * @param [in] scalar PDS scalar. * @param [in] payload PDS parser payload containing the image structure to initialize. * @return 1 if the LINE_SAMPLES attributes contains an unsigned integer, 0 otherwise. */ int image_samples_per_line(const PDS_scalar *scalar, PDS_payload *payload) { if(!is_uint(scalar)) { return 0; } payload->image.samples_per_line = (size_t)scalar->integer.value; return 1; }
/** * Get record size from scalar. * @param [in] scalar PDS scalar. * @param [out] payload PDS parser payload. * @return 0 if the PDS scalar is not an integer, 1 otherwise. */ int record_size(const PDS_scalar *scalar, PDS_payload *payload) { if(!is_uint(scalar)) { return 0; } payload->record_size = (size_t)scalar->integer.value; return 1; }
/** * Get image band count from PDS scalar. * @param [in] scalar PDS scalar. * @param [in] payload PDS parser payload containing the image structure to initialize. * @return 1 if BANDS attributes contains an unsigned integer, 0 otherwise. */ int image_bands(const PDS_scalar *scalar, PDS_payload *payload) { if(!is_uint(scalar)) { return 0; } payload->image.bands = (size_t)scalar->integer.value; return 1; }
/* function 'parse_ipmi_command' requires 'c_name' with size 'ITEM_IPMI_SENSOR_LEN_MAX' */ int parse_ipmi_command(const char *command, char *c_name, int *val, char *error, size_t max_error_len) { const char *__function_name = "parse_ipmi_command"; const char *p; size_t sz_c_name; int ret = FAIL; zabbix_log(LOG_LEVEL_DEBUG, "In %s() command:'%s'", __function_name, command); while ('\0' != *command && NULL != strchr(" \t", *command)) command++; for (p = command; '\0' != *p && NULL == strchr(" \t", *p); p++) ; if (0 == (sz_c_name = p - command)) { zbx_strlcpy(error, "IPMI command is empty", max_error_len); goto fail; } if (ITEM_IPMI_SENSOR_LEN_MAX <= sz_c_name) { zbx_snprintf(error, max_error_len, "IPMI command is too long [%.*s]", sz_c_name, command); goto fail; } memcpy(c_name, command, sz_c_name); c_name[sz_c_name] = '\0'; while ('\0' != *p && NULL != strchr(" \t", *p)) p++; if ('\0' == *p || 0 == strcasecmp(p, "on")) *val = 1; else if (0 == strcasecmp(p, "off")) *val = 0; else if (SUCCEED == is_uint(p)) *val = atoi(p); else { zbx_snprintf(error, max_error_len, "IPMI command value is not supported [%s]", p); goto fail; } ret = SUCCEED; fail: zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
/* Pattern: 1 [VRICLD]<uint> 2 <uint> 3 <float> */ int token_check( char *token, int pattern ) { int status = 0; char c; switch (pattern) { case 1: c = *token++; if (is_elem( c ) && is_end(is_uint( token ))) status = 1; break; case 2: if (is_end(is_uint( token ))) status = 1; break; case 3: if (is_end(is_digits(is_char_eq(is_int( token ), '.')))) status = 1; break; } return status; }
bool operator() (ti_atomic_t ta) const { switch (ta) { case TI_BOOL: if (is_bool(v_)) return true; break; case TI_INT: if (is_int(v_)) return true; break; case TI_UINT: if (is_uint(v_)) return true; break; case TI_DOUBLE: if (is_double(v_)) return true; break; case TI_STRING: if (is_string(v_)) return true; break; case TI_TIME: if (is_time(v_)) return true; break; case TI_IPV4ADDR: if (is_ipv4addr(v_)) return true; break; case TI_IPV6ADDR: if (is_ipv6addr(v_)) return true; break; default: assert(false); } return false; }
void Flag::print_as_flag(outputStream* st) { if (is_bool()) { st->print("-XX:%s%s", get_bool() ? "+" : "-", _name); } else if (is_int()) { st->print("-XX:%s=%d", _name, get_int()); } else if (is_uint()) { st->print("-XX:%s=%u", _name, get_uint()); } else if (is_intx()) { st->print("-XX:%s=" INTX_FORMAT, _name, get_intx()); } else if (is_uintx()) { st->print("-XX:%s=" UINTX_FORMAT, _name, get_uintx()); } else if (is_uint64_t()) { st->print("-XX:%s=" UINT64_FORMAT, _name, get_uint64_t()); } else if (is_size_t()) { st->print("-XX:%s=" SIZE_FORMAT, _name, get_size_t()); } else if (is_double()) { st->print("-XX:%s=%f", _name, get_double()); } else if (is_ccstr()) { st->print("-XX:%s=", _name); const char* cp = get_ccstr(); if (cp != NULL) { // Need to turn embedded '\n's back into separate arguments // Not so efficient to print one character at a time, // but the choice is to do the transformation to a buffer // and print that. And this need not be efficient. for (; *cp != '\0'; cp += 1) { switch (*cp) { default: st->print("%c", *cp); break; case '\n': st->print(" -XX:%s=", _name); break; } } } } else { ShouldNotReachHere(); } }
int parse_ipmi_command(char *command, char **c_name, int *val) { char *p; zabbix_log(LOG_LEVEL_DEBUG, "In parse_ipmi_command(%s)", command); if (0 != strncmp(command, "IPMI", 4)) return FAIL; p = command + 4; while (*p == ' ' && *p != '\0') p++; *c_name = p; *val = 1; if (NULL != (p = strchr(p, ' '))) { *p++ = '\0'; while (*p == ' ' && *p != '\0') p++; if (*p == '\0' || 0 == strcasecmp(p, "on")) *val = 1; else if (0 == strcasecmp(p, "off")) *val = 0; else if (SUCCEED == is_uint(p)) *val = atoi(p); else { zabbix_log(LOG_LEVEL_ERR, "IPMI command Value is not supported [%s %s]", command, p); return FAIL; } } return SUCCEED; }
bool operator() (ti_atomic_t ta) const { if (!ta.c) return true; switch (ta) { case TI_BOOL: return true; case TI_INT: assert(is_int(v_)); return (is_bool(ta.c->first) || boost::get<int>(ta.c->first) <= boost::get<int>(v_)) && (is_bool(ta.c->second) || boost::get<int>(ta.c->second) >= boost::get<int>(v_)); case TI_UINT: assert(is_uint(v_)); return (is_bool(ta.c->first) || boost::get<unsigned int>(ta.c->first) <= boost::get<unsigned int>(v_)) && (is_bool(ta.c->second) || boost::get<unsigned int>(ta.c->second) >= boost::get<unsigned int>(v_)); case TI_DOUBLE: assert(is_double(v_)); return (is_bool(ta.c->first) || boost::get<double>(ta.c->first) <= boost::get<double>(v_)) && (is_bool(ta.c->second) || boost::get<double>(ta.c->second) >= boost::get<double>(v_)); case TI_STRING: return true; case TI_TIME: return true; case TI_IPV4ADDR: return true; case TI_IPV6ADDR: return true; default: assert(false); } return false; }
int SYSTEM_HW_CPU(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { int ret = SYSINFO_RET_FAIL, filter, cpu, cur_cpu = -1, offset = 0; zbx_uint64_t maxfreq = FAIL, curfreq = FAIL; char line[MAX_STRING_LEN], name[MAX_STRING_LEN], tmp[MAX_STRING_LEN], buffer[MAX_BUFFER_LEN]; FILE *f; if (2 < num_param(param)) return ret; if (0 != get_param(param, 1, tmp, sizeof(tmp)) || '\0' == *tmp || 0 == strcmp(tmp, "all")) cpu = HW_CPU_ALL_CPUS; /* show all CPUs by default */ else if (FAIL == is_uint(tmp)) return ret; else cpu = atoi(tmp); if (0 != get_param(param, 2, tmp, sizeof(tmp)) || '\0' == *tmp || 0 == strcmp(tmp, "full")) filter = HW_CPU_SHOW_ALL; /* show full info by default */ else if (0 == strcmp(tmp, "maxfreq")) filter = HW_CPU_SHOW_MAXFREQ; else if (0 == strcmp(tmp, "vendor")) filter = HW_CPU_SHOW_VENDOR; else if (0 == strcmp(tmp, "model")) filter = HW_CPU_SHOW_MODEL; else if (0 == strcmp(tmp, "curfreq")) filter = HW_CPU_SHOW_CURFREQ; else return ret; if (NULL == (f = fopen(HW_CPU_INFO_FILE, "r"))) return ret; *buffer = '\0'; while (NULL != fgets(line, sizeof(line), f)) { if (2 != sscanf(line, "%[^:]: %[^\n]", name, tmp)) continue; if (0 == strncmp(name, "processor", 9)) { if (-1 != cur_cpu && (HW_CPU_ALL_CPUS == cpu || cpu == cur_cpu)) /* print info about the previous cpu */ offset += print_freq(buffer + offset, sizeof(buffer) - offset, filter, cpu, maxfreq, curfreq); curfreq = FAIL; cur_cpu = atoi(tmp); if (HW_CPU_ALL_CPUS != cpu && cpu != cur_cpu) continue; if (HW_CPU_ALL_CPUS == cpu || HW_CPU_SHOW_ALL == filter) offset += zbx_snprintf(buffer + offset, sizeof(buffer) - offset, "\nprocessor %d:", cur_cpu); if ((HW_CPU_SHOW_ALL == filter || HW_CPU_SHOW_MAXFREQ == filter) && FAIL != (maxfreq = get_cpu_max_freq(cur_cpu))) { ret = SYSINFO_RET_OK; } } if (HW_CPU_ALL_CPUS != cpu && cpu != cur_cpu) continue; if (0 == strncmp(name, "vendor_id", 9) && (HW_CPU_SHOW_ALL == filter || HW_CPU_SHOW_VENDOR == filter)) { ret = SYSINFO_RET_OK; offset += zbx_snprintf(buffer + offset, sizeof(buffer) - offset, " %s", tmp); } else if (0 == strncmp(name, "model name", 10) && (HW_CPU_SHOW_ALL == filter || HW_CPU_SHOW_MODEL == filter)) { ret = SYSINFO_RET_OK; offset += zbx_snprintf(buffer + offset, sizeof(buffer) - offset, " %s", tmp); } else if (0 == strncmp(name, "cpu MHz", 7) && (HW_CPU_SHOW_ALL == filter || HW_CPU_SHOW_CURFREQ == filter)) { ret = SYSINFO_RET_OK; ZBX_STR2UINT64(curfreq, tmp); } } zbx_fclose(f); if (SYSINFO_RET_OK == ret) { if (-1 != cur_cpu && (HW_CPU_ALL_CPUS == cpu || cpu == cur_cpu)) /* print info about the last cpu */ offset += print_freq(buffer + offset, sizeof(buffer) - offset, filter, cpu, maxfreq, curfreq); SET_TEXT_RESULT(result, zbx_strdup(NULL, buffer + 1)); /* buf has a leading space or '\n' */ } return ret; }
double statistics::get_double_value(unsigned idx) const { SASSERT(idx < size()); SASSERT(!is_uint(idx)); return m_d_stats[idx - m_stats.size()].second; }
unsigned statistics::get_uint_value(unsigned idx) const { SASSERT(idx < size()); SASSERT(is_uint(idx)); return m_stats[idx].second; }
char const * statistics::get_key(unsigned idx) const { if (is_uint(idx)) return m_stats[idx].first; else return m_d_stats[idx - m_stats.size()].first; }
int PERF_COUNTER(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { const char *__function_name = "PERF_COUNTER"; char counterpath[PDH_MAX_COUNTER_PATH], tmp[MAX_STRING_LEN]; int ret = SYSINFO_RET_FAIL, interval; double value; PERF_COUNTER_DATA *perfs = NULL; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); if (2 < num_param(param)) goto clean; if (0 != get_param(param, 1, counterpath, sizeof(counterpath)) || '\0' == *counterpath) goto clean; if (0 != get_param(param, 2, tmp, sizeof(tmp)) || '\0' == *tmp) interval = 1; else if (FAIL == is_uint(tmp)) goto clean; else interval = atoi(tmp); if (FAIL == check_counter_path(counterpath)) goto clean; if (1 < interval) { if (!PERF_COLLECTOR_STARTED(collector)) { zabbix_log(LOG_LEVEL_DEBUG, "Collector is not started!"); goto clean; } for (perfs = collector->perfs.pPerfCounterList; NULL != perfs; perfs = perfs->next) { if (0 == strcmp(perfs->counterpath, counterpath) && perfs->interval == interval) { if (PERF_COUNTER_ACTIVE != perfs->status) break; SET_DBL_RESULT(result, compute_average_value(__function_name, perfs, USE_DEFAULT_INTERVAL)); ret = SYSINFO_RET_OK; goto clean; } } if (NULL == perfs && NULL == (perfs = add_perf_counter(NULL, counterpath, interval))) goto clean; } if (ERROR_SUCCESS == calculate_counter_value(__function_name, counterpath, &value)) { if (NULL != perfs) perfs->status = PERF_COUNTER_INITIALIZED; SET_DBL_RESULT(result, value); ret = SYSINFO_RET_OK; } clean: zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name); return ret; }
void value::set_uint(unsigned int value) { ASL_ASSERT(is_uint()); m_uint = value; }
void Flag::print_on(outputStream* st, bool withComments, bool printRanges) { // Don't print notproduct and develop flags in a product build. if (is_constant_in_binary()) { return; } if (!printRanges) { st->print("%9s %-40s %c= ", _type, _name, (!is_default() ? ':' : ' ')); if (is_bool()) { st->print("%-16s", get_bool() ? "true" : "false"); } else if (is_int()) { st->print("%-16d", get_int()); } else if (is_uint()) { st->print("%-16u", get_uint()); } else if (is_intx()) { st->print(INTX_FORMAT_W(-16), get_intx()); } else if (is_uintx()) { st->print(UINTX_FORMAT_W(-16), get_uintx()); } else if (is_uint64_t()) { st->print(UINT64_FORMAT_W(-16), get_uint64_t()); } else if (is_size_t()) { st->print(SIZE_FORMAT_W(-16), get_size_t()); } else if (is_double()) { st->print("%-16f", get_double()); } else if (is_ccstr()) { const char* cp = get_ccstr(); if (cp != NULL) { const char* eol; while ((eol = strchr(cp, '\n')) != NULL) { size_t llen = pointer_delta(eol, cp, sizeof(char)); st->print("%.*s", (int)llen, cp); st->cr(); cp = eol+1; st->print("%5s %-35s += ", "", _name); } st->print("%-16s", cp); } else st->print("%-16s", ""); } st->print("%-20s", " "); print_kind(st); #ifndef PRODUCT if (withComments) { st->print("%s", _doc); } #endif st->cr(); } else if (!is_bool() && !is_ccstr()) { if (printRanges) { st->print("%9s %-50s ", _type, _name); CommandLineFlagRangeList::print(_name, st, true); st->print(" %-20s", " "); print_kind(st); #ifndef PRODUCT if (withComments) { st->print("%s", _doc); } #endif st->cr(); } } }
static int parse_key_params(const char *key, const char *host_addr, icmpping_t *icmpping, char **addr, int *count, int *interval, int *size, int *timeout, icmppingsec_type_t *type, char *error, int max_error_len) { char cmd[16], params[MAX_STRING_LEN], buffer[MAX_STRING_LEN]; int num_params; if (0 == parse_command(key, cmd, sizeof(cmd), params, sizeof(params))) return NOTSUPPORTED; if (0 == strcmp(cmd, SERVER_ICMPPING_KEY)) { *icmpping = ICMPPING; } else if (0 == strcmp(cmd, SERVER_ICMPPINGLOSS_KEY)) { *icmpping = ICMPPINGLOSS; } else if (0 == strcmp(cmd, SERVER_ICMPPINGSEC_KEY)) { *icmpping = ICMPPINGSEC; } else { zbx_snprintf(error, max_error_len, "unsupported pinger key"); return NOTSUPPORTED; } num_params = num_param(params); if (6 < num_params || (ICMPPINGSEC != *icmpping && 5 < num_params)) { zbx_snprintf(error, max_error_len, "too many arguments"); return NOTSUPPORTED; } if (0 != get_param(params, 2, buffer, sizeof(buffer)) || '\0' == *buffer) { *count = 3; } else if (FAIL == is_uint(buffer) || MIN_COUNT > (*count = atoi(buffer)) || *count > MAX_COUNT) { zbx_snprintf(error, max_error_len, "number of packets [%s] is not between %d and %d", buffer, MIN_COUNT, MAX_COUNT); return NOTSUPPORTED; } if (0 != get_param(params, 3, buffer, sizeof(buffer)) || '\0' == *buffer) { *interval = 0; } else if (FAIL == is_uint(buffer) || MIN_INTERVAL > (*interval = atoi(buffer))) { zbx_snprintf(error, max_error_len, "interval [%s] should be at least %d", buffer, MIN_INTERVAL); return NOTSUPPORTED; } if (0 != get_param(params, 4, buffer, sizeof(buffer)) || '\0' == *buffer) { *size = 0; } else if (FAIL == is_uint(buffer) || MIN_SIZE > (*size = atoi(buffer)) || *size > MAX_SIZE) { zbx_snprintf(error, max_error_len, "packet size [%s] is not between %d and %d", buffer, MIN_SIZE, MAX_SIZE); return NOTSUPPORTED; } if (0 != get_param(params, 5, buffer, sizeof(buffer)) || '\0' == *buffer) *timeout = 0; else if (FAIL == is_uint(buffer) || MIN_TIMEOUT > (*timeout = atoi(buffer))) { zbx_snprintf(error, max_error_len, "timeout [%s] should be at least %d", buffer, MIN_TIMEOUT); return NOTSUPPORTED; } if (0 != get_param(params, 6, buffer, sizeof(buffer)) || '\0' == *buffer) *type = ICMPPINGSEC_AVG; else { if (0 == strcmp(buffer, "min")) { *type = ICMPPINGSEC_MIN; } else if (0 == strcmp(buffer, "avg")) { *type = ICMPPINGSEC_AVG; } else if (0 == strcmp(buffer, "max")) { *type = ICMPPINGSEC_MAX; } else { zbx_snprintf(error, max_error_len, "mode [%s] is not supported", buffer); return NOTSUPPORTED; } } if (0 != get_param(params, 1, buffer, sizeof(buffer)) || '\0' == *buffer) *addr = strdup(host_addr); else *addr = strdup(buffer); return SUCCEED; }
unsigned int value::get_uint() const { ASL_ASSERT(is_uint()); return (m_uint); }
int get_value_simple(DB_ITEM *item, AGENT_RESULT *result) { char *t; char c[MAX_STRING_LEN]; char param[MAX_STRING_LEN]; char error[MAX_STRING_LEN]; char service[MAX_STRING_LEN]; char service_sysinfo[MAX_STRING_LEN]; char ip[MAX_STRING_LEN]; char port[MAX_STRING_LEN]; int port_int=0; int ret = SUCCEED; char *l,*r; /* Assumption: host name does not contain '_perf' */ init_result(result); zabbix_log( LOG_LEVEL_DEBUG, "In get_value_simple([%s]", item->key); if(0 == strncmp(item->key,"service.ntp",11)) { l=strchr(item->key,'['); r=strrchr(item->key,']'); if(l==NULL || r==NULL) zbx_snprintf(c,sizeof(c),"net.tcp.service[%s]", item->key); else { zbx_strlcpy( param,l+1, r-l-1); if(item->useip==1) { zbx_snprintf(c,sizeof(c),"net.tcp.service[%s,%s]", item->key, item->host_ip); } else { zbx_snprintf(c,sizeof(c),"net.tcp.service[%s,%s]", item->key, item->host_ip); } } } else if(0 == strncmp(item->key,"dns",3)) { if(item->useip==1) { l=strchr(item->key,'['); r=strrchr(item->key,']'); if(l==NULL || r==NULL) zbx_snprintf(c,sizeof(c),"%s", item->key); else { zbx_strlcpy( param,l+1, r-l-1); /* zbx_snprintf(c,sizeof(c),"dns[%s,%s]",item->ip,param);*/ zbx_snprintf(c,sizeof(c),"dns[%s]", param); } } else { zbx_snprintf(error,sizeof(error),"You must use IP address in Host %s definition", item->host_name); zabbix_log( LOG_LEVEL_WARNING, "%s", error); result->str=strdup(error); return NOTSUPPORTED; } } else { ip[0]=0; port[0]=0; service[0]=0; if(num_param(item->key) == 1) { if(get_param(item->key, 1, service, MAX_STRING_LEN) != 0) { ret = NOTSUPPORTED; } } else if(num_param(item->key) == 2) { if(get_param(item->key, 1, service, MAX_STRING_LEN) != 0) { ret = NOTSUPPORTED; } if(get_param(item->key, 2, port, MAX_STRING_LEN) != 0) { ret = NOTSUPPORTED; } else if(is_uint(port)==SUCCEED) { port_int=atoi(port); } else { zbx_snprintf(error,sizeof(error),"Port number must be numeric in [%s]", item->key); zabbix_log( LOG_LEVEL_WARNING, "%s", error); result->str=strdup(error); ret = NOTSUPPORTED; } } else { zbx_snprintf(error,sizeof(error),"Too many parameters in [%s]", item->key); zabbix_log( LOG_LEVEL_WARNING, "%s", error); result->str=strdup(error); ret = NOTSUPPORTED; } if(ret == SUCCEED) { if(item->useip==1) { strscpy(ip,item->host_ip); } else { strscpy(ip,item->host_dns); } t = strstr(service,"_perf"); if(t != NULL) { t[0]=0; strscpy(service_sysinfo,"net.tcp.service.perf"); } else strscpy(service_sysinfo,"net.tcp.service"); if(port_int == 0) { zbx_snprintf(c,sizeof(c),"%s[%s,%s]", service_sysinfo, service, ip); } else { zbx_snprintf(c,sizeof(c),"%s[%s,%s,%d]", service_sysinfo, service, ip, port_int); } zabbix_log( LOG_LEVEL_DEBUG, "Sysinfo [%s]", c); } else { return ret; } } /* else if(NULL == strstr(item->key,"_perf")) { if(item->useip==1) { zbx_snprintf(c,sizeof(c),"net.tcp.service[%s,%s]",item->key,item->ip); } else { zbx_snprintf(c,sizeof(c),"net.tcp.service[%s,%s]",item->key,item->host); } } else { strscpy(s,item->key); t=strstr(s,"_perf"); t[0]=0; if(item->useip==1) { zbx_snprintf(c,sizeof(c),"net.tcp.service.perf[%s,%s]",s,item->ip); } else { zbx_snprintf(c,sizeof(c),"net.tcp.service.perf[%s,%s]",s,item->host); } } */ if(process(c, 0, result) == NOTSUPPORTED) { zbx_snprintf(error,sizeof(error),"Simple check [%s] is not supported", c); zabbix_log( LOG_LEVEL_WARNING, "%s", error); result->str=strdup(error); ret = NOTSUPPORTED; } return ret; }