Nonexistant environment variable HOME #4

Open
opened 6 months ago by Seb35 · 5 comments
Seb35 commented 6 months ago

First, thanks for this plugin, I installed it on Icinga.

I just had a small issue: the HOME env variable used in ianardap.py:24 is not provided by Icinga 2.13 (at least in my installation), triggering an exception:

Traceback (most recent call last):
  File "/usr/local/bin/check_expire", line 21, in <module>
    import ianardap
  File "/usr/local/lib/python3.8/dist-packages/ianardap.py", line 24, in <module>
    CACHE = os.environ["HOME"] + "/.ianardapcaches"
  File "/usr/lib/python3.8/os.py", line 675, in __getitem__
    raise KeyError(key) from None
KeyError: 'HOME'

I applied the following diff:

diff --git a/ianardap.py b/ianardap.py
index 473aa56..a3b45a0 100755
--- a/ianardap.py
+++ b/ianardap.py
@@ -24 +24 @@ IANABASES = {"domains": "https://data.iana.org/rdap/dns.json",
-CACHE = os.environ["HOME"] + "/.ianardapcaches" 
+CACHE = os.environ["HOME"] + "/.ianardapcaches" if "HOME" in os.environ else "/var/cache/ianardap"

I created the directory and chown’ed it to the right user, it works.


Resolution:

  1. I’m not sure the fix above is a best practice, particularly regarding permissions in a shared directory. If I understand correctly, the specs about monitoring plugins are in this repo, but there no mention of cache (where to store a cached file).
  2. A second resolution is to add the HOME variable in the CheckCommand configuration of Icinga, as documented here with a directory specified by the sysadmin.
First, thanks for this plugin, I installed it on Icinga. I just had a small issue: the HOME env variable used in [ianardap.py:24](https://forge.chapril.org/bortzmeyer/check_expire/src/commit/b3709c64e96811f1267fcaebcc8f48d1dd551b8e/ianardap.py#L24) is not provided by Icinga 2.13 (at least in my installation), triggering an exception: ``` Traceback (most recent call last): File "/usr/local/bin/check_expire", line 21, in <module> import ianardap File "/usr/local/lib/python3.8/dist-packages/ianardap.py", line 24, in <module> CACHE = os.environ["HOME"] + "/.ianardapcaches" File "/usr/lib/python3.8/os.py", line 675, in __getitem__ raise KeyError(key) from None KeyError: 'HOME' ``` I applied the following diff: ```diff diff --git a/ianardap.py b/ianardap.py index 473aa56..a3b45a0 100755 --- a/ianardap.py +++ b/ianardap.py @@ -24 +24 @@ IANABASES = {"domains": "https://data.iana.org/rdap/dns.json", -CACHE = os.environ["HOME"] + "/.ianardapcaches" +CACHE = os.environ["HOME"] + "/.ianardapcaches" if "HOME" in os.environ else "/var/cache/ianardap" ``` I created the directory and chown’ed it to the right user, it works. ---- **Resolution:** 1. I’m not sure the fix above is a best practice, particularly regarding permissions in a shared directory. If I understand correctly, the specs about monitoring plugins are [in this repo](https://github.com/monitoring-plugins/monitoring-plugin-guidelines), but there no mention of cache (where to store a cached file). 2. A second resolution is to add the HOME variable in the CheckCommand configuration of Icinga, [as documented here](https://icinga.com/docs/icinga-2/latest/doc/03-monitoring-basics/#environment-variables) with a directory specified by the sysadmin.
Owner

Indeed, it works for me because I set HOME in the systemd configuration file:

% grep Environ /etc/systemd/system/multi-user.target.wants/icinga2.service
EnvironmentFile=/usr/lib/icinga2/icinga2
EnvironmentFile=/etc/default/icinga2

% cat /etc/default/icinga2
HOME="/var/lib/nagios"

IMHO, applications should be able to rely on HOME. I don't like the idea of having a hardwired home in the script itself, Icinga should do it, either automatically or through systemd (or, as you mentioned, through the env variable).

Indeed, it works for me because I set HOME in the systemd configuration file: ``` % grep Environ /etc/systemd/system/multi-user.target.wants/icinga2.service EnvironmentFile=/usr/lib/icinga2/icinga2 EnvironmentFile=/etc/default/icinga2 % cat /etc/default/icinga2 HOME="/var/lib/nagios" ``` IMHO, applications should be able to rely on HOME. I don't like the idea of having a hardwired home in the script itself, Icinga should do it, either automatically or through systemd (or, as you mentioned, through the env variable).
Seb35 commented 6 months ago
Poster

I aggree about the hardcoded value.

I will propose a pull request using "$XDG_CACHE_HOME/ianardap" if XDG_CACHE_HOME is set, else "$HOME/.ianardapcaches" if HOME is set, else no cache file with a loud warning to encourage users to set a cache. This might be changed if you prefer.

I aggree about the hardcoded value. I will propose a pull request using "$XDG_CACHE_HOME/ianardap" if XDG_CACHE_HOME is set, else "$HOME/.ianardapcaches" if HOME is set, else no cache file with a loud warning to encourage users to set a cache. This might be changed if you prefer.
Seb35 commented 6 months ago
Poster

So the pull request is linked, but I have an HTTP error 500 when I open #5 when logged in, no error when I’m logged out.

So the pull request is linked, but I have an HTTP error 500 when I open #5 when logged in, no error when I’m logged out.
Owner

This Gitea bug has been reported to the admin.

This Gitea bug has been reported to the admin.
Seb35 commented 6 months ago
Poster

This Gitea bug has been reported to the admin.

I also reported it yesterday – sorry I didn’t mention it – and a workaround is working for me (activate the PR on my fork). pilou- added this comment on Gitea.

> This Gitea bug has been reported to the admin. I also reported it yesterday – sorry I didn’t mention it – and a workaround is working for me (activate the PR on my fork). pilou- added [this comment](https://github.com/go-gitea/gitea/issues/20826#issuecomment-1356902596) on Gitea.
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: bortzmeyer/check_expire#4
Loading…
There is no content yet.