Example #1
0
File: memory.c Project: Shmuma/z
static int      VM_MEMORY_PFREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
	AGENT_RESULT	result_tmp;
	zbx_uint64_t	tot_val = 0;
	zbx_uint64_t	free_val = 0;

	assert(result);

	init_result(result);
	init_result(&result_tmp);

	if(VM_MEMORY_TOTAL(cmd, param, flags, &result_tmp) != SYSINFO_RET_OK ||
		!(result_tmp.type & AR_UINT64))
			return  SYSINFO_RET_FAIL;
	tot_val = result_tmp.ui64;

	/* Check fot division by zero */
	if(tot_val == 0)
	{
		free_result(&result_tmp);
		return  SYSINFO_RET_FAIL;
	}

	if(VM_MEMORY_FREE(cmd, param, flags, &result_tmp) != SYSINFO_RET_OK ||
		!(result_tmp.type & AR_UINT64))
			return  SYSINFO_RET_FAIL;
	free_val = result_tmp.ui64;

	free_result(&result_tmp);

	SET_DBL_RESULT(result, (100.0 * (double)free_val) / (double)tot_val);

	return SYSINFO_RET_OK;
}
Example #2
0
static int      VM_MEMORY_AVAILABLE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
	AGENT_RESULT	result_tmp;
	zbx_uint64_t	sum = 0;

	assert(result);

	init_result(result);

	init_result(&result_tmp);
	if(VM_MEMORY_FREE(cmd, param, flags, &result_tmp) != SYSINFO_RET_OK ||
		!(result_tmp.type & AR_UINT64))
			return  SYSINFO_RET_FAIL;
	sum += result_tmp.ui64;

	if(VM_MEMORY_BUFFERS(cmd, param, flags, &result_tmp) != SYSINFO_RET_OK ||
		!(result_tmp.type & AR_UINT64))
			return  SYSINFO_RET_FAIL;
	sum += result_tmp.ui64;

	if(VM_MEMORY_CACHED(cmd, param, flags, &result_tmp) != SYSINFO_RET_OK ||
		!(result_tmp.type & AR_UINT64))
			return  SYSINFO_RET_FAIL;
	sum += result_tmp.ui64;

	free_result(&result_tmp);

	SET_UI64_RESULT(result, sum);

	return SYSINFO_RET_OK;
}
Example #3
0
File: memory.c Project: Shmuma/z
static int	VM_MEMORY_BUFFERS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_BUFFERRAM
	struct sysinfo info;

	assert(result);

        init_result(result);
		
	if( 0 == sysinfo(&info))
	{
#ifdef HAVE_SYSINFO_MEM_UNIT
		SET_UI64_RESULT(result, (zbx_uint64_t)info.bufferram * (zbx_uint64_t)info.mem_unit);
#else
		SET_UI64_RESULT(result, info.bufferram);
#endif
		return SYSINFO_RET_OK;
	}
	else
	{
		return SYSINFO_RET_FAIL;
	}
#else
	assert(result);

        init_result(result);
		
	return	SYSINFO_RET_FAIL;
#endif
}
Example #4
0
int	NET_IF_COLLISIONS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
    kstat_named_t kn;
    char    if_name[MAX_STRING_LEN];
    int	    ret;

    assert(result);

    init_result(result);

    if(num_param(param) > 1)
    {
	return SYSINFO_RET_FAIL;
    }

    if(get_param(param, 1, if_name, sizeof(if_name)) != 0)
    {
	return SYSINFO_RET_FAIL;
    }

    if( SYSINFO_RET_OK == (ret = get_kstat_named_field(if_name, "collisions", &kn)) )
    {
	SET_UI64_RESULT(result, kn.value.ui32);
    }

    return ret;
}
Example #5
0
static int	NET_IF_TOTAL_ERRORS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
    kstat_named_t ikn;
    kstat_named_t okn;
    char    if_name[MAX_STRING_LEN];
    int	    ret;

    assert(result);

    init_result(result);

    if(num_param(param) > 1)
    {
	return SYSINFO_RET_FAIL;
    }

    if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
    {
	return SYSINFO_RET_FAIL;
    }

	if ( SYSINFO_RET_OK == (ret = get_kstat_named_field(if_name, "ierrors", &ikn)) &&
		SYSINFO_RET_OK == (ret = get_kstat_named_field(if_name, "oerrors", &okn)) )
			SET_UI64_RESULT(result, ikn.value.ui32 + okn.value.ui32);

    return ret;
}
Example #6
0
int	KERNEL_MAXPROC(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_FUNCTION_SYSCTL_KERN_MAXPROC
	int	mib[2];
	size_t	len;
	int	maxproc;

	assert(result);

	init_result(result);	
	
	mib[0] = CTL_KERN;
	mib[1] = KERN_MAXPROC;

	len = sizeof(maxproc);

	if (0 != sysctl(mib, 2, &maxproc, &len, NULL, 0))
		return SYSINFO_RET_FAIL;

	SET_UI64_RESULT(result, maxproc);

	return SYSINFO_RET_OK;
#else
	return	SYSINFO_RET_FAIL;
#endif
}
Example #7
0
int	SYSTEM_UPTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
	kstat_ctl_t	*kc;
	kstat_t		*kp;
	kstat_named_t	*kn;
	time_t		now;
	int		ret = SYSINFO_RET_FAIL;

	assert(result);

	init_result(result);

	if (NULL == (kc = kstat_open()))
		return ret;

	if (NULL != (kp = kstat_lookup(kc, "unix", 0, "system_misc")))
	{
		if (-1 != kstat_read(kc, kp, 0))
		{
			if (NULL != (kn = (kstat_named_t*)kstat_data_lookup(kp, "boot_time")))
			{
				time(&now);
				SET_UI64_RESULT(result, difftime(now, (time_t) kn->value.ul));
				ret = SYSINFO_RET_OK;
			}
		}
	}
	kstat_close(kc);

	return ret;
}
Example #8
0
File: cname.c Project: a1406/txgg
int main(int argc, char *argv[])
{
	size_t size;
	if (argc < 2) {
		printf("please input xls file name\n");
		return (0);
	}
	if (load_excel(argv[1]) != 0)
	{
		printf("load excel fail\n");
		return (0);		
	}
	init_result();
    /*
	size = generate_pb_data(get_data_base);

	size = cfg__npcs__pack(&result, outbuf);	
	*/
	size = cfg__name__pack(&result, outbuf);
	
	int fd = open("name.output", O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
	if (write(fd, outbuf, size) != size) {
		perror("write fail\n");
	}
	close(fd);
}
Example #9
0
int	SYSTEM_UPTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_FUNCTION_SYSCTL_KERN_BOOTTIME
	int		mib[2], now;
	size_t		len;
	struct timeval	uptime;

	assert(result);

	init_result(result);

	mib[0] = CTL_KERN;
	mib[1] = KERN_BOOTTIME;

	len = sizeof(struct timeval);

	if (0 != sysctl(mib, 2, &uptime, &len, NULL, 0))
		return SYSINFO_RET_FAIL;

	now = time(NULL);

	SET_UI64_RESULT(result, now - uptime.tv_sec);

	return SYSINFO_RET_OK;
#else
	return SYSINFO_RET_FAIL;
#endif /* HAVE_FUNCTION_SYSCTL_KERN_BOOTTIME */
}
Example #10
0
float	*mult_matrix(float *m1, float *m2)
{
  int	i, j, k, l;
  float	*result;

  result = init_result();
  k = 0;
  l = 0;
  i = 0;
  while (k != (COLUMN * LINE))
    {
      i = (k / LINE) * COLUMN;
      if ((k % LINE) == 0)
	l = 0;
      j = l;
      while (j < (COLUMN * LINE))
	{
	  result[k] = (m1[i] * m2[j]) + result[k];
	  i += 1;
	  j += 3;
	}
      k++;
      l++;
    }
  return (result);
}
Example #11
0
int	NET_IF_COLLISIONS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
	char		if_name[MAX_STRING_LEN];
	net_stat_t	ns;
	int		ret = SYSINFO_RET_OK;

	assert(result);

	init_result(result);

	if (num_param(param) > 1)
		return SYSINFO_RET_FAIL;

	if (0 != get_param(param, 1, if_name, sizeof(if_name)))
		return SYSINFO_RET_FAIL;

	if (SYSINFO_RET_OK == get_net_stat(if_name, &ns))
	{
		SET_UI64_RESULT(result, ns.colls);
	}
	else
		ret = SYSINFO_RET_FAIL;

	return ret;
}
Example #12
0
int	EXECUTE_STR(const char *command, AGENT_RESULT *result)
{
	int	ret = SYSINFO_RET_FAIL;
	char	*cmd_result = NULL, error[MAX_STRING_LEN];

	assert(result);

	init_result(result);

	if (SUCCEED != zbx_execute(command, &cmd_result, error, sizeof(error), CONFIG_TIMEOUT))
	{
		SET_MSG_RESULT(result, zbx_strdup(NULL, error));
		goto lbl_exit;
	}

	zbx_rtrim(cmd_result, ZBX_WHITESPACE);

	zabbix_log(LOG_LEVEL_DEBUG, "Run remote command [%s] Result [%d] [%.20s]...",
			command, strlen(cmd_result), cmd_result);

	if ('\0' == *cmd_result)	/* we got whitespace only */
		goto lbl_exit;

	SET_TEXT_RESULT(result, zbx_strdup(NULL, cmd_result));

	ret = SYSINFO_RET_OK;
lbl_exit:
	zbx_free(cmd_result);

	return ret;
}
Example #13
0
int	SYSTEM_CPU_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
	char	mode[32];
	int	sysinfo_name;
	long	ncpu = 0;

	assert(result);

	init_result(result);

	if (num_param(param) > 1)
		return SYSINFO_RET_FAIL;

	if (0 != get_param(param, 1, mode, sizeof(mode)))
		*mode = '\0';

	if ('\0' == *mode || 0 == strcmp(mode, "online"))	/* default parameter */
		sysinfo_name = _SC_NPROCESSORS_ONLN;
	else if(0 == strcmp(mode, "max"))
		sysinfo_name = _SC_NPROCESSORS_CONF;
	else
		return SYSINFO_RET_FAIL;

	if (-1 == (ncpu = sysconf(sysinfo_name)) && EINVAL == errno)
		return SYSINFO_RET_FAIL;

	SET_UI64_RESULT(result, ncpu);

	return SYSINFO_RET_OK;
}
Example #14
0
int     SYSTEM_CPU_INTR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
	int		ret = SYSINFO_RET_FAIL;
	char		line[MAX_STRING_LEN],
			name[32];
	zbx_uint64_t	value = 0;
	FILE		*f;

	assert(result);

	init_result(result);

	if (NULL == (f = fopen("/proc/stat", "r")))
		return SYSINFO_RET_FAIL;

	while (NULL != fgets(line, sizeof(line), f))
	{
		if (2 != sscanf(line, "%s " ZBX_FS_UI64, name, &value))
			continue;

		if (0 == strcmp(name, "intr"))
		{
			SET_UI64_RESULT(result, value);
			ret = SYSINFO_RET_OK;
			break;
		}
	}
	zbx_fclose(f);

	return ret;
}
Example #15
0
File: net.c Project: Shmuma/z
static int      NET_IF_IN_BYTES(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
	struct ifnet value;
	char    if_name[MAX_STRING_LEN];
	int     ret = SYSINFO_RET_FAIL;

	assert(result);

	init_result(result);

	if(num_param(param) > 1)
	{
		return SYSINFO_RET_FAIL;
	}

	if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
	{
		return SYSINFO_RET_FAIL;
	}

	ret = get_ifdata(if_name, &value);
	
	if(ret == SYSINFO_RET_OK)
	{
		SET_UI64_RESULT(result, value.if_ibytes);
		ret = SYSINFO_RET_OK;
	}
	
	return ret;
}
Example #16
0
static int	NET_IF_IN_PACKETS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
    kstat_named_t kn;
    char    if_name[MAX_STRING_LEN];
    int	    ret;

    assert(result);

    init_result(result);

    if(num_param(param) > 1)
    {
	return SYSINFO_RET_FAIL;
    }

    if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
    {
	return SYSINFO_RET_FAIL;
    }

    if ( SYSINFO_RET_OK == (ret = get_kstat_named_field(if_name, "ipackets64", &kn)) )
    {
	SET_UI64_RESULT(result, kn.value.ui64);
    }
    else if ( SYSINFO_RET_OK == (ret = get_kstat_named_field(if_name, "ipackets", &kn)) )
    {
	SET_UI64_RESULT(result, kn.value.ui32);
    }

    return ret;
}
Example #17
0
File: diskio.c Project: Shmuma/z
static int	VFS_DEV_READ_OPERATIONS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
/*	char devname[MAX_STRING_LEN];
	struct diskstats ds;*/
	int ret = SYSINFO_RET_FAIL;
        
	assert(result);

        init_result(result);
