zm/api/monitors.json failing

Forum for questions and support relating to the 1.32.x releases only.
Post Reply
SkippyDo
Posts: 219
Joined: Mon Nov 20, 2017 6:49 pm

zm/api/monitors.json failing

Post by SkippyDo »

Recently installed 1.32.2 and it looks like I've got api configuration issues as I am unable to get http://<server>/zm/api/monitors.json to work from a browser (first discovered there was an api issue when attempting to access via ZMninja pro). No clue as to where to look for resolving this.
Last edited by SkippyDo on Wed Dec 26, 2018 11:50 am, edited 1 time in total.
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: zm/api/monitors.json failing

Post by rockedge »

I think you are missing PHP modules php-apcu and php-apcu-bc ...install these and enable them and restart Apache
SkippyDo
Posts: 219
Joined: Mon Nov 20, 2017 6:49 pm

Re: zm/api/monitors.json failing

Post by SkippyDo »

From what I can tell those are installed:

ii cakephp 2.10.11-2 all rapid application development framework for PHP
ii cakephp-scripts 2.10.11-2 all rapid application development framework for PHP (scripts)

ii php 2:7.3+69 all server-side, HTML-embedded scripting language (default)
ii php-apcu 5.1.16+4.0.11-1 amd64 APC User Cache for PHP
ii php-apcu-bc 1.0.4-3 amd64 APCu Backwards Compatibility Module
ii php-common 2:69 all Common files for PHP packages
ii php-gd 2:7.3+69 all GD module for PHP [default]
ii php-mysql 2:7.3+69 all MySQL module for PHP [default]
ii php7.0 7.0.33-0+deb9u1 all server-side, HTML-embedded scripting language (metapackage)
ii php7.0-cli 7.0.33-0+deb9u1 amd64 command-line interpreter for the PHP scripting language
ii php7.0-common 7.0.33-0+deb9u1 amd64 documentation, examples and common module for PHP
ii php7.0-json 7.0.33-0+deb9u1 amd64 JSON module for PHP
ii php7.0-mysql 7.0.33-0+deb9u1 amd64 MySQL module for PHP
ii php7.0-opcache 7.0.33-0+deb9u1 amd64 Zend OpCache module for PHP
ii php7.0-readline 7.0.33-0+deb9u1 amd64 readline module for PHP
ii php7.3 7.3.0-2 all server-side, HTML-embedded scripting language (metapackage)
ii php7.3-cli 7.3.0-2 amd64 command-line interpreter for the PHP scripting language
ii php7.3-common 7.3.0-2 amd64 documentation, examples and common module for PHP
ii php7.3-gd 7.3.0-2 amd64 GD module for PHP
ii php7.3-json 7.3.0-2 amd64 JSON module for PHP
ii php7.3-mysql 7.3.0-2 amd64 MySQL module for PHP
ii php7.3-opcache 7.3.0-2 amd64 Zend OpCache module for PHP
ii php7.3-readline 7.3.0-2 amd64 readline module for PHP
SkippyDo
Posts: 219
Joined: Mon Nov 20, 2017 6:49 pm

Re: zm/api/monitors.json failing

Post by SkippyDo »

Reinstalled everything (except OS) and still no go. However, I now get a page with "Release Notes for CakePHP 2.10.11." when specifying only the api directory (http://<server>/zm/api), which means that I'm now reading the api directory.

Contents of my zm/api directory:

app/ build.properties build.xml composer.json CONTRIBUTING.md css@ img@ index.php lib/ README.md
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: zm/api/monitors.json failing

Post by rockedge »

what comes up with the URL? ->

Code: Select all

http://yourzm_server/zm/api/host/getVersion.json
SkippyDo
Posts: 219
Joined: Mon Nov 20, 2017 6:49 pm

Re: zm/api/monitors.json failing

Post by SkippyDo »

The requested URL /zm/api/host/getVersion.json was not found on this server.

NOTE: In my subject title I omitted the "host" path component. But with or without it still produces a 404 error.
SkippyDo
Posts: 219
Joined: Mon Nov 20, 2017 6:49 pm

Re: zm/api/monitors.json failing

Post by SkippyDo »

What version of PHP should I be running? I seem to have bits for both 7.0 and 7.3 installed.
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: zm/api/monitors.json failing

Post by rockedge »

the url for example on one of my test systems is
http://localhost/zm/api/host/getVersion.json and the response is in the code block below
for this test since I have OPT_USE_AUTH turned ON so I login to the web console gui then in a new tab on the browser use the above URL
and I receive the response below.
As far as the PHP version I would stick with PHP 7.3 but I think either one would work.

Code: Select all

{
    "version": "1.33.0",
    "apiversion": "1.0"
}
I login into the web console so the API authority is satisfied and if I don't login this as the response. But it would indicate also that the API is working.

Code: Select all

{
    "success": false,
    "data": {
        "name": "Not Authenticated",
        "message": "Not Authenticated",
        "url": "\/zm\/api\/host\/getVersion.json",
        "exception": {
            "class": "UnauthorizedException",
            "code": 401,
            "message": "Not Authenticated",
            "trace": [
                "#0 \/usr\/share\/zoneminder\/www\/api\/lib\/Cake\/Event\/CakeEventManager.php(243): AppController->beforeFilter(Object(CakeEvent))",
                "#1 \/usr\/share\/zoneminder\/www\/api\/lib\/Cake\/Controller\/Controller.php(677): CakeEventManager->dispatch(Object(CakeEvent))",
                "#2 \/usr\/share\/zoneminder\/www\/api\/lib\/Cake\/Routing\/Dispatcher.php(189): Controller->startupProcess()",
                "#3 \/usr\/share\/zoneminder\/www\/api\/lib\/Cake\/Routing\/Dispatcher.php(167): Dispatcher->_invoke(Object(HostController), Object(CakeRequest))",
                "#4 \/usr\/share\/zoneminder\/www\/api\/app\/webroot\/index.php(107): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))",
                "#5 {main}"
            ]
        },
        "queryLog": []
    }
}
SkippyDo
Posts: 219
Joined: Mon Nov 20, 2017 6:49 pm

Re: zm/api/monitors.json failing

Post by SkippyDo »

Yes, I see those tests everywhere, but... no matter what I do I can only get this response:

The requested URL /zm/host/api/getVersion.json was not found on this server.

Just what is the "host" directory? Is it a virtual rewrite or something? I have no such directory (nothing, anywhere). It "seems" like I have all the necessary php libraries/files but they are not being found/loaded by ZM: libphp7.0.so and libphp7.3.so exist in /usr/lib/apache2/modules.

I can get output from zm/api/composer.json (composer.json is in the api directory).
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: zm/api/monitors.json failing

Post by rockedge »

I think you have found a clue! rewrites are very important for the API to work as is the example of /host/.....The Cakewalk framework and CRUD are what builds the API...dependent on rewrites! Yes /host/ is important and is how the Calkwalk frame work works...

check that mod rewrite is on!
and that a .htaccess file exists in /zm/api with this in it:

Code: Select all

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule ^$ app/webroot/ [L]
   RewriteRule (.*) app/webroot/$1 [L]
   RewriteBase /zm/api
</IfModule>
I use Hiawatha and the that rewrite looks like this:

Code: Select all

UrlToolkit {
  ToolkitID = api_rule
  Match ^/zm/api Rewrite  /zm/api/app/webroot/index.php$1
}
SkippyDo
Posts: 219
Joined: Mon Nov 20, 2017 6:49 pm

Re: zm/api/monitors.json failing

Post by SkippyDo »

Got it!

I initially tried via .htaccess but not go. Some more searching and I can across https://community.openhab.org/t/zonemin ... i/34575/26. I added the following to the /etc/apache2/conf-enabled/zoneminder.conf file:

Code: Select all

<Directory "/usr/share/zoneminder/www/api/app">
   RewriteEngine on
   RewriteRule ^$ webroot/ [L]
   RewriteRule (.*) webroot/$1 [L]
   RewriteBase /zm/api
</Directory>

<Directory "/usr/share/zoneminder/www/api/app/webroot">
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    RewriteBase /zm/api
</Directory>
Post Reply