Now pass the basic auth information to curl and send a GET request to the API:
- $ curl -u root:icinga -k -s 'https://icinga.org:5665/v1'
+ $ curl -u root:icinga -k -s 'https://localhost:5665/v1'
In case you will get an `Unauthorized` error message make sure to
check the API user credentials.
Example for all services in NOT-OK state:
- https://icinga.org:5665/v1/services?filter=service.state!=0
+ https://localhost:5665/v1/services?filter=service.state!=0
Example for matching all hosts by name (**Note**: `"` are url-encoded as `%22`):
- https://icinga.org:5665/v1/hosts?filter=match(%22nbmif*%22,host.name)
+ https://localhost:5665/v1/hosts?filter=match(%22nbmif*%22,host.name)
**TODO**
Reschedule a service check for all services in NOT-OK state:
- $ curl -u root:icinga -k -s 'https://icinga.org:5665/v1/actions/reschedule-check?filter=service.state!=0&type=Service' -X POST | python -m json.tool
+ $ curl -u root:icinga -k -s 'https://localhost:5665/v1/actions/reschedule-check?filter=service.state!=0&type=Service' -X POST | python -m json.tool
{
"results": [
{
Example for the main url endpoint `/v1/status`:
- $ curl -k -s -u root:icinga 'https://icinga.org:5665/v1/status' | python -m json.tool
+ $ curl -k -s -u root:icinga 'https://localhost:5665/v1/status' | python -m json.tool
{
"results": [
{
Example for the icinga application url endpoint `/v1/status/IcingaApplication`:
- $ curl -k -s -u root:icinga 'https://icinga.org:5665/v1/status/IcingaApplication' | python -m json.tool
+ $ curl -k -s -u root:icinga 'https://localhost:5665/v1/status/IcingaApplication' | python -m json.tool
{
"results": [
{
Send a `GET` request to `/v1/hosts` to list all host objects and
their attributes.
- $ curl -u root:icinga -k -s 'https://icinga.org:5665/v1/hosts'
+ $ curl -u root:icinga -k -s 'https://localhost:5665/v1/hosts'
#### <a id="icinga2-api-hosts-create"></a> Create New Host Object
Example:
- $ curl -u root:icinga -k -s 'https://icinga.org:5665/v1/hosts/google.com' \
+ $ curl -u root:icinga -k -s 'https://localhost:5665/v1/hosts/google.com' \
-X PUT \
-d '{ "templates": [ "generic-host" ], "attrs": { "address": "8.8.8.8", "vars.os" : "Linux" } }' \
| python -m json.tool
If the configuration validation fails, the new object will not be created and the response body
contains a detailed error message. The following example omits the required `check_command` attribute.
- $ curl -u root:icinga -k -s 'https://icinga.org:5665/v1/hosts/google.com' \
+ $ curl -u root:icinga -k -s 'https://localhost:5665/v1/hosts/google.com' \
-X PUT \
-d '{ "attrs": { "address": "8.8.8.8", "vars.os" : "Linux" } }' \
| python -m json.tool
Send a `GET` request including the host name inside the url:
- $ curl -u root:icinga -k -s 'https://icinga.org:5665/v1/hosts/google.com'
+ $ curl -u root:icinga -k -s 'https://localhost:5665/v1/hosts/google.com'
You can select specific attributes by adding them as url parameters using `?attrs=...`. Multiple
attributes must be added one by one, e.g. `?attrs=host.address&attrs=host.name`.
- $ curl -u root:icinga -k -s 'https://icinga.org:5665/v1/hosts/google.com?attrs=host.name&attrs=host.address' | python -m json.tool
+ $ curl -u root:icinga -k -s 'https://localhost:5665/v1/hosts/google.com?attrs=host.name&attrs=host.address' | python -m json.tool
{
"results": [
{
Example for existing object `google.com`:
- $ curl -u root:icinga -k -s 'https://icinga.org:5665/v1/hosts/google.com' \
+ $ curl -u root:icinga -k -s 'https://localhost:5665/v1/hosts/google.com' \
-X POST \
-d '{ "attrs": { "address": "8.8.4.4", "vars.os" : "Windows" } }' \
| python -m json.tool
Example:
- $ curl -u root:icinga -k -s 'https://icinga.org:5665/v1/hosts/google.com?cascade=1' -X DELETE | python -m json.tool
+ $ curl -u root:icinga -k -s 'https://localhost:5665/v1/hosts/google.com?cascade=1' -X DELETE | python -m json.tool
{
"results": [
{
Send a `POST` request to a new config package called `puppet` in this example. This
will create a new empty configuration package.
- $ curl -k -s -u root:icinga -X POST https://icinga.org:5665/v1/config/packages/puppet | python -m json.tool
+ $ curl -k -s -u root:icinga -X POST https://localhost:5665/v1/config/packages/puppet | python -m json.tool
{
"results": [
{
Note: This example contains an error (`chec_command`), do not blindly copy paste it.
- $ curl -k -s -u root:icinga -X POST -d '{ "files": { "conf.d/test.conf": "object Host \"cfg-mgmt\" { chec_command = \"dummy\" }" } }' https://icinga.org:5665/v1/config/stages/puppet | python -m json.tool
+ $ curl -k -s -u root:icinga -X POST -d '{ "files": { "conf.d/test.conf": "object Host \"cfg-mgmt\" { chec_command = \"dummy\" }" } }' https://localhost:5665/v1/config/stages/puppet | python -m json.tool
{
"results": [
{
The following example contains one configuration package `puppet`.
The latter already has a stage created, but it is not active.
- $ curl -k -s -u root:icinga https://icinga.org:5665/v1/config/packages | python -m json.tool
+ $ curl -k -s -u root:icinga https://localhost:5665/v1/config/packages | python -m json.tool
{
"results": [
{
Sent a `GET` request to the url endpoint `/v1/config/stages` including the package
(`puppet`) and stage (`nbmif-1441625839-0`) name.
- $ curl -k -s -u root:icinga https://icinga.org:5665/v1/config/stages/puppet/nbmif-1441625839-0 | python -m json.tool
+ $ curl -k -s -u root:icinga https://localhost:5665/v1/config/stages/puppet/nbmif-1441625839-0 | python -m json.tool
{
"results": [
...
The following example fetches the faulty configuration inside `conf.d/test.conf`
for further analysis.
- $ curl -k -s -u root:icinga https://icinga.org:5665/v1/config/files/puppet/nbmif-1441625839-0/conf.d/test.conf
+ $ curl -k -s -u root:icinga https://localhost:5665/v1/config/files/puppet/nbmif-1441625839-0/conf.d/test.conf
object Host "cfg-mgmt" { chec_command = "dummy" }
Note: The returned files are plain-text instead of JSON-encoded.
Fetch the `startup.log` file and check the config validation errors:
- $ curl -k -s -u root:icinga https://icinga.org:5665/v1/config/files/puppet/imagine-1441133065-1/startup.log
+ $ curl -k -s -u root:icinga https://localhost:5665/v1/config/files/puppet/imagine-1441133065-1/startup.log
...
critical/config: Error: Attribute 'chec_command' does not exist.