Skip to content

Commit

Permalink
Delete graphite data when resource gets deleted
Browse files Browse the repository at this point in the history
Tendrl-bug-id: Tendrl#148
  • Loading branch information
rishubhjain committed Sep 28, 2017
1 parent 2e1d15a commit 8d1b6c1
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
74 changes: 74 additions & 0 deletions tendrl/monitoring_integration/flows/update_graphite/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import etcd
import os
import datetime


from tendrl.commons import flows
from tendrl.commons.utils import log_utils as logger


WHISPER_PATH = "/var/lib/carbon/whisper/tendrl/"

class UpdateGraphite(flows.BaseFlow):

def run(self):
super(UpdateGraphite, self).run()
cluster_id = self.parameters.get("TendrlContext.integration_id")
resource_name = str(
self.parameters.get("Trigger.resource_name")).lower()
resource_type = str(
self.parameters.get("Trigger.resource_type")).lower()
self.update_graphite(cluster_id, resource_name, resource_type)

def update_graphite(cluster_id, resource_name, resource_type):
if resource_type = "volume":
resource_path = os.path.join(WHISPER_PATH, "clusters",
str(cluster_id),
"volumes", resource_name)
archive_path = os.path.join(WHISPER_PATH, "clusters",
str(cluster_id),
"archive", "volumes")
if not os.path.exists(archive_path):
os.system("mkdir " + str(archive_path))
resource_folder_name = str(resource_name) + "_" + \
str(datetime.datetime.now().isoformat())
archive_path = os.path.join(archive_path, resource_folder_name)
os.system("mkdir " + str(archive_path))
if os.path.exists(resource_path):
os.system("mv " + str(resource_path) + " " + str(archive_path) + "/.")
if os.path.exists(os.path.join(str(archive_path), resource_name)):
logger.log("info", NS.get("publisher_id", None),
{'message': "Volume " + str(resource_name) +
"deleted from graphite"})
else:
logger.log("error", NS.get("publisher_id", None),
{'message': "Volume " + str(resource_name) +
"deletion from graphite failed"})
if resource_type = "brick":
host_name = resource_name.split("|", 1)[1].split(":", 1)[0].replace(".", "_")
brick_name = resource_name.split("|", 1)[1].split(":", 1)[1].replace("/", '\|')
vol_name = resource_name.split("|", 1)[0]
archive_path = os.path.join(WHISPER_PATH, "clusters",
str(cluster_id),
"archive", "bricks")
if not os.path.exists(archive_path):
os.system("mkdir " + str(archive_path))
resource_folder_name = str(brick_name) + "_" + \
str(datetime.datetime.now().isoformat())
archive_path = os.path.join(archive_path, resource_folder_name)
os.system("mkdir " + str(archive_path))
resource_path = os.path.join(WHISPER_PATH, "clusters",
str(cluster_id), "nodes",
str(host_name), "bricks",
str(brick_name))
if os.path.exists(resource_path):
os.system("mv " + str(resource_path) + " " + str(archive_path) + "/.")
if os.path.exists(os.path.join(str(archive_path), brick_name)):
logger.log("info", NS.get("publisher_id", None),
{'message': "Brick " + str(resource_name) +
"deleted from graphite"})
else:
logger.log("error", NS.get("publisher_id", None),
{'message': "Brick " + str(resource_name) +
"deletion from graphite failed"})

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ namespace.monitoring:
type: Create
version: 1
uuid: 1951e821-7aa9-4a91-8183-e73bc8275bde
UpdateGraphite:
tags:
- tendrl/integration/monitoring
help: Update Graphite
enabled: true
inputs:
mandatory:
- TendrlContext.integration_id
- Trigger.resource_name
- Trigger.resource_type
run: monitoring.flows.UpdateGraphite
type: Create
version: 1
uuid: 1951e821-7aa9-4a91-8183-e73bc8275bfe
objects:
AlertTypes:
enabled: True
Expand Down

0 comments on commit 8d1b6c1

Please sign in to comment.