Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

where are my filters? (untested) #117

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions ZbxTgDaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def db_query(self, query):

return result

def triggers(self):
def triggers(self, severity):
q = "SELECT h.name AS host, h.hostid AS hostid, t.triggerid," \
"t.description AS `trigger`, t.priority AS severity, t.lastchange " \
"FROM triggers t " \
Expand All @@ -58,12 +58,16 @@ def triggers(self):
"LEFT JOIN hosts_groups hg ON h.hostid = hg.hostid " \
"LEFT JOIN groups g ON hg.groupid = g.groupid " \
"LEFT JOIN interface ifa ON h.hostid = ifa.hostid AND ifa.main = 1 " \
"WHERE t.value = 1 " \
"WHERE " + "t.value = 1 " \
"AND h.status = 0 " \
"AND t.status = 0 " \
"AND i.status = 0 " \
"AND t.priority > 0 " \
"GROUP BY t.triggerid;"
"AND i.status = 0 "
if severity:
q += "AND t.priority = {0} " \
"GROUP BY t.triggerid;".format(severity)
else:
q += "AND t.priority > 0 " \
"GROUP BY t.triggerid;"
print q
result = self.db_query(q)
return result
Expand Down Expand Up @@ -191,7 +195,8 @@ def md5(fname):
#print type(message_id_last)
if m["message"]["message_id"] > message_id_last:
if re.search(r"^/triggers", text):
triggers = zbxdb.triggers()
severity = text[10:]
triggers = zbxdb.triggers(severity)
if triggers:
for t in triggers:
reply_text.append("Severity: {0}, Host: {1}, Trigger: {2}".format(
Expand All @@ -212,4 +217,4 @@ def md5(fname):


if __name__ == "__main__":
main()
main()