(redata, jdata, logger)
Perform Heroku Actions
Perform Heroku Actions
Perform Heroku Actions
def callAction(redata, jdata, logger):
    ''' Perform Heroku Actions '''
    # Ready API Request
    # Generate Base64 encoded API Key
    basekey = base64.b64encode(":" + redata['data']['apikey'])
    # Create headers for API call
    headers = {
        "Accept" : "application/vnd.heroku+json; version=3",
        "Authorization" : basekey
    }
    # Set Timeout value for API Call
    timeout = 5.00
    # URL to request
    url = "https://api.heroku.com/apps/%s/dynos/%s" % (
      redata['data']['appname'],
      redata['data']['dynoname']
    )
    # Perform API Call
    try:
        result = requests.delete(
          url,
          timeout=timeout,
          headers=headers,
          verify=True
        )
    except:
        # If fail return False to mark reaction false
        return False
        line = ("heroku-restart-dyno: Could not connect to Heroku"
                " for monitor %s") % jdata['cid']
        logger.info(line)

    # Process results
    # Log heroku results for troubleshooting later
    line = ("heroku-restart-dyno: Got status code reply %d from Heroku"
            " for monitor %s") % (result.status_code, jdata['cid'])
    logger.debug(line)
    # Verify we got a 201 and set as success, or set as failure
    if result.status_code == 202:
        return True
    else:
        line = ("heroku-restart-dyno: Monitor %s got %s from Heroku after"
                " making a request to %s") % (jdata['cid'], result.text, url)
        logger.debug(line)
        return False
def callAction ( redata , jdata , logger ) : # Ready API Request # Generate Base64 encoded API Key basekey = base64 . b64encode ( ":" + redata [ 'data' ] [ 'apikey' ] ) # Create headers for API call headers = { "Accept" : "application/vnd.heroku+json; version=3" , "Authorization" : basekey } # Set Timeout value for API Call timeout = 5.00 # URL to request url = "https://api.heroku.com/apps/%s/dynos/%s" % ( redata [ 'data' ] [ 'appname' ] , redata [ 'data' ] [ 'dynoname' ] ) # Perform API Call try : result = requests . delete ( url , timeout = timeout , headers = headers , verify = True ) except : # If fail return False to mark reaction false return False line = ( "heroku-restart-dyno: Could not connect to Heroku" " for monitor %s" ) % jdata [ 'cid' ] logger . info ( line ) # Process results # Log heroku results for troubleshooting later line = ( "heroku-restart-dyno: Got status code reply %d from Heroku" " for monitor %s" ) % ( result . status_code , jdata [ 'cid' ] ) logger . debug ( line ) # Verify we got a 201 and set as success, or set as failure if result . status_code == 202 : return True else : line = ( "heroku-restart-dyno: Monitor %s got %s from Heroku after" " making a request to %s" ) % ( jdata [ 'cid' ] , result . text , url ) logger . debug ( line ) return False