Home > Nagios, plugins > Nagios plugin to check folder

Nagios plugin to check folder

August 1st, 2011 Leave a comment Go to comments

This plugin object is to check if a file has been inside certain folder
for a period of time and alert if so.

It’s still not fully developed so the variables are not passed as arguments
but are inside the script, so Directory and Time are configured within the .vbs.
In our case the files came in via FTP and some external process should move these
files some where else, sometimes these work how it should, so we monitor it to detect and
fix failures, thats what a good SysAdmins do!

Download it here

'Script Check for files in folders
'Author: Felipe Ferreira
'Data: 29/07/2011
'Version: 2.0 (nagios)

' TODO:
'ok 1. Have arrray of folders to be checked, pass time as argument
'ok 2. Output folder that has problems


'---------- VARs
Const intOK = 0
Const intCritical = 2
Const intError = 3
Const ForReading=1,ForWriting=2,ForAppending=8
Dim filename,filenamemov,emailaddr
Dim arrFolders(17)
Dim argcountcommand,dteToday
Dim arg(4)
Dim strMailServer,Verbose,strExt,intTimeOld,intIndex
Dim intcount : intCount = 0
Dim stroutput

'option explicit

'----------EDIT LINES
intTimeOld = 15   ' how many seconds old are the files
Verbose = 0       ' 1 FOR DEBUG MODE, 0 FOR SILENT MODE
'----------EDIT LINES
dteToday = now()
'DatePart("m",Now())
pt "Today = " & dteToday


arrFolders(0) = "X:digitalXLocalUserftp_fotXama - Locais"
arrFolders(1) = "X:digitalXLocalUserftp_fotXama_Bairros"
arrFolders(3) = "X:digitalXLocalUserftp_fotGlobo_Remotas"
arrFolders(4) = "X:digitalXLocalUserftp_sfotocol"
arrFolders(5) = "X:digitalXLocalUserftp_sAudioevideo"
arrFolders(6) = "X:digitalXLocalUserftp_svide"




For intIndex = 0 To UBound(arrFolders)
	pt "Checking folder: " &  arrFolders(intIndex)
	if arrFolders(intIndex) = "" then
	 pt "Empty folder value!"
	 Exit For
	else
	 call checkfiles(arrFolders(intIndex))
	end if
Next


if intCount >= 1 then
	wscript.echo "CRITICAL - " & intCount & " Arquvio(s) com mais de " & intTimeOld  & " minutos em " & stroutput
	wscript.quit(intCritical)
else
	wscript.echo  "OK -  Nenhum diretorio contem arquvios com mais de 5 minutos"
	wscript.quit(intOK)
end if


sub checkfiles(folderspec)
'check if any files exist on folder
on error resume next
	Dim fs : Set fs = CreateObject("Scripting.FileSystemObject")
	If (fs.FolderExists(folderspec)) Then
		Set f = fs.GetFolder(folderspec)
		Set fc = f.Files
		For Each f1 in fc
		  intDif = DateDiff("n",f1.DateCreated,dteToday)
		  pt f1.name & " - " & f1.DateCreated & " - " & dteToday & " DIFF= " & intDIf
		  If (intDif > intTimeOld)  then
			 stroutput = stroutput &  folderspec & f1.name & " ("& intDIf & "min) , "
			 intCount = intCount + 1
		  end if
		next
	else
		wscript.echo "ERROR -  Diretorio: " & folderspec & " nao foi encontrado."
		wscript.quit(intError)
	end if
	set fs = nothing
end sub

sub pt(txt)
	if Verbose = 1 then
		wscript.echo txt
	end if
end sub

  1. No comments yet.
  1. No trackbacks yet.

VAMOVE *

*