forked from Tendrl/commons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP - Added alerting mechanism for job status
tendrl-bug-id: Tendrl/node-agent#602 Signed-off-by: Shubhendu <shtripat@redhat.com>
- Loading branch information
Shubhendu
committed
Sep 6, 2017
1 parent
2c36537
commit cb3db7e
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import json | ||
import os | ||
import socket | ||
|
||
from tendrl.commons.event import Event | ||
from tendrl.commons.message import Message | ||
from tendrl.commons.utils.time_utils import now as tendrl_now | ||
|
||
|
||
def alert_job_status(curr_value, msg): | ||
import pdb; pdb.set_trace() | ||
alert = {} | ||
alert['source'] = NS.publisher_id | ||
alert['classification'] = 'cluster' | ||
alert['pid'] = os.getpid() | ||
alert['time_stamp'] = tendrl_now().isoformat() | ||
alert['alert_type'] = 'STATUS' | ||
severity = "INFO" | ||
if curr_value.lower() == "failed": | ||
severity = "WARNING" | ||
alert['severity'] = severity | ||
alert['resource'] = 'cluster' | ||
alert['current_value'] = curr_value | ||
alert['tags'] = dict( | ||
message=msg, | ||
integration_id=NS.tendrl_context.integration_id, | ||
cluster_name=NS.tendrl_context.cluster_name, | ||
sds_name=NS.tendrl_context.sds_name, | ||
fqdn=socket.getfqdn() | ||
) | ||
alert['node_id'] = NS.node_context.node_id | ||
if not NS.node_context.node_id: | ||
return | ||
Event( | ||
Message( | ||
"notice", | ||
"alerting", | ||
{'message': json.dumps(alert)} | ||
) | ||
) |