Skip to content

Commit

Permalink
rework logging
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-pickin-epi committed Oct 23, 2024
1 parent ff7af7c commit ef05db6
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions sensu-alertmanager
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def report(level, msg, alert=None):
def debug(msg):
report("debug", msg)

def log(msg):
report("info", msg)
def log(msg, alert=None):
report("info", msg, alert)

def warn(msg, alert=None):
report("warn", msg, alert)
Expand Down Expand Up @@ -97,7 +97,9 @@ def post(msg, retry=0):
alert.append(msg)

if retry:
log("Retry: {}".format(retry))
log("Retry: {}".format(retry), alert)
elif ((args.verbose > 0 and md['name'] != "keepalive") or (args.verbose > 1)):
log("Sending alert", alert)

try:
r = requests.post(args.alertmanager, json = alert, timeout = args.timeout)
Expand Down Expand Up @@ -134,9 +136,6 @@ def process(data):
if 'sensu' in msg['annotations'].keys():
msg['generatorURL'] ='https://{}/c/~/n/{}/events/{}/{}'.format(msg['annotations']['sensu'], md['namespace'], entity_name, md['name'])

if ((args.verbose > 0 and md['name'] != "keepalive") or (args.verbose > 1)):
log('Post:{}'.format(json.dumps(msg)))

post(msg)


Expand Down

0 comments on commit ef05db6

Please sign in to comment.