Skip to content

Instantly share code, notes, and snippets.

@jirihnidek
Created August 19, 2025 10:36
Show Gist options
  • Save jirihnidek/611c9710d9c838c92db0408731f2dafe to your computer and use it in GitHub Desktop.
Save jirihnidek/611c9710d9c838c92db0408731f2dafe to your computer and use it in GitHub Desktop.
Bar rhc collector (Proof of concept)
#!/bin/bash
# /usr/libexec/bar-collector
VERSION=0.2
DELAY="0.1"
if [[ $1 = "--help" ]]; then
echo "NAME:"
echo " $0 - bar rhc worker"
echo ""
echo "USAGE:"
echo " $0 [global options]"
echo ""
echo "VERSION:"
echo " ${VERSION}"
echo ""
echo "DESCRIPTION:"
echo " It creates bar.json file containing valid JSON document"
echo ""
echo "GLOBAL OPTIONS:"
echo " --help show help"
echo " --version print version"
exit 0
fi
if [[ $1 = "--version" ]]; then
echo "${VERSION}"
exit 0
fi
echo "working in directory '${PWD}' ..." | systemd-cat -t "bar" -p "debug"
echo "creating data file '${PWD}/bar.json' ..." | systemd-cat -t "bar" -p "debug"
sleep "${DELAY}"
echo "{\"foo\":\"foo\"}" > bar.json
if [[ $? -ne 0 ]]; then
echo "failed to create data file '${PWD}/bar.json'" | systemd-cat -t "bar" -p "error"
exit 1
fi
# Output JSON document with information about directory, where collected data are stored
echo "{\"collector_output\":\"${PWD}/bar.json\", \"mime_type\":\"application/json\"}"
# /usr/lib/rhc/collector.d/com.redhat.bar.toml
[meta]
name = "Red Hat Bar Collector"
[exec]
version_command = "/usr/libexec/bar-collector --version"
[exec.collector]
command = "/usr/libexec/bar-collector"
[exec.uploader]
command = "/usr/libexec/bar-uploader"
[systemd]
service = "rhc-collector-bar.service"
timer = "rhc-collector-bar.timer"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment