Virtualmin Command Line API, unformatted output?

SYSTEM INFORMATION
OS type and version Ubuntu 22.4
Webmin version 2.111
Virtualmin version 7.20.2 Pro
Webserver version Apache/2.4.58
Related packages SUGGESTED

I’m working with the Command Line API. The output for multiline results usually is pretty-printed, with nice boxes, headers etc. Great for readability. However, I need to parse the output for a python app. Do I really have to filter out all the heading, dashes etc, or is there an option that results in plain, hopefully delimited, ASCII output? Can’t find it in the dox.
Remember: CLI interface, not remote. Thank you!

It would be better if there was a command line option that returned the data as xml or json which would be much easier to parse but I dont think the current out put can be formatted that way. Perhaps this should be added to the developers to do list

Either one would be fine. In the meantime, I wrote a cumbersome parser …

@Jamie, I think we should support the --json flag for all Virtualmin CLI commands.

However, with so many scripts to change, we need to find a way to handle it somehow differently.

There is always a --multiline flag that produces a much more easily parsable format. It’s not JSON, but should be simple to handle in Python because it’s always like :

object-ID-1:
  attribute1: value1
  attribute2: value2
  etc..
object-ID-2:
  attribute1: value3
  attribute2: value4
etc..

Still requires the user to parse it, which is harder than import json or import yaml or whatever premade parser.

We do also support JSON format when using the remote API, which does the conversion from the Virtualmin format above automatically with the json=1 parameter. I’d generally recommend using the remote API for scripts actually, since it means the script doesn’t have to run as root.

I know you do, Jamie. For this application, I prefer CLI and root.

@Jamie, I got excited, dug in, and solved the problem in the latest commit by adding a new --multiline-json flag.

@bschmitt If you want to give it a try, you can apply the patch and see how it works for you:

webmin patch https://github.com/virtualmin/virtualmin-gpl/commit/475dfc8

:exclamation: After further code improvements, we updated the parameters to output the same format as the remote API. The parameter names were also changed to --json and --xml for the CLI. :exclamation:

4 Likes

That was fast!

Illia, you are a champ!

2 Likes

Thank you!!!

Will do tomorrow, thank you!

You’re welcome!

Sorry, I’m a total noob when it comes to git patches. Could someone give me the complete command to apply that patch? Thank you!!

Yes, it’s mentioned in the comment above.

Tried that before:

webmin patch https://github.com/virtualmin/virtualmin-gpl/commit/475dfc8
Error: Command `patch` doesn't exist


webmin --list-commands

disable-proxy
disable-twofactor
enable-proxy
language-manager
list-config
passwd
server
set-config
update-devel

your version of webmin may to early try upgrading to webmin version 2.202 and try again

Upgraded to 2.02, patch applied successfully:

webmin patch https://github.com/virtualmin/virtualmin-gpl/commit/                                                                                                         475dfc8
Patch applied successfully to:
  config
  config-freebsd
  list-admins.pl
  list-aliases.pl
  list-available-scripts.pl
  list-available-shells.pl
  list-backup-keys.pl
  list-backup-logs.pl
  list-commands.pl
  list-custom.pl
  list-databases.pl
  list-domains.pl
  list-dropbox-files.pl
  list-features.pl
  list-gcs-buckets.pl
  list-gcs-files.pl
  list-mysql-servers.pl
  list-php-directories.pl
  list-php-ini.pl
  list-php-versions.pl
  list-plans.pl
  list-ports.pl
  list-proxies.pl
  list-redirects.pl
  list-rs-containers.pl
  list-rs-files.pl
  list-s3-accounts.pl
  list-s3-buckets.pl
  list-s3-files.pl
  list-scheduled-backups.pl
  list-scripts.pl
  list-server-statuses.pl
  list-service-certs.pl
  list-shared-addresses.pl
  list-simple-aliases.pl
  list-templates.pl
  list-users.pl
  virtual-server-lib-funcs.pl

However:

virtualmin list-certs-expiry --all-domains --multiline-json
Unknown parameter --multiline-json

Same after systemctl restart webmin

This command in particular isn’t yet supported.

That’s what I would need it for. Never mind, I wrote my own parser.