Zabbix: Получаем по известному триггеру (triggerid) номера телефонов для оповещения
Мега запрос..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
SELECT sendto FROM media WHERE userid IN (SELECT userid FROM (SELECT users_groups.userid FROM operations INNER JOIN opmessage_grp ON opmessage_grp.operationid = operations.operationid INNER JOIN users_groups ON opmessage_grp.usrgrpid = users_groups.usrgrpid WHERE operations.actionid IN (SELECT actionid FROM conditions WHERE conditiontype = 2 AND value = 15266 UNION ALL SELECT actionid FROM conditions WHERE conditiontype = 0 AND value IN (SELECT groups.groupid FROM triggers INNER JOIN functions ON triggers.triggerid = functions.triggerid INNER JOIN items ON items.itemid = functions.itemid INNER JOIN hosts ON hosts.hostid = items.hostid INNER JOIN hosts_groups ON hosts_groups.hostid = hosts.hostid INNER JOIN groups ON groups.groupid = hosts_groups.groupid WHERE triggers.triggerid = 15266) UNION ALL SELECT actionid FROM conditions WHERE conditiontype = 1 AND value IN (SELECT hosts.hostid FROM triggers INNER JOIN functions ON triggers.triggerid = functions.triggerid INNER JOIN items ON items.itemid = functions.itemid INNER JOIN hosts ON hosts.hostid = items.hostid INNER JOIN hosts_groups ON hosts_groups.hostid = hosts.hostid INNER JOIN groups ON groups.groupid = hosts_groups.groupid WHERE triggers.triggerid = 15266)) UNION ALL SELECT opmessage_usr.userid FROM operations INNER JOIN opmessage_usr ON opmessage_usr.operationid = operations.operationid WHERE operations.actionid IN (SELECT actionid FROM conditions WHERE conditiontype = 2 AND value = 15266 UNION ALL SELECT actionid FROM conditions WHERE conditiontype = 0 AND value IN (SELECT groups.groupid FROM triggers INNER JOIN functions ON triggers.triggerid = functions.triggerid INNER JOIN items ON items.itemid = functions.itemid INNER JOIN hosts ON hosts.hostid = items.hostid INNER JOIN hosts_groups ON hosts_groups.hostid = hosts.hostid INNER JOIN groups ON groups.groupid = hosts_groups.groupid WHERE triggers.triggerid = 15266) UNION ALL SELECT actionid FROM conditions WHERE conditiontype = 1 AND value IN (SELECT hosts.hostid FROM triggers INNER JOIN functions ON triggers.triggerid = functions.triggerid INNER JOIN items ON items.itemid = functions.itemid INNER JOIN hosts ON hosts.hostid = items.hostid INNER JOIN hosts_groups ON hosts_groups.hostid = hosts.hostid INNER JOIN groups ON groups.groupid = hosts_groups.groupid WHERE triggers.triggerid = 15266))) AS us GROUP BY userid) AND mediatypeid = 5; |