Giter Club home page Giter Club logo

newrelic-api's Introduction

image

image

Latest PyPI version

Number of PyPI downloads

newrelic-api: A Python interface to New Relic's API

newrelic-api is a package for easily interacting with New Relic's API in a concise, pythonic way. For full documentation on each endpoint, please see New Relic's API explorer. This is based off of the v2 API.

Project status

This client is out of sync with the latest changes to New Relic's APIs, work is under way to update this project and bring it up to date. If you need to use an NR resource that is not supported or is out of date then please submit a PR.

Installation

To install, install via pip or easy_install:

$ pip install newrelic-api
or
$ easy_install newrelic-api

If you want to install it from source, grab the git repository and run setup.py:

$ git clone git://github.com/ambitioninc/newrelic-api.git
$ cd newrelic-api
$ python setup.py install

Documentation

All documentation can be found at http://new-relic-api.readthedocs.org

Author

Micah Hausler

newrelic-api's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

newrelic-api's Issues

Filtering servers by label doesn't work

I think this is an actual bug in the documentation but testing with requests shows that this works:

requests.get('https://api.newrelic.com/v2/servers.json', headers={'X-Api-Key':'key'}, data={'filter[labels]':'Type:Elasticsearch'}).json()

While this which looks like it is what this project is currently using, doesn't:

requests.get('https://api.newrelic.com/v2/servers.json?filter[labels]=Type:Elastisearch', headers={'X-Api-Key':'key'}).json()

newrelic-api and newrelic parameter changes.

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

Support for returning data within a time range

Would be great to introduce the ability to return data within a time range.

This functionality isn't available in the New Relic API Explorer, but works if you're calling it manually via CURL as per this doc https://docs.newrelic.com/docs/apis/rest-api-v2/requirements/extracting-metric-data

For example, the below would return the metrics between 05/09/2014 - 11/09/2015 in 1 hour periods;

-d'names[]=from=2015-09-05T10:00:00+00:00&to=2015-09-11T10:00:00+00:00&period=3600'

Python isn't my primary language, but I'lltry and submit a pull request myself unless someone thinks they can do it before me.

Support condition update when conditions are paginated

Currently alert_conditions.update(...) calls alert_conditions.list() to see if the condition already exists. If it doesn't exist, update(...) gives a NoEntityException with message: "Target alert condition is not included in that policy." That makes sense.

However, list() only returns the first page of conditions. If the condition we want to update exists on the second page, we will also receive the exception.

Instead, we want update() to look through all pages of conditions to see if the one we're trying to update exists.

Project maintainer

This repo is out of date with New Relics APIs and seems to be no longer maintained @ambitioninc do you have any plans to keep this project going?

I work on a fork (https://github.com/sansible/newrelic-api) where we have been adding support for the current NR APIs, would it be possible to get these changes merged over here? Looking at the PRs on this repo it seems that nothing has been merged for a while.

Alert Policies API is Depreceted

Hi,

When I follow the docs to get alert policies, I get the following error:

Traceback (most recent call last):
File ".../newrelic_api/alert_policies.py", line 95, in list
params=self.build_param_string(filters)
File ".../newrelic_api/base.py", line 47, in _get
raise NewRelicAPIServerException('{}: {}'.format(response.status_code, response.text))
NewRelicAPIServerException: 410: {"error":{"title":"The alert policies API is deprecated. Please see 'alerts.newrelic.com' for the new alerting infrastructure."}}

Any idea why this is happening? When I test the GET query on New Relic's API Explorer or when I use Perl to import the data, I don't have any problems.
Maybe there is something wrong with the way the header parameters are created?

Pagination link support

Is there some way to be able to use the pagination links which are returned in the Link header with the response?

Link: <https://api.newrelic.com/v2/servers.json?page=2>; rel="next", <https://api.newrelic.com/v2/servers.json?page=6>; rel="last"

I've got a lot of servers which I'd like to delete any which are not reporting, and I'm not really seeing a way to do that right now.

Thanks!

response.json() should be called only after checking response.status = OK

First of all, thank you for this excellent API client. I appreciate you guys sharing your good work.

Issue

Sometimes, NewRelic's API responds with Internal Server Error 500, which breaks the assumption that the response object's json() method will successfully return.

This is what happens now when the server errors:

client.update(6741145, name='blah')
*** JSONDecodeError: Expecting value: line 1 column 1 (char 0)

At this point, response.content contains an HTML document of the NewRelic homepage, probably just their default error handling page. This is not good API error implementation, and I've filed a issue with NewRelic support on this.

Recommendation

  1. create custom exceptions to represent server errors gracefully (e.g. NewRelicAPIServerError)
  2. if response.status != 200, raise NewRelicAPIServerError with helpful message

Scope

Here are all the places that could use a safety check:
https://github.com/ambitioninc/newrelic-api/search?utf8=%E2%9C%93&q=%22return+response.json%22&type=Code

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.