Skip to content

Commit

Permalink
Merge branch 'restructure' into 'master'
Browse files Browse the repository at this point in the history
Restructure the files

See merge request ix.ai/grafana-email!9
  • Loading branch information
tlex committed Sep 27, 2020
2 parents eb293df + ec3cecd commit f0250da
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ variables:
ENABLE_ARM64: 'true'
ENABLE_ARMv7: 'true'
ENABLE_ARMv6: 'true'
ENABLE_386: 'true'

include:
- project: 'ix.ai/ci-templates'
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use "--disable=all --enable=classes
# --disable=W".
disable=logging-format-interpolation,
disable=logging-fstring-interpolation,
# too-few-public-methods,
invalid-name,
no-self-use,
Expand Down
15 changes: 7 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
FROM alpine:latest
LABEL maintainer="[email protected]" \
ai.ix.repository="ix.ai/etherscan-exporter"
ai.ix.repository="ix.ai/grafana-email"

WORKDIR /app
WORKDIR /grafana-email
COPY grafana-email/ /grafana-email
RUN set -xeu; \
apk --no-cache add python3 py3-pillow py3-requests py3-pip; \
pip install --no-cache-dir -r requirements.txt

COPY src/ /app

RUN apk --no-cache add python3 py3-pillow py3-requests && \
pip3 install --no-cache-dir -r requirements.txt

ENTRYPOINT ["python3", "/app/grafana-email.py"]
ENTRYPOINT ["python3", "/grafana-email/grafana-email.py"]
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
[![Pipeline Status](https://gitlab.com/ix.ai/grafana-email/badges/master/pipeline.svg)](https://gitlab.com/ix.ai/grafana-email/)
[![Docker Stars](https://img.shields.io/docker/stars/ixdotai/grafana-email.svg)](https://hub.docker.com/r/ixdotai/grafana-email/)
[![Docker Pulls](https://img.shields.io/docker/pulls/ixdotai/grafana-email.svg)](https://hub.docker.com/r/ixdotai/grafana-email/)
[![Docker Image Version (latest)](https://img.shields.io/docker/v/ixdotai/grafana-email/latest)](https://hub.docker.com/r/ixdotai/grafana-email/)
[![Docker Image Size (latest)](https://img.shields.io/docker/image-size/ixdotai/grafana-email/latest)](https://hub.docker.com/r/ixdotai/grafana-email/)
[![Gitlab Project](https://img.shields.io/badge/GitLab-Project-554488.svg)](https://gitlab.com/ix.ai/grafana-email/)

Connects to Grafana and sends an e-mail with attached graphs.
Expand Down Expand Up @@ -130,7 +132,9 @@ services:
## Tags and Arch
Starting with version v0.3.0, the images are multi-arch, with builds for amd64, arm64 and armv7.
Starting with version v0.3.0, the images are multi-arch, with builds for amd64, arm64 and armv7. Version v0.4.0 also
adds 386 build.
* `vN.N.N` - for example v0.3.0
* `latest` - always pointing to the latest version
* `dev-master` - the last build on the master branch
Expand Down
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh

echo "Setting VERSION='${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}' in src/constants.py"
echo "VERSION = '${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}'" >> src/constants.py
echo "Setting VERSION='${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}' in grafana-email/constants.py"
echo "VERSION = '${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}'" >> grafana-email/constants.py
File renamed without changes.
File renamed without changes.
23 changes: 12 additions & 11 deletions src/grafana-email.py → grafana-email/grafana-email.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ def __init__(self):
self.message['Subject'] = os.environ.get('SMTP_SUBJECT', 'Grafana Email Report')
self.message['From'] = self.smtp['from']
self.message['To'] = self.smtp['to']
LOG.debug('Panel options: {}'.format(self.panel_args))
LOG.debug('SMTP options: {}'.format(self.smtp))
LOG.debug('Grafana options: {}'.format(self.grafana))

LOG.debug(f'Panel options: {self.panel_args}')
LOG.debug(f'SMTP options: {self.smtp}')
LOG.debug(f'Grafana options: {self.grafana}')

def get_panels(self):
""" downloads each panel and saves it to a variable """
Expand All @@ -99,18 +100,18 @@ def get_panels(self):
)

if self.grafana.get('url_params'):
uri = '{uri}?{url_params}'.format(uri=uri, url_params=self.grafana['url_params'])
uri = f'{uri}?{self.grafana["url_params"]}'

LOG.info('Setting download URI to {}'.format(uri))
LOG.info(f'Setting download URI to {uri}')

params = {}
for param, arg in self.panel_args.items():
if arg:
params.update({param: arg})

headers = {'Authorization': 'Bearer {}'.format(self._token)}
headers = {'Authorization': f'Bearer {self._token}'}
if self.grafana.get('header_host'):
headers.update({'Host': '{}'.format(self.grafana['header_host'])})
headers.update({'Host': f"{self.grafana['header_host']}"})

for panel in self.grafana['panel_ids'].split(','):
params['panelId'] = panel
Expand Down Expand Up @@ -140,7 +141,7 @@ def send_email(self):
<img src="cid:[[image]]" style="{width:[[width]]px;height:[[height]]px}" />
</p>
"""
html = html.replace('[[image]]', '{}_panel_{}.png'.format(host, panel))
html = html.replace('[[image]]', f'{host}_panel_{panel}.png')
html = html.replace('[[width]]', str(self.panel_args['width']))
html = html.replace('[[height]]', str(self.panel_args['height']))
html += '</body></html>'
Expand All @@ -150,11 +151,11 @@ def send_email(self):

for panel, image in [(k, v) for x in self.panels for (k, v) in x.items()]:
img = MIMEImage(image, 'png')
img.add_header('Content-ID', '<{host}_panel_{panel}.png>'.format(host=host, panel=panel))
img.add_header('Content-ID', f'<{host}_panel_{panel}.png>')
img.add_header(
'Content-Disposition',
'inline',
filename='{host}_panel_{panel}.png'.format(host=host, panel=panel)
filename=f'{host}_panel_{panel}.png',
)
self.message.attach(img)

Expand All @@ -177,7 +178,7 @@ def send_email(self):
if __name__ == '__main__':
configure_logging()
# pylint: disable=no-member
LOG.info("Starting {} {}".format(FILENAME, constants.VERSION))
LOG.info(f"Starting {FILENAME} {constants.VERSION}")
grafana = GrafanaEmail()
grafana.get_panels()
grafana.send_email()
2 changes: 1 addition & 1 deletion src/requirements.txt → grafana-email/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
requests==2.22.0
requests==2.24.0
pygelf==0.3.6
pillow>=6.2.1

0 comments on commit f0250da

Please sign in to comment.