/*	
        if(num_param(param) > 1)
        {
                return SYSINFO_RET_FAIL;
        }

        if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
        {
                return SYSINFO_RET_FAIL;
        }
	
	if(get_disk_stats(devname, &ds) == SYSINFO_RET_OK)
	{
		SET_UI64_RESULT(result, ds.ds_rxfer);
		ret = SYSINFO_RET_OK;
	}
*/	
	return ret;
}
Example #18
0
static void	process_listener(zbx_sock_t *s)
{
	AGENT_RESULT	result;
	char		*command;
	char		**value = NULL;
	int		ret;

	if (SUCCEED == (ret = zbx_tcp_recv_to(s, &command, CONFIG_TIMEOUT)))
	{
		zbx_rtrim(command, "\r\n");

		zabbix_log(LOG_LEVEL_DEBUG, "Requested [%s]", command);

		init_result(&result);
		process(command, 0, &result);

		if (NULL == (value = GET_TEXT_RESULT(&result)))
			value = GET_MSG_RESULT(&result);

		if (NULL != value)
		{
			zabbix_log(LOG_LEVEL_DEBUG, "Sending back [%s]", *value);
			ret = zbx_tcp_send_to(s, *value, CONFIG_TIMEOUT);
		}

		free_result(&result);
	}

	if (FAIL == ret)
		zabbix_log(LOG_LEVEL_DEBUG, "Process listener error: %s", zbx_tcp_strerror());
}
Example #19
0
static int	zbx_execute_script_on_agent(DC_HOST *host, const char *command, char **result,
		char *error, size_t max_error_len)
{
	const char	*__function_name = "zbx_execute_script_on_agent";
	int		ret;
	AGENT_RESULT	agent_result;
	char		*param, *port = NULL;
	DC_ITEM		item;

	zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);

	*error = '\0';
	memset(&item, 0, sizeof(item));
	memcpy(&item.host, host, sizeof(item.host));

	if (SUCCEED != (ret = DCconfig_get_interface_by_type(&item.interface, host->hostid, INTERFACE_TYPE_AGENT)))
	{
		zbx_snprintf(error, max_error_len, "Whatap agent interface is not defined for host [%s]", host->host);
		goto fail;
	}

	port = zbx_strdup(port, item.interface.port_orig);
	substitute_simple_macros(NULL, NULL, NULL, NULL, &host->hostid, NULL, NULL, &port, MACRO_TYPE_COMMON, NULL, 0);

	if (SUCCEED != (ret = is_ushort(port, &item.interface.port)))
	{
		zbx_snprintf(error, max_error_len, "Invalid port number [%s]", item.interface.port_orig);
		goto fail;
	}

	param = zbx_dyn_escape_string(command, "\"");
	item.key = zbx_dsprintf(item.key, "system.run[\"%s\",\"%s\"]", param, NULL == result ? "nowait" : "wait");
	item.value_type = ITEM_VALUE_TYPE_TEXT;
	zbx_free(param);

	init_result(&agent_result);

	alarm(CONFIG_TIMEOUT);

	if (SUCCEED != (ret = get_value_agent(&item, &agent_result)))
	{
		if (ISSET_MSG(&agent_result))
			zbx_strlcpy(error, agent_result.msg, max_error_len);
		ret = FAIL;
	}
	else if (NULL != result && ISSET_TEXT(&agent_result))
		*result = zbx_strdup(*result, agent_result.text);

	alarm(0);

	free_result(&agent_result);

	zbx_free(item.key);
fail:
	zbx_free(port);

	zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret));

	return ret;
}
Example #20
0
static int	SYSTEM_SWAP_PUSED(AGENT_RESULT *result)
{
	AGENT_RESULT	result_tmp;
	zbx_uint64_t	tot_val = 0;
	zbx_uint64_t	free_val = 0;

        init_result(&result_tmp);

	if (SYSINFO_RET_OK != SYSTEM_SWAP_TOTAL(cmd, param, flags, &result_tmp) || !(result_tmp.type & AR_UINT64))
		return SYSINFO_RET_FAIL;
	tot_val = result_tmp.ui64;

	/* Check for division by zero */
	if (0 == tot_val)
	{
		free_result(&result_tmp);
		return SYSINFO_RET_FAIL;
	}

	if (SYSINFO_RET_OK != SYSTEM_SWAP_FREE(cmd, param, flags, &result_tmp) || !(result_tmp.type & AR_UINT64))
		return SYSINFO_RET_FAIL;
	free_val = result_tmp.ui64;

	free_result(&result_tmp);

	SET_DBL_RESULT(result, 100.0 - (100.0 * (double)free_val) / (double)tot_val);

        return SYSINFO_RET_OK;
}
Example #21
0
File: DROP.c Project: a1406/txgg
int main(int argc, char *argv[])
{
	size_t size;
	if (argc < 2) {
		printf("please input xls file name\n");
		return (0);
	}
	if (load_excel(argv[1]) != 0)
	{
		printf("load excel fail\n");
		return (0);		
	}
	init_result();	
	size = generate_pb_data(get_data_base);

	size = cfg__drops__pack(&result, outbuf);

	CFGDROPS *check = cfg__drops__unpack(NULL, size, outbuf);	
	
	int fd = open("drop.output", O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
	if (write(fd, outbuf, size) != size) {
		perror("write fail\n");
	}
	close(fd);
	return (0);
}
Example #22
0
bool BWSearch1CPU(uint8_t *W, vector *C, vector *C1, comp_matrix *O, comp_matrix *Oi, result *res, results_list *r_list) {

	int16_t start, end, half, n;;
	SA_TYPE _k, _l;

	_k = res->k;
	_l = res->l;

	start = res->start;
	end   = res->end;

	n = end - start + 1;
	half = n / 2;

	result r;

	init_result(&r, 0);
	bound_result(&r, half, end);
	change_result(&r, _k, _l, end);

	BWExactSearchBackward(W, C, C1, O, &r);

	if (r.k <= r.l) {
		r.start = start;
		r.pos = half-1;
		BWSimpleSearch1Backward(W, C, C1, O, &r, r_list);

		if (r.k <= r.l) add_result(&r, r_list); //Match
	}

	half--;

	init_result(&r, 1);
	bound_result(&r, start, half);
	change_result(&r, _k, _l, start);

	BWExactSearchForward(W, C, C1, Oi, &r);
	if (r.k <= r.l) {
		r.pos = half+1;
		r.end = end;
		BWSimpleSearch1Forward(W, C, C1, Oi, &r, r_list);
	}

	return false;

}
Example #23
0
int     SYSTEM_CPU_SWITCHES(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
	assert(result);

	init_result(result);

	return SYSINFO_RET_FAIL;
}
Example #24
0
static int	ONLY_ACTIVE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
	assert(result);

	init_result(result);
	SET_MSG_RESULT(result, strdup("Accessible only as active check!"));
	return SYSINFO_RET_FAIL;
}
Example #25
0
File: net.c Project: Shmuma/z
int     NET_IF_COLLISIONS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
        assert(result);

        init_result(result);
	
	return SYSINFO_RET_FAIL;
}
Example #26
0
static void	process_listener(zbx_socket_t *s)
{
	AGENT_RESULT	result;
	char		**value = NULL;
	int		ret;

	if (SUCCEED == (ret = zbx_tcp_recv_to(s, CONFIG_TIMEOUT)))
	{
		zbx_rtrim(s->buffer, "\r\n");

		zabbix_log(LOG_LEVEL_DEBUG, "Requested [%s]", s->buffer);

		init_result(&result);

		if (SUCCEED == process(s->buffer, PROCESS_WITH_ALIAS, &result))
		{
			if (NULL != (value = GET_TEXT_RESULT(&result)))
			{
				zabbix_log(LOG_LEVEL_DEBUG, "Sending back [%s]", *value);
				ret = zbx_tcp_send_to(s, *value, CONFIG_TIMEOUT);
			}
		}
		else
		{
			value = GET_MSG_RESULT(&result);

			if (NULL != value)
			{
				static char	*buffer = NULL;
				static size_t	buffer_alloc = 256;
				size_t		buffer_offset = 0;

				zabbix_log(LOG_LEVEL_DEBUG, "Sending back [" ZBX_NOTSUPPORTED ": %s]", *value);

				if (NULL == buffer)
					buffer = (char *)zbx_malloc(buffer, buffer_alloc);

				zbx_strncpy_alloc(&buffer, &buffer_alloc, &buffer_offset,
						ZBX_NOTSUPPORTED, ZBX_CONST_STRLEN(ZBX_NOTSUPPORTED));
				buffer_offset++;
				zbx_strcpy_alloc(&buffer, &buffer_alloc, &buffer_offset, *value);

				ret = zbx_tcp_send_bytes_to(s, buffer, buffer_offset, CONFIG_TIMEOUT);
			}
			else
			{
				zabbix_log(LOG_LEVEL_DEBUG, "Sending back [" ZBX_NOTSUPPORTED "]");

				ret = zbx_tcp_send_to(s, ZBX_NOTSUPPORTED, CONFIG_TIMEOUT);
			}
		}

		free_result(&result);
	}

	if (FAIL == ret)
		zabbix_log(LOG_LEVEL_DEBUG, "Process listener error: %s", zbx_socket_strerror());
}
Example #27
0
int	CHECK_DNS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_RES_QUERY

#if !defined(PACKETSZ)
#	define PACKETSZ 512
#endif /* PACKETSZ */

#if !defined(C_IN)
#	define C_IN	ns_c_in
#endif /* C_IN */

#if !defined(T_ANY)
#	define T_ANY	ns_t_any
#endif /* T_ANY */

	int		res;
	char		ip[MAX_STRING_LEN];
	char		zone[MAX_STRING_LEN];
#ifdef	PACKETSZ
	unsigned char	respbuf[PACKETSZ];
#else
	unsigned char	respbuf[NS_PACKETSZ];
#endif

	assert(result);

	init_result(result);

	if (num_param(param) > 2)
		return SYSINFO_RET_FAIL;

	if (0 != get_param(param, 1, ip, MAX_STRING_LEN))
               *ip = '\0';

	/* default parameter */
	if (*ip == '\0')
		strscpy(ip, "127.0.0.1");

	if (0 != get_param(param, 2, zone, MAX_STRING_LEN))
		*zone = '\0';

	/* default parameter */
	if (*zone == '\0')
		strscpy(zone, "localhost");

	if (!(_res.options & RES_INIT))
		res_init();

	res = res_query(zone, C_IN, T_ANY, respbuf, sizeof(respbuf));

	SET_UI64_RESULT(result, res != -1 ? 1 : 0);

	return SYSINFO_RET_OK;
