Script python to get information into a bconsole from bareos.

92 views
Skip to first unread message

Yan Silva

unread,
May 31, 2024, 12:39:28 PM5/31/24
to bareos-users
Hi folks!!

I have a script in python to get a number of jobs in Warning and Error, but when i try to execute the script, for example: python testing_script.py get_error_jobs, hes show me this error:

   File "/usr/lib/python3.9/site-packages/bareos/bsock/directorconsolejson.py", line 93, in call
    raise bareos.exceptions.JsonRpcErrorReceivedException(json)
bareos.exceptions.JsonRpcErrorReceivedException: failed: .sql: is an invalid command.

The function from script is:

def get_error_jobs(args):
    console = create_console()
    error_jobs = console.call('.sql query="SELECT COUNT(Job) FROM Job where jobstatus=\'E\' AND starttime >= current_date - INTERVAL \'1 days\';"')
    try:
        print((error_jobs["query"][0]["count"]))
    except KeyError:
        print(0)

I execute directly this comand (.sql query="SELECT COUNT(Job) FROM Job where jobstatus=\'E\' AND starttime >= current_date - INTERVAL \'1 days\';) in the bconsole, and hes works fine.

Has anyone experienced this problem?

Jörg Steffens

unread,
Jun 5, 2024, 5:08:09 AM6/5/24
to bareos...@googlegroups.com
Hi,

I guess, you are using other credentials in Python than in the bconsole.
The bconsole has normally root access, while in Python you are typically
using a named console with limited permissions (profile).

Regards,
Jörg

On 31.05.24 at 18:39 wrote Yan Silva:
> --
> You received this message because you are subscribed to the Google
> Groups "bareos-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to bareos-users...@googlegroups.com
> <mailto:bareos-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/bareos-users/ca42ebd4-19b8-4de3-a855-0160ad718700n%40googlegroups.com <https://groups.google.com/d/msgid/bareos-users/ca42ebd4-19b8-4de3-a855-0160ad718700n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
Jörg Steffens joerg.s...@bareos.com
Bareos GmbH & Co. KG Phone: +49 221 630693-91
https://www.bareos.com

Sitz der Gesellschaft: Köln | Amtsgericht Köln: HRA 29646
Komplementär: Bareos Verwaltungs-GmbH
Geschäftsführer: Stephan Dühr, Jörg Steffens, Philipp Storz


Message has been deleted

Yan Silva

unread,
Jul 9, 2024, 12:45:11 PM7/9/24
to bareos-users
Even root access i execute and get the same error:

Screenshot_20240708_095358.png

Im using this bareos version: bareos-dir Version: 23.0.3~pre34.9a6c163ce (13 March 2024) and Python 3.9.

The same code works fine with bareos version 20.0.1 and Python 2.7
Screenshot_20240708_100429.png
Message has been deleted

Bruno Friedmann (bruno-at-bareos)

unread,
Jul 13, 2024, 6:08:11 AM7/13/24
to bareos-users
Maybe because you're trying something that doesn't exist 

In normal bconsole if you try command ".sql" you will also have *.sql
Automatically selected Catalog: mycatalog
Using Catalog "mycatalog"
query keyword not found.
You have messages.

which is not "sql" command

Not all traditional command have their api2 counter part, you will have to run normal command and play with return.

Hope this help.

Jörg Steffens

unread,
Jul 13, 2024, 6:35:22 AM7/13/24
to bareos...@googlegroups.com
On 10.07.24 at 10:09 wrote Bruno Friedmann (bruno-at-bareos):
> Maybe because you're trying something that doesn't exist
>
> In normal bconsole if you try command ".sql" you will also have *.sql
> Automatically selected Catalog: mycatalog
> Using Catalog "mycatalog"
> *query keyword not found.*
> You have messages.
>
> which is not "sql" command

I fear, that is not the cause of the problem.
The ".sql" command exists, but require a "query" parameter. It works
well in all api modes.

For me, it is still doubtful, that both commands (Python 2.7 and Python
> 3) user the same credentials, and/or that the Bareos server offers
the some permission for these credentials.

I still guess, other ACLs are defined for the Bareos user (not the
system user!) in the Python 3 case.

I guess you got misleaded by my last comment about "root" user. I did
not meant the system user, but the Bareos user/console, see
https://docs.bareos.org/Configuration/Director.html#console-resource

So, check with what credentials your script logins to the Director and
check what ACLs are defined for that user.

If you have a Bareos support contract, you probable could solve this
quickly with the help of the Bareos support team.

Without further information, there is nothing more I can do to help you
and as your answer to my last reply did take more than a month, I guess
this issue is not of much importance for you.

Regards,
Jörg

--
Jörg Steffens joerg.s...@bareos.com
Bareos GmbH & Co. KG Phone: +49 221 630693-0

Yan Silva

unread,
Jul 15, 2024, 8:49:35 AM7/15/24
to bareos-users
Sorry for so long to answer your previously answer, i was on vacation from my job, thats why.

Now i get it the problem and resolve them, i create a new profile conf and set him to the user (console), after that put him in the script.

Thanks, Jörg, its help a lot :)

Jörg Steffens

unread,
Jul 15, 2024, 12:53:36 PM7/15/24
to bareos...@googlegroups.com
On 15.07.24 at 14:49 wrote Yan Silva:
> Sorry for so long to answer your previously answer, i was on vacation
> from my job, thats why.
>
> Now i get it the problem and resolve them, i create a new profile conf
> and set him to the user (console), after that put him in the script.
>
> Thanks, Jörg, its help a lot :)

I'm glad, you found and solved the problem!

Regards,
Jörg

--
Jörg Steffens joerg.s...@bareos.com
Bareos GmbH & Co. KG Phone: +49 221 630693-91
Reply all
Reply to author
Forward
0 new messages