Hi,
I need some help getting NOEXIST to work for a directory.
I want to make sure that the /run/log/journal directory doesn't exist.
I see the NOEXIST option, but it seems to be for a FILE and I'm not sure what FILE semantics also apply to DIR. Thus far I've not been able to get it to work correctly.
-- Grant. . . . unix || die
Looking at the source code, the NOEXIST option is only available for file testing, not directory testing. You could make a request to add that feature.
The other option is to make your own simple external script that monitors for the non-existence of the directory.
Tom
On Tue, Oct 29, 2024 at 7:53 AM Grant Taylor via Xymon <xymon@xymon.com> wrote:
Hi,
I need some help getting NOEXIST to work for a directory.
I want to make sure that the /run/log/journal directory doesn't exist.
I see the NOEXIST option, but it seems to be for a FILE and I'm not sure what FILE semantics also apply to DIR. Thus far I've not been able to get it to work correctly.
-- Grant. . . . unix || die
Xymon mailing list -- xymon@xymon.com To unsubscribe send an email to xymon-leave@xymon.com
On 10/29/24 6:04 PM, Tom Schmidt wrote:
Looking at the source code, the NOEXIST option is only available for file testing, not directory testing. You could make a request to add that feature.
Thank you for clarifying and confirming what I thought might be the case. :-)
The other option is to make your own simple external script that monitors for the non-existence of the directory.
I've used a dir:COMMAND in the client-local.cfg (from memory) file
that looks for the directory and doesn't report it if it's not there and
avoids failing if the directory isn't there. I then have a DIR: ...
SIZE<1 in analysis.cfg for the directory in question.
-- Grant. . . . unix || die
Hi,
On 30/10/2024 00:55, Grant Taylor via Xymon wrote:
On 10/29/24 6:04 PM, Tom Schmidt wrote:
Looking at the source code, the NOEXIST option is only available for file testing, not directory testing. You could make a request to add that feature.
Thank you for clarifying and confirming what I thought might be the case. :-)
there is a workaround (read: dirty hack) you could use:
put a DIR check in your check list, like
DIR /home/user/test-directory SIZE<4B
and a corresponding line into logfetch.cfg:
[host=CLIENTHOSTNAME] dir://home/user/test-directory
(replacing CLIENTHOSTNAME with the correct value of course)
This checks for a directory /home/user/test-directory bigger than 4B. If it does not exist, xymon will report:
Could not determine size of directory /home/user/test-directory
If it does exist (even when empty, that's why we need to use 4B in size), xymon will report:
Could not determine size of directory /home/user/test-directory
It is not quite the same, but it could be used for this scenario. You could of course fine-tune the size values if you expect the directory to have a certain size, my test case was just an empty file.
Cheers Christoph
The other option is to make your own simple external script that monitors for the non-existence of the directory.
I've used a dir:
COMMANDin the client-local.cfg (from memory) file that looks for the directory and doesn't report it if it's not there and avoids failing if the directory isn't there. I then have a DIR: ... SIZE<1 in analysis.cfg for the directory in question.
On 10/30/24 05:44, Christoph Zechner wrote:
there is a workaround (read: dirty hack) you could use:
put a DIR check in your check list
That's what I did, and said as much.
On 10/29/24 18:55, Grant Taylor via Xymon wrote:
I've used a dir:
COMMANDin the client-local.cfg (from memory) file that looks for the directory and doesn't report it if it's not there and avoids failing if the directory isn't there. I then have a DIR: ... SIZE<1 in analysis.cfg for the directory in question.
The COMMAND part of the dir:COMMAND is that the command generates a
list of the directories that exist out of the possible directories.
If one of the possible directories doesn't exist, then it won't be
listed in COMMANDs output and as such won't generate an error for the
directory not existing.
For clarity, the possible directories are:
- /run/log/journal
- /var/log/journal
I'm wanting to make sure that /run/log/journal doesn't exist as I want to use persistent journaling to /var/log/journal.
Aside: I suppose I should also make sure that /var/log/journal does exist and that it's being used; read size > 0.
COMMAND is a simple /bin/ls -d /???/log/journal command that will
simply list one or both of the directories if they exist.
P.S. I'm tired of systemd-journald consuming ~4 GB of swap for logs that are in /run (tmpfs) which is memory -> swap backed. I've got multiple systems where logs are 80% of what's in swap. IMHO those logs should live on disk; hence /var/log/journal. -- I'm wanting to have Xymon be a safety net and report when it finds systems using the wrong directory.
-- Grant. . . .
What happens if you just make it a file: entry, even though it's a directory? My guess is that EXISTS simply reports whether the [file://run/log/journal] section has any content matching the "file" name. The fact that it happens to be a directory probably doesn't matter for EXISTS.
There's a chance that the [dir:<dirname>] is significantly different in structure from [file:<filename>] to the point that Xymon gets weirded out and complains that the "file" doesn't look like a file. If that's the case, use backticks to make the dir look like a file. Something like:
file:D=/run/log/journal; [ -d $D ] && stat --printf "type:100000 (file)\nmode:%a (%A)\nlinkcount:%h\nowner:%u (%U)\ngroup:%g (%G)\nsize:%s\nclock:$(date +'%s (%F %T.%N %z)')\natime:%X (%x)\nctime:%Z (%z)\nmtime:%Y (%y)\n" /run/log/journal
If the dir exists, this gives me:
type:100000 (file) mode:2755 (drwxr-sr-x) linkcount:3 owner:0 (root) group:190 (systemd-journal) size:60 clock:1730432083 (2024-11-01 14:34:43.189892664 +1100) atime:1730392322 (2024-11-01 03:32:02.629206150 +1100) ctime:1714705493 (2024-05-03 13:04:53.832001476 +1000) mtime:1714705472 (2024-05-03 13:04:32.778000198 +1000)
so Xymon should see this as a file, and things like EXISTS should work, and show this as OK.
If the dir doesn't exist, this gives me no output, so EXISTS should flag this as an error with an appropriate message.
Ugly, but should work, if you have GNUstat and date. If you like, you could
put this (or equivalent) into a script and use file:testdir /run/log/journal.
J
On Fri, 1 Nov 2024 at 13:07, Grant Taylor via Xymon <xymon@xymon.com> wrote:
On 10/30/24 05:44, Christoph Zechner wrote:
there is a workaround (read: dirty hack) you could use:
put a DIR check in your check list
That's what I did, and said as much.
On 10/29/24 18:55, Grant Taylor via Xymon wrote:
I've used a dir:
COMMANDin the client-local.cfg (from memory) file that looks for the directory and doesn't report it if it's not there and avoids failing if the directory isn't there. I then have a DIR: ... SIZE<1 in analysis.cfg for the directory in question.The
COMMANDpart of the dir:COMMANDis that the command generates a list of the directories that exist out of the possible directories.If one of the possible directories doesn't exist, then it won't be listed in
COMMANDs output and as such won't generate an error for the directory not existing.For clarity, the possible directories are:
- /run/log/journal
- /var/log/journal
I'm wanting to make sure that /run/log/journal doesn't exist as I want to use persistent journaling to /var/log/journal.
Aside: I suppose I should also make sure that /var/log/journal does exist and that it's being used; read size > 0.
COMMANDis a simple/bin/ls -d /???/log/journalcommand that will simply list one or both of the directories if they exist.P.S. I'm tired of systemd-journald consuming ~4 GB of swap for logs that are in /run (tmpfs) which is memory -> swap backed. I've got multiple systems where logs are 80% of what's in swap. IMHO those logs should live on disk; hence /var/log/journal. -- I'm wanting to have Xymon be a safety net and report when it finds systems using the wrong directory.
-- Grant. . . .
Xymon mailing list -- xymon@xymon.com To unsubscribe send an email to xymon-leave@xymon.com
On 10/31/24 22:51, Jeremy Laidman wrote:
What happens if you just make it a file: entry, even though it's a directory? My guess is that EXISTS simply reports whether the [file://run/log/journal] section has any content matching the "file" name. The fact that it happens to be a directory probably doesn't matter for EXISTS.
I tried that, and found that if the directory existed when Xymon was treating it like a file, I'd get a different error that would cause the page to change colors and report a false error message.
This is most apparent when you're wanting a file / directory to exist but you test it as the wrong type; directory / file respectively.
But I found the error message to be uninformative and easy to misinterpret.
There's a chance that the [dir:<dirname>] is significantly different in structure from [file:<filename>] to the point that Xymon gets weirded out and complains that the "file" doesn't look like a file.
Yes, that's a way to describe what I saw in my testing.
If that's the case, use backticks to make the dir look like a file. Something like:
file:
D=/run/log/journal; [ -d $D ] && stat --printf "type:100000 (file)\nmode:%a (%A)\nlinkcount:%h\nowner:%u (%U)\ngroup:%g (%G)\nsize:%s\nclock:$(date +'%s (%F %T.%N %z)')\natime:%X (%x)\nctime:%Z (%z)\nmtime:%Y (%y)\n" /run/log/journal
Oh. ... If I'm reading that correctly, you're testing if the directory ${D} exists and reporting a synthetic file entry back to Xymon.
If the dir exists, this gives me:
type:100000 (file) mode:2755 (drwxr-sr-x) linkcount:3 owner:0 (root) group:190 (systemd-journal) size:60 clock:1730432083 (2024-11-01 14:34:43.189892664 +1100) atime:1730392322 (2024-11-01 03:32:02.629206150 +1100) ctime:1714705493 (2024-05-03 13:04:53.832001476 +1000) mtime:1714705472 (2024-05-03 13:04:32.778000198 +1000)
That is an interesting hack. I'll have to try it.
so Xymon should see this as a file, and things like EXISTS should work, and show this as OK.
If the dir doesn't exist, this gives me no output, so EXISTS should flag this as an error with an appropriate message.
I actually want the /run/log/journal directory^W file to NOT exist. But that's a small edit. ;-)
Ugly, but should work, Yes ... but maybe borderline elegant. }:-)
if you have GNUstat and date.
Seeing as how the context is systemd-journald's storage location, thus a
Linux system, I think that it's fair to assume that GNU stat and
date are available. :-)
If you like, you could put this (or equivalent) into a script and use file:
testdir /run/log/journal.
Yep, I was already thinking about that.
I'll want to do some playing and see what the PATH or working directory
is when running such a file:script /directory is. I think it would be
nice if I could store the script in Xymon's bin directory. Hopefully I
wouldn't need to worry about hard coded paths to scripts that way.
Aside: I've got multiple different systems running Xymon and there are a few different installations, depending on distro & version there of vs compiled from source.
What I've got seems to be working, but I do want to try your elegant hack.
Time permitting I'll do so and follow up. Eventually.
-- Grant. . . .
LOL, "elegant hack" - you give me too much credit, describing it as elegant!
On my system: /usr/libexec/xymon-client:/bin:/usr/bin:/sbin:/usr/sbin:/etc
which is the same path if I run "xymoncmd --env=/path/to/xymon-client/etc/xymonclient.cfg"
I actually want the /run/log/journal directory^W file to NOT exist. But
that's a small edit. ;-)
Once the [file:dirname] entry is created for the dir, you will get an alert if it doesn't exist, unless you add NOEXIST (in analysis.cfg), which reverses the test result so you get an alert if it does exist.
J
participants (4)
-
Christoph Zechner
-
Grant Taylor
-
Jeremy Laidman
-
Tom Schmidt