Class: LogStash::Outputs::OpsGenie
- Inherits:
-
Base
- Object
- Base
- LogStash::Outputs::OpsGenie
- Defined in:
- lib/logstash/outputs/opsgenie.rb
Overview
The OpsGenie output is used to Create, Close, Acknowledge Alerts and Add Note to alerts in OpsGenie. For this output to work, your event must contain “opsgenieAction” field and you must configure apiKey field in configuration.
If opsgenieAction is "create", event must contain "message" field.
For other actions ("close", "acknowledge" or "note"), event must contain "alias" or "alertId" field.
If your event have the following fields (If you use default field names).
Example JSON-encoded event:
{
"message": "alert_message",
"@version": "1",
"@timestamp": "2015-09-22T11:20:00.250Z",
"host": "192.168.1.1",
"opsgenieAction": "create",
"alias": "alert_alias",
"teams": ["teams"],
"recipients": "the-recipients",
"description": "alert_description",
"actions": ["actions"],
"source": "alert_source",
"tags": ["tags"],
"entity": "alert_entity",
"user": "alert_owner",
"note": "additional_alert_note"
"details": [
"extra_prop1:value1",
"extra_prop2:value2"
]
}
An alert with following properties will be created.
{
"message": "alert_message",
"alias": "alert_alias",
"teams": ["teams"],
"description": "alert_description",
"source": "alert_source",
"tags": [
"tags"
],
"recipients": [
"the-recipients"
],
"details": {
"extra_prop1": "value1",
"extra_prop2": "value2"
},
"actions": [
"actions"
],
"entity": "alert_entity",
}
Fields with prefix “Attribute” are the keys of the fields will be extracted from Logstash event. For more information about the api requests and their contents, please refer to Alert API(“www.opsgenie.com/docs/web-api/alert-api”) support doc.
Instance Method Summary collapse
- #executePost(uri, params) ⇒ Object
- #populateAliasOrId(event, params) ⇒ Object
- #receive(event) ⇒ Object
- #register ⇒ Object
Instance Method Details
#executePost(uri, params) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/logstash/outputs/opsgenie.rb', line 155 def executePost(uri, params) if not uri == nil then @logger.info("Executing url #{uri}") url = URI(uri) http = Net::HTTP.new(url.host, url.port) if url.scheme == 'https' http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end request = Net::HTTP::Post.new(url.path) request.body = params.to_json response = http.request(request) body = response.body body = JSON.parse(body) @logger.warn("Executed [#{uri}]. Response:[#{body}]") end end |
#populateAliasOrId(event, params) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/logstash/outputs/opsgenie.rb', line 142 def populateAliasOrId(event, params) alertAlias = event[@aliasAttribute] if event[@aliasAttribute] if alertAlias == nil then alertId = event[@alertIdAttribute] if event[@alertIdAttribute] if !(alertId == nil) then params['alertId'] = alertId; end else params['alias'] = alertAlias end end |
#receive(event) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/logstash/outputs/opsgenie.rb', line 174 def receive(event) return unless output?(event) @logger.info("processing #{event}") opsGenieAction = event[@actionAttribute] if event[@actionAttribute] if opsGenieAction then params = { :apiKey => @apiKey} case opsGenieAction.downcase when "create" uri = "#{@opsGenieBaseUrl}#{@createActionUrl}" params = populateCreateAlertContent(params,event) when "close" uri = "#{@opsGenieBaseUrl}#{@closeActionUrl}" when "acknowledge" uri = "#{@opsGenieBaseUrl}#{@acknowledgeActionUrl}" when "note" uri = "#{@opsGenieBaseUrl}#{@noteActionUrl}" else @logger.warn("Action #{opsGenieAction} does not match any available action, discarding..") return end populateCommonContent(params, event) executePost(uri, params) else @logger.warn("No opsgenie action defined") return end end |
#register ⇒ Object
138 139 |
# File 'lib/logstash/outputs/opsgenie.rb', line 138 def register end |