如果给定的主机在Consul(0.8.5)中处于维护模式,我正在为我们的监控写一个检查。在命令行上非常简单,因为我可以运行consul maint
并获得适当的输出。通过REST,我可以设置维护模式,但似乎无法检索它。
如何在不解析Consul的多行输出的情况下以安全的方式在shell脚本中检查这个?
答案 0 :(得分:1)
您可以通过_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": ""
}
]
的条目。
$objectOne = new stdClass();
$objectOne->statement = "Hello";
$objectTwo = new stdClass();
randomFunctionThatShouldCauseAnError();
$objectTwo->statement = "Error before this";