-
Notifications
You must be signed in to change notification settings - Fork 88
POC: SnapRAID API ? #28
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
Conversation
|
Wow, this UI looks fantastic! Nice job! The JSON output would be a god sense for me. I am the maintainer of the SnapRAID AIO Script and parsing the ouput as it is right now is... painful, especially tables. Having a predictable output would be a dream! |
|
I wrote some scripts to integrate and automate snapraid functionality and I like this proposal. off the top of my head, lsblk has the -P option to write the results in "key=value" format There are also "jsonifier" middleware projects that wrangle the stdout output of (some) CLI software and provide a json for ingest in ther programs. But these are just moving the annoyance and fragility of stdout parsing to the middleware, having a native option from the CLI software itself is probably best. |
|
Hi @firsttris Thanks for the proposal. Your work on a Web UI and the prototype for JSON output is impressive, especially considering you're new to the C codebase. It clearly highlights a gap in SnapRAID's current machine-readable output. What you suggest is similar to the existing log_tag() statements, which are designed to output structured and stable information for tools and scripts. I would like to continue to use this system, but I can use your proposal as a direct hint of what specific information is missing and what should be added. We cannot change the existing log_tag() statements because we need to maintain backward compatibility with all the existing tools and scripts that rely on their stable format. However, we can add as many new log_tag() statements as needed to provide the data you require. Essentially, log_tag() outputs information in the format NAME:VALUE0:VALUE1:... in the log file specified with -log. You can also force this output to stdout or stderr using the special arguments >&1 or >&2. For example: snapraid status -l ">&2" This keeps the structured data separate and stable, which is crucial for external monitoring tools. Could you identify the specific information your Web UI requires that is currently difficult to parse from the standard output? We can then work together to define new, stable log_tag() entries for that data. This approach will satisfy your need for a stable API while maintaining backward compatibility for the SnapRAID project. |
|
Currently, my Web UI parses the regular stdout, not the JSON proposal. I was just experimenting to see if there might be a better approach — and it turns out there’s already a solution I hadn’t considered. While I was using the --log option to write logs to a file, it didn’t occur to me that I could simply use -l ">&2". That actually solves it nicely. Thanks for your help! |
|
snapraid status -l ">&2" wish I knew this sooner ... |
|
I wish i knew this sooner too.. it's a great thing to consider for my script. Thanks! |
|
I prepared a prerelease version of SnapRAID that includes a few new log tags and their full documentation in snapraid_log.txt. You can download it from Git or from http://ftp.snapraid.it/ |
Hey,
I’ve been using SnapRAID for almost 10 years now on my home server. To this day, it’s still my preferred solution.
It saved me many times.
For a long time, I thought it would be great to have a Web UI for controlling and monitoring SnapRAID, but I never had the time to explore the idea properly.
Also, from time to time I see people on Reddit requesting such a feature:
https://www.reddit.com/r/Snapraid/comments/1h32mdn/any_good_gui_for_snapraid/
https://www.reddit.com/r/Snapraid/comments/1ha3468/snapraid_ui/
https://www.reddit.com/r/DataHoarder/comments/2s0zg8/management_and_monitoring_for_snapraid/
There is a native Windows application called Elucidate, but since I'm a Linux user and want something that runs directly on the server, that wasn’t really an option.
Also, OpenMediaVault has (or had) a WebUI plugin for SnapRAID, but I manily use Arch and Fedora.
Because I have a strong background in TypeScript, and since there’s still no good solution in 2025, I thought it would be a fun project to build a SnapRAID Web UI with Docker/Podman support myself:
https://github.com/firsttris/snapraid-ui
Since SnapRAID doesn’t have many commands, I assumed it wouldn’t be too difficult.
However, because SnapRAID is strictly a command-line tool, it doesn’t provide an API. Parsing plain stdout to understand what happened is cumbersome, brittle, and likely to break over time.
So I started wondering whether SnapRAID could expose some form of API.
Implementing a socket-based API would probably be a much larger task.
But adding a simple --json command-line option to output structured data (or JSON streaming for commands like sync and scrub) seems far more realistic to implement.
To understand what would be required to add such a --json option to the SnapRAID CLI, I explored the codebase. Please consider this more of a proof-of-concept to demonstrate the idea rather than a finished solution. I mainly wanted to prototype it and see what it would take.
I think it’s not entirely easy, because JSON output needs to be implemented individually for each command.
I have no experience with the C programming language,
but I still managed to get JSON output working for some commands.
Even if my Web UI project ends up not being great, such feature would make it much easier for others to build their own UIs, dashboards, or integrations for SnapRAID.
I also want to highlight that I’m completely open to better ideas or alternative approaches. If this is not the right direction, that’s totally fine — no hard feelings at all.
I’m happy to collaborate or support any effort that moves in that direction.
Examples: