Page 1 of 1
[SOLVED] API not working after upgrade from 1.36.12 to 1.36.18
Posted: Mon Jun 06, 2022 5:42 pm
by SkippyDo
Did an update of OS bits and Zoneminder (via 'apt [update & upgrade]') and now APIs aren't working. All had been fine for quite a while up until this update. OS: Debian Bullseye ZM: 1.36.18 (from 1.36.12)
Relevant Cake error logged is:
2022-06-06 09:20:30 Error: [MissingConnectionException] Database connection "Mysql" is missing, or could not be created.
Exception Attributes: array (
'class' => 'Mysql',
'message' => 'SQLSTATE[HY000] [2006] MySQL server has gone away',
'enabled' => true,
)
Commands via curl
curl -XPOST -d "user=<user>&pass=<password>" https://<FQDN>/zm/api/host/login.json
curl -v -XGET https://<FQDN>/zm/api/monitors.json?token=<token obtained via XPUT>
[relevant output:}
* SSL certificate verify ok.
> GET /zm/api/monitors.json?token=<token> HTTP/1.1
> Host: <FQDN>
> User-Agent: curl/7.74.0
> Accept: */*
>
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* old SSL session ID is stale, removing
* Mark bundle as not supporting multiuse
< HTTP/1.1 500 Internal Server Error
< Date: Mon, 06 Jun 2022 17:21:22 GMT
< Server: Apache
< Content-Length: 422
< Connection: close
< Content-Type: application/json; charset=UTF-8
<
{
"code": 500,
"name": "Database connection "Mysql" is missing, or could not be created.",
"message": "SQLSTATE[HY000] [2006] MySQL server has gone away",
"url": "\/zm\/api\/monitors.json?token=<token>"
* Closing connection 0
* TLSv1.3 (OUT), TLS alert, close notify (256):
Regular ZM web interface is no problem. Mysql/mariadb running.
Accounts/logins are all unchanged (all have API access).
I'm starting to chase my tail and figure it's best to stop and see if someone can get me pointed in the right direction.
Thanks.
Re: API not working after upgrade from 1.36.12 to 1.36.18
Posted: Mon Jun 06, 2022 6:33 pm
by iconnor
I think (and hope) that this is something specific to your system. API still works here for me.
It has been a long time since I've seen that mysql error message. Maybe check mysql logs too. Are you running out of connections maybe?
Re: API not working after upgrade from 1.36.12 to 1.36.18
Posted: Tue Jun 07, 2022 4:40 am
by SkippyDo
These API issues are buggers!
I am able to run a php script to fetch a count of tables in the ZM database, so that would suggest that the basic php bits are OK.
I can do a curl command to fetch web server version, so curl stuff should be OK (as a test tool).
I'm seeing SSL encryption stuff working OK (have had issues in the past, but they're cleared up [permission issues on cert files]).
Looking at the mysql error.log file when attempting to connect via zmNinja:
2022-06-06 20:48:25 7955 [Warning] Aborted connection 7955 to db: 'unconnected' user: 'unauthenticated' host: 'localhost' (This connection closed normally without authentication)
2022-06-06 20:48:25 7957 [Warning] Aborted connection 7957 to db: 'unconnected' user: 'unauthenticated' host: 'localhost' (This connection closed normally without authentication)
2022-06-06 20:48:25 7929 [Warning] Aborted connection 7929 to db: 'zm' user: 'zmuser' host: 'localhost' (Got an error reading communication packets)
2022-06-06 20:48:25 7959 [Warning] Aborted connection 7959 to db: 'unconnected' user: 'unauthenticated' host: 'localhost' (This connection closed normally without authentication)
2022-06-06 20:48:25 7961 [Warning] Aborted connection 7961 to db: 'unconnected' user: 'unauthenticated' host: 'localhost' (This connection closed normally without authentication)
2022-06-06 20:48:25 7963 [Warning] Aborted connection 7963 to db: 'unconnected' user: 'unauthenticated' host: 'localhost' (This connection closed normally without authentication)
Bolded line doesn't come up every time (as a matter of fact, I'd only seen it once). Only get one line (non-bolded ones) if running curl (same results on local machine and remote machine).
Seems that the ZM API bits aren't getting and or passing the right authentication info (for zmuser?).
It's unlikely a resource issue with connections. I seem to recall playing around with that a long time ago (for another problem).
Re: API not working after upgrade from 1.36.12 to 1.36.18
Posted: Tue Jun 14, 2022 1:25 pm
by SkippyDo
Still stumped.
It is an issue with Cake. Unable to see what info it's using to try and connect to the database with.
Anyone have any thoughts as to how I can debug this?
Here's what gets logged in the cake_error.log file:
Request URL: /zm/api/monitors.json?token=<token>
Stack Trace:
#0 /usr/share/zoneminder/www/api/lib/Cake/Model/Datasource/DboSource.php(278): Mysql->connect()
#1 /usr/share/zoneminder/www/api/lib/Cake/Model/ConnectionManager.php(105): DboSource->__construct()
#2 /usr/share/zoneminder/www/api/lib/Cake/Model/Model.php(3659): ConnectionManager::getDataSource()
#3 /usr/share/zoneminder/www/api/lib/Cake/Model/Model.php(1162): Model->setDataSource()
#4 /usr/share/zoneminder/www/api/lib/Cake/Model/Model.php(3686): Model->setSource()
#5 /usr/share/zoneminder/www/api/lib/Cake/Model/Model.php(1394): Model->getDataSource()
#6 /usr/share/zoneminder/www/api/app/Plugin/CakePHP-Enum-Behavior/Model/Behavior/EnumBehavior.php(34): Model->schema()
#7 /usr/share/zoneminder/www/api/lib/Cake/Model/BehaviorCollection.php(145): EnumBehavior->setup()
#8 /usr/share/zoneminder/www/api/lib/Cake/Model/BehaviorCollection.php(66): BehaviorCollection->load()
#9 /usr/share/zoneminder/www/api/lib/Cake/Model/Model.php(781): BehaviorCollection->init()
#10 [internal function]: Model->__construct()
#11 /usr/share/zoneminder/www/api/lib/Cake/Utility/ClassRegistry.php(169): ReflectionClass->newInstance()
#12 /usr/share/zoneminder/www/api/lib/Cake/Controller/Controller.php(746): ClassRegistry::init()
#13 /usr/share/zoneminder/www/api/lib/Cake/Controller/Controller.php(376): Controller->loadModel()
#14 /usr/share/zoneminder/www/api/lib/Cake/Controller/Controller.php(414): Controller->__isset()
#15 /usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Component/CrudComponent.php(812): Controller->__get()
#16 /usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Component/CrudComponent.php(614): CrudComponent->_setModelProperties()
#17 /usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Component/CrudComponent.php(751): CrudComponent->getSubject()
#18 /usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Component/CrudComponent.php(728): CrudComponent->_loadListener()
#19 /usr/share/zoneminder/www/api/app/Plugin/Crud/Controller/Component/CrudComponent.php(169): CrudComponent->_loadListeners()
#20 /usr/share/zoneminder/www/api/lib/Cake/Utility/ObjectCollection.php(129): CrudComponent->initialize()
#21 /usr/share/zoneminder/www/api/lib/Cake/Event/CakeEventManager.php(244): ObjectCollection->trigger()
#22 /usr/share/zoneminder/www/api/lib/Cake/Controller/Controller.php(682): CakeEventManager->dispatch()
#23 /usr/share/zoneminder/www/api/lib/Cake/Routing/Dispatcher.php(189): Controller->startupProcess()
#24 /usr/share/zoneminder/www/api/lib/Cake/Routing/Dispatcher.php(167): Dispatcher->_invoke()
#25 /usr/share/zoneminder/www/api/app/webroot/index.php(117): Dispatcher->dispatch()
#26 {main}
Re: [SOLVED] API not working after upgrade from 1.36.12 to 1.36.18
Posted: Sun Jun 26, 2022 4:13 pm
by SkippyDo
Figured out what was causing my problem. Commented out the following lines from www/api/app/Config/database.php:
'ssl_ca' => ZM_DB_SSL_CA_CERT,
'ssl_key' => ZM_DB_SSL_CLIENT_KEY,
'ssl_cert' => ZM_DB_SSL_CLIENT_CERT,
Unsure why this suddenly became an issue when upgrading from 1.36.12 to 1.36.18/19. Looking at the repository sources this file hasn't changed in a long time. I've got ZM_DB_SSL_CLIENT_KEY AND ZM_DB_SSL_CLIENT_KEY defined in my local/site-specific zm/conf.d/"custom.conf" file. NOTE: I cannot, however, enable to ZM_DB_SSL_CA_CERT variable as this tends to cause errors. ALL cert files are readable by the user www-data.