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

Raise alerts for volume/brick status change. #288

Merged
merged 2 commits into from
Jun 7, 2017
Merged
Changes from 1 commit
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
112 changes: 112 additions & 0 deletions tendrl/gluster_integration/sds_sync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import os
import re
import socket
import subprocess

from tendrl.gluster_integration.sds_sync import brick_utilization
Expand All @@ -12,6 +13,7 @@

from tendrl.commons import sds_sync
from tendrl.gluster_integration import ini2json
from tendrl.commons.utils.time_utils import now as tendrl_now


class GlusterIntegrationSdsSyncStateThread(sds_sync.SdsSyncThread):
Expand All @@ -20,6 +22,37 @@ def __init__(self):
super(GlusterIntegrationSdsSyncStateThread, self).__init__()
self._complete = gevent.event.Event()

def _emit_event(self, resource, curr_value, msg, instance):
alert = {}
alert['source'] = NS.publisher_id
alert['pid'] = os.getpid()
alert['time_stamp'] = tendrl_now().isoformat()
alert['alert_type'] = 'status'
severity = "info"
if curr_value == "Stopped":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use lower case for string comparison

severity = "critical"
alert['severity'] = severity
alert['resource'] = resource
alert['current_value'] = curr_value
alert['tags'] = dict(
plugin_instance=instance,
message=msg,
cluster_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)}
)
)

def _run(self):
Event(
Message(
Expand Down Expand Up @@ -82,8 +115,38 @@ def _run(self):
if "Volumes" in raw_data:
index = 1
volumes = raw_data['Volumes']
node_context = NS.node_context.load()
tag_list = list(node_context.tags)
while True:
try:
# Raise alerts for volume state change.
cluster_provisioner = "provisioner/%s" % NS.tendrl_context.integration_id
if cluster_provisioner in tag_list:
try:
stored_volume_status = NS._int.client.read(
"clusters/%s/Volumes/%s/status" % (
NS.tendrl_context.integration_id,
volumes['volume%s.id' % index]
)
).value
current_status = volumes['volume%s.status' % index]
if current_status != stored_volume_status:
msg = "Status of volume: %s changed from %s to %s" % (
volumes['volume%s.name' % index],
stored_volume_status,
current_status
)
instance = "volume_%s" % volumes['volume%s.name' % index]
self._emit_event(
"volume_status",
current_status,
msg,
instance
)

except etcd.EtcdKeyNotFound:
pass

volume = NS.gluster.objects.Volume(
vol_id=volumes[
'volume%s.id' % index
Expand Down Expand Up @@ -187,6 +250,55 @@ def _run(self):
hostname not in network_ip):
b_index += 1
continue

# Raise alerts if the brick path changes
try:
stored_brick_status = NS._int.client.read(
"clusters/%s/Volumes/%s/Bricks/%s/status" % (
NS.tendrl_context.integration_id,
volumes['volume%s.id' % index],
volumes[
'volume%s.brick%s.path' % (
index, b_index
)
].replace("/", "_")
)
).value
current_status = volumes.get(
'volume%s.brick%s.status' % (
index,
b_index
)
)
if current_status != stored_brick_status:
msg = "Status of brick: %s under volume %s changed from %s to %s" % (
volumes[
'volume%s.brick%s.path' % (
index, b_index
)
],
volumes['volume%s.name' % index],
stored_brick_status,
current_status
)
instance = "volume_%s|brick_%s" % (
volumes['volume%s.name' % index],
volumes[
'volume%s.brick%s.path' % (
index, b_index
)
]
)
self._emit_event(
"brick_status",
current_status,
msg,
instance
)

except etcd.EtcdKeyNotFound:
pass

brick = NS.gluster\
.objects.Brick(
vol_id=volumes['volume%s.id' % index],
Expand Down