转到正文

OneCMDB中文

研究和推广OneCMDB,传递ITIL&ITSM知识。

存档

分类: OneCMDB汉化

目录

1. 概述

这个文档介绍了如何使用Web ServicesOneCMDB交互,这使得像Java这样的其他变成语言可以和OneCMDB交互。Web Services接口目的是要尽可能简单、实用和强大。

1.1. 一些OneCMDB概念

OneCMDB按照面向对象方式组织, 即对象从其他对象继承。这意味着所有配置项(CI)源于另外一个CI,所有CI都从一个已经存在的根派生。有两种风格的配置项:模板和实例,模板描述每个实例必须有什么属性、什么类型,也包含缺省值。实例包含模板中定义的属性对应的值。

  • CI 都有唯一的ID(人类不可读的),而且是不能改变的),他和后端存储紧密相关。
  • CI 具有唯一的别名。别名可以指定和修改,除非别名在别地地方使用。它经常用于OneCMDB XML定义中。
  • CI 具有一个显示名称,它定义CI作为一行文字如何呈现。显示名称通常一个或多个属性值的串联,它在需要显示时被计算。这样好处是CI不必有一个具体的名称,它将随相应值的变化而改变。
  • CI(模板和实例) (templates and instances) 可以在一个XML文档中描述,它可以从OneCMDB中导出,可以导入到OneCMDB中。

2. 范例模型

为了说明向OneCMDB提交的不同的查询和更新命令,定义了一个简单的带实例的模板模型,它用在所有范例中。

2.1. 模板模型

CI之间的继承用箭头表示。例如:NetworkDevice模板有CI模板中定义的所有属性,Router模板有NetworkDevice和CI的所有属性。

Image:TemplateDiagram.gif

2.2. 实例模型

在此图中箭头表示CI(实例)之间的关联关系。

Image:InstanceDiagram.gif

2.3. OneCMDB XML模型描述

上面的模板和实例模型可以由下面的XML文档定义。这个XML文档可以被导入到OneCMDB中。请注意这只是一个完整文档中的一部分。

<onemcdb>
	<templates>
		<!-- Definition of NetworkDevice Template -->
		<template alias=”NetworkDevice” displayName=”NetDevice ${primaryIp}>
			<derivedFrom><ref alias=Ci/></derivedFrom>
			<attribute attAlias=”primaryIp”>
				<simpleType>String</simpleType>
			</attribute>
		</template>

		<!-- Definiton of the Router
			Defines a Complex Attribute of Type Site and Reference Type Reference.
			It also defines the occurrence of values[0..1] meaning that it's not required to have site value
			but it can not have more than one site. Default policy are [1..1].-->

		<template alias=”Router”>
			<derivedFrom><ref alias=”NetworkDevice”/></derivedFrom>
			<attribute attAlias=”site”>
				<complexType>
					<ref alias="Site"/>
					<refType><ref alias="Reference"/></refType>
				</complexType>
				<policy>
					<minOccurs>0</minOccurs>
					<maxOccurs>1</maxOccurs>
				</policy>
			</attribute>
		</template>
		...
	</templates>
	<instances>
		<!-- Definition of an Router instance that has a reference to Site S1 -->
		<Router alias=”R1”>
			<primaryIp>192.168.1.2<//primaryIp>
			<site><ref alias=”S1”/></site>
		</Router>
		<Site alias=”S1”>
			...
		</Site>
		....
	</instances>
</onecmdb>

3. Web Service 接口(WSDL)

OneCMDB Core功能可以用Web Service访问,这使用户无需受编程语言限制与OneCMDB远程交互。下面的范例将展示如何使用PHP和Java实现交互。

Core 中像创建CI、更新CI、删除CI、查找CI、查询CI和查询CI变更历史功能是可用的。

其他OneCMDB 功能像任务和策略处理在服务没有实现。

本服务的WSDL描述,可以从 http://localhost:8080/webservice/onecmdb?wsdl 获取。

3.1. 设置Java环境

通过Java访问Web Service API可按照以下方法设置:

  • 在classpath中包含以下Jar文件。这些文件可以在目录install/tomcat*/webapps/onecmdb-desktop/WEB-INF/lib下找到
    • onecmdb-core-2.0.1.jar
    • activation-1.1.jar
    • commons-codec-1.3.jar
    • commons-httpclient.jar
    • commons-logging-1.0.4.jar
    • jdom-1.0.jar
    • jsr173_api-1.0.jar
    • wsdl4j-1.6.1.jar
    • wstx-asl-3.2.0.jar
    • xfire-all-1.2.6.jar

然后,创建Web Service接口如下:

import org.onecmdb.core.utils.wsdl.IOneCMDBWebService;
import org.onecmdb.core.utils.wsdl.OneCMDBServiceFactory;

