Last active
December 21, 2015 11:59
-
-
Save eedeep/6302514 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def toggle_new_relic_availability_monitoring(host_tag, action): | |
"""Given a valid action and a host tagname in env dictionary (shared among all tasks) | |
make an API call to newrelic to toggle availability monitoring on or off.""" | |
valid_actions = ['enable', 'disable',] | |
if action.lower() not in valid_actions: | |
raise Exception('You must specify a valid action. Valid actions '\ | |
'are: {valid_actions}'.format(valid_actions=valid_actions})) | |
try: | |
app_id = NEW_RELIC_APPS[host_tag] | |
except KeyError: | |
raise Exception('Could not find a new relic app ID for tag: {host_tag} .'\ | |
'Be sure you pass a valid tag name.'.format(host_tag=host_tag)) | |
result = requests.post( | |
'https://rpm.newrelic.com/accounts/{account_id}/applications/{app_id}/{action}'.format( | |
account_id=NEW_RELIC_ACCOUNT_ID, | |
app_id=app_id, | |
action=action | |
), | |
headers=NEW_RELIC_HEADERS) | |
) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment