[SOLVED] Remote update check via API not working

Started by chrisgch, June 21, 2021, 12:12:39 PM

Previous topic - Next topic
June 21, 2021, 12:12:39 PM Last Edit: June 21, 2021, 03:33:46 PM by chrisgch
First, I want to thank the developers for the great work they do with opensense.

I have a small problem: I'm trying to check for updates remotely via API by calling
https://<firewall_IP>/api/core/firmware/status
The method is the same as in this script:
https://github.com/bartsmit/opnsense-update-email

Unfortunately this doesn't seem to work unless I log into the dashboard and click on the "check for updates" link. This has been broken since about March.

Immediately after an update I get this error:
{"status_msg":"Firmware status check was aborted internally. Please try again.","status":"error"}

After an update check via dashboard (when there is no update) I get:
{"api_version":"2","connection":"ok","downgrade_packages":[],"download_size":"","last_check":"Mon Jun 21 12:07:37 CEST 2021","new_packages":[],"os_version":"FreeBSD 12.1-RELEASE-p18-HBSD","product_id":"opnsense","product_target":"opnsense","product_version":"21.1.7_1","reinstall_packages":[],"remove_packages":[],"repository":"ok","upgrade_major_message":"","upgrade_major_version":"","upgrade_needs_reboot":"0","upgrade_packages":[],"upgrade_sets":[],"all_packages":[],"all_sets":[],"status_msg":"There are no updates available on the selected mirror.","status":"none"}

