Enabling alerts posted to a URL
OpsCenter can send alert data to a specified URL that has a page capable of receiving and processing POST data. JSON, template, and form URL-encoded content types are supported.
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);
will echo 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 results
in multiple instances of the event plugin. The configuration file can have any name
provided the file has the .conf file extension, contains the valid event plugin
identifier [posturl]
, 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 posturl1.conf,
posturl2.conf, and so on. 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 Ops Center installation and configuration locations.
posturl.conf
The location of the posturl.conf file depends on the type of installation:- Package installations: /etc/opscenter/event-plugins/posturl.conf
- Tarball installations: installation_location/conf/event-plugins/posturl.conf
opscenterd.conf
The location of the opscenterd.conf file depends on the type of installation:- Package installations: /etc/opscenter/opscenterd.conf
- Tarball installations: install_location/conf/opscenterd.conf
Prerequisites
- Make sure your web server and posting script are configured to receive alerts.
- If your machine is connected behind a proxy, open
opscenterd.conf for editing and add the
following under
[http_proxy_settings]
:http_proxy_url = http://your_proxy:port http_proxy_username = your_proxy_username http_proxy_password = your_proxy_password
Procedure
- On the OpsCenter daemon host, open posturl.conf for editing.
- Set enabled=1.
- Optional: Specify the levels and clusters for which the alert configuration will run if you do not want alerts called for all levels and clusters.
- Optional:
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. - Set a username and password for HTTP Basic authentication.
-
Set the type of posted data for
post_type
.Supported options areform
(default),json
, ortemplate
. Customize the message using the available key values described in the config file comments. - Save posturl.conf and restart the OpsCenter daemon.
- Verify events are posting correctly.
Example
In a system with posting form data enabled for critical and alert-level events for all clusters, posturl.conf looks like:
[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}
Example
fields
prefix. Specify all of the fields to
include:fields=message={message}
message_type=CRITICAL
Example
Example form data displaying the message and cluster name:
FORM DATA: array (
'event-msg' => 'OpsCenter starting up.',
'mixedKey' => 'cluster-C1',
'textKey' => 'value',
)
Example
JSON DATA:
{{
"event-msg": "OpsCenter starting up.",
"mixedKey": "cluster:C1",
"textKey": "value"
}}
Example
TEMPLATE DATA:
{{
"event-msg": "OpsCenter starting up.",
"mixedKey": "cluster:C1",
"textKey": "value"
}}