API error or expected?

Forum for questions and support relating to the 1.32.x releases only.
Post Reply
BiloxiGeek
Posts: 271
Joined: Tue Feb 11, 2014 2:04 pm

API error or expected?

Post by BiloxiGeek »

I've got some perl scripts I've used just to futz around with the API a bit here and there. Since updating to 1.32.0 I'm seeing some errors that I don't believe were there before the update.

When deleting an event via the API using

Code: Select all

curl -b /root/cookies.txt --silent --insecure -XDELETE  https://server/zm/api/events/<EventID>.json
I see this in /var/log/zoneminder/cake_error.log:

Code: Select all

2018-09-23 06:11:55 Error: [UnauthorizedException] Not Authenticated
Request URL: /zm/api/monitors/index/Type%20!=:WebSite.json
Stack Trace:
#0 /usr/share/zoneminder/www/api/app/Controller/MonitorsController.php(23): AppController->beforeFilter()
#1 [internal function]: MonitorsController->beforeFilter(Object(CakeEvent))
#2 /usr/share/zoneminder/www/api/lib/Cake/Event/CakeEventManager.php(243): call_user_func(Array, Object(CakeEvent))
#3 /usr/share/zoneminder/www/api/lib/Cake/Controller/Controller.php(677): CakeEventManager->dispatch(Object(CakeEvent))
#4 /usr/share/zoneminder/www/api/lib/Cake/Routing/Dispatcher.php(189): Controller->startupProcess()
#5 /usr/share/zoneminder/www/api/lib/Cake/Routing/Dispatcher.php(167): Dispatcher->_invoke(Object(MonitorsController), Object(CakeRequest))
#6 /usr/share/zoneminder/www/api/app/webroot/index.php(108): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#7 {main}
I have authenticated and the event does get deleted but I see this block of log every time regardless.
User avatar
iconnor
Posts: 2900
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: API error or expected?

Post by iconnor »

I am unable to reproduce this.

Are you sure that the line comes from your event deletion? I can't see any reason for it to redirect to the Monitors view with a WebSite type filter.
BiloxiGeek
Posts: 271
Joined: Tue Feb 11, 2014 2:04 pm

Re: API error or expected?

Post by BiloxiGeek »

It looks like I'm seeing quite a few lines of errors whenever I try something via curl and the API. For example, just pulling events.json I get quite a few lines of seemingly errors before the json data:

First I authenticate using:

Code: Select all

curl --silent --insecure -d "username=useid&password=password&action=login&view=console" -c /root/cookies.txt https://hostname/zm/index.php -o /dev/null
That correctly generates a fresh cookies.txt file. Then I pull a list of events with:

Code: Select all

curl -b /root/cookies.txt -XGET --silent --insecure https://hostname/zm/api/events.json
I would expect to see the json data and nothing else but I get quite a few lines of other stuff first.

Code: Select all

<pre class="cake-error"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr5baa00875ee1b-trace').style.display = (document.getElementById('cakeErr5baa00875ee1b-trace').style.display == 'none' ? '' : 'none');"><b>Notice</b> (8)</a>: Use of undefined constant ZM_DB_SSL_CA_CERT - assumed &#039;ZM_DB_SSL_CA_CERT&#039; [<b>CORE/Cake/Model/ConnectionManager.php</b>, line <b>69</b>]<div id="cakeErr5baa00875ee1b-trace" class="cake-stack-trace" style="display: none;"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr5baa00875ee1b-code').style.display = (document.getElementById('cakeErr5baa00875ee1b-code').style.display == 'none' ? '' : 'none')">Code</a> <a href="javascript:void(0);" onclick="document.getElementById('cakeErr5baa00875ee1b-context').style.display = (document.getElementById('cakeErr5baa00875ee1b-context').style.display == 'none' ? '' : 'none')">Context</a><pre id="cakeErr5baa00875ee1b-code" class="cake-code-dump" style="display: none;"><code><span style="color: #000000"><span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">include_once&nbsp;</span><span style="color: #0000BB">CONFIG&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">'database.php'</span><span style="color: #007700">;</span></span></code>
<code><span style="color: #000000"><span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">class_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'DATABASE_CONFIG'</span><span style="color: #007700">))&nbsp;{</span></span></code>
<span class="code-highlight"><code><span style="color: #000000"><span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">static::</span><span style="color: #0000BB">$config&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DATABASE_CONFIG</span><span style="color: #007700">();</span></span></code></span></pre><pre class="stack-trace">ConnectionManager::_init() - CORE/Cake/Model/ConnectionManager.php, line 69
ConnectionManager::getDataSource() - CORE/Cake/Model/ConnectionManager.php, line 83
Model::setDataSource() - CORE/Cake/Model/Model.php, line 3646
Model::setSource() - CORE/Cake/Model/Model.php, line 1162
Model::getDataSource() - CORE/Cake/Model/Model.php, line 3673
Model::_readDataSource() - CORE/Cake/Model/Model.php, line 3040
Model::find() - CORE/Cake/Model/Model.php, line 3012
EventsController::index() - APP/Controller/EventsController.php, line 86
ReflectionMethod::invokeArgs() - [internal], line ??
Controller::invokeAction() - CORE/Cake/Controller/Controller.php, line 491
AppController::invokeAction() - APP/Plugin/Crud/Lib/CrudControllerTrait.php, line 31
Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 193
Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167
[main] - APP/webroot/index.php, line 108</pre></div></pre><pre class="cake-error"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr5baa00875f585-trace').style.display = (document.getElementById('cakeErr5baa00875f585-trace').style.display == 'none' ? '' : 'none');"><b>Notice</b> (8)</a>: Use of undefined constant ZM_DB_SSL_CLIENT_KEY - assumed &#039;ZM_DB_SSL_CLIENT_KEY&#039; [<b>CORE/Cake/Model/ConnectionManager.php</b>, line <b>69</b>]<div id="cakeErr5baa00875f585-trace" class="cake-stack-trace" style="display: none;"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr5baa00875f585-code').style.display = (document.getElementById('cakeErr5baa00875f585-code').style.display == 'none' ? '' : 'none')">Code</a> <a href="javascript:void(0);" onclick="document.getElementById('cakeErr5baa00875f585-context').style.display = (document.getElementById('cakeErr5baa00875f585-context').style.display == 'none' ? '' : 'none')">Context</a><pre id="cakeErr5baa00875f585-code" class="cake-code-dump" style="display: none;"><code><span style="color: #000000"><span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">include_once&nbsp;</span><span style="color: #0000BB">CONFIG&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">'database.php'</span><span style="color: #007700">;</span></span></code>
<code><span style="color: #000000"><span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">class_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'DATABASE_CONFIG'</span><span style="color: #007700">))&nbsp;{</span></span></code>
<span class="code-highlight"><code><span style="color: #000000"><span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">static::</span><span style="color: #0000BB">$config&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DATABASE_CONFIG</span><span style="color: #007700">();</span></span></code></span></pre><pre class="stack-trace">ConnectionManager::_init() - CORE/Cake/Model/ConnectionManager.php, line 69
ConnectionManager::getDataSource() - CORE/Cake/Model/ConnectionManager.php, line 83
Model::setDataSource() - CORE/Cake/Model/Model.php, line 3646
Model::setSource() - CORE/Cake/Model/Model.php, line 1162
Model::getDataSource() - CORE/Cake/Model/Model.php, line 3673
Model::_readDataSource() - CORE/Cake/Model/Model.php, line 3040
Model::find() - CORE/Cake/Model/Model.php, line 3012
EventsController::index() - APP/Controller/EventsController.php, line 86
ReflectionMethod::invokeArgs() - [internal], line ??
Controller::invokeAction() - CORE/Cake/Controller/Controller.php, line 491
AppController::invokeAction() - APP/Plugin/Crud/Lib/CrudControllerTrait.php, line 31
Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 193
Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167
[main] - APP/webroot/index.php, line 108</pre></div></pre><pre class="cake-error"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr5baa00875fcdf-trace').style.display = (document.getElementById('cakeErr5baa00875fcdf-trace').style.display == 'none' ? '' : 'none');"><b>Notice</b> (8)</a>: Use of undefined constant ZM_DB_SSL_CLIENT_CERT - assumed &#039;ZM_DB_SSL_CLIENT_CERT&#039; [<b>CORE/Cake/Model/ConnectionManager.php</b>, line <b>69</b>]<div id="cakeErr5baa00875fcdf-trace" class="cake-stack-trace" style="display: none;"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr5baa00875fcdf-code').style.display = (document.getElementById('cakeErr5baa00875fcdf-code').style.display == 'none' ? '' : 'none')">Code</a> <a href="javascript:void(0);" onclick="document.getElementById('cakeErr5baa00875fcdf-context').style.display = (document.getElementById('cakeErr5baa00875fcdf-context').style.display == 'none' ? '' : 'none')">Context</a><pre id="cakeErr5baa00875fcdf-code" class="cake-code-dump" style="display: none;"><code><span style="color: #000000"><span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">include_once&nbsp;</span><span style="color: #0000BB">CONFIG&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">'database.php'</span><span style="color: #007700">;</span></span></code>
<code><span style="color: #000000"><span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">class_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'DATABASE_CONFIG'</span><span style="color: #007700">))&nbsp;{</span></span></code>
<span class="code-highlight"><code><span style="color: #000000"><span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">static::</span><span style="color: #0000BB">$config&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DATABASE_CONFIG</span><span style="color: #007700">();</span></span></code></span></pre><pre class="stack-trace">ConnectionManager::_init() - CORE/Cake/Model/ConnectionManager.php, line 69
ConnectionManager::getDataSource() - CORE/Cake/Model/ConnectionManager.php, line 83
Model::setDataSource() - CORE/Cake/Model/Model.php, line 3646
Model::setSource() - CORE/Cake/Model/Model.php, line 1162
Model::getDataSource() - CORE/Cake/Model/Model.php, line 3673
Model::_readDataSource() - CORE/Cake/Model/Model.php, line 3040
Model::find() - CORE/Cake/Model/Model.php, line 3012
EventsController::index() - APP/Controller/EventsController.php, line 86
ReflectionMethod::invokeArgs() - [internal], line ??
Controller::invokeAction() - CORE/Cake/Controller/Controller.php, line 491
AppController::invokeAction() - APP/Plugin/Crud/Lib/CrudControllerTrait.php, line 31
Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 193
Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 167
[main] - APP/webroot/index.php, line 108</pre></div></pre>
All that preceeds the events.json output that I expect to see. The json data is normal and valid but all those error lines are confusing a perl script that used to work just fine.
BiloxiGeek
Posts: 271
Joined: Tue Feb 11, 2014 2:04 pm

