When creating a rule like in the screenshot
SQL request is formed:
SELECT * FROM devices,bgpPeers_cbgp,bgpPeers WHERE (devices.device_id = ? AND devices.device_id = bgpPeers_cbgp.device_id AND devices.device_id = bgpPeers.device_id) AND bgpPeers.bgpPeerFsmEstablishedTime > 300 AND bgpPeers.bgpPeerState = "established" AND (devices.status = 1 && (devices.disabled = 0 && devices.ignore = 0)) = 1 AND bgpPeers_cbgp.AcceptedPrefixes_delta < -10
You can see that the “devices” table is joined with the “bgpPeers” table by the “device_id” field, and the “bgpPeers_cbgp” table is also joined with the “devices” table by the “devices_id” field, but must be joined with the “bgpPeers” table by the “device_id” field AND “bgpPeerIdentifier” field, or by the field “bgpPeer_id” (it is more logical, but the field “bgpPeer_id” not presented in the table “bgpPeers_cbgp”). It should look like this:
SELECT * FROM devices,bgpPeers_cbgp,bgpPeers WHERE (devices.device_id = ? AND devices.device_id = bgpPeers.device_id AND bgpPeers.device_id = bgpPeers_cbgp.device_id AND bgpPeers.bgpPeerIdentifier = bgpPeers_cbgp.bgpPeerIdentifier) AND bgpPeers.bgpPeerFsmEstablishedTime > 300 AND bgpPeers.bgpPeerState = "established" AND (devices.status = 1 && (devices.disabled = 0 && devices.ignore = 0)) = 1 AND bgpPeers_cbgp.AcceptedPrefixes_delta < -10
or (it is more logical, but the field “bgpPeer_id” not presented in the table “bgpPeers_cbgp”)
SELECT * FROM devices,bgpPeers_cbgp,bgpPeers WHERE (devices.device_id = ? AND devices.device_id = bgpPeers.device_id AND bgpPeers.bgpPeer_id = bgpPeers_cbgp.bgpPeer_id) AND bgpPeers.bgpPeerFsmEstablishedTime > 300 AND bgpPeers.bgpPeerState = "established" AND (devices.status = 1 && (devices.disabled = 0 && devices.ignore = 0)) = 1 AND bgpPeers_cbgp.AcceptedPrefixes_delta < -10
Version: 1.45-16-g01666e5 - Thu Nov 08 2018 00:04:45 GMT+0700
DB Schema #270