Hosts
manage your hosts via the API
get
https://api.cloudradar.io
/v1/hosts/
Get Hosts
Bash
Powershell
Python
1
curl -X GET \
2
https://api.cloudradar.io/v1/hosts/ \
3
-H 'Authorization: Bearer 33891543f62ead9e18c32e1252e320c2710f708d9085fd5b'
Copied!
1
$headers = @{'Authorization' = 'Bearer 33891543f62ead9e18c32e1252e320c2710f708d9085fd5b'}
2
$response = Invoke-RestMethod -Headers $headers -Uri "https://api.cloudradar.io/v1/hosts/"
3
$response.hosts
Copied!
1
#!/usr/bin/env python
2
3
import requests
4
import sys
5
6
token = '33891543f62ead9e18c32e1252e320c2710f708d9085fd5b'
7
url = 'https://api.cloudradar.io/v1/hosts/'
8
9
headers = { 'Authorization': 'Bearer '+token }
10
11
response = requests.request("GET", url, headers=headers)
12
if response.status_code != 200:
13
sys.stderr.write("Request failed. " + response.text)
14
sys.exit(response.status_code)
15
16
# Decode the json object to a python list
17
hosts = response.json()['hosts']
18
# Iterate over the list
19
for host in hosts:
20
print("Name: %s, Connect: %s, Muted: %s" % (host['name'],host['connect'],host['muted']))
Copied!
post
https://api.cloudradar.io
/v1/hosts/
Create a host
Bash
Powershell
1
curl -X POST \
2
https://api.cloudradar.io/v1/hosts/ \
3
-H 'Authorization: Bearer 33891543f62ead9e18c32e1252e320c2710f708d9085fd5b' \
4
-H 'Content-Type: application/json' \
5
-d '{
6
"name":"host.example.com",
7
"connect":"host.example.com",
8
"description":"Nice host. Isn'\''t it?",
9
"tags": ["Tag 1","Tag 2","Berlin","Server"],
10
"cagent":true,
11
"dashboard":true
12
}'
Copied!
1
$newhost = @{
2
'name' = 'host.example.com'
3
'connect' = 'host.example.com'
4
'description' = 'Nice host'
5
'cagent' = $true
6
'dashboard' = $true
7
}
8
$json = $newhost | ConvertTo-Json
9
$headers = @{
10
'Authorization' = 'Bearer ad42b039ef8c8e3b2d3e2fa396eae3f1c332503999575515'
11
'Content-Type' = 'application/x-www-form-urlencoded'
12
}
13
$response = Invoke-RestMethod -Headers $headers -Method Post -Body $json -ContentType 'application/json' -Uri "https://api.cloudradar.io/v1/hosts/"
14
$response.host
Copied!
delete
https://api.cloudradar.io
/v1/hosts/<HOST_UUID>
Delete a host
1
curl -X DELETE \
2
'https://api.cloudradar.io/v1/hosts/4ad9936f-f6ff-4484-b1ae-fd2c2e0e3d10?purgeFromReports=1' \
3
-H 'Authorization: Bearer 33891543f62ead9e18c32e1252e320c2710f708d9085fd5b'
Copied!
patch
https://api.cloudradar.io
/v1/hosts/<HOST_UUID>
Update host properties
1
curl -X PATCH \
2
https://api.cloudradar.io/v1/hosts/be9b90f4-5dff-4fec-8ef4-bb2bea07bf5c \
3
-H 'Authorization: Bearer 33891543f62ead9e18c32e1252e320c2710f708d9085fd5b' \
4
-H 'Content-Type: application/json' \
5
-d '{
6
"name":"host2.example.com",
7
"connect":"1.1.1.1",
8
"tags":[],
9
"active": true,
10
"cagent": false
11
}'
Copied!
The following example shows how to mute a host from the command line with a simple python script. The host UUID is expected as a command line parameter, for example python mute-host.py d25ad016-d40a-46e8-9aaa-b7df6929cfe0

Examples

Automated installation of a host with Powershell

The following example uses Powershell to create a host via the API, download the agent, and install it with the credentials of the newly created host.
1
$cagent_version="1.4.0"
2
$newhost = @{
3
'name' = $env:computername
4
'connect' = $null
5
'cagent' = $true
6
'dashboard' = $true
7
}
8
$json = $newhost | ConvertTo-Json
9
$headers = @{
10
'Authorization' = 'Bearer ad42b039ef8c8e3b2d3e2fa396eae3f1c332503999575515'
11
'Content-Type' = 'application/json'
12
}
13
$response = Invoke-RestMethod `
14
-Headers $headers `
15
-Method Post `
16
-Body $json `
17
-ContentType 'application/json' `
18
-Uri "https://api.cloudradar.io/v1/hosts/"
19
$response
20
21
$TempDir = [System.IO.Path]::GetTempPath()
22
cd $TempDir
23
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
24
$url="https://repo.cloudradar.io/windows/cagent/cagent-plus_$($cagent_version)_Windows_64.msi"
25
Invoke-WebRequest -Uri $url `
26
-OutFile "cagent-plus_$($cagent_version)_Windows_64.msi"
27
msiexec /i cagent-plus_$($cagent_version)_Windows_64.msi `
28
/q /quiet `
29
HUB_URL="https://hub.cloudradar.io/ctrapper/" `
30
HUB_USER="$($response.host.uuid)" `
31
HUB_PASSWORD="$($response.host.hub_password)"
32
del .\cagent-plus_$($cagent_version)_Windows_64.msi
Copied!

Mute a host

mute-host.py
1
#!/usr/bin/env python
2
3
import requests
4
import sys
5
import json
6
7
hostUUID = sys.argv[1]
8
token = '33891543f62ead9e18c32e1252e320c2710f708d9085fd5b'
9
url = 'https://api.cloudradar.io/v1/hosts/' + sys.argv[1]
10
11
headers = { 'Authorization': 'Bearer '+token }
12
payload = { 'muted': True }
13
14
response = requests.request("PATCH", url, data=json.dumps(payload), headers=headers)
15
if response.status_code != 200:
16
sys.stderr.write("Request failed. " + response.text + "\n")
17
sys.exit(response.status_code)
18
19
print("Request sent.")
Copied!

Mute all hosts

mute-all-hosts.py
1
#!/usr/bin/env python
2
3
import requests
4
import sys
5
import json
6
7
token = '33891543f62ead9e18c32e1252e320c2710f708d9085fd5b'
8
url = 'https://api.cloudradar.io/v1/hosts/'
9
headers = { 'Authorization': 'Bearer '+token }
10
11
#
12
# Get list of all hosts
13
#
14
response = requests.request("GET", url, headers=headers)
15
if response.status_code != 200:
16
sys.stderr.write("Request failed. " + response.text)
17
sys.exit(response.status_code)
18
19
# Decode the json object to a python list
20
hosts = response.json()['hosts']
21
payload = { 'muted': True }
22
# Iterate over the list
23
for host in hosts:
24
url = 'https://api.cloudradar.io/v1/hosts/' + host['uuid']
25
response = requests.request("PATCH", url, data=json.dumps(payload), headers=headers)
26
if response.status_code != 200:
27
sys.stderr.write("Request failed. " + response.text + "\n")
28
sys.exit(response.status_code)
29
print("Host %s muted" % host['name'])
Copied!
Last modified 7mo ago