Last active
August 19, 2025 12:52
-
-
Save jirihnidek/fc66ef4ede3099f88f192f2919c55d6f to your computer and use it in GitHub Desktop.
Foo rhc collector (Proof of concept)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # /usr/lib/rhc/collector.d/com.redhat.foo.toml | |
| [meta] | |
| name = "Red Hat Foo Collector" | |
| [exec] | |
| version_command = "/usr/libexec/foo-collector --version" | |
| user = "foo" | |
| group = "foo" | |
| [exec.collector] | |
| command = "/usr/libexec/foo-collector" | |
| [exec.uploader] | |
| command = "/usr/libexec/foo-uploader" | |
| [systemd] | |
| service = "rhc-collector-foo.service" | |
| timer = "rhc-collector-foo.timer" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # /usr/libexec/foo-collector | |
| VERSION=0.2 | |
| DELAY="0.1" | |
| LOGFILE="/var/log/foo/foo.log" | |
| if [[ $1 = "--help" ]]; then | |
| echo "NAME:" | |
| echo " $0 - foo rhc worker" | |
| echo "" | |
| echo "USAGE:" | |
| echo " $0 [global options]" | |
| echo "" | |
| echo "VERSION:" | |
| echo " ${VERSION}" | |
| echo "" | |
| echo "DESCRIPTION:" | |
| echo " It creates foo.txt file containing foo message" | |
| 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 "foo" -p "debug" | |
| echo "creating data file '${PWD}/foo.txt' ..." | systemd-cat -t "foo" -p "debug" | |
| sleep "${DELAY}" | |
| echo "foo" > foo.txt | |
| if [[ $? -ne 0 ]]; then | |
| echo "failed to create data file '${PWD}/foo.txt'" | systemd-cat -t "foo" -p "error" | |
| exit 1 | |
| fi | |
| # Output JSON document with information about directory, where collected data are stored | |
| echo "{\"collector_output\":\"${PWD}\"}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # /usr/libexec/foo-uploader | |
| VERSION=0.2 | |
| DELAY="0.4" | |
| TARGET="/dev/null" | |
| if [[ $1 = "--help" ]]; then | |
| echo "NAME:" | |
| echo " $0 - foo rhc uploader" | |
| echo "" | |
| echo "USAGE:" | |
| echo " $0 DIRECTORY_WITH_COLLECTED_DATA" | |
| echo " $0 [global options]" | |
| echo "" | |
| echo "VERSION:" | |
| echo " ${VERSION}" | |
| echo "" | |
| echo "DESCRIPTION:" | |
| echo " It uploads archive to /dev/null" | |
| 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 "foo" -p "debug" | |
| COLLECTION_DIR="${@: -1}" | |
| if [[ ! -d "${COLLECTION_DIR}" ]]; then | |
| echo "${COLLECTION_DIR} is not directory" | systemd-cat -t "foo" -p "error" | |
| exit 1 | |
| fi | |
| echo "adding directory '${COLLECTION_DIR}' to archive ${PWD}/foo.tar ..." | systemd-cat -t "foo" -p "debug" | |
| sleep "${DELAY}" | |
| tar -cf foo.tar ${COLLECTION_DIR} | |
| if [[ $? -ne 0 ]]; then | |
| echo "unable to add ${COLLECTION_DIR} to ${PWD}/foo.tar" | systemd-cat -t "foo" -p "error" | |
| exit 1 | |
| fi | |
| echo "compresing archive '${PWD}/foo.tar' to '${PWD}/foo.tar.gz' ..." | systemd-cat -t "foo" -p "debug" | |
| sleep "${DELAY}" | |
| gzip -f foo.tar | |
| if [[ $? -ne 0 ]]; then | |
| echo "failed to compress ${PWD}/foo.tar" | systemd-cat -t "foo" -p "error" | |
| exit 1 | |
| fi | |
| ARCHIVE="${PWD}/foo.tar.gz" | |
| echo "uploading archive ${ARCHIVE} to ${TARGET}" | systemd-cat -t "foo" -p "debug" | |
| sleep "${DELAY}" | |
| # Run "uploader" | |
| cp "${ARCHIVE}" "${TARGET}" | |
| if [[ $? -eq 0 ]]; then | |
| echo "{\"target\":\"${TARGET}\"}" | |
| exit 0 | |
| else | |
| exit 1 | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # /usr/lib/systemd/system/rhc-collector-foo.service | |
| [Unit] | |
| Description=Red Hat Foo collector | |
| After=network.target | |
| [Service] | |
| Type=oneshot | |
| ExecStart=/usr/bin/rhc-collector-executor com.redhat.foo | |
| [Install] | |
| WantedBy=multi-user.target | |
| # /usr/lib/systemd/system/service.d/10-timeout-abort.conf | |
| # This file is part of the systemd package. | |
| # See https://fedoraproject.org/wiki/Changes/Shorter_Shutdown_Timer. | |
| # | |
| # To facilitate debugging when a service fails to stop cleanly, | |
| # TimeoutStopFailureMode=abort is set to "crash" services that fail to stop in | |
| # the time allotted. This will cause the service to be terminated with SIGABRT | |
| # and a coredump to be generated. | |
| # | |
| # To undo this configuration change, create a mask file: | |
| # sudo mkdir -p /etc/systemd/system/service.d | |
| # sudo ln -sv /dev/null /etc/systemd/system/service.d/10-timeout-abort.conf | |
| [Service] | |
| TimeoutStopFailureMode=abort |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # /usr/lib/systemd/system/rhc-collector-foo.timer | |
| [Unit] | |
| Description=Red Hat Foo collector | |
| [Timer] | |
| OnCalendar=daily | |
| RandomizedDelaySec=4h | |
| [Install] | |
| WantedBy=timers.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment