static int SYSTEM_SWAP_PUSED(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; init_result(&result_tmp); if(SYSTEM_SWAP_TOTAL(cmd, param, flags, &result_tmp) != SYSINFO_RET_OK || !(result_tmp.type & AR_UINT64)) return SYSINFO_RET_FAIL; tot_val = result_tmp.ui64; /* Check for division by zero */ if(tot_val == 0) { free_result(&result_tmp); return SYSINFO_RET_FAIL; } if(SYSTEM_SWAP_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 - (100.0 * (double)free_val) / (double)tot_val); return SYSINFO_RET_OK; }
int SYSTEM_SWAP_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result) { char *swapdev, *mode; int ret = SYSINFO_RET_FAIL; if (2 < request->nparam) return SYSINFO_RET_FAIL; swapdev = get_rparam(request, 0); mode = get_rparam(request, 1); if (NULL != swapdev && '\0' != *swapdev && 0 != strcmp(swapdev, "all")) return SYSINFO_RET_FAIL; if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "free")) ret = SYSTEM_SWAP_FREE(result); else if (0 == strcmp(mode, "used")) ret = SYSTEM_SWAP_USED(result); else if (0 == strcmp(mode, "total")) ret = SYSTEM_SWAP_TOTAL(result); else if (0 == strcmp(mode, "pfree")) ret = SYSTEM_SWAP_PFREE(result); else if (0 == strcmp(mode, "pused")) ret = SYSTEM_SWAP_PUSED(result); else ret = SYSINFO_RET_FAIL; return ret; }
static int SYSTEM_SWAP_PFREE(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 * (double)free_val) / (double)tot_val); return SYSINFO_RET_OK; }
int SYSTEM_SWAP_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result) { char *swapdev, *mode; int ret; if (2 < request->nparam) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters.")); return SYSINFO_RET_FAIL; } swapdev = get_rparam(request, 0); mode = get_rparam(request, 1); /* default parameter */ if (NULL != swapdev && '\0' != *swapdev && 0 != strcmp(swapdev, "all")) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter.")); return SYSINFO_RET_FAIL; } /* default parameter */ if (NULL == mode || *mode == '\0' || 0 == strcmp(mode, "free")) ret = SYSTEM_SWAP_FREE(result); else if (0 == strcmp(mode, "used")) ret = SYSTEM_SWAP_USED(result); else if (0 == strcmp(mode, "total")) ret = SYSTEM_SWAP_TOTAL(result); else if (0 == strcmp(mode, "pfree")) ret = SYSTEM_SWAP_PFREE(result); else if (0 == strcmp(mode, "pused")) ret = SYSTEM_SWAP_PUSED(result); else { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter.")); return SYSINFO_RET_FAIL; } return ret; }
int SYSTEM_SWAP_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result) { char *tmp; int ret; if (2 < request->nparam) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters.")); return SYSINFO_RET_FAIL; } tmp = get_rparam(request, 0); if (NULL != tmp && '\0' != *tmp && 0 != strcmp(tmp, "all")) /* default parameter */ { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter.")); return SYSINFO_RET_FAIL; } tmp = get_rparam(request, 1); if (NULL == tmp || '\0' == *tmp || 0 == strcmp(tmp, "free")) /* default parameter */ ret = SYSTEM_SWAP_FREE(request, result); else if (0 == strcmp(tmp, "total")) ret = SYSTEM_SWAP_TOTAL(request, result); else if (0 == strcmp(tmp, "used")) ret = SYSTEM_SWAP_USED(request, result); else if (0 == strcmp(tmp, "pfree")) ret = SYSTEM_SWAP_PFREE(request, result); else if (0 == strcmp(tmp, "pused")) ret = SYSTEM_SWAP_PUSED(request, result); else { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter.")); return SYSINFO_RET_FAIL; } return ret; }