Skip to content

Commit

Permalink
Fix multiple linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
satterly committed Mar 20, 2023
1 parent faff378 commit 2a6632b
Show file tree
Hide file tree
Showing 127 changed files with 1,686 additions and 1,365 deletions.
2 changes: 2 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
known_third_party = Queue,alerta,alerta_azuremonitor,alerta_msteamswebhook,alerta_sentry,alerta_slack,alertaclient,boto,cachetclient,consul,dateutil,dingtalkchatbot,flask,google,influxdb,jinja2,kombu,mailer,matterhook,mock,op5,pymsteams,pytest,pyzabbix,requests,settings,setuptools,telepot,twilio,yaml
46 changes: 46 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
repos:
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.5.1
hooks:
- id: autopep8
- repo: https://github.com/pre-commit/pre-commit-hooks.git
rev: v2.5.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-byte-order-marker
- id: check-case-conflict
- id: check-docstring-first
- id: check-json
- id: check-merge-conflict
- id: check-yaml
- id: debug-statements
- id: double-quote-string-fixer
- id: end-of-file-fixer
- id: fix-encoding-pragma
args: ['--remove']
- id: pretty-format-json
args: ['--autofix']
- id: name-tests-test
args: ['--django']
exclude: ^tests/helpers/
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
args: ['--config=setup.cfg', '--ignore=E501']
- repo: https://github.com/asottile/pyupgrade
rev: v1.27.0
hooks:
- id: pyupgrade
args: ['--py3-plus']
- repo: https://github.com/asottile/seed-isort-config
rev: v1.9.4
hooks:
- id: seed-isort-config
- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.21
hooks:
- id: isort
1 change: 0 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,3 @@ Yoshiharu Mori <[email protected]>
Карамышев Степан <[email protected]>

$ git log --format='%aN <%aE>' | sort -f | uniq

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,3 @@ License
-------

Copyright (c) 2014-2020 Nick Satterly and [AUTHORS](AUTHORS). Available under the MIT License.

75 changes: 40 additions & 35 deletions integrations/consul/consulalerta.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,112 +2,117 @@

import json
import os

import consul
import sys
import time

import consul
from alertaclient.api import Client

CONSUL_HOST = os.environ.get('CONSUL_HOST', '127.0.0.1')
CONSUL_PORT = int(os.environ.get('CONSUL_PORT', 8500))

client = consul.Consul(host=CONSUL_HOST, port=CONSUL_PORT, token=None, scheme='http', consistency='default', dc=None, verify=True)
client = consul.Consul(host=CONSUL_HOST, port=CONSUL_PORT, token=None,
scheme='http', consistency='default', dc=None, verify=True)

j = json.load(sys.stdin)
print("Request:")
print('Request:')
print(j)

try:
url = client.kv.get('alerta/apiurl')[1]['Value']
except Exception:
print("No URL defined, exiting")
print('No URL defined, exiting')
sys.exit(1)

try:
key = client.kv.get('alerta/apikey')[1]['Value']
except Exception:
print("No key defined, exiting")
print('No key defined, exiting')
sys.exit(1)


try:
max_retries = int(client.kv.get('alerta/max_retries')[1]['Value'])
except TypeError:
print("No value defined, using default")
print('No value defined, using default')
max_retries = 3

try:
sleep = int(client.kv.get('alerta/sleep')[1]['Value'])
except TypeError:
print("No value defined, using default")
print('No value defined, using default')
sleep = 2

try:
timeout = int(client.kv.get('alerta/timeout')[1]['Value'])
except TypeError:
print("No value defined, using default")
print('No value defined, using default')
timeout = 900

try:
origin = client.kv.get('alerta/origin')[1]['Value']
except TypeError:
print("No value defined, using default")
origin = "consul"
print('No value defined, using default')
origin = 'consul'

try:
alerttype = client.kv.get('alerta/alerttype')[1]['Value']
except TypeError:
print("No value defined, using default")
alerttype = "ConsulAlert"
print('No value defined, using default')
alerttype = 'ConsulAlert'


api = Client(endpoint=url, key=key)

SEVERITY_MAP = {
'critical': 'critical',
'warning': 'warning',
'passing': 'ok',
'critical': 'critical',
'warning': 'warning',
'passing': 'ok',
}

def createalert( data ):

def createalert(data):
try:
environment = client.kv.get('alerta/env/{0}'.format(data['Node']))[1]['Value']
environment = client.kv.get(
'alerta/env/{}'.format(data['Node']))[1]['Value']
except Exception:
try:
environment = client.kv.get('alerta/defaultenv')[1]['Value']
except Exception:
environment = "Production"
environment = 'Production'

for _ in range(max_retries):
try:
print("Response:")
print('Response:')
response = api.send_alert(
resource=data['Node'],
event=data['CheckId'],
value=data['Status'],
correlate=SEVERITY_MAP.keys(),
environment=environment,
service=[data['CheckId']],
severity=SEVERITY_MAP[data['Status']],
text=data['Output'],
timeout=timeout,
origin=origin,
type=alerttype
resource=data['Node'],
event=data['CheckId'],
value=data['Status'],
correlate=SEVERITY_MAP.keys(),
environment=environment,
service=[data['CheckId']],
severity=SEVERITY_MAP[data['Status']],
text=data['Output'],
timeout=timeout,
origin=origin,
type=alerttype
)
print(response)
except Exception as e:
print("HTTP Error: {}".format(e))
print('HTTP Error: {}'.format(e))
time.sleep(sleep)
continue
else:
break
else:
print("api is down")
print('api is down')


def main():
for item in enumerate(j):
i=item[0]
i = item[0]
createalert(j[i])

if __name__ == "__main__":

if __name__ == '__main__':
main()
17 changes: 11 additions & 6 deletions integrations/consul/consulheartbeat.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env python

from alertaclient.api import Client
import consul
import time

client = consul.Consul(host='127.0.0.1', port=8500, token=None, scheme='http', consistency='default', dc=None, verify=True)
import consul
from alertaclient.api import Client

client = consul.Consul(host='127.0.0.1', port=8500, token=None,
scheme='http', consistency='default', dc=None, verify=True)

url = client.kv.get('alerta/apiurl')[1]['Value']
key = client.kv.get('alerta/apikey')[1]['Value']
Expand All @@ -16,21 +18,24 @@
origin = client.kv.get('alerta/origin')[1]['Value']
api = Client(endpoint=url, key=key)


def createheartbeat():
for _ in range(max_retries):
try:
print(api.heartbeat(origin=origin, timeout=timeout))
except Exception as e:
print("HTTP Error: {}".format(e))
print('HTTP Error: {}'.format(e))
time.sleep(sleep)
continue
else:
break
else:
print("api is down")
print('api is down')


def main():
createheartbeat()

if __name__ == "__main__":

if __name__ == '__main__':
main()
7 changes: 3 additions & 4 deletions integrations/consul/setup.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@

from setuptools import setup

version = '1.1.1'

setup(
name="alerta-consul",
name='alerta-consul',
version=version,
description='Send emails from Alerta',
url='https://github.com/alerta/alerta-contrib',
license='MIT',
author='Marco Supino',
author_email='[email protected]',
py_modules=['consulalerta','consulheartbeat'],
py_modules=['consulalerta', 'consulheartbeat'],
install_requires=[
'alerta',
'python-consul'
Expand All @@ -24,7 +23,7 @@
'consul-heartbeat = consulheartbeat:main'
]
},
keywords="alerta monitoring consul",
keywords='alerta monitoring consul',
classifiers=[
'Topic :: System :: Monitoring',
]
Expand Down
4 changes: 2 additions & 2 deletions integrations/fail2ban/alerta.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ actionban = echo <matches> | grep -q "Failed password for [a-z][-a-z0-9_]* from
# Notes.: Alerta API URL
# Values: STRING
#
alertaurl =
alertaurl =

# Option: alertaapikey
# Notes.: Alerta API key
# Values: STRING
#
alertaapikey =
alertaapikey =

# Option: logpath
# Notes.: Absolute path to the log file
Expand Down
2 changes: 1 addition & 1 deletion integrations/mailer/email.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<strong>Duplicate Count</strong>: {{ alert.duplicate_count }} <br>
<strong>Origin</strong>: {{ alert.origin }} <br>
<strong>Tags</strong>: {{ alert.tags|join(', ') }} <br>
{% for key,value in alert.attributes.items() -%}
{% for key,value in alert.attributes.items() -%}
{{ key|title }}: {{ value }}
{% endfor -%}
<br>
Expand Down
1 change: 0 additions & 1 deletion integrations/mailer/email.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ To acknowledge this alert visit this URL:
{{ dashboard_url }}/#/alert/{{ alert.id }}

Generated by {{ program }} on {{ hostname }} at {{ now }}

Loading

0 comments on commit 2a6632b

Please sign in to comment.