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

--output json doesn't produce json output #83

Closed
joejulian opened this Issue Jun 5, 2015 · 8 comments

Comments

5 participants
@joejulian
Copy link

joejulian commented Jun 5, 2015

Many systemctl commands do not produce json output when --output json is set.

# systemctl -o json list-dependencies glusterd
glusterd.service
● ├─system.slice
● └─basic.target
●   ├─alsa-restore.service
●   ├─alsa-state.service
●   ├─dnf-makecache.timer
●   ├─fedora-autorelabel-mark.service
●   ├─fedora-autorelabel.service
●   ├─fedora-loadmodules.service
●   ├─firewalld.service
●   ├─paths.target
●   ├─slices.target
●   │ ├─-.slice
●   │ └─system.slice
●   ├─sockets.target
●   │ ├─avahi-daemon.socket
●   │ ├─cups.socket
●   │ ├─dbus.socket
●   │ ├─dm-event.socket
...
@keszybz

This comment has been minimized.

Copy link
Member

keszybz commented Jun 6, 2015

From the manpage: -o: When used with status, controls the formatting of the journal entries that are shown.

@joejulian

This comment has been minimized.

Copy link

joejulian commented Jun 6, 2015

It would still be nice if it would produce machine readable outputs for better integration with tools like saltstack, puppet, or any other user created tool that wants to do something with the output.

@eliasp

This comment has been minimized.

Copy link
Contributor

eliasp commented Jun 7, 2015

Although I agree that -o json should return proper JSON, believe the proper way for external tools like SaltStack etc. to talk to systemd is DBus. See also saltstack/salt#20392 - everything else is more or less just hack-ish and prone to break easily.

@keszybz

This comment has been minimized.

Copy link
Member

keszybz commented Jun 7, 2015

Some of the verbs implemented by systemctl are designed to provide a high-level overview in a human readable format. All that information is available over dbus, and/or journalctl, systemctl show. We could provide that information in json format, but there's a second problem. Information and format of information printed by e.g. systemctl status is not stable. Since the output is not suitable for programmatic consumption anyway, there's no need to provide it in a machine readable format.

But for things like 'list-dependencies', output is simple enough that we could add the ability to dump it in json format. In principle, this information is already available through other means, but it is actually a fair amount of work to gather it in this form, and I think it could be useful to open it up to programmatic consumption. I'm not going to work on this myself, but if somebody comes up with a patch, I'd be happy to review and merge.

@poettering

This comment has been minimized.

Copy link
Member

poettering commented Jun 8, 2015

I am not convinced adding JSON for all of this is really a good idea. I mean, I am all for providing good APIs to integrate systemd's concepts with other projects, but I'd try to keep things minimal there, and focus on as few sets of APIs as possible, but then keep the quality of them high. Now, for scripting languages I am pretty sure the bus APIs are the best option. The largest part of our APIs is exposed via dbus. The journal is an exception, for performance reasons much of it happens on the client side, hence it probably makes sense to support the JSON exporting for it directly. However, that really doesn't mean we should expose everything else in JSON too... In particular as JSON itself is a just a passive format, and not a real RPC... If we'd want to turn it into one we'd need REST and HTTP and whatnot, and I am not really sure we should cover all that in systemd itself...

@njam

This comment has been minimized.

Copy link

njam commented Aug 24, 2016

What is the recommended API to retrieve dependencies of a unit/target?
I can't find anything on the D-Bus interface, is there something else?

@poettering

This comment has been minimized.

Copy link
Member

poettering commented Aug 24, 2016

@njam please direct questions like yours to the proper channels, i.e. the systemd mailing list. Random github issues are really not the place to ask such questions.

@njam

This comment has been minimized.

lucab pushed a commit to lucab/systemd that referenced this issue Aug 7, 2017

Merge pull request systemd#83 from dm0-/v234-coreos
Cherry-pick non-upstreamed patches from v233 onto v234
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment