int NET_IF_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char if_name[MAX_STRING_LEN], mode[16]; zbx_uint64_t tbytes, tpackets, terrors; if (num_param(param) > 2) return SYSINFO_RET_FAIL; if (0 != get_param(param, 1, if_name, sizeof(if_name))) *if_name = '\0'; if (0 != get_param(param, 2, mode, sizeof(mode))) *mode = '\0'; if (SYSINFO_RET_OK != get_ifdata(if_name, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &tbytes, &tpackets, &terrors, NULL)) return SYSINFO_RET_FAIL; if ('\0' == *mode || 0 == strcmp(mode, "bytes")) /* default parameter */ SET_UI64_RESULT(result, tbytes); else if (0 == strcmp(mode, "packets")) SET_UI64_RESULT(result, tpackets); else if (0 == strcmp(mode, "errors")) SET_UI64_RESULT(result, terrors); else return SYSINFO_RET_FAIL; return SYSINFO_RET_OK; }
int NET_IF_TOTAL(AGENT_REQUEST *request, AGENT_RESULT *result) { char *if_name, *mode; zbx_uint64_t tbytes, tpackets, terrors; if (2 < request->nparam) return SYSINFO_RET_FAIL; if_name = get_rparam(request, 0); mode = get_rparam(request, 1); if (SYSINFO_RET_OK != get_ifdata(if_name, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &tbytes, &tpackets, &terrors, NULL)) return SYSINFO_RET_FAIL; if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "bytes")) /* default parameter */ SET_UI64_RESULT(result, tbytes); else if (0 == strcmp(mode, "packets")) SET_UI64_RESULT(result, tpackets); else if (0 == strcmp(mode, "errors")) SET_UI64_RESULT(result, terrors); else return SYSINFO_RET_FAIL; return SYSINFO_RET_OK; }
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; }
static int ifmib_get_stats(struct ifstat_driver *driver, struct ifstat_list *ifs) { int count, i; struct ifmibdata ifmd; struct ifstat_data *cur; if (ifs->flags & IFSTAT_HASINDEX) { /* poll by index */ for (cur = ifs->first; cur != NULL; cur = cur->next) { i = ifstat_get_interface_index(cur); if (i < 0 || !get_ifdata(i, &ifmd)) continue; if (strcmp(ifstat_get_interface_name(cur), ifmd.ifmd_name)) continue; ifstat_set_interface_stats(cur, ifmd.ifmd_data.ifi_ibytes, ifmd.ifmd_data.ifi_obytes); ifstat_set_interface_index(cur, i); } return 1; } if ((count = get_ifcount()) <= 0) return 0; for (i = 1; i <= count; i++) { if (!get_ifdata(i, &ifmd)) continue; if ((cur = ifstat_get_interface(ifs, ifmd.ifmd_name)) == NULL) continue; ifstat_set_interface_stats(cur, ifmd.ifmd_data.ifi_ibytes, ifmd.ifmd_data.ifi_obytes); ifstat_set_interface_index(cur, i); } return 1; }
static int ifmib_scan_interfaces(struct ifstat_driver *driver, struct ifstat_list *ifs) { int count, i; struct ifmibdata ifmd; if ((count = get_ifcount()) <= 0) return 0; for (i = 1; i <= count; i++) { if (!get_ifdata(i, &ifmd)) continue; examine_interface(ifs, ifmd.ifmd_name, ifmd.ifmd_flags, ifmd.ifmd_data.ifi_type); } return 1; }
int NET_IF_COLLISIONS(AGENT_REQUEST *request, AGENT_RESULT *result) { char *if_name; zbx_uint64_t icollisions; if (1 < request->nparam) return SYSINFO_RET_FAIL; if_name = get_rparam(request, 0); if (SYSINFO_RET_OK != get_ifdata(if_name, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &icollisions)) return SYSINFO_RET_FAIL; SET_UI64_RESULT(result, icollisions); return SYSINFO_RET_OK; }
int NET_IF_COLLISIONS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char if_name[MAX_STRING_LEN]; zbx_uint64_t icollisions; if (num_param(param) > 1) return SYSINFO_RET_FAIL; if (0 != get_param(param, 1, if_name, sizeof(if_name))) *if_name = '\0'; if (SYSINFO_RET_OK != get_ifdata(if_name, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &icollisions)) return SYSINFO_RET_FAIL; SET_UI64_RESULT(result, icollisions); return SYSINFO_RET_OK; }