Although there has been discussion in the past (http://www.xymon.com/archive/2007/02/msg00047.html) about a way to track numbers of files in a directory through the xymon client, no working solution was posted (and the only one I found (http://www.xymon.com/archive/2007/02/msg00079.html), the author claimed it would work, but (a) it does not - variable should not have a $ before it when you set it, and (b) the author gives no indication of how it should be used). I had a use for this facility, and didn't need the normal dir count that returns a size in KB (or whatever du returns on your server), and did not want to write an ext script as that seemed to create unnecessary load, so after several false starts, and finally having to read the source code, I found a working solution, which was to write a script that output the information in the same format as the du command and then redefine the du command in xymonclient.cfg as per the two listings below.
Create filecount.sh in the client/bin folder, chmod +x it, and replace the du command by setting the DU environment variable in client/etc/xymonclient.cfg...
[xymon at myServer client]$ cat bin/filecount.sh #!/bin/sh
Written by SebA 11/01/11
#filecount=ls $1 | wc -l
The following is more efficient, at least on CentOS 5: 'it will show files
immediately and it has no memory limitations.'
#filecount=ls -1 -U $1 | wc -l
Must be >=1, or Xymon will interpret the result as a failure, so include .
and .. (and 'hidden') files.
filecount=ls -a -1 -U $1 | wc -l
Ensure we have a tab between the number and the pathname...
echo "$filecount $1"
That last line may have been converted from a tab character, so replace the consecutive space characters when you use it!
[xymon at myServer client]$ grep filecount etc/xymonclient.cfg DU="$XYMONHOME/bin/filecount.sh" # Replace with my filecount script. /Seb
You can then use dir as normal on the server in client-local.cfg and hobbit-clients.cfg (sorry - my client is running newest xymon, while the server is running hobbit). So you can use SIZE on the file-count where it would normally work on the dir-size (du).
Of course, proper client/server support, instead of overriding du would be better, but maybe this will help someone until that happens, or maybe this will be the trigger for that to happen. ;)
In the course of my debugging, I was somewhat frustrated by the length of time changes took to progagate from the server to the client (but I can live with this). What would be routinely useful though is that even if the result is a green in the files column, that it displayed what the criteria are (like it does if the result is non-green)? Because it (hobbit-clients.cfg) is clearly cached by the server and not checked when the client reports. (I believe hobbit-alerts.cfg (or whatever it is called now) is checked when the client reports, no? So they do not behave the same.) Anyway, this caching means one does not know which criteria were used to determine a green result. Plus, displaying it in the page would be more convenient as most people don't have the file open in another window!
Kind regards,
SebA
Internal Virus Database is out of date. Checked by AVG - www.avg.com Version: 8.5.449 / Virus Database: 271.1.1/3243 - Release Date: 11/07/10 19:34:00