28.6. 集群警报配置命令示例

以下连续示例展示了一些基本的报警配置命令,以显示用于创建报警、添加接收者和显示配置的报警的格式。

请注意,虽然您必须在集群中的每个节点上安装警报代理,但您需要仅运行一次 pcs 命令。

以下命令创建了一个简单的报警,为报警添加两个接收者,并显示配置的值。

  • 由于没有指定报警 ID 值,系统会创建 alert 的报警 ID 值。
  • 第一个接收者创建命令指定 rec_value 的接收者。由于这个命令没有指定接收者 ID,因此 alert-recipient 的值被用作接收者 ID。
  • 第二个接收者创建命令指定了 rec_value2 的接收者。此命令为接收者指定 my-recipient 的接收者 ID。
# pcs alert create path=/my/path
# pcs alert recipient add alert value=rec_value
# pcs alert recipient add alert value=rec_value2 id=my-recipient
# pcs alert config
Alerts:
 Alert: alert (path=/my/path)
  Recipients:
   Recipient: alert-recipient (value=rec_value)
   Recipient: my-recipient (value=rec_value2)

以下命令添加第二个报警,以及该报警的接收者。第二个报警的报警 ID 是 my-alert,接收者的值是 my-other-recipient。因为没有指定接收者 ID,系统会提供接收者 ID my-alert-recipient

# pcs alert create id=my-alert path=/path/to/script description=alert_description options option1=value1 opt=val meta timeout=50s timestamp-format="%H%B%S"
# pcs alert recipient add my-alert value=my-other-recipient
# pcs alert
Alerts:
 Alert: alert (path=/my/path)
  Recipients:
   Recipient: alert-recipient (value=rec_value)
   Recipient: my-recipient (value=rec_value2)
 Alert: my-alert (path=/path/to/script)
  Description: alert_description
  Options: opt=val option1=value1
  Meta options: timestamp-format=%H%B%S timeout=50s
  Recipients:
   Recipient: my-alert-recipient (value=my-other-recipient)

以下命令修改报警 my-alert 和接收者 my-alert-recipient 的报警值。

# pcs alert update my-alert options option1=newvalue1 meta timestamp-format="%H%M%S"
# pcs alert recipient update my-alert-recipient options option1=new meta timeout=60s
# pcs alert
Alerts:
 Alert: alert (path=/my/path)
  Recipients:
   Recipient: alert-recipient (value=rec_value)
   Recipient: my-recipient (value=rec_value2)
 Alert: my-alert (path=/path/to/script)
  Description: alert_description
  Options: opt=val option1=newvalue1
  Meta options: timestamp-format=%H%M%S timeout=50s
  Recipients:
   Recipient: my-alert-recipient (value=my-other-recipient)
    Options: option1=new
    Meta options: timeout=60s

以下命令从 alert 中删除接收者 my-alert-recipient

# pcs alert recipient remove my-recipient
# pcs alert
Alerts:
 Alert: alert (path=/my/path)
  Recipients:
   Recipient: alert-recipient (value=rec_value)
 Alert: my-alert (path=/path/to/script)
  Description: alert_description
  Options: opt=val option1=newvalue1
  Meta options: timestamp-format="%M%B%S" timeout=50s
  Recipients:
   Recipient: my-alert-recipient (value=my-other-recipient)
    Options: option1=new
    Meta options: timeout=60s

以下命令将从配置中删除 myalert

# pcs alert remove myalert
# pcs alert
Alerts:
 Alert: alert (path=/my/path)
  Recipients:
   Recipient: alert-recipient (value=rec_value)