我正在编写一个检查来检查给定主机是否在 Consul (0.8.5) 中处于维护模式。在命令行上非常简单,因为我可以运行 consul maint 并获得适当的输出。通过REST我可以设置维护模式,但似乎无法检索它。
如何在 shell 脚本中以安全的方式检查这一点,而不解析 Consul 的多行输出?
最佳答案
您可以通过http://localhost:8500/v1/health/node/name_of_node
检查节点是否处于维护状态。如果节点处于维护模式,则输出将包含一个带有检查 ID _node_maintenance
的条目。
$ curl http://localhost:8500/v1/health/node/name_of_node
[
{
"ModifyIndex": 270813,
"CreateIndex": 270813,
"ServiceTags": [],
"Node": "name_of_node",
"CheckID": "_node_maintenance",
"Name": "Node Maintenance Mode",
"Status": "critical",
"Notes": "Maintenance mode is enabled for this node, but no reason was provided. This is a default message.",
"Output": "",
"ServiceID": "",
"ServiceName": ""
}
]
关于shell - 检查主机是否处于 Consul 维护模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48624870/