Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Help with Script created to check log files.

$
0
0

Hi,

I have a program we use in our organization on multiple workstations that connect to a MS SQL 2005 database on a Virtual Microsoft 2008 r2 Server. The program is quite old and programmed around the days when serial connections were the most efficient means of connection to a device. If for any reason the network, virtual server or the SAN which the virtual server runs off have roughly 25% utilization or higher on its resources the program on the workstations timeout from the SQL database and drop the program from the database completely rendering it useless. The program does not have the smarts to resync itself to the SQL database and it just sits there with "connection failed" until human interaction. A simple restart of the program reconnects itself to the SQL database without any issues. This is fine when staff are onsite but the program runs on systems out of hours when the site is unmanned.

The utilization of the server environment is more than sufficient if not it has double the recommended resources needed for the program. I am in regular contact with the support for the program and it is a known issue for them which i believe they do not have any desire to fix in the near future. 

I wish to create a simple script that checks the log files on each workstation or server the program runs on and emails me if a specific word comes up in that log file. The word will only show when a connection failure has occurred.

After the email is sent i wish for the script to close the program and reopen it to resync the connection.

I will schedule the script to run ever 15 minutes.

I have posted this up in a previous post about a month ago but i went on holidays over xmas and the post died from my lack or response.

Below is what i have so far as my script. I have only completed the monitoring of the log file and the email portion of it. I had some help from a guy on this forum to get the script to where it is now. I know basic to intermediate scripting so sorry for my crudity if any.

The program is called "wasteman2G" and the log file is located in \\servername\WasteMan2G\Config\DCS\DCS_IN\alert.txt

I would like to get the email side of this script working first and then move on to getting the restart of the program running after.

At the moment i am not receiving an error from the script. It runs and doesn't complete what it should.

Could someone please help?

                            Const strMailto = "rvellios@XXX.XX.XX.XX"
Const strMailFrom = "support@XXX.XX.XX.XX"
Const strSMTPServer = "mrc1tpv002.XXXX.local"
Const FileToRead = "\\Mrctpv005\WasteMan2G\Config\DCS\DCS_IN\alert.txt"
arrTextToScanFor = Array("SVR2006","SVR2008")

Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

Set oFile = objFSO.GetFile(FileToRead)
dLastCreateDate = CDate(WshShell.RegRead("HKLM\Software\RDScripts\CheckTXTFile\CreateDate"))
If oFile.DateCreated = dLastCreateDate Then
    intStartAtLine = CInt(WshShell.RegRead("HKLM\Software\RDScripts\CheckTXTFile\LastLineChecked"))
Else
    intStartAtLine = 0
End If

i = 0
Set objTextFile = oFile.OpenAsTextStream()
Do While Not objTextFile.AtEndOfStream
    If i < intStartAtLine Then
        objTextFile.SkipLine
    Else
        strNextLine = objTextFile.Readline()
        For each strItem in arrTextToScanFor
            If InStr(LCase(strNextLine),LCase(strItem)) Then
                strResults = strNextLine & vbcrlf & strResults
            End If
        Next
    End If
    i = i + 1
Loop
objTextFile.close

WshShell.RegWrite "HKLM\Software\RDScripts\CheckTXTFile\FileChecked", FileToRead, "REG_SZ"
WshShell.RegWrite "HKLM\Software\RDScripts\CheckTXTFile\CreateDate", oFile.DateCreated, "REG_SZ"
WshShell.RegWrite "HKLM\Software\RDScripts\CheckTXTFile\LastLineChecked", i, "REG_DWORD"
WshShell.RegWrite "HKLM\Software\RDScripts\CheckTXTFile\LastScanned", Now, "REG_SZ"

If strResults <> "" Then
    SendCDOMail strMailFrom,strMailto,"VPN Logfile scan alert",strResults,"","",strSMTPServer
End If

Function SendCDOMail( strFrom, strSendTo, strSubject, strMessage , strUser, strPassword, strSMTP )

  With CreateObject("CDO.Message")
        .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTP
        .Configuration.Fields.item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic
        .Configuration.Fields.item("http://schemas.microsoft.com/cdo/configuration/sendusername") = strUser
        .Configuration.Fields.item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = strPassword
        .Configuration.Fields.Update
        .From = strFrom
        .To = strSendTo
        .Subject = strSubject
        .TextBody = strMessage
        On Error Resume Next
        .Send
      If Err.Number <> 0 Then
           WScript.Echo "SendMail Failed:" & Err.Description
      End If
  End With

End Function



Viewing all articles
Browse latest Browse all 15028

Trending Articles