Page 1 of 2

Monitor several folders size in Windows

Posted: Mon Oct 02, 2017 9:55 am
by lpereira
Hello all:
This is related this post https://support.nagios.com/forum/viewto ... 16&t=45210

i was able to monitor a Windows folder by his size. however i'm unable to figure out how to monitor multiple folders

i have downloaded the script from here:
https://exchange.nagios.org/directory/P ... bs/details

Code: Select all

Set WshShell = WScript.CreateObject("WScript.Shell")
If WScript.Arguments.Length = 0 Then
  Set ObjShell = CreateObject("Shell.Application")
  ObjShell.ShellExecute "wscript.exe" _
    , """" & WScript.ScriptFullName & """ RunAsAdministrator", , "runas", 1
  WScript.Quit
End if

Dim strfolder
Dim intwarning
Dim intcritic
Dim wsh
Dim intvelkost
Dim intjednotka
Dim Perf_Data
'##########################################################'
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wsh = CreateObject("WScript.Shell")
'##########################################################'
If Wscript.Arguments.Count = 3 Then
strfolder = Wscript.Arguments(0)
intwarning = Wscript.Arguments(1)
intcritic = Wscript.Arguments(2)

Set objFolder = objFSO.GetFolder(strfolder)
intjednotka = 1048576 '1MB->bytes'
intvelkost = objFolder.Size/intjednotka
Perf_Data = "|'FolderSize'=" & round (objFolder.Size / 1048576,1) & "MB;"


if (objFolder.Size/1024000) > Cint(intcritic) then 
Wscript.Echo "CRITICAL:" & round (objFolder.Size / 1048576,1) & " MB" & Perf_Data
Wscript.Quit(2)
elseif (objFolder.Size/1048576) > Cint(intwarning) then 
Wscript.Echo "WARNING:" & round (objFolder.Size / 1048576,1) & " MB" & Perf_Data
Wscript.Quit(1)
else
Wscript.Echo "OK:" & round (objFolder.Size /1048576,1) & " MB" & Perf_Data
Wscript.Quit(0)
end if

else
Wscript.Echo "UNKNOWN:"& strfolder &"-" & intwarning & "-" & intcritic
Wscript.Quit(3)
End If

what i did is add the folder path in nsclient.ini
; A list of scripts available to run from the CheckExternalScripts module. Syntax is: <command>=<script> <arguments>
[/settings/external scripts/scripts]
check_foldersize=C:\windows\System32\cscript.exe //NoLogo //T:30 "C:\Program Files\nsclient++\scripts\check_folder_size.vbs" "E:\System Volume Information" 8192 5120
i have tried to add a similar line below pointing to the same folder on drive G but i got only one output when i run the command Nagios Side.

can anyone tell me how can i get this working?

thanks

Re: Monitor several folders size in Windows

Posted: Mon Oct 02, 2017 1:48 pm
by cdienger
Can you attach the similar line that you added as well as the command you're running on the XI side?

It sounds like commands that you're running on XI probably point to the same command in the ini file.

Re: Monitor several folders size in Windows

Posted: Mon Oct 02, 2017 1:57 pm
by lpereira
cdienger wrote:Can you attach the similar line that you added as well as the command you're running on the XI side?

It sounds like commands that you're running on XI probably point to the same command in the ini file.
what i'm running is

Code: Select all

 ./check_nrpe -H ServerIP -t 30 -c check_foldersize -n
and the return is (for instance)

Code: Select all

CRITICAL:218709.9 MB|'FolderSize'=218709.9MB

Re: Monitor several folders size in Windows

Posted: Mon Oct 02, 2017 2:04 pm
by cdienger
In that case it will only run one of the definitions in the ini file. You'll want to do something like:

Code: Select all

[/settings/external scripts/scripts]
    check_foldersize=C:\windows\System32\cscript.exe //NoLogo //T:30 "c:\program files\nsclient++\scripts\check_folder_size.vbs" "$ARG1$" 50 78
and then specify the folder when you run the command:

Code: Select all

./check_nrpe -H NSCLIENTIP -c check_foldersize -a "c:\program files\nsclient++"

Re: Monitor several folders size in Windows

Posted: Mon Oct 02, 2017 2:35 pm
by lpereira
cdienger wrote:In that case it will only run one of the definitions in the ini file. You'll want to do something like:

Code: Select all

[/settings/external scripts/scripts]
    check_foldersize=C:\windows\System32\cscript.exe //NoLogo //T:30 "c:\program files\nsclient++\scripts\check_folder_size.vbs" "$ARG1$" 50 78
and then specify the folder when you run the command:

Code: Select all

./check_nrpe -H NSCLIENTIP -c check_foldersize -a "c:\program files\nsclient++"
i'm getting the following error linux side

Code: Select all

 ./check_nrpe -H SERVERIP -c check_foldersize -a "F:\System Volume Information" -n
Exception processing request: Request contained arguments (not currently allowed, check the allow arguments option).
i did what you recommended on the nsclient file

Code: Select all

[/settings/external scripts/scripts]
check_foldersize=C:\windows\System32\cscript.exe //NoLogo //T:30 "c:\program files\nsclient++\scripts\check_folder_size.vbs" "$ARG1$" 8192 5120
[/settings/external scripts/alias]
check_folder_size.vbs=check_foldersize


Re: Monitor several folders size in Windows

Posted: Mon Oct 02, 2017 2:55 pm
by cdienger
make sure the nsclient.ini file contains:

Code: Select all

[/settings/external scripts]
allow arguments = true
allow nasty characters = true

Re: Monitor several folders size in Windows

Posted: Mon Oct 02, 2017 3:10 pm
by lpereira
cdienger wrote:make sure the nsclient.ini file contains:

Code: Select all

[/settings/external scripts]
allow arguments = true
allow nasty characters = true
yes the nsclient.ini has those two lines

Re: Monitor several folders size in Windows

Posted: Mon Oct 02, 2017 3:48 pm
by cdienger
Check the entire file for lines starting with allow arguments and allow nasty characters. You man need to set it in a couple places. Make sure to restart the nsclient service after making any changes.

Re: Monitor several folders size in Windows

Posted: Tue Oct 03, 2017 6:52 am
by lpereira
Yes i reviewed them all... in some options is set to "0", i changed them to "1" and i got the following msj

Code: Select all

[root@Nagios XI libexec]# ./check_nrpe -H IP SERVER -c check_foldersize -a "C:\System Volume Information" -n
Exception processing request: Request contained arguments (not currently allowed, check the allow arguments option).
So, i assume 0 is correct

Re: Monitor several folders size in Windows

Posted: Tue Oct 03, 2017 12:39 pm
by scottwilkerson
you want these to be set to true

Code: Select all

allow arguments = true
Once they all are, you need to restart the NSClient{++ service.

If this still doesn't work, can you attach the nsclient.ini from this windows machine so we can take a look?

Thanks.