bundles/sshmon: add check_github_for_new_release

This commit is contained in:
Franzi 2020-11-21 20:03:50 +01:00
parent a4ca98e79e
commit 91f2fd839b
Signed by: kunsi
GPG key ID: 12E3D2136B818350
2 changed files with 32 additions and 0 deletions

View file

@ -0,0 +1,31 @@
#!/usr/bin/env python3
from requests import get
from sys import argv, exit
assert len(argv) == 3, 'Usage: check_github_for_new_release <repo> <version>'
repo = argv[1]
current_version = argv[2]
try:
r = get('https://api.github.com/repos/{}/releases/latest'.format(repo), headers={'Accept': 'application/json'}).json()
except Exception as e:
print(repr(e))
exit(3)
newest_release = r['name']
if newest_release != current_version:
print('There is a newer version available: {} (currently installed: {})'.format(newest_release, current_version))
if r['prerelease'] or r['draft']:
print('Please note this is only a prerelease/draft.')
# Don't alert people for prereleases.
exit(0)
else:
exit(2)
else:
print('Currently installed version matches newest release on github')
exit(0)

View file

@ -47,6 +47,7 @@ for check in {
'cpu_stats', 'cpu_stats',
'mounts', 'mounts',
'ram', 'ram',
'github_for_new_release',
'http_url_for_string', 'http_url_for_string',
'https_certificate_at_url', 'https_certificate_at_url',
'http_wget', 'http_wget',