...
When a script is called as a condition, it needs to return a value - either true or false depending if the condition matches or not.
Configuration - JSON Structure
Alerts are stored as JSON configuration, in Ceptor's configuration as a property named "alerts_JSON_" in the abstract server configuration named "alerts" (the Ceptor Console will create it for you if it does not already exists - but if you need to change it using APIs, you need to know the naming).
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
{"actions": [
{
"name": "Log the alert",
"type": "log",
"conditions": [],
"level": "WARN"
},
{
"name": "Alert Administrator",
"type": "sms",
"conditions": [],
"mobile": "+4526164023"
},
{
"name": "Send email to admin",
"type": "email",
"conditions": [],
"email": "kr@asseco.dk",
"email.prefix": "[Alert !!!]"
},
{
"name": "Create an action",
"type": "log",
"conditions": [{
"name": "Only server down",
"type": "server_down"
}],
"logger": "alerts",
"level": "ERROR"
},
{
"name": "Run a script",
"type": "script",
"conditions": [],
"script": "%{script}//\r\n// Example javascript that simply writes both the configuration and alerts to stdout\r\n//\r\n\r\nprint(context.configuration);\r\nprint(context.alert.getType());\r\nprint(context.alert.getID());\r\nprint(context.alert.getTitle() + ' - ' + context.alert.getMessage());\r\nprint(context.alert.toJSONString());"
}
]} |
The "alerts_JSON_" property contains a JSON array called "actions", and each action looks like this:
...
Type of action, must be one of:
- sms
- console
- log
- script
...
For conditions, each condition is a JSON object within the conditions array in an Alert Action
...
Type of alert to match, one of:
- certificateexpires_soon
- certificate_is_expired
- server_down
- server_up
...
Configuration - Properties
In order to be able to send emails / SMS messages, some configuration is required - this configuration must be set for the Ceptor Configuration Server which processes the alert actions defined.
Example configuration:
Code Block |
---|
<group name="alerts" description="Alert actions related configuration">
<property name="mail.from" value="" description=""/>
<property name="mail.replyto" value="" description=""/>
<property name="mail.smtp.host" value="" description=""/>
<property name="mail.smtp.password" value="" description=""/>
<property name="mail.smtp.port" value="25" description=""/>
<property name="mail.smtp.protocol" value="smtps" description=""/>
<property name="mail.smtp.user" value="" description=""/>
<property name="sms.apikey" value="" description="For CPSMS, if present, sms.password is not used"/>
<property name="sms.appnr" value="1231" description="For unwire, specify from phone number"/>
<property name="sms.flashsms" value="false" description="If true, SMS is sent as flash SMS"/>
<property name="sms.from" value="Ceptor" description="Max 11 characters from name or number"/>
<property name="sms.httpProxyHost" value="" description="HTTP Proxy Server"/>
<property name="sms.httpProxyPassword" value="" description="HTTP Proxy Password for proxy authentication"/>
<property name="sms.httpProxyPort" value="8080" description="HTTP Proxy Port"/>
<property name="sms.httpProxyUser" value="" description="HTTP Proxy Userid to use for authentication"/>
<property name="sms.mediacode" value="" description="For unwire, specify mediacode"/>
<property name="sms.password" value="" description="Password for SMS gateway"/>
<property name="sms.provider" value="cpsms" description="cpsms or unwire depending on which SMS provider to use (locallogging for logging codes to log file)"/>
<property name="sms.smsc" value="dk.tdc" description="For unwire, specify operator to use"/>
<property name="sms.username" value="portalprotect" description="Username for SMS gateway"/>
<property name="sms.verifysslhostname" value="true" description="Set to false to turn off hostname verification"/>
<property name="sms.verifysslservercert" value="true" description="Set to false to turn SSL server certificate validation"/>
</group> |
Alerts - JSON Structure
Each Alert has its own JSON Structure
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
{
"type": "server_up",
"id": "63ba3e15-0275-4c8b-aa0f-b2340873cc1e",
"title": "Server api.worldbank.org:80 up",
"message": "Server worldbank_sandbox (api.worldbank.org@api.worldbank.org:80) is back up after 42 minutes",
"gateway": "gateway1",
"destination": "worldbank_sandbox",
"host": "api.worldbank.org",
"port": 80,
"duration": 2520512
} |
This is a list of the keys / attributes that the alert can contain:
...
Type of alert, one of:
- certificateexpires_soon
- certificate_is_expired
- server_down
- server_up
...