diff --git a/hbd b/hbd index 4bbb553..b66bf6c 100755 --- a/hbd +++ b/hbd @@ -199,12 +199,12 @@ def email(s, msg): return ret def pushmsg(msg): - if pushsrv == "pushover": - return pushover(msg) - elif pushsrv == "mattermost": + if pushsrv in ["all", "pushover"]: + pushover(msg) + if pushsrv in ["all","mattermost"]: return pushmattermost(msg) - else: - print(msg) + if pushsrv in ["all"]: + print("notice:", msg) def pushover(msg): @@ -225,7 +225,7 @@ CHANNEL = "Monitoring" TOKEN = "rxz6b3886iygxnhbzpmgbsrocy" HOST = "192.168.10.101" ICON = "https://in-transit.ca/HeartBeat.png" -USERNAME = "nagios" +USERNAME = "admin" def pushmattermost(msg): @@ -445,9 +445,17 @@ def readsock(sock): message = msg.get('msg', None) 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: log(name, "booted") if name in watchhosts: + m = "%s booted" % (host.name) email("booted", m) pushmsg(m) if message: @@ -456,12 +464,6 @@ def readsock(sock): email("msg", 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: lasts = conn.state @@ -799,7 +801,7 @@ def pickleit(): # # Main # -PUSHSRVS = [ "pushover", "mattermost" ] +PUSHSRVS = ["all", "pushover", "mattermost" ] helpflag = False forground = False pushsrv = "pushover" # mattermost @@ -837,7 +839,7 @@ for o, a in optlist: DEBUG += 1 cmdargs += [o] -if pushsrv == "mattermost": +if pushsrv in ["all", "mattermost"]: try: from mattermostdriver import Driver except: @@ -933,6 +935,8 @@ if f: drophosts = a elif o == 'nsupdate_bin': nsupdate_bin = a + elif o == 'pushsrv': + pushsrv = a f.close() if len(args) != 0: