Skip to content

Commit

Permalink
added workflow for new Zabbix release checking
Browse files Browse the repository at this point in the history
  • Loading branch information
aiantsen committed Oct 20, 2023
1 parent 4fb5f96 commit 92c3824
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/scripts/check_new_zabbx_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python
import sys
import requests

sys.path.append('.')
from zabbix_utils.version import __max_supported__


BRANCHES_URL = "https://git.zabbix.com/rest/api/latest/projects\
/ZBX/repos/zabbix/branches?limit=100&filterText=release"

sver = __max_supported__

try:
branches = requests.get(BRANCHES_URL, timeout=5).json()['values']
except Exception as error:
print(f'Branches list getting failed... Data: {error}', flush=True)
sys.exit(error)

versions = []

for branch in branches:
version = branch['displayId'].split('/')[-1]
try:
version = float(version)
except:
continue
versions.append(version)

if sver < max(versions):
print(f"""New Zabbix version was found in https://git.zabbix.com.
The zabbix_utils library supports <{sver} but the latest version of Zabbix is {max(versions)}
""", flush=True)
sys.exit()
63 changes: 63 additions & 0 deletions .github/scripts/telegram_msg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python3
import requests
import sys
import os
import json

chat_id = os.environ.get("TBOT_CHAT") # chat id. env TBOT_CHAT must be set!
token = os.environ.get("TBOT_TOKEN") # bot token. env TBOT_TOKEN must be set!
parse_mode = 'HTML' # HTML, MarkdownV2 or empty

if not os.environ.get("TBOT_CHAT"):
print('Please set environmental variable "TBOT_CHAT"')
if not os.environ.get("TBOT_TOKEN"):
print('Please set environmental variable "TBOT_TOKEN"')


def sendMessage(msg, passthrough=True):

if passthrough:
print(msg)

if len(msg) == 0:
return '{"ok":true}'

url = f"https://api.telegram.org/bot{token}/sendMessage"

if len(msg) > 4096:
msg = "Message output is too long. Please check the GitHub action log."

if os.environ.get("SUBJECT"):
msg = f'{os.environ.get("SUBJECT")}\n\n{msg}'

if os.environ.get("GH_JOB"):
msg += f'\n\n<a href="{os.environ.get("GH_JOB")}">{os.environ.get("GH_JOB")}</a>'

payload = {
"text": msg,
"parse_mode": parse_mode,
"disable_web_page_preview": False,
"disable_notification": False,
"reply_to_message_id": None,
"chat_id": chat_id
}
headers = {
"accept": "application/json",
"User-Agent": "Python script",
"content-type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

return response.text


if len(sys.argv) == 2:
result = sendMessage(sys.argv[1])
else:
result = sendMessage(sys.stdin.read())

result = json.loads(result)
if not result["ok"]:
print(result["error_code"], result["description"])
sys.exit(1)
31 changes: 31 additions & 0 deletions .github/workflows/check_new_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: check_new_release
run-name: Check new Zabbix release

on:
schedule:
- cron: "0 0 * * *"

jobs:
build-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Prepare environment
run: |
python -m pip install --upgrade pip
pip install requests
apt install -y tee tail
- name: Check new Zabbix release
run: |
./.github/scripts/check_new_zabbx_release.py | tee /tmp/import.log
- name: Send report
if: steps.import_templates.outcome == 'failure'
env:
TBOT_TOKEN: ${{ secrets.TBOT_TOKEN }}
TBOT_CHAT: ${{ vars.TBOT_CHAT }}
SUBJECT: Found new Zabbix release
run: tail /tmp/import.log | ./.github/scripts/telegram_msg.py

0 comments on commit 92c3824

Please sign in to comment.