Creating services manually with Icinga2 API not working - monitoring

I am new on Icinga2, using 2.4.0 version and I am trying to execute some API calls but I have found a problem when I have tried to create a service manually.
This is the command that I execute to create a service called api_dummy_service_1 for api_dummy_host_1 host:
curl -u $ICINGA2_API_USER:$ICINGA2_API_PASSWORD \
-H 'Accept: application/json' -X PUT \
-k "https://$ICINGA2_HOST:$ICINGA2_API_PORT/v1/objects/services/api_dummy_host_1!api_dummy_service_1" \
-d '{ "templates": [ "generic-service" ], "attrs": { "display_name": "api_dummy_service_1", "check_command" : "dns", "vars.dns_lookup": "google-public-dns-a.google.com.", "vars.dns_expected_answer": "8.8.8.8", "host_name": "api_dummy_host_1" } }' | python -m json.tool
When I execute it, the following error message appears:
-bash: !api_dummy_service_1: event not found
I have examinated Icinga logs, I have activated debug mode on Icinga also and tried to search information related to this in internet with no results.
Can anyone help me please? Thanks in advance!

Issue fixed! After doing more test in detail we have detected that the problem was related to the URL that we use to connect with icinga2 API, the ! character must be escaped.
I have changed ! to %21 and the command works

Related

Dart : At the end of the tutorial, I don't know how to check that the app is working

https://dartfrog.vgv.dev/docs/tutorials/todos#summary
I got to this section, but I don't know how to get it to work at the end, so I can't get it to work.
in my browser
http://localhost:8080/todos
When I access the above url, [] is displayed, so I think it's working.
# Update a specific todo by id
curl --request PUT \
--url http://localhost:8080/todos/<id> \
--header 'Content-Type: application/json' \
--data '{
"title": "Take out trash!",
"isCompleted": true
}'
How can I check that the above part works?
The line you see there is a command you are supposed to run on your commandline.
If you use a newer version of windows you probably have curl already, if not, see How do I install and use cURL on Windows?
So you open your command prompt and enter
curl --request PUT --url http://localhost:8080/todos/<id> --header 'Content-Type: application/json' --data '{ "title": "Take out trash!", "isCompleted": true }'
where I guess the <id> part needs to be an id. So for example 1.
Please note that that is a tutorial for a backend in Dart. They are not commonly called an app. If you are looking to build a nice app for your device or webbrowser, with ui controls like input boxes and buttons, you are reading the wrong tutorial.

Getting Issues via REST API but not all

I currently trying to get the issues from JIRA via REST API via this:
curl -D- -u USERNAME -X GET -H "Content-Type: application/json" \
https://issues.apache.org/jira/rest/api/2/search? jql=project%20%3D%20MNG%20AND%20fixVersion%20%3D%203.4.0 \
-o release.json
But unfortunately i don't get all issues. Only 50 instead of 59. I already checked if all the issues have the correct fixVersion set to 3.4.0.
But via browser:
https://issues.apache.org/jira/issues/?jql=project%20%3D%20MNG%20AND%20fixVersion%20%3D%203.4.0
I got all the issues.
Do i oversight something ? Some idea hint ?
50 is a default value for "maxResults" parameter. Here's API documentation https://docs.atlassian.com/jira/REST/latest/#api/2/search-search

Post command error using Solr: argument list too long

I'm trying to add documents to a specific core that I have created before with this command:
./solr create -c kba_oct_2011
Than I add the schema using curl utility:
curl http://localhost:8983/solr/kba_oct_2011/schema -X POST -H 'Content-type:application/json' --data-binary '{
"add-field" : {
"name":"title",
"type":"text_general",
"indexed":true,
"stored":true
},
"add-field" : {
"name":"description",
"type":"text_general",
"indexed":true,
"stored":true
},
"add-field" : {
"name":"date",
"type":"date",
"indexed":true,
"stored":true
}
}'
And in the end I'm trying to add documents using post command:
./post -c kba_oct_2011 /home/IPA/IPA_ws/Dataset_news_KBA/2011/10_October/*.xml
In the directory /home/IPA/IPA_ws/Dataset_news_KBA/2011/10_October/ there are 72.420 files and when I execute the command I have this error:
-bash: ./post: Argument list too long
Someone can I help me?
Thanks!
This occurs beacuse your expanded argument list expands command line input limit.
Use xargs to provide argument list to your post command.

How to use curl in rails app

I have curl str
curl -L –user '61332:Ne5re3w34fa' -H «Content-Type: application/json» -d '{«confirmed_at»: {«date»:«2014-04-30», «period»: 30}, «merchant_id»:73, «state»:[3,4], «type»: 0, «sub_id»:«test»}' -X POST https://myurl/
which returns me data in console
But how to use it inside rails app?
Ruby stdlib has opportunity to run system commands
Here is good review of all possible variants: Calling shell commands from Ruby
Also there is curl gem: https://rubygems.org/gems/curb

How can I use curl to upload a file using paperclip?

I want to upload a file together with some information(e.g. package_type) with curl
in my submission model:
has_attached_file :package
What I tried:
curl -d "submission[package_type]=type1&submission[package]=#/home/ubuntu/Downloads/test.zip" http://localhost:3000/restapi.json
If I leave out the file object, it works(a entry will be inserted into the database)
But I specify the file like above, it gives me an error:
No handler found for "#/home/ubuntu/Downloads/test.zip"
Update:
I just found that that I should use the -F option in curl, but in that case the file information cannot be recorded, is there anyway to include both the file object and file info? Maybe something like curl -d -F ?
I had a similar issue and ended up setting the content-type to multipart/form-data instead of dealing with base64 encoding issues when posting to my REST API. Here is an example which includes headers for auth:
curl -v -H 'Content-Type: multipart/form-data' -H "X-User-Email: <email>" -H "X-User-Token: <token>" -X POST -i -F submission[package_type]=type1 -F submission[image_attributes][image]=#f117.jpg http://localhost:3000/api/v1/submissions

Resources