Check_mk syntax to to make python add new hosts
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](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.

