Home > HowTo, Windows > Nagios to check log vbs

Nagios to check log vbs

September 30th, 2011 Leave a comment Go to comments

I just wrote a quick plugin to check any txt file on windows for a certain
keyword. I have written simillar plugins for linux but this one was done in vbs.


'Script Check for keyword in a specific file
'Author: Felipe Ferreira
'Data: 29/09/2011
'Version: 1.0 (nagios)

' TODO:
'get args, set warnings
'OK -  Go into a folderfile and look for a keyword if found report it

option explicit

'---------- VARs
Const intOK = 0
Const intCritical = 2
Const intError = 3
Const ForReading=1,ForWriting=2,ForAppending=8
Dim strfile,keyword
Dim intcount : intCount = 0
Dim stroutput,intCrit

'----------EDIT LINES
strfile = "c:EditorialloglogKindle.log"
keyword="Não foi possivel conectar ao servidor"
intCrit = 1                                                                                     ' Number of keyword found, to be consider critical
'----------EDIT LINES

if strfile = "" then
	 pt "Empty folder value!"
else
	 call checkfiles(strfile)
end if

if intCount >= intCrit then
	wscript.echo "CRITICAL - " & strfile & " with total of " & intcount & " keywords:" & keyword & " found |keyword=" & intCount
	wscript.quit(intCritical)
else
	wscript.echo  "OK -  No problems found |keyword=" & intCount
	wscript.quit(intOK)
end if

sub checkfiles(strfile)
'Look for specific keyword on the file
	Dim objFSO,objServerList,strLine
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	If objFSO.FileExists(strfile) Then
	   Set objServerList = objFSO.OpenTextFile(strfile, ForReading)
	   Do Until objServerList.AtEndOfStream
		 strLine = objServerList.ReadLine
		 if instr(strLine, keyword) then
		  intCount = intCount + 1
		 end if
	   Loop
	  objServerList.Close
	End If
	Set objServerList = Nothing
	Set objFSO = Nothing
end sub

Categories: HowTo, Windows Tags:
  1. No comments yet.
  1. No trackbacks yet.

VAMOVE *

*