allow all pushsrvs, fix boot msg timing

This commit is contained in:
2020-02-04 18:21:59 -05:00
parent de283cb1a9
commit 328ce83058
+18 -14
View File
@@ -199,12 +199,12 @@ def email(s, msg):
return ret return ret
def pushmsg(msg): def pushmsg(msg):
if pushsrv == "pushover": if pushsrv in ["all", "pushover"]:
return pushover(msg) pushover(msg)
elif pushsrv == "mattermost": if pushsrv in ["all","mattermost"]:
return pushmattermost(msg) return pushmattermost(msg)
else: if pushsrv in ["all"]:
print(msg) print("notice:", msg)
def pushover(msg): def pushover(msg):
@@ -225,7 +225,7 @@ CHANNEL = "Monitoring"
TOKEN = "rxz6b3886iygxnhbzpmgbsrocy" TOKEN = "rxz6b3886iygxnhbzpmgbsrocy"
HOST = "192.168.10.101" HOST = "192.168.10.101"
ICON = "https://in-transit.ca/HeartBeat.png" ICON = "https://in-transit.ca/HeartBeat.png"
USERNAME = "nagios" USERNAME = "admin"
def pushmattermost(msg): def pushmattermost(msg):
@@ -445,9 +445,17 @@ def readsock(sock):
message = msg.get('msg', None) message = msg.get('msg', None)
boot = msg.get('boot', 0) boot = msg.get('boot', 0)
conn, res = host.conndata(cid, addr[0], rtt, now)
if res:
log(name, res)
if name in watchhosts:
email("address change", "%s %s" % (host.name, res))
pushmsg("%s %s" % (host.name, res))
if boot: if boot:
log(name, "booted") log(name, "booted")
if name in watchhosts: if name in watchhosts:
m = "%s booted" % (host.name)
email("booted", m) email("booted", m)
pushmsg(m) pushmsg(m)
if message: if message:
@@ -456,12 +464,6 @@ def readsock(sock):
email("msg", message) email("msg", message)
pushmsg(message) pushmsg(message)
conn, res = host.conndata(cid, addr[0], rtt, now)
if res:
log(name, res)
if name in watchhosts:
email("address change", "%s %s" % (host.name, res))
pushmsg("%s %s" % (host.name, res))
if conn.getstate() != hbdclass.Connection.up: # XXX and interval > 0: if conn.getstate() != hbdclass.Connection.up: # XXX and interval > 0:
lasts = conn.state lasts = conn.state
@@ -799,7 +801,7 @@ def pickleit():
# #
# Main # Main
# #
PUSHSRVS = [ "pushover", "mattermost" ] PUSHSRVS = ["all", "pushover", "mattermost" ]
helpflag = False helpflag = False
forground = False forground = False
pushsrv = "pushover" # mattermost pushsrv = "pushover" # mattermost
@@ -837,7 +839,7 @@ for o, a in optlist:
DEBUG += 1 DEBUG += 1
cmdargs += [o] cmdargs += [o]
if pushsrv == "mattermost": if pushsrv in ["all", "mattermost"]:
try: try:
from mattermostdriver import Driver from mattermostdriver import Driver
except: except:
@@ -933,6 +935,8 @@ if f:
drophosts = a drophosts = a
elif o == 'nsupdate_bin': elif o == 'nsupdate_bin':
nsupdate_bin = a nsupdate_bin = a
elif o == 'pushsrv':
pushsrv = a
f.close() f.close()
if len(args) != 0: if len(args) != 0: