diff options
| author | sasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-02-15 17:17:59 +0000 |
|---|---|---|
| committer | sasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-02-15 17:17:59 +0000 |
| commit | 02edd0c48946e1a487ed3fb035cd3af104ba5a5d (patch) | |
| tree | 58603e6a2f088794b8cbc71773d851a005dcdfc5 /src/zabbix_server/trapper | |
| parent | af96ef3f63267e56a7bf5e208efa6b4aa12e409e (diff) | |
| download | zabbix-02edd0c48946e1a487ed3fb035cd3af104ba5a5d.tar.gz zabbix-02edd0c48946e1a487ed3fb035cd3af104ba5a5d.tar.xz zabbix-02edd0c48946e1a487ed3fb035cd3af104ba5a5d.zip | |
- [DEV-109] Server changes - Trapper
git-svn-id: svn://svn.zabbix.com/trunk@5353 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/zabbix_server/trapper')
| -rw-r--r-- | src/zabbix_server/trapper/trapper.c | 213 |
1 files changed, 213 insertions, 0 deletions
diff --git a/src/zabbix_server/trapper/trapper.c b/src/zabbix_server/trapper/trapper.c index 49bd1e5f..d094b4ec 100644 --- a/src/zabbix_server/trapper/trapper.c +++ b/src/zabbix_server/trapper/trapper.c @@ -43,6 +43,219 @@ static zbx_process_t zbx_process; +static void calc_timestamp(char *line,int *timestamp, char *format) +{ + int hh=0,mm=0,ss=0,yyyy=0,dd=0,MM=0; + int hhc=0,mmc=0,ssc=0,yyyyc=0,ddc=0,MMc=0; + int i,num; + struct tm tm; + time_t t; + + zabbix_log( LOG_LEVEL_DEBUG, "In calc_timestamp()"); + + hh=mm=ss=yyyy=dd=MM=0; + + for(i=0;(format[i]!=0)&&(line[i]!=0);i++) + { + if(isdigit(line[i])==0) continue; + num=(int)line[i]-48; + + switch ((char) format[i]) { + case 'h': + hh=10*hh+num; + hhc++; + break; + case 'm': + mm=10*mm+num; + mmc++; + break; + case 's': + ss=10*ss+num; + ssc++; + break; + case 'y': + yyyy=10*yyyy+num; + yyyyc++; + break; + case 'd': + dd=10*dd+num; + ddc++; + break; + case 'M': + MM=10*MM+num; + MMc++; + break; + } + } + + zabbix_log( LOG_LEVEL_DEBUG, "hh [%d] mm [%d] ss [%d] yyyy [%d] dd [%d] MM [%d]", + hh, + mm, + ss, + yyyy, + dd, + MM); + + /* Seconds can be ignored. No ssc here. */ + if(hhc!=0&&mmc!=0&&yyyyc!=0&&ddc!=0&&MMc!=0) + { + tm.tm_sec=ss; + tm.tm_min=mm; + tm.tm_hour=hh; + tm.tm_mday=dd; + tm.tm_mon=MM-1; + tm.tm_year=yyyy-1900; + + t=mktime(&tm); + if(t>0) + { + *timestamp=t; + } + } + + zabbix_log( LOG_LEVEL_DEBUG, "End timestamp [%d]", + *timestamp); +} + +/****************************************************************************** + * * + * Function: process_data * + * * + * Purpose: process new item value * + * * + * Parameters: sockfd - descriptor of agent-server socket connection * + * server - server name * + * key - item's key * + * value - new value of server:key * + * lastlogsize - if key=log[*], last size of log file * + * * + * Return value: SUCCEED - new value processed sucesfully * + * FAIL - otherwise * + * * + * Author: Alexei Vladishev * + * * + * Comments: for trapper server process * + * * + ******************************************************************************/ +static int process_data(zbx_sock_t *sock,char *server,char *key,char *value,char *lastlogsize, char *timestamp, + char *source, char *severity) +{ + AGENT_RESULT agent; + DB_RESULT result; + DB_ROW row; + DB_ITEM item; + char server_esc[MAX_STRING_LEN], key_esc[MAX_STRING_LEN]; + + zabbix_log(LOG_LEVEL_DEBUG, "In process_data([%s],[%s],[%s],[%s])", + server, + key, + value, + lastlogsize); + + DBescape_string(server, server_esc, MAX_STRING_LEN); + DBescape_string(key, key_esc, MAX_STRING_LEN); + + result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and h.proxyid=0" + " and i.key_='%s' and i.status in (%d,%d) and i.type in (%d,%d)" DB_NODE, + ZBX_SQL_ITEM_SELECT, + HOST_STATUS_MONITORED, + server_esc, + key_esc, + ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED, + ITEM_TYPE_TRAPPER, + ITEM_TYPE_ZABBIX_ACTIVE, + DBnode_local("h.hostid")); + + if (NULL == (row = DBfetch(result))) { + DBfree_result(result); + return FAIL; +/* + zabbix_log( LOG_LEVEL_DEBUG, "Before checking autoregistration for [%s]", + server); + + if(autoregister(server) == SUCCEED) + { + DBfree_result(result); + + result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type in (%d,%d) and" ZBX_COND_NODEID, + ZBX_SQL_ITEM_SELECT, + HOST_STATUS_MONITORED, + server_esc, + key_esc, + ITEM_STATUS_ACTIVE, + ITEM_TYPE_TRAPPER, + ITEM_TYPE_ZABBIX_ACTIVE, + LOCAL_NODE("h.hostid")); + row = DBfetch(result); + if(!row) + { + DBfree_result(result); + return FAIL; + } + } + else + { + DBfree_result(result); + return FAIL; + } +*/ + } + + DBget_item_from_db(&item, row); + + if (item.type == ITEM_TYPE_ZABBIX_ACTIVE && FAIL == zbx_tcp_check_security(sock, item.trapper_hosts, 1)) { + DBfree_result(result); + return FAIL; + } + + zabbix_log(LOG_LEVEL_DEBUG, "Processing [%s]", + value); + + if (0 == strcmp(value, "ZBX_NOTSUPPORTED")) { + zabbix_log( LOG_LEVEL_WARNING, "Active parameter [%s] is not supported by agent on host [%s]", + item.key, + item.host_name); + zabbix_syslog("Active parameter [%s] is not supported by agent on host [%s]", + item.key, + item.host_name); + DBupdate_item_status_to_notsupported(item.itemid, "Not supported by ZABBIX agent"); + } else { + if (0 == strncmp(item.key, "log[", 4) || 0 == strncmp(item.key, "eventlog[", 9)) { + item.lastlogsize = atoi(lastlogsize); + item.timestamp = atoi(timestamp); + + calc_timestamp(value, &item.timestamp, item.logtimefmt); + + item.eventlog_severity = atoi(severity); + item.eventlog_source = source; + zabbix_log(LOG_LEVEL_DEBUG, "Value [%s] Lastlogsize [%s] Timestamp [%s]", + value, + lastlogsize, + timestamp); + } + + init_result(&agent); + + if( SUCCEED == set_result_type(&agent, item.value_type, value)) { + process_new_value(&item, &agent); + update_triggers(item.itemid); + } else { + zabbix_log( LOG_LEVEL_WARNING, "Type of received value [%s] is not suitable for [%s@%s]", + value, + item.key, + item.host_name); + zabbix_syslog("Type of received value [%s] is not suitable for [%s@%s]", + value, + item.key, + item.host_name); + } + free_result(&agent); + } + DBfree_result(result); + + return SUCCEED; +} + /****************************************************************************** * * * Function: send_result * |
