-
Notifications
You must be signed in to change notification settings - Fork 15
Examples
Crapworks edited this page Dec 14, 2012
·
8 revisions
Here are some example api calls via Curl. Of course the response depends on your configuration.
Find all host objects
$ curl -H "content-type: application/json" 'http://admin:password@localhost:5000/host'
[
{
"check_command": "check-host-alive",
"name": "generic-host",
"notification_interval": "0",
"retain_nonstatus_information": "1",
"failure_prediction_enabled": "1",
"notifications_enabled": "1",
"contact_groups": "admins",
"retain_status_information": "1",
"notification_period": "24x7",
"event_handler_enabled": "1",
"process_perf_data": "1",
"max_check_attempts": "10",
"flap_detection_enabled": "1",
"notification_options": "d,u,r",
"register": "0"
},
{
"alias": "localhost",
"use": "generic-host",
"host_name": "localhost",
"address": "127.0.0.1"
},
[...]
]
Get all hosts with testhost in the host_name
field
$ curl -H "content-type: application/json" 'http://admin:password@localhost:5000/host?host_name=testhost'
[
{
"alias": "testhost2",
"use": "generic-host",
"host_name": "testhost2",
"address": "127.0.0.3"
},
{
"alias": "testhost1",
"use": "generic-host",
"host_name": "testhost1",
"address": "127.0.0.2"
},
{
"alias": "testhost3",
"use": "generic-host",
"host_name": "testhost3",
"address": "127.0.0.4"
}
]
$ cat /tmp/hosts
[
{
"alias": "newhost1",
"use": "generic-host",
"host_name": "newhost1",
"address": "127.0.0.101"
},
{
"alias": "newhost2",
"use": "generic-host",
"host_name": "newhost2",
"address": "127.0.0.102"
},
{
"alias": "newhost3",
"use": "generic-host",
"host_name": "newhost3",
"address": "127.0.0.103"
}
]
$ curl -X POST -d @/tmp/hosts -H "content-type: application/json" 'http://admin:password@localhost:5000/host'
{
"results": [
{
"200": "successfully stored host object: newhost1"
},
{
"200": "successfully stored host object: newhost2"
},
{
"200": "successfully stored host object: newhost3"
}
],
"summary": {
"failed": 0,
"total": 3,
"succeeded": 3
}
}
$ curl -H "content-type: application/json" 'http://admin:password@localhost:5000/host?host_name=new'
[
{
"alias": "newhost3",
"use": "generic-host",
"host_name": "newhost3",
"address": "127.0.0.103"
},
{
"alias": "newhost1",
"use": "generic-host",
"host_name": "newhost1",
"address": "127.0.0.101"
},
{
"alias": "newhost2",
"use": "generic-host",
"host_name": "newhost2",
"address": "127.0.0.102"
}
]
$ cat /tmp/host-update
[
{
"alias": "newhost1",
"use": "generic-host",
"host_name": "newhost1",
"_MAC": "11:11:11:11:11:11",
"address": "127.0.0.101"
},
{
"alias": "newhost2",
"use": "generic-host",
"host_name": "newhost2",
"_MAC": "22:22:22:22:22:22",
"address": "127.0.0.102"
},
{
"alias": "newhost3",
"use": "generic-host",
"host_name": "newhost3",
"_MAC": "33:33:33:33:33:33",
"address": "127.0.0.103"
}
]
$ curl -X POST -d @/tmp/hosts-update -H "content-type: application/json" 'http://admin:password@localhost:5000/host'
{
"results": [
{
"200": "successfully stored host object: newhost1"
},
{
"200": "successfully stored host object: newhost2"
},
{
"200": "successfully stored host object: newhost3"
}
],
"summary": {
"failed": 0,
"total": 3,
"succeeded": 3
}
}
$ curl -H "content-type: application/json" 'http://admin:password@localhost:5000/host?host_name=new'
[
{
"alias": "newhost3",
"use": "generic-host",
"_MAC": "33:33:33:33:33:33",
"host_name": "newhost3",
"address": "127.0.0.103"
},
{
"alias": "newhost1",
"use": "generic-host",
"_MAC": "11:11:11:11:11:11",
"host_name": "newhost1",
"address": "127.0.0.101"
},
{
"alias": "newhost2",
"use": "generic-host",
"_MAC": "22:22:22:22:22:22",
"host_name": "newhost2",
"address": "127.0.0.102"
}
]
Delete all host objects with testhost in the host_name
field
$ curl -X DELETE -H "content-type: application/json" 'http://admin:password@localhost:5000/host?host_name=testhost'
{
"results": [
{
"200": "successfully deleted host object: testhost2"
},
{
"200": "successfully deleted host object: testhost1"
},
{
"200": "successfully deleted host object: testhost3"
}
],
"summary": {
"failed": 0,
"total": 3,
"succeeded": 3
}
}
$ curl -X POST -H "content-type: application/json" 'http://admin:password@localhost:5000/control?restart'
{
"result": "successfully sent command to command file"
}