此内容没有您所选择的语言版本。

8. Alerts


Alert definitions cannot be created or edited using the CLI, but there are some management tasks that can still be performed. For fired alerts themselves, server-side scripts can be used as alert responses (and the alert referenced as an implicit variable) and the fired alert can be viewed and acknowledged by an administrator. Definitions can be enabled or disabled.

8.1. Using Alerts with Scripts

One possible response to an alert is for the server to automatically run a stored server script (essentially a stored CLI script file).
That server-side alert script can reference the alert object for the triggered alert. The server defines an implicit alert variable, which pulls in the alert information, ID, definition, and other information for the fired alert.
Because the alert method identifies the alert definition, it identifies the resource which triggered the alert. This allows you to create a reusable proxy resource definition in the script that could be applied to any resource which uses that alert script.
For example:
var myResource = ProxyFactory.getResource(alert.alertDefinition.resource.id)
Copy to Clipboard Toggle word wrap

Note

This method is only available to server-side script used with alerts, not to the interactive CLI or external CLI script files.

8.2. Acknowledging Alerts

One common administrative action when an alert is fired is for an administrator to review and then acknowledge the alert, which effectively closes it. This script example acknowledges all of the current alerts for all Linux platform resources.
The criteria for the search can be set to be more restrictive so that only certain alerts or only certain resources are included in the action.
The steps in this script:
  1. Search for fired alerts; in this case, the search is based on the resource type (Linux).
  2. Retrieve the data for the search results.
  3. Acknowledge all returned alerts.

Example 26. Acknowledging Alerts for Platform Resources

// set the criteria and search for the alerts
var criteria = new AlertCriteria() 
criteria.addFilterResourceTypeName('Linux')
var alerts = AlertManager.findAlertsByCriteria(criteria)

// go through the results and then acknowledge the alerts
if( alerts != null ) {
  if( alerts.size() > 1 ) {
     for( i =0; i < alerts.size(); ++i) {
          alert = alerts.get(i);
          AlertManager.acknowledgeAlerts([alert.id])
     }
  }
  else if( alerts.size() == 1 ) {
     alert = alerts.get(0);
     AlertManager.acknowledgeAlerts([alert.id])
  }
}
Copy to Clipboard Toggle word wrap

8.3. Enabling or Disabling Alert Definitions

Alert definitions cannot be created or edited through the CLI, but they can be enabled or disabled.
This example script disables all of the definitions returned in the search. In real life, the criteria for the search are crucial to make sure that only the right definitions are disabled, rather than disabling large blocs of definitions.
The steps in this script:
  1. Search for matching alert definitions based on priority (low, in this case).
  2. Retrieve the data for the search results.
  3. Disable all returned alert definitions, based on the IDs in the retrieved search list.

Example 27. Disabling Alerts Based on Priority

// set the search criteria for the alert definitions with a reasonable filter
var criteria = new AlertDefinitionCriteria()
criteria.addFilterPriority(AlertPriority.LOW)

//search for the alert definitions
alertdefs = AlertDefinitionManager.findAlertDefinitionsByCriteria(criteria)

//get the data from the results
alertdef = alertdefs.get(0);

println("  alert: " + alertdef.id );

//disable the matching alerts, based on ID
AlertDefinitionManager.disableAlertDefinitions([alertdef.id]);
Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat