Skip to content

Commit

Permalink
Removed Python 2.6 support
Browse files Browse the repository at this point in the history
* Migrated flake8 settings from tox.ini to setup.cfg
* Moved dependencies from requirements.txt to setup.py
* Set dependencies to current versions or greater
  • Loading branch information
micahhausler committed Apr 17, 2017
1 parent 0f525d9 commit 2706b2a
Show file tree
Hide file tree
Showing 16 changed files with 437 additions and 139 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
language: python
python:
- '2.6'
- '2.7'
env:
- TOXENV=py26
- TOXENV=docs
- TOXENV=py27
install:
- pip install tox
Expand Down
42 changes: 36 additions & 6 deletions elastalert/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ def get_aggregation_summary_text(self, matches):
summary_table_fields = [summary_table_fields]
# Include a count aggregation so that we can see at a glance how many of each aggregation_key were encountered
summary_table_fields_with_count = summary_table_fields + ['count']
text += "Aggregation resulted in the following data for summary_table_fields ==> {0}:\n\n".format(summary_table_fields_with_count)
text += "Aggregation resulted in the following data for summary_table_fields ==> {0}:\n\n".format(
summary_table_fields_with_count
)
text_table = Texttable()
text_table.header(summary_table_fields_with_count)
match_aggregation = {}
Expand Down Expand Up @@ -297,7 +299,9 @@ def alert(self, matches):
if qk in match:
elastalert_logger.info(
'Alert for %s, %s at %s:' % (self.rule['name'], match[qk], lookup_es_key(match, self.rule['timestamp_field'])))
alerts.append('1)Alert for %s, %s at %s:' % (self.rule['name'], match[qk], lookup_es_key(match, self.rule['timestamp_field'])))
alerts.append(
'1)Alert for %s, %s at %s:' % (self.rule['name'], match[qk], lookup_es_key(match, self.rule['timestamp_field']))
)
fullmessage['match'] = match[qk]
else:
elastalert_logger.info('Alert for %s at %s:' % (self.rule['name'], lookup_es_key(match, self.rule['timestamp_field'])))
Expand Down Expand Up @@ -703,7 +707,11 @@ def alert(self, matches):
except Exception as ex:
# Re-raise the exception, preserve the stack-trace, and give some
# context as to which watcher failed to be added
raise Exception("Exception encountered when trying to add '{0}' as a watcher. Does the user exist?\n{1}" .format(watcher, ex)), None, sys.exc_info()[2]
raise Exception(
"Exception encountered when trying to add '{0}' as a watcher. Does the user exist?\n{1}" .format(
watcher,
ex
)), None, sys.exc_info()[2]

except JIRAError as e:
raise EAException("Error creating JIRA ticket using jira_args (%s): %s" % (self.jira_args, e))
Expand Down Expand Up @@ -985,7 +993,12 @@ def alert(self, matches):
# set https proxy, if it was provided
proxies = {'https': self.pagerduty_proxy} if self.pagerduty_proxy else None
try:
response = requests.post(self.url, data=json.dumps(payload, cls=DateTimeEncoder, ensure_ascii=False), headers=headers, proxies=proxies)
response = requests.post(
self.url,
data=json.dumps(payload, cls=DateTimeEncoder, ensure_ascii=False),
headers=headers,
proxies=proxies
)
response.raise_for_status()
except RequestException as e:
raise EAException("Error posting to pagerduty: %s" % e)
Expand Down Expand Up @@ -1173,7 +1186,18 @@ def get_info(self):

class ServiceNowAlerter(Alerter):
""" Creates a ServiceNow alert """
required_options = set(['username', 'password', 'servicenow_rest_url', 'short_description', 'comments', 'assignment_group', 'category', 'subcategory', 'cmdb_ci', 'caller_id'])
required_options = set([
'username',
'password',
'servicenow_rest_url',
'short_description',
'comments',
'assignment_group',
'category',
'subcategory',
'cmdb_ci',
'caller_id'
])

def __init__(self, rule):
super(GitterAlerter, self).__init__(rule)
Expand Down Expand Up @@ -1202,7 +1226,13 @@ def alert(self, matches):
"caller_id": self.rule["caller_id"]
}
try:
response = requests.post(self.servicenow_rest_url, auth=(self.rule['username'], self.rule['password']), headers=headers, data=json.dumps(payload, cls=DateTimeEncoder), proxies=proxies)
response = requests.post(
self.servicenow_rest_url,
auth=(self.rule['username'], self.rule['password']),
headers=headers,
data=json.dumps(payload, cls=DateTimeEncoder),
proxies=proxies
)
response.raise_for_status()
except RequestException as e:
raise EAException("Error posting to ServiceNow: %s" % e)
Expand Down
17 changes: 14 additions & 3 deletions elastalert/create_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,19 @@ def main():
parser.add_argument('--index', help='Index name to create')
parser.add_argument('--old-index', help='Old index name to copy')
parser.add_argument('--send_get_body_as', default='GET', help='Method for querying Elasticsearch - POST, GET or source')
parser.add_argument('--boto-profile', default=None, dest='profile', help='DEPRECATED: (use --profile) Boto profile to use for signing requests')
parser.add_argument('--profile', default=None, help='AWS profile to use for signing requests. Optionally use the AWS_DEFAULT_PROFILE environment variable')
parser.add_argument('--aws-region', default=None, help='AWS Region to use for signing requests. Optionally use the AWS_DEFAULT_REGION environment variable')
parser.add_argument(
'--boto-profile',
default=None,
dest='profile',
help='DEPRECATED: (use --profile) Boto profile to use for signing requests')
parser.add_argument(
'--profile',
default=None,
help='AWS profile to use for signing requests. Optionally use the AWS_DEFAULT_PROFILE environment variable')
parser.add_argument(
'--aws-region',
default=None,
help='AWS Region to use for signing requests. Optionally use the AWS_DEFAULT_REGION environment variable')
parser.add_argument('--timeout', default=60, help='Elasticsearch request timeout')
parser.add_argument('--config', default='config.yaml', help='Global config file (default: config.yaml)')
args = parser.parse_args()
Expand Down Expand Up @@ -139,5 +149,6 @@ def main():

print('Done!')


if __name__ == '__main__':
main()
Loading

0 comments on commit 2706b2a

Please sign in to comment.