Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API call to add monitor resports missing Name and OutputCodec parameters #3341

Open
aou opened this issue Aug 26, 2021 · 15 comments
Open

API call to add monitor resports missing Name and OutputCodec parameters #3341

aou opened this issue Aug 26, 2021 · 15 comments

Comments

@aou
Copy link

aou commented Aug 26, 2021

Hello!

Describe Your Environment

  • Version of ZoneMinder: 1.36
  • How you installed ZoneMinder [e.g. PPA, RPMFusion, from-source, etc] docker image built from zmdockerfiles
  • Full name and version of OS fedora 34
  • Browser name and version (if this is an issue with the web interface)

Describe the bug
Trying to add a monitor with the API results in messages about missing Name and OutputCodec parameters:

{'message': {'Name': ['Monitor Name must be specified for creation',
   'Monitor Name must be specified for creation'],
  'OutputCodec': ['Please choose one of the following values : H264, Mjpeg, Mpeg1, Mpeg2',
   'Please choose one of the following values : H264, Mjpeg, Mpeg1, Mpeg2']}}

To Reproduce
Steps to reproduce the behavior:
this request was made with python, have tried a couple of different values for OutputCodec, like 0, '0', 'H264'

    res = requests.post(
        f"{config.ZM_APIURL}/monitors.json",
        params={
            "Monitor[Name]": row.name,
            "Monitor[Function]": "Mocord",
            "Monitor[Type]": "Ffmpeg",
            "Monitor[Path]": path,
            "Monitor[Width]": "1280",
            "Monitor[Height]": "720",
            "Monitor[Colours]": "3",
            "Monitor[OutputCodec]": "H264",
            "token": token,
        },
    )

Interestingly, making the same request with the pyzm module results in a slightly different error, where the Name parameter seems to be filled, but OutputCodec still missing

Expected behavior
A clear and concise description of what you expected to happen.

Debug Logs
Nothing shows up in the logs for me when I make the API call.

@welcome
Copy link

welcome bot commented Aug 26, 2021

Thanks for opening your first issue here! Just a reminder, this forum is for Bug Reports only. Be sure to follow the issue template!

@aou
Copy link
Author

aou commented Aug 26, 2021

I modified the log volumes in my dockerfile, which I think made some permissions errors, so not all logs were showing. Fixed that, and I found this:

2021-08-26 14:05:03 Error: [PDOException] SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'h264' for column 'OutputCodec' at row 1
Request URL: /zm/api/monitors.json?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJab25lTWluZGVyIiwiaWF0IjoxNjMwMDEwMzM0LCJleHAiOjE2MzAwMTc1MzQsInVzZXIiOiJhZG1pbiIsInR5cGUiOiJhY2Nlc3MifQ._nrXrnp61shUHkx0uKUcWNy4xvIS6gNoNBhq7XEcWxk
Stack Trace:
#0 /usr/share/zoneminder/www/api/lib/Cake/Model/Datasource/DboSource.php(502): PDOStatement->execute(Array)
#1 /usr/share/zoneminder/www/api/lib/Cake/Model/Datasource/DboSource.php(468): DboSource->_execute('INSERT INTO `zm...', Array)
#2 /usr/share/zoneminder/www/api/lib/Cake/Model/Datasource/DboSource.php(1132): DboSource->execute('INSERT INTO `zm...')
#3 /usr/share/zoneminder/www/api/lib/Cake/Model/Model.php(1942): DboSource->create(Object(Monitor), Array, Array)
#4 /usr/share/zoneminder/www/api/lib/Cake/Model/Model.php(1760): Model->_doSave(Array, Array)
#5 /usr/share/zoneminder/www/api/app/Controller/MonitorsController.php(121): Model->save(Array)
#6 [internal function]: MonitorsController->add()
#7 /usr/share/zoneminder/www/api/lib/Cake/Controller/Controller.php(499): ReflectionMethod->invokeArgs(Object(MonitorsController), Array)
#8 /usr/share/zoneminder/www/api/app/Plugin/Crud/Lib/CrudControllerTrait.php(31): Controller->invokeAction(Object(CakeRequest))
#9 /usr/share/zoneminder/www/api/lib/Cake/Routing/Dispatcher.php(193): AppController->invokeAction(Object(CakeRequest))
#10 /usr/share/zoneminder/www/api/lib/Cake/Routing/Dispatcher.php(167): Dispatcher->_invoke(Object(MonitorsController), Object(CakeRequest))
#11 /usr/share/zoneminder/www/api/app/webroot/index.php(117): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#12 {main}

I think there are a couple of issues with error messaging and validation -- the error message implies that "H264" would be a valid value, but in fact it looks like lower case "h264" makes it past validation -- but then, it dies at the database level for not being an integer representative of (what i'm assuming is) an enum.

@aou
Copy link
Author

aou commented Aug 26, 2021

oh wait, actually that error log doesn't show up in the tailed logs, because of the filename! Had to exec into the docker container to see it.

@aou
Copy link
Author

aou commented Aug 26, 2021

I hacked together a solution by editing api/app/Model/Monitor.php and commenting out OutputCodec from the "actsAs" section, guessing that would bypass validation, and allow me to pass 0 directly back to the db. which worked!

Someone who knows better probably figure out an actual fix. I know zero php. :P

@connortechnology
Copy link
Member

Unfortunately the OutputCodec is actually an integer not an enumeration.
'0' => Auto,
'27' => 'h264',
'173' => 'h265/hevc',

These values actually come from the ffmpeg libraries. I think the right and friendly thing to do here is detect and auto-convert h264 to 27 in the api.

Looks like the api may just be out of date. I'll try to look further today.

@aou
Copy link
Author

aou commented Aug 30, 2021

@connortechnology oooh wow. ok, that's interesting. Yeah there's definitely a bug in that there doesn't seem to be a way to get a valid value in there, due to the validation bug, but totally not obvious that it's not or shouldn't be an enum. You're right, probably at the api level converting the string (preferably ignoring case) to the integer value that ffmpeg expects.

@ericzinnikas
Copy link

Seeing the same issue, unable to create cameras via the API. Commenting out this fixes the issue.

I tried replacing with something like:

'OutputCodec'     => array(0 => 'auto', 27 => 'h264', 173 => 'h265'),

but I still received some errors (will try to debug more later).

@seemantsharma001
Copy link

Has anyone got an solution for this issue ?
{
"message": {
"OutputCodec": [
"Please choose one of the following values : H264, Mjpeg, Mpeg1, Mpeg2",
"Please choose one of the following values : H264, Mjpeg, Mpeg1, Mpeg2"
]
}
}

@aou
Copy link
Author

aou commented Jun 2, 2022

@seemantsharma001 Way back when, I made a fork of zmdockerfiles, and had the Dockerfile patch the Monitor.php in a really hamfisted way, basically commenting out the 'OutputCodec' line. I believe @connortechnology above in this thread found the same "solution".

The commit is here, but I stopped using zoneminder shortly after, so almost certainly you'd need to re-apply the logic in your own environment.

@seemantsharma001
Copy link

Hi @aou I installed zoneminder on raspberry pi and didn't find the path api/app/Model/Monitor.php , can you please help?

@aou
Copy link
Author

aou commented Jun 2, 2022

looks like it's here

Is it a docker install or from package manager? If from package manager, you need to see where the files are installed and edit there. If running from docker, you'd have to do something like what I did, edit the docker file to patch as appropriate. Or I guess you could also exec bash into the docker container and edit by hand.

@seemantsharma001
Copy link

.disk/ etc/ media/ root/ srv/ var/
bin/ home/ mnt/ run/ sys/
boot/ lib/ opt/ sbin/ tmp/
dev/ lost+found/ proc/ snap/ usr/

These are the directories and I am not sure in which the zm in installed, any help? sorry to bother you but I am new to zm and rpi

@aou
Copy link
Author

aou commented Jun 2, 2022

sorry i'm not sure from the description how the app is installed / running. If it's on a debian-based system and you installed via package manager, you can try dpkg -L <package_name>

@aou
Copy link
Author

aou commented Jun 2, 2022

Might be good to try this out on something other than the raspberry pi to start, so you can get familiar with the mechanics of running a modified codebase.

@seemantsharma001
Copy link

@aou your logic helped and its working like magic. Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants