curl
本节介绍如何使用命令行上
的实用程序从 MySQL Enterprise Monitor 的清单中删除有关资产和资产组的信息
。
从清单中删除资产不会从其安装位置删除或卸载资产。删除过程仅从 MySQL Enterprise Service Manager 的内部记录中删除资产或资产组的所有记录。这使您能够删除受监视但不再使用的集群、拓扑和实例的条目。
在尝试从清单中删除资产或组之前,请确保该资产或组未运行或未安装。
有关库存的更多信息,请参阅 附录 B,管理库存。
本节介绍以下内容:
检索可删除资产信息:如何检查可删除的内容。
列出相关的可删除资产:如何检查相关资产及其状态。
从库存中删除资产:如何删除资产。
请求状态代码:来自各种请求类型的返回代码。
curl 实用程序可用于直接从 MySQL Enterprise Service Manager 的受监控资产清单中请求信息。要检索有关是否可以删除特定资产的信息,检索为 JSON 数组,请使用以下语法执行 curl 请求:
curl -k -v --user username:password
"https://servername:port/v4/inventory/AssetType/AssetID/deletable
在哪里:
username:password
是对 MySQL Enterprise Service Manager 具有管理员访问权限的用户的用户名和密码。servername:port
是 MySQL Enterprise Service Manager 的服务器名和端口号。AssetType
是您要检索的资产信息的类型。有效的资产类型如下:MySQL 实例:
com.mysql.etools.inventory.model.mysql.MysqlServer
MySQL Enterprise Monitor 代理:
com.mysql.etools.inventory.model.agent.Agent
笔记如果代理的状态未知,代理正在运行,或者代理正在监视未计划在同一操作中删除的一个或多个 MySQL 实例,则无法从清单中删除代理。
主持人:
com.mysql.etools.inventory.model.os.Host
笔记如果主机包含未计划在同一操作中删除的代理或 MySQL 实例,则无法从清单中删除主机。
NDB集群:
com.mysql.etools.inventory.model.mysql.cluster.NdbCluster
NDB API 节点:
com.mysql.etools.inventory.model.mysql.cluster.NdbApiNode
笔记删除 NDBAPINode 也会删除服务器。
NDB 数据节点:
com.mysql.etools.inventory.model.mysql.cluster.NdbDataNode
NDB 管理节点:
com.mysql.etools.inventory.model.mysql.cluster.NdbManagementNode
AssetID
是资产类型的唯一字母数字标识符。笔记要查找
AssetID
,请查看特定资产类型的库存页面。有关详细信息,请参阅 附录 B,管理库存。
以下示例检索具有唯一标识符的 MYSQL 实例的信息
c14ee437-a615-11e4-8334-f8b156b72e61
:
在以下示例中,为清楚起见添加了换行符。
curl -k -v --user admin:mysql
"https://localhost:18443/v4/inventory/com.mysql.etools.inventory.model.mysql.MysqlServer/
c14ee437-a615-11e4-8334-f8b156b72e61/deletable"
如果MySQL实例是可删除的,请求返回如下数据,确认该资产类型可以从库存中删除:
"asset" : {
"id" : "c14ee437-a615-11e4-8334-f8b156b72e61",
"assetClass" : "com.mysql.etools.inventory.model.mysql.MysqlServer"
},
"isDeletable" : true,
"treeDeletable" : true,
"problems" : [ ],
"token" : "3b66cd39467791a739e5131a8d6a856b"
在哪里:
asset
:列出请求资产的id和资产类别。isDeletable
:真|假。列出是否可以从清单中删除资产的信息。treeDeletable
:真|假。列出是否可以删除相关资产。problems
:列出无法从库存中删除资产信息的原因。可能的原因是:ACL_FAIL
: 用户没有足够的权限执行该操作。删除资产需要 对Server Group 和 MySQL NDB Cluster的Administer权限 。要从清单中删除资产,用户必须属于具有该权限的角色。
有关详细信息,请参阅 第 22.3 节,“受监控资产权限”。
IS_LIVE
: 代理正在运行。代理正在运行并向服务管理器广播信息。无法从库存中删除正在运行的资产。要从清单中删除资产,您必须先停止或卸载它。UNKNOWN_LIVENESS
: 无法确定代理的状态。此问题可能是由网络问题或某些其他问题(例如停电)导致服务管理器无法联系代理程序引起的。AGENT_HAS_UNRELATED_SERVER
:如果代理正在监视不包含在请求范围内的 MySQL 实例,则无法删除服务器和相关代理。agent
要包含它,您必须通过包含关键字 来扩大相关请求的范围 。OS_HAS_UNRELATED_AGENT
:无法删除包含未计划删除的代理的主机。主机包含一个不包含在请求范围内的代理。agent
要包含它,您必须通过包含关键字 来扩大相关请求的范围。OS_HAS_UNRELATED_SERVER
:无法删除包含未计划删除的 MySQL 实例的主机。主机包含一个不包含在请求范围内的 MySQL 实例。mysqlserver
要包含它,您必须通过包含关键字 来扩大相关请求的范围。
token
:资产状态的唯一字母数字标识符。此令牌可用于 请求,以确认资产状态在请求运行DELETE
时间和请求运行时间之间未发生变化 。deletable
DELETE
该请求还返回一个状态代码,指示请求成功或失败。有关详细信息,请参阅 请求状态代码。
该related
请求使您能够返回与类型字段中定义的主要资产相关的其他资产的数据。例如,使用 related,您可以请求 MySQL 实例和监视它的代理、它所在的主机等的可删除信息。
related
还使您能够通过一个请求从库存中删除多项资产。
related
采用以下值的逗号分隔列表:
agent
:与主要资产相关的任何代理。mysqlserver
:与主要资产相关的任何 MySQL 实例。ndbcluster
:与主要资产相关的任何 NDBCluster。os
:与主要资产相关的任何主机。
请求的语法如下:
curl -k -v --user username:password
"https://servername:port/v4/inventory/AssetType/AssetID/deletable?
related=agent,mysqlserver,ndbcluster,os"
例如,以下请求有关具有 AssetID 的 MySQL 实例
c14ee437-a615-11e4-8334-f8b156b72e61
和监视它的代理的可删除信息:
curl -k -v --user admin:mysql
"https://localhost:18443/v4/inventory/com.mysql.etools.inventory.model.mysql.MysqlServer/
c14ee437-a615-11e4-8334-f8b156b72e61/deletable?related=agent"
返回以下 JSON 数组:
"asset" : {
"id" : "c14ee437-a615-11e4-8334-f8b156b72e61",
"assetClass" : "com.mysql.etools.inventory.model.mysql.MysqlServer"
},
"isDeletable" : true,
"treeDeletable" : false,
"problems" : [ ],
"children" : [ {
"asset" : {
"id" : "b68947f9-39f2-4003-981f-8c9cc7a7409f",
"assetClass" : "com.mysql.etools.inventory.model.agent.Agent"
},
"isDeletable" : false,
"treeDeletable" : false,
"problems" : [ {
"code" : "IS_LIVE",
"description" : "IS_LIVE"
} ]
} ],
"token" : "d0e3607f6029a91a35a9956950908761"
返回的数据显示,虽然MySQL实例是可删除的,但不是treeDeletable
,这意味着它不能在相关中删除DELETE
,因为监控代理仍在运行。
要从 MySQL Enterprise Service Manager 的清单中删除单个资产,请使用以下语法:
在尝试从清单中删除资产或资产组之前,请确保该资产或资产组未运行或未安装。
curl -k -v -X DELETE --header "X-Requested-With:XMLHttpRequest"
--header "If-Match:tokenID"
--user admin:mysql
"https://servername:port/v4/inventory/AssetType/AssetID"
要从 MySQL Enterprise Service Manager 清单中删除相关资产,请使用以下语法:
curl -k -v -X DELETE --header "X-Requested-With:XMLHttpRequest"
--header "If-Match:tokenID"
--user admin:mysql
"https://servername:port/v4/inventory/AssetType/AssetID?
related=agent,mysqlserver,ndbcluster,os"
--header "If-Match:tokenID"
是可选的,仅当您要确认可删除信息仍然准确时才应使用。如果包含 tokenID,并且与可删除请求检索到的值相匹配,则执行 DELETE 操作。
例如,下面显示了一个带有返回数据的可删除请求,其中列出了一个可删除的代理、MySQL 实例、它用于监视的主机以及驻留在同一服务器上的另一个代理:
curl -k -v --user admin:mysql
"https://localhost:18443/v4/inventory/com.mysql.etools.inventory.model.agent.Agent/
d71ff41c-affd-4ebe-966e-395e6f06b5e3/deletable?related=mysqlserver,os,agent"
{
"asset" : {
"id" : "d71ff41c-affd-4ebe-966e-395e6f06b5e3",
"assetClass" : "com.mysql.etools.inventory.model.agent.Agent"
},
"isDeletable" : true,
"treeDeletable" : true,
"problems" : [ ],
"children" : [ {
"asset" : {
"id" : "sid:{S-1-5-21-700548433-2193620149-503502644}",
"assetClass" : "com.mysql.etools.inventory.model.os.Host"
},
"isDeletable" : true,
"treeDeletable" : true,
"problems" : [ ],
"children" : [ {
"asset" : {
"id" : "b68947f9-39f2-4003-981f-8c9cc7a7409f",
"assetClass" : "com.mysql.etools.inventory.model.agent.Agent"
},
"isDeletable" : true,
"treeDeletable" : true,
"problems" : [ ],
"children" : [ {
"asset" : {
"id" : "c14ee437-a615-11e4-8334-f8b156b72e61",
"assetClass" : "com.mysql.etools.inventory.model.mysql.MysqlServer"
},
"isDeletable" : true,
"treeDeletable" : true,
"problems" : [ ]
} ]
} ]
} ],
"token" : "7048b6e53c81f549b55c5f3e861c2eee"
The following example shows a related DELETE request, deleting all assets listed as deletable in the deletable example:
curl -k -v -X DELETE --header "X-Requested-With:XMLHttpRequest"
--user admin:mysql "https://localhost:18443/v4/inventory/com.mysql.etools.inventory.model.agent.Agent/
d71ff41c-affd-4ebe-966e-395e6f06b5e3?related=mysqlserver,os,agent"
It is not currently possible to delete an entire replication
topology, unlike NDB Cluster, which can be deleted using the
com.mysql.etools.inventory.model.mysql.cluster.NdbCluster
Asset type.
To delete the assets involved in a replication topology, you
must delete each individually, or use a
related
request type where possible.
The status code can be found in the following section of the return message, following the HTTP/1.1:
HTTP/1.1 200
Set-Cookie: JSESSIONID=8C0C2E1AFD45F170E7E41621F934723D; Path=/; Secure; HttpOnly
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Content-Type-Options: nosniff
Content-Type: application/json
Transfer-Encoding: chunked
Date: Tue, 24 Jul 2018 12:31:47 GMT
The following status codes are returned for
deletable
and DELETE
requests:
200
: 删除请求成功。内容以 JSON 数组形式返回。204
: 删除请求成功。不返回任何内容。400
: 请求无效。检查资产信息或请求的语法是否有错误、拼写错误等。403
: (DELETE
仅请求)X-Requested-With
标题不存在。404
: 提供的 AssetID 不正确。409
: 无法执行 DELETE 请求。JSON 数组中提供了更多信息。412
: 请求的令牌检查失败。