Enable alerts posted to a URL
About this task
Configure OpsCenter to send alert data to a specified URL that has a page capable of receiving and processing POST data.
For example, a simple PHP script containing print_r($_POST);
echoes the received POST request.
An example POST request with its payload:
POST / HTTP/1.0 Host: localhost User-Agent: Twisted PageGetter Content-Length: 184 Content-type: application/x-www-form-urlencoded connection: close target_node=None&event_source=OpsCenter&success=None&level=1&level_str=INFO&api_source_ip=None&user=None&time=1400098707681966&action=18&message=OpsCenter+starting+up.&source_node=None
The request body contains fields described in Alerts along with the cluster name where applicable. JSON, template, and form URL-encoded content types are supported. To specify the field format and which fields are sent, reference the configuration file for examples of the key-value pair formatting.
Multiple instances of the posturl.conf file result in multiple instances of the event plugin.
You can assign any name to the configuration file, as long as the file has the .conf
file extension, contains the valid event plugin identifier [posturl]
at the top of the file, and resides in the /event-plugins directory location.
All configuration files are loaded, so DataStax recommends that you differentiate the file names.
For example, use incremental names such as posturl1.conf
and posturl2.conf
.
Multiple plugin instances facilitate flexibility when setting up alerts for development and production clusters. All OpsCenter event plugins support multiple configurations files and subsequent plugin instances.
For related information, refer to OpsCenter installation and configuration locations.
OpsCenter can post alerts via http or https. To enable https, update the URL from http:// to https://. |
Prerequisites
-
Make sure your web server and posting script are configured to receive alerts.
-
Locate the
opscenterd.conf
file. The location of this file depends on the type of installation:-
Package installations: /etc/opscenter/opscenterd.conf
-
Tarball installations: install_location/conf/opscenterd.conf
-
-
If your machine is connected behind a proxy, open the
opscenterd.conf
file to edit it and add the following configuration for[http_proxy_settings]
:proxy_url = http://your_proxy:port proxy_username = your_proxy_username proxy_password = your_proxy_password
Procedure
-
Locate the
posturl.conf
file. The location of this file depends on the type of installation:-
Package installations: /etc/opscenter/event-plugins/posturl.conf
-
Tarball installations: installation_location/conf/event-plugins/posturl.conf
-
-
On the OpsCenter daemon host, open the
posturl.conf
file for editing. -
Set
enabled=1
. -
Specify the levels and clusters for which the alert configuration runs if you do not want alerts called for all levels and clusters.
-
Adjust the connection timeout (
connection_timeout
) if the connection to the posturl is taking too long. -
For
url
, provide a valid path to the posting script. -
Optional: To enable alerts to use the
curl
command, setenable_curl
toTrue
. -
Set a username and password for HTTP Basic authentication.
-
Set the type of posted data for
post_type
.Supported options are
form
(default),json
, ortemplate
. You can customize the message using the available key values described in the configuration file comments. -
Save the
posturl.conf
file, and restart the OpsCenter daemon. -
Verify that the events post correctly.
Sample posturl.conf
file
In a system with posting form data enabled for critical and alert-level events for all clusters, the posturl.conf
file appears as follows:
[posturl]
enabled=1
# levels can be a comma-delimited list of any of the following:
# DEBUG,INFO,WARN,ERROR,CRITICAL,ALERT
# If left empty, will listen for all levels
levels=CRITICAL,ALERT
# clusters is a comma-delimited list of cluster names for which
# this alert config will be eligible to run.
# If left empty, this alert will be called for events on all clusters
clusters=
# the URL to send a HTTP POST to
url=http://host/path/to/script
# Set a username for basic HTTP authorization
#username=foo
# Set a password for basic HTTP authorization
#password=bar
# Set the type of posted data. Available options are `form`, `json`, and `template`.
post_type=form
# Fields specified here will override the default event data fields.
#
# They must be formatted as key-value pair, with key and value separated by
# an equals (=). Each pair after the first must be on its own line,
# indented beyond the first line
#
# You may use tokens found within the default event data for or in
# values. For example, some available keys are:
# cluster, time, level_str, message, target_node, event_source, success, api_source_ip, user, source_node
# Keys must be encapsulated in {brackets}.
#
#fields=textKey=value
# mixedKey=cluster-{cluster}
# event-msg={message}
Examples of configuration settings
This example adds a static custom field to the posturl.conf
file by using the fields
prefix.
Specify all of the fields to include:
fields=message={message} message_type=CRITICAL
This example displays form data containing the message and cluster name:
FORM DATA: array ( 'event-msg' => 'OpsCenter starting up.', 'mixedKey' => 'cluster-C1', 'textKey' => 'value', )
This example displays JSON data containing the message and cluster name:
JSON DATA: {{ "event-msg": "OpsCenter starting up.", "mixedKey": "cluster:C1", "textKey": "value" }}
This example displays template data containing the message and cluster name:
TEMPLATE DATA: {{ "event-msg": "OpsCenter starting up.", "mixedKey": "cluster:C1", "textKey": "value" }}