Question: I´m using Check\_MK and i was trying to implement a python script to run via cfengine to add automatically new installed hosts.
I´m having some trouble with both using pycurl or running and external curl.

An example of the command i want to be able to pycurl is:

curl "<http://10.20.30.40/mysite/check_mk/webapi.py?action=add_host&_username=autouser&_secret=mysecret>" -d 'request={"attributes":{"alias": "Alias of winxp\_1", "tag\_agent": "cmk-agent", "tag\_criticality": "prod", "ipaddress": "127.0.0.1"}, "hostname": "winxp\_1", "folder": "os/windows"}'

This works fine from the terminal

but I cannot find the right syntax to make it working from within the python script.

thanks for any help.

Answer: 
this works for me.

NOTES: The user must exist. The "folder" must exist; i put "/" in sample.

```
import urllib2

req = urllib2.Request("http://localhost/mysite/check_mk/webapi.py?action=add_host&_username=autouser&_secret=mysecret",
             headers = {"Content-Type": "application/x-www-form-urlencoded"},
             data = 'request={"attributes":{"alias": "Alias of winxp_1", "tag_agent": "cmk-agent", "tag_criticality": "prod", "ipaddress": "127.0.0.1"}, "hostname": "winxp_1", "folder": "/"}')

f = urllib2.urlopen(req)

```

Sorry for my english.
The same like Daniel, but with variables:

```
url = "/mysite/check_mk/webapi.py"

request_url = "%s%s?action=add_host&_username=%s&_secret=%s" % ( check_mk_host, url, check_mk_username, check_mk_password )

request_data = {}

request_data['attributes'] = {}

request_data['attributes']['tag_agent'] = 'cmk-agent'

request_data['hostname'] = vm

request_data['folder'] = "/Auto"

request_data = json.dumps(request_data)

data = "request=%s" % request_data

br = mechanize.Browser()

br.open(mechanize.Request(request_url, data=data))

```