This is how I monitor the number of files older than n-minutes in a windows directory:
1. fill in the correct zabbix-server-IP and de correct hostname of the windows system
in the commandstring in the vb-script (see below)
2. save the vb-script as c:\zabbix\file_age.vbs on the windows system to be monitored.
3. add userparameter in the zabbix_agentd.conf:
UserParameter=file_age[*],cscript.exe c:\zabbix\file_age.vbs $1 $2
4. restart zabbix agent
5. create 2 items in zabbix:
first one:
description: younameit
type: zabbix trapper
key: tr_file_age
type: numeric
second one:
description: tr_file_age
type: zabbix agent
key: file_age[c:\root\sub,120]
type: text
interval: 300
explanation: the second one makes the zabbix agent execute the script every 300 seconds, while the first one catches the output of the script. The output is the number of files older dan 120 minutes in the directory c:\root\sub
The script itself:
strDirectoryFolder = WScript.Arguments(0)
max_age = WScript.Arguments(1)
counter = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strDirectoryFolder)
Set colFiles = objFolder.Files
date1 = Now()
For Each objFile in colFiles
strFileName = objFile.Path
date2 = objFile.DateCreated
strFile = strFileName
fileage = DateDiff("n",date2,Now()) - max_age
If fileage > 0 Then
counter = counter + 1
End If
Next
Set WshShell = CreateObject("wscript.Shell")
commandstring="c:\zabbix\zabbix_sender.exe -z ZBX_IPADDRESS -s HOSTNAME -k tr_file_age -o " & counter
WshShell.Run commandstring,0
WScript.Quit
Good luck,
1. fill in the correct zabbix-server-IP and de correct hostname of the windows system
in the commandstring in the vb-script (see below)
2. save the vb-script as c:\zabbix\file_age.vbs on the windows system to be monitored.
3. add userparameter in the zabbix_agentd.conf:
UserParameter=file_age[*],cscript.exe c:\zabbix\file_age.vbs $1 $2
4. restart zabbix agent
5. create 2 items in zabbix:
first one:
description: younameit
type: zabbix trapper
key: tr_file_age
type: numeric
second one:
description: tr_file_age
type: zabbix agent
key: file_age[c:\root\sub,120]
type: text
interval: 300
explanation: the second one makes the zabbix agent execute the script every 300 seconds, while the first one catches the output of the script. The output is the number of files older dan 120 minutes in the directory c:\root\sub
The script itself:
strDirectoryFolder = WScript.Arguments(0)
max_age = WScript.Arguments(1)
counter = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strDirectoryFolder)
Set colFiles = objFolder.Files
date1 = Now()
For Each objFile in colFiles
strFileName = objFile.Path
date2 = objFile.DateCreated
strFile = strFileName
fileage = DateDiff("n",date2,Now()) - max_age
If fileage > 0 Then
counter = counter + 1
End If
Next
Set WshShell = CreateObject("wscript.Shell")
commandstring="c:\zabbix\zabbix_sender.exe -z ZBX_IPADDRESS -s HOSTNAME -k tr_file_age -o " & counter
WshShell.Run commandstring,0
WScript.Quit
Good luck,