Re: API error or expected?

Post by BiloxiGeek »

Tried pulling up one event via API using https://hostname/zm/api/events/14003.json

Got some errors and then the expected result:

Code: Select all

Notice (8): Use of undefined constant ZM_DB_SSL_CA_CERT - assumed 'ZM_DB_SSL_CA_CERT' [CORE/Cake/Model/ConnectionManager.php, line 69]

Notice (8): Use of undefined constant ZM_DB_SSL_CLIENT_KEY - assumed 'ZM_DB_SSL_CLIENT_KEY' [CORE/Cake/Model/ConnectionManager.php, line 69]

Notice (8): Use of undefined constant ZM_DB_SSL_CLIENT_CERT - assumed 'ZM_DB_SSL_CLIENT_CERT' [CORE/Cake/Model/ConnectionManager.php, line 69]

Warning (2): filesize() [<a href='http://php.net/function.filesize'>function.filesize</a>]: stat failed for /var/lib/zoneminder/events/105/2018-09-25/14003/ [APP/Model/Event.php, line 137]

{ "event": { "Event": { "Id": "14003"
Normal json output continued beyond this point.
BiloxiGeek
Posts: 271
Joined: Tue Feb 11, 2014 2:04 pm

[SOLVED] Re: API error or expected?

Post by BiloxiGeek »

Added these lines to /etc/zm/zm.conf and no longer getting the errors. There is a .rpmnew version of the file but the actual zm.conf file never got those lines during the update to 1.32.x. That apparently was the missing piece.

Code: Select all

# SSL CA certificate for ZoneMinder database
ZM_DB_SSL_CA_CERT=

# # SSL client key for ZoneMinder database
ZM_DB_SSL_CLIENT_KEY=

# # SSL client cert for ZoneMinder database
ZM_DB_SSL_CLIENT_CERT=
API calls work as expected now. zmNinja on iPhone and iPad are back to normal as well.
Post Reply