<commit_before>from etcd import EtcdKeyNotFound
from subprocess import CalledProcessError
from tendrl.commons.event import Event
from tendrl.commons.message import ExceptionMessage
from tendrl.monitoring_integration.alert import constants
from tendrl.monitoring_integration.alert.handlers import AlertHandler
from tendrl.monitoring_integration.alert import utils
from tendrl.monitoring_integration.alert.exceptions import InvalidAlertSeverity
from tendrl.monitoring_integration.alert.exceptions import NodeNotFound


class CapacityUtilizationHandler(AlertHandler):

    handles = 'capacity'
    representive_name = 'capacity_utilization_alert'

    def __init__(self):
        AlertHandler.__init__(self)
        self.template = "tendrl.clusters.{cluster_id}.nodes.{host_name}.bricks"

    def format_alert(self, alert_json):
        alert  = self.parse_alert_metrics(alert_json)
        try:
            alert["alert_id"] = None
            alert["node_id"] = utils.find_node_id(
                alert['tags']['integration_id'],
                alert['tags']['fqdn']
            )
            alert["time_stamp"] = alert_json['NewStateDate']
            alert["resource"] = self.representive_name
            alert['alert_type'] = constants.ALERT_TYPE 
            alert['severity'] = constants.TENDRL_GRAFANA_SEVERITY_MAP[
                alert_json['State']]
            alert['significance'] = constants.SIGNIFICANCE_HIGH
            alert['pid'] = utils.find_grafana_pid()
            alert['source'] = constants.ALERT_SOURCE
            alert['tags']['fqdn'] = alert['tags']['fqdn']
            alert['classification'] = alert_json["classification"]
            if alert['severity'] == "WARNING":
                alert['tags']['message'] = ("Capacity utilization trend of node %s is" \
                " %s which is above the %s threshold (%s)." % (
                    alert['tags']['fqdn'],
                    alert['current_value'],
                    alert['severity'],
                    alert['tags']['warning_max']
                ))
            elif alert['severity'] == "INFO":
                alert['tags']['message'] = ("Capacity utilization trend of node %s is"\
                " back to normal" % (
                    alert['tags']['fqdn']
                ))
            else:
                logger.log(<commit_msg>Added handler for capacity utilization trend in node level<commit_after>from etcd import EtcdKeyNotFound
from subprocess import CalledProcessError
from tendrl.commons.event import Event
from tendrl.commons.message import ExceptionMessage
from tendrl.monitoring_integration.alert import constants
from tendrl.monitoring_integration.alert.handlers import AlertHandler
from tendrl.monitoring_integration.alert import utils
from tendrl.monitoring_integration.alert.exceptions import InvalidAlertSeverity
from tendrl.monitoring_integration.alert.exceptions import NodeNotFound


class CapacityUtilizationHandler(AlertHandler):

    handles = 'capacity'
    representive_name = 'capacity_utilization_alert'

    def __init__(self):
        AlertHandler.__init__(self)
        self.template = "tendrl.clusters.{cluster_id}.nodes.{host_name}.bricks"

    def format_alert(self, alert_json):
        alert  = self.parse_alert_metrics(alert_json)
        try:
            alert["alert_id"] = None
            alert["node_id"] = utils.find_node_id(
                alert['tags']['integration_id'],
                alert['tags']['fqdn']
            )
            alert["time_stamp"] = alert_json['NewStateDate']
            alert["resource"] = self.representive_name
            alert['alert_type'] = constants.ALERT_TYPE 
            alert['severity'] = constants.TENDRL_GRAFANA_SEVERITY_MAP[
                alert_json['State']]
            alert['significance'] = constants.SIGNIFICANCE_HIGH
            alert['pid'] = utils.find_grafana_pid()
            alert['source'] = constants.ALERT_SOURCE
            alert['tags']['fqdn'] = alert['tags']['fqdn']
            alert['classification'] = alert_json["classification"]
            if alert['severity'] == "WARNING":
                alert['tags']['message'] = ("Storage utilization of node %s is" \
                " %s which is above the %s threshold (%s)." % (
                    alert['tags']['fqdn'],
                    alert['current_value'],
                    alert['severity'],
                    alert['tags']['warning_max']
                ))
            elif alert['severity'] == "INFO":
                alert['tags']['message'] = ("Storage utilization of node %s is"\
                " back to normal" % (
                    alert['tags']['fqdn']
                ))
            else:
                logger.log(
{'fraction_non_alphanumeric': 0.11377626830821481, 'fraction_numerical': 0.0, 'mean_word_length': 2.4621601763409258, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5835167', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1211, 'n_words': 241}