Skip to content

Commit

Permalink
Merge pull request airbnb#617 from airbnb/javier-fix-bug-put-json
Browse files Browse the repository at this point in the history
[output] Fix for PUT request bug
  • Loading branch information
jacknagz authored Mar 3, 2018
2 parents 73537e0 + f70c7ca commit e86fab0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion stream_alert/alert_processor/outputs/output_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def _put_request(cls, url, params=None, headers=None, verify=True):
Returns:
dict: Contains the http response object
"""
return requests.put(url, headers=headers, params=params,
return requests.put(url, headers=headers, json=params,
verify=verify, timeout=cls._DEFAULT_REQUEST_TIMEOUT)

@classmethod
Expand Down
16 changes: 9 additions & 7 deletions stream_alert/alert_processor/outputs/pagerduty.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
giveup_handler
)

def events_v2_data(routing_key, **kwargs):
def events_v2_data(routing_key, with_record=True, **kwargs):
"""Helper method to generate the payload to create an event using PagerDuty Events API v2
Keyword Args:
routing_key (str): Routing key for this PagerDuty integration
with_record (boolean): Option to add the record data or not
descriptor (str): Service descriptor (ie: slack channel, pd integration)
rule_name (str): Name of the triggered rule
alert (dict): Alert relevant to the triggered rule
Expand All @@ -43,11 +44,11 @@ def events_v2_data(routing_key, **kwargs):
dict: Contains JSON blob to be used as event
"""
summary = 'StreamAlert Rule Triggered - {}'.format(kwargs['rule_name'])
details = OrderedDict()
details['description'] = kwargs['alert']['rule_description']
if with_record:
details['record'] = kwargs['alert']['record']

details = {
'rule_description': kwargs['alert']['rule_description'],
'record': kwargs['alert']['record']
}
payload = {
'summary': summary,
'source': kwargs['alert']['log_source'],
Expand Down Expand Up @@ -115,7 +116,7 @@ def dispatch(self, **kwargs):
message = 'StreamAlert Rule Triggered - {}'.format(kwargs['rule_name'])
rule_desc = kwargs['alert']['rule_description']
details = {
'rule_description': rule_desc,
'description': rule_desc,
'record': kwargs['alert']['record']
}
data = {
Expand Down Expand Up @@ -650,7 +651,8 @@ def dispatch(self, **kwargs):
incident_id = incident_json.get('incident', {}).get('id')

# Create alert to hold all the incident details
event_data = events_v2_data(creds['integration_key'], **kwargs)
with_record = rule_context.get('with_record', True)
event_data = events_v2_data(creds['integration_key'], with_record, **kwargs)
event = self._create_event(event_data)
if not event:
LOGGER.error('Could not create incident event, %s', self.__service__)
Expand Down

0 comments on commit e86fab0

Please sign in to comment.