I think your INSERT statement should be like this -
...
INSERT INTO db2.Hearbeat_tbl (ID,EventName,Hostname,UpdInterval,State,ExternalCmd,ThreadID)
VALUES (new.triggerid,new.description,@hostName,'10',0,'MyExternalCommand',0);
...
---------------------------------------------------------
Another way - try to use one INSERT...SELECT query to fill the Heartbeat_tbl table.
This SELECT query should return the 'host' you need:
SELECT h.host FROM functions f
JOIN items i
ON i.itemid = f.itemid
JOIN hosts h
ON h.hostid = i.hostid
WHERE f.triggerid = NEW.triggerid;
Insert query:
INSERT INTO db2.Hearbeat_tbl (ID, EventName, Hostname, UpdInterval, State, ExternalCmd, ThreadID)
SELECT
NEW.triggerid,
NEW.description,
h.host,
'10',
0,
'MyExternalCommand',
0
FROM functions f
JOIN items i
ON i.itemid = f.itemid
JOIN hosts h
ON h.hostid = i.hostid
WHERE f.triggerid = NEW.triggerid;
Devart Company,
MySQL management tools
http://www.devart.com/dbforge/mysql/