diff options
Diffstat (limited to 'src')
| -rwxr-xr-x | src/conf_mode/system_update-check.py | 17 | ||||
| -rwxr-xr-x | src/system/vyos-system-update-check.py | 2 |
2 files changed, 18 insertions, 1 deletions
diff --git a/src/conf_mode/system_update-check.py b/src/conf_mode/system_update-check.py index 7ed736eac..6a07d93a6 100755 --- a/src/conf_mode/system_update-check.py +++ b/src/conf_mode/system_update-check.py @@ -15,10 +15,12 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import json +import requests from pathlib import Path from sys import exit +from vyos.base import Warning from vyos.config import Config from vyos.utils.process import call from vyos import ConfigError @@ -54,6 +56,21 @@ def verify(config): if 'url' not in config: raise ConfigError('URL is required!') + url = config['url'] + + # Make sure that provided URL is available and responses a valid JSON + # otherwise print warning and display type of error (connection, timeout and etc.) + try: + response = requests.get(url, timeout=10) + response.raise_for_status() + response.json() + except requests.exceptions.RequestException as e: + error_type = type(e).__name__ + Warning( + '"system update-check url" has a valid URL but ' + f'unable to retrieve data from the server: {error_type}' + ) + def generate(config): # bail out early - looks like removal from running config diff --git a/src/system/vyos-system-update-check.py b/src/system/vyos-system-update-check.py index 66a8b0d02..b7d1fc7c5 100755 --- a/src/system/vyos-system-update-check.py +++ b/src/system/vyos-system-update-check.py @@ -60,7 +60,7 @@ if __name__ == '__main__': remote_version = jmespath.search('[0].version', remote_data) if local_version != remote_version and remote_version: call(f'wall -n "Update available: {remote_version} \nUpdate URL: {url}"') - # MOTD used in /run/motd.d/10-update + # MOTD used in /run/motd.d/10-vyos-update motd_file.parent.mkdir(exist_ok=True) motd_file.write_text(f'---\n' f'Current version: {local_version}\n' |
