/****************************************************************************** * * * Function: parse_traps * * * * Purpose: split traps and process them with process_trap() * * * * Author: Rudolfs Kreicbergs * * * ******************************************************************************/ static void parse_traps(char *buffer) { char *c, *line, *begin = NULL, *end = NULL, *addr = NULL; c = line = buffer; for (; '\0' != *c; c++) { if ('\n' == *c) line = c + 1; if (0 != strncmp(c, "ZBXTRAP", 7)) continue; *c = '\0'; c += 7; /* c now points to the delimiter between "ZBXTRAP" and address */ while ('\0' != *c && NULL != strchr(ZBX_WHITESPACE, *c)) c++; /* c now points to the address */ /* process the previos trap */ if (NULL != begin) { *(line - 1) = '\0'; process_trap(addr, begin, end); end = NULL; } /* parse the current trap */ begin = line; addr = c; while ('\0' != *c && NULL == strchr(ZBX_WHITESPACE, *c)) c++; if ('\0' == c) { zabbix_log(LOG_LEVEL_WARNING, "invalid trap found [%s...]", begin); begin = NULL; c = addr; continue; } *c++ = '\0'; end = c; /* the rest of the trap */ } /* process the last trap */ if (NULL != end) process_trap(addr, begin, end); else if (NULL == addr) /* no trap was found */ zabbix_log(LOG_LEVEL_WARNING, "invalid trap found [%s]", buffer); }
void process_trapper_child(zbx_sock_t *sock) { char *data; /* suseconds_t is not defined under HP-UX */ /* struct timeval tv; suseconds_t msec; gettimeofday(&tv, NULL); msec = tv.tv_usec;*/ alarm(ZABBIX_TRAPPER_TIMEOUT); if(zbx_tcp_recv(sock, &data) != SUCCEED) { alarm(0); return; } process_trap(sock, data, sizeof(data)); alarm(0); /* gettimeofday(&tv, NULL); zabbix_log( LOG_LEVEL_DEBUG, "Trap processed in " ZBX_FS_DBL " seconds", (double)(tv.tv_usec-msec)/1000000 );*/ }
static void process_trapper_child(zbx_socket_t *sock, zbx_timespec_t *ts) { if (SUCCEED != zbx_tcp_recv_to(sock, CONFIG_TRAPPER_TIMEOUT)) return; process_trap(sock, sock->buffer, ts); }
static void process_trapper_child(zbx_sock_t *sock) { char *data; if (SUCCEED != zbx_tcp_recv_to(sock, &data, CONFIG_TRAPPER_TIMEOUT)) return; process_trap(sock, data, sizeof(data)); }
/****************************************************************************** * * * Function: parse_traps * * * * Purpose: split traps and process them with process_trap() * * * * Author: Rudolfs Kreicbergs * * * ******************************************************************************/ static void parse_traps(int flag) { char *c, *line, *begin = NULL, *end = NULL, *addr = NULL, *pzbegin, *pzaddr = NULL, *pzdate = NULL; c = line = buffer; while ('\0' != *c) { if ('\n' == *c) { line = ++c; continue; } if (0 != strncmp(c, "ZBXTRAP", 7)) { c++; continue; } pzbegin = c; c += 7; /* c now points to the delimiter between "ZBXTRAP" and address */ while ('\0' != *c && NULL != strchr(ZBX_WHITESPACE, *c)) c++; /* c now points to the address */ /* process the previous trap */ if (NULL != begin) { *(line - 1) = '\0'; *pzdate = '\0'; *pzaddr = '\0'; process_trap(addr, begin, end); end = NULL; } /* parse the current trap */ begin = line; addr = c; pzdate = pzbegin; while ('\0' != *c && NULL == strchr(ZBX_WHITESPACE, *c)) c++; pzaddr = c; end = c + 1; /* the rest of the trap */ } if (0 == flag) { if (NULL == begin) offset = c - buffer; else offset = c - begin; if (offset == MAX_BUFFER_LEN - 1) { if (NULL != end) { zabbix_log(LOG_LEVEL_WARNING, "SNMP trapper buffer is full," " trap data might be truncated"); parse_traps(1); } else zabbix_log(LOG_LEVEL_WARNING, "failed to find trap in SNMP trapper file"); offset = 0; *buffer = '\0'; } else { if (NULL != begin && begin != buffer) memmove(buffer, begin, offset + 1); } } else { if (NULL != end) { *(line - 1) = '\0'; *pzdate = '\0'; *pzaddr = '\0'; process_trap(addr, begin, end); offset = 0; *buffer = '\0'; } else { zabbix_log(LOG_LEVEL_WARNING, "invalid trap data found \"%s\"", buffer); offset = 0; *buffer = '\0'; } } }