After an update check via dashboard (when there are updates) I get:
{"api_version":"2","connection":"ok","downgrade_packages":[],"download_size":"22MiB","last_check":"Mon Jun 21 11:32:49 CEST 2021","new_packages":[{"name":"oniguruma","repository":"OPNsense","version":"6.9.7.1"},{"name":"php73-mbstring","repository":"OPNsense","version":"7.3.28"},{"name":"php73-pecl-psr","repository":"OPNsense","version":"1.1.0"},{"name":"php73-phalcon4","repository":"OPNsense","version":"4.1.2"}],"os_version":"FreeBSD 12.1-RELEASE-p16-HBSD","product_id":"opnsense","product_target":"opnsense","product_version":"21.1.6","reinstall_packages":[],"remove_packages":[],"repository":"ok","upgrade_major_message":"","upgrade_major_version":"","upgrade_needs_reboot":"1","upgrade_packages":[{"name":"curl","repository":"OPNsense","current_version":"7.76.1","new_version":"7.77.0"},{"name":"glib","repository":"OPNsense","current_version":"2.66.7_1,1","new_version":"2.66.8,2"},{"name":"isc-dhcp44-relay","repository":"OPNsense","current_version":"4.4.2_1","new_version":"4.4.2P1"},{"name":"isc-dhcp44-server","repository":"OPNsense","current_version":"4.4.2_1","new_version":"4.4.2P1_1"},{"name":"nspr","repository":"OPNsense","current_version":"4.30","new_version":"4.31"},{"name":"nss","repository":"OPNsense","current_version":"3.65","new_version":"3.66"},{"name":"openldap-sasl-client","repository":"OPNsense","current_version":"2.4.58","new_version":"2.4.59"},{"name":"opnsense","repository":"OPNsense","current_version":"21.1.6","new_version":"21.1.7_1"},{"name":"opnsense-lang","repository":"OPNsense","current_version":"20.1.4","new_version":"21.1.7"},{"name":"opnsense-update","repository":"OPNsense","current_version":"21.1.6","new_version":"21.1.7"},{"name":"os-dyndns","repository":"OPNsense","current_version":"1.24","new_version":"1.24_2"},{"name":"pcre2","repository":"OPNsense","current_version":"10.36","new_version":"10.37"},{"name":"py37-certifi","repository":"OPNsense","current_version":"2020.12.5","new_version":"2021.5.30"},{"name":"py37-chardet","repository":"OPNsense","current_version":"3.0.4_3,1","new_version":"4.0.0,1"},{"name":"py37-setuptools","repository":"OPNsense","current_version":"44.0.0_1","new_version":"57.0.0"},{"name":"py37-ujson","repository":"OPNsense","current_version":"3.0.0","new_version":"4.0.2"},{"name":"py37-yaml","repository":"OPNsense","current_version":"5.3.1_1","new_version":"5.4.1"},{"name":"squid","repository":"OPNsense","current_version":"4.14","new_version":"4.15"},{"name":"strongswan","repository":"OPNsense","current_version":"5.9.2_1","new_version":"5.9.2_2"},{"name":"base","size":"181051140","repository":"OPNsense","current_version":"21.1.6","new_version":"21.1.7"},{"name":"kernel","size":"28598360","repository":"OPNsense","current_version":"21.1.6","new_version":"21.1.7"}],"upgrade_sets":[],"all_packages":{"base":{"reason":"aktualisieren","old":"21.1.6","new":"21.1.7","repository":"OPNsense","name":"base"},"curl":{"reason":"aktualisieren","old":"7.76.1","new":"7.77.0","repository":"OPNsense","name":"curl"},"glib":{"reason":"aktualisieren","old":"2.66.7_1,1","new":"2.66.8,2","repository":"OPNsense","name":"glib"},"isc-dhcp44-relay":{"reason":"aktualisieren","old":"4.4.2_1","new":"4.4.2P1","repository":"OPNsense","name":"isc-dhcp44-relay"},"isc-dhcp44-server":{"reason":"aktualisieren","old":"4.4.2_1","new":"4.4.2P1_1","repository":"OPNsense","name":"isc-dhcp44-server"},"kernel":{"reason":"aktualisieren","old":"21.1.6","new":"21.1.7","repository":"OPNsense","name":"kernel"},"nspr":{"reason":"aktualisieren","old":"4.30","new":"4.31","repository":"OPNsense","name":"nspr"},"nss":{"reason":"aktualisieren","old":"3.65","new":"3.66","repository":"OPNsense","name":"nss"},"oniguruma":{"new":"6.9.7.1","reason":"neu","name":"oniguruma","repository":"OPNsense","old":"N\/V"},"openldap-sasl-client":{"reason":"aktualisieren","old":"2.4.58","new":"2.4.59","repository":"OPNsense","name":"openldap-sasl-client"},"opnsense":{"reason":"aktualisieren","old":"21.1.6","new":"21.1.7_1","repository":"OPNsense","name":"opnsense"},"opnsense-lang":{"reason":"aktualisieren","old":"20.1.4","new":"21.1.7","repository":"OPNsense","name":"opnsense-lang"},"opnsense-update":{"reason":"aktualisieren","old":"21.1.6","new":"21.1.7","repository":"OPNsense","name":"opnsense-update"},"os-dyndns":{"reason":"aktualisieren","old":"1.24","new":"1.24_2","repository":"OPNsense","name":"os-dyndns"},"pcre2":{"reason":"aktualisieren","old":"10.36","new":"10.37","repository":"OPNsense","name":"pcre2"},"php73-mbstring":{"new":"7.3.28","reason":"neu","name":"php73-mbstring","repository":"OPNsense","old":"N\/V"},"php73-pecl-psr":{"new":"1.1.0","reason":"neu","name":"php73-pecl-psr","repository":"OPNsense","old":"N\/V"},"php73-phalcon4":{"new":"4.1.2","reason":"neu","name":"php73-phalcon4","repository":"OPNsense","old":"N\/V"},"py37-certifi":{"reason":"aktualisieren","old":"2020.12.5","new":"2021.5.30","repository":"OPNsense","name":"py37-certifi"},"py37-chardet":{"reason":"aktualisieren","old":"3.0.4_3,1","new":"4.0.0,1","repository":"OPNsense","name":"py37-chardet"},"py37-setuptools":{"reason":"aktualisieren","old":"44.0.0_1","new":"57.0.0","repository":"OPNsense","name":"py37-setuptools"},"py37-ujson":{"reason":"aktualisieren","old":"3.0.0","new":"4.0.2","repository":"OPNsense","name":"py37-ujson"},"py37-yaml":{"reason":"aktualisieren","old":"5.3.1_1","new":"5.4.1","repository":"OPNsense","name":"py37-yaml"},"squid":{"reason":"aktualisieren","old":"4.14","new":"4.15","repository":"OPNsense","name":"squid"},"strongswan":{"reason":"aktualisieren","old":"5.9.2_1","new":"5.9.2_2","repository":"OPNsense","name":"strongswan"}},"all_sets":[],"status_msg":"Es sind 25 Aktualisierungen verf\u00fcgbar, gesamte Download-Gr\u00f6\u00dfe betr\u00e4gt 221.9MiB. Diese Aktualisierung erfordert einen Neustart.","status":"update"}

So the problem seems to be that calling https://<firewall_IP>/api/core/firmware/status does NOT initiate an update check, it only reports the status of the last update check.

Is there anything I need to do to make the call check for updates? Or do I need to run some kind of cron script to check for updates, so the call to the URL returns something useful?

In the Webinterface, there it is also not possible to run the Update check.
There is all the time the circle running.
And also there is no output in the update console at all.

Looks something is not working.

Cheers Robert

It always worked for me in the Web console, just not remotely.

Maybe you should try a different update mirror in
System - Firmware- Settings?


June 21, 2021, 03:33:08 PM #4 Last Edit: June 21, 2021, 03:45:15 PM by chrisgch
Thanks a lot, changing requests.get to requests.post in the python script takes indeed much longer, so it seems to perform an update check. I will put a bug report on the Github project of the update checker.

Yep, sounds like it's working now :)

FWIW, the POST has no negative effect on prior versions so the change is trivial.


Cheers,
Franco