Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

newrelic-api and newrelic parameter changes. #30

Open
bngweber opened this issue Apr 21, 2016 · 0 comments
Open

newrelic-api and newrelic parameter changes. #30

bngweber opened this issue Apr 21, 2016 · 0 comments

Comments

@bngweber
Copy link

Following the example in the docs for moving an application to a different policy, I am attempting to move a server to a different policy. My code is as follows.

! /usr/bin/python

from newrelic_api import AlertPolicies, Servers

server_id = Servers().list(
filter_name='<server_name>'
)['servers'][0]['id']

non_notify_policy = AlertPolicies().list(
filter_name='<policy_name>',
filter_type=['server'],
filter_enabled=True
)['alert_policies'][0]

server_in_policy = server_id in non_notify_policy.get('links', {}).get('servers')

if not server_in_policy:
server_ids = non_notify_policy['links']['servers']
server_ids.append(server_id)

new_alert_policy = non_notify_policy.copy()
new_alert_policy['links']['servers'] = server_ids

AlertPolicies().update(
    id=new_alert_policy['id'],
    policy_update=new_alert_policy
)

When run I get the following errors.

/usr/bin/python2.7 /home/user/PycharmProjects/new_relic_maintenance_mode_disable_alerts/new_relic_maintenance_mode_disable_Alerts
Traceback (most recent call last):
File "/home/user/PycharmProjects/new_relic_maintenance_mode_disable_alerts/new_relic_maintenance_mode_disable_Alerts", line 25, in
policy_update=new_alert_policy
File "/home/user/.local/lib/python2.7/site-packages/newrelic_api/alert_policies.py", line 239, in update
data=policy_update
File "/home/user/.local/lib/python2.7/site-packages/newrelic_api/base.py", line 71, in _put
raise NewRelicAPIServerException('{}: {}'.format(response.status_code, response.text))
newrelic_api.exceptions.NewRelicAPIServerException: 400: {"error":{"title":"missing parameter: alert_policy"}}

Process finished with exit code 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant