Skip to content
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

Host-Metering honors RHSM proxy configurations #61

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions contrib/man/host-metering.1
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ Will be used as the proxy URL for HTTP requests unless overridden by NO_PROXY.
\fBHTTPS_PROXY\fR
Will be used as the proxy URL for HTTPS requests unless overridden by NO_PROXY.

As systemd services do not have visibility into environment variables that are active in the user environment by default, the HTTP_PROXY and HTTPS_PROXY variables set within the user environment will not be detected by the host-metering service.
As systemd services do not have visibility into environment variables that are active in the user environment by default, the HTTP_PROXY and HTTPS_PROXY variables set within the user environment will not be detected by the host-metering service.
By default, the host-metering service will use the 'proxy_hostname' and 'proxy_port' as configured in '/etc/rhsm/rhsm.conf'.
To use custom proxy settings that will persist across package updates, you can create a .conf override file containing your custom proxy settings within the `/etc/systemd/system/host-metering.service.d/` directory.
This override configuration will take priority over proxy information available in '/etc/rhsm/rhsm.conf'.

Example override file contents:
Example override file contents:
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:3465"
Environment="HTTPS_PROXY=http://proxy.example.com:3465"
Expand Down
1 change: 1 addition & 0 deletions contrib/rpm/host-metering.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ install -m 0755 -vd %{buildroot}%{_bindir}
install -m 0755 -vp $(pwd)/bin/* %{buildroot}%{_bindir}/
install -m 0755 -vd %{buildroot}%{_unitdir}
install -m 644 contrib/systemd/host-metering.service %{buildroot}%{_unitdir}/%{name}.service
install -m 0755 contrib/systemd/host-metering-proxy-setup.sh %{buildroot}%{_bindir}/host-metering-proxy-setup.sh
install -m 0755 -vd %{buildroot}%{_presetdir}
install -m 644 contrib/systemd/80-host-metering.preset %{buildroot}%{_presetdir}/80-%{name}.preset
install -m 0755 -vd %{buildroot}%{_mandir}/man1
Expand Down
21 changes: 21 additions & 0 deletions contrib/systemd/host-metering-proxy-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

if [ -z "${HTTP_PROXY}" ] || [ -z "${HTTPS_PROXY}" ]; then
HTTP_PROXY=""
HTTPS_PROXY=""

if [ -f /etc/rhsm/rhsm.conf ]; then
PROXY_HOSTNAME=$(grep -E '^proxy_hostname\s*=' /etc/rhsm/rhsm.conf | awk -F= '{print $2}' | xargs)
PROXY_PORT=$(grep -E '^proxy_port\s*=' /etc/rhsm/rhsm.conf | awk -F= '{print $2}' | xargs)

if [ -n "$PROXY_HOSTNAME" ] && [ -n "$PROXY_PORT" ]; then
HTTP_PROXY="http://$PROXY_HOSTNAME:$PROXY_PORT"
HTTPS_PROXY="http://$PROXY_HOSTNAME:$PROXY_PORT"
fi
fi
fi

export HTTP_PROXY
export HTTPS_PROXY

exec /usr/bin/host-metering daemon
4 changes: 2 additions & 2 deletions contrib/systemd/host-metering.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ After=network-online.target
[Service]
Type=simple
Environment=LC_ALL=C.UTF-8
ExecStart=/usr/bin/host-metering daemon
ExecStart=/usr/bin/host-metering-proxy-setup.sh
ExecReload=/usr/bin/kill -HUP $MAINPID

Restart=always

[Install]
WantedBy=multi-user.target
WantedBy=multi-user.target
13 changes: 13 additions & 0 deletions hostinfo/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package hostinfo

import (
"fmt"
"os"
"strings"
)

Expand Down Expand Up @@ -55,12 +56,24 @@ func LoadHostInfo() (*HostInfo, error) {
}

func (hi *HostInfo) String() string {
httpProxy := os.Getenv("HTTP_PROXY")
if httpProxy == "" {
httpProxy = "No proxy set"
}

httpsProxy := os.Getenv("HTTPS_PROXY")
if httpsProxy == "" {
httpsProxy = "No proxy set"
}

return strings.Join(
[]string{
"HostInfo:",
fmt.Sprintf("| CpuCount: %d", hi.CpuCount),
fmt.Sprintf("| HostName: %s", hi.HostName),
fmt.Sprintf("| HostId: %s", hi.HostId),
fmt.Sprintf("| HTTP Proxy: %s", httpProxy),
fmt.Sprintf("| HTTPS Proxy: %s", httpsProxy),
fmt.Sprintf("| ExternalOrganization: %s", hi.ExternalOrganization),
fmt.Sprintf("| SocketCount: %s", hi.SocketCount),
fmt.Sprintf("| Product: %s", hi.Product),
Expand Down
2 changes: 2 additions & 0 deletions hostinfo/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func TestHostInfo(t *testing.T) {
"| CpuCount: 64\n" +
"| HostName: host.mock.test\n" +
"| HostId: 01234567-89ab-cdef-0123-456789abcdef\n" +
"| HTTP Proxy: No proxy set\n" +
"| HTTPS Proxy: No proxy set\n" +
"| ExternalOrganization: 12345678\n" +
"| SocketCount: 3\n" +
"| Product: [394 69]\n" +
Expand Down