public class OneCMDBClient {
	public static void main(String argv[]) {
		try {
			// 创建web service接口
			IOneCMDBWebService service = OneCMDBServiceFactory.getWebService("http://localhost:8080/webservice/onecmdb");

			// 身份认证
			String token = service.auth("admin", "123");
			System.out.println("Authenticated token=" + token);

			// ....

			// 退出
			service.logout(token);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

这里,提供了在System配置项的图形查询完整范例。

import org.onecmdb.core.utils.bean.CiBean;
import org.onecmdb.core.utils.graph.query.GraphQuery;
import org.onecmdb.core.utils.graph.query.constraint.AttributeValueConstraint;
import org.onecmdb.core.utils.graph.query.selector.ItemOffspringSelector;
import org.onecmdb.core.utils.graph.result.Graph;
import org.onecmdb.core.utils.wsdl.IOneCMDBWebService;
import org.onecmdb.core.utils.wsdl.OneCMDBServiceFactory;

public class OneCMDBClient {
	public static void main(String argv[]) {
		try {
			// 创建web service接口
			IOneCMDBWebService service = OneCMDBServiceFactory.getWebService("http://localhost:8080/webservice/onecmdb");
			String token = service.auth("admin", "123");
			System.out.println("Authenticated token=" + token);

			// 构成查询...
			GraphQuery query = new GraphQuery();
			ItemOffspringSelector sel = new ItemOffspringSelector();
			sel.setTemplateAlias("System");

			// 添加约束...
			AttributeValueConstraint constraint = new AttributeValueConstraint();
			constraint.setAlias("Name");
			constraint.setOperation(AttributeValueConstraint.LIKE);
			constraint.setValue("Al%");

			sel.applyConstraint(constraint);

			query.addSelector(sel);

			// 执行查询
			Graph result = service.queryGraph(token, query);
			result.buildMap();
			for (CiBean bean : result.fetchAllNodeOffsprings()) {
				System.out.println("System=" + bean.toStringValue("Name"));
			}

			// 退出
			service.logout(token);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}

3.1.1. 使用基本模型Java范例

  1. Create/Update CI’s

4. API 概述

有效Web Services 函数有:

auth(String username, String pwd) throws Exception : String

logout(String authToken) : void

history(String auth, CiBean vBean, RfcQueryCriteria criteria) : RFCBean[] 

historyCount(String auth, CiBean vBean, RfcQueryCriteria criteria) : int

search(String auth, QueryCriteria criteria) : CiBean[]

searchCount(String auth, QueryCriteria criteria) : int

query(String auth, String xPath, String attributes) : CiBean[]

update(String auth, CiBean localBeans[], CiBean baseBeans[]) : IRfcResult

findRelation(String auth, CiBean left, CiBean right) : String[]

evalRelation(String auth, CiBean root, String relationPath, QueryCriteria crit) : CiBean[]

evalRelationCount(String auth, CiBean root, String relationPath, QueryCriteria crit) : int

queryGraph(String token, GraphQuery q) : Graph

4.1. Auth函数

语法:

auth(String username, String pwd) throws Exception : String

OneCMDB中认证一个用户。返回的令牌在所有方法中使用,要结束会话则使用Logout函数。如果用户无法通过身份验证抛出异常。

4.2. GraphQuery函数

语法:

graphQuery(String auth, GraphQuery) : Graph

这是OneCMDB目前支持的最先进的查询方法。它可以查询源自不同模板的CI以及这些CI之间的关系,它也可以对每个模板支持分页和条件搜索(如属性值)。

欲了解更多信息和示例,请参阅 WSDL的图形查询(本站翻译文章:[译]WSDL的图形查询

4.3. Query函数

语法:

query(String auth, String xPath, String attributes) : CiBean[]

使用XPath语法查询OneCMDB,返回结果总是CiBean数组,见下文的CiBean数据类型的定义。

通用XPath:

  • /template/* – 列出所有模板。
  • /template/<alias> – 获取特定别名的模板。
  • /instance/<template-alias>/* – 列出某个模板的所有实例。
  • /instance/<template-alias>/<instance-alias> -获取特定的实例。

attributes参数可用于指定包含在结果CI中属性。它通过指定属性路径控制检索索引的深度。

范例

query(“xxx”, “/instance/Router/*”, “primaryIp site site/supervisor”); 

将返回所有路由器实例和应用的Site、Person配置项实例。

4.4. Update 函数

语法:

update(String auth, CiBean localBeans[], CiBean baseBeans[]) : IRfcResult

方法用于在OneCMDB中创建、更新、删除CI。这个方法有三个参数:auth会话的令牌、bean本地集合和bean的基准集合。CI的基准集合用于决定查询时哪些CI有效,CI的本地集合用户修改已经存在的CI或者新建不存在的CI。这是一个CVS做法,基准集合是签出点,本地集合是当前修改的条目。它实现了三方比较,该方法可以检测到冲突。目前只实现了删除CI和属性检测。(译者注:localBeans即bean本地集合相当于新值,baseBeans即bean基准集合相当于旧值。即在baseBeans上修改为localBeans。)

4.5 Search(Count) 函数

语法:

search(String auth, QueryCriteria criteria) : CiBean[]
searchCount(String auth, QueryCriteria criteria) : int

OneCMDB中搜索符合某些条件的CI。searchCount函数有同样的参数但只返回搜索结果中命中数量(忽略maxResult属性),它对实现大数据集的分页非常有用。search方法比query方法快一些,但是需要更复杂的参数。

典型搜索条件是:

  • 针对值、别名、描述的文本搜索。
  • 特定模板的实例。

search函数也支持结果集的分页,通过使用maxResult和firstResult属性组合实现,见下面范例。

4.6 History(Count) 函数

语法:

history(String auth, CiBean vBean, RfcQueryCriteria criteria) : RFCBean[]
historyCount(String auth, CiBean vBean, RfcQueryCriteria criteria) : int

查看CI的变更历史记录。OneCMDBCI所有变化都进行跟踪,并存储在一个RFC对象中。这些对象可以使用这个函数检索出来。

4.7 Relation 函数

语法:

findRelation(String auth, CiBean left, CiBean right) : String[]
evalRelation(String auth, CiBean root, String relationPath, QueryCriteria crit) : CiBean[]
evalRelationCount(String auth, CiBean root, String relationPath, QueryCriteria crit) : int

注意:这些函数还处于alpha状态和改变中。findRelation方法在OneCMDB 1.3.0中未实现。

Relation 函数用于浏览模型关系。一旦关系路径是已知的,就可能从一个指定的关系路径源获取关联的实例。关系路径语法如下:

direction cmd delimiter

这里

  • direction
    • > 正向
    • < 反向
  • cmd
    • $attr{alias} – 从指定别名属性出发正向关联
    • $template{alias} – 反向,意味着CI是从指定别名模板的实例关联
  • delimiter
    • 管道标志 |

范例 – 关联一个Person实例到一个Router实例

<$template{Site}|<$template{Router}

范例 – 关联一个Router实例到Person属性

>$attr{site}|>$attr{supervisor}

4.8 Logout 函数

语法:

logout(String authToken) : void

终止会话令牌。

4.9 范例

注意: 所有的例子使用上面描述的范例模型。

4.9.1 PHP范例

下面的PHP范例使用PHP5内建SOAP扩展,它默认没有启用,要启用它请在PHP网站http://www.php.net 查找更多信息。(Windows系统中通过在php.ini文件中添加extension=php_soap.dll启用它。)

4.9.1.1 范例 – 列出路由器的所有实例

<?php
  // 指定WSDL URL
  $wsdl_url = "http://localhost:8080/webservice/onecmdb?wsdl";

  // 创建Soap 客户端
  $client = new SoapClient($wsdl_url);

  // 通过OneCMDB身份认证
  $token = $client->auth(“admin”, “123”);

  // 查询路由器实例
  $routers = $client->query($token, “/instance/Router/*”, ”*”);

  // 退出
  $client->logout($token);

  // 显示转储结果
  print_r($routers);
?>

4.9.1.2 范例 – 搜索某个属性值

<?php

	// 范例 - 搜索指定属性值的CI
	// ========================================================

	// 使用PHP5 内部soap客户端创建Soap客户端
	$wsdl_url = "http://localhost:8080/webservice/onecmdb?wsdl";
	$client = new SoapClient($wsdl_url);
	try {
		$token = $client->auth("admin", "123");
	} catch (SoapFault $e) {
		print("Auth Error:::: $e");
	}

	// 设置搜索条件
	$criteria->offspringOfAlias = "Router";
	$criteria->textMatchValue = "true";
	$criteria->text = "192.168.1.2";

	// 映射到正确的命名空间
	$arg1 = new SoapVar($criteria, 0, "QueryCriteria", "http://model.internal.core.onecmdb.org"); 

	// 获取搜索结果数量
	$result = $client->searchCount($token, $arg1);
	print("Matched : $result CI");
	print("<br/>");

	// 搜索所有符合条件的CI
	$result = $client->search($token, $arg1);

	// 显示结果
	// 注意:如果返回数组中只有一个条目,它将不再是数组!
	if (is_array($result->CiBean)) {
		print("<ul>");
   		foreach ($result->CiBean as $bean) {
   			print("<li>");
   	  		print("Alias=$bean->alias displayName=$bean->displayName");
   			print("</li>");
   		}
   		print("</ul>");
	} else {
		$bean = $result->CiBean;
   		print("Alias=$bean->alias displayName=$bean->displayName");
   	} 

   	// 这样退出也不错
   	$client->logout($auth);
?>

4.9.1.3 范例 – 添加一个配置项模板和实例

<?php
// 该函数创建一个实例对象
function getInstance($alias) {
		$instance->alias = $alias;
		$instance->derivedFrom = "NewTemplate";		

		$attrValue->alias = "a1";
		$attrValue->value = "value for $alias";
		$instance->attributeValues[0] = new SoapVar($attrValue, 0, "ValueBean", "http://bean.utils.core.onecmdb.org");

		// 映射到正确的命名空间
		$soapArg =  new SoapVar($instance, 0, "CiBean", "http://bean.utils.core.onecmdb.org");
		return($soapArg);
}

	// 检查时间
	$start = time();

	/**
	 * 范例 - 添加一个配置项模板和实例
	 */
	$wsdl_url = "http://localhost:8080/webservice/onecmdb?wsdl";

	$client = new SoapClient($wsdl_url);
	try {
		$token = $client->auth("admin", "123");
	} catch (SoapFault $e) {
		print("Auth Error:::: $e");
	}

	$template->alias = "NewTemplate";
	$template->derivedFrom = "Root";
	$template->displayNameExpression = "Test PHP CI";
	$template->description = "Testing template creating from PHP";
	$template->template = "true";

	$attr1->alias = "a1";
	$attr1->type = "xs:string";
	$attr1->description = "Test attribute";
	$template->attributes[0] = new SoapVar($attr1, 0, "AttributeBean", "http://bean.utils.core.onecmdb.org");

	// 映射到正确的命名空间
	$arg1[0] =  new SoapVar($template, 0, "CiBean", "http://bean.utils.core.onecmdb.org");

	// 创建100个实例
	for ($i = 0; $i < 100; $i++) {
		// 产生实例
		$arg1[] = getInstance("instance-$i");
	}

	$count = count($arg1);
	print("<h1>Example - Create/Delete $count CI:s</h1>");
	$updateStart = time();

	// 创建所有配置项
	$result = $client->update($token, $arg1, Null);
	$updateStop = time();
	$dtUpdate = $updateStop-$updateStart;
	$stop = time();
	$dt = $stop-$start;
	print("<h2>Create/Update Request took $dt [s], call to server $dtUpdate [s]</h2>");

	// 删除所有已经创建的配置项
	$startDelete = time();
	$result = $client->update($token, Null, $arg1);
	$stopDelete = time();
	$dtDelete = $stopDelete - $startDelete;
	print("<h2>Delete Request ($result->rejected) took $dtDelete [s]</h2>");
?>

4.9.1.4 范例 – 显示某个配置项历史

<?php

function showRFC($rfc) {

	print("<td>$rfc->ts</td>");
	print("<td>$rfc->issuer</td>");
	print("<td>$rfc->summary</td>");

}
	/**
	 * 范例 - 显示CI历史
	 */
	$wsdl_url = "http://localhost:8080/webservice/onecmdb?wsdl";

	$client = new SoapClient($wsdl_url);
	try {
		$token = $client->auth("admin", "123");
	} catch (SoapFault $e) {
		print("Auth Error:::: $e");
	}

	try {
		// 请求最后的变更 	
		$rfcQuery->fetchAttributes = "true";
		$rfcQuery->maxResult = "20";
		$rfcQuery->descendingOrder = "true";
		// 绑定参数的命名空间
		$arg1 = new SoapVar($rfcQuery, 0, "RfcQueryCriteria", "http://ccb.internal.core.onecmdb.org");

		$result = $client->history($token, Null, $arg1);

		// 用表格显示结果
		print("<table border=\"1\">");
		print("<tr>");
		print("<th>Date</th>");
		print("<th>Issuer</th>");
		print("<th>Summary</th>");
		print("</tr>");

		// 注意:如果返回数组中只有一个条目,它将不再是数组!
		if (is_array($result->RFCBean)) {

			foreach($result->RFCBean as $rfc) {
				print("<tr>");
				showRFC($rfc);
				print("</tr>");
			}

		} else {
				print("<tr>");
				showRFC($result->RFCBean);
				print("</tr>");
		}
		print("</table>");

	} catch (SoapFault $e) {
		print("Auth Error:::: $e");
	}
?>

4.9.2 使用XFire客户端的Java语言范例

4.9.2.1 范例 – 转储配置项模板到XML

/**
 * <code>范例1</code> 取得所有配置项模板,并生成XML输出
 */
public class Example1 {

	public static void main(String argv[]) {
		// 注意: 这里不需要?wsdl
		String url = "http://localhost:8080/webservice/onecmdb";
		String username = "admin";
		String pwd = "123";
		String path = "/template/*";

		try {
			// 创建服务
			Service serviceModel = new ObjectServiceFactory().create(IOneCMDBWebService.class);

			// 创建IOneCMDBWebService代理实例
			IOneCMDBWebService service = (IOneCMDBWebService)
			    new XFireProxyFactory().create(serviceModel, url);

			// 通过OneCMDB身份认证
			String token = service.auth(username, pwd);

			// 查询所有模板
			CiBean[] beanArray = service.query(token, path, "*");
			List<CiBean> beans = Arrays.asList(beanArray);

			// 产生所有模板的XML文本到标准输出
			XmlGenerator gen = new XmlGenerator();
			gen.setBeans(beans);
			gen.transfer(System.out);
		} catch (Exception e) {
			System.err.println("ERROR:" + e.toString());
			e.printStackTrace();
		}
	}
}

4.9.2.2 范例 – 从XML文件导入配置项

/**
 * <code>范例2</code> 导入XML文件(myModel.xml)并更新OneCMDB
 *
 */
public class Example2 {
	public static void main(String argv[]) {
		String url = "http://localhost:8080/webservice/onecmdb";
		String username = "admin";
		String pwd = "123";
		String myFile = "file:myModel.xml";

		try {
			Service serviceModel = new ObjectServiceFactory().create(IOneCMDBWebService.class);

			IOneCMDBWebService service = (IOneCMDBWebService)
			    new XFireProxyFactory().create(serviceModel, url);

			String token = service.auth(username, pwd);

			XmlParser provider = new XmlParser();
			provider.addURL(myFile);

			// 解析XML文件
			CiBean beans[] = provider.getBeans().toArray(new CiBean[0]);

			// 更新OneCMDB.
			IRfcResult result = service.update(token, beans, null);

			// 检查是否更新成功
			if (result.isRejected()) {
				System.out.println("Error importing, cause : " + result.getRejectCause());
			} else {
				System.out.println("Import completed");
			}
		} catch (Exception e) {
			System.err.println("ERROR:" + e.toString());
			e.printStackTrace();
		}
	}
}

4.9.2.3 范例 – 搜索配置项并分页

/**
 * <code>范例3</code> 在OneCMDB中搜索实例并分页
 */
public class Example3 {
	public static void main(String argv[]) {

		String url = "http://localhost:8080/webservice/onecmdb";
		String username = "admin";
		String pwd = "123";

		try {
			Service serviceModel = new ObjectServiceFactory().create(IOneCMDBWebService.class);

			IOneCMDBWebService service = (IOneCMDBWebService)
			    new XFireProxyFactory().create(serviceModel, url);

			String token = service.auth(username, pwd);

			int pageSize = 5;
			int offset = 0;
			// 列出所有路由器
			QueryCriteria criteria = new QueryCriteria();
			criteria.setOffspringOfAlias("Router");
			criteria.setMatchCiInstances(true);
			criteria.setMaxResult(pageSize);

			int count = service.searchCount(token, criteria);
			System.out.println("Total router instances : " + count);

			// 搜索配置项并分页
			while(offset < count) {
				criteria.setFirstResult(offset);
				CiBean[] beanArray = service.search(token, criteria);
				System.out.println("Retrieved " + beanArray.length + " routers");
				offset += pageSize;
			}

		} catch (Exception e) {
			System.err.println("ERROR:" + e.toString());
			e.printStackTrace();
		}
	}
}

4.9.2.4 范例 – 删除配置项

/**
 * <code>范例4</code> 从OneCMDB中删除CI
 */
public class Example4 {
	public static void main(String argv[]) {

		String url = "http://localhost:8080/webservice/onecmdb";
		String username = "admin";
		String pwd = "123";

		try {
			Service serviceModel = new ObjectServiceFactory().create(IOneCMDBWebService.class);

			IOneCMDBWebService service = (IOneCMDBWebService)
			new XFireProxyFactory().create(serviceModel, url);

			String token = service.auth(username, pwd);

			// 创建10个路由器实例
			List<CiBean> list = new ArrayList<CiBean>();
			for (int i = 0; i < 10; i++) {
				list.add(new CiBean("Router", "ri-" + i, false));
			}

			// 更新OneCMDB
			IRfcResult result = service.update(token, list.toArray(new CiBean[0]), null);
			if (result.isRejected()) {
				System.out.println("Can't add instances cause " + result.getRejectCause());
				System.exit(-1);
			}
			System.out.println("Instances added");

			// 现在删除这些实例
			// 注意作为最后一个参数的列表
			result = service.update(token, null, list.toArray(new CiBean[0]));
			if (result.isRejected()) {
				System.out.println("Can't delete instances cause " + result.getRejectCause());
				System.exit(-1);
			}
			System.out.println("Instances deleted");

		} catch (Exception e) {
			System.err.println("ERROR:" + e.toString());
			e.printStackTrace();
		}
	}
}

4.9.2.5 范例 – 查看最近修改的配置项ed CI.

译者注:英文Wiki文章这里并没有代码

5 Web Service 数据类型描述

Web Service接口中使用参数对象简介,每个数据类型更详细描述可以在WSDL找到。

5.1 CiBean

范围:输入和输出

命名空间 http://bean.utils.core.onecmdb.org

定义配置项,包含属性和值的列表

属性:

id
配置项后端ID,只读。
alias
CI的别名
derivedFrom
采用模板的别名
template
是模板还是实例
description
配置项的详细描述
displayNameExpression
显示名称的表达式,没有经过计算的。
displayName
经过计算的显示名称。(只读)
attributes
CI所有继承的、自身属性列表。当CI是一个模板时有值。
attributeValues
CI所有属性的值列表。

5.2 AttributeBean

范围:输入和输出

命名空间:http://bean.utils.core.onecmdb.org

定义CI的属性定义。

属性:

alias
属性的别名。
displayName
属性的显示名称。
complexType
如果 complexType 值为 true,其之就是到另外CI的引用(别名)。
type
类型别名。
refType
引用类型别名,如果没有需要的引用类型,则为null。
maxOccurs
该属性出现最多次数。
minOccurs
该属性出现最少次数。
description
属性的详细描述。
id
后端ID。(只读)
derived
属性是否在这个模板中定义。(只读)

5.3 ValueBean

范围:输入和输出

命名空间:http://bean.utils.core.onecmdb.org

定义CI的值。

属性::

id
后端ID,只读。 
alias
属性的别名
value
实际值,可以是复杂类型,那意味着它是别名。
complexValue
指示值是否是复杂类型。
beanValue
值是另外一个 CiBean。

5.4 RfcQueryCriteria

范围: 输入

命名空间:http://ccb.internal.core.onecmdb.org

用于查询OneCMDBCI变更情况对象。

属性:

rfcClass
查询中应该包含一个RFC类型(类),这个变更类有如下这些类可用(如果没有设置将查询所有变更):
org.onecmdb.core.internal.ccb.rfc.RFCNewCi
org.onecmdb.core.internal.ccb.rfc.RFCNewAttribute
org.onecmdb.core.internal.ccb.rfc.RFCDestroy
org.onecmdb.core.internal.ccb.rfc.RFCModifyAlias
org.onecmdb.core.internal.ccb.rfc.RFCModifyAttributeType
org.onecmdb.core.internal.ccb.rfc.RFCModifyAttributeReferenceType
org.onecmdb.core.internal.ccb.rfc.RFCModifyDerivedAttributeValue
org.onecmdb.core.internal.ccb.rfc.RFCModifyAttributeValue
org.onecmdb.core.internal.ccb.rfc.RFCModifyDescription
org.onecmdb.core.internal.ccb.rfc.RFCModifyIsTemplate
org.onecmdb.core.internal.ccb.rfc.RFCModifyDescription
org.onecmdb.core.internal.ccb.rfc.RFCModifyDisplayNameExpression
org.onecmdb.core.internal.ccb.rfc.RFCModifyMaxOccurs
org.onecmdb.core.internal.ccb.rfc.RFCModifyMinOccurs
fromDate
变更发生的起始时间。
toDate
变更发生的结束时间。
descendingOrder
按时间对结果排序,缺省为false。
maxResult
每次返回多少变更记录。和firstResult一起使用实现分页。
firstResult
每次跳过多少变更记录。和maxResult一起使用实现分页。
fetchAttributes
查询CI所有属性变更,缺省只查询CI的变更。
attributeAlias
查询指定别名的属性的变更。

5.5 RFCBean

范围: output

命名空间:http://wsdl.utils.core.onecmdb.org

为查询CI历史时的结果。

id
对应RFC后端ID。
issuer
提交变更的用户。
ts
发生变更的时间。
summary
变更摘要。
transactionId
封闭事务的后端ID。

5.6 QueryCriteria

范围: 输入

命名空间:http://model.internal.core.onecmdb.org

用于在OneCMDB中查询CI的对象。支持分页和自由文本搜索。

属性描述:

offspringOfId
只搜索某ID的后代。
offspringOfAlias
只搜索某别名的后代。
matchCiTemplates
匹配CI模板。
matchCiInstances
匹配CI 实例。
matchAttributeTemplates
匹配属性模板,意味着属性的定义。
matchAttributeInstances
匹配属性实例,意味着属性的值。
maxResult
返回总数。
firstResult
跳过条数直到firstResult值对应的记录。
matchAttribute
在属性中匹配
matchCi
CI中匹配
text
搜索的自由文本,将使用通配符前后匹配。
textMatchAlias
在别名上匹配文本。
textMatchValue
在值上匹配文本。
textMatchDescription
在描述上匹配文本。

5.7 IRfcResult

范围: 输出

命名空间:http://core.onecmdb.org

执行更新命令之后的结果。

属性描述:

rejected
反映一个提交的变更是否被拒绝。如果被拒绝,rejectCause将包含一个拒绝原因。
rejectCause
拒绝的主要原因,如果没有拒绝则返回null。

原文见:http://www.onecmdb.org/wiki/index.php?title=OneCMDB_Web_Services_V2.0,由OneCMDB中文站翻译,完成于2010年01月12日。

参数

实例概览Widget是一个小部件,最复杂的部件。可以配置如下内容:

  • 表格
    • 可见与否
    • 属性顺序
    • 排除/包含 哪些属性
    • 列宽
    • 可见与否
  • 图形
    • 可见与否

这个小部件params 部分支持以下内容:

	<params>
		<rootCI asSimpleList="true">NAGIOS_Host</rootCI>
		<table>
			<visible>true</visible>
			<ColumnFilter asList="true" alias="NAGIOS_Host">
				<Column attAlias="host_name" asList="true" include="true">
					<include>true</include>
					<width>300</width>
				</Column>
				<Column attAlias="address" asList="true">
					<include>true</include>
					<width>300</width>
				</Column>
				<order asSimpleList="true">host_name</order>
				<order asSimpleList="true">address</order>
			</ColumnFilter>
		</table>
		<tree>
			<visible>true</visible>
		</tree>
		<graph>
			<visible>true</visible>
			<applet definitions>
			....
		</graph>			

这个配置将在左侧模板面板中只显示Nagios_Host 模板。

可见列是 host_name 和 address,列宽300像素。显示顺序是先 host_name 后 address。

列可以设置 include为true 或者 exclude为true。如果列过滤器中有任何列标记include为"true" ,则只显示这些列;如果一个或者多个列标记exclude为"true",则这些列将被隐藏而其他列还是可见。

order 指定列显示的顺序,如果并不是所有列指定了顺序,那么剩余的列将在顺序显示列之后按照随机顺序显示。

下面是Nagios 试图的完整范例。

<?xml version="1.0"?>
<CustomView>
	<widgets>
		<widget asList="true" id="cmdb-model-instance-overview">
			<heading>Nagios View</heading>
			<width>650px</width>
			<height>600px</height>
			<params>
				<rootCI asSimpleList="true">NAGIOS_Host</rootCI>
				<rootCI asSimpleList="true">NAGIOS_Hostgroup</rootCI>
				<rootCI asSimpleList="true">NAGIOS_Service</rootCI>
				<rootCI asSimpleList="true">NAGIOS_Servicegroup</rootCI>
				<rootCI asSimpleList="true">NAGIOS_Command</rootCI>
				<rootCI asSimpleList="true">NAGIOS_Timeperiod</rootCI>
				<table>
					<visible>true</visible>
					<ColumnFilter asList="true" alias="NAGIOS_Host">
						<Column attAlias="host_name" asList="true" include="true">
							<include>true</include>
							<width>300</width>
						</Column>
						<Column attAlias="address" asList="true">
							<include>true</include>
							<width>300</width>
						</Column>
					</ColumnFilter>

					<ColumnFilter asList="true" alias="NAGIOS_Service">
							<Column asList="true" attAlias="host_name">
								<include>true</include>
								<width>150</width>
							</Column>
							<Column asList="true" attAlias="service_description">
								<include>true</include>
								<width>200</width>
							</Column>
							<Column asList="true" attAlias="check_command">
								<include>true</include>
								<width>200</width>
							</Column>
							<Column asList="true" attAlias="max_check_attempts">
								<include>true</include>
								<width>50</width>
							</Column>
							<Column asList="true" attAlias="normal_check_intervall">
								<include>true</include>
								<width>50</width>
							</Column>
							<Column asList="true" attAlias="retry_check_intervall">
								<include>true</include>
								<width>50</width>
							</Column>
							<Column asList="true" attAlias="check_period">
								<include>true</include>
								<width>200</width>
							</Column>
							<Column asList="true" attAlias="notification_period">
								<include>true</include>
								<width>150</width>
							</Column>
					</ColumnFilter>
				</table>

				<tree>
					<visible>true</visible>
				</tree>

				<graph>
					<visible>true</visible>
					<code>org.onecmdb.rest.graph.utils.applet.AppletLaunch.class</code>
					<archive>onecmdb/content/Content/applet/onecmdb-applet.jar, onecmdb/content/Content/applet/onecmdb-applet-dependencies.jar</archive>
					<param>
						<url>${baseURL}/onecmdb/query</url>
						<rootCI>Ci</rootCI>
						<appletlaunch.callcode>org.onecmdb.rest.graph.applet.InstanceViewApplet</appletlaunch.callcode>
						<appletlaunch.color.background>FFFFFF</appletlaunch.color.background>
						<appletlaunch.splash>onecmdb/content/Content/applet/applet-loading.gif</appletlaunch.splash>
						<appletlaunch.splasherror>onecmdb/content/Content/applet/applet-error.gif</appletlaunch.splasherror>
						<appletlaunch.version>1.5.0</appletlaunch.version>
						<iconURL>${baseURL}/onecmdb/icon</iconURL>
						<graphBackgroundColor>0x454545</graphBackgroundColor>
					</param>
				</graph>
			</params>
		</widget>
	</widgets>
</CustomView>

原文见:http://www.onecmdb.org/wiki/index.php?title=Instance_Overview_Widget_Params,由OneCMDB中文站翻译,完成于2010年01月11日。

译者注:这是OneCMDB 1.3.0版本之后的文章,不一定适用新版本OneCMDB

目录

PHP 范例程序

PHP范例程序用表格显示用户定义的CI,这个表格的列是可以配置和编辑的。它们都是用PHP语言编写,并使用OneCMDB 1.3.0 中引入的WebService接口。代码可以在SourceForge下载到。(译者注:直接下载地址是http://sourceforge.net/projects/onecmdb/files/onecmdb%20%28older%20versions%29/1.3.0/php-example-application-0.0.2.zip/download

欲了解更多有关Web Service APIOneCMDB文档,请参考Web ServicesTutorial。(译者注:这里写的Web Services连接页面并没有文章,对应的可参考本站翻译文章:[译]OneCMDB Web Services V2.0。这里的Tutorial连接页面也没有文章,对应的可参考本站翻译文章:[译]OneCMDB 教程V2.0。)

1. 前提条件

  • PHP 5并启用SOAP。
  • http服务器,例如Apache,并做好PHP环境配置。
  • OneCMDB 1.3.0 安装完成。

2. 设置

  • 解压tar文件,并让http服务器可以访问到。
  • 如果OneCMDB不是安装在本机,指定OneCMDB安装位置。
    • 编辑文件onecmdb-tool.php中getOneCMDB_URL()函数。

3. 开始使用

  • 打开页面 http://localhost/onecmdb-php-example/login.php,或者 http服务器安装位置。
  • 登录为用户名admin,密码123。
  • 点击Table View Configuration配置表格。
  • 一旦表格配置好,它将在主页中列出。

3.1 配置表格视图

要添加一个新表,按[添加],然后按下[编辑]进行编辑。

配置一个表格需要填写四个字段。

  • Image
    • 标题中显示的图片URL地址。
  • Title
    • 表格的标题,将显示在主页中。
  • Template
    • 所有这个模板的实例将显示在表格中。
  • Columns
    • 指定要显示的列的表达式,见下文。

3.2 列字段

列字段语法如下:

[ColHeader1,Expr1];[ColHeader2,Expr2];...

这里:

ColHeaderN 将显示在列标头中

ExprN 根据每一行(实例)计算。表达式可以是CI的属性,也可以是CI实例到另外CI的引用。

3.2.1 表达式

对于CI及属性基本的了解,请阅读Web ServicesTutorial 获取更多信息。(译者注:和前面一样,请参阅本站翻译文章[译]OneCMDB Web Services V2.0[译]OneCMDB 教程V2.0。)

  • 简单属性
    • ${alias} CI的别名。
    • ${displayName} CI的显示名称。
    • ${attrAlias} 属性别名的值。
  • 复杂属性(引用)
    • $>attr{attrAlias}|>attr{attrAlias2}
      • 将显示路径attrAlias.attrAlias2的引用CI,该|标志被视为分隔符。
    • <$template{templateAlias}
      • 将显示所有引用此CICI
  • 注意: >attr{alias} 和<template{alias} 可以再同一个表达式组合使用。

3.2.2 范例

列出所有Hadware实例,并带有displayName、Name、Type属性和softwares引用,输入如下内容:

template: Hardware
columns: [ID,${displayName}];[Name,${A_Name}];[Type,${A_Type}];[Software,${K_Software}]

列出所有软件和运行它的硬件,输入如下内容:

template: Software
columns: [ID,${displayName}];[Name,${A_Name}];[Hardware,$<template{Hardware}]

原文见:http://www.onecmdb.org/wiki/index.php?title=PHP_Example_Application,由OneCMDB中文站翻译,完成于2010年01月11日。

目录

1. OneCMDB – 查询

CMDBf [1] (CMDB 联盟) 已经作为供OneCMDB所使用的查询语言指导路线。OneCMDB目前不支持CMDBf查询语法。

查询OneCMDB获取配置项,并以XML格式表示。

<?xml version="1.0" encoding="UTF-8"?>
<GraphQuery>
	<ItemOffspringSelector id="system" template="System" primary="true">
		<matchTemplate>false</matchTemplate>
		<constraint>

			<AttributeValueConstraint>
				<value>text%</value>
				<alias>Name</alias>
				<operation>LIKE</operation>
			</AttributeValueConstraint>
		</constraint>
	</ItemOffspringSelector>

	<ItemOffspringSelector id="os" template="OS">
		<matchTemplate>false</matchTemplate>
	</ItemOffspringSelector>

	<ItemRelationSelector id="os2system" template="InstalledOn">
		<target>system</target>
		<source>os</source>
		<mandatory>true</mandatory>
	</ItemRelationSelector>
</GraphQuery>

这将获取所有源自System 的实例和源自OS的实例被并且实例被引用。

请注意引用选择器被标记成必须的,这意味着只有System实例和有一个确切的引用的OS的实例被返回。如果mandatory 设置成false,则所有OSSystem都会被返回。

选择器可包含一个Constraint 选择,如在上面的例子中的 AttributeValueConstraint.。如果一组约束被应用,可以使用 ItemAndGroupConstraint 或者 ItemOrGroupConstraint 。例如:

...
<ItemOffspringSelector id="system" template="System" primary="true">
	<matchTemplate>false</matchTemplate>
	<constraint>
		<ItemAndGroupConstraint>

			<AttributeValueConstraint>
				<value>Servasd%</value>
				<alias>Name</alias>
				<operation>like</operation>
			</AttributeValueConstraint>

			<AttributeValueConstraint>
				<value>192.168.1.3</value>
				<alias>IPAddress</alias>
				<operation>eq</operation>
			</AttributeValueConstraint>
		</ItemAndGroupConstraint>
	</constraint>
	...

GraphQuery 包含一组不同类型的选择器。每个选择器可以包含一个不同类型的约束。

1.1 查询选择器类型

所有选择器的条目都有这些XML属性:

  • template – 模板的别名。
  • id – 选择器的ID名字。用于指定目标/来源和指定按照树或者图形格式化输出。
  • primary – "true"意味着引擎将首先获取这些实例,然后获取这些实例找到的to或者from应用的实例。

所有选择器的条目都有这些XML元素:

  • pageInfo – 限制返回对象的数量。
    • firstResult – 从这个偏移开始。
    • maxResult – 获取对象的最大数量。

具体有这些不同的选择器存在::

  • ItemOffspringSelector
    • limitToChild – true/false 获取源自这个模板所有的实例。
    • matchTemplates – 是否仅仅获取实例
  • ItemAliasSelector
    • alias – 指定搜索的别名。
  • ItemRelationSelector
    • target – 关系中目的选择器ID。
    • source – 关系中源选择器ID。
    • mandatory – 缺省值为true。意味着如果一个实例没有这个应用则它不会是结果中的一部分。

1.2 选择器约束类型

  • AttributeValueConstraint – 依赖属性值匹配对象。
    • operation
      • LIKE,EQ,GT,GE,LT,LE and IS_NULL
    • alias
      • 指定在哪个属性中执行搜索。如果没有指定则在所有属性中搜索。注意这个别名是属性的别名而不是配置项的别名。
    • value – 应用到操作中的值。如果是like操作被使用,’%’ 作为通配符使用。
    • valueType – 指定值是文本、日期还是数字,默认是文本(注意:2.0.0Beta中无效)。
  • ItemAndGroupConstraint – 所有约束分组并执行操作,可以包含和分组、或分组。
  • ItemOrGroupConstraint- 所有约束分组并执行操作,可以包含和分组、或分组。

2 OneCMDB 查询结果

但从OneCMDB中导出数据时可以使用不同的格式。

  • tree – 按树形结构格式化引用,主选择器作为顶层节点,仅仅支持实例的结果集合。
  • graph – 格式化所有实例作为Node节点,格式化所有引用作为Edge节点,仅仅支持实例的结果集合。
  • onecmdb – 格式化化所有结果作为模板和实例。这种格式可用于导入配置项到OneCMDB中。

后面所有范例中将使用下面的查询:

<?xml version="1.0" encoding="UTF-8"?>
<GraphQuery>
	<ItemOffspringSelector id="system" template="System"
		primary="true">
		<matchTemplate>false</matchTemplate>
	</ItemOffspringSelector>

	<ItemOffspringSelector id="os" template="OS">
		<matchTemplate>false</matchTemplate>
	</ItemOffspringSelector>

	<ItemRelationSelector id="os2system" template="InstalledOn">
		<target>system</target>
		<source>os</source>
		<mandatory>true</mandatory>
	</ItemRelationSelector>
</GraphQuery>

2.1 树

指定xmlStyle为tree将产生如下结构:

<Tree>
	<selector-id>
		<attrAlias>value</attrAlias>
		...
		<reference-selector-id direction="INBOUND|OUTBOUND">
			<selector-id alias=".." ...>
			</selector-id>
			...
		</reference-selector-id>
		...
	</selector-id>
	<selector-id alias="">
		...
	</selector-id>
	...
</Tree>

2.2 图形

指定xmlStyle为graph将产生如下结果:

<Nodes>
	<Node>
		<template ....>
			Template definition here.
		</template>
		<Offsprings totalCount="n">
			<instance ...>
			</instance>
			...
		</Offsprings>
	</Node>
</Nodes>
<Edges>
	<Edge>
		<template ....>
			Template definition here.
		</template>
		<Offsprings totalCount="n">
			<instance ...>
			</instance>
			...
		</Offsprings>
	</Edge>
</Egdes>

2.3 OneCMDB

指定xmlStyleonecmdb将产生如下结果:

<onecmdb>
	<templates>
		<template ....>
			Template definition here.
		</template>
	</templates>
	<instances>
		<instance ...>
			Values here.
		<instance>
	</instances>
</onecmdb>

3. 结果集范例

3.1 树

<?xml version="1.0" encoding="UTF-8"?>
<Tree>
    <system alias="Server1235140235014" id="6466729608999320056" type="Laptop"  createDate="2009-02-20T14:30:48.991"  modifyDate="2009-02-20T14:34:27.204">
        <IPAddress>192.168.1.3</IPAddress>
        <IPv6Address></IPv6Address>
        <Name>Server-2</Name>
        <type></type>
        <Hostname></Hostname>
        <SerialNumber></SerialNumber>

        <MAC_Address></MAC_Address>
        <icon>computer</icon>
        <os2system direction="INBOUND">
            <os alias="Linux1235140256386" id="6511231821654831789" type="Vista"  createDate="2009-02-20T14:31:43.279"  modifyDate="2009-02-20T14:39:17.703">
                <Family>Windows</Family>
                <Version>Vista SP1</Version>
                <Name>Vista 12-23-23-23</Name>

                <LicenseKey></LicenseKey>
                <DSLEntry>http://www.onecmdb.org/docs/BasicDatacenter/DSL/Dummy_OS_Package.txt</DSLEntry>
                <type></type>
                <icon>windows_vista</icon>
            </os>
        </os2system>
    </system>
    <system alias="Server1235136691508" id="-5594175356767968185" type="Server"  createDate="2009-02-20T13:31:41.251"  modifyDate="2009-02-20T13:31:55.647">

        <IPAddress>192.168.1.2</IPAddress>
        <IPv6Address></IPv6Address>
        <Name>Server-1</Name>
        <type></type>
        <Hostname></Hostname>
        <SerialNumber></SerialNumber>
        <MAC_Address></MAC_Address>
        <icon>computer</icon>

        <os2system direction="INBOUND">
            <os alias="Linux1235136742592" id="-1734321206646869776" type="Linux"  createDate="2009-02-20T13:32:23.064"  modifyDate="2009-02-20T14:31:43.404">
                <Family>Linux</Family>
                <Version>CentOS 4</Version>
                <Name>Red Hat Linux</Name>
                <LicenseKey></LicenseKey>
                <DSLEntry></DSLEntry>

                <type></type>
                <icon>linux</icon>
            </os>
        </os2system>
    </system>
</Tree>

3.2 图形

<?xml version="1.0" encoding="UTF-8"?>
<OneCMDBGraph>
	<Nodes>
	<Node id="system" type="System">
			<template alias="System" id="-7669800229146595453" displayName="${Name} ${IPAddress}" created="2009-02-20T09:56:52.352" lastModified="2009-02-20T09:57:15.752">
				<derivedFrom>
					<ref alias="Hardware"/>
				</derivedFrom>
				<description>This CI specifies one system. A System is connected to a network.</description>

				<attribute attAlias="Location" displayName="Location" derived="true" id="8068622947760380320">
					<complexType>
						<ref alias="Location"/>
						<refType><ref alias="PointsTo"/></refType>
					</complexType>
					<policy>
						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>

					</policy>
				</attribute>
				<attribute attAlias="IPAddress" displayName="IPv4 Address" derived="false" id="3855714186426234308">
					<simpleType>xs:string</simpleType>
					<policy>
						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>

					</policy>
				</attribute>
				<attribute attAlias="Manufacturer" displayName="Manufacturer" derived="true" id="-958989050751007321">
					<complexType>
						<ref alias="Company"/>
						<refType><ref alias="PointsTo"/></refType>
					</complexType>
					<policy>
						<maxOccurs>1</maxOccurs>

						<minOccurs>1</minOccurs>
					</policy>
				</attribute>
				<attribute attAlias="IPv6Address" displayName="IPv6 Address" derived="false" id="-8531996163921693937">
					<simpleType>xs:string</simpleType>
					<policy>
						<maxOccurs>1</maxOccurs>

						<minOccurs>1</minOccurs>
					</policy>
				</attribute>
				<attribute attAlias="Financials" displayName="Financial Info" derived="true" id="-1060952245017242924">
					<complexType>
						<ref alias="Financial"/>
						<refType><ref alias="PointsTo"/></refType>
					</complexType>

					<policy>
						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>
					</policy>
				</attribute>
				<attribute attAlias="Name" displayName="Name" derived="true" id="-5100631602909667004">
					<simpleType>xs:string</simpleType>

					<policy>
						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>
					</policy>
				</attribute>
				<attribute attAlias="Status" displayName="Status" derived="true" id="1519620407458411252">
					<complexType>
						<ref alias="OperationalStatus"/>

						<refType><ref alias="PointsTo"/></refType>
					</complexType>
					<policy>
						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>
					</policy>
				</attribute>
				<attribute attAlias="type" displayName="Type" derived="true" id="-1673884082628696233">

					<simpleType>xs:string</simpleType>
					<policy>
						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>
					</policy>
				</attribute>
				<attribute attAlias="ConnectedTo" displayName="Connected To" derived="false" id="-3666481373642595764">

					<complexType>
						<ref alias="System"/>
						<refType><ref alias="ConnectedTo"/></refType>
					</complexType>
					<policy>
						<maxOccurs>unbound</maxOccurs>
						<minOccurs>0</minOccurs>
					</policy>

				</attribute>
				<attribute attAlias="Maintenance" displayName="Maintenance Info" derived="true" id="-688925696344764976">
					<complexType>
						<ref alias="Maintenance"/>
						<refType><ref alias="PointsTo"/></refType>
					</complexType>
					<policy>
						<maxOccurs>1</maxOccurs>

						<minOccurs>1</minOccurs>
					</policy>
				</attribute>
				<attribute attAlias="Hostname" derived="false" id="674380289125989798">
					<simpleType>xs:string</simpleType>
					<policy>
						<maxOccurs>1</maxOccurs>

						<minOccurs>1</minOccurs>
					</policy>
				</attribute>
				<attribute attAlias="Network" displayName="Network" derived="false" id="177445534745656517">
					<complexType>
						<ref alias="Network"/>
						<refType><ref alias="BelongsTo"/></refType>
					</complexType>

					<policy>
						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>
					</policy>
				</attribute>
				<attribute attAlias="SerialNumber" displayName="Serial Number" derived="true" id="896531332138664931">
					<simpleType>xs:string</simpleType>

					<policy>
						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>
					</policy>
				</attribute>
				<attribute attAlias="MAC_Address" displayName="MAC Address" derived="false" id="-4098150313519232941">
					<simpleType>xs:string</simpleType>

					<policy>
						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>
					</policy>
				</attribute>
				<attribute attAlias="Service" displayName="Service" derived="true" id="3389503358813144435">
					<complexType>
						<ref alias="Service"/>

						<refType><ref alias="BelongsTo"/></refType>
					</complexType>
					<policy>
						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>
					</policy>
				</attribute>
				<attribute attAlias="icon" displayName="Icon" derived="true" id="3643547014002026039">

					<description>Filename (no file extension) of icon image.</description>
					<simpleType>xs:string</simpleType>
					<policy>
						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>
					</policy>
				</attribute>

		<setSimpleValue attAlias="Name" id="-491182037504367078">System</setSimpleValue>
		<setSimpleValue attAlias="icon" id="-4895452324526313082">system</setSimpleValue>
			</template>
		<Offsprings totalCount="-1">
				<Laptop alias="Server1235140235014" id="6466729608999320056" displayName="${Name} ${IPAddress}" created="2009-02-20T14:30:48.991" lastModified="2009-02-20T14:34:27.204" displayValue="Server-2 192.168.1.3">
					Server-2 192.168.1.3
					<description>This CI specifies one laptop computer system. A laptop computer system can may not be located in one place.Is owned by one person at a time.</description>
					<icon id="-2478114294188147891">computer</icon>

					<Name id="-5321727766033555871">Server-2</Name>
					<IPAddress id="991434085522247207">192.168.1.3</IPAddress>
				</Laptop>
				<Server alias="Server1235136691508" id="-5594175356767968185" displayName="${Name} ${IPAddress}" created="2009-02-20T13:31:41.251" lastModified="2009-02-20T13:31:55.647" displayValue="Server-1 192.168.1.2">
					Server-1 192.168.1.2
					<description>This CI specifies one server computer system. A Server Computer System is used to host server applications.</description>
					<icon id="-5476264572729428563">computer</icon>

					<Name id="9054617740438863749">Server-1</Name>
					<IPAddress id="7097063150098853561">192.168.1.2</IPAddress>
				</Server>
		</Offsprings>
	</Node>
	<Node id="os" type="OS">
			<template alias="OS" id="1550264688322738908" displayName="${Name} ${Version} (on ${InstalledOn})" created="2009-02-20T09:56:52.461" lastModified="2009-02-20T09:57:15.830">
				<derivedFrom>

					<ref alias="Software"/>
				</derivedFrom>
				<description>This CI defines an Operating System. The OS is installed on a System.</description>
				<attribute attAlias="Family" displayName="OS Family" derived="false" id="-7182725288778467473">
					<simpleType>xs:string</simpleType>
					<policy>
						<maxOccurs>1</maxOccurs>

						<minOccurs>1</minOccurs>
					</policy>
				</attribute>
				<attribute attAlias="Service" displayName="Service" derived="true" id="909277383647389050">
					<complexType>
						<ref alias="Service"/>
						<refType><ref alias="BelongsTo"/></refType>
					</complexType>

					<policy>
						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>
					</policy>
				</attribute>
				<attribute attAlias="Maintenance" displayName="Maintenance Info" derived="true" id="8915745697131428160">
					<complexType>
						<ref alias="Maintenance"/>

						<refType><ref alias="PointsTo"/></refType>
					</complexType>
					<policy>
						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>
					</policy>
				</attribute>
				<attribute attAlias="Version" displayName="Version" derived="true" id="1010235024601151869">

					<simpleType>xs:string</simpleType>
					<policy>
						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>
					</policy>
				</attribute>
				<attribute attAlias="InstalledOn" displayName="Installed On" derived="false" id="-5618129852733072561">

					<complexType>
						<ref alias="System"/>
						<refType><ref alias="InstalledOn"/></refType>
					</complexType>
					<policy>
						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>
					</policy>

				</attribute>
				<attribute attAlias="Name" displayName="Name" derived="true" id="-5100631602909667004">
					<simpleType>xs:string</simpleType>
					<policy>
						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>
					</policy>

				</attribute>
				<attribute attAlias="LicenseKey" displayName="License Key" derived="true" id="-2352201440659426885">
					<simpleType>xs:string</simpleType>
					<policy>
						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>
					</policy>

				</attribute>
				<attribute attAlias="DSLEntry" displayName="DSL Entry" derived="true" id="7005495293072869270">
					<simpleType>xs:anyURI</simpleType>
					<policy>
						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>
					</policy>

				</attribute>
				<attribute attAlias="type" displayName="Type" derived="true" id="-1673884082628696233">
					<simpleType>xs:string</simpleType>
					<policy>
						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>
					</policy>

				</attribute>
				<attribute attAlias="Financial" displayName="Financial Info" derived="true" id="3562485879534836585">
					<complexType>
						<ref alias="Financial"/>
						<refType><ref alias="PointsTo"/></refType>
					</complexType>
					<policy>
						<maxOccurs>1</maxOccurs>

						<minOccurs>1</minOccurs>
					</policy>
				</attribute>
				<attribute attAlias="icon" displayName="Icon" derived="true" id="3643547014002026039">
					<description>Filename (no file extension) of icon image.</description>
					<simpleType>xs:string</simpleType>
					<policy>

						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>
					</policy>
				</attribute>
		<setSimpleValue attAlias="Name" id="6043654632345676934">OS</setSimpleValue>
		<setSimpleValue attAlias="icon" id="-4070924605936333213">os</setSimpleValue>
			</template>

		<Offsprings totalCount="-1">
				<Vista alias="Linux1235140256386" id="6511231821654831789" displayName="${Name} ${Version} (on ${InstalledOn})" created="2009-02-20T14:31:43.279" lastModified="2009-02-20T14:39:17.703" displayValue="Vista 12-23-23-23 Vista SP1 (on Server-2 192.168.1.3)">
					Vista 12-23-23-23 Vista SP1 (on Server-2 192.168.1.3)
					<description>This CI defines a Windows Vista Operating System. The OS is installed on a System.</description>
					<Family id="-423179391843078901">Windows</Family>
					<Version id="-2589702871642488351">Vista SP1</Version>
					<icon id="8389918497939484690">windows_vista</icon>

					<InstalledOn id="3414627840301061375"><ref alias="Server1235140235014"/></InstalledOn>
					<Name id="-5967618150841602849">Vista 12-23-23-23</Name>
					<DSLEntry id="-4259576344594506509">http://www.onecmdb.org/docs/BasicDatacenter/DSL/Dummy_OS_Package.txt</DSLEntry>
				</Vista>
				<Linux alias="Linux1235136742592" id="-1734321206646869776" displayName="${Name} ${Version} (on ${InstalledOn})" created="2009-02-20T13:32:23.064" lastModified="2009-02-20T14:31:43.404" displayValue="Red Hat Linux CentOS 4 (on Server-1 192.168.1.2)">
					Red Hat Linux CentOS 4 (on Server-1 192.168.1.2)
					<description>This CI defines an Linux Operating System. The OS is installed on a System.</description>
					<Family id="-2923656087883528171">Linux</Family>

					<Version id="-8328019824579720715">CentOS 4</Version>
					<icon id="-3209264809147918475">linux</icon>
					<InstalledOn id="5440758284085809800"><ref alias="Server1235136691508"/></InstalledOn>
					<Name id="-5710292546045663087">Red Hat Linux</Name>
				</Linux>
		</Offsprings>
	</Node>

	</Nodes>
	<Edges>
	<Edge id="os2system" type="InstalledOn">
			<template alias="InstalledOn" id="-1006816011846020382" displayName="${source} installed on ${target}" created="2009-02-20T09:56:52.430" lastModified="2009-02-20T09:56:52.430">
				<derivedFrom>
					<ref alias="DependsOn"/>
				</derivedFrom>
				<description>Reference describes that the source is installed on the target.</description>

				<attribute attAlias="target" displayName="Target" derived="true" id="-7414601453516701457">
					<description>The target of this reference</description>
					<complexType>
						<ref alias="Root"/>
					</complexType>
					<policy>
						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>

					</policy>
				</attribute>
				<attribute attAlias="source" displayName="Source" derived="true" id="-1887940032442927370">
					<description>The source of this reference</description>
					<complexType>
						<ref alias="Root"/>
					</complexType>
					<policy>

						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>
					</policy>
				</attribute>
				<attribute attAlias="icon" displayName="Icon" derived="true" id="3643547014002026039">
					<description>Filename (no file extension) of icon image.</description>
					<simpleType>xs:string</simpleType>

					<policy>
						<maxOccurs>1</maxOccurs>
						<minOccurs>1</minOccurs>
					</policy>
				</attribute>
		<setSimpleValue attAlias="icon" id="-5479133687379398917">reference</setSimpleValue>
			</template>

		<Offsprings totalCount="-1">
				<InstalledOn alias="InstalledOn-e691f94fca5dcf99" id="-1832409452270202983" displayName="${source} installed on ${target}" created="2009-02-20T14:31:43.357" lastModified="2009-02-20T14:31:43.357" displayValue="Vista 12-23-23-23 Vista SP1 (on Server-2 192.168.1.3) installed on Server-2 192.168.1.3">
					Vista 12-23-23-23 Vista SP1 (on Server-2 192.168.1.3) installed on Server-2 192.168.1.3
					<description>Reference describes that the source is installed on the target.</description>
					<icon id="-89745764215687412">reference</icon>
					<target id="8306236105688124921"><ref alias="Server1235140235014"/></target>
					<source id="2966627667351814671"><ref alias="Linux1235140256386"/></source>
				</InstalledOn>

				<InstalledOn alias="InstalledOn-76c496f2fc71b8ed" id="8558131162272348397" displayName="${source} installed on ${target}" created="2009-02-20T13:32:23.086" lastModified="2009-02-20T13:32:23.086" displayValue="Red Hat Linux CentOS 4 (on Server-1 192.168.1.2) installed on Server-1 192.168.1.2">
					Red Hat Linux CentOS 4 (on Server-1 192.168.1.2) installed on Server-1 192.168.1.2
					<description>Reference describes that the source is installed on the target.</description>
					<target id="602122949767499345"><ref alias="Server1235136691508"/></target>
					<icon id="6678424966705800989">reference</icon>
					<source id="-4812105171859237682"><ref alias="Linux1235136742592"/></source>
				</InstalledOn>
		</Offsprings>

	</Edge>
	</Edges>

</OneCMDBGraph>

3.3 OneCMDB

<?xml version="1.0" encoding="UTF-8"?>
<onecmdb>
<templates>
</templates>
<instances>
	<Laptop alias="Server1235140235014" id="6466729608999320056" displayName="${Name} ${IPAddress}" created="2009-02-20T14:30:48.991" lastModified="2009-02-20T14:34:27.204" displayValue="Server-2 192.168.1.3">
		Server-2 192.168.1.3
		<description>This CI specifies one laptop computer system. A laptop computer system can may not be located in one place.Is owned by one person at a time.</description>
		<icon id="-2478114294188147891">computer</icon>
		<Name id="-5321727766033555871">Server-2</Name>

		<IPAddress id="991434085522247207">192.168.1.3</IPAddress>
	</Laptop>
	<Server alias="Server1235136691508" id="-5594175356767968185" displayName="${Name} ${IPAddress}" created="2009-02-20T13:31:41.251" lastModified="2009-02-20T13:31:55.647" displayValue="Server-1 192.168.1.2">
		Server-1 192.168.1.2
		<description>This CI specifies one server computer system. A Server Computer System is used to host server applications.</description>
		<icon id="-5476264572729428563">computer</icon>
		<Name id="9054617740438863749">Server-1</Name>

		<IPAddress id="7097063150098853561">192.168.1.2</IPAddress>
	</Server>
	<Vista alias="Linux1235140256386" id="6511231821654831789" displayName="${Name} ${Version} (on ${InstalledOn})" created="2009-02-20T14:31:43.279" lastModified="2009-02-20T14:39:17.703" displayValue="Vista 12-23-23-23 Vista SP1 (on Server-2 192.168.1.3)">
		Vista 12-23-23-23 Vista SP1 (on Server-2 192.168.1.3)
		<description>This CI defines a Windows Vista Operating System. The OS is installed on a System.</description>
		<Family id="-423179391843078901">Windows</Family>
		<Version id="-2589702871642488351">Vista SP1</Version>

		<icon id="8389918497939484690">windows_vista</icon>
		<InstalledOn id="3414627840301061375"><ref alias="Server1235140235014"/></InstalledOn>
		<Name id="-5967618150841602849">Vista 12-23-23-23</Name>
		<DSLEntry id="-4259576344594506509">http://www.onecmdb.org/docs/BasicDatacenter/DSL/Dummy_OS_Package.txt</DSLEntry>
	</Vista>
	<Linux alias="Linux1235136742592" id="-1734321206646869776" displayName="${Name} ${Version} (on ${InstalledOn})" created="2009-02-20T13:32:23.064" lastModified="2009-02-20T14:31:43.404" displayValue="Red Hat Linux CentOS 4 (on Server-1 192.168.1.2)">
		Red Hat Linux CentOS 4 (on Server-1 192.168.1.2)
		<description>This CI defines an Linux Operating System. The OS is installed on a System.</description>

		<Family id="-2923656087883528171">Linux</Family>
		<Version id="-8328019824579720715">CentOS 4</Version>
		<icon id="-3209264809147918475">linux</icon>
		<InstalledOn id="5440758284085809800"><ref alias="Server1235136691508"/></InstalledOn>
		<Name id="-5710292546045663087">Red Hat Linux</Name>
	</Linux>
</instances>
</onecmdb>

原文见:http://www.onecmdb.org/wiki/index.php?title=OneCMDB_Query,由OneCMDB中文站翻译,完成于2010年01月09日。

目录

HTTP API V2.0

1. 概述

要开始和OneCMDB互动最简单的方式使用HTTP API,它是基于API的URL,所有的操作都可以通过URL执行。为了对本手册中的模型和概念有所理解,请先阅读OneCMDB 概念(本站翻译文章:[译]OneCMDB 概念)。

使用基本模型和演示实例数据的完整PHP范例,请参考:HTTP API – PHP Exmaple

2. 命令

下面的命令可用:

  • auth
    • 验证用户。其结果将是一个令牌,该令牌将和其他命令一起使用。
  • query
    • OneCMDB中获取数据,它是一个只读操作。
  • update
  • create
  • delete

访问服务的URL格式如下:

http://host:port/onecmdb/remote/http/cmd?option1&option2…&optionN

3. XPath – XML路径语言

HTTP API 使用XPath语言来定位对象。XPath是一种查询XML文档的W3C标准。有关XPath的更多信息请参见 http://en.wikipedia.org/wiki/XPath (译者注:中文版请参见http://zh.wikipedia.org/wiki/XPath)。有关路径参数请参阅下面XPath语法示例。

4. 认证命令

如果OneCMDB启用了认证,则认证命令必须首先被执行。所有后续查询/更新/删除命令都需要这个返回的令牌。参数如下:

  • user=’username’
    • 登录的用户名。
  • pwd=’password’
    • 用户名对应的密码。

请求范例:

	http://localhost:8080/remote/http/auth?user=admin&pwd=123

应答:

	X6g4

5. 查询命令

参数:

  • auth=’令牌’
    • 之前认证命令收到的令牌。
  • path=’XPath 表达式’
    • 过滤接收到的对象。
  • ouputAttributes=’expr1 expr2 … exprN’
    • 一组XPath表达式设置从路径参数中获取到的对象返回指定的属性。如果省略将返回对象的 displayName 属性,如果需要使用所有属性则可使用*。
      • 内部属性有
        • alias
        • id
        • derivedFrom
        • description
        • created (Available in patch)
        • lastModified (Available in patch)
        • displayName
        • displayNameExpression
  • outputFormat=’property|csv|xml’
    • 应答内容如何格式化。

示例如下。

5.1 列出所有路由器

请求:

http://localhost:8080/remote/http/query?auth=x6g4&path=/instance/Router/*&outputFormat=xml

按XML格式响应:

<?xml version="1.0" encoding="UTF-8"?>
<onecmdb>
        <instances>
                <Router alias="R1">
                        Router 192.168.1.1 at Site Danderyd
                </Router>
                <Router alias="R2">
                        Router 192.168.1.2 at Site Solna
                </Router>
        </instances>
</onecmdb>

返回值是每个路由器经过计算的显示名称。

5.2 查找包含特定别名的路由器

请求:

http://localhost:8080/remote/http/query?auth=x6g4&path=/instance/Router/R1&outputFormat=xml

按XML格式响应:

<?xml version="1.0" encoding="UTF-8"?>
<onecmdb>
        <instances>
                <Router alias="R1">
                        Router 192.168.1.1 at Site Danderyd
                </Router>
        </instances>
</onecmdb>

5.3 列出所有路由器 primaryIp 和 site 属性,按csv格式返回结果

请求:

http://localhost:8080/remote/http/query?
auth=x6g4&
path=/instance/Router/*&
outputAttributes=primaryIp%20site/name&
outputFormat=csv

按CSV格式响应:

/instance/Router/*/primaryIp;/instances/Router/*/site/name
192.168.1.1;Solna
192.168.1.2;Danderyd

5.4 根据primaryIp值查找路由器,按csv格式返回结果

请求:

http://localhost:8080/remote/http/query?
auth=x6g4&
path=/instance/Router/*[primaryIp/asString='192.168.1.1’]&
outputAttributes=primaryIp%20site/name&
outputFormat=csv

按CSV格式响应:

/instance/Router/*/primaryIp;/instances/Router/*/site/name
192.168.1.1;Solna

5.5 获取某个人负责的路由器IP地址

请求:

http://localhost:8080/remote/http/query?
auth=x6g4&
path=/instance/Router/*[site/supervisor/name=”Sven”]&
outputAttributes=primaryIp site/supervisor/name&
outputFormat=xml

按XML格式响应:

<?xml version="1.0" encoding="UTF-8"?>
<onecmdb>
        <instances>
                <Site alias="S1">
                        Site Danderyd
                        <supervisor><ref alias="Anna"/></supervisor>
                        <supervisor><ref alias="Sven"/></supervisor>
                </Site>
                <Person alias="Anna">
                        Person Anna Svensson
                        <name>Anna Svensson</name>
                </Person>
                <Person alias="Sven">
                        Person Sven Svensson
                        <name>Sven Svensson</name>
                </Person>
                <Router alias="R1">
                        Router 192.168.1.1 at Site Danderyd
                        <site><ref alias="S1"/></site>
                        <primaryIp>192.168.1.1</primaryIp>
                </Router>
        </instances>
</onecmdb>

按property格式响应:

Router.R1.primaryIp=192.168.1.1
Router.R1.site.supervisor.name[0]=Anna Svensson
Router.R1.site.supervisor.name[1]=Sven Svensson

按CSV格式响应:

/instance/Router/*[site/supervisor/alias="Sven"]/primaryIp;/instance/Router/*[site/supervisor/alias="Sven"]/site/supervisor/name
192.168.1.1;Anna Svensson,Sven Svensson

6. 更新命令

  • Auth=’令牌’
    • 之前认证命令收到的令牌。
  • Path=’XPath 表达式’
    • 过滤接收到的对象。
  • InputAttributes=’attribute=value;… ;attributeN=valueN’
    • 一组属性和值,用分号(’;')分隔。

示例如下。

6.1 修改 Sven 的个人电话号码

请求:

http://localhost:8080/remote/http/update?
auth=x6g4&
path=/instance/Person/Sven&
inputAttributes=telephone=070-657388576&

响应:

如果正常,HTTP 状态值为 200

如果对象不存在,HTTP 状态值为 404

6.2 连接到某个路由器实例到特定站点且该站点为某个人负责

请求:

http://localhost:8080/remote/http/update?
Auth=x6g4&
Path=/instance/Router/R1&
InputAttributes=site=[/instance/Site/S1];site/supervisor=[/instance/People/Sven]&

7. 创建命令

  • Auth=’令牌’
    • 之前认证命令收到的令牌。
  • Path=’XPath 表达式’
    • 一个不存在的新路径。
  • InputAttributes=’attribute=value; … ;attributeN=valueN’
    • 一组属性和值,用分号(’;')分隔。

7.1 新建一个人员实例

注意:路径中指定的别名叫做 Peter 的人员将被创建。这个别名必须是唯一,如果不是将会返回一个错误。请求:

http://localhost:8080/remote/http/create?
Auth=x6g4
Path=/instance/Person/Peter
InputAttributes=name=Peter Svensson;email=peter@acme.com&

8. 删除命令

  • auth=’令牌’
    • 之前认证命令收到的令牌。
  • path
    • 要删除的对象的路径。

示例如下。

8.1 从OneCMDB中删除 Sven 这个人

请求:

http://localhost:8080/remote/http/delete?
Auth=x6g4&
Path=/instance/People/Sven

原文见:http://www.onecmdb.org/wiki/index.php?title=OneCMDB_HTTP_API_V2.0,由OneCMDB中文站翻译,完成于2010年01月09日。

OneCMDB 提供了一些Java接口,这些接口不是供远程访问使用的。我们打算发布语言独立的远程访问API

目录

1. 设置

OneCMDB Core使用Spring框架启动和实例化核心对象。下面的xml bean定义文件控制OneCMDB怎样被启动。 

  • Datasource.xml 定义使用的后台数据。
  • Provider.xml 定义加载的缺省模型。
  • Onecmdb.xml 定义下面描述的核心接口。

TODO: 描述jar包依赖关系。

2. OneCMDB概述

Image:ApiOverview.png

2.1 上下文

Image:ApiContextClassDiagram.png

Onecmdb.xml 定义了这个IOneCmdbContext。这个上下文配置了一些服务对象,这些服务对象用来管理模型对象。从上下文中检索服务的方式是通过创建一个Isession对象并使用通过认证的凭据,目前还没有定义验证模块,因此任何用户名密码都可以访问。

2.2 服务

Image:ApiIModelClassDiagram.png
OneCMDB服务增强了OneCMDB核心的功能。 以下各节描述了现有的服务。

2.2.1 IModelService

查询模型,获取Root模型对象。

2.2.2 ICcb

控制模型的修改。

2.2.3 IReferenceService

定义模型对象之间的引用类型对象。

2.2.4 IPolicyService

定义策略。

2.2.5 ICiService

获取CI模型对象的引用。

2.2.6 IContainerService

[当前没有使用]
增加了对容器对象的支持。

2.2.7 IJobService

增加了运行中OneCMDB处理调度任务的支持。

2.3 模型 – 配置项

Image:ApiICiClassDiagram.png

配置项是OneCMDB的核心部分。配置项按照等级次序组织,这意味着所有配置项有且仅有一个Root对象。

3. 代码范例

3.1 开始使用

	// 指定OneCMDB Spring bean的定义文件
	String[] resources = {"onecmdb.xml"};
	ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(resources);

	// 获取OneCMDB上下文
	final IOneCmdbContext cmdb = (IOneCmdbContext) appContext.getBean("onecmdb");

	// 说明你是谁
	ISession session = cmdb.createSession("some_user", "mypassword");

	// 该Session包含的所有服务的引用。
	IModelService modelsvc = (IModelService) session.getService(IModelService.class);

3.2 查找 Root 模型对象

        // 使用模型服务查询模型
	ModelService modelsvc = (IModelService) session.getService(IModelService.class);

        // 取得Root模型对象
	ICI root = modelsvc.getRoot();

	// 取得它的后代
	Set<ICI> offsprings = root.getOffsprings();

	// 打印出来
	for (ICi ci: offsprings) {
		System.out.println(“-->ci.getDisplayName()”);
	}

3.3 查询对象模型

	// 查找特定别名的CI,不支持表达式
	ICi ci = modelsvc.findCi(new Path<String>("IP"));
	if (ci == null) {
		System.out.println("No ci with alias name IP found!");
		return;
	}

	// 查新IP配置项的后代并分页
	QueryCriteria criteria = new QueryCriteria();

	// 设置模板ID
	criteria.setOffspringOfId(ci.getId());

	// 设置前10条
	criteria.setFirstResult(0);
	criteria.setMaxResult(10);
	QueryResult<ICi> result = modelsvc.query(criteria);

	// 设置下一页
	criteria.setFirstResult(10);
	criteria.setMaxResult(10);
	result = modelsvc.query(criteria);

3.4 修改模型

	ISession session = new Setup().getSession("user", "passwd");
	ICcb ccb = (ICcb) session.getService(ICcb.class);
	IModelService modelSvc = (IModelService)session.getService(IModelService.class);

	// 查找模板配置项
	ICi ci = modelSvc.findCi(new Path<String>("IP"));

	// 从一个IP模板创建一个实例
	ICmdbTransaction tx = ccb.getTx(session);
	{
		ICiModifiable rootTemplate = tx.getTemplate(ci);
		ICiModifiable ipTemplate = rootTemplate.createOffspring();

		// 注意: 这个方法应该被命名为setTemplate(boolean);
		ipTemplate.setIsBlueprint(false);

		// 设置IpAddress属性,它是一个简单属性
		ipTemplate.setDerivedAttributeValue("ipAddress",
					0, SimpleTypeFactory.STRING.parseString("192.168.1.1"));
	}

	// 所有的修改都是异步执行
	ITicket ticket = ccb.submitTx(tx);

	// 等待完成
	IRfcResult result = ccb.waitForTx(ticket);

	// 检查结果
	if (result.isRejected()) {
		System.out.println("Request was rejected, cause " + result.getRejectCause());
		return;
	}

	// 问题: 结果不包含新近创建的ICi任何信息
	// 这个问题是因为事务可以包含多余一个修改。
	System.out.println("Instance added ok.");

原文见:http://www.onecmdb.org/wiki/index.php?title=OneCMDB_Core_Java_API_V2.0,由OneCMDB中文站翻译,完成于2010年01月08日。

OneCMDB Desktop:

OneCMDB Desktop的开始菜单:

Image:V2_startmenu.jpg

OneCMDB Desktop中模型概述:

OneCMDB Desktop中模型导入:

OneCMDB Desktop中CMDB内容表格展现视图:

OneCMDB Desktop中自定义视图:

原文见:http://www.onecmdb.org/wiki/index.php?title=Screenshots,由OneCMDB中文站翻译,完成于2010年01月04日。

OneCMDB 多用户版

OneCMDB 多用户版包含在工作站或者服务器上运行OneCMDB所有内容。它捆绑了最新版本的OneCMDB Core和OneCMDB Desktop,以及一个嵌入式数据库(HSQLDB)、一个Web服务器(Apache Tomcat servlet container)、一个网络发现工具(network mapper:nmap)。一个自动化安装程序完成所有组件运行需要的配置。

支持操作系统:Win32、Windows 2000、XP 和Vista 以及 Linux。
我们以后可能提供其他操作系统安装包,如果你需要特定平台上的OneCMDB请毫不犹豫地联系我们。

安装详细信息:在Windows上安装需要管理员权限。

获取OneCMDB

OneCMDB 可以从SourceForge 主机下载:http://sourceforge.net/project/showfiles.php?group_id=176340

原文见:http://www.onecmdb.org/wiki/index.php?title=Downloads,由OneCMDB中文站翻译,完成于2010年01月04日。

后台数据库中包含四个表。

  1. CI 和ATTRIBUTE – 存储所有有关配置项当前状态和属性信息。
  2. CMDBX 和RFC – 存储所有历史信息。

CI 和 ATTRIBUTE 表结构

OneCMDB-DBModel-CI-ATTRIBUTE

CMDBTX 和 RFC 表结构

RFC表用于hibernate中每个子类映射继承的辨别标志discriminator )。这个辨别标志(discriminator )值作为每个RFC子类的类名显示。每个类型的有效列在该类中描述。

一个CI的更改过程如下:

  • 比较一下当前CI和RFC中生成的修改。所有RFC被打包在一起形成一个CMDBTX对象,该CMDBTX对象存储了谁做出的改变的信息。
  • CCB服务可以通过使用RFC辅助功能根据RFC信息执行变更。在这些辅助功能中,策略可以被加载用于拒绝变更。如果同一个CMDBTX中变更中任何一个变更被拒绝,整个CMDBTX也会被拒绝。(译者注:原文中RFC Workers,本处将worker翻译成辅助功能)
  • 所有通过RFC辅助功能的变更对象将被送到后端数据库存储起来,所有RFC信息也被存储起来。

OneCMDB_DBModel-TX-RFC

原文见:http://www.onecmdb.org/wiki/index.php?title=Database_Schema,由OneCMDB中文站翻译,完成于2010年01月04日。

目录

1. OneCMDB – XML模型定义

所有导入OneCMDB的数据必须按照下面的方式组织:

<onecmdb>
	<templates>
		<template alias="...">
			...
		</template>
	</templates>
	<instances>
  		...
	</instances>
</onecmdb>

文件可以包含模板定义和实例。

2. 模板

在XML文件中模板通过别名来识别,他必须包含一个派生自(父亲)定义。

<template alias="Server" displayName="Server ${Name}">
	<derivedFrom>
		<ref alias="Hardware"/>
	</derivedFrom>
	<description>Description for this template. Will be inherited to the instances.</description>
</template>

这样定义一个新模板,它派生自Hardware叫做Server

2.1 显示名称

模板的一个特点是可以给所有的实例定义一个显示名称。显示名称的目的是在差不多一行内描述一个实例,不采用一个叫名称的属性,而使用一个或者多个属性的值作为显示名称,表达如下:

Server ${Name} belongs to service {$Service.Name}

这将显示一个服务器实例像Server xxxx belongs to service yyyyy。${xxx}用于指出它将被别名叫做xxx的属性对应的实际值替换,如果一个属性时复合属性则可以附加’.'而遍历到具体的引用。因此${Service.Name} 将从Service实例中取得Name 属性的值。程序并不限制’.'的使用数量。

2.2 定义简单属性

<template alias="Server">
	<derivedFrom>
		<ref alias="Hardware"/>
	</derivedFrom>
	<attribute attAlias="Name" displayName="Name">
		<description>Description of this attribute</description>
		<simpleType>xs:string</simpleType>
		<policy>
			<maxOccurs>1</maxOccurs>
			<minOccurs>1</minOccurs>
		</policy>
	</attribute>
</template>

在这里,我们定义了一个叫做“Name”的属性,它可以包含一个简单类型xs:string的值。

复合属性和简单属性都有多样性,若要指定无穷大将maxOccurs 设置为-1或者unbound。简单属性只支持简单的类型(这符合XML的原始数据类型,参考[1]了解值必须如何格式化):

  • xs:string
  • xs:integer
  • xs:nonNegativeShort
  • xs:anyURI
  • xs:float
  • xs:boolean
  • xs:password
  • xs:duration
  • xs:dateTime
  • xs:time
  • xs:date

注意:OneCMDB有一个内部限制:一个值只能包含1024字节。(译者注:最多只能包含1024个字节,共计341个汉字)

2.3 定义复合属性

复合属性包含到另一个实例的引用。每个引用也是一个类型,因此,一个复合类型和一个引用类型需要指定。

<template alias="Server">
	<derivedFrom>
		<ref alias="Hardware"/>
	</derivedFrom>

	<attribute attAlias="Service" displayName="Service">
		<complexType>
			<ref alias="Service"/>
			<refType><ref alias="BelongsTo"/></refType>
		</complexType>
		<policy>
			<minOccurs>0</minOccurs>
			<maxOccurs>unbound</maxOccurs>
		</policy>
	</attribute>
</template>

这定义了一个属性,它引用(属于)零个或多个Service实例。

注意:所有从一个Service派生的子孙的实例都可以被选中

2.4 设置属性缺省值

A模板可以给每个属性定义一个缺省值,像这样既可:

<template alias="Server">
	<derivedFrom>
		<ref alias="Hardware"/>
	</derivedFrom>
	...
	<setSimpleValue attAlias="Name">Server</setSimpleValue>
	<setComplexValue attAlias="Service"><ref alias="service-1"/></setComplexValue>
</template>

3. 实例

实例的定义如下:

...
<instances>
	<Server alias="server-1">
		<Name>ns-server-01</Name>
		<Service><ref alias="service-1"/></Service>
	</Server>

	<Server alias="server-2">
		<Name>ns-server-02</Name>
		<Service><ref alias="service-1"/></Service>
	</Server>

	<Service alias="service-1">
		<Name>Platform Service</Name>
	</Server>
</instances>
...

名称为 <Server alias="server-1"> 的节点指定这个实例从哪个模板派生以及它的别名。别名可用于指定一个属性的引用。实例也包含模板中相当于attrAlias的名称节点。要指定引用使用文本<ref alias="yyyy"/>作为节点。

原文见:http://www.onecmdb.org/wiki/index.php?title=OneCMDB_Model_File,由OneCMDB中文站翻译,完成于2010年01月03日。