How to get application uptime report with New Relic API ? - api

I need to get a weekly report of my applications uptime.
The metric is available on the "SLA Report" screen (http://awesomescreenshot.com/0f02fsy34e) but i can't find a way to get it programatically.
Other SLA metrics are available using the API : http://docs.newrelic.com/docs/features/sla-report-examples#metrics

The uptime information is not considered a metric so is not available via the REST API. If you like you may contact support.newrelic.com to request this as a new feature.

Even though there was no direct api request for getting uptime from newrelic we can give the nrql queries inside curl.
curl -X POST -H "Accept: application/xml" -H "X-Query-Key: your_query_api_key" -d "nrql=SELECT+percentage(count(*)%2c+WHERE+result+%3d+'SUCCESS')+FROM+SyntheticCheck+SINCE+1+week+ago+WHERE+monitorName+%3d+'your+monitor+name'+FACET+dateOf(timestamp)" "https://insights-api.newrelic.com/v1/accounts/your_account_id/query"
The above curl will give uptime percentages distributed by Days of week. If you don't know how to url encode your nrql query please try this http://string-functions.com/urlencode.aspx. Hope this helps.

mm. I figured out that the following gives a csv formatted text content and could be useful for extracting data (monthly), but it's not going ask you for credentials on the tool / command line you use. (Beware). Since i export the monthly metrics from my machine, it's simple for me to make it work, and it really gives me much more flexibility.
https://rpm.newrelic.com/optimize/sla_report/run?account_id=<account_id>&application_id=<app_id>&format=csv&interval=months

Related

API Cursor Based Pagination with Curl

currently im working on a project for university. The goal is to make api calls with cmd (Curl) and transfer the data into a bi tool. I dont have any experience with coding/scripting and so on. The problem i currently have is that a single api call brings back 100 resources but i need all of the Data to visualize it.
curl -X get "https://(url)" -H "accept: application/json" -H "authorization: Basic (Username:Password) --proxy () --output () --output-dir ()
So my goal here is to create like a loop so that all of the data ist getting saved in one file.
Any Ideas?
Thank you !
Either it is in the API documentation how to get all the pages or there are Range headers or there are Link headers or hyperlinks attached to the response body for the next/previous pages or there is a MIME type e.g. JSON-LD, HTML, XML, etc. you can request with Accept header which contains hyperlinks. Without knowing the exact API it is not possible to tell which implementation the API developers chose. Maybe they were lazy and neither of them.

How to get all unread items using Feedly API

OK, either this is incredibly obvious and I'm just too dumb to see it, or it is not possible at all.
I created a Feedly developer access token and can call some end points just fine, like /profile, /categories, etc. Currently testing them with curl, but eventually will do this in Ruby.
What I can't find from the documentation (or even by Googling) is how to access all the unread entries from all my subscriptions just like I do in the Feedly app:
As far as I understand, Streams are for specific feeds. And the closest thing to the All stream, I think, is the Global Resource Id "global.all". But when I call it according to the documentation I get "API handler not found".
curl -H 'Authorization: OAuth [<MY_ACCESS_TOKEN>]' http://cloud.feedly.com/v3/user/<MY_USER_ID>/category/global.all
{"errorCode":404,"errorId":"ap5int-sv2.2018082612.1607238","errorMessage":"API handler not found"}
At some point I thought maybe Feedly just doesn't support this and went and looked at Inoreader's API documentation and it looks pretty much the same. There is no /All stream where I can pull my unread entries. So I feel like I'm missing something very obvious here.
What I am trying to do:
Basically I want to create an app for myself where I pull all my unread entries and flag the ones I'm interested in as "Read Later". This is part of a bigger workflow app that I'm working on.
You're almost there. To get a stream of all your unread articles, the syntax would be:
curl -H 'Authorization: OAuth <access token>' 'https://cloud.feedly.com/v3/streams/contents?streamId=user/<user id>/category/global.all&unreadOnly=true'
The <user id> can be obtained by the Profile API which can be found here.
The streams API is documented here.
Hope this helps.

Jira -- How to get issue changelog via REST API - but ALL, not single issue

I've seen this question many times, but no sufficient answer.
We're trying to dump all JIRA data into our data warehouse/ BI system. Or at least, the interesting parts.
One thing you can do is track status times, cycle time, lead time directly with field durations. This is very easy via JIRA's direct SQL database. The tables changeItem and changeGroup.
Of course the REST JSON API has less performance impact on the database.
However ... there appears to be no equivalent in the rest API of fetching ALL issue change history. Yes, you can fetch the changelog of one issue directly via an API call. If you have 100k issues, are you expected to make 100k API calls, iterating through issue IDs? Sounds like madness.
Is it somehow possible to expand changelogs through the search API, which amasses all issue data? I haven't seen it. Is what I'm seeking here possible? Or will we have to stick to the SQL route?
I think you are asking pretty much the same question as before: How can I fetch (via GET) all JIRA issues? Do I go to the Search node?, but additionally interesting in getting changelog data.
Yes, again you have to do it in batch, requesting JIRA API several times.
Here is little bash script, which could help you to do that:
#!/usr/bin/env bash
LDAP_USERNAME='<username>'
LDAP_PASSWORD='<password>'
JIRA_URL='https://jira.example.com/rest/api/2/search?'
JQL_QUERY='project=FOOBAR'
START_AT=0
MAX_RESULTS=50
TOTAL=$(curl --silent -u "${LDAP_USERNAME}:${LDAP_PASSWORD}" -X GET -H "Content-Type: application/json" "${JIRA_URL}maxResults=0&jql=${JQL_QUERY}" | jq '.total')
echo "Query would export ${TOTAL} issues."
while [ ${START_AT} -lt ${TOTAL} ]; do
echo "Exporting from ${START_AT} to $((START_AT + MAX_RESULTS))"
curl --silent -u "${LDAP_USERNAME}:${LDAP_PASSWORD}" -X GET -H "Content-Type: application/json" "${JIRA_URL}maxResults=${MAX_RESULTS}&startAt=${START_AT}&jql=${JQL_QUERY}& expand=changelog" | jq -c '.issues[]' >> issues.json
START_AT=$((START_AT + MAX_RESULTS))
done
Please note the expand parameter, which additionally put all change log to the json dump as well. Alternatively you can use issue dumper python solution: implement the callback to store data to db and you're done.
Another service worth considering especially if you need to have a feed like list of changes:
/plugins/servlet/streams?maxResults=99&issues=activity+IS+issue%3Aupdate&providers=issues
This returns a feed of last changes in issues in XML format for some criteria, like users etc. Actually, you may play around with "Activity Stream" gadget on a Dashboard to see hot it works.
The service has limit of 99 changes at once, but there's paging(see the Show More.. button)

Getting file diff with Github API

net project for which I need to detect and parse changes made to a specific single text file in a repository between different pull requests.
I've been successfully able to access the pull requests and the commits using the Github API but I don't know how to retrieve the lines that changed in the last commit?
Is this possible using the API? What would be the best approach?
If not should I try to read the last two file versions and implement a differ algorithm locally?
Thanks!
A pull request contains a diff_url entry like
"diff_url": "https://github.com/octocat/Hello-World/pull/1347.diff"
You can do this for any commit. For example, to get the diff of commit 7fd1a60b01f91b3 on octocat's Hello-World it's https://github.com/octocat/Hello-World/commit/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d.diff.
This also works for branches. Here's master on octocat's Hello-World. https://github.com/octocat/Hello-World/commit/master.diff.
The general form is:
https://github.com/<owner>/<repo>/commit/<commit>.diff
For private repositories:
curl -H "Accept: application/vnd.github.v3.diff" https://<personal access token>:x-oauth-basic#api.github.com/repos/<org>/<repo>/pulls/<pull request>
Also works with the normal cURL -u parameter.
See: https://docs.github.com/en/rest/reference/pulls#get-a-pull-request
The crux is in the requested media type. You can pass the Accept header with value
application/vnd.github.diff
see documentation. For full reference, a GET request with the above and Authorization header to https://api.github.com/repos/{orgName}/{repoName}/pulls/{prId} does the trick.

REST API for driving distance?

Is there a service that will give me the driving distance between two addresses? Apparently Google Maps API requires you to display a map, which I don't want to do (on that particular page), and I'd like to just snag the data and save it to my DB after a user submits a form, rather than waiting for JS to do it's thing.
If it's relevant, this is going into a Django app. I discovered that CloudMade offers a Python API, which is nice, except their latest dev release has a bug in it (can't use the API object), but more importantly, it's support for Canada is awful (couldn't find directions from any major city around here!).
MapQuest's Directions API is HTTP Querystring based (I'm not sure if it's entirely RESTful). Can get XML or JSON response. Just need to send it an HTTP GET Request.
http://developer.mapquest.com/web/products/open/directions-service
Use the "distance" response parameter.
I don't have a high enough reputation on SO to comment on an answer but I just wanted to be clear that contrary to the voted correct answer, Google Directions API has to adhere to the Google Maps API. If you scroll down the supplied link, you will see:
Note: the Directions API may only be used in conjunction with displaying results on a Google map; using Directions data without displaying a map for which directions data was requested is prohibited. Additionally, calculation of directions generates copyrights and warnings which must be displayed to the user in some fashion. For complete details on allowed usage, consult the Maps API Terms of Service License Restrictions.
Would it be possible to use Google Maps GDirections object? This can return the textual directions instead of the map overlay if called with a div object. From there you can use the getDistance (or getDuration) functions. You can always use an invisible div for the returns if you don't want anything to be displayed on the page.
Start here
http://code.google.com/apis/maps/documentation/examples/directions-advanced.html
http://code.google.com/apis/maps/documentation/reference.html#GDirections
And use this sample code
var map;
var directionsPanel;
var directions;
function initialize() {
directionsPanel = document.getElementById("route");
directions = new GDirections(null, directionsPanel);
GEvent.addListener(directions , "load", onGDirectionsLoad);
directions.load("from: 500 Memorial Drive, Cambridge, MA to: 4 Yawkey Way, Boston, MA 02215 (Fenway Park)");
}
function onGDirectionsLoad(){
alert(directions.getDistance().html);
}
Here is my solution:
Signup for Mapquest Developer network.
Get AppId
Open your command shell and run the following command(or use fiddler) But running it through curl will give you flexibility to automate your request
curl -X POST -H "Content-Type: application/json" -d '{locations: ["Salt Lake City, UT","Ogden, UT",],options: {allToAll: false}}' http://www.mapquestapi.com/directions/v2/routematrix?key=YOURKEYGOESHERE >> distance.txt
Save above command with all your destinations into batch or sh file.
Now grep and parse out your distance.txt file for what you need.
There are free services out there, but the quality of the data may be questionable/non-existent in areas. Be aware of licences on the data too, storing in your own DB may be a breach.
http://openrouteservice.org/
Take a look at Navteq. I used their service in developing a driving directions application about 5 years ago, and got good results. Can't speak for them lately though. I believe the best URL is Navteq Routing Service
You can use the new Google Directions API directly, without using any javascript.
http://code.google.com/apis/maps/documentation/directions/