#endif /* HAVE_RES_QUERY */

	return SYSINFO_RET_FAIL;
}
Example #28
0
File: memory.c Project: Shmuma/z
static int	VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
        FILE    *f;
        char    *t;
        char    c[MAX_STRING_LEN];
        zbx_uint64_t    res = 0;

        assert(result);

        init_result(result);

        if(NULL == (f = fopen("/proc/meminfo","r") ))
        {
                return  SYSINFO_RET_FAIL;
        }
        while(NULL!=fgets(c,MAX_STRING_LEN,f))
        {
                if(strncmp(c,"Cached:",7) == 0)
                {
                        t=(char *)strtok(c," ");
                        t=(char *)strtok(NULL," ");
                        sscanf(t, ZBX_FS_UI64, &res );
                        t=(char *)strtok(NULL," ");

                        if(strcasecmp(t,"kb"))          res <<= 10;
                        else if(strcasecmp(t, "mb"))    res <<= 20;
                        else if(strcasecmp(t, "gb"))    res <<= 30;
                        else if(strcasecmp(t, "tb"))    res <<= 40;

                        break;
                }
        }
        zbx_fclose(f);

        SET_UI64_RESULT(result, res);
        return SYSINFO_RET_OK;
#else
	assert(result);

        init_result(result);
		
	return SYSINFO_RET_FAIL;
#endif
}
Example #29
0
void BWSearch1CPU(char *W, vector *C, vector *C1, comp_matrix *O, comp_matrix *Oi, result *res, results_list *r_list) {

  unsigned int half, n;
  int start, end;
  unsigned int _k, _l;

  _k = res->k;
  _l = res->l;

  start = res->start;
  end   = res->end;

  n = end - start + 1;
  half = n / 2;

  result r;

  init_result(&r, 0);
  bound_result(&r, half, end);
  change_result(&r, _k, _l, end);

  BWExactSearchBackward(W, C, C1, O, &r);

  if (r.k <= r.l) {
    r.start = start;
    r.pos = half-1;
    BWSimpleSearch1Backward(W, C, C1, O, &r, r_list);

    if (r.k <= r.l) add_result(&r, r_list); //Match
  }

  half--;

  init_result(&r, 1);
  bound_result(&r, start, half);
  change_result(&r, _k, _l, start);

  BWExactSearchForward(W, C, C1, Oi, &r);
  if (r.k <= r.l) {
    r.pos = half+1;
    r.end = end;
    BWSimpleSearch1Forward(W, C, C1, Oi, &r, r_list);
  }

}
Example #30
0
int	NET_TCP_LISTEN(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
	MIB_TCPTABLE	*pTcpTable = NULL;
	DWORD		dwSize, dwRetVal;
	int		i, ret = SYSINFO_RET_FAIL;
	unsigned short	port;
	char		tmp[8];

	assert(result);

	init_result(result);

	if (num_param(param) > 1)
		return SYSINFO_RET_FAIL;

	if (0 != get_param(param, 1, tmp, sizeof(tmp)))
		return SYSINFO_RET_FAIL;

	if (SUCCEED != is_ushort(tmp, &port))
		return SYSINFO_RET_FAIL;

	dwSize = sizeof(MIB_TCPTABLE);
	pTcpTable = (MIB_TCPTABLE *)zbx_malloc(pTcpTable, dwSize);

	/* Make an initial call to GetTcpTable to
	   get the necessary size into the dwSize variable */
	if (ERROR_INSUFFICIENT_BUFFER == (dwRetVal = GetTcpTable(pTcpTable, &dwSize, TRUE)))
		pTcpTable = (MIB_TCPTABLE *)zbx_realloc(pTcpTable, dwSize);

	/* Make a second call to GetTcpTable to get
	   the actual data we require */
	if (NO_ERROR == (dwRetVal = GetTcpTable(pTcpTable, &dwSize, TRUE)))
	{
		for (i = 0; i < (int)pTcpTable->dwNumEntries; i++)
		{
			if (MIB_TCP_STATE_LISTEN == pTcpTable->table[i].dwState &&
					port == ntohs((u_short)pTcpTable->table[i].dwLocalPort))
			{
				SET_UI64_RESULT(result, 1);
				break;
			}
		}
		ret = SYSINFO_RET_OK;
	}
	else
	{
		zabbix_log(LOG_LEVEL_DEBUG, "GetTcpTable failed with error: %s", strerror_from_system(dwRetVal));
		goto clean;
	}

	if (!ISSET_UI64(result))
		SET_UI64_RESULT(result, 0);
clean:
	zbx_free(pTcpTable);

	return ret;
}