-
Language:
English
-
Language:
English
Red Hat Training
A Red Hat training course is available for Red Hat JBoss Operations Network
9. 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.
9.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)
Note
This method is only available to server-side script used with alerts, not to the interactive CLI or external CLI script files.
9.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:
- Search for fired alerts; in this case, the search is based on the resource type (Linux).
- Retrieve the data for the search results.
- Acknowledge all returned alerts.
Example 23. 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]) } }
9.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:
- Search for matching alert definitions based on priority (low, in this case).
- Retrieve the data for the search results.
- Disable all returned alert definitions, based on the IDs in the retrieved search list.
Example 24. 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]);