<commit_before>#!/usr/bin/python
######################################################################
# Cloud Routes Bridge
# -------------------------------------------------------------------
# Actions Module
######################################################################

import syslog
import time

import pygerduty


def action(**kwargs):
    ''' This method is called to action a reaction '''
    redata = kwargs['redata']
    jdata = kwargs['jdata']
    run = True
    # Check for Trigger
    if redata['trigger'] > jdata['failcount']:
        run = False

    # Check for lastrun
    checktime = time.time() - float(redata['lastrun'])
    if checktime < redata['frequency']:
        run = False

    #if redata['data']['call_on'] not in jdata['check']['status']:
    #    run = False

    if run:
        return actionPDTrigger(redata, jdata)
    else:
        return None


def actionPDTrigger(redata, jdata):
    ''' Perform EC2 Actions '''
    try:
        pager = pygerduty.PagerDuty(
            redata['data']['subdomain'],
            redata['data']['api_key'])
        try:
            service_key=redata['data']['service_key']
            description=redata['data']['description']
            details=redata['data']['details']
            incident_key=redata['data']['incident_key']

            # Should I test if incident_key is empty string or null?

            new_incident_key=pager.trigger_incident(service_key, description, incident_key, details)

            # What do I do with new_incident_key?

            return True
        except:
            return False
    except:
        line = "pagerduty-notification: Could not connect to PagerDuty for monitor %s" % jdata['cid']
        syslog.syslog(syslog.LOG_INFO, line)<commit_msg>we want to honor both hilo and lohi flips<commit_after>#!/usr/bin/python
######################################################################
# Cloud Routes Bridge
# -------------------------------------------------------------------
# Actions Module
######################################################################

import syslog
import time

import pygerduty


def action(**kwargs):
    ''' This method is called to action a reaction '''
    redata = kwargs['redata']
    jdata = kwargs['jdata']
    run = True
    # Check for Trigger
    if redata['trigger'] > jdata['failcount']:
        run = False

    # Check for lastrun
    checktime = time.time() - float(redata['lastrun'])
    if checktime < redata['frequency']:
        run = False

    if redata['data']['call_on'] not in jdata['check']['status']:
        run = False

    if run:
        return actionPDTrigger(redata, jdata)
    else:
        return None


def actionPDTrigger(redata, jdata):
    ''' Perform EC2 Actions '''
    try:
        pager = pygerduty.PagerDuty(
            redata['data']['subdomain'],
            redata['data']['api_key'])
        try:
            service_key=redata['data']['service_key']
            description=redata['data']['description']
            details=redata['data']['details']
            incident_key=redata['data']['incident_key']

            # Should I test if incident_key is empty string or null?

            new_incident_key=pager.trigger_incident(service_key, description, incident_key, details)

            # What do I do with new_incident_key?

            return True
        except:
            return False
    except:
        line = "pagerduty-notification: Could not connect to PagerDuty for monitor %s" % jdata['cid']
        syslog.syslog(syslog.LOG_INFO, line)
{'fraction_non_alphanumeric': 0.2206625491297024, 'fraction_numerical': 0.0005614823133071309, 'mean_word_length': 2.4965652600588815, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4819555', 'n_tokens_mistral': 980, 'n_tokens_neox': 938, 'n_words': 241}