I have a simple bash script that I want to track how many times it is run. This script will be downloaded and run on other machines so I want to keep dependencies to a minimum.
I want to use curl, but I am unsure of what options there were as far as sending a POST to google analytics or something similar.
Thanks!
You can implement Google Analytics collect POST request with curl in your script. Just add the following :
tracking_id="UA-XXXXXXXX-X"
category="AppCounter"
action="CountAction"
label="CountLabel"
value="1"
curl -d 'v=1&tid='"$tracking_id"'&cid=555&t=event&ec='"$category"'&ea='"$action"'&el='"$label"'&ev='"$value"'' \
-H "User-Agent: AppSpecific" \
"https://www.google-analytics.com/collect"
See the Measurement protocol for Google Analytics
Related
Is there a way to get an issues report by querying the SonarQube web API?
With previous versions of SonarQube, I was able to generate an HTML report after each build but this feature looks like it's been deprecated in newer installments.
At the moment, I'm trying this bit of code
curl -u foo:bar https://sonar.example.com/api/issues/search?pageSize=100&componentKeys=my-app&metricKeys=violations,ncloc,line
But it errors with {"errors":[{"msg":"The 'component' parameter is missing"}]
Ideally, what I'm after is to just get the lines of code, the number of bugs, vulnerabilities, and Code smells in each run/scan.
Something like this
But through querying the API after each analysis.
Is this possible, please?
Had the same issue. The problem is that there is something wrong with the CURL command and you need to specify the full url as string using quotes.
Your case would be:
curl -u foo:bar "https://sonar.example.com/api/measures/search?pageSize=100&componentKeys=my-app&metricKeys=ncloc,violations,complexity"
This is an example with measures. Be sure to check the required parameters.
I'm aware it is possible to generate code snippets from individual Postman requests, but I can't find similar functionality for a entire collection.
I also know that there are tools like newman for running an exported collection in Postman Collection 2.1 json format.
But specifically what I'm looking for is a tool that generates bash code from a collection or from a exported collection in Postman Collection 2.1 json format. This way my co-workers who don't use Postman can replicate the API requests.
Is this option available in Postman and I'm just missing it or are there any tools that do this?
I ended using the Postman SDK and postman-code-gen to create code snippets from Postman Collections that I exported from Postman.
Not really sure why this feature isn't provided already by Postman, but I made a simple CLI tool that does it:
https://github.com/arashout/postman-collection-gen
# cURL request generation
node main.js -c example_collection.json
# curl --location --request GET 'https://v7rr12wbr7.execute-api.us-west-2.amazonaws.com/prod/courses?c0=PHYS153&c1=APSC160&c2=CHEM154&version_key=1.2'
# curl --location --request GET 'https://v7rr12wbr7.execute-api.us-west-2.amazonaws.com/prod/courses?c0=PHYS153'
# How to generate other languages:
node main.js -c example_collection.json -l shell,httpie
node main.js -c example_collection.json -l Swift,URLSession
I'm not sure I understand your question completely.
But I can tell you how I export collection and then run tests.
Export Collection to JSON: choose tab 'Collections' at the left tab of the Postman. Select the 3-dot menu and choose 'Export'.
Export your test environment: Open 'Manage Environments'. Click download.
I don't know a tool that generates bash code, I write it manually.
Write .sh file like the following to run your tests.
"newman run your_test_collection.json -r cli -e your_test_environment.json --reporter-cli-no-assertions --global-var"
Usually, I create different .sh files for different sets of tests.
My question:
I am using SonarQube version 7.1 and trying to extract the metrics and quality gate related to individual projects.
What we have tried
We were using Python SonarQube API to extract these data before our company upgraded to version 7.1. "api/resources" web service Deprecated since sonarqube5.4, so we cannot use it anymore.
I have also tried using getting data using CURL command via Web API using
curl -i -H "Content-Type: application/json" -H "x-api-key:token" -X GET 'http://MY_HOST/api/measures/component?metricKeys=key&component=project_key'
We are able to get a json payload for individual metrics, but involves tedious task of creating the URL every single time.
But I wanted to know if there is a better/smarter way to access these "measures", be it any language or implementation.
You could do this:
Call the API api/metrics/search first to get a (json) list of all the metrics and then iterate over that list and create a comma separated string of all the metric keys.
For example something like this: ncloc,complexity,violations .. as mentioned in the parameters example value in the API documentation here.
Then you could just add this comma separated list to the url as a parameter something like: http://MY_HOST/api/measures/component?metricKeys=ncloc,complexity,violations&component=project_key
and call it once to get the response for all metrics.
Also, I haven't tried this, but as per the latest documentation, the parameter component is optional. So if you omit that, ideally you should get a response with metrics of all the projects.
I have multiple nifi servers that I would like to be able to POST templates to via the REST interface from a script
The "/controller/templates" endpoint appears to be the proper REST endpoint to support POSTing an arbitrary template to my Nifi installation.
The "snippetId" field is what is confusing me, how do I determine "The id of the snippet whose contents will comprise the template"? Does anyone have an example of how I can upload a template "test.xml" to my server without having to use the UI?
The API has moved in 1.0 to:
POST /process-groups/{id}/templates/upload
Example, using Python's requests library:
res = requests.post( "{hostname}/nifi-api/process-groups/{destination_process_group}/templates/upload".format( **args ),
files={"template": open( file_path, 'rb')} )
The provided documentation is somewhat confusing, and the solution I worked out was derived from the nifi api deploy groovy script at https://github.com/aperepel/nifi-api-deploy
Ultimately, to POST a template directly, you can use the following in Python requests
requests.post("%s/nifi-api/controller/templates"%(url,), files={"template":open(filename, 'rb')})
Where filename is the filename of your template and url is the path to your nifi instance. I haven't figured it out in curl directly but this should hopefully get folks with a similar question started!
Edit:
Note that you also can't upload a template with the same name as an existing template. Make sure to delete your existing template before attempting to re-upload. Using the untangle library to parse the XML of the template, the following script works just fine:
import untangle, sys, requests
def deploy_template(filename, url):
p = untangle.parse(filename)
new_template_name=p.template.name.cdata
r=requests.get("%s/nifi-api/controller/templates"%(url,), headers={"Accept":"application/json"})
for each in r.json()["templates"]:
if each["name"]==new_template_name:
requests.delete(each["uri"])
requests.post("%s/nifi-api/controller/templates"%(url,), files={"template":open(filename, 'rb')})
if __name__=="__main__":
deploy_template(sys.argv[1], sys.argv[2])
If you want to POST a template to NiFi via cURL you can use the following command:
curl -iv -F template=#my_nifi_template.xml -X POST http://nifi-host:nifi-port/nifi-api/controller/templates
This will add the template to the NiFi instance with the same name that the template was given when it was generated.
And the -iv is optional - It's just there for debugging purposes.
You can use Nifi Api to upload a template, to do that follow these two steps:
1. Get a token from Nifi Api:
token=$(curl -k -X POST --negotiate -u : https://nifi_hostname:port/nifi-api/access/kerberos)
2. Upload the template file using the token:
curl -k -F template=#template_file.xml -X POST https://nifi_hostname:port/nifi-api/process-groups/Process_group_id/templates/upload -H "Authorization: Bearer $token"
The documentation can be confusing because that endpoint is overloaded and the documentation tool only generates doc for one of them (see NIFI-1113). There is an email thread that addresses the import of a template using curl, so between the above answer and the email thread, hopefully you can find the approach that works for you.
I've implemented a full Python client for doing this in NiPyApi
Key functions for templates are:
[
"list_all_templates", "get_template_by_name", "deploy_template",
"upload_template", "create_pg_snippet", "create_template",
"delete_template", "export_template", 'get_template'
]
The client supports NiFi-1.1.2 - 1.7.1 currently, and NiFi-Registry (which is a lot better than templates for flow deployment)
I was wondering the best way to upload file to a web server in cocoa. I cant seem to get my curl code to work even though it works when run from terminal.
curl code:
system(#"curl -T /file.txt http://webserevertouploadto.com")
Thanks for any help
Try using NSTask instead of system() to execute curl. If you're looking for a native Cocoa solution for uploading files via FTP, take a look at ConnectionKit.
One negative of using curl is that it won't respect the user's proxy settings.
I prefer to use the NSURLConnection API.
Check this out:
http://www.cocoadev.com/index.pl?HTTPFileUploadSample