Counting the number of files in a Windows client

This forum was archived to /woltlab and is now in read-only mode.
  • Sadly all Icinga return messages are in German in this check.

    What do you mean by that? :)

  • I finally got it working! (partially, the return value is wrong, see below):thumbsup:

                                    value = "-unit count -path ."

    or the mentioned C:\Users\ path works too now (now sure why it didn't work when I tried it first).

    Small new problem - return value problem:

    I also tried a clean simple check_filecount.ps1 script so that I only have a number as a return value - script:

    Write-Host (dir . | measure).Count;

    but the return value instead of 43 (in my case) when executed from within the powershell on the Windows client, is 4353in the icingaweb2 GUI.

    It's same with the original script from #9:

    Datei(en) . - 4353 Datei(en) instead of Datei(en) . - 43 Datei(en)

  • Hi, you should not change the "value = ..." in the command, but use the variable "$files_windows_args$" in the Service like so: 'vars.files_windows_args = "-unit count -path ."'. For the 4353 problem: try the absolute patch, not the "." thing. I'am pretty sure you are counting files in C:\windows\systm32\ and its only a very unlucky coincidence that there are 4353 files.

  • Sry, i mean that my return messages from the script (which are shown in icingaweb) are in german :)

    Ah. Can you upload the script(s) to your GitHub account please? Then sending in a patch is more elegant :)

  • Great,

                                    value = "-unit count -path 'C:\\Program Files\\ICINGA2\\sbin'"

    works :)

    Now the last thing missing is the coloring in icingaweb2 if say a folder contains too many files. How? Also the coloring at the moment is purple. I'd guess that's because $$LASTEXITCODE is not set?

    Edit: That's indeed it and when changed to "0" to "4" the coloring changes :)

    I try to change the return code using an If statement within a .conf file (not sure if it's even possible) but so far it's not working:

    1. [...]
    2. ";exit" = {
    3. If($value -gt 40)
    4. value = "1"
    5. Else
    6. value = "0"
    7. order = 99
    8. }

    How would this be possible?

  • If you use my script just add "-c g40" ('vars.files_windows_args = "-unit count -path /my/path/ -c g40"')

  • If you use my script just add "-c g40" ('vars.files_windows_args = "-unit count -path /my/path/ -c g40"')

    Ok, I put it as you mentioned and it works so far and shows that the threshold is over the limit

    Critical: Datei(en) C:\Program Files\ICINGA2\sbin Mehr als 40 Datei(en) - 44 Datei(en

    but the color doesn't change and it's shown as "OK" and in green.


                                value = "$files_windows_args$"


      vars.files_windows_args = "-unit count -path 'C:\\Program Files\\ICINGA2\\sbin' -c g40"

  • I got it working :thumbsup: I still had the $$LASTEXITCODE set manually to 0 to test things. Now I have set both on the Linux server and Windows client the same object CheckCommand "files-windows" {...}.

    Still don't know how they are related and whether I need both but if I remove the object CheckCommand "files-windows" {...} either on the Linux server or the Windows client, it doesn't work.

    Summary if someone encounters the same problem and wants to monitor a Windows client:

    Add both to the Linux server and the Windows client, in the:

    • commands.conf (the object CheckCommand powershell andobject CheckCommandpowershell-x86 not required) this:

    (The check_files.ps1 from post #9 is (obviously) in the C:\Program Files\ICINGA2\sbin folder)

    • And in the services.conf this:
    1. apply Service "check filecount" {
    2. import "generic-service"
    3. check_command = "files-windows"
    4. command_endpoint = host.vars.remote_client
    5. vars.files_windows_args = "-unit count -path 'C:\\Program Files\\ICINGA2\\sbin' -c g45"
    6. assign where host.vars.os == "Windows"
    7. }

    • (I had the basic by-default installed disk usage, cpu usage, ... tools located in C:\Program Files\ICINGA2\sbin already working when I started my question, otherwise you may see my above posted zones.conf)

    Thanks everyone for help :thumbsup:

  • You always need the command config files on the master, AND clients, because otherwise the config verification will fail, because icinga always checks all config files for missing things and errors. So, if the master knows something about your service check, he needs to know the command too, even he is not executing this himself.