Left file: C:\Users\Administrator\AppData\Local\Temp\operations.c-revBASE.svn003.tmp.c Right file: D:\SVN\zabbix\src\zabbix_server\operations.c 722c722,863 < zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name); --- > > /****************************************************************************** > * * > * Function: add_host_macro * > * * > * Purpose: add macro to host if linked template,onlu support {$SNMP_COMMUNITY} now * > * * > * Author: cheliequan * > * * > ******************************************************************************/ > static void add_host_macro (const DB_EVENT * event) > { > const char *__function_name = "add_host_macro"; > DB_RESULT result; > DB_RESULT result2; > DB_ROW row; > DB_ROW row2; > DB_ROW row3; > zbx_uint64_t dhostid, hostid = 0, proxy_hostid; > zbx_uint64_t hostmacroid; > char *snmp_community = NULL; > unsigned char svc_type; > zbx_db_insert_t db_insert; > zabbix_log (LOG_LEVEL_DEBUG, "In %s() eventid:" ZBX_FS_UI64, > __function_name, event->eventid); > if (EVENT_OBJECT_DHOST == event->object > || EVENT_OBJECT_DSERVICE == event->object) > > { > if (EVENT_OBJECT_DHOST == event->object) > > { > result = > DBselect > ("select ds.dhostid,dr.proxy_hostid,ds.ip,ds.dns,ds.port,ds.type,dc.snmp_community," > "dc.snmpv3_securityname,dc.snmpv3_securitylevel," > "dc.snmpv3_authpassphrase,dc.snmpv3_privpassphrase,dc.snmpv3_authprotocol," > "dc.snmpv3_privprotocol,dc.snmpv3_contextname" > " from drules dr,dchecks dc,dservices ds" > " where dc.druleid=dr.druleid" " and ds.dcheckid=dc.dcheckid" > " and ds.dhostid=" ZBX_FS_UI64 " order by ds.dserviceid", > event->objectid); > } > > else > > { > result = > DBselect > ("select ds.dhostid,dr.proxy_hostid,ds.ip,ds.dns,ds.port,ds.type,dc.snmp_community," > "dc.snmpv3_securityname,dc.snmpv3_securitylevel," > "dc.snmpv3_authpassphrase,dc.snmpv3_privpassphrase,dc.snmpv3_authprotocol," > "dc.snmpv3_privprotocol,dc.snmpv3_contextname" > " from drules dr,dchecks dc,dservices ds,dservices ds1" > " where dc.druleid=dr.druleid" " and ds.dcheckid=dc.dcheckid" > " and ds1.dhostid=ds.dhostid" " and ds1.dserviceid=" > ZBX_FS_UI64 " order by ds.dserviceid", event->objectid); > } > while (NULL != (row = DBfetch (result))) > > { > ZBX_STR2UINT64 (dhostid, row[0]); > ZBX_DBROW2UINT64 (proxy_hostid, row[1]); > svc_type = (unsigned char) atoi (row[5]); > switch (svc_type) > > { > case SVC_SNMPv1: > case SVC_SNMPv2c: > if (('\0' == *row[6]) || (0 == strcmp ("public", row[6]))) > > { > break; > } > snmp_community = DBdyn_escape_string (row[6]); > break; > case SVC_SNMPv3: > > /*fix bug to do */ > break; > default: > zabbix_log (LOG_LEVEL_DEBUG, "type %d in %s() not support now", > svc_type, __function_name); > break; > } > if (NULL == snmp_community) > > { > break; > } > > /*get hostid */ > result2 = DBselect ("select distinct h.hostid" > " from hosts h,interface i,dservices ds" > " where h.hostid=i.hostid" > " and i.ip=ds.ip" > " and h.status in (%d,%d)" > " and h.proxy_hostid%s" > " and ds.dhostid=" ZBX_FS_UI64 > " order by h.hostid", HOST_STATUS_MONITORED, > HOST_STATUS_NOT_MONITORED, > DBsql_id_cmp (proxy_hostid), dhostid); > if (NULL != (row2 = DBfetch (result2))) > > { > ZBX_STR2UINT64 (hostid, row2[0]); > } > DBfree_result (result2); > if (0 == hostid) > > { > zbx_free (snmp_community); > continue; > } > > /*get hostid and hostmacro */ > result2 = DBselect ("select distinct hm.macro,hm.value" > " from hostmacro hm" > " where hm.hostid=" ZBX_FS_UI64 > " and hm.value='%s'", hostid, snmp_community); > > /*alrealy insert same macro value no action */ > if (NULL != (row3 = DBfetch (result2))) > > { > DBfree_result (result2); > zbx_free (snmp_community); > continue; > } > zbx_db_insert_prepare (&db_insert, "hostmacro", "hostmacroid", > "hostid", "macro", "value", NULL); > hostmacroid = DBget_maxid ("hostmacro"); > zbx_db_insert_add_values (&db_insert, hostmacroid, hostid, > "{$SNMP_COMMUNITY}", snmp_community); > zbx_db_insert_execute (&db_insert); > zbx_db_insert_clean (&db_insert); > zbx_free (snmp_community); > } > DBfree_result (result); > } > zabbix_log (LOG_LEVEL_DEBUG, "End of %s()", __function_name); > return; 723a865,890 > > > /****************************************************************************** > * * > * Function: op_macro_add * > * * > * Purpose: add macro for linked template * > * * > * Parameters: event - [IN] * > * Author: cheliequan * > * * > ******************************************************************************/ > void op_macro_add (const DB_EVENT * event) > { > const char *__function_name = "op_macro_add"; > zabbix_log (LOG_LEVEL_DEBUG, "In %s()", __function_name); > if (event->source != EVENT_SOURCE_DISCOVERY > && event->source != EVENT_SOURCE_AUTO_REGISTRATION) > return; > if (event->object != EVENT_OBJECT_DHOST > && event->object != EVENT_OBJECT_DSERVICE > && event->object != EVENT_OBJECT_ZABBIX_ACTIVE) > return; > add_host_macro (event); > zabbix_log (LOG_LEVEL_DEBUG, "End of %s()", __function_name); > }