Created
January 23, 2025 00:26
-
-
Save LuisCardenasSolis/d8a503eb6c14b5aed2e6244dd549c07c to your computer and use it in GitHub Desktop.
Consult SQL for count hosts UP and DOWN from zabbix groups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| g.name AS grupo, | |
| COUNT(DISTINCT h.hostid) AS total, | |
| SUM(CASE WHEN ts.value = 0 THEN 1 ELSE 0 END) AS up, | |
| SUM(CASE WHEN ts.value = 1 THEN 1 ELSE 0 END) AS down | |
| FROM | |
| hosts h | |
| JOIN | |
| hosts_groups hg ON h.hostid = hg.hostid | |
| JOIN | |
| hstgrp g ON hg.groupid = g.groupid | |
| LEFT JOIN ( | |
| SELECT | |
| h.hostid AS hostid, | |
| t.value AS value | |
| FROM | |
| hosts h | |
| JOIN | |
| items i ON h.hostid = i.hostid | |
| JOIN | |
| functions f ON i.itemid = f.itemid | |
| JOIN | |
| triggers t ON f.triggerid = t.triggerid | |
| WHERE | |
| i.key_ = 'icmpping' | |
| ) ts ON h.hostid = ts.hostid | |
| WHERE | |
| g.name IN ('Servidores Linux', 'Firewalls') | |
| GROUP BY | |
| g.name | |
| ORDER BY | |
| total DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment