def classify_issue(message):
    """ Classify issue type, team, component
    accept alert message
    return dict of classification """
    classifying_dict = MTConfigHandler().get_config_section('classification')
    return browse_classifying_dict(message.lower(),
                                   issue_dict=classifying_dict)
Beispiel #2
0
 def get_jira(self):
     """ Return jira connection from config
     if not exist init one """
     if not self._jira:
         jira_config = MTConfigHandler().get_config_section('jira')
         self._jira = JIRA(jira_config['host'],
                           basic_auth=(jira_config['id'],
                                       jira_config['password']))
     return self._jira
Beispiel #3
0
def is_auto_action_alert(alert=None):
    """ Verify if alert require auto action or not """
    if 'lvl_2' in alert['tags']:
        return False
    if '@' in alert['username']:
        return False
    auto_ticket_list = MTConfigHandler().get_config_section(
        'auto_escalation')['ticket']
    for issue in auto_ticket_list:
        if issue in alert['message']:
            return True
    return False
Beispiel #4
0
 def prepare_jira_detail_dict(self, alert=None):
     """ create a dict to create jira ticket """
     classified_dict = classify_issue(alert['message'])
     component = classified_dict['component']
     priority = classified_dict['priority']
     labels = ['push']
     opsgenie_alert = self.get_alert(alert_id=alert['alertId'])
     description = add_jira_opsgenie_syncback(opsgenie_alert.description,
                                              alert)
     jira_config = MTConfigHandler().get_config_section('jira')
     alias_field = jira_config['custom_fields']['opsgenie_alias']
     opsgenie_alias = alert['alias']
     jira_dict = {
         'component': component,
         'priority': priority,
         'labels': labels,
         'description': description,
         alias_field: opsgenie_alias
     }
     return jira_dict
""" Data model for Opsgenie """
from opsgenie.swagger_client import AlertApi
from opsgenie.swagger_client import configuration
from opsgenie.swagger_client.rest import ApiException
from opsgenie.swagger_client.models import AddAlertTagsRequest
from app.controllers.mt_config_handler import MTConfigHandler

configuration.api_key['Authorization'] = MTConfigHandler().get_config_section(
    'opsgenie')['apikey']
configuration.api_key_prefix['Authorization'] = 'GenieKey'


class MTOpsgenie(object):
    """ Class model for opsgenie """
    __opsgenie = None

    def __init__(self):
        if not self.__opsgenie:
            self.__opsgenie = AlertApi()

    def get_alert_from_id(self, alert_id):
        """ Get opsgenie alert from given alert ID """
        try:
            response = AlertApi().get_alert(identifier=alert_id)
            return response.data
        except ApiException as err:
            raise err

    def get_alert_from_tiny_id(self, tiny_id):
        """ Get opsgenie alert from given tiny ID """
        try:
Beispiel #6
0
 def return_view(self):
     """ Return config page """
     config = MTConfigHandler().get_config()
     return render_template('config.html', name='Bender', config=config)
Beispiel #7
0
 def return_json_view(self):
     """ Return config in json format """
     return jsonify(MTConfigHandler().get_config())