简介:
itop 开发例子. 登陆验证方法见http://blog.mreald.com/180
实现过程:
1.查看所有的对象类型
管理工具 -> 数据模型 (右边括号内就是)
2.查看特定对象包含字段(空与非空)如下图
3.查看具体实例 如下图
http://jsfiddle.net/U6qwK/6/ 上查看
4.写代码实现
python 3 版本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import urllib #import urllib2 import urllib.request, urllib.error import json def http_post(operations): url = "http://10.12.7.11/mdcmdb/webservices/rest.php?version=1.3" auth = { "auth_user" : "username" , "auth_pwd" : "dsffs" } #opr = {"operation": "list_operations"} opr = operations oprjson = urllib.parse.urlencode({ 'json_data' : json.dumps(opr)} ).encode( "utf-8" ) jdata = urllib.parse.urlencode(auth).encode( "utf-8" ) jdata = jdata + b '&' + oprjson response = urllib.request.urlopen(url,jdata) return response.read().decode() def get_organization(friendlyname): getopr = { "operation" : "core/get" , "class" : "Organization" , "key" : "SELECT Organization WHERE friendlyname='" + friendlyname + "'", } tmp=http_post(getopr) result=json.loads(str(tmp)) if int(result["message"].split()[1]) >= 1 : return 0 else: return 1 return result def add_new_organization(friendlyname,parent_friendlyname): createopr = { "operation": "core/create", "class": "Organization", "comment": "add new Organization", "output_fields" : "*", "fields": { "friendlyname":friendlyname, "name":friendlyname, "parent_id":"SELECT Organization WHERE friendlyname='"+parent_friendlyname+"'" , "parent_id_friendlyname" :parent_friendlyname, } } result = http_post(createopr) return result |